<?php
//exit;
date_default_timezone_set ( "America/Lima" ); 

define('SF_ROOT_DIR', "/home/invergladi/public_html/gladis");
//define('SF_ROOT_DIR', "C://wamp/www/credisur");
define('SF_APP',      'sys');
require_once(SF_ROOT_DIR.DIRECTORY_SEPARATOR."lib".DIRECTORY_SEPARATOR."functions".DIRECTORY_SEPARATOR."HelperHelper.php");
require_once(SF_ROOT_DIR.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'config.php');
require_once(SF_ROOT_DIR.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'config_core_compile.php');
require_once(SF_ROOT_DIR.DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR.'config_autoload.php');


$con= Conexion::getConexion();
$a_param = Conexion::getParamDbByAlias($apps);

$dia = date('N');

if($dia == 7) exit;
$hoy = date("Y-m-d H:i:s");

if (!mysql_select_db($a_param['db'], $con)) {
    echo 'Could not select database';
    exit;
}


	//Debe ser un 
	//Esta tarea no debe ejecutarse el domingo
	
$sql = "SELECT 	idPrestamo
		FROM 	`cr_prestamo` 
		WHERE 	( PeriodicidadPago = 'S' OR PeriodicidadPago = 'Q')
				and FechaVencimiento < '".$hoy."'
				and estado= 'P'
		";
	
$result = mysql_query($sql,$con);
if(mysql_num_rows($result) > 0 ){
	while($row = mysql_fetch_array($result)){
		
		$idPrestamo 		= $row['idPrestamo'];
		
		$sql = "
    		update cr_prestamo
    		set MoraAcumulada	= DATEDIFF( left('".$hoy."', 10 ),FechaVencimiento ) * 5
    		WHERE  1=1 
    		 and  idPrestamo = '".$idPrestamo."'
	    	";
	   	echo $sql."<br>";
	   	$result_i = mysql_db_query(Conexion::getNameDb(), $sql, $con);
	   	
	   	
		
	}
}

?>