<!DOCTYPE html>
<html lang="es-ES">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Pantalla Reporte Libro de Compras</title>
<?php
include "../../conn.php";
include "../../general.php";
include "../../token.php";

$rep=$_GET["rep"];
$tipo=$_GET["tipo"];
$mostrar=$_POST["mostrar"];
$valores=$_POST["valores"];
$proveedor=$_POST["proveedor"];
$cod_contexto=$_POST["contexto"];

//$mostrar_asiento_cc = $_GET["showCC"];

?>
<?php if($mi_cod_pais == 1) { //if bolivia ?>

	<?php if($mostrar == 0) { ?>

	<link href="../../libros.css" rel="stylesheet" type="text/css" />

	<style type="text/css" media="print">
	@page {size: letter landscape;}
	DIV {page-break-after: always;}
	</style>

	<?php } else { ?>
	<link href="../../maincss.css" rel="stylesheet" type="text/css" />
	<link href="../../printcss.css" rel="stylesheet" type="text/css" media="print" />
	<?php } ?> 
	</head>
	<?php

	if (empty($_POST["fechaini"]))
	{
		$fechaini=$_GET["fechaini"];
	} else {
		$fechaini=$_POST["fechaini"];
	}

	if (empty($_POST["fechafin"]))
	{
		$fechafin=$_GET["fechafin"];
	} else {
		$fechafin=$_POST["fechafin"];
	}
	/*
	if (empty($_POST["usuario"]))
	{
		$usuario=$_GET["usuario"];
	} else {
		$usuario=$_POST["usuario"];
	}
	*/

	$n_decimales = 2;

	?>
	<body>
	<?php


	//Inicio reporte Libro de Compras

	if($rep == 9 && $tipo == 1) { // if 2

		$filas_por_pagina = 30;

		//responsable
		$result2 = mysqli_query($link, "select a.codPerson as cod_persona, case when b.fldMiddleName is NULL then concat(b.fldLastName,', ',b.fldFirstName) else concat(b.fldLastName,' ',b.fldMiddleName,', ',b.fldFirstName) end as persona, b.fldAlternativeKey as ci 
		from 
		txsTaxesConfig a, agnPerson b
		where 
		a.codPerson = b.pkyPerson and 
		b.sysEnabled = 1 and b.sysAuthorized = 1;");
		while ($row = mysqli_fetch_array($result2)) {
			$nombre_responsable = $row['persona'];
			$ci_responsable = $row['ci'];
		}
		mysqli_free_result($result2);	

		if ($proveedor == 0) { //if proveedor
			$valor_proveedor = ' ';
			$nom_proveedor = 'Todos';
		} else { 
			$valor_proveedor = ' a.codSupplier = '.$proveedor.' and ';
			//nombre de proveedor
			$resultprov = mysqli_query($link, "select pkyCompany as codigo, fldName as proveedor
		from agnCompany
		where
		fldIsSupplier = 1 and
		pkyCompany = '$proveedor' and 
		sysEnabled = 1 and sysAuthorized = 1;");
			while ($row = mysqli_fetch_array($resultprov)) {
			$nom_proveedor = $row['codigo'].' - '.$row['proveedor'];
			}
			mysqli_free_result($resultprov);
		} //fin if proveedor

		//contexto
		if($cod_contexto == -1){ 
			$nom_contexto = 'Todos';
			$valor_contexto = ' ';
		} else {
			$resultcontx = mysqli_query($link, "select pkyContext as cod_contexto, fldName as contexto, codCostCenter as cod_cc 
			from srvContext
			where 
			pkyContext = '$cod_contexto';");
				while ($row = mysqli_fetch_array($resultcontx)) {   
					$nom_contexto = $row['cod_contexto'].' - '.$row['contexto'];
				}
				mysqli_free_result($resultcontx);
			$valor_contexto = ' a.sysContext = '.$cod_contexto.' and ';	
		}

		//listado de facturas compras
		/*
		$result = mysqli_query($link, "select a.pkyPurchasesLedger as codigo, a.fldNumber as nro_fac,
		a.fldAuthorization as nro_auto, a.fldDate as fecha, 
		a.fldControlCode as cod_control, a.codSupplier as cod_prov, 
		a.fldName as proveedor, a.fldNIT as nit, a.fldGrossTotal as total_bruto, 
		a.fldICE as ice, a.fldExempt as excento, a.fldNetTotal as total_neto,
		a.fldTaxCredit as credito, a.fldParentComponent as tabla_genera, a.cosComponentKey as cod_genera, a.txtDescription as glosa
		from
		txsPurchasesLedger a
		where 
		$valor_proveedor 
		a.fldDate >= '$fechaini' and
		a.fldDate <= '$fechafin' and
		a.sysEnabled = 1 AND a.sysAuthorized = 1
		order by fecha, proveedor, nro_auto;"); fldDiscount
		*/

		$result = mysqli_query($link, "select t.codigo as codigo, t.nro_fac as nro_fac,
		t.nro_auto as nro_auto, t.fecha as fecha, 
		t.cod_control as cod_control, t.cod_prov as cod_prov, 
		t.proveedor as proveedor, t.nit as nit, t.total_bruto as total_bruto, 
		t.ice as ice, t.excento as excento, t.total_neto as total_neto,
		t.credito as credito, t.descuento as descuento, t.cod_tipo_compra as cod_tipo_compra, 
		t.papa as papa, t.cod_papa as cod_papa, t.glosa as glosa, t.usuario_reg as usuario_reg
		from
		(select a.pkyPurchasesLedger as codigo, a.fldNumber as nro_fac,
		a.fldAuthorization as nro_auto, a.fldDate as fecha, 
		a.fldControlCode as cod_control, a.codSupplier as cod_prov, 
		a.fldName as proveedor, a.fldNIT as nit, a.fldGrossTotal as total_bruto, 
		a.fldICE as ice, a.fldExempt as excento, a.fldNetTotal as total_neto,
		a.fldTaxCredit as credito, a.fldDiscount as descuento, a.codType as cod_tipo_compra, 
		a.fldParentComponent as papa, a.cosComponentKey as cod_papa, a.txtDescription as glosa, h.fldName as usuario_reg
		from
		txsPurchasesLedger a, accGroup h
		where 
		$valor_proveedor 
		$valor_contexto 
		a.sysAuthorizationGroup = h.pkyGroup and 
		a.fldDate >= '$fechaini' and
		a.fldDate <= '$fechafin' and 
		a.sysEnabled = 1 AND a.sysAuthorized = 1

		UNION ALL

		select a.pkyImportDocument as codigo, a.fldNumber as nro_fac, 
		3 as nro_auto, a.fldPaymentDate as fecha, 
		0 as cod_control, a.codSupplier as cod_prov, 
		a.fldName as proveedor, a.fldNIT as nit, a.fldTotal as total_bruto, 
		0 as ice, 0 as excento, a.fldTotal as total_neto, 
		a.fldTotalVAT as credito, 0 as descuento, a.codType as cod_tipo_compra, 
		a.fldParentComponent as papa, a.cosComponentKey as cod_papa, a.txtDescription as glosa, h.fldName as usuario_reg
		from 
		pchImportDocument a, accGroup h 
		where 
		$valor_proveedor 
		$valor_contexto 
		a.sysAuthorizationGroup = h.pkyGroup and 
		a.fldPaymentDate >= '$fechaini' and
		a.fldPaymentDate <= '$fechafin' and
		a.sysEnabled = 1 AND a.sysAuthorized = 1

		UNION ALL 

		select a.pkyTicket as codigo, a.fldNumber as nro_fac, 
		1 as nro_auto, a.fldDate as fecha, 
		0 as cod_control, a.codSupplier as cod_prov, 
		a.fldName as proveedor, a.fldNIT as nit, a.fldGrossTotal as total_bruto, 
		0 as ice, a.fldExempt as excento, a.fldNetTotal as total_neto, 
		a.fldTaxCredit as credito, 0 as descuento, a.codType as cod_tipo_compra, 
		a.fldParentComponent as papa, a.cosComponentKey as cod_papa, a.txtDescription as glosa, h.fldName as usuario_reg  
		from 
		txsTicket a, accGroup h  
		where 
		$valor_proveedor
		$valor_contexto 
		a.sysAuthorizationGroup = h.pkyGroup and 
		a.fldDate >= '$fechaini' and
		a.fldDate <= '$fechafin' and
		a.sysEnabled = 1 AND a.sysAuthorized = 1) t 
		order by t.fecha, t.proveedor, t.nro_auto;");

		$numero_filas = mysqli_num_rows($result);
		$var = ceil($numero_filas/$filas_por_pagina); //redondea hacia arriba

		$matriz_compras = array();
		$i = 1;
		while ($row = mysqli_fetch_array($result)) {
			$matriz_compras [$i][1] = $row['codigo'];
			$matriz_compras [$i][2] = $row['nro_fac'];
			$matriz_compras [$i][3] = $row['nro_auto'];
			$matriz_compras [$i][4] = $row['fecha'];
			$matriz_compras [$i][5] = $row['cod_control'];
			if($row['cod_control'] == NULL){
				$matriz_compras [$i][5] = 0;
			} else {
				$matriz_compras [$i][5] = $row['cod_control'];
			}
			$matriz_compras [$i][6] = $row['cod_pro'];
			$matriz_compras [$i][7] = $row['proveedor'];
			$matriz_compras [$i][8] = $row['nit'];
			$matriz_compras [$i][9] = round($row['total_bruto'],$n_decimales);
			$matriz_compras [$i][10] = round($row['ice'],$n_decimales);
			$matriz_compras [$i][11] = round($row['excento'],$n_decimales);
			$matriz_compras [$i][12] = round($row['total_neto'],$n_decimales);
			$matriz_compras [$i][13] = round($row['credito'],$n_decimales);
			$matriz_compras [$i][14] = $row['glosa'];
			$matriz_compras [$i][15] = $row['papa'];
			$matriz_compras [$i][16] = $row['cod_papa'];
			$matriz_compras [$i][17] = round($row['descuento'],$n_decimales);
			if($row['descuento'] <= 0) { 
				$matriz_compras [$i][17] = 0;
			}
			$matriz_compras [$i][18] = $row['cod_tipo_compra'];
			//revisar esto en el nuevo formato, tal vez no es necesario
			//$valor_poliza = 0;
			if($matriz_compras [$i][3] == 3 && $valores == 1) { //if poliza
				$iva013 = $monto_iva / 100;
				//$valor_poliza = $matriz_compras [$j][2];
				//$matriz_compras [$i][2] = 0;
				$matriz_compras [$i][9] = $matriz_compras [$i][13] / $iva013;
				$matriz_compras [$i][12] = $matriz_compras [$i][9];
			} // fin if poliza
			
			//para enlazar al que genero el asiento
			$papa_componente = $matriz_compras [$i][15];
			$papa_codigo = $matriz_compras [$i][16];
			//$usuario = $usuario_det;
			include "../../generadopor.php";
			$matriz_compras [$i][19] = $papa_enlace;
			
			$matriz_compras [$i][20] = $row['usuario_reg'];
			//echo $matriz_compras [$i][1].'<br>';
			$i++;
		}
		$fin = $i - 1;
		mysqli_free_result($result);


		$sucursal = '0';
		$dir_sucursal = $mi_direccion;

		$total_comp_par = 0;
		$total_no_cred_par = 0;
		$total_sub_par = 0;
		$total_desc_par = 0;
		$total_para_cred_par = 0;
		$total_cred_par = 0;

		$total_comp = 0;
		$total_no_cred = 0;
		$total_sub = 0;
		$total_desc = 0;
		$total_para_cred = 0;
		$total_cred = 0;

		if($numero_filas == 0) {//if $numero_filas
		$i = 1;
		$var = 1;
		$filas_por_pagina = 28;
		}//fin if $numero_filas

		//este if es para mostrar con el formato de libro de compras
		if($mostrar == 0) { //mostrar 0

			$j = 1;
			$nu = 1;
			for($i = 1; $i <= $var; $i++) {//for
				?>
				<?php if($mostrar_logo_reportes_formato == 0) { //if formato 0 ?>
				<table border="0" align="center" cellpadding="2" width="990">
				<tr>
					<td width="315"><?php echo $usuario; ?></td>
					<td width="320" align="center"><b>LIBRO DE COMPRAS IVA</b></td>
					<td width="315" align="right"><b>Folio: <?php echo $i; ?> de <?php echo $var; ?></b></td>
				</tr>
				<tr>
					<td width="315">&nbsp;</td>
					<td width="320" align="center">DEL <?php echo date("d/m/Y",strtotime($fechaini)); ?> AL <?php echo date("d/m/Y",strtotime($fechafin)); ?></td>
					<td width="315" align="right">CIFRAS EN BOLIVIANOS</td>
				</tr>
				</table>
				<table border="1" align="center" cellpadding="2" width="990">
				<tr>
					<td width="485"><b>Nombre o Raz&oacute;n Social: </b><?php echo $nombre_empresa; ?></td>
					<td width="485"><b>NIT: </b><?php echo $mi_nit; ?></td>
				</tr>
				<tr>
					<td width="485"><b>No. Sucursal: </b><?php echo $sucursal; ?></td>
					<td width="485"><b>Direcci&oacute;n: </b><?php echo $dir_sucursal; ?></td>
				</tr>
				</table>
				<?php } //fin if formato 0 ?>

				<?php if($mostrar_logo_reportes_formato == 1) { //if formato 1 ?>
				<table border="0" align="center" cellpadding="2" width="990">
				<tr>
					<td rowspan="2" width="15%"><img src="../../Images/logo.jpg" alt="Logo" width="100" height="40" /></td>
					<td width="315">&nbsp;</td>
					<td width="320" align="center"><b>LIBRO DE COMPRAS IVA</b></td>
					<td width="315" align="right"><b>Folio: <?php echo $i; ?> de <?php echo $var; ?></b></td>
				</tr>
				<tr>
					<td width="315">&nbsp;</td>
					<td width="320" align="center">DEL <?php echo date("d/m/Y",strtotime($fechaini)); ?> AL <?php echo date("d/m/Y",strtotime($fechafin)); ?></td>
					<td width="315" align="right">CIFRAS EN BOLIVIANOS</td>
				</tr>
				</table>
				<table border="1" align="center" cellpadding="2" width="990">
				<tr>
					<td width="485"><b>Nombre o Raz&oacute;n Social: </b><?php echo $nombre_empresa; ?></td>
					<td width="485"><b>NIT: </b><?php echo $mi_nit; ?></td>
				</tr>
				<tr>
					<td width="485"><b>No. Sucursal: </b><?php echo $sucursal; ?></td>
					<td width="485"><b>Direcci&oacute;n: </b><?php echo $dir_sucursal; ?></td>
				</tr>
				</table>
				<?php } //fin if formato 1 ?>
				<br />

				<table border="1" align="center" cellpadding="2" width="990" height="600">
					<TR> 
					<TD align="center" width="10" style='border-bottom: solid 1px'><b>No.</b></TD>
					<TD align="center" width="55" style='border-bottom: solid 1px'><b>Fecha de la factura o DUI</b></TD>
					<TD align="center" width="55" style='border-bottom: solid 1px'><b>NIT Proveedor</b></TD>
					<TD align="center" width="310" style='border-bottom: solid 1px'><b>Nombre o Raz&oacute;n Social</b></TD>
					<TD align="center" width="40" style='border-bottom: solid 1px'><b>Nro. de la Factura</b></TD>
					<TD align="center" width="65" style='border-bottom: solid 1px'><b>Nro. de DUI</b></TD>
					<TD align="center" width="65" style='border-bottom: solid 1px'><b>Nro. Autorizaci&oacute;n</b></TD>
					<TD align="center" width="55" style='border-bottom: solid 1px'><b>Importe total de la compra<br />A</b></TD>
					<TD align="center" width="55" style='border-bottom: solid 1px'><b>Importe no sujeto a cr&eacute;dito fiscal<br />B</b></TD>
					<TD align="center" width="55" style='border-bottom: solid 1px'><b>Subtotal<br />C = A - B</b></TD>
					<TD align="center" width="55" style='border-bottom: solid 1px'><b>Descuentos bonificaciones y rebajas obtenidas<br />D</b></TD>
					<TD align="center" width="55" style='border-bottom: solid 1px'><b>Importe base para cr&eacute;dito fiscal<br />E = C - D</b></TD>
					<TD align="center" width="55" style='border-bottom: solid 1px'><b>Cr&eacute;dito fiscal<br />F = E * 13%</b></TD>
					<TD align="center" width="70" style='border-bottom: solid 1px'><b>Cod. Control</b></TD>
					<TD align="center" width="10" style='border-bottom: solid 1px'><b>Tipo de compra</b></TD>
					</TR>

				<?php
				$color = 2;
				$q = 1;//
				while ($q <= $filas_por_pagina) { //while
				
				if($numero_filas == 0) {//if filas
					printf("<tr><td align='center'>%s</td>", $matriz_compras [$j][4]);//fecha
				} else { //else filas
					if($color % 2 == 0) { //if color
						if($matriz_compras [$j][4] != NULL) {
						printf("<tr BGCOLOR='#e2e7fa'><td align='center'>%s</td>", $nu);//numero
						} else { 
						printf("<tr BGCOLOR='#e2e7fa'><td align='center'>&nbsp;</td>");//numero vacio
						}
					} else {
						if($matriz_compras [$j][4] != NULL) {
						printf("<tr><td align='center'>%s</td>", $nu);//numero
						} else { 
						printf("<tr><td align='center'>&nbsp;</td>");//numero vacio
						}
					}//fin if color
				}//fin filas
					printf("<td align='center'>%s</td>", $matriz_compras [$j][4]);//fecha
					printf("<td align='right'>%s</td>", $matriz_compras [$j][8]);//nit
					$texto = $matriz_compras [$j][7];//proveedor
					$texto = strtr(strtoupper($texto), "àáâãäåæçèéêëìíîïðñòóôõöøùüú", "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÜÚ");
					$texto = substr($texto,0,150);
					printf("<td align='left'>%s</td>", $texto);//proveedor
					if($matriz_compras [$j][4] != NULL) {//if no null
						if($matriz_compras [$j][3] == 3) {
							printf("<td align='right'>%s</td>", 0);//nro. factura
							printf("<td align='right'>%s</td>", $matriz_compras [$j][2]);//DUI
						} else {
							printf("<td align='right'>%s</td>", $matriz_compras [$j][2]);//nro. factura
							printf("<td align='right'>%s</td>", 0);//DUI	
						}
						
					} else {//else if no null
						
						printf("<td align='right'>%s</td>", NULL);//nro. factura
						printf("<td align='right'>%s</td>", NULL);//DUI
					
					}//fin if no null
					
					printf("<td align='right'>%s</td>", $matriz_compras [$j][3]);//nro. auto
						
					if($matriz_compras [$j][9] == 0) {//if si es 0
					printf("<td align='right'>%s</td>", NULL);//imp. total compra A
					printf("<td align='right'>%s</td>", NULL);//imp. no cred. fis. B
					printf("<td align='right'>%s</td>", NULL);//subtotal C=A-B
					printf("<td align='right'>%s</td>", NULL);//descuentos D
					printf("<td align='right'>%s</td>", NULL);//imp. cred. fis. E=C-D
					printf("<td align='right'>%s</td>", NULL);//cred. fis. F=E*13%
					printf("<td align='right'>%s</td>", NULL);//cod control
					printf("<td align='right'>%s</td></tr>", NULL);//tipo compra
					} else { //else si es 0
					$imp_total_compra = $matriz_compras [$j][9] + $matriz_compras [$j][17];
					printf("<td align='right'>%s</td>", number_format($imp_total_compra,$n_decimales));//imp. total compra A
					$imp_no_cred_fis = $matriz_compras [$j][10] + $matriz_compras [$j][11];
					printf("<td align='right'>%s</td>", number_format($imp_no_cred_fis,$n_decimales));//imp. no cred. fis. B
					$subtotal = $imp_total_compra - $imp_no_cred_fis;
					printf("<td align='right'>%s</td>", number_format($subtotal,$n_decimales));//subtotal C=A-B
					printf("<td align='right'>%s</td>", number_format($matriz_compras [$j][17],$n_decimales));//descuentos D
					$imp_cred_fis = $subtotal - $matriz_compras [$j][17];
					printf("<td align='right'>%s</td>", number_format($imp_cred_fis,$n_decimales));//imp. cred. fis. E=C-D
					//$cred_fis = $imp_cred_fis * $monto_iva / 100;
					printf("<td align='right'>%s</td>", number_format($matriz_compras [$j][13],$n_decimales));//cred. fis. F=E*13%
					printf("<td align='right'>%s</td>", $matriz_compras [$j][5]);//cod control
					printf("<td align='right'>%s</td></tr>", $matriz_compras [$j][18]);//tipo compra
					
					$total_comp_par = $total_comp_par + $imp_total_compra;
					$total_no_cred_par = $total_no_cred_par + $imp_no_cred_fis;
					$total_sub_par = $total_sub_par + $subtotal;
					$total_desc_par = $total_desc_par + $matriz_compras [$j][17];
					$total_para_cred_par = $total_para_cred_par + $imp_cred_fis;
					$total_cred_par = $total_cred_par + $matriz_compras [$j][13];
					
					$total_comp = $total_comp + $imp_total_compra;
					$total_no_cred = $total_no_cred + $imp_no_cred_fis;
					$total_sub = $total_sub + $subtotal;
					$total_desc = $total_desc + $matriz_compras [$j][17];
					$total_para_cred = $total_para_cred + $imp_cred_fis;
					$total_cred = $total_cred + $matriz_compras [$j][13];
					}//fin if si es 0
					
					
					if($numero_filas == 0 && $j == 14) {
						printf("<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td align='right' colspan='6'><font size='16'><b>SIN MOVIMIENTO</b></font></td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>");
					}
					
					$color++;
					$j++;
					$q++;
					$nu++;
				}//fin while


				?>

				<tr>
				<td colspan="5" align="left" style='border-top: solid 1px'><b>Nombre del Responsable: </b><?php echo strtr(strtoupper($nombre_responsable), "àáâãäåæçèéêëìíîïðñòóôõöøùüú", "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÜÚ"); ?></td>
				<td colspan="2" align="left" style='border-top: solid 1px'><b>TOTALES PARCIALES:</b></td>
				<td align="right" style='border-top: solid 1px'><b><?php echo number_format($total_comp_par,$n_decimales); ?></b></td>
				<td align="right" style='border-top: solid 1px'><b><?php echo number_format($total_no_cred_par,$n_decimales); ?></b></td>
				<td align="right" style='border-top: solid 1px'><b><?php echo number_format($total_sub_par,$n_decimales); ?></b></td>
				<td align="right" style='border-top: solid 1px'><b><?php echo number_format($total_desc_par,$n_decimales); ?></b></td>
				<td align="right" style='border-top: solid 1px'><b><?php echo number_format($total_para_cred_par,$n_decimales); ?></b></td>
				<td align="right" style='border-top: solid 1px'><b><?php echo number_format($total_cred_par,$n_decimales); ?></b></td>
				<td style='border-top: solid 1px'>&nbsp;</td>
				<td style='border-top: solid 1px'>&nbsp;</td>
				</tr>
				<tr>
					<td colspan="5" align="left"><b>C.I.: </b><?php echo $ci_responsable; ?></td>
					<td colspan="2" align="left"><b>TOTALES GENERALES:</b></td>
					<td align="right"><b><?php echo number_format($total_comp,$n_decimales); ?></b></td>
					<td align="right"><b><?php echo number_format($total_no_cred,$n_decimales); ?></b></td>
					<td align="right"><b><?php echo number_format($total_sub,$n_decimales); ?></b></td>
					<td align="right"><b><?php echo number_format($total_desc,$n_decimales); ?></b></td>
					<td align="right"><b><?php echo number_format($total_para_cred,$n_decimales); ?></b></td>
					<td align="right"><b><?php echo number_format($total_cred,$n_decimales); ?></b></td>
					<td>&nbsp;</td>
					<td>&nbsp;</td>
				</tr>
				</table>

				<?php
				$total_comp_par = 0;
				$total_no_cred_par = 0;
				$total_sub_par = 0;
				$total_desc_par = 0;
				$total_para_cred_par = 0;
				$total_cred_par = 0;
				if($i != $var) {//if $i
					?>
				<div>
				<!--

				<table border="0" align="center" height="100"><tr><td>&nbsp;</td></tr></table>
				-->
				</div>
				<?php
				}//fin if $i
			}//fin for

		}// fin if mostrar 0


		//este if es para mostrar con el formato detalle de facturas
		if($mostrar == 1) { //mostrar 1

			?>
			<table border="0" align="left" width="100%" cellpadding="5">
			<tr><td><?php echo $mostrar_logo_reportes; ?>
			</td><td align="right"><b>Fecha: <?php echo date("Y-m-d"); ?><br/>Hora: <?php echo date("H:i:s"); ?><br/>Usuario: <?php echo $usuario; ?></b>
			</td></tr></table>
			<p><br /><center><font color="#000099" size="+1"><b>Detalle Facturas Compras</b></font></center></p>
			<table border="0" cellpadding="2" align="center" width="100%">
			<tr>
			<td>	
				<table border="1" align="center" cellpadding="2" width="100%">
					<TR> 
					<TD width="33%"><b>Proveedor: </b><?php echo $nom_proveedor; ?></TD>
					<TD width="33%"><b>Sucursal: </b><?php echo $sucursal; ?></TD>
					<TD width="33%"><b>De Fecha: </b><?php echo $fechaini; ?> <b>a Fecha: </b><?php echo $fechafin; ?></TD>
					</TR>
					<TR>
					<TD colspan="2"><b>Contexto: </b><?php echo $nom_contexto; ?></TD>
					<TD><b>Expresado en: </b><?php echo $nom_moneda_principal; ?></TD>
					</TR>
				</table>

			</td>
			<!--
			<td valign="top" width="150">

				<table border="1" align="center" cellpadding="2" width="100%">
				<tr>
				<TD><b>Tipo de Cambio:</b></TD>
				</tr><tr>
				<TD align="center"><a href="../../ModuleAccounting/VoucherExchangeRate/index.php?pkyExchangeRate=<?php echo $ultimo_tc; ?>&user=<?php echo $usuario; ?>&token=<?php echo $token; ?>" title="Tipo de Cambio"><?php echo $ultimo_tc; ?></a> (<?php echo $tc_fecha; ?> - <?php echo $tc_hora; ?>)<br/ >
					<table border="0" cellpadding="2" align="center">
						<?php
						for($m = 1; $m <= $fin_m; $m++) {
						printf("<tr><td align='left'>1 %s</td>", $ma_tc [$m][1]);//moneda base
						printf("<td align='center'>%s</td>", ' = ');//letra a
						printf("<td align='left'>%s %s</td>", number_format($ma_tc [$m][3],$n_tipocambio), $ma_tc [$m][2]);//moneda target y tasa
						//printf("<td align='right'>%s</td></tr>", number_format($ma_tc [$m][3],$n_tipocambio));//tasa
						}
						?>
					</table>
				</TD>
				</tr>
				</table>
				
			</td>
			-->
			</tr>
			</table>
			<br />

			<table border="1" align="center" cellpadding="2" width="100%">
				<thead>
				<TR> 
				<TD align="center"><b>No.</b></TD>
				<TD align="center"><b>NIT Proveedor</b></TD>
				<TD align="center"><b>Nombre o Raz&oacute;n Social</b></TD>
				<TD align="center"><b>Nro. Factura</b></TD>
				<TD align="center"><b>Nro. DUI</b></TD>
				<TD align="center"><b>Nro. Autorizaci&oacute;n / CUF</b></TD>
				<TD align="center" width="65"><b>Fecha de la factura o DUI</b></TD>
				<TD align="center"><b>Importe total de la compra<br />A</b></TD>
				<TD align="center"><b>Total ICE<br />B1</b></TD>
				<TD align="center"><b>Importe exento<br />B2</b></TD>
				<TD align="center"><b>Importe no sujeto a cr&eacute;dito fiscal<br />B = B1 + B2</b></TD>
				<TD align="center"><b>Subtotal<br />C = A - B</b></TD>
				<TD align="center"><b>Descuentos bonificaciones y rebajas obtenidas<br />D</b></TD>
				<TD align="center"><b>Importe base para cr&eacute;dito fiscal<br />E = C - D</b></TD>
				<TD align="center"><b>Cr&eacute;dito fiscal<br />F = E * 13%</b></TD>
				<TD align="center" width="90"><b>Cod. Control</b></TD>
				<TD align="center"><b>Tipo de compra</b></TD>
				<TD align="center"><b>Glosa</b></TD>
				<TD align="center"><b>Gen. Por</b></TD>
				<TD align="center"><b>Usuario</b></TD>
				</TR>
				</thead>
				<tbody class="marcafila">

			<?php
			$color = 2;
			$j = 1;
			$nu = 1;
			$total_comp = 0;
			$total_ice = 0;
			$total_exe = 0;
			$total_no_cred = 0;
			$total_sub = 0;
			$total_desc = 0;
			$total_para_cred = 0;
			$total_cred = 0;

				while ($j <= $fin) { //while
				
				if($color % 2 == 0) { //if color
					printf("<tr BGCOLOR='#e2e7fa'><td align='center'>%s</td>", $nu);//numero
				} else {
					printf("<tr><td align='center'>%s</td>", $nu);//numero
				}//fin if color
				
				printf("<td align='right'>%s</td>", $matriz_compras [$j][8]);//nit
				$texto = $matriz_compras [$j][7];//proveedor
				$texto = strtr(strtoupper($texto), "àáâãäåæçèéêëìíîïðñòóôõöøùüú", "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÜÚ");
				//$texto = substr($texto,0,150);
				printf("<td align='left'>%s</td>", $texto);//proveedor
				if($matriz_compras [$j][3] == 3) {
					printf("<td align='right'>%s</td>", 0);//nro. factura
					printf("<td align='right'>%s</td>", $matriz_compras [$j][2]);//DUI
				} else {
					printf("<td align='right'>%s</td>", $matriz_compras [$j][2]);//nro. factura
					printf("<td align='right'>%s</td>", 0);//DUI	
				}
					
				printf("<td align='right'>%s</td>", $matriz_compras [$j][3]);//nro. auto
				printf("<td align='center'>%s</td>", $matriz_compras [$j][4]);//fecha
				
				$imp_total_compra = $matriz_compras [$j][9] + $matriz_compras [$j][17];
				printf("<td align='right'>%s</td>", number_format($imp_total_compra,$n_decimales));//imp. total compra A
				printf("<td align='right'>%s</td>", number_format($matriz_compras [$j][10],$n_decimales));//imp. ICE
				printf("<td align='right'>%s</td>", number_format($matriz_compras [$j][11],$n_decimales));//imp. exento
				$imp_no_cred_fis = $matriz_compras [$j][10] + $matriz_compras [$j][11];
				printf("<td align='right'>%s</td>", number_format($imp_no_cred_fis,$n_decimales));//imp. no cred. fis. B
				$subtotal = $imp_total_compra - $imp_no_cred_fis;
				printf("<td align='right'>%s</td>", number_format($subtotal,$n_decimales));//subtotal C=A-B
				printf("<td align='right'>%s</td>", number_format($matriz_compras [$j][17],$n_decimales));//descuentos D
				$imp_cred_fis = $subtotal - $matriz_compras [$j][17];
				printf("<td align='right'>%s</td>", number_format($imp_cred_fis,$n_decimales));//imp. cred. fis. E=C-D
				//$cred_fis = $imp_cred_fis * $monto_iva / 100;
				printf("<td align='right'>%s</td>", number_format($matriz_compras [$j][13],$n_decimales));//cred. fis. F=E*13%
				printf("<td align='right'>%s</td>", $matriz_compras [$j][5]);//cod control
				printf("<td align='right'>%s</td>", $matriz_compras [$j][18]);//tipo compra
				
				$glosa2 = $matriz_compras [$j][14];
				$glosa2 = nl2br($glosa2);//quita salto de linea 
				$glosa2 = str_replace('\n','<br />',$glosa2);//reemplaza para salto de linea
				printf("<td>%s</td>", $glosa2);//glosa
				printf("<td align='center'>%s</td>", $matriz_compras [$j][19]);//gen por
				printf("<td align='center'>%s</td></tr>", $matriz_compras [$j][20]);//usuario
				
				$total_comp = $total_comp + $imp_total_compra;
				$total_ice = $total_ice + $matriz_compras [$j][10];
				$total_exe = $total_exe + $matriz_compras [$j][11];
				$total_no_cred = $total_no_cred + $imp_no_cred_fis;
				$total_sub = $total_sub + $subtotal;
				$total_desc = $total_desc + $matriz_compras [$j][17];
				$total_para_cred = $total_para_cred + $imp_cred_fis;
				$total_cred = $total_cred + $matriz_compras [$j][13];

				$nu++;
				$color++;
				$j++;
			
				} //fin while
			?>
			
			<tr BGCOLOR='#ffcccc'><td colspan="7"><b>Total</b></td>
			<td align="right"><?php printf("<b>%s</b>", number_format($total_comp,$n_decimales)); ?></td>
			<td align="right"><?php printf("<b>%s</b>", number_format($total_ice,$n_decimales)); ?></td>
			<td align="right"><?php printf("<b>%s</b>", number_format($total_exe,$n_decimales)); ?></td>
			<td align="right"><?php printf("<b>%s</b>", number_format($total_no_cred,$n_decimales)); ?></td>
			<td align="right"><?php printf("<b>%s</b>", number_format($total_sub,$n_decimales)); ?></td>
			<td align="right"><?php printf("<b>%s</b>", number_format($total_desc,$n_decimales)); ?></td>
			<td align="right"><?php printf("<b>%s</b>", number_format($total_para_cred,$n_decimales)); ?></td>
			<td align="right"><?php printf("<b>%s</b>", number_format($total_cred,$n_decimales)); ?></td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			</tr>
			</tbody>
			</table>

			<?php	
		}// fin if mostrar 1

		//este if es para mostrar con el formato SIAT
		if($mostrar == 2) { //mostrar 2

			?>
			<table border="0" align="left" width="100%" cellpadding="5">
			<tr><td><?php echo $mostrar_logo_reportes; ?>
			</td><td align="right"><b>Fecha: <?php echo date("Y-m-d"); ?><br/>Hora: <?php echo date("H:i:s"); ?><br/>Usuario: <?php echo $usuario; ?></b>
			</td></tr></table>
			<p><br /><center><font color="#000099" size="+1"><b>Detalle Facturas Compras (Formato SIAT)</b></font></center></p>
			<table border="0" cellpadding="2" align="center" width="100%">
			<tr>
			<td>	
				<table border="1" align="center" cellpadding="2" width="100%">
					<TR> 
					<TD width="33%"><b>Proveedor: </b><?php echo $nom_proveedor; ?></TD>
					<TD width="33%"><b>Sucursal: </b><?php echo $sucursal; ?></TD>
					<TD width="33%"><b>De Fecha: </b><?php echo $fechaini; ?> <b>a Fecha: </b><?php echo $fechafin; ?></TD>
					</TR>
					<TR>
					<TD colspan="2"><b>Contexto: </b><?php echo $nom_contexto; ?></TD>
					<TD><b>Expresado en: </b><?php echo $nom_moneda_principal; ?></TD>
					</TR>
				</table>

			</td>
			<!--
			<td valign="top" width="150">

				<table border="1" align="center" cellpadding="2" width="100%">
				<tr>
				<TD><b>Tipo de Cambio:</b></TD>
				</tr><tr>
				<TD align="center"><a href="../../ModuleAccounting/VoucherExchangeRate/index.php?pkyExchangeRate=<?php echo $ultimo_tc; ?>&user=<?php echo $usuario; ?>&token=<?php echo $token; ?>" title="Tipo de Cambio"><?php echo $ultimo_tc; ?></a> (<?php echo $tc_fecha; ?> - <?php echo $tc_hora; ?>)<br/ >
					<table border="0" cellpadding="2" align="center">
						<?php
						for($m = 1; $m <= $fin_m; $m++) {
						printf("<tr><td align='left'>1 %s</td>", $ma_tc [$m][1]);//moneda base
						printf("<td align='center'>%s</td>", ' = ');//letra a
						printf("<td align='left'>%s %s</td>", number_format($ma_tc [$m][3],$n_tipocambio), $ma_tc [$m][2]);//moneda target y tasa
						//printf("<td align='right'>%s</td></tr>", number_format($ma_tc [$m][3],$n_tipocambio));//tasa
						}
						?>
					</table>
				</TD>
				</tr>
				</table>
				
			</td>
			-->
			</tr>
			</table>
			<br />

			<table border="1" align="center" cellpadding="2" width="100%">
				<thead>
				<TR> 
				<TD align="center"><b>No.</b></TD>
				<TD align="center"><b>Especificación</b></TD>
				<TD align="center"><b>NIT Proveedor</b></TD>
				<TD align="center"><b>Raz&oacute;n Social Proveedor</b></TD>
				<TD align="center"><b>Código de Autorizaci&oacute;n / CUF</b></TD>
				<TD align="center"><b>Nro. Factura</b></TD>
				<TD align="center"><b>Nro. DUI/DIM</b></TD>
				<TD align="center" width="65"><b>Fecha de la Factura/DUI/DIM</b></TD>
				<TD align="center"><b>Importe Total de la Compra</b></TD>
				<TD align="center"><b>Importe ICE</b></TD>
				<TD align="center"><b>Importe IEHD</b></TD>
				<TD align="center"><b>Importe IPJ</b></TD>
				<TD align="center"><b>Tasas</b></TD>
				<TD align="center"><b>Otro no Sujeto a Crédito Fiscal</b></TD>
				<TD align="center"><b>Importes Exentos</b></TD>
				<TD align="center"><b>Importe Compras Gravadas a Tasa Cero</b></TD>
				<TD align="center"><b>Subtotal</b></TD>
				<TD align="center"><b>Descuentos/Bonificaciones/Rebajas Obtenidas</b></TD>
				<TD align="center"><b>Importe Gift Card</b></TD>
				<TD align="center"><b>Importe Base CF</b></TD>
				<TD align="center"><b>Cr&eacute;dito Fiscal</b></TD>
				<TD align="center"><b>Tipo de compra</b></TD>
				<TD align="center" width="90"><b>Cod. Control</b></TD>
				</TR>
				</thead>
				<tbody class="marcafila">

			<?php
			$color = 2;
			$j = 1;
			$nu = 1;
			$total_comp = 0;
			$total_ice = 0;
			$total_exe = 0;
			$total_no_cred = 0;
			$total_sub = 0;
			$total_desc = 0;
			$total_para_cred = 0;
			$total_cred = 0;

				while ($j <= $fin) { //while
				
				if($color % 2 == 0) { //if color
					printf("<tr BGCOLOR='#e2e7fa'><td align='center'>%s</td>", $nu);//numero
				} else {
					printf("<tr><td align='center'>%s</td>", $nu);//numero
				}//fin if color
				
				printf("<td align='right'>%s</td>", 1);//especificacion
				printf("<td align='right'>%s</td>", $matriz_compras [$j][8]);//nit
				$texto = $matriz_compras [$j][7];//proveedor
				$texto = strtr(strtoupper($texto), "àáâãäåæçèéêëìíîïðñòóôõöøùüú", "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÜÚ");
				//$texto = substr($texto,0,150);
				printf("<td align='left'>%s</td>", $texto);//proveedor
				printf("<td align='right'>%s</td>", $matriz_compras [$j][3]);//cod. auto/cuf

				if($matriz_compras [$j][3] == 3) {
					printf("<td align='right'>%s</td>", 0);//nro. factura
					printf("<td align='right'>%s</td>", $matriz_compras [$j][2]);//DUI
				} else {
					printf("<td align='right'>%s</td>", $matriz_compras [$j][2]);//nro. factura
					printf("<td align='right'>%s</td>", 0);//DUI	
				}
					
				printf("<td align='center'>%s</td>", cambiarFormatoFechaBarra($matriz_compras [$j][4]));//fecha
				
				$imp_total_compra = $matriz_compras [$j][9] + $matriz_compras [$j][17];
				printf("<td align='right'>%s</td>", number_format($imp_total_compra,$n_decimales));//imp. total compra A
				printf("<td align='right'>%s</td>", number_format($matriz_compras [$j][10],$n_decimales));//imp. ICE
				printf("<td align='right'>%s</td>", number_format(0,$n_decimales));//imp. IEHD
				printf("<td align='right'>%s</td>", number_format(0,$n_decimales));//imp. IPJ
				printf("<td align='right'>%s</td>", number_format(0,$n_decimales));//tasas porcentaje
				printf("<td align='right'>%s</td>", number_format($matriz_compras [$j][11],$n_decimales));//otro no sujeto a cred fiscal 30% gasolina
				printf("<td align='right'>%s</td>", number_format(0,$n_decimales));//imp.exentos
				$imp_no_cred_fis = $matriz_compras [$j][10] + $matriz_compras [$j][11];
				printf("<td align='right'>%s</td>", number_format($imp_no_cred_fis,$n_decimales));//imp. compras gravadas tasa cero B
				$subtotal = $imp_total_compra - $imp_no_cred_fis;
				printf("<td align='right'>%s</td>", number_format($subtotal,$n_decimales));//subtotal C=A-B
				printf("<td align='right'>%s</td>", number_format($matriz_compras [$j][17],$n_decimales));//descuentos D
				printf("<td align='right'>%s</td>", number_format(0,$n_decimales));//imp. gift card
				$imp_cred_fis = $subtotal - $matriz_compras [$j][17];
				printf("<td align='right'>%s</td>", number_format($imp_cred_fis,$n_decimales));//imp. base cred. fis. E=C-D
				//$cred_fis = $imp_cred_fis * $monto_iva / 100;
				printf("<td align='right'>%s</td>", number_format($matriz_compras [$j][13],$n_decimales));//cred. fis. F=E*13%
				printf("<td align='right'>%s</td>", $matriz_compras [$j][18]);//tipo compra
				printf("<td align='right'>%s</td></tr>", $matriz_compras [$j][5]);//cod control
				
				$total_comp = $total_comp + $imp_total_compra;
				$total_ice = $total_ice + $matriz_compras [$j][10];
				$total_exe = $total_exe + $matriz_compras [$j][11];
				$total_no_cred = $total_no_cred + $imp_no_cred_fis;
				$total_sub = $total_sub + $subtotal;
				$total_desc = $total_desc + $matriz_compras [$j][17];
				$total_para_cred = $total_para_cred + $imp_cred_fis;
				$total_cred = $total_cred + $matriz_compras [$j][13];

				$nu++;
				$color++;
				$j++;
			
				} //fin while
			?>
			
			<tr BGCOLOR='#ffcccc'><td colspan="8"><b>Total</b></td>
			<td align="right"><?php printf("<b>%s</b>", number_format($total_comp,$n_decimales)); ?></td>
			<td align="right"><?php printf("<b>%s</b>", number_format($total_ice,$n_decimales)); ?></td>
			<td align="right"><?php printf("<b>%s</b>", number_format(0,$n_decimales)); ?></td>
			<td align="right"><?php printf("<b>%s</b>", number_format(0,$n_decimales)); ?></td>
			<td align="right"><?php printf("<b>%s</b>", number_format(0,$n_decimales)); ?></td>
			<td align="right"><?php printf("<b>%s</b>", number_format($total_exe,$n_decimales)); ?></td>
			<td align="right"><?php printf("<b>%s</b>", number_format(0,$n_decimales)); ?></td>
			<td align="right"><?php printf("<b>%s</b>", number_format($total_no_cred,$n_decimales)); ?></td>
			<td align="right"><?php printf("<b>%s</b>", number_format($total_sub,$n_decimales)); ?></td>
			<td align="right"><?php printf("<b>%s</b>", number_format($total_desc,$n_decimales)); ?></td>
			<td align="right"><?php printf("<b>%s</b>", number_format(0,$n_decimales)); ?></td>
			<td align="right"><?php printf("<b>%s</b>", number_format($total_para_cred,$n_decimales)); ?></td>
			<td align="right"><?php printf("<b>%s</b>", number_format($total_cred,$n_decimales)); ?></td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			</tr>
			</tbody>
			</table>

			<?php	
		}// fin if mostrar 2

	} //fin if 2

} //fin if bolivia
?>


<?php if($mi_cod_pais == 176) { //if paraguay ?>

	<?php if($mostrar == 0) { ?>

	<link href="../../libros176.css" rel="stylesheet" type="text/css" />

	<style type="text/css" media="print">
	@page {size: letter;}
	DIV {page-break-after: always;}
	</style>

	<?php } else { ?>
	<link href="../../maincss.css" rel="stylesheet" type="text/css" />
	<link href="../../printcss.css" rel="stylesheet" type="text/css" media="print" />
	<?php } ?> 
	</head>
	<?php

	if (empty($_POST["fechaini"]))
	{
		$fechaini=$_GET["fechaini"];
	} else {
		$fechaini=$_POST["fechaini"];
	}

	if (empty($_POST["fechafin"]))
	{
		$fechafin=$_GET["fechafin"];
	} else {
		$fechafin=$_POST["fechafin"];
	}
	/*
	if (empty($_POST["usuario"]))
	{
		$usuario=$_GET["usuario"];
	} else {
		$usuario=$_POST["usuario"];
	}
	*/

	//$n_decimales176 = 0;

	?>
	<body>
	<?php


	//Inicio reporte Libro de Compras

	if($rep == 9 && $tipo == 1) { // if 2

	$filas_por_pagina = 62;

	if ($proveedor == 0) { //if proveedor
		$valor_proveedor = ' ';
		$valor_proveedor2 = ' ';
		$nom_proveedor = 'Todos';
	} else { 
		$valor_proveedor = ' a.codSupplier = '.$proveedor.' and ';
		$valor_proveedor2 = ' a.codCompany = '.$proveedor.' and ';
		//nombre de proveedor
		$resultprov = mysqli_query($link, "select pkyCompany as codigo, fldName as proveedor
	from agnCompany
	where
	fldIsSupplier = 1 and
	pkyCompany = '$proveedor' and 
	sysEnabled = 1 and sysAuthorized = 1;");
		while ($row = mysqli_fetch_array($resultprov)) {
		$nom_proveedor = $row['codigo'].' - '.$row['proveedor'];
		}
		mysqli_free_result($resultprov);
	} //fin if proveedor


	//contexto
	if($cod_contexto == -1){ 
		$nom_contexto = 'Todos';
		$valor_contexto = ' ';
	} else {
		$resultcontx = mysqli_query($link, "select pkyContext as cod_contexto, fldName as contexto, codCostCenter as cod_cc 
		from srvContext
		where 
		pkyContext = '$cod_contexto';");
			while ($row = mysqli_fetch_array($resultcontx)) {   
				$nom_contexto = $row['cod_contexto'].' - '.$row['contexto'];
			}
			mysqli_free_result($resultcontx);
		$valor_contexto = ' a.sysContext = '.$cod_contexto.' and ';	
	}

	//listado de facturas compras

	$result = mysqli_query($link, "select fin.codigo as codigo, fin.nro_fac as nro_fac, fin.nro_auto as nro_auto, fin.fecha as fecha, fin.cod_control as cod_control, fin.cod_prov as cod_prov, fin.proveedor as proveedor, fin.ruc as ruc, fin.total_bruto as total_bruto, fin.ice as ice, fin.excento as excento, fin.total10 as total10, fin.credito10 as credito10, fin.total5 as total5, fin.credito5 as credito5, fin.fecha_emision as fecha_emision, fin.tabla_genera as tabla_genera, fin.cod_genera as cod_genera, fin.glosa as glosa, fin.cod_moneda as cod_moneda, fin.cod_tc as cod_tc, fin.cod_tipo_doc as cod_tipo_doc, fin.cod_tipo as cod_tipo
	from
	(select a.pkyPurchasesLedger as codigo, a.fldNumber as nro_fac, a.fldAuthorization as nro_auto, a.fldDate as fecha, a.fldControlCode as cod_control, a.codSupplier as cod_prov, a.fldName as proveedor, a.fldNIT as ruc, a.fldGrossTotal as total_bruto, a.fldICE as ice, a.fldExempt as excento, a.fldNetTotal as total10, a.fldTaxCredit as credito10, a.fldNetTotalAlternative as total5, a.fldTaxCreditAlternative as credito5, a.fldEmissionDate as fecha_emision,  a.fldParentComponent as tabla_genera, a.cosComponentKey as cod_genera, a.txtDescription as glosa, a.codCurrency as cod_moneda, a.codExchangeRate as cod_tc, 1 as cod_tipo_doc, a.codType as cod_tipo
	from
	txsPurchasesLedger a
	where 
	a.codCurrency = '$cod_moneda_principal' and 
	$valor_proveedor 
	$valor_contexto 
	a.fldDate >= '$fechaini' and
	a.fldDate <= '$fechafin' and
	a.sysEnabled = 1 AND a.sysAuthorized = 1

	union all

	select t.codigo as codigo, t.nro_fac as nro_fac, t.nro_auto as nro_auto, t.fecha as fecha, t.cod_control as cod_control, t.cod_prov as cod_prov, 
	t.proveedor as proveedor, t.ruc as ruc, t.total_bruto * tc.fldRate as total_bruto, t.ice * tc.fldRate as ice, t.excento * tc.fldRate as excento, t.total10 * tc.fldRate as total10, t.credito10 * tc.fldRate as credito10, t.total5 * tc.fldRate as total5, t.credito5 * tc.fldRate as credito5, t.fecha_emision as fecha_emision, t.tabla_genera as tabla_genera, t.cod_genera as cod_genera, t.glosa as glosa, t.cod_moneda as cod_moneda, t.cod_tc as cod_tc, t.cod_tipo_doc as cod_tipo_doc, t.cod_tipo as cod_tipo
	from
	(select a.pkyPurchasesLedger as codigo, a.fldNumber as nro_fac, a.fldAuthorization as nro_auto, a.fldDate as fecha, a.fldControlCode as cod_control, a.codSupplier as cod_prov, a.fldName as proveedor, a.fldNIT as ruc, a.fldGrossTotal as total_bruto, a.fldICE as ice, a.fldExempt as excento, a.fldNetTotal as total10, a.fldTaxCredit as credito10, a.fldNetTotalAlternative as total5, a.fldTaxCreditAlternative as credito5, a.fldEmissionDate as fecha_emision,  a.fldParentComponent as tabla_genera, a.cosComponentKey as cod_genera, a.txtDescription as glosa, a.codCurrency as cod_moneda, a.codExchangeRate as cod_tc, 1 as cod_tipo_doc, a.codType as cod_tipo
	from
	txsPurchasesLedger a
	where 
	a.codCurrency <> '$cod_moneda_principal' and 
	$valor_proveedor 
	$valor_contexto 
	a.fldDate >= '$fechaini' and
	a.fldDate <= '$fechafin' and
	a.sysEnabled = 1 AND a.sysAuthorized = 1) t, actExchangeRateDetail tc
	where
	tc.codTargetCurrency = t.cod_moneda and
	tc.codBaseCurrency = '$cod_moneda_principal' and
	tc.codExchangeRate = t.cod_tc


	UNION ALL 


	select a.pkyDiscountsDevolutions as codigo, a.fldNumber as nro_fac, a.fldAuthorization as nro_auto, a.fldDate as fecha, a.fldControlCode as cod_control, a.codCompany as cod_prov, a.fldName as proveedor, a.fldNIT as ruc, a.fldGrossTotal* -1 as total_bruto, 0 as ice, a.fldExempt * -1 as excento, a.fldNetTotal * -1 as total10, a.fldTaxCredit * -1  as credito10, a.fldNetTotalAlternative * -1 as total5, a.fldTaxCreditAlternative * - 1 as credito5, a.fldEmissionDate as fecha_emision,  a.fldParentComponent as tabla_genera, a.cosComponentKey as cod_genera, a.txtDescription as glosa, a.codCurrency as cod_moneda, a.codExchangeRate as cod_tc, 3 as cod_tipo_doc, 0 as cod_tipo
	from
	txsDiscountsDevolutions a
	where 
	a.codCurrency = '$cod_moneda_principal' and 
	a.fldIsReceived = 1 and 
	$valor_proveedor2 
	$valor_contexto 
	a.fldDate >= '$fechaini' and
	a.fldDate <= '$fechafin' and
	a.sysEnabled = 1 AND a.sysAuthorized = 1

	union all

	select t.codigo as codigo, t.nro_fac as nro_fac, t.nro_auto as nro_auto, t.fecha as fecha, t.cod_control as cod_control, t.cod_prov as cod_prov, 
	t.proveedor as proveedor, t.ruc as ruc, t.total_bruto * tc.fldRate as total_bruto, t.ice * tc.fldRate as ice, t.excento * tc.fldRate as excento, t.total10 * tc.fldRate as total10, t.credito10 * tc.fldRate as credito10, t.total5 * tc.fldRate as total5, t.credito5 * tc.fldRate as credito5, t.fecha_emision as fecha_emision, t.tabla_genera as tabla_genera, t.cod_genera as cod_genera, t.glosa as glosa, t.cod_moneda as cod_moneda, t.cod_tc as cod_tc, t.cod_tipo_doc as cod_tipo_doc, t.cod_tipo as cod_tipo
	from
	(select a.pkyDiscountsDevolutions as codigo, a.fldNumber as nro_fac, a.fldAuthorization as nro_auto, a.fldDate as fecha, a.fldControlCode as cod_control, a.codCompany as cod_prov, a.fldName as proveedor, a.fldNIT as ruc, a.fldGrossTotal* -1 as total_bruto, 0 as ice, a.fldExempt * -1 as excento, a.fldNetTotal * -1 as total10, a.fldTaxCredit * -1  as credito10, a.fldNetTotalAlternative * -1 as total5, a.fldTaxCreditAlternative * - 1 as credito5, a.fldEmissionDate as fecha_emision,  a.fldParentComponent as tabla_genera, a.cosComponentKey as cod_genera, a.txtDescription as glosa, a.codCurrency as cod_moneda, a.codExchangeRate as cod_tc, 3 as cod_tipo_doc, 0 as cod_tipo
	from
	txsDiscountsDevolutions a
	where 
	a.codCurrency <> '$cod_moneda_principal' and 
	a.fldIsReceived = 1 and 
	$valor_proveedor2 
	$valor_contexto 
	a.fldDate >= '$fechaini' and
	a.fldDate <= '$fechafin' and
	a.sysEnabled = 1 AND a.sysAuthorized = 1) t, actExchangeRateDetail tc
	where
	tc.codTargetCurrency = t.cod_moneda and
	tc.codBaseCurrency = '$cod_moneda_principal' and
	tc.codExchangeRate = t.cod_tc) fin 
	order by fin.fecha, fin.proveedor, fin.nro_auto;");


	$numero_filas = mysqli_num_rows($result);
	$var = ceil($numero_filas/$filas_por_pagina); //redondea hacia arriba

	$matriz_compras = array();
	$i = 1;
	while ($row = mysqli_fetch_array($result)) {
		$matriz_compras [$i][1] = $row['codigo'];
		$matriz_compras [$i][2] = $row['nro_fac'];
		$matriz_compras [$i][3] = $row['nro_auto'];
		$matriz_compras [$i][4] = $row['fecha'];
		$matriz_compras [$i][5] = $row['cod_control'];
		if($row['cod_control'] == NULL){
			$matriz_compras [$i][5] = 0;
		} else {
			$matriz_compras [$i][5] = $row['cod_control'];
		}
		$matriz_compras [$i][6] = $row['cod_pro'];
		$matriz_compras [$i][7] = $row['proveedor'];
		$matriz_compras [$i][8] = $row['ruc'];
		$matriz_compras [$i][9] = round($row['total_bruto'],$n_decimales176);
		$matriz_compras [$i][10] = round($row['ice'],$n_decimales176);
		$matriz_compras [$i][11] = round($row['excento'],$n_decimales176);
		$matriz_compras [$i][12] = round($row['total10'],$n_decimales176);
		$matriz_compras [$i][13] = round($row['credito10'],$n_decimales176);
		$matriz_compras [$i][14] = $row['glosa'];
		$matriz_compras [$i][15] = $row['tabla_genera'];
		$matriz_compras [$i][16] = $row['cod_genera'];
		$matriz_compras [$i][17] = round($row['descuento'],$n_decimales176);
		$matriz_compras [$i][18] = $row['cod_tipo_doc'];
		$matriz_compras [$i][19] = NULL; //enlace al papa
		$matriz_compras [$i][20] = round($row['total5'],$n_decimales176);
		$matriz_compras [$i][21] = round($row['credito5'],$n_decimales176);
		$matriz_compras [$i][22] = $row['cod_tipo'];//directo=1, indirecto=2, exento=3
			
		//para enlazar al que genero el asiento
		$papa_componente = $matriz_compras [$i][15];
		$papa_codigo = $matriz_compras [$i][16];
		//$usuario = $usuario_det;
		include "../../generadopor.php";
		$matriz_compras [$i][19] = $papa_enlace;
		$i++;
	}
	$fin = $i - 1;
	mysqli_free_result($result);


	$sucursal = '0';
	$dir_sucursal = $mi_direccion;

	$total_imp_10_par = 0;
	$total_iva_10_par = 0;
	$total_imp_5_par = 0;
	$total_iva_5_par = 0;
	$total_ex_par = 0;
	$total_tot_par = 0;
	$total_bas_par = 0;

	$total_imp_10 = 0;
	$total_iva_10 = 0;
	$total_imp_5 = 0;
	$total_iva_5 = 0;
	$total_ex = 0;
	$total_tot = 0;
	$total_bas = 0;

	$total_dir_10 = 0;
	$total_dir_iva_10 = 0;
	$total_dir_5 = 0;
	$total_dir_iva_5 = 0;
	$total_dir_ex = 0;
	$total_dir_tot = 0;

	$total_indir_10 = 0;
	$total_indir_iva_10 = 0;
	$total_indir_5 = 0;
	$total_indir_iva_5 = 0;
	$total_indir_ex = 0;
	$total_indir_tot = 0;

	$total_exe_10 = 0;
	$total_exe_iva_10 = 0;
	$total_exe_5 = 0;
	$total_exe_iva_5 = 0;
	$total_exe_ex = 0;
	$total_exe_tot = 0;

	$total_gen3_10 = 0;
	$total_gen3_iva_10 = 0;
	$total_gen3_5 = 0;
	$total_gen3_iva_5 = 0;
	$total_gen3_ex = 0;
	$total_gen3_tot = 0;

	$total_cred_10 = 0;
	$total_cred_iva_10 = 0;
	$total_cred_5 = 0;
	$total_cred_iva_5 = 0;
	$total_cred_ex = 0;
	$total_cred_tot = 0;

	$total_co_imp_10 = 0;
	$total_co_iva_10 = 0;
	$total_co_imp_5 = 0;
	$total_co_iva_5 = 0;
	$total_co_ex = 0;
	$total_co_tot = 0;

	$total_cr_imp_10 = 0;
	$total_cr_iva_10 = 0;
	$total_cr_imp_5 = 0;
	$total_cr_iva_5 = 0;
	$total_cr_ex = 0;
	$total_cr_tot = 0;

	if($numero_filas == 0) {//if $numero_filas
	$i = 1;
	$var = 1;
	$filas_por_pagina = 62;
	}//fin if $numero_filas

	//este if es para mostrar con el formato de libro de compras
	if($mostrar == 0) { //mostrar 0

	$j = 1;
	//$nu = 1;
	for($i = 1; $i <= $var; $i++) {//for
	?>
	<table border="0" align="center" cellpadding="2" width="990">
	<tr>
		<td rowspan="6" width="200">
		<img src="../../Images/logo.jpg" />
		</td>
	</tr>
	<tr>
		<td width="670"><b><font style="font-size:14px"><?php echo $nombre_empresa; ?></font></b></td>
		<td width="120">Fecha: <?php echo date("d/m/Y",strtotime($fecha_hoy)); ?></td>
	</tr>
	<tr>
		<td><?php echo $dir_sucursal; ?></td>
		<td>Hora: <?php echo date("H:i:s"); ?></td>
	</tr>
	<tr>
		<td>RUC: <?php echo $mi_nit; ?></td>
		<td>&nbsp;</td>
	</tr>
	<tr>
		<td width="990" colspan="2">&nbsp;</td>
	</tr>
	<tr>
		<td width="990" colspan="2">LIBRO COMPRAS LEY 125/91 DEL <?php echo date("d/m/Y",strtotime($fechaini)); ?> AL <?php echo date("d/m/Y",strtotime($fechafin)); ?></td>
	</tr>
	</table>

	<br />

	<table border="1" align="center" cellpadding="2" width="990" height="1200">
		<TR> 
		<TD align="center" colspan="2" style='border-bottom: solid 1px'><b>DOCUMENTO</b></TD>
		<TD align="center" colspan="2" style='border-bottom: solid 1px'><b>PROVEEDOR DE BIENES/SERVICIOS</b></TD>
		<TD align="center" colspan="2" style='border-bottom: solid 1px'><b>10%</b></TD>
		<TD align="center" colspan="2" style='border-bottom: solid 1px'><b>5%</b></TD>
		<TD align="center">&nbsp;</TD>
		<TD align="center">&nbsp;</TD>
		<TD align="center" width="55" rowspan="2" style='border-bottom: solid 1px'><b>BASE IMPONIBLE DE IMPORTACI&Oacute;N</b></TD>
		<?php if($numero_filas != 0) { ?>
		<TD align="center" width="10" rowspan="2" style='border: none'>&nbsp;</TD>
		<?php } ?>
		</TR>
		<TR>
		<TD align="center" width="10" style='border-bottom: solid 1px'><b>D&Iacute;A</b></TD>
		<TD align="center" width="40" style='border-bottom: solid 1px'><b>N&Uacute;MERO</b></TD>
		<TD align="center" width="55" style='border-bottom: solid 1px'><b>RUC</b></TD>
		<TD align="center" width="400" style='border-bottom: solid 1px'><b>RAZ&Oacute;N SOCIAL/NOMBRE(S)</b></TD>
		<TD align="center" width="55" style='border-bottom: solid 1px'><b>GRAVADAS</b></TD>
		<TD align="center" width="55" style='border-bottom: solid 1px'><b>IVA</b></TD>
		<TD align="center" width="55" style='border-bottom: solid 1px'><b>GRAVADAS</b></TD>
		<TD align="center" width="55" style='border-bottom: solid 1px'><b>IVA</b></TD>
		<TD align="center" width="55" style='border-bottom: solid 1px'><b>EXENTAS</b></TD>
		<TD align="center" width="55" style='border-bottom: solid 1px'><b>TOTAL</b></TD>
		</TR>
		
		<?php if($i > 1) { //if tras ?>
			
		<tr>
		<td colspan="4" align="center" style='border-bottom: dashed 1px'><b>TRANSPORTE... </b></td>
		<td align="right" style='border-bottom: dashed 1px'><b><?php echo number_format($total_imp_10_par,$n_decimales176); ?></td>
		<td align="right" style='border-bottom: dashed 1px'><b><?php echo number_format($total_iva_10_par,$n_decimales176); ?></td>
		<td align="right" style='border-bottom: dashed 1px'><b><?php echo number_format($total_imp_5_par,$n_decimales176); ?></td>
		<td align="right" style='border-bottom: dashed 1px'><b><?php echo number_format($total_iva_5_par,$n_decimales176); ?></td>
		<td align="right" style='border-bottom: dashed 1px'><b><?php echo number_format($total_ex_par,$n_decimales176); ?></td>
		<td align="right" style='border-bottom: dashed 1px'><b><?php echo number_format($total_tot_par,$n_decimales176); ?></td>
		<td align="right" style='border-bottom: dashed 1px'><b><?php echo number_format($total_bas_par,$n_decimales176); ?></td>
		<td style='border: none'>&nbsp;</td>
		</tr>
		
		<?php } //fin if tras ?>

	<?php
	/*
	$total_imp_10_par = 0;
	$total_iva_10_par = 0;
	$total_imp_5_par = 0;
	$total_iva_5_par = 0;
	$total_ex_par = 0;
	$total_tot_par = 0;
	$total_bas_par = 0;
		*/
	$color = 2;
	$q = 1;//
	while ($q <= $filas_por_pagina) { //while
		
	if($numero_filas == 0) {//if filas
		printf("<tr><td align='center'>&nbsp;</td>");//fecha vacia
	} else { //else filas
		if($color % 2 == 0) { //if color
			if($matriz_compras [$j][4] != NULL) {
			printf("<tr BGCOLOR='#e2e7fa'><td align='center'>%s</td>", date("d",strtotime($matriz_compras [$j][4])));//fecha dia
			} else { 
			printf("<tr BGCOLOR='#e2e7fa'><td align='center'>&nbsp;</td>");//fecha vacio
			}
		} else {
			if($matriz_compras [$j][4] != NULL) {
			printf("<tr><td align='center'>%s</td>", date("d",strtotime($matriz_compras [$j][4])));//fecha dia
			} else { 
			printf("<tr><td align='center'>&nbsp;</td>");//fecha vacio
			}
		}//fin if color
	}//fin filas
		printf("<td align='right'>%s</td>", $matriz_compras [$j][2]);//nro. factura
		printf("<td align='right'>%s</td>", $matriz_compras [$j][8]);//ruc
		$texto = $matriz_compras [$j][7];//proveedor
		$texto = strtr(strtoupper($texto), "àáâãäåæçèéêëìíîïðñòóôõöøùüú", "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÜÚ");
		$texto = substr($texto,0,150);
		printf("<td align='left'>%s</td>", $texto);//proveedor
		
		//$importe_10 = round($matriz_compras [$j][12] / 1.1,$n_decimales);
		//$iva_10 = round($matriz_compras [$j][12] / 11,$n_decimales);
		//$importe_5 = round(0,$n_decimales);
		//$iva_5 = round($importe_5 * 0.05,$n_decimales);
		$importe_10 = round($matriz_compras [$j][12] - $matriz_compras [$j][13],$n_decimales176);	
		$iva_10 = round($matriz_compras [$j][13],$n_decimales176);	
		$importe_5 = round($matriz_compras [$j][20] - $matriz_compras [$j][21],$n_decimales176);	
		$iva_5 = round($matriz_compras [$j][21],$n_decimales176);	
		$exento = round($matriz_compras [$j][11],$n_decimales176);
		$total_final = $importe_10 + $iva_10 + $importe_5 + $iva_5 + $exento;
		$base_imp = 0;
			
		if($total_final == 0) {//if si es 0
		printf("<td align='right'>%s</td>", NULL);//gravadas 10
		printf("<td align='right'>%s</td>", NULL);//iva 10
		printf("<td align='right'>%s</td>", NULL);//gravadas 5
		printf("<td align='right'>%s</td>", NULL);//iva 5
		printf("<td align='right'>%s</td>", NULL);//exenta
		printf("<td align='right'>%s</td>", NULL);//total
		printf("<td align='right'>%s</td></tr>", NULL);//base imponible
		} else { //else si es 0
		printf("<td align='right'>%s</td>", number_format($importe_10,$n_decimales176));//gravadas 10
		printf("<td align='right'>%s</td>", number_format($iva_10,$n_decimales176));//iva 10
		printf("<td align='right'>%s</td>", number_format($importe_5,$n_decimales176));//gravadas 5
		printf("<td align='right'>%s</td>", number_format($iva_5,$n_decimales176));//iva 5
		printf("<td align='right'>%s</td>", number_format($exento,$n_decimales176));//exento
		printf("<td align='right'>%s</td>", number_format($total_final,$n_decimales176));//total final
		printf("<td align='right'>%s</td>", number_format($base_imp,$n_decimales176));//base imponible importaciones
		printf("<td align='left'>%s</td></tr>", 'CO');//co, cr
		
		$total_imp_10_par = $total_imp_10_par + $importe_10;
		$total_iva_10_par = $total_iva_10_par + $iva_10;
		$total_imp_5_par = $total_imp_5_par + $importe_5;
		$total_iva_5_par = $total_iva_5_par + $iva_5;
		$total_ex_par = $total_ex_par + $exento;
		$total_tot_par = $total_tot_par + $total_final;
		$total_bas_par = $total_bas_par + $base_imp;
		
		$total_imp_10 = $total_imp_10 + $importe_10;
		$total_iva_10 = $total_iva_10 + $iva_10;
		$total_imp_5 = $total_imp_5 + $importe_5;
		$total_iva_5 = $total_iva_5 + $iva_5;
		$total_ex = $total_ex + $exento;
		$total_tot = $total_tot + $total_final;
		$total_bas = $total_bas + $base_imp;
		
		if($matriz_compras [$j][22] == 1) { //if dir
		$total_dir_10 = $total_dir_10 + $importe_10;
		$total_dir_iva_10 = $total_dir_iva_10 + $iva_10;
		$total_dir_5 = $total_dir_5 + $importe_5;
		$total_dir_iva_5 = $total_dir_iva_5 + $iva_5;
		$total_dir_ex = $total_dir_ex + $exento;
		$total_dir_tot = $total_dir_tot + $total_final;
		}//fin if dir
		
		if($matriz_compras [$j][22] == 2) { //if indir
		$total_indir_10 = $total_indir_10 + $importe_10;
		$total_indir_iva_10 = $total_indir_iva_10 + $iva_10;
		$total_indir_5 = $total_indir_5 + $importe_5;
		$total_indir_iva_5 = $total_indir_iva_5 + $iva_5;
		$total_indir_ex = $total_indir_ex + $exento;
		$total_indir_tot = $total_indir_tot + $total_final;
		}//fin if indir
		
		if($matriz_compras [$j][22] == 3) { //if exe
		$total_exe_10 = $total_exe_10 + $importe_10;
		$total_exe_iva_10 = $total_exe_iva_10 + $iva_10;
		$total_exe_5 = $total_exe_5 + $importe_5;
		$total_exe_iva_5 = $total_exe_iva_5 + $iva_5;
		$total_exe_ex = $total_exe_ex + $exento;
		$total_exe_tot = $total_exe_tot + $total_final;
		}//fin if exe
		
		if($matriz_compras [$j][22] == 1 || $matriz_compras [$j][22] == 2 || $matriz_compras [$j][22] == 3) { //if gen3
		$total_gen3_10 = $total_gen3_10 + $importe_10;
		$total_gen3_iva_10 = $total_gen3_iva_10 + $iva_10;
		$total_gen3_5 = $total_gen3_5 + $importe_5;
		$total_gen3_iva_5 = $total_gen3_iva_5 + $iva_5;
		$total_gen3_ex = $total_gen3_ex + $exento;
		$total_gen3_tot = $total_gen3_tot + $total_final;
		}//fin if gen3
		
		if($matriz_compras [$j][22] == 0) { //if cred
		$total_cred_10 = $total_cred_10 + $importe_10;
		$total_cred_iva_10 = $total_cred_iva_10 + $iva_10;
		$total_cred_5 = $total_cred_5 + $importe_5;
		$total_cred_iva_5 = $total_cred_iva_5 + $iva_5;
		$total_cred_ex = $total_cred_ex + $exento;
		$total_cred_tot = $total_cred_tot + $total_final;
		}//fin if cred
		
		}//fin if si es 0
		
		
		if($numero_filas == 0 && $j == 32) {
			printf("<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td align='center' colspan='6'><font size='16'><b>SIN MOVIMIENTO</b></font></td><td>&nbsp;</td><td>&nbsp;</td></tr>");
		}
		
		$color++;
		$j++;
		$q++;
	}//fin while


	?>
	<?php if($i != $var) {//if comp ?>
	<tr>
	<td colspan="4" align="center" style='border-top: dashed 1px'><b>TRANSPORTE... </b></td>
	<td align="right" style='border-top: dashed 1px'><b><?php echo number_format($total_imp_10_par,$n_decimales176); ?></td>
	<td align="right" style='border-top: dashed 1px'><b><?php echo number_format($total_iva_10_par,$n_decimales176); ?></td>
	<td align="right" style='border-top: dashed 1px'><b><?php echo number_format($total_imp_5_par,$n_decimales176); ?></td>
	<td align="right" style='border-top: dashed 1px'><b><?php echo number_format($total_iva_5_par,$n_decimales176); ?></td>
	<td align="right" style='border-top: dashed 1px'><b><?php echo number_format($total_ex_par,$n_decimales176); ?></td>
	<td align="right" style='border-top: dashed 1px'><b><?php echo number_format($total_tot_par,$n_decimales176); ?></td>
	<td align="right" style='border-top: dashed 1px'><b><?php echo number_format($total_bas_par,$n_decimales176); ?></td>
	<td style='border: none'>&nbsp;</td>
	</tr>
	<?php } else {//else if comp ?>
	<tr>
	<td colspan="4" align="center" style='border-top: solid 1px'><b>TOTALES: </b></td>
	<td align="right" style='border-top: solid 1px'><b><?php echo number_format($total_imp_10,$n_decimales176); ?></td>
	<td align="right" style='border-top: solid 1px'><b><?php echo number_format($total_iva_10,$n_decimales176); ?></td>
	<td align="right" style='border-top: solid 1px'><b><?php echo number_format($total_imp_5,$n_decimales176); ?></td>
	<td align="right" style='border-top: solid 1px'><b><?php echo number_format($total_iva_5,$n_decimales176); ?></td>
	<td align="right" style='border-top: solid 1px'><b><?php echo number_format($total_ex,$n_decimales176); ?></td>
	<td align="right" style='border-top: solid 1px'><b><?php echo number_format($total_tot,$n_decimales176); ?></td>
	<td align="right" style='border-top: solid 1px'><b><?php echo number_format($total_bas,$n_decimales176); ?></td>
	<?php if($numero_filas != 0) { ?>
	<td style='border: none'>&nbsp;</td>
	<?php } ?>
	</tr>
	<!--
	<tr>
	<td colspan="4" align="center" style='border-top: solid 1px'><b>REDONDEO: </b></td>
	<td align="right" style='border-top: solid 1px'><b><?php echo number_format($total_imp_10,$n_decimales); ?></td>
	<td align="right" style='border-top: solid 1px'><b><?php echo number_format($total_iva_10,$n_decimales); ?></td>
	<td align="right" style='border-top: solid 1px'><b><?php echo number_format($total_imp_5,$n_decimales); ?></td>
	<td align="right" style='border-top: solid 1px'><b><?php echo number_format($total_iva_5,$n_decimales); ?></td>
	<td align="right" style='border-top: solid 1px'><b><?php echo number_format($total_ex,$n_decimales); ?></td>
	<td align="right" style='border-top: solid 1px'><b><?php echo number_format($total_tot,$n_decimales); ?></td>
	<td align="right" style='border-top: solid 1px'><b><?php echo number_format($total_bas,$n_decimales); ?></td>
	<?php if($numero_filas != 0) { ?>
	<td style='border: none'>&nbsp;</td>
	<?php } ?>
	</tr>
	-->
	<?php }//fin if comp ?>

	</table>

	<table border="0" align="center" cellpadding="2" width="990">
	<tr>
	<td align="right">P&aacute;gina: <?php echo $i; ?> de <?php echo $var; ?></td>
	</tr>
	</table>

	<?php

		if($i != $var) {//if $i
		?>
			<div>
			</div>
		<?php
		}//fin if $i
	}//fin for

	?>
	<br/><br/>
	<table border="1" align="center" cellpadding="2" width="700">
	<tr>
	<td align="right" width="200" style='border-top: solid 1px'><b>TOTAL COMPRAS BRUTAS</b></td>
	<td align="center" width="55" style='border-top: solid 1px'><b>GRAVADAS 10%</b></td>
	<td align="center" width="55" style='border-top: solid 1px'><b>IVA 10%</b></td>
	<td align="center" width="55" style='border-top: solid 1px'><b>GRAVADAS 5%</b></td>
	<td align="center" width="55" style='border-top: solid 1px'><b>IVA 5%</b></td>
	<td align="center" width="55" style='border-top: solid 1px'><b>EXENTAS</b></td>
	<td align="center" width="55" style='border-top: solid 1px'><b>TOTAL</b></td>
	</tr>
	<tr>
	<td align="right" width="200" style='border-top: solid 1px'><b>TOTAL IVA DIRECTO: </b></td>
	<td align="right" width="55" style='border-top: solid 1px'><b><?php echo number_format($total_dir_10,$n_decimales176); ?></td>
	<td align="right" width="55" style='border-top: solid 1px'><b><?php echo number_format($total_dir_iva_10,$n_decimales176); ?></td>
	<td align="right" width="55" style='border-top: solid 1px'><b><?php echo number_format($total_dir_5,$n_decimales176); ?></td>
	<td align="right" width="55" style='border-top: solid 1px'><b><?php echo number_format($total_dir_iva_5,$n_decimales176); ?></td>
	<td align="right" width="55" style='border-top: solid 1px'><b><?php echo number_format($total_dir_ex,$n_decimales176); ?></td>
	<td align="right" width="55" style='border-top: solid 1px'><b><?php echo number_format($total_dir_tot,$n_decimales176); ?></td>
	</tr>
	<tr>
	<td align="right" width="200" style='border-top: solid 1px'><b>TOTAL IVA INDIRECTO: </b></td>
	<td align="right" width="55" style='border-top: solid 1px'><b><?php echo number_format($total_indir_10,$n_decimales176); ?></td>
	<td align="right" width="55" style='border-top: solid 1px'><b><?php echo number_format($total_indir_iva_10,$n_decimales176); ?></td>
	<td align="right" width="55" style='border-top: solid 1px'><b><?php echo number_format($total_indir_5,$n_decimales176); ?></td>
	<td align="right" width="55" style='border-top: solid 1px'><b><?php echo number_format($total_indir_iva_5,$n_decimales176); ?></td>
	<td align="right" width="55" style='border-top: solid 1px'><b><?php echo number_format($total_indir_ex,$n_decimales176); ?></td>
	<td align="right" width="55" style='border-top: solid 1px'><b><?php echo number_format($total_indir_tot,$n_decimales176); ?></td>
	</tr>
	<tr>
	<td align="right" width="200" style='border-top: solid 1px'><b>TOTAL COMPRAS EXENTAS: </b></td>
	<td align="right" width="55" style='border-top: solid 1px'><b><?php echo number_format($total_exe_10,$n_decimales176); ?></td>
	<td align="right" width="55" style='border-top: solid 1px'><b><?php echo number_format($total_exe_iva_10,$n_decimales176); ?></td>
	<td align="right" width="55" style='border-top: solid 1px'><b><?php echo number_format($total_exe_5,$n_decimales176); ?></td>
	<td align="right" width="55" style='border-top: solid 1px'><b><?php echo number_format($total_exe_iva_5,$n_decimales176); ?></td>
	<td align="right" width="55" style='border-top: solid 1px'><b><?php echo number_format($total_exe_ex,$n_decimales176); ?></td>
	<td align="right" width="55" style='border-top: solid 1px'><b><?php echo number_format($total_exe_tot,$n_decimales176); ?></td>
	</tr>
	<tr>
	<td align="right" width="200" style='border-top: solid 1px'><b>TOTAL GENERAL: </b></td>
	<td align="right" width="55" style='border-top: solid 1px'><b><?php echo number_format($total_gen3_10,$n_decimales176); ?></td>
	<td align="right" width="55" style='border-top: solid 1px'><b><?php echo number_format($total_gen3_iva_10,$n_decimales176); ?></td>
	<td align="right" width="55" style='border-top: solid 1px'><b><?php echo number_format($total_gen3_5,$n_decimales176); ?></td>
	<td align="right" width="55" style='border-top: solid 1px'><b><?php echo number_format($total_gen3_iva_5,$n_decimales176); ?></td>
	<td align="right" width="55" style='border-top: solid 1px'><b><?php echo number_format($total_gen3_ex,$n_decimales176); ?></td>
	<td align="right" width="55" style='border-top: solid 1px'><b><?php echo number_format($total_gen3_tot,$n_decimales176); ?></td>
	</tr>
	<tr>
	<td align="right" width="200" style='border-top: solid 1px'><b>TOTAL NOTAS DE CR&Eacute;DITO</b></td>
	<td align="center" width="55" style='border-top: solid 1px'><b>GRAVADAS 10%</b></td>
	<td align="center" width="55" style='border-top: solid 1px'><b>IVA 10%</b></td>
	<td align="center" width="55" style='border-top: solid 1px'><b>GRAVADAS 5%</b></td>
	<td align="center" width="55" style='border-top: solid 1px'><b>IVA 5%</b></td>
	<td align="center" width="55" style='border-top: solid 1px'><b>EXENTAS</b></td>
	<td align="center" width="55" style='border-top: solid 1px'><b>TOTAL</b></td>
	</tr>
	<tr>
	<td align="right" width="200" style='border-top: solid 1px'><b>NOTAS DE CR&Eacute;DITO: </b></td>
	<td align="right" width="55" style='border-top: solid 1px'><b><?php echo number_format($total_cred_10*-1,$n_decimales176); ?></td>
	<td align="right" width="55" style='border-top: solid 1px'><b><?php echo number_format($total_cred_iva_10*-1,$n_decimales176); ?></td>
	<td align="right" width="55" style='border-top: solid 1px'><b><?php echo number_format($total_cred_5*-1,$n_decimales176); ?></td>
	<td align="right" width="55" style='border-top: solid 1px'><b><?php echo number_format($total_cred_iva_5*-1,$n_decimales176); ?></td>
	<td align="right" width="55" style='border-top: solid 1px'><b><?php echo number_format($total_cred_ex*-1,$n_decimales176); ?></td>
	<td align="right" width="55" style='border-top: solid 1px'><b><?php echo number_format($total_cred_tot*-1,$n_decimales176); ?></td>
	</tr>
	<tr>
	<td align="right" width="200" style='border-top: solid 1px'><b>TOTAL GENERAL: </b></td>
	<td align="right" width="55" style='border-top: solid 1px'><b><?php echo number_format($total_cred_10*-1,$n_decimales176); ?></td>
	<td align="right" width="55" style='border-top: solid 1px'><b><?php echo number_format($total_cred_iva_10*-1,$n_decimales176); ?></td>
	<td align="right" width="55" style='border-top: solid 1px'><b><?php echo number_format($total_cred_5*-1,$n_decimales176); ?></td>
	<td align="right" width="55" style='border-top: solid 1px'><b><?php echo number_format($total_cred_iva_5*-1,$n_decimales176); ?></td>
	<td align="right" width="55" style='border-top: solid 1px'><b><?php echo number_format($total_cred_ex*-1,$n_decimales176); ?></td>
	<td align="right" width="55" style='border-top: solid 1px'><b><?php echo number_format($total_cred_tot*-1,$n_decimales176); ?></td>
	</tr>
	</table>
	<?php

	}// fin if mostrar 0



	//este if es para mostrar con el formato detalle de facturas
	if($mostrar == 1) { //mostrar 1

	?>
	<table border="0" align="left" width="100%" cellpadding="5">
	<tr><td><?php echo $mostrar_logo_reportes; ?>
	</td><td align="right"><b>Fecha: <?php echo date("Y-m-d"); ?><br/>Hora: <?php echo date("H:i:s"); ?><br/>Usuario: <?php echo $usuario; ?></b>
	</td></tr></table>
	<p><br /><center><font color="#000099" size="+1"><b>Detalle Facturas Compras</b></font></center></p>
	<table border="0" cellpadding="2" align="center" width="100%">
	<tr>
	<td>	
		<table border="1" align="center" cellpadding="2" width="100%">
			<TR> 
			<TD width="33%"><b>Proveedor: </b><?php echo $nom_proveedor; ?></TD>
			<TD width="33%"><b>Sucursal: </b><?php echo $sucursal; ?></TD>
			<TD width="33%"><b>De Fecha: </b><?php echo $fechaini; ?> <b>a Fecha: </b><?php echo $fechafin; ?></TD>
			</TR>
			<TR>
			<TD colspan="2"><b>Contexto: </b><?php echo $nom_contexto; ?></TD>
			<TD><b>Expresado en: </b><?php echo $nom_moneda_principal; ?></TD>
			</TR>
		</table>

	</td>
	<!--
	<td valign="top" width="150">

		<table border="1" align="center" cellpadding="2" width="100%">
		<tr>
		<TD><b>Tipo de Cambio:</b></TD>
		</tr><tr>
		<TD align="center"><a href="../../ModuleAccounting/VoucherExchangeRate/index.php?pkyExchangeRate=<?php echo $ultimo_tc; ?>&user=<?php echo $usuario; ?>&token=<?php echo $token; ?>" title="Tipo de Cambio"><?php echo $ultimo_tc; ?></a> (<?php echo $tc_fecha; ?> - <?php echo $tc_hora; ?>)<br/ >
			<table border="0" cellpadding="2" align="center">
				<?php
				for($m = 1; $m <= $fin_m; $m++) {
				printf("<tr><td align='left'>1 %s</td>", $ma_tc [$m][1]);//moneda base
				printf("<td align='center'>%s</td>", ' = ');//letra a
				printf("<td align='left'>%s %s</td>", number_format($ma_tc [$m][3],$n_tipocambio), $ma_tc [$m][2]);//moneda target y tasa
				//printf("<td align='right'>%s</td></tr>", number_format($ma_tc [$m][3],$n_tipocambio));//tasa
				}
				?>
			</table>
		</TD>
		</tr>
		</table>
		
	</td>
	-->
	</tr>
	</table>
	<br />

	<table border="1" align="center" cellpadding="2" width="100%">
		<thead>
		<TR> 
		<TD align="center"><b>No.</b></TD>
		<TD align="center" width="65"><b>Fecha</b></TD>
		<TD align="center"><b>N&uacute;mero</b></TD>
		<TD align="center"><b>RUC</b></TD>
		<TD align="center"><b>Raz&oacute;n Social/Nombre(s)</b></TD>
		<TD align="center"><b>Gravadas 10%</b></TD>
		<TD align="center"><b>IVA 10%</b></TD>
		<TD align="center"><b>Gravadas 5%</b></TD>
		<TD align="center"><b>IVA 5%</b></TD>
		<TD align="center"><b>Exentas</b></TD>
		<TD align="center"><b>Total</b></TD>
		<TD align="center"><b>Base Imponible de Importaci&oacute;n</b></TD>
		<TD align="center"><b>CO/CR</b></TD>
		<TD align="center"><b>Glosa</b></TD>
		<TD align="center"><b>Generado por</b></TD>
		</TR>
		</thead>
		<tbody class="marcafila">

	<?php
	$color = 2;
	$j = 1;
	$nu = 1;
	$total_imp_10 = 0;
	$total_iva_10 = 0;
	$total_imp_5 = 0;
	$total_iva_5 = 0;
	$total_ex = 0;
	$total_tot = 0;
	$total_bas = 0;

	$total_dir_10 = 0;
	$total_dir_iva_10 = 0;
	$total_dir_5 = 0;
	$total_dir_iva_5 = 0;
	$total_dir_ex = 0;
	$total_dir_tot = 0;

	$total_indir_10 = 0;
	$total_indir_iva_10 = 0;
	$total_indir_5 = 0;
	$total_indir_iva_5 = 0;
	$total_indir_ex = 0;
	$total_indir_tot = 0;

	$total_exe_10 = 0;
	$total_exe_iva_10 = 0;
	$total_exe_5 = 0;
	$total_exe_iva_5 = 0;
	$total_exe_ex = 0;
	$total_exe_tot = 0;

	$total_gen3_10 = 0;
	$total_gen3_iva_10 = 0;
	$total_gen3_5 = 0;
	$total_gen3_iva_5 = 0;
	$total_gen3_ex = 0;
	$total_gen3_tot = 0;

	$total_cred_10 = 0;
	$total_cred_iva_10 = 0;
	$total_cred_5 = 0;
	$total_cred_iva_5 = 0;
	$total_cred_ex = 0;
	$total_cred_tot = 0;

	/*
	//matriz que genero para encontrar la tabla
	$matriz_tabla = array();
	$matriz_tabla [1][1] = 'ComponentAccountsPayable';
	//$matriz_tabla [1][2] = 'pay';
	$matriz_tabla [2][1] = 'ComponentAccountEntry';
	//$matriz_tabla [2][2] = 'act';
	$matriz_tabla [3][1] = 'ComponentPayrollExpenses';
	//$matriz_tabla [3][3] = 'pch';
	$matriz_tabla [4][1] = 'ComponentPurchaseOrder';
	//$matriz_tabla [4][4] = 'pch';
	$matriz_tabla [5][1] = 'ComponentReceiptOfGoods';
	//$matriz_tabla [5][5] = 'pch';
	*/

		while ($j <= $fin) { //while
		
		if($color % 2 == 0) { //if color
		printf("<tr BGCOLOR='#e2e7fa'><td align='center'>%s</td>", $nu);//numero
		} else {
		printf("<tr><td align='center'>%s</td>", $nu);//numero
		}//fin if color
		
		printf("<td align='center'>%s</td>", $matriz_compras [$j][4]);//fecha
		printf("<td align='right'>%s</td>", $matriz_compras [$j][2]);//nro. factura
		printf("<td align='right'>%s</td>", $matriz_compras [$j][8]);//ruc
		$texto = $matriz_compras [$j][7];//proveedor
		$texto = strtr(strtoupper($texto), "àáâãäåæçèéêëìíîïðñòóôõöøùüú", "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÜÚ");
		//$texto = substr($texto,0,150);
		printf("<td align='left'>%s</td>", $texto);//proveedor
		//$importe_10 = round($matriz_compras [$j][12] / 1.1,$n_decimales);
		//$iva_10 = round($matriz_compras [$j][12] / 11,$n_decimales);
		//$importe_5 = round(0,$n_decimales);
		//$iva_5 = round($importe_5 * 0.05,$n_decimales);
		$importe_10 = round($matriz_compras [$j][12] - $matriz_compras [$j][13],$n_decimales176);	
		$iva_10 = round($matriz_compras [$j][13],$n_decimales176);	
		$importe_5 = round($matriz_compras [$j][20] - $matriz_compras [$j][21],$n_decimales176);	
		$iva_5 = round($matriz_compras [$j][21],$n_decimales176);	
		$exento = round($matriz_compras [$j][11],$n_decimales176);
		$total_final = $importe_10 + $iva_10 + $importe_5 + $iva_5 + $exento;
		$base_imp = 0;
		
		printf("<td align='right'>%s</td>", number_format($importe_10,$n_decimales176));//gravadas 10
		printf("<td align='right'>%s</td>", number_format($iva_10,$n_decimales176));//iva 10
		printf("<td align='right'>%s</td>", number_format($importe_5,$n_decimales176));//gravadas 5
		printf("<td align='right'>%s</td>", number_format($iva_5,$n_decimales176));//iva 5
		printf("<td align='right'>%s</td>", number_format($exento,$n_decimales176));//exento
		printf("<td align='right'>%s</td>", number_format($total_final,$n_decimales176));//total final
		printf("<td align='right'>%s</td>", number_format($base_imp,$n_decimales176));//base imponible importaciones
		printf("<td align='center'>%s</td>", 'CO');//co, cr
		
		$glosa2 = $matriz_compras [$j][14];
		$glosa2 = nl2br($glosa2);//quita salto de linea 
		$glosa2 = str_replace('\n','<br />',$glosa2);//reemplaza para salto de linea
		printf("<td>%s</td>", $glosa2);//glosa
		//$tabla_genera = $matriz_compras [$j][15];
		//$codigo_genera = $matriz_compras [$j][16];
		//$tabla_genera2 = substr($tabla_genera, 9); //quito la primera parte de la cadena
		printf("<td align='right'>%s</td></tr>", $matriz_compras [$j][19]);//generado por
		
		$total_imp_10 = $total_imp_10 + $importe_10;
		$total_iva_10 = $total_iva_10 + $iva_10;
		$total_imp_5 = $total_imp_5 + $importe_5;
		$total_iva_5 = $total_iva_5 + $iva_5;
		$total_ex = $total_ex + $exento;
		$total_tot = $total_tot + $total_final;
		$total_bas = $total_bas + $base_imp;
		
		if($matriz_compras [$j][22] == 1) { //if dir
		$total_dir_10 = $total_dir_10 + $importe_10;
		$total_dir_iva_10 = $total_dir_iva_10 + $iva_10;
		$total_dir_5 = $total_dir_5 + $importe_5;
		$total_dir_iva_5 = $total_dir_iva_5 + $iva_5;
		$total_dir_ex = $total_dir_ex + $exento;
		$total_dir_tot = $total_dir_tot + $total_final;
		}//fin if dir
		
		if($matriz_compras [$j][22] == 2) { //if indir
		$total_indir_10 = $total_indir_10 + $importe_10;
		$total_indir_iva_10 = $total_indir_iva_10 + $iva_10;
		$total_indir_5 = $total_indir_5 + $importe_5;
		$total_indir_iva_5 = $total_indir_iva_5 + $iva_5;
		$total_indir_ex = $total_indir_ex + $exento;
		$total_indir_tot = $total_indir_tot + $total_final;
		}//fin if indir
		
		if($matriz_compras [$j][22] == 3) { //if exe
		$total_exe_10 = $total_exe_10 + $importe_10;
		$total_exe_iva_10 = $total_exe_iva_10 + $iva_10;
		$total_exe_5 = $total_exe_5 + $importe_5;
		$total_exe_iva_5 = $total_exe_iva_5 + $iva_5;
		$total_exe_ex = $total_exe_ex + $exento;
		$total_exe_tot = $total_exe_tot + $total_final;
		}//fin if exe
		
		if($matriz_compras [$j][22] == 1 || $matriz_compras [$j][22] == 2 || $matriz_compras [$j][22] == 3) { //if gen3
		$total_gen3_10 = $total_gen3_10 + $importe_10;
		$total_gen3_iva_10 = $total_gen3_iva_10 + $iva_10;
		$total_gen3_5 = $total_gen3_5 + $importe_5;
		$total_gen3_iva_5 = $total_gen3_iva_5 + $iva_5;
		$total_gen3_ex = $total_gen3_ex + $exento;
		$total_gen3_tot = $total_gen3_tot + $total_final;
		}//fin if gen3
		
		if($matriz_compras [$j][22] == 0) { //if cred
		$total_cred_10 = $total_cred_10 + $importe_10;
		$total_cred_iva_10 = $total_cred_iva_10 + $iva_10;
		$total_cred_5 = $total_cred_5 + $importe_5;
		$total_cred_iva_5 = $total_cred_iva_5 + $iva_5;
		$total_cred_ex = $total_cred_ex + $exento;
		$total_cred_tot = $total_cred_tot + $total_final;
		}//fin if cred

		$nu++;
		$color++;
		$j++;
	
		} //fin while
	?>
	
	<tr BGCOLOR='#ffcccc'><td colspan="5"><b>TOTAL</b></td>
	<td align="right"><?php printf("<b>%s</b>", number_format($total_imp_10,$n_decimales176)); ?></td>
	<td align="right"><?php printf("<b>%s</b>", number_format($total_iva_10,$n_decimales176)); ?></td>
	<td align="right"><?php printf("<b>%s</b>", number_format($total_imp_5,$n_decimales176)); ?></td>
	<td align="right"><?php printf("<b>%s</b>", number_format($total_iva_5,$n_decimales176)); ?></td>
	<td align="right"><?php printf("<b>%s</b>", number_format($total_ex,$n_decimales176)); ?></td>
	<td align="right"><?php printf("<b>%s</b>", number_format($total_tot,$n_decimales176)); ?></td>
	<td align="right"><?php printf("<b>%s</b>", number_format($total_bas,$n_decimales176)); ?></td>
	<td>&nbsp;</td>
	<td>&nbsp;</td>
	<td>&nbsp;</td>
	</tr>

	<tr><td align="center" colspan="15"><b>TOTAL COMPRAS BRUTAS</b></td>
	</tr>
	<tr BGCOLOR='#ffcccc'><td colspan="5"><b>TOTAL IVA DIRECTO: </b></td>
	<td align="right"><?php printf("<b>%s</b>", number_format($total_dir_10,$n_decimales176)); ?></td>
	<td align="right"><?php printf("<b>%s</b>", number_format($total_dir_iva_10,$n_decimales176)); ?></td>
	<td align="right"><?php printf("<b>%s</b>", number_format($total_dir_5,$n_decimales176)); ?></td>
	<td align="right"><?php printf("<b>%s</b>", number_format($total_dir_iva_5,$n_decimales176)); ?></td>
	<td align="right"><?php printf("<b>%s</b>", number_format($total_dir_ex,$n_decimales176)); ?></td>
	<td align="right"><?php printf("<b>%s</b>", number_format($total_dir_tot,$n_decimales176)); ?></td>
	<td>&nbsp;</td>
	<td>&nbsp;</td>
	<td>&nbsp;</td>
	<td>&nbsp;</td>
	</tr>
	<tr BGCOLOR='#ffcccc'><td colspan="5"><b>TOTAL IVA INDIRECTO: </b></td>
	<td align="right"><?php printf("<b>%s</b>", number_format($total_indir_10,$n_decimales176)); ?></td>
	<td align="right"><?php printf("<b>%s</b>", number_format($total_indir_iva_10,$n_decimales176)); ?></td>
	<td align="right"><?php printf("<b>%s</b>", number_format($total_indir_5,$n_decimales176)); ?></td>
	<td align="right"><?php printf("<b>%s</b>", number_format($total_indir_iva_5,$n_decimales176)); ?></td>
	<td align="right"><?php printf("<b>%s</b>", number_format($total_indir_ex,$n_decimales176)); ?></td>
	<td align="right"><?php printf("<b>%s</b>", number_format($total_indir_tot,$n_decimales176)); ?></td>
	<td>&nbsp;</td>
	<td>&nbsp;</td>
	<td>&nbsp;</td>
	<td>&nbsp;</td>
	</tr>
	<tr BGCOLOR='#ffcccc'><td colspan="5"><b>TOTAL COMPRAS EXENTAS: </b></td>
	<td align="right"><?php printf("<b>%s</b>", number_format($total_exe_10,$n_decimales176)); ?></td>
	<td align="right"><?php printf("<b>%s</b>", number_format($total_exe_iva_10,$n_decimales176)); ?></td>
	<td align="right"><?php printf("<b>%s</b>", number_format($total_exe_5,$n_decimales176)); ?></td>
	<td align="right"><?php printf("<b>%s</b>", number_format($total_exe_iva_5,$n_decimales176)); ?></td>
	<td align="right"><?php printf("<b>%s</b>", number_format($total_exe_ex,$n_decimales176)); ?></td>
	<td align="right"><?php printf("<b>%s</b>", number_format($total_exe_tot,$n_decimales176)); ?></td>
	<td>&nbsp;</td>
	<td>&nbsp;</td>
	<td>&nbsp;</td>
	<td>&nbsp;</td>
	</tr>
	<tr BGCOLOR='#ffcccc'><td colspan="5"><b>TOTAL GENERAL: </b></td>
	<td align="right"><?php printf("<b>%s</b>", number_format($total_gen3_10,$n_decimales176)); ?></td>
	<td align="right"><?php printf("<b>%s</b>", number_format($total_gen3_iva_10,$n_decimales176)); ?></td>
	<td align="right"><?php printf("<b>%s</b>", number_format($total_gen3_5,$n_decimales176)); ?></td>
	<td align="right"><?php printf("<b>%s</b>", number_format($total_gen3_iva_5,$n_decimales176)); ?></td>
	<td align="right"><?php printf("<b>%s</b>", number_format($total_gen3_ex,$n_decimales176)); ?></td>
	<td align="right"><?php printf("<b>%s</b>", number_format($total_gen3_tot,$n_decimales176)); ?></td>
	<td>&nbsp;</td>
	<td>&nbsp;</td>
	<td>&nbsp;</td>
	<td>&nbsp;</td>
	</tr>
	<tr><td align="center" colspan="15"><b>TOTAL NOTAS DE CR&Eacute;DITO</b></td>
	</tr>
	<tr BGCOLOR='#ffcccc'><td colspan="5"><b>NOTAS DE CR&Eacute;DITO: </b></td>
	<td align="right"><?php printf("<b>%s</b>", number_format($total_cred_10*-1,$n_decimales176)); ?></td>
	<td align="right"><?php printf("<b>%s</b>", number_format($total_cred_iva_10*-1,$n_decimales176)); ?></td>
	<td align="right"><?php printf("<b>%s</b>", number_format($total_cred_5*-1,$n_decimales176)); ?></td>
	<td align="right"><?php printf("<b>%s</b>", number_format($total_cred_iva_5*-1,$n_decimales176)); ?></td>
	<td align="right"><?php printf("<b>%s</b>", number_format($total_cred_ex*-1,$n_decimales176)); ?></td>
	<td align="right"><?php printf("<b>%s</b>", number_format($total_cred_tot*-1,$n_decimales176)); ?></td>
	<td>&nbsp;</td>
	<td>&nbsp;</td>
	<td>&nbsp;</td>
	<td>&nbsp;</td>
	</tr>
	<tr BGCOLOR='#ffcccc'><td colspan="5"><b>TOTAL GENERAL: </b></td>
	<td align="right"><?php printf("<b>%s</b>", number_format($total_cred_10*-1,$n_decimales176)); ?></td>
	<td align="right"><?php printf("<b>%s</b>", number_format($total_cred_iva_10*-1,$n_decimales176)); ?></td>
	<td align="right"><?php printf("<b>%s</b>", number_format($total_cred_5*-1,$n_decimales176)); ?></td>
	<td align="right"><?php printf("<b>%s</b>", number_format($total_cred_iva_5*-1,$n_decimales176)); ?></td>
	<td align="right"><?php printf("<b>%s</b>", number_format($total_cred_ex*-1,$n_decimales176)); ?></td>
	<td align="right"><?php printf("<b>%s</b>", number_format($total_cred_tot*-1,$n_decimales176)); ?></td>
	<td>&nbsp;</td>
	<td>&nbsp;</td>
	<td>&nbsp;</td>
	<td>&nbsp;</td>
	</tr>

	</tbody>
	</table>

	<?php	
	}// fin if mostrar 1

	} //fin if 2

} //fin if paraguay
?>

</body>
</html>
