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

//$usuario=$_POST["usuario"];
$rep=$_GET["rep"];
$tipo=$_GET["tipo"];
$planilla=$_POST["planilla"];
$mostrar=$_POST["mostrar"];
$empleado=$_POST["empleado"];
$genero=$_POST["genero"];
$ciudad=$_POST["ciudad"];
$cargo=$_POST["cargo"];
$sucursal=$_POST["sucursal"];
$cod_contexto=$_POST["contexto"];
$mesini=$_POST["mesini"];
$anoini=$_POST["anoini"];
$mesfin=$_POST["mesfin"];
$anofin=$_POST["anofin"];
$orden=$_POST["orden"];
$cod_afp=$_POST["afp"];

$empleado_det=$_GET["empleado_det"];
$cargo_det=$_GET["cargo_det"];
$bono_det=$_GET["bono_det"];
$sucursal_det=$_GET["sucursal_det"];
$periodo_det=$_GET["periodo_det"];
$mostrar_det=$_GET["mostrar_det"];
//$mesini_det=$_GET["mesini_det"];
//$anoini_det=$_GET["anoini_det"];
//$mesfin_det=$_GET["mesfin_det"];
//$anofin_det=$_GET["anofin_det"];
//$usuario_det=$_GET["usuario_det"];

if($mostrar_det != NULL) { $mostrar = $mostrar_det; }

//$mostrar_asiento_cc = $_GET["showCC"];
//if($planilla == 1) { $mostrar = 1; }//esto comentar cuando termine la planilla
if($planilla == 3) { $mostrar = 2; }
if($planilla == 4) { $mostrar = 1; }
if($planilla == 5) { $mostrar = 1; }
if($planilla == 6) { $mostrar = 1; }

?>

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

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

<?php if($planilla == 0) { ?>
<style type="text/css" media="print">
@page {
	size: legal landscape; /*size: 270mm 320mm landscape;*/
	margin-top:0.5cm;
	margin-bottom:0.5cm;
	margin-left:1.5cm;
	margin-right:0.5cm;
	} 
DIV {page-break-after: always;}
</style>

<?php } else {?>

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

<?php } //fin if mos 0?>

<?php if($mostrar == 1) { ?>
<link href="../../maincss.css" rel="stylesheet" type="text/css" />
<link href="../../printcss.css" rel="stylesheet" type="text/css" media="print" />
<?php } ?> 

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

<link href="../../boletas.css" rel="stylesheet" type="text/css" />
<?php 
$tam_estilo = 'size: 21.59cm 14.3cm;'; //tamaño media carta size: 21.59cm 14.3cm;
$tam_hoja = '200px'; //624px=16.5cm 550px=14.5cm (espacio entre la cabecera y el pie)
?> 

<style type="text/css" media="print">
@page { 
<?php echo $tam_estilo; ?>
margin-top:0.5cm;
margin-bottom:0.5cm;
margin-left:0.5cm;
margin-right:0.5cm;
}
DIV {page-break-after: always;}
</style>

<?php } ?>


</head>
<?php
/*
if (empty($_POST["fechaini"]))
{
    $fechaini=$_GET["fechaini"];
} else {
	$fechaini=$_POST["fechaini"];
}

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

if (empty($_POST["usuario"]))
{
    $usuario=$_GET["usuario"];
} else {
	$usuario=$_POST["usuario"];
}
*/
//encuentro la fecha inicial y final

$n_decimales = 2;

?>
<body>

<?php


//Inicio reporte sueldos y salarios

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


$filas_por_pagina = 16;

//rep legal
$result2 = mysqli_query($link, "select a.codPerson as cod_persona, 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 persona, b.fldAlternativeKey as ci 
from 
txsTaxesConfig a, agnPerson b
where 
a.codPerson = b.pkyPerson and 
b.sysEnabled = 1 and b.sysAuthorized = 1;");
while ($row = mysqli_fetch_array($result2)) {
	$nombre_responsable = $row['persona'];
	$ci_responsable = $row['ci'];
}
mysqli_free_result($result2);	


if ($planilla == 0) { 
	$nom_planilla = 'Mensual';
} 
if ($planilla == 1) { 
	$nom_planilla = 'Mensual Ampliada';
}
if ($planilla == 2) { 
	$nom_planilla = 'Tributaria';
	$filas_por_pagina = 32;
}
if ($planilla == 8) { 
	$nom_planilla = 'Tributaria v2';
	$filas_por_pagina = 30;
}
if ($planilla == 3) { 
	$nom_planilla = 'Boletas de Pago (Solo Formato Impresi&oacute;n)';
}
if ($planilla == 4) { 
	$nom_planilla = 'Fondo Solidario';
}
if ($planilla == 5) { 
	$nom_planilla = 'Caja de Salud';
}
if ($planilla == 6) { 
	$nom_planilla = 'AFP';
}
if ($planilla == 7) { 
	$nom_planilla = 'Retroactivo';
}


if ($mostrar == 0) { 
	$nom_mostrar = 'Formato presentaci&oacute;n';
}
if ($mostrar == 1) { 
	$nom_mostrar = 'Reporte';
}


if ($empleado == 0) { //if empleado
    $valor_empleado = ' ';
	$valor_empleado2 = ' ';
	$nom_empleado = 'Todos';
  } else { 
    $valor_empleado = ' a.codEmployee = '.$empleado.' and ';
	$valor_empleado2 = ' b.codEmployee = '.$empleado.' and ';
	//nombre de empleado
	$resultemp = mysqli_query($link, "select pkyPerson as codigo, case when fldOtherNames is NULL then case when fldMiddleName is NULL then concat(fldLastName,', ',fldFirstName) else concat(fldLastName,' ',fldMiddleName,', ',fldFirstName) end else case when fldMiddleName is NULL then concat(fldLastName,', ',fldFirstName,' ',fldOtherNames) else concat(fldLastName,' ',fldMiddleName,', ',fldFirstName,' ',fldOtherNames) end end as empleado 
				from agnPerson
				where
				fldIsEmployee = 1 and
				pkyPerson = '$empleado' and 
				sysEnabled = 1 and sysAuthorized = 1;");
	while ($row = mysqli_fetch_array($resultemp)) {
	$nom_empleado = $row['codigo'].' - '.$row['empleado'];
	}
	mysqli_free_result($resultemp);
} //fin if empleado


if ($genero == 0) { // if genero
	$nom_genero = 'Todos';
	$valor_genero = ' ';
	$valor_genero2 = ' ';
} else {
	//nombre genero
	$result3 = mysqli_query($link, "select pkyGender as cod_gen, fldName as genero
							from 
							agnGender
							where
							pkyGender = '$genero' and 
							sysEnabled = 1 and sysAuthorized = 1;");
	while ($row = mysqli_fetch_array($result3)) {
		$nom_genero = $row['genero'];
	}
	mysqli_free_result($result3);
	$valor_genero = ' b.codGender = ' .$genero. ' and ';
	$valor_genero2 = ' d.codGender = ' .$genero. ' and ';
} //fin if genero


if ($ciudad == 0) { // if ciudad
	$nom_ciudad = 'Todos';
	$valor_ciudad = ' ';
	$valor_ciudad2 = ' ';
} else {
	//nombre ciudad
	$result4 = mysqli_query($link, "select a.pkyCity as cod_ciu, a.fldName as ciudad, b.fldName as pais
							from 
							regCity a, regCountry b
							where
							a.pkyCity = '$ciudad' and 
							a.codCountry = b.pkyCountry and 
							a.sysEnabled = 1 and a.sysAuthorized = 1;");
	while ($row = mysqli_fetch_array($result4)) {
		$nom_ciudad = $row['ciudad'].' - '.$row['pais'];
	}
	mysqli_free_result($result4);
	$valor_ciudad = ' d.codCity = ' .$ciudad. ' and ';
	$valor_ciudad2 = ' e.codCity = ' .$ciudad. ' and ';
} //fin if ciudad


if ($cargo == 0) { // if cargo
	$nom_cargo = 'Todos';
	$valor_cargo = ' ';
	$valor_cargo2 = ' ';
} else {
	//nombre cargo
	$result5 = mysqli_query($link, "select pkyJob as cod_cargo, fldName as cargo
							from 
							hrsJob
							where
							pkyJob = '$cargo' and 
							sysEnabled = 1 and sysAuthorized = 1;");
	while ($row = mysqli_fetch_array($result5)) {
		$nom_cargo = $row['cargo'];
	}
	mysqli_free_result($result5);
	$valor_cargo = ' a.codJob = ' .$cargo. ' and ';
	$valor_cargo2 = ' d.codJob = ' .$cargo. ' and ';
} //fin if cargo


if ($sucursal == 0) { // if sucursal
	$nom_sucursal = 'Todos';
	$valor_sucursal = ' ';
	$valor_sucursal2 = ' ';
} else {
	//nombre sucursal
	$result4 = mysqli_query($link, "select a.pkyCompanyBranch as cod_suc, a.fldName as suc, a.fldID as id, b.fldName as ciudad
							from 
							agnCompanyBranch a, regCity b 
							where 
							a.pkyCompanyBranch = '$sucursal' and 
							a.codCompany = 2 and 
							a.codCity = b.pkyCity and 
							a.sysEnabled = 1 and a.sysAuthorized = 1;");
	while ($row = mysqli_fetch_array($result4)) {
		$nom_sucursal = $row['suc'].' - '.$row['id'].' - '.$row['ciudad'];
	}
	mysqli_free_result($result4);
	$valor_sucursal = ' a.codBranch = ' .$sucursal. ' and ';
	$valor_sucursal2 = ' d.codBranch = ' .$sucursal. ' and ';
} //fin if sucursal

//contexto
if($cod_contexto == -1) { // if contexto
	$nom_contexto = 'Todos';
	$valor_contexto = ' ';
	$valor_contexto2 = ' ';
} 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_contexto2 = ' a.sysContext = '.$cod_contexto.' and ';	
} //fin if contexto


if ($cod_afp < 0) { 
	$valor_afp = '';
	$valor_afp1 = '';
	$valor_afp2 = '';
	$valor_afp3 = '';
	$valor_afp4 = '';
	$valor_afp42 = '';
	$valor_afp5 = '(b.fldFormat = 1 or b.fldFormat = 2) and '; //para lab pat afp
	$nom_afp = 'Todos';
} else {
	$valor_afp = ' j.fldFormat = '.$cod_afp.' and ';	
	$valor_afp1 = ' distinct ';
	$valor_afp2 = ', j.fldFormat as cod_afp';
	$valor_afp3 = ', hrsDiscountException i, hrsFixedDiscounts j';
	$valor_afp4 = 'i.codFixedDiscount = j.pkyFixedDiscounts and i.codEmployee = b.pkyPerson and j.fldIsLaboral = 1 and ';
	$valor_afp42 = 'i.codFixedDiscount = j.pkyFixedDiscounts and i.codEmployee = d.pkyPerson and j.fldIsLaboral = 1 and ';
	$valor_afp5 = ' b.fldFormat = '.$cod_afp.' and ';; //para lab pat afp
	if($cod_afp == 0) { $nom_afp = 'No Asignado'; }
	if($cod_afp == 1) { $nom_afp = 'Previsi&oacute;n'; }
	if($cod_afp == 2) { $nom_afp = 'Futuro'; }
}


if ($orden == 0) { 
	$nom_orden = 'Nombre';
	$valor_orden = 'order by empleado';
	$valor_orden2 = 'order by empleado';
} 
if ($orden == 1) { 
	$nom_orden = 'Fecha Nacimiento';
	$valor_orden = 'order by fecha_nac, empleado';
	$valor_orden2 = 'order by fecha_nac, empleado';
}
if ($orden == 2) { 
	$nom_orden = 'Sexo';
	$valor_orden = 'order by cod_sexo desc, empleado';
	$valor_orden2 = 'order by cod_sexo desc, empleado';
}
if ($orden == 3) { 
	$nom_orden = 'Cargo';
	$valor_orden = 'order by cargo, empleado';
	$valor_orden2 = 'order by cargo, empleado';
}
if ($orden == 4) { 
	$nom_orden = 'Fecha Contrataci&oacute;n';
	$valor_orden = 'order by fecha_cont, empleado';
	$valor_orden2 = 'order by fecha_cont, empleado';
}
if ($orden == 5) { 
	$nom_orden = 'AFP';
	$valor_orden = 'order by cod_afp, empleado';
	$valor_orden2 = 'order by cod_afp, empleado';
	//obligo a mostrar todos afp
	$valor_afp = '';
	$valor_afp1 = ' distinct ';
	$valor_afp2 = ', j.fldFormat as cod_afp';
	$valor_afp3 = ', hrsDiscountException i, hrsFixedDiscounts j';
	$valor_afp4 = 'i.codFixedDiscount = j.pkyFixedDiscounts and i.codEmployee = b.pkyPerson and j.fldIsLaboral = 1 and ';
	$valor_afp42 = 'i.codFixedDiscount = j.pkyFixedDiscounts and i.codEmployee = d.pkyPerson and j.fldIsLaboral = 1 and ';
	$nom_afp = 'Todos';
	$cod_afp = -1;
}
if ($orden == 6) { 
	$nom_orden = 'AFP y Fecha Contrataci&oacute;n';
	$valor_orden = 'order by cod_afp, fecha_cont, empleado';
	$valor_orden2 = 'order by cod_afp, fecha_cont, empleado';
	//obligo a mostrar todos afp
	$valor_afp = '';
	$valor_afp1 = ' distinct ';
	$valor_afp2 = ', j.fldFormat as cod_afp';
	$valor_afp3 = ', hrsDiscountException i, hrsFixedDiscounts j';
	$valor_afp4 = 'i.codFixedDiscount = j.pkyFixedDiscounts and i.codEmployee = b.pkyPerson and j.fldIsLaboral = 1 and ';
	$valor_afp42 = 'i.codFixedDiscount = j.pkyFixedDiscounts and i.codEmployee = d.pkyPerson and j.fldIsLaboral = 1 and ';
	$nom_afp = 'Todos';
	$cod_afp = -1;
}
if ($orden == 7) { 
	$nom_orden = 'C&oacute;digo';
	$valor_orden = 'order by cod_empleado';
	$valor_orden2 = 'order by cod_empleado';
}

$nom_mesini = nombreMes($mesini);
$nom_mesfin = nombreMes($mesfin);

if($mostrar == 0) {
$vfechaini =  $anoini.'-'.$mesini.'-01';
$vfechafin =  $anoini.'-'.$mesini.'-31';	
} else {
$vfechaini =  $anoini.'-'.$mesini.'-01';
$vfechafin =  $anofin.'-'.$mesfin.'-31';
}
//retroactivo desde diciembre
if($planilla == 7) {
$anoinid = $anoini-1;
$mesinid = 12;
$mesinif = $mesini+1;
$mesinim = $mesini+2;
$mesinia = $mesini+3;
$vfechaini =  $anoinid.'-'.$mesinid.'-01';
$vfechafin =  $anofin.'-'.$mesfin.'-31';

$vdfechaini = $vfechaini;//dic ini
$vdfechafin = $anoinid.'-'.$mesinid.'-31';//dic fin
$vefechaini = $anoini.'-'.$mesini.'-01';//ene ini
$vefechafin = $anoini.'-'.$mesini.'-31';//ene fin
$vffechaini = $anoini.'-'.$mesinif.'-01';//feb ini
$vffechafin = $anoini.'-'.$mesinif.'-31';//feb fin
$vmfechaini = $anoini.'-'.$mesinim.'-01';//mar ini
$vmfechafin = $anoini.'-'.$mesinim.'-31';//mar fin
$vafechaini = $anoini.'-'.$mesinia.'-01';//abr ini
$vafechafin = $anoini.'-'.$mesinia.'-31';//abr fin
}

/*
select distinct a.pkySalaryPayrollDetail as cod_plan_det, a.codSalaryPayroll as cod_plan, a.codEmployee as cod_empleado, case when b.fldMiddleName is NULL then concat(b.fldLastName,', ',b.fldFirstName) else concat(b.fldLastName,' ',b.fldMiddleName,', ',b.fldFirstName) 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.fldDiscounts as monto_dcto_otros, a.fldTotalSalary as liquido_pagable, b.fldBirthDate as fecha_nac, b.codGender as cod_sexo, b.fldBankAccount as cta_banco, b.codBank as cod_banco, b.codBirthCity as cod_ciu_nac, h.fldPeriod as periodo, b.fldRetirementPensionCode as nua, b.fldLastName as ap_pat, b.fldMiddleName as ap_mat, b.fldMarriedLastName as ap_cas, b.fldFirstName as nombre1, b.fldOtherNames as nombre2, b.fldRetired as cod_jubilado, b.codEmployeeType as mod_contrato, j.fldFormat as cod_afp
from hrsSalaryPayrollDetail a, agnPerson b, regCity c, agnCompanyBranch d, hrsJob e, agnMaritalStatus f, hrsSalaryPayroll h, hrsDiscountException i, hrsFixedDiscounts j
where 

h.fldPeriod >= '2017-02-01' and 
h.fldPeriod <= '2017-12-28' and 
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 = h.pkySalaryPayroll and 
i.codFixedDiscount = j.pkyFixedDiscounts and 
i.codEmployee = b.pkyPerson and 
h.sysEnabled = 1 and h.sysAuthorized = 1
*/
$result = mysqli_query($link, "select $valor_afp1 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, a.codBranch as cod_suc, d.fldName as sucursal, a.codJob as cod_cargo, 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_basico, 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.fldDiscounts as monto_dcto_otros, a.fldTotalSalary as liquido_pagable, b.fldBirthDate as fecha_nac, b.codGender as cod_sexo, b.fldBankAccount as cta_banco, b.codBank as cod_banco, b.codBirthCity as cod_ciu_nac, h.fldPeriod as periodo, b.fldRetirementPensionCode as nua, b.fldLastName as ap_pat, b.fldMiddleName as ap_mat, b.fldMarriedLastName as ap_cas, b.fldFirstName as nombre1, b.fldOtherNames as nombre2, b.fldRetired as cod_jubilado, b.codEmployeeType as mod_contrato, 
h.fldMinimumWage as salario_minimo_nacional, h.fldTaxableWage as renta_no_imponible, h.fldManWorkingHours as horas_trabajo_hombre, h.fldWomanWorkingHours as horas_trabajo_mujer, h.fldManWorkingDays as dias_trabajo_hombre, h.fldWomanWorkingDays as dias_trabajo_mujer, d.codCity as cod_ciu_suc $valor_afp2
from hrsSalaryPayrollDetail a, agnPerson b, regCity c, agnCompanyBranch d, hrsJob e, agnMaritalStatus f, hrsSalaryPayroll h $valor_afp3
where 
$valor_empleado 
$valor_genero 
$valor_ciudad 
$valor_cargo 
$valor_sucursal 
$valor_contexto 
$valor_afp 
$valor_afp4 
h.fldPeriod >= '$vfechaini' and 
h.fldPeriod <= '$vfechafin' and 
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 = h.pkySalaryPayroll and 
h.sysEnabled = 1 and h.sysAuthorized = 1
$valor_orden;");

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

$matriz_pla = array();
$i = 1;
while ($row = mysqli_fetch_array($result)) {
	$matriz_pla [$i][1] = $row['cod_plan'];
	$matriz_pla [$i][2] = $row['cod_empleado'];
	$matriz_pla [$i][3] = $row['empleado'];
	$matriz_pla [$i][4] = $row['ciudad'];
	$matriz_pla [$i][5] = $row['sucursal'];
	$matriz_pla [$i][6] = $row['cargo'];
	$matriz_pla [$i][7] = $row['caja_salud'];
	$matriz_pla [$i][8] = $row['nro_cont'];
	$matriz_pla [$i][9] = $row['antiguedad'];
	$matriz_pla [$i][10] = $row['fecha_cont'];
	$matriz_pla [$i][11] = $row['estado_civil'];
	$matriz_pla [$i][12] = $row['iva'];
	$matriz_pla [$i][13] = $row['tiempo_trab'];
	$matriz_pla [$i][14] = $row['vacaciones'];
	$matriz_pla [$i][15] = $row['faltas_domingo'];
	$matriz_pla [$i][16] = $row['enfermedad'];
	$matriz_pla [$i][17] = $row['otros'];
	$matriz_pla [$i][18] = $row['salario_basico'];//salario del empleado
	$matriz_pla [$i][19] = $row['horas_extra'];
	$matriz_pla [$i][20] = $row['monto_horas_extra'];
	$matriz_pla [$i][21] = $row['horas_recargo'];
	$matriz_pla [$i][22] = $row['monto_horas_recargo'];
	$matriz_pla [$i][23] = $row['horas_domingo'];
	$matriz_pla [$i][24] = $row['monto_horas_domingo'];
	$matriz_pla [$i][25] = $row['horas_extraordinarias'];
	$matriz_pla [$i][26] = $row['monto_horas_extraordinarias'];
	$matriz_pla [$i][27] = $row['horas_feriado'];
	$matriz_pla [$i][28] = $row['monto_horas_feriado'];
	$matriz_pla [$i][29] = $row['monto_ing_varios'];
	$matriz_pla [$i][30] = $row['monto_antiguedad'];
	$matriz_pla [$i][31] = $row['haber_ganado'];//salario por dia trabajado sumado bonos y extras
	$matriz_pla [$i][32] = $row['monto_afp'];
	$matriz_pla [$i][33] = $row['monto_dctos_varios'];
	$matriz_pla [$i][34] = $row['monto_dctos_faltas'];
	$matriz_pla [$i][35] = $row['monto_dcto_solidario'];
	$matriz_pla [$i][36] = $row['monto_dcto_impuestos'];
	//$matriz_pla [$i][37] = $row['monto_dcto_otros'];
	$matriz_pla [$i][38] = $row['liquido_pagable'];
	$matriz_pla [$i][39] = $row['fecha_nac'];
	$matriz_pla [$i][40] = $row['cod_sexo'];
	$matriz_pla [$i][41] = $row['cta_banco'];
	$matriz_pla [$i][42] = $row['cod_ciu_nac'];
	$matriz_pla [$i][43] = NULL; //nro doc ci, pasaporte
	$matriz_pla [$i][44] = NULL; //pais nacionalidad
	$matriz_pla [$i][45] = $row['faltas'];
	$matriz_pla [$i][46] = $row['periodo'];
	$matriz_pla [$i][47] = NULL; //cod tipo doc 1=CI, 2=RUN, 3=Pasaporte, 4=Carnet de extranjero o 5=Otro.
	$matriz_pla [$i][48] = NULL; //lugar de expedicion LP=La Paz OR=Oruro PT=Potosi CB=Cochabamba SC=Santa Cruz BN=Beni PA=Pando TJ=Tarija CH=Chuquisaca
	$matriz_pla [$i][49] = 0; //tipo AFP 1=Prevision, 2=Futuro, 3=Otros
	$matriz_pla [$i][50] = $row['nua'];
	$matriz_pla [$i][51] = $row['ap_pat'];
	$matriz_pla [$i][52] = $row['ap_mat'];
	$matriz_pla [$i][53] = $row['ap_cas'];
	$matriz_pla [$i][54] = $row['nombre1'];
	$matriz_pla [$i][55] = $row['nombre2'];
	$matriz_pla [$i][56] = $row['cod_jubilado']; //jubilado 0=no, 1=si
	$matriz_pla [$i][57] = NULL; //clasificacion laboral (puede ser nulo o blanco)
	//1=Tiempo indefinido, 2=A plazo fijo, 3=Por temporada, 4=Por realización de obra o servicio, 5=Condicional o eventual.
	if($row['mod_contrato'] == 3) { $matriz_pla [$i][58] = 1; }
	if($row['mod_contrato'] == 2) { $matriz_pla [$i][58] = 4; }
	if($row['mod_contrato'] == 1) { $matriz_pla [$i][58] = 5; }//1=Tiempo indefinido, 2=A plazo fijo, 3=Por temporada, 4=Por realización de obra o servicio, 5=Condicional o eventual.
	$matriz_pla [$i][59] = NULL; //fecha de retiro
	$matriz_pla [$i][60] = NULL; //nro de dominicales
	$matriz_pla [$i][61] = NULL; //domingos trabajados
	$matriz_pla [$i][62] = $row['monto_imp_acum']; //iva periodo anterior
	$matriz_pla [$i][63] = $row['monto_act_imp']; //iva actualizacion
	$matriz_pla [$i][64] = $row['monto_imp_periodo']; //iva periodo actual actualizado
	$matriz_pla [$i][65] = $row['cod_banco']; //cod banco
	$matriz_pla [$i][66] = NULL; //banco
	$matriz_pla [$i][67] = $row['cod_cargo']; //cod cargo
	$matriz_pla [$i][68] = $row['cod_suc']; //cod sucursal
	$matriz_pla [$i][69] = NULL; //salario dia
	$matriz_pla [$i][70] = NULL; //salario dias trabajados mes
	$matriz_pla [$i][71] = NULL; //horas trabajadas dia
	$matriz_pla [$i][72] = $row['salario_minimo_nacional']; //salario minimo nacional
	$matriz_pla [$i][73] = $row['renta_no_imponible']; //renta no imponible
	$matriz_pla [$i][74] = $row['horas_trabajo_hombre']; //horas trabajo hombre
	$matriz_pla [$i][75] = $row['horas_trabajo_mujer']; //horas trabajo mujer
	$matriz_pla [$i][76] = $row['dias_trabajo_hombre']; //dias trabajo hombre
	$matriz_pla [$i][77] = $row['dias_trabajo_mujer']; //dias trabajo mujer
	$matriz_pla [$i][78] = $row['cod_ciu_suc']; //cod ciudad sucursal
	$matriz_pla [$i][79] = NULL; //ciudad sucursal
	$matriz_pla [$i][80] = NULL; //novedad I/R/L/S (I=ingreso, R=retiro, L=todo el periodo con licencia no remunerada, S=subsidio referido a Riesgo Común y Riesgo Profesional)
	$matriz_pla [$i][81] = NULL; //fecha novedad I/R/L/S  
	$matriz_pla [$i][82] = NULL; //tipo documento 1=CI, 2=RUN, 3=PAS, 4=CEX
	$matriz_pla [$i][83] = 'E'; //tipo asegurado E=estacional, M=minero, C=cooperativista, Vacio=ninguno
	$matriz_pla [$i][84] = NULL; //nombre AFP 1=Prevision, 2=Futuro
	$matriz_pla [$i][85] = NULL; //cod dependiente RC-IVA
	$matriz_pla [$i][86] = NULL; //novedades RC-IVA (I=incorporacion, V=vigente, D=desvinculado)
	
	
	if($row['cod_sexo'] == 1) {
		$matriz_pla [$i][69] = $row['salario_basico']/$matriz_pla [$i][76]; //salario dia
		$matriz_pla [$i][71] = $matriz_pla [$i][74]/$matriz_pla [$i][76]; //horas trabajadas dia
	} else {
		$matriz_pla [$i][69] = $row['salario_basico']/$matriz_pla [$i][77]; //salario dia
		$matriz_pla [$i][71] = $matriz_pla [$i][75]/$matriz_pla [$i][77]; //horas trabajadas dia
	}
	$matriz_pla [$i][70] = $matriz_pla [$i][69] * ($matriz_pla [$i][13]+$matriz_pla [$i][45]); //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)
	
	
	$cod_empleado = $matriz_pla [$i][2];
	$cod_ciu_nac = $matriz_pla [$i][42];
	$cod_banco = $matriz_pla [$i][65];
	$cod_ciu_suc = $matriz_pla [$i][78];
	
	
	//ci, pas, cod dep RC-IVA
	$resultci = mysqli_query($link, "select fldNumber as nro, codIdentityDocumentType as tipo, codCity as ciudad
from hrsEmployeeDocument 
where 
codPerson = '$cod_empleado';");
	while ($row = mysqli_fetch_array($resultci)) {   
		//$matriz_pla [$i][43] = $row['nro'];
		if($row['tipo'] == 1) { 
			$matriz_pla [$i][43] = $row['nro'];
			$matriz_pla [$i][47] = 1; //ci
		}
		if($row['tipo'] == 2) { 
			$matriz_pla [$i][43] = $row['nro'];
			$matriz_pla [$i][47] = 3; //pasaporte
		}
		if($row['tipo'] == 9) { 
			$matriz_pla [$i][85] = $row['nro'];//cod dep RC-IVA
		}
		if($row['ciudad'] == 1 && $row['tipo'] == 1) { $matriz_pla [$i][48] = 'LP'; }
		if($row['ciudad'] == 2 && $row['tipo'] == 1) { $matriz_pla [$i][48] = 'SC'; } 
		if($row['ciudad'] == 3 && $row['tipo'] == 1) { $matriz_pla [$i][48] = 'CB'; }
		if($row['ciudad'] == 4 && $row['tipo'] == 1) { $matriz_pla [$i][48] = 'CH'; }
		if($row['ciudad'] == 5 && $row['tipo'] == 1) { $matriz_pla [$i][48] = 'TJ'; }
		if($row['ciudad'] == 6 && $row['tipo'] == 1) { $matriz_pla [$i][48] = 'OR'; }
		if($row['ciudad'] == 7 && $row['tipo'] == 1) { $matriz_pla [$i][48] = 'PT'; }
		if($row['ciudad'] == 8 && $row['tipo'] == 1) { $matriz_pla [$i][48] = 'BN'; }
		if($row['ciudad'] == 9 && $row['tipo'] == 1) { $matriz_pla [$i][48] = 'PA'; }
	}
	mysqli_free_result($resultci);
	
	//pais
	$resultpais = mysqli_query($link, "select a.fldName as pais
from regCountry a, regCity b 
where 
b.pkyCity = '$cod_ciu_nac' and 
b.codCountry = a.pkyCountry;");
	while ($row = mysqli_fetch_array($resultpais)) {   
		$matriz_pla [$i][44] = $row['pais'];
	}
	mysqli_free_result($resultpais);
	
	//afp
	$resultafp = mysqli_query($link, "select b.fldFormat as cod_afp
from
hrsDiscountException a, hrsFixedDiscounts b
where
a.codFixedDiscount = b.pkyFixedDiscounts and 
a.codEmployee = '$cod_empleado';");
while ($row = mysqli_fetch_array($resultafp)) {
	if($row['cod_afp'] <> 0) {
	$matriz_pla [$i][49] = $row['cod_afp'];//se supone que se repiten
	}
}
mysqli_free_result($resultafp);


	//fecha de baja empleado
	$resultbaja = mysqli_query($link, "select fldDate as fecha_baja
from hrsEmployeeMovement
where 
fldDate >= '$vfechaini' and 
fldDate <= '$vfechafin' and 
codType = 2 and 
codPerson = '$cod_empleado' and 
sysEnabled = 1 and sysAuthorized = 1;");
while ($row = mysqli_fetch_array($resultbaja)) {
	if($row['fecha_baja'] <> NULL) {
	$matriz_pla [$i][59] = $row['fecha_baja'];//se busca después de hecha la planilla
	}
}
mysqli_free_result($resultbaja);

//banco
$resultbanco = mysqli_query($link, "select b.pkyCompany as cod_banco, b.fldName as banco
from tryBank a, agnCompany b
where
a.pkyBank = '$cod_banco' and 
a.codCompany = b.pkyCompany;");
while ($row = mysqli_fetch_array($resultbanco)) {
	$matriz_pla [$i][66] = $row['banco'];
}
mysqli_free_result($resultbanco);

//ciudad sucursal
	$resultciusuc = mysqli_query($link, "select a.fldName as ciudad
from regCity a 
where 
a.pkyCity = '$cod_ciu_suc';");
	while ($row = mysqli_fetch_array($resultciusuc)) {   
		$matriz_pla [$i][79] = $row['ciudad'];
	}
	mysqli_free_result($resultciusuc);

//novedad I/R/L/S
if(strtotime($matriz_pla [$i][10]) >= strtotime($vfechaini) && strtotime($matriz_pla [$i][10]) <= strtotime($vfechafin)) { 
	$matriz_pla [$i][80] = 'I'; 
	$matriz_pla [$i][81] = $matriz_pla [$i][10];
	$matriz_pla [$i][86] = 'I'; //incorporacion RC-IVA
}
if(strtotime($matriz_pla [$i][59]) >= strtotime($vfechaini) && strtotime($matriz_pla [$i][59]) <= strtotime($vfechafin)) { 
	$matriz_pla [$i][80] = 'R';
	$matriz_pla [$i][81] = $matriz_pla [$i][59];
	$matriz_pla [$i][86] = 'D'; //desvinculado RC-IVA 
}
if(strtotime($matriz_pla [$i][10]) < strtotime($vfechaini) && (strtotime($matriz_pla [$i][59]) > strtotime($vfechafin) || strtotime($matriz_pla [$i][59]) == NULL)) { 
	$matriz_pla [$i][86] = 'V'; //vigente RC-IVA 
}


//tipo documento 1=CI, 2=RUN, 3=PAS, 4=CEX
if ($matriz_pla [$i][47] == 1) { $matriz_pla [$i][82] = 'CI';} 
if ($matriz_pla [$i][47] == 2) { $matriz_pla [$i][82] = 'RUN';}
if ($matriz_pla [$i][47] == 3) { $matriz_pla [$i][82] = 'PAS';}
if ($matriz_pla [$i][47] == 4) { $matriz_pla [$i][82] = 'CEX';}   

//nombre AFP 1=Prevision, 2=Futuro
if ($matriz_pla [$i][49] == 1) { $matriz_pla [$i][84] = 'PREVISI&Oacute;N';} 
if ($matriz_pla [$i][49] == 2) { $matriz_pla [$i][84] = 'FUTURO';} 


//echo $matriz_pla [$i][10].'<br>';
	/*
	//para enlazar al que genero el asiento
	$papa_componente = $matriz_pla [$i][15];
	$papa_codigo = $matriz_pla [$i][16];
	//$usuario = $usuario_det;
	include "../../generadopor.php";
	$matriz_pla [$i][19] = $papa_enlace;
	
	$matriz_pla [$i][20] = $row['usuario_reg'];
	//echo $matriz_pla [$i][1].'<br>';
	*/
	$i++;
}
$fin = $i - 1;
mysqli_free_result($result);



//$horas_pagadas = 8;
$bono_produccion = 0;
$subsidio_frontera = 0;
//$sucursal = '0';
//$dir_sucursal = $mi_direccion;

$total_haber_basico = 0;
$total_bono_ant = 0;
$total_bono_prod = 0;
$total_sub_frontera = 0;
$total_trab_extraor_noct = 0;
$total_domingo = 0;
$total_otros_bonos = 0;
$total_ganado = 0;
$total_afp = 0;
$total_iva = 0;
$total_otros_desc = 0;
$total_desc = 0;
$total_liq_pagable = 0;
//mensual ampliada presentacion
$total_salario_dias_trabajados = 0;
$total_horas_extras = 0;
$total_monto_horas_extras = 0;
$total_horas_domingo = 0;
$total_monto_horas_domingo = 0;
$total_horas_extraor = 0;
$total_monto_horas_extraor = 0;
$total_monto_otros_ing = 0;
$total_afp_10 = 0;
$total_afp_05_1 = 0;
$total_afp_171 = 0;
$total_afp_05_2 = 0;
$total_solidario_1 = 0;
$total_solidario_5 = 0;
$total_solidario_10 = 0;
$total_faltas = 0;


$total_haber_basico_par = 0;
$total_bono_ant_par = 0;
$total_bono_prod_par = 0;
$total_sub_frontera_par = 0;
$total_trab_extraor_noct_par = 0;
$total_domingo_par = 0;
$total_otros_bonos_par = 0;
$total_ganado_par = 0;
$total_afp_par = 0;
$total_iva_par = 0;
$total_otros_desc_par = 0;
$total_desc_par = 0;
$total_liq_pagable_par = 0;




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

//Planilla de sueldos

//este if es para mostrar con el formato presentacion
if($mostrar == 0 && $planilla == 0) { //mostrar 0

$j = 1;
$nu = 1;
for($i = 1; $i <= $var; $i++) {//for
?>
<?php if($mostrar_logo_reportes_formato == 0) { //if formato 0 ?>
<table border="1" align="center" cellpadding="2" width="1160">
<tr>
	<td width="490"><b>Nombre o Raz&oacute;n Social: </b><?php echo $nombre_empresa; ?></td>
    <td width="490"><b>NIT: </b><?php echo $mi_nit; ?></td>
</tr>
<tr>
	<td width="490"><b>No. Empleador Min. de Trabajo: </b><?php echo $num_min_trabajo; ?></td>
    <td width="490"><b>No. Empleador Caja de Salud: </b><?php echo $num_caja_salud; ?></td>
</tr>
</table>
<table border="0" align="center" cellpadding="2" width="1160">
<tr>
	<td width="300"><?php //echo $usuario; ?></td>
    <td width="390" align="center"><b>PLANILLA DE SUELDOS Y SALARIOS</b></td>
    <td width="300" align="right"><b>P&aacute;gina: <?php echo $i; ?> de <?php echo $var; ?></b></td>
</tr>
<tr>
	<td width="300">&nbsp;</td>
    <td width="390" align="center">Cifras en Bolivianos</td>
    <td width="300" align="right">CORRESPONDIENTE AL MES DE <?php echo strtoupper($nom_mesini); ?> DE <?php echo $anoini; ?></td>
</tr>
</table>
<?php } //fin if formato 0 ?>

<?php if($mostrar_logo_reportes_formato == 1) { //if formato 1 ?>
<table border="1" align="center" cellpadding="2" width="1160">
<tr>
	<td rowspan="2" width="15%"><img src="../../Images/logo.jpg" alt="Logo" width="100" height="40" /></td>
    <td width="490"><b>Nombre o Raz&oacute;n Social: </b><?php echo $nombre_empresa; ?></td>
    <td width="490"><b>NIT: </b><?php echo $mi_nit; ?></td>
</tr>
<tr>
	<td width="490"><b>No. Empleador Min. de Trabajo: </b><?php echo $num_min_trabajo; ?></td>
    <td width="490"><b>No. Empleador Caja de Salud: </b><?php echo $num_caja_salud; ?></td>
</tr>
</table>
<table border="0" align="center" cellpadding="2" width="1160">
<tr>
	<td width="300"><?php //echo $usuario; ?></td>
    <td width="390" align="center"><b>PLANILLA DE SUELDOS Y SALARIOS</b></td>
    <td width="300" align="right"><b>P&aacute;gina: <?php echo $i; ?> de <?php echo $var; ?></b></td>
</tr>
<tr>
	<td width="300">&nbsp;</td>
    <td width="390" align="center">Cifras en Bolivianos</td>
    <td width="300" align="right">CORRESPONDIENTE AL MES DE <?php echo strtoupper($nom_mesini); ?> DE <?php echo $anoini; ?></td>
</tr>
</table>
<?php } //fin if formato 1 ?>

<br />

<table border="1" align="center" cellpadding="2" width="1160" height="600">
    <TR> 
    <TD align="center" width="10" style='border-bottom: solid 1px'><b>No.</b></TD>
    <TD align="center" width="40" style='border-bottom: solid 1px'><b>Docu-<br/>mento de Iden-<br/>tidad</b></TD>
    <TD align="center" width="280" style='border-bottom: solid 1px'><b>Apellidos y Nombres</b></TD>
    <TD align="center" width="40" style='border-bottom: solid 1px'><b>Pa&iacute;s de Nacio-<br/>nalidad</b></TD>
    <TD align="center" width="50" style='border-bottom: solid 1px'><b>Fecha de Nacimiento</b></TD>
    <TD align="center" width="20" style='border-bottom: solid 1px'><b>Sexo<br />(V/M)</b></TD>
    <TD align="center" width="120" style='border-bottom: solid 1px'><b>Ocupaci&oacute;n que Desempe&ntilde;a</b></TD>
    <TD align="center" width="50" style='border-bottom: solid 1px'><b>Fecha de Ingreso</b></TD>
    <TD align="center" width="20" style='border-bottom: solid 1px'><b>Horas Pagadas (D&iacute;a)</b></TD>
    <TD align="center" width="20" style='border-bottom: solid 1px'><b>D&iacute;as Pagados (Mes)</b></TD>
    <TD align="center" width="40" style='border-bottom: solid 1px'><b>(1) Haber B&aacute;sico</b></TD>
    <TD align="center" width="40" style='border-bottom: solid 1px'><b>(2) Bono de Antig&uuml;e-<br/>dad</b></TD>
    <TD align="center" width="40" style='border-bottom: solid 1px'><b>(3) Bono de Produc-<br/>ci&oacute;n</b></TD>
    <TD align="center" width="40" style='border-bottom: solid 1px'><b>(4) Subsidio de Frontera</b></TD>
    <TD align="center" width="40" style='border-bottom: solid 1px'><b>(5) Trabajo Extra-<br/>ordinario y Nocturno</b></TD>
    <TD align="center" width="40" style='border-bottom: solid 1px'><b>(6) Pago Dominical y Domingo Trabajado</b></TD>
    <TD align="center" width="40" style='border-bottom: solid 1px'><b>(7) Otros Bonos</b></TD>
    <TD align="center" width="40" style='border-bottom: solid 1px'><b>(8) Total Ganado Suma<br/>(1 a 7)</b></TD>
    <TD align="center" width="40" style='border-bottom: solid 1px'><b>(9) Aporte a las AFPs</b></TD>
    <TD align="center" width="40" style='border-bottom: solid 1px'><b>(10) RC-IVA</b></TD>
    <TD align="center" width="40" style='border-bottom: solid 1px'><b>(11) Otros Des-<br/>cuentos</b></TD>
    <TD align="center" width="40" style='border-bottom: solid 1px'><b>(12) Total Des-<br/>cuentos Suma<br/>(9 a 11)</b></TD>
    <TD align="center" width="40" style='border-bottom: solid 1px'><b>(13) L&iacute;quido Pagable (12 - 8)</b></TD>
    <TD align="center" width="120" style='border-bottom: solid 1px'><b>(14) Firma</b></TD>
    </TR>

<?php
$color = 2;
$q = 1;//
  while ($q <= $filas_por_pagina) { //while
  
  if($numero_filas == 0) {//if filas
	printf("<tr><td align='center' style='border-bottom: solid 1px'>%s</td>", $matriz_pla [$j][3]);//fecha
  } else { //else filas
    if($color % 2 == 0) { //if color
		if($matriz_pla [$j][3] != NULL) {
		printf("<tr BGCOLOR='#e2e7fa'><td align='center' style='border-bottom: solid 1px'>%s</td>", $nu);//numero
		} else { 
		printf("<tr BGCOLOR='#e2e7fa'><td align='center' style='border-bottom: solid 1px'><hr /></td>");//numero vacio
		}
	} else {
		if($matriz_pla [$j][3] != NULL) {
		printf("<tr><td align='center' style='border-bottom: solid 1px'>%s</td>", $nu);//numero
		} else { 
		printf("<tr><td align='center' style='border-bottom: solid 1px'><hr /></td>");//numero vacio
		}
	}//fin if color
  }//fin filas
    
	if($matriz_pla [$j][3] != NULL) {//if no hay
	
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", $matriz_pla [$j][43]);//ci
	$texto = $matriz_pla [$j][3];//empleado
	$texto = strtr(strtoupper($texto), "àáâãäåæçèéêëìíîïðñòóôõöøùüú", "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÜÚ");
	$texto = substr($texto,0,150);
	printf("<td align='left' style='border-bottom: solid 1px'>%s</td>", $texto);//empleado
	printf("<td align='left' style='border-bottom: solid 1px'>%s</td>", $matriz_pla [$j][44]);//nacionalidad
	if($matriz_pla [$j][39] <> NULL) {
	printf("<td align='center' style='border-bottom: solid 1px'>%s</td>", cambiarFormatoFechaBarra($matriz_pla [$j][39]));//fecha nac
	} else {
	printf("<td align='center' style='border-bottom: solid 1px'>%s</td>", $matriz_pla [$j][39]);//fecha nac	
	}
	
	if($matriz_pla [$j][40] == 1) {//if sexo
		printf("<td align='center' style='border-bottom: solid 1px'>V</td>");//V
	} else {
		printf("<td align='center' style='border-bottom: solid 1px'>M</td>");//M
	}//fin if sexo
	
	printf("<td align='left' style='border-bottom: solid 1px'>%s</td>", $matriz_pla [$j][6]);//cargo
	if($matriz_pla [$j][10] <> NULL) {
	printf("<td align='center' style='border-bottom: solid 1px'>%s</td>", cambiarFormatoFechaBarra($matriz_pla [$j][10]));//fecha ing
	} else {
	printf("<td align='center' style='border-bottom: solid 1px'>%s</td>", $matriz_pla [$j][10]);//fecha ing
	}
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($matriz_pla [$j][71],$n_decimales));//horas pagadas
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", $matriz_pla [$j][13]+$matriz_pla [$j][45]);//dias pagados
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($matriz_pla [$j][70],$n_decimales));//salario por dias trabajados
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($matriz_pla [$j][30],$n_decimales));//bono antiguedad
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($bono_produccion,$n_decimales));//bono produccion
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($subsidio_frontera,$n_decimales));//subsidio frontera
	$trab_extraor_nocturno = $matriz_pla [$j][20]+$matriz_pla [$j][22]+$matriz_pla [$j][26]+$matriz_pla [$j][28];
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($trab_extraor_nocturno,$n_decimales));//trabajo extraordinario y nocturno
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($matriz_pla [$j][24],$n_decimales));//dominical
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($matriz_pla [$j][29],$n_decimales));//otros bonos
	$suma_total_ganado = $matriz_pla [$j][70]+$matriz_pla [$j][30]+$bono_produccion+$subsidio_frontera+$trab_extraor_nocturno+$matriz_pla [$j][24]+$matriz_pla [$j][29];
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($suma_total_ganado,$n_decimales));//total ganado
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($matriz_pla [$j][32]+$matriz_pla [$j][35],$n_decimales));//aporte afp + solidario
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($matriz_pla [$j][36],$n_decimales));//iva
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($matriz_pla [$j][33]+$matriz_pla [$j][34],$n_decimales));//desc varios + desc faltas
	$suma_total_desc = $matriz_pla [$j][32]+$matriz_pla [$j][35]+$matriz_pla [$j][36]+$matriz_pla [$j][33]+$matriz_pla [$j][34];
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($suma_total_desc,$n_decimales));//total descuentos
	$liquido_pagable = $suma_total_ganado-$suma_total_desc;
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($liquido_pagable,$n_decimales));//liquido pagable
	printf("<td style='border-bottom: solid 1px'>&nbsp;</td></tr>");//firma
		
	
	$total_haber_basico = $total_haber_basico+$matriz_pla [$j][70];
	$total_bono_ant = $total_bono_ant+$matriz_pla [$j][30];
	$total_bono_prod = $total_bono_prod+$bono_produccion;
	$total_sub_frontera = $total_sub_frontera+$subsidio_frontera;
	$total_trab_extraor_noct = $total_trab_extraor_noct+$trab_extraor_nocturno;
	$total_domingo = $total_domingo+$matriz_pla [$j][24];
	$total_otros_bonos = $total_otros_bonos+$matriz_pla [$j][29];
	$total_ganado = $total_ganado+$suma_total_ganado;
	$total_afp = $total_afp+$matriz_pla [$j][32]+$matriz_pla [$j][35];
	$total_iva = $total_iva+$matriz_pla [$j][36];
	$total_otros_desc = $total_otros_desc+$matriz_pla [$j][33]+$matriz_pla [$j][34];
	$total_desc = $total_desc+$suma_total_desc;
	$total_liq_pagable = $total_liq_pagable+$liquido_pagable;
	} else { //else if no hay
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//ci
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//empleado
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//nacionalidad
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//fecha nacimiento
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//sexo
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//cargo
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//fecha ingreso
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//horas pagadas
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//dias pagados
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//haber basico
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//bono antiguedad
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//bono produccion
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//subsidio frontera
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//trabajo extraordinario y nocturno
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//dominical
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//otros bonos
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//total ganado
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//aporte afp
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//iva
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//otros descuentos
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//total descuentos
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//liquido pagable
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td></tr>");//firma
	}//fin if no hay
	
	if($numero_filas == 0 && $j == 7) {
		printf("<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td align='center' colspan='10'><font size='16'><b>SIN MOVIMIENTO</b></font></td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>");
	}
	
	$color++;
	$j++;
	$q++;
	$nu++;
  }//fin while


?>


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

<!--

<table border="0" align="center" height="100"><tr><td>&nbsp;</td></tr></table>
-->
</div>
<?php
}//fin if $i
}//fin for
?>
<tr>
    <td colspan="10" style='border-top: solid 1px; border-bottom: solid 1px' align="right"><b>TOTALES</b></td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($total_haber_basico,$n_decimales); ?></td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($total_bono_ant,$n_decimales); ?></td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($total_bono_prod,$n_decimales); ?></td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($total_sub_frontera,$n_decimales); ?></td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($total_trab_extraor_noct,$n_decimales); ?></td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($total_domingo,$n_decimales); ?></td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($total_otros_bonos,$n_decimales); ?></td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($total_ganado,$n_decimales); ?></td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($total_afp,$n_decimales); ?></td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($total_iva,$n_decimales); ?></td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($total_otros_desc,$n_decimales); ?></td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($total_desc,$n_decimales); ?></td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($total_liq_pagable,$n_decimales); ?></td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b>&nbsp;</td>
</tr>
<?php if ($pie_planilla == 1) { //if pie 1 ?>
<tr>
<td colspan="8" align="left"><br/><b>Elaborado por: <?php echo $usuario; ?></b><br/>&nbsp;</td>
<td colspan="8" align="left"><br/><b><?php echo $firma_contabilidad; ?></b><br/>&nbsp;</td>
<td colspan="8" align="left"><br/><b><?php echo $firma_gerencia; ?></b><br/>&nbsp;</td>
</tr>
<?php } //fin if pie 1 ?>
<?php if ($pie_planilla == 0) { //if pie 0 ?>
<tr>
<td colspan="8" align="center"><br/><b><?php echo strtr(strtoupper($nombre_responsable), "àáâãäåæçèéêëìíîïðñòóôõöøùüú", "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÜÚ"); ?><br/>Nombre del Empleador o Representante Legal</b></td>
<td colspan="6" align="center"><br/><b><?php echo $ci_responsable; ?><br/>No. de Documento de Identidad</b></td>
<td colspan="6" align="center"><br/><b><u>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</u><br/>Firma</b></td>
<td colspan="4" align="center"><br/><b><u>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</u><br/>Fecha</b></td>
</tr>
<?php } //fin if pie 0 ?>
</table>
<?php
}// fin if mostrar 0


//este if es para mostrar con el formato reporte
if($mostrar == 1 && $planilla == 0) { //mostrar 1

?>
<table border="0" align="left" width="100%" cellpadding="5">
<tr><td><?php echo $mostrar_logo_reportes; ?>
</td><td align="right"><b>Fecha: <?php echo date("Y-m-d"); ?><br/>Hora: <?php echo date("H:i:s"); ?><br/>Usuario: <?php echo $usuario; ?></b>
</td></tr></table>
<p><br /><center><font color="#000099" size="+1"><b>Reporte Planilla de Sueldos y Salarios</b></font></center></p>
<table border="0" cellpadding="2" align="center" width="100%">
<tr>
<td>	
    <table border="1" align="center" cellpadding="2" width="100%">
        <TR> 
        <TD width="33%"><b>Planilla: </b><?php echo $nom_planilla; ?></TD>
        <TD width="33%"><b>Sucursal: </b><?php echo $nom_sucursal; ?></TD>
        <TD width="33%"><b>Ciudad de la(s) Sucursal(es): </b><?php echo $nom_ciudad; ?></TD>
        </TR>
        <TR> 
        <TD><b>Empleado: </b><?php echo $nom_empleado; ?></TD>
        <TD><b>Genero: </b><?php echo $nom_genero; ?></TD>
        <TD><b>Cargo: </b><?php echo $nom_cargo; ?></TD>
        </TR>
        <TR>
        <TD><b>Mes A&ntilde;o Inicial: </b><?php echo $nom_mesini; ?> de <?php echo $anoini; ?></TD>
        <TD><b>Mes A&ntilde;o Final: </b><?php echo $nom_mesfin; ?> de <?php echo $anofin; ?></TD>
        <TD><b>Ordenado por: </b><?php echo $nom_orden; ?></TD>
        </TR>
        <TR>
        <TD><b>AFP: </b><?php echo $nom_afp; ?></TD>
        <TD><b>Contexto: </b><?php echo $nom_contexto; ?></TD>
        <TD><b>Expresado en: </b><?php echo $nom_moneda_principal; ?></TD>
        </TR>
    </table>

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

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

<table border="1" align="center" cellpadding="2" width="100%">
 	<thead>
    <TR> 
    <TD align="center"><b>No.</b></TD>
    <TD align="center"><b>Cod. Empleado</b></TD>
    <TD align="center"><b>Doc. de Identidad</b></TD>
    <TD align="center"><b>Ext.</b></TD>
    <TD align="center"><b>Apellidos y Nombres</b></TD>
    <TD align="center"><b>Ciudad</b></TD>
    <TD align="center"><b>Pa&iacute;s de Nacionalidad</b></TD>
    <TD align="center"><b>Sucursal</b></TD>
    <TD align="center"><b>Cod. Caja Nal. Salud</b></TD>
    <TD align="center"><b>Nro. Doc.</b></TD>
    <TD align="center"><b>Antig&uuml;edad</b></TD>
    <TD align="center"><b>Fecha de Nacimiento</b></TD>
    <TD align="center"><b>Sexo (V/M)</b></TD>
    <TD align="center"><b>Ocupaci&oacute;n que Desempe&ntilde;a</b></TD>
    <TD align="center"><b>Fecha de Ingreso</b></TD>
    <TD align="center"><b>Fecha de Retiro</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>Horas Pagadas (D&iacute;a)</b></TD>
    <TD align="center"><b>D&iacute;as Pagados (Mes)</b></TD>
    <TD align="center"><b>(1) Haber B&aacute;sico</b></TD>
    <TD align="center"><b>(2) Bono de Antig&uuml;edad</b></TD>
    <TD align="center"><b>(3) Bono de Producci&oacute;n</b></TD>
    <TD align="center"><b>(4) Subsidio de Frontera</b></TD>
    <TD align="center"><b>Cant. Horas Extras</b></TD>
    <TD align="center"><b>(A) Horas Extras</b></TD>
    <TD align="center"><b>Cant. Horas Recargo</b></TD>
    <TD align="center"><b>(B) Horas Recargo</b></TD>
    <TD align="center"><b>Cant. Horas Extraordinarias</b></TD>
    <TD align="center"><b>(C) Horas Extraordinarias</b></TD>
    <TD align="center"><b>Cant. Horas Feriado</b></TD>
    <TD align="center"><b>(D) Horas Feriado</b></TD>
    <TD align="center"><b>(5) Trabajo Extraordinario y Nocturno Suma (A a D)</b></TD>
    <TD align="center"><b>Cant. Horas Dominical y Domingo Trabajado</b></TD>
    <TD align="center"><b>(6) Pago Dominical y Domingo Trabajado</b></TD>
    <TD align="center"><b>(7) Otros Bonos</b></TD>
    <TD align="center"><b>(8) Total Ganado Suma (1 a 7)</b></TD>
    <TD align="center"><b>(E) AFPs 10%</b></TD>
    <TD align="center"><b>(F) AFPs 0.5%</b></TD>
    <TD align="center"><b>(G) AFPs 1.71%</b></TD>
    <TD align="center"><b>(H) AFPs 0.5%</b></TD>
    <TD align="center"><b>(9) Aporte a las AFPs Suma (E a H)</b></TD>
    <TD align="center"><b>(I) Solidario 1%</b></TD>
    <TD align="center"><b>(J) Solidario 5%</b></TD>
    <TD align="center"><b>(K) Solidario 10%</b></TD>
    <TD align="center"><b>Solidario Nacional Suma (I a K)</b></TD>
    <TD align="center"><b>RC-IVA Acumulado Mes Anterior</b></TD>
    <TD align="center"><b>RC-IVA Actualizaci&oacute;n Mes Anterior</b></TD>
    <TD align="center"><b>RC-IVA Acum. + Act. Mes Anterior</b></TD>
    <TD align="center"><b>(10) RC-IVA Mes Actual</b></TD>
    <!--<TD align="center"><b>D&iacute;as Faltas</b></TD>-->
    <TD align="center"><b>Descuentos Faltas</b></TD>
    <TD align="center"><b>(11) Otros Descuentos</b></TD>
    <TD align="center"><b>(12) Total Descuentos Suma (9 a 11)</b></TD>
    <TD align="center"><b>(13) L&iacute;quido Pagable (12 - 8)</b></TD>
    <TD align="center"><b>Cta. Banco</b></TD>
    <TD align="center"><b>Banco</b></TD>
    </TR>
    </thead>
    <tbody class="marcafila">

<?php
$color = 2;
$j = 1;
$nu = 1;
$total_haber_basico = 0;
$total_bono_ant = 0;
$total_bono_prod = 0;
$total_sub_frontera = 0;
$total_trab_extraor_noct = 0;
$total_domingo = 0;
$total_otros_bonos = 0;
$total_ganado = 0;
$total_afp_10 = 0;
$total_afp_05_1 = 0;
$total_afp_171 = 0;
$total_afp_05_2 = 0;
$total_afp = 0;
$total_solidario_1 = 0;
$total_solidario_5 = 0;
$total_solidario_10 = 0;
$total_solidario = 0;
$total_iva_ant = 0;
$total_iva_act = 0;
$total_iva_ant_act = 0;
$total_iva = 0;
//$total_varios_desc = 0;
$total_faltas_desc = 0;
$total_otros_desc = 0;
$total_desc = 0;
$total_liq_pagable = 0;
$total_vacaciones = 0;
$total_faltas = 0;
$total_faltas_dom = 0;
$total_enfermedad = 0;
$total_otros = 0;
$total_hrs_extras = 0;
$total_monto_hrs_extras = 0;
$total_hrs_recargo = 0;
$total_monto_hrs_recargo = 0;
$total_hrs_extraor = 0;
$total_monto_hrs_extraor = 0;
$total_hrs_feriado = 0;
$total_monto_hrs_feriado = 0;
$total_hrs_dom = 0;



	while ($j <= $fin) { //while
	
	$cod_emp = $matriz_pla [$j][2];
	$cod_cargo = $matriz_pla [$j][67];
	$cod_suc = $matriz_pla [$j][68];
	$periodo = $matriz_pla [$j][46];
	
    if($color % 2 == 0) { //if color
	printf("<tr BGCOLOR='#e2e7fa'><td align='center'>%s</td>", $nu);//numero
	} else {
	printf("<tr><td align='center'>%s</td>", $nu);//numero
	}//fin if color
    
	printf("<td align='center'><a href='../../ModuleAgenda/VoucherPerson/index.php?pkyPerson=$cod_empleado&user=$usuario&token=$token' title='Persona'>%s</a></td>", $matriz_pla [$j][2]);//cod empleado
	printf("<td align='right'>%s</td>", $matriz_pla [$j][43]);//ci
	printf("<td align='center'>%s</td>", $matriz_pla [$j][48]);//ext
	$texto = $matriz_pla [$j][3];//empleado
	$texto = strtr(strtoupper($texto), "àáâãäåæçèéêëìíîïðñòóôõöøùüú", "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÜÚ");
	$texto = substr($texto,0,150);
	printf("<td align='left'>%s</td>", $texto);//empleado
	printf("<td align='left'>%s</td>", $matriz_pla [$j][4]);//ciudad
	printf("<td align='left'>%s</td>", $matriz_pla [$j][44]);//nacionalidad
	printf("<td align='left'>%s</td>", $matriz_pla [$j][5]);//sucursal
	printf("<td align='right'>%s</td>", $matriz_pla [$j][7]);//caja de salud
	printf("<td align='right'>%s</td>", $matriz_pla [$j][8]);//contrato
	printf("<td align='right'>%s</td>", $matriz_pla [$j][9]);//antiguedad
	printf("<td align='center'>%s</td>", cambiarFormatoFechaBarra($matriz_pla [$j][39]));//fecha nac
	
	if($matriz_pla [$j][40] == 1) {//if sexo
		printf("<td align='center'>V</td>");//V
	} else {
		printf("<td align='center'>M</td>");//M
	}//fin if sexo
	
	printf("<td align='left'>%s</td>", $matriz_pla [$j][6]);//cargo
	printf("<td align='center'>%s</td>", cambiarFormatoFechaBarra($matriz_pla [$j][10]));//fecha ing
	if($matriz_pla [$j][59] != NULL) {//if ret
		printf("<td align='center'>%s</td>", cambiarFormatoFechaBarra($matriz_pla [$j][59]));//fecha ret
	} else {
		printf("<td align='center'>%s</td>", $matriz_pla [$j][59]);//fecha ret
	}//fin if ret
	printf("<td align='right'>%s</td>", $matriz_pla [$j][14]);//vacaciones
	printf("<td align='right'>%s</td>", $matriz_pla [$j][45]);//faltas
	printf("<td align='right'>%s</td>", $matriz_pla [$j][15]);//faltas domingo
	printf("<td align='right'>%s</td>", $matriz_pla [$j][16]);//enfermedad
	printf("<td align='right'>%s</td>", $matriz_pla [$j][17]);//otros
	printf("<td align='right'>%s</td>", number_format($matriz_pla [$j][71],$n_decimales));//horas pagadas
	printf("<td align='right'>%s</td>", $matriz_pla [$j][13]+$matriz_pla [$j][45]);//dias pagados
	printf("<td align='right'>%s</td>", number_format($matriz_pla [$j][70],$n_decimales));//salario por dias trabajados
	printf("<td align='right'>%s</td>", number_format($matriz_pla [$j][30],$n_decimales));//bono antiguedad
	printf("<td align='right'>%s</td>", number_format($bono_produccion,$n_decimales));//bono produccion
	printf("<td align='right'>%s</td>", number_format($subsidio_frontera,$n_decimales));//subsidio frontera
	printf("<td align='right'>%s</td>", $matriz_pla [$j][19]);//horas extras
	printf("<td align='right'>%s</td>", number_format($matriz_pla [$j][20],$n_decimales));//monto horas extras
	printf("<td align='right'>%s</td>", $matriz_pla [$j][21]);//horas recargo
	printf("<td align='right'>%s</td>", number_format($matriz_pla [$j][22],$n_decimales));//monto horas recargo
	printf("<td align='right'>%s</td>", $matriz_pla [$j][25]);//horas extraor
	printf("<td align='right'>%s</td>", number_format($matriz_pla [$j][26],$n_decimales));//monto horas extraor
	printf("<td align='right'>%s</td>", $matriz_pla [$j][27]);//horas feriado
	printf("<td align='right'>%s</td>", number_format($matriz_pla [$j][28],$n_decimales));//monto horas feriado
	$trab_extraor_nocturno = $matriz_pla [$j][20]+$matriz_pla [$j][22]+$matriz_pla [$j][26]+$matriz_pla [$j][28];
	printf("<td align='right'>%s</td>", number_format($trab_extraor_nocturno,$n_decimales));//trabajo extraordinario y nocturno
	printf("<td align='right'>%s</td>", $matriz_pla [$j][23]);//horas domingo
	printf("<td align='right'>%s</td>", number_format($matriz_pla [$j][24],$n_decimales));//dominical
	printf("<td align='right'><a href='../../ModuleHumanResources/ReportSalaryPayroll/report.php?rep=9&tipo=2&empleado_det=$cod_emp&cargo_det=$cod_cargo&sucursal_det=$cod_suc&bono_det=0&periodo_det=$periodo&mostrar_det=$mostrar&usuario_det=$usuario&token=$token' title='Detalle Bonos'>%s</a></td>", number_format($matriz_pla [$j][29],$n_decimales));//otros bonos
	$suma_total_ganado = $matriz_pla [$j][70]+$matriz_pla [$j][30]+$bono_produccion+$subsidio_frontera+$trab_extraor_nocturno+$matriz_pla [$j][24]+$matriz_pla [$j][29];
	printf("<td align='right'>%s</td>", number_format($suma_total_ganado,$n_decimales));//total ganado
	printf("<td align='right'>%s</td>", number_format($matriz_pla [$j][32]*10/12.71,$n_decimales));//aporte afp 10%
	printf("<td align='right'>%s</td>", number_format($matriz_pla [$j][32]*0.5/12.71,$n_decimales));//aporte afp 0.5%
	printf("<td align='right'>%s</td>", number_format($matriz_pla [$j][32]*1.71/12.71,$n_decimales));//aporte afp 1.71%
	printf("<td align='right'>%s</td>", number_format($matriz_pla [$j][32]*0.5/12.71,$n_decimales));//aporte afp 0.5%
	
	printf("<td align='right'>%s</td>", number_format($matriz_pla [$j][32],$n_decimales));//aporte afp
	
	if($suma_total_ganado > 13000) {
	$suma_total_ganado_13000 = $suma_total_ganado - 13000;
	} else {
	$suma_total_ganado_13000 = 0;	
	}
	printf("<td align='right'>%s</td>", number_format($suma_total_ganado_13000 * 0.01,$n_decimales));//(total ganado - 13000)*1%
	if($suma_total_ganado > 25000) {
	$suma_total_ganado_25000 = $suma_total_ganado - 25000;
	} else {
	$suma_total_ganado_25000 = 0;	
	}
	printf("<td align='right'>%s</td>", number_format($suma_total_ganado_25000 * 0.05,$n_decimales));//(total ganado - 25000)*5%
	if($suma_total_ganado > 35000) {
	$suma_total_ganado_35000 = $suma_total_ganado - 35000;
	} else {
	$suma_total_ganado_35000 = 0;	
	}
	printf("<td align='right'>%s</td>", number_format($suma_total_ganado_35000 * 0.1,$n_decimales));//(total ganado - 35000)*10%
	
	printf("<td align='right'>%s</td>", number_format($matriz_pla [$j][35],$n_decimales));//solidario nacional
	printf("<td align='right'>%s</td>", number_format($matriz_pla [$j][62],$n_decimales));//iva anterior
	printf("<td align='right'>%s</td>", number_format($matriz_pla [$j][63],$n_decimales));//iva actualizacion
	printf("<td align='right'>%s</td>", number_format($matriz_pla [$j][64],$n_decimales));//iva anterior actualizado periodo
	printf("<td align='right'>%s</td>", number_format($matriz_pla [$j][36],$n_decimales));//iva
	//printf("<td align='right'>%s</td>", number_format($matriz_pla [$j][45],0));//dias faltas
	printf("<td align='right'>%s</td>", number_format($matriz_pla [$j][34],$n_decimales));//desc faltas
	printf("<td align='right'><a href='../../ModuleHumanResources/ReportSalaryPayroll/report.php?rep=9&tipo=2&empleado_det=$cod_emp&cargo_det=$cod_cargo&sucursal_det=$cod_suc&bono_det=1&periodo_det=$periodo&mostrar_det=$mostrar&usuario_det=$usuario&token=$token' title='Detalle Descuentos'>%s</a></td>", number_format($matriz_pla [$j][33],$n_decimales));//otros descuentos
	$suma_total_desc = $matriz_pla [$j][32]+$matriz_pla [$j][33]+$matriz_pla [$j][34]+$matriz_pla [$j][35]+$matriz_pla [$j][36];
	printf("<td align='right'>%s</td>", number_format($suma_total_desc,$n_decimales));//total descuentos
	$liquido_pagable = $suma_total_ganado-$suma_total_desc;
	printf("<td align='right'>%s</td>", number_format($liquido_pagable,$n_decimales));//liquido pagable
	printf("<td align='right'>%s</td>", $matriz_pla [$j][41]);//cta banco
	printf("<td align='right'>%s</td></tr>", $matriz_pla [$j][66]);//banco
	
		
	
	$total_haber_basico = $total_haber_basico+$matriz_pla [$j][70];
	$total_bono_ant = $total_bono_ant+$matriz_pla [$j][30];
	$total_bono_prod = $total_bono_prod+$bono_produccion;
	$total_sub_frontera = $total_sub_frontera+$subsidio_frontera;
	$total_trab_extraor_noct = $total_trab_extraor_noct+$trab_extraor_nocturno;
	$total_domingo = $total_domingo+$matriz_pla [$j][24];
	$total_otros_bonos = $total_otros_bonos+$matriz_pla [$j][29];
	$total_ganado = $total_ganado+$suma_total_ganado;
	$total_afp_10 = $total_afp_10 + round($matriz_pla [$j][32]*10/12.71,2);
	$total_afp_05_1 = $total_afp_05_1 + round($matriz_pla [$j][32]*0.5/12.71,2);
	$total_afp_171 = $total_afp_171 + round($matriz_pla [$j][32]*1.71/12.71,2);
	$total_afp_05_2 = $total_afp_05_2 + round($matriz_pla [$j][32]*0.5/12.71,2);
	$total_afp = $total_afp+$matriz_pla [$j][32];
	
	$total_solidario_1 = $total_solidario_1 + round($suma_total_ganado_13000 * 0.01,2);
	$total_solidario_5 = $total_solidario_5 + round($suma_total_ganado_25000 * 0.05,2);
	$total_solidario_10 = $total_solidario_10 + round($suma_total_ganado_35000 * 0.1,2);
	$total_solidario = $total_solidario+$matriz_pla [$j][35];
	$total_iva_ant = $total_iva_ant+$matriz_pla [$j][62];
	$total_iva_act = $total_iva_act+$matriz_pla [$j][63];
	$total_iva_ant_act = $total_iva_ant_act+$matriz_pla [$j][64];
	$total_iva = $total_iva+$matriz_pla [$j][36];
	//$total_varios_desc = $total_varios_desc+$matriz_pla [$j][33];
	$total_faltas_desc = $total_faltas_desc+$matriz_pla [$j][34];
	$total_otros_desc = $total_otros_desc+$matriz_pla [$j][33];
	$total_desc = $total_desc+$suma_total_desc;
	$total_liq_pagable = $total_liq_pagable+$liquido_pagable;
	$total_vacaciones = $total_vacaciones+$matriz_pla [$j][14];
	$total_faltas = $total_faltas+$matriz_pla [$j][45];
	$total_faltas_dom = $total_faltas_dom+$matriz_pla [$j][15];
	$total_enfermedad = $total_enfermedad+$matriz_pla [$j][16];
	$total_otros = $total_otros+$matriz_pla [$j][17];
	$total_hrs_extras = $total_hrs_extras+$matriz_pla [$j][19];
	$total_monto_hrs_extras = $total_monto_hrs_extras+$matriz_pla [$j][20];
	$total_hrs_recargo = $total_hrs_recargo+$matriz_pla [$j][21];
	$total_monto_hrs_recargo = $total_monto_hrs_recargo+$matriz_pla [$j][22];
	$total_hrs_extraor = $total_hrs_extraor+$matriz_pla [$j][25];
	$total_monto_hrs_extraor = $total_monto_hrs_extraor+$matriz_pla [$j][26];
	$total_hrs_feriado = $total_hrs_feriado+$matriz_pla [$j][27];
	$total_monto_hrs_feriado = $total_monto_hrs_feriado+$matriz_pla [$j][28];
	$total_hrs_dom = $total_hrs_dom+$matriz_pla [$j][23];
	
	$nu++;
	$color++;
	$j++;
  
	} //fin while
?>
 
<tr BGCOLOR='#ffcccc'><td colspan="16"><b>Total</b></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_vacaciones,0)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_faltas,0)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_faltas_dom,0)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_enfermedad,0)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_otros,0)); ?></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_haber_basico,$n_decimales)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_bono_ant,$n_decimales)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_bono_prod,$n_decimales)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_sub_frontera,$n_decimales)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_hrs_extras,0)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_monto_hrs_extras,$n_decimales)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_hrs_recargo,0)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_monto_hrs_recargo,$n_decimales)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_hrs_extraor,0)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_monto_hrs_extraor,$n_decimales)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_hrs_feriado,0)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_monto_hrs_feriado,$n_decimales)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_trab_extraor_noct,$n_decimales)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_hrs_dom,0)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_domingo,$n_decimales)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_otros_bonos,$n_decimales)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_ganado,$n_decimales)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_afp_10,$n_decimales)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_afp_05_1,$n_decimales)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_afp_171,$n_decimales)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_afp_05_2,$n_decimales)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_afp,$n_decimales)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_solidario_1,$n_decimales)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_solidario_5,$n_decimales)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_solidario_10,$n_decimales)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_solidario,$n_decimales)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_iva_ant,$n_decimales)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_iva_act,$n_decimales)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_iva_ant_act,$n_decimales)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_iva,$n_decimales)); ?></td>
<!--<td align="right"><?php printf("<b>%s</b>", number_format($total_varios_desc,$n_decimales)); ?></td>-->
<td align="right"><?php printf("<b>%s</b>", number_format($total_faltas_desc,$n_decimales)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_otros_desc,$n_decimales)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_desc,$n_decimales)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_liq_pagable,$n_decimales)); ?></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<?php if ($pie_planilla == 1) { //if pie 1 ?>
<tr>
<td colspan="20" align="left"><br/><b>Elaborado por: <?php echo $usuario; ?></b><br/>&nbsp;</td>
<td colspan="20" align="left"><br/><b><?php echo $firma_contabilidad; ?></b><br/>&nbsp;</td>
<td colspan="20" align="left"><br/><b><?php echo $firma_gerencia; ?></b><br/>&nbsp;</td>
</tr>
<?php } //fin if pie 1 ?>
</tbody>
</table>

<?php	
}// fin if mostrar 1



//Planilla de sueldos (ampliada) 

//este if es para mostrar con el formato presentacion
if($mostrar == 0 && $planilla == 1) { //mostrar 0

$j = 1;
$nu = 1;
for($i = 1; $i <= $var; $i++) {//for
?>
<?php if($mostrar_logo_reportes_formato == 0) { //if formato 0 ?>
<table border="1" align="center" cellpadding="2" width="1160">
<tr>
	<td width="490"><b>Nombre o Raz&oacute;n Social: </b><?php echo $nombre_empresa; ?></td>
    <td width="490"><b>NIT: </b><?php echo $mi_nit; ?></td>
</tr>
<tr>
	<td width="490"><b>No. Empleador Min. de Trabajo: </b><?php echo $num_min_trabajo; ?></td>
    <td width="490"><b>No. Empleador Caja de Salud: </b><?php echo $num_caja_salud; ?></td>
</tr>
</table>
<table border="0" align="center" cellpadding="2" width="1160">
<tr>
	<td width="300"><?php //echo $usuario; ?></td>
    <td width="390" align="center"><b>PLANILLA DE SUELDOS Y SALARIOS</b></td>
    <td width="300" align="right"><b>P&aacute;gina: <?php echo $i; ?> de <?php echo $var; ?></b></td>
</tr>
<tr>
	<td width="300">&nbsp;</td>
    <td width="390" align="center">Cifras en Bolivianos</td>
    <td width="300" align="right">CORRESPONDIENTE AL MES DE <?php echo strtoupper($nom_mesini); ?> DE <?php echo $anoini; ?></td>
</tr>
</table>
<?php } //fin if formato 0 ?>

<?php if($mostrar_logo_reportes_formato == 1) { //if formato 1 ?>
<table border="1" align="center" cellpadding="2" width="1160">
<tr>
	<td rowspan="2" width="15%"><img src="../../Images/logo.jpg" alt="Logo" width="100" height="40" /></td>
    <td width="490"><b>Nombre o Raz&oacute;n Social: </b><?php echo $nombre_empresa; ?></td>
    <td width="490"><b>NIT: </b><?php echo $mi_nit; ?></td>
</tr>
<tr>
	<td width="490"><b>No. Empleador Min. de Trabajo: </b><?php echo $num_min_trabajo; ?></td>
    <td width="490"><b>No. Empleador Caja de Salud: </b><?php echo $num_caja_salud; ?></td>
</tr>
</table>
<table border="0" align="center" cellpadding="2" width="1160">
<tr>
	<td width="300"><?php //echo $usuario; ?></td>
    <td width="390" align="center"><b>PLANILLA DE SUELDOS Y SALARIOS</b></td>
    <td width="300" align="right"><b>P&aacute;gina: <?php echo $i; ?> de <?php echo $var; ?></b></td>
</tr>
<tr>
	<td width="300">&nbsp;</td>
    <td width="390" align="center">Cifras en Bolivianos</td>
    <td width="300" align="right">CORRESPONDIENTE AL MES DE <?php echo strtoupper($nom_mesini); ?> DE <?php echo $anoini; ?></td>
</tr>
</table>
<?php } //fin if formato 1 ?>

<br />

<table border="1" align="center" cellpadding="2" width="1160" height="600">
    <TR> 
    <TD align="center" width="10" style='border-bottom: solid 1px'><b>No.</b></TD>
    <TD align="center" width="40" style='border-bottom: solid 1px'><b>Docu-<br/>mento de Iden-<br/>tidad</b></TD>
    <TD align="center" width="40" style='border-bottom: solid 1px'><b>Ext</b></TD>
    <TD align="center" width="280" style='border-bottom: solid 1px'><b>Apellidos y Nombres</b></TD>
    <TD align="center" width="40" style='border-bottom: solid 1px'><b>Cta. Bancaria</b></TD>
    <TD align="center" width="20" style='border-bottom: solid 1px'><b>Sexo<br />(V/M)</b></TD>
    <TD align="center" width="50" style='border-bottom: solid 1px'><b>Fecha de Nacimiento</b></TD>
    <TD align="center" width="120" style='border-bottom: solid 1px'><b>Ocupaci&oacute;n que Desempe&ntilde;a</b></TD>
    <!--<TD align="center" width="20" style='border-bottom: solid 1px'><b>Nivel</b></TD>-->
    <TD align="center" width="20" style='border-bottom: solid 1px'><b>AFP</b></TD>
    <TD align="center" width="50" style='border-bottom: solid 1px'><b>Fecha de Ingreso</b></TD>
    <TD align="center" width="50" style='border-bottom: solid 1px'><b>Fecha de Retiro</b></TD>
    <TD align="center" width="40" style='border-bottom: solid 1px'><b>Haber B&aacute;sico</b></TD>
    <TD align="center" width="20" style='border-bottom: solid 1px'><b>Nro. D&iacute;as Trabajados (Mes)</b></TD>
    <TD align="center" width="20" style='border-bottom: solid 1px'><b>Horas Pagadas (D&iacute;a)</b></TD>
    <TD align="center" width="20" style='border-bottom: solid 1px'><b>D&iacute;as Pagados (Mes)<br/>(A)</b></TD>
    <TD align="center" width="40" style='border-bottom: solid 1px'><b>Bono de Antig&uuml;edad<br/>(B)</b></TD>
    <TD align="center" width="20" style='border-bottom: solid 1px'><b>Nro. Horas Extras<br/>(C)</b></TD>
    <TD align="center" width="20" style='border-bottom: solid 1px'><b>Horas Extras Pagadas<br/>(D)</b></TD>
    <TD align="center" width="20" style='border-bottom: solid 1px'><b>Nro. Horas Extras Dom.<br/>(E)</b></TD>
    <TD align="center" width="20" style='border-bottom: solid 1px'><b>Horas Extras Dom. Pagadas<br/>(F)</b></TD>
    <TD align="center" width="20" style='border-bottom: solid 1px'><b>Nro. Horas Recargo Noc.<br/>(G)</b></TD>
    <TD align="center" width="20" style='border-bottom: solid 1px'><b>Horas Recargo Noc. Pagadas<br/>(H)</b></TD>
    <TD align="center" width="40" style='border-bottom: solid 1px'><b>Otros Ingresos<br/>(I)</b></TD>
    <TD align="center" width="40" style='border-bottom: solid 1px'><b>Total Ganado A+B+D+F+H+I<br/>(J)</b></TD>
    <TD align="center" width="40" style='border-bottom: solid 1px'><b>AFPs 10%<br/>(K)</b></TD>
    <TD align="center" width="40" style='border-bottom: solid 1px'><b>AFPs 0.5%<br/>(L)</b></TD>
    <TD align="center" width="40" style='border-bottom: solid 1px'><b>AFPs 1.71%<br/>(M)</b></TD>
    <TD align="center" width="40" style='border-bottom: solid 1px'><b>AFPs 0.5%<br/>(N)</b></TD>
    <TD align="center" width="40" style='border-bottom: solid 1px'><b>Solidario 1%<br/>(O)</b></TD>
    <TD align="center" width="40" style='border-bottom: solid 1px'><b>Solidario 5%<br/>(P)</b></TD>
    <TD align="center" width="40" style='border-bottom: solid 1px'><b>Solidario 10%<br/>(Q)</b></TD>
    <TD align="center" width="40" style='border-bottom: solid 1px'><b>RC-IVA 13%<br/>(R)</b></TD>
    <TD align="center" width="20" style='border-bottom: solid 1px'><b>Nro. d&iacute;as no trabajados</b></TD>
    <TD align="center" width="40" style='border-bottom: solid 1px'><b>Otros Dctos.<br/>(S)</b></TD>
    <TD align="center" width="40" style='border-bottom: solid 1px'><b>Total Dctos. K+L+N+M+O+<br/>P+Q+R+S<br/>(T)</b></TD>
    <TD align="center" width="40" style='border-bottom: solid 1px'><b>L&iacute;quido Pagable J-T<br/>(U)</b></TD>
    <TD align="center" width="120" style='border-bottom: solid 1px'><b>Firma</b></TD>
    </TR>

<?php
$color = 2;
$q = 1;//
  while ($q <= $filas_por_pagina) { //while
  
  if($numero_filas == 0) {//if filas
	printf("<tr><td align='center' style='border-bottom: solid 1px'>%s</td>", $matriz_pla [$j][3]);//fecha
  } else { //else filas
    if($color % 2 == 0) { //if color
		if($matriz_pla [$j][3] != NULL) {
		printf("<tr BGCOLOR='#e2e7fa'><td align='center' style='border-bottom: solid 1px'>%s</td>", $nu);//numero
		} else { 
		printf("<tr BGCOLOR='#e2e7fa'><td align='center' style='border-bottom: solid 1px'><hr /></td>");//numero vacio
		}
	} else {
		if($matriz_pla [$j][3] != NULL) {
		printf("<tr><td align='center' style='border-bottom: solid 1px'>%s</td>", $nu);//numero
		} else { 
		printf("<tr><td align='center' style='border-bottom: solid 1px'><hr /></td>");//numero vacio
		}
	}//fin if color
  }//fin filas
    
	if($matriz_pla [$j][3] != NULL) {//if no hay
	
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", $matriz_pla [$j][43]);//ci
	printf("<td align='center' style='border-bottom: solid 1px'>%s</td>", $matriz_pla [$j][48]);//ext
	$texto = $matriz_pla [$j][3];//empleado
	$texto = strtr(strtoupper($texto), "àáâãäåæçèéêëìíîïðñòóôõöøùüú", "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÜÚ");
	$texto = substr($texto,0,150);
	printf("<td align='left' style='border-bottom: solid 1px'>%s</td>", $texto);//empleado
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", $matriz_pla [$j][41]);//cta banco
		
	if($matriz_pla [$j][40] == 1) {//if sexo
		printf("<td align='center' style='border-bottom: solid 1px'>V</td>");//V
	} else {
		printf("<td align='center' style='border-bottom: solid 1px'>M</td>");//M
	}//fin if sexo
	
	if($matriz_pla [$j][39] <> NULL) {
	printf("<td align='center' style='border-bottom: solid 1px'>%s</td>", cambiarFormatoFechaBarra($matriz_pla [$j][39]));//fecha nac
	} else {
	printf("<td align='center' style='border-bottom: solid 1px'>%s</td>", $matriz_pla [$j][39]);//fecha nac	
	}
	
	printf("<td align='left' style='border-bottom: solid 1px'>%s</td>", $matriz_pla [$j][6]);//cargo
	printf("<td align='left' style='border-bottom: solid 1px'>%s</td>", $matriz_pla [$j][84]);//nombre AFP 
	
	if($matriz_pla [$j][10] <> NULL) {
	printf("<td align='center' style='border-bottom: solid 1px'>%s</td>", cambiarFormatoFechaBarra($matriz_pla [$j][10]));//fecha ing
	} else {
	printf("<td align='center' style='border-bottom: solid 1px'>%s</td>", $matriz_pla [$j][10]);//fecha ing
	}
	
	if($matriz_pla [$j][59] <> NULL) {
	printf("<td align='center' style='border-bottom: solid 1px'>%s</td>", cambiarFormatoFechaBarra($matriz_pla [$j][59]));//fecha ret
	} else {
	printf("<td align='center' style='border-bottom: solid 1px'>%s</td>", $matriz_pla [$j][59]);//fecha ret
	}
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($matriz_pla [$j][18],$n_decimales));//salario basico
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", $matriz_pla [$j][13]+$matriz_pla [$j][45]);//dias pagados
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($matriz_pla [$j][71],$n_decimales));//horas pagadas
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($matriz_pla [$j][70],$n_decimales));//salario por dias trabajados
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($matriz_pla [$j][30],$n_decimales));//bono antiguedad
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", $matriz_pla [$j][19]);//horas extras
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($matriz_pla [$j][20],$n_decimales));//monto horas extras
	//$trab_extraor_nocturno = $matriz_pla [$j][20]+$matriz_pla [$j][22]+$matriz_pla [$j][26]+$matriz_pla [$j][28];
	//printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($trab_extraor_nocturno,$n_decimales));//trabajo extraordinario y nocturno
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", $matriz_pla [$j][23]);//horas domingo
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($matriz_pla [$j][24],$n_decimales));//dominical
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", $matriz_pla [$j][25]);//horas extraor
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($matriz_pla [$j][26],$n_decimales));//monto horas extraor
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($matriz_pla [$j][29],$n_decimales));//otros bonos
	$suma_total_ganado = $matriz_pla [$j][70]+$matriz_pla [$j][30]+$bono_produccion+$subsidio_frontera+$trab_extraor_nocturno+$matriz_pla [$j][24]+$matriz_pla [$j][29];
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($suma_total_ganado,$n_decimales));//total ganado
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($matriz_pla [$j][32]*10/12.71,$n_decimales));//aporte afp 10%
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($matriz_pla [$j][32]*0.5/12.71,$n_decimales));//aporte afp 0.5%
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($matriz_pla [$j][32]*1.71/12.71,$n_decimales));//aporte afp 1.71%
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($matriz_pla [$j][32]*0.5/12.71,$n_decimales));//aporte afp 0.5%
	if($suma_total_ganado > 13000) {
	$suma_total_ganado_13000 = $suma_total_ganado - 13000;
	} else {
	$suma_total_ganado_13000 = 0;	
	}
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($suma_total_ganado_13000 * 0.01,$n_decimales));//(total ganado - 13000)*1%
	if($suma_total_ganado > 25000) {
	$suma_total_ganado_25000 = $suma_total_ganado - 25000;
	} else {
	$suma_total_ganado_25000 = 0;	
	}
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($suma_total_ganado_25000 * 0.05,$n_decimales));//(total ganado - 25000)*5%
	if($suma_total_ganado > 35000) {
	$suma_total_ganado_35000 = $suma_total_ganado - 35000;
	} else {
	$suma_total_ganado_35000 = 0;	
	}
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($suma_total_ganado_35000 * 0.1,$n_decimales));//(total ganado - 35000)*10%
	
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($matriz_pla [$j][36],$n_decimales));//iva
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($matriz_pla [$j][45],$n_decimales));//faltas
	
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($matriz_pla [$j][33]+$matriz_pla [$j][34],$n_decimales));//desc varios + desc faltas
	$suma_total_desc = $matriz_pla [$j][32]+$matriz_pla [$j][35]+$matriz_pla [$j][36]+$matriz_pla [$j][33]+$matriz_pla [$j][34];
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($suma_total_desc,$n_decimales));//total descuentos
	$liquido_pagable = $suma_total_ganado-$suma_total_desc;
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($liquido_pagable,$n_decimales));//liquido pagable
	printf("<td style='border-bottom: solid 1px'>&nbsp;</td></tr>");//firma
		
	
	$total_haber_basico = $total_haber_basico+$matriz_pla [$j][18];
	$total_salario_dias_trabajados = $total_salario_dias_trabajados+$matriz_pla [$j][70];
	$total_bono_ant = $total_bono_ant+$matriz_pla [$j][30];
	$total_horas_extras = $total_horas_extras+$matriz_pla [$j][19];
	$total_monto_horas_extras = $total_monto_horas_extras+$matriz_pla [$j][20];
	$total_horas_domingo = $total_horas_domingo+$matriz_pla [$j][23];
	$total_monto_horas_domingo = $total_monto_horas_domingo+$matriz_pla [$j][24];
	$total_horas_extraor = $total_horas_extraor+$matriz_pla [$j][25];
	$total_monto_horas_extraor = $total_monto_horas_extraor+$matriz_pla [$j][26];
	$total_monto_otros_ing = $total_monto_otros_ing+$matriz_pla [$j][29];
	$total_ganado = $total_ganado+$suma_total_ganado;
	$total_afp_10 = $total_afp_10 + round($matriz_pla [$j][32]*10/12.71,2);
	$total_afp_05_1 = $total_afp_05_1 + round($matriz_pla [$j][32]*0.5/12.71,2);
	$total_afp_171 = $total_afp_171 + round($matriz_pla [$j][32]*1.71/12.71,2);
	$total_afp_05_2 = $total_afp_05_2 + round($matriz_pla [$j][32]*0.5/12.71,2);
	$total_solidario_1 = $total_solidario_1 + round($suma_total_ganado_13000 * 0.01,2);
	$total_solidario_5 = $total_solidario_5 + round($suma_total_ganado_25000 * 0.05,2);
	$total_solidario_10 = $total_solidario_10 + round($suma_total_ganado_35000 * 0.1,2);
	$total_iva = $total_iva+$matriz_pla [$j][36];
	$total_faltas = $total_faltas+$matriz_pla [$j][45];
	$total_otros_desc = $total_otros_desc+$matriz_pla [$j][33]+$matriz_pla [$j][34];
	$total_desc = $total_desc+$suma_total_desc;
	$total_liq_pagable = $total_liq_pagable+$liquido_pagable;
	} else { //else if no hay
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//ci
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//ext
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//empleado
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//cta banco
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//sexo
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//fecha nac
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//cargo
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//nombre AFP
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//fecha ing
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//fecha ret
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//salario basico
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//dias pagados
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//horas pagados
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//salario por dias trabajados
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//bono antiguedad
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//horas extras
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//monto horas extras
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//horas domingo
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//dominical
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//horas extraor
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//monto horas extraor
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//otros bonos
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//total ganado
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//aporte afp 10%
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//aporte afp 0.5%
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//aporte afp 1.71%
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//aporte afp 0.5%
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//(total ganado - 13000)*1%
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//(total ganado - 25000)*5%
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//(total ganado - 25000)*10%
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//iva
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//faltas
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//otros desc
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//total desc
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//liquido pagable
	
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td></tr>");//firma
	}//fin if no hay
	
	if($numero_filas == 0 && $j == 7) {
		printf("<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td align='center' colspan='10'><font size='16'><b>SIN MOVIMIENTO</b></font></td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>");
	}
	
	$color++;
	$j++;
	$q++;
	$nu++;
  }//fin while


?>


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

<!--

<table border="0" align="center" height="100"><tr><td>&nbsp;</td></tr></table>
-->
</div>
<?php
}//fin if $i
}//fin for
?>
<tr>
    <td colspan="11" style='border-top: solid 1px; border-bottom: solid 1px' align="right"><b>TOTALES</b></td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($total_haber_basico,$n_decimales); ?></td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b>&nbsp;</td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b>&nbsp;</td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($total_salario_dias_trabajados,$n_decimales); ?></td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($total_bono_ant,$n_decimales); ?></td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($total_horas_extras,$n_decimales); ?></td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($total_monto_horas_extras,$n_decimales); ?></td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($total_horas_domingo,$n_decimales); ?></td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($total_monto_horas_domingo,$n_decimales); ?></td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($total_horas_extraor,$n_decimales); ?></td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($total_monto_horas_extraor,$n_decimales); ?></td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($total_monto_otros_ing,$n_decimales); ?></td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($total_ganado,$n_decimales); ?></td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($total_afp_10,$n_decimales); ?></td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($total_afp_05_1,$n_decimales); ?></td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($total_afp_171,$n_decimales); ?></td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($total_afp_05_2,$n_decimales); ?></td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($total_solidario_1,$n_decimales); ?></td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($total_solidario_5,$n_decimales); ?></td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($total_solidario_10,$n_decimales); ?></td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($total_iva,$n_decimales); ?></td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($total_faltas,$n_decimales); ?></td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($total_otros_desc,$n_decimales); ?></td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($total_desc,$n_decimales); ?></td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($total_liq_pagable,$n_decimales); ?></td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b>&nbsp;</td>
</tr>
<?php if ($pie_planilla == 1) { //if pie 1 ?>
<tr>
<td colspan="11" align="left"><br/><b>Elaborado por: <?php echo $usuario; ?></b><br/>&nbsp;</td>
<td colspan="14" align="left"><br/><b><?php echo $firma_contabilidad; ?></b><br/>&nbsp;</td>
<td colspan="12" align="left"><br/><b><?php echo $firma_gerencia; ?></b><br/>&nbsp;</td>
</tr>
<?php } //fin if pie 1 ?>
<?php if ($pie_planilla == 0) { //if pie 0 ?>
<tr>
<td colspan="11" align="center"><br/><b><?php echo strtr(strtoupper($nombre_responsable), "àáâãäåæçèéêëìíîïðñòóôõöøùüú", "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÜÚ"); ?><br/>Nombre del Empleador o Representante Legal</b></td>
<td colspan="9" align="center"><br/><b><?php echo $ci_responsable; ?><br/>No. de Documento de Identidad</b></td>
<td colspan="9" align="center"><br/><b><u>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</u><br/>Firma</b></td>
<td colspan="8" align="center"><br/><b><u>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</u><br/>Fecha</b></td>
<tr>
<?php } //fin if pie 0 ?>
</table>
<?php
}// fin if mostrar 0


//este if es para mostrar con el formato reporte
if($mostrar == 1 && $planilla == 1) { //mostrar 1

?>
<table border="0" align="left" width="100%" cellpadding="5">
<tr><td><?php echo $mostrar_logo_reportes; ?>
</td><td align="right"><b>Fecha: <?php echo date("Y-m-d"); ?><br/>Hora: <?php echo date("H:i:s"); ?><br/>Usuario: <?php echo $usuario; ?></b>
</td></tr></table>
<p><br /><center><font color="#000099" size="+1"><b>Reporte Planilla de Sueldos y Salarios Ampliada</b></font></center></p>
<table border="0" cellpadding="2" align="center" width="100%">
<tr>
<td>	
    <table border="1" align="center" cellpadding="2" width="100%">
        <TR> 
        <TD width="33%"><b>Planilla: </b><?php echo $nom_planilla; ?></TD>
        <TD width="33%"><b>Sucursal: </b><?php echo $nom_sucursal; ?></TD>
        <TD width="33%"><b>Ciudad de la(s) Sucursal(es): </b><?php echo $nom_ciudad; ?></TD>
        </TR>
        <TR> 
        <TD><b>Empleado: </b><?php echo $nom_empleado; ?></TD>
        <TD><b>Genero: </b><?php echo $nom_genero; ?></TD>
        <TD><b>Cargo: </b><?php echo $nom_cargo; ?></TD>
        </TR>
        <TR>
        <TD><b>Mes A&ntilde;o Inicial: </b><?php echo $nom_mesini; ?> de <?php echo $anoini; ?></TD>
        <TD><b>Mes A&ntilde;o Final: </b><?php echo $nom_mesfin; ?> de <?php echo $anofin; ?></TD>
        <TD><b>Ordenado por: </b><?php echo $nom_orden; ?></TD>
        </TR>
        <TR>
        <TD><b>AFP: </b><?php echo $nom_afp; ?></TD>
        <TD><b>Contexto: </b><?php echo $nom_contexto; ?></TD>
        <TD><b>Expresado en: </b><?php echo $nom_moneda_principal; ?></TD>
        </TR>
    </table>

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

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

<table border="1" align="center" cellpadding="2" width="100%">
 	<thead>
    <TR> 
    <TD align="center"><b>1</b></TD>
    <TD align="center"><b>2</b></TD>
    <TD align="center"><b>3</b></TD>
    <TD align="center"><b>4</b></TD>
    <TD align="center"><b>5</b></TD>
    <TD align="center"><b>6</b></TD>
    <TD align="center"><b>7</b></TD>
    <TD align="center"><b>8</b></TD>
    <TD align="center"><b>9</b></TD>
    <TD align="center"><b>10</b></TD>
    <TD align="center"><b>11</b></TD>
    <TD align="center"><b>12</b></TD>
    <TD align="center"><b>13</b></TD>
    <TD align="center"><b>14</b></TD>
    <TD align="center"><b>15</b></TD>
    <TD align="center"><b>16</b></TD>
    <TD align="center"><b>17</b></TD>
    <TD align="center"><b>18</b></TD>
    <TD align="center"><b>19</b></TD>
    <TD align="center"><b>20</b></TD>
    <TD align="center"><b>21</b></TD>
    <TD align="center"><b>22</b></TD>
    <TD align="center"><b>23</b></TD>
    <TD align="center"><b>24</b></TD>
    <TD align="center"><b>25</b></TD>
    <TD align="center"><b>26</b></TD>
    <TD align="center"><b>27</b></TD>
    <TD align="center"><b>28</b></TD>
    <TD align="center"><b>29</b></TD>
    <TD align="center"><b>30</b></TD>
    <TD align="center"><b>31</b></TD>
    <TD align="center"><b>32</b></TD>
    <TD align="center"><b>33</b></TD>
    <TD align="center"><b>34</b></TD>
    <TD align="center"><b>35</b></TD>
    <TD align="center"><b>36</b></TD>
    <TD align="center"><b>37</b></TD>
    <TD align="center"><b>38</b></TD>
    <TD align="center"><b>39</b></TD>
    <TD align="center"><b>40</b></TD>
    <TD align="center"><b>41</b></TD>
    <TD align="center"><b>42</b></TD>
    <TD align="center"><b>43</b></TD>
    <TD align="center"><b>44</b></TD>
    </TR>
    <TR> 
    <TD align="center"><b>No.</b></TD>
    <TD align="center"><b>Tipo Doc. de Identidad</b></TD>
    <TD align="center"><b>Nro. de Doc. de Identidad</b></TD>
    <TD align="center"><b>Ext. del Doc. de Identidad</b></TD>
    <TD align="center"><b>AFP a la que Aporta</b></TD>
    <TD align="center"><b>NUA/CUA</b></TD>
    <TD align="center"><b>Apellido Paterno</b></TD>
    <TD align="center"><b>Apellido Materno</b></TD>
    <TD align="center"><b>Apellido de Casada</b></TD>
    <TD align="center"><b>Primer Nombre</b></TD>
    <TD align="center"><b>Otros Nombres</b></TD>
    <TD align="center"><b>Pa&iacute;s de Nacionalidad</b></TD>
    <TD align="center"><b>Fecha de Nacimiento</b></TD>
    <TD align="center"><b>Sexo</b></TD>
    <TD align="center"><b>Jubilado</b></TD>
    <TD align="center"><b>Clasificaci&oacute;n Laboral</b></TD>
    <TD align="center"><b>Cargo</b></TD>
    <TD align="center"><b>Fecha de Ingreso</b></TD>
    <TD align="center"><b>Modalidad de Contrato</b></TD>
    <TD align="center"><b>Fecha de Retiro</b></TD>
    <TD align="center"><b>Horas Pagadas (D&iacute;a)</b></TD>
    <TD align="center"><b>D&iacute;as Pagados (Mes)</b></TD>
    <TD align="center"><b>Nro. de Dominicales</b></TD>
    <TD align="center"><b>Domingos Trabajados</b></TD>
    <TD align="center"><b>Horas Extra</b></TD>
    <TD align="center"><b>Horas de Recargo Nocturno</b></TD>
    <TD align="center"><b>Horas Extra Dominicales</b></TD>
    <TD align="center"><b>Haber B&aacute;sico</b></TD>
    <TD align="center"><b>Salario Dominical</b></TD>
    <TD align="center"><b>Monto Pagado por Domingo Trabajado</b></TD>
    <TD align="center"><b>Monto Pagado por Horas Extra</b></TD>
    <TD align="center"><b>Monto Pagado por Horas Nocturnas</b></TD>
    <TD align="center"><b>Monto Pagado por Horas Extra Dominicales</b></TD>
    <TD align="center"><b>Bono de Antig&uuml;edad</b></TD>
    <TD align="center"><b>Bono de Producci&oacute;n</b></TD>
    <TD align="center"><b>Subsidio de Frontera</b></TD>
    <TD align="center"><b>Otros Bonos o Pagos</b></TD>
    <TD align="center"><b>Total Ganado</b></TD>
    <TD align="center"><b>Aporte a las AFPs</b></TD>
    <TD align="center"><b>RC-IVA</b></TD>
    <TD align="center"><b>Otros Descuentos</b></TD>
    <TD align="center"><b>Total Descuentos Suma</b></TD>
    <TD align="center"><b>L&iacute;quido Pagable</b></TD>
    <TD align="center"><b>Sucursal o Ubicaci&oacute;n Adicional</b></TD>
    </TR>
    </thead>
    <tbody class="marcafila">

<?php
$color = 2;
$j = 1;
$nu = 1;
$total_haber_basico = 0;
$total_bono_ant = 0;
$total_bono_prod = 0;
$total_sub_frontera = 0;
$total_trab_extraor_noct = 0;
$total_domingo = 0;
$total_otros_bonos = 0;
$total_ganado = 0;
$total_afp = 0;
$total_iva = 0;
$total_otros_desc = 0;
$total_desc = 0;
$total_liq_pagable = 0;
$total_vacaciones = 0;
$total_faltas = 0;
$total_faltas_dom = 0;
$total_enfermedad = 0;
$total_otros = 0;
$total_hrs_extras = 0;
$total_monto_hrs_extras = 0;
$total_hrs_recargo = 0;
$total_monto_hrs_recargo = 0;
$total_hrs_extraor = 0;
$total_monto_hrs_extraor = 0;
$total_hrs_feriado = 0;
$total_monto_hrs_feriado = 0;
$total_hrs_dom = 0;



	while ($j <= $fin) { //while
	
	$cod_emp = $matriz_pla [$j][2];
	$cod_cargo = $matriz_pla [$j][67];
	$cod_suc = $matriz_pla [$j][68];
	$periodo = $matriz_pla [$j][46];
	
    if($color % 2 == 0) { //if color
	printf("<tr BGCOLOR='#e2e7fa'><td align='center'>%s</td>", $nu);//numero
	} else {
	printf("<tr><td align='center'>%s</td>", $nu);//numero
	}//fin if color
    //printf("<td align='center'><a href='../../ModuleAgenda/VoucherPerson/index.php?pkyPerson=$cod_empleado&user=$usuario&token=$token' title='Persona'>%s</a></td>", $matriz_pla [$j][2]);//cod empleado
	printf("<td align='center'>%s</td>", $matriz_pla [$j][47]);//tipo documento
	printf("<td align='right'>%s</td>", $matriz_pla [$j][43]);//nro documento
	printf("<td align='right'>%s</td>", $matriz_pla [$j][48]);//extension documento
	printf("<td align='right'>%s</td>", $matriz_pla [$j][49]);//afp
	printf("<td align='right'>%s</td>", $matriz_pla [$j][50]);//nua
	$texto = $matriz_pla [$j][51];//ap pat
	$texto = strtr(strtoupper($texto), "àáâãäåæçèéêëìíîïðñòóôõöøùüú", "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÜÚ");
	//$texto = substr($texto,0,150);
	printf("<td align='left'>%s</td>", $texto);//ap pat
	$texto = $matriz_pla [$j][52];//ap mat
	$texto = strtr(strtoupper($texto), "àáâãäåæçèéêëìíîïðñòóôõöøùüú", "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÜÚ");
	//$texto = substr($texto,0,150);
	printf("<td align='left'>%s</td>", $texto);//ap mat
	$texto = $matriz_pla [$j][53];//ap casada
	$texto = strtr(strtoupper($texto), "àáâãäåæçèéêëìíîïðñòóôõöøùüú", "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÜÚ");
	//$texto = substr($texto,0,150);
	printf("<td align='left'>%s</td>", $texto);//ap casada
	$texto = $matriz_pla [$j][54];//nombre
	$texto = strtr(strtoupper($texto), "àáâãäåæçèéêëìíîïðñòóôõöøùüú", "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÜÚ");
	//$texto = substr($texto,0,150);
	printf("<td align='left'>%s</td>", $texto);//nombre
	$texto = $matriz_pla [$j][55];//nombre otros
	$texto = strtr(strtoupper($texto), "àáâãäåæçèéêëìíîïðñòóôõöøùüú", "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÜÚ");
	//$texto = substr($texto,0,150);
	printf("<td align='left'>%s</td>", $texto);//nombre otros
	printf("<td align='left'>%s</td>", $matriz_pla [$j][44]);//nacionalidad
	printf("<td align='center'>%s</td>", cambiarFormatoFechaBarra($matriz_pla [$j][39]));//fecha nac
	if($matriz_pla [$j][40] == 1) {//if sexo 0=mujer, 1=varon
		printf("<td align='center'>1</td>");//V
	} else {
		printf("<td align='center'>0</td>");//M
	}//fin if sexo
	printf("<td align='center'>%s</td>", $matriz_pla [$j][56]);//jubilado 0=no, 1=si
	printf("<td align='left'>%s</td>", $matriz_pla [$j][57]);//clasifcacion laboral
	printf("<td align='left'>%s</td>", $matriz_pla [$j][6]);//cargo
	printf("<td align='center'>%s</td>", cambiarFormatoFechaBarra($matriz_pla [$j][10]));//fecha ing
	printf("<td align='center'>%s</td>", $matriz_pla [$j][58]);//modalidad contrato
	if($matriz_pla [$j][59] <> NULL) {//if baja
	printf("<td align='center'>%s</td>", cambiarFormatoFechaBarra($matriz_pla [$j][59]));//fecha baja
	} else {
	printf("<td align='center'>%s</td>", $matriz_pla [$j][59]);//fecha baja	
	}//fin if baja
	printf("<td align='right'>%s</td>", $matriz_pla [$j][71]);//horas pagadas
	printf("<td align='right'>%s</td>", $matriz_pla [$j][13]+$matriz_pla [$j][45]);//dias pagados
	printf("<td align='right'>%s</td>", $matriz_pla [$j][60]);//nro dominicales
	printf("<td align='right'>%s</td>", $matriz_pla [$j][61]);//domingos trabajados
	printf("<td align='right'>%s</td>", $matriz_pla [$j][19]);//horas extras
	printf("<td align='right'>%s</td>", $matriz_pla [$j][21]);//horas recargo
	//printf("<td align='right'>%s</td>", $matriz_pla [$j][25]);//horas extraor
	printf("<td align='right'>%s</td>", $matriz_pla [$j][23]);//horas domingo
	printf("<td align='right'>%s</td>", number_format($matriz_pla [$j][70],$n_decimales));//salario por dias trabajados
	printf("<td align='right'>%s</td>", number_format($matriz_pla [$j][24],$n_decimales));//dominical repito1
	printf("<td align='right'>%s</td>", number_format($matriz_pla [$j][24],$n_decimales));//dominical repito2
	printf("<td align='right'>%s</td>", number_format($matriz_pla [$j][20],$n_decimales));//monto horas extras
	printf("<td align='right'>%s</td>", number_format($matriz_pla [$j][22],$n_decimales));//monto horas recargo
	//printf("<td align='right'>%s</td>", number_format($matriz_pla [$j][26],$n_decimales));//monto horas extraor
	printf("<td align='right'>%s</td>", number_format($matriz_pla [$j][24],$n_decimales));//dominical repito3
	printf("<td align='right'>%s</td>", number_format($matriz_pla [$j][30],$n_decimales));//bono antiguedad
	printf("<td align='right'>%s</td>", number_format($bono_produccion,$n_decimales));//bono produccion
	printf("<td align='right'>%s</td>", number_format($subsidio_frontera,$n_decimales));//subsidio frontera
	printf("<td align='right'>%s</td>", number_format($matriz_pla [$j][29],$n_decimales));//otros bonos
	$trab_extraor_nocturno = $matriz_pla [$j][20]+$matriz_pla [$j][22]+$matriz_pla [$j][26]+$matriz_pla [$j][28];
	$suma_total_ganado = $matriz_pla [$j][70]+$matriz_pla [$j][30]+$bono_produccion+$subsidio_frontera+$trab_extraor_nocturno+$matriz_pla [$j][24]+$matriz_pla [$j][29];
	
	printf("<td align='right'>%s</td>", number_format($suma_total_ganado,$n_decimales));//total ganado
	printf("<td align='right'>%s</td>", number_format($matriz_pla [$j][32]+$matriz_pla [$j][35],$n_decimales));//aporte afp + solidario
	printf("<td align='right'>%s</td>", number_format($matriz_pla [$j][36],$n_decimales));//iva
	printf("<td align='right'>%s</td>", number_format($matriz_pla [$j][33]+$matriz_pla [$j][34],$n_decimales));//desc varios+desc faltas
	
	$suma_total_desc = $matriz_pla [$j][32]+$matriz_pla [$j][33]+$matriz_pla [$j][34]+$matriz_pla [$j][35]+$matriz_pla [$j][36];
	printf("<td align='right'>%s</td>", number_format($suma_total_desc,$n_decimales));//total descuentos
	$liquido_pagable = $suma_total_ganado-$suma_total_desc;
	printf("<td align='right'>%s</td>", number_format($liquido_pagable,$n_decimales));//liquido pagable
	printf("<td align='left'>%s</td></tr>", $matriz_pla [$j][5]);//sucursal
	
	/*
	printf("<td align='right'>%s</td>", $matriz_pla [$j][9]);//antiguedad
	printf("<td align='left'>%s</td>", $matriz_pla [$j][4]);//ciudad
	
	printf("<td align='right'>%s</td>", $matriz_pla [$j][7]);//caja de salud
	printf("<td align='right'>%s</td>", $matriz_pla [$j][8]);//contrato
		
	printf("<td align='right'>%s</td>", $matriz_pla [$j][14]);//vacaciones
	printf("<td align='right'>%s</td>", $matriz_pla [$j][45]);//faltas
	printf("<td align='right'>%s</td>", $matriz_pla [$j][15]);//faltas domingo
	printf("<td align='right'>%s</td>", $matriz_pla [$j][16]);//enfermedad
	printf("<td align='right'>%s</td>", $matriz_pla [$j][17]);//otros
		
	printf("<td align='right'>%s</td>", $matriz_pla [$j][21]);//horas recargo
	
		
	printf("<td align='right'>%s</td>", $matriz_pla [$j][27]);//horas feriado
	printf("<td align='right'>%s</td>", number_format($matriz_pla [$j][28],$n_decimales));//monto horas feriado
	
	printf("<td align='right'>%s</td>", number_format($trab_extraor_nocturno,$n_decimales));//trabajo extraordinario y nocturno
	
	printf("<td align='right'>%s</td></tr>", $matriz_pla [$j][41]);//cta banco
	*/
		
	
	$total_haber_basico = $total_haber_basico+$matriz_pla [$j][70];
	$total_bono_ant = $total_bono_ant+$matriz_pla [$j][30];
	$total_bono_prod = $total_bono_prod+$bono_produccion;
	$total_sub_frontera = $total_sub_frontera+$subsidio_frontera;
	$total_trab_extraor_noct = $total_trab_extraor_noct+$trab_extraor_nocturno;
	$total_domingo = $total_domingo+$matriz_pla [$j][24];
	$total_otros_bonos = $total_otros_bonos+$matriz_pla [$j][29];
	$total_ganado = $total_ganado+$suma_total_ganado;
	$total_afp = $total_afp+$matriz_pla [$j][32]+$matriz_pla [$j][35];
	$total_iva = $total_iva+$matriz_pla [$j][36];
	$total_otros_desc = $total_otros_desc+$matriz_pla [$j][33]+$matriz_pla [$j][34];
	$total_desc = $total_desc+$suma_total_desc;
	$total_liq_pagable = $total_liq_pagable+$liquido_pagable;
	$total_vacaciones = $total_vacaciones+$matriz_pla [$j][14];
	$total_faltas = $total_faltas+$matriz_pla [$j][45];
	$total_faltas_dom = $total_faltas_dom+$matriz_pla [$j][15];
	$total_enfermedad = $total_enfermedad+$matriz_pla [$j][16];
	$total_otros = $total_otros+$matriz_pla [$j][17];
	$total_hrs_extras = $total_hrs_extras+$matriz_pla [$j][19];
	$total_monto_hrs_extras = $total_monto_hrs_extras+$matriz_pla [$j][20];
	$total_hrs_recargo = $total_hrs_recargo+$matriz_pla [$j][21];
	$total_monto_hrs_recargo = $total_monto_hrs_recargo+$matriz_pla [$j][22];
	$total_hrs_extraor = $total_hrs_extraor+$matriz_pla [$j][25];
	$total_monto_hrs_extraor = $total_monto_hrs_extraor+$matriz_pla [$j][26];
	$total_hrs_feriado = $total_hrs_feriado+$matriz_pla [$j][27];
	$total_monto_hrs_feriado = $total_monto_hrs_feriado+$matriz_pla [$j][28];
	$total_hrs_dom = $total_hrs_dom+$matriz_pla [$j][23];
	
	$nu++;
	$color++;
	$j++;
  
	} //fin while
?>
 
<tr BGCOLOR='#ffcccc'><td colspan="24"><b>Total</b></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_hrs_extras,0)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_hrs_recargo,0)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_hrs_dom,0)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_haber_basico,$n_decimales)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_domingo,$n_decimales)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_domingo,$n_decimales)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_monto_hrs_extras,$n_decimales)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_monto_hrs_recargo,$n_decimales)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_domingo,$n_decimales)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_bono_ant,$n_decimales)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_bono_prod,$n_decimales)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_sub_frontera,$n_decimales)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_otros_bonos,$n_decimales)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_ganado,$n_decimales)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_afp,$n_decimales)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_iva,$n_decimales)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_otros_desc,$n_decimales)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_desc,$n_decimales)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_liq_pagable,$n_decimales)); ?></td>
<td>&nbsp;</td>
<?php if ($pie_planilla == 1) { //if pie 1 ?>
<tr>
<td colspan="15" align="left"><br/><b>Elaborado por: <?php echo $usuario; ?></b><br/>&nbsp;</td>
<td colspan="14" align="left"><br/><b><?php echo $firma_contabilidad; ?></b><br/>&nbsp;</td>
<td colspan="15" align="left"><br/><b><?php echo $firma_gerencia; ?></b><br/>&nbsp;</td>
</tr>
<?php } //fin if pie 1 ?>
</tr>

</tbody>
</table>

<!--
<td align="right"><?php printf("<b>%s</b>", number_format($total_vacaciones,0)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_faltas,0)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_faltas_dom,0)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_enfermedad,0)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_otros,0)); ?></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_hrs_extraor,0)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_monto_hrs_extraor,$n_decimales)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_hrs_feriado,0)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_monto_hrs_feriado,$n_decimales)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_trab_extraor_noct,$n_decimales)); ?></td>
-->





<?php	
}// fin if mostrar 1



//Planilla tributaria

$total_ganado2 = 0;
$total_afp2 = 0;
$total_sueldo_neto = 0;
$total_min_no_imp = 0;
$total_dif_suj_imp = 0;
$total_iva13 = 0;
$total_form110 = 0;
$total_iva110 = 0;
$total_13_2smn = 0;
$total_sal_adm_trib = 0;
$total_sal_dep = 0;
$total_sal_iva_mes_ant = 0;
$total_actuliz = 0;
$total_iva_actualiz = 0;
$total_sal_fav_dep = 0;
$total_iva_util = 0;
$total_iva_pagar = 0;
$total_iva_sig_mes = 0;


//fechas planilla para ufv
$resultplaiva = mysqli_query($link, "select fldDate as fecha_mes_actual, fldPreviousDate as fecha_mes_anterior 
from hrsSalaryPayroll
where 
fldPeriod >= '$vfechaini' and 
fldPeriod <= '$vfechafin' and 
sysEnabled = 1 and sysAuthorized = 1;");
while ($row = mysqli_fetch_array($resultplaiva)) {
	$fecha_mes_actual = $row['fecha_mes_actual'];
	$fecha_mes_anterior = $row['fecha_mes_anterior'];
}
mysqli_free_result($resultplaiva);

//tasa de cambio mes actual ufv para iva
$resulttciva = mysqli_query($link, "select a.fldRate as tasa 
from actExchangeRateDetail a, actExchangeRate b
where 
b.pkyExchangeRate = a.codExchangeRate and 
b.fldExclusive = 0 and 
b.fldDate = '$fecha_mes_actual' and 
a.codBaseCurrency = '$cod_moneda_principal' and 
a.codTargetCurrency = '$cod_moneda_actualizacion_iva' and 
b.sysEnabled = 1 and b.sysAuthorized = 1;");
while ($row = mysqli_fetch_array($resulttciva)) {
	$tipo_cambio_actual = $row['tasa'];
}
mysqli_free_result($resulttciva);

//tasa de cambio mes anterior ufv para iva
$resulttciva = mysqli_query($link, "select a.fldRate as tasa 
from actExchangeRateDetail a, actExchangeRate b
where 
b.pkyExchangeRate = a.codExchangeRate and 
b.fldExclusive = 0 and 
b.fldDate = '$fecha_mes_anterior' and 
a.codBaseCurrency = '$cod_moneda_principal' and 
a.codTargetCurrency = '$cod_moneda_actualizacion_iva' and 
b.sysEnabled = 1 and b.sysAuthorized = 1;");
while ($row = mysqli_fetch_array($resulttciva)) {
	$tipo_cambio_anterior = $row['tasa'];
}
mysqli_free_result($resulttciva);

//este if es para mostrar con el formato presentacion
if($mostrar == 0 && $planilla == 2) { //mostrar 0

$j = 1;
$nu = 1;
for($i = 1; $i <= $var; $i++) {//for
?>
<?php if($mostrar_logo_reportes_formato == 0) { //if formato 0 ?>
<table border="1" align="center" cellpadding="2" width="990">
<tr>
	<td width="490"><b>Nombre o Raz&oacute;n Social: </b><?php echo $nombre_empresa; ?></td>
    <td width="490"><b>NIT: </b><?php echo $mi_nit; ?></td>
</tr>
<!--
<tr>
	<td width="490"><b>No. Empleador Min. de Trabajo: </b><?php echo $num_min_trabajo; ?></td>
    <td width="490"><b>No. Empleador Caja de Salud: </b><?php echo $num_caja_salud; ?></td>
</tr>
-->
</table>
<table border="0" align="center" cellpadding="2" width="990">
<tr>
	<td width="300" align="center"><b><?php echo strtoupper($nom_moneda_actualizacion_iva); ?> Anterior: <?php echo number_format($tipo_cambio_anterior,5); ?></b></td>
    <td width="390" align="center"><b>PLANILLA TRIBUTARIA</b></td>
    <td width="300" align="right"><b>P&aacute;gina: <?php echo $i; ?> de <?php echo $var; ?></b></td>
</tr>
<tr>
	<td width="300" align="center"><b><?php echo strtoupper($nom_moneda_actualizacion_iva); ?> Actual: <?php echo number_format($tipo_cambio_actual,5); ?></b></td>
    <td width="390" align="center">Cifras en Bolivianos</td>
    <td width="300" align="right">CORRESPONDIENTE AL MES DE <?php echo strtoupper($nom_mesini); ?> DE <?php echo $anoini; ?></td>
</tr>
</table>
<?php } //fin if formato 0 ?>

<?php if($mostrar_logo_reportes_formato == 1) { //if formato 1 ?>
<table border="1" align="center" cellpadding="2" width="990">
<tr>
	<td width="15%"><img src="../../Images/logo.jpg" alt="Logo" width="100" height="40" /></td>
	<td width="490"><b>Nombre o Raz&oacute;n Social: </b><?php echo $nombre_empresa; ?></td>
    <td width="490"><b>NIT: </b><?php echo $mi_nit; ?></td>
</tr>
<!--
<tr>
	<td width="490"><b>No. Empleador Min. de Trabajo: </b><?php echo $num_min_trabajo; ?></td>
    <td width="490"><b>No. Empleador Caja de Salud: </b><?php echo $num_caja_salud; ?></td>
</tr>
-->
</table>
<table border="0" align="center" cellpadding="2" width="990">
<tr>
	<td width="300" align="center"><b><?php echo strtoupper($nom_moneda_actualizacion_iva); ?> Anterior: <?php echo number_format($tipo_cambio_anterior,5); ?></b></td>
    <td width="390" align="center"><b>PLANILLA TRIBUTARIA</b></td>
    <td width="300" align="right"><b>P&aacute;gina: <?php echo $i; ?> de <?php echo $var; ?></b></td>
</tr>
<tr>
	<td width="300" align="center"><b><?php echo strtoupper($nom_moneda_actualizacion_iva); ?> Actual: <?php echo number_format($tipo_cambio_actual,5); ?></b></td>
    <td width="390" align="center">Cifras en Bolivianos</td>
    <td width="300" align="right">CORRESPONDIENTE AL MES DE <?php echo strtoupper($nom_mesini); ?> DE <?php echo $anoini; ?></td>
</tr>
</table>
<?php } //fin if formato 1 ?>

<br />

<table border="1" align="center" cellpadding="2" width="990" height="600">
    <TR> 
    <TD align="center" width="10" style='border-bottom: solid 1px'><b>No.</b></TD>
    <TD align="center" width="250" style='border-bottom: solid 1px'><b>Apellidos y Nombres</b></TD>
    <!--<TD align="center" width="40" style='border-bottom: solid 1px'><b>Nacionalidad</b></TD>
    <TD align="center" width="40" style='border-bottom: solid 1px'><b>C.I.</b></TD>
    <TD align="center" width="80" style='border-bottom: solid 1px'><b>Cargo</b></TD>
    <TD align="center" width="50" style='border-bottom: solid 1px'><b>Fecha de Ingreso</b></TD>-->
    <TD align="center" width="40" style='border-bottom: solid 1px'><b>Total Ganado</b></TD>
    <TD align="center" width="40" style='border-bottom: solid 1px'><b>AFPs</b></TD>
    <TD align="center" width="40" style='border-bottom: solid 1px'><b>Sueldo Neto</b></TD>
    <TD align="center" width="40" style='border-bottom: solid 1px'><b>M&iacute;nimo no Imponible</b></TD>
    <TD align="center" width="40" style='border-bottom: solid 1px'><b>Dif. Sujeto a Impto.</b></TD>
    <TD align="center" width="40" style='border-bottom: solid 1px'><b>IVA 13%</b></TD>
    <TD align="center" width="40" style='border-bottom: solid 1px'><b>Form. 110</b></TD>
    <TD align="center" width="40" style='border-bottom: solid 1px'><b>Form. 110 (13%)</b></TD>
    <TD align="center" width="40" style='border-bottom: solid 1px'><b>13% Sobre Dos SMN</b></TD>
    <TD align="center" width="40" style='border-bottom: solid 1px'><b>Saldo a Favor Adm. Trib.</b></TD>
    <TD align="center" width="40" style='border-bottom: solid 1px'><b>Saldo a Favor Depend.</b></TD>
    <TD align="center" width="40" style='border-bottom: solid 1px'><b>Saldo RC-IVA Mes Ant.</b></TD>
    <TD align="center" width="40" style='border-bottom: solid 1px'><b>Actualiz.</b></TD>
    <TD align="center" width="40" style='border-bottom: solid 1px'><b>Saldo RC-IVA Actualiz.</b></TD>
    <TD align="center" width="40" style='border-bottom: solid 1px'><b>Total Saldo a Favor Depend.</b></TD>
    <TD align="center" width="40" style='border-bottom: solid 1px'><b>CF-IVA Utilizado</b></TD>
    <TD align="center" width="40" style='border-bottom: solid 1px'><b>RC-IVA a Pagar</b></TD>
    <TD align="center" width="40" style='border-bottom: solid 1px'><b>RC-IVA a Favor Sig. Mes</b></TD>
    </TR>

<?php
$color = 2;
$q = 1;//
  while ($q <= $filas_por_pagina) { //while
    $cod_empleado = $matriz_pla [$j][2];
  if($numero_filas == 0) {//if filas
	printf("<tr><td align='center' style='border-bottom: solid 1px'>%s</td>", $matriz_pla [$j][3]);//empleado
  } else { //else filas
    if($color % 2 == 0) { //if color
		if($matriz_pla [$j][3] != NULL) {
		printf("<tr BGCOLOR='#e2e7fa'><td align='center' style='border-bottom: solid 1px'>%s</td>", $nu);//numero
		} else { 
		printf("<tr BGCOLOR='#e2e7fa'><td align='center' style='border-bottom: solid 1px'><hr /></td>");//numero vacio
		}
	} else {
		if($matriz_pla [$j][3] != NULL) {
		printf("<tr><td align='center' style='border-bottom: solid 1px'>%s</td>", $nu);//numero
		} else { 
		printf("<tr><td align='center' style='border-bottom: solid 1px'><hr /></td>");//numero vacio
		}
	}//fin if color
  }//fin filas
    
	if($matriz_pla [$j][3] != NULL) {//if no hay
	
	$texto = $matriz_pla [$j][3];//empleado
	$texto = strtr(strtoupper($texto), "àáâãäåæçèéêëìíîïðñòóôõöøùüú", "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÜÚ");
	$texto = substr($texto,0,150);
	printf("<td align='left' style='border-bottom: solid 1px'>%s</td>", $texto);//empleado
	/*
	printf("<td align='left' style='border-bottom: solid 1px'>%s</td>", $matriz_pla [$j][44]);//nacionalidad
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", $matriz_pla [$j][43]);//ci
	printf("<td align='left' style='border-bottom: solid 1px'>%s</td>", $matriz_pla [$j][6]);//cargo
	if($matriz_pla [$j][10] <> NULL) {
	printf("<td align='center' style='border-bottom: solid 1px'>%s</td>", cambiarFormatoFechaBarra($matriz_pla [$j][10]));//fecha ing
	} else {
	printf("<td align='center' style='border-bottom: solid 1px'>%s</td>", $matriz_pla [$j][10]);//fecha ing	
	}
	*/
			
	$trab_extraor_nocturno = $matriz_pla [$j][20]+$matriz_pla [$j][22]+$matriz_pla [$j][26]+$matriz_pla [$j][28];
	$suma_total_ganado = $matriz_pla [$j][70]+$matriz_pla [$j][30]+$bono_produccion+$subsidio_frontera+$trab_extraor_nocturno+$matriz_pla [$j][24]+$matriz_pla [$j][29];
	$porcentaje_afp = 0.8729;//12.71%(1-0.1271)
	$sueldo_neto = $suma_total_ganado * $porcentaje_afp - $matriz_pla [$j][35];
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($suma_total_ganado,$n_decimales));//total ganado
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($matriz_pla [$j][32],$n_decimales));//afps
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($sueldo_neto,$n_decimales));//sueldo neto
	if($sueldo_neto > $matriz_pla [$j][73]) {
		$min_no_imp = $matriz_pla [$j][73];
	} else {
		$min_no_imp = $sueldo_neto;
	}
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($min_no_imp,$n_decimales));//minimo no imponible
	$dif_sujeto_imp = $sueldo_neto - $min_no_imp;
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($dif_sujeto_imp,$n_decimales));//dif sujeto a impuesto
	$iva13 = $dif_sujeto_imp * 13/100;
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($iva13,$n_decimales));//iva 13%
	/*
	$periodo = $matriz_pla [$j][46];
	$mesp = date("m",strtotime($periodo)); 
	$anop = date("Y",strtotime($periodo)); 
	$fechainip = $anop.'-'.$mesp.'-01';
	$fechafinp = $anop.'-'.$mesp.'-31';
	//formulario de impuestos

	$resultimp = mysqli_query($link, "select b.fldAmount as monto, b.fldVAT as iva
from hrsTaxesForm a, hrsTaxesFormDetail b
where 
a.pkyTaxesForm = b.codTaxesForm and 
b.codEmployee = '$cod_empleado' and 
a.fldPeriod >= '$fechainip' and 
a.fldPeriod <= '$fechafinp' and 
a.sysEnabled = 1 and a.sysAuthorized = 1;");
	while ($row = mysqli_fetch_array($resultimp)) {
		$monto_iva_110 = $row['monto']; 
		$iva_110 = $row['iva']; 
	}
	mysqli_free_result($resultimp);
	*/
	$iva_110 = $matriz_pla [$j][12];
	$form_110 = round($iva_110*100/13,0);
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($form_110,$n_decimales));//form 110
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($iva_110,$n_decimales));//iva form 110
	if($acumula_2_smn_iva == 0) {//if iva 0
		if($iva13 > ($matriz_pla [$j][73]*13/100)) {
			$sobre2smn = $matriz_pla [$j][73]*13/100;
		} else {
			$sobre2smn = $iva13;
		}
	}//fin if iva 0
	if($acumula_2_smn_iva == 1) {//if iva 1
		if($sueldo_neto >= $matriz_pla [$j][73]) {
			$sobre2smn = $matriz_pla [$j][73]*13/100;
		} else {
			$sobre2smn = $iva13;
		}
	}//fin if iva 1
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($sobre2smn,$n_decimales));//13% sobre 2 smn
	
	if($iva13 > ($iva_110+$sobre2smn)) {
		$sal_fav_adm = $iva13-$iva_110-$sobre2smn;
	} else {
		$sal_fav_adm = 0;
	}
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($sal_fav_adm,$n_decimales));//saldo a favor adm trib
	
	if(($iva_110+$sobre2smn) > $iva13) {
		$sal_fav_dep = $iva_110+$sobre2smn-$iva13;
	} else {
		$sal_fav_dep = 0;
	}
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($sal_fav_dep,$n_decimales));//saldo a favor dep
	$sal_iva_mes_ant = $matriz_pla [$j][62];
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($sal_iva_mes_ant,$n_decimales));//saldo iva mes anterior
	/*
	//tc mes anterior
	$fechamesant = strtotime('-1 month', strtotime($fechafinp));
	$fechamesant = date ('Y-m-d', $fechamesant);
	$resulttcant = 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 <= '$fechamesant' AND fldExclusive = '0') AND 
T2.fldDate = T1.fldDate AND 
T2.fldTime = T1.fldTime AND 
sysEnabled = 1 AND sysAuthorized = 1;");
	while ($row = mysqli_fetch_array($resulttcant)) {
		$tc_ant = $row['tc'];
	}
	mysqli_free_result($resulttcant);
	
	//ufv mes anterior
	$cod_moneda_ufv = 4;
	$resultufvant = mysqli_query($link, "select fldRate as monto 
from actExchangeRateDetail 
where 
codExchangeRate = '$tc_ant' and 
codBaseCurrency = '$cod_moneda_principal' and 
codTargetCurrency = '$cod_moneda_ufv' and 
sysEnabled = 1 and sysAuthorized = 1;");
	while ($row = mysqli_fetch_array($resultufvant)) {
		$ufv_ant = $row['monto'];
	}
	mysqli_free_result($resultufvant);
	
	//tc mes periodo
	$resulttcper = 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 <= '$fechafinp' AND fldExclusive = '0') AND 
T2.fldDate = T1.fldDate AND 
T2.fldTime = T1.fldTime AND 
sysEnabled = 1 AND sysAuthorized = 1;");
	while ($row = mysqli_fetch_array($resulttcper)) {
		$tc_per = $row['tc'];
	}
	mysqli_free_result($resulttcper);
	
	//ufv mes periodo
	$resultufvper = mysqli_query($link, "select fldRate as monto 
from actExchangeRateDetail 
where 
codExchangeRate = '$tc_per' and 
codBaseCurrency = '$cod_moneda_principal' and 
codTargetCurrency = '$cod_moneda_ufv' and 
sysEnabled = 1 and sysAuthorized = 1;");
	while ($row = mysqli_fetch_array($resultufvper)) {
		$ufv_per = $row['monto'];
	}
	mysqli_free_result($resultufvper);
	
	$actualizacion_ufv = ($sal_iva_mes_ant*$ufv_per/$ufv_ant)-$sal_iva_mes_ant;
	*/
	$actualizacion_ufv = $matriz_pla [$j][63];
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($actualizacion_ufv,$n_decimales));//actualizacion ufv
	$saldo_iva_actualizado = $sal_iva_mes_ant+$actualizacion_ufv;
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($saldo_iva_actualizado,$n_decimales));//saldo iva actuaizado
	$total_saldo_iva_fav_dep = $sal_fav_dep+$saldo_iva_actualizado;
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($total_saldo_iva_fav_dep,$n_decimales));//saldo favor iva dep
	
	if($sal_fav_adm > $total_saldo_iva_fav_dep) {
		$iva_utilizado = $saldo_iva_actualizado;
	} else {
		$iva_utilizado = $sal_fav_adm;
	}
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($iva_utilizado,$n_decimales));//cf iva utilizado
	$iva_a_pagar = $sal_fav_adm-$iva_utilizado;
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($iva_a_pagar,$n_decimales));//iva a pagar
	$iva_favor_sig_mes = $total_saldo_iva_fav_dep-$iva_utilizado;
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td></tr>", number_format($iva_favor_sig_mes,$n_decimales));//iva a favor sig mes
	
	$total_ganado2 = $total_ganado2+$suma_total_ganado;
	$total_afp2 = $total_afp2+$matriz_pla [$j][32];	
	$total_sueldo_neto = $total_sueldo_neto+$sueldo_neto;
	$total_min_no_imp = $total_min_no_imp+$min_no_imp;
	$total_dif_suj_imp = $total_dif_suj_imp+$dif_sujeto_imp;
	$total_iva13 = $total_iva13+$iva13;
	$total_form110 = $total_form110+$form_110;
	$total_iva110 = $total_iva110+$iva_110;
	$total_13_2smn = $total_13_2smn+$sobre2smn;
	$total_sal_adm_trib = $total_sal_adm_trib+$sal_fav_adm;
	$total_sal_dep = $total_sal_dep+$sal_fav_dep;
	$total_sal_iva_mes_ant = $total_sal_iva_mes_ant+$sal_iva_mes_ant;
	$total_actuliz = $total_actuliz+$actualizacion_ufv;
	$total_iva_actualiz = $total_iva_actualiz+$saldo_iva_actualizado;
	$total_sal_fav_dep = $total_sal_fav_dep+$total_saldo_iva_fav_dep;
	$total_iva_util = $total_iva_util+$iva_utilizado;
	$total_iva_pagar = $total_iva_pagar+$iva_a_pagar;
	$total_iva_sig_mes = $total_iva_sig_mes+$iva_favor_sig_mes;

	
	} else { //else if no hay
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//empleado
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//total ganado
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//afp
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//sueldo neto
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//min no imponible
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//dif sujeto a imp.
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//iva 13%
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//form 110
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//iva 110
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//13% 2 smn
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//saldo favor adm trib
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//saldo favor dep
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//saldo iva mes ant
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//actualizacion iva
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//saldo iva actualizado
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//total saldo favor dep
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//iva utilizado
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//iva a pagar
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td></tr>");//iva a favor sig mes
	
	}//fin if no hay
	
	if($numero_filas == 0 && $j == 7) {
		printf("<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td align='center' colspan='10'><font size='16'><b>SIN MOVIMIENTO</b></font></td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>");
	}
	
	$color++;
	$j++;
	$q++;
	$nu++;
  }//fin while


?>


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

<!--

<table border="0" align="center" height="100"><tr><td>&nbsp;</td></tr></table>
-->
</div>
<?php
}//fin if $i
}//fin for
?>
<tr>
    <td colspan="2" style='border-top: solid 1px; border-bottom: solid 1px' align="right"><b>TOTALES</b></td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($total_ganado2,$n_decimales); ?></b></td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($total_afp2,$n_decimales); ?></b></td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($total_sueldo_neto,$n_decimales); ?></b></td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($total_min_no_imp,$n_decimales); ?></b></td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($total_dif_suj_imp,$n_decimales); ?></b></td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($total_iva13,$n_decimales); ?></b></td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($total_form110,$n_decimales); ?></b></td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($total_iva110,$n_decimales); ?></b></td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($total_13_2smn,$n_decimales); ?></b></td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($total_sal_adm_trib,$n_decimales); ?></b></td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($total_sal_dep,$n_decimales); ?></b></td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($total_sal_iva_mes_ant,$n_decimales); ?></b></td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($total_actuliz,$n_decimales); ?></b></td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($total_iva_actualiz,$n_decimales); ?></b></td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($total_sal_fav_dep,$n_decimales); ?></b></td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($total_iva_util,$n_decimales); ?></b></td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($total_iva_pagar,$n_decimales); ?></b></td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($total_iva_sig_mes,$n_decimales); ?></b></td>
</tr>
<?php if ($pie_planilla == 1) { //if pie 1 ?>
<tr>
<td colspan="7" align="left"><br/><b>Elaborado por: <?php echo $usuario; ?></b><br/>&nbsp;</td>
<td colspan="7" align="left"><br/><b><?php echo $firma_contabilidad; ?></b><br/>&nbsp;</td>
<td colspan="7" align="left"><br/><b><?php echo $firma_gerencia; ?></b><br/>&nbsp;</td>
</tr>
<?php } //fin if pie 1 ?>
<?php if ($pie_planilla == 0) { //if pie 0 ?>
<tr>
<td colspan="7" align="center"><br/><b><?php echo strtr(strtoupper($nombre_responsable), "àáâãäåæçèéêëìíîïðñòóôõöøùüú", "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÜÚ"); ?><br/>Nombre del Empleador o Representante Legal</b></td>
<td colspan="5" align="center"><br/><b><?php echo $ci_responsable; ?><br/>No. de Documento de Identidad</b></td>
<td colspan="5" align="center"><br/><b><u>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</u><br/>Firma</b></td>
<td colspan="4" align="center"><br/><b><u>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</u><br/>Fecha</b></td>
<tr>
<?php } //fin if pie 0 ?>
</table>
<?php
}// fin if mostrar 0


//este if es para mostrar con el formato reporte
if($mostrar == 1 && $planilla == 2) { //mostrar 1

?>
<table border="0" align="left" width="100%" cellpadding="5">
<tr><td><?php echo $mostrar_logo_reportes; ?>
</td><td align="right"><b>Fecha: <?php echo date("Y-m-d"); ?><br/>Hora: <?php echo date("H:i:s"); ?><br/>Usuario: <?php echo $usuario; ?></b>
</td></tr></table>
<p><br /><center><font color="#000099" size="+1"><b>Reporte Planilla Tributaria</b></font></center></p>
<table border="0" cellpadding="2" align="center" width="100%">
<tr>
<td>	
    <table border="1" align="center" cellpadding="2" width="100%">
        <TR> 
        <TD width="33%"><b>Planilla: </b><?php echo $nom_planilla; ?></TD>
        <TD width="33%"><b>Sucursal: </b><?php echo $nom_sucursal; ?></TD>
        <TD width="33%"><b>Ciudad de la(s) Sucursal(es): </b><?php echo $nom_ciudad; ?></TD>
        </TR>
        <TR> 
        <TD><b>Empleado: </b><?php echo $nom_empleado; ?></TD>
        <TD><b>Genero: </b><?php echo $nom_genero; ?></TD>
        <TD><b>Cargo: </b><?php echo $nom_cargo; ?></TD>
        </TR>
        <TR>
        <TD><b>Mes A&ntilde;o Inicial: </b><?php echo $nom_mesini; ?> de <?php echo $anoini; ?></TD>
        <TD><b>Mes A&ntilde;o Final: </b><?php echo $nom_mesfin; ?> de <?php echo $anofin; ?></TD>
        <TD><b>Ordenado por: </b><?php echo $nom_orden; ?></TD>
        </TR>
        <TR>
        <TD><b>AFP: </b><?php echo $nom_afp; ?></TD>
        <TD><b>Contexto: </b><?php echo $nom_contexto; ?></TD>
        <TD><b>Expresado en: </b><?php echo $nom_moneda_principal; ?></TD>
        </TR>
    </table>

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

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

<table border="1" align="center" cellpadding="2" width="100%">
 	<thead>
    <TR> 
    <TD align="center"><b>No.</b></TD>
    <TD align="center"><b>Cod. Empleado</b></TD>
    <TD align="center"><b>Apellidos y Nombres</b></TD>
    <TD align="center"><b>Nacionalidad</b></TD>
    <TD align="center"><b>C.I.</b></TD>
    <TD align="center"><b>Cargo</b></TD>
    <TD align="center" width="50"><b>Fecha de Ingreso</b></TD>
    <TD align="center"><b>Total Ganado</b></TD>
    <TD align="center"><b>AFPs</b></TD>
    <TD align="center"><b>Sueldo Neto</b></TD>
    <TD align="center"><b>M&iacute;nimo no Imponible</b></TD>
    <TD align="center"><b>Dif. Sujeto a Impto.</b></TD>
    <TD align="center"><b>IVA 13%</b></TD>
    <TD align="center"><b>Form. 110</b></TD>
    <TD align="center"><b>Form. 110 (13%)</b></TD>
    <TD align="center"><b>13% Sobre Dos SMN</b></TD>
    <TD align="center"><b>Saldo a Favor Adm. Trib.</b></TD>
    <TD align="center"><b>Saldo a Favor Depend.</b></TD>
    <TD align="center"><b>Saldo RC-IVA Mes Ant.</b></TD>
    <TD align="center"><b>Actualiz.</b></TD>
    <TD align="center"><b>Saldo RC-IVA Actualiz.</b></TD>
    <TD align="center"><b>Total Saldo a Favor Depend.</b></TD>
    <TD align="center"><b>CF-IVA Utilizado</b></TD>
    <TD align="center"><b>RC-IVA a Pagar</b></TD>
    <TD align="center"><b>RC-IVA a Favor Sig. Mes</b></TD>
    </TR>
    </thead>
    <tbody class="marcafila">

<?php
$color = 2;
$j = 1;
$nu = 1;
$total_ganado2 = 0;
$total_afp2 = 0;
$total_sueldo_neto = 0;
$total_min_no_imp = 0;
$total_dif_suj_imp = 0;
$total_iva13 = 0;
$total_form110 = 0;
$total_iva110 = 0;
$total_13_2smn = 0;
$total_sal_adm_trib = 0;
$total_sal_dep = 0;
$total_sal_iva_mes_ant = 0;
$total_actuliz = 0;
$total_iva_actualiz = 0;
$total_sal_fav_dep = 0;
$total_iva_util = 0;
$total_iva_pagar = 0;
$total_iva_sig_mes = 0;



	while ($j <= $fin) { //while
	
	$cod_empleado = $matriz_pla [$j][2];
    if($color % 2 == 0) { //if color
	printf("<tr BGCOLOR='#e2e7fa'><td align='center'>%s</td>", $nu);//numero
	} else {
	printf("<tr><td align='center'>%s</td>", $nu);//numero
	}//fin if color
    
	printf("<td align='center'><a href='../../ModuleAgenda/VoucherPerson/index.php?pkyPerson=$cod_empleado&user=$usuario&token=$token' title='Persona'>%s</a></td>", $matriz_pla [$j][2]);//cod empleado
	$texto = $matriz_pla [$j][3];//empleado
	$texto = strtr(strtoupper($texto), "àáâãäåæçèéêëìíîïðñòóôõöøùüú", "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÜÚ");
	$texto = substr($texto,0,150);
	printf("<td align='left'>%s</td>", $texto);//empleado
	printf("<td align='left'>%s</td>", $matriz_pla [$j][44]);//nacionalidad
	printf("<td align='right'>%s</td>", $matriz_pla [$j][43]);//ci
	printf("<td align='left'>%s</td>", $matriz_pla [$j][6]);//cargo
	printf("<td align='center'>%s</td>", cambiarFormatoFechaBarra($matriz_pla [$j][10]));//fecha ing
	
	$trab_extraor_nocturno = $matriz_pla [$j][20]+$matriz_pla [$j][22]+$matriz_pla [$j][26]+$matriz_pla [$j][28];
	$suma_total_ganado = $matriz_pla [$j][70]+$matriz_pla [$j][30]+$bono_produccion+$subsidio_frontera+$trab_extraor_nocturno+$matriz_pla [$j][24]+$matriz_pla [$j][29];
	$porcentaje_afp = 0.8729;//12.71%(1-0.1271)
	$sueldo_neto = $suma_total_ganado * $porcentaje_afp - $matriz_pla [$j][35];
	printf("<td align='right'>%s</td>", number_format($suma_total_ganado,$n_decimales));//total ganado
	printf("<td align='right'>%s</td>", number_format($matriz_pla [$j][32],$n_decimales));//afps
	printf("<td align='right'>%s</td>", number_format($sueldo_neto,$n_decimales));//sueldo neto
	if($sueldo_neto > $matriz_pla [$j][73]) {
		$min_no_imp = $matriz_pla [$j][73];
	} else {
		$min_no_imp = $sueldo_neto;
	}
	printf("<td align='right'>%s</td>", number_format($min_no_imp,$n_decimales));//minimo no imponible
	$dif_sujeto_imp = $sueldo_neto - $min_no_imp;
	printf("<td align='right'>%s</td>", number_format($dif_sujeto_imp,$n_decimales));//dif sujeto a impuesto
	$iva13 = $dif_sujeto_imp * 13/100;
	printf("<td align='right'>%s</td>", number_format($iva13,$n_decimales));//iva 13%
	
	/* esto no es necesario se calcula en la planilla
	$periodo = $matriz_pla [$j][46];
	$mesp = date("m",strtotime($periodo)); 
	$anop = date("Y",strtotime($periodo)); 
	$fechainip = $anop.'-'.$mesp.'-01';
	$fechafinp = $anop.'-'.$mesp.'-31';
	//formulario de impuestos
	$resultimp = mysqli_query($link, "select b.fldAmount as monto, b.fldVAT as iva
from hrsTaxesForm a, hrsTaxesFormDetail b
where 
a.pkyTaxesForm = b.codTaxesForm and 
b.codEmployee = '$cod_empleado' and 
a.fldPeriod >= '$fechainip' and 
a.fldPeriod <= '$fechafinp' and 
a.sysEnabled = 1 and a.sysAuthorized = 1;");
	while ($row = mysqli_fetch_array($resultimp)) {
		$monto_iva_110 = $row['monto']; 
		$iva_110 = $row['iva']; 
	}
	mysqli_free_result($resultimp);
	*/
	$iva_110 = $matriz_pla [$j][12];
	$form_110 = round($iva_110*100/13,0);
	printf("<td align='right'>%s</td>", number_format($form_110,$n_decimales));//form 110
	printf("<td align='right'>%s</td>", number_format($iva_110,$n_decimales));//iva form 110
	if($acumula_2_smn_iva == 0) {//if iva 0
		if($iva13 > ($matriz_pla [$j][73]*13/100)) {
			$sobre2smn = $matriz_pla [$j][73]*13/100;
		} else {
			$sobre2smn = $iva13;
		}
	}//fin if iva 0
	if($acumula_2_smn_iva == 1) {//if iva 1
		if($sueldo_neto >= $matriz_pla [$j][73]) {
			$sobre2smn = $matriz_pla [$j][73]*13/100;
		} else {
			$sobre2smn = $iva13;
		}
	}//fin if iva 1
	printf("<td align='right'>%s</td>", number_format($sobre2smn,$n_decimales));//13% sobre 2 smn
	
	if($iva13 > ($iva_110+$sobre2smn)) {
		$sal_fav_adm = $iva13-$iva_110-$sobre2smn;
	} else {
		$sal_fav_adm = 0;
	}
	printf("<td align='right'>%s</td>", number_format($sal_fav_adm,$n_decimales));//saldo a favor adm trib
	
	if(($iva_110+$sobre2smn) > $iva13) {
		$sal_fav_dep = $iva_110+$sobre2smn-$iva13;
	} else {
		$sal_fav_dep = 0;
	}
	printf("<td align='right'>%s</td>", number_format($sal_fav_dep,$n_decimales));//saldo a favor dep
	$sal_iva_mes_ant = $matriz_pla [$j][62];
	printf("<td align='right'>%s</td>", number_format($sal_iva_mes_ant,$n_decimales));//saldo iva mes anterior
	/*
	//tc mes anterior
	$fechamesant = strtotime('-1 month', strtotime($fechafinp));
	$fechamesant = date ('Y-m-d', $fechamesant);
	$resulttcant = 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 <= '$fechamesant' AND fldExclusive = '0') AND 
T2.fldDate = T1.fldDate AND 
T2.fldTime = T1.fldTime AND 
sysEnabled = 1 AND sysAuthorized = 1;");
	while ($row = mysqli_fetch_array($resulttcant)) {
		$tc_ant = $row['tc'];
	}
	mysqli_free_result($resulttcant);
	
	//ufv mes anterior
	$cod_moneda_ufv = 4;
	$resultufvant = mysqli_query($link, "select fldRate as monto 
from actExchangeRateDetail 
where 
codExchangeRate = '$tc_ant' and 
codBaseCurrency = '$cod_moneda_principal' and 
codTargetCurrency = '$cod_moneda_ufv' and 
sysEnabled = 1 and sysAuthorized = 1;");
	while ($row = mysqli_fetch_array($resultufvant)) {
		$ufv_ant = $row['monto'];
	}
	mysqli_free_result($resultufvant);
	
	//tc mes periodo
	$resulttcper = 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 <= '$fechafinp' AND fldExclusive = '0') AND 
T2.fldDate = T1.fldDate AND 
T2.fldTime = T1.fldTime AND 
sysEnabled = 1 AND sysAuthorized = 1;");
	while ($row = mysqli_fetch_array($resulttcper)) {
		$tc_per = $row['tc'];
	}
	mysqli_free_result($resulttcper);
	
	//ufv mes periodo
	$resultufvper = mysqli_query($link, "select fldRate as monto 
from actExchangeRateDetail 
where 
codExchangeRate = '$tc_per' and 
codBaseCurrency = '$cod_moneda_principal' and 
codTargetCurrency = '$cod_moneda_ufv' and 
sysEnabled = 1 and sysAuthorized = 1;");
	while ($row = mysqli_fetch_array($resultufvper)) {
		$ufv_per = $row['monto'];
	}
	mysqli_free_result($resultufvper);
	
	$actualizacion_ufv = ($sal_iva_mes_ant*$ufv_per/$ufv_ant)-$sal_iva_mes_ant;
	*/
	$actualizacion_ufv = $matriz_pla [$j][63];
	printf("<td align='right'>%s</td>", number_format($actualizacion_ufv,$n_decimales));//actualizacion ufv
	$saldo_iva_actualizado = $sal_iva_mes_ant+$actualizacion_ufv;//$matriz_pla [$j][64]
	printf("<td align='right'>%s</td>", number_format($saldo_iva_actualizado,$n_decimales));//saldo iva actuaizado
	$total_saldo_iva_fav_dep = $sal_fav_dep+$saldo_iva_actualizado;
	printf("<td align='right'>%s</td>", number_format($total_saldo_iva_fav_dep,$n_decimales));//saldo favor iva dep
	
	if($sal_fav_adm > $total_saldo_iva_fav_dep) {
		$iva_utilizado = $saldo_iva_actualizado;
	} else {
		$iva_utilizado = $sal_fav_adm;
	}
	printf("<td align='right'>%s</td>", number_format($iva_utilizado,$n_decimales));//cf iva utilizado
	$iva_a_pagar = $sal_fav_adm-$iva_utilizado;
	printf("<td align='right'>%s</td>", number_format($iva_a_pagar,$n_decimales));//iva a pagar
	$iva_favor_sig_mes = $total_saldo_iva_fav_dep-$iva_utilizado;
	printf("<td align='right'>%s</td></tr>", number_format($iva_favor_sig_mes,$n_decimales));//iva a favor sig mes
	
	$total_ganado2 = $total_ganado2+$suma_total_ganado;
	$total_afp2 = $total_afp2+$matriz_pla [$j][32];	
	$total_sueldo_neto = $total_sueldo_neto+$sueldo_neto;
	$total_min_no_imp = $total_min_no_imp+$min_no_imp;
	$total_dif_suj_imp = $total_dif_suj_imp+$dif_sujeto_imp;
	$total_iva13 = $total_iva13+$iva13;
	$total_form110 = $total_form110+$form_110;
	$total_iva110 = $total_iva110+$iva_110;
	$total_13_2smn = $total_13_2smn+$sobre2smn;
	$total_sal_adm_trib = $total_sal_adm_trib+$sal_fav_adm;
	$total_sal_dep = $total_sal_dep+$sal_fav_dep;
	$total_sal_iva_mes_ant = $total_sal_iva_mes_ant+$sal_iva_mes_ant;
	$total_actuliz = $total_actuliz+$actualizacion_ufv;
	$total_iva_actualiz = $total_iva_actualiz+$saldo_iva_actualizado;
	$total_sal_fav_dep = $total_sal_fav_dep+$total_saldo_iva_fav_dep;
	$total_iva_util = $total_iva_util+$iva_utilizado;
	$total_iva_pagar = $total_iva_pagar+$iva_a_pagar;
	$total_iva_sig_mes = $total_iva_sig_mes+$iva_favor_sig_mes;
		
	
	$nu++;
	$color++;
	$j++;
  
	} //fin while
?>

<tr BGCOLOR="#ffcccc"><td colspan="7"><b>Total</b></td>
<td align="right"><b><?php echo number_format($total_ganado2,$n_decimales); ?></b></td>
<td align="right"><b><?php echo number_format($total_afp2,$n_decimales); ?></b></td>
<td align="right"><b><?php echo number_format($total_sueldo_neto,$n_decimales); ?></b></td>
<td align="right"><b><?php echo number_format($total_min_no_imp,$n_decimales); ?></b></td>
<td align="right"><b><?php echo number_format($total_dif_suj_imp,$n_decimales); ?></b></td>
<td align="right"><b><?php echo number_format($total_iva13,$n_decimales); ?></b></td>
<td align="right"><b><?php echo number_format($total_form110,$n_decimales); ?></b></td>
<td align="right"><b><?php echo number_format($total_iva110,$n_decimales); ?></b></td>
<td align="right"><b><?php echo number_format($total_13_2smn,$n_decimales); ?></b></td>
<td align="right"><b><?php echo number_format($total_sal_adm_trib,$n_decimales); ?></b></td>
<td align="right"><b><?php echo number_format($total_sal_dep,$n_decimales); ?></b></td>
<td align="right"><b><?php echo number_format($total_sal_iva_mes_ant,$n_decimales); ?></b></td>
<td align="right"><b><?php echo number_format($total_actuliz,$n_decimales); ?></b></td>
<td align="right"><b><?php echo number_format($total_iva_actualiz,$n_decimales); ?></b></td>
<td align="right"><b><?php echo number_format($total_sal_fav_dep,$n_decimales); ?></b></td>
<td align="right"><b><?php echo number_format($total_iva_util,$n_decimales); ?></b></td>
<td align="right"><b><?php echo number_format($total_iva_pagar,$n_decimales); ?></b></td>
<td align="right"><b><?php echo number_format($total_iva_sig_mes,$n_decimales); ?></b></td>
</tr>
<?php if ($pie_planilla == 1) { //if pie 1 ?>
<tr>
<td colspan="8" align="left"><br/><b>Elaborado por: <?php echo $usuario; ?></b><br/>&nbsp;</td>
<td colspan="9" align="left"><br/><b><?php echo $firma_contabilidad; ?></b><br/>&nbsp;</td>
<td colspan="8" align="left"><br/><b><?php echo $firma_gerencia; ?></b><br/>&nbsp;</td>
</tr>
<?php } //fin if pie 1 ?>
</tbody>
</table>

<?php	
}// fin if mostrar 1





//Planilla Tributaria V2


$total_sueldo_neto = 0;//J
$total_dos_smn = 0;//K
$total_base_imp = 0;//L
$total_imp_13 = 0;//M
$total_dos_smn_13 = 0;//N
$total_imp_neto_iva = 0;//O
$total_iva_110 = 0;//P
$total_saldo_fisco = 0;//Q
$total_saldo_depen = 0;//R
$total_sal_iva_mes_ant = 0;//S
$total_actualiz = 0;//T
$total_iva_actualiz = 0;//U
$total_iva_util = 0;//V
$total_iva_retenido = 0;//W
$total_iva_sig_mes = 0;//X

//este if es para mostrar con el formato presentacion
if($mostrar == 0 && $planilla == 8) { //mostrar 0

	$j = 1;
	$nu = 1;
	for($i = 1; $i <= $var; $i++) {//for
	?>
	<?php if($mostrar_logo_reportes_formato == 0) { //if formato 0 ?>
	<table border="1" align="center" cellpadding="2" width="990">
	<tr>
		<td width="490"><b>Nombre o Raz&oacute;n Social: </b><?php echo $nombre_empresa; ?></td>
		<td width="490"><b>NIT: </b><?php echo $mi_nit; ?></td>
	</tr>
	<!--
	<tr>
		<td width="490"><b>No. Empleador Min. de Trabajo: </b><?php echo $num_min_trabajo; ?></td>
		<td width="490"><b>No. Empleador Caja de Salud: </b><?php echo $num_caja_salud; ?></td>
	</tr>
	-->
	</table>
	<table border="0" align="center" cellpadding="2" width="990">
	<tr>
		<td width="300" align="center"><b><?php echo strtoupper($nom_moneda_actualizacion_iva); ?> Anterior: <?php echo number_format($tipo_cambio_anterior,5); ?></b></td>
		<td width="390" align="center"><b>PLANILLA TRIBUTARIA v2</b></td>
		<td width="300" align="right"><b>P&aacute;gina: <?php echo $i; ?> de <?php echo $var; ?></b></td>
	</tr>
	<tr>
		<td width="300" align="center"><b><?php echo strtoupper($nom_moneda_actualizacion_iva); ?> Actual: <?php echo number_format($tipo_cambio_actual,5); ?></b></td>
		<td width="390" align="center">Cifras en Bolivianos</td>
		<td width="300" align="right">CORRESPONDIENTE AL MES DE <?php echo strtoupper($nom_mesini); ?> DE <?php echo $anoini; ?></td>
	</tr>
	</table>
	<?php } //fin if formato 0 ?>
	
	<?php if($mostrar_logo_reportes_formato == 1) { //if formato 1 ?>
	<table border="1" align="center" cellpadding="2" width="990">
	<tr>
		<td width="15%"><img src="../../Images/logo.jpg" alt="Logo" width="100" height="40" /></td>
		<td width="490"><b>Nombre o Raz&oacute;n Social: </b><?php echo $nombre_empresa; ?></td>
		<td width="490"><b>NIT: </b><?php echo $mi_nit; ?></td>
	</tr>
	<!--
	<tr>
		<td width="490"><b>No. Empleador Min. de Trabajo: </b><?php echo $num_min_trabajo; ?></td>
		<td width="490"><b>No. Empleador Caja de Salud: </b><?php echo $num_caja_salud; ?></td>
	</tr>
	-->
	</table>
	<table border="0" align="center" cellpadding="2" width="990">
	<tr>
		<td width="300" align="center"><b><?php echo strtoupper($nom_moneda_actualizacion_iva); ?> Anterior: <?php echo number_format($tipo_cambio_anterior,5); ?></b></td>
		<td width="390" align="center"><b>PLANILLA TRIBUTARIA v2</b></td>
		<td width="300" align="right"><b>P&aacute;gina: <?php echo $i; ?> de <?php echo $var; ?></b></td>
	</tr>
	<tr>
		<td width="300" align="center"><b><?php echo strtoupper($nom_moneda_actualizacion_iva); ?> Actual: <?php echo number_format($tipo_cambio_actual,5); ?></b></td>
		<td width="390" align="center">Cifras en Bolivianos</td>
		<td width="300" align="right">CORRESPONDIENTE AL MES DE <?php echo strtoupper($nom_mesini); ?> DE <?php echo $anoini; ?></td>
	</tr>
	</table>
	<?php } //fin if formato 1 ?>
	
	<br />
	
	<table border="1" align="center" cellpadding="2" width="990" height="600">
		<TR> 
		<TD align="center" width="10" style='border-bottom: solid 1px'><b>No.</b></TD>
		<TD align="center" width="10" style='border-bottom: solid 1px'><b>A&ntilde;o<br/>A</b></TD>
		<TD align="center" width="10" style='border-bottom: solid 1px'><b>Peri-<br/>odo<br/>B</b></TD>
		<TD align="center" width="10" style='border-bottom: solid 1px'><b>Cod. Dep. RC-IVA<br/>C</b></TD>
		<TD align="center" width="130" style='border-bottom: solid 1px'><b>Nombres<br/>D</b></TD>
		<TD align="center" width="20" style='border-bottom: solid 1px'><b>Primer Ap.<br/>E</b></TD>
		<TD align="center" width="20" style='border-bottom: solid 1px'><b>Segundo Ap.<br/>F</b></TD>
		<TD align="center" width="20" style='border-bottom: solid 1px'><b>Nro. C.I.<br/>G</b></TD>
		<TD align="center" width="10" style='border-bottom: solid 1px'><b>Tipo Doc.<br/>H</b></TD>
		<TD align="center" width="50" style='border-bottom: solid 1px'><b>Novedad I=incorp. V=vigente D=desvin.<br/>I</b></TD>
		<TD align="center" width="40" style='border-bottom: solid 1px'><b>Ingreso Neto<br/>J</b></TD>
		<TD align="center" width="40" style='border-bottom: solid 1px'><b>Dos SMN no Impo-<br/>nibles<br/>K</b></TD>
		<TD align="center" width="40" style='border-bottom: solid 1px'><b>Base Impo-<br/>nible<br/>L=J-K (si J>K)</b></TD>
		<TD align="center" width="40" style='border-bottom: solid 1px'><b>Importe RC-IVA<br/>M=L*13%</b></TD>
		<TD align="center" width="40" style='border-bottom: solid 1px'><b>13% de Dos SMN<br/>N</b></TD>
		<TD align="center" width="40" style='border-bottom: solid 1px'><b>Impuesto neto RC-IVA<br/>O=M-N (si M>N)</b></TD>
		<TD align="center" width="40" style='border-bottom: solid 1px'><b>F-110 13% Fact. Presen.<br/>P</b></TD>
		<TD align="center" width="40" style='border-bottom: solid 1px'><b>Saldo a Favor Fisco<br/>Q=O-P (si O>P)</b></TD>
		<TD align="center" width="40" style='border-bottom: solid 1px'><b>Saldo a Favor Depend.<br/>R=P-O (si P>O)</b></TD>
		<TD align="center" width="40" style='border-bottom: solid 1px'><b>Saldo Favor Depend. Mes Ant.<br/>S</b></TD>
		<TD align="center" width="40" style='border-bottom: solid 1px'><b>Saldo Favor Depend. Mant. Valor<br/>T</b></TD>
		<TD align="center" width="40" style='border-bottom: solid 1px'><b>Saldo Favor Depend. Actualiz.<br/>U=S+T</b></TD>
		<TD align="center" width="40" style='border-bottom: solid 1px'><b>Saldo Utilizado<br/>V=U (si U&#8804;Q)<br/>V=Q (si Q&lt;U)</b></TD>
		<TD align="center" width="40" style='border-bottom: solid 1px'><b>Imp. RC-IVA Retenido<br/>W=Q-V (si Q>V)</b></TD>
		<TD align="center" width="40" style='border-bottom: solid 1px'><b>Saldo RC-IVA a Favor Depend. Sig. Mes<br/>X=R+U-V</b></TD>
		</TR>
	
	<?php
	$color = 2;
	$q = 1;//
	  while ($q <= $filas_por_pagina) { //while
		$cod_empleado = $matriz_pla [$j][2];
	  if($numero_filas == 0) {//if filas
		printf("<tr><td align='center' style='border-bottom: solid 1px'>%s</td>", $matriz_pla [$j][3]);//empleado
	  } else { //else filas
		if($color % 2 == 0) { //if color
			if($matriz_pla [$j][3] != NULL) {
			printf("<tr BGCOLOR='#e2e7fa'><td align='center' style='border-bottom: solid 1px'>%s</td>", $nu);//numero
			} else { 
			printf("<tr BGCOLOR='#e2e7fa'><td align='center' style='border-bottom: solid 1px'><hr /></td>");//numero vacio
			}
		} else {
			if($matriz_pla [$j][3] != NULL) {
			printf("<tr><td align='center' style='border-bottom: solid 1px'>%s</td>", $nu);//numero
			} else { 
			printf("<tr><td align='center' style='border-bottom: solid 1px'><hr /></td>");//numero vacio
			}
		}//fin if color
	  }//fin filas
		
		if($matriz_pla [$j][3] != NULL) {//if no hay
		
			printf("<td align='center' style='border-bottom: solid 1px'>%s</td>", substr($matriz_pla [$j][46], 0, 4));//año
			printf("<td align='center' style='border-bottom: solid 1px'>%s</td>", (int)substr($matriz_pla [$j][46], 5, 2));//periodo
			printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", $matriz_pla [$j][85]);//codigo dependiente
			
			$texto = $matriz_pla [$j][54].' '.$matriz_pla [$j][55];//nombres
			$texto = strtr(strtoupper($texto), "àáâãäåæçèéêëìíîïðñòóôõöøùüú", "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÜÚ");
			//$texto = substr($texto,0,150);
			printf("<td align='left' style='border-bottom: solid 1px'>%s</td>", $texto);//nombres

			$texto = $matriz_pla [$j][51];//ap pat, primer ap
			$texto = strtr(strtoupper($texto), "àáâãäåæçèéêëìíîïðñòóôõöøùüú", "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÜÚ");
			//$texto = substr($texto,0,150);
			printf("<td align='left' style='border-bottom: solid 1px'>%s</td>", $texto);//ap pat, primer ap
			
			$texto = $matriz_pla [$j][52];//ap mat, segundo ap
			$texto = strtr(strtoupper($texto), "àáâãäåæçèéêëìíîïðñòóôõöøùüú", "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÜÚ");
			//$texto = substr($texto,0,150);
			printf("<td align='left' style='border-bottom: solid 1px'>%s</td>", $texto);//ap mat, segundo ap
			
			printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", $matriz_pla [$j][43]);//ci
			printf("<td align='center' style='border-bottom: solid 1px'>%s</td>", $matriz_pla [$j][82]);//tipo documento CI, PAS, CEX
			printf("<td align='center' style='border-bottom: solid 1px'>%s</td>", $matriz_pla [$j][86]);//novedad I=incorporacion, V=vigente, D=desvinculado
			
			$trab_extraor_nocturno = $matriz_pla [$j][20]+$matriz_pla [$j][22]+$matriz_pla [$j][26]+$matriz_pla [$j][28];
			$suma_total_ganado = $matriz_pla [$j][70]+$matriz_pla [$j][30]+$bono_produccion+$subsidio_frontera+$trab_extraor_nocturno+$matriz_pla [$j][24]+$matriz_pla [$j][29];
			$porcentaje_afp = 0.8729;//12.71%(1-0.1271)
			
			$sueldo_neto = $suma_total_ganado * $porcentaje_afp - $matriz_pla [$j][35];
			printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($sueldo_neto,$n_decimales));//monto ingreso neto J
			
			$dos_smn = $matriz_pla [$j][73];
			printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($dos_smn,$n_decimales));//2 salario minimo nacional K
			
			if($sueldo_neto > $dos_smn) {
				$base_imp = $sueldo_neto - $dos_smn;
			} else {
				$base_imp = 0;
			}
			printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($base_imp,$n_decimales));//base imponible L=J-K (si J>K else 0)
			
			$imp_13 = round($base_imp * 13/100,0);
			printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($imp_13,$n_decimales));//importe RCIVA M=L*13%
			
			if($imp_13 == 0) {
				$dos_smn_13 = 0;
			} else {
				$dos_smn_13 = round($matriz_pla [$j][73] * 13/100,0);
			}
			printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($dos_smn_13,$n_decimales));//13% de 2 SMN N=K*13% (si M<>0 else 0)
			
			if($imp_13 > $dos_smn_13) {
				$imp_neto_iva = $imp_13 - $dos_smn_13;
			} else {
				$imp_neto_iva = 0;
			}
			printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($imp_neto_iva,$n_decimales));//importe neto RCIVA O=M-N (si M>N else 0)
			
			$iva_110 = $matriz_pla [$j][12];
			printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($iva_110,$n_decimales));//iva form 110 P
			
			if($imp_neto_iva > $iva_110) {
				$saldo_fisco = $imp_neto_iva - $iva_110;
			} else {
				$saldo_fisco = 0;
			}
			printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($saldo_fisco,$n_decimales));//saldo favor fisco Q=O-P (si O>P else 0)
			
			if($iva_110 > $imp_neto_iva) {
				$saldo_depen = $iva_110 - $imp_neto_iva;
			} else {
				$saldo_depen = 0;
			}
			printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($saldo_depen,$n_decimales));//saldo favor dependiente R=P-O (si P>O else 0)

			$sal_iva_mes_ant = $matriz_pla [$j][62];
			printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($sal_iva_mes_ant,$n_decimales));//saldo iva mes anterior S
		
			$actualizacion_ufv = $matriz_pla [$j][63];
			printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($actualizacion_ufv,$n_decimales));//actualizacion ufv T

			$saldo_iva_actualizado = $sal_iva_mes_ant+$actualizacion_ufv;
			printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($saldo_iva_actualizado,$n_decimales));//saldo iva actualizado U

			if($saldo_iva_actualizado <= $saldo_fisco) {
				$iva_utilizado = $saldo_iva_actualizado;
			} else {
				$iva_utilizado = $saldo_fisco;
			}
			printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($iva_utilizado,$n_decimales));//saldo iva utilizado V=U (si U<=Q else Q)

			if($saldo_fisco > $iva_utilizado) {
				$iva_retenido = $saldo_fisco - $iva_utilizado;
			} else {
				$iva_retenido = 0;
			}
			printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($iva_retenido,$n_decimales));//importe iva retenido W=Q-V (si Q>V else 0)

			$iva_favor_sig_mes = $saldo_depen + $saldo_iva_actualizado - $iva_utilizado;
			printf("<td align='right' style='border-bottom: solid 1px'>%s</td></tr>", number_format($iva_favor_sig_mes,$n_decimales));//iva a favor sig mes X=R+U-V

			$total_sueldo_neto = $total_sueldo_neto + $sueldo_neto;//J
			$total_dos_smn = $total_dos_smn + $dos_smn;//K
			$total_base_imp = $total_base_imp + $base_imp;//L
			$total_imp_13 = $total_imp_13 + $imp_13;//M
			$total_dos_smn_13 = $total_dos_smn_13 + $dos_smn_13;//N
			$total_imp_neto_iva = $total_imp_neto_iva + $imp_neto_iva;//O
			$total_iva_110 = $total_iva_110 + $iva_110;//P
			$total_saldo_fisco = $total_saldo_fisco + $saldo_fisco;//Q
			$total_saldo_depen = $total_saldo_depen + $saldo_depen;//R
			$total_sal_iva_mes_ant = $total_sal_iva_mes_ant + $sal_iva_mes_ant;//S
			$total_actualiz = $total_actualiz + $actualizacion_ufv;//T
			$total_iva_actualiz = $total_iva_actualiz + $saldo_iva_actualizado;//U
			$total_iva_util = $total_iva_util + $iva_utilizado;//V
			$total_iva_retenido = $total_iva_retenido + $iva_retenido;//W
			$total_iva_sig_mes = $total_iva_sig_mes + $iva_favor_sig_mes;//X
		
		
		} else { //else if no hay
			printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//año A
			printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//periodo B
			printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//codigo dependiente C
			printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//nombres D
			printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//primer ap E
			printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//segundo ap F
			printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//ci G
			printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//tipo doc H
			printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//novedad I
			printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//sueldo neto J
			printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//2 SMN K
			printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//base imponible L
			printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//importe iva M
			printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//13% 2 smn N
			printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//importe neto iva O
			printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//F110 13% P
			printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//saldo favor fisco Q
			printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//saldo favor dep R
			printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//saldo iva mes ant S
			printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//actualizacion iva T
			printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//saldo iva actualizado U
			printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//iva utilizado V
			printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//iva retenido W
			printf("<td align='center' style='border-bottom: solid 1px'><hr /></td></tr>");//iva a favor sig mes X
		
		}//fin if no hay
		
		if($numero_filas == 0 && $j == 7) {
			printf("<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td align='center' colspan='10'><font size='16'><b>SIN MOVIMIENTO</b></font></td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>");
		}
		
		$color++;
		$j++;
		$q++;
		$nu++;
	  }//fin while
	
	
	?>
	
	
	<?php
	/*
	$total_comp_par = 0;
	$total_no_cred_par = 0;
	$total_sub_par = 0;
	$total_desc_par = 0;
	$total_para_cred_par = 0;
	$total_cred_par = 0;
	*/
	if($i != $var) {//if $i
		?>
	</tr>
	</table>
	<div>
	
	<!--
	
	<table border="0" align="center" height="100"><tr><td>&nbsp;</td></tr></table>
	-->
	</div>
	<?php
	}//fin if $i
	}//fin for
	?>
	<tr>
		<td colspan="10" style='border-top: solid 1px; border-bottom: solid 1px' align="right"><b>TOTALES</b></td>
		<td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($total_sueldo_neto,$n_decimales); ?></b></td>
		<td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($total_dos_smn,$n_decimales); ?></b></td>
		<td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($total_base_imp,$n_decimales); ?></b></td>
		<td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($total_imp_13,$n_decimales); ?></b></td>
		<td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($total_dos_smn_13,$n_decimales); ?></b></td>
		<td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($total_imp_neto_iva,$n_decimales); ?></b></td>
		<td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($total_iva_110,$n_decimales); ?></b></td>
		<td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($total_saldo_fisco,$n_decimales); ?></b></td>
		<td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($total_saldo_depen,$n_decimales); ?></b></td>
		<td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($total_sal_iva_mes_ant,$n_decimales); ?></b></td>
		<td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($total_actualiz,$n_decimales); ?></b></td>
		<td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($total_iva_actualiz,$n_decimales); ?></b></td>
		<td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($total_iva_util,$n_decimales); ?></b></td>
		<td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($total_iva_retenido,$n_decimales); ?></b></td>
		<td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($total_iva_sig_mes,$n_decimales); ?></b></td>
	</tr>
	<?php if ($pie_planilla == 1) { //if pie 1 ?>
	<tr>
	<td colspan="8" align="left"><br/><b>Elaborado por: <?php echo $usuario; ?></b><br/>&nbsp;</td>
	<td colspan="9" align="left"><br/><b><?php echo $firma_contabilidad; ?></b><br/>&nbsp;</td>
	<td colspan="8" align="left"><br/><b><?php echo $firma_gerencia; ?></b><br/>&nbsp;</td>
	</tr>
	<?php } //fin if pie 1 ?>
	<?php if ($pie_planilla == 0) { //if pie 0 ?>
	<tr>
	<td colspan="9" align="center"><br/><b><?php echo strtr(strtoupper($nombre_responsable), "àáâãäåæçèéêëìíîïðñòóôõöøùüú", "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÜÚ"); ?><br/>Nombre del Empleador o Representante Legal</b></td>
	<td colspan="6" align="center"><br/><b><?php echo $ci_responsable; ?><br/>No. de Documento de Identidad</b></td>
	<td colspan="5" align="center"><br/><b><u>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</u><br/>Firma</b></td>
	<td colspan="5" align="center"><br/><b><u>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</u><br/>Fecha</b></td>
	<tr>
	<?php } //fin if pie 0 ?>
	</table>
	<?php
	}// fin if mostrar 0
	
	
	//este if es para mostrar con el formato reporte
	if($mostrar == 1 && $planilla == 8) { //mostrar 1
	
	?>
	<table border="0" align="left" width="100%" cellpadding="5">
	<tr><td><?php echo $mostrar_logo_reportes; ?>
	</td><td align="right"><b>Fecha: <?php echo date("Y-m-d"); ?><br/>Hora: <?php echo date("H:i:s"); ?><br/>Usuario: <?php echo $usuario; ?></b>
	</td></tr></table>
	<p><br /><center><font color="#000099" size="+1"><b>Reporte Planilla Tributaria v2</b></font></center></p>
	<table border="0" cellpadding="2" align="center" width="100%">
	<tr>
	<td>	
		<table border="1" align="center" cellpadding="2" width="100%">
			<TR> 
			<TD width="33%"><b>Planilla: </b><?php echo $nom_planilla; ?></TD>
			<TD width="33%"><b>Sucursal: </b><?php echo $nom_sucursal; ?></TD>
			<TD width="33%"><b>Ciudad de la(s) Sucursal(es): </b><?php echo $nom_ciudad; ?></TD>
			</TR>
			<TR> 
			<TD><b>Empleado: </b><?php echo $nom_empleado; ?></TD>
			<TD><b>Genero: </b><?php echo $nom_genero; ?></TD>
			<TD><b>Cargo: </b><?php echo $nom_cargo; ?></TD>
			</TR>
			<TR>
			<TD><b>Mes A&ntilde;o Inicial: </b><?php echo $nom_mesini; ?> de <?php echo $anoini; ?></TD>
			<TD><b>Mes A&ntilde;o Final: </b><?php echo $nom_mesfin; ?> de <?php echo $anofin; ?></TD>
			<TD><b>Ordenado por: </b><?php echo $nom_orden; ?></TD>
			</TR>
			<TR>
			<TD><b>AFP: </b><?php echo $nom_afp; ?></TD>
			<TD><b>Contexto: </b><?php echo $nom_contexto; ?></TD>
			<TD><b>Expresado en: </b><?php echo $nom_moneda_principal; ?></TD>
			</TR>
		</table>
	
	</td>
	<!--
	<td valign="top" width="150">
	
		<table border="1" align="center" cellpadding="2" width="100%">
		<tr>
		<TD><b>Tipo de Cambio:</b></TD>
		</tr><tr>
		<TD align="center"><a href="../../ModuleAccounting/VoucherExchangeRate/index.php?pkyExchangeRate=<?php echo $ultimo_tc; ?>&user=<?php echo $usuario; ?>&token=<?php echo $token; ?>" title="Tipo de Cambio"><?php echo $ultimo_tc; ?></a> (<?php echo $tc_fecha; ?> - <?php echo $tc_hora; ?>)<br/ >
			<table border="0" cellpadding="2" align="center">
				<?php
				for($m = 1; $m <= $fin_m; $m++) {
				printf("<tr><td align='left'>1 %s</td>", $ma_tc [$m][1]);//moneda base
				printf("<td align='center'>%s</td>", ' = ');//letra a
				printf("<td align='left'>%s %s</td>", number_format($ma_tc [$m][3],$n_tipocambio), $ma_tc [$m][2]);//moneda target y tasa
				//printf("<td align='right'>%s</td></tr>", number_format($ma_tc [$m][3],$n_tipocambio));//tasa
				}
				?>
			</table>
		</TD>
		</tr>
		</table>
		
	</td>
	-->
	</tr>
	</table>
	<br />
	
	<table border="1" align="center" cellpadding="2" width="100%">
		 <thead>
		<TR> 
		<TD align="center"><b>No.</b></TD>
		<TD align="center"><b>Cod.</b></TD>
		<TD align="center"><b>A&ntilde;o<br/>A</b></TD>
		<TD align="center"><b>Periodo<br/>B</b></TD>
		<TD align="center"><b>Cod. Dep. RC-IVA<br/>C</b></TD>
		<TD align="center"><b>Nombres<br/>D</b></TD>
		<TD align="center"><b>Primer Ap.<br/>E</b></TD>
		<TD align="center"><b>Segundo Ap.<br/>F</b></TD>
		<TD align="center"><b>Nro. C.I.<br/>G</b></TD>
		<TD align="center"><b>Tipo Doc.<br/>H</b></TD>
		<TD align="center"><b>Novedad I=incorp. V=vigente D=desvin.<br/>I</b></TD>
		<TD align="center"><b>Nacionalidad<br/>-</b></TD>
		<TD align="center"><b>Cargo<br/>-</b></TD>
		<TD align="center" width="50"><b>Fecha de Ingreso<br/>-</b></TD>
		<TD align="center"><b>Total Ganado<br/>-</b></TD>
		<TD align="center"><b>AFPs<br/>-</b></TD>
		<TD align="center"><b>Ingreso Neto<br/>J</b></TD>
		<TD align="center"><b>Dos SMN no Imponibles<br/>K</b></TD>
		<TD align="center"><b>Base Imponible<br/>L=J-K (si J>K)</b></TD>
		<TD align="center"><b>Importe RC-IVA<br/>M=L*13%</b></TD>
		<TD align="center"><b>13% de Dos SMN<br/>N</b></TD>
		<TD align="center"><b>Impuesto neto RC-IVA<br/>O=M-N (si M>N)</b></TD>
		<TD align="center"><b>F-110 Fact. Presentadas<br/>-</b></TD>
		<TD align="center"><b>F-110 13% Fact. Presentadas<br/>P</b></TD>
		<TD align="center"><b>Saldo a Favor Fisco<br/>Q=O-P (si O>P)</b></TD>
		<TD align="center"><b>Saldo a Favor Depend.<br/>R=P-O (si P>O)</b></TD>
		<TD align="center"><b>Saldo Favor Depend. Mes Ant.<br/>S</b></TD>
		<TD align="center"><b>Saldo Favor Depend. Mant. Valor<br/>T</b></TD>
		<TD align="center"><b>Saldo Favor Depend. Actualiz.<br/>U=S+T</b></TD>
		<TD align="center"><b>Saldo Utilizado<br/>V=U (si U&#8804;Q)<br/>V=Q (si Q&lt;U)</b></TD>
		<TD align="center"><b>Imp. RC-IVA Retenido<br/>W=Q-V (si Q>V)</b></TD>
		<TD align="center"><b>Saldo RC-IVA a Favor Depend. Sig. Mes<br/>X=R+U-V</b></TD>
		</TR>
		</thead>
		<tbody class="marcafila">
	
		<?php
		$color = 2;
		$j = 1;
		$nu = 1;
		
		$total_ganado2 = 0;	
		$total_afp2 = 0;	
		$total_sueldo_neto = 0;//J
		$total_dos_smn = 0;//K
		$total_base_imp = 0;//L
		$total_imp_13 = 0;//M
		$total_dos_smn_13 = 0;//N
		$total_imp_neto_iva = 0;//O
		$total_form110 = 0;
		$total_iva_110 = 0;//P
		$total_saldo_fisco = 0;//Q
		$total_saldo_depen = 0;//R
		$total_sal_iva_mes_ant = 0;//S
		$total_actualiz = 0;//T
		$total_iva_actualiz = 0;//U
		$total_iva_util = 0;//V
		$total_iva_retenido = 0;//W
		$total_iva_sig_mes = 0;//X
	
	
	
		while ($j <= $fin) { //while
		
		$cod_empleado = $matriz_pla [$j][2];
		if($color % 2 == 0) { //if color
		printf("<tr BGCOLOR='#e2e7fa'><td align='center'>%s</td>", $nu);//numero
		} else {
		printf("<tr><td align='center'>%s</td>", $nu);//numero
		}//fin if color
		
		printf("<td align='center'><a href='../../ModuleAgenda/VoucherPerson/index.php?pkyPerson=$cod_empleado&user=$usuario&token=$token' title='Persona'>%s</a></td>", $matriz_pla [$j][2]);//cod empleado
		printf("<td align='center'>%s</td>", substr($matriz_pla [$j][46], 0, 4));//año
		printf("<td align='center'>%s</td>", (int)substr($matriz_pla [$j][46], 5, 2));//periodo
		printf("<td align='right'>%s</td>", $matriz_pla [$j][85]);//codigo dependiente
		$texto = $matriz_pla [$j][54].' '.$matriz_pla [$j][55];//nombres
		$texto = strtr(strtoupper($texto), "àáâãäåæçèéêëìíîïðñòóôõöøùüú", "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÜÚ");
		printf("<td align='left'>%s</td>", $texto);//nombres
		$texto = $matriz_pla [$j][51];//ap pat, primer ap
		$texto = strtr(strtoupper($texto), "àáâãäåæçèéêëìíîïðñòóôõöøùüú", "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÜÚ");
		printf("<td align='left'>%s</td>", $texto);//ap pat, primer ap
		$texto = $matriz_pla [$j][52];//ap mat, segundo ap
		$texto = strtr(strtoupper($texto), "àáâãäåæçèéêëìíîïðñòóôõöøùüú", "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÜÚ");
		printf("<td align='left'>%s</td>", $texto);//ap mat, segundo ap
		printf("<td align='right'>%s</td>", $matriz_pla [$j][43]);//ci
		printf("<td align='center'>%s</td>", $matriz_pla [$j][82]);//tipo documento CI, PAS, CEX
		printf("<td align='center'>%s</td>", $matriz_pla [$j][86]);//novedad I=incorporacion, V=vigente, D=desvinculado
		printf("<td align='left'>%s</td>", $matriz_pla [$j][44]);//nacionalidad
		printf("<td align='left'>%s</td>", $matriz_pla [$j][6]);//cargo
		printf("<td align='center'>%s</td>", cambiarFormatoFechaBarra($matriz_pla [$j][10]));//fecha ing
		
		$trab_extraor_nocturno = $matriz_pla [$j][20]+$matriz_pla [$j][22]+$matriz_pla [$j][26]+$matriz_pla [$j][28];
		$suma_total_ganado = $matriz_pla [$j][70]+$matriz_pla [$j][30]+$bono_produccion+$subsidio_frontera+$trab_extraor_nocturno+$matriz_pla [$j][24]+$matriz_pla [$j][29];
		$porcentaje_afp = 0.8729;//12.71%(1-0.1271)
		$sueldo_neto = $suma_total_ganado * $porcentaje_afp - $matriz_pla [$j][35];
		printf("<td align='right'>%s</td>", number_format($suma_total_ganado,$n_decimales));//total ganado
		printf("<td align='right'>%s</td>", number_format($matriz_pla [$j][32],$n_decimales));//afps
		printf("<td align='right'>%s</td>", number_format($sueldo_neto,$n_decimales));//sueldo neto J
		$dos_smn = $matriz_pla [$j][73];
		printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($dos_smn,$n_decimales));//2 salario minimo nacional K
		
		if($sueldo_neto > $dos_smn) {
			$base_imp = $sueldo_neto - $dos_smn;
		} else {
			$base_imp = 0;
		}
		printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($base_imp,$n_decimales));//base imponible L=J-K (si J>K else 0)
		
		$imp_13 = round($base_imp * 13/100);
		printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($imp_13,$n_decimales));//importe RCIVA M=L*13%
		
		if($imp_13 == 0) {
			$dos_smn_13 = 0;
		} else {
			$dos_smn_13 = round($matriz_pla [$j][73] * 13/100,0);
		}
		printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($dos_smn_13,$n_decimales));//13% de 2 SMN N=K*13% (si M<>0 else 0)
		
		if($imp_13 > $dos_smn_13) {
			$imp_neto_iva = $imp_13 - $dos_smn_13;
		} else {
			$imp_neto_iva = 0;
		}
		printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($imp_neto_iva,$n_decimales));//importe neto RCIVA O=M-N (si M>N else 0)
		
		$iva_110 = $matriz_pla [$j][12];
		$form_110 = round($iva_110*100/13,0);
		printf("<td align='right'>%s</td>", number_format($form_110,$n_decimales));//form 110
		
		printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($iva_110,$n_decimales));//iva form 110 P
		
		if($imp_neto_iva > $iva_110) {
			$saldo_fisco = $imp_neto_iva - $iva_110;
		} else {
			$saldo_fisco = 0;
		}
		printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($saldo_fisco,$n_decimales));//saldo favor fisco Q=O-P (si O>P else 0)
		
		if($iva_110 > $imp_neto_iva) {
			$saldo_depen = $iva_110 - $imp_neto_iva;
		} else {
			$saldo_depen = 0;
		}
		printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($saldo_depen,$n_decimales));//saldo favor dependiente R=P-O (si P>O else 0)

		$sal_iva_mes_ant = $matriz_pla [$j][62];
		printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($sal_iva_mes_ant,$n_decimales));//saldo iva mes anterior S
	
		$actualizacion_ufv = $matriz_pla [$j][63];
		printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($actualizacion_ufv,$n_decimales));//actualizacion ufv T

		$saldo_iva_actualizado = $sal_iva_mes_ant+$actualizacion_ufv;
		printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($saldo_iva_actualizado,$n_decimales));//saldo iva actualizado U

		if($saldo_iva_actualizado <= $saldo_fisco) {
			$iva_utilizado = $saldo_iva_actualizado;
		} else {
			$iva_utilizado = $saldo_fisco;
		}
		printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($iva_utilizado,$n_decimales));//saldo iva utilizado V=U (si U<=Q else Q)

		if($saldo_fisco > $iva_utilizado) {
			$iva_retenido = $saldo_fisco - $iva_utilizado;
		} else {
			$iva_retenido = 0;
		}
		printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($iva_retenido,$n_decimales));//importe iva retenido W=Q-V (si Q>V else 0)

		$iva_favor_sig_mes = $saldo_depen + $saldo_iva_actualizado - $iva_utilizado;
		printf("<td align='right' style='border-bottom: solid 1px'>%s</td></tr>", number_format($iva_favor_sig_mes,$n_decimales));//iva a favor sig mes X=R+U-V

		$total_ganado2 = $total_ganado2 + $suma_total_ganado;	
		$total_afp2 = $total_afp2 + $matriz_pla [$j][32];	
		$total_sueldo_neto = $total_sueldo_neto + $sueldo_neto;//J
		$total_dos_smn = $total_dos_smn + $dos_smn;//K
		$total_base_imp = $total_base_imp + $base_imp;//L
		$total_imp_13 = $total_imp_13 + $imp_13;//M
		$total_dos_smn_13 = $total_dos_smn_13 + $dos_smn_13;//N
		$total_imp_neto_iva = $total_imp_neto_iva + $imp_neto_iva;//O
		$total_form110 = $total_form110 + $form_110;
		$total_iva_110 = $total_iva_110 + $iva_110;//P
		$total_saldo_fisco = $total_saldo_fisco + $saldo_fisco;//Q
		$total_saldo_depen = $total_saldo_depen + $saldo_depen;//R
		$total_sal_iva_mes_ant = $total_sal_iva_mes_ant + $sal_iva_mes_ant;//S
		$total_actualiz = $total_actualiz + $actualizacion_ufv;//T
		$total_iva_actualiz = $total_iva_actualiz + $saldo_iva_actualizado;//U
		$total_iva_util = $total_iva_util + $iva_utilizado;//V
		$total_iva_retenido = $total_iva_retenido + $iva_retenido;//W
		$total_iva_sig_mes = $total_iva_sig_mes + $iva_favor_sig_mes;//X
		
		
		$nu++;
		$color++;
		$j++;
	  
		} //fin while
		?>
		
		<tr BGCOLOR="#ffcccc"><td colspan="14"><b>Total</b></td>
		<td align="right"><b><?php echo number_format($total_ganado2,$n_decimales); ?></b></td>
		<td align="right"><b><?php echo number_format($total_afp2,$n_decimales); ?></b></td>
		<td align="right"><b><?php echo number_format($total_sueldo_neto,$n_decimales); ?></b></td>
		<td align="right"><b><?php echo number_format($total_dos_smn,$n_decimales); ?></b></td>
		<td align="right"><b><?php echo number_format($total_base_imp,$n_decimales); ?></b></td>
		<td align="right"><b><?php echo number_format($total_imp_13,$n_decimales); ?></b></td>
		<td align="right"><b><?php echo number_format($total_dos_smn_13,$n_decimales); ?></b></td>
		<td align="right"><b><?php echo number_format($total_imp_neto_iva,$n_decimales); ?></b></td>
		<td align="right"><b><?php echo number_format($total_form110,$n_decimales); ?></b></td>
		<td align="right"><b><?php echo number_format($total_iva_110,$n_decimales); ?></b></td>
		<td align="right"><b><?php echo number_format($total_saldo_fisco,$n_decimales); ?></b></td>
		<td align="right"><b><?php echo number_format($total_saldo_depen,$n_decimales); ?></b></td>
		<td align="right"><b><?php echo number_format($total_sal_iva_mes_ant,$n_decimales); ?></b></td>
		<td align="right"><b><?php echo number_format($total_actualiz,$n_decimales); ?></b></td>
		<td align="right"><b><?php echo number_format($total_iva_actualiz,$n_decimales); ?></b></td>
		<td align="right"><b><?php echo number_format($total_iva_util,$n_decimales); ?></b></td>
		<td align="right"><b><?php echo number_format($total_iva_retenido,$n_decimales); ?></b></td>
		<td align="right"><b><?php echo number_format($total_iva_sig_mes,$n_decimales); ?></b></td>
		</tr>
		<?php if ($pie_planilla == 1) { //if pie 1 ?>
		<tr>
		<td colspan="8" align="left"><br/><b>Elaborado por: <?php echo $usuario; ?></b><br/>&nbsp;</td>
		<td colspan="9" align="left"><br/><b><?php echo $firma_contabilidad; ?></b><br/>&nbsp;</td>
		<td colspan="8" align="left"><br/><b><?php echo $firma_gerencia; ?></b><br/>&nbsp;</td>
		</tr>
		<?php } //fin if pie 1 ?>
		</tbody>
		</table>
		
		<?php	
	}// fin if mostrar 1



//Planilla Boletas de pago solo formato boleta

//este if es para mostrar con el formato boleta
if($mostrar == 2 && $planilla == 3) { //mostrar 0

for($j = 1; $j <= $numero_filas; $j++) {//for
//calculo iva sig mes
$suma_total_ganado = $matriz_pla [$j][70]+$matriz_pla [$j][30]+$bono_produccion+$subsidio_frontera+$trab_extraor_nocturno+$matriz_pla [$j][24]+$matriz_pla [$j][29];
$porcentaje_afp = 0.8729;//12.71%(1-0.1271)
$sueldo_neto = $suma_total_ganado * $porcentaje_afp;
if($sueldo_neto > $matriz_pla [$j][73]) {
		$min_no_imp = $matriz_pla [$j][73];
	} else {
		$min_no_imp = $sueldo_neto;
	}
$dif_sujeto_imp = $sueldo_neto - $min_no_imp;
$iva13 = round($dif_sujeto_imp * 13/100);
$iva_110 = round($matriz_pla [$j][12]);

	if($acumula_2_smn_iva == 0) {//if iva 0
		if($iva13 > ($matriz_pla [$j][73]*13/100)) {
			$sobre2smn = $matriz_pla [$j][73]*13/100;
		} else {
			$sobre2smn = $iva13;
		}
	}//fin if iva 0
	if($acumula_2_smn_iva == 1) {//if iva 1
		if($sueldo_neto >= $matriz_pla [$j][73]) {
			$sobre2smn = $matriz_pla [$j][73]*13/100;
		} else {
			$sobre2smn = $iva13;
		}
	}//fin if iva 1
/*
	if($iva13 > ($matriz_pla [$j][73]*13/100)) {
		$sobre2smn = $matriz_pla [$j][73]*13/100;
	} else {
		$sobre2smn = $iva13;
	}
	
	if($sueldo_neto >= $matriz_pla [$j][73]) {
		$sobre2smn = round($matriz_pla [$j][73]*13/100);
	} else {
		$sobre2smn = $iva13;
	}
*/
if($iva13 > ($iva_110+$sobre2smn)) {
		$sal_fav_adm = $iva13-$iva_110-$sobre2smn;
	} else {
		$sal_fav_adm = 0;
	}
if(($iva_110+$sobre2smn) > $iva13) {
		$sal_fav_dep = $iva_110+$sobre2smn-$iva13;
	} else {
		$sal_fav_dep = 0;
	}
$sal_iva_mes_ant = $matriz_pla [$j][62];
$actualizacion_ufv = $matriz_pla [$j][63];
$saldo_iva_actualizado = $sal_iva_mes_ant+$actualizacion_ufv;
$total_saldo_iva_fav_dep = $sal_fav_dep+$saldo_iva_actualizado;
if($sal_fav_adm > $total_saldo_iva_fav_dep) {
		$iva_utilizado = $saldo_iva_actualizado;
	} else {
		$iva_utilizado = $sal_fav_adm;
	}
$iva_a_pagar = $sal_fav_adm-$iva_utilizado;
$iva_favor_sig_mes = $total_saldo_iva_fav_dep-$iva_utilizado;

//jubilado
if ($matriz_pla [$j][56] == 0) { 
	$jubilado = 'No';
} else { 
	$jubilado = 'Si';
}

$cod_empleado = $matriz_pla [$j][2];

?>
<table border="0" align="center" cellpadding="2" width="100%">
<tr>
<td align="left"><img src="../../Images/logo.jpg" alt="Logo" /> <!--espacio para el logo width="100" height="50"-->
</td>
</tr>
</table>
<table border="1" align="center" cellpadding="2" width="100%">
<tr>
	<td width="50%"><b>Nombre o Raz&oacute;n Social: </b><?php echo strtr(strtoupper($nombre_empresa), "àáâãäåæçèéêëìíîïðñòóôõöøùüú", "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÜÚ"); ?></td>
    <?php if($boleta_nit == 0) { ?>
    <td width="50%"><b>NIT: </b><?php echo $mi_nit; ?></td>
    <?php } ?>
</tr>
<!--
<tr>
	<td width="50%"><b>No. Empleador Min. de Trabajo: </b><?php echo $num_min_trabajo; ?></td>
    <td width="50%"><b>No. Empleador Caja de Salud: </b><?php echo $num_caja_salud; ?></td>
</tr>
-->
</table>
<table border="0" align="center" cellpadding="2" width="100%">
<!--
<tr>
	<td width="300"><?php //echo $usuario; ?></td>
    <td width="390" align="center"><b>PLANILLA TRIBUTARIA</b></td>
    <td width="300" align="right"><b>P&aacute;gina: <?php echo $i; ?> de <?php echo $var; ?></b></td>
</tr>
-->
<tr>
    <td align="center" colspan="2"><b>BOLETA DE PAGO DE SUELDO CORRESPONDIENTE AL MES DE <?php echo strtoupper($nom_mesini); ?> DE <?php echo $anoini; ?><br/>(EXPRESADA EN BOLIVIANOS)</b></td>
</tr>
</table>

<br />

<table border="1" align="center" cellpadding="2" width="100%">
    <TR> 
    <TD width="50%" style='border-bottom: solid 1px'><b>Apellidos y Nombres: </b><?php echo strtr(strtoupper($matriz_pla [$j][3]), "àáâãäåæçèéêëìíîïðñòóôõöøùüú", "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÜÚ"); ?></TD>
    <TD width="25%" style='border-bottom: solid 1px'><b>C.I.: </b><?php echo $matriz_pla [$j][43]; ?> <?php echo $matriz_pla [$j][48]; ?></TD>
    <TD width="25%" style='border-bottom: solid 1px'><b>Fecha de Ingreso: </b><?php echo cambiarFormatoFechaBarra($matriz_pla [$j][10]); ?></TD>
    </TR>
    <TR> 
    <TD style='border-bottom: solid 1px'><b>Cargo: </b><?php echo strtr(strtoupper($matriz_pla [$j][6]), "àáâãäåæçèéêëìíîïðñòóôõöøùüú", "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÜÚ"); ?></TD>
    <TD style='border-bottom: solid 1px'><b>Sucursal: </b><?php echo strtr(strtoupper($matriz_pla [$j][5]), "àáâãäåæçèéêëìíîïðñòóôõöøùüú", "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÜÚ"); ?></TD>
    <TD style='border-bottom: solid 1px'><b>Saldo IVA: </b><?php echo number_format($iva_favor_sig_mes,$n_decimales); ?></TD>
    </TR>
    <TR> 
    <TD style='border-bottom: solid 1px'><b>Haber B&aacute;sico: </b><?php echo number_format($matriz_pla [$j][70],$n_decimales); ?></TD>
    <TD style='border-bottom: solid 1px'><b>D&iacute;as Trabajados: </b><?php echo number_format($matriz_pla [$j][13],0); ?></TD>
    <TD style='border-bottom: solid 1px'><b>Horas Extras: </b><?php echo number_format($matriz_pla [$j][19]*$multiplicador_horas_extras,0); ?></TD>
    </TR>
    <TR> 
    <TD style='border-bottom: solid 1px'><b>Horas Recargo: </b><?php echo number_format($matriz_pla [$j][21],0); ?></TD>
    <TD style='border-bottom: solid 1px'><b>Horas Domingo: </b><?php echo number_format($matriz_pla [$j][23],0); ?></TD>
    <TD style='border-bottom: solid 1px'><b>Horas Extraordinarias: </b><?php echo number_format($matriz_pla [$j][25],0); ?></TD>
    </TR>
    <TR> 
    <TD colspan="2" style='border-bottom: solid 1px'><b>Horas Feriado: </b><?php echo number_format($matriz_pla [$j][27],0); ?></TD>
    <TD style='border-bottom: solid 1px'><b>Jubilado: </b><?php echo $jubilado; ?></TD>
    </TR>
</table>

<br />
<table border="0" align="center" width="100%">
<tr valign="top"><td>
<!--ingresos-->
<table border="1" align="center" width="100%" height="<?php echo $tam_hoja; ?>"><!--tabla 11-->
<tr valign="top"><td>
<?php $suma_ingresos = 0; ?>
    <table border="0" align="center" cellpadding="2" width="100%">
        <TR> 
        <TD width="50%" style='border-bottom: solid 1px' colspan="2" align="center"><b>INGRESOS</b></TD>
        </TR>
        <TR>
        <TD width="70%"><b>HABER B&Aacute;SICO</b></TD>
        <TD width="30%" align="right"><?php echo number_format($matriz_pla [$j][70],$n_decimales); ?></TD>
        </TR>
        <?php $suma_ingresos = $suma_ingresos + $matriz_pla [$j][70]; ?>
        <?php if ($matriz_pla [$j][30] > 0 || $boleta_mostrar_todo == 1) { ?>
        <TR>
        <TD><b>BONO DE ANTIG&Uuml;EDAD</b></TD>
        <TD align="right"><?php echo number_format($matriz_pla [$j][30],$n_decimales); ?></TD>
        </TR>
        <?php $suma_ingresos = $suma_ingresos + $matriz_pla [$j][30]; ?>
        <?php } ?>
        <?php if ($bono_produccion > 0) { ?>
        <TR>
        <TD><b>BONO DE PRODUCCI&Oacute;N</b></TD>
        <TD align="right"><?php echo number_format($bono_produccion,$n_decimales); ?></TD>
        </TR>
        <?php $suma_ingresos = $suma_ingresos + $bono_produccion; ?>
        <?php } ?>
        <?php if ($subsidio_frontera > 0) { ?>
        <TR>
        <TD><b>SUBSIDIO FRONTERA</b></TD>
        <TD align="right"><?php echo number_format($subsidio_frontera,$n_decimales); ?></TD>
        </TR>
        <?php $suma_ingresos = $suma_ingresos + $subsidio_frontera; ?>
        <?php } ?>
        
        <?php if ($matriz_pla [$j][20] > 0 || $boleta_mostrar_todo == 1) { ?>
        <TR>
        <TD><b>HORAS EXTRAS</b></TD>
        <TD align="right"><?php echo number_format($matriz_pla [$j][20],$n_decimales); ?></TD>
        </TR>
        <?php $suma_ingresos = $suma_ingresos + $matriz_pla [$j][20]; ?>
        <?php } ?>
        
        <?php if ($matriz_pla [$j][22] > 0 || $boleta_mostrar_todo == 1) { ?>
        <TR>
        <TD><b>HORAS RECARGO</b></TD>
        <TD align="right"><?php echo number_format($matriz_pla [$j][22],$n_decimales); ?></TD>
        </TR>
        <?php $suma_ingresos = $suma_ingresos + $matriz_pla [$j][22]; ?>
        <?php } ?>
        
        <?php if ($matriz_pla [$j][24] > 0 || $boleta_mostrar_todo == 1) { ?>
        <TR>
        <TD><b>HORAS DOMINGO</b></TD>
        <TD align="right"><?php echo number_format($matriz_pla [$j][24],$n_decimales); ?></TD>
        </TR>
        <?php $suma_ingresos = $suma_ingresos + $matriz_pla [$j][24]; ?>
        <?php } ?>
        
        <?php if ($matriz_pla [$j][26] > 0) { ?>
        <TR>
        <TD><b>HORAS EXTRAORDINARIAS</b></TD>
        <TD align="right"><?php echo number_format($matriz_pla [$j][26],$n_decimales); ?></TD>
        </TR>
        <?php $suma_ingresos = $suma_ingresos + $matriz_pla [$j][26]; ?>
        <?php } ?>
        
        <?php if ($matriz_pla [$j][28] > 0) { ?>
        <TR>
        <TD><b>HORAS FERIADO</b></TD>
        <TD align="right"><?php echo number_format($matriz_pla [$j][28],$n_decimales); ?></TD>
        </TR>
        <?php $suma_ingresos = $suma_ingresos + $matriz_pla [$j][28]; ?>
        <?php } ?>
        <?php
        //detalle bono
    $resultbono = mysqli_query($link, "select a.pkyBonusDiscount as cod_bondes, a.fldDocumentNumber as nro_doc, a.fldDate as fecha, a.fldPeriod as periodo, b.codEmployee as cod_empleado, b.codConcept as cod_conceptobd, c.fldName as bono_descuento, b.fldAmount as monto
    from hrsBonusDiscount a, hrsBonusDiscountDetail b, hrsBonusDiscountConcept c
    where 
    a.pkyBonusDiscount = b.codBonusDiscount and 
    b.codConcept = c.pkyBonusDiscountConcept and 
    c.fldIsDiscount = 0 and 
    b.codEmployee = '$cod_empleado' and 
    a.fldDate >= '$vfechaini' and 
    a.fldDate <= '$vfechafin' and 
    a.sysEnabled = 1 and a.sysAuthorized = 1
    order by c.fldName, a.fldDate, b.fldAmount;");
    
        while ($row = mysqli_fetch_array($resultbono)) { //while
          if($row['monto'] > 0 || $boleta_mostrar_todo == 1) {
            printf("<tr><td><b>%s</b></td>", strtr(strtoupper($row['bono_descuento']), "àáâãäåæçèéêëìíîïðñòóôõöøùüú", "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÜÚ"));//nombre
            printf("<td align='right'>%s</td></tr>", number_format($row['monto'],$n_decimales));//monto
            $suma_ingresos = $suma_ingresos + $row['monto'];
          }
        }//fin while
    ?>
    </table>
</td></tr></table><!--fin tabla 11-->

<table border="0" align="center" cellpadding="2" width="100%">
<TR>
    <TD style='border-bottom: solid 1px; border-left: solid 1px'><b>TOTAL GANADO</b></TD>
    <TD style='border-bottom: solid 1px; border-right: solid 1px' align="right"><?php echo number_format($suma_ingresos,$n_decimales); ?></TD>
</TR>
<TR>
	<TD colspan="2">&nbsp;</TD>
</TR>
<TR>
	<TD colspan="2">&nbsp;</TD>
</TR>
<TR>
	<TD colspan="2">&nbsp;</TD>
</TR>
<TR>
	<TD colspan="2">&nbsp;</TD>
</TR>
<TR>
	<TD colspan="2" align="center"><?php echo strtr(strtoupper($nombre_empresa), "àáâãäåæçèéêëìíîïðñòóôõöøùüú", "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÜÚ"); ?></TD>
</TR>   
</table>
<!--fin ingresos-->

</td>
<td>

<!--descuentos-->
<table border="1" align="center" width="100%" height="<?php echo $tam_hoja; ?>"><!--tabla 12-->
<tr valign="top"><td>
<?php $suma_descuentos = 0; ?>
    <table border="0" align="center" cellpadding="2" width="100%">
        <TR> 
        <TD width="50%" style='border-bottom: solid 1px' colspan="2" align="center"><b>DESCUENTOS</b></TD>
        </TR>
        <?php if ($boleta_afp_desglosado == 1) { //1 muestra desglosado ?>
        <TR>
        <TD width="70%"><b>COTIZACI&Oacute;N MENSUAL (10%)</b></TD>
        <TD width="30%" align="right"><?php echo number_format($matriz_pla [$j][32]*10/12.71,$n_decimales); ?></TD>
        </TR>
        <TR>
        <TD width="70%"><b>COMISI&Oacute;N AFP (0.5%)</b></TD>
        <TD width="30%" align="right"><?php echo number_format($matriz_pla [$j][32]*0.5/12.71,$n_decimales); ?></TD>
        </TR>
        <TR>
        <TD width="70%"><b>RIESGO COM&Uacute;N (1.71%)</b></TD>
        <TD width="30%" align="right"><?php echo number_format($matriz_pla [$j][32]*1.71/12.71,$n_decimales); ?></TD>
        </TR>
        <TR>
        <TD width="70%"><b>APORTE SOLIDARIO (0.5%)</b></TD>
        <TD width="30%" align="right"><?php echo number_format($matriz_pla [$j][32]*0.5/12.71,$n_decimales); ?></TD>
        </TR>
        <?php } ?>
        <?php if ($boleta_afp_desglosado == 0) { //0 no muestra desglosado ?>
        <TR>
        <TD><b>AFPs</b></TD>
        <TD align="right"><?php echo number_format($matriz_pla [$j][32],$n_decimales); ?></TD>
        </TR>
        <?php } ?>
        <?php $suma_descuentos = $suma_descuentos + $matriz_pla [$j][32]; ?>
        
        <?php if ($matriz_pla [$j][35] > 0 || $boleta_mostrar_todo == 1) { ?>
        <TR>
        <TD><b>APORTE NACIONAL SOLIDARIO</b></TD>
        <TD align="right"><?php echo number_format($matriz_pla [$j][35],$n_decimales); ?></TD>
        </TR>
        <?php $suma_descuentos = $suma_descuentos + $matriz_pla [$j][35]; ?>
        <?php } ?>
        
        <?php if ($matriz_pla [$j][34] > 0 || $boleta_mostrar_todo == 1) { ?>
        <TR>
        <TD><b>FALTAS</b></TD>
        <TD align="right"><?php echo number_format($matriz_pla [$j][34],$n_decimales); ?></TD>
        </TR>
        <?php $suma_descuentos = $suma_descuentos + $matriz_pla [$j][34]; ?>
        <?php } ?>
        
        <?php if ($matriz_pla [$j][36] > 0 || $boleta_mostrar_todo == 1) { ?>
        <TR>
        <TD><b>RC-IVA</b></TD>
        <TD align="right"><?php echo number_format($matriz_pla [$j][36],$n_decimales); ?></TD>
        </TR>
        <?php $suma_descuentos = $suma_descuentos + $matriz_pla [$j][36]; ?>
        <?php } ?>
        
        <?php
        //detalle descuentos
    $resultdesc = mysqli_query($link, "select a.pkyBonusDiscount as cod_bondes, a.fldDocumentNumber as nro_doc, a.fldDate as fecha, a.fldPeriod as periodo, b.codEmployee as cod_empleado, b.codConcept as cod_conceptobd, c.fldName as bono_descuento, b.fldAmount as monto
    from hrsBonusDiscount a, hrsBonusDiscountDetail b, hrsBonusDiscountConcept c
    where 
    a.pkyBonusDiscount = b.codBonusDiscount and 
    b.codConcept = c.pkyBonusDiscountConcept and 
    c.fldIsDiscount = 1 and 
    b.codEmployee = '$cod_empleado' and 
    a.fldDate >= '$vfechaini' and 
    a.fldDate <= '$vfechafin' and 
    a.sysEnabled = 1 and a.sysAuthorized = 1
    order by c.fldName, a.fldDate, b.fldAmount;");
    
        while ($row = mysqli_fetch_array($resultdesc)) { //while
          if($row['monto'] > 0 || $boleta_mostrar_todo == 1) {
            printf("<tr><td><b>%s</b></td>", strtr(strtoupper($row['bono_descuento']), "àáâãäåæçèéêëìíîïðñòóôõöøùüú", "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÜÚ"));//nombre
            printf("<td align='right'>%s</td></tr>", number_format($row['monto'],$n_decimales));//monto
            $suma_descuentos = $suma_descuentos + $row['monto'];
          }
        }//fin while
    ?>
    </table>
</td></tr></table><!--fin tabla 12-->

<table border="0" align="center" cellpadding="2" width="100%">
<TR>
    <TD style='border-bottom: solid 1px; border-left: solid 1px'><b>TOTAL DESCUENTOS</b></TD>
    <TD style='border-bottom: solid 1px; border-right: solid 1px' align="right"><?php echo number_format($suma_descuentos,$n_decimales); ?></TD>
</TR>
<TR>
    <TD style='border-bottom: solid 1px; border-left: solid 1px'><b>L&Iacute;QUIDO PAGABLE</b></TD>
    <TD style='border-bottom: solid 1px; border-right: solid 1px' align="right"><b><?php echo number_format($suma_ingresos-$suma_descuentos,$n_decimales); ?></b></TD>
</TR>
<TR>
	<TD colspan="2">&nbsp;</TD>
</TR>
<TR>
	<TD colspan="2">&nbsp;</TD>
</TR>
<TR>
	<TD colspan="2" align="center">__________________________</TD>
</TR> 
<TR>
	<TD colspan="2" align="center">RECIB&Iacute; CONFORME</TD>
</TR>   
</table>
<!--fin descuentos-->

</td>
</tr>
</table>


<?php

if($j != $numero_filas) {//if $j
	?>

<div>

</div>
<?php
}//fin if $j
}//fin for
?>

<?php
}// fin if mostrar 0


//fondo solidario
//este if es para mostrar con el formato reporte
if($mostrar == 1 && $planilla == 4) { //mostrar 1

?>
<table border="0" align="left" width="100%" cellpadding="5">
<tr><td><?php echo $mostrar_logo_reportes; ?>
</td><td align="right"><b>Fecha: <?php echo date("Y-m-d"); ?><br/>Hora: <?php echo date("H:i:s"); ?><br/>Usuario: <?php echo $usuario; ?></b>
</td></tr></table>
<p><br /><center><font color="#000099" size="+1"><b>Reporte Planilla Fondo Solidario</b></font></center></p>
<table border="0" cellpadding="2" align="center" width="100%">
<tr>
<td>	
    <table border="1" align="center" cellpadding="2" width="100%">
        <TR> 
        <TD width="33%"><b>Planilla: </b><?php echo $nom_planilla; ?></TD>
        <TD width="33%"><b>Sucursal: </b><?php echo $nom_sucursal; ?></TD>
        <TD width="33%"><b>Ciudad de la(s) Sucursal(es): </b><?php echo $nom_ciudad; ?></TD>
        </TR>
        <TR> 
        <TD><b>Empleado: </b><?php echo $nom_empleado; ?></TD>
        <TD><b>Genero: </b><?php echo $nom_genero; ?></TD>
        <TD><b>Cargo: </b><?php echo $nom_cargo; ?></TD>
        </TR>
        <TR>
        <TD><b>Mes A&ntilde;o Inicial: </b><?php echo $nom_mesini; ?> de <?php echo $anoini; ?></TD>
        <TD><b>Mes A&ntilde;o Final: </b><?php echo $nom_mesfin; ?> de <?php echo $anofin; ?></TD>
        <TD><b>Ordenado por: </b><?php echo $nom_orden; ?></TD>
        </TR>
        <TR>
        <TD><b>AFP: </b><?php echo $nom_afp; ?></TD>
        <TD><b>Contexto: </b><?php echo $nom_contexto; ?></TD>
        <TD><b>Expresado en: </b><?php echo $nom_moneda_principal; ?></TD>
        </TR>
    </table>

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

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

<table border="1" align="center" cellpadding="2" width="100%">
 	<thead>
    <?php if($cod_afp <= 0) { $nro_col = 17; //if todos ?>
    <TR> 
    <TD align="center"><b>No.</b></TD>
    <TD align="center"><b>Tipo Doc. de Identidad</b></TD>
    <TD align="center"><b>Nro. de Doc. de Identidad</b></TD>
    <TD align="center"><b>Ext. del Doc. de Identidad</b></TD>
    <TD align="center"><b>NUA/CUA</b></TD>
    <TD align="center"><b>AFP a la que Aporta</b></TD>
    <TD align="center"><b>Apellido Paterno</b></TD>
    <TD align="center"><b>Apellido Materno</b></TD>
    <TD align="center"><b>Apellido de Casada</b></TD>
    <TD align="center"><b>Primer Nombre</b></TD>
    <TD align="center"><b>Otros Nombres</b></TD>
    <TD align="center"><b>Cargo</b></TD>
    <TD align="center"><b>Sucursal</b></TD>
    <TD align="center"><b>Departamento</b></TD>
    <TD align="center"><b>Novedad I/R/L/S</b></TD>
    <TD align="center"><b>Fecha de Novedad</b></TD>
    <TD align="center"><b>Dias Cotizados</b></TD>
    <TD align="center"><b>Total Ganado Solidario (TGS)</b></TD>
    <TD align="center"><b>TGS - 13.000</b></TD>
    <TD align="center"><b>1%</b></TD>
    <TD align="center"><b>TGS - 25.000</b></TD>
    <TD align="center"><b>5%</b></TD>
    <TD align="center"><b>TGS - 35.000</b></TD>
    <TD align="center"><b>10%</b></TD>
    <TD align="center"><b>Total Solidario</b></TD>
    </TR>
    <?php } //fin if todos ?>
    
    <?php if($cod_afp == 1) { $nro_col = 10; //if 1prev ?>
    <TR> 
    <TD align="center"><b>No.</b></TD>
    <TD align="center"><b>Tipo</b></TD>
    <TD align="center"><b>N&uacute;mero</b></TD>
    <TD align="center"><b>Ext.</b></TD>
    <TD align="center"><b>NUA/CUA</b></TD>
    <TD align="center" width="250"><b>Nombre Completo</b></TD>
    <TD align="center"><b>Departamento</b></TD>
    <TD align="center"><b>Novedad I/R/L/S</b></TD>
    <TD align="center"><b>Fecha Novedad</b></TD>
    <TD align="center"><b>Dias Cotizados</b></TD>
    <TD align="center"><b>Total Ganado Solidario (Sin considerar tope de 60 Salarios M&iacute;nimos Nacionales)</b></TD>
    <TD align="center"><b>Total Ganado Solidario - Bs. 13000 (Si la diferencia es positiva)</b></TD>
    <TD align="center"><b>Total Ganado Solidario - Bs. 25000 (Si la diferencia es positiva)</b></TD>
    <TD align="center"><b>Total Ganado Solidario - Bs. 35000 (Si la diferencia es positiva)</b></TD>
    </TR>
    <?php } //fin if 1prev?>
    
    <?php if($cod_afp == 2) { $nro_col = 14; //if 2fut ?>
    <TR> 
    <TD align="center"><b>No.</b></TD>
    <TD align="center"><b>Tipo</b></TD>
    <TD align="center"><b>N&uacute;mero</b></TD>
    <TD align="center"><b>Ext.</b></TD>
    <TD align="center"><b>NUA/CUA</b></TD>
    <TD align="center"><b>Primer Apellido (Paterno)</b></TD>
    <TD align="center"><b>Primer Apellido (Materno)</b></TD>
    <TD align="center"><b>Apellido de Casada</b></TD>
    <TD align="center"><b>Primer Nombre</b></TD>
    <TD align="center"><b>Segundo Nombre</b></TD>
    <TD align="center"><b>Departamento</b></TD>
    <TD align="center"><b>Novedad I/R/L/S</b></TD>
    <TD align="center"><b>Fecha de Novedad dd/mm/aaaa</b></TD>
    <TD align="center"><b>Dias Cotizados</b></TD>
    <TD align="center"><b>Total Ganado Solidario (Sin considerar tope de 60 Salarios M&iacute;nimos Nacionales)</b></TD>
    <TD align="center"><b>Total Ganado Solidario - Bs. 13000 (Si la diferencia es positiva)</b></TD>
    <TD align="center"><b>Total Ganado Solidario - Bs. 25000 (Si la diferencia es positiva)</b></TD>
    <TD align="center"><b>Total Ganado Solidario - Bs. 35000 (Si la diferencia es positiva)</b></TD>
    </TR>
    <?php } //fin if 2fut?>
    </thead>
    <tbody class="marcafila">

<?php
$color = 2;
$j = 1;
$nu = 1;
$total_ganado_solidario = 0;
$total_13000 = 0;
$total_1 = 0;
$total_25000 = 0;
$total_5 = 0;
$total_35000 = 0;
$total_10 = 0;
$total_solidario = 0;


	while ($j <= $fin) { //while
	
	//si el monto de afp es 0 y si es jubilado y si no tiene asignada una afp le asigno de acuerdo a su fecha de nacimiento par=1 prevision, impar=2 futuro
	//por eso tiene que mostrarse en bloques individuales aqui recien asigno a los que no tienen afp
	if($matriz_pla [$j][32] == 0 && $matriz_pla [$j][56] == 1 && $matriz_pla [$j][49] == 0) { //if afp
		$dia_nac_afp = substr($matriz_pla [$j][39],8);
		if($dia_nac_afp % 2 == 0){
			$matriz_pla [$j][49] = 1;	
		} else {
			$matriz_pla [$j][49] = 2;
		}
	}//fin if afp
	
	//hago antes el calculo para ver si muestra o no al empleado
	$trab_extraor_nocturno = $matriz_pla [$j][20]+$matriz_pla [$j][22]+$matriz_pla [$j][26]+$matriz_pla [$j][28];
	$suma_total_ganado = $matriz_pla [$j][70]+$matriz_pla [$j][30]+$bono_produccion+$subsidio_frontera+$trab_extraor_nocturno+$matriz_pla [$j][24]+$matriz_pla [$j][29];
	
	if($suma_total_ganado > 13000) {//if 13000
	
	$cod_emp = $matriz_pla [$j][2];
	$cod_cargo = $matriz_pla [$j][67];
	$cod_suc = $matriz_pla [$j][68];
	$periodo = $matriz_pla [$j][46];
	
	if($cod_afp < 0) { //if 0
	
    if($color % 2 == 0) { //if color
	printf("<tr BGCOLOR='#e2e7fa'><td align='center'>%s</td>", $nu);//numero
	} else {
	printf("<tr><td align='center'>%s</td>", $nu);//numero
	}//fin if color
    //printf("<td align='center'><a href='../../ModuleAgenda/VoucherPerson/index.php?pkyPerson=$cod_empleado&user=$usuario&token=$token' title='Persona'>%s</a></td>", $matriz_pla [$j][2]);//cod empleado
	printf("<td align='center'>%s</td>", $matriz_pla [$j][82]);//tipo documento
	printf("<td align='right'>%s</td>", $matriz_pla [$j][43]);//nro documento
	printf("<td align='center'>%s</td>", $matriz_pla [$j][48]);//extension documento
	printf("<td align='right'>%s</td>", $matriz_pla [$j][50]);//nua
	if($matriz_pla [$j][49] == 0) { $nombre_afp = 'NA'; }
	if($matriz_pla [$j][49] == 1) { $nombre_afp = 'Previsi&oacute;n'; }
	if($matriz_pla [$j][49] == 2) { $nombre_afp = 'Futuro'; }
	printf("<td align='left'>%s</td>", $nombre_afp);//afp
	
	$texto = $matriz_pla [$j][51];//ap pat
	$texto = strtr(strtoupper($texto), "àáâãäåæçèéêëìíîïðñòóôõöøùüú", "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÜÚ");
	//$texto = substr($texto,0,150);
	printf("<td align='left'>%s</td>", $texto);//ap pat
	$texto = $matriz_pla [$j][52];//ap mat
	$texto = strtr(strtoupper($texto), "àáâãäåæçèéêëìíîïðñòóôõöøùüú", "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÜÚ");
	//$texto = substr($texto,0,150);
	printf("<td align='left'>%s</td>", $texto);//ap mat
	$texto = $matriz_pla [$j][53];//ap casada
	$texto = strtr(strtoupper($texto), "àáâãäåæçèéêëìíîïðñòóôõöøùüú", "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÜÚ");
	//$texto = substr($texto,0,150);
	printf("<td align='left'>%s</td>", $texto);//ap casada
	$texto = $matriz_pla [$j][54];//nombre
	$texto = strtr(strtoupper($texto), "àáâãäåæçèéêëìíîïðñòóôõöøùüú", "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÜÚ");
	//$texto = substr($texto,0,150);
	printf("<td align='left'>%s</td>", $texto);//nombre
	$texto = $matriz_pla [$j][55];//nombre otros
	$texto = strtr(strtoupper($texto), "àáâãäåæçèéêëìíîïðñòóôõöøùüú", "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÜÚ");
	//$texto = substr($texto,0,150);
	printf("<td align='left'>%s</td>", $texto);//nombre otros
	printf("<td align='left'>%s</td>", $matriz_pla [$j][6]);//cargo
	printf("<td align='left'>%s</td>", $matriz_pla [$j][5]);//sucursal
	printf("<td align='left'>%s</td>", $matriz_pla [$j][79]);//departamento sucursal
	printf("<td align='center'>%s</td>", $matriz_pla [$j][80]);//novedad I/R/L/S
	if($matriz_pla [$j][81] <> NULL) {//if fecha novedad
	printf("<td align='center'>%s</td>", cambiarFormatoFechaBarra($matriz_pla [$j][81]));//fecha novedad
	} else {
	printf("<td align='center'>%s</td>", $matriz_pla [$j][81]);//fecha novedad	
	}//fin if fecha novedad
	
	printf("<td align='right'>%s</td>", number_format($matriz_pla [$j][13],0));//dias cotizados
	printf("<td align='right'>%s</td>", number_format($suma_total_ganado,$n_decimales));//total ganado
	//printf("<td align='right'>%s</td>", number_format($matriz_pla [$j][32]+$matriz_pla [$j][35],$n_decimales));//aporte afp + solidario
	if($suma_total_ganado > 13000) {
	$suma_total_ganado_13000 = $suma_total_ganado - 13000;
	} else {
	$suma_total_ganado_13000 = 0;	
	}
	printf("<td align='right'>%s</td>", number_format($suma_total_ganado_13000,$n_decimales));//total ganado - 13000
	$suma_total_ganado_13000_1 = $suma_total_ganado_13000 * 0.01;
	printf("<td align='right'>%s</td>", number_format($suma_total_ganado_13000_1,$n_decimales));//(total ganado - 13000)*1%
	if($suma_total_ganado > 25000) {
	$suma_total_ganado_25000 = $suma_total_ganado - 25000;
	} else {
	$suma_total_ganado_25000 = 0;	
	}
	printf("<td align='right'>%s</td>", number_format($suma_total_ganado_25000,$n_decimales));//total ganado - 25000
	$suma_total_ganado_25000_5 = $suma_total_ganado_25000 * 0.05;
	printf("<td align='right'>%s</td>", number_format($suma_total_ganado_25000_5,$n_decimales));//(total ganado - 25000)*5%
	if($suma_total_ganado > 35000) {
	$suma_total_ganado_35000 = $suma_total_ganado - 35000;
	} else {
	$suma_total_ganado_35000 = 0;	
	}
	printf("<td align='right'>%s</td>", number_format($suma_total_ganado_35000,$n_decimales));//total ganado - 35000
	$suma_total_ganado_35000_10 = $suma_total_ganado_35000 * 0.1;
	printf("<td align='right'>%s</td>", number_format($suma_total_ganado_35000_10,$n_decimales));//(total ganado - 35000)*10%
	$suma_total_solidario = $suma_total_ganado_13000_1 + $suma_total_ganado_25000_5 + $suma_total_ganado_35000;
	printf("<td align='right'>%s</td></tr>", number_format($suma_total_solidario,$n_decimales));//suma total solidario
	
	} //fin if 0
	
	
	if($cod_afp == 1 && $matriz_pla [$j][49] == 1) { //if 1
	
    if($color % 2 == 0) { //if color
	printf("<tr BGCOLOR='#e2e7fa'><td align='center'>%s</td>", $nu);//numero
	} else {
	printf("<tr><td align='center'>%s</td>", $nu);//numero
	}//fin if color
    //printf("<td align='center'><a href='../../ModuleAgenda/VoucherPerson/index.php?pkyPerson=$cod_empleado&user=$usuario&token=$token' title='Persona'>%s</a></td>", $matriz_pla [$j][2]);//cod empleado
	printf("<td align='center'>%s</td>", $matriz_pla [$j][82]);//tipo documento
	printf("<td align='right'>%s</td>", $matriz_pla [$j][43]);//nro documento
	printf("<td align='center'>%s</td>", $matriz_pla [$j][48]);//extension documento
	printf("<td align='right'>%s</td>", $matriz_pla [$j][50]);//nua
	
	$texto = $matriz_pla [$j][3];//empleado
	$texto = strtr(strtoupper($texto), "àáâãäåæçèéêëìíîïðñòóôõöøùüú", "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÜÚ");
	//$texto = substr($texto,0,150);
	printf("<td align='left'>%s</td>", $texto);//empleado
	printf("<td align='left'>%s</td>", $matriz_pla [$j][79]);//departamento sucursal
	printf("<td align='center'>%s</td>", $matriz_pla [$j][80]);//novedad I/R/L/S
	if($matriz_pla [$j][81] <> NULL) {//if fecha novedad
	printf("<td align='center'>%s</td>", cambiarFormatoFechaBarra($matriz_pla [$j][81]));//fecha novedad
	} else {
	printf("<td align='center'>%s</td>", $matriz_pla [$j][81]);//fecha novedad	
	}//fin if fecha novedad
	
	printf("<td align='right'>%s</td>", number_format($matriz_pla [$j][13],0));//dias cotizados
	printf("<td align='right'>%s</td>", number_format($suma_total_ganado,$n_decimales));//total ganado
	//printf("<td align='right'>%s</td>", number_format($matriz_pla [$j][32]+$matriz_pla [$j][35],$n_decimales));//aporte afp + solidario
	if($suma_total_ganado > 13000) {
	$suma_total_ganado_13000 = $suma_total_ganado - 13000;
	} else {
	$suma_total_ganado_13000 = 0;	
	}
	printf("<td align='right'>%s</td>", number_format($suma_total_ganado_13000,$n_decimales));//total ganado - 13000
	if($suma_total_ganado > 25000) {
	$suma_total_ganado_25000 = $suma_total_ganado - 25000;
	} else {
	$suma_total_ganado_25000 = 0;	
	}
	printf("<td align='right'>%s</td>", number_format($suma_total_ganado_25000,$n_decimales));//total ganado - 25000
	if($suma_total_ganado > 35000) {
	$suma_total_ganado_35000 = $suma_total_ganado - 35000;
	} else {
	$suma_total_ganado_35000 = 0;	
	}
	printf("<td align='right'>%s</td></tr>", number_format($suma_total_ganado_35000,$n_decimales));//total ganado - 35000
	
	} //fin if 1
	
	if($cod_afp == 2 && $matriz_pla [$j][49] == 2) { //if 2
	
    if($color % 2 == 0) { //if color
	printf("<tr BGCOLOR='#e2e7fa'><td align='center'>%s</td>", $nu);//numero
	} else {
	printf("<tr><td align='center'>%s</td>", $nu);//numero
	}//fin if color
    //printf("<td align='center'><a href='../../ModuleAgenda/VoucherPerson/index.php?pkyPerson=$cod_empleado&user=$usuario&token=$token' title='Persona'>%s</a></td>", $matriz_pla [$j][2]);//cod empleado
	printf("<td align='center'>%s</td>", $matriz_pla [$j][82]);//tipo documento
	printf("<td align='right'>%s</td>", $matriz_pla [$j][43]);//nro documento
	printf("<td align='center'>%s</td>", $matriz_pla [$j][48]);//extension documento
	printf("<td align='right'>%s</td>", $matriz_pla [$j][50]);//nua
	
	$texto = $matriz_pla [$j][51];//ap pat
	$texto = strtr(strtoupper($texto), "àáâãäåæçèéêëìíîïðñòóôõöøùüú", "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÜÚ");
	//$texto = substr($texto,0,150);
	printf("<td align='left'>%s</td>", $texto);//ap pat
	$texto = $matriz_pla [$j][52];//ap mat
	$texto = strtr(strtoupper($texto), "àáâãäåæçèéêëìíîïðñòóôõöøùüú", "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÜÚ");
	//$texto = substr($texto,0,150);
	printf("<td align='left'>%s</td>", $texto);//ap mat
	$texto = $matriz_pla [$j][53];//ap casada
	$texto = strtr(strtoupper($texto), "àáâãäåæçèéêëìíîïðñòóôõöøùüú", "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÜÚ");
	//$texto = substr($texto,0,150);
	printf("<td align='left'>%s</td>", $texto);//ap casada
	$texto = $matriz_pla [$j][54];//nombre
	$texto = strtr(strtoupper($texto), "àáâãäåæçèéêëìíîïðñòóôõöøùüú", "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÜÚ");
	//$texto = substr($texto,0,150);
	printf("<td align='left'>%s</td>", $texto);//nombre
	$texto = $matriz_pla [$j][55];//nombre otros
	$texto = strtr(strtoupper($texto), "àáâãäåæçèéêëìíîïðñòóôõöøùüú", "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÜÚ");
	//$texto = substr($texto,0,150);
	printf("<td align='left'>%s</td>", $texto);//nombre otros
	printf("<td align='left'>%s</td>", $matriz_pla [$j][79]);//departamento sucursal
	printf("<td align='center'>%s</td>", $matriz_pla [$j][80]);//novedad I/R/L/S
	if($matriz_pla [$j][81] <> NULL) {//if fecha novedad
	printf("<td align='center'>%s</td>", cambiarFormatoFechaBarra($matriz_pla [$j][81]));//fecha novedad
	} else {
	printf("<td align='center'>%s</td>", $matriz_pla [$j][81]);//fecha novedad	
	}//fin if fecha novedad
	
	printf("<td align='right'>%s</td>", number_format($matriz_pla [$j][13],0));//dias cotizados
	printf("<td align='right'>%s</td>", number_format($suma_total_ganado,$n_decimales));//total ganado
	//printf("<td align='right'>%s</td>", number_format($matriz_pla [$j][32]+$matriz_pla [$j][35],$n_decimales));//aporte afp + solidario
	if($suma_total_ganado > 13000) {
	$suma_total_ganado_13000 = $suma_total_ganado - 13000;
	} else {
	$suma_total_ganado_13000 = 0;	
	}
	printf("<td align='right'>%s</td>", number_format($suma_total_ganado_13000,$n_decimales));//total ganado - 13000
	if($suma_total_ganado > 25000) {
	$suma_total_ganado_25000 = $suma_total_ganado - 25000;
	} else {
	$suma_total_ganado_25000 = 0;	
	}
	printf("<td align='right'>%s</td>", number_format($suma_total_ganado_25000,$n_decimales));//total ganado - 25000
	if($suma_total_ganado > 35000) {
	$suma_total_ganado_35000 = $suma_total_ganado - 35000;
	} else {
	$suma_total_ganado_35000 = 0;	
	}
	printf("<td align='right'>%s</td></tr>", number_format($suma_total_ganado_35000,$n_decimales));//total ganado - 35000
	
	} //fin if 2

	$total_ganado_solidario = $total_ganado_solidario + $suma_total_ganado;
	$total_13000 = $total_13000 + $suma_total_ganado_13000;
	$total_1 = $total_1 + $suma_total_ganado_13000_1;
	$total_25000 = $total_25000 + $suma_total_ganado_25000;
	$total_5 = $total_5 + $suma_total_ganado_25000_5;
	$total_35000 = $total_35000 + $suma_total_ganado_35000;
	$total_10 = $total_10 + $suma_total_ganado_35000_10;
	$total_solidario = $total_solidario + $suma_total_solidario;
	
	$nu++;
	$color++;
	} //fin if 13000
	
	$j++;
  
	} //fin while
?>
 
<tr BGCOLOR='#ffcccc'><td colspan="<?php echo $nro_col; ?>"><b>Total</b></td>
<?php if($cod_afp < 0) { //if 01 ?>
<td align="right"><?php printf("<b>%s</b>", number_format($total_ganado_solidario,$n_decimales)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_13000,$n_decimales)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_1,$n_decimales)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_25000,$n_decimales)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_5,$n_decimales)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_35000,$n_decimales)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_10,$n_decimales)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_solidario,$n_decimales)); ?></td>
<?php } //fin if 01 ?>

<?php if($cod_afp == 1 || $cod_afp == 2) { //if 12 ?>
<td align="right"><?php printf("<b>%s</b>", number_format($total_ganado_solidario,$n_decimales)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_13000,$n_decimales)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_25000,$n_decimales)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_35000,$n_decimales)); ?></td>
<?php } //fin if 12 ?>
</tr>
<?php if ($pie_planilla == 1) { //if pie 1 ?>
<?php if($cod_afp < 0) { //if 01 ?>
<tr>
<td colspan="8" align="left"><br/><b>Elaborado por: <?php echo $usuario; ?></b><br/>&nbsp;</td>
<td colspan="9" align="left"><br/><b><?php echo $firma_contabilidad; ?></b><br/>&nbsp;</td>
<td colspan="8" align="left"><br/><b><?php echo $firma_gerencia; ?></b><br/>&nbsp;</td>
</tr>
<?php } //fin if 01 ?>
<?php if($cod_afp == 1) { //if 11 ?>
<tr>
<td colspan="6" align="left"><br/><b>Elaborado por: <?php echo $usuario; ?></b><br/>&nbsp;</td>
<td colspan="4" align="left"><br/><b><?php echo $firma_contabilidad; ?></b><br/>&nbsp;</td>
<td colspan="4" align="left"><br/><b><?php echo $firma_gerencia; ?></b><br/>&nbsp;</td>
</tr>
<?php } //fin if 11 ?>
<?php if($cod_afp == 2) { //if 21 ?>
<tr>
<td colspan="7" align="left"><br/><b>Elaborado por: <?php echo $usuario; ?></b><br/>&nbsp;</td>
<td colspan="6" align="left"><br/><b><?php echo $firma_contabilidad; ?></b><br/>&nbsp;</td>
<td colspan="5" align="left"><br/><b><?php echo $firma_gerencia; ?></b><br/>&nbsp;</td>
</tr>
<?php } //fin if 21 ?>
<?php } //fin if pie 1 ?>
</tbody>
</table>

<?php	
}// fin if mostrar 1


//caja de salud
//este if es para mostrar con el formato reporte
if($mostrar == 1 && $planilla == 5) { //mostrar 1

?>
<table border="0" align="left" width="100%" cellpadding="5">
<tr><td><?php echo $mostrar_logo_reportes; ?>
</td><td align="right"><b>Fecha: <?php echo date("Y-m-d"); ?><br/>Hora: <?php echo date("H:i:s"); ?><br/>Usuario: <?php echo $usuario; ?></b>
</td></tr></table>
<p><br /><center><font color="#000099" size="+1"><b>Reporte Planilla Caja de Salud</b></font></center></p>
<table border="0" cellpadding="2" align="center" width="100%">
<tr>
<td>	
    <table border="1" align="center" cellpadding="2" width="100%">
        <TR> 
        <TD width="33%"><b>Planilla: </b><?php echo $nom_planilla; ?></TD>
        <TD width="33%"><b>Sucursal: </b><?php echo $nom_sucursal; ?></TD>
        <TD width="33%"><b>Ciudad de la(s) Sucursal(es): </b><?php echo $nom_ciudad; ?></TD>
        </TR>
        <TR> 
        <TD><b>Empleado: </b><?php echo $nom_empleado; ?></TD>
        <TD><b>Genero: </b><?php echo $nom_genero; ?></TD>
        <TD><b>Cargo: </b><?php echo $nom_cargo; ?></TD>
        </TR>
        <TR>
        <TD><b>Mes A&ntilde;o Inicial: </b><?php echo $nom_mesini; ?> de <?php echo $anoini; ?></TD>
        <TD><b>Mes A&ntilde;o Final: </b><?php echo $nom_mesfin; ?> de <?php echo $anofin; ?></TD>
        <TD><b>Ordenado por: </b><?php echo $nom_orden; ?></TD>
        </TR>
        <TR>
        <TD><b>AFP: </b><?php echo $nom_afp; ?></TD>
        <TD><b>Contexto: </b><?php echo $nom_contexto; ?></TD>
        <TD><b>Expresado en: </b><?php echo $nom_moneda_principal; ?></TD>
        </TR>
    </table>

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

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

<table border="1" align="center" cellpadding="2" width="100%">
 	<thead>
    <TR> 
    <TD align="center"><b>No.</b></TD>
    <TD align="center"><b>Cod. Empleado</b></TD>
    <TD align="center"><b>Doc. de Identidad</b></TD>
    <TD align="center"><b>Expedido</b></TD>
    <TD align="center"><b>Apellido Paterno</b></TD>
    <TD align="center"><b>Apellido Materno</b></TD>
    <TD align="center"><b>Apellido de Casada</b></TD>
    <TD align="center"><b>Primer Nombre</b></TD>
    <TD align="center"><b>Otros Nombres</b></TD>
    <TD align="center"><b>Nacionalidad</b></TD>
    <TD align="center"><b>Cod. Asegurado</b></TD>
    <TD align="center"><b>Fecha de Nacimiento</b></TD>
    <TD align="center"><b>Sexo (M/F)</b></TD>
    <TD align="center"><b>Cargo</b></TD>
    <TD align="center"><b>Fecha de Ingreso</b></TD>
    <TD align="center"><b>Fecha de Retiro</b></TD>
    <TD align="center"><b>Haber Cotizado</b></TD>
    <TD align="center"><b>D&iacute;as Pagados (Mes)</b></TD>
    <TD align="center"><b>Haber Ganado</b></TD>
    <TD align="center"><b>Bono de Antig&uuml;edad</b></TD>
    <TD align="center"><b>Horas Extras</b></TD>
    <TD align="center"><b>Monto Horas Extras</b></TD>
    <TD align="center"><b>Bono de Producci&oacute;n</b></TD>
    <TD align="center"><b>Otros Bonos</b></TD>
    <TD align="center"><b>Dominicales</b></TD>
    <TD align="center"><b>Monto Dominicales</b></TD>
    <TD align="center"><b>Total Cotizable</b></TD>
    <TD align="center"><b>Total Ganado</b></TD>
    <!--<TD align="center"><b>Quincena</b></TD>-->
    <TD align="center"><b>Aporte a las AFPs</b></TD>
    <TD align="center"><b>RC-IVA</b></TD>
    <TD align="center"><b>Otros Descuentos</b></TD>
    <TD align="center"><b>Total Descuentos</b></TD>
    <TD align="center"><b>L&iacute;quido Pagable</b></TD>
    </TR>
    </thead>
    <tbody class="marcafila">

<?php
$color = 2;
$j = 1;
$nu = 1;
$total_haber_cotizado = 0;
$total_haber_ganado = 0;
$total_bono_ant = 0;
$total_hrs_extras = 0;
$total_bono_prod = 0;
$total_otros_bonos = 0;
$total_dominicales = 0;
$total_cotizable = 0;
$total_ganado = 0;
$total_quincena = 0;
$total_afp = 0;
$total_iva = 0;
$total_otros_desc = 0;
$total_desc = 0;
$total_liq_pagable = 0;

	while ($j <= $fin) { //while
	
	$cod_emp = $matriz_pla [$j][2];
	$cod_cargo = $matriz_pla [$j][67];
	$cod_suc = $matriz_pla [$j][68];
	$periodo = $matriz_pla [$j][46];
	
    if($color % 2 == 0) { //if color
	printf("<tr BGCOLOR='#e2e7fa'><td align='center'>%s</td>", $nu);//numero
	} else {
	printf("<tr><td align='center'>%s</td>", $nu);//numero
	}//fin if color
    
	printf("<td align='center'><a href='../../ModuleAgenda/VoucherPerson/index.php?pkyPerson=$cod_empleado&user=$usuario&token=$token' title='Persona'>%s</a></td>", $matriz_pla [$j][2]);//cod empleado
	printf("<td align='right'>%s</td>", $matriz_pla [$j][43]);//ci
	printf("<td align='center'>%s</td>", $matriz_pla [$j][48]);//expedido
	$texto = $matriz_pla [$j][51];//ap pat
	$texto = strtr(strtoupper($texto), "àáâãäåæçèéêëìíîïðñòóôõöøùüú", "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÜÚ");
	//$texto = substr($texto,0,150);
	printf("<td align='left'>%s</td>", $texto);//ap pat
	$texto = $matriz_pla [$j][52];//ap mat
	$texto = strtr(strtoupper($texto), "àáâãäåæçèéêëìíîïðñòóôõöøùüú", "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÜÚ");
	//$texto = substr($texto,0,150);
	printf("<td align='left'>%s</td>", $texto);//ap mat
	$texto = $matriz_pla [$j][53];//ap casada
	$texto = strtr(strtoupper($texto), "àáâãäåæçèéêëìíîïðñòóôõöøùüú", "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÜÚ");
	//$texto = substr($texto,0,150);
	printf("<td align='left'>%s</td>", $texto);//ap casada
	$texto = $matriz_pla [$j][54];//nombre
	$texto = strtr(strtoupper($texto), "àáâãäåæçèéêëìíîïðñòóôõöøùüú", "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÜÚ");
	//$texto = substr($texto,0,150);
	printf("<td align='left'>%s</td>", $texto);//nombre
	$texto = $matriz_pla [$j][55];//nombre otros
	$texto = strtr(strtoupper($texto), "àáâãäåæçèéêëìíîïðñòóôõöøùüú", "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÜÚ");
	//$texto = substr($texto,0,150);
	printf("<td align='left'>%s</td>", $texto);//nombre otros
	printf("<td align='left'>%s</td>", $matriz_pla [$j][44]);//nacionalidad
	printf("<td align='right'>%s</td>", $matriz_pla [$j][7]);//caja de salud
	printf("<td align='right'>%s</td>", cambiarFormatoFechaBarra($matriz_pla [$j][39]));//fecha nac
	if($matriz_pla [$j][40] == 1) {//if sexo
		printf("<td align='center'>M</td>");//M
	} else {
		printf("<td align='center'>F</td>");//F
	}//fin if sexo
	printf("<td align='left'>%s</td>", $matriz_pla [$j][6]);//cargo
	printf("<td align='center'>%s</td>", cambiarFormatoFechaBarra($matriz_pla [$j][10]));//fecha ing
	if($matriz_pla [$j][59] <> NULL) {//if baja
	printf("<td align='center'>%s</td>", cambiarFormatoFechaBarra($matriz_pla [$j][59]));//fecha baja
	} else {
	printf("<td align='center'>%s</td>", $matriz_pla [$j][59]);//fecha baja	
	}//fin if baja
	printf("<td align='right'>%s</td>", number_format($matriz_pla [$j][70],$n_decimales));//salario por dias trabajados cotizado
	printf("<td align='right'>%s</td>", $matriz_pla [$j][13]+$matriz_pla [$j][45]);//dias pagados
	$suma_haber_ganado = $matriz_pla [$j][70] - $matriz_pla [$j][34]; //salario por dias trabajados - desc faltas
	printf("<td align='right'>%s</td>", number_format($suma_haber_ganado,$n_decimales));//haber ganado
	printf("<td align='right'>%s</td>", number_format($matriz_pla [$j][30],$n_decimales));//bono antiguedad
	printf("<td align='right'>%s</td>", $matriz_pla [$j][19]);//horas extras
	printf("<td align='right'>%s</td>", number_format($matriz_pla [$j][20],$n_decimales));//monto horas extras
	printf("<td align='right'>%s</td>", number_format($bono_produccion,$n_decimales));//bono produccion
	
	$suma_otros_bonos = $matriz_pla [$j][22]+$matriz_pla [$j][26]+$matriz_pla [$j][28]+$subsidio_frontera+$matriz_pla [$j][29];
	printf("<td align='right'>%s</td>", number_format($suma_otros_bonos,$n_decimales));//otros bonos
	printf("<td align='right'>%s</td>", $matriz_pla [$j][23]);//dominicales
	printf("<td align='right'>%s</td>", number_format($matriz_pla [$j][24],$n_decimales));//monto dominicales
	
	$suma_cotizable = $matriz_pla [$j][70] + $matriz_pla [$j][30] + $matriz_pla [$j][20] + $bono_produccion + $suma_otros_bonos + $matriz_pla [$j][24];
	printf("<td align='right'>%s</td>", number_format($suma_cotizable,$n_decimales));//total cotizable
	
	$suma_total_haber_ganado = $suma_haber_ganado + $matriz_pla [$j][30] + $matriz_pla [$j][20] + $bono_produccion + $suma_otros_bonos + $matriz_pla [$j][24];
	printf("<td align='right'>%s</td>", number_format($suma_total_haber_ganado,$n_decimales));//total haber ganado
	/*$quincena = 0;
	printf("<td align='right'>%s</td>", number_format($quincena,$n_decimales));//quincena*/
	printf("<td align='right'>%s</td>", number_format($matriz_pla [$j][32],$n_decimales));//aporte afp
	printf("<td align='right'>%s</td>", number_format($matriz_pla [$j][36],$n_decimales));//iva
	
	$suma_otros_desc = $matriz_pla [$j][33]+$matriz_pla [$j][34]+$matriz_pla [$j][35];
	printf("<td align='right'>%s</td>", number_format($suma_otros_desc,$n_decimales));//otros descuentos
	
	$suma_total_desc = $suma_otros_desc+$matriz_pla [$j][32]+$matriz_pla [$j][36];
	printf("<td align='right'>%s</td>", number_format($suma_total_desc,$n_decimales));//total descuentos
			
	$liquido_pagable = $suma_total_haber_ganado-$suma_total_desc;
	printf("<td align='right'>%s</td></tr>", number_format($liquido_pagable,$n_decimales));//liquido pagable
		
	$total_haber_cotizado = $total_haber_cotizado + $matriz_pla [$j][70];
	$total_haber_ganado = $total_haber_ganado + $suma_haber_ganado;
	$total_bono_ant = $total_bono_ant + $matriz_pla [$j][30];
	$total_hrs_extras = $total_hrs_extras + $matriz_pla [$j][20];
	$total_bono_prod = $total_bono_prod + $bono_produccion;
	$total_otros_bonos = $total_otros_bonos + $suma_otros_bonos;
	$total_dominicales = $total_dominicales + $matriz_pla [$j][24];
	$total_cotizable = $total_cotizable + $suma_cotizable;
	$total_ganado = $total_ganado + $suma_total_haber_ganado;
	/*$total_quincena = $total_quincena + $quincena;*/
	$total_afp = $total_afp + $matriz_pla [$j][32];
	$total_iva = $total_iva + $matriz_pla [$j][36];
	$total_otros_desc = $total_otros_desc + $suma_otros_desc;
	$total_desc = $total_desc + $suma_total_desc;
	$total_liq_pagable = $total_liq_pagable + $liquido_pagable;
	
	$nu++;
	$color++;
	$j++;
  
	} //fin while
?>
 
<tr BGCOLOR='#ffcccc'><td colspan="16"><b>Total</b></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_haber_cotizado,$n_decimales)); ?></td>
<td>&nbsp;</td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_haber_ganado,$n_decimales)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_bono_ant,$n_decimales)); ?></td>
<td>&nbsp;</td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_hrs_extras,$n_decimales)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_bono_prod,$n_decimales)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_otros_bonos,$n_decimales)); ?></td>
<td>&nbsp;</td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_dominicales,$n_decimales)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_cotizable,$n_decimales)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_ganado,$n_decimales)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_afp,$n_decimales)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_iva,$n_decimales)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_otros_desc,$n_decimales)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_desc,$n_decimales)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($total_liq_pagable,$n_decimales)); ?></td>
</tr>
<?php if ($pie_planilla == 1) { //if pie 1 ?>
<tr>
<td colspan="11" align="left"><br/><b>Elaborado por: <?php echo $usuario; ?></b><br/>&nbsp;</td>
<td colspan="11" align="left"><br/><b><?php echo $firma_contabilidad; ?></b><br/>&nbsp;</td>
<td colspan="11" align="left"><br/><b><?php echo $firma_gerencia; ?></b><br/>&nbsp;</td>
</tr>
<?php } //fin if pie 1 ?>
</tbody>
</table>

<?php	
}// fin if mostrar 1


//afp
//este if es para mostrar con el formato reporte
if($mostrar == 1 && $planilla == 6) { //mostrar 1

?>
<table border="0" align="left" width="100%" cellpadding="5">
<tr><td><?php echo $mostrar_logo_reportes; ?>
</td><td align="right"><b>Fecha: <?php echo date("Y-m-d"); ?><br/>Hora: <?php echo date("H:i:s"); ?><br/>Usuario: <?php echo $usuario; ?></b>
</td></tr></table>
<p><br /><center><font color="#000099" size="+1"><b>Reporte Planilla AFP <?php echo $nom_afp; ?></b></font></center></p>
<table border="0" cellpadding="2" align="center" width="100%">
<tr>
<td>	
    <table border="1" align="center" cellpadding="2" width="100%">
        <TR> 
        <TD width="33%"><b>Planilla: </b><?php echo $nom_planilla; ?></TD>
        <TD width="33%"><b>Sucursal: </b><?php echo $nom_sucursal; ?></TD>
        <TD width="33%"><b>Ciudad de la(s) Sucursal(es): </b><?php echo $nom_ciudad; ?></TD>
        </TR>
        <TR> 
        <TD><b>Empleado: </b><?php echo $nom_empleado; ?></TD>
        <TD><b>Genero: </b><?php echo $nom_genero; ?></TD>
        <TD><b>Cargo: </b><?php echo $nom_cargo; ?></TD>
        </TR>
        <TR>
        <TD><b>Mes A&ntilde;o Inicial: </b><?php echo $nom_mesini; ?> de <?php echo $anoini; ?></TD>
        <TD><b>Mes A&ntilde;o Final: </b><?php echo $nom_mesfin; ?> de <?php echo $anofin; ?></TD>
        <TD><b>Ordenado por: </b><?php echo $nom_orden; ?></TD>
        </TR>
        <TR>
        <TD><b>AFP: </b><?php echo $nom_afp; ?></TD>
        <TD><b>Contexto: </b><?php echo $nom_contexto; ?></TD>
        <TD><b>Expresado en: </b><?php echo $nom_moneda_principal; ?></TD>
        </TR>
    </table>

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

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

<table border="1" align="center" cellpadding="2" width="100%">
 	<thead>
    <?php if($cod_afp <= 0) { $nro_col = 17; $nro_cola = 4; //if todos ?>
    <TR> 
    <TD align="center"><b>No.</b></TD>
    <TD align="center"><b>Tipo Doc. de Identidad</b></TD>
    <TD align="center"><b>Nro. de Doc. de Identidad</b></TD>
    <TD align="center"><b>Ext. del Doc. de Identidad</b></TD>
    <TD align="center"><b>NUA/CUA</b></TD>
    <TD align="center"><b>AFP a la que Aporta</b></TD>
    <TD align="center"><b>Fecha de Nacimiento</b></TD>
    <TD align="center"><b>Apellido Paterno</b></TD>
    <TD align="center"><b>Apellido Materno</b></TD>
    <TD align="center"><b>Apellido de Casada</b></TD>
    <TD align="center"><b>Primer Nombre</b></TD>
    <TD align="center"><b>Otros Nombres</b></TD>
    <TD align="center"><b>Departamento</b></TD>
    <TD align="center"><b>Novedad I/R/L/S</b></TD>
    <TD align="center"><b>Fecha de Novedad</b></TD>
    <TD align="center"><b>Dias Cotizados</b></TD>
    <TD align="center"><b>Tipo Asegurado</b></TD>
    <TD align="center"><b>Ing. Base < 65 A&ntilde;os Aporta</b></TD>
    <TD align="center"><b>Ing. Base > 65 A&ntilde;os Aporta</b></TD>
    <TD align="center"><b>Ing. Base < 65 A&ntilde;os Jubilado No Aporta</b></TD>
    <TD align="center"><b>Ing. Base > 65 A&ntilde;os Jubilado No Aporta</b></TD>
    <TD align="center"><b>Cotizaci&oacute;n adicional</b></TD>
    </TR>
    <?php } //fin if todos?>
    
    <?php if($cod_afp == 1) { $nro_col = 11; $nro_cola = 4; //if 1prev ?>
    <TR> 
    <TD align="center"><b>No.</b></TD>
    <TD align="center"><b>Tipo</b></TD>
    <TD align="center"><b>N&uacute;mero</b></TD>
    <TD align="center"><b>Ext.</b></TD>
    <TD align="center"><b>NUA/CUA</b></TD>
    <TD align="center" width="250"><b>Nombre Completo</b></TD>
    <TD align="center"><b>Departamento</b></TD>
    <TD align="center"><b>Novedad I/R/L/S</b></TD>
    <TD align="center"><b>Fecha Novedad</b></TD>
    <TD align="center"><b>Dias Cotizados</b></TD>
    <TD align="center"><b>Tipo de Asegurado (Minero-M, Estacional-E, Consultor de Linea-CL)</b></TD>
    <TD align="center"><b>Total Ganado Dependiente Menor de 65 a&ntilde;os o Asegurado con Pensi&oacute;n del SIP Menor de 65 a&ntilde;os que decide aportar al SIP</b></TD>
    <TD align="center"><b>Total Ganado Dependiente Mayor de 65 a&ntilde;os o Asegurado con Pensi&oacute;n del SIP Mayor de 65 a&ntilde;os que decide aportar al SIP</b></TD>
    <TD align="center"><b>Total Ganado Asegurado con Pensi&oacute;n del SIP Menor de 65 a&ntilde;os que decide no aportar al SIP</b></TD>
    <TD align="center"><b>Total Ganado Asegurado con Pensi&oacute;n del SIP Mayor de 65 a&ntilde;os que decide no aportar al SIP</b></TD>
    <TD align="center"><b>Cotizaci&oacute;n adicional</b></TD>
    </TR>
    <?php } //fin if 1prev?>
    
    <?php if($cod_afp == 2) { $nro_col = 15; $nro_cola = 7; //if 2fut ?>
    <TR> 
    <TD align="center"><b>No.</b></TD>
    <TD align="center"><b>Tipo</b></TD>
    <TD align="center"><b>N&uacute;mero</b></TD>
    <TD align="center"><b>Ext.</b></TD>
    <TD align="center"><b>NUA/CUA</b></TD>
    <TD align="center"><b>Primer Apellido (Paterno)</b></TD>
    <TD align="center"><b>Primer Apellido (Materno)</b></TD>
    <TD align="center"><b>Apellido de Casada</b></TD>
    <TD align="center"><b>Primer Nombre</b></TD>
    <TD align="center"><b>Segundo Nombre</b></TD>
    <TD align="center"><b>Departamento</b></TD>
    <TD align="center"><b>Novedad I/R/L/S</b></TD>
    <TD align="center"><b>Fecha de Novedad dd/mm/aaaa</b></TD>
    <TD align="center"><b>Dias Cotizados</b></TD>
    <TD align="center"><b>Tipo de Aseg.</b></TD>
    <TD align="center"><b>Tot. gan. depen. o aseg. <65 aporta</b></TD>
    <TD align="center"><b>Tot. gan. depen. o aseg. >65 aporta</b></TD>
    <TD align="center"><b>Tot. gan. aseg. con pens. <65 no aporta</b></TD>
    <TD align="center"><b>Tot. gan. aseg. con pens. >65 no aporta</b></TD>
    <TD align="center"><b>Cotizaci&oacute;n adicional</b></TD>
    <TD align="center"><b>Fdo. Viv. Total Ganado en Bs.</b></TD>
    <TD align="center"><b>Fdo. Sol. Total Ganado en Bs.</b></TD>
    <TD align="center"><b>Fdo. Sol. Total Ganado en Bs. (Minero)</b></TD>
    </TR>
    <?php } //fin if 2fut?>
    </thead>
    <tbody class="marcafila">

<?php
$color = 2;
$j = 1;
$nu = 1;
$ing_menor_65_si = 0;
$ing_mayor_65_si = 0;
$ing_menor_65_jub_no = 0;
$ing_mayor_65_jub_no = 0;
$coti_adic = 0;
$fondo_viv = 0;
$fondo_sol = 0;
$minero = 0;

//si eligen no asignado en afp 
if($cod_afp == 0) { $nro_col = 17; $nro_cola = 4; }

	while ($j <= $fin) { //while
	//si el monto de afp es 0 y si es jubilado y si no tiene asignada una afp le asigno de acuerdo a su fecha de nacimiento par=1 prevision, impar=2 futuro
	//por eso tiene que mostrarse en bloques individuales aqui recien asigno a los que no tienen afp
	if($matriz_pla [$j][32] == 0 && $matriz_pla [$j][56] == 1 && $matriz_pla [$j][49] == 0) { //if afp
		$dia_nac_afp = substr($matriz_pla [$j][39],8);
		if($dia_nac_afp % 2 == 0){
			$matriz_pla [$j][49] = 1;	
		} else {
			$matriz_pla [$j][49] = 2;
		}
	}//fin if afp
	
	$cotizacion_adicional = 0;
	
	$trab_extraor_nocturno = $matriz_pla [$j][20]+$matriz_pla [$j][22]+$matriz_pla [$j][26]+$matriz_pla [$j][28];
	$suma_total_ganado = $matriz_pla [$j][70]+$matriz_pla [$j][30]+$bono_produccion+$subsidio_frontera+$trab_extraor_nocturno+$matriz_pla [$j][24]+$matriz_pla [$j][29];
	
	$cod_emp = $matriz_pla [$j][2];
	$cod_cargo = $matriz_pla [$j][67];
	$cod_suc = $matriz_pla [$j][68];
	$periodo = $matriz_pla [$j][46];
	//echo $matriz_pla [$j][3].'<br>';
	
	if($cod_afp < 0) { //if 0
		
    if($color % 2 == 0) { //if color
	printf("<tr BGCOLOR='#e2e7fa'><td align='center'>%s</td>", $nu);//numero
	} else {
	printf("<tr><td align='center'>%s</td>", $nu);//numero
	}//fin if color
    //printf("<td align='center'><a href='../../ModuleAgenda/VoucherPerson/index.php?pkyPerson=$cod_empleado&user=$usuario&token=$token' title='Persona'>%s</a></td>", $matriz_pla [$j][2]);//cod empleado
	printf("<td align='center'>%s</td>", $matriz_pla [$j][82]);//tipo documento 
	printf("<td align='right'>%s</td>", $matriz_pla [$j][43]);//nro documento
	printf("<td align='center'>%s</td>", $matriz_pla [$j][48]);//extension documento
	printf("<td align='right'>%s</td>", $matriz_pla [$j][50]);//nua
	
	if($matriz_pla [$j][49] == 0) { $nombre_afp = 'NA'; }
	if($matriz_pla [$j][49] == 1) { $nombre_afp = 'Previsi&oacute;n'; }
	if($matriz_pla [$j][49] == 2) { $nombre_afp = 'Futuro'; }
	printf("<td align='left'>%s</td>", $nombre_afp);//afp
	printf("<td align='center'>%s</td>", cambiarFormatoFechaBarra($matriz_pla [$j][39]));//fecha nacimiento
		
	$texto = $matriz_pla [$j][51];//ap pat
	$texto = strtr(strtoupper($texto), "àáâãäåæçèéêëìíîïðñòóôõöøùüú", "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÜÚ");
	//$texto = substr($texto,0,150);
	printf("<td align='left'>%s</td>", $texto);//ap pat
	$texto = $matriz_pla [$j][52];//ap mat
	$texto = strtr(strtoupper($texto), "àáâãäåæçèéêëìíîïðñòóôõöøùüú", "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÜÚ");
	//$texto = substr($texto,0,150);
	printf("<td align='left'>%s</td>", $texto);//ap mat
	$texto = $matriz_pla [$j][53];//ap casada
	$texto = strtr(strtoupper($texto), "àáâãäåæçèéêëìíîïðñòóôõöøùüú", "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÜÚ");
	//$texto = substr($texto,0,150);
	printf("<td align='left'>%s</td>", $texto);//ap casada
	$texto = $matriz_pla [$j][54];//nombre
	$texto = strtr(strtoupper($texto), "àáâãäåæçèéêëìíîïðñòóôõöøùüú", "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÜÚ");
	//$texto = substr($texto,0,150);
	printf("<td align='left'>%s</td>", $texto);//nombre
	$texto = $matriz_pla [$j][55];//nombre otros
	$texto = strtr(strtoupper($texto), "àáâãäåæçèéêëìíîïðñòóôõöøùüú", "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÜÚ");
	//$texto = substr($texto,0,150);
	printf("<td align='left'>%s</td>", $texto);//nombre otros
	
	printf("<td align='left'>%s</td>", $matriz_pla [$j][79]);//departamento sucursal
	printf("<td align='center'>%s</td>", $matriz_pla [$j][80]);//novedad I/R/L/S
	if($matriz_pla [$j][81] <> NULL) {//if fecha novedad
	printf("<td align='center'>%s</td>", cambiarFormatoFechaBarra($matriz_pla [$j][81]));//fecha novedad
	} else {
	printf("<td align='center'>%s</td>", $matriz_pla [$j][81]);//fecha novedad	
	}//fin if fecha novedad
	
	printf("<td align='right'>%s</td>", number_format($matriz_pla [$j][13],0));//dias cotizados
	printf("<td align='center'>%s</td>", $matriz_pla [$j][83]);//tipo asegurado E por defecto	
	
	//compruebo la edad
	$ffecha_ini = $matriz_pla [$j][39]; //fecha de nacimiento
	$ffecha_fin = $vfechafin; //fecha final de la planilla
	$prueba_edad=calcularEdad($ffecha_ini,$ffecha_fin);
		
	if($matriz_pla [$j][56] == 0 && $prueba_edad < 65) {
	printf("<td align='right'>%s</td>", number_format($suma_total_ganado,$n_decimales));//total ganado no jubilado < 65 aporta
	$ing_menor_65 = $ing_menor_65 + $suma_total_ganado;
	} else {
	printf("<td align='right'>%s</td>", number_format(0,$n_decimales));//total ganado no jubilado < 65 aporta
	}
	
	if($matriz_pla [$j][56] == 0 && $prueba_edad >= 65) {
	printf("<td align='right'>%s</td>", number_format($suma_total_ganado,$n_decimales));//total ganado no jubilado > 65 aporta
	$ing_mayor_65 = $ing_mayor_65 + $suma_total_ganado;
	} else {
	printf("<td align='right'>%s</td>", number_format(0,$n_decimales));//total ganado no jubilado > 65 aporta
	}
	
	if($matriz_pla [$j][56] == 1 && $prueba_edad < 65) {
	printf("<td align='right'>%s</td>", number_format($suma_total_ganado,$n_decimales));//total ganado jubilado < 65 no aporta
	$ing_menor_65_jub = $ing_menor_65_jub + $suma_total_ganado;
	} else {
	printf("<td align='right'>%s</td>", number_format(0,$n_decimales));//total ganado no jubilado < 65 no aporta
	}
	
	if($matriz_pla [$j][56] == 1 && $prueba_edad >= 65) {
	printf("<td align='right'>%s</td>", number_format($suma_total_ganado,$n_decimales));//total ganado jubilado > 65 no aporta
	$ing_mayor_65_jub = $ing_mayor_65_jub + $suma_total_ganado;
	} else {
	printf("<td align='right'>%s</td>", number_format(0,$n_decimales));//total ganado no jubilado > 65 no aporta
	}
	
	printf("<td align='right'>%s</td>", number_format($cotizacion_adicional,$n_decimales));//cotizacion adicional
	
	echo '</tr>';
	
	} //fin if 0
	
	
	
	if($cod_afp == 1 && $matriz_pla [$j][49] == 1) { //if 1
	
	if($color % 2 == 0) { //if color
	printf("<tr BGCOLOR='#e2e7fa'><td align='center'>%s</td>", $nu);//numero
	} else {
	printf("<tr><td align='center'>%s</td>", $nu);//numero
	}//fin if color
    //printf("<td align='center'><a href='../../ModuleAgenda/VoucherPerson/index.php?pkyPerson=$cod_empleado&user=$usuario&token=$token' title='Persona'>%s</a></td>", $matriz_pla [$j][2]);//cod empleado
	printf("<td align='center'>%s</td>", $matriz_pla [$j][82]);//tipo documento 
	printf("<td align='right'>%s</td>", $matriz_pla [$j][43]);//nro documento
	printf("<td align='center'>%s</td>", $matriz_pla [$j][48]);//extension documento
	printf("<td align='right'>%s</td>", $matriz_pla [$j][50]);//nua
	
	$texto = $matriz_pla [$j][3];//empleado
	$texto = strtr(strtoupper($texto), "àáâãäåæçèéêëìíîïðñòóôõöøùüú", "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÜÚ");
	//$texto = substr($texto,0,150);
	printf("<td align='left'>%s</td>", $texto);//empleado
		
	printf("<td align='left'>%s</td>", $matriz_pla [$j][79]);//departamento sucursal
	printf("<td align='center'>%s</td>", $matriz_pla [$j][80]);//novedad I/R/L/S
	if($matriz_pla [$j][81] <> NULL) {//if fecha novedad
	printf("<td align='center'>%s</td>", cambiarFormatoFechaBarra($matriz_pla [$j][81]));//fecha novedad
	} else {
	printf("<td align='center'>%s</td>", $matriz_pla [$j][81]);//fecha novedad	
	}//fin if fecha novedad
	
	printf("<td align='right'>%s</td>", number_format($matriz_pla [$j][13],0));//dias cotizados
	printf("<td align='center'>%s</td>", $matriz_pla [$j][83]);//tipo asegurado E por defecto	
	
	//compruebo la edad
	$ffecha_ini = $matriz_pla [$j][39]; //fecha de nacimiento
	$ffecha_fin = $vfechafin; //fecha final de la planilla
	$prueba_edad=calcularEdad($ffecha_ini,$ffecha_fin);
		
	if($matriz_pla [$j][56] == 0 && $prueba_edad < 65) {
	printf("<td align='right'>%s</td>", number_format($suma_total_ganado,$n_decimales));//total ganado no jubilado < 65 aporta
	$ing_menor_65 = $ing_menor_65 + $suma_total_ganado;
	} else {
	printf("<td align='right'>%s</td>", number_format(0,$n_decimales));//total ganado no jubilado < 65 aporta
	}
	
	if($matriz_pla [$j][56] == 0 && $prueba_edad >= 65) {
	printf("<td align='right'>%s</td>", number_format($suma_total_ganado,$n_decimales));//total ganado no jubilado > 65 aporta
	$ing_mayor_65 = $ing_mayor_65 + $suma_total_ganado;
	} else {
	printf("<td align='right'>%s</td>", number_format(0,$n_decimales));//total ganado no jubilado > 65 aporta
	}
	
	if($matriz_pla [$j][56] == 1 && $prueba_edad < 65) {
	printf("<td align='right'>%s</td>", number_format($suma_total_ganado,$n_decimales));//total ganado jubilado < 65 no aporta
	$ing_menor_65_jub = $ing_menor_65_jub + $suma_total_ganado;
	} else {
	printf("<td align='right'>%s</td>", number_format(0,$n_decimales));//total ganado no jubilado < 65 no aporta
	}
	
	if($matriz_pla [$j][56] == 1 && $prueba_edad >= 65) {
	printf("<td align='right'>%s</td>", number_format($suma_total_ganado,$n_decimales));//total ganado jubilado > 65 no aporta
	$ing_mayor_65_jub = $ing_mayor_65_jub + $suma_total_ganado;
	} else {
	printf("<td align='right'>%s</td>", number_format(0,$n_decimales));//total ganado no jubilado > 65 no aporta
	}
	
	printf("<td align='right'>%s</td>", number_format($cotizacion_adicional,$n_decimales));//cotizacion adicional
	
	echo '</tr>';
	
	} //fin if 1
	
	
	if($cod_afp == 2 && $matriz_pla [$j][49] == 2) { //if 2
	
	if($color % 2 == 0) { //if color
	printf("<tr BGCOLOR='#e2e7fa'><td align='center'>%s</td>", $nu);//numero
	} else {
	printf("<tr><td align='center'>%s</td>", $nu);//numero
	}//fin if color
    //printf("<td align='center'><a href='../../ModuleAgenda/VoucherPerson/index.php?pkyPerson=$cod_empleado&user=$usuario&token=$token' title='Persona'>%s</a></td>", $matriz_pla [$j][2]);//cod empleado
	printf("<td align='center'>%s</td>", $matriz_pla [$j][82]);//tipo documento 
	printf("<td align='right'>%s</td>", $matriz_pla [$j][43]);//nro documento
	printf("<td align='center'>%s</td>", $matriz_pla [$j][48]);//extension documento
	printf("<td align='right'>%s</td>", $matriz_pla [$j][50]);//nua
	
	$texto = $matriz_pla [$j][51];//ap pat
	$texto = strtr(strtoupper($texto), "àáâãäåæçèéêëìíîïðñòóôõöøùüú", "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÜÚ");
	//$texto = substr($texto,0,150);
	printf("<td align='left'>%s</td>", $texto);//ap pat
	$texto = $matriz_pla [$j][52];//ap mat
	$texto = strtr(strtoupper($texto), "àáâãäåæçèéêëìíîïðñòóôõöøùüú", "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÜÚ");
	//$texto = substr($texto,0,150);
	printf("<td align='left'>%s</td>", $texto);//ap mat
	$texto = $matriz_pla [$j][53];//ap casada
	$texto = strtr(strtoupper($texto), "àáâãäåæçèéêëìíîïðñòóôõöøùüú", "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÜÚ");
	//$texto = substr($texto,0,150);
	printf("<td align='left'>%s</td>", $texto);//ap casada
	$texto = $matriz_pla [$j][54];//nombre
	$texto = strtr(strtoupper($texto), "àáâãäåæçèéêëìíîïðñòóôõöøùüú", "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÜÚ");
	//$texto = substr($texto,0,150);
	printf("<td align='left'>%s</td>", $texto);//nombre
	$texto = $matriz_pla [$j][55];//nombre otros
	$texto = strtr(strtoupper($texto), "àáâãäåæçèéêëìíîïðñòóôõöøùüú", "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÜÚ");
	//$texto = substr($texto,0,150);
	printf("<td align='left'>%s</td>", $texto);//nombre otros
	
	printf("<td align='left'>%s</td>", $matriz_pla [$j][79]);//departamento sucursal
	printf("<td align='center'>%s</td>", $matriz_pla [$j][80]);//novedad I/R/L/S
	if($matriz_pla [$j][81] <> NULL) {//if fecha novedad
	printf("<td align='center'>%s</td>", cambiarFormatoFechaBarra($matriz_pla [$j][81]));//fecha novedad
	} else {
	printf("<td align='center'>%s</td>", $matriz_pla [$j][81]);//fecha novedad	
	}//fin if fecha novedad
	
	printf("<td align='right'>%s</td>", number_format($matriz_pla [$j][13],0));//dias cotizados
	printf("<td align='center'>%s</td>", $matriz_pla [$j][83]);//tipo asegurado E por defecto	
	
	//compruebo la edad
	$ffecha_ini = $matriz_pla [$j][39]; //fecha de nacimiento
	$ffecha_fin = $vfechafin; //fecha final de la planilla
	$prueba_edad=calcularEdad($ffecha_ini,$ffecha_fin);
		
	if($matriz_pla [$j][56] == 0 && $prueba_edad < 65) {
	printf("<td align='right'>%s</td>", number_format($suma_total_ganado,$n_decimales));//total ganado no jubilado < 65 aporta
	$ing_menor_65 = $ing_menor_65 + $suma_total_ganado;
	} else {
	printf("<td align='right'>%s</td>", number_format(0,$n_decimales));//total ganado no jubilado < 65 aporta
	}
	
	if($matriz_pla [$j][56] == 0 && $prueba_edad >= 65) {
	printf("<td align='right'>%s</td>", number_format($suma_total_ganado,$n_decimales));//total ganado no jubilado > 65 aporta
	$ing_mayor_65 = $ing_mayor_65 + $suma_total_ganado;
	} else {
	printf("<td align='right'>%s</td>", number_format(0,$n_decimales));//total ganado no jubilado > 65 aporta
	}
	
	if($matriz_pla [$j][56] == 1 && $prueba_edad < 65) {
	printf("<td align='right'>%s</td>", number_format($suma_total_ganado,$n_decimales));//total ganado jubilado < 65 no aporta
	$ing_menor_65_jub = $ing_menor_65_jub + $suma_total_ganado;
	} else {
	printf("<td align='right'>%s</td>", number_format(0,$n_decimales));//total ganado no jubilado < 65 no aporta
	}
	
	if($matriz_pla [$j][56] == 1 && $prueba_edad >= 65) {
	printf("<td align='right'>%s</td>", number_format($suma_total_ganado,$n_decimales));//total ganado jubilado > 65 no aporta
	$ing_mayor_65_jub = $ing_mayor_65_jub + $suma_total_ganado;
	} else {
	printf("<td align='right'>%s</td>", number_format(0,$n_decimales));//total ganado no jubilado > 65 no aporta
	}
	
	printf("<td align='right'>%s</td>", number_format($cotizacion_adicional,$n_decimales));//cotizacion adicional
	
	$fondo_viv_tg = $suma_total_ganado;
	$fondo_sol_tg = $suma_total_ganado;
	$minero_tg = 0;
	if(strcmp($matriz_pla [$j][83],'M') == 0) {
		$minero_tg = $suma_total_ganado;
	}
	printf("<td align='right'>%s</td>", number_format($fondo_viv_tg,$n_decimales));//fondo vivienda total ganado
	printf("<td align='right'>%s</td>", number_format($fondo_sol_tg,$n_decimales));//fondo solidario total ganado
	printf("<td align='right'>%s</td>", number_format($minero_tg,$n_decimales));//minero total ganado
		
	echo '</tr>';
	
	} //fin if 2
	
	$coti_adic = $coti_adic + $cotizacion_adicional;
	$fondo_viv = $fondo_viv + $fondo_viv_tg;
	$fondo_sol = $fondo_sol + $fondo_sol_tg;
	$minero = $minero + $minero_tg;
	
	$nu++;
	$color++;

	
	$j++;
  
	} //fin while
?>
 
<tr BGCOLOR='#ffcccc'><td colspan="<?php echo $nro_col; ?>"><b>Total</b></td>
<td align="right"><?php printf("<b>%s</b>", number_format($ing_menor_65,$n_decimales)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($ing_mayor_65,$n_decimales)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($ing_menor_65_jub,$n_decimales)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($ing_mayor_65_jub,$n_decimales)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($coti_adic,$n_decimales)); ?></td>
<?php if($cod_afp == 2) { //if 2 ?>
<td align="right"><?php printf("<b>%s</b>", number_format($fondo_viv,$n_decimales)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($fondo_sol,$n_decimales)); ?></td>
<td align="right"><?php printf("<b>%s</b>", number_format($minero,$n_decimales)); ?></td>
<?php } //fin if 2 ?>
</tr>
<?php	

//aporte laboral
$resultlab = mysqli_query($link, "select a.codFixedDiscount as cod_aporte, b.fldName as aporte, sum(a.fldTotal) as monto 
from 
hrsSalaryPayrollFixedDiscounts a, hrsFixedDiscounts b, hrsSalaryPayroll c
where
c.fldPeriod >= '$vfechaini' and 
c.fldPeriod <= '$vfechafin' and 
a.codSalaryPayroll = c.pkySalaryPayroll and  
a.codFixedDiscount = b.pkyFixedDiscounts and 
b.fldIsLaboral = 1 and 
$valor_afp5 
c.sysEnabled = 1 and c.sysAuthorized = 1 
group by 
a.codFixedDiscount 
order by 
b.fldName;");
$total_laboral = 0;
while ($row = mysqli_fetch_array($resultlab)) {
	//printf("<tr BGCOLOR='#ffcccc'><td colspan='13'>&nbsp;</td>");//espacio
	printf("<tr BGCOLOR='#ffcccc'><td colspan='$nro_col'><b>%s</b></td>", $row['aporte']);//aporte
	printf("<td align='right'><b>%s</b></td>", number_format($row['monto'],$n_decimales));//monto
	printf("<td colspan='$nro_cola'>&nbsp;</td></tr>");//espacio
	$total_laboral = $total_laboral + $row['monto'];
}
mysqli_free_result($resultlab);
//printf("<tr BGCOLOR='#ffcccc'><td colspan='13'>&nbsp;</td>");//espacio
printf("<tr BGCOLOR='#ffcccc'><td colspan='$nro_col'><b>Total Laboral</b></td>");//titulo total
printf("<td align='right'><b>%s</b></td>", number_format($total_laboral,$n_decimales));//total aporte laboral
printf("<td colspan='$nro_cola'>&nbsp;</td></tr>");//espacio

//aporte patronal
$resultpat = mysqli_query($link, "select a.codFixedDiscount as cod_aporte, b.fldName as aporte, sum(a.fldTotal) as monto 
from 
hrsSalaryPayrollFixedDiscounts a, hrsFixedDiscounts b, hrsSalaryPayroll c
where
c.fldPeriod >= '$vfechaini' and 
c.fldPeriod <= '$vfechafin' and 
a.codSalaryPayroll = c.pkySalaryPayroll and  
a.codFixedDiscount = b.pkyFixedDiscounts and 
b.fldIsLaboral = 0 and 
$valor_afp5  
c.sysEnabled = 1 and c.sysAuthorized = 1 
group by 
a.codFixedDiscount 
order by 
b.fldName;");
$total_patronal = 0;
while ($row = mysqli_fetch_array($resultpat)) {
	//printf("<tr BGCOLOR='#ffcccc'><td colspan='13'>&nbsp;</td>");//espacio
	printf("<tr BGCOLOR='#ffcccc'><td colspan='$nro_col'><b>%s</b></td>", $row['aporte']);//aporte
	printf("<td align='right'><b>%s</b></td>", number_format($row['monto'],$n_decimales));//monto
	printf("<td colspan='$nro_cola'>&nbsp;</td></tr>");//espacio
	$total_patronal = $total_patronal + $row['monto'];
}
mysqli_free_result($resultpat);
//printf("<tr BGCOLOR='#ffcccc'><td colspan='13'>&nbsp;</td>");//espacio
printf("<tr BGCOLOR='#ffcccc'><td colspan='$nro_col'><b>Total Patronal</b></td>");//titulo total
printf("<td align='right'><b>%s</b></td>", number_format($total_patronal,$n_decimales));//total aporte patronal
printf("<td colspan='$nro_cola'>&nbsp;</td></tr>");//espacio
?>

<?php if ($pie_planilla == 1) { //if pie 1 ?>
<?php if($cod_afp < 0) { //if 01 ?>
<tr>
<td colspan="8" align="left"><br/><b>Elaborado por: <?php echo $usuario; ?></b><br/>&nbsp;</td>
<td colspan="7" align="left"><br/><b><?php echo $firma_contabilidad; ?></b><br/>&nbsp;</td>
<td colspan="7" align="left"><br/><b><?php echo $firma_gerencia; ?></b><br/>&nbsp;</td>
</tr>
<?php } //fin if 01 ?>
<?php if($cod_afp == 1) { //if 11 ?>
<tr>
<td colspan="6" align="left"><br/><b>Elaborado por: <?php echo $usuario; ?></b><br/>&nbsp;</td>
<td colspan="5" align="left"><br/><b><?php echo $firma_contabilidad; ?></b><br/>&nbsp;</td>
<td colspan="5" align="left"><br/><b><?php echo $firma_gerencia; ?></b><br/>&nbsp;</td>
</tr>
<?php } //fin if 11 ?>
<?php if($cod_afp == 2) { //if 21 ?>
<tr>
<td colspan="8" align="left"><br/><b>Elaborado por: <?php echo $usuario; ?></b><br/>&nbsp;</td>
<td colspan="8" align="left"><br/><b><?php echo $firma_contabilidad; ?></b><br/>&nbsp;</td>
<td colspan="7" align="left"><br/><b><?php echo $firma_gerencia; ?></b><br/>&nbsp;</td>
</tr>
<?php } //fin if 21 ?>
<?php } //fin if pie 1 ?>
</tbody>
</table>

<?php	
}// fin if mostrar 1



//retroactivo

$suma_dic = 0;
$suma_actual = 0;
$suma_basico_ene = 0;
$suma_ant_ene = 0;
$suma_basico_feb = 0;
$suma_ant_feb = 0;
$suma_basico_mar = 0;
$suma_ant_mar = 0;
$suma_basico_abr = 0;
$suma_ant_abr = 0;
$suma_otros_retro = 0;
$suma_total_retro = 0;
$suma_afp_desc = 0;
$suma_iva_desc = 0;
$suma_otros_desc = 0;
$suma_total_desc = 0;
$suma_liq_pagable = 0;
//planilla de retroactivo
$resultretro = mysqli_query($link, "select $valor_afp1 a.pkySalaryReimbursement as cod_retro, a.fldDate as fecha, a.fldInitMonth as mes_ini, a.fldEndMonth as mes_fin, a.fldIsBasicPercent as basico_porcentaje, a.fldIsSeniorityPercent as antiguedad_porcentaje, a.fldIsProductionPercent as produccion_porcentaje, b.codEmployee as cod_empleado, b.fldBasicAmount as basico, b.fldSeniorityAmount as antiguedad, b.fldProductionAmount as produccion, b.codEmployeeMovement as cod_mov_emp, c.fldBasicSalary as salario_actual, case when d.fldOtherNames is NULL then case when d.fldMiddleName is NULL then concat(d.fldLastName,', ',d.fldFirstName) else concat(d.fldLastName,' ',d.fldMiddleName,', ',d.fldFirstName) end else case when d.fldMiddleName is NULL then concat(d.fldLastName,', ',d.fldFirstName,' ',d.fldOtherNames) else concat(d.fldLastName,' ',d.fldMiddleName,', ',d.fldFirstName,' ',d.fldOtherNames) end end as empleado, d.fldBirthDate as fecha_nac, d.codGender as cod_sexo, d.codJob as cargo, d.fldHiringDate as fecha_cont, e.codCity as cod_ciu_suc $valor_afp2
from hrsSalaryReimbursement a, hrsSalaryReimbursementDetail b, hrsEmployeeMovement c, agnPerson d, agnCompanyBranch e $valor_afp3
where 
$valor_empleado2 
$valor_genero2 
$valor_ciudad2 
$valor_cargo2 
$valor_sucursal2 
$valor_contexto2 
$valor_afp 
$valor_afp42 
a.pkySalaryReimbursement = b.codSalaryReimbursement and 
b.codEmployeeMovement = c.pkyEmployeeMovement and 
b.codEmployee = d.pkyPerson and 
d.codBranch = e.pkyCompanyBranch and 
a.fldInitMonth >= '$vfechaini' and
a.fldEndMonth <= '$vfechafin' and 
a.sysEnabled = 1 and a.sysAuthorized = 1 
$valor_orden2;");

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

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

$ma_retro = array();
$r = 1;
while ($row = mysqli_fetch_array($resultretro)) {
	$ma_retro [$r][1] = $row['cod_retro'];
	$ma_retro [$r][2] = $row['fecha'];
	$ma_retro [$r][3] = $row['mes_ini'];
	$ma_retro [$r][4] = $row['mes_fin'];
	$ma_retro [$r][5] = $row['basico_porcentaje'];
	$ma_retro [$r][6] = $row['antiguedad_porcentaje'];
	$ma_retro [$r][7] = $row['produccion_porcentaje'];
	$ma_retro [$r][8] = $row['cod_empleado'];
	$ma_retro [$r][9] = $row['basico'];
	$ma_retro [$r][10] = $row['antiguedad'];
	$ma_retro [$r][11] = $row['produccion'];
	$ma_retro [$r][12] = $row['cod_mov_emp'];
	$ma_retro [$r][13] = NULL; //ci
	$ma_retro [$r][14] = NULL; //apellidos y nombres
	$ma_retro [$r][15] = NULL; //sexo
	$ma_retro [$r][16] = NULL; //cargo
	$ma_retro [$r][17] = NULL; //fecha ingreso
	$ma_retro [$r][18] = NULL; //fecha retiro
	$ma_retro [$r][19] = 0; //haber basico diciembre
	$ma_retro [$r][20] = $row['salario_actual'];; //haber basico actual
	$ma_retro [$r][21] = 0; //haber basico enero
	$ma_retro [$r][22] = 0; //antiguedad enero
	$ma_retro [$r][23] = 0; //haber basico febrero
	$ma_retro [$r][24] = 0; //antiguedad febrero
	$ma_retro [$r][25] = 0; //haber basico marzo
	$ma_retro [$r][26] = 0; //antiguedad marzo
	$ma_retro [$r][27] = 0; //haber basico abril
	$ma_retro [$r][28] = 0; //antiguedad abril
	$ma_retro [$r][29] = 0; //otros
	$ma_retro [$r][30] = 0; //total
	$ma_retro [$r][31] = 0; //afp desc
	$ma_retro [$r][32] = 0; //iva desc
	$ma_retro [$r][33] = 0; //otros desc
	$ma_retro [$r][34] = 0; //total desc
	$ma_retro [$r][35] = 0; //liquido pagable
	for($i = 1; $i <= $fin; $i++) {//for i
	if($ma_retro [$r][8] == $matriz_pla [$i][2]) { //if cod
		if($matriz_pla [$i][43] <> NULL) { $ma_retro [$r][13] = $matriz_pla [$i][43]; }//ci
		if($matriz_pla [$i][3] <> NULL) { $ma_retro [$r][14] = $matriz_pla [$i][3]; }//apellidos y nombres
		if($matriz_pla [$i][40] <> NULL) { $ma_retro [$r][15] = $matriz_pla [$i][40]; }//sexo
		if($matriz_pla [$i][6] <> NULL) { $ma_retro [$r][16] = $matriz_pla [$i][6]; }//cargo
		if($matriz_pla [$i][10] <> NULL) { $ma_retro [$r][17] = $matriz_pla [$i][10]; }//fecha ingreso
		if($matriz_pla [$i][59] <> NULL) { $ma_retro [$r][18] = $matriz_pla [$i][59]; }//fecha retiro
		
		if(strtotime($matriz_pla [$i][46]) >= strtotime($vdfechaini) && strtotime($matriz_pla [$i][46]) <= strtotime($vdfechafin)) { $ma_retro [$r][19] = $matriz_pla [$i][18]; }//haber basico diciembre
		
		if(strtotime($matriz_pla [$i][46]) >= strtotime($vefechaini) && strtotime($matriz_pla [$i][46]) <= strtotime($vefechafin)) { 
			if($ma_retro [$r][5] == 1) {
			$ma_retro [$r][21] = $matriz_pla [$i][31]*$ma_retro [$r][9]/100; //haber ganado enero
			$ma_retro [$r][22] = $matriz_pla [$i][30]*$ma_retro [$r][10]/100; //antiguedad enero
			} else {
			$ma_retro [$r][21] = $matriz_pla [$i][31]*$ma_retro [$r][9]/100; //haber ganado enero
			$ma_retro [$r][22] = $matriz_pla [$i][30]+$ma_retro [$r][10]; //antiguedad enero	
			}
		}
		
		if(strtotime($matriz_pla [$i][46]) >= strtotime($vffechaini) && strtotime($matriz_pla [$i][46]) <= strtotime($vffechafin)) { 
			if($ma_retro [$r][5] == 1) {
			$ma_retro [$r][23] = $matriz_pla [$i][31]*$ma_retro [$r][9]/100; //haber ganado febrero
			$ma_retro [$r][24] = $matriz_pla [$i][30]*$ma_retro [$r][10]/100; //antiguedad febrero
			} else {
			$ma_retro [$r][23] = $matriz_pla [$i][31]*$ma_retro [$r][9]/100; //haber ganado febrero
			$ma_retro [$r][24] = $matriz_pla [$i][30]+$ma_retro [$r][10]; //antiguedad feberero	
			}
		}
		
		if(strtotime($matriz_pla [$i][46]) >= strtotime($vmfechaini) && strtotime($matriz_pla [$i][46]) <= strtotime($vmfechafin)) { 
			if($ma_retro [$r][5] == 1) {
			$ma_retro [$r][25] = $matriz_pla [$i][31]*$ma_retro [$r][9]/100; //haber ganado marzo
			$ma_retro [$r][26] = $matriz_pla [$i][30]*$ma_retro [$r][10]/100; //antiguedad marzo
			} else {
			$ma_retro [$r][25] = $matriz_pla [$i][31]*$ma_retro [$r][9]/100; //haber ganado marzo
			$ma_retro [$r][26] = $matriz_pla [$i][30]+$ma_retro [$r][10]; //antiguedad marzo	
			}
		}
		
		if(strtotime($matriz_pla [$i][46]) >= strtotime($vafechaini) && strtotime($matriz_pla [$i][46]) <= strtotime($vafechafin)) { 
			if($ma_retro [$r][5] == 1) {
			$ma_retro [$r][27] = $matriz_pla [$i][31]*$ma_retro [$r][9]/100; //haber ganado abril
			$ma_retro [$r][28] = $matriz_pla [$i][30]*$ma_retro [$r][10]/100; //antiguedad abril
			} else {
			$ma_retro [$r][27] = $matriz_pla [$i][31]*$ma_retro [$r][9]/100; //haber ganado abril
			$ma_retro [$r][28] = $matriz_pla [$i][30]+$ma_retro [$r][10]; //antiguedad abril
			}
		}
		
	}//fin if cod
	}//fin for i
	
	$ma_retro [$r][30] = $ma_retro [$r][21]+$ma_retro [$r][22]+$ma_retro [$r][23]+$ma_retro [$r][24]+$ma_retro [$r][25]+$ma_retro [$r][26]+$ma_retro [$r][27]+$ma_retro [$r][28]+$ma_retro [$r][29];//total
	$ma_retro [$r][31] = $ma_retro [$r][30]*12.71/100;//afp des
	$ma_retro [$r][34] = $ma_retro [$r][31]+$ma_retro [$r][32]+$ma_retro [$r][33];//total desc
	$ma_retro [$r][35] = $ma_retro [$r][30]-$ma_retro [$r][34];//liquido pagable	
	
	$r++;
}
mysqli_free_result($resultretro);
$fin_r = $r - 1;

//retroactivo
//este if es para mostrar con el formato presentacion
if($mostrar == 0 && $planilla == 7) { //mostrar 0

$j = 1;
$nu = 1;
for($i = 1; $i <= $var; $i++) {//for
?>
<?php if($mostrar_logo_reportes_formato == 0) { //if formato 0 ?>
<table border="1" align="center" cellpadding="2" width="1160">
<tr>
	<td width="490"><b>Nombre o Raz&oacute;n Social: </b><?php echo $nombre_empresa; ?></td>
    <td width="490"><b>NIT: </b><?php echo $mi_nit; ?></td>
</tr>
<tr>
	<td width="490"><b>No. Empleador Min. de Trabajo: </b><?php echo $num_min_trabajo; ?></td>
    <td width="490"><b>No. Empleador Caja de Salud: </b><?php echo $num_caja_salud; ?></td>
</tr>
</table>
<table border="0" align="center" cellpadding="2" width="1160">
<tr>
	<td width="300"><?php //echo $usuario; ?></td>
    <td width="390" align="center"><b>PLANILLA DE RETROACTIVO - INCREMENTO SALARIAL GESTI&Oacute;N <?php echo $anoini; ?></b></td>
    <td width="300" align="right"><b>P&aacute;gina: <?php echo $i; ?> de <?php echo $var; ?></b></td>
</tr>
<tr>
	<td width="300">&nbsp;</td>
    <td width="390" align="center">Cifras en Bolivianos</td>
    <!--<td width="300" align="right">CORRESPONDIENTE AL MES DE <?php echo strtoupper($nom_mesini); ?> DE <?php echo $anoini; ?></td>-->
</tr>
</table>
<?php } //fin if formato 0 ?>

<?php if($mostrar_logo_reportes_formato == 1) { //if formato 1 ?>
<table border="1" align="center" cellpadding="2" width="1160">
<tr>
	<td rowspan="2" width="15%"><img src="../../Images/logo.jpg" alt="Logo" width="100" height="40" /></td>
    <td width="490"><b>Nombre o Raz&oacute;n Social: </b><?php echo $nombre_empresa; ?></td>
    <td width="490"><b>NIT: </b><?php echo $mi_nit; ?></td>
</tr>
<tr>
	<td width="490"><b>No. Empleador Min. de Trabajo: </b><?php echo $num_min_trabajo; ?></td>
    <td width="490"><b>No. Empleador Caja de Salud: </b><?php echo $num_caja_salud; ?></td>
</tr>
</table>
<table border="0" align="center" cellpadding="2" width="1160">
<tr>
	<td width="300"><?php //echo $usuario; ?></td>
    <td width="390" align="center"><b>PLANILLA DE RETROACTIVO - INCREMENTO SALARIAL GESTI&Oacute;N <?php echo $anoini; ?></b></td>
    <td width="300" align="right"><b>P&aacute;gina: <?php echo $i; ?> de <?php echo $var; ?></b></td>
</tr>
<tr>
	<td width="300">&nbsp;</td>
    <td width="390" align="center">Cifras en Bolivianos</td>
    <!--<td width="300" align="right">CORRESPONDIENTE AL MES DE <?php echo strtoupper($nom_mesini); ?> DE <?php echo $anoini; ?></td>-->
</tr>
</table>
<?php } //fin if formato 1 ?>

<br />

<table border="1" align="center" cellpadding="2" width="1160" height="600">
	<thead>
    <TR> 
    <TD align="center" width="10" style='border-bottom: solid 1px'><b>No.</b></TD>
    <TD align="center" width="40" style='border-bottom: solid 1px'><b>Docu-<br/>mento de Iden-<br/>tidad</b></TD>
    <TD align="center" width="280" style='border-bottom: solid 1px'><b>Apellidos y Nombres</b></TD>
    <TD align="center" width="20" style='border-bottom: solid 1px'><b>Sexo<br />(F/M)</b></TD>
    <TD align="center" width="120" style='border-bottom: solid 1px'><b>Ocupaci&oacute;n que Desempe&ntilde;a</b></TD>
    <TD align="center" width="50" style='border-bottom: solid 1px'><b>Fecha de Ingreso</b></TD>
    <TD align="center" width="50" style='border-bottom: solid 1px'><b>Fecha de Retiro</b></TD>
    <TD align="center" width="40" style='border-bottom: solid 1px'><b>Haber B&aacute;sico en la Planilla de <?php echo nombreMes($mesinid); ?> <?php echo $anoinid; ?></b></TD>
    <TD align="center" width="40" style='border-bottom: solid 1px'><b>Haber B&aacute;sico con Incremento en la Gesti&oacute;n <?php echo $anoini; ?></b></TD>
    <TD align="center" width="40" style='border-bottom: solid 1px'><b>(1) Monto <?php echo nombreMes($mesini); ?></b></TD>
    <TD align="center" width="40" style='border-bottom: solid 1px'><b>(2) Monto Antig&uuml;edad <?php echo nombreMes($mesini); ?></b></TD>
    <TD align="center" width="40" style='border-bottom: solid 1px'><b>(3) Monto <?php echo nombreMes($mesinif); ?></b></TD>
    <TD align="center" width="40" style='border-bottom: solid 1px'><b>(4) Monto Antig&uuml;edad <?php echo nombreMes($mesinif); ?></b></TD>
    <TD align="center" width="40" style='border-bottom: solid 1px'><b>(5) Monto <?php echo nombreMes($mesinim); ?></b></TD>
    <TD align="center" width="40" style='border-bottom: solid 1px'><b>(6) Monto Antig&uuml;edad <?php echo nombreMes($mesinim); ?></b></TD>
    <TD align="center" width="40" style='border-bottom: solid 1px'><b>(7) Monto <?php echo nombreMes($mesinia); ?></b></TD>
    <TD align="center" width="40" style='border-bottom: solid 1px'><b>(8) Monto Antig&uuml;edad <?php echo nombreMes($mesinia); ?></b></TD>
    <TD align="center" width="40" style='border-bottom: solid 1px'><b>(9) Otros</b></TD>
    <TD align="center" width="40" style='border-bottom: solid 1px'><b>(10) Total Retroactivo Suma<br/>(1 a 9)</b></TD>
    <TD align="center" width="40" style='border-bottom: solid 1px'><b>(11) Desc. AFPs 12.71%</b></TD>
    <TD align="center" width="40" style='border-bottom: solid 1px'><b>(12) Desc. RC-IVA 13%</b></TD>
    <TD align="center" width="40" style='border-bottom: solid 1px'><b>(13) Otros Desc.</b></TD>
    <TD align="center" width="40" style='border-bottom: solid 1px'><b>(14) Total Desc. Suma<br/>(11 a 13)</b></TD>
    <TD align="center" width="40" style='border-bottom: solid 1px'><b>(15) L&iacute;quido Pagable (10 - 14)</b></TD>
    <TD align="center" width="120" style='border-bottom: solid 1px'><b>Firma</b></TD>
    </TR>
	</thead>
    <tbody class="marcafila">
<?php
$color = 2;
$q = 1;//
  while ($q <= $filas_por_pagina) { //while
  
  if($ma_retro [$j][13] == NULL && $ma_retro [$j][14] == NULL && $numero_filas != 0) { //if controla filtros, ci y nombre
  $j++;
  }
  
  if($numero_filas == 0) {//if filas
	printf("<tr><td align='center' style='border-bottom: solid 1px'>%s</td>", $ma_retro [$j][2]);//fecha
  } else { //else filas
    if($color % 2 == 0) { //if color
		if($ma_retro [$j][2] != NULL) {
		printf("<tr BGCOLOR='#e2e7fa'><td align='center' style='border-bottom: solid 1px'>%s</td>", $nu);//numero
		} else { 
		printf("<tr BGCOLOR='#e2e7fa'><td align='center' style='border-bottom: solid 1px'><hr /></td>");//numero vacio
		}
	} else {
		if($ma_retro [$j][2] != NULL) {
		printf("<tr><td align='center' style='border-bottom: solid 1px'>%s</td>", $nu);//numero
		} else { 
		printf("<tr><td align='center' style='border-bottom: solid 1px'><hr /></td>");//numero vacio
		}
	}//fin if color
  }//fin filas
    
	
	if($ma_retro [$j][2] != NULL) {//if no hay
	
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", $ma_retro [$j][13]);//ci
	$texto = $ma_retro [$j][14];//empleado
	$texto = strtr(strtoupper($texto), "àáâãäåæçèéêëìíîïðñòóôõöøùüú", "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÜÚ");
	$texto = substr($texto,0,150);
	printf("<td align='left' style='border-bottom: solid 1px'>%s</td>", $texto);//empleado
	if($ma_retro [$j][15] == 1) {//if sexo
		printf("<td align='center' style='border-bottom: solid 1px'>M</td>");//M
	} else {
		printf("<td align='center' style='border-bottom: solid 1px'>F</td>");//F
	}//fin if sexo
	printf("<td align='left' style='border-bottom: solid 1px'>%s</td>", $ma_retro [$j][16]);//cargo
	if($ma_retro [$j][17] <> NULL) {
	printf("<td align='center' style='border-bottom: solid 1px'>%s</td>", cambiarFormatoFechaBarra($ma_retro [$j][17]));//fecha ingreso
	} else {
	printf("<td align='center' style='border-bottom: solid 1px'>%s</td>", $ma_retro [$j][17]);//fecha ingreso	
	}
	if($ma_retro [$j][18] <> NULL) {
	printf("<td align='center' style='border-bottom: solid 1px'>%s</td>", cambiarFormatoFechaBarra($ma_retro [$j][18]));//fecha retiro
	} else {
	printf("<td align='center' style='border-bottom: solid 1px'>%s</td>", $ma_retro [$j][18]);//fecha retiro	
	}
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($ma_retro [$j][19],$n_decimales));//haber basico diciembre
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($ma_retro [$j][20],$n_decimales));//haber basico actual
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($ma_retro [$j][21],$n_decimales));//haber basico enero
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($ma_retro [$j][22],$n_decimales));//antiguedad enero
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($ma_retro [$j][23],$n_decimales));//haber basico febrero
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($ma_retro [$j][24],$n_decimales));//antiguedad febrero
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($ma_retro [$j][25],$n_decimales));//haber basico marzo
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($ma_retro [$j][26],$n_decimales));//antiguedad marzo
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($ma_retro [$j][27],$n_decimales));//haber basico abril
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($ma_retro [$j][28],$n_decimales));//antiguedad abril
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($ma_retro [$j][29],$n_decimales));//otros
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($ma_retro [$j][30],$n_decimales));//total retroactivo
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($ma_retro [$j][31],$n_decimales));//afp desc
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($ma_retro [$j][32],$n_decimales));//iva desc
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($ma_retro [$j][33],$n_decimales));//otros desc
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($ma_retro [$j][34],$n_decimales));//total desc
	printf("<td align='right' style='border-bottom: solid 1px'>%s</td>", number_format($ma_retro [$j][35],$n_decimales));//liquido pagable
	printf("<td style='border-bottom: solid 1px'>&nbsp;</td></tr>");//firma
	
	$suma_dic = $suma_dic+$ma_retro [$j][19];
	$suma_actual = $suma_actual+$ma_retro [$j][20];
	$suma_basico_ene = $suma_basico_ene+$ma_retro [$j][21];
	$suma_ant_ene = $suma_ant_ene+$ma_retro [$j][22];
	$suma_basico_feb = $suma_basico_feb+$ma_retro [$j][23];
	$suma_ant_feb = $suma_ant_feb+$ma_retro [$j][24];
	$suma_basico_mar = $suma_basico_mar+$ma_retro [$j][25];
	$suma_ant_mar = $suma_ant_mar+$ma_retro [$j][26];
	$suma_basico_abr = $suma_basico_abr+$ma_retro [$j][27];
	$suma_ant_abr = $suma_ant_abr+$ma_retro [$j][28];
	$suma_otros_retro = $suma_otros_retro+$ma_retro [$j][29];
	$suma_total_retro = $suma_total_retro+$ma_retro [$j][30];
	$suma_afp_desc = $suma_afp_desc+$ma_retro [$j][31];
	$suma_iva_desc = $suma_iva_desc+$ma_retro [$j][32];
	$suma_otros_desc = $suma_otros_desc+$ma_retro [$j][33];
	$suma_total_desc = $suma_total_desc+$ma_retro [$j][34];
	$suma_liq_pagable = $suma_liq_pagable+$ma_retro [$j][35];
		
	} else { //else if no hay
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//ci
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//empleado
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//sexo
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//cargo
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//fecha ingreso
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//fecha retiro
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//haber basico diciembre
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//haber basico actual
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//haber basico enero
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//antiguedad enero
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//haber basico febrero
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//antiguedad febrero
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//haber basico marzo
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//antiguedad marzo
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//haber basico abril
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//antiguedad abril
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//otros
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//total retroactivo
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//afp descuentos
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//iva descuentos
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//otros descuentos
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//total descuentos
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td>");//liquido pagable
	printf("<td align='center' style='border-bottom: solid 1px'><hr /></td></tr>");//firma
	}//fin if no hay
	
	if($numero_filas == 0 && $j == 7) {
		printf("<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td align='center' colspan='10'><font size='16'><b>SIN MOVIMIENTO</b></font></td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>");
	}
	$color++;
	$nu++;
	$q++; 
    $j++;
  
  }//fin while


?>


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

<!--

<table border="0" align="center" height="100"><tr><td>&nbsp;</td></tr></table>
-->
</div>
<?php
}//fin if $i
}//fin for
?>
<tr>
    <td colspan="7" style='border-top: solid 1px; border-bottom: solid 1px' align="right"><b>TOTALES</b></td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($suma_dic,$n_decimales); ?></td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($suma_actual,$n_decimales); ?></td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($suma_basico_ene,$n_decimales); ?></td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($suma_ant_ene,$n_decimales); ?></td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($suma_basico_feb,$n_decimales); ?></td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($suma_ant_feb,$n_decimales); ?></td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($suma_basico_mar,$n_decimales); ?></td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($suma_ant_mar,$n_decimales); ?></td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($suma_basico_abr,$n_decimales); ?></td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($suma_ant_abr,$n_decimales); ?></td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($suma_otros_retro,$n_decimales); ?></td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($suma_total_retro,$n_decimales); ?></td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($suma_afp_desc,$n_decimales); ?></td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($suma_iva_desc,$n_decimales); ?></td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($suma_otros_desc,$n_decimales); ?></td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($suma_total_desc,$n_decimales); ?></td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b><?php echo number_format($suma_liq_pagable,$n_decimales); ?></td>
    <td align="right" style='border-top: solid 1px; border-bottom: solid 1px'><b>&nbsp;</td>
</tr>
<?php if ($pie_planilla == 1) { //if pie 1 ?>
<tr>
<td colspan="8" align="left"><br/><b>Elaborado por: <?php echo $usuario; ?></b><br/>&nbsp;</td>
<td colspan="9" align="left"><br/><b><?php echo $firma_contabilidad; ?></b><br/>&nbsp;</td>
<td colspan="8" align="left"><br/><b><?php echo $firma_gerencia; ?></b><br/>&nbsp;</td>
</tr>
<?php } //fin if pie 1 ?>
<?php if ($pie_planilla == 0) { //if pie 0 ?>
<tr>
<td colspan="8" align="center"><br/><b><?php echo strtr(strtoupper($nombre_responsable), "àáâãäåæçèéêëìíîïðñòóôõöøùüú", "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÜÚ"); ?><br/>Nombre del Empleador o Representante Legal</b></td>
<td colspan="6" align="center"><br/><b><?php echo $ci_responsable; ?><br/>No. de Documento de Identidad</b></td>
<td colspan="6" align="center"><br/><b><u>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</u><br/>Firma</b></td>
<td colspan="4" align="center"><br/><b><u>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</u><br/>Fecha</b></td>
</tr>
<?php } //fin if pie 0 ?>
</tbody>
</table>
<?php
}// fin if mostrar 0


//retroactivo
//este if es para mostrar con el formato reporte
if($mostrar == 1 && $planilla == 7) { //mostrar 1

?>
<table border="0" align="left" width="100%" cellpadding="5">
<tr><td><?php echo $mostrar_logo_reportes; ?>
</td><td align="right"><b>Fecha: <?php echo date("Y-m-d"); ?><br/>Hora: <?php echo date("H:i:s"); ?><br/>Usuario: <?php echo $usuario; ?></b>
</td></tr></table>
<p><br /><center><font color="#000099" size="+1"><b>Reporte Planilla de Retroactivo - Incremento Salarial <?php echo $anoini; ?></b></font></center></p>
<table border="0" cellpadding="2" align="center" width="100%">
<tr>
<td>	
    <table border="1" align="center" cellpadding="2" width="100%">
        <TR> 
        <TD width="33%"><b>Planilla: </b><?php echo $nom_planilla; ?></TD>
        <TD width="33%"><b>Sucursal: </b><?php echo $nom_sucursal; ?></TD>
        <TD width="33%"><b>Ciudad de la(s) Sucursal(es): </b><?php echo $nom_ciudad; ?></TD>
        </TR>
        <TR> 
        <TD><b>Empleado: </b><?php echo $nom_empleado; ?></TD>
        <TD><b>Genero: </b><?php echo $nom_genero; ?></TD>
        <TD><b>Cargo: </b><?php echo $nom_cargo; ?></TD>
        </TR>
        <TR>
        <TD><b>Mes A&ntilde;o Inicial: </b><?php echo $nom_mesini; ?> de <?php echo $anoini; ?></TD>
        <TD><b>Mes A&ntilde;o Final: </b><?php echo $nom_mesfin; ?> de <?php echo $anofin; ?></TD>
        <TD><b>Ordenado por: </b><?php echo $nom_orden; ?></TD>
        </TR>
        <TR>
        <TD><b>AFP: </b><?php echo $nom_afp; ?></TD>
        <TD><b>Contexto: </b><?php echo $nom_contexto; ?></TD>
        <TD><b>Expresado en: </b><?php echo $nom_moneda_principal; ?></TD>
        </TR>
    </table>

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

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

<table border="1" align="center" cellpadding="2" width="100%">
 	<thead>
    <TR> 
    <TD align="center"><b>No.</b></TD>
    <TD align="center"><b>Documento de Identidad</b></TD>
    <TD align="center"><b>Apellidos y Nombres</b></TD>
    <TD align="center"><b>Sexo<br />(F/M)</b></TD>
    <TD align="center"><b>Ocupaci&oacute;n que Desempe&ntilde;a</b></TD>
    <TD align="center"><b>Fecha de Ingreso</b></TD>
    <TD align="center"><b>Fecha de Retiro</b></TD>
    <TD align="center"><b>Haber B&aacute;sico en la Planilla de <?php echo nombreMes($mesinid); ?> <?php echo $anoinid; ?></b></TD>
    <TD align="center"><b>Haber B&aacute;sico con Incremento en la Gesti&oacute;n <?php echo $anoini; ?></b></TD>
    <TD align="center"><b>(1) Monto <?php echo nombreMes($mesini); ?></b></TD>
    <TD align="center"><b>(2) Monto Antig&uuml;edad <?php echo nombreMes($mesini); ?></b></TD>
    <TD align="center"><b>(3) Monto <?php echo nombreMes($mesinif); ?></b></TD>
    <TD align="center"><b>(4) Monto Antig&uuml;edad <?php echo nombreMes($mesinif); ?></b></TD>
    <TD align="center"><b>(5) Monto <?php echo nombreMes($mesinim); ?></b></TD>
    <TD align="center"><b>(6) Monto Antig&uuml;edad <?php echo nombreMes($mesinim); ?></b></TD>
    <TD align="center"><b>(7) Monto <?php echo nombreMes($mesinia); ?></b></TD>
    <TD align="center"><b>(8) Monto Antig&uuml;edad <?php echo nombreMes($mesinia); ?></b></TD>
    <TD align="center"><b>(9) Otros</b></TD>
    <TD align="center"><b>(10) Total Retroactivo Suma<br/>(1 a 9)</b></TD>
    <TD align="center"><b>(11) Desc. AFPs 12.71%</b></TD>
    <TD align="center"><b>(12) Desc. RC-IVA 13%</b></TD>
    <TD align="center"><b>(13) Otros Desc.</b></TD>
    <TD align="center"><b>(14) Total Desc. Suma<br/>(11 a 13)</b></TD>
    <TD align="center"><b>(15) L&iacute;quido Pagable (10 - 14)</b></TD>
    <TD align="center"><b>Firma</b></TD>
    </TR>
    </thead>
    <tbody class="marcafila">

<?php
$color = 2;
$j = 1;
$nu = 1;


	while ($j <= $fin_r) { //while

	if($ma_retro [$j][13] <> NULL && $ma_retro [$j][14] <> NULL) { //if controla filtros, ci y nombre
    
	if($color % 2 == 0) { //if color
	printf("<tr BGCOLOR='#e2e7fa'><td align='center'>%s</td>", $nu);//numero
	} else {
	printf("<tr><td align='center'>%s</td>", $nu);//numero
	}//fin if color
    
	printf("<td align='right'>%s</td>", $ma_retro [$j][13]);//ci
	$texto = $ma_retro [$j][14];//empleado
	$texto = strtr(strtoupper($texto), "àáâãäåæçèéêëìíîïðñòóôõöøùüú", "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÜÚ");
	$texto = substr($texto,0,150);
	printf("<td align='left'>%s</td>", $texto);//empleado
	if($ma_retro [$j][15] == 1) {//if sexo
		printf("<td align='center'>M</td>");//M
	} else {
		printf("<td align='center'>F</td>");//F
	}//fin if sexo
	printf("<td align='left'>%s</td>", $ma_retro [$j][16]);//cargo
	if($ma_retro [$j][17] <> NULL) {
	printf("<td align='center'>%s</td>", cambiarFormatoFechaBarra($ma_retro [$j][17]));//fecha ingreso
	} else {
	printf("<td align='center'>%s</td>", $ma_retro [$j][17]);//fecha ingreso	
	}
	if($ma_retro [$j][18] <> NULL) {
	printf("<td align='center'>%s</td>", cambiarFormatoFechaBarra($ma_retro [$j][18]));//fecha retiro
	} else {
	printf("<td align='center'>%s</td>", $ma_retro [$j][18]);//fecha retiro	
	}
	printf("<td align='right'>%s</td>", number_format($ma_retro [$j][19],$n_decimales));//haber basico diciembre
	printf("<td align='right'>%s</td>", number_format($ma_retro [$j][20],$n_decimales));//haber basico actual
	printf("<td align='right'>%s</td>", number_format($ma_retro [$j][21],$n_decimales));//haber basico enero
	printf("<td align='right'>%s</td>", number_format($ma_retro [$j][22],$n_decimales));//antiguedad enero
	printf("<td align='right'>%s</td>", number_format($ma_retro [$j][23],$n_decimales));//haber basico febrero
	printf("<td align='right'>%s</td>", number_format($ma_retro [$j][24],$n_decimales));//antiguedad febrero
	printf("<td align='right'>%s</td>", number_format($ma_retro [$j][25],$n_decimales));//haber basico marzo
	printf("<td align='right'>%s</td>", number_format($ma_retro [$j][26],$n_decimales));//antiguedad marzo
	printf("<td align='right'>%s</td>", number_format($ma_retro [$j][27],$n_decimales));//haber basico abril
	printf("<td align='right'>%s</td>", number_format($ma_retro [$j][28],$n_decimales));//antiguedad abril
	printf("<td align='right'>%s</td>", number_format($ma_retro [$j][29],$n_decimales));//otros
	printf("<td align='right'>%s</td>", number_format($ma_retro [$j][30],$n_decimales));//total retroactivo
	printf("<td align='right'>%s</td>", number_format($ma_retro [$j][31],$n_decimales));//afp desc
	printf("<td align='right'>%s</td>", number_format($ma_retro [$j][32],$n_decimales));//iva desc
	printf("<td align='right'>%s</td>", number_format($ma_retro [$j][33],$n_decimales));//otros desc
	printf("<td align='right'>%s</td>", number_format($ma_retro [$j][34],$n_decimales));//total desc
	printf("<td align='right'>%s</td>", number_format($ma_retro [$j][35],$n_decimales));//liquido pagable
	printf("<td>&nbsp;</td></tr>");//firma
	
	$suma_dic = $suma_dic+$ma_retro [$j][19];
	$suma_actual = $suma_actual+$ma_retro [$j][20];
	$suma_basico_ene = $suma_basico_ene+$ma_retro [$j][21];
	$suma_ant_ene = $suma_ant_ene+$ma_retro [$j][22];
	$suma_basico_feb = $suma_basico_feb+$ma_retro [$j][23];
	$suma_ant_feb = $suma_ant_feb+$ma_retro [$j][24];
	$suma_basico_mar = $suma_basico_mar+$ma_retro [$j][25];
	$suma_ant_mar = $suma_ant_mar+$ma_retro [$j][26];
	$suma_basico_abr = $suma_basico_abr+$ma_retro [$j][27];
	$suma_ant_abr = $suma_ant_abr+$ma_retro [$j][28];
	$suma_otros_retro = $suma_otros_retro+$ma_retro [$j][29];
	$suma_total_retro = $suma_total_retro+$ma_retro [$j][30];
	$suma_afp_desc = $suma_afp_desc+$ma_retro [$j][31];
	$suma_iva_desc = $suma_iva_desc+$ma_retro [$j][32];
	$suma_otros_desc = $suma_otros_desc+$ma_retro [$j][33];
	$suma_total_desc = $suma_total_desc+$ma_retro [$j][34];
	$suma_liq_pagable = $suma_liq_pagable+$ma_retro [$j][35];
	
	$nu++;
	$color++;
	
	}//fin if controla filtros, ci y nombre
	
	$j++;
  
	} //fin while
?>
 
<tr BGCOLOR='#ffcccc'>
	<td colspan="7" align="right"><b>Totales</b></td>
    <td align="right"><b><?php echo number_format($suma_dic,$n_decimales); ?></td>
    <td align="right"><b><?php echo number_format($suma_actual,$n_decimales); ?></td>
    <td align="right"><b><?php echo number_format($suma_basico_ene,$n_decimales); ?></td>
    <td align="right"><b><?php echo number_format($suma_ant_ene,$n_decimales); ?></td>
    <td align="right"><b><?php echo number_format($suma_basico_feb,$n_decimales); ?></td>
    <td align="right"><b><?php echo number_format($suma_ant_feb,$n_decimales); ?></td>
    <td align="right"><b><?php echo number_format($suma_basico_mar,$n_decimales); ?></td>
    <td align="right"><b><?php echo number_format($suma_ant_mar,$n_decimales); ?></td>
    <td align="right"><b><?php echo number_format($suma_basico_abr,$n_decimales); ?></td>
    <td align="right"><b><?php echo number_format($suma_ant_abr,$n_decimales); ?></td>
    <td align="right"><b><?php echo number_format($suma_otros_retro,$n_decimales); ?></td>
    <td align="right"><b><?php echo number_format($suma_total_retro,$n_decimales); ?></td>
    <td align="right"><b><?php echo number_format($suma_afp_desc,$n_decimales); ?></td>
    <td align="right"><b><?php echo number_format($suma_iva_desc,$n_decimales); ?></td>
    <td align="right"><b><?php echo number_format($suma_otros_desc,$n_decimales); ?></td>
    <td align="right"><b><?php echo number_format($suma_total_desc,$n_decimales); ?></td>
    <td align="right"><b><?php echo number_format($suma_liq_pagable,$n_decimales); ?></td>
    <td align="right"><b>&nbsp;</td>
</tr>
<?php if ($pie_planilla == 1) { //if pie 1 ?>
<tr>
<td colspan="8" align="left"><br/><b>Elaborado por: <?php echo $usuario; ?></b><br/>&nbsp;</td>
<td colspan="9" align="left"><br/><b><?php echo $firma_contabilidad; ?></b><br/>&nbsp;</td>
<td colspan="8" align="left"><br/><b><?php echo $firma_gerencia; ?></b><br/>&nbsp;</td>
</tr>
<?php } //fin if pie 1 ?>
</tbody>
</table>

<?php	
}// fin if mostrar 1


} //fin if 2


//detalle bono o descuento

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


	//nombre de empleado
	$resultemp = mysqli_query($link, "select pkyPerson as codigo, case when fldOtherNames is NULL then case when fldMiddleName is NULL then concat(fldLastName,', ',fldFirstName) else concat(fldLastName,' ',fldMiddleName,', ',fldFirstName) end else case when fldMiddleName is NULL then concat(fldLastName,', ',fldFirstName,' ',fldOtherNames) else concat(fldLastName,' ',fldMiddleName,', ',fldFirstName,' ',fldOtherNames) end end as  empleado, codGender as genero
				from agnPerson
				where
				pkyPerson = '$empleado_det' and 
				sysEnabled = 1 and sysAuthorized = 1;");
	while ($row = mysqli_fetch_array($resultemp)) {
	$nom_empleado_det = $row['codigo'].' - '.$row['empleado'];
		if($row['genero'] == 1) {
			$nom_genero_det = 'Masculino';
		} else {
			$nom_genero_det = 'Femenino';
		}
	}
	mysqli_free_result($resultemp);



	//nombre cargo
	$result5 = mysqli_query($link, "select pkyJob as cod_cargo, fldName as cargo
							from 
							hrsJob
							where
							pkyJob = '$cargo_det' and 
							sysEnabled = 1 and sysAuthorized = 1;");
	while ($row = mysqli_fetch_array($result5)) {
		$nom_cargo_det = $row['cargo'];
	}
	mysqli_free_result($result5);


	//nombre sucursal
	$result4 = mysqli_query($link, "select a.pkyCompanyBranch as cod_suc, a.fldName as suc, a.fldID as id, b.fldName as ciudad
							from 
							agnCompanyBranch a, regCity b 
							where 
							a.pkyCompanyBranch = '$sucursal_det' and 
							a.codCompany = 2 and 
							a.codCity = b.pkyCity and 
							a.sysEnabled = 1 and a.sysAuthorized = 1;");
	while ($row = mysqli_fetch_array($result4)) {
		$nom_sucursal_det = $row['suc'].' - '.$row['id'].' - '.$row['ciudad'];
	}
	mysqli_free_result($result4);


//bono o descuento
if($bono_det == 0) {
	$nom_bono_det = 'Bonos';
} else {
	$nom_bono_det = 'Descuentos';
}

$nom_periodo_det = substr($periodo_det, 0, -3);

$vfechaini_det =  $nom_periodo_det.'-01';
$vfechafin_det =  $nom_periodo_det.'-31';


//detalle bono o descuento
$resultdet = mysqli_query($link, "select a.pkyBonusDiscount as cod_bondes, a.fldDocumentNumber as nro_doc, a.fldDate as fecha, a.fldPeriod as periodo, b.codEmployee as cod_empleado, b.codConcept as cod_conceptobd, c.fldName as bono_descuento, b.fldAmount as monto
from hrsBonusDiscount a, hrsBonusDiscountDetail b, hrsBonusDiscountConcept c
where 
a.pkyBonusDiscount = b.codBonusDiscount and 
b.codConcept = c.pkyBonusDiscountConcept and 
c.fldIsDiscount = '$bono_det' and 
b.codEmployee = '$empleado_det' and 
a.fldDate >= '$vfechaini_det' and 
a.fldDate <= '$vfechafin_det' and 
a.sysEnabled = 1 and a.sysAuthorized = 1
order by c.fldName, a.fldDate, b.fldAmount;");

?>
<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_det; ?></b>
</td></tr></table>
<p><br /><center><font color="#000099" size="+1"><b>Detalle <?php echo $nom_bono_det; ?></b></font></center></p>
<table border="0" cellpadding="2" align="center" width="100%">
<tr>
<td>	
    <table border="1" align="center" cellpadding="2" width="100%">
        <TR> 
        <TD width="33%"><b>Empleado: </b><?php echo $nom_empleado_det; ?></TD>
        <TD width="33%"><b>G&eacute;nero: </b><?php echo $nom_genero_det; ?></TD>
        <TD width="33%"><b>Cargo: </b><?php echo $nom_cargo_det; ?></TD>
        </TR>
        <TR> 
        <TD><b>Periodo: </b><?php echo $nom_periodo_det; ?></TD>
        <TD><b>Sucursal: </b><?php echo $nom_sucursal_det; ?></TD>
        <TD><b>Expresado en: </b><?php echo $nom_moneda_principal; ?></TD>
        </TR>
    </table>

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

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

    <?php
	$suma_total = 0;
	$color = 2;
	while ($row = mysqli_fetch_array($resultdet)) { //while
		if($color % 2 == 0) { //if color
		printf("<tr BGCOLOR='#e2e7fa'><td align='center'>%s</td>", $row['cod_conceptobd']);//cod
		} else {
		printf("<tr><td align='center'>%s</td>", $row['cod_conceptobd']);//cod
		}//fin if color
		printf("<td align='left'>%s</td>", $row['bono_descuento']);//nombre
		printf("<td align='right'>%s</td></tr>", number_format($row['monto'],$n_decimales));//monto
		 $suma_total = $suma_total + $row['monto'];
		 $color++;
	}//fin while

?>
<tr BGCOLOR='#ffcccc'><td colspan="2"><b>Total</b></td>
<td align="right"><?php printf("<b>%s</b>", number_format($suma_total,$n_decimales)); ?></td>
</tr>
</tbody>
</table>
<?php

} //fin if 3

?>

</body>
</html>
