<?php
date_default_timezone_set('America/Lima');
class cCajagestion{
	function insertar($fec,$tip,$efe,$tradep,$yap,$plin,$usu_id){
		$now =  date('Y-m-d h:i:s a');
		$sql = "INSERT INTO  tb_cajagestion(
		tb_cajagestion_fecreg ,
		tb_cajagestion_fec ,
		tb_cajagestion_tip ,
		tb_cajagestion_efe ,
		tb_cajagestion_deptra ,
		tb_cajagestion_yap ,
		tb_cajagestion_pli ,
		tb_usuario_id
		)
		VALUES ('$now','$fec','$tip','$efe','$tradep','$yap','$plin','$usu_id');"; 
		//echo $sql;exit;
		$oCado = new Cado();
		$rst=$oCado->ejecute_sql($sql);
		return $rst;	
	}
	function ultimoInsert(){
		$sql = "select max(tb_cajagestion_id) as 'id' from tb_cajagestion "; 
		$oCado = new Cado();
		$rst=$oCado->ejecute_sql($sql);
		return $rst;	
	}
	
		function modificar($id,$efe,$tradep,$yap,$plin){
			$now =  date('Y-m-d h:i:s a');
			$sql = "UPDATE tb_cajagestion SET
			tb_cajagestion_efe = '$efe' ,
			tb_cajagestion_deptra = '$tradep',
			tb_cajagestion_yap =  '$yap',
			tb_cajagestion_pli = '$plin'
			WHERE tb_cajagestion_id = '$id' "; 
			$oCado = new Cado();
			$rst=$oCado->ejecute_sql($sql);
			return $rst;	
		}
	function mostrar_filtro($fec1,$fec2,$usu_id){
		$sql="SELECT * 
		FROM tb_cajagestion cg
		LEFT JOIN tb_usuario u ON cg.tb_usuario_id=u.tb_usuario_id
		WHERE cg.tb_cajagestion_xac=1
		AND cg.tb_cajagestion_fec BETWEEN '$fec1' AND '$fec2' ";
		
		if($usu_id!=''){
			$sql = $sql." AND cg.tb_usuario_id = '$usu_id' ";
		}
		
		$sql = $sql." ORDER BY cg.tb_cajagestion_fec ";
		//echo $sql;exit;
		$oCado = new Cado();
		$rst=$oCado->ejecute_sql($sql);
		return $rst;
	}
	
	function mostrarUno($id){
		$sql="SELECT * FROM tb_cajagestion cg
		LEFT JOIN tb_usuario u ON cg.tb_usuario_id=u.tb_usuario_id
		WHERE cg.tb_cajagestion_id= '$id' "; 
		$oCado = new Cado();
		$rst=$oCado->ejecute_sql($sql);
		return $rst;
	}
	
	
		function mostrarUno2($usu_id,$tip,$fec){
		$sql="SELECT * FROM tb_cajagestion cg
		LEFT JOIN tb_usuario u ON cg.tb_usuario_id=u.tb_usuario_id
		WHERE cg.tb_usuario_id= '$usu_id' and cg.tb_cajagestion_tip = '$tip' and cg.tb_cajagestion_fec = '$fec' "; 
		$oCado = new Cado();
		$rst=$oCado->ejecute_sql($sql);
		return $rst;
	}
	
	
	
	function modificar_campo($id,$campo,$valor){
		$now =  date('Y-m-d h:i:s a');
		$sql = "UPDATE tb_cajagestion SET
		tb_cajagestion_$campo =  '$valor' 
		WHERE tb_cajagestion_id =$id;"; 
		$oCado = new Cado();
		$rst=$oCado->ejecute_sql($sql);
		return $rst;	
	}
	
	
	
	
	function consultaventacierre($usu_id,$punven_id,$tip,$ban_id,$fec1){
		$sql="SELECT sum(i.tb_ingreso_imp) as 'total' from tb_ingreso i 
		inner join tb_caja cj on cj.tb_caja_id = i.tb_caja_id
		where i.tb_ingreso_xac = '1'   and i.tb_ingreso_fec = '$fec1' ";
		
		
		if($usu_id!="") $sql.= "  and i.tb_ingreso_usureg = '$usu_id' ";
		if($punven_id!="") $sql.= " and cj.tb_puntoventa_id = '$punven_id' ";
		if($tip!="") $sql.= "and cj.tb_caja_tip = '$tip' ";
		if($ban_id!="") $sql.= " and cj.tb_banco_id='$ban_id'";
		
		$oCado = new Cado();
		$rst=$oCado->ejecute_sql($sql);
		return $rst;
	}
	
	
	
}
?>