CREAR FACTURA CLIENTE USANDO DI SERVER

Code with Edd

COMO CREAR UNA FACTURA DE CLIENTES EN SAP BUSINESS ONE USANDO DI SERVER.

Estructura que debe de tener el XML que se genera para crear una factura de clientes en SAPB1 utilizando la librería DI Server.

public AddResponseDocument AddInvoiceV2(string SessionID, MearketingDoctoReqV2[] document)
{
    try
    {
        string soap_cmd = "";
        string response = "";

        soap_cmd = "<?xml version=\"1.0\" encoding=\"UTF-16\"?>";
        soap_cmd += "<env:Envelope xmlns:env=\"http://www.w3.org/2003/05/soap-envelope\">";
        soap_cmd += "<env:Header>";
        soap_cmd += "<SessionID>" + SessionID + "</SessionID>";
        soap_cmd += "</env:Header>";
        soap_cmd += "<env:Body>";

        soap_cmd += "<dis:AddObject xmlns:dis=\"http://www.sap.com/SBO/DIS\">";
        soap_cmd += "<BOM>";
        soap_cmd += "<BO>";

        soap_cmd += "<AdmInfo>";
        soap_cmd += "<Object>oInvoices</Object>";
        soap_cmd += "</AdmInfo>";

        soap_cmd += "<Documents>";
        soap_cmd += "<row>";

        soap_cmd += "<DocType>dDocument_Items</DocType>";
        soap_cmd += "<DocDate>" + DateTime.Now.ToString("yyyy-MM-dd") + "</DocDate>";
        soap_cmd += "<DocDueDate>" + DateTime.Now.ToString("yyyy-MM-dd") + "</DocDueDate>";
        soap_cmd += "<CardCode>" + document[0].cardCode + "</CardCode>";
        soap_cmd += "<DocCurrency>" + document[0].docCurrency + "</DocCurrency>";
        soap_cmd += "<Comments>" + document[0].comments + "</Comments>";
        soap_cmd += "<SalesPersonCode>" + document[0].slpCode + "</SalesPersonCode>";

        soap_cmd += "</row>";
        soap_cmd += "</Documents>";


        soap_cmd += "<Document_Lines>";
        for (int i = 0; i < document.Length; i++)
        {
            soap_cmd += "<row>";
            soap_cmd += "<LineNum>" + i + "</LineNum>";
            soap_cmd += "<ItemCode>" + document[i].itemCode + "</ItemCode>";
            soap_cmd += "<Quantity>" + document[i].quantity + "</Quantity>";
            if (document[i].discountPercent > 0)
            {
                // agrega partida con descuento........
                soap_cmd += "<Price>" + document[i].price + "</Price>";
                //soap_cmd += "<UnitPrice>" + document[i].unitPrice + "</UnitPrice>";
                soap_cmd += "<LineTotal>" + (document[i].price * document[i].quantity) + "</LineTotal>";
                soap_cmd += "<DiscountPercent>" + document[i].discountPercent + "</DiscountPercent>";
            }
            else
            {
                soap_cmd += "<Price>" + document[i].price + "</Price>";
                soap_cmd += "<UnitPrice>" + document[i].unitPrice + "</UnitPrice>";
                soap_cmd += "<DiscountPercent>" + document[i].discountPercent + "</DiscountPercent>";
            }
            
            soap_cmd += "<Currency>" + document[i].currency + "</Currency>";
            soap_cmd += "<WarehouseCode>" + document[i].warehouseCode + "</WarehouseCode>";
            soap_cmd += "</row>";
        }
        soap_cmd += "</Document_Lines>";


        soap_cmd += "<BatchNumbers>";

        double solicito = 0;
        double disponible = 0;

        for (int i = 0; i < document.Length; i++)
        {
            DataTable dtLotes = this.GetLotes(document[i].itemCode, document[i].warehouseCode);
            solicito = document[i].quantity;
            disponible = 0;

            if (dtLotes != null)
            {
                for (int j = 0; j < dtLotes.Rows.Count; j++)
                {
                    disponible = double.Parse(dtLotes.Rows[j]["Quantity"].ToString());
                    if (disponible >= solicito)
                    {
                        dtLotes.Rows[j]["Asignada"] = solicito;
                        break;
                    }
                    else
                    {
                        dtLotes.Rows[j]["Asignada"] = disponible;
                        solicito -= disponible;
                    }
                }

                for (int j = 0; j < dtLotes.Rows.Count; j++)
                {
                    if (double.Parse(dtLotes.Rows[j]["Asignada"].ToString()) != 0)
                    {
                        soap_cmd += "<row>";
                        soap_cmd += "<BaseLineNumber>" + i + "</BaseLineNumber>";
                        soap_cmd += "<BatchNumber>" + dtLotes.Rows[j]["BatchNum"].ToString() + "</BatchNumber>";
                        soap_cmd += "<Quantity>" + double.Parse(dtLotes.Rows[j]["Asignada"].ToString()) + "</Quantity>";
                        soap_cmd += "</row>";
                    }
                }
            }
        }
        soap_cmd += "</BatchNumbers>";

        soap_cmd += "</BO>";
        soap_cmd += "</BOM>";
        soap_cmd += "</dis:AddObject>";
        soap_cmd += "</env:Body>";
        soap_cmd += "</env:Envelope>";


        response = NodeDIS.Interact(soap_cmd);

        AddResponseDocument res = this.xml.AddDocumentResponseV2(response);

        res.docNum = this.GetDocNumInvoice(res.docEntry);

        return res;
    }
    catch (Exception ex)
    {
        this.logger.LogError(ex, ex.Message + " | " + ex.StackTrace);
        return new AddResponseDocument { success = false, codeErr = 400, docEntry = null, docNum = null, message = ex.Message };
    }
}

Referencia: SAP Business One SDK – Help Center

https://help.sap.com/viewer/product/SAP_BUSINESS_ONE/9.3/es-ES

.

CREAR FACTURA CLIENTE USANDO DI SERVER
Web | + posts

Full Stack Web Developer && SDK SAPB1 Developer.

Melómano, Gamer (Xbox), Comprador compulsivo de Amazon y Posiblemente con TDAH.

Scroll hacia arriba