/// <summary> /// Metodo para guardar los documetnos validad y pasarlos al siguiente paso /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnGrabar_Click(object sender, RoutedEventArgs e) { int count = 0; foreach (var item in lista_reporte) { if (item.EstadoValidar != "4") { clsEntidadDocument doc = new clsEntidadDocument(localDB).cs_fxObtenerUnoPorId(item.Id); doc.Cs_pr_Procesado = "2"; doc.cs_pxActualizar(false, false); count++; } } if (count > 0) { //Mensage de exito de comprobantes y pasar al siguiente paso automaticamente. System.Windows.Forms.MessageBox.Show("Sus documentos electronicos validados fueron grabados.", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Information); cs_pxCargarDgvComprobanteselectronicos(); } else { System.Windows.Forms.MessageBox.Show("No existen documentos a procesar.", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
/// <summary> /// Evento al culminar la edicion de una celda en la grilla /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void dgDocumentos_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e) { DataGridRow item = e.Row; DocumentoValidar comprobante = (DocumentoValidar)item.DataContext; clsEntidadDocument doc = new clsEntidadDocument(localDB).cs_fxObtenerUnoPorId(comprobante.Id); doc.Cs_pr_ComentarioSUNAT = comprobante.Comentario; doc.cs_pxActualizar(false, false); // System.Windows.Forms.MessageBox.Show(comprobante.SerieNumero + " s " + comprobante.Comentario); }
/// <summary> /// Evento para eliminar el comprobante seleccionado /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnDescartar_Click(object sender, RoutedEventArgs e) { try { List <DocumentoValidar> seleccionados = new List <DocumentoValidar>(); foreach (var it in lista_reporte) { if (it.Check == true) { seleccionados.Add(it); } } if (seleccionados.Count > 0) { if (System.Windows.Forms.MessageBox.Show("¿Está seguro que desea descartar los documentos seleccionados?\nEstos documentos serán eliminados completamente de la base de datos.", "¿Está seguro?", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { string mensaje = string.Empty; foreach (DocumentoValidar row in seleccionados) { bool resultado = new clsEntidadDocument(localDB).cs_pxEliminarDocumento(row.Id); if (resultado == false) { mensaje += row.SerieNumero + "\n"; } } if (mensaje.Length > 0) { System.Windows.Forms.MessageBox.Show("Los siguientes documentos no se eliminaron de la base de datos.\n" + mensaje, "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { System.Windows.Forms.MessageBox.Show("Los documentos se eliminaron de la base de datos.", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Information); } cs_pxCargarDgvComprobanteselectronicos(); } } else { System.Windows.Forms.MessageBox.Show("Debe seleccionar documento(s) a eliminar.", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception ex) { clsBaseLog.cs_pxRegistarAdd("delete docs" + ex.ToString()); //clsBaseMensaje.cs_pxMsgEr("ERR15", ex.Message); } }
/// <summary> /// Evento de carga completa del webbrowser /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void webBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { //clsBaseLog.cs_pxRegistarAdd(numeroDoc); //SI ES la primera carga y se presiono verificar try { HtmlDocument documentBrowser = webBrowser.Document; HtmlElement bodyDocument = documentBrowser.Body; if (bodyDocument.InnerText != null) { if (bodyDocument.InnerText.Contains("refrescando") && verificarDocs == true) { clsBaseLog.cs_pxRegistarAdd(bodyDocument.InnerText + " - " + numeroDoc); cargoPagina++; } else if (bodyDocument.InnerText.Contains("Resultado") && verificarDocs == true) { cargoPagina++; string comentario = ""; //System.Windows.Forms.MessageBox.Show(bodyDocument.InnerText); HtmlElementCollection html_nodo_lista_tables = webBrowser.Document.GetElementsByTagName("table"); if (html_nodo_lista_tables.Count > 0) { HtmlElementCollection col = html_nodo_lista_tables[4].Document.GetElementsByTagName("td"); comentario = col[4].InnerText; } clsEntidadDocument doc = new clsEntidadDocument(localDB).cs_fxObtenerUnoPorId(idDoc); doc.Cs_pr_ComentarioSUNAT = comentario; if (comentario.Contains("válido")) { doc.Cs_pr_EstadoValidar = "0"; } else if (comentario.Contains("BAJA")) { doc.Cs_pr_EstadoValidar = "2"; } else { doc.Cs_pr_EstadoValidar = "3"; } if (tipoDoc == "2" || tipoDoc == "4" || tipoDoc == "5") { if (!comentario.Contains("no")) { //buscar si esta de baja if (comentario.Contains("BAJA")) { doc.Cs_pr_EstadoValidar = "2"; } else { doc.Cs_pr_EstadoValidar = "0"; } } else { doc.Cs_pr_EstadoValidar = "3"; } } doc.cs_pxActualizar(false, false); docsValidados++; } else if (webBrowser.DocumentText.Contains("lista") && verificarDocs == true) { cargoPagina++; HtmlElementCollection html_nodo_lista = webBrowser.Document.GetElementsByTagName("form"); HtmlElementCollection html_nodo_lista_tables = html_nodo_lista[0].Document.GetElementsByTagName("table"); if (html_nodo_lista_tables.Count > 0) { HtmlElementCollection col = html_nodo_lista_tables[4].Document.GetElementsByTagName("input"); HtmlElement rucEmisor = col.GetElementsByName("num_ruc")[0]; rucEmisor.SetAttribute("value", rucEmisorDoc); HtmlElementCollection selects = html_nodo_lista_tables[4].Document.GetElementsByTagName("select"); HtmlElement selectTipoComprobante = selects.GetElementsByName("tipocomprobante")[0]; selectTipoComprobante.Children[Convert.ToInt32(tipoDoc)].SetAttribute("selected", "selected"); HtmlElement numSerie = col.GetElementsByName("num_serie")[0]; numSerie.SetAttribute("value", serieDoc); HtmlElement numComprob = col.GetElementsByName("num_comprob")[0]; numComprob.SetAttribute("value", numeroDoc); HtmlElement fecEmision = col.GetElementsByName("fec_emision")[0]; fecEmision.SetAttribute("value", fechaEmisionDoc); if (tipoDoc != "2" && tipoDoc != "4" && tipoDoc != "5") { HtmlElement montoDocumento = col.GetElementsByName("cantidad")[0]; montoDocumento.SetAttribute("value", montoDoc); } string nombreRandom = RandomString(5); var testImagePath = Directory.GetCurrentDirectory() + "\\imageCaptcha.png"; string s = GetGlobalCookies(webBrowser.Document.Url.AbsoluteUri); //clsBaseLog.cs_pxRegistarAdd(s + " - " + numeroDoc); WebClient Client1 = new WebClient(); Client1.Headers.Add(HttpRequestHeader.Cookie, s); Client1.DownloadFile("http://www.sunat.gob.pe/ol-ti-itconsvalicpe/captcha?accion=image&nmagic=0", testImagePath); Client1.Dispose(); string textoCaptchaIngresar = textoCaptcha("imageCaptcha"); if (textoCaptchaIngresar.Contains("'")) { textoCaptchaIngresar = textoCaptchaIngresar.Replace("'", "I"); } if (textoCaptchaIngresar.Contains(" ")) { textoCaptchaIngresar = textoCaptchaIngresar.Replace(" ", ""); } if (textoCaptchaIngresar.Trim().Length < 4) { //VOLVER A DESCARGAR WebClient Client2 = new WebClient(); Client2.Headers.Add(HttpRequestHeader.Cookie, s); Client2.DownloadFile("http://www.sunat.gob.pe/ol-ti-itconsvalicpe/captcha?accion=image&nmagic=0", testImagePath); Client2.Dispose(); textoCaptchaIngresar = textoCaptcha("imageCaptcha"); if (textoCaptchaIngresar.Contains("'")) { textoCaptchaIngresar = textoCaptchaIngresar.Replace("'", "I"); } if (textoCaptchaIngresar.Contains(" ")) { textoCaptchaIngresar = textoCaptchaIngresar.Replace(" ", ""); } if (textoCaptchaIngresar.Trim().Length < 4) { textoCaptchaIngresar = "AAAA"; } } // clsBaseLog.cs_pxRegistarAdd("uno"+textoCaptchaIngresar); HtmlElement codigoCaptcha = col.GetElementsByName("codigo")[0]; codigoCaptcha.SetAttribute("value", textoCaptchaIngresar.ToUpper()); Thread.Sleep(400); string elementValue = codigoCaptcha.GetAttribute("value"); if (elementValue.Length < 4) { codigoCaptcha.SetAttribute("value", textoCaptchaIngresar.ToUpper()); string elementValue2 = codigoCaptcha.GetAttribute("value"); if (elementValue2.Length <= 0) { codigoCaptcha.SetAttribute("value", textoCaptchaIngresar.ToUpper()); } } //clsBaseLog.cs_pxRegistarAdd(textoCaptchaIngresar); //end Codigo captcha HtmlElementCollection html_nodo_lista_inputenviar = html_nodo_lista.GetElementsByName("wacepta"); HtmlElementCollection html_nodo_lista_inputs = html_nodo_lista[0].Document.GetElementsByTagName("input"); if (html_nodo_lista_inputs.Count > 8) { HtmlElement inputEnviar = html_nodo_lista_inputs[8]; // timer2.Interval = 900; // 'Give it a few seconds to make sure the OpenFileDialog is open // timer2.Elapsed += new ElapsedEventHandler(runWorkerTimerMessageBox); // timer2.Start(); inputEnviar.InvokeMember("click"); } string elementValue2s = codigoCaptcha.GetAttribute("value"); // clsBaseLog.cs_pxRegistarAdd("dos"+elementValue2s); //File.Delete(testImagePath); } // ClickOKButton(); } else { if (verificarDocs == true) { clsBaseLog.cs_pxRegistarAdd(bodyDocument.InnerText); } } } else { clsBaseLog.cs_pxRegistarAdd("browser null"); cargoPagina = 2; } // Mostrar_Formulario_Detalle_Mensaje = false; } catch (Exception ex) { clsBaseLog.cs_pxRegistarAdd(ex.ToString()); cargoPagina = 2; /*No se ejecuta nada para que no detenga el proceso de busqueda de mensajes, ya que esta función * es invocada mas de tres veces*/ } }
/// <summary> /// Metodo para procesar la cadena del xml brindado. /// </summary> /// <param name="cadenaXML"></param> /// <param name="local"></param> /// <param name="facturas"></param> /// <returns></returns> /// Aquí se le esta pasando el XML en la cadena cadenaXML public string procesarXML(string cadenaXML, clsEntityDatabaseLocal local, string RucReceptor) { string resultado = string.Empty; try { clsEntidadDocument documento = new clsEntidadDocument(local); XmlDocument xmlDocument = new XmlDocument(); //var textXml = cabecera.Cs_pr_XML; var textXml = cadenaXML; textXml = textXml.Replace("cbc:", ""); textXml = textXml.Replace("cac:", ""); textXml = textXml.Replace("sac:", ""); textXml = textXml.Replace("ext:", ""); textXml = textXml.Replace("ds:", ""); xmlDocument.LoadXml(textXml); var signatureValue = xmlDocument.GetElementsByTagName("SignatureValue")[0].InnerText; var digestValue = xmlDocument.GetElementsByTagName("DigestValue")[0].InnerText; XmlNodeList IDS = xmlDocument.GetElementsByTagName("ID"); foreach (XmlNode node in IDS) { string padre = node.ParentNode.LocalName; if (padre == "Invoice" || padre == "CreditNote" || padre == "DebitNote") { documento.Cs_tag_ID = node.InnerText; string[] partes = node.InnerText.Split('-'); string serie = partes[0]; string numero = partes[1].PadLeft(8, '0'); // Completa con ceros las parte del número de documento documento.Cs_tag_ID = serie + "-" + numero; break; } } XmlNodeList InvoiceTypeCodeXml = xmlDocument.GetElementsByTagName("InvoiceTypeCode"); if (InvoiceTypeCodeXml.Count > 0) { documento.Cs_tag_InvoiceTypeCode = xmlDocument.GetElementsByTagName("InvoiceTypeCode")[0].InnerText; } else { //buscar si es nota de credito o debito XmlNodeList nodeitemCreditNote = xmlDocument.GetElementsByTagName("CreditNoteLine"); if (nodeitemCreditNote.Count > 0) { documento.Cs_tag_InvoiceTypeCode = "07"; } XmlNodeList nodeitemDebitNote = xmlDocument.GetElementsByTagName("DebitNoteLine"); if (nodeitemDebitNote.Count > 0) { documento.Cs_tag_InvoiceTypeCode = "08"; } } documento.Cs_tag_IssueDate = xmlDocument.GetElementsByTagName("IssueDate")[0].InnerText; documento.Cs_tag_DocumentCurrencyCode = xmlDocument.GetElementsByTagName("DocumentCurrencyCode")[0].InnerText; documento.Cs_cr_Moneda = clsBaseUtil.cs_GetMoneda(documento.Cs_tag_DocumentCurrencyCode); //get accounting supplier party XmlNodeList AccountingSupplierParty = xmlDocument.GetElementsByTagName("AccountingSupplierParty"); foreach (XmlNode dat in AccountingSupplierParty) { XmlDocument xmlDocumentinner = new XmlDocument(); xmlDocumentinner.LoadXml(dat.OuterXml); var identicode = xmlDocumentinner.GetElementsByTagName("IdentificationCode"); if (identicode.Count > 0) { documento.Cs_tag_AccountingSupplierParty_Party_PostalAddress_Country_IdentificationCode = identicode.Item(0).InnerText; } var streetcountry = xmlDocumentinner.GetElementsByTagName("CountrySubentity"); if (streetcountry.Count > 0) { documento.Cs_tag_AccountingSupplierParty_Party_PostalAddress_CountrySubentity = streetcountry.Item(0).InnerText; } var streetdistrict = xmlDocumentinner.GetElementsByTagName("District"); if (streetdistrict.Count > 0) { documento.Cs_tag_AccountingSupplierParty_Party_PostalAddress_District = streetdistrict.Item(0).InnerText; } var cityname = xmlDocumentinner.GetElementsByTagName("CityName"); if (cityname.Count > 0) { documento.Cs_tag_AccountingSupplierParty_Party_PostalAddress_CityName = cityname.Item(0).InnerText; } var citysub = xmlDocumentinner.GetElementsByTagName("CitySubdivisionName"); if (citysub.Count > 0) { documento.Cs_tag_AccountingSupplierParty_Party_PostalAddress_CitySubdivisionName = citysub.Item(0).InnerText; } var asppai = xmlDocumentinner.GetElementsByTagName("ID"); if (asppai.Count > 0) { documento.Cs_tag_AccountingSupplierParty_Party_PostalAddress_ID = asppai.Item(0).InnerText; } var asppn = xmlDocumentinner.GetElementsByTagName("PartyName"); if (asppn.Count > 0) { documento.Cs_tag_AccountingSupplierParty_Party_PartyName_Name = asppn.Item(0).InnerText; } var caaid = xmlDocumentinner.GetElementsByTagName("CustomerAssignedAccountID"); if (caaid.Count > 0) { documento.Cs_tag_AccountingSupplierParty_CustomerAssignedAccountID = caaid.Item(0).InnerText; } var aacid = xmlDocumentinner.GetElementsByTagName("AdditionalAccountID"); if (aacid.Count > 0) { documento.Cs_tag_AccountingSupplierParty_AdditionalAccountID = aacid.Item(0).InnerText; } var stname = xmlDocumentinner.GetElementsByTagName("StreetName"); if (stname.Count > 0) { documento.Cs_tag_AccountingSupplierParty_Party_PostalAddress_StreetName = stname.Item(0).InnerText; } var regname = xmlDocumentinner.GetElementsByTagName("RegistrationName"); if (regname.Count > 0) { documento.Cs_tag_AccountingSupplierParty_Party_PartyLegalEntity_RegistrationName = regname.Item(0).InnerText; } } //get accounting supplier party XmlNodeList AccountingCustomerParty = xmlDocument.GetElementsByTagName("AccountingCustomerParty"); foreach (XmlNode dat in AccountingCustomerParty) { XmlDocument xmlDocumentinner = new XmlDocument(); xmlDocumentinner.LoadXml(dat.OuterXml); var caaid = xmlDocumentinner.GetElementsByTagName("CustomerAssignedAccountID"); if (caaid.Count > 0) { documento.Cs_tag_AccountingCustomerParty_CustomerAssignedAccountID = caaid.Item(0).InnerText; } var aacid = xmlDocumentinner.GetElementsByTagName("AdditionalAccountID"); if (aacid.Count > 0) { documento.Cs_tag_AccountingCustomerParty_AdditionalAccountID = aacid.Item(0).InnerText; } var descr = xmlDocumentinner.GetElementsByTagName("Description"); if (descr.Count > 0) { documento.Cs_tag_AccountingCustomerParty_Party_PhysicalLocation_Description = descr.Item(0).InnerText; } var regname = xmlDocumentinner.GetElementsByTagName("RegistrationName"); if (regname.Count > 0) { documento.Cs_tag_AccountingCustomerParty_Party_PartyLegalEntity_RegistrationName = regname.Item(0).InnerText; } } XmlNodeList DiscrepancyResponse = xmlDocument.GetElementsByTagName("DiscrepancyResponse"); foreach (XmlNode dat in DiscrepancyResponse) { XmlDocument xmlDocumentinner = new XmlDocument(); xmlDocumentinner.LoadXml(dat.OuterXml); var refid = xmlDocumentinner.GetElementsByTagName("ReferenceID"); if (refid.Count > 0) { string[] partes = refid.Item(0).InnerText.Split('-'); string serie = partes[0]; string numero = partes[1].PadLeft(8, '0'); documento.Cs_tag_Discrepancy_ReferenceID = serie + "-" + numero; } var respcode = xmlDocumentinner.GetElementsByTagName("ResponseCode"); if (respcode.Count > 0) { documento.Cs_tag_Discrepancy_ResponseCode = respcode.Item(0).InnerText; } var descr = xmlDocumentinner.GetElementsByTagName("Description"); if (descr.Count > 0) { documento.Cs_tag_Discrepancy_Description = descr.Item(0).InnerText; } } XmlNodeList BillingResponse = xmlDocument.GetElementsByTagName("BillingReference"); foreach (XmlNode dat in BillingResponse) { XmlDocument xmlDocumentinner = new XmlDocument(); xmlDocumentinner.LoadXml(dat.OuterXml); var brefid = xmlDocumentinner.GetElementsByTagName("ID"); if (brefid.Count > 0) { string[] partes = brefid.Item(0).InnerText.Split('-'); string serie = partes[0]; string numero = partes[1].PadLeft(8, '0'); documento.Cs_tag_BillingReference_ID = serie + "-" + numero; } var respcode = xmlDocumentinner.GetElementsByTagName("DocumentTypeCode"); if (respcode.Count > 0) { documento.Cs_tag_BillingReference_DocumentTypeCode = respcode.Item(0).InnerText; } } XmlNodeList LegalMonetaryTotal = null; if (documento.Cs_tag_InvoiceTypeCode == "08") { LegalMonetaryTotal = xmlDocument.GetElementsByTagName("RequestedMonetaryTotal"); } else { LegalMonetaryTotal = xmlDocument.GetElementsByTagName("LegalMonetaryTotal"); } foreach (XmlNode dat in LegalMonetaryTotal) { XmlDocument xmlDocumentinner = new XmlDocument(); xmlDocumentinner.LoadXml(dat.OuterXml); var cta = xmlDocumentinner.GetElementsByTagName("ChargeTotalAmount"); if (cta.Count > 0) { documento.Cs_tag_LegalMonetaryTotal_ChargeTotalAmount_currencyID = cta.Item(0).InnerText; } var pam = xmlDocumentinner.GetElementsByTagName("PayableAmount"); if (pam.Count > 0) { documento.Cs_tag_LegalMonetaryTotal_PayableAmount_currencyID = pam.Item(0).InnerText; } var ata = xmlDocumentinner.GetElementsByTagName("AllowanceTotalAmount"); if (ata.Count > 0) { documento.Cs_tag_LegalMonetaryTotal_ChargeTotalAmount_AllowanceTotalAmount = ata.Item(0).InnerText; } } documento.Cs_pr_EstadoValidar = "4"; documento.Cs_pr_Procesado = "1"; documento.Cs_pr_XML = cadenaXML.Replace("'", "\""); bool procesar = false; if (RucReceptor.Trim() == documento.Cs_tag_AccountingCustomerParty_CustomerAssignedAccountID) { procesar = true; } if (documento.Cs_tag_InvoiceTypeCode == "03" || documento.Cs_tag_BillingReference_DocumentTypeCode == "03") { procesar = true; } if (procesar == true) { //buscar si existe el doc en la base de datos bool existe = new clsEntidadDocument(local).cs_pxExisteDocumento(documento.Cs_tag_ID, documento.Cs_tag_AccountingSupplierParty_CustomerAssignedAccountID); if (existe) // No le encuentro sentido a su existencia { return(""); } string idDocumento = documento.cs_pxInsertar(false, false); // Insertar if (idDocumento != "") { XmlNodeList nodestaxTotal = xmlDocument.GetElementsByTagName("TaxTotal"); foreach (XmlNode dat in nodestaxTotal) { string nodoPadre = dat.ParentNode.LocalName; if (nodoPadre == "Invoice" || nodoPadre == "DebitNote" || nodoPadre == "CreditNote") { clsEntidadDocument_TaxTotal taxTotal = new clsEntidadDocument_TaxTotal(local); taxTotal.Cs_pr_Document_Id = idDocumento; XmlDocument xmlDocumentTaxtotal = new XmlDocument(); xmlDocumentTaxtotal.LoadXml(dat.OuterXml); XmlNodeList taxAmount = xmlDocumentTaxtotal.GetElementsByTagName("TaxAmount"); if (taxAmount.Count > 0) { taxTotal.Cs_tag_TaxAmount = taxAmount.Item(0).InnerText; } XmlNodeList subtotal = xmlDocumentTaxtotal.GetElementsByTagName("TaxSubtotal"); if (subtotal.Count > 0) { XmlDocument xmlDocumentTaxSubtotal = new XmlDocument(); xmlDocumentTaxSubtotal.LoadXml(subtotal.Item(0).OuterXml); var subTotalAmount = xmlDocumentTaxSubtotal.GetElementsByTagName("TaxAmount"); if (subTotalAmount.Count > 0) { taxTotal.Cs_tag_TaxSubtotal_TaxAmount = subTotalAmount.Item(0).InnerText; } var subTotalID = xmlDocumentTaxSubtotal.GetElementsByTagName("ID"); if (subTotalID.Count > 0) { taxTotal.Cs_tag_TaxSubtotal_TaxCategory_TaxScheme_ID = subTotalID.Item(0).InnerText; } var subTotalName = xmlDocumentTaxSubtotal.GetElementsByTagName("Name"); if (subTotalName.Count > 0) { taxTotal.Cs_tag_TaxSubtotal_TaxCategory_TaxScheme_Name = subTotalName.Item(0).InnerText; } var subTotalTaxTypeCode = xmlDocumentTaxSubtotal.GetElementsByTagName("TaxTypeCode"); if (subTotalTaxTypeCode.Count > 0) { taxTotal.Cs_tag_TaxSubtotal_TaxCategory_TaxScheme_TaxTypeCode = subTotalTaxTypeCode.Item(0).InnerText; } } taxTotal.cs_pxInsertar(false, true); } } XmlNodeList additionalInformation = xmlDocument.GetElementsByTagName("AdditionalInformation"); foreach (XmlNode dat in additionalInformation) { XmlDocument xmlDocumentinner = new XmlDocument(); xmlDocumentinner.LoadXml(dat.OuterXml); clsEntidadDocument_UBLExtension_ExtensionContent_AdditionalInformation_AdditionalMonetaryTotal adittionalMonetary; XmlNodeList LIST1 = xmlDocumentinner.GetElementsByTagName("AdditionalMonetaryTotal"); for (int ii = 0; ii < LIST1.Count; ii++) { adittionalMonetary = new clsEntidadDocument_UBLExtension_ExtensionContent_AdditionalInformation_AdditionalMonetaryTotal(local); adittionalMonetary.Cs_pr_Document_Id = idDocumento; var ss = LIST1.Item(ii); XmlDocument xmlDocumentinner1 = new XmlDocument(); xmlDocumentinner1.LoadXml(ss.OuterXml); var id = xmlDocumentinner1.GetElementsByTagName("ID"); if (id.Count > 0) { adittionalMonetary.Cs_tag_Id = id.Item(0).InnerText; if (id.Item(0).Attributes.Count > 0) { adittionalMonetary.Cs_tag_SchemeID = id.Item(0).Attributes.GetNamedItem("schemeID").Value; } } var Name = xmlDocumentinner1.GetElementsByTagName("Name"); if (Name.Count > 0) { adittionalMonetary.Cs_tag_Name = Name.Item(0).InnerText; } var TotalAmount = xmlDocumentinner1.GetElementsByTagName("TotalAmount"); if (TotalAmount.Count > 0) { adittionalMonetary.Cs_tag_TotalAmount = TotalAmount.Item(0).InnerText; } var percent = xmlDocumentinner1.GetElementsByTagName("Percent"); if (percent.Count > 0) { adittionalMonetary.Cs_tag_Percent = percent.Item(0).InnerText; } var ReferenceAmount = xmlDocumentinner1.GetElementsByTagName("ReferenceAmount"); if (ReferenceAmount.Count > 0) { adittionalMonetary.Cs_tag_ReferenceAmount = ReferenceAmount.Item(0).InnerText; } var payableAmount = xmlDocumentinner1.GetElementsByTagName("PayableAmount"); if (payableAmount.Count > 0) { adittionalMonetary.Cs_tag_PayableAmount = payableAmount.Item(0).InnerText; /*** if (payableAmount.Item(0).Attributes.Count > 0) * { * adittionalMonetary. = payableAmount.Item(0).Attributes.GetNamedItem("currencyID").Value; * }****/ } adittionalMonetary.cs_pxInsertar(false, true); } clsEntidadDocument_UBLExtension_ExtensionContent_AdditionalInformation_AdditionalProperty adittionalProperty; XmlNodeList LIST2 = xmlDocumentinner.GetElementsByTagName("AdditionalProperty"); for (int iii = 0; iii < LIST2.Count; iii++) { adittionalProperty = new clsEntidadDocument_UBLExtension_ExtensionContent_AdditionalInformation_AdditionalProperty(local); adittionalProperty.Cs_pr_Document_Id = idDocumento; var ss = LIST2.Item(iii); XmlDocument xmlDocumentinner1 = new XmlDocument(); xmlDocumentinner1.LoadXml(ss.OuterXml); var id = xmlDocumentinner1.GetElementsByTagName("ID"); if (id.Count > 0) { adittionalProperty.Cs_tag_ID = id.Item(0).InnerText; } var value = xmlDocumentinner1.GetElementsByTagName("Value"); if (value.Count > 0) { adittionalProperty.Cs_tag_Value = value.Item(0).InnerText; } var name = xmlDocumentinner1.GetElementsByTagName("Name"); if (name.Count > 0) { adittionalProperty.Cs_tag_Name = name.Item(0).InnerText; } adittionalProperty.cs_pxInsertar(false, true); } } //Additional /* seccion de items ------ añadir items*/ var numero_item = 0; // double sub_total = 0.00; List <clsEntidadDocument_Line> Lista_items; List <clsEntidadDocument_Line_TaxTotal> Lista_items_taxtotal; clsEntidadDocument_Line item; XmlNodeList nodeitem; if (documento.Cs_tag_InvoiceTypeCode == "07") { nodeitem = xmlDocument.GetElementsByTagName("CreditNoteLine"); } else if (documento.Cs_tag_InvoiceTypeCode == "08") { nodeitem = xmlDocument.GetElementsByTagName("DebitNoteLine"); } else { nodeitem = xmlDocument.GetElementsByTagName("InvoiceLine"); } //List<clsEntidadDocument_Line_Description> Lista_items_description; List <clsEntidadDocument_Line_PricingReference> Lista_items_princingreference; clsEntidadDocument_Line_Description descripcionItem; var total_items = nodeitem.Count; int i = 0; foreach (XmlNode dat in nodeitem) { i++; numero_item++; //var valor_unitario_item = ""; //var valor_total_item = ""; //string condition_price = ""; Lista_items = new List <clsEntidadDocument_Line>(); Lista_items_princingreference = new List <clsEntidadDocument_Line_PricingReference>(); Lista_items_taxtotal = new List <clsEntidadDocument_Line_TaxTotal>(); item = new clsEntidadDocument_Line(local); item.Cs_pr_Document_Id = idDocumento; XmlDocument xmlItem = new XmlDocument(); xmlItem.LoadXml(dat.OuterXml); XmlNodeList ItemDetail = xmlItem.GetElementsByTagName("Item"); if (ItemDetail.Count > 0) { foreach (XmlNode items in ItemDetail) { XmlDocument xmlItemItem = new XmlDocument(); xmlItemItem.LoadXml(items.OuterXml); XmlNodeList taxItemIdentification = xmlItemItem.GetElementsByTagName("ID"); if (taxItemIdentification.Count > 0) { item.Cs_tag_Item_SellersItemIdentification = taxItemIdentification.Item(0).InnerText; } /* XmlNodeList taxItemDescription = xmlItemItem.GetElementsByTagName("Description"); * int j = 0; * foreach (XmlNode description in taxItemDescription) * { * j++; * descripcionItem = new clsEntidadDocument_Line_Description(local); * descripcionItem.Cs_pr_Document_Line_Id = j.ToString(); * descripcionItem.Cs_tag_Description = description.InnerText.Trim(); * descripcionItem.cs_pxInsertar(false,true); * } * j = 0;*/ } } XmlNodeList ID = xmlItem.GetElementsByTagName("ID"); if (ID.Count > 0) { item.Cs_tag_InvoiceLine_ID = ID.Item(0).InnerText; } XmlNodeList InvoicedQuantity; if (documento.Cs_tag_InvoiceTypeCode == "07") { InvoicedQuantity = xmlItem.GetElementsByTagName("CreditedQuantity"); if (InvoicedQuantity.Count > 0) { item.Cs_tag_invoicedQuantity = InvoicedQuantity.Item(0).InnerText; if (InvoicedQuantity.Item(0).Attributes.Count > 0) { item.Cs_tag_InvoicedQuantity_unitCode = InvoicedQuantity.Item(0).Attributes.GetNamedItem("unitCode").Value; } } } else if (documento.Cs_tag_InvoiceTypeCode == "08") { InvoicedQuantity = xmlItem.GetElementsByTagName("DebitedQuantity"); if (InvoicedQuantity.Count > 0) { item.Cs_tag_invoicedQuantity = InvoicedQuantity.Item(0).InnerText; if (InvoicedQuantity.Item(0).Attributes.Count > 0) { item.Cs_tag_InvoicedQuantity_unitCode = InvoicedQuantity.Item(0).Attributes.GetNamedItem("unitCode").Value; } } } else { InvoicedQuantity = xmlItem.GetElementsByTagName("InvoicedQuantity"); if (InvoicedQuantity.Count > 0) { item.Cs_tag_invoicedQuantity = InvoicedQuantity.Item(0).InnerText; if (InvoicedQuantity.Item(0).Attributes.Count > 0) { item.Cs_tag_InvoicedQuantity_unitCode = InvoicedQuantity.Item(0).Attributes.GetNamedItem("unitCode").Value; } } } XmlNodeList LineExtensionAmount = xmlItem.GetElementsByTagName("LineExtensionAmount"); if (LineExtensionAmount.Count > 0) { item.Cs_tag_LineExtensionAmount_currencyID = LineExtensionAmount.Item(0).InnerText; } XmlNodeList Price = xmlItem.GetElementsByTagName("Price"); if (Price.Count > 0) { XmlDocument xmlItemPrice = new XmlDocument(); xmlItemPrice.LoadXml(Price.Item(0).OuterXml); XmlNodeList PriceAmount = xmlItemPrice.GetElementsByTagName("PriceAmount"); if (PriceAmount.Count > 0) { item.Cs_tag_Price_PriceAmount = PriceAmount.Item(0).InnerText; } } XmlNodeList AllowanceCharge = xmlItem.GetElementsByTagName("AllowanceCharge"); if (AllowanceCharge.Count > 0) { XmlDocument xmlItemAllowanceCharge = new XmlDocument(); xmlItemAllowanceCharge.LoadXml(AllowanceCharge.Item(0).OuterXml); XmlNodeList ChargeIndicator = xmlItemAllowanceCharge.GetElementsByTagName("ChargeIndicator"); if (ChargeIndicator.Count > 0) { item.Cs_tag_AllowanceCharge_ChargeIndicator = ChargeIndicator.Item(0).InnerText; } XmlNodeList Amount = xmlItemAllowanceCharge.GetElementsByTagName("Amount"); if (Amount.Count > 0) { item.Cs_tag_AllowanceCharge_Amount = Amount.Item(0).InnerText; } } string idItem = item.cs_pxInsertar(false, true); XmlNodeList ItemDetailes = xmlItem.GetElementsByTagName("Item"); if (ItemDetailes.Count > 0) { foreach (XmlNode items in ItemDetailes) { XmlDocument xmlItemItem = new XmlDocument(); xmlItemItem.LoadXml(items.OuterXml); XmlNodeList taxItemDescription = xmlItemItem.GetElementsByTagName("Description"); foreach (XmlNode description in taxItemDescription) { descripcionItem = new clsEntidadDocument_Line_Description(local); descripcionItem.Cs_pr_Document_Line_Id = idItem; descripcionItem.Cs_tag_Description = description.InnerText.Trim().Replace("'", "\""); descripcionItem.cs_pxInsertar(false, true); } } } clsEntidadDocument_Line_PricingReference lines_pricing_reference; XmlNodeList PricingReference = xmlItem.GetElementsByTagName("PricingReference"); if (PricingReference.Count > 0) { XmlDocument xmlItemItem = new XmlDocument(); xmlItemItem.LoadXml(PricingReference.Item(0).OuterXml); XmlNodeList AlternativeConditionPrice = xmlItemItem.GetElementsByTagName("AlternativeConditionPrice"); foreach (XmlNode itm in AlternativeConditionPrice) { XmlDocument xmlItemPricingReference = new XmlDocument(); xmlItemPricingReference.LoadXml(itm.OuterXml); lines_pricing_reference = new clsEntidadDocument_Line_PricingReference(local); lines_pricing_reference.Cs_pr_Document_Line_Id = idItem; XmlNodeList PriceAmount = xmlItemPricingReference.GetElementsByTagName("PriceAmount"); if (PriceAmount.Count > 0) { lines_pricing_reference.Cs_tag_PriceAmount_currencyID = PriceAmount.Item(0).InnerText; } XmlNodeList PriceTypeCode = xmlItemPricingReference.GetElementsByTagName("PriceTypeCode"); if (PriceTypeCode.Count > 0) { lines_pricing_reference.Cs_tag_PriceTypeCode = PriceTypeCode.Item(0).InnerText; } lines_pricing_reference.cs_pxInsertar(false, true); } } clsEntidadDocument_Line_TaxTotal taxTotalItem; XmlNodeList TaxTotal = xmlItem.GetElementsByTagName("TaxTotal"); if (TaxTotal.Count > 0) { foreach (XmlNode taxitem in TaxTotal) { taxTotalItem = new clsEntidadDocument_Line_TaxTotal(local); taxTotalItem.Cs_pr_Document_Line_Id = idItem; XmlDocument xmlItemTaxtotal = new XmlDocument(); xmlItemTaxtotal.LoadXml(taxitem.OuterXml); XmlNodeList taxItemAmount = xmlItemTaxtotal.GetElementsByTagName("TaxAmount"); if (taxItemAmount.Count > 0) { taxTotalItem.Cs_tag_TaxAmount_currencyID = taxItemAmount.Item(0).InnerText; } XmlNodeList itemsubtotal = xmlItemTaxtotal.GetElementsByTagName("TaxSubtotal"); if (itemsubtotal.Count > 0) { XmlDocument xmlItemTaxSubtotal = new XmlDocument(); xmlItemTaxSubtotal.LoadXml(itemsubtotal.Item(0).OuterXml); var subTotalAmount = xmlItemTaxSubtotal.GetElementsByTagName("TaxAmount"); if (subTotalAmount.Count > 0) { taxTotalItem.Cs_tag_TaxSubtotal_TaxAmount_currencyID = subTotalAmount.Item(0).InnerText; } var subTotalID = xmlItemTaxSubtotal.GetElementsByTagName("ID"); if (subTotalID.Count > 0) { taxTotalItem.Cs_tag_TaxSubtotal_TaxCategory_TaxScheme_ID = subTotalID.Item(0).InnerText; } var subTotalName = xmlItemTaxSubtotal.GetElementsByTagName("Name"); if (subTotalName.Count > 0) { taxTotalItem.Cs_tag_TaxSubtotal_TaxCategory_TaxScheme_Name = subTotalName.Item(0).InnerText; } var subTotalTaxTypeCode = xmlItemTaxSubtotal.GetElementsByTagName("TaxTypeCode"); if (subTotalTaxTypeCode.Count > 0) { taxTotalItem.Cs_tag_TaxSubtotal_TaxCategory_TaxScheme_TaxTypeCode = subTotalTaxTypeCode.Item(0).InnerText; } } taxTotalItem.cs_pxInsertar(false, true); } } } } resultado = idDocumento; } } catch (Exception ex) { string Errror = ex.ToString(); resultado = ""; } return(resultado); }