<?php

session_start();
include("DMMYSQLG.php");
require_once("DF80000.php");

//Consulta Datos Empresa
$dt_empres = mysqli_fetch_array(mysqli_query($con ,"SELECT * FROM dxempres where cla_emp = '".$_SESSION['empresa']."'"));		
$cvdm = intval($dt_empres['cve_delmun']);
$cves = intval($dt_empres['cve_estado']);
//Consulta Datos Del/Mun
$sqld_encabezado = mysqli_query($con ,"SELECT * FROM dxdelmun where cve_delmun = '$cvdm'");
@$rowd_encabezado = mysqli_fetch_array($sqld_encabezado);
//Consulta Datos Estado 
$sqle_encabezado = mysqli_query($con ,"SELECT * FROM dxestado where cve_estado = '$cves'");
@$rowe_encabezado = mysqli_fetch_array($sqle_encabezado);

?>

<?php
 

if ($_REQUEST['control']==1)
{
	$qry_b=mysqli_fetch_array(mysqli_query($con ,"select num_imp from fimpresion where mesa='".$_REQUEST['bot']."' and fol_ven=0 order by nparte1 desc limit 1"));
	if ($qry_b['num_imp']!="")
		$control=$qry_b['num_imp'];
		else $control=1;
		//aviso de que ya se imprimio 
		if ($qry_b['num_imp']>=1){
			$contador=$qry_b['num_imp']+1;
			$query=mysqli_query($con ,"INSERT INTO fimpresion (mesa,fol_ven,num_imp,acc_fec,acc_hor,usuario,clave) VALUES ('".$_REQUEST['bot']."','0','".$contador."','".$dt_empres['fec_alta']."', '".date('H:i:s')."','".$_SESSION['num_usu']."','V')"					);	
		}else {
			$contador=$qry_b['num_imp'];
			$query=mysqli_query($con ,"INSERT INTO fimpresion (mesa,fol_ven,num_imp,acc_fec,acc_hor,usuario,clave) VALUES ('".$_REQUEST['bot']."','0','1','".$dt_empres['fec_alta']."', '".date('H:i:s')."','".$_SESSION['num_usu']."','V')"					);	
		}
	}

?>

<html>
<head>
<title><?php echo "Ticket";?></title>
 <!-- MeadCo Security Manager -->
<!-- ********************************************************************************* -->
<!-- * DO NOT copy this codebase - it can change at any time                         * -->
<!-- * download the (free) ScriptX Resource Kit and store the cab on your own server * -->
<!-- ********************************************************************************* -->
<!-- MeadCo ScriptX -->
<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
	font-family:Arial, Helvetica, sans-serif;
	font-size:10px;
}
.tit{
font-family:Arial, Helvetica, sans-serif;
font-size:10px;
}
.tot{
font-family:Arial, Helvetica, sans-serif;
font-size:14px;
font-weight:bold;
}

.dom{
font-family:Arial, Helvetica, sans-serif;
font-size:10px;
}
td{
font-family:Arial, Helvetica, sans-serif;
font-size:12px;
}
.titOrd{
font-family:Arial, Helvetica, sans-serif;
font-size:14px;
font-weight:bolder;
}
-->
</style>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><object id=factory style="display:none"
  classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814"
  codebase="archivos/smsx.cab#Version=6,1,400,50">
</object>

<script>
function printWindow() {

//factory.printing.copies = 2;
window.print();
}
</script>

 
</head>
 
<body onLoad="printWindow();window.close();">
<form name="form1" method="post" action="">
  <table  border="0" cellspacing="0">
    <tr>
      <td colspan="4" scope="col" align="center" class="titOrd"><?php echo $dt_empres['nom_emp'];
	  				$_REQUEST['bot'];
					$_GET['bot'];
					$_POST['bot'];
					$_REQUEST['control'];
					$_GET['control'];
					$_POST['control']; ?></td>
    </tr>
    <tr>
      <td colspan="4" class="dom" align="justify"><?php  echo 'CALLE: '.$dt_empres['calle']." ".$dt_empres['no_ext'];?></td>
    </tr>
    <tr>
      <td colspan="4" class="dom" align="justify"><?php echo 'COL. '.$dt_empres['des_col'].", ".$rowd_encabezado['des_delmun']." ".$rowe_encabezado['des_estado'];?></td>
    </tr>
    <tr>       <td colspan="4" class="dom" align="justify"><?php echo 'C.P.'.$dt_empres['cod_pos'].' TEL: '.$dt_empres['telefono01'];?></td>
    </tr>
    <tr>
      <td colspan="4"><div align="center"><?php echo 'RFC:'.$dt_empres['rfc'];?></div></td>
    </tr>
    <tr> <?php $dia=isset($dt_empres['fec_alta'])?$dt_empres['fec_alta']:date('Y-m-d')?>
      <td colspan="4" class="titOrd"><?php echo 'FECHA:&nbsp;&nbsp;'.chfecha($dia,'Y-m-d','d/m/Y').'&nbsp;&nbsp;&nbsp; HORA:&nbsp;'.date('H:i:s');?></td>
    </tr>
    <tr>
	<td colspan="4" class="titOrd"><?php 
	$sq_m=mysqli_query($con ,"select * from ctmesas where nparte1='".$_REQUEST['bot']."'");
	$regmp=mysqli_fetch_array($sq_m);
	$sq_p=mysqli_query($con ,"select * from  ptventa where nparte1='".$regmp['descripcion']."'");
		$regmp1=mysqli_fetch_array($sq_p);
	$sq_a=mysqli_query($con ,"select * from  ctarea where nparte1='".$regmp['area']."'");
		$regmp2=mysqli_fetch_array($sq_a);
	$sq_ps=mysqli_query($con ,"select fol_ven from fpos where mesa='".$_REQUEST['bot']."' and status=1");
		$regmp3=mysqli_fetch_array($sq_ps);
	echo $regmp1['np_desc1'].' / '.$regmp2['np_desc1'];   echo '&nbsp;&nbsp;&nbsp;&nbsp; MESA :  '.$regmp['np_desc1'];?></td></tr>	
    </tr>
    <tr>
	<td colspan="4" class="titOrd"><?php echo 'FOLIO:  &nbsp;';  $sql_fmt=mysqli_query($con ,"select fpos.fol_ven,dgpemema.con_ven from fpos left join dgpemema on (dgpemema.fol_ven=fpos.fol_ven) where mesa='".$_REQUEST['bot']."' and status=1");
	while ($regft=mysqli_fetch_array($sql_fmt)){
	$a ++;
	if ($a>=2)
	echo '-';
	echo $regft['con_ven'];
	
	}
	 echo '&nbsp;&nbsp;&nbsp;&nbsp;PAX. : '.$regmp['posicion'];?></td></tr>	
    </tr>
    <tr>
      <td colspan="4" class="titOrd"><?php @$dt_ven=mysqli_fetch_array(mysqli_query($con ,"select dgpemema.cod_ven from dgpemema where fol_ven IN (select fol_ven from fpos where mesa='".$_REQUEST['bot']."' and status=1)"));
	   echo "MESERO(A): "; 
	  $sq_ms=mysqli_fetch_array(mysqli_query($con ,"select * from ctmeser where nparte1=".$dt_ven['cod_ven']."")); 
	  echo $sq_ms['np_desc1'];
 ?>
	   </td>
    </tr>
	
      <td width="20"><div align="center"><strong>Can</strong></div></td>
      <td width="190"><div align="left"><strong>Prod.</strong></div></td>
      <td width="48"><strong>  Importe</strong></td>
    </tr>
    <tr>
      <td colspan="4">&nbsp;</td>
    </tr>
	<?php
 
	@$resu1=mysqli_query($con ,"select * from dgpemema where fol_ven IN (select fol_ven from fpos where mesa='".$_REQUEST['bot']."' and status=1)");
		$numeroArticulos=0;
while (@$rego1=mysqli_fetch_array($resu1)) {
$dt_ger_cajerosj=mysqli_fetch_array(mysqli_query($con ,"SELECT * FROM dgger_cajerosj where pedido='".$rego1['fol_ven']."'"));


	//if(!isset($_REQUEST['rec_caj']))
	//	$_REQUEST['rec_caj']='".$rego1['fol_ven']."';
	@$resu2=mysqli_query($con ,"select * from dgpemema where fol_ven = '".$rego1['fol_ven']."'");
	@$rego2=mysqli_fetch_array($resu2);
	@$resu3=mysqli_query($con ,"select * from dgpememd where cons_ven = '".$rego1['fol_ven']."' and cancela=0 ");
	$noRegsDetalle=mysqli_num_rows($resu3);
	@$re=mysqli_query($con ,"select * from dgpemema where fol_ven = '".$rego1['fol_ven']."' and dgpemema.fol_ven=dgger_cajerosj.pedido and dgger_cajerosj.n_rec=dgger_cajerosd.n_rec and dgger_cajerosd.tip_pag=4'");
	@$res=mysqli_fetch_array($re);
	
	

	while(@$rego3=mysqli_fetch_array($resu3)){
		@$resux=mysqli_query($con ,"SELECT * FROM dginventp WHERE nparte1 = '".$rego3['nparte1']."'");
		@$regox=mysqli_fetch_array($resux);
		echo "
		<tr>
		  <td>".$rego3['can_ref']."</td>
		  <td>".substr($regox['np_desc1'],0,17)."</td>
		  <td><div align=\"right\">".number_format($rego3['total_cd'],2,'.',',')."</div></td>		
		</tr>";
		//		  <td><div align=\"right\">".number_format($rego3['fcomd'],0,'.',',')."</div></td>		
		/*echo "
		<tr>
		  <td colspan=\"3\">$regox['np_desc1']</td>
		</tr>";*/
		//echo res("nparte1");
		$numeroArticulos++;	
	}
		$tot_vta+=$rego2['tot_ven'];
		$d_pago+=$dt_ger_cajerosj['cambio'];
			

} //fin de while k uno los dos 

	echo "	</table>
	 <table  border='0' cellspacing='0'>";	
	echo "
	<tr>
	  <td colspan=\"3\">&nbsp;</td>
	</tr>";
	echo "    
	<tr>
      <td colspan=\"2\" class=\"tot\">SUBTOTAL : </td>
      <td class=\"tot\"><div align=\"right\"> $".number_format($tot_vta,2,'.',',')."</div></td>
    </tr>";
	echo "    
	<tr>
      <td colspan=\"2\" class=\"tot\">PROPINA : </td>
      <td class=\"tot\"><div align=\"right\">  $ ______</div></td>
    </tr>";
	echo "    
	<tr>
      <td colspan=\"2\" class=\"tot\">TOTAL : </td>
      <td class=\"tot\"><div align=\"right\">  $ ______</div></td>
    </tr>";

	echo "
	<tr>
	  <td colspan=\"3\">ARTICULOS DESPACHADOS: $numeroArticulos</td>
	</tr>";
	echo "
	<tr>
	  <td colspan=\"3\">&nbsp;</td>
	</tr>";

$sql_h=mysqli_query($con ,"select * from fcomhues where cvmesa='".$_REQUEST['bot']."' and status=1 order by nparte1 desc limit 1");
$reh1=mysqli_fetch_array($sql_h);
$sql_fh=mysqli_query($con ,"select * from valeryus19 where fnumcto='".$reh1['no_hab']."' and status='HUESPED'");
$reh=mysqli_fetch_array($sql_fh);


if ($reh['fnumcto']!='') $habitacion=$reh['fnumcto']; else $habitacion="   ________";
if ($reh['fnumcto']!='') $nombre=$reh['fnombre'].' '.$reh['fapellido']; else $nombre="____________________";
	echo "    
	<tr>
      <td class=\"tot\">HABITACION : </td>"
     ." <td colspan=\"2\"  class=\"tot\"><div align=\"left\">  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".$habitacion."</div></td>
    </tr>";
	echo "
	<tr>"
	 ." <td colspan=\"3\">&nbsp;</td>
	</tr>";

	echo "    
	<tr>"
     ." <td  class=\"tot\">NOMBRE : </td>"
    ."  <td colspan=\"2\" class=\"tot\"><div align=\"left\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".$nombre."</div></td>
    </tr>";
	echo "
	<tr>"
	 ." <td colspan=\"3\">&nbsp;</td>"
	."</tr>";


	echo "    
	<tr>
      <td class=\"tot\">FIRMA : </td>
      <td colspan=\"2\"  class=\"tot\"><div align=\"left\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_____________</div></td>
    </tr>"; 

	echo "
	<tr>
	  <td colspan=\"3\">&nbsp;</td>
	</tr>";
	echo "
	<tr>
	  <td colspan=\"3\"><strong><div align=\"center\">*GRACIAS POR SU PREFERENCIA*</div></strong></td>
	</tr>";			
	?>

  </table>

</form>
 

</body>
</html>
<?php
 //} ?>
