Advertisement
patadejaguar

mae.creditos.upload.php

Nov 12th, 2013
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.57 KB | None | 0 0
  1. <?php
  2. /**
  3.  * @see Modulo de Carga de Respaldos a la Matriz
  4.  * @author Balam Gonzalez Luis Humberto
  5.  * @version 1.1
  6.  * @package common
  7.  *  Actualizacion
  8.  *      16/04/2008
  9.  *      2008-06-10 Se Agrego la Linea de Informacion del Actualizacion de Movimeintos y recibos
  10.  *
  11.  */
  12. //=====================================================================================================
  13. //=====>    INICIO_H
  14.     include_once("../core/go.login.inc.php");
  15.     include_once("../core/core.error.inc.php");
  16.     include_once("../core/core.html.inc.php");
  17.     include_once("../core/core.init.inc.php");
  18.     $theFile                    = __FILE__;
  19.     $permiso                    = getSIPAKALPermissions($theFile);
  20.     if($permiso === false){     header ("location:../404.php?i=999");   }
  21.     $_SESSION["current_file"]   = addslashes( $theFile );
  22. //<=====    FIN_H
  23.     $iduser = $_SESSION["log_id"];
  24. //=====================================================================================================
  25.  
  26. $xHP        = new cHPage("Carga de Prestamos MAE", HP_FORM);
  27.  
  28. $oficial        = elusuario($iduser);
  29. ini_set("max_execution_time", 600);
  30.  
  31.  
  32. $action             = (isset($_GET["o"])) ? $_GET["o"] : "x";
  33.  
  34. echo $xHP->getHeader();
  35.  
  36. //$jxc ->drawJavaScript(false, true);
  37. ?>
  38. <body>
  39. <?php
  40. //Si la Operacion es Configurar los Datos
  41. if ( $action == "x" ){
  42. ?>
  43. <form name="frmSendFiles" method="POST" action="mae.prestamos.upload.frm.php?o=u" enctype="multipart/form-data">
  44. <fieldset>
  45.     <legend>|&nbsp;&nbsp;&nbsp;&nbsp;Carga batch de Prestamos&nbsp;&nbsp;&nbsp;&nbsp;|</legend>
  46.     <table>
  47.         <tbody>
  48.         <tr>
  49.             <th colspan="2">ENVIAR ARCHIVO DE PRESTAMOS v 1.01</th>
  50.         </tr>
  51.         <tr>
  52.             <td colspan="2"><input type="file" name="cFile1" size="50" /></td>
  53.         </tr>
  54.         <tr>
  55.             <th colspan="2"><input type="submit" value="Enviar Archivos" /></th>
  56.         </tr>
  57.         </tbody>
  58.     </table>
  59. </fieldset>
  60. </form>
  61. <?php
  62.  
  63. } elseif ( $action ==  "u" ) {
  64. echo '<form name="frmConvs" method="POST" action="mae.prestamos.upload.frm.php?o=s">
  65. <fieldset>
  66.     <legend>Mostrar Resultado de la Carga</legend> ';
  67.  
  68.  
  69. $usrFiles   = array();
  70. $usrFiles[0]    = $_FILES["cFile1"];
  71. $msg            = "";
  72. $arrPeriodos    = array (
  73.     "D" => 10,
  74.     "Q" => 15,
  75.     "C" => 14,
  76.     "S" => 7,
  77.     "M" => 30,
  78.     "" => 30,
  79.     "F" => 360
  80. );
  81.  
  82. $prePath        = PATH_BACKUPS;
  83. $lim            = 1; //sizeof($usrFiles) -1;
  84.  
  85. for($i=0; $i<=$lim; $i++){
  86. if(isset($usrFiles[$i])==true){
  87.     //Obtener Extension
  88.     $DExt   = explode(".", substr($usrFiles[$i]['name'], -6));
  89.     $mExt   = $DExt[1];
  90.  
  91.     if($mExt == "csv"){
  92.         $completePath   = $prePath . $usrFiles[$i]['name'];
  93.         if(file_exists($completePath)==true){
  94.             unlink($completePath);
  95.             echo "<p class='aviso'> SE ELIMINO EL ARCHIVO " . $usrFiles[$i]['name'] . "</p>";
  96.         }
  97.         if(move_uploaded_file($usrFiles[$i]['tmp_name'], $completePath )) {
  98.             //echo "<p class='aviso'> SE GUARDO EXITOSAMENTE EL ARCHIVO " . $usrFiles[$i]['name'] . "</p>";
  99.         } else {
  100.             //echo "<p class='aviso'> SE FALLO AL GUARDAR " . $usrFiles[$i]['name'] . "</p>";
  101.         }
  102.         //analizar el Archivo
  103.         $gestor = @fopen($completePath, "r");
  104.  
  105.         $iReg   = 0;
  106.         $cT     = new cTipos();
  107.         //inicializa el LOG del proceso
  108.         $aliasFil   = getSucursal() . "-carga -batch-de-creditos-" . fechasys();
  109.         $xLog       = new cFileLog($aliasFil, true);
  110.         if ($gestor) {
  111.             while (!feof($gestor)) {
  112.                 $bufer          = fgets($gestor, 4096);
  113.                 //$bufer            = stream_get_line($gestor, "\r\n");
  114.                 if (!isset($bufer) ){
  115.                     $msg .= "$iReg\t\tERROR\tLa Linea($iReg) no se leyo($bufer)\r\n";
  116.                 } else {
  117.                     $bufer              = trim($bufer);
  118.                     $datos              = explode(",", $bufer, 18);
  119.                     $xF             = new cFecha();
  120.                    
  121.                     $socio              = $cT->cInt($datos[1]);
  122.                     $credito            = false; //$cT->cInt($datos[1]);
  123.                     $producto           = 200;//DEFAULT_TIPO_CONVENIO; // $cT->cInt($datos[2]);//200 Simple
  124.                     $monto              = $cT->cFloat($datos[8]);
  125.                     $periocidad         = $cT->cInt( $arrPeriodos[trim($datos[7])] );
  126.                     $pagos              = $cT->cInt($datos[6]);
  127.                     $ministracion           = $xF->getFechaISO($datos[10]);
  128.                     $fechaSolicitado        = $xF->getFechaISO($datos[5]);
  129.                     $descDestino            = $cT->cChar($datos[9]);
  130.                    
  131.                     $tasa               = $cT->cFloat($datos[15]);
  132.                     $tasa               = $tasa /100;
  133.                    
  134.                     $dias               = $periocidad * $pagos;
  135.                     $aplicacion         = ($cT->cChar($datos[17]) == "S") ? 501 : 100;
  136.                    
  137.                     $vencimiento            = $xF->setSumarDias($dias, $ministracion); //$cT->cFecha($datos[5]);
  138.                                                        
  139.                     $saldo              = $cT->cFloat($datos[11]);
  140.                     $UltimaOperacion        = fechasys(); //$cT->cFecha($datos[9]);
  141.                     $ContratoCorriente      = CTA_GLOBAL_CORRIENTE; //$cT->cInt($datos[10]);
  142.                     //Eliminar créditos anteriores
  143.                     $Creds              = new cCreditos_solicitud();
  144.                     $rs             = $Creds->query()->select()->exec("numero_socio=$socio");
  145.                     foreach($rs as $data){
  146.                         /*$Creds->setData($data);
  147.                         $solicitud  = $Creds->numero_solicitud()->v();
  148.                         $socio      = $Creds->numero_socio()->v();
  149.                         $xCred      = new cCredito($solicitud, $socio);
  150.                         $msg        .= $xCred->setDelete();*/
  151.                     }
  152.                     if($socio == 0){
  153.                         $msg .= "$iReg\t\tERROR\tLa Linea($iReg) no se leyo($bufer)\r\n";
  154.                     } else {
  155.                         $sqls           = "UPDATE socios_general SET dependencia=" . DEFAULT_EMPRESA . " WHERE codigo=$socio";
  156.                         my_query($sqls);
  157.                        
  158.                         $xCred              = new cCredito();
  159.                         $xConv              = new cProductoDeCredito($producto); $xConv->init();
  160.                         //Crear Contrato corriente si el producto tiene ahorro
  161.                         $DConv              = $xCred->getDatosDeProducto($producto);
  162.                         $tasaAhorro         = $xConv->getTasaDeAhorro(); // $cT->cFloat( $DConv["tasa_ahorro"] );
  163.                         if($ContratoCorriente == 0 AND $tasaAhorro > 0){
  164.                             /*$xCapta               = new cCuentaALaVista(false);
  165.                             $ContratoCorriente  = $xCapta->setNuevaCuenta(99, DEFAULT_SUBPRODUCTO_CAPTACION, $socio, "CUENTA POR IMPORTACION", $credito);
  166.                             $msg            .= "$iReg\t$socio\t$credito\tAgregando una Cuenta Corriente $ContratoCorriente NUEVO\r\n";*/
  167.                         }
  168.                         //Agregar
  169.                         $msg .= "$iReg\t$socio\t$credito\t-----------------------------------------\r\n";
  170.                         $ok  = $xCred->add($producto, $socio, $ContratoCorriente, $monto, $periocidad, $pagos, $dias, $aplicacion, $credito,
  171.                                 DEFAULT_GRUPO, $descDestino, "CREDITO IMPORTADO #$iReg", DEFAULT_USER, $fechaSolicitado,
  172.                                 CREDITO_TIPO_PAGO_PERIODICO,INTERES_POR_SALDO_INSOLUTO, $tasa);
  173.                         if($ok == true){
  174.                             ///Inicializar
  175.                             //autorizar
  176.                             $xCred->setAutorizado($monto, $pagos, $periocidad, CREDITO_TIPO_AUTORIZACION_AUTOMATICA, $ministracion,
  177.                             "CREDITO IMPORTADO #$iReg", false, $ministracion,2, false,
  178.                             $vencimiento, CREDITO_ESTADO_AUTORIZADO, $monto, 0, $UltimaOperacion);
  179.                             $xCred->init();
  180.                             //ministrar
  181.                             $xCred->setForceMinistracion();
  182.                             $xCred->setMinistrar(DEFAULT_RECIBO_FISCAL, DEFAULT_CHEQUE, $monto, DEFAULT_CUENTA_BANCARIA, 0, DEFAULT_CUENTA_BANCARIA, "CREDITO IMPORTADO #$iReg", $ministracion);
  183.                            
  184.                             if( $monto > $saldo ){
  185.                                 $abono  = ($monto - $saldo);
  186.                                 $msg    .= "$iReg\t$socio\t$credito\tAgregando un Abono por $abono por el Saldo $saldo del Monto $monto\r\n";
  187.                                 $xCred->setAbonoCapital($abono, 1, DEFAULT_CHEQUE, DEFAULT_RECIBO_FISCAL,
  188.                                 "CREDITO IMPORTADO #$iReg", DEFAULT_GRUPO, $UltimaOperacion);
  189.                             }
  190.                         } else {
  191.                             $msg .= "$iReg\t$socio\t$credito\tEL Credito no se pudo agregar\r\n";
  192.                         }
  193.                         $msg        .= $xCred->getMessages("txt");
  194.                     }
  195.                 }
  196.             $iReg++;
  197.             }
  198.         }
  199.         @fclose ($gestor);
  200.         $xLog->setWrite($msg);
  201.         echo $xLog->getLinkDownload("Archivo del proceso");
  202.     }   else {
  203.         echo "<p class='aviso'>EL TIPO DE ARCHIVO DE " . $usrFiles[$i]['name'] . "(" .$mExt . ") NO SE ACEPTA</p>";
  204.     }
  205. }
  206. }
  207. echo "</fieldset>
  208. </form> ";
  209. }
  210. if ( !isset($iReg) ){
  211.     $iReg   = 0;
  212.  
  213. }
  214. ?>
  215.  
  216. </body>
  217. <script >
  218. </script>
  219. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement