// Use the button's click event to retrieve the next available document // numbers for Microsoft Dynamics GP documents. private void btnGetNextNumber_Click(object sender, System.EventArgs e) { try { // Instantiate a GetNextDocNumbers object GetNextDocNumbers myDocNumbers = new GetNextDocNumbers(); // Instantiate a GetSopNumber object GetSopNumber mySopNumber = new GetSopNumber(); // Create a string that specifies the Microsoft Dynamics GP server and database // The server name and database will use the values supplied by the user through the UI textboxes. string connString = string.Empty; connString = "data source=" + txtSqlServer.Text + ";" + "initial catalog=" + txtDataBase.Text + ";" + "Integrated Security=SSPI;"; // Use the GetNextSopNumber method of the GetSopNumber object to retrieve the next // number for a Microsoft Dynamics GP invoice document lblSOPNUMBER.Text = mySopNumber.GetNextSopNumber(3, "STDINV", connString); // Use each method of the GetNextDocNumber object to retrieve the next document number // for the available Microsoft Dynamics GP document types lblPMNUMBER.Text = myDocNumbers.GetNextPMPaymentNumber(GetNextDocNumbers.IncrementDecrement.Increment, connString); lblSOPPAYMENT.Text = myDocNumbers.GetNextRMNumber(GetNextDocNumbers.IncrementDecrement.Increment, GetNextDocNumbers.RMPaymentType.RMPayments, connString); lblIVDOCNUMBER.Text = myDocNumbers.GetNextIVNumber(GetNextDocNumbers.IncrementDecrement.Increment, GetNextDocNumbers.IVDocType.IVAdjustment, connString); lblPONUMBER.Text = myDocNumbers.GetNextPONumber(GetNextDocNumbers.IncrementDecrement.Increment, connString); } catch (Exception ex) { // If an error occurs, diplay the error information to the user MessageBox.Show(ex.ToString()); } }
/// <summary> /// Create RM transaction /// <param name="transaction">Header of RM transaction</param> /// <param name="Distribution">Distribution Account of RM Transaction</param> /// <param name="Taxes">Taxes of RM transaction</param> /// <param name="company">COMPANY SHORT NAME</param> /// <returns>Response Class</returns> /// </summary> // Log4NetMR.classClsRegistrarLog logW = new Log4NetMR.classClsRegistrarLog(); public Response TransactionCreate(RMTransactionHeader transaction, RMTransactionDist[] Distribution, RMDocumentTaxes[] Taxes, string company) { Response response; string server = ConfigKey.ReadSetting("SERVER"); string transactionXML = string.Empty; string CNX = "data source=" + server + ";initial catalog=" + company + ";integrated security=SSPI;persist security info=False;packet size=4096"; var eConnect = new eConnectRequest(); RMTransactionType rmTranType = new RMTransactionType(); var getnext = new GetNextDocNumbers(); getnext.RequireServiceProxy = false; try { string DOCNUMBR = string.Empty; if (string.IsNullOrEmpty(transaction.DOCNUMBR)) { DOCNUMBR = getnext.GetNextRMNumber(IncrementDecrement.Increment, RMPaymentType.RMCreditMemo, CNX); } else { DOCNUMBR = transaction.DOCNUMBR; } rmTranType.taRMTransaction = SetTransactionValues(transaction, DOCNUMBR); if (transaction.CREATEDIST == 0) { rmTranType.taRMDistribution_Items = SetDistributionValues(Distribution, DOCNUMBR); } if (transaction.CreateTaxes == 1) { rmTranType.taRMTransactionTaxInsert_Items = SetTaxValues(Taxes, DOCNUMBR); } transactionXML = SerializeRMTransaction(rmTranType); response = eConnect.CreateGPTransaction(CNX, transactionXML); return(response); } catch (Exception ex) { //logW.LogExeption("Econnect", 2, ex); response = new Response(); response.SUCCESS = false; response.MESSAGE = ex.Message; response.STACK = ex.StackTrace; return(response); } finally { getnext.Dispose(); } }
public Response TransactionCreate(GLTrasactionHeader Header, GLTransactionDetail[] Detail, string company) { Response response; string transactionXML = string.Empty; //var server = Properties.Settings.Default.SERVER.ToString(); string server = ConfigKey.ReadSetting("SERVER"); string CNX = "data source=" + server + ";initial catalog=" + company + ";integrated security=SSPI;persist security info=True;packet size=4096"; //string CNX = "data source=stsv-qa15;initial catalog=ELSIN;integrated security=SSPI;persist security info=True;packet size=4096"; var eConnect = new eConnectRequest(); GLTransactionType GLTranType = new GLTransactionType(); var getnext = new GetNextDocNumbers(); //getnext.RequireServiceProxy = false; try { int jrnEntry = Convert.ToInt32(getnext.GetNextGLJournalEntryNumber(IncrementDecrement.Increment, CNX)); GLTranType.taGLTransactionHeaderInsert = SetTransactionValues(Header, jrnEntry); GLTranType.taGLTransactionLineInsert_Items = SetDetailValues(Detail, jrnEntry); transactionXML = SerializeGLTransacion(GLTranType); response = eConnect.CreateGPTransaction(CNX, transactionXML); return(response); } catch (eConnectException ex) { response = new Response(); response.SUCCESS = false; response.MESSAGE = ex.Message; response.STACK = ex.StackTrace; if (ex.InnerException != null) { response.STACK += ex.InnerException.Message; } return(response); } catch (Exception ex) { response = new Response(); response.SUCCESS = false; response.MESSAGE = ex.Message; response.STACK = ex.StackTrace; if (ex.InnerException != null) { response.STACK += ex.InnerException.Message; } return(response); } finally { //getnext.Dispose(); } }
/// <summary> /// Create PM transaction /// </summary> /// <param name="transaction">Header of PM transaction</param> /// <param name="Distribution">Distribution Account of PM Transaction</param> /// <param name="Taxes">Taxes of PM transaction</param> /// <param name="company">COMPANY SHORT NAME</param> /// <returns>Response Class</returns> public Response TransactionCreate(PMTransactionHeader transaction, PMTransactionDist[] Distribution, PMTransactionTax[] Taxes, string company) { Response response; string server = ConfigKey.ReadSetting("SERVER"); string transactionXML = string.Empty; //var server = Properties.Settings.Default.SERVER.ToString(); string CNX = "data source=" + server + ";initial catalog=" + company + ";integrated security=SSPI;persist security info=False;packet size=4096"; var eConnect = new eConnectRequest(); PMTransactionType pmTranType = new PMTransactionType(); var getnext = new GetNextDocNumbers(); getnext.RequireServiceProxy = false; try { string VCHRNUMBER = getnext.GetPMNextVoucherNumber(IncrementDecrement.Increment, CNX); pmTranType.taPMTransactionInsert = SetTransactionValues(transaction, VCHRNUMBER); if (transaction.CREATEDIST == 0) { pmTranType.taPMDistribution_Items = SetDistributionValues(Distribution, VCHRNUMBER); } if (transaction.CreateTaxes == 1) { pmTranType.taPMTransactionTaxInsert_Items = SetTaxValues(Taxes, VCHRNUMBER); } transactionXML = SerializePMTransaction(pmTranType); response = eConnect.CreateGPTransaction(CNX, transactionXML); return(response); } catch (Exception ex) { response = new Response(); response.SUCCESS = false; response.MESSAGE = ex.Message; response.STACK = ex.StackTrace; //+ " Inner Exception: " + ex.InnerException.Message; return(response); } finally { getnext.Dispose(); } }
public static string eConnectGetNextSOPReturnNumbe(string DOCID, string con) { string res = ""; GetNextDocNumbers NextDocNumberObject = new GetNextDocNumbers(); try { res = NextDocNumberObject.GetNextSOPNumber(GetNextDocNumbers.IncrementDecrement.Increment, DOCID, GetNextDocNumbers.SopType.SOPReturn, con); } catch (Exception ex) { IEvent e = new ErrorEvent("", "", ex.Message); e.Publish(); res = ex.Message; } return(res); }
/// <summary> /// /// </summary> /// <param name="Cashreceipt"></param> /// <param name="Distribution"></param> /// <param name="company"></param> /// <returns></returns> public Response CashReceiptCreate(RMCashReceipt Cashreceipt, RMTransactionDist[] Distribution, string company) { Response response; string server = ConfigKey.ReadSetting("SERVER"); string transactionXML = string.Empty; string CNX = "data source=" + server + ";initial catalog=" + company + ";integrated security=SSPI;persist security info=False;packet size=4096"; var eConnect = new eConnectRequest(); RMCashReceiptsType rmcashreceipttype = new RMCashReceiptsType(); var getnext = new GetNextDocNumbers(); getnext.RequireServiceProxy = false; try { string DOCNUMBR = string.Empty; DOCNUMBR = getnext.GetNextRMNumber(IncrementDecrement.Increment, RMPaymentType.RMPayments, CNX); rmcashreceipttype.taRMCashReceiptInsert = SetReceiptValues(Cashreceipt, DOCNUMBR); if (Cashreceipt.CREATEDIST == 0) { rmcashreceipttype.taRMDistribution_Items = SetPaymentDistributionValues(Distribution, DOCNUMBR); } transactionXML = SerializeRMCashReceipts(rmcashreceipttype); response = eConnect.CreateGPTransaction(CNX, transactionXML); response.DOCUMENT = DOCNUMBR.Trim(); return(response); } catch (Exception ex) { response = new Response(); response.SUCCESS = false; response.MESSAGE = ex.Message; response.STACK = ex.StackTrace; return(response); } finally { getnext.Dispose(); } }
public Response TransactionCreate(SOPHeader header, List <SOPDetail> detail, List <SOPDistribution> distribution, List <SOPTax> taxes, List <SOPCommissions> commissions, SopType soptype, string company) { Response response; string server = ConfigKey.ReadSetting("SERVER"); string transactionXML = string.Empty; //var server = Properties.Settings.Default.SERVER.ToString(); string CNX = "data source=" + server + ";initial catalog=" + company + ";integrated security=SSPI;persist security info=False;packet size=4096"; var eConnect = new eConnectRequest(); SOPTransactionType sopTranType = new SOPTransactionType(); var getnext = new GetNextDocNumbers(); getnext.RequireServiceProxy = false; string INVOICENUMBER; try { if (header.SOPNUMBE == string.Empty) { INVOICENUMBER = getnext.GetNextSOPNumber(IncrementDecrement.Increment, header.DOCID, soptype, CNX); } else { INVOICENUMBER = header.SOPNUMBE; } sopTranType.taSopHdrIvcInsert = SetHeaderValues(header, INVOICENUMBER); sopTranType.taSopLineIvcInsert_Items = SetDetailValues(detail, INVOICENUMBER); sopTranType.taSopDistribution_Items = SetDistributionValues(distribution, INVOICENUMBER); sopTranType.taSopLineIvcTaxInsert_Items = SetTaxValues(taxes, INVOICENUMBER); sopTranType.taSopCommissions_Items = SetCommissionValues(commissions, INVOICENUMBER); transactionXML = SerializeSOPTransaction(sopTranType); response = eConnect.CreateGPTransaction(CNX, transactionXML); return(response); } catch (Exception) { throw; } }
public string getNum(int metodo) { GetNextDocNumbers myDocNumbers = new GetNextDocNumbers(); GetSopNumber mySopNumber = new GetSopNumber(); //n.Add(mySopNumber.GetNextSopNumber(3, "STDINV", connString)); // Use each method of the GetNextDocNumber object to retrieve the next document number // for the available Microsoft Dynamics GP document types if (metodo == 1) { return(myDocNumbers.GetPMNextVoucherNumber(GetNextDocNumbers.IncrementDecrement.Increment, connectionString)); } else if (metodo == 2) { return(myDocNumbers.GetNextPOPReceiptNumber(GetNextDocNumbers.IncrementDecrement.Increment, connectionString)); } else { return(null); } }
public static string NextSopDocumentNumber(string salesDocID) { GetNextDocNumbers sopTransNumber = new GetNextDocNumbers(); string nextTransactionNumber = string.Empty; string sConnectionString = ""; try { StringBuilder sb = new StringBuilder(); sb.Append("<eConnect xmlns:dt=\"urn: schemas - microsoft - com:datatypes\">"); sb.Append("<RMCustomerMasterType>"); sb.Append("<eConnectProcessInfo>"); sb.Append("</eConnectProcessInfo>"); sb.Append("<taUpdateCreateCustomerRcd>"); sb.Append("<CUSTNMBR>JEFF0002</CUSTNMBR>"); sb.Append("<CUSTNAME>JL Lawn Care Service</CUSTNAME>"); sb.Append("<STMTNAME>JL Lawn Care Service </STMTNAME>"); sb.Append("<SHRTNAME>JL Lawn Care</SHRTNAME>"); sb.Append("<ADRSCODE>PRIMARY </ADRSCODE>"); sb.Append("<ADDRESS1>123 Main Street</ADDRESS1>"); sb.Append("<CITY>Valley City </CITY>"); sb.Append("<STATE>ND </STATE>"); sb.Append("<ZIPCODE>58072 </ZIPCODE>"); sb.Append("<COUNTRY>USA </COUNTRY>"); sb.Append("<PHNUMBR1>55532336790000 </PHNUMBR1>"); sb.Append("<PHNUMBR2>55551161817181 </PHNUMBR2>"); sb.Append("<FAX>55584881000000 </FAX>"); sb.Append("<UPSZONE>red </UPSZONE>"); sb.Append("<SHIPMTHD>PICKUP </SHIPMTHD>"); sb.Append("<TAXSCHID>ILLINOIS</TAXSCHID>"); sb.Append("<PRBTADCD>PRIMARY </PRBTADCD>"); sb.Append("<PRSTADCD>PRIMARY </PRSTADCD>"); sb.Append("<STADDRCD>PRIMARY </STADDRCD>"); sb.Append("<SLPRSNID>GREG E.</SLPRSNID>"); sb.Append("<SALSTERR>TERRITORY 6</SALSTERR>"); sb.Append("<COMMENT1>comment1</COMMENT1>"); sb.Append("<COMMENT2>comment2</COMMENT2>"); sb.Append("<PYMTRMID>Net 30 </PYMTRMID>"); sb.Append("<CHEKBKID>PAYROLL </CHEKBKID>"); sb.Append("<KPCALHST>0 </KPCALHST>"); //sb.Append("<RMCSHACTNUMST>000-1200-00 </RMCSHACTNUMST>"); sb.Append("<UseCustomerClass>0</UseCustomerClass>"); sb.Append("<UpdateIfExists>1</UpdateIfExists>"); sb.Append("</taUpdateCreateCustomerRcd>"); sb.Append("</RMCustomerMasterType>"); sb.Append("</eConnect>"); sb = new StringBuilder(); sb.Append("<eConnect xmlns:dt=\"urn: schemas - microsoft - com:datatypes\">"); sb.Append("<RMCustomerMasterType>"); sb.Append("<eConnectProcessInfo>"); sb.Append("</eConnectProcessInfo>"); sb.Append("<taPMTransactionInsert>"); sb.Append("<BACHNUMB>1</BACHNUMB>"); sb.Append("<VCHNUMWK>99999</VCHNUMWK>"); sb.Append("<VENDORID>ACETRAVE0001</VENDORID>"); sb.Append("<DOCNUMBR>99999</DOCNUMBR>"); sb.Append("<DOCTYPE>1</DOCTYPE>"); sb.Append("<DOCAMNT>99.99</DOCAMNT>"); sb.Append("<DOCDATE>2020-01-01</DOCDATE>"); sb.Append("<MSCCHAMT>0.00</MSCCHAMT>"); sb.Append("<PRCHAMNT>99.99</PRCHAMNT>"); sb.Append("<TAXAMNT>0.00</TAXAMNT>"); sb.Append("<FRTAMNT>0.00</FRTAMNT>"); sb.Append("<TRDISAMT>0.00</TRDISAMT>"); sb.Append("<CHRGAMNT>99.99</CHRGAMNT>"); sb.Append("<CASHAMNT>0.00</CASHAMNT>"); sb.Append("<CHEKAMNT>0.00</CHEKAMNT>"); sb.Append("<CRCRDAMT>0.00</CRCRDAMT>"); sb.Append("<DISTKNAM>0.00</DISTKNAM>"); sb.Append("</taPMTransactionInsert>"); sb.Append("</RMCustomerMasterType>"); sb.Append("</eConnect>"); sConnectionString = "server=LAPTOP-G581GE4V\\SQL2016_GP2018R2;database=TWO;Integrated Security=SSPI;persist security info=False"; eConnectMethods eConnectObject = new eConnectMethods(); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(sb.ToString()); bool eConnectResult; eConnectResult = eConnectObject.CreateEntity(sConnectionString, xmlDoc.OuterXml); return(nextTransactionNumber); } catch (Exception ex) {// If an error occurs, diplay the error information to the user MessageBox.Show(ex.Message); throw ex; } finally { sopTransNumber.Dispose(); } }
/// <summary> /// Arma cabecera de factura en objeto econnect. /// </summary> /// <param name="hojaXl"></param> /// <param name="fila"></param> /// <param name="sTimeStamp"></param> /// <param name="param"></param> public void armaFacturaCaEconn(ExcelWorksheet hojaXl, int fila, string sTimeStamp, Parametros param) { try { iError = 0; GetNextDocNumbers nextDocNumber = new GetNextDocNumbers(); facturaPopCa.POPRCTNM = nextDocNumber.GetNextPOPReceiptNumber(IncrementDecrement.Increment, _DatosConexionDB.Elemento.ConnStr); facturaPopCa.POPTYPE = 3; //shipment/invoice facturaPopCa.VNDDOCNM = hojaXl.Cells[fila, Convert.ToInt32(param.nsa_serie)].Value.ToString().Trim() + "-" + hojaXl.Cells[fila, Convert.ToInt32(param.facturaPopCaVNDDOCNM)].Value.ToString().Trim(); if (!Utiles.ConvierteAFecha(hojaXl.Cells[fila, Convert.ToInt32(param.facturaPopCareceiptdate)].Value.ToString(), out fechaFactura)) { this.sMensaje = "Excepción. La fecha de la factura no tiene el formato correcto: yyyyMMdd"; this.iError++; return; } facturaPopCa.receiptdate = String.Format("{0:MM/dd/yyyy}", fechaFactura); facturaPopCa.BACHNUMB = sTimeStamp; facturaPopCa.VENDORID = hojaXl.Cells[fila, Convert.ToInt32(param.facturaPopCaVENDORID)].Value.ToString(); facturaPopCa.REFRENCE = hojaXl.Cells[fila, Convert.ToInt32(param.facturaPopCaREFRENCE)].Value.ToString(); facturaPopCa.CURNCYID = hojaXl.Cells[fila, Convert.ToInt32(param.facturaPopCaCURNCYID)].Value.ToString(); if (hojaXl.Cells[fila, Convert.ToInt32(param.facturaPopCaXCHGRATE)].Value == null) { facturaPopCa.XCHGRATE = 0; } else { facturaPopCa.XCHGRATE = Convert.ToDecimal(hojaXl.Cells[fila, Convert.ToInt32(param.facturaPopCaXCHGRATE)].Value); facturaPopCa.EXCHDATE = String.Format("{0:MM/dd/yyyy}", fechaFactura); facturaPopCa.EXPNDATE = String.Format("{0:MM/dd/yyyy}", fechaFactura.AddDays(+60)); } if (facturaPopCa.CURNCYID != param.functionalCurrency && facturaPopCa.XCHGRATE <= 0) { this.sMensaje = "Excepción. La tasa de cambio no puede ser cero."; this.iError++; return; } facturaPopCa.TRDISAMTSpecified = true; facturaPopCa.TRDISAMT = 0; facturaPopCa.DISAVAMTSpecified = true; facturaPopCa.DISAVAMT = 0; facturaPopCa.USINGHEADERLEVELTAXES = 0; facturaPopCa.REFRENCE = hojaXl.Cells[fila, Convert.ToInt32(param.nsa_tipo_comprob)].Value.ToString().Trim() + " " + facturaPopCa.VNDDOCNM; if (hojaXl.Cells[fila, Convert.ToInt32(param.nsa_tipo_comprob)].Value.ToString().Trim().Length != 2) { this.sMensaje = "Excepción. No tiene tipo de documento o es inválido. [armaFacturaCaEconn]"; this.iError++; } } catch (FormatException fmt) { sMensaje = "Excepción. La tasa de cambio tiene un formato incorrecto. " + fmt.Message + " [armaFacturaCaEconn]"; iError++; } catch (OverflowException ovr) { sMensaje = "Excepción. El monto de la tasa de cambio es demasiado grande. " + ovr.Message + " [armaFacturaCaEconn]"; iError++; } catch (Exception errorGral) { sMensaje = "Excepción encontrada al armar cabecera de factura. " + errorGral.Message + " [armaFacturaCaEconn]"; iError++; } }
public String CreatePurchaseOrder(Document document) { string Flag = ""; if (document.DocumentLines == null || document.DocumentLines.Count <= 0) throw new Exception("Purchase order does not contains lines."); try { string POPNumber; //string DocPrefix = "SWEB"; //ej: SWEB o como se deban crear las ordenes //string Batch = "BATCH"; //Numero de Batch de las ordenes a Crear // Next consecutive for a P.O. Flag = "PO Sequence"; GetNextDocNumbers nextPopNumber = new GetNextDocNumbers(); POPNumber = nextPopNumber.GetNextPONumber(GetNextDocNumbers.IncrementDecrement.Increment, CurCompany.ErpConnection.CnnString); taPoLine_ItemsTaPoLine[] docLines = new taPoLine_ItemsTaPoLine[document.DocumentLines.Count]; //Create an object that holds XML node object taPoLine_ItemsTaPoLine curLine; int i = 1; // Next consecutive for a Purchase Receipt foreach (DocumentLine dr in document.DocumentLines) { //Debe ser active, para garantizar que no es Misc, o service Item if (dr.Product.Status.StatusID == EntityStatus.Active) { curLine = new taPoLine_ItemsTaPoLine(); //Validate Item/Vendor, GP requires that the Vendor has assigned the ItemNumber ValidateItemAndVendor(document.Vendor.AccountCode, dr.Product.ProductCode); //Validate Item/Location, GP requires that the Location has assigned the ItemNumber ValidateItemAndLocation(document.Location.ErpCode, dr.Product.ProductCode); // Populate Lines Flag = "Line Info"; curLine.PONUMBER = POPNumber; curLine.POTYPE = GP_DocType.PO_Standard; curLine.VENDORID = document.Vendor.AccountCode; curLine.QUANTITY = (decimal)dr.Quantity; curLine.QUANTITYSpecified = true; curLine.REQDATE = DateTime.Today.ToString("yyyy-MM-dd"); curLine.ITEMNMBR = dr.Product.ProductCode; curLine.LOCNCODE = document.Location.ErpCode; curLine.ORD = i; curLine.UOFM = dr.Unit.ErpCode; curLine.POLNESTA = 1; //NEW docLines[i - 1] = curLine; i++; } } //Create a SOPTransactionType schema object and populate its taSopLineIvcInsert_Items poperty POPTransactionType docType = new POPTransactionType(); //Adicionado Track Lists docType.taPoLine_Items = docLines; //Create a taSopHdrIvcInsert XML node object taPoHdr docHdr = new taPoHdr(); //Populate Header Flag = "Header Info"; docHdr.PONUMBER = POPNumber; docHdr.POSTATUS = 1; //NEW docHdr.POTYPE = GP_DocType.PO_Standard; docHdr.REQDATE = DateTime.Today.ToString("yyyy-MM-dd"); docHdr.VENDORID = document.Vendor.AccountCode; docHdr.NOTETEXT = document.Comment; docType.taPoHdr = docHdr; POPTransactionType[] docTypeArray = new POPTransactionType[1]; docTypeArray[0] = docType; //Create an eConnect XML document object and populate its docType property with //the docType schema object Flag = "eConnect"; eConnectType eConnect = new eConnectType(); eConnect.POPTransactionType = docTypeArray; //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()); return POPNumber; } catch (Exception ex) { //ExceptionMngr.WriteEvent("CreatePurchaseOrder: ", ListValues.EventType.Error, ex, null, // ListValues.ErrorCategory.ErpConnection); throw new Exception(Flag + ". " + WriteLog.GetTechMessage(ex)); } }
/// <summary> /// Arma pago PM en objeto econnect pagoPm. /// </summary> /// <param name="hojaXl"></param> /// <param name="fila"></param> /// <param name="sTimeStamp"></param> /// <param name="param"></param> public void armaPagoPmEconn(ExcelWorksheet hojaXl, int fila, string sTimeStamp, Parametros param) { //Stream outputFile = File.Create(@"C:\gpusuario\traceArmaFActuraPmEconn" + fila.ToString() + ".txt"); //TextWriterTraceListener textListener = new TextWriterTraceListener(outputFile); //TraceSource trace = new TraceSource("trSource", SourceLevels.All); try { //trace.Listeners.Clear(); //trace.Listeners.Add(textListener); //trace.TraceInformation("arma factura pm econn"); //trace.TraceInformation("fila: " + fila.ToString() + " col vendorid:" +param.facturaPmVENDORID); iError = 0; GetNextDocNumbers nextDocNumber = new GetNextDocNumbers(); pagoPm.PMNTNMBR = nextDocNumber.GetPMNextVoucherNumber(IncrementDecrement.Increment, _DatosConexionDB.Elemento.ConnStr); pagoPm.PYENTTYP = short.Parse(hojaXl.Cells[fila, param.PagosPmPYENTTYP].Value.ToString().Trim()); pagoPm.VENDORID = hojaXl.Cells[fila, param.PagosPmVENDORID].Value.ToString().Trim(); pagoPm.DOCNUMBR = hojaXl.Cells[fila, param.PagosPmDOCNUMBR].Value.ToString().Trim(); pagoPm.BACHNUMB = sTimeStamp; pagoPm.CHEKBKID = hojaXl.Cells[fila, param.PagosPmCHEKBKID].Value.ToString().Trim(); if (hojaXl.Cells[fila, param.PagosPmTRXDSCRN].Value != null) { pagoPm.TRXDSCRN = hojaXl.Cells[fila, param.PagosPmTRXDSCRN].Value.ToString().Trim(); } pagoPm.DOCDATE = DateTime.Parse(hojaXl.Cells[fila, param.PagosPmDOCDATE].Value.ToString().Trim()).ToString(param.FormatoFecha); //pagoPm.CURNCYID = hojaXl.Cells[fila, param.facturaPmCURNCYID].Value.ToString(); pagoPm.DOCAMNT = Decimal.Round(Convert.ToDecimal(hojaXl.Cells[fila, param.PagosPmDOCAMNT].Value.ToString(), CultureInfo.InvariantCulture), 2); } catch (NullReferenceException nr) { sMensaje = nr.Message + " " + nr.TargetSite.ToString(); iError++; } catch (FormatException fmt) { sMensaje = "Alguna de las columnas contiene un monto o fecha con formato incorrecto. " + fmt.Message + " " + fmt.TargetSite.ToString(); iError++; } catch (OverflowException ovr) { sMensaje = "Alguna de las columna contiene un número demasiado grande. " + ovr.Message + " " + ovr.TargetSite.ToString(); iError++; } catch (Exception errorGral) { string inner = errorGral.InnerException == null ? "" : errorGral.InnerException.Message; sMensaje = "Excepción desconocida al armar el pago pm. " + errorGral.Message + ". " + inner + " " + errorGral.TargetSite.ToString(); iError++; } //finally //{ // trace.Flush(); // trace.Close(); //} }
/// <summary> /// Arma factura PM en objeto econnect facturaPm. /// </summary> /// <param name="hojaXl"></param> /// <param name="fila"></param> /// <param name="sTimeStamp"></param> /// <param name="param"></param> public void armaFacturaPmEconn(ExcelWorksheet hojaXl, int fila, string sTimeStamp, Parametros param) { //Stream outputFile = File.Create(@"C:\gpusuario\traceArmaFActuraPmEconn" + fila.ToString() + ".txt"); //TextWriterTraceListener textListener = new TextWriterTraceListener(outputFile); //TraceSource trace = new TraceSource("trSource", SourceLevels.All); try { //trace.Listeners.Clear(); //trace.Listeners.Add(textListener); //trace.TraceInformation("arma factura pm econn"); //trace.TraceInformation("fila: " + fila.ToString() + " col vendorid:" +param.facturaPmVENDORID); iError = 0; string esf = hojaXl.Cells[fila, param.facturaPmEsFactura].Value.ToString().Trim().ToUpper(); short tipoDocumento = 0; GetNextDocNumbers nextDocNumber = new GetNextDocNumbers(); facturaPm.VCHNUMWK = nextDocNumber.GetPMNextVoucherNumber(IncrementDecrement.Increment, _DatosConexionDB.Elemento.ConnStr); if (short.TryParse(esf, out tipoDocumento)) { facturaPm.DOCTYPE = tipoDocumento; facturaPm.VENDORID = hojaXl.Cells[fila, param.facturaPmVENDORID].Value.ToString().Trim(); facturaPm.DOCNUMBR = hojaXl.Cells[fila, param.facturaPmDOCNUMBR].Value.ToString().Trim(); } else if (esf.Equals("SI")) { facturaPm.DOCTYPE = 1; //invoice facturaPm.VENDORID = hojaXl.Cells[fila, param.facturaPmVENDORID].Value.ToString().Trim(); facturaPm.DOCNUMBR = hojaXl.Cells[fila, param.facturaPmDOCNUMBR].Value.ToString().Trim(); } else { facturaPm.DOCTYPE = 3; //misc charge facturaPm.VENDORID = param.facturaPmGenericVENDORID; facturaPm.DOCNUMBR = param.facturaPmGenericVENDORID + "-" + hojaXl.Cells[fila, param.facturaPmDOCNUMBR].Value.ToString().Trim(); } facturaPm.BACHNUMB = sTimeStamp; facturaPm.BatchCHEKBKID = param.facturaPmBatchCHEKBKID; if (param.FacturaPmLOCALIZACION.Equals("BOL")) { if (hojaXl.Cells[fila, param.addCodigoControl].Value != null) { facturaPm.USRDEFND1 = hojaXl.Cells[fila, param.addCodigoControl].Value.ToString().Trim(); } if (hojaXl.Cells[fila, param.addNumAutorizacion].Value != null) { facturaPm.USRDEFND2 = hojaXl.Cells[fila, param.addNumAutorizacion].Value.ToString().Trim(); } } if (hojaXl.Cells[fila, param.facturaPmTRXDSCRN].Value != null) { facturaPm.TRXDSCRN = hojaXl.Cells[fila, param.facturaPmTRXDSCRN].Value.ToString(); } if (hojaXl.Cells[fila, param.facturaPmRETENCION].Value != null) { facturaPm.USRDEFND2 = hojaXl.Cells[fila, param.facturaPmRETENCION].Value.ToString(); } facturaPm.DOCDATE = DateTime.Parse(hojaXl.Cells[fila, param.facturaPmDOCDATE].Value.ToString().Trim()).ToString(param.FormatoFecha); if (hojaXl.Cells[fila, param.facturaPmDUEDATE].Value != null) { facturaPm.DUEDATE = DateTime.Parse(hojaXl.Cells[fila, param.facturaPmDUEDATE].Value.ToString().Trim()).ToString(param.FormatoFecha); } facturaPm.CURNCYID = hojaXl.Cells[fila, param.facturaPmCURNCYID].Value.ToString(); facturaPm.PRCHAMNT = Decimal.Round(Convert.ToDecimal(hojaXl.Cells[fila, param.facturaPmPRCHAMNT].Value.ToString(), CultureInfo.InvariantCulture), 2); if (param.DistribucionPmAplica.Equals("SI")) { facturaPm.CREATEDIST = 0; //no crea el asiento contable automáticamente } else { //armado manual del detalle de los impuestos. El asiento contable se calcula automáticamente facturaPm.TAXSCHID = getDatosProveedor(facturaPm.VENDORID); armaDetalleImpuestos(facturaPm.TAXSCHID); facturaPm.TAXAMNT = taxDetails.Sum(t => t.TAXAMNT); } facturaPm.DOCAMNT = facturaPm.MSCCHAMT + facturaPm.PRCHAMNT + facturaPm.TAXAMNT + facturaPm.FRTAMNT - facturaPm.TRDISAMT; //facturaPm.DOCAMNT = facturaPm.PRCHAMNT; facturaPm.CHRGAMNT = facturaPm.DOCAMNT; if (hojaXl.Cells[fila, param.facturaPmPAGADO].Value != null && hojaXl.Cells[fila, param.facturaPmPAGADO].Value.ToString() == "SI") { facturaPm.CASHAMNT = facturaPm.PRCHAMNT; facturaPm.CAMCBKID = hojaXl.Cells[param.facturaPmrowCHEKBKID, param.facturaPmcolCHEKBKID].Value.ToString().ToUpper().Trim(); facturaPm.CDOCNMBR = "R" + facturaPm.DOCNUMBR; facturaPm.CAMPMTNM = "R" + facturaPm.VCHNUMWK; facturaPm.CAMTDATE = facturaPm.DOCDATE; } } catch (NullReferenceException nr) { sMensaje = nr.Message + " " + nr.TargetSite.ToString(); iError++; } catch (FormatException fmt) { sMensaje = "Alguna de las columnas contiene un monto o fecha con formato incorrecto. " + fmt.Message + " [Excepción en FacturaDeCompraPM.armaFacturaPmEconn]"; iError++; } catch (OverflowException ovr) { sMensaje = "Alguna de las columna contiene un número demasiado grande. " + ovr.Message + " [Excepción en FacturaDeCompraPM.armaFacturaPmEconn]"; iError++; } catch (Exception errorGral) { string inner = errorGral.InnerException == null ? "" : errorGral.InnerException.Message; sMensaje = "Excepción desconocida al armar la factura o comprobante. " + errorGral.Message + ". " + inner + " [Excepción en FacturaDeCompraPM.armaFacturaPmEconn]"; iError++; } //finally //{ // trace.Flush(); // trace.Close(); //} }
public String CreatePurchaseOrder(Document document) { string Flag = ""; if (document.DocumentLines == null || document.DocumentLines.Count <= 0) { throw new Exception("Purchase order does not contains lines."); } try { string POPNumber; //string DocPrefix = "SWEB"; //ej: SWEB o como se deban crear las ordenes //string Batch = "BATCH"; //Numero de Batch de las ordenes a Crear // Next consecutive for a P.O. Flag = "PO Sequence"; GetNextDocNumbers nextPopNumber = new GetNextDocNumbers(); POPNumber = nextPopNumber.GetNextPONumber(GetNextDocNumbers.IncrementDecrement.Increment, CurCompany.ErpConnection.CnnString); taPoLine_ItemsTaPoLine[] docLines = new taPoLine_ItemsTaPoLine[document.DocumentLines.Count]; //Create an object that holds XML node object taPoLine_ItemsTaPoLine curLine; int i = 1; // Next consecutive for a Purchase Receipt foreach (DocumentLine dr in document.DocumentLines) { //Debe ser active, para garantizar que no es Misc, o service Item if (dr.Product.Status.StatusID == EntityStatus.Active) { curLine = new taPoLine_ItemsTaPoLine(); //Validate Item/Vendor, GP requires that the Vendor has assigned the ItemNumber ValidateItemAndVendor(document.Vendor.AccountCode, dr.Product.ProductCode); //Validate Item/Location, GP requires that the Location has assigned the ItemNumber ValidateItemAndLocation(document.Location.ErpCode, dr.Product.ProductCode); // Populate Lines Flag = "Line Info"; curLine.PONUMBER = POPNumber; curLine.POTYPE = GP_DocType.PO_Standard; curLine.VENDORID = document.Vendor.AccountCode; curLine.QUANTITY = (decimal)dr.Quantity; curLine.QUANTITYSpecified = true; curLine.REQDATE = DateTime.Today.ToString("yyyy-MM-dd"); curLine.ITEMNMBR = dr.Product.ProductCode; curLine.LOCNCODE = document.Location.ErpCode; curLine.ORD = i; curLine.UOFM = dr.Unit.ErpCode; curLine.POLNESTA = 1; //NEW docLines[i - 1] = curLine; i++; } } //Create a SOPTransactionType schema object and populate its taSopLineIvcInsert_Items poperty POPTransactionType docType = new POPTransactionType(); //Adicionado Track Lists docType.taPoLine_Items = docLines; //Create a taSopHdrIvcInsert XML node object taPoHdr docHdr = new taPoHdr(); //Populate Header Flag = "Header Info"; docHdr.PONUMBER = POPNumber; docHdr.POSTATUS = 1; //NEW docHdr.POTYPE = GP_DocType.PO_Standard; docHdr.REQDATE = DateTime.Today.ToString("yyyy-MM-dd"); docHdr.VENDORID = document.Vendor.AccountCode; docHdr.NOTETEXT = document.Comment; docType.taPoHdr = docHdr; POPTransactionType[] docTypeArray = new POPTransactionType[1]; docTypeArray[0] = docType; //Create an eConnect XML document object and populate its docType property with //the docType schema object Flag = "eConnect"; eConnectType eConnect = new eConnectType(); eConnect.POPTransactionType = docTypeArray; //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()); return(POPNumber); } catch (Exception ex) { //ExceptionMngr.WriteEvent("CreatePurchaseOrder: ", ListValues.EventType.Error, ex, null, // ListValues.ErrorCategory.ErpConnection); throw new Exception(Flag + ". " + WriteLog.GetTechMessage(ex)); } }