<?php

//=====================================================================================================
//=====>	INICIO_H
include_once "../core/go.login.inc.php";
include_once "../core/core.error.inc.php";
include_once "../core/core.html.inc.php";
include_once "../core/core.init.inc.php";
$theFile = __FILE__;
$permiso = getSIPAKALPermissions($theFile);
if ($permiso === false) {
    header("location:../404.php?i=999");
}
$_SESSION["current_file"] = addslashes($theFile);
//<=====	FIN_H
//=====================================================================================================
$xInit = new cHPage("", HP_SERVICE);
$txt = "";
$recibo = parametro("recibo", false, MQL_INT);
$rs = array("error" => true);
$recibo = setNoMenorQueCero($recibo);
if ($recibo > 0) {
    $xPol = new cPoliza(false);
    if ($xPol->setPorRecibo($recibo) == true) {
        $rs = array("codigo" => $xPol->getCodigo(), "codigo_unico" => $xPol->getCodigoUnico());
    }
}
header('Content-type: application/json');
echo json_encode($rs);
 /**
  * Genera las polizas del dia por Cajero
  * @param date $fecha
  */
 function setGenerarPolizasAlCierre($fecha = false)
 {
     $xLi = new cSQLListas();
     $ql = new MQL();
     $msg = "";
     $otros = " AND (`operaciones_recibostipo`.`tipo_poliza_generada` != 999) AND `operaciones_recibos`.`total_operacion` > 0 ";
     $sql = $xLi->getListadoDeRecibos("", "", "", $fecha, $fecha, $otros);
     $rs = $ql->getDataRecord($sql);
     foreach ($rs as $rw) {
         $recibo = $rw["numero"];
         $xPol = new cPoliza(false);
         if ($xPol->setPorRecibo($recibo) == true) {
             $msg .= "WARN\tLa Poliza del recibo {$recibo} Existe con el ID " . $xPol->getCodigoUnico() . "\r\n";
         } else {
             $msg .= $this->setRegenerarPrepolizaContable($fecha, $recibo);
             $msg .= $this->setPolizaPorRecibo($recibo, true);
             if ($xPol->setPorRecibo($recibo) == false) {
                 $msg .= "ERROR\tAl generar la Poliza del recibo {$recibo}\r\n";
             }
         }
         $msg .= $xPol->getMessages();
     }
     $this->mMessages .= $msg;
     return $msg;
 }
function jsaSetGenerarPolizaPorRecibo($numero)
{
    if (setNoMenorQueCero($numero) > 0) {
        $Recibo = $numero;
        $xPol = new cPoliza(false);
        $idpoliza = "";
        $msg = "";
        if ($xPol->setPorRecibo($numero) == true) {
            $idpoliza = $xPol->getCodigo();
        } else {
            $xUCont = new cUtileriasParaContabilidad();
            $xUCont->setRegenerarPrepolizaContable(false, $Recibo);
            $xUCont->setPolizaPorRecibo($Recibo);
            $idpoliza = $xUCont->getIDPoliza();
            $msg .= $xUCont->getMessages();
        }
        $msg .= $xPol->getMessages();
        //exportar
        $xPolCW = new cPolizaCompacW(0);
        $xPolCW->initByID($idpoliza);
        $xPolCW->setRun();
        $msg .= $xPolCW->getMessages();
        $strDown = $xPolCW->setExport();
        if (MODO_DEBUG == true) {
            $xLog = new cFileLog();
            $xLog->setWrite($msg);
            $strDown .= $xLog->getLinkDownload("TR.Eventos");
        }
        $xBtn = new cHButton();
        return $xBtn->getBasic("TR.Modificar Poliza", "jsModificarPoliza('{$idpoliza}')", $xBtn->ic()->EDITAR, "cmdeditpoliza") . $strDown;
    } else {
        return "NO HAY REGISTRO QUE GENERAR [{$numero}]";
    }
}