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/www/ingresar_pago_automatico.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sin t&iacute;tulo</title>
<style type="text/css">
<!--
.Estilo2 {color: #FF6633;
	font-size: 16px;
}
.Estilo3 {color: #2492FF;
	font-weight: bold;
}
.Estilo4 {	color: #D94B3C;
	font-size: 24px;
}
.Estilo51 {	font-size: 22px
}
.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;
}
-->
</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 Estilo51">PAGO AUTOMATICO</div>
      </caption>
      <tr>
        <th colspan="2" scope="col"><label>Seleccione el Archivo a Cargar</label></th>
      </tr>
      <tr>
        <td width="150"><div align="center"><span class="Estilo2">ARHIVO(Excel): </span></div></td>
        <td width="265"><div align="center">
          <input type="file" name="archivo_carga" id="archivo_carga" />
        </div></td>
      </tr>
      <tr>
        <td colspan="2"><div align="center">
          <input type="submit" name="cargar" id="cargar" value="Enviar" />
        </div></td>
      </tr>
      <tr>
        <td colspan="2"><div align="center">
          <input name="menu2" type="button" class="Estilo50" id="menu2" onclick="window.location.href='proveedor_desc.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;

function Conectarse()
	{
	   if (!($link=@mysql_connect("localhost","asjudine","as2006")))
	   {
		  echo "Error conectando con el servidor.";
		  exit();
	   }
	   $dbname = "asjudinet";
	   if (!@mysql_select_db($dbname,$link))
	   {
		  echo "Error seleccionando la base de datos.";
		  exit();
	   }
	   return $link;
	}
	Conectarse();


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');



$data->read($archivo_carga);



error_reporting(E_ALL ^ E_NOTICE);


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


echo "<TABLE width='1000' border='0' align='center' cellpadding='0' cellspacing='1'>
                              <TR>
                              <TD bgcolor='#FFFFCC'><div align='center'><span class='texto'>CEDULA</span></div></TD>
                              <TD bgcolor='#FFFFCC'><div align='center'><span class='texto'>VALOR</span></div></TD>		 
                              <TD bgcolor='#FFFFCC'><div align='center'><span class='texto'>CODIGO </span></div></TD>
                              <TD bgcolor='#FFFFCC'><div align='center'><span class='texto'>UNIDAD</span></div></TD>		 		  
                              <TD bgcolor='#FFFFCC'><div align='center'><span class='texto'>ANOMALIA</span></div></TD>";	
							  
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];			
			

	}

	$mssql = mysql_query('SELECT max(id), codigo, valor , max(cuota) , mes_inicio,  max(ano_inicio), cod_descuento, unidad_descuento, max(fecha_registro) FROM relacion_pagos  WHERE codigo =  "' ."$data2[1]".'" AND tipo_pago = "CRE" GROUP BY codigo ');
			
				if (!$mssql) {
				die('Invalid query jis: ' . mysql_error());
						}
			list($ide, $codi, $valor, $cuota, $mes_inicio, $ano_inicio, $cod_descuento, $unidad_descuento, $regis) =  mysql_fetch_row($mssql);
			
			$num=mysql_num_rows($mssql);
		
		$tota = $tota +1 ;
		
		if ( $num != 0)
			{
			
			  if ($valor == $data2[2])
			  {

			$f1 = explode('-',$fecha_act); 
				$dia1 = $f1[0]; 
				$mes1 = $f1[1]; 
				$ano1 = $f1[2]; 
				
				$f2 = explode('-',$regis); 
				$dia2 = $f2[0]; 
				$mes2 = $f2[1]; 
				$ano2 = $f2[2]; 
	
				$time1 = mktime (0,0,0,$mes1,$dia1,$ano1); 
				$time2 = mktime (0,0,0,$mes2,$dia2,$ano2);
			

					 if( $f1[2] != $f2[2] )
				 {

	
$mssql3 = mysql_query('SELECT * FROM estado_contable  WHERE codigo =  ' . "$data2[1]".' AND tipo_pago = "CRE" ');
			
	$num3=mysql_num_rows($mssql3);
			list($codigo, $saldo_ant , $cuotas_pend , $nuevo_saldo, $cuotas_desc , $fecha_udesc , $proveedor, $tipo_pago ) =  mysql_fetch_row($mssql3);
			

			$ant = $nuevo_saldo ;
			$ant = (int) $ant;
			$nue_sal = $nuevo_saldo - $valor ;
			$nue_sal = (int) $nue_sal;
			$cuo_pen = $cuotas_pend- 1 ; 	
			$cuo_pen = (int) $cuo_pen;
			$cuo_desc = $cuota+ 1 ; 
			$cuo_desc = (int) $cuo_desc;

			$cuota = $cuota + 1 ;
			$cuota = (int) $cuota; 
			
				$regi = $regi + 1;
			if($num>0)
			{
			
			$mssql = mysql_query('SELECT mes_inicio FROM relacion_pagos   WHERE codigo =  ' . "$data2[1]".'  and tipo_pago = "CRE" and id =  ' . "$ide".' ');
			if (!$mssql) {
				die('Invalid query tipi: ' . mysql_error());
						}

			list($mes_inicio) =  mysql_fetch_row($mssql);
			
		
				if($mes_inicio==12 )
				{
					$mes_inicio= 1 ;
					$ano_inicio++;
				}else{
				
					$mes_inicio++;
				}
		
			
		$ter = mysql_query("INSERT INTO relacion_pagos (codigo, valor, cuota, mes_inicio, ano_inicio, cod_descuento,  unidad_descuento, fecha_registro, tipo_pago) VALUES ( '$data2[1]', '$data2[2]', '" ."$cuota". "', '" ."$mes_inicio". "', '" ."$ano_inicio". "', '$data2[3]',  '$data2[4]', '" ."$fecha_act". "', '$data2[5]')");
		if (!$ter) {
				die('Invalid query insert: ' . mysql_error());
						}
	
					
						$upd = mysql_query("UPDATE estado_contable  set  saldo_ant = '" .$ant. "', cuotas_pend = '" .$cuo_pen. "', nuevo_saldo = '" .$nue_sal. "', cuotas_desc = '" .$cuo_desc. "', fecha_udesc = '" .$fecha_act. "'  WHERE codigo = '$data2[1]' and tipo_pago = 'CRE' ");
						if (!$upd) {
				die('Invalid query update: ' . mysql_error());
									}
				
			}
			else
			{
	
			
				$ter2 = mysql_query("INSERT INTO relacion_pagos(codigo, valor, cuota, mes_inicio, ano_inicio, cod_descuento,  unidad_descuento, fecha_registro, tipo_pago) VALUES ('$data2[1]', '$data2[2]', '" . "$cuota". "', '" . "$mes_inicio". "', '" . "$ano_inicio". "', '$data2[3]',  '$data2[4]', '" . "$fecha_act". "', '$data2[5]')");
		if (!$ter2) {
				die('Invalid query insert: ' . mysql_error());
			}
			
						$upd2 = mysql_query("UPDATE estado_contable  set  saldo_ant = '" . $ant. "', cuotas_pend = '" . $cuo_pen. "', nuevo_saldo = '" . $nue_sal. "', cuotas_desc = '" . $cuo_desc. "', fecha_udesc = '" . $fecha_act. "'  WHERE codigo = '$data2[1]' and tipo_pago = 'CRE' ");
						if (!$upd2) {
				die('Invalid query update: ' . mysql_error());
									}
				}
					}
				else
				{
			 printf("<tr>
                                   <td bgcolor='#C5D6FC'><div align='center' class='lista'>".$data2[1]."</span></div></td>
                                   <td bgcolor='#C5D6FC'><div align='center' class='lista'>".$data2[2]."</span></div>
								   <td bgcolor='#C5D6FC'><div align='center' class='lista'>".$data2[3]."</span></div>								   								
		                           <td bgcolor='#C5D6FC'><div align='center' class='lista'>".$data2[4]."</span></div></td>
		                           <TD bgcolor='#C5D6FC'><div align='center'><span class='texto'>CUOTA YA FUE INGRESADA EL DIA DE HOY  </span></div></TD>");    
					}
			
			}
		  else
			{
			printf("<tr>
                                   <td bgcolor='#C5D6FC'><div align='center' class='lista'>".$data2[1]."</span></div></td>
                                   <td bgcolor='#C5D6FC'><div align='center' class='lista'>".$data2[2]."</span></div>
								   <td bgcolor='#C5D6FC'><div align='center' class='lista'>".$data2[3]."</span></div>								   								
		                           <td bgcolor='#C5D6FC'><div align='center' class='lista'>".$data2[4]."</span></div></td>
		                           <TD bgcolor='#C5D6FC'><div align='center'><span class='texto'>VALOR INCORRECTA</span></div></TD>");
			
							  
			}
		}
		else
		{
			 printf("<tr>
                                   <td bgcolor='#C5D6FC'><div align='center' class='lista'>".$data2[1]."</span></div></td>
                                   <td bgcolor='#C5D6FC'><div align='center' class='lista'>".$data2[2]."</span></div>
								   <td bgcolor='#C5D6FC'><div align='center' class='lista'>".$data2[3]."</span></div>								   								
		                           <td bgcolor='#C5D6FC'><div align='center' class='lista'>".$data2[4]."</span></div></td>
		                           <TD bgcolor='#C5D6FC'><div align='center'><span class='texto'>CEDULA INCORRECTA</span></div></TD>");    
		}
		  
			                      
} 

  	  echo "</table>";	
	  echo "$tota";
	  echo "$regi";
echo "<script>alert('Relacion de pago guardada satisfactoriamente');</script>";

}
?>