<?php 
require_once ("../app/formatos/formato.php");
$_POST['cliNom'] = str_ireplace('&','y',$_POST['cliNom']);
$_POST['emp_razsoc'] = str_ireplace('&','y',$_POST['emp_razsoc']);

$xml  = '<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>

<VoidedDocuments 
<VoidedDocuments xmlns="urn:sunat:names:specification:ubl:peru:schema:xsd:VoidedDocuments-1"

 xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" 
 xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" 
 xmlns:ccts="urn:un:unece:uncefact:documentation:2" 
 xmlns:ds="http://www.w3.org/2000/09/xmldsig#" 
 xmlns:ext="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2" 
 xmlns:qdt="urn:oasis:names:specification:ubl:schema:xsd:QualifiedDatatypes-2" 
 xmlns:sac="urn:sunat:names:specification:ubl:peru:schema:xsd:SunatAggregateComponents-1"
 xmlns:udt="urn:un:unece:uncefact:data:specification:UnqualifiedDataTypesSchemaModule:2" 
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<ext:UBLExtensions>
        <ext:UBLExtension>
            <ext:ExtensionContent>
            </ext:ExtensionContent>
        </ext:UBLExtension>
</ext:UBLExtensions>
 <cbc:UBLVersionID>2.0</cbc:UBLVersionID>
 <cbc:CustomizationID>1.0</cbc:CustomizationID>
 
 <cbc:ID>'.$_POST['combaj_numdoc'].'</cbc:ID>
 <cbc:ReferenceDate>'.$_POST['combaj_fec'].'</cbc:ReferenceDate>
 <cbc:IssueDate>'.$_POST['combaj_fec'].'</cbc:IssueDate>
 
 <cac:Signature>
 <cbc:ID>'.$_POST['combaj_empruc'].'</cbc:ID>
 <cac:SignatoryParty>
 <cac:PartyIdentification>
 <cbc:ID>'.$_POST['combaj_empruc'].'</cbc:ID>
 </cac:PartyIdentification>
 <cac:PartyName>
 <cbc:Name>'.$_POST['combaj_emprazsoc'].'</cbc:Name>
 </cac:PartyName>
 </cac:SignatoryParty>
 <cac:DigitalSignatureAttachment>
 <cac:ExternalReference>
 <cbc:URI>#signatureKG</cbc:URI>
 </cac:ExternalReference>
 </cac:DigitalSignatureAttachment>
 </cac:Signature>
 
 <cac:AccountingSupplierParty>
 <cbc:CustomerAssignedAccountID>'.$_POST['combaj_empruc'].'</cbc:CustomerAssignedAccountID>
 <cbc:AdditionalAccountID>6</cbc:AdditionalAccountID>
 <cac:Party>
 <cac:PartyLegalEntity>
 <cbc:RegistrationName>'.$_POST['combaj_emprazsoc'].'</cbc:RegistrationName>
 </cac:PartyLegalEntity>
 </cac:Party>
 </cac:AccountingSupplierParty>

  
 ';
	
$i=1;
foreach($_POST['combaj_docnumdoc'] as $indice=>$can)
{
		$item_tipdoc=$_POST['combaj_tipdoc'][$indice];
		$item_numdoc=$_POST['combaj_docnumdoc'][$indice];
		$item_mot=$_POST['combaj_docmot'][$indice];
		
		$ser =  substr($item_numdoc,0,4);
		$corr =  substr($item_numdoc,5,13);
		
$xml .='

<sac:VoidedDocumentsLine>
 <cbc:LineID>'.$i.'</cbc:LineID>
 <cbc:DocumentTypeCode>'.$item_tipdoc.'</cbc:DocumentTypeCode>
 <sac:DocumentSerialID>'.$ser.'</sac:DocumentSerialID>
 <sac:DocumentNumberID>'.$corr.'</sac:DocumentNumberID>
 <sac:VoidReasonDescription>'.$item_mot.'</sac:VoidReasonDescription>
 </sac:VoidedDocumentsLine>

';

$i++;
}


$xml .='</VoidedDocuments>';


$fac = new DOMDocument;
$fac->standalone         = false;
$fac -> preserveWhiteSpace = true;
$fac->loadXML($xml);

$nom_xml = $_POST['combaj_empruc'].'-'.$_POST['combaj_numdoc'].'.xml';
$archivo = '../docsinfirma/'.$nom_xml;
$fac->save($archivo);
$data["url"] = dirname()."../../docgeneracion/firmarcombaj.php";
$data["arc"] = $archivo;
$data["ruc"] = $_POST['combaj_empruc'];
$data["numdoc"] = $_POST['combaj_numdoc'];
echo json_encode($data);
?>








