<?php

date_default_timezone_set('America/Lima');

class cHistorial{
	function insertar($fec,$det,$ip,$usu_id,$mod_id,$mod_ide,$doc_id,$numdoc){
		$now =  date('d-m-Y h:i:s a');		
		$sql = "INSERT tb_historial (
			`tb_historial_fec` ,
			`tb_historial_reg`,
			`tb_historial_det`,
			`tb_historial_ip`,
			`tb_usuario_id`,
			`tb_modulo_id`,
			`tb_historial_ide`,
			`tb_documento_id`,
			`tb_historial_numdoc`		
			)
			VALUES (
			 '$fec','$now','$det','$ip','$usu_id','$mod_id','$mod_ide','$doc_id','$numdoc'
			);"; 
		$oCado = new Cado();
		$rst=$oCado->ejecute_sql($sql);
		return $rst;	
	}
	function ultimoInsert(){
		$sql = "SELECT last_insert_id()"; 
		$oCado = new Cado();
		$rst=$oCado->ejecute_sql($sql);
		return $rst;	
	}
	
	function mostrar_filtro($fec1,$fec2,$numdoc,$usu_id){
		$sql="SELECT * FROM tb_historial his
			left join tb_modulo modu on modu.tb_modulo_id = his.tb_modulo_id
			left join tb_usuario usu on usu.tb_usuario_id = his.tb_usuario_id
			left join tb_documento doc on doc.tb_documento_id = his.tb_documento_id
			WHERE his.tb_historial_xac='1' and his.tb_historial_fec BETWEEN  '$fec1' AND '$fec2'
			ORDER BY his.tb_historial_id desc";
			
			if($numdoc!="")$sql.=" AND his.tb_historial_numdoc = '$numdoc' ";
			if($usu_id>0)$sql.=" AND his.tb_usuario_id = '$usu_id' ";
			
		$oCado = new Cado();
		$rst=$oCado->ejecute_sql($sql);
		return $rst;
	}
	
}
?>