public FacturaDeVentaSOP(string DatosConexionDB)
        {
            //Stream outputFile = File.Create(@"C:\GPDocIntegration\traceInterfazGP.txt");
            //textListener = new TextWriterTraceListener(outputFile);
            //trace = new TraceSource("trSource", SourceLevels.All);
            //trace.Listeners.Clear();
            //trace.Listeners.Add(textListener);
            //trace.TraceInformation("integra factura sop");

            connStringEF = DatosConexionDB;
            facturaSopCa = new taSopHdrIvcInsert();
            facturaSopDe = new taSopLineIvcInsert_ItemsTaSopLineIvcInsert();
            facturaSop   = new SOPTransactionType();
        }
        public void armaFacturaCaEconn(vwIntegracionesVentas preFacturasIntegCab, IList <vwPreFacturas> preFacturasDet, string sTimeStamp, string tipoContribuyente)
        {
            try
            {
                short soptype = preFacturasIntegCab.SOPTYPE_GP ?? 3;

                //var docId = parametrosDB.IdsDocumento.Where(x=>x.Key.CompareTo(tipoContribuyente)==0)?.First() ;
                string docId = string.Empty;
                parametrosDB.IdsDocumento.TryGetValue(tipoContribuyente.Trim(), out docId);

                if (string.IsNullOrEmpty(docId))
                {
                    throw new InvalidOperationException(string.Concat("No existe configurado el tipo de contribuyente ", tipoContribuyente, " en el archivo de parámetros. [FacturaDeVentaSOPBandejaDB.armaFacturaCaEconn]"));
                }

                string sopnumbe = getNextSopNumbe(soptype, docId);

                facturaSopCa.CREATETAXES = 1;   //1: crear impuestos automáticamente
                facturaSopCa.DEFPRICING  = 1;   //1: calcular automáticamente; 0:se debe indicar el precio unitario

                facturaSopCa.BACHNUMB = sTimeStamp;
                facturaSopCa.SOPTYPE  = soptype;
                facturaSopCa.DOCID    = docId;
                facturaSopCa.SOPNUMBE = sopnumbe;
                facturaSopCa.DOCDATE  = preFacturasIntegCab.FECHADOC.ToString(parametrosDB.FormatoFechaDB);
                facturaSopCa.CUSTNMBR = preFacturasIntegCab.IDCLIENTE;
                facturaSopCa.CSTPONBR = preFacturasIntegCab.NUMDOCARN;

                facturaSopCa.REFRENCE = preFacturasIntegCab.OBSERVACIONES;

                //facturaSopCa.SUBTOTAL = Decimal.Round(unitprice, 2);
                //facturaSopCa.DOCAMNT = facturaSopCa.SUBTOTAL;

                facturaSop.taSopLineIvcInsert_Items = new taSopLineIvcInsert_ItemsTaSopLineIvcInsert[preFacturasDet.Count];
                int i = 0;
                foreach (var d in preFacturasDet)
                {
                    facturaSopDe            = new taSopLineIvcInsert_ItemsTaSopLineIvcInsert();
                    facturaSopDe.SOPTYPE    = facturaSopCa.SOPTYPE;
                    facturaSopDe.SOPNUMBE   = facturaSopCa.SOPNUMBE;
                    facturaSopDe.CUSTNMBR   = facturaSopCa.CUSTNMBR;
                    facturaSopDe.DOCDATE    = facturaSopCa.DOCDATE;
                    facturaSopDe.ITEMNMBR   = d.IDITEM;
                    facturaSopDe.ITEMDESC   = d.DESCRIPCION;
                    facturaSopDe.QUANTITY   = d.CANTIDAD;
                    facturaSopDe.DEFPRICING = 1;     //1: calcular el precio y precio extendido automáticamente
                    //facturaSopDe.DEFEXTPRICE = 1;   //1: calcular el precio extendido en base al precio unitario y la cantidad
                    facturaSop.taSopLineIvcInsert_Items[i] = facturaSopDe;
                    i++;
                    //Decimal unitprice = 0;
                    //if (Decimal.TryParse(hojaXl.Cells[fila, int.Parse(param.FacturaSopUNITPRCE)].Value.ToString(), out unitprice))
                    //{
                    //    facturaSopDe.UNITPRCE = Decimal.Round(unitprice, 2);
                    //}
                    //else
                    //    throw new FormatException("El monto es incorrecto en la fila " + fila.ToString() + ", columna " + param.FacturaSopUNITPRCE + " [armaFacturaCaEconn]");
                }
            }
            catch (FormatException fmt)
            {
                throw new FormatException("Formato incorrecto [armaFacturaCaEconn]", fmt);
            }
            catch (OverflowException ovr)
            {
                throw new OverflowException("Monto demasiado grande [armaFacturaCaEconn]", ovr);
            }
            //finally
            //{
            //    trace.Flush();
            //    trace.Close();

            //}
        }
        private void serializeSOPObject(string filename, Transaction assessment, string documentID, string defaultSiteID)
        {
            try
            {
                taSopLineIvcInsert_ItemsTaSopLineIvcInsert itemLine;

                taSopLineIvcInsert_ItemsTaSopLineIvcInsert[] lineItems =
                    new taSopLineIvcInsert_ItemsTaSopLineIvcInsert[assessment.Items.Count];


                int r = 0;
                //populate item lines
                foreach (Item item in assessment.Items)
                {
                    itemLine =
                        new taSopLineIvcInsert_ItemsTaSopLineIvcInsert();

                    //item pks
                    itemLine.SOPTYPE  = (short)assessment.TransactionType;
                    itemLine.CUSTNMBR = assessment.StudentID;
                    itemLine.SOPNUMBE = assessment.DocumentNumber;
                    itemLine.PRCLEVEL = assessment.PriceLevel; //20100527

                    itemLine.DOCID = documentID;
                    //item details
                    itemLine.ITEMNMBR = item.ItemNo;
                    itemLine.UOFM     = item.Uofm;
                    if (assessment.TransactionType == Transaction_Type.Drop)
                    {
                        itemLine.QUANTITY = item.Qty;
                        itemLine.QTYINSVC = item.Qty;
                    }
                    else if (assessment.TransactionType == Transaction_Type.Assessment)
                    {
                        itemLine.QUOTEQTYTOINV = item.Qty;
                    }
                    else if (assessment.TransactionType == Transaction_Type.Add)
                    {
                        itemLine.QUANTITY = item.Qty;
                    }
                    itemLine.ITEMDESC          = item.ItemDescription;
                    itemLine.UNITPRCE          = item.Unitprice;
                    itemLine.MRKDNPCTSpecified = true;
                    itemLine.MRKDNPCT          = item.MarkDown;

                    itemLine.XTNDPRCE = item.ExtendedPrice;
                    itemLine.LOCNCODE = defaultSiteID;
                    itemLine.DOCDATE  = assessment.DocumentDate.ToShortDateString();

                    //itemLine.UpdateIfExists = 1;
                    lineItems[r] = itemLine;
                    r           += 1;
                }
                //add items

                SOPTransactionType salesOrder = new SOPTransactionType();
                Array.Resize(ref salesOrder.taSopLineIvcInsert_Items, r);
                salesOrder.taSopLineIvcInsert_Items = lineItems;

                taSopHdrIvcInsert header = new taSopHdrIvcInsert();

                //populate header node
                header.SOPTYPE           = (short)assessment.TransactionType;
                header.SOPNUMBE          = assessment.DocumentNumber;
                header.DOCID             = documentID;
                header.PRCLEVEL          = assessment.PriceLevel; //20100527
                header.TRDISAMTSpecified = true;

                header.BACHNUMB = assessment.BatchID;
                header.LOCNCODE = defaultSiteID;
                header.CUSTNMBR = assessment.StudentID;
                header.CUSTNAME = assessment.StudentName;
                header.CURNCYID = assessment.CurrencyID;
                header.DOCDATE  = assessment.DocumentDate.ToShortDateString();
                if (assessment.TransactionType == Transaction_Type.Assessment)
                {
                    header.QUOEXPDA = assessment.ExpirationDate.ToShortDateString();
                    header.INVODATE = assessment.DocumentDate.ToShortDateString();
                }
                header.CMMTTEXT = assessment.Comments;
                header.SUBTOTAL = assessment.Subtotal;
                header.TRDISAMT = assessment.TotalDiscounts;
                header.MISCAMNT = assessment.InstallmentFee;
                header.DOCAMNT  = assessment.TotalAmount;
                header.USINGHEADERLEVELTAXES = 1;
                //header.DEFTAXSCHDS = 1;
                //header.UpdateExisting = 1;

                //add header

                salesOrder.taSopHdrIvcInsert = header;

                eConnectType eConnType = new eConnectType();
                Array.Resize(ref eConnType.SOPTransactionType, 1);
                eConnType.SOPTransactionType[0] = salesOrder;
                //serialization proper
                using (FileStream fs = new FileStream(filename, FileMode.Create))
                {
                    XmlTextWriter writer     = new XmlTextWriter(fs, new UTF8Encoding());
                    XmlSerializer serializer = new XmlSerializer(eConnType.GetType());
                    serializer.Serialize(writer, eConnType);
                    writer.Close();
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
                throw ex;
            }
        }
Exemple #4
0
        private void serializeSOPObject(string filename, Transaction assessment, string documentID, string defaultSiteID)
        {
            try
            {
                taSopLineIvcInsert_ItemsTaSopLineIvcInsert itemLine;

                taSopLineIvcInsert_ItemsTaSopLineIvcInsert[] lineItems =
                    new taSopLineIvcInsert_ItemsTaSopLineIvcInsert[assessment.Items.Count];

                int r = 0;
                //populate item lines
                foreach (Item item in assessment.Items)
                {
                    itemLine =
                        new taSopLineIvcInsert_ItemsTaSopLineIvcInsert();

                    //item pks
                    itemLine.SOPTYPE = (short)assessment.TransactionType;
                    itemLine.CUSTNMBR = assessment.StudentID;
                    itemLine.SOPNUMBE = assessment.DocumentNumber;
                    itemLine.PRCLEVEL = assessment.PriceLevel; //20100527

                    itemLine.DOCID = documentID;
                    //item details
                    itemLine.ITEMNMBR = item.ItemNo;
                    itemLine.UOFM = item.Uofm;
                    if (assessment.TransactionType == Transaction_Type.Drop)
                    {
                        itemLine.QUANTITY = item.Qty;
                        itemLine.QTYINSVC = item.Qty;
                    }
                    else if (assessment.TransactionType == Transaction_Type.Assessment)
                    {
                        itemLine.QUOTEQTYTOINV = item.Qty;
                    }
                    else if (assessment.TransactionType == Transaction_Type.Add)
                    {
                        itemLine.QUANTITY = item.Qty;
                    }
                    itemLine.ITEMDESC = item.ItemDescription;
                    itemLine.UNITPRCE = item.Unitprice;
                    itemLine.MRKDNPCTSpecified = true;
                    itemLine.MRKDNPCT = item.MarkDown;

                    itemLine.XTNDPRCE = item.ExtendedPrice;
                    itemLine.LOCNCODE = defaultSiteID;
                    itemLine.DOCDATE = assessment.DocumentDate.ToShortDateString();

                    //itemLine.UpdateIfExists = 1;
                    lineItems[r] = itemLine;
                    r += 1;
                }
                //add items

                SOPTransactionType salesOrder = new SOPTransactionType();
                Array.Resize(ref salesOrder.taSopLineIvcInsert_Items, r);
                salesOrder.taSopLineIvcInsert_Items = lineItems;

                taSopHdrIvcInsert header = new taSopHdrIvcInsert();

                //populate header node
                header.SOPTYPE = (short)assessment.TransactionType;
                header.SOPNUMBE = assessment.DocumentNumber;
                header.DOCID = documentID;
                header.PRCLEVEL = assessment.PriceLevel; //20100527
                header.TRDISAMTSpecified = true;

                header.BACHNUMB = assessment.BatchID;
                header.LOCNCODE = defaultSiteID;
                header.CUSTNMBR = assessment.StudentID;
                header.CUSTNAME = assessment.StudentName;
                header.CURNCYID = assessment.CurrencyID;
                header.DOCDATE = assessment.DocumentDate.ToShortDateString();
                if (assessment.TransactionType == Transaction_Type.Assessment)
                {
                    header.QUOEXPDA = assessment.ExpirationDate.ToShortDateString();
                    header.INVODATE = assessment.DocumentDate.ToShortDateString();
                }
                header.CMMTTEXT = assessment.Comments;
                header.SUBTOTAL = assessment.Subtotal;
                header.TRDISAMT = assessment.TotalDiscounts;
                header.MISCAMNT = assessment.InstallmentFee;
                header.DOCAMNT = assessment.TotalAmount;
                header.USINGHEADERLEVELTAXES = 1;
                //header.DEFTAXSCHDS = 1;
                //header.UpdateExisting = 1;

                //add header

                salesOrder.taSopHdrIvcInsert = header;

                eConnectType eConnType = new eConnectType();
                Array.Resize(ref eConnType.SOPTransactionType, 1);
                eConnType.SOPTransactionType[0] = salesOrder;
                //serialization proper
                using (FileStream fs = new FileStream(filename, FileMode.Create))
                {
                    XmlTextWriter writer = new XmlTextWriter(fs, new UTF8Encoding());
                    XmlSerializer serializer = new XmlSerializer(eConnType.GetType());
                    serializer.Serialize(writer, eConnType);
                    writer.Close();
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
                throw ex;
            }
        }
        public static bool UpdateSaleTransactionEntry(string gpDatabase, string gpVendorID, ref int errorNumber, ref string errorMessage)
        {
            try
            {
                SOPTransactionType salesOrder = new SOPTransactionType();

                taSopLineIvcInsert_ItemsTaSopLineIvcInsert salesLine  = new taSopLineIvcInsert_ItemsTaSopLineIvcInsert();
                taSopLineIvcInsert_ItemsTaSopLineIvcInsert salesLine2 = new taSopLineIvcInsert_ItemsTaSopLineIvcInsert();
                taSopHdrIvcInsert salesHdr = new taSopHdrIvcInsert();

                taSopLineIvcInsert_ItemsTaSopLineIvcInsert[] LineItems = new taSopLineIvcInsert_ItemsTaSopLineIvcInsert[2];

                salesLine.CUSTNMBR = "AARONFIT0001";
                salesLine.SOPTYPE  = 2;
                salesLine.DOCID    = "STDORD";
                salesLine.QUANTITY = 2;
                salesLine.ITEMNMBR = "3-B3813A";
                salesLine.UNITPRCE = 100;
                salesLine.XTNDPRCE = 200;
                //salesLine.DOCDATE = System.DateTime.Today.ToString("MM/dd/yyyy");
                salesLine.DOCDATE        = "04/12/2027";
                salesLine.UpdateIfExists = 1;
                salesLine.SOPNUMBE       = "ORDST2236";

                salesLine2.CUSTNMBR = "AARONFIT0001";
                salesLine2.SOPTYPE  = 2;
                salesLine2.DOCID    = "STDORD";
                salesLine2.QUANTITY = 0;
                salesLine2.ITEMNMBR = "100XLG";
                salesLine2.UNITPRCE = (decimal)59.95;
                salesLine2.XTNDPRCE = (decimal)(0);
                //salesLine.DOCDATE = System.DateTime.Today.ToString("MM/dd/yyyy");
                salesLine2.DOCDATE        = "04/12/2027";
                salesLine2.UpdateIfExists = 1;
                salesLine2.SOPNUMBE       = "ORDST2236";


                LineItems[0] = salesLine;
                LineItems[1] = salesLine2;

                salesOrder.taSopLineIvcInsert_Items = LineItems;

                salesHdr.SOPTYPE  = 2;
                salesHdr.DOCID    = "STDORD";
                salesHdr.SOPNUMBE = "ORDST2236";
                salesHdr.BACHNUMB = "B1";
                //salesHdr.DOCDATE = System.DateTime.Today.ToString("MM/dd/yyyy");
                salesHdr.DOCDATE  = "04/12/2027";
                salesHdr.CUSTNMBR = "AARONFIT0001";
                salesHdr.SUBTOTAL = 200;
                salesHdr.DOCAMNT  = 200;
                salesHdr.USINGHEADERLEVELTAXES = 0;
                salesHdr.PYMTRMID       = "Net 30";
                salesHdr.MSTRNUMB       = 410;
                salesHdr.UpdateExisting = 1;

                salesOrder.taSopHdrIvcInsert = salesHdr;
                eConnectType         eConnect             = new eConnectType();
                SOPTransactionType[] MySopTransactionType = new SOPTransactionType[1] {
                    salesOrder
                };

                eConnect.SOPTransactionType = MySopTransactionType;

                // Serialize the master vendor type in memory.
                MemoryStream  memoryStream  = new MemoryStream();
                XmlSerializer xmlSerializer = new XmlSerializer(eConnect.GetType());


                // Serialize the eConnectType.
                xmlSerializer.Serialize(memoryStream, eConnect);

                // Reset the position of the memory stream to the start.
                memoryStream.Position = 0;

                // Create an XmlDocument from the serialized eConnectType in memory.
                XmlDocument xmlDocument = new XmlDocument();
                xmlDocument.Load(memoryStream);
                memoryStream.Close();

                string response = string.Empty;

                bool returnValue = UpdateEntity(ref response, xmlDocument.OuterXml, gpDatabase);

                if (returnValue == true)
                {
                    errorNumber  = 0;
                    errorMessage = string.Empty;
                    return(true);
                }
                else
                {
                    errorNumber  = 520;
                    errorMessage = "Failed to delete eConnect test Sale Transaction: " + response;
                    return(false);
                }
            }
            catch (Exception ex)
            {
                gpVendorID   = string.Empty;
                errorNumber  = 529;
                errorMessage = "An unexpected error occurred in CheckeConnect: " + ex.Message;
                return(false);
            }
        }
        public bool ImportSalesOrder(SalesOrderDto salesOrder, ref SalesOrderResponseDto orderResponse)
        {
            try
            {
                taSopHdrIvcInsert sopHeader;
                List <taSopLineIvcInsert_ItemsTaSopLineIvcInsert> sopLines = new List <taSopLineIvcInsert_ItemsTaSopLineIvcInsert>();
                taSopLineIvcInsert_ItemsTaSopLineIvcInsert        sopLine;

                bool   success      = false;
                string orderNumber  = salesOrder.SOPNUMBE;
                string customerID   = salesOrder.CUSTNMBR;
                int    errorCode    = 0;
                string errorMessage = string.Empty;

                sopHeader = new taSopHdrIvcInsert
                {
                    SOPTYPE    = salesOrder.SOPTYPE,
                    SOPNUMBE   = salesOrder.SOPNUMBE,
                    DOCID      = instance.APIModel.APIConfig.SOPTypeID,
                    SHIPMTHD   = salesOrder.SHIPMTHD,
                    TAXAMNT    = salesOrder.TAXAMNT,
                    LOCNCODE   = salesOrder.LOCNCODE,
                    DOCDATE    = salesOrder.DOCDATE.ToShortDateString(),
                    TRDISAMT   = salesOrder.TRDISAMT,
                    MRKDNAMT   = salesOrder.MRKDNAMT,
                    CUSTNMBR   = salesOrder.CUSTNMBR,
                    CUSTNAME   = salesOrder.CUSTNAME,
                    CSTPONBR   = salesOrder.CSTPONBR,
                    ShipToName = salesOrder.ShipToName,
                    ADDRESS1   = salesOrder.ADDRESS1,
                    ADDRESS2   = salesOrder.ADDRESS2,
                    ADDRESS3   = salesOrder.ADDRESS3,
                    CNTCPRSN   = salesOrder.CNTCPRSN,
                    FAXNUMBR   = salesOrder.FAXNUMBR,
                    CITY       = salesOrder.CITY,
                    STATE      = salesOrder.STATE,
                    ZIPCODE    = salesOrder.ZIPCODE,
                    COUNTRY    = salesOrder.COUNTRY,
                    PHNUMBR1   = salesOrder.PHNUMBR1,
                    PHNUMBR2   = salesOrder.PHNUMBR2,
                    PHNUMBR3   = salesOrder.PHNUMBR3,
                    SUBTOTAL   = salesOrder.SUBTOTAL,
                    FREIGHT    = salesOrder.FRTAMNT,
                    MISCAMNT   = salesOrder.MISCAMNT,
                    DOCAMNT    = salesOrder.DOCAMNT,
                    SALSTERR   = salesOrder.SALSTERR,
                    SLPRSNID   = salesOrder.SLPRSNID,
                    UPSZONE    = salesOrder.UPSZONE,
                    USER2ENT   = "GPWEBAPI",
                    BACHNUMB   = "WEBORDERS",

                    USINGHEADERLEVELTAXES = 1,
                    DEFTAXSCHDS           = 1
                };

                foreach (SalesOrderLineDto line in salesOrder.SalesOrderLines)
                {
                    sopLine = new taSopLineIvcInsert_ItemsTaSopLineIvcInsert
                    {
                        SOPTYPE  = sopHeader.SOPTYPE,
                        SOPNUMBE = sopHeader.SOPNUMBE,
                        CUSTNMBR = sopHeader.CUSTNMBR,
                        DOCDATE  = sopHeader.DOCDATE,
                        LOCNCODE = line.LOCNCODE,
                        ITEMNMBR = line.ITEMNMBR,
                        ITEMDESC = line.ITEMDESC,
                        UNITPRCE = line.UNITPRCE,
                        XTNDPRCE = line.XTNDPRCE,
                        QUANTITY = line.QUANTITY,

                        COMMNTID   = line.COMMNTID,
                        COMMENT_1  = line.COMMENT_1,
                        COMMENT_2  = line.COMMENT_2,
                        COMMENT_3  = line.COMMENT_3,
                        COMMENT_4  = line.COMMENT_4,
                        PRCLEVEL   = line.PRCLEVEL,
                        TAXAMNT    = line.TAXAMNT,
                        NONINVEN   = line.NONINVEN,
                        LNITMSEQ   = line.LNITMSEQ,
                        DROPSHIP   = line.DROPSHIP,
                        QTYTBAOR   = line.QTYTBAOR,
                        DOCID      = line.DOCID,
                        SALSTERR   = line.SALSTERR,
                        SLPRSNID   = line.SLPRSNID,
                        ITMTSHID   = line.ITMTSHID,
                        IVITMTXB   = line.IVITMTXB,
                        TAXSCHID   = line.TAXSCHID,
                        PRSTADCD   = line.PRSTADCD,
                        ShipToName = line.ShipToName,
                        CNTCPRSN   = line.CNTCPRSN,
                        ADDRESS1   = line.ADDRESS1,
                        ADDRESS2   = line.ADDRESS2,
                        ADDRESS3   = line.ADDRESS3,
                        CITY       = line.CITY,
                        STATE      = line.STATE,
                        ZIPCODE    = line.ZIPCODE,
                        COUNTRY    = line.COUNTRY,
                        PHONE1     = line.PHONE1,
                        PHONE2     = line.PHONE2,
                        PHONE3     = line.PHONE3,
                        FAXNUMBR   = line.FAXNUMBR,
                        QTYCANCE   = line.QTYCANCE,
                        QTYFULFI   = line.QTYFULFI,
                        ALLOCATE   = line.ALLOCATE,
                        TOTALQTY   = line.TOTALQTY,
                        CMMTTEXT   = line.CMMTTEXT,

                        //Quantity shortage option:
                        //1 = Sell balance;
                        //2 = Override shortage;
                        //3 = Back Order all;
                        //4 = Back Order balance;
                        //5 = Cancel all;
                        //6 = Cancel balance

                        QtyShrtOpt = instance.APIModel.APIConfig.QtyShortageOption,
                        UOFM       = line.UOFM
                    };
                    sopLines.Add(sopLine);
                }


                //**********************************************************************
                //Assemble document
                //**********************************************************************

                SOPTransactionType sopTransaction = new SOPTransactionType();
                sopTransaction.taSopHdrIvcInsert        = sopHeader;
                sopTransaction.taSopLineIvcInsert_Items = sopLines.ToArray();

                SOPTransactionType[] sopTransactionType = { sopTransaction };

                eConnectType eConnect = new eConnectType();
                eConnect.SOPTransactionType = sopTransactionType;

                MemoryStream  memStream  = new MemoryStream();
                XmlSerializer serializer = new XmlSerializer(eConnect.GetType());
                serializer.Serialize(memStream, eConnect);
                memStream.Position = 0;

                XmlDocument xmlDocument = new XmlDocument();
                xmlDocument.Load(memStream);
                memStream.Close();

                string response = string.Empty;
                success = eConn.InsertTransaction(ref response, xmlDocument.OuterXml, instance.APIModel.APIConfig.GPCompanyDB);

                if (success == false)
                {
                    errorMessage = "Failed to import order " + orderNumber + " for customer " + customerID + ": " + response;
                }

                orderResponse.Success      = success;
                orderResponse.OrderNumber  = orderNumber;
                orderResponse.ErrorCode    = errorCode;
                orderResponse.ErrorMessage = errorMessage;
                orderResponse.DocumentData = xmlDocument.OuterXml;

                return(success);
            }
            catch (Exception)
            {
                throw;
            }
        }
        private int CreateSalesOrderLine(DocumentLine docLine, bool isMerged)
        {
            string flag = "Data Definition";

            try
            {
                Command.Connection = new SqlConnection(CurCompany.ErpConnection.CnnString);

                //Create an object that holds XML node object
                taSopLineIvcInsert_ItemsTaSopLineIvcInsert curLine = new taSopLineIvcInsert_ItemsTaSopLineIvcInsert();


                string document = (isMerged) ? docLine.LinkDocNumber : docLine.Document.DocNumber;
                string note = docLine.Note == null ? "" : docLine.Note;

                curLine.SOPTYPE = GP_DocType.SO_Order;
                curLine.CUSTNMBR = docLine.Document.Customer.AccountCode;
                curLine.DOCDATE = ((DateTime)docLine.Document.Date1).ToString("yyyy-MM-dd");
                curLine.SOPNUMBE = document;

                flag = "Item Definition";
                curLine.ITEMDESC = string.IsNullOrEmpty(docLine.LineDescription) ? docLine.Product.Name : docLine.LineDescription;
                curLine.ITEMNMBR = docLine.Product.ProductCode;
                curLine.QUANTITY = (decimal)docLine.Quantity;                
                curLine.UOFM = docLine.Unit.ErpCode;

                curLine.QTYCANCE = (decimal)docLine.QtyCancel;
                curLine.QTYTBAOR = (decimal)docLine.QtyBackOrder;
                curLine.UpdateIfExists = 1;
                //curLine.LNITMSEQ = 0;
                curLine.CMMTTEXT = note;
                curLine.ALLOCATE = 0;
                curLine.LOCNCODE = docLine.Location.ErpCode;

                string docID = ReturnScalar("SELECT DOCID FROM SOP10100 WHERE SOPNUMBE='" + document + "' AND SOPTYPE=2", "", Command.Connection);
                curLine.DOCID = docID;
                

                string xGuid = Guid.NewGuid().ToString();
                curLine.CNTCPRSN = xGuid;

                flag = "eConnect Definition";

                taSopLineIvcInsert_ItemsTaSopLineIvcInsert[] erpLines =
                    new taSopLineIvcInsert_ItemsTaSopLineIvcInsert[] { curLine };


                //Create a SOPTransactionType schema object and populate its taSopLineIvcInsert_Items poperty
                SOPTransactionType salesOrder = new SOPTransactionType();
                salesOrder.taSopLineIvcInsert_Items = erpLines;


                //SALES ORDER HEADER

                //Create a taSopHdrIvcInsert XML node object
                taSopHdrIvcInsert salesHdr = new taSopHdrIvcInsert();

                //Populate the properties of the taSopHdrIvcInsert XML node object           

                salesHdr.SOPTYPE = 2;
                salesHdr.SOPNUMBE = document;
                salesHdr.DOCID = ReturnScalar("SELECT DOCID FROM SOP10100 WHERE SOPNUMBE='" + document + "' AND SOPTYPE=2", "", Command.Connection);
                salesHdr.BACHNUMB = ReturnScalar("SELECT BACHNUMB FROM SOP10100 WHERE SOPNUMBE='" + document + "' AND SOPTYPE=2", "", Command.Connection); // "B2BSO";
                salesHdr.LOCNCODE = docLine.Document.Location.ErpCode;
                salesHdr.DOCDATE = ((DateTime)docLine.Document.Date1).ToString("yyyy-MM-dd");
                salesHdr.UpdateExisting = 1;
                salesHdr.CUSTNMBR = docLine.Document.Customer.AccountCode;
                salesHdr.CSTPONBR = docLine.Document.CustPONumber;                

                salesOrder.taSopHdrIvcInsert = salesHdr;

                //SALES ORDER HEADER


                SOPTransactionType[] salesOrderArray = new SOPTransactionType[1];
                salesOrderArray[0] = salesOrder;

                //Create an eConnect XML document object and populate its SOPTransactionType property with
                //the SOPTransactionType schema object
                eConnectType eConnect = new eConnectType();
                eConnect.SOPTransactionType = salesOrderArray;

                //Serialize the XML document to the file
                XmlSerializer serializer = new XmlSerializer(typeof(eConnectType));
                StringWriter writer = new StringWriter();
                serializer.Serialize(writer, eConnect);

                DynamicsGP_ec.SendData(writer.ToString());

                //Obterne el line ID creado
                flag = "Line Number";

                string  newLine;
                newLine = ReturnScalar("SELECT MAX(LNITMSEQ) FROM SOP10200 WHERE SOPNUMBE='" + document + "' AND CNTCPRSN ='" + xGuid + "'", "", Command.Connection);
                return int.Parse(newLine);


            }
            catch (Exception ex)
            {
                throw new Exception(flag + ". " +WriteLog.GetTechMessage(ex));
            }

        }
        public String CreateSalesOrder(Document document, string docPrefix, string batch)
        {

            if (document.DocumentLines == null || document.DocumentLines.Count <= 0)
                throw new Exception("Sales order does not contains lines.");

            string SOPNumber;
            //string DocPrefix = "SWEB"; //ej: SWEB o como se deban crear las ordenes
            //string Batch = "BATCH"; //Numero de Batch de las ordenes a Crear

            try
            {

                taSopLineIvcInsert_ItemsTaSopLineIvcInsert[] salesLine = new taSopLineIvcInsert_ItemsTaSopLineIvcInsert[document.DocumentLines.Count];
                //Create an object that holds XML node object
                taSopLineIvcInsert_ItemsTaSopLineIvcInsert LineItem; // = new taSopLineIvcInsert_ItemsTaSopLineIvcInsert();
                int lineSeq = 0;
                Decimal subTotal = 0;

                // Next consecutive for a S.O.
                GetSopNumber mySopNumber = new GetSopNumber();
                SOPNumber = mySopNumber.GetNextSopNumber(2, docPrefix, CurCompany.ErpConnection.CnnString);


                Console.WriteLine("1");

                foreach (DocumentLine dl in document.DocumentLines)
                {
                    LineItem = new taSopLineIvcInsert_ItemsTaSopLineIvcInsert();

                    // Populate            
                    LineItem.CUSTNMBR = dl.Document.Customer.AccountCode;
                    LineItem.SOPNUMBE = SOPNumber;
                    LineItem.SOPTYPE = 2;
                    LineItem.DOCID = docPrefix;   // SWEB   STDORD
                    LineItem.ITEMNMBR = dl.Product.ProductCode;
                    LineItem.UOFM = dl.Unit.ErpCode;
                    LineItem.UNITPRCE = (decimal)dl.UnitPrice;
                    LineItem.XTNDPRCE = (decimal)dl.ExtendedPrice;
                    LineItem.LOCNCODE = document.Location.ErpCode;
                    LineItem.DOCDATE = DateTime.Now.ToShortDateString();
                    LineItem.PRCLEVEL = "STANDARD";

                    // quantities
                    LineItem.QUANTITY = (decimal)dl.Quantity;

                    salesLine[lineSeq++] = LineItem;
                    subTotal += (decimal)dl.ExtendedPrice;
                }


                //Create a SOPTransactionType schema object and populate its taSopLineIvcInsert_Items poperty
                SOPTransactionType salesOrder = new SOPTransactionType();
                salesOrder.taSopLineIvcInsert_Items = salesLine;

                //Create a taSopHdrIvcInsert XML node object
                taSopHdrIvcInsert salesHdr = new taSopHdrIvcInsert();

                //Populate the properties of the taSopHdrIvcInsert XML node object           

                salesHdr.SOPTYPE = 2;
                salesHdr.SOPNUMBE = SOPNumber;
                salesHdr.DOCID = docPrefix;
                salesHdr.BACHNUMB = batch; // "B2BSO";
                salesHdr.LOCNCODE = document.Location.ErpCode;
                salesHdr.DOCDATE = DateTime.Now.ToShortDateString();
                salesHdr.SUBTOTAL = subTotal;
                salesHdr.DOCAMNT = subTotal;
                
                salesHdr.CUSTNMBR = document.Customer.AccountCode;
                salesHdr.CUSTNAME = document.Customer.Name;

                //if (document.ErpMaster > 0)
                    //salesHdr.MSTRNUMB = document.ErpMaster;

                //BILLING
                try { salesHdr.PRBTADCD = document.Customer.AccountAddresses[0].ErpCode; }
                catch
                {
                    salesHdr.PRBTADCD = document.DocumentAddresses
                        .Where(f => f.AddressType == AddressType.Billing).First().ErpCode;
                }

                //SHIPPING
                try { salesHdr.PRSTADCD = document.Customer.AccountAddresses[0].ErpCode; }
                catch
                {
                    salesHdr.PRBTADCD = document.DocumentAddresses
                        .Where(f => f.AddressType == AddressType.Shipping).First().ErpCode;
                }

                salesHdr.CSTPONBR = document.CustPONumber;

                salesOrder.taSopHdrIvcInsert = salesHdr;

                SOPTransactionType[] salesOrderArray = new SOPTransactionType[1];
                salesOrderArray[0] = salesOrder;

                //Create an eConnect XML document object and populate its SOPTransactionType property with
                //the SOPTransactionType schema object
                eConnectType eConnect = new eConnectType();
                eConnect.SOPTransactionType = salesOrderArray;

                //Serialize the XML document to the file
                XmlSerializer serializer = new XmlSerializer(typeof(eConnectType));
                StringWriter writer = new StringWriter();
                serializer.Serialize(writer, eConnect);

                DynamicsGP_ec.SendData(writer.ToString());

                //mySopNumber.Dispose();

                return SOPNumber;

            }
            
            catch (Exception ex)
            {
                ExceptionMngr.WriteEvent("CreateSalesOrder", ListValues.EventType.Error, ex, null, ListValues.ErrorCategory.ErpConnection);
                throw;
            }
        }
Exemple #9
0
        private taSopLineIvcInsert_ItemsTaSopLineIvcInsert[] SetDetailValues(List <SOPDetail> detail, string InvoiceNumber)
        {
            try
            {
                var SopLine = new List <taSopLineIvcInsert_ItemsTaSopLineIvcInsert>();
                foreach (SOPDetail item in detail)
                {
                    var sopDetailInsert = new taSopLineIvcInsert_ItemsTaSopLineIvcInsert();
                    sopDetailInsert.SOPTYPE  = item.SOPTYPE;
                    sopDetailInsert.SOPNUMBE = InvoiceNumber;
                    sopDetailInsert.CUSTNMBR = item.CUSTNMBR;
                    //sopDetailInsert.DOCDATE = item.DOCDATE.ToString("dd/MM/yyyy");
                    sopDetailInsert.DOCDATE = item.DOCDATE.ToString("yyyy-MM-dd");
                    //sopDetailInsert.USERDATE = item.USERDATE.ToString("dd/MM/yyyy");
                    sopDetailInsert.USERDATE          = item.USERDATE.ToString("yyyy-MM-dd");
                    sopDetailInsert.LOCNCODE          = item.LOCNCODE;
                    sopDetailInsert.ITEMNMBR          = item.ITEMNMBR;
                    sopDetailInsert.AutoAssignBin     = item.AutoAssignBin.GetValueOrDefault();
                    sopDetailInsert.UNITPRCE          = item.UNITPRCE.GetValueOrDefault();
                    sopDetailInsert.XTNDPRCE          = item.XTNDPRCE.GetValueOrDefault();
                    sopDetailInsert.QUANTITY          = item.QUANTITY.GetValueOrDefault();
                    sopDetailInsert.MRKDNAMT          = item.MRKDNAMT.GetValueOrDefault();
                    sopDetailInsert.MRKDNPCT          = item.MRKDNPCT.GetValueOrDefault();
                    sopDetailInsert.COMMNTID          = item.COMMNTID;
                    sopDetailInsert.COMMENT_1         = item.COMMENT_1;
                    sopDetailInsert.COMMENT_2         = item.COMMENT_2;
                    sopDetailInsert.COMMENT_3         = item.COMMENT_3;
                    sopDetailInsert.COMMENT_4         = item.COMMENT_4;
                    sopDetailInsert.UNITCOST          = item.UNITCOST.GetValueOrDefault();
                    sopDetailInsert.PRCLEVEL          = item.PRCLEVEL;
                    sopDetailInsert.ITEMDESC          = item.ITEMDESC;
                    sopDetailInsert.TAXAMNT           = item.TAXAMNT.GetValueOrDefault();
                    sopDetailInsert.QTYONHND          = item.QTYONHND.GetValueOrDefault();
                    sopDetailInsert.QTYRTRND          = item.QTYRTRND.GetValueOrDefault();
                    sopDetailInsert.QTYINUSE          = item.QTYINUSE.GetValueOrDefault();
                    sopDetailInsert.QTYINSVC          = item.QTYINSVC.GetValueOrDefault();
                    sopDetailInsert.QTYDMGED          = item.QTYDMGED.GetValueOrDefault();
                    sopDetailInsert.NONINVEN          = item.NONINVEN.GetValueOrDefault();
                    sopDetailInsert.LNITMSEQ          = item.LNITMSEQ.GetValueOrDefault();
                    sopDetailInsert.DROPSHIP          = item.DROPSHIP.GetValueOrDefault();
                    sopDetailInsert.QTYTBAOR          = item.QTYTBAOR.GetValueOrDefault();
                    sopDetailInsert.DOCID             = item.DOCID;
                    sopDetailInsert.SALSTERR          = item.SALSTERR;
                    sopDetailInsert.SLPRSNID          = item.SLPRSNID;
                    sopDetailInsert.ITMTSHID          = item.ITMTSHID;
                    sopDetailInsert.IVITMTXB          = item.IVITMTXB.GetValueOrDefault();
                    sopDetailInsert.TAXSCHID          = item.TAXSCHID;
                    sopDetailInsert.PRSTADCD          = item.PRSTADCD;
                    sopDetailInsert.ShipToName        = item.ShipToName;
                    sopDetailInsert.CNTCPRSN          = item.CNTCPRSN;
                    sopDetailInsert.ADDRESS1          = item.ADDRESS1;
                    sopDetailInsert.ADDRESS2          = item.ADDRESS2;
                    sopDetailInsert.ADDRESS3          = item.ADDRESS3;
                    sopDetailInsert.CITY              = item.CITY;
                    sopDetailInsert.STATE             = item.STATE;
                    sopDetailInsert.ZIPCODE           = item.ZIPCODE;
                    sopDetailInsert.COUNTRY           = item.COUNTRY;
                    sopDetailInsert.PHONE1            = item.PHONE1;
                    sopDetailInsert.PHONE2            = item.PHONE2;
                    sopDetailInsert.PHONE3            = item.PHONE3;
                    sopDetailInsert.FAXNUMBR          = item.FAXNUMBR;
                    sopDetailInsert.EXCEPTIONALDEMAND = item.EXCEPTIONALDEMAND.GetValueOrDefault();

                    if (item.ReqShipDate != null)
                    {
                        sopDetailInsert.ReqShipDate = item.ReqShipDate.GetValueOrDefault().ToString("yyyy-MM-dd");
                    }
                    if (item.FUFILDAT != null)
                    {
                        sopDetailInsert.FUFILDAT = item.FUFILDAT.GetValueOrDefault().ToString("yyyy-MM-dd");
                    }
                    if (item.ACTLSHIP != null)
                    {
                        sopDetailInsert.ACTLSHIP = item.ACTLSHIP.GetValueOrDefault().ToString("yyyy-MM-dd");
                    }

                    sopDetailInsert.SHIPMTHD           = item.SHIPMTHD;
                    sopDetailInsert.INVINDX            = item.INVINDX;
                    sopDetailInsert.CSLSINDX           = item.CSLSINDX;
                    sopDetailInsert.SLSINDX            = item.SLSINDX;
                    sopDetailInsert.MKDNINDX           = item.MKDNINDX;
                    sopDetailInsert.RTNSINDX           = item.RTNSINDX;
                    sopDetailInsert.INUSINDX           = item.INUSINDX;
                    sopDetailInsert.INSRINDX           = item.INSRINDX;
                    sopDetailInsert.DMGDINDX           = item.DMGDINDX;
                    sopDetailInsert.AUTOALLOCATESERIAL = item.AUTOALLOCATESERIAL.GetValueOrDefault();
                    sopDetailInsert.AUTOALLOCATELOT    = item.AUTOALLOCATELOT.GetValueOrDefault();
                    sopDetailInsert.GPSFOINTEGRATIONID = item.GPSFOINTEGRATIONID;
                    sopDetailInsert.INTEGRATIONSOURCE  = item.INTEGRATIONSOURCE.GetValueOrDefault();
                    sopDetailInsert.INTEGRATIONID      = item.INTEGRATIONID;
                    sopDetailInsert.RequesterTrx       = item.RequesterTrx.GetValueOrDefault();
                    sopDetailInsert.QTYCANCE           = item.QTYCANCE.GetValueOrDefault();
                    sopDetailInsert.QTYFULFI           = item.QTYFULFI.GetValueOrDefault();
                    sopDetailInsert.ALLOCATE           = item.ALLOCATE.GetValueOrDefault();
                    sopDetailInsert.UpdateIfExists     = item.UpdateIfExists.GetValueOrDefault();
                    sopDetailInsert.RecreateDist       = item.RecreateDist.GetValueOrDefault();
                    sopDetailInsert.QUOTEQTYTOINV      = item.QUOTEQTYTOINV.GetValueOrDefault();
                    sopDetailInsert.TOTALQTY           = item.TOTALQTY.GetValueOrDefault();
                    sopDetailInsert.CMMTTEXT           = item.CMMTTEXT;
                    sopDetailInsert.KitCompMan         = item.KitCompMan.GetValueOrDefault();
                    sopDetailInsert.DEFPRICING         = item.DEFPRICING.GetValueOrDefault();
                    sopDetailInsert.DEFEXTPRICE        = item.DEFEXTPRICE.GetValueOrDefault();
                    sopDetailInsert.CURNCYID           = item.CURNCYID;
                    sopDetailInsert.UOFM                          = item.UOFM;
                    sopDetailInsert.IncludePromo                  = item.IncludePromo.GetValueOrDefault();
                    sopDetailInsert.CKCreditLimit                 = item.CKCreditLimit.GetValueOrDefault();
                    sopDetailInsert.QtyShrtOpt                    = item.QtyShrtOpt.GetValueOrDefault();
                    sopDetailInsert.Print_Phone_NumberGB          = 0;
                    sopDetailInsert.Print_Phone_NumberGBSpecified = true;// item.Print_Phone_NumberGB.GetValueOrDefault();

                    SopLine.Add(sopDetailInsert);
                }


                return(SopLine.ToArray());
            }
            catch (Exception)
            {
                throw;
            }
        }