/* * XML * Los datos son utilizados para almacenar la transacción en la base de datos * tanto local como central. */ public override void SerializeToDB(XmlStringWriter writer) { writer.WriteStartElement("trans_bes_debito_credito"); writer.WriteField("shop_id", shop_id); writer.WriteField("till_id", till_id); writer.WriteField("trans_num", trans_num); writer.WriteField("last_digits", last_digits); writer.WriteField("codigo_comercio", codigo_comercio); writer.WriteField("terminal_id", terminal_id); writer.WriteField("code_auth", code_auth); writer.WriteField("monto", monto); writer.WriteField("cuotas", cuotas); writer.WriteField("nro_operacion", nro_operacion); writer.WriteField("abrev_tipo_tarjeta", abrev_tipo_tarjeta); //writer.WriteField("fecha_contable", fecha_contable); writer.WriteField("abrev_marca_tarjeta", abrev_marca_tarjeta); writer.WriteField("fecha", fecha); /* * if (shopMulti != null) * writer.WriteField("shops_multi_id", shopMulti.ID); * writer.WriteField("shops_multi_points", shopMultiPoints); */ writer.WriteEndElement(); base.SerializeToDB(writer); }
public override void SerializeToDB(XmlStringWriter writer) { writer.WriteStartElement("trans_bes_debito"); writer.WriteField("shop_id", shop_id); writer.WriteField("till_id", till_id); writer.WriteField("trans_num", trans_num); writer.WriteField("last_digits", last_digits); writer.WriteField("nro_operacion", nro_operacion); writer.WriteField("monto", monto); writer.WriteField("code_auth", code_auth); writer.WriteEndElement(); base.SerializeToDB(writer); }
/* * XML * Los datos son utilizados para almacenar la transacción en la base de datos * tanto local como central. */ public override void SerializeToDB(XmlStringWriter writer) { writer.WriteStartElement("trans_bes_cheque"); writer.WriteField("shop_id", shop_id); writer.WriteField("till_id", till_id); writer.WriteField("trans_num", trans_num); writer.WriteField("bank_id", bank_id); writer.WriteField("rut_cheque", rut_cheque); writer.WriteField("nro_cta_corriente", nro_cta_corriente); writer.WriteField("nro_cheque", nro_cheque); writer.WriteField("monto", monto); writer.WriteField("code_auth", code_auth); writer.WriteField("nombre_completo", nombre_completo); writer.WriteField("tasas", tasas); writer.WriteField("fecha", fecha); /* * if (shopMulti != null) * writer.WriteField("shops_multi_id", shopMulti.ID); * writer.WriteField("shops_multi_points", shopMultiPoints); */ writer.WriteEndElement(); base.SerializeToDB(writer); }
}//FINISH PM_OnSerializeToDbTransItemInElement //ANTES DEL CIERRE DE LA TRANSACCION void PM_OnBeforeCloseTransaction(Transaction transaction, ref bool abort) { //throw new NotImplementedException(); // ARROJA ERROR SI EL SERVICIO NO ESTA DISPONIBLE if (webservice == null) { abort = true; BL.MsgError("WEBSERVICE NO COMUNICATION"); return; } else { string printoutType = ""; if (transaction.ManualPrintoutSelected == DbPayment.PrintoutType.KeepDefault || transaction.ManualPrintoutSelected == DbPayment.PrintoutType.NoPrintout) { printoutType = "39"; } if (transaction.ManualPrintoutSelected == DbPayment.PrintoutType.Invoice) { printoutType = "33"; } if (transaction.ManualPrintoutSelected == DbPayment.PrintoutType.Bill) { printoutType = "39"; } if (transaction.ManualPrintoutSelected == DbPayment.PrintoutType.Invoice && transaction.Customer == null) { BL.MsgError("WE NEED A CUSTOMER"); abort = true; return; } //string xmlData = ""; //string documentType = ""; DbCustomer receptorDTE = new DbCustomer(); receptorDTE = customer; XmlStringWriter writer = new XmlStringWriter(BL.DB); writer.WriteRaw(@"<?xml version=""1.0"" encoding=""ISO-8859-1""?>"); if (printoutType == "33")//FACTURA { //INICIO DTE writer.WriteStartElement("DTE"); writer.WriteAttribute("version", "1.0"); writer.WriteAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); writer.WriteAttribute("xmlns:xsd", "http://www.w3.org/2001/XMLSchema"); writer.WriteAttribute("xmlns", "http://www.sii.cl/SiiDte"); //FIN DTE } else//BOLETA { //INICIO EnvioBOLETA writer.WriteStartElement("EnvioBOLETA"); writer.WriteAttribute("version", "1.0"); writer.WriteAttribute("xmlns", "http://www.sii.cl/SiiDte"); writer.WriteAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); writer.WriteAttribute("xsi:schemaLocation", "http://www.sii.cl/SiiDte EnvioBOLETA_v11.xsd"); //FIN EnvioBoleta } //RUT RECEPTOR string rrecep; rrecep = getRutReceptorDTE(); //RUT RECEPTOR if (printoutType == "39")//BOLETA { //ONLY BOLETA writer.WriteStartElement("SetDTE"); writer.WriteAttribute("ID", string.Format("ENVBOL-{0}", transaction.TransDate.ToString("yyyyMMddHHmmss"))); writer.WriteStartElement("Caratula"); writer.WriteAttribute("version", "1.0"); //string shopRut = BL.DB.Shop["rut"].ToString(); //string shopRut = "76328464-6"; string shopRut = dataEmisor.RutBoleta; writer.WriteElement("RutEmisor", shopRut); //string RutEnvia = BL.DB.Shop["RutEnvia"].ToString(); //string RutEnvia = "8833649-6"; string RutEnvia = dataEmisor.RutRepLegal; writer.WriteElement("RutEnvia", RutEnvia); //string RutReceptor = BL.DB.Shop["RutReceptor"].ToString(); //string RutReceptor = "66666666-6"; writer.WriteElement("RutReceptor", rrecep); //DateTime FchResol = Convert.ToDateTime(BL.DB.Shop["FchResol"]); //DateTime FchResol = new DateTime(2014, 04, 22); DateTime FchResol = (dataEmisor.ResolDate); writer.WriteElement("FchResol", FchResol.ToString("yyyy-MM-dd")); //writer.WriteElement("NroResol", 0); writer.WriteElement("NroResol", dataEmisor.NumResol); writer.WriteElement("TmstFirmaEnv", DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss")); writer.WriteStartElement("SubTotDTE"); writer.WriteElement("TpoDTE", printoutType); writer.WriteElement("NroDTE", 1); writer.WriteEndElement(); writer.WriteEndElement(); writer.WriteStartElement("DTE"); writer.WriteAttribute("version", "1.0"); //END ONLY BOLETA } //string besRut = "76054473-6"; //MANAGE THIS FROM DB ON FRONTEND dataEmisor.Rut // string besRut = dataEmisor.Rut; if (printoutType == "39") { //ONLY BOLETA writer.WriteStartElement("Documento"); //string besRut = myClassPAramData["besRUT"].ToString(); string besRutBoletaE = dataEmisor.RutBoleta; solicitarFolio = webservice.Solicitar_Folio(besRutBoletaE, 39); writer.WriteAttribute("ID", string.Format("R{0}T{1}F{2}", besRutBoletaE, printoutType, solicitarFolio.Folio)); //END ONLY BOLETA } else { solicitarFolio = webservice.Solicitar_Folio(besRut, 33); writer.WriteStartElement("Documento"); } writer.WriteStartElement("Encabezado"); writer.WriteStartElement("IdDoc"); writer.WriteElement("TipoDTE", printoutType); writer.WriteElement("Folio", solicitarFolio.Folio); writer.WriteElement("FchEmis", DateTime.Now.ToString("yyyy-MM-dd")); if (printoutType == "39") { //SOLO BOLETA writer.WriteElement("IndServicio", 3); //SOLO BOLETA } else { //TermPagoGlosa //FchVenc writer.WriteElement("TermPagoGlosa", "30 dias Precio Contado"); ///////////////////////////////////////////ASK 4 THIS FIELD writer.WriteElement("FchVenc", "2016-06-30"); /////////////////////////////////////////////////////////////ASK 4 THIS FIELD } writer.WriteEndElement(); //IdDoc //FIN DATOS EMISOR if (printoutType == "39") { writer.WriteStartElement("Emisor"); writer.WriteElement("RUTEmisor", dataEmisor.Rut); writer.WriteElement("RznSocEmisor", dataEmisor.RazonEmisor); writer.WriteElement("GiroEmisor", dataEmisor.GiroEmisor); writer.WriteElement("CdgSIISucur", dataEmisor.CodigoSII); writer.WriteElement("DirOrigen", dataEmisor.DireccionEm); writer.WriteElement("CmnaOrigen", dataEmisor.ComunaEm); writer.WriteElement("CiudadOrigen", dataEmisor.CiudadEm); writer.WriteEndElement(); //Emisor } else { writer.WriteStartElement("Emisor"); //<Acteco>602300</Acteco> writer.WriteElement("Acteco", dataEmisor.ActEco); writer.WriteElement("RUTEmisor", dataEmisor.Rut); writer.WriteElement("RznSoc", dataEmisor.RazonEmisor); writer.WriteElement("GiroEmis", dataEmisor.GiroEmisor); writer.WriteElement("DirOrigen", dataEmisor.DireccionEm); writer.WriteElement("CmnaOrigen", dataEmisor.ComunaEm); writer.WriteElement("CiudadOrigen", dataEmisor.CiudadEm); writer.WriteElement("CdgVendedor", BL.CurrentOperator.Code); writer.WriteEndElement(); //Emisor } //OBJETO RECEPTOR DbCustomer receptorC = BL.DB.GetCustomerByCardNum((rrecep.Replace("-", "")), false); //OBJETO RECEPTOR writer.WriteStartElement("Receptor"); writer.WriteElement("RUTRecep", rrecep); if (printoutType == "33")//FACTURA { //<CdgIntRecep>76124037C</CdgIntRecep> writer.WriteElement("CdgIntRecep", getCodeIntRecep(rrecep)); writer.WriteElement("RznSocRecep", receptorC.C_o); //<GiroRecep>VENTA AL POR MAYOR DE OTROS PRODUCTOS N.</GiroRecep> writer.WriteElement("GiroRecep", receptorC.C_o); writer.WriteElement("DirRecep", receptorC.Street); writer.WriteElement("CmnaRecep", receptorC.Notes1); writer.WriteElement("CiudadRecep", receptorC.City); writer.WriteEndElement(); //Receptor } else//BOLETA { writer.WriteElement("RznSocRecep", null); writer.WriteElement("Contacto", null);//ASK NUM TELEFONO writer.WriteElement("DirRecep", null); writer.WriteElement("CmnaRecep", null); writer.WriteElement("CiudadRecep", null); writer.WriteElement("DirPostal", null); writer.WriteElement("CmnaPostal", null); writer.WriteElement("CiudadPostal", null); writer.WriteEndElement(); //Receptor } writer.WriteStartElement("Totales"); if (printoutType == "33")//FACTURA { double monto, neto, iva; string netoS, ivaS; monto = SafeConvert.ToInt32(transaction.Total); neto = monto * 0.81; iva = monto - neto; netoS = SafeConvert.ToString(neto); ivaS = SafeConvert.ToString(iva); writer.WriteElement("TpoMoneda", "PESO CL"); writer.WriteElement("MntNeto", netoS); writer.WriteElement("TasaIVA", "19.00"); writer.WriteElement("IVA", ivaS); } writer.WriteElement("MntTotal", SafeConvert.ToInt32(transaction.Total)); writer.WriteEndElement(); //Totales writer.WriteEndElement(); //Encabezado int position = 1; foreach (TransArticle art in transaction.GetItems <TransArticle>()) { writer.WriteStartElement("Detalle"); writer.WriteElement("NroLinDet", position); writer.WriteStartElement("CdgItem"); writer.WriteElement("TpoCodigo", "Interna"); writer.WriteElement("VlrCodigo", art.Data.Code); writer.WriteEndElement(); //CdgItem writer.WriteElement("NmbItem", art.Data.Description); if (printoutType == "33") { writer.WriteElement("DscItem", art.Data.Description); } writer.WriteElement("QtyItem", art.Data.MeasureUnit == DbArticle.Units.Pieces ? art.Quantity : 1); //writer.WriteElement("QtyItem", 1); writer.WriteElement("UnmdItem", null); writer.WriteElement("PrcItem", art.UnitPrice); //writer.WriteElement("MontoItem", art.TotalPrice); string totalprice = art.TotalPrice.ToString(); totalprice = totalprice.Replace(".00", ""); writer.WriteElement("MontoItem", totalprice); writer.WriteEndElement(); //Detalle position++; } writer.WriteEndElement(); //Documento writer.WriteEndElement(); //DTE if (printoutType == "39") { writer.WriteEndElement(); //SetDTE writer.WriteEndElement(); //EnvioBOLETA || DTE } string xmlString = writer.ToString(); if (printoutType == "33") { resultProcesarTXTDTE = webservice.Carga_TXTDTE(xmlString, "XML"); } else { resultProcesarTXTBoleta = webservice.Carga_TXTBoleta(xmlString, "XML"); } string fob; if (printoutType == "33") { fob = "Factura"; } else { fob = "Boleta"; } if (dataEmisor.SaveXML == 1) { //SAVE TO FILE XML string path = Path.GetPathRoot(Environment.SystemDirectory); System.IO.Directory.CreateDirectory("C:\\xmlTCPOS"); //System.IO.File.WriteAllText(@"C:\xmlTCPOS\" + fob + "" + DateTime.Now.ToString("yyyyMMddHHmm") + ".xml", xmlString); System.IO.File.WriteAllText(@"" + path + "xmlTCPOS\\" + fob + "" + DateTime.Now.ToString("yyyyMMddHHmm") + ".xml", xmlString); //END SAVE TO FILE XML } if (printoutType == "33") { if (resultProcesarTXTDTE.XML != "") { XmlDocument doc = new XmlDocument(); doc.LoadXml(resultProcesarTXTDTE.XML); XmlElement root = doc.DocumentElement; if (root == null) { abort = true; throw new Exception("XML BAD FORMAT"); } XmlNodeList SignatureValue = root.GetElementsByTagName("TED"); string signature = ""; foreach (XmlNode tableNode in SignatureValue) { signature = tableNode.InnerXml; } if (signature != "") { signature = string.Format("<TED version=\"1.0\">" + signature + "</TED>"); } transaction.SetCustomField("webservice_bes_signature", signature); transaction.SetCustomField("dte_doc_type", printoutType); XmlNodeList folioNUMValue = root.GetElementsByTagName("F"); string folioNUM = ""; foreach (XmlNode tableNode in folioNUMValue) { folioNUM = tableNode.InnerXml; } if (folioNUM != "") { folioNUM = string.Format("" + folioNUM + ""); } transaction.SetCustomField("webservice_bes_folionum", folioNUM); //GUARDA FOLIO 2 PRINT if (folioNUM != "") { transaction.SetCustomField("bes_folio_num", folioNUM); } //END GUARDA FOLIO 2 PRINT //PRINT TIPO DOC transaction.SetCustomField("tipo_documento", "FACTURA ELECTRONICA"); //END PRINT TIPO DOC } else { abort = true; BL.MsgError("No answer from webservice,\nelectronic invoice cannot be accepted\nPlease use another type of document"); } } else { //if response from webservice read xml response and get the signature, save it into transaction and print signature if (resultProcesarTXTBoleta.XML != "") { XmlDocument doc = new XmlDocument(); doc.LoadXml(resultProcesarTXTBoleta.XML); XmlElement root = doc.DocumentElement; if (root == null) { abort = true; throw new Exception("XML BAD FORMAT"); } //OBTENER TED Y GUARDAR XmlNodeList SignatureValue = root.GetElementsByTagName("TED"); string signature = ""; foreach (XmlNode tableNode in SignatureValue) { signature = tableNode.InnerXml; } if (signature != "") { signature = string.Format("<TED version=\"1.0\">" + signature + "</TED>"); } transaction.SetCustomField("webservice_bes_signature", signature); transaction.SetCustomField("dte_doc_type", printoutType); //FIN OBTENER TED Y GUARDAR //OBTENER FOLIONUM Y GUARDAR XmlNodeList folioNUMValue = root.GetElementsByTagName("F"); string folioNUM = ""; foreach (XmlNode tableNode in folioNUMValue) { folioNUM = tableNode.InnerXml; } if (folioNUM != "") { folioNUM = string.Format("" + folioNUM + ""); } transaction.SetCustomField("webservice_bes_folionum", folioNUM); //FIN FOLIONUM Y GUARDAR //GUARDA FOLIO 2 PRINT if (folioNUM != "") { transaction.SetCustomField("bes_folio_num", folioNUM); } //END GUARDA FOLIO 2 PRINT transaction.SetCustomField("tipo_documento", "BOLETA ELECTRONICA"); } else { abort = true; BL.MsgError("No answer from webservice,\nelectronic invoice cannot be accepted\nPlease use another type of document"); } } } }//FINISH PM_OnBeforeCloseTransaction