/// <summary> /// /// </summary> /// <param name="paymentType"></param> /// <returns></returns> private string SerializeRMCashReceipts(RMCashReceiptsType paymentType) { try { eConnectType eConnect = new eConnectType(); RMCashReceiptsType[] TranType = { paymentType }; eConnect.RMCashReceiptsType = TranType; MemoryStream ms = new MemoryStream(); XmlSerializer serializer = new XmlSerializer(eConnect.GetType()); serializer.Serialize(ms, eConnect); ms.Position = 0; XmlDocument xmldoc = new XmlDocument(); xmldoc.Load(ms); string TransactionXML = xmldoc.OuterXml; return(TransactionXML); } catch (Exception) { // logW.LogExeption("Econnect", 2, ex); throw; } }
/// <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(); } }
/// <summary> /// Integra recibos de cobro y aplica a facturas /// </summary> /// <param name="worker"></param> /// <param name="e"></param> private void IntegraRMCobrosYAplicaciones(BackgroundWorker worker, DoWorkEventArgs e) { string mensajeOk = ""; string mensajeError = ""; Model.RMFactura docGP = null; Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); string nroLote = DateTime.Now.ToString("yyyyMMdd.HHmmss"); worker.ReportProgress(0, new string[] { "Collection receipt batch " + nroLote, "Collection receipt batch " + nroLote }); cantidad = 0; foreach (var dato in _cobros.LBoletosBrasil) { mensajeOk = ""; mensajeError = ""; DateTime fechaCobro = dato.FechaTotalLiquidado.AddDays(parametrosCobrosXL.FechaTotalLiquidadoAddDays); using (eConnectMethods eConnectMethods = new eConnectMethods()) { eConnectMethods.RequireProxyService = true; List <RMCashReceiptsType> masterRMCashReceiptsType = new List <RMCashReceiptsType>(); List <RMApplyType> masterRMApplyType = new List <RMApplyType>(); try { bool error = false; RMCashReceiptsType RMCashReceiptsTypeEntry = new RMCashReceiptsType(); taRMCashReceiptInsert CashReceiptItem = new taRMCashReceiptInsert(); //el número de la planilla puede venir así: B-10201, B-10201., B-10201 01, B-10201. 01 //string numFactura = dato.NumeroFactura.Trim().Length > 7 ? Model.Utiles.Izquierda(dato.NumeroFactura, 8) : Model.Utiles.Izquierda(dato.NumeroFactura, 7); docGP = this.getCustnmbrDocnumbr(dato.NumeroFactura.Trim(), dato.FechaVencimientoPago); decimal valorBoleto = decimal.Round(dato.ValorBoleto, 2); decimal valorPago = decimal.Round(dato.ValorPago, 2); CashReceiptItem.CUSTNMBR = docGP.Custnmbr; // custData["custnmbr"].ToString(); //_custnmbr; CashReceiptItem.DOCNUMBR = "RB" + dato.NumeroCobro; CashReceiptItem.DOCDATE = fechaCobro.ToString(parametrosCobrosXL.FormatoFecha); //System.Configuration.ConfigurationManager.AppSettings[_pre + "_FormatoFecha"]); CashReceiptItem.ORTRXAMT = valorPago; CashReceiptItem.GLPOSTDT = CashReceiptItem.DOCDATE; CashReceiptItem.BACHNUMB = nroLote; CashReceiptItem.CSHRCTYP = 0; CashReceiptItem.CHEKBKID = parametrosCobrosXL.ChekbkidDefault; //System.Configuration.ConfigurationManager.AppSettings[_pre + "_CHEKBKID"]; CashReceiptItem.CHEKNMBR = dato.NumeroCobro.ToString(); CashReceiptItem.TRXDSCRN = dato.NumeroFacturaYCuota; RMApplyType RMApplyTypeEntry = new RMApplyType(); taRMApply ApplyItem = new taRMApply(); ApplyItem.APTODCNM = docGP.Docnmbr; // custData["docnumbr"].ToString(); // _docnmbr.Trim(); ApplyItem.APFRDCNM = "RB" + dato.NumeroCobro; ApplyItem.APPTOAMT = valorPago - Convert.ToDecimal(docGP.Amount) > 0 ? Convert.ToDecimal(docGP.Amount) : valorPago; ApplyItem.APFRDCTY = 9; ApplyItem.APTODCTY = 1; ApplyItem.APPLYDATE = fechaCobro.ToString(parametrosCobrosXL.FormatoFecha); // System.Configuration.ConfigurationManager.AppSettings[_pre + "_FormatoFecha"]); ApplyItem.GLPOSTDT = fechaCobro.ToString(parametrosCobrosXL.FormatoFecha); // System.Configuration.ConfigurationManager.AppSettings[_pre + "_FormatoFecha"]); cantidad++; if (!error) { eConnectType eConnDoc = new eConnectType(); RMCashReceiptsTypeEntry.taRMCashReceiptInsert = CashReceiptItem; masterRMCashReceiptsType.Add(RMCashReceiptsTypeEntry); eConnDoc.RMCashReceiptsType = masterRMCashReceiptsType.ToArray(); RMApplyTypeEntry.taRMApply = ApplyItem; masterRMApplyType.Add(RMApplyTypeEntry); eConnDoc.RMApplyType = masterRMApplyType.ToArray(); XmlDocument xmlDoc = Serializa(eConnDoc); eConnectMethods.CreateEntity(parametrosCobrosXL.ConnStringTarget, xmlDoc.OuterXml); mensajeOk = dato.NumeroFactura + " - " + dato.NumeroCobro + ": Collection receipt OK" + Environment.NewLine; } else { mensajeError = dato.NumeroFactura + " - " + dato.NumeroCobro + ": Error" + Environment.NewLine; } System.Threading.Thread.Sleep(100); } catch (eConnectException ec) { mensajeError = dato.NumeroFactura + " - " + dato.NumeroCobro + " eConn: " + ec.Message + Environment.NewLine + ec.StackTrace; } catch (Exception ex) { mensajeError = dato.NumeroFactura + " - " + dato.NumeroCobro + ": " + ex.Message + Environment.NewLine + ex.StackTrace; } finally { eConnectMethods.Dispose(); worker.ReportProgress(0, new string[] { mensajeError, mensajeOk }); } } } worker.ReportProgress(0, new string[] { "Collection receipt uploading finished.", "Collection receipt uploading finished." }); }