<!DOCTYPE html>
<html lang="es-ES">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Pantalla Reporte Pagos</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";
include "../../token.php";

$rep=$_GET["rep"];
$tipo=$_GET["tipo"];
$mostrar=$_POST["mostrar"];
$nombre=$_POST["nombre"];
$fechaini=$_POST["fechaini"];
$fechafin=$_POST["fechafin"];
$via_pago=$_POST["via_pago"];
$cod_contexto=$_POST["contexto"];
$otra_moneda=$_POST["otra_moneda"];
$ordenar=$_POST["ordenar"];
//$usuario=$_POST["usuario"];

$glosa_ver=$_POST["glosa_ver"];


//$n_decimales = 6;

//verificar el tipo de usuario 3 es normal (no muestra CxP)
$resultuser = mysqli_query($link, "select pkyUser as cod_user, codType as cod_tipo 
from accUser
where fldLogin = '$usuario' and
sysEnabled = 1 and sysAuthorized = 1;");
		
while ($row = mysqli_fetch_array($resultuser)) {
$cod_usuario = $row['cod_user'];
$cod_tipo_usuario = $row['cod_tipo'];
}
mysqli_free_result($resultuser);

if($cod_tipo_usuario == 3) { 
	$valor_ver_cxp = ' c.sysVisible <> 1 and ';
} else {
	$valor_ver_cxp = ' ';
}

?>
<body>

<?php

$empresaoempleado = substr($nombre, -2);
$nombreemp = substr($nombre, 0, -3);

if($mostrar == 0) { 
	$nom_mostrar = 'Todos'; 
	$valor_mostrar = ' ';
}
if($mostrar == 1) { 
	$nom_mostrar = 'Saldos igual a cero'; 
	$valor_mostrar = ' fin.saldo = 0 and ';
}
if($mostrar == 2) { 
	$nom_mostrar = 'Saldos diferentes a cero'; 
	$valor_mostrar = ' fin.saldo != 0 and ';
}

if($ordenar == 0) { 
	$nom_ordenar = 'Fecha'; 
	$valor_ordenar = ' order by fin.fecha, fin.cod_pago ';
}
if($ordenar == 1) { 
	$nom_ordenar = 'C&oacute;digo'; 
	$valor_ordenar = ' order by fin.cod_pago ';
}
if($ordenar == 2) { 
	$nom_ordenar = 'Nro. Documento'; 
	$valor_ordenar = ' order by cast(fin.nro_doc as unsigned), fin.fecha, fin.cod_pago ';
}
if($ordenar == 3) { 
	$nom_ordenar = 'V&iacute;a'; 
	$valor_ordenar = ' order by fin.via, fin.fecha, fin.cod_pago ';
}
if($ordenar == 4) { 
	$nom_ordenar = 'Empresa / Empleado'; 
	$valor_ordenar = ' order by fin.empresa_empleado, fin.fecha, fin.cod_pago ';
}


//Inicio reporte pagos

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

//nombre otra moneda
$resultotra = mysqli_query($link, "SELECT fldName as otra_moneda
from
actCurrency
where
pkyCurrency = '$otra_moneda' and
sysEnabled = 1 and sysAuthorized = 1;");
		
	while ($row = mysqli_fetch_array($resultotra)) {
	$nom_otra_moneda = $row['otra_moneda'];
	}
	mysqli_free_result($resultotra);

// via pago
if($via_pago == 0) { // if via cobro
	$nom_via_pago = 'Todos';
	$valor_via = ' ';
} else {// else if via cobro
	$resultvia = mysqli_query($link, "select pkyPaymentRoute as codigo, fldName as nombre
									from payPaymentRoute
									where
									pkyPaymentRoute = '$via_pago';");
	while ($row = mysqli_fetch_array($resultvia)) {   
	$nom_via_pago = $row['nombre'];
	}
	mysqli_free_result($resultvia);
	$valor_via = ' fin.cod_via = '. $via_pago .' and ';
}//fin if via cobro

//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 ';	
}


//valor del codigo del ultimo tipo de cambio
//uso del codigo del tipo de cambio según la fecha final, para calcular la tasa de cambio, tambien sirve para mostar en la cabecera
$resultom = mysqli_query($link, "SELECT T2.pkyExchangeRate as tc FROM 
(SELECT fldDate, MAX(fldTime) AS fldTime FROM actExchangeRate WHERE fldExclusive = '0' GROUP BY fldDate) as T1,
actExchangeRate T2 
WHERE 
T1.fldDate = (SELECT MAX(fldDate) FROM actExchangeRate WHERE fldDate <= '$fechafin' AND fldExclusive = '0') AND 
T2.fldDate = T1.fldDate AND 
T2.fldTime = T1.fldTime AND 
sysEnabled = 1 AND sysAuthorized = 1;");
while ($row = mysqli_fetch_array($resultom)) {
	$ultimo_tc = $row['tc'];
	}
	mysqli_free_result($resultom);

$resulttc = mysqli_query($link, "select pkyExchangeRate as cod_tc, fldDate as fecha, fldTime as hora
from
actExchangeRate
where
pkyExchangeRate = '$ultimo_tc';");
while ($row = mysqli_fetch_array($resulttc)) {
	$tc_fecha = $row['fecha'];
	$tc_hora = $row['hora'];
}
mysqli_free_result($resulttc);

$resulttcdet = mysqli_query($link, "select a.pkyExchangeRateDetail as cod_tc_det, a.codBaseCurrency as cod_mon_target, b.fldName as mon_target, b.txtDescription as nom_mon_target, a.codTargetCurrency as cod_mon_base, c.fldName as mon_base, c.txtDescription as nom_mon_base, a.fldRate as tasa
from
actExchangeRateDetail a, actCurrency b, actCurrency c
where
a.codExchangeRate = '$ultimo_tc' and 
a.codBaseCurrency = '$cod_moneda_principal' and 
a.codBaseCurrency = b.pkyCurrency and 
a.codTargetCurrency = c.pkyCurrency 
order by cod_mon_target, cod_mon_base;");
$ma_tc = array();
$m = 1;
while ($row = mysqli_fetch_array($resulttcdet)) {
	$ma_tc [$m][1] = $row['mon_base'];
	$ma_tc [$m][2] = $row['mon_target'];
	$ma_tc [$m][3] = $row['tasa'];
	$m++;
}
mysqli_free_result($resulttcdet);
$fin_m = $m - 1;



if ($empresaoempleado == -1) { // if 2.2
	
	if($nombreemp == 0) {
	$nom_cliente = 'Empresas';
	$valor_cliente = ' ';
	} else { 
		$resultcli = mysqli_query($link, "select pkyCompany as codigo, fldName as empresa
								from agnCompany
								where
								pkyCompany = '$nombreemp' and
								sysEnabled = 1 and sysAuthorized = 1;");
		while ($row = mysqli_fetch_array($resultcli)) {
			$nom_cliente = $row['codigo'].' - '.$row['empresa'];
		}
		mysqli_free_result($resultcli);
	$valor_cliente = ' fin.cod_emp = '. $nombreemp .' and ';
	}


	//Pagos empresas
	$result5 = mysqli_query($link, "select fin.cod_pago as cod_pago, fin.nro_doc as nro_doc, fin.fecha as fecha, fin.cod_via as cod_via, fin.via as via, fin.cod_emp as cod_emp, fin.empresa_empleado as empresa_empleado, fin.cod_moneda_pago as cod_moneda_pago, fin.moneda_pago as moneda_pago, fin.cod_cxp as cod_cxp, fin.cod_banco as cod_banco, fin.cod_cheque as cod_cheque, fin.cod_caja as cod_caja, fin.cod_moneda_cxp as cod_moneda_cxp, fin.moneda_cxp as moneda_cxp, fin.monto_pagado as monto_pagado, fin.monto_reducido as monto_reducido, fin.saldo as saldo, fin.monto_reducido_om as monto_reducido_om, fin.saldo_om as saldo_om, fin.glosa as glosa, fin.papa as papa, fin.cod_papa as cod_papa
from(
select t.cod_pago as cod_pago, t.nro_doc as nro_doc, t.fecha as fecha, t.cod_via as cod_via, t.via as via, t.cod_emp as cod_emp, t.empresa as empresa_empleado, t.cod_moneda_pago as cod_moneda_pago, t.moneda_pago as moneda_pago, t.cod_cxp as cod_cxp, t.cod_banco as cod_banco, t.cod_cheque as cod_cheque, t.cod_caja as cod_caja, t.cod_moneda_cxp as cod_moneda_cxp, t.moneda_cxp as moneda_cxp, t.monto_pagado as monto_pagado, t.monto_reducido as monto_reducido, t.saldo as saldo, t.monto_reducido * tc.fldRate as monto_reducido_om, t.saldo * tc.fldRate as saldo_om, t.glosa as glosa, t.papa as papa, t.cod_papa as cod_papa
from (
select a.pkyPayment as cod_pago, a.fldDocumentNumber as nro_doc, a.fldDate as fecha, a.codRoute as cod_via, d.fldName as via, a.codClient as cod_emp, e.fldName as empresa, a.codCurrency as cod_moneda_pago, m.fldName as moneda_pago, b.codAccountsPayable as cod_cxp, a.codBankMovement as cod_banco, a.codCheck as cod_cheque, a.codPettyCashMovement as cod_caja, c.codCurrency as cod_moneda_cxp, n.fldName as moneda_cxp, b.fldTotal * g.fldRate as monto_pagado, b.fldTotal as monto_reducido, c.fldBalance as saldo, a.txtDescription as glosa, a.fldParentComponent as papa, a.cosComponentKey as cod_papa
from payPayment a, payPaymentDetail b, payAccountsPayable c, payPaymentRoute d, agnCompany e, actExchangeRateDetail g, actCurrency m, actCurrency n
where
$valor_ver_cxp 
$valor_contexto 
a.pkyPayment = b.codPayment and
a.fldDate >= '$fechaini' and
a.fldDate <= '$fechafin' and
b.codAccountsPayable = c.pkyAccountsPayable and
a.codRoute = d.pkyPaymentRoute and 
a.codClient = e.pkyCompany and 
a.codCurrency != c.codCurrency and 
a.codExchangeRate = g.codExchangeRate and 
g.codBaseCurrency = a.codCurrency and 
g.codTargetCurrency = c.codCurrency and 
a.codCurrency = m.pkyCurrency and 
c.codCurrency = n.pkyCurrency and 
a.sysEnabled = 1 and a.sysAuthorized = 1
union all
select a.pkyPayment as cod_pago, a.fldDocumentNumber as nro_doc, a.fldDate as fecha, a.codRoute as cod_via, d.fldName as via, a.codClient as cod_emp, e.fldName as empresa, a.codCurrency as cod_moneda_pago, m.fldName as moneda_pago, b.codAccountsPayable as cod_cxp, a.codBankMovement as cod_banco, a.codCheck as cod_cheque, a.codPettyCashMovement as cod_caja, c.codCurrency as cod_moneda_cxp, n.fldName as moneda_cxp, b.fldTotal * 1 as monto_pagado, b.fldTotal as monto_reducido, c.fldBalance as saldo, a.txtDescription as glosa, a.fldParentComponent as papa, a.cosComponentKey as cod_papa
from payPayment a, payPaymentDetail b, payAccountsPayable c, payPaymentRoute d, agnCompany e, actCurrency m, actCurrency n
where
$valor_ver_cxp 
$valor_contexto 
a.pkyPayment = b.codPayment and
a.fldDate >= '$fechaini' and
a.fldDate <= '$fechafin' and
b.codAccountsPayable = c.pkyAccountsPayable and
a.codRoute = d.pkyPaymentRoute and 
a.codClient = e.pkyCompany and 
a.codCurrency = c.codCurrency and 
a.codCurrency = m.pkyCurrency and 
c.codCurrency = n.pkyCurrency and 
a.sysEnabled = 1 and a.sysAuthorized = 1) t, actExchangeRateDetail tc 
where 
tc.codExchangeRate = '$ultimo_tc' and 
tc.codBaseCurrency = '$otra_moneda' and 
tc.codTargetCurrency = t.cod_moneda_cxp 

union all 

select t.cod_pago as cod_pago, t.nro_doc as nro_doc, t.fecha as fecha, t.cod_via as cod_via, t.via as via, t.cod_emp as cod_emp, t.empresa as empresa_empleado, t.cod_moneda_pago as cod_moneda_pago, t.moneda_pago as moneda_pago, t.cod_cxp as cod_cxp, t.cod_banco as cod_banco, t.cod_cheque as cod_cheque, t.cod_caja as cod_caja, t.cod_moneda_cxp as cod_moneda_cxp, t.moneda_cxp as moneda_cxp, t.monto_pagado as monto_pagado, t.monto_reducido as monto_reducido, t.saldo as saldo, t.monto_reducido * 1 as monto_reducido_om, t.saldo * 1 as saldo_om, t.glosa as glosa, t.papa as papa, t.cod_papa as cod_papa
from (
select a.pkyPayment as cod_pago, a.fldDocumentNumber as nro_doc, a.fldDate as fecha, a.codRoute as cod_via, d.fldName as via, a.codClient as cod_emp, e.fldName as empresa, a.codCurrency as cod_moneda_pago, m.fldName as moneda_pago, b.codAccountsPayable as cod_cxp, a.codBankMovement as cod_banco, a.codCheck as cod_cheque, a.codPettyCashMovement as cod_caja, c.codCurrency as cod_moneda_cxp, n.fldName as moneda_cxp, b.fldTotal * g.fldRate as monto_pagado, b.fldTotal as monto_reducido, c.fldBalance as saldo, a.txtDescription as glosa, a.fldParentComponent as papa, a.cosComponentKey as cod_papa
from payPayment a, payPaymentDetail b, payAccountsPayable c, payPaymentRoute d, agnCompany e, actExchangeRateDetail g, actCurrency m, actCurrency n
where
$valor_ver_cxp 
$valor_contexto 
a.pkyPayment = b.codPayment and
a.fldDate >= '$fechaini' and
a.fldDate <= '$fechafin' and
b.codAccountsPayable = c.pkyAccountsPayable and
a.codRoute = d.pkyPaymentRoute and 
a.codClient = e.pkyCompany and 
a.codCurrency != c.codCurrency and 
a.codExchangeRate = g.codExchangeRate and 
g.codBaseCurrency = a.codCurrency and 
g.codTargetCurrency = c.codCurrency and 
a.codCurrency = m.pkyCurrency and 
c.codCurrency = n.pkyCurrency and 
a.sysEnabled = 1 and a.sysAuthorized = 1
union all
select a.pkyPayment as cod_pago, a.fldDocumentNumber as nro_doc, a.fldDate as fecha, a.codRoute as cod_via, d.fldName as via, a.codClient as cod_emp, e.fldName as empresa, a.codCurrency as cod_moneda_pago, m.fldName as moneda_pago, b.codAccountsPayable as cod_cxp, a.codBankMovement as cod_banco, a.codCheck as cod_cheque, a.codPettyCashMovement as cod_caja, c.codCurrency as cod_moneda_cxp, n.fldName as moneda_cxp, b.fldTotal * 1 as monto_pagado, b.fldTotal as monto_reducido, c.fldBalance as saldo, a.txtDescription as glosa, a.fldParentComponent as papa, a.cosComponentKey as cod_papa
from payPayment a, payPaymentDetail b, payAccountsPayable c, payPaymentRoute d, agnCompany e, actCurrency m, actCurrency n
where 
$valor_ver_cxp 
$valor_contexto 
a.pkyPayment = b.codPayment and
a.fldDate >= '$fechaini' and
a.fldDate <= '$fechafin' and
b.codAccountsPayable = c.pkyAccountsPayable and
a.codRoute = d.pkyPaymentRoute and 
a.codClient = e.pkyCompany and 
a.codCurrency = c.codCurrency and 
a.codCurrency = m.pkyCurrency and 
c.codCurrency = n.pkyCurrency and 
a.sysEnabled = 1 and a.sysAuthorized = 1) t
where 
t.cod_moneda_cxp = '$otra_moneda') fin  
where   
$valor_cliente 
$valor_mostrar 
$valor_via 
fin.cod_pago is not null 
$valor_ordenar;");		

?>

<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>Pagos</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>Ver Saldos: </b><?php echo $nom_mostrar; ?></TD>
        <TD width="25%"><b>Empresa/Empleado: </b><?php echo $nom_cliente; ?></TD>
        <TD width="25%"><b>V&iacute;a: </b><?php echo $nom_via_pago; ?></TD>
        <TD width="25%"><b>Contexto: </b><?php echo $nom_contexto; ?></TD>
        </TR>
        <TR>
        <TD colspan="2"><b>De Fecha: </b><?php echo $fechaini; ?> <b>a Fecha: </b><?php echo $fechafin; ?></TD>
        <TD><b>Ordenado por: </b><?php echo $nom_ordenar; ?></TD>
        <TD><b>Expresado en: </b><?php echo $nom_otra_moneda; ?></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></tr>", 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>Cod.</b></TD>
    <TD align="center"><b>Nro. Doc.</b></TD>
    <TD align="center"><b>Fecha</b></TD>
    <TD align="center"><b>V&iacute;a</b></TD>
    <TD align="center"><b>Empresa</b></TD>
    <TD align="center"><b>CxP</b></TD>
    <TD align="center"><b>Banco</b></TD>
    <TD align="center"><b>Cheque</b></TD>
    <TD align="center"><b>Caja</b></TD>
    <TD align="center"><b>Gen. Por</b></TD>
    <TD align="center"><b>Mon. Pago</b></TD>
    <TD align="center"><b>Monto Pagado</b></TD>
    <TD align="center"><b>Mon. CxP</b></TD>
    <TD align="center"><b>Monto Reducido</b></TD>
    <TD align="center"><b>Saldo</b></TD>
    <TD align="center"><b>Monto Reducido en <?php echo $nom_otra_moneda; ?></b></TD>
    <TD align="center"><b>Saldo en <?php echo $nom_otra_moneda; ?></b></TD>
    <?php if($glosa_ver == 1) { ?>
    <TD align="center"><b>Glosa</b></TD>
    <?php } ?>
    </TR>
    </thead>
    <tbody class="marcafila">

  <?php
  $color = 2;
  $suma_total_red = 0;
  $suma_total_sal = 0;
  while ($row = mysqli_fetch_array($result5)) { //while
  	
	//para enlazar al que genero el asiento
	$papa_componente = $row['papa'];
	$papa_codigo = $row['cod_papa'];
	//$usuario = $usuario_det;
	include "../../generadopor.php";
	
	$codigo = $row['cod_pago'];
	$cod_cxp = $row['cod_cxp'];
	$cod_banco = $row['cod_banco'];
	$cod_cheque = $row['cod_cheque'];
	$cod_caja = $row['cod_caja'];
	if($color % 2 == 0) { //if color
		printf("<tr BGCOLOR='#e2e7fa'><td align='center'><a href='../../ModulePayments/VoucherPayment/index.php?pkyPayment=$codigo&user=$usuario&token=$token' title='Nota de Pago'>%s</a></td>", $row['cod_pago']);//cod
	} else { 
		printf("<tr><td align='center'><a href='../../ModulePayments/VoucherPayment/index.php?pkyPayment=$codigo&user=$usuario&token=$token' title='Nota de Pago'>%s</a></td>", $row['cod_pago']);//cod
	} //cierra if color
	printf("<td align='center'>%s</td>", $row['nro_doc']);//nro doc
	printf("<td align='right'>%s</td>", $row['fecha']);//fecha
	printf("<td>%s</td>", $row['via']);// via
	printf("<td>%s</td>", $row['empresa_empleado']);// empresa
	printf("<td align='right'><a href='../../ModulePayments/VoucherAccountsPayable/index.php?pkyAccountsPayable=$cod_cxp&user=$usuario&token=$token' title='Nota de Cuenta por Pagar'>%s</a></td>", $row['cod_cxp']);// cod cxp
	printf("<td align='right'><a href='../../ModuleTreasury/VoucherBankMovement/index.php?pkyBankMovement=$cod_banco&user=$usuario&token=$token' title='Nota Movimiento Bancario'>%s</a></td>", $row['cod_banco']);// cod banco
	printf("<td align='right'><a href='../../ModuleTreasury/VoucherCheck/index.php?pkyCheck=$cod_cheque&user=$usuario&token=$token' title='Cheque'>%s</a></td>", $row['cod_cheque']);// cod cheque
	printf("<td align='right'><a href='../../ModulePettyCash/VoucherPettyCashMovement/index.php?pkyPettyCashMovement=$cod_caja&user=$usuario&token=$token' title='Nota de Movimiento de Caja'>%s</a></td>", $row['cod_caja']);// cod caja
	printf("<td align='center'>%s</td>", $papa_enlace);//gen por
	printf("<td align='center'>%s</td>", $row['moneda_pago']);// moneda de pago
	printf("<td align='right'>%s</td>", number_format($row['monto_pagado'],$n_decimales));//monto pagado
	printf("<td align='center'>%s</td>", $row['moneda_cxp']);// moneda cxp   
	printf("<td align='right'>%s</td>", number_format($row['monto_reducido'],$n_decimales));//monto reducido
	printf("<td align='right'>%s</td>", number_format($row['saldo'],$n_decimales));//saldo
	printf("<td align='right'>%s</td>", number_format($row['monto_reducido_om'],$n_decimales));//monto reducido om
	printf("<td align='right'>%s</td>", number_format($row['saldo_om'],$n_decimales));//saldo om
	if($glosa_ver == 1) {//if ver_glosa
	$glosa = $row['glosa'];
	$glosa = nl2br($glosa);
	$glosa = str_replace('\n','<br />',$glosa);
	printf("<td align='left'>%s</td>", $glosa);//glosa
	}//fin if ver_glosa
	echo '</tr>';
	

    $suma_total_red = $suma_total_red + $row['monto_reducido_om'];
    $suma_total_sal = $suma_total_sal + $row['saldo_om'];
    
	$color++;
 }//fin while

mysqli_free_result($result5);

?>
<tr BGCOLOR='#ffcccc'><td colspan="15"><b>Total Pagos Empresas</b></td>
<td align="right"><?php printf("<b>%s</b>", number_format($suma_total_red,$n_decimales)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($suma_total_sal,$n_decimales)); ?></td>
<?php if($glosa_ver == 1) { ?>
<td>&nbsp;</td>
<?php } ?>
</tr>
</tbody>
</table>
<?php




	}//fin if 2.2
	
	
	if ($empresaoempleado == -2) { // if 2.3
	
	
	if($nombreemp == 0) {
	$nom_cliente = 'Empleados';
	$valor_cliente = ' ';
	} else { 
		$resultcli = mysqli_query($link, "select pkyPerson as codigo, case when fldMiddleName is NULL then concat(fldLastName,', ',fldFirstName) else concat(fldLastName,' ',fldMiddleName,', ',fldFirstName) end as empleado
								from agnPerson
								where
								pkyPerson = '$nombreemp' and
								sysEnabled = 1 and sysAuthorized = 1;");
		while ($row = mysqli_fetch_array($resultcli)) {
			$nom_cliente = $row['codigo'].' - '.$row['empleado'];
		}
		mysqli_free_result($resultcli);
	$valor_cliente = ' fin.cod_emp = '. $nombreemp .' and ';
	}
	
	//Pagos empleados
	$result5 = mysqli_query($link, "select fin.cod_pago as cod_pago, fin.nro_doc as nro_doc, fin.fecha as fecha, fin.cod_via as cod_via, fin.via as via, fin.cod_emp as cod_emp, fin.empresa_empleado as empresa_empleado, fin.cod_moneda_pago as cod_moneda_pago, fin.moneda_pago as moneda_pago, fin.cod_cxp as cod_cxp, fin.cod_banco as cod_banco, fin.cod_cheque as cod_cheque, fin.cod_caja as cod_caja, fin.cod_moneda_cxp as cod_moneda_cxp, fin.moneda_cxp as moneda_cxp, fin.monto_pagado as monto_pagado, fin.monto_reducido as monto_reducido, fin.saldo as saldo, fin.monto_reducido_om as monto_reducido_om, fin.saldo_om as saldo_om, fin.glosa as glosa, fin.papa as papa, fin.cod_papa as cod_papa
from(
select t.cod_pago as cod_pago, t.nro_doc as nro_doc, t.fecha as fecha, t.cod_via as cod_via, t.via as via, t.cod_emp as cod_emp, t.empleado as empresa_empleado, t.cod_moneda_pago as cod_moneda_pago, t.moneda_pago as moneda_pago, t.cod_cxp as cod_cxp, t.cod_banco as cod_banco, t.cod_cheque as cod_cheque, t.cod_caja as cod_caja, t.cod_moneda_cxp as cod_moneda_cxp, t.moneda_cxp as moneda_cxp, t.monto_pagado as monto_pagado, t.monto_reducido as monto_reducido, t.saldo as saldo, t.monto_reducido * tc.fldRate as monto_reducido_om, t.saldo * tc.fldRate as saldo_om, t.glosa as glosa, t.papa as papa, t.cod_papa as cod_papa
from (
select a.pkyPayment as cod_pago, a.fldDocumentNumber as nro_doc, a.fldDate as fecha, a.codRoute as cod_via, d.fldName as via, a.codEmployee as cod_emp, case when e.fldMiddleName is NULL then concat(e.fldLastName,', 
',e.fldFirstName) else concat(e.fldLastName,' ',e.fldMiddleName,', ',e.fldFirstName) end as empleado, a.codCurrency as cod_moneda_pago, m.fldName as moneda_pago, b.codAccountsPayable as cod_cxp, a.codBankMovement as cod_banco, a.codCheck as cod_cheque, a.codPettyCashMovement as cod_caja, c.codCurrency as cod_moneda_cxp, n.fldName as moneda_cxp, b.fldTotal * g.fldRate as monto_pagado, b.fldTotal as monto_reducido, c.fldBalance as saldo, a.txtDescription as glosa, a.fldParentComponent as papa, a.cosComponentKey as cod_papa
from payPayment a, payPaymentDetail b, payAccountsPayable c, payPaymentRoute d, agnPerson e, actExchangeRateDetail g, actCurrency m, actCurrency n
where
$valor_ver_cxp 
$valor_contexto 
a.pkyPayment = b.codPayment and
a.fldDate >= '$fechaini' and
a.fldDate <= '$fechafin' and
b.codAccountsPayable = c.pkyAccountsPayable and
a.codRoute = d.pkyPaymentRoute and 
a.codEmployee = e.pkyPerson and 
a.codCurrency != c.codCurrency and 
a.codExchangeRate = g.codExchangeRate and 
g.codBaseCurrency = a.codCurrency and 
g.codTargetCurrency = c.codCurrency and 
a.codCurrency = m.pkyCurrency and 
c.codCurrency = n.pkyCurrency and 
a.sysEnabled = 1 and a.sysAuthorized = 1
union all
select a.pkyPayment as cod_pago, a.fldDocumentNumber as nro_doc, a.fldDate as fecha, a.codRoute as cod_via, d.fldName as via, a.codEmployee as cod_emp, case when e.fldMiddleName is NULL then concat(e.fldLastName,', 
',e.fldFirstName) else concat(e.fldLastName,' ',e.fldMiddleName,', ',e.fldFirstName) end as empleado, a.codCurrency as cod_moneda_pago, m.fldName as moneda_pago, b.codAccountsPayable as cod_cxp, a.codBankMovement as cod_banco, a.codCheck as cod_cheque, a.codPettyCashMovement as cod_caja, c.codCurrency as cod_moneda_cxp, n.fldName as moneda_cxp, b.fldTotal * 1 as monto_pagado, b.fldTotal as monto_reducido, c.fldBalance as saldo, a.txtDescription as glosa, a.fldParentComponent as papa, a.cosComponentKey as cod_papa
from payPayment a, payPaymentDetail b, payAccountsPayable c, payPaymentRoute d, agnPerson e, actCurrency m, actCurrency n
where
$valor_ver_cxp 
$valor_contexto 
a.pkyPayment = b.codPayment and
a.fldDate >= '$fechaini' and
a.fldDate <= '$fechafin' and
b.codAccountsPayable = c.pkyAccountsPayable and
a.codRoute = d.pkyPaymentRoute and 
a.codEmployee = e.pkyPerson and  
a.codCurrency = c.codCurrency and 
a.codCurrency = m.pkyCurrency and 
c.codCurrency = n.pkyCurrency and 
a.sysEnabled = 1 and a.sysAuthorized = 1) t, actExchangeRateDetail tc 
where 
tc.codExchangeRate = '$ultimo_tc' and 
tc.codBaseCurrency = '$otra_moneda' and 
tc.codTargetCurrency = t.cod_moneda_cxp 

union all 

select t.cod_pago as cod_pago, t.nro_doc as nro_doc, t.fecha as fecha, t.cod_via as cod_via, t.via as via, t.cod_emp as cod_emp, t.empleado as empresa_empleado, t.cod_moneda_pago as cod_moneda_pago, t.moneda_pago as moneda_pago, t.cod_cxp as cod_cxp, t.cod_banco as cod_banco, t.cod_cheque as cod_cheque, t.cod_caja as cod_caja, t.cod_moneda_cxp as cod_moneda_cxp, t.moneda_cxp as moneda_cxp, t.monto_pagado as monto_pagado, t.monto_reducido as monto_reducido, t.saldo as saldo, t.monto_reducido * 1 as monto_reducido_om, t.saldo * 1 as saldo_om, t.glosa as glosa, t.papa as papa, t.cod_papa as cod_papa
from (
select a.pkyPayment as cod_pago, a.fldDocumentNumber as nro_doc, a.fldDate as fecha, a.codRoute as cod_via, d.fldName as via, a.codEmployee as cod_emp, case when e.fldMiddleName is NULL then concat(e.fldLastName,', 
',e.fldFirstName) else concat(e.fldLastName,' ',e.fldMiddleName,', ',e.fldFirstName) end as empleado, a.codCurrency as cod_moneda_pago, m.fldName as moneda_pago, b.codAccountsPayable as cod_cxp, a.codBankMovement as cod_banco, a.codCheck as cod_cheque, a.codPettyCashMovement as cod_caja, c.codCurrency as cod_moneda_cxp, n.fldName as moneda_cxp, b.fldTotal * g.fldRate as monto_pagado, b.fldTotal as monto_reducido, c.fldBalance as saldo, a.txtDescription as glosa, a.fldParentComponent as papa, a.cosComponentKey as cod_papa
from payPayment a, payPaymentDetail b, payAccountsPayable c, payPaymentRoute d, agnPerson e, actExchangeRateDetail g, actCurrency m, actCurrency n
where
$valor_ver_cxp 
$valor_contexto 
a.pkyPayment = b.codPayment and
a.fldDate >= '$fechaini' and
a.fldDate <= '$fechafin' and
b.codAccountsPayable = c.pkyAccountsPayable and
a.codRoute = d.pkyPaymentRoute and 
a.codEmployee = e.pkyPerson and  
a.codCurrency != c.codCurrency and 
a.codExchangeRate = g.codExchangeRate and 
g.codBaseCurrency = a.codCurrency and 
g.codTargetCurrency = c.codCurrency and 
a.codCurrency = m.pkyCurrency and 
c.codCurrency = n.pkyCurrency and 
a.sysEnabled = 1 and a.sysAuthorized = 1
union all
select a.pkyPayment as cod_pago, a.fldDocumentNumber as nro_doc, a.fldDate as fecha, a.codRoute as cod_via, d.fldName as via, a.codEmployee as cod_emp, case when e.fldMiddleName is NULL then concat(e.fldLastName,', 
',e.fldFirstName) else concat(e.fldLastName,' ',e.fldMiddleName,', ',e.fldFirstName) end as empleado, a.codCurrency as cod_moneda_pago, m.fldName as moneda_pago, b.codAccountsPayable as cod_cxp, a.codBankMovement as cod_banco, a.codCheck as cod_cheque, a.codPettyCashMovement as cod_caja, c.codCurrency as cod_moneda_cxp, n.fldName as moneda_cxp, b.fldTotal * 1 as monto_pagado, b.fldTotal as monto_reducido, c.fldBalance as saldo, a.txtDescription as glosa, a.fldParentComponent as papa, a.cosComponentKey as cod_papa
from payPayment a, payPaymentDetail b, payAccountsPayable c, payPaymentRoute d, agnPerson e, actCurrency m, actCurrency n
where
$valor_ver_cxp 
$valor_contexto 
a.pkyPayment = b.codPayment and
a.fldDate >= '$fechaini' and
a.fldDate <= '$fechafin' and
b.codAccountsPayable = c.pkyAccountsPayable and
a.codRoute = d.pkyPaymentRoute and 
a.codEmployee = e.pkyPerson and  
a.codCurrency = c.codCurrency and 
a.codCurrency = m.pkyCurrency and 
c.codCurrency = n.pkyCurrency and 
a.sysEnabled = 1 and a.sysAuthorized = 1) t
where 
t.cod_moneda_cxp = '$otra_moneda') fin  
where   
$valor_cliente 
$valor_mostrar 
$valor_via 
fin.cod_pago is not null 
$valor_ordenar;");		

?>
<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>Pagos</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>Ver Saldos: </b><?php echo $nom_mostrar; ?></TD>
        <TD width="25%"><b>Empresa/Empleado: </b><?php echo $nom_cliente; ?></TD>
        <TD width="25%"><b>V&iacute;a: </b><?php echo $nom_via_pago; ?></TD>
        <TD width="25%"><b>Contexto: </b><?php echo $nom_contexto; ?></TD>
        </TR>
        <TR>
        <TD colspan="2"><b>De Fecha: </b><?php echo $fechaini; ?> <b>a Fecha: </b><?php echo $fechafin; ?></TD>
        <TD><b>Ordenado por: </b><?php echo $nom_ordenar; ?></TD>
        <TD><b>Expresado en: </b><?php echo $nom_otra_moneda; ?></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></tr>", 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>Cod.</b></TD>
    <TD align="center"><b>Nro. Doc.</b></TD>
    <TD align="center"><b>Fecha</b></TD>
    <TD align="center"><b>V&iacute;a</b></TD>
    <TD align="center"><b>Empleado</b></TD>
    <TD align="center"><b>CxP</b></TD>
    <TD align="center"><b>Banco</b></TD>
    <TD align="center"><b>Cheque</b></TD>
    <TD align="center"><b>Caja</b></TD>
    <TD align="center"><b>Gen. Por</b></TD>
    <TD align="center"><b>Mon. Pago</b></TD>
    <TD align="center"><b>Monto Pagado</b></TD>
    <TD align="center"><b>Mon. CxP</b></TD>
    <TD align="center"><b>Monto Reducido</b></TD>
    <TD align="center"><b>Saldo</b></TD>
    <TD align="center"><b>Monto Reducido en <?php echo $nom_otra_moneda; ?></b></TD>
    <TD align="center"><b>Saldo en <?php echo $nom_otra_moneda; ?></b></TD>
    <?php if($glosa_ver == 1) { ?>
    <TD align="center"><b>Glosa</b></TD>
    <?php } ?>
    </TR>
    </thead>
    <tbody class="marcafila">

  <?php
  $color = 2;
  $suma_total_red = 0;
  $suma_total_sal = 0;
  while ($row = mysqli_fetch_array($result5)) { //while
  
  	//para enlazar al que genero el asiento
	$papa_componente = $row['papa'];
	$papa_codigo = $row['cod_papa'];
	//$usuario = $usuario_det;
	include "../../generadopor.php";
  
	$codigo = $row['cod_pago'];
	$cod_cxp = $row['cod_cxp'];
	$cod_banco = $row['cod_banco'];
	$cod_cheque = $row['cod_cheque'];
	$cod_caja = $row['cod_caja'];
	if($color % 2 == 0) { //if color
		printf("<tr BGCOLOR='#e2e7fa'><td align='center'><a href='../../ModulePayments/VoucherPayment/index.php?pkyPayment=$codigo&user=$usuario&token=$token' title='Nota de Pago'>%s</a></td>", $row['cod_pago']);//cod
	} else { 
		printf("<tr><td align='center'><a href='../../ModulePayments/VoucherPayment/index.php?pkyPayment=$codigo&user=$usuario&token=$token' title='Nota de Pago'>%s</a></td>", $row['cod_pago']);//cod
	} //cierra if color
	printf("<td align='center'>%s</td>", $row['nro_doc']);//nro doc
	printf("<td align='right'>%s</td>", $row['fecha']);//fecha
	printf("<td>%s</td>", $row['via']);// via
	printf("<td>%s</td>", $row['empresa_empleado']);// empleado
	printf("<td align='right'><a href='../../ModulePayments/VoucherAccountsPayable/index.php?pkyAccountsPayable=$cod_cxp&user=$usuario&token=$token' title='Nota de Cuenta por Pagar'>%s</a></td>", $row['cod_cxp']);// cod cxp
	printf("<td align='right'><a href='../../ModuleTreasury/VoucherBankMovement/index.php?pkyBankMovement=$cod_banco&user=$usuario&token=$token' title='Nota Movimiento Bancario'>%s</a></td>", $row['cod_banco']);// cod banco
	printf("<td align='right'><a href='../../ModuleTreasury/VoucherCheck/index.php?pkyCheck=$cod_cheque&user=$usuario&token=$token' title='Cheque'>%s</a></td>", $row['cod_cheque']);// cod cheque
	printf("<td align='right'><a href='../../ModulePettyCash/VoucherPettyCashMovement/index.php?pkyPettyCashMovement=$cod_caja&user=$usuario&token=$token' title='Nota de Movimiento de Caja'>%s</a></td>", $row['cod_caja']);// cod caja
	printf("<td align='center'>%s</td>", $papa_enlace);//gen por
	printf("<td align='center'>%s</td>", $row['moneda_pago']);// moneda de pago
	printf("<td align='right'>%s</td>", number_format($row['monto_pagado'],$n_decimales));//monto pagado
	printf("<td align='center'>%s</td>", $row['moneda_cxp']);// moneda cxp   
	printf("<td align='right'>%s</td>", number_format($row['monto_reducido'],$n_decimales));//monto reducido
	printf("<td align='right'>%s</td>", number_format($row['saldo'],$n_decimales));//saldo
	printf("<td align='right'>%s</td>", number_format($row['monto_reducido_om'],$n_decimales));//monto reducido om
	printf("<td align='right'>%s</td>", number_format($row['saldo_om'],$n_decimales));//saldo om
	if($glosa_ver == 1) {//if ver_glosa
	$glosa = $row['glosa'];
	$glosa = nl2br($glosa);
	$glosa = str_replace('\n','<br />',$glosa);
	printf("<td align='left'>%s</td>", $glosa);//glosa
	}//fin if ver_glosa
	echo '</tr>';
	

    $suma_total_red = $suma_total_red + $row['monto_reducido_om'];
    $suma_total_sal = $suma_total_sal + $row['saldo_om'];
    
	$color++;
 }//fin while

mysqli_free_result($result5);

?>
<tr BGCOLOR='#ffcccc'><td colspan="15"><b>Total Pagos Empleados</b></td>
<td align="right"><?php printf("<b>%s</b>", number_format($suma_total_red,$n_decimales)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($suma_total_sal,$n_decimales)); ?></td>
<?php if($glosa_ver == 1) { ?>
<td>&nbsp;</td>
<?php } ?>
</tr>
</tbody>
</table>
		
<?php
	}//fin if 2.3
	
	
	
	
	
	
	if ($empresaoempleado == -3) { // if 2.4
	
	$nom_cliente = 'Todos';
	$valor_cliente = ' ';

	//Pagos empresas
	$result5 = mysqli_query($link, "select fin.cod_pago as cod_pago, fin.nro_doc as nro_doc, fin.fecha as fecha, fin.cod_via as cod_via, fin.via as via, fin.cod_emp as cod_emp, fin.empresa_empleado as empresa_empleado, fin.cod_moneda_pago as cod_moneda_pago, fin.moneda_pago as moneda_pago, fin.cod_cxp as cod_cxp, fin.cod_banco as cod_banco, fin.cod_cheque as cod_cheque, fin.cod_caja as cod_caja, fin.cod_moneda_cxp as cod_moneda_cxp, fin.moneda_cxp as moneda_cxp, fin.monto_pagado as monto_pagado, fin.monto_reducido as monto_reducido, fin.saldo as saldo, fin.monto_reducido_om as monto_reducido_om, fin.saldo_om as saldo_om, fin.glosa as glosa, fin.papa as papa, fin.cod_papa as cod_papa
from(
select t.cod_pago as cod_pago, t.nro_doc as nro_doc, t.fecha as fecha, t.cod_via as cod_via, t.via as via, t.cod_emp as cod_emp, t.empresa as empresa_empleado, t.cod_moneda_pago as cod_moneda_pago, t.moneda_pago as moneda_pago, t.cod_cxp as cod_cxp, t.cod_banco as cod_banco, t.cod_cheque as cod_cheque, t.cod_caja as cod_caja, t.cod_moneda_cxp as cod_moneda_cxp, t.moneda_cxp as moneda_cxp, t.monto_pagado as monto_pagado, t.monto_reducido as monto_reducido, t.saldo as saldo, t.monto_reducido * tc.fldRate as monto_reducido_om, t.saldo * tc.fldRate as saldo_om, t.glosa as glosa, t.papa as papa, t.cod_papa as cod_papa
from (
select a.pkyPayment as cod_pago, a.fldDocumentNumber as nro_doc, a.fldDate as fecha, a.codRoute as cod_via, d.fldName as via, a.codClient as cod_emp, e.fldName as empresa, a.codCurrency as cod_moneda_pago, m.fldName as moneda_pago, b.codAccountsPayable as cod_cxp, a.codBankMovement as cod_banco, a.codCheck as cod_cheque, a.codPettyCashMovement as cod_caja, c.codCurrency as cod_moneda_cxp, n.fldName as moneda_cxp, b.fldTotal * g.fldRate as monto_pagado, b.fldTotal as monto_reducido, c.fldBalance as saldo, a.txtDescription as glosa, a.fldParentComponent as papa, a.cosComponentKey as cod_papa
from payPayment a, payPaymentDetail b, payAccountsPayable c, payPaymentRoute d, agnCompany e, actExchangeRateDetail g, actCurrency m, actCurrency n
where
$valor_ver_cxp 
$valor_contexto 
a.pkyPayment = b.codPayment and
a.fldDate >= '$fechaini' and
a.fldDate <= '$fechafin' and
b.codAccountsPayable = c.pkyAccountsPayable and
a.codRoute = d.pkyPaymentRoute and 
a.codClient = e.pkyCompany and 
a.codCurrency != c.codCurrency and 
a.codExchangeRate = g.codExchangeRate and 
g.codBaseCurrency = a.codCurrency and 
g.codTargetCurrency = c.codCurrency and 
a.codCurrency = m.pkyCurrency and 
c.codCurrency = n.pkyCurrency and 
a.sysEnabled = 1 and a.sysAuthorized = 1
union all
select a.pkyPayment as cod_pago, a.fldDocumentNumber as nro_doc, a.fldDate as fecha, a.codRoute as cod_via, d.fldName as via, a.codClient as cod_emp, e.fldName as empresa, a.codCurrency as cod_moneda_pago, m.fldName as moneda_pago, b.codAccountsPayable as cod_cxp, a.codBankMovement as cod_banco, a.codCheck as cod_cheque, a.codPettyCashMovement as cod_caja, c.codCurrency as cod_moneda_cxp, n.fldName as moneda_cxp, b.fldTotal * 1 as monto_pagado, b.fldTotal as monto_reducido, c.fldBalance as saldo, a.txtDescription as glosa, a.fldParentComponent as papa, a.cosComponentKey as cod_papa
from payPayment a, payPaymentDetail b, payAccountsPayable c, payPaymentRoute d, agnCompany e, actCurrency m, actCurrency n
where
$valor_ver_cxp 
$valor_contexto 
a.pkyPayment = b.codPayment and
a.fldDate >= '$fechaini' and
a.fldDate <= '$fechafin' and
b.codAccountsPayable = c.pkyAccountsPayable and
a.codRoute = d.pkyPaymentRoute and 
a.codClient = e.pkyCompany and 
a.codCurrency = c.codCurrency and 
a.codCurrency = m.pkyCurrency and 
c.codCurrency = n.pkyCurrency and 
a.sysEnabled = 1 and a.sysAuthorized = 1) t, actExchangeRateDetail tc 
where 
tc.codExchangeRate = '$ultimo_tc' and 
tc.codBaseCurrency = '$otra_moneda' and 
tc.codTargetCurrency = t.cod_moneda_cxp 

union all 

select t.cod_pago as cod_pago, t.nro_doc as nro_doc, t.fecha as fecha, t.cod_via as cod_via, t.via as via, t.cod_emp as cod_emp, t.empresa as empresa_empleado, t.cod_moneda_pago as cod_moneda_pago, t.moneda_pago as moneda_pago, t.cod_cxp as cod_cxp, t.cod_banco as cod_banco, t.cod_cheque as cod_cheque, t.cod_caja as cod_caja, t.cod_moneda_cxp as cod_moneda_cxp, t.moneda_cxp as moneda_cxp, t.monto_pagado as monto_pagado, t.monto_reducido as monto_reducido, t.saldo as saldo, t.monto_reducido * 1 as monto_reducido_om, t.saldo * 1 as saldo_om, t.glosa as glosa, t.papa as papa, t.cod_papa as cod_papa
from (
select a.pkyPayment as cod_pago, a.fldDocumentNumber as nro_doc, a.fldDate as fecha, a.codRoute as cod_via, d.fldName as via, a.codClient as cod_emp, e.fldName as empresa, a.codCurrency as cod_moneda_pago, m.fldName as moneda_pago, b.codAccountsPayable as cod_cxp, a.codBankMovement as cod_banco, a.codCheck as cod_cheque, a.codPettyCashMovement as cod_caja, c.codCurrency as cod_moneda_cxp, n.fldName as moneda_cxp, b.fldTotal * g.fldRate as monto_pagado, b.fldTotal as monto_reducido, c.fldBalance as saldo, a.txtDescription as glosa, a.fldParentComponent as papa, a.cosComponentKey as cod_papa
from payPayment a, payPaymentDetail b, payAccountsPayable c, payPaymentRoute d, agnCompany e, actExchangeRateDetail g, actCurrency m, actCurrency n
where
$valor_ver_cxp 
$valor_contexto 
a.pkyPayment = b.codPayment and
a.fldDate >= '$fechaini' and
a.fldDate <= '$fechafin' and
b.codAccountsPayable = c.pkyAccountsPayable and
a.codRoute = d.pkyPaymentRoute and 
a.codClient = e.pkyCompany and 
a.codCurrency != c.codCurrency and 
a.codExchangeRate = g.codExchangeRate and 
g.codBaseCurrency = a.codCurrency and 
g.codTargetCurrency = c.codCurrency and 
a.codCurrency = m.pkyCurrency and 
c.codCurrency = n.pkyCurrency and 
a.sysEnabled = 1 and a.sysAuthorized = 1
union all
select a.pkyPayment as cod_pago, a.fldDocumentNumber as nro_doc, a.fldDate as fecha, a.codRoute as cod_via, d.fldName as via, a.codClient as cod_emp, e.fldName as empresa, a.codCurrency as cod_moneda_pago, m.fldName as moneda_pago, b.codAccountsPayable as cod_cxp, a.codBankMovement as cod_banco, a.codCheck as cod_cheque, a.codPettyCashMovement as cod_caja, c.codCurrency as cod_moneda_cxp, n.fldName as moneda_cxp, b.fldTotal * 1 as monto_pagado, b.fldTotal as monto_reducido, c.fldBalance as saldo, a.txtDescription as glosa, a.fldParentComponent as papa, a.cosComponentKey as cod_papa
from payPayment a, payPaymentDetail b, payAccountsPayable c, payPaymentRoute d, agnCompany e, actCurrency m, actCurrency n
where
$valor_ver_cxp 
$valor_contexto 
a.pkyPayment = b.codPayment and
a.fldDate >= '$fechaini' and
a.fldDate <= '$fechafin' and
b.codAccountsPayable = c.pkyAccountsPayable and
a.codRoute = d.pkyPaymentRoute and 
a.codClient = e.pkyCompany and 
a.codCurrency = c.codCurrency and 
a.codCurrency = m.pkyCurrency and 
c.codCurrency = n.pkyCurrency and 
a.sysEnabled = 1 and a.sysAuthorized = 1) t
where 
t.cod_moneda_cxp = '$otra_moneda') fin  
where   
$valor_cliente 
$valor_mostrar 
$valor_via 
fin.cod_pago is not null 
$valor_ordenar;");		

	//Pagos empleados
	$result6 = mysqli_query($link, "select fin.cod_pago as cod_pago, fin.nro_doc as nro_doc, fin.fecha as fecha, fin.cod_via as cod_via, fin.via as via, fin.cod_emp as cod_emp, fin.empresa_empleado as empresa_empleado, fin.cod_moneda_pago as cod_moneda_pago, fin.moneda_pago as moneda_pago, fin.cod_cxp as cod_cxp, fin.cod_banco as cod_banco, fin.cod_cheque as cod_cheque, fin.cod_caja as cod_caja, fin.cod_moneda_cxp as cod_moneda_cxp, fin.moneda_cxp as moneda_cxp, fin.monto_pagado as monto_pagado, fin.monto_reducido as monto_reducido, fin.saldo as saldo, fin.monto_reducido_om as monto_reducido_om, fin.saldo_om as saldo_om, fin.glosa as glosa, fin.papa as papa, fin.cod_papa as cod_papa
from(
select t.cod_pago as cod_pago, t.nro_doc as nro_doc, t.fecha as fecha, t.cod_via as cod_via, t.via as via, t.cod_emp as cod_emp, t.empleado as empresa_empleado, t.cod_moneda_pago as cod_moneda_pago, t.moneda_pago as moneda_pago, t.cod_cxp as cod_cxp, t.cod_banco as cod_banco, t.cod_cheque as cod_cheque, t.cod_caja as cod_caja, t.cod_moneda_cxp as cod_moneda_cxp, t.moneda_cxp as moneda_cxp, t.monto_pagado as monto_pagado, t.monto_reducido as monto_reducido, t.saldo as saldo, t.monto_reducido * tc.fldRate as monto_reducido_om, t.saldo * tc.fldRate as saldo_om, t.glosa as glosa, t.papa as papa, t.cod_papa as cod_papa
from (
select a.pkyPayment as cod_pago, a.fldDocumentNumber as nro_doc, a.fldDate as fecha, a.codRoute as cod_via, d.fldName as via, a.codEmployee as cod_emp, case when e.fldMiddleName is NULL then concat(e.fldLastName,', 
',e.fldFirstName) else concat(e.fldLastName,' ',e.fldMiddleName,', ',e.fldFirstName) end as empleado, a.codCurrency as cod_moneda_pago, m.fldName as moneda_pago, b.codAccountsPayable as cod_cxp, a.codBankMovement as cod_banco, a.codCheck as cod_cheque, a.codPettyCashMovement as cod_caja, c.codCurrency as cod_moneda_cxp, n.fldName as moneda_cxp, b.fldTotal * g.fldRate as monto_pagado, b.fldTotal as monto_reducido, c.fldBalance as saldo, a.txtDescription as glosa, a.fldParentComponent as papa, a.cosComponentKey as cod_papa
from payPayment a, payPaymentDetail b, payAccountsPayable c, payPaymentRoute d, agnPerson e, actExchangeRateDetail g, actCurrency m, actCurrency n
where
$valor_ver_cxp 
$valor_contexto 
a.pkyPayment = b.codPayment and
a.fldDate >= '$fechaini' and
a.fldDate <= '$fechafin' and
b.codAccountsPayable = c.pkyAccountsPayable and
a.codRoute = d.pkyPaymentRoute and 
a.codEmployee = e.pkyPerson and 
a.codCurrency != c.codCurrency and 
a.codExchangeRate = g.codExchangeRate and 
g.codBaseCurrency = a.codCurrency and 
g.codTargetCurrency = c.codCurrency and 
a.codCurrency = m.pkyCurrency and 
c.codCurrency = n.pkyCurrency and 
a.sysEnabled = 1 and a.sysAuthorized = 1
union all
select a.pkyPayment as cod_pago, a.fldDocumentNumber as nro_doc, a.fldDate as fecha, a.codRoute as cod_via, d.fldName as via, a.codEmployee as cod_emp, case when e.fldMiddleName is NULL then concat(e.fldLastName,', 
',e.fldFirstName) else concat(e.fldLastName,' ',e.fldMiddleName,', ',e.fldFirstName) end as empleado, a.codCurrency as cod_moneda_pago, m.fldName as moneda_pago, b.codAccountsPayable as cod_cxp, a.codBankMovement as cod_banco, a.codCheck as cod_cheque, a.codPettyCashMovement as cod_caja, c.codCurrency as cod_moneda_cxp, n.fldName as moneda_cxp, b.fldTotal * 1 as monto_pagado, b.fldTotal as monto_reducido, c.fldBalance as saldo, a.txtDescription as glosa, a.fldParentComponent as papa, a.cosComponentKey as cod_papa
from payPayment a, payPaymentDetail b, payAccountsPayable c, payPaymentRoute d, agnPerson e, actCurrency m, actCurrency n
where
$valor_ver_cxp 
$valor_contexto 
a.pkyPayment = b.codPayment and
a.fldDate >= '$fechaini' and
a.fldDate <= '$fechafin' and
b.codAccountsPayable = c.pkyAccountsPayable and
a.codRoute = d.pkyPaymentRoute and 
a.codEmployee = e.pkyPerson and  
a.codCurrency = c.codCurrency and 
a.codCurrency = m.pkyCurrency and 
c.codCurrency = n.pkyCurrency and 
a.sysEnabled = 1 and a.sysAuthorized = 1) t, actExchangeRateDetail tc 
where 
tc.codExchangeRate = '$ultimo_tc' and 
tc.codBaseCurrency = '$otra_moneda' and 
tc.codTargetCurrency = t.cod_moneda_cxp 

union all 

select t.cod_pago as cod_pago, t.nro_doc as nro_doc, t.fecha as fecha, t.cod_via as cod_via, t.via as via, t.cod_emp as cod_emp, t.empleado as empresa_empleado, t.cod_moneda_pago as cod_moneda_pago, t.moneda_pago as moneda_pago, t.cod_cxp as cod_cxp, t.cod_banco as cod_banco, t.cod_cheque as cod_cheque, t.cod_caja as cod_caja, t.cod_moneda_cxp as cod_moneda_cxp, t.moneda_cxp as moneda_cxp, t.monto_pagado as monto_pagado, t.monto_reducido as monto_reducido, t.saldo as saldo, t.monto_reducido * 1 as monto_reducido_om, t.saldo * 1 as saldo_om, t.glosa as glosa, t.papa as papa, t.cod_papa as cod_papa
from (
select a.pkyPayment as cod_pago, a.fldDocumentNumber as nro_doc, a.fldDate as fecha, a.codRoute as cod_via, d.fldName as via, a.codEmployee as cod_emp, case when e.fldMiddleName is NULL then concat(e.fldLastName,', 
',e.fldFirstName) else concat(e.fldLastName,' ',e.fldMiddleName,', ',e.fldFirstName) end as empleado, a.codCurrency as cod_moneda_pago, m.fldName as moneda_pago, b.codAccountsPayable as cod_cxp, a.codBankMovement as cod_banco, a.codCheck as cod_cheque, a.codPettyCashMovement as cod_caja, c.codCurrency as cod_moneda_cxp, n.fldName as moneda_cxp, b.fldTotal * g.fldRate as monto_pagado, b.fldTotal as monto_reducido, c.fldBalance as saldo, a.txtDescription as glosa, a.fldParentComponent as papa, a.cosComponentKey as cod_papa
from payPayment a, payPaymentDetail b, payAccountsPayable c, payPaymentRoute d, agnPerson e, actExchangeRateDetail g, actCurrency m, actCurrency n
where
$valor_ver_cxp 
$valor_contexto 
a.pkyPayment = b.codPayment and
a.fldDate >= '$fechaini' and
a.fldDate <= '$fechafin' and
b.codAccountsPayable = c.pkyAccountsPayable and
a.codRoute = d.pkyPaymentRoute and 
a.codEmployee = e.pkyPerson and  
a.codCurrency != c.codCurrency and 
a.codExchangeRate = g.codExchangeRate and 
g.codBaseCurrency = a.codCurrency and 
g.codTargetCurrency = c.codCurrency and 
a.codCurrency = m.pkyCurrency and 
c.codCurrency = n.pkyCurrency and 
a.sysEnabled = 1 and a.sysAuthorized = 1
union all
select a.pkyPayment as cod_pago, a.fldDocumentNumber as nro_doc, a.fldDate as fecha, a.codRoute as cod_via, d.fldName as via, a.codEmployee as cod_emp, case when e.fldMiddleName is NULL then concat(e.fldLastName,', 
',e.fldFirstName) else concat(e.fldLastName,' ',e.fldMiddleName,', ',e.fldFirstName) end as empleado, a.codCurrency as cod_moneda_pago, m.fldName as moneda_pago, b.codAccountsPayable as cod_cxp, a.codBankMovement as cod_banco, a.codCheck as cod_cheque, a.codPettyCashMovement as cod_caja, c.codCurrency as cod_moneda_cxp, n.fldName as moneda_cxp, b.fldTotal * 1 as monto_pagado, b.fldTotal as monto_reducido, c.fldBalance as saldo, a.txtDescription as glosa, a.fldParentComponent as papa, a.cosComponentKey as cod_papa
from payPayment a, payPaymentDetail b, payAccountsPayable c, payPaymentRoute d, agnPerson e, actCurrency m, actCurrency n
where
$valor_ver_cxp 
$valor_contexto 
a.pkyPayment = b.codPayment and
a.fldDate >= '$fechaini' and
a.fldDate <= '$fechafin' and
b.codAccountsPayable = c.pkyAccountsPayable and
a.codRoute = d.pkyPaymentRoute and 
a.codEmployee = e.pkyPerson and  
a.codCurrency = c.codCurrency and 
a.codCurrency = m.pkyCurrency and 
c.codCurrency = n.pkyCurrency and 
a.sysEnabled = 1 and a.sysAuthorized = 1) t
where 
t.cod_moneda_cxp = '$otra_moneda') fin  
where   
$valor_cliente 
$valor_mostrar 
$valor_via 
fin.cod_pago is not null 
$valor_ordenar;");			
?>
<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>Pagos</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>Ver Saldos: </b><?php echo $nom_mostrar; ?></TD>
        <TD width="25%"><b>Empresa/Empleado: </b><?php echo $nom_cliente; ?></TD>
        <TD width="25%"><b>V&iacute;a: </b><?php echo $nom_via_pago; ?></TD>
        <TD width="25%"><b>Contexto: </b><?php echo $nom_contexto; ?></TD>
        </TR>
        <TR>
        <TD colspan="2"><b>De Fecha: </b><?php echo $fechaini; ?> <b>a Fecha: </b><?php echo $fechafin; ?></TD>
        <TD><b>Ordenado por: </b><?php echo $nom_ordenar; ?></TD>
        <TD><b>Expresado en: </b><?php echo $nom_otra_moneda; ?></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></tr>", 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>Cod.</b></TD>
    <TD align="center"><b>Nro. Doc.</b></TD>
    <TD align="center"><b>Fecha</b></TD>
    <TD align="center"><b>V&iacute;a</b></TD>
    <TD align="center"><b>Empresa/Empleado</b></TD>
    <TD align="center"><b>CxP</b></TD>
    <TD align="center"><b>Banco</b></TD>
    <TD align="center"><b>Cheque</b></TD>
    <TD align="center"><b>Caja</b></TD>
    <TD align="center"><b>Gen. Por</b></TD>
    <TD align="center"><b>Mon. Pago</b></TD>
    <TD align="center"><b>Monto Pagado</b></TD>
    <TD align="center"><b>Mon. CxP</b></TD>
    <TD align="center"><b>Monto Reducido</b></TD>
    <TD align="center"><b>Saldo</b></TD>
    <TD align="center"><b>Monto Reducido en <?php echo $nom_otra_moneda; ?></b></TD>
    <TD align="center"><b>Saldo en <?php echo $nom_otra_moneda; ?></b></TD>
    <?php if($glosa_ver == 1) { ?>
    <TD align="center"><b>Glosa</b></TD>
    <?php } ?>
    </TR>
    </thead>
    <tbody class="marcafila">

  <?php
  $color = 2;
  $suma_total_red = 0;
  $suma_total_sal = 0;
  while ($row = mysqli_fetch_array($result5)) { //while
	
	//para enlazar al que genero el asiento
	$papa_componente = $row['papa'];
	$papa_codigo = $row['cod_papa'];
	//$usuario = $usuario_det;
	include "../../generadopor.php";
	
	$codigo = $row['cod_pago'];
	$cod_cxp = $row['cod_cxp'];
	$cod_banco = $row['cod_banco'];
	$cod_cheque = $row['cod_cheque'];
	$cod_caja = $row['cod_caja'];
	if($color % 2 == 0) { //if color
		printf("<tr BGCOLOR='#e2e7fa'><td align='center'><a href='../../ModulePayments/VoucherPayment/index.php?pkyPayment=$codigo&user=$usuario&token=$token' title='Nota de Pago'>%s</a></td>", $row['cod_pago']);//cod
	} else { 
		printf("<tr><td align='center'><a href='../../ModulePayments/VoucherPayment/index.php?pkyPayment=$codigo&user=$usuario&token=$token' title='Nota de Pago'>%s</a></td>", $row['cod_pago']);//cod
	} //cierra if color
	printf("<td align='center'>%s</td>", $row['nro_doc']);//nro doc
	printf("<td align='right'>%s</td>", $row['fecha']);//fecha
	printf("<td>%s</td>", $row['via']);// via
	printf("<td>%s</td>", $row['empresa_empleado']);// empresa
	printf("<td align='right'><a href='../../ModulePayments/VoucherAccountsPayable/index.php?pkyAccountsPayable=$cod_cxp&user=$usuario&token=$token' title='Nota de Cuenta por Pagar'>%s</a></td>", $row['cod_cxp']);// cod cxp
	printf("<td align='right'><a href='../../ModuleTreasury/VoucherBankMovement/index.php?pkyBankMovement=$cod_banco&user=$usuario&token=$token' title='Nota Movimiento Bancario'>%s</a></td>", $row['cod_banco']);// cod banco
	printf("<td align='right'><a href='../../ModuleTreasury/VoucherCheck/index.php?pkyCheck=$cod_cheque&user=$usuario&token=$token' title='Cheque'>%s</a></td>", $row['cod_cheque']);// cod cheque
	printf("<td align='right'><a href='../../ModulePettyCash/VoucherPettyCashMovement/index.php?pkyPettyCashMovement=$cod_caja&user=$usuario&token=$token' title='Nota de Movimiento de Caja'>%s</a></td>", $row['cod_caja']);// cod caja
	printf("<td align='center'>%s</td>", $papa_enlace);//gen por
	printf("<td align='center'>%s</td>", $row['moneda_pago']);// moneda de pago
	printf("<td align='right'>%s</td>", number_format($row['monto_pagado'],$n_decimales));//monto pagado
	printf("<td align='center'>%s</td>", $row['moneda_cxp']);// moneda cxp   
	printf("<td align='right'>%s</td>", number_format($row['monto_reducido'],$n_decimales));//monto reducido
	printf("<td align='right'>%s</td>", number_format($row['saldo'],$n_decimales));//saldo
	printf("<td align='right'>%s</td>", number_format($row['monto_reducido_om'],$n_decimales));//monto reducido om
	printf("<td align='right'>%s</td>", number_format($row['saldo_om'],$n_decimales));//saldo om
	if($glosa_ver == 1) {//if ver_glosa
	$glosa = $row['glosa'];
	$glosa = nl2br($glosa);
	$glosa = str_replace('\n','<br />',$glosa);
	printf("<td align='left'>%s</td>", $glosa);//glosa
	}//fin if ver_glosa
	echo '</tr>';
	

    $suma_total_red = $suma_total_red + $row['monto_reducido_om'];
    $suma_total_sal = $suma_total_sal + $row['saldo_om'];
    
	$color++;
 }//fin while

mysqli_free_result($result5);

?>
<tr BGCOLOR='#ffcccc'><td colspan="15"><b>Total Pagos Empresas</b></td>
<td align="right"><?php printf("<b>%s</b>", number_format($suma_total_red,$n_decimales)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($suma_total_sal,$n_decimales)); ?></td>
<?php if($glosa_ver == 1) { ?>
<td>&nbsp;</td>
<?php } ?>
</tr>

<?php
$color = 2;
  $suma_total_red2 = 0;
  $suma_total_sal2 = 0;
  while ($row = mysqli_fetch_array($result6)) { //while
	
	//para enlazar al que genero el asiento
	$papa_componente = $row['papa'];
	$papa_codigo = $row['cod_papa'];
	//$usuario = $usuario_det;
	include "../../generadopor.php";
	
	$codigo = $row['cod_pago'];
	$cod_cxp = $row['cod_cxp'];
	$cod_banco = $row['cod_banco'];
	$cod_cheque = $row['cod_cheque'];
	$cod_caja = $row['cod_caja'];
	if($color % 2 == 0) { //if color
		printf("<tr BGCOLOR='#e2e7fa'><td align='center'><a href='../../ModulePayments/VoucherPayment/index.php?pkyPayment=$codigo&user=$usuario&token=$token' title='Nota de Pago'>%s</a></td>", $row['cod_pago']);//cod
	} else { 
		printf("<tr><td align='center'><a href='../../ModulePayments/VoucherPayment/index.php?pkyPayment=$codigo&user=$usuario&token=$token' title='Nota de Pago'>%s</a></td>", $row['cod_pago']);//cod
	} //cierra if color
	printf("<td align='center'>%s</td>", $row['nro_doc']);//nro doc
	printf("<td align='right'>%s</td>", $row['fecha']);//fecha
	printf("<td>%s</td>", $row['via']);// via
	printf("<td>%s</td>", $row['empresa_empleado']);// empleado
	printf("<td align='right'><a href='../../ModulePayments/VoucherAccountsPayable/index.php?pkyAccountsPayable=$cod_cxp&user=$usuario&token=$token' title='Nota de Cuenta por Pagar'>%s</a></td>", $row['cod_cxp']);// cod cxp
	printf("<td align='right'><a href='../../ModuleTreasury/VoucherBankMovement/index.php?pkyBankMovement=$cod_banco&user=$usuario&token=$token' title='Nota Movimiento Bancario'>%s</a></td>", $row['cod_banco']);// cod banco
	printf("<td align='right'><a href='../../ModuleTreasury/VoucherCheck/index.php?pkyCheck=$cod_cheque&user=$usuario&token=$token' title='Cheque'>%s</a></td>", $row['cod_cheque']);// cod cheque
	printf("<td align='right'><a href='../../ModulePettyCash/VoucherPettyCashMovement/index.php?pkyPettyCashMovement=$cod_caja&user=$usuario&token=$token' title='Nota de Movimiento de Caja'>%s</a></td>", $row['cod_caja']);// cod caja
	printf("<td align='center'>%s</td>", $papa_enlace);//gen por
	printf("<td align='center'>%s</td>", $row['moneda_pago']);// moneda de pago
	printf("<td align='right'>%s</td>", number_format($row['monto_pagado'],$n_decimales));//monto pagado
	printf("<td align='center'>%s</td>", $row['moneda_cxp']);// moneda cxp   
	printf("<td align='right'>%s</td>", number_format($row['monto_reducido'],$n_decimales));//monto reducido
	printf("<td align='right'>%s</td>", number_format($row['saldo'],$n_decimales));//saldo
	printf("<td align='right'>%s</td>", number_format($row['monto_reducido_om'],$n_decimales));//monto reducido om
	printf("<td align='right'>%s</td>", number_format($row['saldo_om'],$n_decimales));//saldo om
	if($glosa_ver == 1) {//if ver_glosa
	$glosa = $row['glosa'];
	$glosa = nl2br($glosa);
	$glosa = str_replace('\n','<br />',$glosa);
	printf("<td align='left'>%s</td>", $glosa);//glosa
	}//fin if ver_glosa
	echo '</tr>';
	

    $suma_total_red2 = $suma_total_red2 + $row['monto_reducido_om'];
    $suma_total_sal2 = $suma_total_sal2 + $row['saldo_om'];
    
	$color++;
 }//fin while

mysqli_free_result($result6);

?>
<tr BGCOLOR='#ffcccc'><td colspan="15"><b>Total Pagos Empleados</b></td>
<td align="right"><?php printf("<b>%s</b>", number_format($suma_total_red2,$n_decimales)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($suma_total_sal2,$n_decimales)); ?></td>
<?php if($glosa_ver == 1) { ?>
<td>&nbsp;</td>
<?php } ?>
</tr>

<tr BGCOLOR='#ffcccc'><td colspan="15"><b>Total Pagos Empresas y Empleados</b></td>
<td align="right"><?php printf("<b>%s</b>", number_format($suma_total_red + $suma_total_red2,$n_decimales)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($suma_total_sal + $suma_total_sal2,$n_decimales)); ?></td>
<?php if($glosa_ver == 1) { ?>
<td>&nbsp;</td>
<?php } ?>
</tr>
</tbody>
</table>
<?php 
	}//fin if 2.4
	
} //fin if 2



?>

</body>
</html>
