<?php

session_start();
include("DMMYSQLG.php");
require_once("DF80000.php");
//TICKET FINAL
//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
//var_dump($_SESSION);
$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);
@$resu1=mysqli_query($con ,"select * from dgpemema where fol_ven = '".$_REQUEST['bot']."'");
@$rego1=mysqli_fetch_array($resu1);
$dt_ger_cajerosj=mysqli_fetch_array(mysqli_query($con ,"SELECT * FROM dgger_cajerosj where pedido='".$rego1['fol_ven']."'"));

$sql_hab=mysqli_query($con ,"select * from valeryus19 where n_reg='".$_SESSION['hb']."' or n_reg='".$_SESSION['foliohb']."' and (status='HUESPED' or status='MISCELANEOS')");
$r_hab=mysqli_fetch_array($sql_hab);
if (mysqli_num_rows($sql_hab)!=0){
mysqli_query($con ,"UPDATE fcomhues SET no_hab='".$r_hab['fnumcto']."', `nombre`='".$r_hab['fnombre'].' '.$r_hab['fapellido']."' WHERE  fol_ven='".$rego1['fol_ven']."'");
}
?>
<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.caab#Version=6,1,400,50">
</object>
<script>
function printWindow() {

window.print();
window.close();
}
</script>
 </head> 
 <body onLoad="printWindow();">
<form name="form1" method="post" action="">
  <table  border="0" cellspacing="0">
<?php
 //if ($_REQUEST['but']!=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 ''.$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']." MEXICO";?></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:&nbsp;&nbsp;'.$dt_empres['rfc'];?></div></td>
    </tr>
    <tr>
      <td colspan="4" class="titOrd"><?php echo 'FECHA:&nbsp;&nbsp;'.chfecha($dt_empres['fec_alta'],'Y-m-d','d/m/Y').'&nbsp;&nbsp;&nbsp; HORA:&nbsp;'.$rego1['hor_ven'];?></td>
    </tr>
    <tr>
	<td colspan="4" class="titOrd"><?php

	$pax=mysqli_query($con ,"select no_pers from fcomhues where fol_ven='".$_REQUEST['bot']."'");
	$personas=mysqli_fetch_array($pax); 
	$sq_m=mysqli_query($con ,"select * from ctmesas where nparte1='".$_SESSION['mesa']."'");
	$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['tip_ven'].' / '.$regmp2['np_desc1']; echo '&nbsp;&nbsp;&nbsp; M-'.$regmp['np_desc1']; echo "&nbsp;&nbsp;&nbsp;PAX. : ".$personas['no_pers'];
	if ( ($rego1['cod_ven']!='') || ($rego1['cod_ven']!=0) ){
	  $sq_ms=mysqli_fetch_array(mysqli_query($con ,"select * from ctmeser where nparte1=".$rego1['cod_ven']."")); 
	  //echo $sq_ms['iniciales'];
	  }
	  else {
	  //echo "CAJERO";
	  }?></td></tr>	
    </tr>
    <tr>
	<?php

	@$bus1 = mysqli_query($con ,"SELECT * FROM dgcatven WHERE cod_ven = '".$dt_ger_cajerosj['vendedor']."'");
	$re1 = mysqli_fetch_array($bus1);
	?>
	<td colspan="4" class="titOrd"><?php echo 'FOLIO: '.str_pad($rego1['con_ven'],5,'0',STR_PAD_LEFT);  echo "&nbsp;&nbsp;&nbsp;CAJERO: ".$re1['nom_ven']."";?></td></tr>	
    </tr>
    
      <td width="30"><div align="left"><strong>Can</strong></div></td>
	  <td><div align="center"><strong>UM</strong></div></td>
      <td width="160"><strong>Prod.</strong></td>
      <td width="68" align="right"><strong>Importe</strong></td>

    </tr>
	<?php

	if(!isset($_REQUEST['rec_caj']))
		$_REQUEST['rec_caj']=$_REQUEST['bot'];
	@$resu2=mysqli_query($con ,"select * from dgpemema where fol_ven = '".$_REQUEST['bot']."'");
	@$rego2=mysqli_fetch_array($resu2);

	//BUSQUEDA DE CUENTA TOTAL POR POSICION
	@$resu3=mysqli_query($con ,"select * from dgpememd where cons_ven ='".$_REQUEST['bot']."' and cancela=0");
	@$tot=mysqli_fetch_array(mysqli_query($con ,"select sum(total_cd) as total from dgpememd where cons_ven = '".$_REQUEST['bot']."'"));
//	}
	$noRegsDetalle=mysqli_num_rows($resu3);
	
	@$re=mysqli_query($con ,"select * from dgpemema where fol_ven = '".$_REQUEST['bot']." 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);
	
	
	$numeroArticulos=0;
	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>SV</td>"
		 ." <td>".substr($regox['np_desc1'],0,17)."</td>"
		 ." <td><div align=\"right\">".number_format(($rego3['pre_bas']*$rego3['can_ref']),2,'.',',')."</div></td>"		
		."</tr>";
		$numeroArticulos+= $rego3['can_ref'];	
					$tot_vta+=($rego3['pre_bas']*$rego3['can_ref']);
					// $tot_des+=($rego3['pre_bas']*$rego3['can_ref'])*($rego2['por_des']/100);
	$imp1= $rego3['pre_bas'];				
	//$imp2= ($imp1 / 1.16);
	//$imp3= ($imp1 / 1.16)-$rego3["imp_des"];
	//$imp4= (($imp1 / 1.16)-$rego3["imp_des"])*.16;
	//$imp5= $imp3+$imp4;
	$imp6+= ($imp1*$rego3['can_ref']);
	$totDes+= $rego3["imp_des"];
	//$sinDes=$rego3["imp_des"] / 1.16;
	//$b2 = "".$regox["nparte1"]."|CONSUMO|SERVICIO||".$rego3["can_ref"]."|".number_format($imp2,4,'.','')."|0.0000|".$sinDes."| IVA 16% |16|NO APLICA|0|".$dt_empres['fec_alta']."";
	
	//$bb2[]=$b2;
	}

		$d_pago+=$dt_ger_cajerosj['cambio'];


	include("DF10000.php");
	$can=round($rego2['tot_ven'],2);
	$parTot=explode(".","$can");
	if($parTot[1]==0 || $parTot[1]==''){
		$parTot[1]='00';
	}	
	$pre_let=num2letras(number_format($parTot[0], 2, '.', ''));
		

echo "	</table>
	 <table  border='0' cellspacing='0'>";
echo '	<td width="30"><div align="left"></div></td>
      <td width="110"><strong></strong></td>
      <td width="48" align="right"><strong></strong></td>';

echo "<tr> <td colspan=\"3\">ARTICULOS DESPACHADOS: $numeroArticulos&nbsp;&nbsp;HORA:&nbsp;".$dt_ger_cajerosj['acc_hor']."</td> </tr>";	
	echo "    
	<tr>
      <td colspan=\"3\" class=\"tot\">SUBTOTAL : </td>
      <td class=\"tot\"><div align=\"right\"> $".number_format($tot_vta,2,'.',',')."</div></td>
    </tr>";
    $porSer=$rego1['servicio'];
	//$porSer=$regmp1['servicio'];
	if($porSer!='0'){
	echo "    
	<tr>
      <td colspan=\"3\" class=\"tot\">SERVICIO : </td>
      <td class=\"tot\"><div align=\"right\">  $ ".number_format($rego1['servicio'],2,'.',',')."</div></td>
    </tr>";
	}
	$sql_bus_propi=mysqli_query($con ,"select * from fpropina where fol_ven='".$_REQUEST['bot']."'");
	$reg_prop=mysqli_fetch_array($sql_bus_propi);
	echo "    
	<tr>
      <td colspan=\"3\" class=\"tot\">PROPINA : </td>
      <td class=\"tot\"><div align=\"right\">  $ ".number_format($reg_prop['tip'],2,'.',',')."</div></td>
    </tr>";
	echo "    
	<tr>
      <td colspan=\"3\" class=\"tot\">DESCUENTO : </td>
      <td class=\"tot\"><div align=\"right\">$".number_format($totDes,2,'.',',')."</div></td>
    </tr>";
	//<td class=\"tot\"><div align=\"right\">$".number_format($fint=$imp1+$d_pago+$reg_prop['tip']+$rego1['servicio']-$totDes,2,'
	echo " 
	<tr>
      <td colspan=\"3\" class=\"tot\">TOTAL : </td>
      <td class=\"tot\"><div align=\"right\">$".number_format($fint=$tot_vta+$reg_prop['tip']+$rego1['servicio']-$totDes,2,'.',',')."</div></td>
    </tr>";
	
echo "
	<tr>
	  <td colspan=\"4\">&nbsp;</td>
	</tr>";	
	@$re=mysqli_query($con ,"select dgger_cajerosj.num_cli as CLIENTE,dgger_cajerosd.tip_pag,dgger_cajerosd.ref,dgtippag.desc_pag as tipp,dgger_cajerosd.importe as pago from dgger_cajerosd left join dgger_cajerosj on (dgger_cajerosj.n_rec=dgger_cajerosd.n_rec) left join dgtippag on (dgtippag.tip_pag=dgger_cajerosd.tip_pag)  where dgger_cajerosj.pedido = '".$_REQUEST['bot']."'  and dgger_cajerosj.n_rec=dgger_cajerosd.n_rec");
	 while ($res=mysqli_fetch_array($re)){
	 $_SESSION['hb']=$res['CLIENTE'];
	echo "    
	<tr>
      <td colspan=\"3\" class=\"tot\">".$res['tipp']." : </td>
      <td class=\"tot\"><div align=\"right\">$".number_format($res['pago'],2,'.',',')."</div></td>
    </tr>";
	$totpgg+=($res['pago']+$reg_prop['tip']);
	
	$formas[]=$res['tip_pag'];
		  //echo "--->".$abonos['nparte1_det']."-".$abonos['proteina']."-".$abonos['id_invend']."";
		  if ($res['ref']<>''){
		  $referencia[]=$res['ref'];
		  }
	
	}
	echo "
	<tr>
	  <td colspan=\"4\">&nbsp;</td>
	</tr>"; 


if (mysqli_num_rows($sql_hab)!=0){
if ($r_hab['fnumcto']!='') $habitacion=$r_hab['fnumcto']; else $habitacion="-------------";
if ($r_hab['fnumcto']!='') $nombre=$r_hab['fnombre'].' '.$reh['fapellido']; else $nombre="-------------";
echo "    
	<tr>
      <td class=\"tot\">HABITACION : </td>
      <td colspan=\"3\"  class=\"tot\"><div align=\"left\">  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".$habitacion."</div></td>
    </tr>";
	echo "
	<tr>
	  <td colspan=\"4\">&nbsp;</td>
	</tr>";

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

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

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

	}
	//+++++++++++++++++++++++++++++++++++++++++++++++FACTURACION++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//$a1   

unset($_SESSION['hb']);
$numFac="B".$rego1['con_ven']."".$auxFec[2]."".$auxHor[0]."".$auxHor[1]."".$auxHor[2]."";
		echo "<tr><td colspan=\"4\">&nbsp;</td></tr>";
	
	echo "<tr> <td colspan=\"4\"><strong><div align=\"center\">*GRACIAS POR SU PREFERENCIA*</div></strong></td>	</tr>";			
	
	
	?>

  </table>
</form>
 
</body>
</html>

