<?php
include_once("../../../php/sessionStart.php"); 
include_once("../../../php/db/dbExec.php");
include_once('../../../php/functions.php');
include_once("../../../php/fpdf/functions.php");
include_once('../../../php/maxExecTime.php');

global $empCod, $usuNom, $bitMod, $bitForm, $selBan, $dtFec, $numNum, $Banctab, $Banctac, $txtCodp, $txtNomp;

$empCod=utf8_decode($_SESSION["empCod"]);
$empNom=utf8_decode($_SESSION["empNom"]);
$usuCod = utf8_decode($_SESSION['usuCod']);
$usuNom = utf8_decode($_SESSION['usuNom']);

$numNum=$_GET["numNum"];
$selBan=$_GET["selBan"];
$Banctab=$_GET["Banctab"];
$Banctac=$_GET["Banctac"];
$dtFec=$_GET["dtFec"];

# QUERYS
$sNomper = "SELECT np.*, TRIM(mae.mae_nom) AS mae_nom, TRIM(mae.mae_ape) AS mae_ape,
            TRIM(mae.mae_nomch) AS mae_nomch, TRIM(mae.mae_ctab) AS mae_ctab, TRIM(tpu.tpu_nom) AS tpu_nom 
            FROM nomper np
            LEFT JOIN maestro mae ON np.np_emp=mae.mae_emp AND np.np_cod = mae.mae_cod 
            LEFT JOIN tpuesto tpu ON mae.mae_tpue = tpu.tpu_cod 
            WHERE np_emp='$empCod' AND np_numpla='$numNum' AND mae_fpago<3";

# EJECUCION DE QUERYS
$db = new dbExec();
$carpeta = '/Acreditaciones';
if (!file_exists($carpeta)) {
    mkdir($carpeta, 0777, true);
}


$tc=",";

$filenom = fopen("/Acreditaciones/Acredita.txt", "w+");

# CREA EL CICLO PARA EL LISTADO
$item=1;

$select["nomper"] = $db->query($sNomper);
$totpag=0;

while ($rec = $db->fetchAssoc($select["nomper"])) {
    $t1= $rec["mae_ctab"];
    $t2= trim($rec["mae_nomch"]);
    $t3= $rec["np_liqrec"];

    $t_fila = (string)($t1).$tc.(string)$t2.$tc.$t3;

    fwrite($filenom, $t_fila . PHP_EOL);

    $item += 1;
}
$db->close();

fclose($filenom);

$texto = file_get_contents("/Acreditaciones/Acredita.txt"); 
$texto = nl2br(utf8_encode($texto)); 
echo $texto;
exit;
?>