Ver Mensaje Individual
  #7  
Antiguo 20-05-2019
wilcg wilcg is offline
Miembro
 
Registrado: abr 2014
Posts: 107
Reputación: 10
wilcg Va por buen camino
No soy experto en delphi, pero empiricamente he estado trabajando en un proyecto.
El XML lo he estado resolviendo de este modo, a ver si te es útil. OJO que la extructura del xml aún falta corregir.

Código Delphi [-]
Var
  FirmarXML: TCFXML;
  Zip: TZipFile;
  tDocXmlNombre: string;
  Xml: IXMLDOCUMENT;
  nMaster, nPrimero, nSegundo, nTercero, nCuarto, nQuinto, nAtributo, nItem,
    nItemSub, nCDATA: IXMLNODE;
begin
  Xml := NewXMLDocument;
  Xml.Version := '1.0';
  Xml.Encoding := 'UTF-8';
  // XML.StandAlone := 'yes';
  Xml.Options := [doNodeAutoIndent];

  nMaster := Xml.AddChild('Invoice');
  nMaster.Attributes['xmlns'] :=
    'urnasis:names:specification:ubl:schema:xsd:Invoice-2';
  nMaster.Attributes['xmlns:cac'] :=
    'urnasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2';
  nMaster.Attributes['xmlns:cbc'] :=
    'urnasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2';
  nMaster.Attributes['xmlns:ccts'] := 'urn:un:unece:uncefact:documentation:2';
  nMaster.Attributes['xmlns:ds'] := 'http://www.w3.org/2000/09/xmldsig#';
  nMaster.Attributes['xmlns:ext'] :=
    'urnasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2';
  nMaster.Attributes['xmlns:qdt'] :=
    'urnasis:names:specification:ubl:schema:xsd:QualifiedDatatypes-2';
  nMaster.Attributes['xmlns:udt'] :=
    'urn:un:unece:uncefact:data:specification:UnqualifiedDataTypesSchemaModule:2';
  nMaster.Attributes['xmlns:xsi'] :=
    'http://www.w3.org/2001/XMLSchema-instance';

  { Encabezado de Firma digital }
  nPrimero := nMaster.AddChild('ext:UBLExtensions');

  { Firma DIGITAL }
  nSegundo := nPrimero.AddChild('ext:UBLExtension');
  nSegundo.AddChild('ext:ExtensionContent').Text := '';

  { Ubl versión }
  nPrimero := nMaster.AddChild('cbc:UBLVersionID');
  nPrimero.Text := '2.1';
  { Cuztom }
  nPrimero := nMaster.AddChild('cbc:CustomizationID');
  nPrimero.Text := '2.0';

  // Información de COMPROBANTE
  { numeracion de factura }
  nPrimero := nMaster.AddChild('cbc:ID');
  nPrimero.Text := edtSerie.Text + '-' +
    FEnumCBT(FloatToStr(edtNumeracion.Value), 7, '0', False);

  { fecha y hora de emisión }
  nPrimero := nMaster.AddChild('cbc:IssueDate');
  nPrimero.Text := FormatDateTime('yyyy-mm-dd', edtFechaEmision.Date);

  { Código del comprobante }
  nPrimero := nMaster.AddChild('cbc:InvoiceTypeCode');
  nPrimero.Attributes['listID'] := '0101';
  nPrimero.Attributes['listAgencyName'] := 'PE:SUNAT';
  nPrimero.Attributes['listName'] := 'SUNAT:Identificador de Tipo de Documento';
  nPrimero.Attributes['listURI'] :=
    'urne:gob:sunat:cpe:see:gem:catalogos:catalogo01';
  nPrimero.Text := FEObCodCBT(FEObIntLookup(edtComprobante));

  { Leyendo a letras el valor }
  nPrimero := nMaster.AddChild('cbc:Note');
  nPrimero.Attributes['languageLocaleID'] := '1000';
  nPrimero.Text := 'SON: ' + UpperCase(FELeyendoNUM(txtTotal.Value)) +
    ' Y 00/100 ' + ObDatoStrInt('monedas', 'id_moneda', 'descripcion',
    FEObIntLookup(edtMoneda));

  { Obteniendo el código de MONEDA }
  nPrimero := nMaster.AddChild('cbcocumentCurrencyCode');
  nPrimero.Attributes['listID'] := 'ISO 4217 Alpha';
  nPrimero.Attributes['listName'] := 'Currency';
  nPrimero.Attributes['listAgencyName'] :=
    'United Nations Economic Commission for Europe';
  nPrimero.Text := ObDatoStrInt('monedas', 'id_moneda', 'codigo',
    FEObIntLookup(edtMoneda));

  { Información de EMPRESA remitente }
  nPrimero := nMaster.AddChild('cac:Signature');
  nPrimero.AddChild('cbc:ID').Text := tRucEmisor;
  nSegundo := nPrimero.AddChild('cac:SignatoryParty');
  nTercero := nSegundo.AddChild('cac:PartyIdentification');
  nTercero.AddChild('cbc:ID').Text := tRucEmisor;
  nCuarto := nSegundo.AddChild('cac:PartyName');
  nCuarto.AddChild('cbc:Name').DOMNode.appendChild
    (Xml.DOMDocument.createCDATASection(tRazonEmisor));
  nSegundo := nPrimero.AddChild('cacigitalSignatureAttachment');
  nTercero := nSegundo.AddChild('cac:ExternalReference');
  nTercero.AddChild('cbc:URI').Text := tRucEmisor;

  { Datos del EMISOR }
  nPrimero := nMaster.AddChild('cac:AccountingSupplierParty');
  nItem := nPrimero.AddChild('cbc:CustomerAssignedAccountID');
  nItem.Text := tRucEmisor; // NUMERO DOC del Emisor
  nItem := nPrimero.AddChild('cbc:AdditionalAccountID');
  nItem.Text := FE_CodigoTipoDoc(tRucEmisor);
  // ID del DOC del Receptor     ( 1 = DNI; 6 = RUC )   Códigos de Tipos de Documentos de Identidad

  nSegundo := nPrimero.AddChild('cac:Party');
  nTercero := nSegundo.AddChild('cac:PartyIdentification');
  nAtributo := nTercero.AddChild('cbc:ID');
  nAtributo.Attributes['schemeID'] := '6';
  nAtributo.Attributes['schemeName'] :=
    'SUNAT:Identificador de Documento de Identidad';
  nAtributo.Attributes['schemeAgencyName'] := 'PE:SUNAT';
  nAtributo.Attributes['schemeURI'] :=
    'urne:gob:sunat:cpe:see:gem:catalogos:catalogo06';
  nAtributo.Text := tRucEmisor;
  nTercero := nSegundo.AddChild('cac:PartyName');
  nTercero.AddChild('cbc:Name').DOMNode.appendChild
    (Xml.DOMDocument.createCDATASection(tRazonEmisor));
  nTercero := nSegundo.AddChild('cac:PartyLegalEntity');
  nTercero.AddChild('cbc:RegistrationName').DOMNode.appendChild
    (Xml.DOMDocument.createCDATASection(tRazonEmisor));
  nItem := nTercero.AddChild('cac:RegistrationAddress');
  nItem.AddChild('cbc:AddressTypeCode').Text := IntToStr(tUbiGeoEmisor);
  // Código del domicilio fiscal o de local anexo del emisor

  { Datos del RECEPTOR }
  nPrimero := nMaster.AddChild('cac:AccountingCustomerParty');
  nItem := nPrimero.AddChild('cbc:CustomerAssignedAccountID');
  nItem.Text := edtDni.Text; // NUMERO DOC del Receptor
  nItem := nPrimero.AddChild('cbc:AdditionalAccountID');
  nItem.Text := FE_CodigoTipoDoc(edtDni.Text);
  // ID del DOC del Receptor     ( 1 = DNI; 6 = RUC ) Códigos de Tipos de Documentos de Identidad

  nSegundo := nPrimero.AddChild('cac:Party');
  nTercero := nSegundo.AddChild('cac:PartyIdentification');
  nAtributo := nTercero.AddChild('cbc:ID');
  nAtributo.Attributes['schemeID'] := FE_CodigoTipoDoc(edtDni.Text);
  nAtributo.Attributes['schemeName'] :=
    'SUNAT:Identificador de Documento de Identidad';
  nAtributo.Attributes['schemeAgencyName'] := 'PE:SUNAT';
  nAtributo.Attributes['schemeURI'] :=
    'urne:gob:sunat:cpe:see:gem:catalogos:catalogo06';
  nAtributo.Text := edtDni.Text;
  nTercero := nSegundo.AddChild('cac:PartyLegalEntity');
  nTercero.AddChild('cbc:RegistrationName').DOMNode.appendChild
    (Xml.DOMDocument.createCDATASection(edtNombre.Text));

  nPrimero := nMaster.AddChild('cac:TaxTotal');
  nSegundo := nPrimero.AddChild('cbc:TaxAmount');
  nSegundo.Attributes['currencyID'] := ObDatoStrInt('monedas', 'id_moneda',
    'codigo', FEObIntLookup(edtMoneda));
  nSegundo.Text := FormatFloat('0.00', txtIgv.Value); // corregir
  nSegundo := nPrimero.AddChild('cac:TaxSubtotal');
  nItem := nSegundo.AddChild('cbc:TaxableAmount');
  nItem.Attributes['currencyID'] := ObDatoStrInt('monedas', 'id_moneda',
    'codigo', FEObIntLookup(edtMoneda));
  nItem.Text := FormatFloat('0.00', txtTotal.Value);
  nTercero := nSegundo.AddChild('cbc:TaxAmount');
  nTercero.Attributes['currencyID'] := ObDatoStrInt('monedas', 'id_moneda',
    'codigo', FEObIntLookup(edtMoneda));
  nTercero.Text := FormatFloat('0.00', txtSubTotal.Value); // corregir
  nTercero := nSegundo.AddChild('cac:TaxCategory');
  nItem := nTercero.AddChild('cbc:ID');
  nItem.Attributes['schemeID'] := 'UN/ECE 5305';
  nItem.Attributes['schemeName'] := 'Tax Category Identifier';
  nItem.Attributes['schemeAgencyName'] :=
    'United Nations Economic Commission for Europe';
  nItem.Text := 'S';

  nCuarto := nTercero.AddChild('cac:TaxScheme');
  nQuinto := nCuarto.AddChild('cbc:ID');
  nQuinto.Attributes['schemeID'] := 'UN/ECE 5153';
  nQuinto.Attributes['schemeAgencyID'] := '6';
  nQuinto.Text := IntToStr(IgvObCodigoIntInt(ObIntLookup(edtImpuesto)));
  // Codigo Internacional del IGV

  nQuinto := nCuarto.AddChild('cbc:Name');
  nQuinto.Text := 'IGV'; // Corregir  ---- OJO ---- PENDIENTE
  nQuinto := nCuarto.AddChild('cbc:TaxTypeCode');
  nQuinto.Text := IgvObCntitStrInt(ObIntLookup(edtImpuesto));
  // CODIGO DEL TRIBUTO valor 3 igv (VAT, EXC, OTH)

  nPrimero := nMaster.AddChild('cac:LegalMonetaryTotal');
  nSegundo := nPrimero.AddChild('cbc:AllowanceTotalAmount');
  nSegundo.Attributes['currencyID'] := ObDatoStrInt('monedas', 'id_moneda',
    'codigo', FEObIntLookup(edtMoneda));
  nSegundo.Text := FloatToStr(txtDescuento.Value);
  nSegundo := nPrimero.AddChild('cbc:PayableAmount');
  nSegundo.Attributes['currencyID'] := ObDatoStrInt('monedas', 'id_moneda',
    'codigo', FEObIntLookup(edtMoneda));
  nSegundo.Text := FloatToStr(txtTotal.Value);
Responder Con Cita