$Estructura = $xLayout->getContent();
$production = ($out == OUT_TXT or $out == OUT_CSV) ? true : false;
$FechaExtraccion = $FechaFinal;
$FechaTitulo = date("ymd", strtotime($FechaFinal));
$casfin = EACP_CLAVE_CASFIN;
$delimitador = $xLayout->getSeparador();
$msg = "";
$supervisor = 2;
//$xCatalogoActividades	= new cPersonaActividadEconomica();
$sql = "SELECT\n\t\t*\nFROM\n\t`aml_risk_catalog` `aml_risk_catalog`\n\t\tINNER JOIN `aml_risk_register` `aml_risk_register`\n\t\tON `aml_risk_catalog`.`clave_de_control` = `aml_risk_register`.\n\t\t`tipo_de_riesgo`\nWHERE\n\t(`aml_risk_catalog`.`tipo_de_riesgo` = " . AML_CLAVE_OPERACIONES_INTERNAS . "\n\tOR\n\t`aml_risk_catalog`.`tipo_de_riesgo` = " . AML_CLAVE_OPERACIONES_INUSUALES . ")\t\t\n\t\n\tAND \n\t(`aml_risk_register`.`estado_de_envio` =0)\n\tAND\n\t(`aml_risk_register`.`reporte_inmediato` =1)\n\tORDER BY `aml_risk_register`.`fecha_de_reporte`\n";
$xTBL = new cTabla($sql);
$rpt = "";
$rs = $query->getDataRecord($sql);
$xEquivOps = new cSistemaEquivalencias(TOPERACIONES_RECIBOSTIPOS);
$xEquivOps->init($xEquivOps->PLD_OPERACIONES);
$xEquivInst = new cSistemaEquivalencias(TTESORERIA_TIPOS_DE_PAGO);
$xEquivInst->init($xEquivInst->PLD_OPERACIONES);
//$xEquivIns
$operaciones = 0;
$totalerrores = 0;
foreach ($rs as $data) {
    $xRisk = new cAml_risk_register();
    $xRisk->setData($data);
    $persona = $xRisk->persona_relacionada()->v();
    // $data["persona"];
    $fechaDetec = $xF->getFechaByInt($xRisk->fecha_de_reporte()->v());
    //$data["fecha"]);
    //$tipo_de_riesgo	=  $data["tipo_de_riesgo"];
    //obtener listado de operaciones en el mes
    $xAML = new cAMLPersonas($persona);
    $xSoc = new cSocio($persona, true);
 function add($persona, $tipo, $fecha, $valor, $documento, $tipo_de_documento = false, $usuario = false, $hora = false, $instrumento = false, $tipo_de_operacion = false, $tercero_relacionado = DEFAULT_SOCIO, $mensajes = "", $inmediato = false)
 {
     $hora = $hora == false ? date("Hi") : $hora;
     $usuario = $usuario == false ? getUsuarioActual() : $usuario;
     $tipo_de_documento = $tipo_de_documento == false ? iDE_RECIBO : $tipo_de_documento;
     $instrumento = setNoMenorQueCero($instrumento);
     if ($instrumento <= 0 or setNoMenorQueCero($tipo_de_operacion) <= 0) {
         switch ($tipo_de_documento) {
             case iDE_RECIBO:
                 $EqOps = new cSistemaEquivalencias(TOPERACIONES_RECIBOSTIPOS);
                 $EqTes = new cSistemaEquivalencias(TTESORERIA_TIPOS_DE_PAGO);
                 $xRec = new cReciboDeOperacion(false, false, $documento);
                 $instrumento = $EqTes->get($xRec->getTipoDePago());
                 $tipo_de_operacion = $EqOps->get($xRec->getTipoDeRecibo());
                 if ($xRec->isDivisaExtranjera() == true) {
                     $instrumento = AML_OPERACIONES_CLAVE_DIVISA;
                 }
                 if ($tipo_de_operacion == null) {
                     $tipo_de_operacion = "01";
                 }
                 break;
         }
     }
     if ($inmediato == true) {
         $inmediato = 1;
     }
     $inmediato = setNoMenorQueCero($inmediato);
     $xPR = new cAml_risk_register();
     $xPR->clave_de_riesgo($xPR->query()->getLastID());
     $xPR->escore($valor);
     $xPR->fecha_de_reporte($fecha);
     $xPR->hora_de_reporte($hora);
     $xPR->persona_relacionada($persona);
     $xPR->tipo_de_riesgo($tipo);
     $xPR->usuario_de_origen($usuario);
     $xPR->tipo_de_documento($tipo_de_documento);
     $xPR->documento_relacionado($documento);
     $xPR->estado_de_envio(SYS_UNO);
     $xPR->fecha_de_envio(0);
     $xPR->estado_de_envio(0);
     $xPR->fecha_de_checking(0);
     $xPR->oficial_de_checking(AML_OFICIAL_DE_CUMPLIMIENTO);
     $xPR->monto_total_relacionado(0);
     //cargar datos del recibo
     $xPR->instrumento_financiero($instrumento);
     //mejorar segun catalogo CNBV
     $xPR->tipo_de_operacion($tipo_de_operacion);
     $xPR->tercero_relacionado($tercero_relacionado);
     $xPR->mensajes_del_sistema($mensajes);
     $xPR->reporte_inmediato($inmediato);
     $ql = $xPR->query()->insert();
     $ql->save();
     $this->mMessages .= $ql->getMessages(OUT_TXT);
 }
$production = ($out == OUT_TXT or $out == OUT_CSV) ? true : false;
$FechaExtraccion = $FechaFinal;
$FechaTitulo = date("ymd", strtotime($FechaFinal));
$casfin = EACP_CLAVE_CASFIN;
$delimitador = $xLayout->getSeparador();
$msg = "";
$supervisor = 2;
//$xCatalogoActividades	= new cPersonaActividadEconomica();
$sql = "SELECT\n\t\t*\nFROM\n\t`aml_risk_catalog` `aml_risk_catalog`\n\t\tINNER JOIN `aml_risk_register` `aml_risk_register`\n\t\tON `aml_risk_catalog`.`clave_de_control` = `aml_risk_register`.\n\t\t`tipo_de_riesgo`\nWHERE\n\t`aml_risk_catalog`.`tipo_de_riesgo` = " . AML_CLAVE_OPERACIONES_INUSUALES . "\n\tAND (getFechaByInt(`aml_risk_register`.`fecha_de_reporte`) <='{$FechaFinal}')\n\tAND (`aml_risk_register`.`estado_de_envio` =0)\n\tORDER BY `aml_risk_register`.`fecha_de_reporte`\n";
//setLog($sql);
$xTBL = new cTabla($sql);
$rpt = "";
$rs = $query->getDataRecord($sql);
$xEquivOps = new cSistemaEquivalencias(TOPERACIONES_RECIBOSTIPOS);
$xEquivOps->init($xEquivOps->PLD_OPERACIONES);
$xEquivInst = new cSistemaEquivalencias(TTESORERIA_TIPOS_DE_PAGO);
$xEquivInst->init($xEquivInst->PLD_OPERACIONES);
//$xEquivIns
$operaciones = 0;
$totalerrores = 0;
foreach ($rs as $data) {
    $xRisk = new cAml_risk_register();
    $xRisk->setData($data);
    $persona = $xRisk->persona_relacionada()->v();
    // $data["persona"];
    $fechaDetec = $xF->getFechaByInt($xRisk->fecha_de_reporte()->v());
    //$data["fecha"]);
    //$tipo_de_riesgo	=  $data["tipo_de_riesgo"];
    //obtener listado de operaciones en el mes
    $xAML = new cAMLPersonas($persona);
    $xSoc = new cSocio($persona, true);