function jsaSetDesvincularPersona($credito, $fecha, $observaciones)
{
    $msg = "";
    $xLng = new cLang();
    $xCred = new cCredito($credito);
    $xCred->init();
    $xdat = new cFecha(0);
    $fecha = $xdat->getFechaISO($fecha);
    $xCred->setResetPersonaAsociada($fecha, $observaciones);
    $oP = $xCred->getOPersona();
    $xEmp = new cEmpresas($xCred->getClaveDeEmpresa());
    $xEmp->init();
    $xRN = new cReglaDeNegocio();
    $xRN->setVariables(array("nombre_de_persona" => $oP->getNombreCompleto(), "mensaje" => $observaciones, "saldo_del_credito" => $xCred->getSaldoActual(), "nombre_de_la_empresa" => $xEmp->getNombreCorto()));
    $xRN->setExecuteActions($xRN->reglas()->RN_NOMINA_AL_DESVINCULAR);
    return $xLng->get(MSG_READY_SAVE);
}
 function getFicha($mark = true, $extraTool = "", $extendido = false, $ConPersona = false)
 {
     if ($this->mCreditoInicializado == false) {
         $this->initCredito();
     }
     $lafila = $this->getDatosDeCredito();
     $xL = new cLang();
     $solicitud = $this->getNumeroDeCredito();
     $convenio = $lafila["descripcion_tipoconvenio"];
     $fministracion = $lafila["fecha_ministracion"];
     $fvencimiento = $lafila["fecha_vencimiento"];
     $periocidad_pago = $lafila["descripcion_periocidadpagos"];
     $autorizado = getFMoney($lafila["monto_autorizado"]);
     $saldo = getFMoney($lafila["saldo_actual"]);
     $estatus = $lafila["descripcion_estatus"];
     $tool = $extraTool;
     $tasa = getFMoney($lafila["tasa_interes"] * 100);
     $mora = $lafila["tasa_moratorio"] * 100;
     $pagos = $lafila["pagos_autorizados"];
     $ultimopago = $lafila["ultimo_periodo_afectado"];
     $cls = "";
     $xD = new cFecha(0);
     $TasaIVA = $this->getTasaIVA();
     $TasaMora = $this->getTasaDeMora();
     $trInicial = "";
     $cls = "credito-estado-" . $this->getEstadoActual();
     $montoParc = getFMoney($this->mMontoFijoParcialidad);
     $activo = true;
     if ($ConPersona == true) {
         $xSoc = $this->getOPersona();
         // new cSocio($this->getClaveDePersona(), true);
         $trInicial = "<tr><th>" . $xL->getT("TR.Persona") . "</th><td>" . $xSoc->getCodigo() . "</td><td colspan='2'>" . $xSoc->getNombreCompleto() . "</td></tr>";
     }
     if ($this->getTipoEnSistema() == CREDITO_PRODUCTO_NOMINA) {
         if ($this->getClaveDeEmpresa() != DEFAULT_EMPRESA) {
             $xEmp = new cEmpresas($this->getClaveDeEmpresa());
             $xEmp->init();
             $convenio = "{$convenio} - " . $xEmp->getNombreCorto();
         } else {
             $convenio = "{$convenio} - ND";
         }
     }
     $tdSaldo = "<th class='izq'>" . $xL->getT("TR.Saldo Principal") . "</th><td class='mny'>{$saldo}</td>";
     $tdMonto = "<th class='izq'>" . $xL->getT("TR.Monto Original") . "</th><td class='mny'>{$autorizado}</td>";
     $tdFecha = "<th class='izq'>" . $xL->getT("TR.fecha de desembolso") . "</th><td>" . $xD->getFechaCorta($fministracion) . "</td>";
     $tdPagos = $this->getPeriocidadDePago() != CREDITO_TIPO_PERIOCIDAD_FINAL_DE_PLAZO ? "<td class='mny'>{$ultimopago} de {$pagos} POR \$ {$montoParc}</td>" : "<td class='izq'>UNICO</td>";
     $tdVencimiento = "<th class='izq'>" . $xL->getT("TR.Fecha de Vencimiento") . "</th><td>" . $xD->getDayName($fvencimiento) . "; " . $xD->getFechaCorta($fvencimiento) . "</td>";
     //Si el Estatus es AUTORIZADO
     if ($this->getEstadoActual() == CREDITO_ESTADO_AUTORIZADO) {
         $tdSaldo = "";
         $tdFecha = "<th class='izq'>" . $xL->getT("TR.Fecha de Autorizacion") . "</th><td>" . $xD->getFechaCorta($this->getFechaDeAutorizacion()) . "</td>";
         $activo = false;
         $tdPagos = "<td class='mny'>{$pagos}</td>";
     } elseif ($this->getEstadoActual() == CREDITO_ESTADO_SOLICITADO) {
         $tdSaldo = "";
         $tdMonto = "<th class='izq'>" . $xL->getT("TR.Monto Solicitado") . "</th><td class='mny'>" . getFMoney($this->getMontoSolicitado()) . "</td>";
         $tdFecha = "<th class='izq'>" . $xL->getT("TR.Fecha de Solicitud") . "</th><td>" . $xD->getFechaCorta($this->getFechaDeMinistracion()) . "</td>";
         $activo = false;
         $tdPagos = "<td class='mny'>{$pagos}</td>";
     }
     if ($this->getPeriocidadDePago() != CREDITO_TIPO_PERIOCIDAD_FINAL_DE_PLAZO) {
         $fvencimiento = $this->getFechaDeMora();
         $tdVencimiento = "<th class='izq'>" . $xL->getT("TR.Fecha de Vencimiento") . "</th><td>" . $xD->getDayName($fvencimiento) . "; " . $xD->getFechaCorta($fvencimiento) . "</td>";
     }
     if ($extendido == true) {
         $xPP = new cCreditos_destinos();
         $xPP->setData($xPP->query()->initByID($this->getClaveDeDestino()));
         $tdExigible = $activo == false ? "" : "<th class='izq'>" . $xL->getT("TR.Saldo exigible") . "</th><td class='mny'>" . getFMoney($this->getSaldoIntegrado(false, true)) . "</td>";
         $oficial = $this->getOOficial()->getNombreCompleto();
         $codigo_de_oficial = $this->getClaveDeOficialDeCredito();
         $tool = "<tr>\n\t\t\t\t\t\t\t\t<th class='izq'>" . $xL->getT("TR.Tasa Anualizada de Moratorio") . "</th><td class='mny'>" . getFMoney($TasaMora * 100) . "%</td>\n\t\t\t\t\t\t\t\t{$tdExigible}</tr>\n\t\t\t\t\t<tr><th class='izq'>" . $xL->getT("TR.Destino del Credito") . "</th><td colspan='3'>" . $xPP->descripcion_destinos()->v() . ": " . $this->mDescripcionDestino . "</td></tr>\n\t\t\t\t\t<tr><th class='izq'>Oficial a Cargo</td><td class='notice' colspan='3'>{$oficial}</td></tr>" . $tool;
         if ($activo == true) {
             if ($this->getPeriocidadDePago() != CREDITO_TIPO_PERIOCIDAD_FINAL_DE_PLAZO) {
                 $letra = $this->getPeriodoActual() + 1;
                 $IntAct = $this->getInteresDevengado(fechasys(), $letra, false, true);
             } else {
                 $IntAct = $this->getInteresDevengado();
             }
             $IntDevNorm = $this->getInteresNormalDevengado();
             $IntDevMor = $this->getInteresMoratorioDev();
             $IntPerNor = $IntAct[SYS_INTERES_NORMAL];
             $IntPerMor = $IntAct[SYS_INTERES_MORATORIO];
             $IntPagMor = $this->getInteresMoratorioPagado();
             $IntPagNor = $this->getInteresNormalPagado();
             $TIntNorm = $IntDevNorm + $IntPerNor - $IntPagNor;
             $TIntMor = $IntDevMor + $IntPerMor - $IntPagMor;
             $BaseIVA = $TIntNorm > 0 ? $TIntNorm : 0;
             $BaseIVA += $TIntMor > 0 ? $TIntMor : 0;
             $IntIVA = setNoMenorQueCero(($TIntNorm + $TIntMor) * $TasaIVA);
             $cargos = $this->getCargosDeCobranza();
             $cargosIVA = setNoMenorQueCero($cargos * TASA_IVA);
             $trCargos = "";
             if ($cargos > 0) {
                 $trCargos = "<tr>\n\t\t\t\t\t\t<td /><td />\n\t\t\t\t\t\t<th>" . $xL->getT("TR.Cargos por Cobranza") . "</th><td class='mny'>" . getFMoney($cargos) . "</td>\n\t\t\t\t\t</tr><tr>\n\t\t\t\t\t\t<td /><td />\n\t\t\t\t\t\t<th>" . $xL->getT("TR.IVA de Otros cargos") . "</th><td class='mny'>" . getFMoney($cargosIVA) . "</td>\n\t\t\t\t\t</tr>\t";
             }
             $tool .= "<tr>\n\t\t\t\t\t\t<th>" . $xL->getT("TR.Interes Normal Generado") . "</th><td class='mny'>" . getFMoney($IntDevNorm) . "</td>\n\t\t\t\t\t\t\n\t\t\t\t\t\t<th>" . $xL->getT("TR.Interes Moratorio Generado") . "</th><td class='mny'>" . getFMoney($IntDevMor) . "</td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<th>" . $xL->getT("TR.Interes Normal del Mes") . "</th><td class='mny'>" . getFMoney($IntPerNor) . "</td>\n\t\t\t\t\t\t<th>" . $xL->getT("TR.Interes Moratorio del mes") . "</th><td class='mny'>" . getFMoney($IntPerMor) . "</td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<th>" . $xL->getT("TR.Interes Normal Pagado") . "</th><td class='mny'>(" . getFMoney($IntPagNor) . ")</td>\n\t\t\t\t\t\t<th>" . $xL->getT("TR.Interes Moratorio Pagado") . "</th><td class='mny'>(" . getFMoney($IntPagMor) . ")</td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<th>" . $xL->getT("TR.TOTAL INTERES NORMAL") . "</th><th class='mny'>" . getFMoney($TIntNorm) . "</th>\n\t\t\t\t\t\t<th>" . $xL->getT("TR.TOTAL INTERES MORATORIO") . "</th><th class='mny'>" . getFMoney($TIntMor) . "</th>\n\t\t\t\t\t</tr>\n\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td /><td />\n\t\t\t\t\t\t<th>" . $xL->getT("TR.SALDO DE CAPITAL") . "</th><td class='total, mny'>" . getFMoney($this->getSaldoActual()) . "</td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td /><td />\n\t\t\t\t\t\t<th>" . $xL->getT("TR.TOTAL INTERESES") . "</th><td class='mny'>" . getFMoney($TIntNorm + $TIntMor) . "</td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td /><td />\n\t\t\t\t\t\t<th>" . $xL->getT("TR.IVA POR INTERESES") . "</th><td class='mny'>" . getFMoney($IntIVA) . "</td>\n\t\t\t\t\t</tr>\t\t\t\t\t\n\t\t\t\t\t\t\t\t{$trCargos}\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td /><td />\n\t\t\t\t\t\t<th>" . $xL->getT("TR.TOTAL POR PAGAR") . "</th><td class='total, mny'>" . getFMoney($TIntNorm + $TIntMor + $IntIVA + $this->getSaldoActual() + ($cargos + $cargosIVA)) . "</td>\n\t\t\t\t\t</tr>";
         }
         $tool = "<tfoot>{$tool}</tfoot>";
     }
     $exoFicha = "\n\t\t<table id='fichadecredito'>\n\t\t\t<tbody>\n\t\t\t\t{$trInicial}\n\t\t\t\t<tr>\n\t\t\t\t\t<th class='izq'>" . $xL->getT("TR.Numero de Credito") . "</th><td>{$solicitud}</td>\n\t\t\t\t\t<th class='izq'>" . $xL->getT("TR.Producto") . "</th><td>{$convenio}</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t\t<th class='izq'>" . $xL->getT("TR.Periocidad de Pago") . "</th><td>{$periocidad_pago}</td>\n\t\t\t\t\t<th class='izq'>" . $xL->getT("TR.Numero de Pagos") . "</th>{$tdPagos}\n\t\t\t\t<tr>\n\t\t\t\t<tr>\n\t\t\t\t\t\n\t\t\t\t\t<th class='izq'>" . $xL->getT("TR.Tasa Anualizada de interes") . "</th><td class='mny'>" . getFMoney($tasa) . "%</td>\n\t\t\t\t\t<th class='izq'>" . $xL->getT("TR.Estado_actual") . "</th><td  class='{$cls}'>{$estatus}</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t\t<th class='izq'>" . $xL->getT("TR.Tasa de IVA") . "</th><td class='mny'>" . getFMoney($TasaIVA * 100) . "%</td>\n\t\t\t\t\t<th class='izq'>CAT</th><td class='mny'>" . $this->getCAT() . "</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>{$tdFecha} {$tdVencimiento}</tr>\n\t\t\t\t<tr>{$tdMonto} {$tdSaldo}</tr>\n\t\t\t</tbody>\n\t\t\t{$tool}\n\t\t</table>";
     if ($mark == true) {
         $exoFicha = "<fieldset><legend>|&nbsp;&nbsp;" . $xL->getT("TR.Informacion de Credito") . "&nbsp;&nbsp;|</legend>{$exoFicha}</fieldset>";
     }
     return $exoFicha;
 }
$ByAll = "";
$senders = getEmails($_REQUEST);
$empresa = parametro("dependencia", SYS_TODAS, MQL_INT);
$empresa = parametro("empresa", $empresa, MQL_INT);
if (isset($_REQUEST["fechaMX"])) {
    $fecha_inicial = $xF->getFechaISO($_REQUEST["fechaMX"]);
    $fecha_final = $xF->getFechaISO($_REQUEST["fechaMX"]);
}
$ByDependencia = $empresa == SYS_TODAS ? "" : " AND `socios`.`iddependencia`=" . $empresa;
$ByUsuario = $cajero == SYS_TODAS ? "" : " AND operaciones_recibos.idusuario={$cajero} ";
$ByFecha = " AND (operaciones_recibos.fecha_operacion>='{$fecha_inicial}' AND operaciones_recibos.fecha_operacion<='{$fecha_final}') ";
$nombre_empresa = "";
if ($empresa != SYS_TODAS) {
    $xEmp = new cEmpresas($empresa);
    $xEmp->init();
    $nombre_empresa = $xEmp->getNombreCorto();
}
//XXX: Hacer un UNION para captacion
$setSql = "\nSELECT\n\t`operaciones_recibos`.`idoperaciones_recibos`,\n\t`operaciones_recibos`.`fecha_operacion`,\n\t`operaciones_recibos`.`docto_afectado`,\n\t`operaciones_recibos`.`numero_socio`,\n\t`socios`.`nombre`,\n\t\n\t(CASE WHEN (`creditos_solicitud`.`persona_asociada` = " . DEFAULT_EMPRESA . ")\n\tTHEN ''\n\tELSE `socios`.`dependencia` END) AS 'dependencia',\n\t\n\t`operaciones_recibos`.`tipo_docto`,\n\t`operaciones_recibostipo`.`descripcion_recibostipo` AS `tipo_de_recibo`,\n\t`operaciones_recibos`.`tipo_pago`,\n\t`operaciones_recibos`.`recibo_fiscal`,\t\n\t\n\t`operaciones_recibos`.`total_operacion`,\n\t`operaciones_recibos`.`observacion_recibo`,\n\n\t\n\t`operaciones_recibos`.`idusuario`\n\t\n\t\n\tFROM\n\t`operaciones_recibos` `operaciones_recibos` \n\t\tLEFT OUTER JOIN `creditos_solicitud` `creditos_solicitud` \n\t\tON `operaciones_recibos`.`docto_afectado` = `creditos_solicitud`.\n\t\t`numero_solicitud` \n\t\t\tINNER JOIN `operaciones_recibostipo` `operaciones_recibostipo` \n\t\t\tON `operaciones_recibos`.`tipo_docto` = `operaciones_recibostipo`.\n\t\t\t`idoperaciones_recibostipo` \n\t\t\t\tINNER JOIN `socios` `socios` \n\t\t\t\tON `operaciones_recibos`.`numero_socio` = `socios`.`codigo`\n\t\t\t\t\n\tWHERE operaciones_recibostipo.mostrar_en_corte!='0'\n\t\t\t{$ByFecha}\n\t\t\t{$ByUsuario}\n\t\t\t{$ByDependencia}\n\t\tORDER BY\n\t\t\t`operaciones_recibos`.`tipo_pago`,\n\t\t\t`operaciones_recibos`.`fecha_operacion`,\n\t\t\t`operaciones_recibos`.`tipo_docto`,\n\t\t\t`socios`.`dependencia`,\n\t\t\t`operaciones_recibos`.`idoperaciones_recibos`\n\t";
$output = $output == SYS_DEFAULT ? OUT_RXML : $output;
$xRPT = new cReportes($xHP->getTitle() . "-{$nombre_empresa}");
$xRPT->setSenders($senders);
$xRPT->setFile("report38");
$xRPT->setOut($output);
$xRPT->setSQL($setSql);
echo $xRPT->render(true);
//exit( $setSql);
/*if ($input!=OUT_EXCEL) {
	$oRpt = new PHPReportMaker();
	$oRpt->setDatabase(MY_DB_IN);
	$oRpt->setUser(RPT_USR_DB);
    $xOEmp->oficial_que_cierra($oficial);
    $xOEmp->nombre_corto($alias);
    $xOEmp->producto_preferente($producto);
    $xOEmp->email_de_envio($emails);
    $xOEmp->clave_de_persona($idsocio);
    $xOEmp->query()->update()->save($empresa);
    $xEmp = new cEmpresas($empresa);
    $xEmp->init();
    $xEmp->setActualizarPorPersona();
    $msg .= $xEmp->getMessages();
}
if (setNoMenorQueCero($empresa) > 0) {
    $xEmp = new cEmpresas($empresa);
    $xEmp->init();
    if ($xEmp->isInit() == true) {
        $alias = $xEmp->getNombreCorto();
        //$iddirectivo=
        $iddirectivo = $xEmp->getClaveDeContacto();
        $directivo = $xEmp->getNombreContacto();
        $idsocio = $xEmp->getClaveDePersona();
        $periocidad1 = $xEmp->getPeriocidadPref();
        $lstPeriodos = $xEmp->getListaDePeriocidad();
        $periocidad2 = isset($lstPeriodos[1]) ? $lstPeriodos[1] : $periocidad1;
        $producto = $xEmp->getProductoPref();
        $mails = $xEmp->getEmailsDeEnvio();
        $oficial = $xEmp->getClaveDeOficial();
        $mail1 = isset($mails[0]) ? $mails[0] : "";
        $mail2 = isset($mails[1]) ? $mails[1] : "";
        $mail3 = isset($mails[2]) ? $mails[2] : "";
        $diasaviso1 = $xEmp->getDiasDeAviso($periocidad1, MQL_STRING);
        $diasaviso2 = $xEmp->getDiasDeAviso($periocidad2, MQL_STRING);
 function setEmpresa($empresa, $puesto, $depto = "", $idempleado = "", $nss = 0, $ExtTelefonica = 0)
 {
     //cargar datos de la empresa
     $this->mClaveEmpresa = $empresa;
     $this->mPuesto = $puesto;
     $this->mDepto = $depto;
     $this->mIDEmpleado = $idempleado;
     $this->mNSS = $nss;
     $this->mExtTelefonica = $ExtTelefonica;
     //iniciar domicilio?
     $xEmp = new cEmpresas($this->mCodigoPostal);
     if ($xEmp->init() == true) {
         $this->mNombreEmpresa = $xEmp->getNombreCorto();
         $this->mDomicilio = $xEmp->getDomicilio();
         $OPers = $xEmp->getOPersona();
         if ($OPers != null) {
             $xViv = $OPers->getODomicilio();
             if ($xViv != null) {
                 $this->mClaveDeEstado = $xViv->getClaveDeEstado();
                 $this->mClaveDeMunicipio = $xViv->getClaveDeMunicipio();
                 $this->mClaveDeLocalidad = $xViv->getClaveDeLocalidad();
                 $this->mNombreDeLocalidad = $xViv->getLocalidad();
                 $this->mNombreDeMunicipio = $xViv->getMunicipio();
                 $this->mNombreDeEstado = $xViv->getEstado();
                 $this->mCodigoPostal = $xViv->getCodigoPostal();
                 $this->mIDDomicilio = $xViv->getClaveUnica();
             }
         }
     }
 }
function jsaSetGuardarDeposito($tipo_pago, $banco, $monto, $cobranza, $fecha, $observaciones, $empresa, $periodo)
{
    //'idtipo_pago', 'idcodigodecuenta', 'idmontodeposito', 'idsumacbza', 'idfecha-0', 'idobservaciones', 'idcodigodeempresas', 'idperiodo'
    $diferencia = $monto - $cobranza;
    $xEmp = new cEmpresas($empresa);
    $xEmp->init();
    $persona = $xEmp->getClaveDePersona();
    $xF = new cFecha();
    $fecha = $xF->getFechaISO($fecha);
    $xCaja = new cCaja();
    $documento = DEFAULT_CREDITO;
    $nombreemp = $xEmp->getNombreCorto();
    $xPer = $xEmp->getOPeriodo(false, false, $periodo);
    $periodo2 = $xPer->periodo_marcado()->v();
    $periocidad = $xPer->periocidad()->v();
    $observaciones = "{$empresa}-{$nombreemp}-{$periocidad}-{$periodo2}-ID.{$periodo}-" . $observaciones;
    if ($tipo_pago == TESORERIA_COBRO_TRANSFERENCIA) {
        $op = $xCaja->setCobroTransferencia(DEFAULT_RECIBO, $banco, $monto, $diferencia, $fecha, $observaciones, $persona, $documento);
    } elseif ($tipo_pago == TESORERIA_COBRO_EFECTIVO) {
        $xCaja->setCobroEfectivo(DEFAULT_RECIBO, $monto, $cobranza, $observaciones);
    }
    //Agregar operacion de la empresa
    $xEmp->addOperacion($monto, $periodo2, $periocidad, $fecha, -1, false, $observaciones);
}