function initPorCredito($idcredito, $dataCredito = false)
 {
     $xCred = new cCredito($idcredito);
     $xCred->init($dataCredito);
     $xF = new cFecha();
     if ($xCred->getTipoEnSistema() == CREDITO_PRODUCTO_NOMINA) {
         //cargar datos de la empresa
         $idemp = $xCred->getClaveDeEmpresa();
         $periocidad = $xCred->getPeriocidadDePago();
         $this->setPeriocidadDePago($periocidad);
         $this->mTipoCreditoSis = $xCred->getTipoEnSistema();
         $this->mClaveDePlan = setNoMenorQueCero($xCred->getNumeroDePlanDePagos());
         if ($this->mClaveDePlan > 0) {
             //TODO: validar fecha de primer pago en calculos automaticos
             $this->mFechaPrimerPago = $xCred->getFechaPrimeraParc();
         } else {
             $this->mFechaPrimerPago = $this->getFechaDePago($xCred->getFechaDeMinistracion(), 1);
         }
         if ($xCred->getFechaPrimeraParc() == $this->mFechaFail or $xF->getInt($xCred->getFechaPrimeraParc()) <= $xF->getInt($xCred->getFechaDeMinistracion())) {
             $this->mFechaPrimerPago = $this->getFechaDePago($xCred->getFechaDeMinistracion(), 1);
         }
         $xEmp = new cEmpresas($idemp);
         $xEmp->init();
         $DDias = $xEmp->getDiasDeNomina($periocidad);
         $this->mDiaDeAbono1 = isset($DDias[0]) ? setNoMenorQueCero($DDias[0]) : $this->mDiaDeAbono1;
         $this->mDiaDeAbono2 = isset($DDias[1]) ? setNoMenorQueCero($DDias[1]) : $this->mDiaDeAbono2;
         $this->mDiaDeAbono3 = isset($DDias[2]) ? setNoMenorQueCero($DDias[2]) : $this->mDiaDeAbono3;
     } else {
         $this->mFechaPrimerPago = $this->getFechaDePago($xCred->getFechaDeMinistracion(), 1);
     }
 }
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 initByCredito($ClaveCredito = false)
 {
     $ClaveCredito = $ClaveCredito == false ? $this->mCredito : $ClaveCredito;
     $xCred = new cCredito($ClaveCredito);
     $xCred->init();
     $this->mClaveDeCredito = $xCred->getNumeroDeCredito();
     $this->mClaveDePersona = $xCred->getClaveDePersona();
     $this->mClaveDeGrupo = $xCred->getClaveDeGrupo();
     $this->mClaveDeEmpresa = $xCred->getClaveDeEmpresa();
     $this->mTasaDeIVA = $xCred->getTasaIVA();
     $this->mTotalParciales = $xCred->getPagosAutorizados();
     if ($this->mDiasTolerancia == 0) {
         $DProducto = $xCred->getOProductoDeCredito();
         $this->mDiasTolerancia = $DProducto->getDiasTolerados();
     }
     if ($xCred->getNumeroDePlanDePagos() != false) {
         $this->mNumeroDePlan = $xCred->getNumeroDePlanDePagos();
         $this->init();
     }
     $this->mIsInit = true;
     $this->mMessages .= $xCred->getMessages(OUT_TXT);
     return $this->mNumeroDePlan;
 }
 /**
  * Agrega un Recibo Nuevo
  * @param integer	$socio
  * @param integer	$documento
  * @param date		$fecha_operacion
  * @param integer	$parcialidad
  * @param integer	$tipo_docto
  * @param string	$cadena
  * @param string	$cheque_afectador
  * @param string	$tipo_pago
  * @param string	$recibo_fiscal
  * @param integer	$grupo_asoc
  * @param integer	$cuenta_bancaria
  */
 function setNuevoRecibo($socio, $documento, $fecha_operacion, $parcialidad, $tipo_docto = false, $cadena = "", $cheque_afectador = "NA", $tipo_pago = "ninguno", $recibo_fiscal = "NA", $grupo_asoc = DEFAULT_GRUPO, $cuenta_bancaria = false, $moneda = false, $unidades_originales = 0, $persona_asociada = false)
 {
     $ql = new MQL();
     $tipo_docto = setNoMenorQueCero($tipo_docto) <= 0 ? $this->mTipoDeRecibo : $tipo_docto;
     //----------------------------------DATOS DEL RECIBO------------------------
     $total_operacion = 0;
     // Total Operacion
     $observaciones = $cadena;
     $indice_origen = 99;
     // Indice de Origen
     $sucursal = getSucursal();
     $eacp = EACP_CLAVE;
     $moneda = $moneda == false ? $this->mMoneda : $moneda;
     $unidades_originales = $unidades_originales == 0 ? $this->mUnidadesOriginales : $unidades_originales;
     $persona_asociada = $persona_asociada == false ? $this->mClavePersonAsoc : $persona_asociada;
     $persona_asociada = setNoMenorQueCero($persona_asociada);
     //si es pago o ministracion
     if ($tipo_docto == RECIBOS_TIPO_PAGO_CREDITO and $persona_asociada <= DEFAULT_SOCIO) {
         $xCred = new cCredito($documento);
         if ($xCred->init() == true) {
             $persona_asociada = $xCred->getClaveDeEmpresa();
         }
     }
     //
     $cuenta_bancaria = setNoMenorQueCero($cuenta_bancaria);
     if ($cuenta_bancaria > 0) {
         $this->setCuentaBancaria($cuenta_bancaria);
     }
     // DATOS GENERALES
     $idrecibo = getFolio(iDE_RECIBO);
     //Verificar la Cuenta Bancaria
     if (!isset($socio)) {
         $socio = $this->mSocio;
     }
     $iduser = getUsuarioActual();
     $xDTab = new cSAFETabla(TOPERACIONES_RECIBOS);
     //----------------------------------------------------------------------------- clave_de_moneda, unidades_en_moneda
     $xRec = new cOperaciones_recibos();
     $xRec->archivo_fisico("");
     $xRec->cadena_distributiva($cadena);
     $xRec->cheque_afectador($cheque_afectador);
     $xRec->clave_de_moneda($moneda);
     $xRec->docto_afectado($documento);
     $xRec->eacp($eacp);
     $xRec->fecha_de_registro(fechasys());
     $xRec->fecha_operacion($fecha_operacion);
     $xRec->grupo_asociado($grupo_asoc);
     $xRec->idoperaciones_recibos($idrecibo);
     $xRec->idusuario($iduser);
     $xRec->indice_origen($indice_origen);
     $xRec->numero_socio($socio);
     $xRec->observacion_recibo($observaciones);
     $xRec->origen_aml(0);
     $xRec->persona_asociada($persona_asociada);
     //empresa
     $xRec->recibo_fiscal($recibo_fiscal);
     $xRec->sucursal($sucursal);
     $xRec->tipo_docto($tipo_docto);
     $xRec->total_operacion($total_operacion);
     $xRec->unidades_en_moneda($unidades_originales);
     $xRec->tipo_pago($tipo_pago);
     if ($this->mAfectar == true) {
         $xsr = $xRec->query()->insert()->save();
         // my_query($sql_i_rec);
         if ($xsr != false) {
             $this->mMessages .= "OK\tSe agrego exitosamente el Recibo : {$idrecibo} : del Documento {$documento}\r\n";
             $this->mCodigoDeRecibo = $idrecibo;
             $this->setNumeroDeRecibo($idrecibo);
             $this->init();
         } else {
             $this->mMessages .= "ERROR\tError al Agregar el Recibo {$idrecibo} del Documento {$documento} \r\n";
             $idrecibo = false;
         }
     } else {
         $this->mMessages .= "WARN\tNo se agrega el Recibo por que es NO AFECTABLE \r\n";
     }
     return $idrecibo;
 }
 function setCredito($credito)
 {
     $this->mDocumento = $credito;
     $xFDE = new cFecha();
     $xLng = new cLang();
     $cCred = new cCredito($credito);
     $cCred->init();
     $idsolicitud = $credito;
     $DCred = $cCred->getDatosDeCredito();
     $DProd = $cCred->getOProductoDeCredito();
     $OOParam = new cProductoDeCreditoOtrosDatosCatalogo();
     $numero_de_socio = $cCred->getClaveDePersona();
     $this->mPersona = $numero_de_socio;
     $cSoc = new cSocio($numero_de_socio);
     $cSoc->init();
     $svar_info_cred = "";
     $tblInfCred = new cFicha(iDE_CREDITO, $idsolicitud);
     $this->setPersona($numero_de_socio);
     $svar_info_cred = $tblInfCred->show(true);
     //Lista de Beneficiados
     $lst_beneficiados = "";
     $this->getListadoDeAvales($idsolicitud);
     $SQLCBen = "SELECT `socios_relacionestipos`.`descripcion_relacionestipos` AS 'relacion', `socios_relaciones`.`nombres`,\t`socios_relaciones`.`apellido_paterno`,\t`socios_relaciones`.`apellido_materno`,\n\t\t\t`socios_consanguinidad`.`descripcion_consanguinidad` AS 'consaguinidad'\n\t\t\tFROM `socios_relaciones` `socios_relaciones` INNER JOIN `socios_consanguinidad` `socios_consanguinidad` ON `socios_relaciones`.`consanguinidad` = `socios_consanguinidad`.`idsocios_consanguinidad`\n\t\t\tINNER JOIN `socios_relacionestipos` `socios_relacionestipos` ON `socios_relaciones`.`tipo_relacion` = `socios_relacionestipos`.`idsocios_relacionestipos`\n\t\t\tWHERE (`socios_relaciones`.`socio_relacionado` ={$numero_de_socio}) AND (`socios_relaciones`.`credito_relacionado` ={$idsolicitud})\tAND\t(`socios_relaciones`.`tipo_relacion`=11)";
     $tblCBen = new cTabla($SQLCBen);
     $lst_beneficiados = $tblCBen->Show();
     $firmas_de_avales = $this->mFirmasAvales;
     // $cSoc->getCoResponsables("firmas", "avales", $idsolicitud );
     //Plan de Pago segun SQL
     $splan_pagos = $cCred->getPlanDePago(OUT_HTML, true, true);
     //==================================================================================
     $fichas_de_avales = $this->mFichasAvales;
     //$cCred->getAvales_InText();
     $fecha_larga_de_documento = $xFDE->getFechaLarga($cCred->getFechaDeMinistracion());
     $fichas_de_respsolidarios = "";
     //TODO: FALTA
     //Otros Datos
     $monto_ministrado = $cCred->getMontoAutorizado();
     $tasa_interes_mensual_ordinario = round($cCred->getTasaDeInteres() / 12 * 100, 2);
     $tasa_interes_anual_ordinario = $cCred->getTasaDeInteres();
     $fecha_de_vencimiento = $cCred->getFechaDeVencimiento();
     $fecha_de_ministracion = $cCred->getFechaDeMinistracion();
     $tasa_garantia_liquida = $DCred["porciento_garantia_liquida"] * 100;
     $monto_garantia_liquida = $monto_ministrado * $tasa_garantia_liquida;
     $tasa_interes_mensual_moratorio = round($cCred->getTasaDeMora() / 12 * 100, 2);
     $dias_del_credito = $cCred->getDiasAutorizados();
     $meses_del_credito = sprintf("%02d", ceil($dias_del_credito / 30.416666666666668));
     $periocidad = $cCred->getPeriocidadDePago();
     //Tipo de Credito por SQL
     $SQLTCred = "SELECT * FROM creditos_modalidades WHERE idcreditos_modalidades=" . $DCred["tipo_credito"];
     $tipo_de_credito = mifila($SQLTCred, "descripcion_modalidades");
     //Datos del Grupo Solidarios por SQL
     $SQLGAsoc = "SELECT * FROM socios_grupossolidarios WHERE idsocios_grupossolidarios=" . $DCred["grupo_asociado"];
     $InfoGrupo = obten_filas($SQLGAsoc);
     $nombre_rep_social = $InfoGrupo["representante_nombrecompleto"];
     $codigo_rep_social = $InfoGrupo["representante_numerosocio"];
     $nombre_voc_vigila = $InfoGrupo["vocalvigilancia_nombrecompleto"];
     $nombre_del_grupo = $InfoGrupo["nombre_gruposolidario"];
     $domicilio_rep_social = domicilio($codigo_rep_social);
     $tabla_asociadas = "";
     $lista_asociadas = "";
     $tasa_de_cat = $cCred->getCAT();
     $DPeriocidad = new cPeriocidadDePago($cCred->getPeriocidadDePago());
     $DPeriocidad->init();
     $monto_con_interes = "";
     $monto_con_interes_letras = "";
     if ($DCred["grupo_asociado"] != DEFAULT_GRUPO) {
         $SQL_get_grupo = "SELECT `socios_general`.`codigo`, CONCAT(`socios_general`.`nombrecompleto`, ' ', `socios_general`.`apellidopaterno`, ' ', `socios_general`.`apellidomaterno`) AS 'nombre_completo'\n\t\t\t\t\t\t\t\t\tFROM `socios_general` `socios_general` WHERE (`socios_general`.`grupo_solidario` =" . $DCred["grupo_asociado"] . ")";
         $rsg = getRecordset($SQL_get_grupo);
         while ($rwt = mysql_fetch_array($rsg)) {
             $lista_asociadas .= ", " . $rwt["nombre_completo"];
         }
     }
     if (EACP_INCLUDE_INTERES_IN_PAGARE == true) {
         if ($periocidad == CREDITO_TIPO_PERIOCIDAD_FINAL_DE_PLAZO) {
             $monto_con_interes = $cCred->getMontoAutorizado() + $cCred->getInteresDiariogenerado() * $cCred->getDiasAutorizados();
         } else {
             $sqlInt = "SELECT `operaciones_mvtos`.`docto_afectado`, `operaciones_mvtos`.`tipo_operacion`, COUNT(`operaciones_mvtos`.`idoperaciones_mvtos`) AS `mvtos`,\n\t\t\t\t\tSUM(`operaciones_mvtos`.`afectacion_real` *\t`eacp_config_bases_de_integracion_miembros`.`afectacion`) AS 'monto'\n\t\t\t\t\tFROM `operaciones_mvtos` `operaciones_mvtos` INNER JOIN `eacp_config_bases_de_integracion_miembros`\t`eacp_config_bases_de_integracion_miembros`\n\t\t\t\t\tON `operaciones_mvtos`.`tipo_operacion` = `eacp_config_bases_de_integracion_miembros`.`miembro` WHERE (`operaciones_mvtos`.`docto_afectado` = {$idsolicitud})\n\t\t\t\t\tAND (`eacp_config_bases_de_integracion_miembros`.`codigo_de_base` = 2601)\n\t\t\t\t\tGROUP BY `operaciones_mvtos`.`docto_afectado`, `eacp_config_bases_de_integracion_miembros`.`codigo_de_base`\n\t\t\t\t\tORDER BY `eacp_config_bases_de_integracion_miembros`.`codigo_de_base`, `operaciones_mvtos`.`fecha_afectacion`, `operaciones_mvtos`.`socio_afectado`\t";
             $xF = obten_filas($sqlInt);
             $monto_con_interes = $xF["monto"];
         }
         $monto_con_interes_letras = convertirletras($monto_con_interes);
         $monto_con_interes = getFMoney($monto_con_interes);
     }
     $this->mArr["variable_informacion_del_credito"] = $cCred->getFicha();
     //"variable_lista_de_beneficiados" 		=> $lst_beneficiados,
     $this->mArr["variable_tipo_de_credito"] = $tipo_de_credito;
     $this->mArr["variable_monto2_ministrado_con_intereses_en_letras"] = $monto_con_interes_letras;
     $this->mArr["variable_monto2_ministrado_con_intereses"] = $monto_con_interes;
     $this->mArr["variable_monto_ministrado"] = getFMoney($monto_ministrado);
     $this->mArr["variable_tasa_mensual_de_interes_ordinario"] = $tasa_interes_mensual_ordinario;
     $this->mArr["variable_credito_fecha_de_vencimiento"] = $xFDE->getFechaMediana($fecha_de_vencimiento);
     $this->mArr["variable_monto_garantia_liquida"] = getFMoney($monto_garantia_liquida);
     $this->mArr["variable_tasa_mensual_de_interes_moratorio"] = $tasa_interes_mensual_moratorio . "";
     $this->mArr["variable_tasa_de_garantia_liquida"] = $tasa_garantia_liquida . "";
     $this->mArr["variable_plan_de_pagos"] = $splan_pagos;
     $this->mArr["variable_docto_fecha_larga_actual"] = $fecha_larga_de_documento;
     $this->mArr["variable_nombre_de_la_representante_social"] = $nombre_rep_social;
     $this->mArr["variable_listado_de_integrantes"] = $lista_asociadas;
     $this->mArr["variable_nombre_de_la_vocal_de_vigilancia"] = $nombre_voc_vigila;
     $this->mArr["variable_nombre_del_grupo_solidario"] = $nombre_del_grupo;
     $this->mArr["variable_domicilio_de_la_representante_social"] = $domicilio_rep_social;
     $this->mArr["variable_meses_de_duracion_del_credito"] = $meses_del_credito;
     $this->mArr["variable_en_letras_monto_ministrado"] = convertirletras($monto_ministrado);
     $this->mArr["variable_credito_fecha_de_ministracion"] = $xFDE->getFechaCorta($fecha_de_ministracion);
     $this->mArr["variable_tasa_cat"] = $tasa_de_cat;
     $this->mArr["variable_credito_periocidad"] = $DPeriocidad->getNombre();
     $this->mArr["variable_credito_monto_parcialidad_fija"] = getFMoney($cCred->getMontoDeParcialidad());
     $this->mArr["variable_credito_numero_de_pagos"] = $cCred->getPagosAutorizados();
     $this->mArr["variable_tasa_anual_de_interes_moratorio"] = $cCred->getTasaDeInteres() * 2 * 100 . "%";
     $this->mArr["variable_tasa_anual_de_interes_ordinario"] = $cCred->getTasaDeInteres() * 100 . "%";
     //sobreescribir datos de la empresa
     $xEmp = new cEmpresas($cCred->getClaveDeEmpresa());
     $xEmp->init();
     $this->mArr["variable_nombre_de_la_empresa"] = $xEmp->getNombre();
     $this->mArr["variable_nombre_de_empresa"] = $xEmp->getNombre();
     $this->mArr["variable_fecha_de_primer_pago"] = $xFDE->getFechaMediana($cCred->getFechaPrimeraParc());
     $this->mArr["variable_avales_en_fichas"] = $fichas_de_avales;
     $this->mArr["variable_firmas_de_avales"] = $firmas_de_avales;
     $this->mArr["variable_avales_autorizacion_central_riesgo"] = $this->mFichaRiesgoAv;
     $this->mArr["variable_fecha_ultimo_abono"] = $xFDE->getFechaLarga($cCred->getFechaUltimaParc());
     $this->mArr["variable_fecha_de_primer_abono"] = $xFDE->getFechaMediana($cCred->getFechaPrimeraParc());
     //$this->mArr["variable_fecha_de_primer_abono"]						=
     $this->mArr["variable_en_letras_tasa_mensual_de_interes_moratorio"] = convertirletras_porcentaje($tasa_interes_mensual_moratorio);
     $this->mArr["variable_lista_de_avales_con_domicilio"] = $this->mLAvalesConDir;
     /*variable_aval1_nombre_completo variable_aval1_domicilio_completo variable_aval1_domicilio_localidad variable_aval1_domicilio_municipio*/
     //Cargar Avales
     $this->mArr["variable_listado_de_garantias"] = $this->getListadoDeGarantias();
     //$this->mArr["variable_modalidad_de_credito"]					= $cCred->getOEstado()
     $this->mArr["variable_estado_de_credito"] = $cCred->getOEstado()->descripcion_estatus()->v(OUT_TXT);
     //$this->mArr["variable_credito_num_de_pago_actual"]				= $cCred->getPeriodoActual();
     $this->mArr["variable_contrato_id_legal"] = $DProd->getOtrosParametros($OOParam->CONTRATO_ID_LEGAL);
     $this->mArr["variable_producto_comision_apertura"] = $DProd->getOtrosParametros($OOParam->TASA_DE_COMISION_AP);
 }
$percbza = EACP_PER_COBRANZA;
// Periodo Cobranza.
$perseg = EACP_PER_SEGUIMIENTO;
// Period de Seguimiento.
$permens = date("m");
// Periodo de dias en el mes
$persem = date("N");
// Periodo de dias en la semana.
$peranual = date("Y");
// Ao Natural.
//Datos del Respeto al Plan de Pagos
$OPdto = $xCred->getOProductoDeCredito();
$OPerx = $xCred->getOPeriocidad();
$OEstado = $xCred->getOEstado();
$respetar_plan_pagos = $xCred->getRespetarPlanDePago();
$empresa = $xCred->getClaveDeEmpresa();
$tasa_iva = $xCred->getTasaIVA();
$msg .= "WARN\tPLAN\tQue hacer con el Plan: {$respetar_plan_pagos}\r\n";
$contrato_captacion = $dsol["contrato_corriente_relacionado"];
$saldo_anterior = $xCred->getSaldoActual();
if ($grupo == 0 || !isset($grupo) || $grupo == "" || $grupo == false) {
    $grupo = DEFAULT_GRUPO;
}
$xNRec = new cReciboDeOperacion(RECIBOS_TIPO_PAGO_CREDITO);
$xNRec->setNuevoRecibo($socio, $solicitud, $fecha_operacion, $parcialidad, RECIBOS_TIPO_PAGO_CREDITO, $observaciones, $cheque, $tipo_pago, $recibo_fiscal, $grupo, false, AML_CLAVE_MONEDA_LOCAL, 0, $empresa);
$xNRec->init();
$msg .= $xNRec->getMessages(OUT_TXT);
$recibo_pago = $xNRec->getCodigoDeRecibo();
if ($procesado == SYS_AUTOMATICO or $pempresa > 0) {
    $icxObs = $SRC["cobservaciones"];
    $msg .= "WARN\tTOTAL AUTOMATICO\t:{$icxObs}\t{$totalAutomatico}\r\n";