/**
  * Muestra el Plan de Pagos en Texto, o HTML, Simple o Completo
  *
  * @param string $InOut		Tipo de Sal�ida, por Defecto HTML
  * @param boolean $simple	Solo Imprime el Plan de Pagos sin detallarla Lista
  * @param boolen $NoExtend	SI es a TRue solo muestra el Plan de pagos
  * @return string			Plan de Pagos en Formto definido en OUT
  */
 function getPlanDePago($InOut = "html", $simple = false, $NoExtend = false)
 {
     $PlanBody = "";
     if ($this->mCreditoInicializado == false) {
         $this->init();
     }
     $xF = new cFecha();
     $xL = new cLang();
     $xQ = new MQL();
     $xF->init(FECHA_FORMATO_MX);
     $xF->setSeparador("/");
     if ($this->mPagosAutorizados > 1) {
         if (setNoMenorQueCero($this->mNumeroDePlanDePago) <= 0) {
             $extras = $this->getDatosDelPlanDePagos();
         } else {
             $sqlrs = "SELECT *\n\t\t\t\t\t\tFROM operaciones_recibos\n\t\t\t\t\t\tWHERE idoperaciones_recibos=" . $this->getNumeroDePlanDePagos();
             $idrecibo = $this->getNumeroDePlanDePagos();
             $extras = obten_filas($sqlrs);
         }
         //------------------------------------- DATOS DEL RECIBO
         //TODO: Validar IDRECIBO, si es Mayor a cero y si existe 2014-10-31
         //XXX: Terminar valicacion de IDRECIBO 201/10/31
         $idrecibo = $extras["idoperaciones_recibos"];
         $idsocio = $extras["numero_socio"];
         //"numero_socio"
         $idsolicitud = $extras["docto_afectado"];
         // docto_afectado
         $sumrec = $extras["total_operacion"];
         $nombre = getNombreSocio($idsocio);
         $SUMCap = 0;
         $SUMInt = 0;
         $SUMIva = 0;
         $SUMAh = 0;
         $SUMOtros = 0;
         $SumTotal = 0;
         // ------------------------------------ DATOS DE LA SOLICITUD.
         if ($this->mCreditoInicializado == false) {
             $sqlsol = "SELECT * FROM creditos_solicitud WHERE numero_solicitud={$idsolicitud}";
             $dsol = obten_filas($sqlsol);
             $tasa_ahorro = $dsol["tasa_ahorro"] * 100;
             $tasa_interes = $dsol["tasa_interes"] * 100;
             $dias_totales = $dsol["dias_autorizados"];
             $numero_pagos = $dsol["pagos_autorizados"];
             $nombre_otro = "";
         } else {
             $tasa_ahorro = $this->mTasaAhorro * 100;
             $tasa_interes = $this->mTasaInteres * 100;
             $dias_totales = $this->mDiasAutorizados;
             $numero_pagos = $this->mPagosAutorizados;
             $nombre_otro = "";
         }
         $this->mLimitPlan = ceil($numero_pagos / 3);
         if ($NoExtend == false) {
             $PlanBody .= $this->getFichaDeSocio();
             $PlanBody .= $this->getFicha();
         }
         if ($simple == false) {
             $sql = "\n\t\t\t\t\tSELECT operaciones_mvtos.periodo_socio AS 'parcialidad', fecha_afectacion,\n\t\t\t\t\t\t\toperaciones_tipos.idoperaciones_tipos  As 'tipo',\n\t\t\t\t\t\t\toperaciones_tipos.descripcion_operacion AS 'concepto' ,\n\t\t\t\t\t\t\toperaciones_mvtos.afectacion_real AS 'monto',\n\t\t\t\t\t\t\toperaciones_mvtos.saldo_actual AS 'saldo'\n\n\t\t\t\t\tFROM \t`operaciones_mvtos` `operaciones_mvtos`\n\t\t\t\t\t\t\tINNER JOIN `operaciones_tipos` `operaciones_tipos`\n\t\t\t\t\t\t\tON `operaciones_mvtos`.`tipo_operacion` = `operaciones_tipos`.\n\t\t\t\t\t\t\t`idoperaciones_tipos`\n\n\t\t\t\t\tWHERE operaciones_mvtos.recibo_afectado={$idrecibo}\n\t\t\t\t\tORDER BY operaciones_mvtos.periodo_socio, operaciones_tipos.idoperaciones_tipos";
             $rs = $xQ->getDataRecord($sql);
             $trs = "";
             //Parcialidad, evaluador de inciio y final
             $PInit = 0;
             $PFin = 0;
             $capital = 0;
             $interes = 0;
             $iva = 0;
             $ahorro = 0;
             $otros = 0;
             $total = 0;
             $saldo = 0;
             $tds = "";
             foreach ($rs as $rw) {
                 $PInit = $rw["parcialidad"];
                 $tipo = $rw["tipo"];
                 switch ($tipo) {
                     case 410:
                         $capital = $rw["monto"];
                         $SUMCap += $capital;
                         $saldo = $rw["saldo"];
                         if ($saldo < 0) {
                             $saldo = 0;
                         }
                         break;
                     case 411:
                         $interes = $rw["monto"];
                         $SUMInt += $interes;
                         break;
                     case 412:
                         $ahorro = $rw["monto"];
                         $SUMAh += $ahorro;
                         break;
                     case 413:
                         $iva = $rw["monto"];
                         $SUMIva += $iva;
                         break;
                     default:
                         $otros = $rw["monto"];
                         $SUMOtros += $otros;
                         $top = getInfTOperacion($tipo);
                         $nombre_otro = $top["descripcion_operacion"];
                         break;
                 }
                 if ($PInit != $PFin) {
                     $trs .= $tds;
                 } else {
                     $total = $capital + $interes + $ahorro + $iva;
                     $tdAhorro = "<td class='mny'>" . getFMoney($ahorro) . "</td>";
                     $tdOtros = "<td class='mny'>" . getFMoney($otros) . "</td>";
                     if ($ahorro == 0) {
                         $tdAhorro = "";
                     }
                     if ($otros == 0) {
                         $tdOtros = "";
                     }
                     $tds = "<tr>\n\t\t\t\t\t\t\t<td>" . $rw["parcialidad"] . "</td>\n\t\t\t\t\t\t\t<td class='ctr'>" . getDiaDeLaSemana($rw["fecha_afectacion"]) . "</td><td class='ctr'>" . $xF->getFechaCorta($rw["fecha_afectacion"]) . "</td>\n\t\t\t\t\t\t\t<td class='mny'>" . getFMoney($capital) . "</td>\n\t\t\t\t\t\t\t<td class='mny'>" . getFMoney($interes) . "</td>\n\t\t\t\t\t\t\t<td class='mny'>" . getFMoney($iva) . "</td>\n\t\t\t\t\t\t\t{$tdAhorro}\n\t\t\t\t\t\t\t{$tdOtros}\n\t\t\t\t\t\t\t<td class='mny'>" . getFMoney($total) . "</td>\n\t\t\t\t\t\t\t<td class='mny'>" . getFMoney($saldo) . "</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t";
                 }
                 $PFin = $PInit;
             }
             $trs .= $tds;
             $SumTotal = $SUMCap + $SUMAh + $SUMInt + $SUMIva + $SUMOtros;
             $thAhorro = " <th>" . $xL->getT("TR.Ahorro") . "</th>";
             $thOtros = "<th>{$nombre_otro}</th>";
             $tfAhorro = "<th class='mny'>" . getFMoney($SUMAh) . "</th>";
             $tfOtros = "<th class='mny'>" . getFMoney($SUMOtros) . "</th>";
             if ($SUMAh == 0) {
                 $thAhorro = "";
                 $tfAhorro = "";
             }
             if ($SUMOtros == 0) {
                 $thOtros = "";
                 $tfOtros = "";
             }
             $PlanBody .= "<table >\n\t\t\t  <tbody>\n\t\t\t    <tr>\n\t\t\t      <th>" . $xL->getT("TR.Pago") . "</th>\n\t\t\t      <th colspan='2'>" . $xL->getT("TR.Fecha de Pago") . "</th>\n\t\t\t      <th>" . $xL->getT("TR.Capital") . "</th>\n\t\t\t      <th>" . $xL->getT("TR.Interes") . "</th>\n\t\t\t      <th>" . $xL->getT("TR.IVA") . "</th>\n\t\t\t     {$thAhorro}\n\t\t\t      {$thOtros}\n\t\t\t      <th>" . $xL->getT("TR.Total") . "</th>\n\t\t\t      <th>" . $xL->getT("TR.saldo") . "</th>\n\t\t\t    </tr>\n\t\t\t    {$trs}\n\t\t\t    <tr>\n\t\t\t      <td colspan='3'>" . $xL->getT("TR.SUMAS") . "</td>\n\t\t\t      <th class='mny'>" . getFMoney($SUMCap) . "</th>\n\t\t\t      <th class='mny'>" . getFMoney($SUMInt) . "</th>\n\t\t\t      <th class='mny'>" . getFMoney($SUMIva) . "</th>\n\t\t\t      {$tfAhorro}\n\t\t\t      {$tfOtros}\n\t\t\t      <th class='mny'>" . getFMoney($SumTotal) . "</th>\n\t\t\t      <td />\n\t\t\t    </tr>\n\t\t\t  </tbody>\n\t\t\t</table>";
         } else {
             $sqlparc = "SELECT periodo_socio AS 'parcialidad', MAX(fecha_afectacion)\n\t\t\t\t\t\t\t\tAS 'fecha_de_pago', SUM(afectacion_real) AS 'total_parcialidad',\n\t\t\t\t\t\t\t\t MAX(saldo_anterior) AS 'saldo_anterior_', MIN(saldo_actual) AS 'saldo_actual_'\n\t\t\t\t\t\t\t\tFROM operaciones_mvtos\n\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\trecibo_afectado={$idrecibo}\n\t\t\t\t\t\t\tGROUP BY periodo_socio ORDER BY periodo_socio";
             $rs = $xQ->getDataRecord($sqlparc);
             $pi = 1;
             $tp = "";
             $pt = 1;
             $lim = $xQ->getNumberOfRows();
             //si el Limite es mayor a 100, restar 100 y poner
             if ($lim > $this->mLimitPlan * 4) {
                 $this->mLimitPlan = ceil($lim / 4);
             }
             if ($lim < $this->mLimitPlan) {
                 $this->mLimitPlan = ceil($lim / 2);
             }
             $items = 1;
             foreach ($rs as $rw) {
                 $saldo = $rw["saldo_actual_"];
                 $saldo = $saldo < 0 ? 0 : $saldo;
                 $SumTotal += $rw["total_parcialidad"];
                 if ($items == 1) {
                     $this->mFechaPrimeraParc = $rw["fecha_de_pago"];
                 }
                 if ($pi == $this->mLimitPlan or $pt == $lim) {
                     $tp .= "\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td>" . $rw["parcialidad"] . "</td>\n\t\t\t\t\t\t<td>" . $xF->getFechaCorta($rw["fecha_de_pago"]) . "</td>\n\t\t\t\t\t\t<td class='mny'>" . getFMoney($rw["total_parcialidad"]) . "</td>\n\t\t\t\t\t\t<td class='mny'>" . getFMoney($saldo) . "</td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t</tbody>\n\t\t\t\t\t</table>\n\t\t\t\t\t</td>";
                     $pi = 1;
                 } elseif ($pi == 1) {
                     $tp .= "\n\t\t\t\t\t\t<td>\n\n\t\t\t\t\t\t<table class='sector_plan_simplificado'>\n\t\t\t\t\t\t<tbody>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<th>" . $xL->getT("TR.PAGO") . "</th>\n\t\t\t\t\t\t\t<th>" . $xL->getT("TR.Fecha") . "</th>\n\t\t\t\t\t\t\t<th>" . $xL->getT("TR.Monto") . "</th>\n\t\t\t\t\t\t\t<th>" . $xL->getT("TR.Saldo") . "</th>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td>" . $rw["parcialidad"] . "</td>\n\t\t\t\t\t\t\t<td>" . $xF->getFechaCorta($rw["fecha_de_pago"]) . "</td>\n\t\t\t\t\t\t\t<td class='mny'>" . getFMoney($rw["total_parcialidad"]) . "</td>\n\t\t\t\t\t\t\t<td class='mny'>" . getFMoney($saldo) . "</td>\n\t\t\t\t\t\t</tr>";
                     $pi++;
                 } else {
                     $tp .= "\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td>" . $rw["parcialidad"] . "</td>\n\t\t\t\t\t\t\t<td>" . $xF->getFechaCorta($rw["fecha_de_pago"]) . "</td>\n\t\t\t\t\t\t\t<td class='mny'>" . getFMoney($rw["total_parcialidad"]) . "</td>\n\t\t\t\t\t\t\t<td class='mny'>" . getFMoney($saldo) . "</td>\n\t\t\t\t\t\t</tr>";
                     $pi++;
                 }
                 $pt++;
                 $items++;
                 $this->mFechaUltimaParc = $rw["fecha_de_pago"];
             }
             $PlanBody .= "<table class='plan_de_pagos'>\n\t\t\t\t\t\t\t\t<tbody>\n\t\t\t\t\t\t\t\t{$tp}\n\t\t\t\t\t\t\t\t</tbody>\n\t\t\t\t\t\t\t\t<!-- SUMAS -->\n\t\t\t\t\t\t\t\t<tfoot>\n\t\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t\t<td colspan='2'><hr />TOTAL</th>\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t<td  class='mny'><hr />" . getFMoney($SumTotal) . "</th>\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t\t</tfoot>\n\t\t\t\t\t\t\t</table>\n\t\t\t\t\t\t\t";
         }
         //END IF
         $PlanFoot = "<hr />\n\t\t\t<table>\n\t\t\t\t<tr>\n\t\t\t\t\t<td><center>" . $xL->getT("TR.Firma del Solicitante") . "</td>\n\t\t\t\t\t<td><center>" . $xL->getT("TR.Genera el Plan de Pagos") . "</center></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t\t<td><br /><br /><br /> </td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t\t\t<td><center>{$nombre}</center></td>\n\t\t\t\t\t\t<td><center>" . $this->mOficialQueGenera . "</center></td>\n\t\t\t\t</tr>\n\t\t\t\t</table>";
         if ($NoExtend == false) {
             $PlanBody .= "<hr />\n\t\t\t\t\t\t<table>\n\t\t\t\t\t\t  \t<tr>\n\t\t\t\t\t\t    \t<td>" . $xL->getT("TR.Dias Totales") . ":</td>\n\t\t\t\t\t\t    \t<th>{$dias_totales} Dias</th>\n\t\t\t\t\t\t    \t<td>" . $xL->getT("TR.Tasa de Interes") . " :</td>\n\t\t\t\t\t\t    \t<th>{$tasa_interes} %</th>\n\t\t\t\t\t\t    \t<td>" . $xL->getT("TR.Tasa de Ahorro") . " :</td>\n\t\t\t\t\t\t    \t<th>{$tasa_ahorro} %</th>\n\t\t\t\t\t\t    </tr>\n\t\t\t\t\t    </table>\n\t\t\t\t\t\t";
             $PlanBody .= $PlanFoot;
         }
     }
     //End evaluate si es Mas Planes de pagos
     return $PlanBody;
 }
function dia_semana($date)
{
    return getDiaDeLaSemana($date);
}