<!DOCTYPE html>
<html lang="es-ES">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Nota de Planilla de Sueldos</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 "../../class.nroenletraver2.php";
include "../../general.php";
include "../../token.php";

//index.php?pkySalaryPayroll=1&printAccountEntry=1&user=Luigi&token=123456
$rep=$_GET["rep"];
$tipo=$_GET["tipo"];
$muestra_asiento = $_GET["printAccountEntry"];

$cod_plan = $_GET["pkySalaryPayroll"];
//$usuario = $_GET["user"];

//$n_cantidad = 6;
if($rep == 1) { $muestra_cc = 1; }
if($rep == 2) { $muestra_cc = 0; }
?>
<body>

<?php

// Inicio impresion planilla de sueldos

$result = mysqli_query($link, "select a.pkySalaryPayroll as cod_plan, a.fldDocumentNumber as nro_doc, a.fldDate as fecha, a.fldPeriod as periodo, a.codExchangeRate as cod_tc, a.txtDescription as glosa, a.fldManWorkingDays as dias_trabajo_hombre, a.fldWomanWorkingDays as dias_trabajo_mujer, a.sysEnabled as enabled, a.sysAuthorized as authorized, g.fldName as usuario_reg, a.sysContext as cod_contexto, s.fldName as contexto, a.codAccountEntry as cod_asiento
from hrsSalaryPayroll a, accGroup g, srvContext s
where 
a.sysAuthorizationGroup = g.pkyGroup and
a.sysContext = s.pkyContext and 
a.pkySalaryPayroll = '$cod_plan';");
	while ($row = mysqli_fetch_array($result)) {
		$nro_doc = $row['nro_doc'];
		$fecha = $row['fecha'];
		$periodo = $row['periodo'];
		$cod_tc = $row['cod_tc'];
		$cod_asiento = $row['cod_asiento'];
		$glosa = $row['glosa'];
		$glosa = nl2br($glosa);//quita salto de linea 
		$glosa = str_replace('\n','<br />',$glosa);//reemplaza para salto de linea
		$dias_trabajo_hombre = $row['dias_trabajo_hombre'];
		$dias_trabajo_mujer = $row['dias_trabajo_mujer'];
		$usuario_reg = $row['usuario_reg'];
		$enabled = $row['enabled'];
		$authorized = $row['authorized'];
		$cod_contexto = $row['cod_contexto'];
		$contexto = $row['contexto'];
	}
	mysqli_free_result($result);
	

$resulttc = mysqli_query($link, "select pkyExchangeRate as cod_tc, fldDate as fecha, fldTime as hora
from
actExchangeRate
where
pkyExchangeRate = '$cod_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 = '$cod_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;


$result2 = mysqli_query($link, "select a.pkySalaryPayrollDetail as cod_plan_det, a.codSalaryPayroll as cod_plan, a.codEmployee as cod_empleado, case when b.fldOtherNames is NULL then case when b.fldMiddleName is NULL then concat(b.fldLastName,', ',b.fldFirstName) else concat(b.fldLastName,' ',b.fldMiddleName,', ',b.fldFirstName) end else case when b.fldMiddleName is NULL then concat(b.fldLastName,', ',b.fldFirstName,' ',b.fldOtherNames) else concat(b.fldLastName,' ',b.fldMiddleName,', ',b.fldFirstName,' ',b.fldOtherNames) end end as empleado, c.fldName as ciudad, d.fldName as sucursal, e.fldName as cargo, a.fldHealthFundCode as caja_salud, a.fldDocumentNumber as nro_cont, a.fldSeniority as antiguedad, a.fldHiringDate as fecha_cont, f.fldName as estado_civil, a.fldVAT as iva, a.fldWorkedTime as tiempo_trab, a.fldVacation as vacaciones, a.fldAbsences as faltas, a.fldSundayAbsences as faltas_domingo, a.fldSick as enfermedad, a.fldOther as otros, a.fldBasicSalary as salario, a.fldExtraHours as horas_extra, a.fldExtraHoursAmount as monto_horas_extra, a.fldChargeHours as horas_recargo, a.fldChargeHoursAmount as monto_horas_recargo, a.fldSundayHours as horas_domingo, a.fldSundayHoursAmount as monto_horas_domingo, a.fldExtraodinaryHours as horas_extraordinarias, a.fldExtraodinaryHoursAmount as monto_horas_extraordinarias, a.fldHolidayHours as horas_feriado, a.fldHolidayHoursAmount as monto_horas_feriado, a.fldVariousIncome as monto_ing_varios, a.fldSeniorityBonus as monto_antiguedad, a.fldSalary as haber_ganado, a.fldAFP as monto_afp, a.fldDiscounts as monto_dctos_varios, a.fldAbsencesDiscounts as monto_dctos_faltas, a.fldSpecialDiscounts as monto_dcto_solidario, a.fldAccumulatedVAT as monto_imp_acum, a.fldVATAdjust as monto_act_imp, a.fldAdjustedVAT as monto_imp_periodo, a.fldVATDiscounts as monto_dcto_impuestos, a.fldTotalSalary as liquido_pagable, b.codGender as cod_sexo
from hrsSalaryPayrollDetail a, agnPerson b, regCity c, agnCompanyBranch d, hrsJob e, agnMaritalStatus f
where 
a.codEmployee = b.pkyPerson and
a.codCity = c.pkyCity and 
a.codBranch = d.pkyCompanyBranch and 
a.codJob = e.pkyJob and 
a.codMaritalStatus = f.pkyMaritalStatus and 
a.codSalaryPayroll = '$cod_plan' 
order by empleado;");


?>
<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>Nota de Planilla de Sueldos</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>Cod. Reg.: </b><?php echo $cod_plan; ?></TD>
        <TD width="25%"><b>Nro. Doc.: </b><?php echo $nro_doc; ?></TD>
        <TD width="25%"><b>Fecha de Reg.: </b><?php echo $fecha; ?></TD>
        <TD width="25%"><b>Periodo: </b><?php echo substr($periodo, 0,-3); ?></TD>
        </TR>
        <TR>
        <TD colspan="2"><b>Asiento: </b><a href="../../ModuleAccounting/VoucherAccountEntry/index.php?pkyAccountEntry=<?php echo $cod_asiento; ?>&showCC=<?php echo $mostrar_asiento_cc; ?>&user=<?php echo $usuario; ?>&token=<?php echo $token; ?>" title="Asiento Contable"><?php echo $cod_asiento; ?></a>
		<table border="0" align="right"><tr><td>
		<?php if($muestra_asiento == 0) { ?>
			<a href="../../ModuleHumanResources/VoucherSalaryPayroll/index.php?pkySalaryPayroll=<?php echo $cod_plan; ?>&printAccountEntry=1&user=<?php echo $usuario; ?>&token=<?php echo $token; ?>" title="Mostrar Asiento Contable" style="text-decoration:none; color:#0000FF; font-style:normal;"> + </a>
		<?php } else { ?>
			<a href="../../ModuleHumanResources/VoucherSalaryPayroll/index.php?pkySalaryPayroll=<?php echo $cod_plan; ?>&printAccountEntry=0&user=<?php echo $usuario; ?>&token=<?php echo $token; ?>" title="Ocultar Asiento Contable" style="text-decoration:none; color:#0000FF; font-style:normal;"> - </a>
        <?php } ?>
		</td></tr></table>
		</TD>
        <TD colspan="2"><b>Contexto: </b><?php echo $cod_contexto; ?> - <?php echo $contexto; ?></TD>
        </TR>
        <TR>
        <TD colspan="4"><b>Glosa: </b><?php echo $glosa; ?></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 $cod_tc; ?>&user=<?php echo $usuario; ?>&token=<?php echo $token; ?>" title="Tipo de Cambio"><?php echo $cod_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. Empleado</b></TD>
    <TD align="center"><b>Empleado</b></TD>
    <TD align="center"><b>Ciudad</b></TD>
    <TD align="center"><b>Sucursal</b></TD>
    <TD align="center"><b>Cargo</b></TD>
    <TD align="center"><b>Cod. Caja Nal. Salud</b></TD>
    <TD align="center"><b>Nro. Contrato</b></TD>
    <TD align="center"><b>Antig&uuml;edad (Meses)</b></TD>
    <TD align="center"><b>Contrataci&oacute;n</b></TD>
    <TD align="center"><b>Estado Civil</b></TD>
    <TD align="center"><b>IVA</b></TD>
    <TD align="center"><b>Tiempo Trabajado</b></TD>
    <TD align="center"><b>Vacaciones</b></TD>
    <TD align="center"><b>Faltas</b></TD>
    <TD align="center"><b>Faltas Domingo (D&iacute;as)</b></TD>
    <TD align="center"><b>Enfermedad (D&iacute;as)</b></TD>
    <TD align="center"><b>Otros</b></TD>
    <TD align="center"><b>Salario</b></TD>
    <TD align="center"><b>Salario por Tiempo Trabajado</b></TD>
    <TD align="center"><b>Horas Extra</b></TD>
    <TD align="center"><b>Monto Horas Extra</b></TD>
    <TD align="center"><b>Horas Recargo</b></TD>
    <TD align="center"><b>Monto Horas Recargo</b></TD>
    <TD align="center"><b>Horas Domingo</b></TD>
    <TD align="center"><b>Monto Horas Domingo</b></TD>
    <TD align="center"><b>Horas Extraordinarias</b></TD>
    <TD align="center"><b>Monto Horas Extraordinarias</b></TD>
    <TD align="center"><b>Horas Feriados</b></TD>
    <TD align="center"><b>Monto Horas Feriados</b></TD>
    <TD align="center"><b>Monto Ing. Varios</b></TD>
    <TD align="center"><b>Monto Antig&uuml;edad</b></TD>
    <TD align="center"><b>Haber Ganado</b></TD>
    <TD align="center"><b>Monto AFP</b></TD>
    <TD align="center"><b>Monto Dctos. Varios</b></TD>
    <TD align="center"><b>Monto Dctos. Faltas</b></TD>
    <TD align="center"><b>Monto Solidario</b></TD>
    <TD align="center"><b>Monto IVA Acumulado mes Ant.</b></TD>
    <TD align="center"><b>Monto IVA Actualizado mes Ant.</b></TD>
    <TD align="center"><b>Monto IVA Act. Acum. mes Ant.</b></TD>
    <TD align="center"><b>Monto Dcto. Impuestos</b></TD>
    <TD align="center"><b>L&iacute;quido Pagable</b></TD>
    <!--<TD align="center"><b>Monto Total Horas Extra</b></TD>
    <TD align="center"><b>Monto Total Horas Recargo</b></TD>
    <TD align="center"><b>Haber Ganado</b></TD>-->
    </TR>
    </thead>
    <tbody class="marcafila">
    <?php
    $color = 2;
	$suma_ant = 0;
	$suma_iva = 0;
	$suma_tiempo_trab = 0;
	$suma_vaca = 0;
	$suma_faltas = 0;
	$suma_faltas_dom = 0;
	$suma_enf = 0;
	$suma_otros = 0;
	$suma_salario = 0;
	$suma_salario_x_tiempo_trabajado = 0;
	$suma_hrs_ext = 0;
	$suma_monto_hrs_ext = 0;
	$suma_hrs_rec = 0;
	$suma_monto_hrs_rec = 0;
	$suma_hrs_dom = 0;
	$suma_monto_hrs_dom = 0;
	$suma_hrs_extraor = 0;
	$suma_monto_hrs_extraor = 0;
	$suma_hrs_fer = 0;
	$suma_monto_hrs_fer = 0;
	$suma_monto_ing_varios = 0;
	$suma_monto_ant = 0;
	$suma_haber_ganado = 0;
	$suma_monto_afp = 0;
	$suma_monto_desc_varios = 0;
	$suma_monto_desc_faltas = 0;
	$suma_monto_desc_sol = 0;
	$suma_monto_iva_acum = 0;
	$suma_monto_iva_act = 0;
	$suma_monto_iva_act_acum = 0;
	$suma_monto_desc_imp = 0;
	$suma_liquido_pag = 0;
	
	while ($row = mysqli_fetch_array($result2)) { //while
	
		$cod_persona = $row['cod_empleado'];
		if($color % 2 == 0) { //if color
		printf("<tr BGCOLOR='#e2e7fa'><td align='center'><a href='../../ModuleAgenda/VoucherPerson/index.php?pkyPerson=$cod_persona&user=$usuario&token=$token' title='Persona'>%s</a></td>", $row['cod_empleado']);//cod empleado
		} else {
		printf("<tr><td align='center'><a href='../../ModuleAgenda/VoucherPerson/index.php?pkyPerson=$cod_persona&user=$usuario&token=$token' title='Persona'>%s</a></td>", $row['cod_empleado']);//cod empleado
		} //cierra if color
		printf("<td align='left'>%s</td>", $row['empleado']);//empleado
		
		printf("<td align='left'>%s</td>", $row['ciudad']);//ciudad
		printf("<td align='left'>%s</td>", $row['sucursal']);//sucursal
		printf("<td align='left'>%s</td>", $row['cargo']);//cargo
		printf("<td align='right'>%s</td>", $row['caja_salud']);//caja salud
		printf("<td align='right'>%s</td>", $row['nro_cont']);//nro_cont
		printf("<td align='right'>%s</td>", number_format($row['antiguedad'],$n_cantidad));//antiguedad
		printf("<td align='right'>%s</td>", $row['fecha_cont']);//fecha contratacion
		printf("<td align='left'>%s</td>", $row['estado_civil']);//estado civil
		printf("<td align='right'>%s</td>", number_format($row['iva'],$n_decimales));//iva
		printf("<td align='right'>%s</td>", number_format($row['tiempo_trab'],$n_cantidad));//tiempo trabajado
		printf("<td align='right'>%s</td>", number_format($row['vacaciones'],$n_cantidad));//vacaciones
		printf("<td align='right'>%s</td>", number_format($row['faltas'],$n_cantidad));//faltas
		printf("<td align='right'>%s</td>", number_format($row['faltas_domingo'],$n_cantidad));//faltas domingo
		printf("<td align='right'>%s</td>", number_format($row['enfermedad'],$n_cantidad));//enfermedad dias
		printf("<td align='right'>%s</td>", number_format($row['otros'],$n_cantidad));//otros
		printf("<td align='right'>%s</td>", number_format($row['salario'],$n_decimales));//salario
		
		if($row['cod_sexo'] == 1) {
		$salario_dia = $row['salario']/$dias_trabajo_hombre; //salario dia
		} else {
		$salario_dia = $row['salario']/$dias_trabajo_mujer; //salario dia
		}
		$salario_dias_trabajados_mes = $salario_dia * ($row['tiempo_trab']+$row['faltas']); //salario por dias trabajados en el mes (Sumo tiempo trabajado + faltas porque se paga por los dias trabajados aunque falten, solo se paga por menos dias si entro a trabajar a medio mes o salió a medio mes)
		printf("<td align='right'>%s</td>", number_format($salario_dias_trabajados_mes,$n_decimales));//salario dias trabajados mes
		
		printf("<td align='right'>%s</td>", number_format($row['horas_extra'],$n_cantidad));//horas extra
		printf("<td align='right'>%s</td>", number_format($row['monto_horas_extra'],$n_decimales));//monto horas extra
		printf("<td align='right'>%s</td>", number_format($row['horas_recargo'],$n_cantidad));//horas recargo
		printf("<td align='right'>%s</td>", number_format($row['monto_horas_recargo'],$n_decimales));//monto horas recargo
		printf("<td align='right'>%s</td>", number_format($row['horas_domingo'],$n_cantidad));//horas domingo
		printf("<td align='right'>%s</td>", number_format($row['monto_horas_domingo'],$n_decimales));//monto horas domingo
		printf("<td align='right'>%s</td>", number_format($row['horas_extraordinarias'],$n_cantidad));//horas extraordinarias
		printf("<td align='right'>%s</td>", number_format($row['monto_horas_extraordinarias'],$n_decimales));//monto horas extraordinarias
		printf("<td align='right'>%s</td>", number_format($row['horas_feriado'],$n_cantidad));//horas feriado
		printf("<td align='right'>%s</td>", number_format($row['monto_horas_feriado'],$n_decimales));//monto horas feriado
		printf("<td align='right'>%s</td>", number_format($row['monto_ing_varios'],$n_decimales));//monto ing varios
		printf("<td align='right'>%s</td>", number_format($row['monto_antiguedad'],$n_decimales));//monto antiguedad
		printf("<td align='right'>%s</td>", number_format($row['haber_ganado'],$n_decimales));//haber ganado
		printf("<td align='right'>%s</td>", number_format($row['monto_afp'],$n_decimales));//monto afp
		printf("<td align='right'>%s</td>", number_format($row['monto_dctos_varios'],$n_decimales));//monto dctos varios
		printf("<td align='right'>%s</td>", number_format($row['monto_dctos_faltas'],$n_decimales));//monto dctos faltas
		printf("<td align='right'>%s</td>", number_format($row['monto_dcto_solidario'],$n_decimales));//monto solidario
		printf("<td align='right'>%s</td>", number_format($row['monto_imp_acum'],$n_decimales));//monto iva acumulado
		printf("<td align='right'>%s</td>", number_format($row['monto_act_imp'],$n_decimales));//monto iva actualizacion
		printf("<td align='right'>%s</td>", number_format($row['monto_imp_periodo'],$n_decimales));//monto iva actualizado acumulado
		printf("<td align='right'>%s</td>", number_format($row['monto_dcto_impuestos'],$n_decimales));//monto dcto impuestos
		printf("<td align='right'>%s</td></tr>", number_format($row['liquido_pagable'],$n_decimales));//monto liquido pagable
		
	
		$suma_ant = $suma_ant + $row['antiguedad'];
		$suma_iva = $suma_iva + $row['iva'];
		$suma_tiempo_trab = $suma_tiempo_trab + $row['tiempo_trab'];
		$suma_vaca = $suma_vaca + $row['vacaciones'];
		$suma_faltas = $suma_faltas + $row['faltas'];
		$suma_faltas_dom = $suma_faltas_dom + $row['faltas_domingo'];
		$suma_enf = $suma_enf + $row['enfermedad'];
		$suma_otros = $suma_otros + $row['otros'];
		$suma_salario = $suma_salario + $row['salario'];
		$suma_salario_x_tiempo_trabajado = $suma_salario_x_tiempo_trabajado + $salario_dias_trabajados_mes;
		$suma_hrs_ext = $suma_hrs_ext + $row['horas_extra'];
		$suma_monto_hrs_ext = $suma_monto_hrs_ext + $row['monto_horas_extra'];
		$suma_hrs_rec = $suma_hrs_rec + $row['horas_recargo'];
		$suma_monto_hrs_rec = $suma_monto_hrs_rec + $row['monto_horas_recargo'];
		$suma_hrs_dom = $suma_hrs_dom + $row['horas_domingo'];
		$suma_monto_hrs_dom = $suma_monto_hrs_dom + $row['monto_horas_domingo'];
		$suma_hrs_extraor = $suma_hrs_extraor + $row['horas_extraordinarias'];
		$suma_monto_hrs_extraor = $suma_monto_hrs_extraor + $row['monto_horas_extraordinarias'];
		$suma_hrs_fer = $suma_hrs_fer + $row['horas_feriado'];
		$suma_monto_hrs_fer = $suma_monto_hrs_fer + $row['monto_horas_feriado'];
		$suma_monto_ing_varios = $suma_monto_ing_varios + $row['monto_ing_varios'];
		$suma_monto_ant = $suma_monto_ant + $row['monto_antiguedad'];
		$suma_haber_ganado = $suma_haber_ganado + $row['haber_ganado'];
		$suma_monto_afp = $suma_monto_afp + $row['monto_afp'];
		$suma_monto_desc_varios = $suma_monto_desc_varios + $row['monto_dctos_varios'];
		$suma_monto_desc_faltas = $suma_monto_desc_faltas + $row['monto_dctos_faltas'];
		$suma_monto_desc_sol = $suma_monto_desc_sol + $row['monto_dcto_solidario'];
		$suma_monto_iva_acum = $suma_monto_iva_acum + $row['monto_imp_acum'];
		$suma_monto_iva_act = $suma_monto_iva_act + $row['monto_act_imp'];
		$suma_monto_iva_act_acum = $suma_monto_iva_act_acum + $row['monto_imp_periodo'];
		$suma_monto_desc_imp = $suma_monto_desc_imp + $row['monto_dcto_impuestos'];
		$suma_liquido_pag = $suma_liquido_pag + $row['liquido_pagable'];
		$color++;
	}//fin while
	mysqli_free_result($result2);
	
	//convierte el total en literal
	/*
	$letras=new NroEnLetra($suma_total,2);
	
	$mostrar_letras = ucfirst($letras->getLetra());
	
	$busca_espacio = substr($mostrar_letras,-6,1);
	if($busca_espacio == ' ') {
		$fin_letras = substr($mostrar_letras,-5);
		$mostrar_letras = substr($mostrar_letras,0,-5);
		$mostrar_letras = $mostrar_letras .'0'. $fin_letras;
	}
	$resultmoneda = mysqli_query($link, "select txtDescription as nom_moneda
	from actCurrency
	where
	pkyCurrency = '$cod_moneda';");
	while ($row = mysqli_fetch_array($resultmoneda)) {
		$nom_moneda_letras_tot = $row['nom_moneda'];
	}
	mysqli_free_result($resultmoneda);
	*/
	?>
	<tr BGCOLOR='#ffcccc'>
    <!--
    <td colspan="8"><b>Total &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <?php echo $mostrar_letras; ?> <?php echo $nom_moneda_letras_tot; ?></b></td>
    -->
    <td colspan="7"><b>Total</b></td>
    <td align="right"><b><?php echo number_format($suma_ant,$n_cantidad); ?></b></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td align="right"><b><?php echo number_format($suma_iva,$n_decimales); ?></b></td>
    <td align="right"><b><?php echo number_format($suma_tiempo_trab,$n_cantidad); ?></b></td>
    <td align="right"><b><?php echo number_format($suma_vaca,$n_cantidad); ?></b></td>
    <td align="right"><b><?php echo number_format($suma_faltas,$n_cantidad); ?></b></td>
    <td align="right"><b><?php echo number_format($suma_faltas_dom,$n_cantidad); ?></b></td>
    <td align="right"><b><?php echo number_format($suma_enf,$n_cantidad); ?></b></td>
    <td align="right"><b><?php echo number_format($suma_otros,$n_cantidad); ?></b></td>
    <td align="right"><b><?php echo number_format($suma_salario,$n_decimales); ?></b></td>
    <td align="right"><b><?php echo number_format($suma_salario_x_tiempo_trabajado,$n_decimales); ?></b></td>
    <td align="right"><b><?php echo number_format($suma_hrs_ext,$n_cantidad); ?></b></td>
    <td align="right"><b><?php echo number_format($suma_monto_hrs_ext,$n_decimales); ?></b></td>
    <td align="right"><b><?php echo number_format($suma_hrs_rec,$n_cantidad); ?></b></td>
    <td align="right"><b><?php echo number_format($suma_monto_hrs_rec,$n_decimales); ?></b></td>
    <td align="right"><b><?php echo number_format($suma_hrs_dom,$n_cantidad); ?></b></td>
    <td align="right"><b><?php echo number_format($suma_monto_hrs_dom,$n_decimales); ?></b></td>
    <td align="right"><b><?php echo number_format($suma_hrs_extraor,$n_cantidad); ?></b></td>
    <td align="right"><b><?php echo number_format($suma_monto_hrs_extraor,$n_decimales); ?></b></td>
    <td align="right"><b><?php echo number_format($suma_hrs_fer,$n_cantidad); ?></b></td>
    <td align="right"><b><?php echo number_format($suma_monto_hrs_fer,$n_decimales); ?></b></td>
    <td align="right"><b><?php echo number_format($suma_monto_ing_varios,$n_decimales); ?></b></td>
    <td align="right"><b><?php echo number_format($suma_monto_ant,$n_decimales); ?></b></td>
    <td align="right"><b><?php echo number_format($suma_haber_ganado,$n_decimales); ?></b></td>
    <td align="right"><b><?php echo number_format($suma_monto_afp,$n_decimales); ?></b></td>
    <td align="right"><b><?php echo number_format($suma_monto_desc_varios,$n_decimales); ?></b></td>
    <td align="right"><b><?php echo number_format($suma_monto_desc_faltas,$n_decimales); ?></b></td>
    <td align="right"><b><?php echo number_format($suma_monto_desc_sol,$n_decimales); ?></b></td>
    <td align="right"><b><?php echo number_format($suma_monto_iva_acum,$n_decimales); ?></b></td>
    <td align="right"><b><?php echo number_format($suma_monto_iva_act,$n_decimales); ?></b></td>
    <td align="right"><b><?php echo number_format($suma_monto_iva_act_acum,$n_decimales); ?></b></td>
    <td align="right"><b><?php echo number_format($suma_monto_desc_imp,$n_decimales); ?></b></td>
    <td align="right"><b><?php echo number_format($suma_liquido_pag,$n_decimales); ?></b></td>
    </tr>
</tbody>    
</table>
<br />
<?php
    if($enabled == 0){
				printf("<table border='0' align='center' cellpadding='2' width='600'><tr><td align='center'><font color='#FF0000' size='+1'>REGISTRO ANULADO</font></td></tr></table>");
			}
	if($authorized == 0){
				printf("<table border='0' align='center' cellpadding='2' width='600'><tr><td align='center'><font color='#FF0000' size='+1'>REGISTRO PENDIENTE DE AUTORIZACI&Oacute;N</font></td></tr></table>");
			}

?>

<?php
if($muestra_asiento == 1) {//if muestra_asiento 1
	
	if($cod_asiento != NULL){//if cod_asiento
		$result3 = mysqli_query($link, "select a.pkyAccountEntry as cod_mov_det, a.fldTransactionNumber as nro_trans, a.fldDocumentNumber as nro_doc, a.fldDate as fecha, b.fldName as tipo, a.codExchangeRate as cod_tc, a.txtDescription as glosa, a.sysEnabled as enabled, a.sysAuthorized as authorized
from actAccountEntry a, actAccountEntryType b
where
a.pkyAccountEntry = '$cod_asiento' and
a.codType = b.pkyAccountEntryType;");
		while ($row = mysqli_fetch_array($result3)) {
		$cod_asiento2 = $row['cod_mov_det'];
		$nro_trans2 = $row['nro_trans'];
		$nro_doc2 = $row['nro_doc'];
		$fecha_asiento2 = $row['fecha'];
		$tipo_asiento2 = $row['tipo'];
		$cod_tc2 = $row['cod_tc'];
		$glosa2 = $row['glosa'];
		$glosa2 = nl2br($glosa2);
		$glosa2 = str_replace('\n','<br />',$glosa2);
		$enabled2 = $row['enabled'];
		$authorized2 = $row['authorized'];
		}
		mysqli_free_result($result3);
		
		$result6 = mysqli_query($link, "select a.pkyAccountEntryDetail as cod_asiento_det, a.codAccountEntry as cod_asiento, a.codAccount as cod_cuenta, b.fldName as nom_cuenta, a.fldDebit as debe, a.fldCredit as haber
from actAccountEntryDetail a, actAccount b
where
a.codAccountEntry = '$cod_asiento2' and
a.codAccount = b.pkyAccount 
order by haber, cod_asiento_det;");
		
		if($muestra_cc == 1){
		$texto_asiento = '<a href="../../ModuleHumanResources/VoucherSalaryPayroll/index.php?pkySalaryPayroll='.$cod_plan.'&printAccountEntry=1&rep=2&user='.$usuario.'&token='.$token.'" title="Asiento Contable, Sin Centros de Costo" style="text-decoration:none; color:#000099; font-style:normal;">Asiento Contable, Con Centros de Costo</a>';
		} else {
		$texto_asiento = '<a href="../../ModuleHumanResources/VoucherSalaryPayroll/index.php?pkySalaryPayroll='.$cod_plan.'&printAccountEntry=1&rep=1&user='.$usuario.'&token='.$token.'" title="Asiento Contable, Con Centros de Costo" style="text-decoration:none; color:#000099; font-style:normal;">Asiento Contable</a>';
		}
		$control_vista_asiento = 1;
	} else {//else cod_asiento
		$texto_asiento = "Asiento Contable<br /><br /><table border='0' align='center' cellpadding='2' width='600'><tr><td align='center'><font color='#FF0000' size='+1'>NO EXISTE ASIENTO CONTABLE ASOCIADO A ESTE MOVIMIENTO</font></td></tr></table>";
		$enabled2 = 1;
		$authorized2 = 1;
		$control_vista_asiento = 0;
	}//fin if else cod_asiento
	
	
?>
<p>&nbsp;</p>
<p><center><font color="#000099"><b><?php echo $texto_asiento; ?></b></font></center></p>
<?php
if($control_vista_asiento == 1) {//if $control_vista_asiento = 1
?>
<table border="1" align="center" cellpadding="2" width="100%">
	<TR> 
	<TD width="25%"><b>Cod. Reg.: </b><?php echo $cod_asiento2; ?></TD>
    <TD width="25%"><b>Nro. Doc.: </b><?php echo $nro_doc2; ?></TD>
    <TD width="25%"><b>Moneda: </b><?php echo $nom_moneda_principal; ?></TD>
    <TD width="25%"><b>Fecha de Reg.: </b><?php echo $fecha_asiento2; ?></TD>
    </TR>
    <TR>
    <TD colspan="2"><b>Tipo de Asiento: </b><?php echo $tipo_asiento2; ?></TD>
    <TD colspan="2"><b>Nro. Transacci&oacute;n: </b><?php echo $nro_trans2; ?></TD>
    </TR>
    <TR>
    <TD colspan="4"><b>Glosa: </b><?php echo $glosa2; ?></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>Cod. Asiento</b></TD>
    <TD align="center"><b>Cod. Cuenta</b></TD>
    <TD align="center"><b>Cuenta</b></TD>
    <TD align="center"><b>Debe</b></TD>
    <TD align="center"><b>Haber</b></TD>
    </TR>
    </thead>
    <tbody class="marcafila">
    <?php
    $color = 2;
	$suma_debe = 0;
	$suma_haber = 0;
	while ($row = mysqli_fetch_array($result6)) { //while 6
		$cod_detalle_ = $row['cod_asiento_det'];
		$cod_asiento_ = $row['cod_asiento'];//cod asiento
		$cod_cuenta_ = $row['cod_cuenta'];//cod cuenta
		$nom_cuenta_ = $row['nom_cuenta'];//nombre cuenta
		if($mi_cod_pais == 1) {
		$debe_ = $row['debe'];
		$haber_ = $row['haber'];
		}
		if($mi_cod_pais == 176) {
		$debe_ = round($row['debe'], $n_decimales);
		$haber_ = round($row['haber'], $n_decimales);
		}
			$result7 = mysqli_query($link, "select a.codCostCenter as cod_cc, b.fldName as nombre, b.codType as cod_tipo_cc, c.fldName as tipo_cc, a.fldPercent as porcentaje
			from
			actAccountEntryDetailCC a, actCostCenter b, actCostCenterType c
			where
			a.codAccountEntryDetail = '$cod_detalle_' and 
			a.codCostCenter = b.pkyCostCenter and 
			b.codType = c.pkyCostCenterType;");
			$matriz_cc = array();
			$c = 1;
			while ($row = mysqli_fetch_array($result7)) {
			$matriz_cc [$c][1] = $row['cod_cc'];
			$matriz_cc [$c][2] = $row['nombre'];
			$matriz_cc [$c][3] = $row['porcentaje'];
			$matriz_cc [$c][4] = $row['porcentaje'] / 100 * $debe_;
			$matriz_cc [$c][5] = $row['porcentaje'] / 100 * $haber_;
			$matriz_cc [$c][6] = $row['cod_tipo_cc'];
			$matriz_cc [$c][7] = $row['tipo_cc'];
			$c++;
			}
			mysqli_free_result($result7);
			$fin_cc = $c - 1;
			
		if($color % 2 == 0) { //if color
		printf("<tr BGCOLOR='#e2e7fa'><td align='center'>%s</td>", $cod_detalle_);//cod 
		} else {
		printf("<tr><td align='center'>%s</td>", $cod_detalle_);//cod
		} //cierra if color
		printf("<td align='center'>%s</td>", $cod_asiento_);//cod asiento
		printf("<td align='center'>%s</td>", $cod_cuenta_);//cod cuenta
		if($muestra_cc == 0) {//if muestra_cc = 0
			if($haber_ == 0) { //if identado haber
				printf("<td align='left'>%s</td>", $nom_cuenta_);//nombre cuenta
			} else {
				printf("<td align='left'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;%s</td>", $nom_cuenta_);//nombre cuenta
			} //fin if identado haber
		} else {
			$sum_porc_cc = 0;
			$sum_cc = 0;
			if($haber_ == 0) { //if identado haber2
				echo "<td align='left'>" .$nom_cuenta_. "<br/>";
			} else {
				echo "<td align='left'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" .$nom_cuenta_. "<br/>";
			} //fin if identado haber2
			$fila_titulo_cc = 0;
			echo "<table border='0' align='left' cellpadding='2'>";
			for($c = 1; $c <= $fin_cc; $c++){//for $c
				//si el cod_tipo es diferente de 0 para mostrar el titulo en cada grupo de cc
				if($fila_titulo_cc != $matriz_cc [$c][6]){
					echo "<tr><td colspan='4'><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" .$matriz_cc [$c][7]. "</b></td></tr>";
					$fila_titulo_cc = $matriz_cc [$c][6];
				}
				echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" .$matriz_cc [$c][1]. "</td>";
				echo "<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" .$matriz_cc [$c][2]. "</td>";
				echo "<td align='right'>&nbsp;&nbsp;&nbsp;&nbsp;" .number_format($matriz_cc [$c][3], $n_descuento). "%" . "</td>";
				if($matriz_cc [$c][4] != 0){
					echo "<td align='right'>&nbsp;&nbsp;&nbsp;&nbsp;" .number_format($matriz_cc [$c][4], $n_decimales). "</td>";
					$sum_cc = $sum_cc + $matriz_cc [$c][4];
				} else {
					echo "<td align='right'>&nbsp;&nbsp;&nbsp;&nbsp;" .number_format($matriz_cc [$c][5], $n_decimales). "</td>";
					$sum_cc = $sum_cc + $matriz_cc [$c][5];
				}
				echo "</tr>";
				$sum_porc_cc = $sum_porc_cc + $matriz_cc [$c][3];
				if($fila_titulo_cc != $matriz_cc [$c+1][6]){
					echo "<tr><td colspan='2'>&nbsp;</td>";
					echo "<td align='right'><HR width='90%' align='right'>" . "</td>";
					echo "<td align='right'><HR width='90%' align='right'>" . "</td>";
					echo "<tr><td colspan='2'>&nbsp;</td>";
					echo "<td align='right'>&nbsp;&nbsp;&nbsp;&nbsp;" .number_format($sum_porc_cc, $n_descuento). "%" . "</td>";
					echo "<td align='right'>&nbsp;&nbsp;&nbsp;&nbsp;" .number_format($sum_cc, $n_decimales). "</td></tr>";
					$sum_cc = 0;
					$sum_porc_cc = 0;
				}
			}//fin for $c
			
			echo "</table></td>";
		}//fin if muestra_cc = 0
		printf("<td align='right'>%s</td>", number_format($debe_, $n_decimales));//debe
		printf("<td align='right'>%s</td></tr>", number_format($haber_, $n_decimales));//haber
		
		$suma_debe = $suma_debe + $debe_;
		$suma_haber = $suma_haber + $haber_;
		$color++;
	}//fin while 6
	mysqli_free_result($result6);
	
	//convierte el total en literal
	$letras=new NroEnLetra($suma_debe,2);
	
	$mostrar_letras = ucfirst($letras->getLetra());
	
	$busca_espacio = substr($mostrar_letras,-6,1);
	if($busca_espacio == ' ') {
		$fin_letras = substr($mostrar_letras,-5);
		$mostrar_letras = substr($mostrar_letras,0,-5);
		$mostrar_letras = $mostrar_letras .'0'. $fin_letras;
	}
	?>
	<tr BGCOLOR='#ffcccc'><td colspan="4"><b>Total &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <?php echo $mostrar_letras; ?> <?php echo $nom_moneda_letras; ?></b></td>
    <td align="right"><b><?php echo number_format($suma_debe, $n_decimales); ?></b></td>
    <td align="right"><b><?php echo number_format($suma_haber, $n_decimales); ?></b></td>
    </tr>
</tbody>    
</table>
<br />

<?php
    if($enabled2 == 0){
				printf("<table border='0' align='center' cellpadding='2' width='600'><tr><td align='center'><font color='#FF0000' size='+1'>ASIENTO ANULADO</font></td></tr></table>");
			}
	if($authorized2 == 0){
				printf("<table border='0' align='center' cellpadding='2' width='600'><tr><td align='center'><font color='#FF0000' size='+1'>ASIENTO PENDIENTE DE AUTORIZACI&Oacute;N</font></td></tr></table>");
			}
	} //fin if $control_vista_asiento = 1
}//fin if muestra_asiento 1
?>

<p>&nbsp;</p>
<br /><br /><br />
<table border="0" align="center" cellpadding="2" width="90%">
<tr>
<td align="center">----------------------------------------</td>
<td align="center">----------------------------------------</td>
<td align="center">----------------------------------------</td>
<td align="center">----------------------------------------</td>
</tr><tr>
<td align="center">Elaborado por: <?php echo $usuario_reg; ?></td>
<td align="center"><?php echo $firma_contabilidad; ?></td>
<td align="center"><?php echo $firma_gerencia; ?></td>
<td align="center"><?php echo $firma_interesado; ?></td>
</tr><tr>
<td align="left">Nombre:__________________________</td>
<td align="left">Nombre:__________________________</td>
<td align="left">Nombre:__________________________</td>
<td align="left">Nombre:__________________________</td>
</tr><tr>
<td align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;C.I.:__________________________</td>
<td align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;C.I.:__________________________</td>
<td align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;C.I.:__________________________</td>
<td align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;C.I.:__________________________</td>
</tr>
</table>

<?php


?>
</body>
</html>
