diff --git a/Exferia_Aplicacion/Exferia_Aplicacion/Exferia_Aplicacion.csproj b/Exferia_Aplicacion/Exferia_Aplicacion/Exferia_Aplicacion.csproj index 018b109..060cd8e 100644 --- a/Exferia_Aplicacion/Exferia_Aplicacion/Exferia_Aplicacion.csproj +++ b/Exferia_Aplicacion/Exferia_Aplicacion/Exferia_Aplicacion.csproj @@ -115,6 +115,7 @@ + diff --git a/Exferia_Aplicacion/Exferia_Aplicacion/Modelos_Factura_E/INTERNO_CentroAdministrativo_Factura_E_Modelo.cs b/Exferia_Aplicacion/Exferia_Aplicacion/Modelos_Factura_E/INTERNO_CentroAdministrativo_Factura_E_Modelo.cs index 618352a..283bcd5 100644 --- a/Exferia_Aplicacion/Exferia_Aplicacion/Modelos_Factura_E/INTERNO_CentroAdministrativo_Factura_E_Modelo.cs +++ b/Exferia_Aplicacion/Exferia_Aplicacion/Modelos_Factura_E/INTERNO_CentroAdministrativo_Factura_E_Modelo.cs @@ -12,7 +12,8 @@ namespace Exferia_Aplicacion.Modelos_Factura_E public string Role { get; set;} public string Encargado { get; set; } public string Descripcion { get; set; } - INTERNO_CentroAdministrativo_Factura_E_Modelo() + + public INTERNO_CentroAdministrativo_Factura_E_Modelo() { } diff --git a/Exferia_Aplicacion/Exferia_Aplicacion/Modelos_Factura_E/INTERNO_Correcciones_Factura_E_Modelo.cs b/Exferia_Aplicacion/Exferia_Aplicacion/Modelos_Factura_E/INTERNO_Correcciones_Factura_E_Modelo.cs index abd86fa..64673ca 100644 --- a/Exferia_Aplicacion/Exferia_Aplicacion/Modelos_Factura_E/INTERNO_Correcciones_Factura_E_Modelo.cs +++ b/Exferia_Aplicacion/Exferia_Aplicacion/Modelos_Factura_E/INTERNO_Correcciones_Factura_E_Modelo.cs @@ -9,12 +9,12 @@ namespace Exferia_Aplicacion.Modelos_Factura_E public class INTERNO_Correcciones_Factura_E_Modelo { public int NumeroFactura { get; set; }//numero factura que rectifica - public int serie { get; set; }//serie de la factura que rectifica - public string RazonCode { get; set; } + public String SerieDelegacion { get; set; }//serie de la factura que rectifica + public string RazonCode { get; set; }//(ReasonDescription) public DateTime Inicio { get; set; } public DateTime Fin { get; set; } - public string RazonCorreccion { get; set; } - public string Observaciones { get; set; } + public string RazonCorreccion { get; set; }//CorrectionMethodDescription + public string Observaciones { get; set; }//AdditionalReasonDescription } } diff --git a/Exferia_Aplicacion/Exferia_Aplicacion/Modelos_Factura_E/INTERNO_Factura_e_Modelo.cs b/Exferia_Aplicacion/Exferia_Aplicacion/Modelos_Factura_E/INTERNO_Factura_e_Modelo.cs index 47915ce..59a27d1 100644 --- a/Exferia_Aplicacion/Exferia_Aplicacion/Modelos_Factura_E/INTERNO_Factura_e_Modelo.cs +++ b/Exferia_Aplicacion/Exferia_Aplicacion/Modelos_Factura_E/INTERNO_Factura_e_Modelo.cs @@ -1,22 +1,24 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Xml; namespace Exferia_Aplicacion.Modelos_Factura_E { public class INTERNO_Factura_e_Modelo { + private string error; #region region Propiedades //datos de las partes implicadas public INTERNO_Vendedor_Factura_E_modelo Vendedor { get; set; } - public INTERNO_CentroAdministrativo_Factura_E_Modelo comprador { get; set; } + public INTERNO_Comprador_Factura_E_modelo Comprador { get; set; } - //const string _label = "TIME: "; //datos factura - public string Identificador { get; set; } - + public string Identificador { get; set; }//BatchIdentifier + public string Moneda { get; set;} public int NumeroFactura { get; set;} public String SerieDelegacion { get; set; } @@ -26,33 +28,880 @@ namespace Exferia_Aplicacion.Modelos_Factura_E public DateTime PeriodoInicio { get; set; } public DateTime PeriodoFin { get; set; } //impuestos---------------------------------------- - public int ImpuestosTipo { get; set; } - public double ImpuestosPorcentaje { get; set; } - public double ImpuestosBase { get; set; } - public double ImpuestosImporte { get; set; } + + INTERNO_Impuestos_Factura_E_modelo Impuesto { get; set; } //resumen----------------------------------------- public double TotalBruto { get; set; } public double TotalDescuento { get; set; } public double TotalBase { get; set; } - public double Totalimpuestos { get; set; } + public double TotalImpuestos { get; set; } public float TotalFactura { get; set; } public float TotalPendiente { get; set; } + public float TotalEjecutable { get; set; } public float TotalAnticipo { get; set; } //elementos factura------------------------------ INTERNO_Item_Factura_E_modelo[] Items { get; set; } + #endregion + #region Constantes + const string FACTURA_E_NAME = "fe:Facturae"; + + const string FACTURA_E_HEADER_NAME = "FileHeader"; + const string FACTURA_E_VERSION_NAME = "SchemaVersion"; + const string FACTURA_E_VERSION = "3.2.1"; + const string FACTURA_E_BATCH_NAME = "Batch"; + const string FACTURA_E_BATCH_ID_NAME = "BatchIdentifier"; + const string FACTURA_E_TotalInvoicesAmount_NAME = "TotalInvoicesAmount"; + const string FACTURA_E_TotalAmount_NAME = "TotalAmount"; + const string FACTURA_E_TotalOutstandingAmount_NAME = "TotalOutstandingAmount"; + const string FACTURA_E_InvoiceCurrencyCode_NAME = "InvoiceCurrencyCode"; + + const string FACTURA_E_PARTES_NAME = "Parties"; + const string FACTURA_E_LIN_FACTURA_NAME = "Invoices"; + + //direccion + const string FACTURA_E_Address_NAME = "Address"; + const string FACTURA_E_PostCode_NAME = "PostCode"; + const string FACTURA_E_Town_NAME = "Town"; + const string FACTURA_E_Province_NAME = "Province"; + const string FACTURA_E_CountryCode_NAME = "CountryCode"; + + //TaxIdentification + const string FACTURA_E_PersonTypeCode_NAME = "PersonTypeCode"; + const string FACTURA_E_TaxIdentificationNumber_NAME = "TaxIdentificationNumber"; + //TaxIdentification + const string FACTURA_E_CorporateName_NAME = "CorporateName"; + const string FACTURA_E_TradeName_NAME = "TradeName"; + const string FACTURA_E_AddressInSpain_NAME = "AddressInSpain"; + + //centro administrativo + const string FACTURA_E_CentreCode_NAME = "CentreCode"; + const string FACTURA_E_RoleTypeCode_NAME = "RoleTypeCode"; + const string FACTURA_E_Name_NAME = "Name"; + const string FACTURA_E_CentreDescription_NAME = "CentreDescription"; + + //SellerParty + const string FACTURA_E_SellerParty_NAME = "SellerParty"; + //BuyerParty + const string FACTURA_E_BuyerParty_NAME = "BuyerParty"; + const string FACTURA_E_AdministrativeCentres_NAME = "AdministrativeCentres"; + const string FACTURA_E_AdministrativeCentre_NAME = "AdministrativeCentre"; + + + + //TaxIdentification + const string FACTURA_E_TaxIdentification_NAME = "TaxIdentification"; + + //LegalEntity + const string FACTURA_E_LegalEntity_NAME = "LegalEntity"; + + //datos contacto + const string FACTURA_E_ContactDetails_NAME = "ContactDetails"; + const string FACTURA_E_Telephone_NAME = "Telephone"; + const string FACTURA_E_TeleFax_NAME = "TeleFax"; + const string FACTURA_E_WebAddress_NAME = "WebAddress"; + const string FACTURA_E_ElectronicMail_NAME = "ElectronicMail"; + + //Invoice + const string FACTURA_E_Invoice_NAME = "Invoice"; + + const string FACTURA_E_InvoiceHeader_NAME = "InvoiceHeader"; + const string FACTURA_E_InvoiceNumber_NAME = "InvoiceNumber"; + const string FACTURA_E_InvoiceSeriesCode_NAME = "InvoiceSeriesCode"; + const string FACTURA_E_InvoiceClass_NAME = "InvoiceClass"; + + const string FACTURA_E_Corrective_NAME = "Corrective"; + const string FACTURA_E_ReasonDescription_NAME = "ReasonDescription"; + const string FACTURA_E_CorrectionMethodDescription_NAME = "CorrectionMethodDescription"; + const string FACTURA_E_AdditionalReasonDescription_NAME = "AdditionalReasonDescription"; + const string FACTURA_E_TaxPeriod_NAME = "TaxPeriod"; + const string FACTURA_E_StartDate_NAME = "StartDate"; + const string FACTURA_E_EndDate_NAME = "EndDate"; + + const string FACTURA_E_InvoiceIssueData_NAME = "InvoiceIssueData"; + const string FACTURA_E_InvoicingPeriod_NAME = "InvoicingPeriod"; + const string FACTURA_E_IssueDate_NAME = "IssueDate"; + const string FACTURA_E_TaxesOutputs_NAME = "TaxesOutputs"; + + //impuestos + const string FACTURA_E_Tax_NAME = "Tax"; + const string FACTURA_E_TaxTypeCode_NAME = "TaxTypeCode"; + const string FACTURA_E_TaxRate_NAME = "TaxRate"; + const string FACTURA_E_TaxableBase_NAME = "TaxableBase"; + //const string FACTURA_E_TotalAmount_NAME = "TotalAmount"; + const string FACTURA_E_TaxAmount_NAME = "TaxAmount"; + + //total (InvoiceTotals) + const string FACTURA_E_InvoiceTotals_NAME = "InvoiceTotals"; + + const string FACTURA_E_TotalGrossAmount_NAME = "TotalGrossAmount"; + const string FACTURA_E_TotalGeneralDiscounts_NAME = "TotalGeneralDiscounts"; + const string FACTURA_E_TotalGrossAmountBeforeTaxes_NAME = "TotalGrossAmountBeforeTaxes"; + const string FACTURA_E_TotalTaxOutputs_NAME = "TotalTaxOutputs"; + //const string FACTURA_E_TotalTaxesWithheld_NAME = "TotalTaxesWithheld"; + //const string FACTURA_E_TotalOutstandingAmount_NAME = "TotalOutstandingAmount"; + const string FACTURA_E_TotalPaymentsOnAccount_NAME = "TotalPaymentsOnAccount"; + const string FACTURA_E_TotalExecutableAmount_NAME = "TotalExecutableAmount"; + //const string FACTURA_E_InvoiceTotals_NAME = "InvoiceTotals"; + + //items + const string FACTURA_E_Items_NAME = "Items"; + const string FACTURA_E_InvoiceLine_NAME = "InvoiceLine"; + const string FACTURA_E_DeliveryNote_NAME = "DeliveryNote"; + const string FACTURA_E_DeliveryNoteNumber = "DeliveryNoteNumber"; + const string FACTURA_E_DeliveryNoteDate_NAME = "DeliveryNoteDate"; + const string FACTURA_E_ItemDescription_NAME = "ItemDescription"; + const string FACTURA_E_Quantity_NAME = "Quantity"; + const string FACTURA_E_UnitPriceWithoutTax_NAME = "UnitPriceWithoutTax"; + const string FACTURA_E_TotalCost_NAME = "TotalCost"; + + const string FACTURA_E_DiscountsAndRebates_NAME = "DiscountsAndRebates"; + const string FACTURA_E_Discount_NAME = "Discount"; + const string FACTURA_E_DiscontReason_NAME = "DiscontReason"; + const string FACTURA_E_DiscountRate_NAME = "DiscountRate"; + const string FACTURA_E_DiscountAmount_NAME = "DiscountAmount"; + + const string FACTURA_E_GrossAmount_NAME = "GrossAmount"; + //const string FACTURA_E_TaxesOutputs_NAME = "TaxesOutputs"; + const string FACTURA_E_TransactionDate_NAME = "TransactionDate"; + const string FACTURA_E_AdditionalLineItemInformation_NAME = "AdditionalLineItemInformation"; + const string FACTURA_E_ArticleCode_NAME = "ArticleCode"; + + + + + + + + #endregion #region Constructores public INTERNO_Factura_e_Modelo() { Moneda = "EUR"; + Vendedor = new INTERNO_Vendedor_Factura_E_modelo(); + Comprador = new INTERNO_Comprador_Factura_E_modelo(); } #endregion #region Metodos - + string importarXML(string path) + { + error = ""; + string res = null; + XmlDocument doc = new XmlDocument(); + try + { + doc.Load(path); + //busca incio factura e + foreach (XmlNode node in doc.DocumentElement.ChildNodes) + { + if(node.Name!=null && node.Name== FACTURA_E_NAME) + { + res= leeXML(node); + if(res!=null) + { + res = "Error al importar XML: " + path +" Error: " +res; + } + return res; + } + } + res = "Error al importar XML: " + path + " Error: Formato de archivo no valido."; + } + catch (Exception e) + { + res = "Error al importar XML: " + path + " Error: " + e.Message; + } + + + + return res; + } + + string exportarXML(string path) + { + error = ""; + string res = null; + XmlDocument doc = new XmlDocument(); + try + { + XmlDeclaration xmlDeclaration = doc.CreateXmlDeclaration("1.0", "UTF-8", null); + XmlElement root = doc.DocumentElement; + doc.InsertBefore(xmlDeclaration, root); + XmlElement factura = doc.CreateElement(string.Empty, FACTURA_E_NAME, string.Empty); + //res = grabaXML(factura); + if (res != null) + { + res = "Error al grabar XML: " + path + " Error: " + res; + } + doc.AppendChild(factura); + doc.Save(path); + } + catch (Exception e) + { + res = "Error al exportar XML: " + path + " Error: " + e.Message; + } + + + + return res; + } #endregion + #region LecturaXML + private string leeXML(XmlNode factura) + { + string res = null; + bool cab, part, lin; + cab = part = lin = false; + + foreach (XmlNode node in factura.ChildNodes) + { + if (node.Name == null) + continue; + string name = node.Name.ToUpper(); + if (node.Name == FACTURA_E_HEADER_NAME.ToUpper()) + { + if(cab) + return "Estructura de archivo no valida, tiene dos " + FACTURA_E_HEADER_NAME; + + cab = true; + res = leeCabecera(node); + if (res != null) + return res; + } + else if (node.Name == FACTURA_E_PARTES_NAME.ToUpper()) + { + if (part) + return "Estructura de archivo no valida, tiene dos " + FACTURA_E_HEADER_NAME; + + part = true; + res = leePartesInvolucradas(node); + if (res != null) + return res; + } + else if (node.Name == FACTURA_E_LIN_FACTURA_NAME.ToUpper()) + { + if (lin) + return "Estructura de archivo no valida, tiene dos " + FACTURA_E_HEADER_NAME; + + lin = true; + res = leeLineasFactura(node); + if (res != null) + return res; + } + if (lin && part && cab) + break; + } + + if (!cab) + res = "No se ha encontrado " + FACTURA_E_HEADER_NAME; + if (!part) + res = " No se ha encontrado " + FACTURA_E_PARTES_NAME; + if (!lin) + res = " No se ha encontrado " + FACTURA_E_LIN_FACTURA_NAME; + return res; + } + + private string leeCabecera(XmlNode cab) + { + string res = null; + //version + var str = getText(cab,FACTURA_E_VERSION_NAME); + if (str == null|| str != FACTURA_E_VERSION) + return "Version no compatible" + error; + //id BatchIdentifier + str= getText(cab, FACTURA_E_BATCH_NAME+"/"+ FACTURA_E_BATCH_ID_NAME); + if (str == null) + return "Estructura invalida" + error; + Identificador = str; + float? dat = getFloat(cab, FACTURA_E_BATCH_NAME + "/" + FACTURA_E_TotalInvoicesAmount_NAME+ "/"+ FACTURA_E_TotalAmount_NAME); + if (dat == null) + return "Estructura invalida" + error; + TotalFactura = dat.Value; + + dat = getFloat(cab, FACTURA_E_BATCH_NAME + "/" + FACTURA_E_TotalOutstandingAmount_NAME + "/" + FACTURA_E_TotalAmount_NAME); + if (dat == null) + return "Estructura invalida" + error; + TotalPendiente = dat.Value; + //moneda + str = getText(cab, FACTURA_E_BATCH_NAME + "/" + FACTURA_E_InvoiceCurrencyCode_NAME); + if (str == null) + return "Estructura invalida" + error; + Moneda = str; + return res; + } + private string leePartesInvolucradas(XmlNode partes) + { + //vendedor--------------------------------------------------- + Vendedor = new INTERNO_Vendedor_Factura_E_modelo(); + string res = null; + var n = getNode(partes, FACTURA_E_SellerParty_NAME); + if (n == null) + return "Estructura invalida" + error; + + res = getTaxIdentification(Vendedor, n, FACTURA_E_TaxIdentification_NAME); + if (res!=null) + return res; + + res = getLegalEntity(Vendedor, n, FACTURA_E_LegalEntity_NAME); + if (res != null) + return res; + res = geteContacto(Vendedor, n, FACTURA_E_LegalEntity_NAME+"/"+ FACTURA_E_ContactDetails_NAME); + if (res != null) + return res; + //comprador---------------------------------------------------- + Comprador = new INTERNO_Comprador_Factura_E_modelo(); + n = getNode(partes, FACTURA_E_BuyerParty_NAME); + if (n == null) + return "Estructura invalida" + error; + res = getTaxIdentification(Vendedor, n, FACTURA_E_TaxIdentification_NAME); + if (res != null) + return res; + + res = getLegalEntity(Vendedor, n, FACTURA_E_LegalEntity_NAME); + if (res != null) + return res; + + //centros administrativos + n = getNode(partes, FACTURA_E_AdministrativeCentres_NAME); + if (n == null) + error = null; + var nodes = getNodes(n, FACTURA_E_AdministrativeCentre_NAME); + if (nodes!=null) + { + var nn = nodes.Count; + if(nn>0) + { + Comprador.Centros = new INTERNO_CentroAdministrativo_Factura_E_Modelo[nn]; + for(int i=0; i