/// <summary> /// Revisa las prefacturas a integrar desde la base de datos. /// Posibles transiciones: ENVIAR_A_GP /// </summary> /// <param name="docStatus"></param> /// <param name="transicion"></param> public void ProcesaBandejaDB(string docStatus, string transicion) { try { var pfi = getPrefacturasAIntegrar(docStatus); int iFacturasIntegradas = 0; string sTimeStamp = System.DateTime.Now.ToString("yyMMddHHmmssfff"); foreach (var item in pfi) { try { var proximoStatus = getSiguienteStatus(item.TIPODOCARN, item.NUMDOCARN, transicion).First(); if (proximoStatus.transicionFactible == 1) { var precondiciones = getPreCondiciones(3, string.Empty, item.TIPODOCARN, item.NUMDOCARN, transicion); if (precondiciones.Where(x => x.cumplePreCondiciones == 1).Count() == precondiciones.Count()) { taSopHdrIvcInsert sopDoc = this.IntegraFacturaSOP(item, sTimeStamp); iFacturasIntegradas++; string idLog = IngresaLogFactura(item, sopDoc.SOPTYPE, sopDoc.SOPNUMBE, transicion, "OK", string.Empty); OnProgreso(100 / pfi.Count, string.Concat("Pre factura: ", item.NUMDOCARN, " -> Factura GP: ", sopDoc.SOPNUMBE, " Log:", idLog)); } else { OnProgreso(100 / pfi.Count, string.Concat("Pre factura: ", item.NUMDOCARN, " -> El documento continúa ", docStatus, " ", precondiciones.Where(x => x.cumplePreCondiciones == 0).First().msjPreCondiciones)); } } else { OnProgreso(100 / pfi.Count, string.Concat("Pre factura: ", item.NUMDOCARN, " -> El documento continúa ", docStatus, " ", proximoStatus.mensaje)); } } catch (eConnectException ec) { OnProgreso(100 / pfi.Count, string.Concat("Pre factura: ", item.NUMDOCARN, " eConnect no pudo integrar el documento a GP. Verifique el mensaje de error. " + ec.Message, Environment.NewLine, ec?.InnerException?.Message)); } catch (SqlException se) { OnProgreso(100 / pfi.Count, string.Concat("Pre factura: ", item.NUMDOCARN, " Excepción al ingresar el log. " + se.Message, Environment.NewLine, se?.InnerException?.Message)); } catch (Exception ee) { //IngresaLogFactura(item, transicion, "No se pudo integrar la pre factura. Revise el mensaje de error.", string.Concat(ee.Message, Environment.NewLine, ee?.InnerException?.Message)); OnProgreso(100 / pfi.Count, string.Concat("Pre factura: ", item.NUMDOCARN, " Excepción desconocida. No se pudo integrar el documento a GP. " + ee.Message, Environment.NewLine, ee?.InnerException?.Message)); } } OnProgreso(100, "----------------------------------------------"); OnProgreso(100, "Nuevos documentos integrados: " + iFacturasIntegradas.ToString()); OnProgreso(100, "Número de documentos con error: " + (pfi.Count - iFacturasIntegradas).ToString()); OnProgreso(100, "Total de documentos leídos: " + pfi.Count.ToString()); } catch (Exception errorGral) { OnProgreso(0, string.Concat("Excepción al procesar la bandeja de la bd de Integraciones. " + errorGral.Message + Environment.NewLine + errorGral?.InnerException?.Message)); } }
public FacturaDeVentaSOPBandejaDB(IParametrosDB paramDB) { //Stream outputFile = File.Create(paramDB.RutaLog+@"\traceInterfazGP.txt"); //textListener = new TextWriterTraceListener(outputFile); //trace = new TraceSource("trSource", SourceLevels.All); //trace.Listeners.Clear(); //trace.Listeners.Add(textListener); //trace.TraceInformation("integra factura sop"); parametrosDB = paramDB; facturaSopCa = new taSopHdrIvcInsert(); facturaSop = new SOPTransactionType(); }
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(); }
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; } }
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; } }
private taSopHdrIvcInsert SetHeaderValues(SOPHeader header, string invoicenumber) { try { var sopHeaderInsert = new taSopHdrIvcInsert(); sopHeaderInsert.SOPTYPE = header.SOPTYPE; sopHeaderInsert.DOCID = header.DOCID; //sopHeaderInsert.DOCDATE = header.DOCDATE.ToString("dd/MM/yyyy"); sopHeaderInsert.DOCDATE = header.DOCDATE.ToString("yyyy-MM-dd"); sopHeaderInsert.SOPNUMBE = invoicenumber; sopHeaderInsert.ORIGNUMB = header.ORIGNUMB; sopHeaderInsert.ORIGTYPE = header.ORIGTYPE.GetValueOrDefault(); sopHeaderInsert.TAXSCHID = header.TAXSCHID; sopHeaderInsert.FRTSCHID = header.FRTSCHID; sopHeaderInsert.MSCSCHID = header.MSCSCHID; sopHeaderInsert.SHIPMTHD = header.SHIPMTHD; sopHeaderInsert.TAXAMNT = header.TAXAMNT.GetValueOrDefault(); sopHeaderInsert.LOCNCODE = header.LOCNCODE; sopHeaderInsert.FREIGHT = header.FREIGHT.GetValueOrDefault(); sopHeaderInsert.MISCAMNT = header.MISCAMNT.GetValueOrDefault(); sopHeaderInsert.TRDISAMT = header.TRDISAMT.GetValueOrDefault(); sopHeaderInsert.TRADEPCT = header.TRADEPCT.GetValueOrDefault(); sopHeaderInsert.DISTKNAM = header.DISTKNAM.GetValueOrDefault(); sopHeaderInsert.MRKDNAMT = header.MRKDNAMT.GetValueOrDefault(); sopHeaderInsert.CUSTNAME = header.CSTPONBR; sopHeaderInsert.ShipToName = header.ShipToName; sopHeaderInsert.ADDRESS1 = header.ADDRESS1; sopHeaderInsert.ADDRESS2 = header.ADDRESS2; sopHeaderInsert.ADDRESS3 = header.ADDRESS3; sopHeaderInsert.CNTCPRSN = header.CNTCPRSN; sopHeaderInsert.FAXNUMBR = header.FAXNUMBR; sopHeaderInsert.CITY = header.CITY; sopHeaderInsert.STATE = header.STATE; sopHeaderInsert.ZIPCODE = header.ZIPCODE; sopHeaderInsert.COUNTRY = header.COUNTRY; sopHeaderInsert.PHNUMBR1 = header.PHNUMBR1; sopHeaderInsert.PHNUMBR2 = header.PHNUMBR2; sopHeaderInsert.PHNUMBR3 = header.PHNUMBR3; sopHeaderInsert.Print_Phone_NumberGB = 0; sopHeaderInsert.Print_Phone_NumberGBSpecified = true; sopHeaderInsert.SUBTOTAL = header.SUBTOTAL.GetValueOrDefault(); sopHeaderInsert.DOCAMNT = header.DOCAMNT.GetValueOrDefault(); sopHeaderInsert.PYMTRCVD = header.PYMTRCVD.GetValueOrDefault(); sopHeaderInsert.SALSTERR = header.SALSTERR; sopHeaderInsert.SLPRSNID = header.SLPRSNID; sopHeaderInsert.UPSZONE = header.UPSZONE; sopHeaderInsert.USER2ENT = header.USER2ENT; sopHeaderInsert.BACHNUMB = header.BACHNUMB; sopHeaderInsert.PRBTADCD = header.PRBTADCD; sopHeaderInsert.PRSTADCD = header.PRSTADCD; sopHeaderInsert.FRTTXAMT = header.FRTTXAMT.GetValueOrDefault(); sopHeaderInsert.MSCTXAMT = header.MSCTXAMT.GetValueOrDefault(); if (header.ORDRDATE != null) { sopHeaderInsert.ORDRDATE = header.ORDRDATE.GetValueOrDefault().ToString("yyyy-MM-dd"); } sopHeaderInsert.MSTRNUMB = header.MSTRNUMB.GetValueOrDefault(); sopHeaderInsert.PYMTRMID = header.PYMTRMID; if (header.DUEDATE != null) { sopHeaderInsert.DUEDATE = header.DUEDATE.GetValueOrDefault().ToString("yyyy-MM-dd"); } if (header.DISCDATE != null) { sopHeaderInsert.DISCDATE = header.DISCDATE.GetValueOrDefault().ToString("yyyy-MM-dd"); } sopHeaderInsert.REFRENCE = header.REFRENCE; sopHeaderInsert.USINGHEADERLEVELTAXES = header.USINGHEADERLEVELTAXES.GetValueOrDefault(); sopHeaderInsert.BatchCHEKBKID = header.BatchCHEKBKID; sopHeaderInsert.CREATECOMM = header.CREATECOMM.GetValueOrDefault(); sopHeaderInsert.COMMAMNT = header.COMMAMNT; sopHeaderInsert.COMPRCNT = header.COMPRCNT; sopHeaderInsert.CREATEDIST = header.CREATEDIST.GetValueOrDefault(); sopHeaderInsert.CREATETAXES = header.CREATETAXES.GetValueOrDefault(); sopHeaderInsert.DEFTAXSCHDS = header.DEFTAXSCHDS.GetValueOrDefault(); sopHeaderInsert.CURNCYID = header.CURNCYID; sopHeaderInsert.XCHGRATE = header.XCHGRATE.GetValueOrDefault(); sopHeaderInsert.RATETPID = header.RATETPID; if (header.EXPNDATE != null) { sopHeaderInsert.EXPNDATE = header.EXPNDATE.GetValueOrDefault().ToString("yyyy-MM-dd"); } if (header.EXCHDATE != null) { sopHeaderInsert.EXCHDATE = header.EXCHDATE.GetValueOrDefault().ToString("yyyy-MM-dd"); } sopHeaderInsert.EXGTBDSC = header.EXGTBDSC; sopHeaderInsert.EXTBLSRC = header.EXTBLSRC; sopHeaderInsert.RATEEXPR = header.RATEEXPR.GetValueOrDefault(); sopHeaderInsert.DYSTINCR = header.DYSTINCR.GetValueOrDefault(); sopHeaderInsert.RATEVARC = header.RATEVARC.GetValueOrDefault(); sopHeaderInsert.TRXDTDEF = header.TRXDTDEF.GetValueOrDefault(); sopHeaderInsert.RTCLCMTD = header.RTCLCMTD.GetValueOrDefault(); sopHeaderInsert.PRVDSLMT = header.PRVDSLMT.GetValueOrDefault(); sopHeaderInsert.DATELMTS = header.DATELMTS.GetValueOrDefault(); if (header.TIME1 != null) { sopHeaderInsert.TIME1 = header.TIME1.GetValueOrDefault().ToString("yyyy-MM-dd"); } sopHeaderInsert.DISAVAMT = header.DISAVAMT.GetValueOrDefault(); sopHeaderInsert.DSCDLRAM = header.DSCDLRAM.GetValueOrDefault(); sopHeaderInsert.DSCPCTAM = header.DSCPCTAM.GetValueOrDefault(); sopHeaderInsert.FREIGTBLE = header.FREIGTBLE.GetValueOrDefault(); sopHeaderInsert.MISCTBLE = header.MISCTBLE.GetValueOrDefault(); sopHeaderInsert.COMMNTID = header.COMMNTID; sopHeaderInsert.COMMENT_1 = header.COMMENT_1; sopHeaderInsert.COMMENT_2 = header.COMMENT_2; sopHeaderInsert.COMMENT_3 = header.COMMENT_3; sopHeaderInsert.COMMENT_4 = header.COMMENT_4; sopHeaderInsert.GPSFOINTEGRATIONID = header.GPSFOINTEGRATIONID; sopHeaderInsert.INTEGRATIONSOURCE = header.INTEGRATIONSOURCE.GetValueOrDefault(); sopHeaderInsert.INTEGRATIONID = header.INTEGRATIONID; if (header.ReqShipDate != null) { sopHeaderInsert.ReqShipDate = header.ReqShipDate.GetValueOrDefault().ToString("yyyy-MM-dd"); } sopHeaderInsert.RequesterTrx = header.RequesterTrx.GetValueOrDefault(); sopHeaderInsert.CKCreditLimit = header.CKCreditLimit.GetValueOrDefault(); sopHeaderInsert.CKHOLD = header.CKHOLD.GetValueOrDefault(); sopHeaderInsert.UpdateExisting = header.UpdateExisting.GetValueOrDefault(); if (header.QUOEXPDA != null) { sopHeaderInsert.QUOEXPDA = header.QUOEXPDA.GetValueOrDefault().ToShortDateString(); } if (header.QUOTEDAT != null) { sopHeaderInsert.QUOTEDAT = header.QUOTEDAT.GetValueOrDefault().ToShortDateString(); } if (header.INVODATE != null) { sopHeaderInsert.INVODATE = header.INVODATE.GetValueOrDefault().ToShortDateString(); } if (header.BACKDATE != null) { sopHeaderInsert.BACKDATE = header.BACKDATE.GetValueOrDefault().ToShortDateString(); } if (header.RETUDATE != null) { sopHeaderInsert.RETUDATE = header.RETUDATE.GetValueOrDefault().ToShortDateString(); } sopHeaderInsert.CMMTTEXT = header.CMMTTEXT; sopHeaderInsert.PRCLEVEL = header.PRCLEVEL; sopHeaderInsert.DEFPRICING = header.DEFPRICING.GetValueOrDefault(); sopHeaderInsert.TAXEXMT1 = header.TAXEXMT1; sopHeaderInsert.TAXEXMT2 = header.TAXEXMT2; sopHeaderInsert.TXRGNNUM = header.TXRGNNUM; sopHeaderInsert.REPTING = header.REPTING.GetValueOrDefault(); sopHeaderInsert.TRXFREQU = header.TRXFREQU.GetValueOrDefault(); sopHeaderInsert.TIMETREP = header.TIMETREP.GetValueOrDefault(); sopHeaderInsert.QUOTEDYSTINCR = header.QUOTEDYSTINCR.GetValueOrDefault(); sopHeaderInsert.NOTETEXT = header.NOTETEXT; sopHeaderInsert.CUSTNMBR = header.CUSTNMBR; return(sopHeaderInsert); } catch (Exception) { throw; } }