<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Pantalla Reporte Libro de Compras</title>
<?php
include "../../conn.php";
include "../../general.php";

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

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

?>
<?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 = 33;

//responsable
$result2 = mysqli_query($link, "select a.codPerson as cod_persona, concat(b.fldFirstName,' ', b.fldLastName) 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['proveedor'];
	}
	mysqli_free_result($resultprov);
} //fin if proveedor

//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;");
*/

$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.tabla_genera as tabla_genera, t.cod_genera as cod_genera, t.glosa as glosa
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.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

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, a.fldParentComponent as tabla_genera, a.cosComponentKey as cod_genera, a.txtDescription as glosa 
from 
pchImportDocument a 
where 
$valor_proveedor 
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, a.fldParentComponent as tabla_genera, a.cosComponentKey as cod_genera, a.txtDescription as glosa 
from 
txsTicket a 
where 
$valor_proveedor
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] = $row['total_bruto'];
	$matriz_compras [$i][10] = $row['ice'];
	$matriz_compras [$i][11] = $row['excento'];
	$matriz_compras [$i][12] = $row['total_neto'];
	$matriz_compras [$i][13] = $row['credito'];
	$matriz_compras [$i][14] = $row['glosa'];
	$matriz_compras [$i][15] = $row['tabla_genera'];
	$matriz_compras [$i][16] = $row['cod_genera'];
	//$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
	$i++;
}
$fin = $i - 1;
mysqli_free_result($result);


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

$total_fac_par = 0;
$total_ice_par = 0;
$total_exe_par = 0;
$total_neto_par = 0;
$total_cred_par = 0;

$total_fac = 0;
$total_ice = 0;
$total_exe = 0;
$total_neto = 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;
for($i = 1; $i <= $var; $i++) {//for
?>
<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>
<br />

<table border="1" align="center" cellpadding="2" width="990" height="600">
    <TR> 
    <TD align="center" width="55" style='border-bottom: solid 1px'><b>Fecha</b></TD>
    <TD align="center" width="55" style='border-bottom: solid 1px'><b>NIT</b></TD>
    <TD align="center" width="440" style='border-bottom: solid 1px'><b>Nombre o Raz&oacute;n Social del Proveedor</b></TD>
    <TD align="center" width="40" style='border-bottom: solid 1px'><b>Nro. Factura</b></TD>
    <TD align="center" width="65" style='border-bottom: solid 1px'><b>Nro. Autorizaci&oacute;n</b></TD>
    <TD align="center" width="80" style='border-bottom: solid 1px'><b>Cod. Control</b></TD>
    <TD align="center" width="55" style='border-bottom: solid 1px'><b>Total Factura</b></TD>
    <TD align="center" width="45" style='border-bottom: solid 1px'><b>Total ICE</b></TD>
    <TD align="center" width="45" style='border-bottom: solid 1px'><b>Importe Excento</b></TD>
    <TD align="center" width="55" style='border-bottom: solid 1px'><b>Importe Neto</b></TD>
    <TD align="center" width="55" style='border-bottom: solid 1px'><b>Cred. Fiscal IVA</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>", $matriz_compras [$j][4]);//fecha
		} else { 
		printf("<tr BGCOLOR='#e2e7fa'><td align='center'>&nbsp;</td>");//fecha vacia
		}
	} else {
		if($matriz_compras [$j][4] != NULL) {
		printf("<tr><td align='center'>%s</td>", $matriz_compras [$j][4]);//fecha
		} else { 
		printf("<tr><td align='center'>&nbsp;</td>");//fecha vacia
		}
	}//fin if color
  }//fin filas
	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,100);
	printf("<td align='left'>%s</td>", $texto);//proveedor
	printf("<td align='right'>%s</td>", $matriz_compras [$j][2]);//nro. factura
	printf("<td align='right'>%s</td>", $matriz_compras [$j][3]);//nro. auto
	printf("<td align='right'>%s</td>", $matriz_compras [$j][5]);//cod control
	if($matriz_compras [$j][9] == 0) {//if si es 0
	printf("<td align='right'>%s</td>", NULL);//total factura
	printf("<td align='right'>%s</td>", NULL);//ice
	printf("<td align='right'>%s</td>", NULL);//excento
	printf("<td align='right'>%s</td>", NULL);//total neto
	printf("<td align='right'>%s</td></tr>", NULL);//credito fiscal IVA
	} else { //else si es 0
	printf("<td align='right'>%s</td>", number_format($matriz_compras [$j][9],$n_decimales));//total factura
	printf("<td align='right'>%s</td>", number_format($matriz_compras [$j][10],$n_decimales));//ice
	printf("<td align='right'>%s</td>", number_format($matriz_compras [$j][11],$n_decimales));//excento
	printf("<td align='right'>%s</td>", number_format($matriz_compras [$j][12],$n_decimales));//total neto
	printf("<td align='right'>%s</td></tr>", number_format($matriz_compras [$j][13],$n_decimales));//credito fiscal IVA
	}//fin if si es 0
	
	if($numero_filas == 0 && $j == 14) {
		printf("<tr><td>&nbsp;</td><td>&nbsp;</td><td align='right' colspan='5'><font size='16'><b>SIN MOVIMIENTO</b></font></td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>");
	}
	
	$total_fac_par = $total_fac_par + $matriz_compras [$j][9];
	$total_ice_par = $total_ice_par + $matriz_compras [$j][10];
	$total_exe_par = $total_exe_par + $matriz_compras [$j][11];
	$total_neto_par = $total_neto_par + $matriz_compras [$j][12];
	$total_cred_par = $total_cred_par + $matriz_compras [$j][13];
	
	$total_fac = $total_fac + $matriz_compras [$j][9];
	$total_ice = $total_ice + $matriz_compras [$j][10];
	$total_exe = $total_exe + $matriz_compras [$j][11];
	$total_neto = $total_neto + $matriz_compras [$j][12];
	$total_cred = $total_cred + $matriz_compras [$j][13];
	$color++;
	$j++;
	$q++;
  }//fin while


?>

<tr>
	<td colspan="4" 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_fac_par,$n_decimales); ?></td>
    <td align="right" style='border-top: solid 1px'><b><?php echo number_format($total_ice_par,$n_decimales); ?></td>
    <td align="right" style='border-top: solid 1px'><b><?php echo number_format($total_exe_par,$n_decimales); ?></td>
    <td align="right" style='border-top: solid 1px'><b><?php echo number_format($total_neto_par,$n_decimales); ?></td>
    <td align="right" style='border-top: solid 1px'><b><?php echo number_format($total_cred_par,$n_decimales); ?></td>
</tr>
<tr>
	<td colspan="4" 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_fac,$n_decimales); ?></td>
    <td align="right"><b><?php echo number_format($total_ice,$n_decimales); ?></td>
    <td align="right"><b><?php echo number_format($total_exe,$n_decimales); ?></td>
    <td align="right"><b><?php echo number_format($total_neto,$n_decimales); ?></td>
    <td align="right"><b><?php echo number_format($total_cred,$n_decimales); ?></td>
</tr>
</table>

<?php
$total_fac_par = 0;
$total_ice_par = 0;
$total_exe_par = 0;
$total_neto_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><b>Empresa: <?php echo $nombre_empresa; ?><br/>NIT: <?php echo $mi_nit; ?></b>
</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><br/>
<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="25%"><b>Proveedor: </b><?php echo $nom_proveedor; ?></TD>
        <TD width="25%"><b>Sucursal: </b><?php echo $sucursal; ?></TD>
        <TD width="25%"><b>De Fecha: </b><?php echo $fechaini; ?> <b>a Fecha: </b><?php echo $fechafin; ?></TD>
        <TD width="25%"><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; ?>" 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" width="65"><b>Fecha</b></TD>
    <TD align="center"><b>NIT</b></TD>
    <TD align="center"><b>Nombre o Raz&oacute;n Social del Proveedor</b></TD>
    <TD align="center"><b>Nro. Factura</b></TD>
    <TD align="center"><b>Nro. Autorizaci&oacute;n</b></TD>
    <TD align="center" width="90"><b>Cod. Control</b></TD>
    <TD align="center"><b>Total Factura</b></TD>
    <TD align="center"><b>Total ICE</b></TD>
    <TD align="center"><b>Importe Excento</b></TD>
    <TD align="center"><b>Importe Neto</b></TD>
    <TD align="center"><b>Cred. Fiscal IVA</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;
$total_fac = 0;
$total_ice = 0;
$total_exe = 0;
$total_neto = 0;
$total_cred = 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>", $matriz_compras [$j][4]);//fecha
	} else {
	printf("<tr><td align='center'>%s</td>", $matriz_compras [$j][4]);//fecha
	}//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,50);
	printf("<td align='left'>%s</td>", $texto);//proveedor
	printf("<td align='right'>%s</td>", $matriz_compras [$j][2]);//nro. factura
	printf("<td align='right'>%s</td>", $matriz_compras [$j][3]);//nro. auto
	printf("<td align='right'>%s</td>", $matriz_compras [$j][5]);//cod control
	if($matriz_compras [$j][9] == 0) {//if si es 0
	printf("<td align='right'>%s</td>", NULL);//total factura
	printf("<td align='right'>%s</td>", NULL);//ice
	printf("<td align='right'>%s</td>", NULL);//excento
	printf("<td align='right'>%s</td>", NULL);//total neto
	printf("<td align='right'>%s</td>", NULL);//credito fiscal IVA
	} else { //else si es 0
	printf("<td align='right'>%s</td>", number_format($matriz_compras [$j][9],$n_decimales));//total factura
	printf("<td align='right'>%s</td>", number_format($matriz_compras [$j][10],$n_decimales));//ice
	printf("<td align='right'>%s</td>", number_format($matriz_compras [$j][11],$n_decimales));//excento
	printf("<td align='right'>%s</td>", number_format($matriz_compras [$j][12],$n_decimales));//total neto
	printf("<td align='right'>%s</td>", number_format($matriz_compras [$j][13],$n_decimales));//credito fiscal IVA
	}//fin if si es 0
	
	$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
	if($tabla_genera == $matriz_tabla [1][1]) { //if 1
	printf("<td align='right'><a href='../../ModulePayments/VoucherAccountsPayable/index.php?pkyAccountsPayable=$codigo_genera&user=$usuario' title='Nota de Cuenta por Pagar'>%s</a></td></tr>", $codigo_genera);//generado por cxp
	} else { //else if 1
	
		if($tabla_genera == $matriz_tabla [2][1]) { //if 2
		printf("<td align='right'><a href='../../ModuleAccounting/VoucherAccountEntry/index.php?pkyAccountEntry=$codigo_genera&showCC=$mostrar_asiento_cc&user=$usuario' title='Asiento Contable'>%s</a></td></tr>", $codigo_genera);//generado por asiento contable
		} else { //else if 2
	
			if($tabla_genera == $matriz_tabla [3][1]) { //if 3
			printf("<td align='right'><a href='../../ModulePurchases/VoucherPayrollExpenses/index.php?pkyPayrollExpenses=$codigo_genera&user=$usuario' title='Planilla de Gastos'>%s</a></td></tr>", $codigo_genera);//generado por Planilla de Gastos
			} else { //else if 3
	
				if($tabla_genera == $matriz_tabla [4][1]) { //if 4
				printf("<td align='right'><a href='../../ModulePurchases/VoucherPurchaseOrder/index.php?pkyPurchaseOrder=$codigo_genera&user=$usuario' title='Nota de Orden de Compra'>%s</a></td></tr>", $codigo_genera);//generado por orden de compra
				} else { //else if 4
	
					if($tabla_genera == $matriz_tabla [5][1]) { //if 5
					printf("<td align='right'><a href='../../ModulePurchases/VoucherReceiptOfGoods/index.php?pkyReceiptOfGoods=$codigo_genera&user=$usuario' title='Nota Recepci&oacute;n de Mercader&iacute;a'>%s</a></td></tr>", $codigo_genera);//generado por orden de compra
					} else { //else if 5
						printf("<td align='right'>%s</td></tr>", NULL);
					} //fin if 5
				} //fin if 4
			} //fin if 3
		} //fin if 2
	} //fin if 1
	
			
	$total_fac = $total_fac + $matriz_compras [$j][9];
	$total_ice = $total_ice + $matriz_compras [$j][10];
	$total_exe = $total_exe + $matriz_compras [$j][11];
	$total_neto = $total_neto + $matriz_compras [$j][12];
	$total_cred = $total_cred + $matriz_compras [$j][13];
	$color++;
	$j++;
  
	} //fin while
?>
 
<tr BGCOLOR='#ffcccc'><td colspan="6"><b>Total</b></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_fac,$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_neto,$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 1

} //fin if 2
?>

</body>
</html>
