parent
353932e811
commit
1919e5ed01
|
|
@ -49,12 +49,24 @@ namespace Exferia_Aplicacion.Modelos_Factura_E
|
||||||
const string FACTURA_E_HEADER_NAME = "FileHeader";
|
const string FACTURA_E_HEADER_NAME = "FileHeader";
|
||||||
const string FACTURA_E_VERSION_NAME = "SchemaVersion";
|
const string FACTURA_E_VERSION_NAME = "SchemaVersion";
|
||||||
const string FACTURA_E_VERSION = "3.2.1";
|
const string FACTURA_E_VERSION = "3.2.1";
|
||||||
|
const string FACTURA_E_Modality_NAME = "Modality";
|
||||||
|
const string FACTURA_E_Modality= "I";
|
||||||
|
const string FACTURA_E_InvoiceIssuerType_NAME = "InvoiceIssuerType";
|
||||||
|
const string FACTURA_E_InvoiceIssuerType = "EM";
|
||||||
|
|
||||||
const string FACTURA_E_BATCH_NAME = "Batch";
|
const string FACTURA_E_BATCH_NAME = "Batch";
|
||||||
const string FACTURA_E_BATCH_ID_NAME = "BatchIdentifier";
|
const string FACTURA_E_BATCH_ID_NAME = "BatchIdentifier";
|
||||||
|
|
||||||
|
const string FACTURA_E_InvoicesCount_NAME = "InvoicesCount";
|
||||||
|
const string FACTURA_E_InvoicesCount = "1";
|
||||||
|
|
||||||
const string FACTURA_E_TotalInvoicesAmount_NAME = "TotalInvoicesAmount";
|
const string FACTURA_E_TotalInvoicesAmount_NAME = "TotalInvoicesAmount";
|
||||||
const string FACTURA_E_TotalAmount_NAME = "TotalAmount";
|
const string FACTURA_E_TotalAmount_NAME = "TotalAmount";
|
||||||
const string FACTURA_E_TotalOutstandingAmount_NAME = "TotalOutstandingAmount";
|
const string FACTURA_E_TotalOutstandingAmount_NAME = "TotalOutstandingAmount";
|
||||||
|
|
||||||
const string FACTURA_E_InvoiceCurrencyCode_NAME = "InvoiceCurrencyCode";
|
const string FACTURA_E_InvoiceCurrencyCode_NAME = "InvoiceCurrencyCode";
|
||||||
|
const string FACTURA_E_InvoiceCurrencyCode = "EUR";
|
||||||
|
|
||||||
|
|
||||||
const string FACTURA_E_PARTES_NAME = "Parties";
|
const string FACTURA_E_PARTES_NAME = "Parties";
|
||||||
const string FACTURA_E_LIN_FACTURA_NAME = "Invoices";
|
const string FACTURA_E_LIN_FACTURA_NAME = "Invoices";
|
||||||
|
|
@ -69,7 +81,10 @@ namespace Exferia_Aplicacion.Modelos_Factura_E
|
||||||
//TaxIdentification
|
//TaxIdentification
|
||||||
const string FACTURA_E_PersonTypeCode_NAME = "PersonTypeCode";
|
const string FACTURA_E_PersonTypeCode_NAME = "PersonTypeCode";
|
||||||
const string FACTURA_E_TaxIdentificationNumber_NAME = "TaxIdentificationNumber";
|
const string FACTURA_E_TaxIdentificationNumber_NAME = "TaxIdentificationNumber";
|
||||||
//TaxIdentification
|
const string FACTURA_E_ResidenceTypeCode_NAME = "ResidenceTypeCode";
|
||||||
|
const string FACTURA_E_ResidenceTypeCode = "R";
|
||||||
|
|
||||||
|
|
||||||
const string FACTURA_E_CorporateName_NAME = "CorporateName";
|
const string FACTURA_E_CorporateName_NAME = "CorporateName";
|
||||||
const string FACTURA_E_TradeName_NAME = "TradeName";
|
const string FACTURA_E_TradeName_NAME = "TradeName";
|
||||||
const string FACTURA_E_AddressInSpain_NAME = "AddressInSpain";
|
const string FACTURA_E_AddressInSpain_NAME = "AddressInSpain";
|
||||||
|
|
@ -228,7 +243,7 @@ namespace Exferia_Aplicacion.Modelos_Factura_E
|
||||||
XmlElement root = doc.DocumentElement;
|
XmlElement root = doc.DocumentElement;
|
||||||
doc.InsertBefore(xmlDeclaration, root);
|
doc.InsertBefore(xmlDeclaration, root);
|
||||||
XmlElement factura = doc.CreateElement(string.Empty, FACTURA_E_NAME, string.Empty);
|
XmlElement factura = doc.CreateElement(string.Empty, FACTURA_E_NAME, string.Empty);
|
||||||
//res = grabaXML(factura);
|
res = grabaXML(doc, factura);
|
||||||
if (res != null)
|
if (res != null)
|
||||||
{
|
{
|
||||||
res = "Error al grabar XML: " + path + " Error: " + res;
|
res = "Error al grabar XML: " + path + " Error: " + res;
|
||||||
|
|
@ -246,7 +261,299 @@ namespace Exferia_Aplicacion.Modelos_Factura_E
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
#region GrabaEscrituraXML
|
||||||
|
private string grabaXML(XmlDocument doc, XmlElement factura)
|
||||||
|
{
|
||||||
|
string res = null;
|
||||||
|
bool cab, part, lin;
|
||||||
|
cab = part = lin = false;
|
||||||
|
XmlElement header = doc.CreateElement(string.Empty, FACTURA_E_HEADER_NAME, string.Empty);
|
||||||
|
XmlElement parties = doc.CreateElement(string.Empty, FACTURA_E_PARTES_NAME, string.Empty);
|
||||||
|
XmlElement items = doc.CreateElement(string.Empty, FACTURA_E_LIN_FACTURA_NAME, string.Empty);
|
||||||
|
|
||||||
|
res = grabaCabecera(doc, header);
|
||||||
|
if (res != null)
|
||||||
|
return res;
|
||||||
|
factura.AppendChild(header);
|
||||||
|
|
||||||
|
res = grabaPartesInvolucradas(doc, parties);
|
||||||
|
if (res != null)
|
||||||
|
return res;
|
||||||
|
factura.AppendChild(parties);
|
||||||
|
res = grabaLineasFactura(doc, items);
|
||||||
|
if (res != null)
|
||||||
|
return res;
|
||||||
|
factura.AppendChild(items);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
private string grabaCabecera(XmlDocument doc, XmlElement cab)
|
||||||
|
{
|
||||||
|
string res = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
XmlElement nod = doc.CreateElement(string.Empty, FACTURA_E_VERSION_NAME, string.Empty);
|
||||||
|
nod.InnerText = FACTURA_E_VERSION;
|
||||||
|
cab.AppendChild(nod);
|
||||||
|
|
||||||
|
nod = doc.CreateElement(string.Empty, FACTURA_E_Modality_NAME, string.Empty);
|
||||||
|
nod.InnerText = FACTURA_E_Modality;
|
||||||
|
cab.AppendChild(nod);
|
||||||
|
|
||||||
|
nod = doc.CreateElement(string.Empty, FACTURA_E_InvoiceIssuerType_NAME, string.Empty);
|
||||||
|
nod.InnerText = FACTURA_E_InvoiceIssuerType;
|
||||||
|
cab.AppendChild(nod);
|
||||||
|
|
||||||
|
//batch
|
||||||
|
XmlElement batch = doc.CreateElement(string.Empty, FACTURA_E_BATCH_NAME, string.Empty);
|
||||||
|
|
||||||
|
nod = doc.CreateElement(string.Empty, FACTURA_E_BATCH_ID_NAME, string.Empty);
|
||||||
|
nod.InnerText = Identificador;
|
||||||
|
batch.AppendChild(nod);
|
||||||
|
|
||||||
|
nod = doc.CreateElement(string.Empty, FACTURA_E_InvoicesCount_NAME, string.Empty);
|
||||||
|
nod.InnerText = FACTURA_E_InvoicesCount;
|
||||||
|
batch.AppendChild(nod);
|
||||||
|
|
||||||
|
XmlElement nod2 = doc.CreateElement(string.Empty, FACTURA_E_TotalInvoicesAmount_NAME, string.Empty);
|
||||||
|
nod = doc.CreateElement(string.Empty, FACTURA_E_TotalAmount_NAME, string.Empty);
|
||||||
|
nod.InnerText = TotalFactura.ToString();
|
||||||
|
nod2.AppendChild(nod);
|
||||||
|
batch.AppendChild(nod2);
|
||||||
|
|
||||||
|
nod2 = doc.CreateElement(string.Empty, FACTURA_E_TotalOutstandingAmount_NAME, string.Empty);
|
||||||
|
nod = doc.CreateElement(string.Empty, FACTURA_E_TotalAmount_NAME, string.Empty);
|
||||||
|
nod.InnerText = TotalPendiente.ToString();
|
||||||
|
nod2.AppendChild(nod);
|
||||||
|
batch.AppendChild(nod2);
|
||||||
|
|
||||||
|
nod2 = doc.CreateElement(string.Empty, FACTURA_E_TotalExecutableAmount_NAME, string.Empty);
|
||||||
|
nod = doc.CreateElement(string.Empty, FACTURA_E_TotalAmount_NAME, string.Empty);
|
||||||
|
nod.InnerText = TotalFactura.ToString();
|
||||||
|
nod2.AppendChild(nod);
|
||||||
|
batch.AppendChild(nod2);
|
||||||
|
|
||||||
|
nod = doc.CreateElement(string.Empty, FACTURA_E_InvoiceCurrencyCode_NAME, string.Empty);
|
||||||
|
nod.InnerText = FACTURA_E_InvoiceCurrencyCode;
|
||||||
|
batch.AppendChild(nod);
|
||||||
|
|
||||||
|
cab.AppendChild(batch);
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
res = "Error en " + nameof(grabaCabecera) + ": " + e.Message;
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
private string grabaPartesInvolucradas(XmlDocument doc, XmlElement nodo)
|
||||||
|
{
|
||||||
|
string res = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//SellerParty
|
||||||
|
XmlElement nbase = doc.CreateElement(string.Empty, FACTURA_E_SellerParty_NAME, string.Empty);
|
||||||
|
res = grabaTaxIdentification(Vendedor, doc, nbase);
|
||||||
|
if (res != null)
|
||||||
|
return res;
|
||||||
|
|
||||||
|
res = grabaLegalEntity(Vendedor, doc, nbase, true);
|
||||||
|
if (res != null)
|
||||||
|
return res;
|
||||||
|
nodo.AppendChild(nbase);
|
||||||
|
//comprador
|
||||||
|
nbase = doc.CreateElement(string.Empty, FACTURA_E_BuyerParty_NAME, string.Empty);
|
||||||
|
res = grabaTaxIdentification(Comprador, doc, nbase);
|
||||||
|
if (res != null)
|
||||||
|
return res;
|
||||||
|
//centros administrativos
|
||||||
|
if(Comprador.Centros!=null && Comprador.Centros.Length>0)
|
||||||
|
{
|
||||||
|
XmlElement ncentros = doc.CreateElement(string.Empty, FACTURA_E_AdministrativeCentres_NAME, string.Empty);
|
||||||
|
foreach (var centro in Comprador.Centros)
|
||||||
|
{
|
||||||
|
if (centro == null)
|
||||||
|
continue;
|
||||||
|
res = grabaCentroAdministrativo(centro, doc, ncentros);
|
||||||
|
if (res != null)
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
nbase.AppendChild(ncentros);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
res = grabaLegalEntity(Comprador, doc, nbase);
|
||||||
|
if (res != null)
|
||||||
|
return res;
|
||||||
|
nodo.AppendChild(nbase);
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
res = "Error en " + nameof(grabaPartesInvolucradas) + ": " + e.Message;
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
private string grabaLineasFactura(XmlDocument doc, XmlElement nodo)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private string grabaTaxIdentification(INTERNO_Entidad_Factura_E_Modelo dat, XmlDocument doc, XmlElement nodo)
|
||||||
|
{
|
||||||
|
string res = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
XmlElement taxn = doc.CreateElement(string.Empty, FACTURA_E_TaxIdentification_NAME, string.Empty);
|
||||||
|
|
||||||
|
XmlElement nod = doc.CreateElement(string.Empty, FACTURA_E_PersonTypeCode_NAME, string.Empty);
|
||||||
|
nod.InnerText = dat.Tipo;
|
||||||
|
taxn.AppendChild(nod);
|
||||||
|
|
||||||
|
nod = doc.CreateElement(string.Empty, FACTURA_E_ResidenceTypeCode_NAME, string.Empty);
|
||||||
|
nod.InnerText = FACTURA_E_ResidenceTypeCode;
|
||||||
|
taxn.AppendChild(nod);
|
||||||
|
|
||||||
|
nod = doc.CreateElement(string.Empty, FACTURA_E_TaxIdentificationNumber_NAME, string.Empty);
|
||||||
|
nod.InnerText = dat.IdImpuestos;
|
||||||
|
taxn.AppendChild(nod);
|
||||||
|
|
||||||
|
nodo.AppendChild(taxn);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
res = "Error en " + nameof(grabaTaxIdentification) + ": " + e.Message;
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
private string grabaDireccon(INTERNO_Direccion_Factura_E_Modelo dat, XmlDocument doc, XmlElement nodo)
|
||||||
|
{
|
||||||
|
string res = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
XmlElement nbase = doc.CreateElement(string.Empty, FACTURA_E_AddressInSpain_NAME, string.Empty);
|
||||||
|
|
||||||
|
XmlElement nod = doc.CreateElement(string.Empty, FACTURA_E_Address_NAME, string.Empty);
|
||||||
|
nod.InnerText = dat.Direccion;
|
||||||
|
nbase.AppendChild(nod);
|
||||||
|
|
||||||
|
nod = doc.CreateElement(string.Empty, FACTURA_E_PostCode_NAME, string.Empty);
|
||||||
|
nod.InnerText = dat.CP;
|
||||||
|
nbase.AppendChild(nod);
|
||||||
|
|
||||||
|
nod = doc.CreateElement(string.Empty, FACTURA_E_Town_NAME, string.Empty);
|
||||||
|
nod.InnerText = dat.Poblacion;
|
||||||
|
nbase.AppendChild(nod);
|
||||||
|
|
||||||
|
nod = doc.CreateElement(string.Empty, FACTURA_E_Province_NAME, string.Empty);
|
||||||
|
nod.InnerText = dat.Provincia;
|
||||||
|
nbase.AppendChild(nod);
|
||||||
|
|
||||||
|
nod = doc.CreateElement(string.Empty, FACTURA_E_CountryCode_NAME, string.Empty);
|
||||||
|
nod.InnerText = dat.Pais;
|
||||||
|
nbase.AppendChild(nod);
|
||||||
|
|
||||||
|
nodo.AppendChild(nbase);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
res = "Error en " + nameof(grabaDireccon) + ": " + e.Message;
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
private string grabaContacto(INTERNO_Direccion_Factura_E_Modelo dat, XmlDocument doc, XmlElement nodo)
|
||||||
|
{
|
||||||
|
string res = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
XmlElement nbase = doc.CreateElement(string.Empty, FACTURA_E_ContactDetails_NAME, string.Empty);
|
||||||
|
|
||||||
|
XmlElement nod = doc.CreateElement(string.Empty, FACTURA_E_Telephone_NAME, string.Empty);
|
||||||
|
nod.InnerText = dat.Tlf;
|
||||||
|
nbase.AppendChild(nod);
|
||||||
|
nod = doc.CreateElement(string.Empty, FACTURA_E_TeleFax_NAME, string.Empty);
|
||||||
|
nod.InnerText = dat.Fax;
|
||||||
|
nbase.AppendChild(nod);
|
||||||
|
nod = doc.CreateElement(string.Empty, FACTURA_E_WebAddress_NAME, string.Empty);
|
||||||
|
nod.InnerText = dat.Web;
|
||||||
|
nbase.AppendChild(nod);
|
||||||
|
nod = doc.CreateElement(string.Empty, FACTURA_E_ElectronicMail_NAME, string.Empty);
|
||||||
|
nod.InnerText = dat.Email;
|
||||||
|
nbase.AppendChild(nod);
|
||||||
|
|
||||||
|
nodo.AppendChild(nbase);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
res = "Error en " + nameof(grabaContacto) + ": " + e.Message;
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
private string grabaLegalEntity(INTERNO_Entidad_Factura_E_Modelo dat, XmlDocument doc, XmlElement nodo, bool contacto=false)
|
||||||
|
{
|
||||||
|
string res = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
XmlElement nbase = doc.CreateElement(string.Empty, FACTURA_E_LegalEntity_NAME, string.Empty);
|
||||||
|
|
||||||
|
XmlElement nod = doc.CreateElement(string.Empty, FACTURA_E_CorporateName_NAME, string.Empty);
|
||||||
|
nod.InnerText = dat.RazonSocial;
|
||||||
|
nbase.AppendChild(nod);
|
||||||
|
|
||||||
|
nod = doc.CreateElement(string.Empty, FACTURA_E_TradeName_NAME, string.Empty);
|
||||||
|
nod.InnerText = dat.NombreComercial;
|
||||||
|
nbase.AppendChild(nod);
|
||||||
|
res=grabaDireccon(dat, doc, nbase);
|
||||||
|
if (res != null)
|
||||||
|
return res;
|
||||||
|
if(contacto)
|
||||||
|
{
|
||||||
|
res = grabaContacto(dat, doc, nbase);
|
||||||
|
if (res != null)
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
nodo.AppendChild(nbase);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
res = "Error en " + nameof(grabaLegalEntity) + ": " + e.Message;
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
private string grabaCentroAdministrativo(INTERNO_CentroAdministrativo_Factura_E_Modelo dat, XmlDocument doc, XmlElement nodo)
|
||||||
|
{
|
||||||
|
string res = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
XmlElement nbase = doc.CreateElement(string.Empty, FACTURA_E_AdministrativeCentre_NAME, string.Empty);
|
||||||
|
|
||||||
|
XmlElement nod = doc.CreateElement(string.Empty, FACTURA_E_CentreCode_NAME, string.Empty);
|
||||||
|
nod.InnerText = dat.Codigo;
|
||||||
|
nbase.AppendChild(nod);
|
||||||
|
nod = doc.CreateElement(string.Empty, FACTURA_E_RoleTypeCode_NAME, string.Empty);
|
||||||
|
nod.InnerText = dat.Role;
|
||||||
|
nbase.AppendChild(nod);
|
||||||
|
nod = doc.CreateElement(string.Empty, FACTURA_E_Name_NAME, string.Empty);
|
||||||
|
nod.InnerText = dat.Encargado;
|
||||||
|
nbase.AppendChild(nod);
|
||||||
|
res = grabaDireccon(dat, doc, nbase);
|
||||||
|
if (res != null)
|
||||||
|
return res;
|
||||||
|
nod = doc.CreateElement(string.Empty, FACTURA_E_CentreDescription_NAME, string.Empty);
|
||||||
|
nod.InnerText = dat.Descripcion;
|
||||||
|
nbase.AppendChild(nod);
|
||||||
|
nodo.AppendChild(nbase);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
res = "Error en " + nameof(grabaCentroAdministrativo) + ": " + e.Message;
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
#region LecturaXML
|
#region LecturaXML
|
||||||
private string leeXML(XmlNode factura)
|
private string leeXML(XmlNode factura)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue