MOON
Server: Apache/2.2.34 (Unix) mod_ssl/2.2.34 OpenSSL/0.9.8e-fips-rhel5 mod_bwlimited/1.4 FrontPage/5.0.2.2635
System: Linux server.asjudinet.com 2.6.32-042stab141.3 #1 SMP Fri Nov 15 22:45:34 MSK 2019 i686
User: asjudine (504)
PHP: 5.2.17
Disabled: NONE
Upload Files
File: /home/asjudine/public_html/credito_rotativo_cargar_automatico_mc.php
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Cargar automatico Credito</title>
<style type="text/css">
/*
<!--
.Estilo2 {color: #0000CC;
	font-size: 16px;
}
.Estilo3 {color: #2492FF;
	font-weight: bold;
}
.Estilo4 {
	color: #003300;
	font-size: 18px;
	font-family: Georgia, "Times New Roman", Times, serif;
}
.recaudo {font-family: "Courier New", Courier, monospace;
	font-size: 12px;
	font-style: normal;
	font-weight: bold;
	font-variant: normal;
	color: #000000;
	background-color: #B6CBDC;
	margin: 4px;
	padding: 8px;
	width: auto;
	border: medium outset #339966;
}
.Estilo50 {color: #CC3333;
	font-family: "Arial Narrow";
	font-weight: bold;
}
.Estilo53 {font-family: "Courier New", Courier, monospace}
-->
*/
</style>
</head>

<body>
<form action="" method="post" enctype="multipart/form-data" name="form1" id="form1">
  <label> </label>
  <div align="center">
    <table width="448" border="3" cellpadding="3" cellspacing="3" class="recaudo">
      <caption>
      <div align="center" class="Estilo4 ">PAGO AUTOMATICO CREDITO</div>
      </caption>
      <tr>
        <th colspan="2" bgcolor="#E0FEF3" scope="col"><label><span class="Estilo53">Seleccione el Archivo a Cargar</span></label></th>
      </tr>
      <tr>
        <td width="150" bgcolor="#E0FEF3"><div align="center"><span class="Estilo2">ARHIVO(Excel): </span></div></td>
        <td width="265" bgcolor="#E0FEF3"><div align="center">
          <input type="file" name="archivo_carga" id="archivo_carga" />
        </div></td>
      </tr>
      <tr>
	    <td bgcolor="#E0FEF3"  align="center">Fecha Nomina:
        
              <input name="fecha_nom" type="text" class="est_cont2" id="fecha_nom" value="0000-00-00" size="12" maxlength="12" />
        </td>
        <td colspan="2" bgcolor="#E0FEF3"><div align="center">
          <input name="cargar" type="submit" class="Estilo3" id="cargar" value="Enviar" />
        </div></td>
      </tr>
      <tr>
        <td colspan="2" bgcolor="#E0FEF3"><div align="center">
          <input name="menu2" type="button" class="Estilo50" id="menu2" onclick="window.location.href='menu_creditos_serviasjudinet.php'" value="IR AL MENU" />
        </div></td>
      </tr>
    </table>
  </div>
  <label><br />
  </label>
  <p>
    <label></label>
  </p>
</form>
<p>&nbsp;</p>
</body>
</html>



<?php 
    require_once("mainfile.php");
    include ("config.php");
    global $dbi;

    require_once("Conectarse.php");
    $valorinconsistencias=0;
    $valorcargue=0;
    $tota = 0 ;
    $regi = 0;
    $total = 0 ;
    $tere = 0;


if(isset($_POST["cargar"]))
{
        // Test CVS
        require_once 'Excel/reader.php';


        // ExcelFile($filename, $encoding);
        $data = new Spreadsheet_Excel_Reader();


        // Set output Encoding.
        $data->setOutputEncoding('CP1251');

        $archivo = $_FILES["archivo_carga"]["tmp_name"];

        $data->read($archivo);



        error_reporting(E_ALL ^ E_NOTICE);


        $fecha_act=date ( "Y-n-j" );

							  
?>
	<table width="700" border="0" cellspacing="2" cellpadding="2" align = "center">
		<tr align="center"> 
	  		<td colspan="6">
	  			<font face="Georgia, Times New Roman, Times, serif" color="#006600">
	  				<b align = "center">PAGOS EFECTUADOS</b>
	  			</font>
	  		</td>
		</tr>

		<tr align="center" bgcolor="#DDDDDD"> 
			<td width="90" align="center">
				<font face="Geneva, Arial, Helvetica, san-serif" size="2" color="#000099">CEDULA</font>
			</td>
		    <td bgcolor="#DDDDDD" width="250" >
		    	<font face="Geneva, Arial, Helvetica, san-serif" size="2" color="#000099">NOMBRE</font>
		    </td>
		    <td width="100">
		    	<font face="Geneva, Arial, Helvetica, san-serif" size="2" color="#000099"  align="center">VALOR</font>
		    </td>
			<td width="300">
				<font face="Geneva, Arial, Helvetica, san-serif" size="2" color="#000099"  align="center">ANOMALIA</font>
			</td>
		</tr>
<?php							  
	$total_subidos = 0;
	$dis = date("d");
	$mes = date("m");
	$anos = date("Y");	
	$fechar = $anos.'-'.$mes.'-'.$dis;
	  
	for ($i = 1; $i <= $data->sheets[0]['numRows'] ; $i++) 
	{
		for ($j = 1; $j <=5; $j++) 
		{
			//echo "\"".$data->sheets[0]['cells'][$i][$j]."\",";
			$data2[$j]=$data->sheets[0]['cells'][$i][$j];			
		}		
        $tota++;
        $CEDULA          = $data2[1];
        $CUOTA 	         = $data2[3];
        $NOMBRE          = $data2[2];
        $CODIG_DESCUENTO = $data2[4];
        $UNIDAD_DESCUENTO= $data2[5];

        $FECHA 	= $_POST['fecha_nom'];

        $CONSULTA = mysql_query("SELECT cedula, nombre, credito_libranza, unidad_descuento, codigo_descuento, cuotas_credito, valor_cuota, fecha_ultimo_descuento, mes_inicio, ano_inicio, saldo_anterior, cuotas_pendientes, cuotas_descontadas, saldo_nuevo FROM credito_rotativo_inter WHERE cedula = '".$CEDULA."' and estado = '1' ");
        if ($CONSULTA) 
        {
            if ((mysql_num_rows($CONSULTA)!=0)) 
            {
                $Consulta_Estado_contable = mysql_query("SELECT valor_cuota FROM  credito_rotativo_estado_contable WHERE cedula = '".$CEDULA."' ORDER BY id DESC LIMIT 1 ");

                if ($Consulta_Estado_contable) 
                {
                    if ((mysql_num_rows($Consulta_Estado_contable)!=0)) 
                    {
                        list($maxcuotaa) = mysql_fetch_row($Consulta_Estado_contable);

                        if($maxcuotaa != $CUOTA)
                        {
                            $ANOMALIA = "CUOTA DIFERENTE";
                            $COLOR_ANOMALIA = 'orange';
                            $total_anomalia++;
                        }
                        else
                        {
                            $CONSULTA_cuota = mysql_query("SELECT valor_cuota,fecha_nomina FROM credito_rotativo_estado_contable WHERE cedula = '".$CEDULA."' AND fecha_nomina = '".$FECHA."' AND valor_cuota = '".$CUOTA."'  ");

                            if ($CONSULTA_cuota) 
                            {
                                if ((mysql_num_rows($CONSULTA_cuota)!=0)) 
                                {
                                    $ANOMALIA = "CUOTA YA SUBIDA";
                                    $COLOR_ANOMALIA = 'yellow';
                                }
                                else
                                {
                                    $CONSULTA_exist_cuota = mysql_query("SELECT cedula, nombre, credito_libranza, numero_cuota, mes_cuota, ano_cuota, valor_cuota, fecha_nomina, fecha_registro, codigo_descuento, unidad_descuento FROM credito_rotativo_estado_contable WHERE cedula = '".$CEDULA."' ORDER BY id DESC LIMIT 1 ");

                                    if ($CONSULTA_exist_cuota) 
                                    {
                                        if ((mysql_num_rows($CONSULTA_exist_cuota)!=0)) 
                                        {
                                            list($cedula, $nombre, $credito_libranza, $numero_cuota, $mes_cuota, $ano_cuota, $valor_cuota, $fecha_nomina, $fecha_registro, $codigo_descuento, $unidad_descuento) = mysql_fetch_row($CONSULTA_exist_cuota);

                                            $numero_cuota++;
                                            $mes_cuota++;

                                            if($mes_cuota > 12)
                                            {
                                                $mes_cuota = 1;
                                                $ano_cuota ++;
                                            }
                                            $insertar_CUOTA = mysql_query("INSERT INTO credito_rotativo_estado_contable (cedula, nombre, credito_libranza, numero_cuota,  mes_cuota, ano_cuota, valor_cuota, fecha_registro, fecha_nomina, codigo_descuento, unidad_descuento) VALUES ('".$cedula."', '".$nombre."', '".$credito_libranza."','".$numero_cuota."', '".$mes_cuota."','".$ano_cuota."','".$CUOTA."', NOW(),'".$FECHA."', '".$CODIG_DESCUENTO."', '".$UNIDAD_DESCUENTO."') ");

                                            if ($insertar_CUOTA) 
                                            {
                                                $CONSULTA10 = mysql_query("SELECT cedula, nombre, credito_libranza, unidad_descuento, codigo_descuento, cuotas_credito, valor_cuota, fecha_ultimo_descuento, mes_inicio, ano_inicio, saldo_anterior, cuotas_pendientes, cuotas_descontadas, saldo_nuevo FROM credito_rotativo_inter WHERE cedula = '".$CEDULA."' ");

                                                if ($CONSULTA10) 
                                                {
                                                    if ((mysql_num_rows($CONSULTA10)!=0)) 
                                                    {
                                                        list($cedula, $nombre, $credito_libranza, $unidad_descuento, $codigo_descuento, $cuotas_credito, $valor_cuota, $fecha_ultimo_descuento, $mes_inicio, $ano_inicio, $saldo_anterior, $cuotas_pendientes, $cuotas_descontadas, $saldo_nuevo) = mysql_fetch_row($CONSULTA10);
                                                    }
                                                    $SALDO_ANTERIOR = $saldo_nuevo;
                                                    $CUOTAS_PEND = (number_format($cuotas_pendientes) - 1);
                                                    $CUOTAS_DESCON = (number_format($cuotas_descontadas) + 1);
                                                    $SALDO_NUEVO = $saldo_anterior - $CUOTA;

                                                    $modif_inter3 =  mysql_query("UPDATE credito_rotativo_inter SET fecha_ultimo_descuento = '".$FECHA."', saldo_anterior = '".$SALDO_ANTERIOR."', cuotas_pendientes = '".$CUOTAS_PEND."', cuotas_descontadas = '".$CUOTAS_DESCON."', saldo_nuevo = '".$SALDO_NUEVO."' WHERE cedula = '".$cedula."' ");
                                                    if ($modif_inter3) 
                                                    {
                                                        $ANOMALIA = "CUOTA SUBIDA CON EXITO";	
                                                        $COLOR_ANOMALIA = 'green';
                                                        $total_subidos++;
                                                    }
                                                    else
                                                    {

                                                        $CONSULTA6 = mysql_query("SELECT cedula, nombre, credito_libranza, unidad_descuento, codigo_descuento, cuotas_credito, valor_cuota, fecha_ultimo_descuento, mes_inicio, ano_inicio, saldo_anterior, cuotas_pendientes, cuotas_descontadas, saldo_nuevo FROM credito_rotativo_inter WHERE cedula = '".$CEDULA."' ");

                                                        if ($CONSULTA6)
                                                        {
                                                            if ((mysql_num_rows($CONSULTA6)!=0)) 
                                                            {
                                                                list($cedula, $nombre, $credito_libranza, $unidad_descuento, $codigo_descuento, $cuotas_credito, $valor_cuota, $fecha_ultimo_descuento, $mes_inicio, $ano_inicio, $saldo_anterior, $cuotas_pendientes, $cuotas_descontadas, $saldo_nuevo) = mysql_fetch_row($CONSULTA6);

                                                                $Insertar_cuota_NUEVA = mysql_query("INSERT INTO credito_rotativo_estado_contable (cedula, nombre, credito_libranza, numero_cuota,  mes_cuota, ano_cuota, valor_cuota, fecha_registro, fecha_nomina, codigo_descuento, unidad_descuento) VALUES('".$cedula."','".$nombre."','".$credito_libranza."','1','".$mes_inicio."','".$ano_inicio."','".$CUOTA."',NOW(),'".$FECHA."','".$CODIG_DESCUENTO."','".$UNIDAD_DESCUENTO."' )");

                                                                if ($Insertar_cuota_NUEVA)
                                                                {
                                                                    $CONSULTA7 = mysql_query("SELECT cedula, nombre, credito_libranza, unidad_descuento, codigo_descuento, cuotas_credito, valor_cuota, fecha_ultimo_descuento, mes_inicio, ano_inicio, saldo_anterior, cuotas_pendientes, cuotas_descontadas, saldo_nuevo FROM credito_rotativo_inter WHERE cedula = '".$CEDULA."' ");

                                                                    if ($CONSULTA7)
                                                                    {
                                                                        if ((mysql_num_rows($CONSULTA7)!=0)) 
                                                                        {
                                                                            list($cedula, $nombre, $credito_libranza, $unidad_descuento, $codigo_descuento, $cuotas_credito, $valor_cuota, $fecha_ultimo_descuento, $mes_inicio, $ano_inicio, $saldo_anterior, $cuotas_pendientes, $cuotas_descontadas, $saldo_nuevo) = mysql_fetch_row($CONSULTA7);
                                                                        }
                                                                    }
                                                                }

                                                                $SALDO_ANTERIOR = $saldo_nuevo;
                                                                $CUOTAS_PEND = (number_format($cuotas_pendientes) - 1);
                                                                $CUOTAS_DESCON = (number_format($cuotas_descontadas) + 1);
                                                                $SALDO_NUEVO = $saldo_anterior - $CUOTA;

                                                                $modif_inter = mysql_query("UPDATE credito_rotativo_inter SET fecha_ultimo_descuento = '".$FECHA."', saldo_anterior = '".$SALDO_ANTERIOR."', cuotas_pendientes = '".$CUOTAS_PEND."', cuotas_descontadas = '".$CUOTAS_DESCON."', saldo_nuevo = '".$SALDO_NUEVO."' WHERE cedula = '".$cedula."' ");

                                                                if ($modif_inter)
                                                                {
                                                                    $ANOMALIA = "CUOTA SUBIDA CON EXITO";	
                                                                    $COLOR_ANOMALIA = 'green';
                                                                    $total_subidos++;
                                                                }

                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                       $CONSULTA5 = mysql_query("SELECT cedula, nombre, credito_libranza, unidad_descuento, codigo_descuento, cuotas_credito, valor_cuota, fecha_ultimo_descuento, mes_inicio, ano_inicio, saldo_anterior, cuotas_pendientes, cuotas_descontadas, saldo_nuevo FROM credito_rotativo_inter WHERE cedula = '".$CEDULA."'  ");
                        if ($CONSULTA5)
                        {
                            if ((mysql_num_rows($CONSULTA5)!=0)) 
                            {
                                list($cedula, $nombre, $credito_libranza, $unidad_descuento, $codigo_descuento, $cuotas_credito, $valor_cuota, $fecha_ultimo_descuento, $mes_inicio, $ano_inicio, $saldo_anterior, $cuotas_pendientes, $cuotas_descontadas, $saldo_nuevo) = mysql_fetch_row($CONSULTA5);

                                $Insertar_cuota_NUEVA = mysql_query("INSERT INTO credito_rotativo_estado_contable (cedula, nombre, credito_libranza, numero_cuota,  mes_cuota, ano_cuota, valor_cuota, fecha_registro, fecha_nomina, codigo_descuento, unidad_descuento) VALUES('".$CEDULA."','".$NOMBRE."','".$credito_libranza."','1','".$mes_inicio."','".$ano_inicio."','".$CUOTA."',NOW(),'".$FECHA."','".$CODIG_DESCUENTO."','".$UNIDAD_DESCUENTO."' )");
                                
                                if ($Insertar_cuota_NUEVA)
                                {
                                    $CONSULTA8 = mysql_query("SELECT cedula, nombre, credito_libranza, unidad_descuento, codigo_descuento, cuotas_credito, valor_cuota, fecha_ultimo_descuento, mes_inicio, ano_inicio, saldo_anterior, cuotas_pendientes, cuotas_descontadas, saldo_nuevo FROM credito_rotativo_inter WHERE cedula = '".$CEDULA."' ");
										       		
                                    if ($CONSULTA8)
                                    {
                                        if ((mysql_num_rows($CONSULTA8)!=0)) 
                                        {
                                            list($cedula, $nombre, $credito_libranza, $unidad_descuento, $codigo_descuento, $cuotas_credito, $valor_cuota, $fecha_ultimo_descuento, $mes_inicio, $ano_inicio, $saldo_anterior, $cuotas_pendientes, $cuotas_descontadas, $saldo_nuevo) = mysql_fetch_row($CONSULTA8);
                                        }
                                    }

                                    $SALDO_ANTERIOR = $saldo_nuevo;
                                    $CUOTAS_PEND = (number_format($cuotas_pendientes) - 1);
                                    $CUOTAS_DESCON = (number_format($cuotas_descontadas) + 1);
                                    $SALDO_NUEVO = $saldo_anterior - $CUOTA;

                                    $modif_inter2 = mysql_query("UPDATE credito_rotativo_inter SET fecha_ultimo_descuento = '".$FECHA."', saldo_anterior = '".$SALDO_ANTERIOR."', cuotas_pendientes = '".$CUOTAS_PEND."', cuotas_descontadas = '".$CUOTAS_DESCON."', saldo_nuevo = '".$SALDO_NUEVO."' WHERE cedula = '".$CEDULA."' ");

                                    if ($modif_inter2)
                                    {
                                        $ANOMALIA = "CUOTA SUBIDA CON EXITO";
                                        $COLOR_ANOMALIA = 'green';	
                                        $total_subidos++;
                                    }	
									    
								}
                            }
                        }
                    }
                }
            }
            else
            {
                $ANOMALIA = "HISTORICO";
		   		$COLOR_ANOMALIA = 'red';   
                $total_anomalia++;
            }
        }
        else
        {
            die('Invalid query ultimo: ' . mysql_error());    
        } 
        echo "<td><b>".$CEDULA."</b></td>";
        echo "<td><b>".$NOMBRE."</b></td>";
        echo "<td><b>".$CUOTA."</b></td>";
        echo "<td><b>".$ANOMALIA."</b></td>";
        echo "</tr>";
    } 
?> 
</table>
	  							  
<table width="300" border="0" cellspacing="2" cellpadding="2" align = "center">
	<tr align="center"> 
    	<td colspan="4">
    		<font face="Georgia, Times New Roman, Times, serif" color="#FF0000">
    			<b align = "center">INFORME DE REGISTROS</b>
    		</font>
    	</td>
	</tr>
	<tr align="center" bgcolor="#DDDDDD"> 
	    <td width="200" align="center">
	    	<font face="Geneva, Arial, Helvetica, san-serif" size="2" color="#000099">
	    		N° Archivos Subidos
	    	</font>
	    </td>
	    <td bgcolor="#DDDDDD" width="300" >
	    	<font face="Geneva, Arial, Helvetica, san-serif" size="2" color="#000099">
	    		N° Inconsistencias
	    	</font>
	    </td>
	    <td width="150">
	    	<font face="Geneva, Arial, Helvetica, san-serif" size="2" color="#000099"  align="center">
	    		Total de Registros
	    	</font>
	    </td>
	</tr>	


	<tr align='center' bgcolor='#f4f4f4'>
		<td width='300'>
			<font face='Geneva, Arial, Helvetica, san-serif' size='2' color='#993300'>
				<?php echo $total_subidos;?>
			</font>
		</td>
		<td width='300'> 
			<font face='Geneva, Arial, Helvetica, san-serif' size='2' color='#993300'>
				<?php echo $total_anomalia;?>
			</font>
		</td>
		<td width='300'>
			<font face='Geneva, Arial, Helvetica, san-serif' size='2' color='#993300'>
				<?php echo $tota;?>
			</font>
		</td>
	</tr>

</table>	
<?php
}
?>