<?php

require_once("DF80000.php");

$fecha='2013-08-01';

$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');
	
	if ($fecIni<''.$fecha.''){
	$table='pvrescaj';
	$taDet='pvrescad';
	//$posicion='fposres';
	//$tip='pvrestip';
	$impresion='pvresimp';
	$memaDet='pvresmemd';
	$mema='pvresmema';
	
	}else{
	$table='dgger_cajerosj';
	$taDet='dgger_cajerosd';
	//$posicion='fpos';
	//$tip='fpropina';
	$impresion='fimpresion';
	$memaDet='dgpememd';
	$mema='dgpemema';
	}

class dgpeMema{
	var  $tabla = '0';
	var  $fol_ven = '0';
	var  $con_ven = '0';
	var  $tip_ven = '0';
	var  $fec_ven = '0';
	var  $hor_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  $cod_ven = '0';
	var  $cancelado = '0';
	var  $fec_can = '0';
	
	var  $imp_pag = '0';
	var  $imp_not = '0';
	var  $pagado = '0';
	
	
	var  $acc_fec = '0';
	var  $acc_hor = '0';
	var  $usuario = '0';
	var  $cancela = '0';
	var  $mt_cancela = '0';
	var  $folio = '0';
	var  $servicio = '0';
	var  $tip_por = '0';
	var  $fpos_nparte1 = '0';
	var  $fpos_mesa = '0';
	var  $fpos_status = '0';
	var  $tip = '0';
	var  $lastInsId = '0';
	
	function dgpeMema($data){
		$this->tabla='dgpemema';
		$this->resetData($data);
	}

	function resetData($data){
		$this->fol_ven=$this->checkData($data['folVen'],'');
		$this->con_ven=$this->checkData($data['conVen'],'');
		$this->tip_ven=$this->checkData($data['tipVen'],'');
		$this->fec_ven=$this->checkData($data['fecVen'],'');
		$this->hor_ven=$this->checkData($data['horVen'],'');
		$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->cod_ven=$this->checkData($data['codVen'],'');
		$this->cancelado=$this->checkData($data['canCelaDo'],'');
		$this->fec_can=$this->checkData($data['fecCan'],'1');		
		
		$this->imp_pag=$this->checkData($data['impPag'],'0000-00-00');		
		$this->imp_not=$this->checkData($data['impNot'],date('Y-m-d'));
		$this->pagado=$this->checkData($data['pagAdo'],date('H:i:s'));
		
		
		$this->acc_fec=$this->checkData($data['accFec'],'');
		$this->acc_hor=$this->checkData($data['accHor'],'');
		$this->usuario=$this->checkData($data['usuArio'],'');
		$this->cancela=$this->checkData($data['canCela'],'');
		$this->mt_cancela=$this->checkData($data['mtCancEla'],'');
		$this->folio=$this->checkData($data['foLio'],'');
		$this->servicio=$this->checkData($data['serVicIo'],'');
		$this->tip_por=$this->checkData($data['tipPor'],'');
		$this->fpos_nparte1=$this->checkData($data['fposNparte1'],'');
		$this->fpos_mesa=$this->checkData($data['fposMesa'],'');
		$this->fpos_status=$this->checkData($data['fposStatus'],'');
		$this->tip=$this->checkData($data['tiP'],'');		
	}

	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 cat_getDiariasBus(){
		//$tipBus=$_POST['r1'];
		//$idAnimal=$_POST['bot'];
		
		$fecIni=chfecha($_POST['fecini'],'d/m/Y','Y-m-d');
	    $fecFin=chfecha($_POST['fecfin'],'d/m/Y','Y-m-d');
		
		$vars=(isset($_POST['setipdie']))?$_POST['setipdie']:"";
		$setIpd=$vars; 
		//$textBus=mysqli_real_escape_string($con,$_POST['t1']);
		
		$secOdv=$_POST['secodven'];
		$setIpv=$_POST['setipven'];
		$setIpn=$_POST['setipvent'];
		
		if($secOdv!='T') {
		 $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 '$fecIni' and '$fecFin')";
		
		return $arrBus;		
	}
	
	
	function report_getDiarias(){
		//$tipoDieta = new tipDie($data);
		//$tabTipDie = $tipoDieta->getTableName();
		
		$fecIni=chfecha(isset($_POST['fecini'])?$_POST['fecini']:"",'d/m/Y','Y-m-d');
	    $fecFin=chfecha($_POST['fecfin'],'d/m/Y','Y-m-d');
	$varfe=(isset($fecha))?$fecha:"";
	     if ($fecIni<''.$varfe.''){
	      $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->cat_getDiariasBus();
		$WHERE="WHERE ".implode(" AND ",$arrDataBus);
		$sq_retrieve="
			SELECT 
				$this->tabla.fol_ven                         as folVen,
				$this->tabla.con_ven                         as conVen,
				$this->tabla.tip_ven                         as tipVen,
				$this->tabla.imp_pag                         as impPag,
			    $this->tabla.cod_ven                         as codVen,
				$this->tabla.tip                             as propina, 
				$this->tabla.cancela                         as cancela,
			    $this->tabla.servicio                        as servicio,
			    $this->tabla.mt_cancela                      as comentario,
				DATE_FORMAT($this->tabla.fec_ven,'%d/%m/%Y') as fecVen,
				$table.acc_hor                               as hora,
				ctmeser.np_desc1                             as nomVen,
			    ctmesas.np_desc1                             as dmesa,    
			    ptventa.tip_ven                              as dptvta,
				
				$table.fol_unp                               as folp	
				
			FROM 
			$this->tabla
			
			LEFT JOIN ctmesas ON ctmesas.nparte1=$this->tabla.fpos_mesa
			LEFT JOIN ctarea ON ctarea.nparte1=ctmesas.area
			LEFT JOIN ctmeser  ON ctmeser.nparte1=$this->tabla.cod_ven
			LEFT JOIN ptventa ON ptventa.nparte1=ctmesas.descripcion
			LEFT JOIN $table ON $table.pedido=$this->tabla.fol_ven		
			LEFT JOIN dgcatven ON $this->tabla.cod_ven=dgcatven.cod_ven
			
			LEFT JOIN  dgtippag ON dgtippag.tip_pag=dgger_cajerosj.tip_mov
			
			$WHERE
			group by $this->tabla.fol_ven
		    
			ORDER BY 
			$this->tabla.con_ven
			";
		
		//echo $sq_retrieve;
		$rs=mysqli_query($GLOBALS['con'] ,$sq_retrieve);
		echo mysqli_error($GLOBALS['con']);		
		if($rs)
			return $rs;
		else
			return 0;		
	}
//CONCAT(dgcatven.nom_ven,' ',dgcatven.ap_pat_ven,' ',dgcatven.ap_mat_ven) as nomVen,	
//$mema.iva_ven,
//$this->tabla.tot_ven                         as totVen,
//$this->tabla.sub_ven                         as subVen,
//ctarea.np_desc1                              as darea,
//dgtippag.ini_pag                             as descpag,
//dgger_cajerosd.tip_pag                             as tipag,
//$this->tabla.por_des                         as descuento,
//$memaDet.imp_des                             as desc_uento,
//$posicion.mesa                               as mesa,
//$this->tabla.cancelado                       as cancelado,
//$table.num_cli                               as cliente,
//LEFT JOIN $posicion ON $posicion.fol_ven=$this->tabla.fol_ven
//LEFT JOIN  $tip ON $tip.fol_ven=$mema.fol_ven
//LEFT JOIN $taDet ON $taDet.n_rec=$table.n_rec	
//LEFT JOIN dgtippag ON dgtippag.tip_pag=$taDet.tip_pag	
//LEFT JOIN $memaDet ON $memaDet.cons_ven=$this->tabla.fol_ven
	
	function report_corral(){
		$arrDataBus=$this->cat_getCorralBus();
		$WHERE="WHERE ".implode(" AND ",$arrDataBus);
		$sq_retrieve="
		SELECT
			distinct($this->tabla.id_corral) as dis_corral
								
		FROM 
			$this->tabla
			
		$WHERE 
			
		GROUP BY
			$this->tabla.id_corral";
		
		$rs=mysqli_query($GLOBALS['con'] ,$sq_retrieve);
		if($rs)
			return $rs;
		else
			return 0;
	}	
	
	
	
	
	
	
}


?>
      

      
