(factura-e-lee-xml)

Se crea la funcion de inportacion en xml
develop
Gerardo 2023-08-09 17:13:03 +02:00
parent e946d3dae9
commit 353932e811
7 changed files with 886 additions and 23 deletions

View File

@ -115,6 +115,7 @@
<Compile Include="Modelos_Factura_E\INTERNO_Correcciones_Factura_E_Modelo.cs" /> <Compile Include="Modelos_Factura_E\INTERNO_Correcciones_Factura_E_Modelo.cs" />
<Compile Include="Modelos_Factura_E\INTERNO_Direccion_Factura_E_Modelo.cs" /> <Compile Include="Modelos_Factura_E\INTERNO_Direccion_Factura_E_Modelo.cs" />
<Compile Include="Modelos_Factura_E\INTERNO_Entidad_Factura_E_Modelo.cs" /> <Compile Include="Modelos_Factura_E\INTERNO_Entidad_Factura_E_Modelo.cs" />
<Compile Include="Modelos_Factura_E\INTERNO_Impuestos_Factura_E_modelo.cs" />
<Compile Include="Modelos_Factura_E\INTERNO_Item_Factura_E_modelo.cs" /> <Compile Include="Modelos_Factura_E\INTERNO_Item_Factura_E_modelo.cs" />
<Compile Include="Modelos_Factura_E\INTERNO_Vendedor_Factura_E_Modelo.cs" /> <Compile Include="Modelos_Factura_E\INTERNO_Vendedor_Factura_E_Modelo.cs" />
<Compile Include="Modelos_Factura_E\INTERNO_Factura_e_Modelo.cs" /> <Compile Include="Modelos_Factura_E\INTERNO_Factura_e_Modelo.cs" />

View File

@ -12,7 +12,8 @@ namespace Exferia_Aplicacion.Modelos_Factura_E
public string Role { get; set;} public string Role { get; set;}
public string Encargado { get; set; } public string Encargado { get; set; }
public string Descripcion { get; set; } public string Descripcion { get; set; }
INTERNO_CentroAdministrativo_Factura_E_Modelo()
public INTERNO_CentroAdministrativo_Factura_E_Modelo()
{ {
} }

View File

@ -9,12 +9,12 @@ namespace Exferia_Aplicacion.Modelos_Factura_E
public class INTERNO_Correcciones_Factura_E_Modelo public class INTERNO_Correcciones_Factura_E_Modelo
{ {
public int NumeroFactura { get; set; }//numero factura que rectifica public int NumeroFactura { get; set; }//numero factura que rectifica
public int serie { get; set; }//serie de la factura que rectifica public String SerieDelegacion { get; set; }//serie de la factura que rectifica
public string RazonCode { get; set; } public string RazonCode { get; set; }//(ReasonDescription)
public DateTime Inicio { get; set; } public DateTime Inicio { get; set; }
public DateTime Fin { get; set; } public DateTime Fin { get; set; }
public string RazonCorreccion { get; set; } public string RazonCorreccion { get; set; }//CorrectionMethodDescription
public string Observaciones { get; set; } public string Observaciones { get; set; }//AdditionalReasonDescription
} }
} }

View File

@ -1,22 +1,24 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Xml;
namespace Exferia_Aplicacion.Modelos_Factura_E namespace Exferia_Aplicacion.Modelos_Factura_E
{ {
public class INTERNO_Factura_e_Modelo public class INTERNO_Factura_e_Modelo
{ {
private string error;
#region region Propiedades #region region Propiedades
//datos de las partes implicadas //datos de las partes implicadas
public INTERNO_Vendedor_Factura_E_modelo Vendedor { get; set; } 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 //datos factura
public string Identificador { get; set; } public string Identificador { get; set; }//BatchIdentifier
public string Moneda { get; set;} public string Moneda { get; set;}
public int NumeroFactura { get; set;} public int NumeroFactura { get; set;}
public String SerieDelegacion { get; set; } public String SerieDelegacion { get; set; }
@ -26,33 +28,880 @@ namespace Exferia_Aplicacion.Modelos_Factura_E
public DateTime PeriodoInicio { get; set; } public DateTime PeriodoInicio { get; set; }
public DateTime PeriodoFin { get; set; } public DateTime PeriodoFin { get; set; }
//impuestos---------------------------------------- //impuestos----------------------------------------
public int ImpuestosTipo { get; set; }
public double ImpuestosPorcentaje { get; set; } INTERNO_Impuestos_Factura_E_modelo Impuesto { get; set; }
public double ImpuestosBase { get; set; }
public double ImpuestosImporte { get; set; }
//resumen----------------------------------------- //resumen-----------------------------------------
public double TotalBruto { get; set; } public double TotalBruto { get; set; }
public double TotalDescuento { get; set; } public double TotalDescuento { get; set; }
public double TotalBase { get; set; } public double TotalBase { get; set; }
public double Totalimpuestos { get; set; } public double TotalImpuestos { get; set; }
public float TotalFactura { get; set; } public float TotalFactura { get; set; }
public float TotalPendiente { get; set; } public float TotalPendiente { get; set; }
public float TotalEjecutable { get; set; }
public float TotalAnticipo { get; set; } public float TotalAnticipo { get; set; }
//elementos factura------------------------------ //elementos factura------------------------------
INTERNO_Item_Factura_E_modelo[] Items { get; set; } 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 #endregion
#region Constructores #region Constructores
public INTERNO_Factura_e_Modelo() public INTERNO_Factura_e_Modelo()
{ {
Moneda = "EUR"; Moneda = "EUR";
Vendedor = new INTERNO_Vendedor_Factura_E_modelo();
Comprador = new INTERNO_Comprador_Factura_E_modelo();
} }
#endregion #endregion
#region Metodos #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 #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<nn; i++)
{
Comprador.Centros[i] = new INTERNO_CentroAdministrativo_Factura_E_Modelo();
res = getAdministrativeCentre(Comprador.Centros[i], nodes.Item(i));
if (res != null)
return res;
}
}
}
return res;
}
private string leeLineasFactura(XmlNode fact)
{
string res = null;
var n = getNode(fact, FACTURA_E_Invoice_NAME);
if (n == null)
return "Estructura invalida" + error;
//cabecera-----------------------------------------------------------------------
int? i = getInt(n, FACTURA_E_InvoiceHeader_NAME + "/" + FACTURA_E_InvoiceNumber_NAME);
if (i == null)
return "Estructura invalida" + error;
NumeroFactura = i.Value;
string str = getText(n, FACTURA_E_InvoiceHeader_NAME + "/" + FACTURA_E_InvoiceSeriesCode_NAME);
if (str == null)
return "Estructura invalida" + error;
SerieDelegacion = str;
str = getText(n, FACTURA_E_InvoiceHeader_NAME + "/" + FACTURA_E_InvoiceClass_NAME);
if (str == null)
return "Estructura invalida" + error;
FacturaOriginal = str == "OO";
if (!FacturaOriginal)
{
var correccion = getNode(n, FACTURA_E_InvoiceHeader_NAME + "/" + FACTURA_E_Corrective_NAME);
if (correccion == null)
return "Estructura invalida " + FACTURA_E_Corrective_NAME + " " + error;
Correcciones = new INTERNO_Correcciones_Factura_E_Modelo();
res = getCorreccion(Correcciones, correccion);
if (res != null)
return res;
}
else
Correcciones = null;
//InvoiceIssueData
DateTime? time = getTime(n, FACTURA_E_InvoiceIssueData_NAME + "/" + FACTURA_E_IssueDate_NAME);
if (time == null)
return "Estructura invalida" + error;
Fecha = time.Value;
time = getTime(n, FACTURA_E_InvoiceIssueData_NAME + "/" + FACTURA_E_InvoicingPeriod_NAME+"/"+ FACTURA_E_StartDate_NAME);
if (time == null)
return "Estructura invalida" + error;
PeriodoInicio = time.Value;
time = getTime(n, FACTURA_E_InvoiceIssueData_NAME + "/" + FACTURA_E_InvoicingPeriod_NAME+ "/" + FACTURA_E_EndDate_NAME);
if (time == null)
return "Estructura invalida" + error;
PeriodoFin = time.Value;
//TaxesOutputs
Impuesto = new INTERNO_Impuestos_Factura_E_modelo();
res = getImpuestos(Impuesto, n, FACTURA_E_TaxesOutputs_NAME + "/" + FACTURA_E_Tax_NAME);
if (res != null)
return res;
//InvoiceTotals
res = getTotal(n, FACTURA_E_InvoiceTotals_NAME);
if (res != null)
return res;
//Items
var items = getNodes(n, FACTURA_E_Items_NAME + "/" + FACTURA_E_InvoiceLine_NAME);
if (items == null)
return "Estructura invalida, sin items: " + error;
var nn = items.Count;
if (nn <= 0)
return "Estructura invalida, sin items.";
Items = new INTERNO_Item_Factura_E_modelo[nn];
for (int ii=0; ii<nn; ii++)
{
Items[ii] = new INTERNO_Item_Factura_E_modelo();
res = getItem(Items[ii], items[ii]);
if (res != null)
return res;
}
return res;
}
private string getItem(INTERNO_Item_Factura_E_modelo dat, XmlNode node)
{
string str = getText(node, FACTURA_E_DeliveryNote_NAME+"/"+ FACTURA_E_DeliveryNoteNumber);
if (str == null)
return "Estructura invalida" + error;
dat.Codigo = str;
DateTime? time = getTime(node, FACTURA_E_DeliveryNote_NAME + "/" + FACTURA_E_DeliveryNoteDate_NAME);
if (time == null)
return "Estructura invalida" + error;
dat.FechaAlbaran = time.Value;
str = getText(node, FACTURA_E_ItemDescription_NAME);
if (str == null)
return "Estructura invalida" + error;
dat.Descripcion = str;
int? i = getInt(node, FACTURA_E_Quantity_NAME);
if (i == null)
return "Estructura invalida" + error;
dat.Cantidad = i.Value;
float? f = getFloat(node, FACTURA_E_UnitPriceWithoutTax_NAME);
if (f == null)
return "Estructura invalida" + error;
dat.Precio = f.Value;
f = getFloat(node, FACTURA_E_TotalCost_NAME);
if (f == null)
return "Estructura invalida" + error;
dat.Total = f.Value;
str = getText(node, FACTURA_E_DiscountsAndRebates_NAME+"/"+ FACTURA_E_Discount_NAME + "/"+ FACTURA_E_DiscontReason_NAME);
if (str == null)
return "Estructura invalida" + error;
dat.DescuentoRazon = str;
f = getFloat(node, FACTURA_E_DiscountsAndRebates_NAME + "/" + FACTURA_E_Discount_NAME + "/" + FACTURA_E_DiscountRate_NAME);
if (f == null)
return "Estructura invalida" + error;
dat.DescuentoPorcentaje = f.Value;
f = getFloat(node, FACTURA_E_DiscountsAndRebates_NAME + "/" + FACTURA_E_Discount_NAME + "/" + FACTURA_E_DiscountAmount_NAME);
if (f == null)
return "Estructura invalida" + error;
dat.Descuentoimporte = f.Value;
f = getFloat(node, FACTURA_E_GrossAmount_NAME);
if (str == null)
return "Estructura invalida" + error;
dat.ImporteBruto = f.Value;
var res = getImpuestos(dat,node, FACTURA_E_TaxesOutputs_NAME + "/"+FACTURA_E_Tax_NAME);
if (res != null)
return res;
time = getTime(node, FACTURA_E_TransactionDate_NAME);
if (time == null)
return "Estructura invalida" + error;
dat.FechaAlbaran = time.Value;
str = getText(node, FACTURA_E_AdditionalLineItemInformation_NAME);
if (time == null)
return "Estructura invalida" + error;
dat.Adicional = str;
str = getText(node, FACTURA_E_ArticleCode_NAME);
if (time == null)
return "Estructura invalida" + error;
dat.CodigoArticulo = str;
return null;
}
private string getTotal( XmlNode node, string xpath)
{
var n = getNode(node, xpath);
if (n == null)
return error;
return getTotal(n);
}
private string getTotal( XmlNode node)
{
float? f = getFloat(node, FACTURA_E_TotalGrossAmount_NAME);
if (f == null)
return "Estructura invalida" + error;
TotalBruto = f.Value;
f = getFloat(node, FACTURA_E_TotalGeneralDiscounts_NAME);
if (f == null)
return "Estructura invalida" + error;
TotalDescuento = f.Value;
f = getFloat(node, FACTURA_E_TotalGrossAmountBeforeTaxes_NAME);
if (f == null)
return "Estructura invalida" + error;
TotalBase = f.Value;
f = getFloat(node, FACTURA_E_TotalTaxOutputs_NAME);
if (f == null)
return "Estructura invalida" + error;
TotalImpuestos = f.Value;
f = getFloat(node, FACTURA_E_InvoiceTotals_NAME);
if (f == null)
return "Estructura invalida" + error;
if (TotalFactura == f.Value)
return "Valores de total factura no coinciden: " + FACTURA_E_InvoiceTotals_NAME;
f = getFloat(node, FACTURA_E_TotalOutstandingAmount_NAME);
if (f == null)
return "Estructura invalida" + error;
TotalPendiente = f.Value;
f = getFloat(node, FACTURA_E_TotalPaymentsOnAccount_NAME);
if (f == null)
return "Estructura invalida" + error;
TotalAnticipo = f.Value;
f = getFloat(node, FACTURA_E_TotalExecutableAmount_NAME);
if (f == null)
return "Estructura invalida" + error;
TotalEjecutable = f.Value;
return null;
}
private string getImpuestos(INTERNO_Impuestos_Factura_E_modelo dat, XmlNode node, string xpath)
{
var n = getNode(node, xpath);
if (n == null)
return error;
return getImpuestos(dat, n);
}
private string getImpuestos(INTERNO_Impuestos_Factura_E_modelo dat, XmlNode node)
{
int? i = getInt(node, FACTURA_E_TaxTypeCode_NAME);
if (i == null)
return "Estructura invalida" + error;
dat.Tipo = i.Value;
float? f = getFloat(node, FACTURA_E_TaxRate_NAME);
if (f == null)
return "Estructura invalida" + error;
dat.Porcentaje = f.Value;
f = getFloat(node, FACTURA_E_TaxableBase_NAME+"/"+ FACTURA_E_TotalAmount_NAME);
if (f == null)
return "Estructura invalida" + error;
dat.Base = f.Value;
f = getFloat(node, FACTURA_E_TaxAmount_NAME + "/" + FACTURA_E_TotalAmount_NAME);
if (f == null)
return "Estructura invalida" + error;
dat.Importe = f.Value;
return null;
}
private string getCorreccion(INTERNO_Correcciones_Factura_E_Modelo dat, XmlNode node)
{
int? i = getInt(node, FACTURA_E_InvoiceNumber_NAME);
if (i == null)
return "Estructura invalida" + error;
dat.NumeroFactura = i.Value;
string str = getText(node, FACTURA_E_InvoiceSeriesCode_NAME);
if (str == null)
return "Estructura invalida" + error;
dat.SerieDelegacion = str;
str = getText(node, FACTURA_E_ReasonDescription_NAME);
if (str == null)
return "Estructura invalida" + error;
dat.RazonCode = str;
str = getText(node, FACTURA_E_CorrectionMethodDescription_NAME);
if (str == null)
return "Estructura invalida" + error;
dat.RazonCorreccion = str;
str = getText(node, FACTURA_E_AdditionalReasonDescription_NAME);
if (str == null)
return "Estructura invalida" + error;
dat.Observaciones = str;
DateTime? time = getTime(node, FACTURA_E_TaxPeriod_NAME+"/"+ FACTURA_E_StartDate_NAME);
if (time == null)
return "Estructura invalida" + error;
dat.Inicio = time.Value;
time = getTime(node, FACTURA_E_TaxPeriod_NAME + "/" + FACTURA_E_EndDate_NAME);
if (time == null)
return "Estructura invalida" + error;
dat.Fin = time.Value;
return null;
}
private string getTaxIdentification(INTERNO_Entidad_Factura_E_Modelo dat, XmlNode node, string xpath)
{
var n = getNode(node, xpath);
if (n == null)
return error;
return getTaxIdentification(dat, n);
}
private string getTaxIdentification(INTERNO_Entidad_Factura_E_Modelo dat, XmlNode node)
{
string res = null;
string str = getText(node, FACTURA_E_PersonTypeCode_NAME);
if (str == null)
return "Estructura invalida" + error;
dat.Tipo = str;
str = getText(node, FACTURA_E_TaxIdentificationNumber_NAME);
if (str == null)
return "Estructura invalida" + error;
dat.IdImpuestos = str;
return null;
}
private string getLegalEntity(INTERNO_Entidad_Factura_E_Modelo dat, XmlNode node, string xpath)
{
var n = getNode(node, xpath);
if (n == null)
return error;
return getLegalEntity(dat, n);
}
private string getLegalEntity(INTERNO_Entidad_Factura_E_Modelo dat, XmlNode node)
{
string str = getText(node, FACTURA_E_CorporateName_NAME);
if (str == null)
return "Estructura invalida" + error;
dat.RazonSocial = str;
str = getText(node, FACTURA_E_TradeName_NAME);
if (str == null)
return "Estructura invalida" + error;
dat.NombreComercial = str;
return geteDireccion(dat, node, FACTURA_E_AddressInSpain_NAME);
}
private string getAdministrativeCentre(INTERNO_CentroAdministrativo_Factura_E_Modelo dat, XmlNode node, string xpath)
{
var n = getNode(node, xpath);
if (n == null)
return error;
return getAdministrativeCentre(dat, n);
}
private string getAdministrativeCentre(INTERNO_CentroAdministrativo_Factura_E_Modelo dat, XmlNode node)
{
string str = getText(node, FACTURA_E_CentreCode_NAME);
if (str == null)
return "Estructura invalida" + error;
dat.Codigo = str;
str = getText(node, FACTURA_E_RoleTypeCode_NAME);
if (str == null)
return "Estructura invalida" + error;
dat.Role = str;
str = getText(node, FACTURA_E_Name_NAME);
if (str == null)
return "Estructura invalida" + error;
dat.Encargado = str;
str = getText(node, FACTURA_E_CentreDescription_NAME);
if (str == null)
return "Estructura invalida" + error;
dat.Descripcion = str;
return geteDireccion(dat, node, FACTURA_E_AddressInSpain_NAME);
}
private string geteDireccion(INTERNO_Direccion_Factura_E_Modelo dat, XmlNode node, string xpath)
{
var n = getNode(node, xpath);
if (n == null)
return error;
return geteDireccion(dat, n);
}
private string geteDireccion(INTERNO_Direccion_Factura_E_Modelo dat, XmlNode node)
{
string str = getText(node, FACTURA_E_Address_NAME);
if (str == null)
return "Estructura invalida" + error;
dat.Direccion = str;
str = getText(node, FACTURA_E_PostCode_NAME);
if (str == null)
return "Estructura invalida" + error;
dat.CP = str;
str = getText(node, FACTURA_E_Town_NAME);
if (str == null)
return "Estructura invalida" + error;
dat.Poblacion = str;
str = getText(node, FACTURA_E_Province_NAME);
if (str == null)
return "Estructura invalida" + error;
dat.Provincia = str;
str = getText(node, FACTURA_E_CountryCode_NAME);
if (str == null)
return "Estructura invalida" + error;
dat.Pais = str;
return null;
}
private string geteContacto(INTERNO_Direccion_Factura_E_Modelo dat, XmlNode node, string xpath)
{
var n = getNode(node, xpath);
if (n == null)
return error;
return geteContacto(dat, n);
}
private string geteContacto(INTERNO_Direccion_Factura_E_Modelo dat, XmlNode node)
{
string str = getText(node, FACTURA_E_Telephone_NAME);
if (str == null)
return "Estructura invalida" + error;
dat.Tlf = str;
str = getText(node, FACTURA_E_TeleFax_NAME);
if (str == null)
return "Estructura invalida" + error;
dat.Fax = str;
str = getText(node, FACTURA_E_WebAddress_NAME);
if (str == null)
return "Estructura invalida" + error;
dat.Web = str;
str = getText(node, FACTURA_E_ElectronicMail_NAME);
if (str == null)
return "Estructura invalida" + error;
dat.Email = str;
return null;
}
#endregion
#region funciones comunes
private XmlNodeList getNodes(XmlNode node, string xpath)
{
XmlNodeList res = null;
try
{
res = node.SelectNodes(xpath);
}
catch (Exception e)
{
error = e.Message;
res = null;
}
if (res == null)
error = "No encontrado nodos: " + xpath + " " + error;
return res;
}
private XmlNode getNode(XmlNode node, string xpath)
{
XmlNode res = null;
try
{
res = node.SelectSingleNode(xpath);
}
catch (Exception e)
{
error = e.Message;
res = null;
}
if (res == null)
error = "No encontrado nodo: " + xpath + " " + error;
return res;
}
private string getText(XmlNode node, string xpath)
{
string res = null;
var n = getNode(node, xpath);
if (n != null && n.InnerText != null)
res = n.InnerText;
if (res == null)
error = "Texto no encontrado en: " + xpath + " " + error;
return res;
}
private float? getFloat(XmlNode node, string xpath)
{
float? res = null;
var str = getText(node, xpath);
if(str!=null)
{
try
{
res = float.Parse(str);
}
catch
{
error = "El valor de " + xpath + " no es numerico " + error;
res = null;
}
}
return res;
}
private int? getInt(XmlNode node, string xpath)
{
int? res = null;
var str = getText(node, xpath);
if (str != null)
{
try
{
res = int.Parse(str);
}
catch
{
error = "El valor de " + xpath + " no es numerico " + error;
res = null;
}
}
return res;
}
private DateTime? getTime(XmlNode node, string xpath)
{
DateTime? res = null;
var str = getText(node, xpath);
if (str != null)
{
try
{
res = DateTime.ParseExact(str, @"yyyy-MM-dd\THH:mm:ss.fff\Z",
CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal);
}
catch
{
error = "El valor de " + xpath + " no es de tipo datetime " + error;
res = null;
}
}
return res;
}
#endregion
} }
} }

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Exferia_Aplicacion.Modelos_Factura_E
{
public class INTERNO_Impuestos_Factura_E_modelo
{
public double Porcentaje { get; set; }
public int Tipo { get; set; }
public double Base { get; set; }
public double Importe { get; set; }
}
}

View File

@ -6,9 +6,9 @@ using System.Threading.Tasks;
namespace Exferia_Aplicacion.Modelos_Factura_E namespace Exferia_Aplicacion.Modelos_Factura_E
{ {
public class INTERNO_Item_Factura_E_modelo public class INTERNO_Item_Factura_E_modelo: INTERNO_Impuestos_Factura_E_modelo
{ {
public string Codigo { get; set; } public string Codigo { get; set; }//(DeliveryNoteNumber)
public string CodigoArticulo { get; set; } public string CodigoArticulo { get; set; }
public DateTime Fecha { get; set; } public DateTime Fecha { get; set; }
@ -21,11 +21,7 @@ namespace Exferia_Aplicacion.Modelos_Factura_E
public double Descuentoimporte { get; set; } public double Descuentoimporte { get; set; }
public double ImporteBruto { get; set; }//despues de descuentos public double ImporteBruto { get; set; }//despues de descuentos
public double ImpuestosPorcentaje { get; set; }
public int ImpuestosTipo { get; set; }
public double ImpuestosBase { get; set; }
public double ImpuestosImporte { get; set; }
public string Adicional { get; set; } public string Adicional { get; set; }
public DateTime FechaAlbaran { get; set; }
} }
} }

View File

@ -10,7 +10,7 @@ namespace Exferia_Aplicacion.Modelos_Factura_E
{ {
INTERNO_Vendedor_Factura_E_modelo() public INTERNO_Vendedor_Factura_E_modelo()
{ {
} }