$sucursal = parametro("sucursal", SYS_TODAS, MQL_RAW);
$out = parametro("out", SYS_DEFAULT);
$FechaInicial = parametro("on", false);
$FechaInicial = parametro("fecha-0", $FechaInicial);
$FechaInicial = $FechaInicial == false ? FECHA_INICIO_OPERACIONES_SISTEMA : $xF->getFechaISO($FechaInicial);
$FechaFinal = parametro("off", false);
$FechaFinal = parametro("fecha-1", $FechaFinal);
$FechaFinal = $FechaFinal == false ? fechasys() : $xF->getFechaISO($FechaFinal);
$jsEvent = $out != OUT_EXCEL ? "initComponents()" : "";
$senders = getEmails($_REQUEST);
$xODat = new cPersonasCatalogoOtrosDatos();
$sql = "SELECT\r\n\t`socios`.`codigo`,\r\n\t`socios`.`nombre`,\r\n\t`socios_otros_parametros`.`clave_del_parametro` \r\nFROM\r\n\t`socios_otros_parametros` `socios_otros_parametros` \r\n\t\tINNER JOIN `socios` `socios` \r\n\t\tON `socios_otros_parametros`.`clave_de_persona` = `socios`.`codigo` \r\nWHERE\r\n\t(`socios_otros_parametros`.`clave_del_parametro` ='" . $xODat->AML_PEP_PRINCIPAL . "')\r\n\t\t\tOR\r\n\t(`socios_otros_parametros`.`clave_del_parametro` ='" . $xODat->AML_PEP_AFINIDAD . "')\t\t\t\r\n\tOR\r\n(`socios_otros_parametros`.`clave_del_parametro` ='" . $xODat->AML_PEP_CONSANGUINIDAD . "')\t\t\t\r\n\t\tOR\r\n(`socios_otros_parametros`.`clave_del_parametro` ='" . $xODat->AML_PEP_VINCULO_ECONOM . "')\t";
$titulo = "";
$archivo = "";
$xRPT = new cReportes($titulo);
$xRPT->setFile($archivo);
$xRPT->setOut($out);
$xRPT->setSQL($sql);
$xRPT->setTitle($xHP->getTitle());
//============ Reporte
$xT = new cTabla($sql, 1);
$xT->setTipoSalida($out);
$body = $xRPT->getEncabezado($xHP->getTitle(), $FechaInicial, $FechaFinal);
$xRPT->setBodyMail($body);
$xRPT->addContent($body);
//$xT->setEventKey("jsGoPanel");
//$xT->setKeyField("creditos_solicitud");
$xRPT->addContent($xT->Show());
//============ Agregar HTML
//$xRPT->addContent( $xHP->init($jsEvent) );
//$xRPT->addContent( $xHP->end() );
         $xTbl->addRaw("<tr><td colspan='3'><h1>" . $xLng->getT("TR.Direcciones") . "<h1><hr />{$adr}</td></tr>");
         //$xTbl->endRow()
         $xFld = new cHFieldset($flTitle);
         $xFld->addHElem($xTbl->get());
         $txtLst .= $xFld->get();
     }
 }
 if ($getPDF == true) {
     //base64_encode($sql)
     $xFMT = new cFormato(8801);
     $xFMT->setProcesarVars(array("variable_listado_de_cedulas" => $txtLst, "variable_item_buscado" => "{$nombre} / {$apaterno} / {$amaterno}", "variable_cadena_consulta" => ""));
     $xRPT = new cReportes($xHP->getTitle());
     $xRPT->getEncabezado($xHP->getTitle());
     if ($ret == true) {
         $xRPT->setOut(OUT_HTML);
         $xRPT->setFile("ofacs_list_");
         $xRPT->addContent($xFMT->get());
         $xRPT->render(true);
         $dompdf = new DOMPDF();
         $dompdf->load_html($xRPT->render(true));
         $dompdf->set_paper("letter", "portrait");
         $dompdf->render();
         $json["pdf"] = base64_encode($dompdf->output());
     } else {
         $xRPT->setSenders($mails);
         $xRPT->setOut(OUT_PDF);
         $xRPT->setFile("ofacs_list_");
         $xRPT->addContent($xFMT->get());
         $xRPT->render(true);
     }
 }
    $fecha_inicial = $xF->getFechaISO($fecha_inicial);
}
//http://localhost/rptotros/rpt_mvtos_x_tipo_segun_fechas.php
//estado=todas
//out=default
//empresa=todas
//convenio=todas
//tipodepago=transferenci
//usuario=todas
$BySucursal = $sucursal == SYS_TODAS ? "" : "  AND operaciones_mvtos.sucursal = '{$sucursal}'  ";
$xmlFile = "report73.nomina";
$ByPersona = $persona == SYS_NINGUNO ? "" : " AND operaciones_mvtos.socio_afectado={$persona} ";
$ByOperacion = $operacion == SYS_TODAS ? "" : " AND `operaciones_mvtos`.`tipo_operacion` = {$operacion} ";
$ByPago = $forma_de_pago == SYS_TODAS ? "" : " AND operaciones_recibos.tipo_pago ='{$forma_de_pago}' ";
$tipo = $operacion;
if ($ByOperacion != "") {
    $cMov = new cOperaciones_tipos();
    $cMov->setData($cMov->query()->initByID($tipo));
    $tipo = $cMov->descripcion_operacion()->v();
}
$setSql = " SELECT\n\t\t\t\toperaciones_mvtos.sucursal,\n\t\t\t\toperaciones_recibos.tipo_pago \t\t\t\tAS 'tipo_de_pago',\n\t\t\t\toperaciones_mvtos.socio_afectado \t\t\tAS 'numero_de_socio',\n\t\t\t\t\n\t\t\t\t`socios`.`nombre` AS `nombre_completo`,\n\t\t\t\t`socios`.`alias_dependencia` AS `empresa`,\n\t\t\t\t\n\t\t\t\toperaciones_tipos.descripcion_operacion \tAS 'tipo_de_operacion',\n\t\t\t\toperaciones_mvtos.fecha_afectacion \t\t\tAS 'fecha',\n\t\t\t\t`operaciones_mvtos`.`idoperaciones_mvtos`\tAS `operacion`,\n\t\t\t\t`operaciones_mvtos`.`recibo_afectado`   \tAS `recibo`,\n\t\t\t\t`operaciones_recibos`.`recibo_fiscal`   \tAS `fiscal`,\n\t\t\t\toperaciones_mvtos.docto_afectado \t\t\tAS 'documento',\n\t\t\t\toperaciones_mvtos.afectacion_real\t\t\tAS 'monto',\n\t\t\t\toperaciones_mvtos.detalles \t\t\t\t\tAS 'observaciones'\n\t\t\t\tFROM\n\t\t\t\t`operaciones_mvtos` `operaciones_mvtos` \n\t\t\t\t\tINNER JOIN `operaciones_tipos` `operaciones_tipos` \n\t\t\t\t\tON `operaciones_mvtos`.`tipo_operacion` = `operaciones_tipos`.\n\t\t\t\t\t`idoperaciones_tipos` \n\t\t\t\t\t\tINNER JOIN `socios` `socios` \n\t\t\t\t\t\tON `socios`.`codigo` = `operaciones_mvtos`.`socio_afectado` \n\t\t\t\t\t\t\tINNER JOIN `operaciones_recibos` `operaciones_recibos` \n\t\t\t\t\t\t\tON `operaciones_mvtos`.`recibo_afectado` = `operaciones_recibos`\n\t\t\t\t\t\t\t.`idoperaciones_recibos`\n\t\t\t\t\t\t\n\t\t\t\tWHERE\n\t\t\t\toperaciones_mvtos.fecha_afectacion>='{$fecha_inicial}'\n\t\t\t\tAND\n\t\t\t\toperaciones_mvtos.fecha_afectacion<='{$fecha_final}'\n\t\t\t\t\t{$ByPersona}\n\t\t\t\t\t{$BySucursal}\n\t\t\t\t\t{$ByOperacion}\n\t\t\t\t\t{$ByPago}\n\t\t\tORDER BY\n\t\t\t\t`operaciones_mvtos`.`sucursal`,\n\t\t\t\t`operaciones_recibos`.`fecha_operacion`,\n\t\t\t\t`operaciones_recibos`.`idoperaciones_recibos`,\n\t\t\t\t`operaciones_mvtos`.`idoperaciones_mvtos` ";
//exit($setSql);
$xRPT = new cReportes("TR.Reporte de operaciones - {$tipo}");
$output = $output == SYS_DEFAULT ? OUT_RXML : $output;
$xRPT->setOut($output);
$xRPT->setSenders($senders);
$body = $xRPT->getEncabezado("", $fecha_inicial, $fecha_final);
$xRPT->setBodyMail($body);
$xRPT->setFile($xmlFile);
$xRPT->setSQL($setSql);
$xRPT->render(true);
}
$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);
	$oRpt->setPassword(RPT_PWD_DB);
	$oRpt->setSQL($setSql);
	$oRpt->setXML("../repository/report38.xml");
	$oOut = $oRpt->createOutputPlugin($input);
	$oRpt->setOutputPlugin($oOut);
	$oRpt->run();
} else {