<!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 Bancarizaci&oacute;n</title>
<link href="../../maincss.css" rel="stylesheet" type="text/css" />
<link href="../../printcss.css" rel="stylesheet" type="text/css" media="print" />
</head>

<?php
include "../../conn.php";
include "../../general.php";

$rep=$_GET["rep"];
$tipo=$_GET["tipo"];
$mostrar=$_POST["mostrar"];
$fechaini=$_POST["fechaini"];
$fechafin=$_POST["fechafin"];

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


?>
<body>
<?php


//Inicio reporte Compras bancarizacion

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

//compras
if($mostrar == 0) { //if mostrar 0

$nom_mostrar = 'Compras';

//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.fldName as proveedor, a.fldNIT as nit, a.fldGrossTotal as total_bruto, 
a.fldNetTotal as total_neto, a.fldParentComponent as papa, 
a.cosComponentKey as cod_papa, c.pkyPayment as cod_pago, 
b.pkyPaymentDetail as cod_pago_det, c.codRoute as cod_tipo_pago, c.codCurrency as cod_moneda, b.fldTotal as monto_pago, c.fldDate as fecha_pago, c.codBankMovement as cod_mov_banco, c.codCheck as cod_cheque
from
txsPurchasesLedger a inner join payPaymentDetail b on 
a.cosComponentKey = b.codAccountsPayable, payPayment c 
where 
a.fldNetTotal >= 50000 and 
c.pkyPayment = b.codPayment and 
((a.fldDate >= '$fechaini' and a.fldDate <= '$fechafin') or
(c.fldDate >= '$fechaini' and c.fldDate <= '$fechafin')) and 
c.fldDate >= '$fechaini' and c.fldDate <= '$fechafin' and 
a.sysEnabled = 1 AND a.sysAuthorized = 1 and 
c.sysEnabled = 1 AND c.sysAuthorized = 1
order by fecha, proveedor, nro_auto;");

/*
select a.pkyPurchasesLedger as codigo, a.fldNumber as nro_fac,
a.fldAuthorization as nro_auto, a.fldDate as fecha, 
a.fldName as proveedor, a.fldNIT as nit, a.fldGrossTotal as total_bruto, 
a.fldNetTotal as total_neto, a.fldParentComponent as papa, 
a.cosComponentKey as cod_papa, c.pkyPayment as cod_pago, 
b.pkyPaymentDetail as cod_pago_det, c.codRoute as cod_tipo_pago, c.codCurrency as cod_moneda, b.fldTotal as monto_pago, c.fldDate as fecha_pago
from
txsPurchasesLedger a inner join payPaymentDetail b on 
a.cosComponentKey = b.codAccountsPayable, payPayment c 
where 
a.fldNetTotal >= 50000 and 
c.pkyPayment = b.codPayment and 
((a.fldDate >= '2016-10-06' and a.fldDate <= '2016-10-06') or
(c.fldDate >= '2016-10-06' and c.fldDate <= '2016-10-06')) and 
a.sysEnabled = 1 AND a.sysAuthorized = 1 and 
c.sysEnabled = 1 AND c.sysAuthorized = 1
*/

$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['proveedor'];
	$matriz_compras [$i][6] = $row['nit'];
	$matriz_compras [$i][7] = round($row['total_bruto'],$n_decimales);
	$matriz_compras [$i][8] = round($row['total_neto'],$n_decimales);
	$matriz_compras [$i][9] = $row['papa'];
	$matriz_compras [$i][10] = $row['cod_papa'];
	$matriz_compras [$i][11] = $row['papa'];
	$matriz_compras [$i][12] = $row['cod_pago'];
	$matriz_compras [$i][13] = $row['cod_pago_det'];
	$matriz_compras [$i][14] = $row['cod_tipo_pago'];
	$matriz_compras [$i][15] = $row['cod_moneda'];
	$matriz_compras [$i][16] = round($row['monto_pago'],$n_decimales);;
	$matriz_compras [$i][17] = $row['fecha_pago'];
	$matriz_compras [$i][18] = 1; //compras: factura = 1, retenciones = 2, inmuebles = 3
	$matriz_compras [$i][19] = 0; //nro doc para retenciones = 2 e inmuebles = 3
	$matriz_compras [$i][20] = 0; //nro contrato
	$matriz_compras [$i][21] = $row['cod_mov_banco'];
	$matriz_compras [$i][22] = $row['cod_cheque'];
	
	$matriz_compras [$i][23] = 0; //nro cta banco pago
	$matriz_compras [$i][24] = 0; //monto acumulado pago
	$matriz_compras [$i][25] = 0; //nit banco pago
	$matriz_compras [$i][26] = 0; //nro doc pago (cheque o transf)
	$matriz_compras [$i][27] = 10; //tipo doc pago  1 - 10
	/*
	1 cheque de cualquier naturaleza
	2 orden de transferencia
	3 Ordenes de transferencia electronica de fondos
	4 transferencia de fondos
	5 tarjeta de débito
	6 tarjeta de credito
	7 tarjeta prepagada
	8 deposito en cuenta
	9 cartas de credito
	10 otros */
		
	//para enlazar al que genero el asiento
	$papa_componente = $matriz_compras [$i][11];
	$papa_codigo = $matriz_compras [$i][10];
	//$usuario = $usuario_det;
	include "../../generadopor.php";
	$matriz_compras [$i][28] = $papa_enlace;
	
	if($matriz_compras [$i][21] != NULL) { //if 1
		$cod_mov_banco = $matriz_compras [$i][21];
		$resultcta = mysqli_query($link, "select b.fldNumber as cuenta, d.fldNIT as nit_banco 
				from tryBankMovement a, tryBankDetail b, tryBank c, agnCompany d
				where 
				a.codBankAccount = b.pkyBankDetail and 
				a.codBank = c.pkyBank and 
				c.codCompany = d.pkyCompany and 
				a.pkyBankMovement = '$cod_mov_banco';");
		while ($row = mysqli_fetch_array($resultcta)) {
			$cuenta = $row['cuenta'];
			//dejar solo numeros
			$matriz_compras [$i][23] = intval(preg_replace('/[^0-9]+/', '', $cuenta), 10); //nro cta banco pago 
			$matriz_compras [$i][25] = $row['nit_banco']; //nit banco pago
		}
		mysqli_free_result($resultcta);
		$matriz_compras [$i][26] = 0; //nro doc pago transf
		$matriz_compras [$i][27] = 2; //tipo doc pago  1 - 10 (2 transf)
	}// fin if 1
	
	
	$cod_cxp = $matriz_compras [$i][10];
	$fecha_pago = $matriz_compras [$i][17];
	$resultacum = mysqli_query($link, "select sum(a.fldTotal) as pagos_acumulados
	from payPaymentDetail a, payPayment b
	where 
	a.codPayment = b.pkyPayment and 
	a.codAccountsPayable = '$cod_cxp' and 
	b.fldDate <= '$fecha_pago' and 
	b.sysEnabled = 1 and b.sysAuthorized = 1;");
	while ($row = mysqli_fetch_array($resultacum)) {
		$matriz_compras [$i][24] = $row['pagos_acumulados']; //monto acumulado pago
	}
	mysqli_free_result($resultacum);
	
	if($matriz_compras [$i][22] != NULL) { //if 2
		$cod_cheque = $matriz_compras [$i][22];
		$resultche = mysqli_query($link, "select b.fldNumber as cuenta, d.fldNIT as nit_banco, a.fldNumber as numero 
				from tryCheck a, tryBankDetail b, tryBank c, agnCompany d
				where 
				a.codLocalAccount = b.pkyBankDetail and 
				a.codBank = c.pkyBank and 
				c.codCompany = d.pkyCompany and 
				a.pkyCheck = '$cod_cheque';");
		while ($row = mysqli_fetch_array($resultche)) {
			$cuenta = $row['cuenta'];
			//dejar solo numeros
			$matriz_compras [$i][23] = intval(preg_replace('/[^0-9]+/', '', $cuenta), 10); //nro cta banco cobro 
			$matriz_compras [$i][25] = $row['nit_banco']; //nit banco cobro
			$matriz_compras [$i][26] = $row['numero']; //nro doc cobro cheque
		}
		mysqli_free_result($resultche);
		$matriz_compras [$i][27] = 1; //tipo doc pago  1 - 10 (1 cheque)
	}// fin if 2
	
	
	//esto es provisional borrar despues
	if($matriz_compras [$i][16] > $matriz_compras [$i][8]) {
		$matriz_compras [$i][16] = $matriz_compras [$i][8];
		$matriz_compras [$i][24] = $matriz_compras [$i][8];
	}
	
	$i++;
}
$fin = $i - 1;
mysqli_free_result($result);


?>
<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>Bancarizaci&oacute;n 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>Mostrar: </b><?php echo $nom_mostrar; ?></TD>
        <TD width="33%"><b>De Fecha: </b><?php echo $fechaini; ?> <b>a Fecha: </b><?php echo $fechafin; ?></TD>
        <TD width="33%"><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"><b>Modalidad Transacci&oacute;n</b></TD>
    <TD align="center" width="65"><b>Fecha de la Factura</b></TD>
    <TD align="center"><b>Tipo Transacci&oacute;n</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. Contrato</b></TD>
    <TD align="center"><b>Importe total de la compra</b></TD>
    <TD align="center"><b>Nro. Autorizaci&oacute;n</b></TD>
    <TD align="center"><b>Nro. Cta. Banco Pago</b></TD>
    <TD align="center"><b>Monto Pago</b></TD>
    <TD align="center"><b>Monto Pagos Acumulados</b></TD>
    <TD align="center"><b>NIT Banco Pago</b></TD>
    <TD align="center"><b>Nro. Doc. Pago (Cheque o Transf.)</b></TD>
    <TD align="center"><b>Tipo Doc. Pago</b></TD>
    <TD align="center"><b>Fecha Doc. Pago</b></TD>
    <TD align="center"><b>Gen. Por</b></TD>
    </TR>
    </thead>
    <tbody class="marcafila">

<?php
$color = 2;
$j = 1;
$mt = 2; //contado = 1, credito = 2
$total_comp = 0;
$total_pagos = 0;


	while ($j <= $fin) { //while
	   
    if($color % 2 == 0) { //if color
	printf("<tr BGCOLOR='#e2e7fa'><td align='center'>%s</td>", $mt);//mod. trans.
	} else {
	printf("<tr><td align='center'>%s</td>", $mt);//mod. trans.
	}//fin if color
    
	printf("<td align='center'>%s</td>", $matriz_compras [$j][4]);//fecha
	printf("<td align='right'>%s</td>", $matriz_compras [$j][18]);//tipo trans.
	printf("<td align='right'>%s</td>", $matriz_compras [$j][6]);//nit
	$texto = $matriz_compras [$j][5];//proveedor
	$texto = strtr(strtoupper($texto), "àáâãäåæçèéêëìíîïðñòóôõöøùüú", "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÜÚ");
	//$texto = substr($texto,0,150);
	printf("<td align='left'>%s</td>", $texto);//proveedor
	if($matriz_compras [$j][18] == 1) {
		printf("<td align='right'>%s</td>", $matriz_compras [$j][2]);//nro. factura
	} else {
		printf("<td align='right'>%s</td>", $matriz_compras [$j][19]);//nro. doc.
	}
		
	printf("<td align='right'>%s</td>", $matriz_compras [$j][20]);//nro. contrato
	
	printf("<td align='right'>%s</td>", number_format($matriz_compras [$j][8],$n_decimales));//imp. total compra 
	if($matriz_compras [$j][18] == 1) {
	printf("<td align='right'>%s</td>", $matriz_compras [$j][3]);//nro. auto
	}
	if($matriz_compras [$j][18] == 2) {
	printf("<td align='right'>%s</td>", 4);//retencion
	}
	if($matriz_compras [$j][18] == 3) {
	printf("<td align='right'>%s</td>", $matriz_compras [$j][19]);//nro. doc
	}
	
	//pago
	printf("<td align='right'>%s</td>", $matriz_compras [$j][23]);// nro. cta. banco pago
	printf("<td align='right'>%s</td>", number_format($matriz_compras [$j][16],$n_decimales));//monto pago
	printf("<td align='right'>%s</td>", number_format($matriz_compras [$j][24],$n_decimales));//monto acumulado pago
	printf("<td align='right'>%s</td>", $matriz_compras [$j][25]);//nit banco pago
	printf("<td align='right'>%s</td>", $matriz_compras [$j][26]);//nro doc pago (cheque o transf)
	printf("<td align='right'>%s</td>", $matriz_compras [$j][27]);//tipo doc pago (1-10)
	printf("<td align='center'>%s</td>", $matriz_compras [$j][17]);//fecha pago 
	printf("<td align='center'>%s</td></tr>", $matriz_compras [$j][28]);//gen por
	
	$total_comp = $total_comp + round($matriz_compras [$j][8],$n_decimales);
	$total_pagos = $total_pagos + round($matriz_compras [$j][16],$n_decimales);

	$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>&nbsp;</td>
<td>&nbsp;</td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_pagos,$n_decimales)); ?></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</tbody>
</table>

<?php	
}// fin if mostrar 0


//ventas
if($mostrar == 1) { //if mostrar 1

$nom_mostrar = 'Ventas';

//listado de facturas ventas

$result = mysqli_query($link, "select a.pkySalesLedger as codigo, a.fldNumber as nro_fac,
a.fldAuthorization as nro_auto, a.fldDate as fecha, 
a.fldName as cliente, a.fldNIT as nit, a.fldGrossTotal as total_bruto, 
a.fldNetTotal as total_neto, a.cosComponentKey as cod_nv, a.fldParentComponent as papa, a.cosComponentKey as cod_papa, d.codAccountReceivable as cod_cxc, 
c.pkyCollection as cod_cobro, 
b.pkyCollectionDetail as cod_cobro_det, c.codRoute as cod_tipo_cobro, c.codCurrency as cod_moneda, b.fldTotal as monto_cobro, c.fldDate as fecha_cobro, c.codBankMovement as cod_mov_banco, c.codCheck as cod_cheque
from
txsSalesLedger a, slsSalesNote d inner join colCollectionDetail b on 
d.codAccountReceivable = b.codAccountsReceivable, colCollection c 
where 
a.fldNetTotal >= 50000 and 
a.cosComponentKey = d.pkySalesNote and 
c.pkyCollection = b.codCollection and 
((a.fldDate >= '$fechaini' and a.fldDate <= '$fechafin') or
(c.fldDate >= '$fechaini' and c.fldDate <= '$fechafin')) and 
c.fldDate >= '$fechaini' and c.fldDate <= '$fechafin' and 
a.sysEnabled = 1 AND a.sysAuthorized = 1 and 
c.sysEnabled = 1 AND c.sysAuthorized = 1 
order by fecha, nro_fac;");

$matriz_ventas = array();
$i = 1;
while ($row = mysqli_fetch_array($result)) {
	$matriz_ventas [$i][1] = $row['codigo'];
	$matriz_ventas [$i][2] = $row['nro_fac'];
	$matriz_ventas [$i][3] = $row['nro_auto'];
	$matriz_ventas [$i][4] = $row['fecha'];
	$matriz_ventas [$i][5] = $row['cliente'];
	$matriz_ventas [$i][6] = $row['nit'];
	$matriz_ventas [$i][7] = round($row['total_bruto'],$n_decimales);
	$matriz_ventas [$i][8] = round($row['total_neto'],$n_decimales);
	$matriz_ventas [$i][9] = $row['papa'];
	$matriz_ventas [$i][10] = $row['cod_papa'];
	$matriz_ventas [$i][11] = $row['papa'];
	$matriz_ventas [$i][12] = $row['cod_pago'];
	$matriz_ventas [$i][13] = $row['cod_pago_det'];
	$matriz_ventas [$i][14] = $row['cod_tipo_cobro'];
	$matriz_ventas [$i][15] = $row['cod_moneda'];
	$matriz_ventas [$i][16] = round($row['monto_cobro'],$n_decimales);;
	$matriz_ventas [$i][17] = $row['fecha_cobro'];
	$matriz_ventas [$i][18] = 1; //compras: factura = 1, retenciones = 2, inmuebles = 3
	$matriz_ventas [$i][19] = 0; //nro doc para retenciones = 2 e inmuebles = 3
	$matriz_ventas [$i][20] = 0; //nro contrato
	$matriz_ventas [$i][21] = $row['cod_mov_banco'];
	$matriz_ventas [$i][22] = $row['cod_cheque'];
	
	$matriz_ventas [$i][23] = $row['cod_cxc'];
	$matriz_ventas [$i][24] = 0; //nro cta banco cobro 
	$matriz_ventas [$i][25] = 0; //nit banco cobro
	$matriz_ventas [$i][26] = 0; //monto acumulado cobro
	$matriz_ventas [$i][27] = 0; //nro doc cobro transf
	
	
	//para enlazar al que genero el asiento
	$papa_componente = $matriz_ventas [$i][11];
	$papa_codigo = $matriz_ventas [$i][10];
	//$usuario = $usuario_det;
	include "../../generadopor.php";
	$matriz_ventas [$i][28] = $papa_enlace;
	
	$matriz_ventas [$i][29] = 10; //tipo doc cobro  1 - 10
	/*
	1 cheque de cualquier naturaleza
	2 orden de transferencia
	3 Ordenes de transferencia electronica de fondos
	4 transferencia de fondos
	5 tarjeta de débito
	6 tarjeta de credito
	7 tarjeta prepagada
	8 deposito en cuenta
	9 cartas de credito
	10 otros */
	
	if($matriz_ventas [$i][21] != NULL) { //if 1
		$cod_mov_banco = $matriz_ventas [$i][21];
		$resultcta = mysqli_query($link, "select b.fldNumber as cuenta, d.fldNIT as nit_banco 
				from tryBankMovement a, tryBankDetail b, tryBank c, agnCompany d
				where 
				a.codBankAccount = b.pkyBankDetail and 
				a.codBank = c.pkyBank and 
				c.codCompany = d.pkyCompany and 
				a.pkyBankMovement = '$cod_mov_banco';");
		while ($row = mysqli_fetch_array($resultcta)) {
			$cuenta = $row['cuenta'];
			//dejar solo numeros
			$matriz_ventas [$i][24] = intval(preg_replace('/[^0-9]+/', '', $cuenta), 10); //nro cta banco cobro 
			$matriz_ventas [$i][25] = $row['nit_banco']; //nit banco cobro
		}
		mysqli_free_result($resultcta);
		$matriz_ventas [$i][27] = 0; //nro doc cobro transf
		$matriz_ventas [$i][29] = 2; //tipo doc cobro  1 - 10 (2 transf)
	}// fin if 1
	
	
	$cod_cxc = $matriz_ventas [$i][23];
	$fecha_cobro = $matriz_ventas [$i][17];
	$resultacum = mysqli_query($link, "select sum(a.fldTotal) as cobros_acumulados
	from colCollectionDetail a, colCollection b
	where 
	a.codCollection = b.pkyCollection and 
	a.codAccountsReceivable = '$cod_cxc' and 
	b.fldDate <= '$fecha_cobro' and 
	b.sysEnabled = 1 and b.sysAuthorized = 1;");
	while ($row = mysqli_fetch_array($resultacum)) {
		$matriz_ventas [$i][26] = $row['cobros_acumulados']; //monto acumulado cobro
	}
	mysqli_free_result($resultacum);
	
	if($matriz_ventas [$i][22] != NULL) { //if 2
		$cod_cheque = $matriz_ventas [$i][22];
		$resultche = mysqli_query($link, "select b.fldNumber as cuenta, d.fldNIT as nit_banco, a.fldNumber as numero 
				from tryCheck a, tryBankDetail b, tryBank c, agnCompany d, tryCheckDepositDetail e, tryCheckDeposit f
				where 
				a.pkyCheck = e.codCheck and 
				e.codCheckDeposit = f.pkyCheckDeposit and 
				f.codBankAccount = b.pkyBankDetail and 
				a.codBank = c.pkyBank and 
				c.codCompany = d.pkyCompany and 
				a.pkyCheck = '$cod_cheque';");
		while ($row = mysqli_fetch_array($resultche)) {
			$cuenta = $row['cuenta'];
			//dejar solo numeros
			$matriz_ventas [$i][24] = intval(preg_replace('/[^0-9]+/', '', $cuenta), 10); //nro cta banco cobro 
			$matriz_ventas [$i][25] = $row['nit_banco']; //nit banco cobro
			$matriz_ventas [$i][27] = $row['numero']; //nro doc cobro cheque
		}
		mysqli_free_result($resultche);
		$matriz_ventas [$i][29] = 1; //tipo doc cobro  1 - 10 (1 cheque)
	}// fin if 2
	
	
	
	$i++;
}
$fin = $i - 1;
mysqli_free_result($result);


?>
<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>Bancarizaci&oacute;n Ventas</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>Mostrar: </b><?php echo $nom_mostrar; ?></TD>
        <TD width="33%"><b>De Fecha: </b><?php echo $fechaini; ?> <b>a Fecha: </b><?php echo $fechafin; ?></TD>
        <TD width="33%"><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"><b>Modalidad Transacci&oacute;n</b></TD>
    <TD align="center" width="65"><b>Fecha de la Factura</b></TD>
    <TD align="center"><b>Nro. Factura</b></TD>
    <TD align="center"><b>Importe total de la venta</b></TD>
    <TD align="center"><b>Nro. Contrato</b></TD>
    <TD align="center"><b>Nro. Autorizaci&oacute;n</b></TD>
    <TD align="center"><b>NIT Cliente</b></TD>
    <TD align="center"><b>Nombre o Raz&oacute;n Social</b></TD>
    <TD align="center"><b>Nro. Cta. Banco Cobro</b></TD>
    <TD align="center"><b>Monto Cobro</b></TD>
    <TD align="center"><b>Monto Cobros Acumulados</b></TD>
    <TD align="center"><b>NIT Banco Cobro</b></TD>
    <TD align="center"><b>Nro. Doc. Cobro (Cheque o Transf.)</b></TD>
    <TD align="center"><b>Tipo Doc. Cobro</b></TD>
    <TD align="center"><b>Fecha Doc. Cobro</b></TD>
    <TD align="center"><b>Gen. Por</b></TD>
    </TR>
    </thead>
    <tbody class="marcafila">

<?php
$color = 2;
$j = 1;
$mt = 2; //contado = 1, credito = 2
$total_ventas = 0;
$total_cobros = 0;


	while ($j <= $fin) { //while
	   
    if($color % 2 == 0) { //if color
	printf("<tr BGCOLOR='#e2e7fa'><td align='center'>%s</td>", $mt);//mod. trans.
	} else {
	printf("<tr><td align='center'>%s</td>", $mt);//mod. trans.
	}//fin if color
    
	printf("<td align='center'>%s</td>", $matriz_ventas [$j][4]);//fecha
	if($matriz_ventas [$j][18] == 1) {
		printf("<td align='right'>%s</td>", $matriz_ventas [$j][2]);//nro. factura
	} else {
		printf("<td align='right'>%s</td>", $matriz_ventas [$j][19]);//nro. doc.
	}
	printf("<td align='right'>%s</td>", number_format($matriz_ventas [$j][8],$n_decimales));//imp. total venta 
	printf("<td align='right'>%s</td>", $matriz_ventas [$j][20]);//nro. contrato
	if($matriz_ventas [$j][18] == 1) {
	printf("<td align='right'>%s</td>", $matriz_ventas [$j][3]);//nro. auto
	}
	if($matriz_ventas [$j][18] == 2) {
	printf("<td align='right'>%s</td>", 4);//retencion
	}
	if($matriz_ventas [$j][18] == 3) {
	printf("<td align='right'>%s</td>", $matriz_ventas [$j][19]);//nro. doc
	}
	printf("<td align='right'>%s</td>", $matriz_ventas [$j][6]);//nit
	$texto = $matriz_ventas [$j][5];//cliente
	$texto = strtr(strtoupper($texto), "àáâãäåæçèéêëìíîïðñòóôõöøùüú", "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÜÚ");
	//$texto = substr($texto,0,150);
	printf("<td align='left'>%s</td>", $texto);//cliente
	
	
	//cobro
	printf("<td align='right'>%s</td>", $matriz_ventas [$j][24]);// nro. cta. banco cobro
	printf("<td align='right'>%s</td>", number_format($matriz_ventas [$j][16],$n_decimales));//monto cobro
	printf("<td align='right'>%s</td>", number_format($matriz_ventas [$j][26],$n_decimales));//monto acumulado cobro
	printf("<td align='right'>%s</td>", $matriz_ventas [$j][25]);//nit banco cobro
	printf("<td align='right'>%s</td>", $matriz_ventas [$j][27]);//nro doc cobro (cheque o transf)
	printf("<td align='right'>%s</td>", $matriz_ventas [$j][29]);//tipo doc cobro (1-10)
	printf("<td align='center'>%s</td>", $matriz_ventas [$j][17]);//fecha cobro 
	printf("<td align='center'>%s</td></tr>", $matriz_ventas [$j][28]);//gen por
	
	$total_ventas = $total_ventas + round($matriz_ventas [$j][8],$n_decimales);
	$total_cobros = $total_cobros + round($matriz_ventas [$j][16],$n_decimales);

	$color++;
	$j++;
  
	} //fin while
?>
 
<tr BGCOLOR='#ffcccc'><td colspan="3"><b>Total</b></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_ventas,$n_decimales)); ?></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_cobros,$n_decimales)); ?></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</tbody>
</table>

<?php	
}// fin if mostrar 1

} //fin if 2


?>


</body>
</html>
