<?php

require_once("DF80000.php");

class dgreQdev{
	var  $tabla = '0';
	var  $fol_ven = '0';
	var  $tip_ven = '0';
	var  $folio_control = '0';
	var  $fec_ven = '0';
	var  $cod_cli = '0';
	var  $por_des = '0';
	var  $alm_gen = '0';
	var  $sub_ven = '0';
	var  $iva_ven = '0';
	var  $tot_ven = '0';
	var  $oper = '0';
	var  $paso = '0';
	var  $facturado = '0';
	var  $iva_des = '0';
	var  $cod_ven = '0';
	var  $cancelado = '0';
	var  $fec_can = '0';
	var  $acc_fec = '0';
	var  $acc_hor = '0';
	var  $usuario = '0';
	var  $trefe = '0';
	var  $mes = '0';
	var  $ano = '0';
	var  $lastInsId = '0';
	
	function dgreQdev($data){
		$this->tabla='dgreqdev';
		$this->resetData($data);
	}

	function resetData($data){
		$this->fol_ven=$this->checkData($data['folVen'],'');
		$this->tip_ven=$this->checkData($data['tipVen'],'');
		$this->folio_control=$this->checkData($data['fconTrol'],'');
		$this->fec_ven=$this->checkData($data['fecVen'],'');
		$this->cod_cli=$this->checkData($data['codCli'],'');
		$this->por_des=$this->checkData($data['porDes'],'');
		$this->alm_gen=$this->checkData($data['almGen'],'');
		$this->sub_ven=$this->checkData($data['subVen'],'');
		$this->iva_ven=$this->checkData($data['ivaVen'],'');
		$this->tot_ven=$this->checkData($data['totVen'],'');
		$this->oper=$this->checkData($data['opeR'],'');
		$this->paso=$this->checkData($data['pasO'],'');
		$this->facturado=$this->checkData($data['facTurAdo'],'');
		$this->iva_des=$this->checkData($data['ivaDes'],'');
		$this->cod_ven=$this->checkData($data['codVen'],'');
		$this->cancelado=$this->checkData($data['canCelaDo'],'');
		$this->fec_can=$this->checkData($data['fecCan'],'');		
		$this->acc_fec=$this->checkData($data['accFec'],'');
		$this->acc_hor=$this->checkData($data['accHor'],'');
		$this->usuario=$this->checkData($data['usuArio'],'');
		$this->trefe=$this->checkData($data['treFe'],'');
		$this->mes=$this->checkData($data['meS'],'');
		$this->ano=$this->checkData($data['anO'],'');
	}

	function checkData($data,$default){
		if(isset($data)) 
			$auxData=$data;
		else 
			$auxData=$default;
		if(get_magic_quotes_gpc()) 
			$auxData = stripslashes($auxData);
		return mysqli_real_escape_string($con,$auxData);
	}

	function getLastInsId(){
		return $this->lastInsId;
	}

	function getMySQLError(){
		return 'Error N:' . mysqli_errno($GLOBALS['con']) . ": " . mysqli_error($GLOBALS['con']); 
	}
	
	function por_getEntradasBus(){
		$tipEst=isset($_POST['r1'])?$_POST['r1']:"";  
		//$idAnimal=$_POST['bot'];
		
		$fecha_inicial=chfecha(isset($_POST['fec'])?$_POST['fec']:"",'d/m/Y','Y-m-d');
	    $fecha_final=chfecha(isset($_POST['fec2'])?$_POST['fec2']:"",'d/m/Y','Y-m-d');
		
		
		$setIpd=isset($_POST['setipdie'])?$_POST['setipdie']:""; 
		//$textBus=mysqli_real_escape_string($con,$_POST['t1']);
		
		$secOdv=isset($_POST['secodven'])?$_POST['secodven']:"";
		$setIpv=isset($_POST['setipven'])?$_POST['setipven']:"";
		$setIpn=isset($_POST['setipvent'])?$_POST['setipvent']:"";
		
		
		/*if($tipEst=="clave") {
		 $arrBus[]="dgger_cajerosj.vendedor='".$_POST['secodven']."'";		
	      }
	       if($setIpv!='T') {
	 	    $arrBus[]="$this->tabla.tip_ven='".$_POST['setipven']."'";
	         }	
	          if($setIpn!='T') {
  		       $arrBus[]='ptventa.nparte1='.$_POST['setipvent'].'';
	            }else{
		         $arrBus[]=' ptventa.nparte1<>0 ';
                  }*/
		           $arrBus[]="($this->tabla.fec_ven between '$fecha_inicial' and '$fecha_final')";
		
		return $arrBus;		
	}
	
	
	function report_getEntradas(){
		//$tipoDieta = new tipDie($data);
		//$tabTipDie = $tipoDieta->getTableName();
		
		$fecIni=chfecha(isset($_POST['fecini'])?$_POST['fecini']:"",'d/m/Y','Y-m-d');
	    $fecFin=chfecha(isset($_POST['fecfin'])?$_POST['fecfin']:"",'d/m/Y','Y-m-d');
	$vf=(isset($fecha))?$fecha:"";
	     if ($fecIni<''.$vf.''){
	      //$table='pvrescaj';
	      //$taDet='pvrescad';
	      //$posicion='fposres';
	      //$tip='pvrestip';
	      //$impresion='pvresimp';
	      //$memaDet='pvresmemd';
	      //$this->tabla='pvresmema';
	
	     }else{
	      //$table='dgger_cajerosj';
	      //$taDet='dgger_cajerosd';
	      //$posicion='fpos';
	      //$tip='fpropina';
	      //$impresion='fimpresion';
	      //$memaDet='dgpememd';
	      //$this->tabla=$this->tabla;
	}
		
		$arrDataBus=$this->por_getEntradasBus();
		$WHERE="WHERE ".implode(" AND ",$arrDataBus);
		$sq_retrieve="
			SELECT 
				$this->tabla.fol_ven      as folVen,
				$this->tabla.tip_ven      as tipVen
				
			FROM 
			$this->tabla
			
			$WHERE
			
			GROUP BY 
			$this->tabla.fol_ven
		    
			ORDER BY 
			$this->tabla.fol_ven
			";
		
		$rs=mysqli_query($GLOBALS['con'] ,$sq_retrieve);
		echo mysqli_error($GLOBALS['con']);		
		if($rs)
			return $rs;
		else
			return 0;		
	}
	
}

?>