<?php
error_reporting(0);
//ini_set("display_errors", 1);
session_start();
   header('Content-Type: text/html; charset=iso-8859-1'); 

if(!isset($_SESSION['nuevonombre'])){
header("Location: index.php");
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<style type="text/css">
.ac{ font-family:Calibri; color:#FF0000;
}
.ap{ font-family:Calibri; color:#006600;}
.ab{ font-family:Calibri; color:#006600;}
#rojo{ color:#FF0000;}
body{ color:#000000; background-color:#EBEBEB;
font-family:Calibri; font-size:14px; font-weight:normal;}
td{ border:1px #00CC00 solid;}
</style>
<title>Editor de txt</title>
</head>

<body>
<?php
//print_r($_SESSION);
require("links.php");
//require("links_conceptos.php");

$archivo = file_get_contents($_SESSION['nuevonombre']);

if($archivo==true ){

if(isset($_POST['grabar'])){

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//inicio de lectura de excel

echo '<br>Nombre del archivo: '.$_SESSION['nombre'].'<br>';
$archivo=$_SESSION['nuevonombre'];
//require_once '../excel/PHPExcel/IOFactory.php';
require_once 'Classes/PHPExcel.php';
$objPHPExcel = PHPExcel_IOFactory::load($archivo);


function validare($dataType,$nombre,$use,$var){
//$xml=array();
if($nombre=='FORMAS DE PAGO'){
echo '<td align="center">---------</td>';
}
if($nombre=='formaDePago'){

if($var=='' ){
echo '<td id="rojo">falta formaDePago</td>';
}else{echo '<td>'.utf8_decode($var).'</td>';
$_SESSION['xml'][$nombre]=$var;
}

}
if($nombre=='condicionesDePago'){

if($var=='' ){
echo '<td id="rojo">falta '.$nombre.'</td>';
}else{echo '<td>'.utf8_decode($var).'</td>';
$_SESSION['xml'][$nombre]=$var;
}

}
if($nombre=='metodoDePago'){

if($var=='' ){
echo '<td id="rojo">falta '.$nombre.'</td>';
}else{echo '<td>'.utf8_decode($var).'</td>';
$_SESSION['xml'][$nombre]=$var;}

}
if($nombre=='Moneda'){

if($var=='' ){
echo '<td id="rojo">falta '.$nombre.'</td>';
}else{echo '<td>'.utf8_decode($var).'</td>';
$_SESSION['xml'][$nombre]=$var;
}

}


if($nombre=='TipoDeComprobante'){

if($var=='' ){
echo '<td id="rojo">falta '.$nombre.'</td>';
}else{echo '<td>'.utf8_decode($var).'</td>';
$_SESSION['xml'][$nombre]=$var;
}

}


if($nombre=='LugarExpedicion'){

if($var=='' ){
echo '<td id="rojo">falta '.$nombre.'</td>';
}else{echo '<td>'.utf8_decode($var).'</td>';
$_SESSION['xml'][$nombre]=$var;
}

}


if($nombre=='TipoCambio'){

if($var=='' ){
echo '<td id="rojo">falta '.$nombre.'</td>';
}else{echo '<td>'.$var.'</td>';
$_SESSION['xml'][$nombre]=$var;
}

}
if($nombre=='serie'){

if($var=='' ){
echo '<td id="rojo">falta '.$nombre.'</td>';
}else{echo '<td>'.$var.'</td>';
$_SESSION['xml'][$nombre]=$var;
}

}

if($nombre=='Fecha'){

if($var=='' ){
echo '<td id="rojo">falta '.$nombre.'</td>';
}else{echo '<td>'.$var.'</td>';
$_SESSION['xml'][$nombre]=$var;
}

}


if($nombre=='SUCURSAL'){

if($var=='' ){
echo '<td id="rojo">falta '.$nombre.'</td>';
}else{echo '<td>'.$var.'</td>';
$_SESSION['xml'][$nombre]=$var;
}

}
if($nombre=='ambiente'){

if($var=='' ){
echo '<td id="rojo">falta '.$nombre.'</td>';
}else{echo '<td>'.$var.'</td>';
$_SESSION['xml'][$nombre]=($var);
}

}
if($nombre=='folio'){

if($var=='' ){
echo '<td id="rojo">falta '.$nombre.'</td>';
}else{
echo '<td>'.$var.'</td>';
$_SESSION['xml'][$nombre]=$var;
}

}

if($nombre=='TipoComprobante'){
if($var=='' ){
echo '<td id="rojo">falta '.$nombre.'</td>';
}else{
echo '<td>'.$var.'</td>';
$_SESSION['xml'][$nombre]=$var;
}
}

if($nombre=='RegimenFiscal'){
if($var=='' ){
echo '<td id="rojo">falta '.$nombre.'</td>';
}else{
echo '<td>'.$var.'</td>';
$_SESSION['xml'][$nombre]=$var;
}
}

if($nombre=='Transaccionid'){

if($var=='' ){
echo '<td id="rojo">falta '.$nombre.'</td>';
}else{
echo '<td>'.$var.'</td>';
$_SESSION['xml'][$nombre]=$var;
}

}
if($nombre=='detallista'){

if($var=='' ){
echo '<td id="rojo">falta '.$nombre.'</td>';
}else{
echo '<td>'.$var.'</td>';
$_SESSION['xml'][$nombre]=$var;
}

}
if($nombre=='TOTALES'){

echo '<td align="center">---------</td>';

}
if($nombre=='subTotal'){

if($var=='' ){
echo '<td id="rojo">falta '.$nombre.'</td>';
}else{echo '<td>1'.$var.'</td>';
$_SESSION['xml'][$nombre]=number_format($var,2,'.','');
}

}

if($nombre=='descuento'){

if($var=='' ){
echo '<td id="rojo">falta '.$nombre.'</td>';
}else{echo '<td>'.$var.'</td>';
$_SESSION['xml'][$nombre]=$var;
}

}
if($nombre=='totalImpuestosRetenidos'){

if($var=='' ){
echo '<td id="rojo">falta '.$nombre.'</td>';
}else{echo '<td>'.$var.'</td>';
$_SESSION['xml'][$nombre]=number_format($var,6,'.','');
}

}
if($nombre=='totalImpuestosTrasladados'){

if($var=='' ){
echo '<td id="rojo">falta '.$nombre.'</td>';
}else{echo '<td>'.$var.'</td>';
$_SESSION['xml'][$nombre]=number_format($var,6,'.','');
}

}
if($nombre=='total'){

if($var=='' ){
echo '<td id="rojo">falta '.$nombre.'</td>';
}else{echo '<td>'.$var.'</td>';
$_SESSION['xml'][$nombre]=number_format($var,6,'.','');
}

}
if($nombre=='RECEPTOR'){

echo '<td align="center">---------</td>';

}
if($nombre=='emailReceptor'){

if($var=='' ){
echo '<td id="rojo">falta '.$nombre.'</td>';
}else{echo '<td>'.$var.'</td>';
$_SESSION['xml'][$nombre]=$var;
}

}
if($nombre=='rfc'){

if($var=='' ){
echo '<td id="rojo">falta '.$nombre.'</td>';
}else{echo '<td>'.$var.'</td>';
$_SESSION['xml'][$nombre]=$var;
}

}


if($nombre=='UsoCFDI'){

if($var=='' ){
echo '<td id="rojo">falta '.$nombre.'</td>';
}else{echo '<td>'.$var.'</td>';
$_SESSION['xml'][$nombre]=$var;
}

}



if($nombre=='nombre'){

if($var=='' ){
echo '<td id="rojo">falta '.$nombre.'</td>';
}else{echo '<td>'.utf8_decode($var).'</td>';
$_SESSION['xml'][$nombre]=$var;
}

}
if($nombre=='calle'){

if($var=='' ){
echo '<td id="rojo">falta '.$nombre.'</td>';
}else{echo '<td>'.utf8_decode($var).'</td>';
$_SESSION['xml'][$nombre]= str_replace('"','', $var);
}

}
if($nombre=='noInterior'){

if($var=='' ){
echo '<td id="rojo">falta '.$nombre.'</td>';
}else{echo '<td>'.utf8_decode($var).'</td>';
$_SESSION['xml'][$nombre]= str_replace('"','', $var);
}

}
if($nombre=='noExterior'){

if($var=='' ){
echo '<td id="rojo">falta '.$nombre.'</td>';
}else{echo '<td>'.utf8_decode($var).'</td>';
$_SESSION['xml'][$nombre]= str_replace('"','', $var);}

}
if($nombre=='colonia'){

if($var=='' ){
echo '<td id="rojo">falta '.$nombre.'</td>';
}else{echo '<td>'.utf8_decode($var).'</td>';
$_SESSION['xml'][$nombre]= str_replace('"','', $var);}

}
if($nombre=='localidad'){

if($var=='' ){
echo '<td id="rojo">falta '.$nombre.'</td>';
}else{echo '<td>'.utf8_decode($var).'</td>';
$_SESSION['xml'][$nombre]= str_replace('"','', $var);}

}
if($nombre=='delegacion'){

if($var=='' ){
echo '<td id="rojo">falta '.$nombre.'</td>';
}else{echo '<td>'.utf8_decode($var).'</td>';
$_SESSION['xml'][$nombre]= str_replace('"','', $var);}

}
if($nombre=='municipio'){

if($var=='' ){
echo '<td id="rojo">falta '.$nombre.'</td>';
}else{echo '<td>'.utf8_decode($var).'</td>';
$_SESSION['xml'][$nombre]= str_replace('"','', $var);}

}
if($nombre=='referencia'){

if($var=='' ){
echo '<td id="rojo">falta '.$nombre.'</td>';
}else{echo '<td>'.utf8_decode($var).'</td>';
$_SESSION['xml'][$nombre]= str_replace('"','', $var);}

}
if($nombre=='estado'){

if($var=='' ){
echo '<td id="rojo">falta '.$nombre.'</td>';
}else{echo '<td>'.utf8_decode($var).'</td>';
$_SESSION['xml'][$nombre]= str_replace('"','', $var);}

}
if($nombre=='pais'){

if($var=='' ){
echo '<td id="rojo">falta '.$nombre.'</td>';
}else{echo '<td>'.utf8_decode($var).'</td>';
$_SESSION['xml'][$nombre]= str_replace('"','', $var);}

}
if($nombre=='codigoPostal'){

if($var=='' ){
echo '<td id="rojo">falta '.$nombre.'</td>';
}else{echo '<td>'.utf8_decode($var).'</td>';
$_SESSION['xml'][$nombre]= str_replace('"','', $var);}

}


if($nombre=='CFDI Relacionado'){

echo '<td align="center">---------</td>';

}

if($nombre=='TipoRelacion'){

if($var=='' ){
echo '<td id="rojo">falta '.$nombre.'</td>';
}else{echo '<td>'.utf8_decode($var).'</td>';
$_SESSION['xml'][$nombre]= str_replace('"','', $var);}

}

if($nombre=='UUID'){

if($var=='' ){
echo '<td id="rojo">falta '.$nombre.'</td>';
}else{echo '<td>'.utf8_decode($var).'</td>';
$_SESSION['xml'][$nombre]= str_replace('"','', $var);}

}


if($nombre=='COMPLEMENTOS'){

echo '<td align="center">---------</td>';

}

}
   
function Batch_xmlElement($valor=false,$value,$value1){

$encabezado = '<?xml version="1.0" encoding="utf-8"?><emitirCFD xmlns="http://namespace.pegasotecnologia.com/SCFD"/>';
$emitirCFD = new SimpleXMLElement($encabezado, 0, false, '', true);

$PoRequestCFD= $emitirCFD->addChild('PoRequestCFD');
$RequestCFD= $PoRequestCFD->addChild('RequestCFD');

$RequestCFD->addAttribute('version', '3.3');
$RequestCFD->addAttribute('xmlns', '');

$xmlComprobante= $RequestCFD->addChild('Comprobante');

$xmlComprobante->addAttribute('Version', '3.3');


if(empty($_SESSION['xml']['formaDePago'])){}else{
$xmlComprobante->addAttribute('FormaPago', utf8_encode($_SESSION['xml']['formaDePago']));
}
if(empty ($_SESSION['xml']['condicionesDePago'])){}else{
$xmlComprobante->addAttribute('CondicionesDePago', utf8_encode($_SESSION['xml']['condicionesDePago']));
}

if(empty ($_SESSION['xml']['Fecha'])){}else{
$xmlComprobante->addAttribute('Fecha', utf8_encode($_SESSION['xml']['Fecha']));
}

if(intval($_SESSION['xml']['subTotal'])){
$xmlComprobante->addAttribute('SubTotal', number_format($_SESSION['xml']['subTotal'],2,'.','') );
}else{}
if(empty($_SESSION['xml']['TipoCambio'])){}else{
$xmlComprobante->addAttribute('TipoCambio', utf8_encode($_SESSION['xml']['TipoCambio']));
}

if(empty($_SESSION['xml']['Moneda'])){}else{
$xmlComprobante->addAttribute('Moneda', utf8_encode($_SESSION['xml']['Moneda']));
}

//CONSTRUIR
if(empty($_SESSION['xml']['TipoDeComprobante'])){}else{
$xmlComprobante->addAttribute('TipoDeComprobante', utf8_encode($_SESSION['xml']['TipoDeComprobante']));
}

if(empty($_SESSION['xml']['LugarExpedicion'])){}else{
$xmlComprobante->addAttribute('LugarExpedicion', utf8_encode($_SESSION['xml']['LugarExpedicion']));
}

if(intval($_SESSION['xml']['total'])){
$xmlComprobante->addAttribute('Total', utf8_encode($_SESSION['xml']['total']));
}else{}
if(empty($_SESSION['xml']['metodoDePago'])){}else{
$xmlComprobante->addAttribute('MetodoPago', utf8_encode($_SESSION['xml']['metodoDePago']));
}

if(!empty($_SESSION['xml']['descuento'])){
$xmlComprobante->addAttribute('Descuento', utf8_encode($_SESSION['xml']['descuento']));
}else{}

if(empty($_SESSION['xml']['serie'])){}else{
$xmlComprobante->addAttribute('Serie', utf8_encode($_SESSION['xml']['serie']));
}
if(empty($_SESSION['xml']['folio'])){}else{
$xmlComprobante->addAttribute('Folio', utf8_encode($_SESSION['xml']['folio']));
}

if(empty($_SESSION['xml']['TipoRelacion'])){}else{
			$xmlComprobante->addChild('CfdiRelacionados');
			$CfdiRelacionados = $xmlComprobante->CfdiRelacionados;

			$CfdiRelacionados->addAttribute('TipoRelacion',$_SESSION['xml']['TipoRelacion']);
			$CfdiRelacionados->addChild('CfdiRelacionado');
			$CfdiRelacionado = $CfdiRelacionados->CfdiRelacionado;
			$CfdiRelacionado->addAttribute('UUID',$_SESSION['xml']['UUID']);
}

$xmlEmisor = $xmlComprobante->addChild('Emisor');
if(empty($_SESSION['rfcEmisor'])){
}else{
$xmlEmisor->addAttribute('Rfc',$_SESSION['rfcEmisor']);
} 

if(empty($_SESSION['xml']['RegimenFiscal'])){}else{
$xmlEmisor->addAttribute('RegimenFiscal', utf8_encode($_SESSION['xml']['RegimenFiscal']));
}			

$xmlRecpetor = $xmlComprobante->addChild('Receptor');

if(empty($_SESSION['xml']['rfc'])){}else{
$xmlRecpetor->addAttribute('Rfc', utf8_encode($_SESSION['xml']['rfc']));
} 
if(empty($_SESSION['xml']['nombre'])){}else{
$xmlRecpetor->addAttribute('Nombre', utf8_encode($_SESSION['xml']['nombre']));
}  
//CONSTRUIR UsoCFDI
if(empty($_SESSION['xml']['UsoCFDI'])){}else{
$xmlRecpetor->addAttribute('UsoCFDI', utf8_encode($_SESSION['xml']['UsoCFDI']));
}  


$xmlConceptos= $xmlComprobante->addChild('Conceptos');

for($i=4; $i<count($value['xmlpcf'])+ 3;  $i++){
$xmlconcepto=$xmlConceptos->addChild('Concepto');
$xmlconcepto->addAttribute('Cantidad', utf8_encode($value['xmlpcf'][$i]['cantidad']));
$xmlconcepto->addAttribute('Unidad', utf8_encode($value['xmlpcf'][$i]['unidad']));
$xmlconcepto->addAttribute('NoIdentificacion', utf8_encode($value['xmlpcf'][$i]['noidentification']));
$xmlconcepto->addAttribute('Descripcion', utf8_encode($value['xmlpcf'][$i]['descripcion']));
$xmlconcepto->addAttribute('ValorUnitario', number_format($value['xmlpcf'][$i]['valorUnitario'],6,'.','') );
$xmlconcepto->addAttribute('Importe', number_format($value['xmlpcf'][$i]['importe'],6,'.',''));

//CONSTRUIR
$xmlconcepto->addAttribute('ClaveProdServ', utf8_encode($value['xmlpcf'][$i]['ClaveProdServ']));
$xmlconcepto->addAttribute('ClaveUnidad', utf8_encode($value['xmlpcf'][$i]['ClaveUnidad']));
if(isset($value['xmlpcf'][$i]['Descuento'])){
$xmlconcepto->addAttribute('Descuento', number_format($value['xmlpcf'][$i]['Descuento'],6,'.','') );
}
//CONSTRUIR
if(isset($value['xmlpcf'][$i]['Base'])){
$impuestosTraslado = $xmlconcepto->addChild('Impuestos');
$Traslados = $impuestosTraslado->addChild('Traslados');
$Traslado = $Traslados->addChild('Traslado');
$Traslado->addAttribute('Base', number_format($value['xmlpcf'][$i]['Base'],6,'.','') );
$Traslado->addAttribute('Impuesto', utf8_encode($value['xmlpcf'][$i]['Impuesto']));
$Traslado->addAttribute('TipoFactor', utf8_encode($value['xmlpcf'][$i]['TipoFactor']));
$Traslado->addAttribute('TasaOCuota', utf8_encode($value['xmlpcf'][$i]['TasaOCuota']));
$Traslado->addAttribute('Importe', number_format($value['xmlpcf'][$i]['Importe'],2,'.','') );
}

/*
$Retenidos = $impuestosTraslado->addChild('Retenidos');
$Retenido = $Retenidos->addChild('Retenido');

$Retenido->addAttribute('Base', utf8_encode($value['xmlpcf'][$i]['Base']));
$Retenido->addAttribute('Impuesto', utf8_encode($value['xmlpcf'][$i]['Impuesto']));
$Retenido->addAttribute('TipoFactor', utf8_encode($value['xmlpcf'][$i]['TipoFactor']));
$Retenido->addAttribute('TasaOCuota', utf8_encode($value['xmlpcf'][$i]['TasaOCuota']));
$Retenido->addAttribute('Importe', utf8_encode($value['xmlpcf'][$i]['Importe']));
*/
//CONSTRUIR

}


if(isset($_SESSION['xml']['totalImpuestosTrasladados']) or isset($_SESSION['xml']['totalImpuestosRetenidos'])){

$xmlImpuestos= $xmlComprobante->addChild('Impuestos');

if(empty($_SESSION['xml']['totalImpuestosTrasladados'])){}else{$xmlImpuestos->addAttribute('TotalImpuestosTrasladados',number_format($_SESSION['xml']['totalImpuestosTrasladados'],2,'.',''));}

if(empty($_SESSION['xml']['totalImpuestosRetenidos'])){}else{$xmlImpuestos->addAttribute('TotalImpuestosRetenidos',$_SESSION['xml']['totalImpuestosRetenidos']);}

$cuantoimp = count($value1['imp']) + 17;

if($_SESSION['xml']['totalImpuestosTrasladados']==''){}else{

$xmlImpuestosTraslados=$xmlImpuestos->addChild('Traslados');
for($i=17; $i<=$cuantoimp;  $i++){
if($value1['imp'][$i]['tipoImpuesto']=='Trasladado'){
$xmlImpuestosTraslado=$xmlImpuestosTraslados->addChild('Traslado');
$xmlImpuestosTraslado->addAttribute('Impuesto', $value1['imp'][$i]['Impuesto']);
$xmlImpuestosTraslado->addAttribute('Importe', number_format($value1['imp'][$i]['Importe'],2,'.','') );
$xmlImpuestosTraslado->addAttribute('TipoFactor', $value1['imp'][$i]['TipoFactor']);
$xmlImpuestosTraslado->addAttribute('TasaOCuota', $value1['imp'][$i]['TasaOCuota']);
}
}

}

if(isset($_SESSION['xml']['totalImpuestosRetenidos'])){

$xmlImpuestosRetenidos=$xmlImpuestos->addChild('Retenciones');
for( $i=17; $i<=$cuantoimp; $i++){
if($value1['imp'][$i]['tipoImpuesto']=='Retenido'){
$xmlImpuestosRetenido=$xmlImpuestosRetenidos->addChild('Retencion');
$xmlImpuestosRetenido->addAttribute('Impuesto', $value1['imp'][$i]["impuesto"]);
$xmlImpuestosRetenido->addAttribute('Importe',  number_format($value1['imp'][$i]["importe"],2,'.',''));
}
}

}



//fin 
}


///////// domicilio receptor
/*$Addenda=$xmlComprobante->addChild('Addenda');
$xmlDomicilio=$Addenda->addChild('AddendaDomicilioReceptor');

if(empty($_SESSION['xml']['colonia'])){}else{
$xmlDomicilio->addAttribute('colonia', utf8_encode($_SESSION['xml']['colonia']));
}       

if(empty($_SESSION['xml']['municipio'])){}else{
$xmlDomicilio->addAttribute('municipio', utf8_encode($_SESSION['xml']['municipio']));
}      
if(empty($_SESSION['xml']['calle'])){}else{
$xmlDomicilio->addAttribute('calle', utf8_encode($_SESSION['xml']['calle']));}

if(empty($_SESSION['xml']['noExterior'])){}else{
$xmlDomicilio->addAttribute('noExterior', utf8_encode($_SESSION['xml']['noExterior']));
}   
if(empty($_SESSION['xml']['noInterior'])){}else{
$xmlDomicilio->addAttribute('noInterior', utf8_encode($_SESSION['xml'][noInterior]));
} 
if(empty($_SESSION['xml']['localidad'])){}else{
$xmlDomicilio->addAttribute('localidad', utf8_encode($_SESSION['xml']['localidad']));
}  

if(empty($_SESSION['xml']['referencia'])){}else{
$xmlDomicilio->addAttribute('referencia', utf8_encode($_SESSION['xml']['referencia']));
} 

if(empty($_SESSION['xml']['estado'])){}else{
$xmlDomicilio->addAttribute('estado', utf8_encode($_SESSION['xml']['estado']));
} 
if(empty($_SESSION['xml']['pais'])){}else{
$xmlDomicilio->addAttribute('pais', utf8_encode($_SESSION['xml']['pais']));
}  
if(empty($_SESSION['xml']['codigoPostal'])){}else{
$xmlDomicilio->addAttribute('codigoPostal', utf8_encode($_SESSION['xml']['codigoPostal']));
}
*/




////////inicio de addenda liverpool
if($_SESSION['xml']['detallista']=='si'){
////////inicio de addenda liverpool
$complemento= $xmlComprobante->addChild('Complemento');
/////
$detallista= $complemento->addChild('detallista');
/////
$detallista->addAttribute('type', 'SimpleInvoiceType');
$detallista->addAttribute('contentVersion', '1.3.1');
$detallista->addAttribute('documentStructureVersion','AMC8.1');
$detallista->addAttribute('documentStatus', 'ORIGINAL');
/////
/*

/////*/
$cuenta = count($_SESSION['detallistaC']['requestForPaymentIdentification']) + 3;
for($i=4;$i<=$cuenta; $i++){
$requestForPaymentIdentification= $detallista->addChild('requestForPaymentIdentification');

$entityType= $requestForPaymentIdentification->addChild('entityType',$_SESSION['detallistaC']['requestForPaymentIdentification'][$i]['entityType']);

}

/////specialInstruction
//print_r($_SESSION['detallistaC']['specialInstruction']);
$cuenta = count($_SESSION['detallistaC']['specialInstruction'])+8;
for($i=9;$i<=$cuenta; $i++){
$specialInstruction= $detallista->addChild('specialInstruction');
$specialInstruction->addAttribute('code', $_SESSION['detallistaC']['specialInstruction'][$i]['code']);
$text= $specialInstruction->addChild('text',$_SESSION['detallistaC']['specialInstruction'][$i]['text']);
}
/////orderIdentification
//echo print_r($_SESSION['detallistaC']['orderIdentification'])+ 13 ;
  $cuenta = count($_SESSION['detallistaC']['orderIdentification']) + 13;
for($i=14;$i<=$cuenta; $i++){

$orderIdentification= $detallista->addChild('orderIdentification');

$referenceIdentification= $orderIdentification->addChild('referenceIdentification',$_SESSION['detallistaC']['orderIdentification'][$i]['referenceIdentification']);
$referenceIdentification->addAttribute('type',$_SESSION['detallistaC']['orderIdentification'][$i]['type']);

$ReferenceDate= $orderIdentification->addChild('ReferenceDate',$_SESSION['detallistaC']['orderIdentification'][$i]['ReferenceDate']);

}

/////AdditionalInformation
//print_r($_SESSION['detallistaC'][AdditionalInformation]) ;
  $cuenta = count($_SESSION['detallistaC']['AdditionalInformation']) + 18;
for($i=19;$i<=$cuenta; $i++){
$AdditionalInformation= $detallista->addChild('AdditionalInformation');
$referenceIdentification= $AdditionalInformation->addChild('referenceIdentification',$_SESSION['detallistaC']['AdditionalInformation'][$i]['referenceIdentification']);
$referenceIdentification->addAttribute('type',$_SESSION['detallistaC']['AdditionalInformation'][$i]['type']);

}


  $cuenta = count($_SESSION['detallistaC']['DeliveryNote']) + 23;
for($i=24;$i<=$cuenta; $i++){

$DeliveryNote= $detallista->addChild('DeliveryNote');
$referenceIdentification= $DeliveryNote->addChild('referenceIdentification',$_SESSION['detallistaC']['DeliveryNote'][$i]['referenceIdentification']);

$ReferenceDate= $DeliveryNote->addChild('ReferenceDate',$_SESSION['detallistaC']['DeliveryNote'][$i]['ReferenceDate']);

}


  $cuenta = count($_SESSION['detallistaC']['buyer']) + 28;
for($i=29;$i<=$cuenta; $i++){

$buyer= $detallista->addChild('buyer');
$gln= $buyer->addChild('gln',$_SESSION['detallistaC']['buyer'][$i]['gln']);
$contactInformation= $buyer->addChild('contactInformation');
$personOrDepartmentName= $contactInformation->addChild('personOrDepartmentName');
$text= $personOrDepartmentName->addChild('text',$_SESSION['detallistaC']['buyer'][$i]['text']);
}

$cuenta = count($_SESSION['detallistaC']['seller']) + 33;
for($i=34;$i<=$cuenta; $i++){

$seller= $detallista->addChild('seller');
$gln= $seller->addChild('gln',$_SESSION['detallistaC']['seller'][$i]['gln']);

$alternatePartyIdentification= $seller->addChild('alternatePartyIdentification',$_SESSION['detallistaC']['seller'][$i]['alternatePartyIdentification']);
$alternatePartyIdentification->addAttribute('type',$_SESSION['detallistaC']['seller'][$i]['type']);

}
////// calado
///allowanceCharge
$cuenta = count($_SESSION['detallistaC']['allowanceCharge']) + 38;
for($i=39;$i<=$cuenta; $i++){
$allowanceCharge= $detallista->addChild('allowanceCharge');
$allowanceCharge->addAttribute('allowanceChargeType',$_SESSION['detallistaC']['allowanceCharge'][$i]['allowanceChargeType']);
$allowanceCharge->addAttribute('settlementType',$_SESSION['detallistaC']['allowanceCharge'][$i]['settlementType']);

$specialServicesType= $allowanceCharge->addChild('specialServicesType',$_SESSION['detallistaC']['allowanceCharge'][$i]['specialServicesType']);

$monetaryAmountOrPercentage= $allowanceCharge->addChild('monetaryAmountOrPercentage');

$rate= $monetaryAmountOrPercentage->addChild('rate');
$rate->addAttribute('base',$_SESSION['detallistaC']['allowanceCharge'][$i]['base']);
$percentage= $rate->addChild('percentage',$_SESSION['detallistaC']['allowanceCharge'][$i]['percentage']);

}




//////////////


if($value['xmlp']['lineItem']!=''){
for($row=4; $row<count($value['xmlp']['lineItem']) + 3;  $row++){
$lineItem= $detallista->addChild('lineItem');
$lineItem->addAttribute('type',$value['xmlp']['lineItem'][$row]['type']);
$lineItem->addAttribute('number',$value['xmlp']['lineItem'][$row]['number']);

$tradeItemIdentification= $lineItem->addChild('tradeItemIdentification');
$gtin= $tradeItemIdentification->addChild('gtin',$value['xmlp']['gtin'][$row]['gtin']);

$alternateTradeItemIdentification= $lineItem->addChild('alternateTradeItemIdentification',$value['xmlp']['alternateTradeItemIdentification'][$row]['alternateTradeItemIdentification']);

$alternateTradeItemIdentification->addAttribute('type',$value['xmlp']['alternateTradeItemIdentification'][$row]['type']);

$tradeItemDescriptionInformation= $lineItem->addChild('tradeItemDescriptionInformation');
$tradeItemDescriptionInformation->addAttribute('language',$value['xmlp']['tradeItemDescriptionInformation'][$row]['language']);
$longText= $tradeItemDescriptionInformation->addChild('longText',$value['xmlp']['longText'][$row]['longText']);

$invoicedQuantity= $lineItem->addChild('invoicedQuantity',$value['xmlp']['invoicedQuantity'][$row]['invoicedQuantity']);
$invoicedQuantity->addAttribute('unitOfMeasure',$value['xmlp']['invoicedQuantity'][$row]['unitOfMeasure']);

$grossPrice= $lineItem->addChild('grossPrice');
$Amount= $grossPrice->addChild('Amount',$value['xmlp']['grossPrice'][$row]['Amount']);

$netPrice= $lineItem->addChild('netPrice');
$Amount= $netPrice->addChild('Amount',$value['xmlp']['netPrice'][$row]['Amount']);

$totalLineAmount= $lineItem->addChild('totalLineAmount');
$grossAmountAmount= $totalLineAmount->addChild('grossAmount');
$Amount= $grossAmountAmount->addChild('Amount',$value['xmlp']['grossAmount'][$row]['Amount']);

$netAmount= $totalLineAmount->addChild('netAmount');
$Amount= $netAmount->addChild('Amount',$value['xmlp']['netAmount'][$row]['Amount']);

}
}

///totalAmount
$cuenta = count($_SESSION['detallistaC']['totalAmount']) + 43;
for($i=44;$i<=$cuenta; $i++){

$totalAmount= $detallista->addChild('totalAmount');
$Amount= $totalAmount->addChild('Amount',$_SESSION['detallistaC']['totalAmount'][$i]['Amount']);

}

$cuenta = count($_SESSION['detallistaC']['TotalAllowanceCharge']) + 48;
for($i=49;$i<=$cuenta; $i++){
$TotalAllowanceCharge= $detallista->addChild('TotalAllowanceCharge');
$TotalAllowanceCharge->addAttribute('allowanceOrChargeType',$_SESSION['detallistaC']['TotalAllowanceCharge'][$i]['allowanceOrChargeType']);
$specialServicesType= $TotalAllowanceCharge->addChild('specialServicesType',$_SESSION['detallistaC']['TotalAllowanceCharge'][$i]['specialServicesType']);
$Amount= $TotalAllowanceCharge->addChild('Amount',$_SESSION['detallistaC']['TotalAllowanceCharge'][$i]['Amount']);
}

}else{
	
	$Addenda=$xmlComprobante->addChild('Addenda');
$xmlDomicilio=$Addenda->addChild('AddendaDomicilioReceptor');

if(empty($_SESSION['xml']['colonia'])){}else{
$xmlDomicilio->addAttribute('colonia', utf8_encode($_SESSION['xml']['colonia']));
}       

if(empty($_SESSION['xml']['municipio'])){}else{
$xmlDomicilio->addAttribute('municipio', utf8_encode($_SESSION['xml']['municipio']));
}      
if(empty($_SESSION['xml']['calle'])){}else{
$xmlDomicilio->addAttribute('calle', utf8_encode($_SESSION['xml']['calle']));}

if(empty($_SESSION['xml']['noExterior'])){}else{
$xmlDomicilio->addAttribute('noExterior', utf8_encode($_SESSION['xml']['noExterior']));
}   
if(empty($_SESSION['xml']['noInterior'])){}else{
$xmlDomicilio->addAttribute('noInterior', utf8_encode($_SESSION['xml'][noInterior]));
} 
if(empty($_SESSION['xml']['localidad'])){}else{
$xmlDomicilio->addAttribute('localidad', utf8_encode($_SESSION['xml']['localidad']));
}  

if(empty($_SESSION['xml']['referencia'])){}else{
$xmlDomicilio->addAttribute('referencia', utf8_encode($_SESSION['xml']['referencia']));
} 

if(empty($_SESSION['xml']['estado'])){}else{
$xmlDomicilio->addAttribute('estado', utf8_encode($_SESSION['xml']['estado']));
} 
if(empty($_SESSION['xml']['pais'])){}else{
$xmlDomicilio->addAttribute('pais', utf8_encode($_SESSION['xml']['pais']));
}  
if(empty($_SESSION['xml']['codigoPostal'])){}else{
$xmlDomicilio->addAttribute('codigoPostal', utf8_encode($_SESSION['xml']['codigoPostal']));
}
	
}
////////fin de addenda liverpool


$Transaccion= $RequestCFD->addChild('Transaccion');
$Transaccion->addAttribute('id', $_SESSION['xml']['Transaccionid']);

$TipoComprobante= $RequestCFD->addChild('TipoComprobante');
$TipoComprobante->addAttribute('nombre', $_SESSION['xml']['TipoComprobante']);
$TipoComprobante->addAttribute('clave', $_SESSION['xml']['TipoComprobante']);

$Sucursal= $RequestCFD->addChild('Sucursal');
$Sucursal->addAttribute('nombre', $_SESSION['xml']['SUCURSAL']);

$Receptor= $RequestCFD->addChild('Receptor');
$Receptor->addAttribute('emailReceptor', $_SESSION['xml']['emailReceptor']);


$strXmlCFDI = $emitirCFD->asXML(); 
$strXmlCFDI = trim($strXmlCFDI);
return $strXmlCFDI;
}   

function detallista($etiqueta,$cols,$row,$valor){
$sin_comillas = str_replace('"','&quot;',$etiqueta);
$sin_menosque = str_replace('<','&lt;',$sin_comillas);
$sin_masque = str_replace('>','&gt;',$sin_menosque); 
return $sin_masque;
}

foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) {
$worksheetTitle     = $worksheet->getTitle();
$highestRow         = $worksheet->getHighestRow(); // e.g. 10
$highestColumn      = $worksheet->getHighestColumn(); // e.g 'F'
$highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);
$nrColumns = ord($highestColumn) - 64;

if($worksheetTitle=='CONCEPTOS'){
?> <br>Data: <table border="0">  
<tr><td colspan="6"  align="center" style="font-size:18px;">Hoja : <?php echo $worksheetTitle; ?></td></tr>
<tr> 

<td>noIdentification</td>
<td>cantidad</td>
<td>unidad</td>
<td>descripcion</td>
<td>p unitario</td>
<td>importe</td>
<td>ClaveProdServ</td>
<td>ClaveUnidad</td>
<td>Descuento</td>

 </tr>
 <td style="background-color:#FCFF93;">opcional</td>
<td style="background-color:#FCFF93;">requerido</td>
<td style="background-color:#FCFF93;">requerido</td>
<td style="background-color:#FCFF93;">requerido</td>
<td style="background-color:#FCFF93;">requerido</td>
<td style="background-color:#FCFF93;">requerido</td>
<td style="background-color:#FCFF93;">requerido</td>
<td style="background-color:#FCFF93;">opcional</td>
<td>&nbsp;</td>
 </tr>
 <tr><br><?php
 $dataType = '';
for ($row = 3; $row <= $highestRow; ++ $row) {
echo '<tr>';

  $a1=$worksheet->getCellByColumnAndRow(0,$row)->getValue();
	if($a1!='' ){
	echo '<td>' . $a1 . '</td>';
$value['xmlpcf'][$row]['noidentification']=$a1;
}else{
echo '<td>' . $a1 . '(Type ' . $dataType . ')</td>';}


  $b=$worksheet->getCellByColumnAndRow(1,$row)->getValue();
	if($b!=''){
	echo '<td>' . $b . '</td>';
	$value['xmlpcf'][$row]['cantidad']=$b;
}else{break;echo $error='<td id="rojo">es necesaria la cantidad y es del tipo decimal '.$b.'</td>';}


  $c=$worksheet->getCellByColumnAndRow(2,$row)->getValue();
	if($c!=''){
	echo '<td>' . $c . '</td>';
	$value['xmlpcf'][$row]['unidad']=$c;
}else{break;echo $error='<td id="rojo">es necesaria la unidad</td>';}


  $d=$worksheet->getCellByColumnAndRow(3,$row)->getValue();
	if($d!=''){
	echo '<td>' . $d . '</td>';
	$value['xmlpcf'][$row]['descripcion']=$d;
	
}else{break;echo $error='<td id="rojo">es necesaria la descripción</td>';}


     $e=$worksheet->getCellByColumnAndRow(4,$row)->getValue();
	if($e!=''){
	echo '<td>' . $e . '</td>';
	$value['xmlpcf'][$row]['valorUnitario']=$e;
}else{break;echo $error='<td id="rojo">es necesaria el p. unitario y del tipo ecimal</td>';}
     
	 
	 
     $f=$worksheet->getCellByColumnAndRow(5,$row)->getValue();
	if($f!=''){
	echo '<td>' . $f . '</td>';
	$value['xmlpcf'][$row]['importe']=$f;
}else{
echo '<td>' .$suma = $b * $e . ' </td>';
$value['xmlpcf'][$row]['importe'] = $b * $e ;
}
	
     $e=$worksheet->getCellByColumnAndRow(6,$row)->getValue();
	if($e!=''){
	echo '<td>' . $e . '</td>';
	$value['xmlpcf'][$row]['ClaveProdServ']=$e;
}else{break;echo $error='<td id="rojo">es necesaria el ClaveProdServ</td>';}

     $e=$worksheet->getCellByColumnAndRow(7,$row)->getValue();
	if($e!=''){
	echo '<td>' . $e . '</td>';
	$value['xmlpcf'][$row]['ClaveUnidad']=$e;
}else{break;echo $error='<td id="rojo">es necesaria el ClaveUnidad</td>';}

     $e1=$worksheet->getCellByColumnAndRow(8,$row)->getValue();
	if($e1!=''){
	echo '<td>' . $e1 . '</td>';
	$value['xmlpcf'][$row]['Descuento']=$e1;
}else{echo '<td>' . $e1 . '(Type ' . $dataType . ')</td>';}

///////////////impuesto trasladado
 $e2=$worksheet->getCellByColumnAndRow(10,$row)->getValue();
	if($e2!=''){
	echo '<td>' . $e2 . '</td>';
	$value['xmlpcf'][$row]['Base']=$e2;
}else{echo '<td>' . $e2 . '(Type ' . $dataType . ')</td>';}

$e3=$worksheet->getCellByColumnAndRow(11,$row)->getValue();
	if($e3!=''){
	echo '<td>' . $e3 . '</td>';
	$value['xmlpcf'][$row]['Impuesto']=$e3;
}else{echo '<td>' . $e3 . '(Type ' . $dataType . ')</td>';}

$e4=$worksheet->getCellByColumnAndRow(12,$row)->getValue();
	if($e4!=''){
	echo '<td>' . $e4 . '</td>';
	$value['xmlpcf'][$row]['TipoFactor']=$e4;
}else{echo '<td>' . $e4 . '(Type ' . $dataType . ')</td>';}

$e5=$worksheet->getCellByColumnAndRow(13,$row)->getValue();
	if($e5!=''){
	echo '<td>' . $e5 . '</td>';
	$value['xmlpcf'][$row]['TasaOCuota']=$e5;
}else{echo '<td>' . $e5 . '(Type ' . $dataType . ')</td>';}

$e6=$worksheet->getCellByColumnAndRow(14,$row)->getValue();
	if($e6!=''){
	echo '<td>' . $e6 . '</td>';
	$value['xmlpcf'][$row]['Importe']=$e6;
}else{echo '<td>' . $e6 . '(Type ' . $dataType . ')</td>';}
	

	
   //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////revisar antiguo
$h=$worksheet->getCellByColumnAndRow(21,$row)->getValue();
	if($h!=''){
	echo '<td>a' . $h . '</td>';
	$value['xmlp']['lineItem'][$row]['type']=$h;
}else{ } 
   
   $i=$worksheet->getCellByColumnAndRow(22,$row)->getValue();
	if($i!=''){
	echo '<td>' . $i . '</td>';
	$value['xmlp']['lineItem'][$row]['number']=$i;
}else{ } 

  $j=$worksheet->getCellByColumnAndRow(23,$row)->getValue();
	if($j!=''){
	echo '<td>' . $j . '</td>';
	$value['xmlp']['gtin'][$row]['gtin']=$j;
}else{ } 
 
   
  $k=$worksheet->getCellByColumnAndRow(24,$row)->getValue();
	if($k!=''){
	echo '<td>' . $k . '</td>';
$value['xmlp']['alternateTradeItemIdentification'][$row]['alternateTradeItemIdentification']=$k;
}else{ } 


  $l=$worksheet->getCellByColumnAndRow(25,$row)->getValue();
	if($l!=''){
	echo '<td>' . $l . '</td>';
$value['xmlp']['alternateTradeItemIdentification'][$row]['type']=$l;
}else{ }    
   
   
   
     $m=$worksheet->getCellByColumnAndRow(26,$row)->getValue();
	if($m!=''){
	echo '<td>' . $m . '</td>';
$value['xmlp']['tradeItemDescriptionInformation'][$row]['language']=$m;
}else{ }


$value['xmlp']['longText'][$row]['longText']=$d;


     $n=$worksheet->getCellByColumnAndRow(27,$row)->getValue();
	if($n!=''){
	echo '<td>' . $n . '</td>';
$value['xmlp']['invoicedQuantity'][$row]['unitOfMeasure']=$n;
}else{ }

     $o=$worksheet->getCellByColumnAndRow(28,$row)->getValue();
	if($o!=''){
	echo '<td>' . $o . '</td>';
$value['xmlp']['invoicedQuantity'][$row]['invoicedQuantity']=$o;
}else{ }
//netAmount
     $p=$worksheet->getCellByColumnAndRow(29,$row)->getValue();
	if($p!=''){
	echo '<td>' . $p . '</td>';
$value['xmlp']['grossPrice'][$row]['Amount']=number_format($p,6,'.','');
}else{ }

     $q=$worksheet->getCellByColumnAndRow(30,$row)->getValue();
	if($q!=''){
	echo '<td>' . $q . '</td>';
$value['xmlp']['netPrice'][$row]['Amount']=number_format($q,6,'.','');
}else{ }


     $r=$worksheet->getCellByColumnAndRow(31,$row)->getValue();
	if($r!=''){
	echo '<td>' . $r . '</td>';
$value['xmlp']['grossAmount'][$row]['Amount']=number_format($r,6,'.','');
}else{ }



     $s=$worksheet->getCellByColumnAndRow(32,$row)->getValue();
	if($s!=''){
	echo '<td>' . $s . '</td>';
$value['xmlp']['netAmount'][$row]['Amount']=number_format($s,6,'.','');
}else{ }

echo '</tr>';

}

?></table><?php
}

if($worksheetTitle=='datosFiscales'){

?><br />
<table border="0" width="100%"><tr><td colspan="2" align="center">DATOS FISCALES</td></tr><tr><td>
<br>Data: <table border="0" >
<tr><td align="center" colspan="2" style="font-size:18px;">Hoja : <?php echo $worksheetTitle; ?></td></tr>
<tr><br><?php
 $use='';
for ($row = 1; $row <= $highestRow; ++ $row) {
echo '<tr>';

  $a=$worksheet->getCellByColumnAndRow(0,$row)->getValue();
	$dataType1 = PHPExcel_Cell_DataType::dataTypeForValue($a);
	if($dataType1!='null'){
	
	if($a=='FORMAS DE PAGO' or $a=='TOTALES' or $a=='RECEPTOR' or $a=='COMPLEMENTOS' or $a=='Emisor' or $a=='CFDI Relacionado'){
	echo '<td id="rojo">' . utf8_decode($a) . '</td>';
	}else{echo '<td>' . utf8_decode($a) . '</td>';}
}else{}

  $b=$worksheet->getCellByColumnAndRow(2,$row)->getValue();
	$dataType2 = PHPExcel_Cell_DataType::dataTypeForValue($b);

  validare($dataType2,$a,$use, trim($b));
  //print_r($xml);      
echo '</tr>';

}

?></table></td><td><?php

/////////////////////////////////loop impuestos

?><br>Data: <table border="0" >
<tr><td align="center" colspan="4" style="font-size:18px;">Hoja : <?php echo 'Impuestos'; ?></td></tr>
<tr><td>impuesto</td><td>TipoFactor</td><td>TasaOCuota</td><td>importe</td><td>tipo Impuesto</td></tr>
<tr><td style="background-color:#FCFF93;">requerido</td><td style="background-color:#FCFF93;">requerido</td><td style="background-color:#FCFF93;">requerido</td><td style="background-color:#FCFF93;">requerido</td><td style="background-color:#FCFF93;">requerido</td></tr>
<tr><br><?php
 

for ($row = 17; $row <= $highestRow; ++ $row) {
//////////////////loop for
echo '<tr>';

  $a1=$worksheet->getCellByColumnAndRow(7,$row)->getValue();
	if($a1!='' ){
	echo '<td>' . $a1 . '</td>';
$value1['imp'][$row]['Impuesto']=$a1;
}else{break; echo '<td>' . $a1 . '</td>';}


  $b=$worksheet->getCellByColumnAndRow(8,$row)->getValue();
	if($e!='Retenido'){
	if($b!=''){
	echo '<td>' . $b . '</td>';
	$value1['imp'][$row]['TipoFactor']=$b;
}else{echo $error='<td id="rojo">es necesaria la tasa del impuesto'.$b.'</td>';}
}else{echo '<td>En retenido no aplica tasa</td>'; }

  $c=$worksheet->getCellByColumnAndRow(9,$row)->getValue();
	if($c!=''){
	echo '<td>' . $c . '</td>';
	$value1['imp'][$row]['TasaOCuota']=$c;
}else{echo $error='<td id="rojo">es necesaria el importe del impuesto '.$c.'</td>';}
   


  $c=$worksheet->getCellByColumnAndRow(10,$row)->getValue();
	if($c!=''){
	echo '<td>' . $c . '</td>';
	$value1['imp'][$row]['Importe']=$c;
}else{echo $error='<td id="rojo">es necesaria el importe del impuesto '.$c.'</td>';}
   


     $e=$worksheet->getCellByColumnAndRow(11,$row)->getValue();
if($e!='' and ($e=='Retenido' or $e=='Trasladado')){
	echo '<td>' . $e . '</td>';
	$value1['imp'][$row]['tipoImpuesto']=$e;
}else{
echo $error='<td id="rojo">es necesaria el tipo de impuesto ""'.$e.'"" o es diferente a los valores "Retenido/Trasladado"</td>';}
   
echo '</tr>';

//////////////////////loop for
}

?></table></td></tr></table><?php

}

if($worksheetTitle=='detallista'){
?><br>Data: <table border="0">

<tr><td colspan="6"  align="center" style="font-size:18px;">Hoja : <?php echo $worksheetTitle; ?></td></tr>

<tr> 

<br><?php

////detallista
$detallistaLectura = 2;
$stop=1;
for($row = $stop; $row <= $detallistaLectura; ++$row){

if($worksheet->getCellByColumnAndRow(0,$row )->getValue()!='ejemplo'){
echo '<tr>';
///////////////////////////

$a1=$worksheet->getCellByColumnAndRow(1,$row)->getValue();
	if($a1!='' ){
	
echo '<td>' . $a1 . '</td>';
}else{ }
//grossAmount

$a2=$worksheet->getCellByColumnAndRow(2,$row)->getValue();
	if($a2!='' ){
echo '<td>' . $a2 . '</td>';
}else{ }

////valor
$a3=$worksheet->getCellByColumnAndRow(3,$row)->getValue();
	if($a3!='' ){
$_SESSION['detallistaC']['detallista'][$row]['type']=$a3;
echo '<td>' . $a3 . '</td>';
}else{ }

$a4=$worksheet->getCellByColumnAndRow(4,$row)->getValue();
	if($a4!='' ){
echo '<td>' . $a4 . '</td>';
}else{ }

////valor
$a5=$worksheet->getCellByColumnAndRow(5,$row)->getValue();
	if($a5!='' ){
	
$_SESSION['detallistaC']['detallista'][$row]['documentStructureVersion']=$a5;

echo '<td>' . $a5 . '</td>';
}else{}

$a6=$worksheet->getCellByColumnAndRow(6,$row)->getValue();
	if($a6!='' ){
echo '<td>' . $a6 . '</td>';
}else{ }
////valor
$a7=$worksheet->getCellByColumnAndRow(7,$row)->getValue();
	if($a7!='' ){
$_SESSION['detallistaC']['detallista'][$row]['documentStatus']=$a7;
echo '<td>' . $a7 . '</td>';
}else{ }

$a8=$worksheet->getCellByColumnAndRow(8,$row)->getValue();
	if($a8!='' ){
echo '<td>' . $a8 . '</td>';
}else{ }
////valor
$a9=$worksheet->getCellByColumnAndRow(9,$row)->getValue();
	if($a9!='' ){
echo '<td>' . $a9 . '</td>';
}else{ }



echo '</tr>';
}

}
////requestForPaymentIdentification
$detallistaLectura = $detallistaLectura + 5 ;
$stop=$stop + 2;
for($row = $stop; $row <= $detallistaLectura; ++$row){

if($worksheet->getCellByColumnAndRow(0,$row )->getValue()!='ejemplo'){
echo '<tr>';
///////////////////////////

$a1=$worksheet->getCellByColumnAndRow(1,$row)->getValue();
	if($a1!='' ){
echo '<td>' . $a1 . '</td>';
}else{ }


$a2=$worksheet->getCellByColumnAndRow(2,$row)->getValue();
	if($a2!='' ){
echo '<td>' . $a2 . '</td>';
}else{ }

////valor
$a3=$worksheet->getCellByColumnAndRow(3,$row)->getValue();
	if($a3!='' ){
$_SESSION['detallistaC']['requestForPaymentIdentification'][$row]['entityType']=$a3;

echo '<td>' . $a3 . '</td>';
}else{ }

$a4=$worksheet->getCellByColumnAndRow(4,$row)->getValue();
	if($a4!='' ){
echo '<td>' . $a4 . '</td>';
}else{ }




echo '</tr>';
}

}
////specialInstruction
$detallistaLectura = $detallistaLectura + 5 ;
$stop=$stop + 5;
for($row = $stop; $row <= $detallistaLectura; ++$row){

if($worksheet->getCellByColumnAndRow(0,$row )->getValue()!='ejemplo'){
echo '<tr>';
///////////////////////////

$a1=$worksheet->getCellByColumnAndRow(1,$row)->getValue();
	if($a1!='' ){
echo '<td>' . $a1 . '</td>';
}else{ }


$a2=$worksheet->getCellByColumnAndRow(2,$row)->getValue();
	if($a2!='' ){
echo '<td>' . $a2 . '</td>';
}else{ }

////valor
$a3=$worksheet->getCellByColumnAndRow(3,$row)->getValue();
	if($a3!='' ){
$_SESSION['detallistaC']['specialInstruction'][$row]['code']=$a3;
echo '<td>' . $a3 . '</td>';
}else{ }



$a5=$worksheet->getCellByColumnAndRow(5,$row)->getValue();
	if($a5!='' ){
echo '<td>' . $a5 . '</td>';
}else{}
////valor
$a6=$worksheet->getCellByColumnAndRow(6,$row)->getValue();
	if($a6!='' ){
$_SESSION['detallistaC']['specialInstruction'][$row]['text']=$a6;
echo '<td>' . $a6 . '</td>';
}else{ }

$a7=$worksheet->getCellByColumnAndRow(7,$row)->getValue();
	if($a7!='' ){
echo '<td>' . $a7 . '</td>';
}else{ }






echo '</tr>';
}}

////orderIdentification
$detallistaLectura = $detallistaLectura + 5 ;
$stop=$stop + 5;
for($row = $stop; $row <= $detallistaLectura; ++$row){

if($worksheet->getCellByColumnAndRow(0,$row )->getValue()!='ejemplo'){
echo '<tr>';
///////////////////////////

$a1=$worksheet->getCellByColumnAndRow(1,$row)->getValue();
	if($a1!='' ){
echo '<td>' . $a1 . '</td>';
}else{ }




$a3=$worksheet->getCellByColumnAndRow(3,$row)->getValue();
	if($a3!='' ){
echo '<td>' . $a3 . '</td>';
}else{ }

////valor
$a4=$worksheet->getCellByColumnAndRow(4,$row)->getValue();
	if($a4!='' ){
$_SESSION['detallistaC']['orderIdentification'][$row]['type']=$a4;

echo '<td>' . $a4 . '</td>';
}else{}


$a5=$worksheet->getCellByColumnAndRow(5,$row)->getValue();
	if($a5!='' ){
echo '<td>' . $a5 . '</td>';
}else{}
////valor
$a6=$worksheet->getCellByColumnAndRow(6,$row)->getValue();
	if($a6!='' ){
$_SESSION['detallistaC']['orderIdentification'][$row]['referenceIdentification']=$a6;

echo '<td>' . $a6 . '</td>';
}else{ }

$a8=$worksheet->getCellByColumnAndRow(8,$row)->getValue();
	if($a8!='' ){
echo '<td>' . $a8 . '</td>';
}else{ }
////valor
$a9=$worksheet->getCellByColumnAndRow(9,$row)->getValue();
	if($a9!='' ){
$_SESSION['detallistaC']['orderIdentification'][$row]['ReferenceDate']=$a9;
echo '<td>' . $a9 . '</td>';
}else{ }

echo '</tr>';
}}


////AdditionalInformation
$detallistaLectura = $detallistaLectura + 5 ;
$stop=$stop + 5;
for($row = $stop; $row <= $detallistaLectura; ++$row){

if($worksheet->getCellByColumnAndRow(0,$row )->getValue()!='ejemplo'){
echo '<tr>';
///////////////////////////

$a1=$worksheet->getCellByColumnAndRow(1,$row)->getValue();
	if($a1!='' ){
echo '<td>' . $a1 . '</td>';
}else{ }





$a3=$worksheet->getCellByColumnAndRow(3,$row)->getValue();
	if($a3!='' ){
echo '<td>' . $a3 . '</td>';
}else{ }
////valor
$a4=$worksheet->getCellByColumnAndRow(4,$row)->getValue();
	if($a4!='' ){
$_SESSION['detallistaC']['AdditionalInformation'][$row]['type']=$a4;

echo '<td>' . $a4 . '</td>';
}else{ }

$a5=$worksheet->getCellByColumnAndRow(5,$row)->getValue();
	if($a5!='' ){
echo '<td>' . $a5 . '</td>';
}else{}
////valor
$a6=$worksheet->getCellByColumnAndRow(6,$row)->getValue();
	if($a6!='' ){
$_SESSION['detallistaC']['AdditionalInformation'][$row]['referenceIdentification']=$a6;

echo '<td>' . $a6 . '</td>';
}else{ }

$a7=$worksheet->getCellByColumnAndRow(7,$row)->getValue();
	if($a7!='' ){
echo '<td>' . $a7 . '</td>';
}else{ }



echo '</tr>';
}}

////DeliveryNote
$detallistaLectura = $detallistaLectura + 5 ;
$stop=$stop + 5;
for($row = $stop; $row <= $detallistaLectura; ++$row){
if($worksheet->getCellByColumnAndRow(0,$row )->getValue()!='ejemplo'){
echo '<tr>';
///////////////////////////

$a1=$worksheet->getCellByColumnAndRow(1,$row)->getValue();
	if($a1!='' ){
echo '<td>' . $a1 . '</td>';
}else{ }


$a2=$worksheet->getCellByColumnAndRow(2,$row)->getValue();
	if($a2!='' ){
echo '<td>' . $a2 . '</td>';
}else{ }

////valor
$a3=$worksheet->getCellByColumnAndRow(3,$row)->getValue();
	if($a3!='' ){
$_SESSION['detallistaC']['DeliveryNote'][$row]['referenceIdentification']=$a3;
echo '<td>' . $a3 . '</td>';
}else{ }


$a5=$worksheet->getCellByColumnAndRow(5,$row)->getValue();
	if($a5!='' ){
echo '<td>' . $a5 . '</td>';
}else{}
////valor
$a6=$worksheet->getCellByColumnAndRow(6,$row)->getValue();
	if($a6!='' ){
$_SESSION['detallistaC']['DeliveryNote'][$row]['ReferenceDate']=$a6;

echo '<td>' . $a6 . '</td>';
}else{ }

$a7=$worksheet->getCellByColumnAndRow(7,$row)->getValue();
	if($a7!='' ){
echo '<td>' . $a7 . '</td>';
}else{ }


echo '</tr>';
}}

////buyer
$detallistaLectura = $detallistaLectura + 5 ;
$stop=$stop + 5;
for($row = $stop; $row <= $detallistaLectura; ++$row){

if($worksheet->getCellByColumnAndRow(0,$row )->getValue()!='ejemplo'){
echo '<tr>';
///////////////////////////

$a1=$worksheet->getCellByColumnAndRow(1,$row)->getValue();
	if($a1!='' ){
echo '<td>' . $a1 . '</td>';
}else{ }


$a2=$worksheet->getCellByColumnAndRow(2,$row)->getValue();
	if($a2!='' ){
echo '<td>' . $a2 . '</td>';
}else{ }

////valor
$a3=$worksheet->getCellByColumnAndRow(3,$row)->getValue();
	if($a3!='' ){
$_SESSION['detallistaC']['buyer'][$row]['gln']=$a3;
	
echo '<td>' . $a3 . '</td>';
}else{ }

$a7=$worksheet->getCellByColumnAndRow(7,$row)->getValue();
	if($a7!='' ){
echo '<td>' . $a7 . '</td>';
}else{ }
////valor
$a8=$worksheet->getCellByColumnAndRow(8,$row)->getValue();
	if($a8!='' ){
$_SESSION['detallistaC']['buyer'][$row]['text']=$a8;

echo '<td>' . $a8 . '</td>';
}else{ }

$a9=$worksheet->getCellByColumnAndRow(9,$row)->getValue();
	if($a9!='' ){
echo '<td>' . $a9 . '</td>';
}else{ }



echo '</tr>';
}}
////seller
$detallistaLectura = $detallistaLectura + 5 ;
$stop=$stop + 5;
for($row = $stop; $row <= $detallistaLectura; ++$row){

if($worksheet->getCellByColumnAndRow(0,$row )->getValue()!='ejemplo'){
echo '<tr>';
///////////////////////////

$a1=$worksheet->getCellByColumnAndRow(1,$row)->getValue();
	if($a1!='' ){
echo '<td>' . $a1 . '</td>';
}else{ }


$a2=$worksheet->getCellByColumnAndRow(2,$row)->getValue();
	if($a2!='' ){
echo '<td>' . $a2 . '</td>';
}else{ }

////valor
$a3=$worksheet->getCellByColumnAndRow(3,$row)->getValue();
	if($a3!='' ){
$_SESSION['detallistaC']['seller'][$row]['gln']=$a3;

echo '<td>' . $a3 . '</td>';
}else{ }



$a5=$worksheet->getCellByColumnAndRow(5,$row)->getValue();
	if($a5!='' ){
echo '<td>' . $a5 . '</td>';
}else{}

$a6=$worksheet->getCellByColumnAndRow(6,$row)->getValue();
	if($a6!='' ){
echo '<td>' . $a6 . '</td>';
}else{ }
////valor
$a7=$worksheet->getCellByColumnAndRow(7,$row)->getValue();
	if($a7!='' ){
		$_SESSION['detallistaC']['seller'][$row]['type']=$a7;

echo '<td>' . $a7 . '</td>';
}else{ }

$a8=$worksheet->getCellByColumnAndRow(8,$row)->getValue();
	if($a8!='' ){
echo '<td>' . $a8 . '</td>';
}else{ }
////valor
$a9=$worksheet->getCellByColumnAndRow(9,$row)->getValue();
	if($a9!='' ){
$_SESSION['detallistaC']['seller'][$row]['alternatePartyIdentification']=$a9;

echo '<td>' . $a9 . '</td>';
}else{ }

$a10=$worksheet->getCellByColumnAndRow(10,$row)->getValue();
	if($a10!='' ){
echo '<td>' . $a10 . '</td>';
}else{ }

echo '</tr>';
}}

////allowanceCharge
$detallistaLectura = $detallistaLectura + 5 ;
$stop=$stop + 5;
for($row = $stop; $row <= $detallistaLectura; ++$row){

if($worksheet->getCellByColumnAndRow(0,$row )->getValue()!='ejemplo'){
echo '<tr>';
///////////////////////////

$a1=$worksheet->getCellByColumnAndRow(1,$row)->getValue();
	if($a1!='' ){
echo '<td>' . $a1 . '</td>';
}else{ }


$a2=$worksheet->getCellByColumnAndRow(2,$row)->getValue();
	if($a2!='' ){
echo '<td>' . $a2 . '</td>';
}else{ }

////valor
$a3=$worksheet->getCellByColumnAndRow(3,$row)->getValue();
	if($a3!='' ){
$_SESSION['detallistaC']['allowanceCharge'][$row]['allowanceChargeType']=$a3;

echo '<td>' . $a3 . '</td>';
}else{ }

$a4=$worksheet->getCellByColumnAndRow(4,$row)->getValue();
	if($a4!='' ){
echo '<td>' . $a4 . '</td>';
}else{ }
////valor
$a5=$worksheet->getCellByColumnAndRow(5,$row)->getValue();
	if($a5!='' ){
$_SESSION['detallistaC']['allowanceCharge'][$row]['settlementType']=$a5;
	
echo '<td>' . $a5 . '</td>';
}else{}



$a7=$worksheet->getCellByColumnAndRow(7,$row)->getValue();
	if($a7!='' ){
echo '<td>' . $a7 . '</td>';
}else{ }

$a8=$worksheet->getCellByColumnAndRow(8,$row)->getValue();
	if($a8!='' ){
$_SESSION['detallistaC']['allowanceCharge'][$row]['specialServicesType']=$a8;

echo '<td>' . $a8 . '</td>';
}else{ }

$a11=$worksheet->getCellByColumnAndRow(11,$row)->getValue();
	if($a11!='' ){
echo '<td>' . $a11 . '</td>';
}else{ }

$a12=$worksheet->getCellByColumnAndRow(12,$row)->getValue();
	if($a12!='' ){
echo '<td>' . $a12 . '</td>';
}else{ }

$a13=$worksheet->getCellByColumnAndRow(13,$row)->getValue();
	if($a13!='' ){
$_SESSION['detallistaC']['allowanceCharge'][$row]['base']=$a13;

echo '<td>' . $a13 . '</td>';
}else{ }

$a15=$worksheet->getCellByColumnAndRow(15,$row)->getValue();
	if($a15!='' ){
echo '<td>' . $a15 . '</td>';
}else{ }


$a16=$worksheet->getCellByColumnAndRow(16,$row)->getValue();
	if($a16!='' ){
$_SESSION['detallistaC']['allowanceCharge'][$row]['percentage']=$a16;

echo '<td>' . $a16 . '</td>';
}else{ }
echo '</tr>';
}}
////totalAmount
$detallistaLectura = $detallistaLectura + 5 ;
$stop=$stop + 5;
for($row = $stop; $row <= $detallistaLectura; ++$row){

if($worksheet->getCellByColumnAndRow(0,$row )->getValue()!='ejemplo'){
echo '<tr>';
///////////////////////////

$a1=$worksheet->getCellByColumnAndRow(1,$row)->getValue();
	if($a1!='' ){
echo '<td>' . $a1 . '</td>';
}else{ }


$a2=$worksheet->getCellByColumnAndRow(2,$row)->getValue();
	if($a2!='' ){
echo '<td>' . $a2 . '</td>';
}else{ }

////valor
$a3=$worksheet->getCellByColumnAndRow(3,$row)->getValue();
	if($a3!='' ){
	$_SESSION['detallistaC']['totalAmount'][$row]['Amount']=$a3;
echo '<td>' . $a3 . '</td>';
}else{ }

$a4=$worksheet->getCellByColumnAndRow(4,$row)->getValue();
	if($a4!='' ){
echo '<td>' . $a4 . '</td>';
}else{ }


echo '</tr>';
}}
////TotalAllowanceCharge
$detallistaLectura = $detallistaLectura + 5 ;
$stop=$stop + 5;
for($row = $stop; $row <= $detallistaLectura; ++$row){

if($worksheet->getCellByColumnAndRow(0,$row )->getValue()!='ejemplo'){
echo '<tr>';
///////////////////////////

$a1=$worksheet->getCellByColumnAndRow(1,$row)->getValue();
	if($a1!='' ){
echo '<td>' . $a1 . '</td>';
}else{ }


$a2=$worksheet->getCellByColumnAndRow(2,$row)->getValue();
	if($a2!='' ){
echo '<td>' . $a2 . '</td>';
}else{ }

////valor
$a3=$worksheet->getCellByColumnAndRow(3,$row)->getValue();
	if($a3!='' ){
$_SESSION['detallistaC']['TotalAllowanceCharge'][$row]['allowanceOrChargeType']=$a3;
echo '<td>' . $a3 . '</td>';
}else{ }

$a4=$worksheet->getCellByColumnAndRow(4,$row)->getValue();
	if($a4!='' ){
echo '<td>' . $a4 . '</td>';
}else{ }

$a5=$worksheet->getCellByColumnAndRow(5,$row)->getValue();
	if($a5!='' ){
echo '<td>' . $a5 . '</td>';
}else{}
////valor
$a6=$worksheet->getCellByColumnAndRow(6,$row)->getValue();
	if($a6!='' ){
$_SESSION['detallistaC']['TotalAllowanceCharge'][$row]['specialServicesType']=$a6;

echo '<td>' . $a6 . '</td>';
}else{ }

$a8=$worksheet->getCellByColumnAndRow(8,$row)->getValue();
	if($a8!='' ){
echo '<td>' . $a8 . '</td>';
}else{ }
////valor
$a9=$worksheet->getCellByColumnAndRow(9,$row)->getValue();
	if($a9!='' ){
$_SESSION['detallistaC']['TotalAllowanceCharge'][$row]['Amount']=$a9;

echo '<td>' . $a9 . '</td>';
}else{ }

$a10=$worksheet->getCellByColumnAndRow(10,$row)->getValue();
	if($a10!='' ){
echo '<td>' . $a10 . '</td>';
}else{ }

echo '</tr>';
}}

?></table><?php
}

}

echo $_SESSION['exito'] = '<p style="color:#006600; font-size:24px;">Listo se agregó la addenda</p>';


$_SESSION['xml_armado'] = Batch_xmlElement($valor,$value,$value1);


?>
<form method="post" action="xml.php">

<input type="submit" name="web_services" value="Timbrar" />


</form>
<br />
<?php





}else{echo '<p class="ap">Si se encontró un link, presiona para borrar.</p>';}

}else{echo '<p class="ac">No es el RFC Emisor o Receptor</p>'; }

if(!isset($_POST['grabar'])){
?>

<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" >

<table border="1" cellpadding="0" cellspacing="0" width="100%" >
<tr>
 <td>



<label>Siguiente</label><br />
<input type="submit" name="grabar"  value="grabar" /><br />

</td></tr>
</table>

</form>
<br />
<?php 
}
$sin_comillas = isset($_SESSION['xml_armado'])?$_SESSION['xml_armado']:'';
$sin_comillas = str_replace('"','&quot;',$sin_comillas);
$sin_menosque = str_replace('<','&lt;',$sin_comillas);
$sin_masque = str_replace('>','&gt;',$sin_menosque);
//print_r($_SESSION) ;
?>
<div style="overflow:auto; height:150px; border:#006600 1px solid;">
<?php echo $sin_masque;?>
</div>
<br /><br /><br /><br />

</body>
</html>
