<?
if(!isset($_SESSION['usuario_p_prov_absa']) || trim($_SESSION['usuario_p_prov_absa']) == "" || trim(strtoupper($_SESSION["URL_PORTAL"]."admin.php")) != trim(strtoupper($_SERVER['HTTP_REFERER']))){
	?><script>window.location.href="<?=$_SESSION["URL_PORTAL"]."index.php"?>"</script><?
	exit;
}
$col_name[0]="A";
$col_name[1]="B";
$col_name[2]="C";
$col_name[3]="D";
$col_name[4]="E";
$col_name[5]="F";
$col_name[6]="G";
$col_name[7]="H";
$col_name[8]="I";
$col_name[9]="J";
$col_name[10]="K";
$col_name[11]="L";
$col_name[12]="M";
$col_name[13]="N";
$col_name[14]="O";
$col_name[15]="P";
$col_name[16]="Q";
$col_name[17]="R";
$col_name[18]="S";
$col_name[19]="T";
$col_name[20]="U";
$col_name[21]="V";
$col_name[22]="W";
$col_name[23]="X";
$col_name[24]="Y";
$col_name[25]="Z";

//if(strtoupper(trim($_SESSION['usuario_p_prov_absa'])) == "ADMIN"){
	$rfcreceptor = $_REQUEST['RFCReceptor'];
/*}else{
	$rfcreceptor = $_SESSION['RFC_RECEPTOR_PORTAL'];
}*/

$q=generaQuery($_REQUEST["serie"],$_REQUEST["serie"],"I CFDI 3.3",$rfcreceptor,$_REQUEST["folio"],$_REQUEST["folio"],$_REQUEST["fecha_emision_inicio"],$_REQUEST["fecha_emision_final"],$_REQUEST["emisor_nombre"],$_REQUEST["emisor_rfc"]);

if(!$rRecibeDoce = mysqli_query($datosbd->CONEXION,$q)){
	?><script>$j_6.messager.alert("Error","Ocurrio un error al consultar los documentos.","error.");</script><?exit;
}
if(mysqli_num_rows($rRecibeDoce) <= 0){
	?><script>$j_6.messager.alert("Error","No se encontraron documentos.","error.");</script><?exit;
}



$objPHPExcel->setActiveSheetIndex(0);
$conEncabezado=0;
$NumRow=0;

if(!$rRecibeDoce = mysqli_query($datosbd->CONEXION,$q)){
	?><script>$j_6.messager.alert("Error","Ocurrio un error al consultar los documentos.","error.");</script><?exit;
}
if(mysqli_num_rows($rRecibeDoce) <= 0){
	?><script>$j_6.messager.alert("Error","No se encontraron documentos.","error.");</script><?exit;
}
while($tRecibeDoce = mysqli_fetch_array($rRecibeDoce,MYSQLI_ASSOC)){
	
	$montoTotalCompensado = $tRecibeDoce["totalIngresoCompensado"];
	$sumaPagadoEnPago=0.00;
	$sumaPagadoEnComplemento=0.00;
	$totalAPagarEnPago=0.00;
	$totalAPagarEnComplemento=0.00;
	
	PintaEncabezado();
	
	$qMontosAplicados = "select pdr.serie as Dserie,pdr.folio as Dfolio,pdr.adicionalA as Duuid,pdr.total as Dtotal,pdr.adicionalB as Dformadepago,pdr.uuidcfdirelacionado,pdr.monto as PDRmontoPago,pdr.numparcialidad as PDRnumparcialidad,pdr.tipocambio as PDRtipocambio,pdr.moneda as PDRmoneda,pdr.MetodoDePago,
			tmp.TipoCambioDR as RPDRtipocambio,tmp.MonedaDR as RPDRmoneda,tmp.ImpPagado as RPDRimpagado,tmp.NumParcialidad as RPDRnumparcialidad,
			r.nombreemi,r.serie,r.folio,
			tmp.MonedaP as RDPmoneda,tmp.Monto as RDPmonto,tmp.recibedoce_UUID,tmp.TipoCambioP as RDPtipocambio,tmp.FormaDePago as RDPformadepago,
			tmp.serie as RepSerie,tmp.folio as RepFolio,tmp.uuid as RepUUID,tmp.recibedoce_pagos_id as recibedoce_pagos_id
			from 
			
			(select d.serie,d.folio,d.adicionalA,d.total,d.adicionalB,pdr.uuidcfdirelacionado,pdr.monto,pdr.numparcialidad,pdr.tipocambio,pdr.moneda,pdr.MetodoDePago,pdr.doce_uuid from doce d inner join
			pago_documentos_ref pdr ON d.adicionalA=pdr.doce_uuid where d.status = 1) as pdr			
			
			left join 
			
			(select rpdr.recibedoce_pagos_ID, rpdr.uuidCFDIRelacionado, rpdr.doce_UUID, rpdr.MonedaDR, rpdr.TipoCambioDR, rpdr.NumParcialidad, rpdr.ImpPagado, rpdr.MetodoDePago, rdp.recibedoce_UUID, rdp.FechaPago, rdp.TipoCambioP, rdp.MonedaP, rdp.Monto, rdp.RfcEmisorCtaOrd, rdp.RfcEmisorCtaBen, rdp.FormaDePago,rcomplemento.serie,rcomplemento.folio,rcomplemento.uuid  from 
			recibedoce_pagos_docto_relacionado rpdr 
			left join recibedoce_pagos rdp ON rpdr.recibedoce_pagos_id = rdp.recibedoce_pagos_id 
			left join recibedoce rcomplemento ON rdp.recibedoce_UUID=rcomplemento.uuid where rpdr.uuidCFDIRelacionado = '".$tRecibeDoce["uuid"]."' and rcomplemento.status not in('R','C'))as tmp
			
			ON pdr.doce_uuid = tmp.doce_UUID and pdr.uuidcfdirelacionado = tmp.uuidCFDIRelacionado and (pdr.numparcialidad = tmp.NumParcialidad or pdr.numparcialidad <> tmp.NumParcialidad)
			left join recibedoce r on tmp.uuidCFDIRelacionado = r.uuid where pdr.uuidCFDIRelacionado='".$tRecibeDoce["uuid"]."'
			
			UNION ALL
			
			select pdr.serie as Dserie,pdr.folio as Dfolio,pdr.adicionalA as Duuid,pdr.total as Dtotal,pdr.adicionalB as Dformadepago,pdr.uuidcfdirelacionado,pdr.monto as PDRmontoPago,pdr.numparcialidad as PDRnumparcialidad,pdr.tipocambio as PDRtipocambio,pdr.moneda as PDRmoneda,pdr.MetodoDePago,
			tmp.TipoCambioDR as RPDRtipocambio,tmp.MonedaDR as RPDRmoneda,tmp.ImpPagado as RPDRimpagado,tmp.NumParcialidad as RPDRnumparcialidad,
			r.nombreemi,r.serie,r.folio,
			tmp.MonedaP as RDPmoneda,tmp.Monto as RDPmonto,tmp.recibedoce_UUID,tmp.TipoCambioP as RDPtipocambio,tmp.FormaDePago as RDPformadepago,
			tmp.serie as RepSerie,tmp.folio as RepFolio,tmp.uuid as RepUUID,tmp.recibedoce_pagos_id as recibedoce_pagos_id
			from 
			
			(select d.serie,d.folio,d.adicionalA,d.total,d.adicionalB,pdr.uuidcfdirelacionado,pdr.monto,pdr.numparcialidad,pdr.tipocambio,pdr.moneda,pdr.MetodoDePago,pdr.doce_uuid from doce d inner join
			pago_documentos_ref pdr ON d.adicionalA=pdr.doce_uuid where d.status = 1) as pdr
			
			
			right join 
			
			(select rpdr.recibedoce_pagos_ID, rpdr.uuidCFDIRelacionado, rpdr.doce_UUID, rpdr.MonedaDR, rpdr.TipoCambioDR, rpdr.NumParcialidad, rpdr.ImpPagado, rpdr.MetodoDePago, rdp.recibedoce_UUID, rdp.FechaPago, rdp.TipoCambioP, rdp.MonedaP, rdp.Monto, rdp.RfcEmisorCtaOrd, rdp.RfcEmisorCtaBen, rdp.FormaDePago,rcomplemento.serie,rcomplemento.folio,rcomplemento.uuid,rcomplemento.status  from 
			recibedoce_pagos_docto_relacionado rpdr 
			left join recibedoce_pagos rdp ON rpdr.recibedoce_pagos_id = rdp.recibedoce_pagos_id 
			left join recibedoce rcomplemento ON rdp.recibedoce_UUID=rcomplemento.uuid where rpdr.uuidCFDIRelacionado = '".$tRecibeDoce["uuid"]."' and 
            rcomplemento.status not in('R','C'))as tmp
			
			ON pdr.doce_uuid = tmp.doce_UUID and pdr.uuidcfdirelacionado = tmp.uuidCFDIRelacionado and (pdr.numparcialidad = tmp.NumParcialidad or pdr.numparcialidad <> tmp.NumParcialidad)
			left join recibedoce r on tmp.uuidCFDIRelacionado = r.uuid where pdr.doce_uuid is null";
			
	
	if(!$rMontosAplicados = mysqli_query($datosbd->CONEXION,$qMontosAplicados)){
		echo mysqli_error($datosbd->CONEXION);
		?><script>$j_6.messager.alert("Error","Ocurrio un error al consultar los documentos.","error.");</script><?exit;
	}
	if(mysqli_num_rows($rMontosAplicados) <= 0){
		continue;
	}
	PintaDetalleEncabezado();
	$con=0;
	$tdEstiloPagoTotalNP="";
	$tdEstiloPagoTotalREP="";
	$tdEstiloPagoNPvsComplemento="";
	$banIncorrecto=false;
	$sumaPagadoEnComplemento=0.00;
	$sumaPagadoEnPago=0.00;
	while($tMontosAplicados = mysqli_fetch_array($rMontosAplicados,MYSQLI_ASSOC)){
		
		$sumaPagadoEnComplemento+=$tMontosAplicados["RPDRimpagado"];
		$sumaPagadoEnPago+=$tMontosAplicados["PDRmontoPago"];
		$con++;
		$res = $con%2;
		$trEstilo="";
		if($res == 0)
			$trEstilo = "style='background-color: #999999'";
		
		$tdEstiloMonto = "";
		$tdEstiloTipoCambio = "";
		$tdEstiloMoneda = "";
		$tdEstiloParcialidad = "";
		$tdEstiloFormaDePago = "";
		if((float) $tMontosAplicados["PDRmontoPago"] != (float) $tMontosAplicados["RPDRimpagado"]){
			$diferencia = (float) $tMontosAplicados["PDRmontoPago"] - (float) $tMontosAplicados["RPDRimpagado"];
			if($diferencia < 0){
				$diferencia = $diferencia * -1;
			}
			
			if((float) $diferencia > (float) $tConfig["tolerancia_NPvsComplemento"]){
				$tdEstiloMonto = "style='background-color: red'";
				$banIncorrecto=true;
			}else{
				$tdEstiloMonto = "style='background-color: orange'";
			}
			// $tdEstiloMonto="style='background-color: red'";
			// $banIncorrecto=true;
		}
		if((float) $tMontosAplicados["PDRtipocambio"] != (float) $tMontosAplicados["RPDRtipocambio"]){
			$diferencia = (float) $tMontosAplicados["PDRtipocambio"] - (float) $tMontosAplicados["RPDRtipocambio"];
			if($diferencia < 0){
				$diferencia = $diferencia * -1;
			}
			
			if((float) $diferencia > (float) $tConfig["tolerancia_tipoCambio"]){
				$tdEstiloTipoCambio = "style='background-color: red'";
				$banIncorrecto=true;
			}else{
				$tdEstiloTipoCambio = "style='background-color: orange'";
			}
			// $tdEstiloTipoCambio="style='background-color: red'";
			// $banIncorrecto=true;
			
		}
		if($tMontosAplicados["PDRmoneda"] != $tMontosAplicados["RPDRmoneda"]){
			$tdEstiloMoneda="style='background-color: red'";
			$banIncorrecto=true;
			
		}
		if($tMontosAplicados["PDRnumparcialidad"] != $tMontosAplicados["RPDRnumparcialidad"]){
			$tdEstiloParcialidad="style='background-color: red'";
			$banIncorrecto=true;
		}
		if($tMontosAplicados["Dformadepago"] != $tMontosAplicados["RDPformadepago"]){
			$tdEstiloFormaDePago="style='background-color: red'";
			$banIncorrecto=true;
		}
		PintaDetalleDetalle();
	}
	
	//Multiplico por 1000000 para sacar la parte entera y poder comparar enteros, ya que con decimales hay problemas
	$sumaPagadoEnPago1000000 = $sumaPagadoEnPago * 1000000;
	$sumaPagadoEnComplemento1000000 = $sumaPagadoEnComplemento * 1000000;
	$arrSumaPagadoEnPago1000000 = explode(".",$sumaPagadoEnPago1000000);
	$arrSumaPagadoEnComplemento1000000 = explode(".",$sumaPagadoEnComplemento1000000);
	
	$tdEstiloPagoNPvsComplemento = "style='text-align: right;'";
	
	// if($sumaPagadoEnPago != $sumaPagadoEnComplemento){
	if($arrSumaPagadoEnPago1000000[0] != $arrSumaPagadoEnComplemento1000000[0]){
		$diferencia = (float) $sumaPagadoEnPago - (float) $sumaPagadoEnComplemento;
		if($diferencia < 0){
			$diferencia = $diferencia * -1;
		}
		
		if((float) $diferencia > (float) $tConfig["tolerancia_NPvsComplemento"]){
			$tdEstiloPagoNPvsComplemento = "style='text-align: right; background-color: red'";
			$banIncorrecto=true;
		}else{
			$tdEstiloPagoNPvsComplemento = "style='text-align: right; background-color: orange'";
		}
		// $tdEstiloPagoTotal="style='background-color: red'";
		// $banIncorrecto=true;
	}
	//echo $tRecibeDoce["total"]." - ".$sumaPagadoEnPago." - ".$montoTotalCompensado;
	$totalAPagarEnPago = $tRecibeDoce["total"] - ($sumaPagadoEnPago + $montoTotalCompensado);
	$totalAPagarEnComplemento = $tRecibeDoce["total"] - ($sumaPagadoEnComplemento + $montoTotalCompensado);
	
	if($totalAPagarEnPago != 0){
		
		$totalAPagarEnPagoNoNegativo = $totalAPagarEnPago;
		if($totalAPagarEnPagoNoNegativo < 0){$totalAPagarEnPagoNoNegativo = $totalAPagarEnPagoNoNegativo*-1;}
		
		$tolerancia_FacturaPagada1000000 = explode(".",$tConfig["tolerancia_FacturaPagada"] * 1000000);
		$totalAPagarEnPagoNoNegativo1000000 = explode(".",$totalAPagarEnPagoNoNegativo * 1000000);
		
		if((float) $totalAPagarEnPagoNoNegativo1000000[0] > (float) $tolerancia_FacturaPagada1000000[0]){
			$tdEstiloPagoTotalNP = "style='text-align: right; background-color: red'";
			$banIncorrecto=true;
		}else{
			$tdEstiloPagoTotalNP = "style='text-align: right; background-color: orange'";
		}
		// $tdEstiloPagoTotalNP="style='background-color: red'";
		// $banIncorrecto=true;
	}
	if($totalAPagarEnComplemento != 0){
		$totalAPagarEnComplementoNoNegativo = $totalAPagarEnComplemento;
		if($totalAPagarEnComplementoNoNegativo < 0){$totalAPagarEnComplementoNoNegativo = $totalAPagarEnComplementoNoNegativo*-1;}
		
		$tolerancia_FacturaPagada1000000 = explode(".",$tConfig["tolerancia_FacturaPagada"] * 1000000);
		$totalAPagarEnComplementoNoNegativo1000000 = explode(".",$totalAPagarEnComplementoNoNegativo * 1000000);
		
		if((float) $totalAPagarEnComplementoNoNegativo1000000[0] > (float) $tolerancia_FacturaPagada1000000[0]){
			$tdEstiloPagoTotalREP = "style='text-align: right; background-color: red'";
			$banIncorrecto=true;
		}else{
			$tdEstiloPagoTotalREP = "style='text-align: right; background-color: orange'";
		}
		// $tdEstiloPagoTotalREP="style='background-color: red'";
		// $banIncorrecto=true;
	}
	PintaTotalesDetalle();
}

$objPHPExcel->getActiveSheet()->setTitle("Status pago CFDIs");


function PintaEncabezado(){
	global $tRecibeDoce,$conEncabezado,$NumRow,$objPHPExcel,$col_name;
	$conEncabezado++;
	$NumRow++;
	$header_name = array("Proveedor","Serie","Folio","UUID","Total","Moneda","Tipo Cambio");
	$col=0;
	$autofilter=0;
	for($row=0; $row < count($header_name); $row++){
			$objPHPExcel->getActiveSheet()->setCellValue($col_name[$col].$NumRow, $header_name[$row]);
			$objPHPExcel->getActiveSheet()->getColumnDimension($col_name[$col])->setAutoSize(true);
			$autofilter++;
			$col++;
	}
	$objPHPExcel->getActiveSheet()->getStyle('A'.$NumRow.':'.$col_name[$autofilter-1].$NumRow)->applyFromArray(
		array(
			'font'    => array(
				'bold'      => true,
				'color'      => array('rgb' => 'FFFFFF')
			),
			'alignment' => array(
				'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
			),
			'borders' => array(
				'allborders'     => array(
 					'style' => PHPExcel_Style_Border::BORDER_THIN
 				)
			),
			'fill' => array(
	 			//'type'       => PHPExcel_Style_Fill::FILL_GRADIENT_LINEAR,
	 			'type'       => PHPExcel_Style_Fill::FILL_SOLID,
				'color' => array('rgb' => '000000'),
	  			'rotation'   => 90
	 			/*'startcolor' => array(
	 				'argb' => '99999999'
	 			),
	 			'endcolor'   => array(
	 				'argb' => '99999999'
	 			)*/
	 		)
		)
	);
	$NumRow++;

	$objPHPExcel->getActiveSheet()->setCellValue($col_name[0].$NumRow, $tRecibeDoce["nombreemi"]);
	$objPHPExcel->getActiveSheet()->setCellValue($col_name[1].$NumRow, $tRecibeDoce["serie"]);
	$objPHPExcel->getActiveSheet()->setCellValue($col_name[2].$NumRow, $tRecibeDoce["folio"]);
	$objPHPExcel->getActiveSheet()->setCellValue($col_name[3].$NumRow, $tRecibeDoce["uuid"]);
	$objPHPExcel->getActiveSheet()->setCellValue($col_name[4].$NumRow, $tRecibeDoce["total"]);
	$objPHPExcel->getActiveSheet()->setCellValue($col_name[5].$NumRow, $tRecibeDoce["tipoMoneda"]);
	$objPHPExcel->getActiveSheet()->setCellValue($col_name[6].$NumRow, $tRecibeDoce["TipoCambio"]);
}
function PintaDetalleEncabezado(){
	global $NumRow,$objPHPExcel,$col_name;
	$NumRow++;
	$objPHPExcel->getActiveSheet()->setCellValue($col_name[0].$NumRow, "PAGOS AL DOCUMENTO");
	$objPHPExcel->getActiveSheet()->mergeCells($col_name[0].$NumRow.':'.$col_name[14].$NumRow);
	$objPHPExcel->getActiveSheet()->getStyle($col_name[0].$NumRow.':'.$col_name[14].$NumRow)->applyFromArray(
			array(
				'font'    => array(
					'bold'      => true,
					'color'      => array('rgb' => '000000')
				),
				'alignment' => array(
					'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
				),
				'borders' => array(
					'allborders'     => array(
						'style' => PHPExcel_Style_Border::BORDER_THIN
					)
				),
				'fill' => array(
					// 'type'       => PHPExcel_Style_Fill::FILL_GRADIENT_LINEAR,
					'type'       => PHPExcel_Style_Fill::FILL_SOLID,
					'rotation'   => 90,
					'color' => array('rgb' => 'BBBBBB'),
					/*'startcolor' => array(
						'argb' => 'FFFFAA00'
					),
					'endcolor'   => array(
						'argb' => '00000000'
					)*/
				)
			)
		);
	$NumRow++;
	$objPHPExcel->getActiveSheet()->setCellValue($col_name[0].$NumRow, "Pago / I CFDI 3.3");
	$objPHPExcel->getActiveSheet()->mergeCells($col_name[0].$NumRow.':'.$col_name[6].$NumRow);
	$objPHPExcel->getActiveSheet()->getStyle($col_name[0].$NumRow.':'.$col_name[6].$NumRow)->applyFromArray(
			array(
				'font'    => array(
					'bold'      => true,
					'color'      => array('rgb' => '000000')
				),
				'alignment' => array(
					'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
				),
				'borders' => array(
					'allborders'     => array(
						'style' => PHPExcel_Style_Border::BORDER_THIN
					)
				),
				'fill' => array(
					// 'type'       => PHPExcel_Style_Fill::FILL_GRADIENT_LINEAR,
					'type'       => PHPExcel_Style_Fill::FILL_SOLID,
					'rotation'   => 90,
					'color' => array('rgb' => 'BBBBBB'),
					/*'startcolor' => array(
						'argb' => 'FFFFAA00'
					),
					'endcolor'   => array(
						'argb' => '00000000'
					)*/
				)
			)
		);
	$objPHPExcel->getActiveSheet()->setCellValue($col_name[7].$NumRow, "Complemento / I CFDI 3.3");
	$objPHPExcel->getActiveSheet()->mergeCells($col_name[7].$NumRow.':'.$col_name[14].$NumRow);
	$objPHPExcel->getActiveSheet()->getStyle($col_name[7].$NumRow.':'.$col_name[14].$NumRow)->applyFromArray(
			array(
				'font'    => array(
					'bold'      => true,
					'color'      => array('rgb' => '000000')
				),
				'alignment' => array(
					'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
				),
				'borders' => array(
					'allborders'     => array(
						'style' => PHPExcel_Style_Border::BORDER_THIN
					)
				),
				'fill' => array(
					// 'type'       => PHPExcel_Style_Fill::FILL_GRADIENT_LINEAR,
					'type'       => PHPExcel_Style_Fill::FILL_SOLID,
					'rotation'   => 90,
					'color' => array('rgb' => 'BBBBBB'),
					/*'startcolor' => array(
						'argb' => 'FFFFAA00'
					),
					'endcolor'   => array(
						'argb' => '00000000'
					)*/
				)
			)
		);
	$NumRow++;
	$objPHPExcel->getActiveSheet()->setCellValue($col_name[0].$NumRow, "Serie");
	$objPHPExcel->getActiveSheet()->setCellValue($col_name[1].$NumRow, "Folio");
	$objPHPExcel->getActiveSheet()->setCellValue($col_name[2].$NumRow, "Forma de pago");
	$objPHPExcel->getActiveSheet()->setCellValue($col_name[3].$NumRow, "Parcialidad");
	$objPHPExcel->getActiveSheet()->setCellValue($col_name[4].$NumRow, "Tipo cambio");
	$objPHPExcel->getActiveSheet()->setCellValue($col_name[5].$NumRow, "Moneda");
	$objPHPExcel->getActiveSheet()->setCellValue($col_name[6].$NumRow, "Monto");
	$objPHPExcel->getActiveSheet()->setCellValue($col_name[7].$NumRow, "Forma de pago");
	$objPHPExcel->getActiveSheet()->setCellValue($col_name[8].$NumRow, "Parcialidad");
	$objPHPExcel->getActiveSheet()->setCellValue($col_name[9].$NumRow, "Tipo cambio");
	$objPHPExcel->getActiveSheet()->setCellValue($col_name[10].$NumRow, "Moneda");
	$objPHPExcel->getActiveSheet()->setCellValue($col_name[11].$NumRow, "Monto");
	$objPHPExcel->getActiveSheet()->setCellValue($col_name[12].$NumRow, "REP UUID");
	$objPHPExcel->getActiveSheet()->setCellValue($col_name[13].$NumRow, "REP Serie");
	$objPHPExcel->getActiveSheet()->setCellValue($col_name[14].$NumRow, "REP Folio");
	
	foreach(range('A','O') as $columnID) {
    $objPHPExcel->getActiveSheet()->getColumnDimension($columnID)
        ->setAutoSize(true);
	}
	
	
	$objPHPExcel->getActiveSheet()->getStyle('A'.$NumRow.':'.$col_name[14].$NumRow)->applyFromArray(
			array(
				'font'    => array(
					'bold'      => true,
					'color'      => array('rgb' => '000000')
				),
				'alignment' => array(
					'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_LEFT,
				),
				'borders' => array(
					'allborders'     => array(
						'style' => PHPExcel_Style_Border::BORDER_THIN
					)
				),
				'fill' => array(
					// 'type'       => PHPExcel_Style_Fill::FILL_GRADIENT_LINEAR,
					'type'       => PHPExcel_Style_Fill::FILL_SOLID,
					'rotation'   => 90,
					'color' => array('rgb' => 'BBBBBB'),
					/*'startcolor' => array(
						'argb' => 'FFFFAA00'
					),
					'endcolor'   => array(
						'argb' => '00000000'
					)*/
				)
			)
		);
}

function PintaDetalleDetalle(){
	global $tMontosAplicados,$NumRow,$objPHPExcel,$col_name,$tdEstiloFormaDePago,$tdEstiloParcialidad,$tdEstiloTipoCambio,$tdEstiloMoneda,$tdEstiloMonto;
	$NumRow++;
	
	if(strpos($tdEstiloFormaDePago,"red") !== false){$tdEstiloFormaDePago="FF0000";}else if(strpos($tdEstiloFormaDePago,"orange") !== false){$tdEstiloFormaDePago="FF9933";}else{$tdEstiloFormaDePago = "FFFFFF";}
	if(strpos($tdEstiloParcialidad,"red") !== false){$tdEstiloParcialidad="FF0000";}else if(strpos($tdEstiloParcialidad,"orange") !== false){$tdEstiloParcialidad="FF9933";}else{$tdEstiloParcialidad = "FFFFFF";}
	if(strpos($tdEstiloTipoCambio,"red") !== false){$tdEstiloTipoCambio="FF0000";}else if(strpos($tdEstiloTipoCambio,"orange") !== false){$tdEstiloTipoCambio="FF9933";}else{$tdEstiloTipoCambio = "FFFFFF";}
	if(strpos($tdEstiloMoneda,"red") !== false){$tdEstiloMoneda="FF0000";}else if(strpos($tdEstiloMoneda,"orange") !== false){$tdEstiloMoneda="FF9933";}else{$tdEstiloMoneda = "FFFFFF";}
	if(strpos($tdEstiloMonto,"red") !== false){$tdEstiloMonto="FF0000";}else if(strpos($tdEstiloMonto,"orange") !== false){$tdEstiloMonto="FF9933";}else{$tdEstiloMonto = "FFFFFF";}
	
	$objPHPExcel->getActiveSheet()->setCellValue($col_name[0].$NumRow, $tMontosAplicados["Dserie"]);
	$objPHPExcel->getActiveSheet()->setCellValue($col_name[1].$NumRow, $tMontosAplicados["Dfolio"]);
	$objPHPExcel->getActiveSheet()->setCellValue($col_name[2].$NumRow, $tMontosAplicados["Dformadepago"]);
	$objPHPExcel->getActiveSheet()->setCellValue($col_name[3].$NumRow, $tMontosAplicados["PDRnumparcialidad"]);
	$objPHPExcel->getActiveSheet()->setCellValue($col_name[4].$NumRow, $tMontosAplicados["PDRtipocambio"]);
	$objPHPExcel->getActiveSheet()->setCellValue($col_name[5].$NumRow, $tMontosAplicados["PDRmoneda"]);
	$objPHPExcel->getActiveSheet()->setCellValue($col_name[6].$NumRow, $tMontosAplicados["PDRmontoPago"]);
	$objPHPExcel->getActiveSheet()->setCellValue($col_name[7].$NumRow, $tMontosAplicados["RDPformadepago"]);
	$objPHPExcel->getActiveSheet()->setCellValue($col_name[8].$NumRow, $tMontosAplicados["RPDRnumparcialidad"]);
	$objPHPExcel->getActiveSheet()->setCellValue($col_name[9].$NumRow, $tMontosAplicados["RPDRtipocambio"]);
	$objPHPExcel->getActiveSheet()->setCellValue($col_name[10].$NumRow, $tMontosAplicados["RPDRmoneda"]);
	$objPHPExcel->getActiveSheet()->setCellValue($col_name[11].$NumRow, $tMontosAplicados["RPDRimpagado"]);
	$objPHPExcel->getActiveSheet()->setCellValue($col_name[12].$NumRow, $tMontosAplicados["RepUUID"]);
	$objPHPExcel->getActiveSheet()->setCellValue($col_name[13].$NumRow, $tMontosAplicados["RepSerie"]);
	$objPHPExcel->getActiveSheet()->setCellValue($col_name[14].$NumRow, $tMontosAplicados["RepFolio"]);
	
	$objPHPExcel->getActiveSheet()->getStyle($col_name[2].$NumRow)->applyFromArray(array('fill' => array('type' => PHPExcel_Style_Fill::FILL_SOLID,'color' => array('rgb' => $tdEstiloFormaDePago),'borders' => array('allborders'=> array('style' => PHPExcel_Style_Border::BORDER_THIN)))));
	$objPHPExcel->getActiveSheet()->getStyle($col_name[3].$NumRow)->applyFromArray(array('fill' => array('type' => PHPExcel_Style_Fill::FILL_SOLID,'color' => array('rgb' => $tdEstiloParcialidad),'borders' => array('allborders'=> array('style' => PHPExcel_Style_Border::BORDER_THIN)))));
	$objPHPExcel->getActiveSheet()->getStyle($col_name[4].$NumRow)->applyFromArray(array('fill' => array('type' => PHPExcel_Style_Fill::FILL_SOLID,'color' => array('rgb' => $tdEstiloTipoCambio),'borders' => array('allborders'=> array('style' => PHPExcel_Style_Border::BORDER_THIN)))));
	$objPHPExcel->getActiveSheet()->getStyle($col_name[5].$NumRow)->applyFromArray(array('fill' => array('type' => PHPExcel_Style_Fill::FILL_SOLID,'color' => array('rgb' => $tdEstiloMoneda),'borders' => array('allborders'=> array('style' => PHPExcel_Style_Border::BORDER_THIN)))));
	$objPHPExcel->getActiveSheet()->getStyle($col_name[6].$NumRow)->applyFromArray(array('fill' => array('type' => PHPExcel_Style_Fill::FILL_SOLID,'color' => array('rgb' => $tdEstiloMonto),'borders' => array('allborders'=> array('style' => PHPExcel_Style_Border::BORDER_THIN)))));
	$objPHPExcel->getActiveSheet()->getStyle($col_name[7].$NumRow)->applyFromArray(array('fill' => array('type' => PHPExcel_Style_Fill::FILL_SOLID,'color' => array('rgb' => $tdEstiloFormaDePago),'borders' => array('allborders'=> array('style' => PHPExcel_Style_Border::BORDER_THIN)))));
	$objPHPExcel->getActiveSheet()->getStyle($col_name[8].$NumRow)->applyFromArray(array('fill' => array('type' => PHPExcel_Style_Fill::FILL_SOLID,'color' => array('rgb' => $tdEstiloParcialidad),'borders' => array('allborders'=> array('style' => PHPExcel_Style_Border::BORDER_THIN)))));
	$objPHPExcel->getActiveSheet()->getStyle($col_name[9].$NumRow)->applyFromArray(array('fill' => array('type' => PHPExcel_Style_Fill::FILL_SOLID,'color' => array('rgb' => $tdEstiloTipoCambio),'borders' => array('allborders'=> array('style' => PHPExcel_Style_Border::BORDER_THIN)))));
	$objPHPExcel->getActiveSheet()->getStyle($col_name[10].$NumRow)->applyFromArray(array('fill' => array('type' => PHPExcel_Style_Fill::FILL_SOLID,'color' => array('rgb' => $tdEstiloMoneda),'borders' => array('allborders'=> array('style' => PHPExcel_Style_Border::BORDER_THIN)))));
	$objPHPExcel->getActiveSheet()->getStyle($col_name[11].$NumRow)->applyFromArray(array('fill' => array('type' => PHPExcel_Style_Fill::FILL_SOLID,'color' => array('rgb' => $tdEstiloMonto),'borders' => array('allborders'=> array('style' => PHPExcel_Style_Border::BORDER_THIN)))));
}

function PintaTotalesDetalle(){
	global $tRecibeDoce,$NumRow,$objPHPExcel,$col_name,$tdEstiloPagoNPvsComplemento,$tdEstiloPagoTotalREP,$tdEstiloPagoTotalNP,$sumaPagadoEnComplemento,$totalAPagarEnPago,$totalAPagarEnComplemento;
	
	if(strpos($tdEstiloPagoTotalREP,"red") !== false){$tdEstiloPagoTotalREP="FF0000";}else if(strpos($tdEstiloPagoTotalREP,"orange") !== false){$tdEstiloPagoTotalREP="FF9933";}else{$tdEstiloPagoTotalREP = "FFFFFF";}
	
	if(strpos($tdEstiloPagoTotalNP,"red") !== false){$tdEstiloPagoTotalNP="FF0000";}else if(strpos($tdEstiloPagoTotalNP,"orange") !== false){$tdEstiloPagoTotalNP="FF9933";}else{$tdEstiloPagoTotalNP = "FFFFFF";}
	
	if(strpos($tdEstiloPagoNPvsComplemento,"red") !== false){$tdEstiloPagoNPvsComplemento="FF0000";}else if(strpos($tdEstiloPagoNPvsComplemento,"orange") !== false){$tdEstiloPagoNPvsComplemento="FF9933";}else{$tdEstiloPagoNPvsComplemento = "FFFFFF";}
	
	/*if($totalAPagarEnPago < 0){$totalAPagarEnPago = $totalAPagarEnPago*-1;}
	if($totalAPagarEnComplemento < 0){$totalAPagarEnComplemento = $totalAPagarEnComplemento*-1;}*/
	
	$NumRow++;
	$objPHPExcel->getActiveSheet()->setCellValue($col_name[0].$NumRow, "Total Pagado");
	$objPHPExcel->getActiveSheet()->mergeCells($col_name[0].$NumRow.':'.$col_name[4].$NumRow);
	$objPHPExcel->getActiveSheet()->setCellValue($col_name[5].$NumRow, $tRecibeDoce["totalPagoDocumentosRef"]);
	$objPHPExcel->getActiveSheet()->mergeCells($col_name[5].$NumRow.':'.$col_name[6].$NumRow);
	$objPHPExcel->getActiveSheet()->setCellValue($col_name[7].$NumRow, "Total Pagado");
	$objPHPExcel->getActiveSheet()->mergeCells($col_name[7].$NumRow.':'.$col_name[10].$NumRow);
	$objPHPExcel->getActiveSheet()->setCellValue($col_name[11].$NumRow, $tRecibeDoce["ImpPagadoComplemento"]);
	
	//Aplico colores en celdas
	$objPHPExcel->getActiveSheet()->getStyle($col_name[5].$NumRow)->applyFromArray(array('fill' => array('type' => PHPExcel_Style_Fill::FILL_SOLID,'color' => array('rgb' => $tdEstiloPagoNPvsComplemento),'borders' => array('allborders'=> array('style' => PHPExcel_Style_Border::BORDER_THIN)))));
	
	$objPHPExcel->getActiveSheet()->getStyle($col_name[11].$NumRow)->applyFromArray(array('fill' => array('type' => PHPExcel_Style_Fill::FILL_SOLID,'color' => array('rgb' => $tdEstiloPagoNPvsComplemento),'borders' => array('allborders'=> array('style' => PHPExcel_Style_Border::BORDER_THIN)))));
	
	
	//Termina de aplicar colores en celdas
	
	$NumRow++;
	$objPHPExcel->getActiveSheet()->setCellValue($col_name[0].$NumRow, "Total Compensado");
	$objPHPExcel->getActiveSheet()->mergeCells($col_name[0].$NumRow.':'.$col_name[4].$NumRow);
	$objPHPExcel->getActiveSheet()->setCellValue($col_name[5].$NumRow, $tRecibeDoce["totalIngresoCompensado"]);
	$objPHPExcel->getActiveSheet()->mergeCells($col_name[5].$NumRow.':'.$col_name[6].$NumRow);
	
	$NumRow++;
	$objPHPExcel->getActiveSheet()->setCellValue($col_name[0].$NumRow, "Total a pagar");
	$objPHPExcel->getActiveSheet()->mergeCells($col_name[0].$NumRow.':'.$col_name[4].$NumRow);
	$objPHPExcel->getActiveSheet()->setCellValue($col_name[5].$NumRow, number_format($totalAPagarEnPago,2,".",""));
	$objPHPExcel->getActiveSheet()->mergeCells($col_name[5].$NumRow.':'.$col_name[6].$NumRow);
	
	$objPHPExcel->getActiveSheet()->setCellValue($col_name[7].$NumRow, "Total a pagar");
	$objPHPExcel->getActiveSheet()->mergeCells($col_name[7].$NumRow.':'.$col_name[10].$NumRow);
	$objPHPExcel->getActiveSheet()->setCellValue($col_name[11].$NumRow, number_format($totalAPagarEnComplemento,2,".",""));
	
	$objPHPExcel->getActiveSheet()->getStyle($col_name[5].$NumRow)->applyFromArray(array('fill' => array('type' => PHPExcel_Style_Fill::FILL_SOLID,'color' => array('rgb' => $tdEstiloPagoTotalNP),'borders' => array('allborders'=> array('style' => PHPExcel_Style_Border::BORDER_THIN)))));
	
	$objPHPExcel->getActiveSheet()->getStyle($col_name[11].$NumRow)->applyFromArray(array('fill' => array('type' => PHPExcel_Style_Fill::FILL_SOLID,'color' => array('rgb' => $tdEstiloPagoTotalREP),'borders' => array('allborders'=> array('style' => PHPExcel_Style_Border::BORDER_THIN)))));
}


$q=generaQuery($_REQUEST["serie"],$_REQUEST["serie"],"I CFDI 3.3",$rfcreceptor,$_REQUEST["folio"],$_REQUEST["folio"],$_REQUEST["fecha_emision_inicio"],$_REQUEST["fecha_emision_final"],$_REQUEST["emisor_nombre"],$_REQUEST["emisor_rfc"]);

function generaQuery($serieI,$serieF,$doc,$rfcReceptor,$folioI,$folioF,$fechaI,$fechaF,$busca_nombre,$busca_rfc){
global $conexion,$tConfig;


$notificar_fecha_inicio = $tConfig["notificar_fecha_inicio"];

if(trim($tConfig["notificar_fecha_inicio"]) == "" || $tConfig["notificar_fecha_inicio"]=="0000-00-00 00:00:00"){
	$notificar_fecha_inicio = "2018-01-01 00:00:00";
}
	if($_SESSION['todo_RFC_p_prov_absa'] == "SI"){
		$complementoQuery="";
		$permisosComplemento=$_SESSION['permisos_p_prov_absa'];
	}else{
		$complementoQuery=" rfcEmisor='".$_SESSION['rfc_cliente_p_prov_absa']."'";
	}

	
	$rfcQuery = "";
	if($rfcReceptor != ""){
		$rfcQuery="rfc_receptor='$rfcReceptor'";
	}
	
	
	/*if(trim($_REQUEST['status']) == ""){
		$filtroStatusPagoComplemento = " Having statusNP in(0,1,4) or statusPCFDI in(0,1,4)";
	}elseif(trim($_REQUEST['status']) == "FALTANTEPAGO"){
		$filtroStatusPagoComplemento = " Having statusNP in(0,1) or statusPCFDI in(0,1)";
	}elseif(trim($_REQUEST['status']) == "YAPAGADO"){
		$filtroStatusPagoComplemento = " Having statusNP = 4 and statusPCFDI = 4 or marcar_como_pagada = 1";
	}*/
	
	// ------------- INICIA STATUS PAGO ------------------
		
		
		$filtroStatusPagoComplemento="";
		if($_GET["status"] != ""){
            $filtroStatusPagoComplemento=" Having ";
			$_POST['status_pago_buscar_nppcfdi'] = explode(",",$_GET["status"]);
            for($i=0; $i < count($_POST['status_pago_buscar_nppcfdi']); $i++){
                if(trim($_POST['status_pago_buscar_nppcfdi'][$i]) != ""){
                   if($_POST['status_pago_buscar_nppcfdi'][$i] == "0"){
					   //$filtroStatusPagoComplemento.= " (totalPagoDocumentosRef = 0 or totalPagoDocumentosRef is null)";
					   $filtroStatusPagoComplemento.= " statusNP = 0";
				   }
                   if($_POST['status_pago_buscar_nppcfdi'][$i] == "1"){
					   if($filtroStatusPagoComplemento != " Having "){
							// $filtroStatusPagoComplemento.= " or totalPagoDocumentosRef > 0";
							$filtroStatusPagoComplemento.= " or statusNP = 1";
					   }else{
						   // $filtroStatusPagoComplemento.= "totalPagoDocumentosRef > 0";
						   $filtroStatusPagoComplemento.= "statusNP = 1";
					   }
				   }
                   if($_POST['status_pago_buscar_nppcfdi'][$i] == "2"){
					   if($filtroStatusPagoComplemento != " Having "){
							// $filtroStatusPagoComplemento.= " or totalPago = total";
							$filtroStatusPagoComplemento.= " or statusNP = 4";
					   }else{
						   // $filtroStatusPagoComplemento.= "totalPago = total";
						   $filtroStatusPagoComplemento.= "statusNP = 4";
					   }
				   }
                   if($_POST['status_pago_buscar_nppcfdi'][$i] == "3"){
					   if($filtroStatusPagoComplemento != " Having "){
							// $filtroStatusPagoComplemento.= " or totalPago > total";
							$filtroStatusPagoComplemento.= " or statusNP = 2";
					   }else{
						   // $filtroStatusPagoComplemento.= "totalPago > total";
						   $filtroStatusPagoComplemento.= "statusNP = 2";
					   }
				   }
				   //---------------------------------
                   if($_POST['status_pago_buscar_nppcfdi'][$i] == "4"){
					   if($filtroStatusPagoComplemento != " Having "){
							// $filtroStatusPagoComplemento.= " or (ImpPagadoComplemento = 0 or ImpPagadoComplemento is null)";
							$filtroStatusPagoComplemento.= " or statusPCFDI = 0";
					   }else{
						   // $filtroStatusPagoComplemento.= "(ImpPagadoComplemento = 0 or ImpPagadoComplemento is null)";
						   $filtroStatusPagoComplemento.= "statusPCFDI = 0";
					   }
				   }
                   if($_POST['status_pago_buscar_nppcfdi'][$i] == "5"){
					   if($filtroStatusPagoComplemento != " Having "){
							// $filtroStatusPagoComplemento.= " or ImpPagadoComplemento > 0";
							$filtroStatusPagoComplemento.= " or statusPCFDI = 1";
					   }else{
						   // $filtroStatusPagoComplemento.= "ImpPagadoComplemento > 0";
						   $filtroStatusPagoComplemento.= "statusPCFDI = 1";
					   }
				   }
                   if($_POST['status_pago_buscar_nppcfdi'][$i] == "6"){
					   if($filtroStatusPagoComplemento != " Having "){
							// $filtroStatusPagoComplemento.= " or impPagadoComplemento = total";
							$filtroStatusPagoComplemento.= " or statusPCFDI = 4";
					   }else{
						   // $filtroStatusPagoComplemento.= "impPagadoComplemento = total";
						   $filtroStatusPagoComplemento.= "statusPCFDI = 4";
					   }
				   }
                   if($_POST['status_pago_buscar_nppcfdi'][$i] == "7"){
					   if($filtroStatusPagoComplemento != " Having "){
							// $filtroStatusPagoComplemento.= " or impPagadoComplemento > total";
							$filtroStatusPagoComplemento.= " or statusPCFDI = 2";
					   }else{
						   // $filtroStatusPagoComplemento.= "impPagadoComplemento > total";
						   $filtroStatusPagoComplemento.= "statusPCFDI = 2";
					   }
				   }
				   if($_POST['status_pago_buscar_nppcfdi'][$i] == "8"){
					   if($filtroStatusPagoComplemento != " Having "){
							$filtroStatusPagoComplemento.= " or statusNP = 7";
					   }else{
						   $filtroStatusPagoComplemento.= "statusNP = 7";
					   }
				   }
				   if($_POST['status_pago_buscar_nppcfdi'][$i] == "9"){
					   if($filtroStatusPagoComplemento != " Having "){
							$filtroStatusPagoComplemento.= " or statusNP = 5";
					   }else{
						   $filtroStatusPagoComplemento.= "statusNP = 5";
					   }
				   }
				   if($_POST['status_pago_buscar_nppcfdi'][$i] == "10"){
					   if($filtroStatusPagoComplemento != " Having "){
							$filtroStatusPagoComplemento.= " or statusNP = 6";
					   }else{
						   $filtroStatusPagoComplemento.= "statusNP = 6";
					   }
				   }
                }
            }
            
        }
		// --------------- TERMINA STATUS PAGO ---------------
				   
        
	$comRFCRECEPTOR="";
	if(trim($_SESSION["RES_RFC_REFERENCIA"]) == "SI"){
		if(trim(strtoupper($_SESSION['usuario_p_prov_absa'])) != "ADMIN"){
			//$comRFCRECEPTOR="rfc_receptor='".$_SESSION['sesion_ref_rfc_receptor']."' and";
			//$comRFCRECEPTOR="rfc_receptor in ('".str_replace(",","','",$_SESSION['sesion_ref_rfc_receptor'])."') and";
			$comRFCRECEPTOR="rfc_receptor='".$_SESSION['RFC_RECEPTOR_PORTAL']."'";
		}
	}
	
	$comSerie="";
	$comFecha="";
	$comFolio = "";
	$qUUID = "";
	
	if($fechaI != ""){
		$comFecha = "fechaDocto >= '$fechaI 00:00:00'";
	}
	if($fechaF != ""){
		if($comFecha != ""){$comFecha.=" and ";}
		$comFecha .= "fechaDocto <= '$fechaF 23:59:59'";
	}
	if(trim($_REQUEST["uuid"]) != ""){
		$qUUID = "";
		if(trim($_REQUEST["uuid"]) != ""){
			$qUUID="uuid like '%".trim($_REQUEST["uuid"])."%'";
		}
	}
	if(trim($_REQUEST["serie"]) != ""){
		$comSerie = "serie='".$_REQUEST["serie"]."'";
	}	
	if(trim($_REQUEST["folio"]) != ""){
		$comFolio = "folio='".$_REQUEST["serie"]."'";
	}
	
	
	/*$comBuscaNombre = "";
	if($busca_nombre != ""){
		$comBuscaNombre = " and (nombreemi like '%$busca_nombre%' or rfcemisor like '%$busca_nombre%')";
	}*/
	
	$comBuscaNombre = "";
	if($busca_nombre != ""){
		$comBuscaNombre = " and nombreemi like '%$busca_nombre%'";
	}
	$comBuscaRFC = "";
	if($busca_rfc != ""){
		$comBuscaRFC = " and rfcemisor like '%$busca_rfc%'";
	}
	
	
		
		$where = "where tipodocto='I CFDI 3.3'";
		
		$where .= $comBuscaNombre.$comBuscaRFC;
		if($rfcQuery != ""){if($where != ""){$rfcQuery = " and ".$rfcQuery;}}
		$where .=$rfcQuery;
		if($complementoQuery != ""){if($where != ""){$complementoQuery = " and ".$complementoQuery;}}
		$where .=$complementoQuery;
		if($comSerie != ""){if($where != ""){$comSerie = " and ".$comSerie;}}
		$where .=$comSerie;
		if($comFolio != ""){if($where != ""){$comFolio = " and ".$comFolio;}}
		$where .=$comFolio;
		if($comRFCRECEPTOR != ""){if($where != ""){$comRFCRECEPTOR = " and ".$comRFCRECEPTOR;}}
		$where .=$comRFCRECEPTOR;
		if($comFecha != ""){if($where != ""){$comFecha = " and ".$comFecha;}}
		$where .=$comFecha;
		if($permisosComplemento != ""){if($where == ""){$permisosComplemento = str_replace("or ","",str_replace("and ","",$permisosComplemento));}}
		$where .= $permisosComplemento;
		if($qUUID != ""){if($where != ""){$qUUID = " and ".$qUUID;}}
		$where .=$qUUID;
		
		
		
		$generaQuery="select *,
		if(length(MetodoDePago) > 3,99,getStatusNP(tipoComprobante,MetodoDePago,numReferenciasPagoDocumentosRef,vigenciaPUE,SoloFechaNP,totalPagoDocumentosRef,totalIngresoCompensado,fechaDocto,if(length('$notificar_fecha_inicio') > 0,'$notificar_fecha_inicio',null),total,if(length(FechaNP) > 0,FechaNP,null),".$tConfig["tolerancia_FacturaPagada"].",marcar_como_pagada)) as statusNP,
		if(length(MetodoDePago) > 3,99,getStatusPCFDI(tipoComprobante,MetodoDePago,impPagadoComplemento,fechaDocto,if(length('$notificar_fecha_inicio') > 0,'$notificar_fecha_inicio',null),total,".$tConfig["tolerancia_FacturaPagada"].",marcar_como_pagada)) as statusPCFDI
		from (select * from view_recibedocepagos
		$where) as tmp $filtroStatusPagoComplemento";
		
		

	return $generaQuery;
}
?>