<?php

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

$tot_vta=0;
$renta=0;
$numeroArticulos=0;
$totDes=0;
$d_pago=0;
$totpgg=0;
$nom_firma="";
$firma="";
//CONCRENTADO VENTAS X DIA
//Consulta Datos Empresa
//$dt_empres = mysqli_fetch_array(mysqli_query($con ,"SELECT * FROM dxempres where cla_emp = '".$_SESSION['empresa']."'"));		
$dt_empres = mysqli_fetch_array(mysqli_query($con ,"select * from dxempres  order by nom_emp")); 
//print_r($_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);
@$resu1=mysqli_query($con ,"select * from dgpemema where fol_ven = '".$_REQUEST['bot']."'");
@$rego1=mysqli_fetch_array($resu1);

if ($rego1['fec_ven']<'2013-07-01'){
	$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';
	}
$vb=(isset($_REQUEST['bot']))?$_REQUEST['bot']:"";
$dt_ger_cajerosj=mysqli_fetch_array(mysqli_query($con ,"SELECT * FROM $table where pedido='".$vb."'"));

?>
<html>
<head>
<title>Ticket</title>

<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;
}
.titPer{
font-family:Arial, Helvetica, sans-serif;
font-size:12px;
font-weight:bolder;
}
-->
</style>
</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();
}
</script>
 </head> 
 <body onLoad="printWindow();window.close();">
<form name="form1" method="post" action="">
<?php
 if (isset($_REQUEST['bot'])&&$_REQUEST['bot']!=''){ ?>
  <table  border="0" cellspacing="0">
    <tr>
      <td colspan="4" scope="col" align="center" class="titOrd"><?php echo $dt_empres['nom_emp'];
	  				$_REQUEST['bot'];
					isset($_GET['bot'])?$_GET['bot']:"";
					$_POST['bot'];
					isset($_REQUEST['control'])?$_REQUEST['control']:"";
					isset($_GET['control'])?$_GET['control']:"";
					isset($_POST['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($rego1['fec_ven'],'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);
	$sqlpp=mysqli_query($con ,"select * from $posicion where fol_ven='".$_REQUEST['bot']."'");
	$rgpp=mysqli_fetch_array($sqlpp);
	$sq_m=mysqli_query($con ,"select * from ctmesas where nparte1='".$rgpp['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 $posicion 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;MESERO: "; 
	  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>
	<td colspan="4" class="titOrd"><?php echo 'FOLIO: '.str_pad($rego1['con_ven'],5,'0',STR_PAD_LEFT);  echo '&nbsp;&nbsp;&nbsp;&nbsp;PAX: '.$personas['no_pers'];?></td></tr>	
    </tr>
    
</td>
    </tr>
      <td width="30"><div align="left"><strong>Can</strong></div></td>
      <td><strong>U.M.</strong></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 $memaDet where cons_ven ='".$_REQUEST['bot']."' and cancela=0");
	@$tot=mysqli_fetch_array(mysqli_query($con ,"select sum(total_cd) as total from $memaDet 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=$table.pedido and $table.n_rec=$taDet.n_rec and $taDet.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>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>";
			
					$tot_vta+=($rego3['pre_bas']*$rego3['can_ref']);
					// $tot_des+=($rego3['pre_bas']*$rego3['can_ref'])*($rego2['por_des']/100);
	$imp1= $rego3['pre_bas']*$rego3['can_ref'];				
	$imp2= ($imp1 / 1.16);
	$imp3= ($imp1 / 1.16)-$rego3["imp_des"];
	$imp4= (($imp1 / 1.16)-$rego3["imp_des"])*.16;
	$imp5= $imp3+$imp4;
					
	$b2 = "".$regox["nparte1"]."|".$regox["np_desc1"]."|NO APLICA||".$rego3["can_ref"]."|".number_format($imp1,4,'.','')."|".number_format($renta,4,'.','')."|0| IVA 16% |16|NO APLICA|0|".$dt_empres['fec_alta']."";
	
	$bb2[]=$b2;
	$numeroArticulos+= $rego3['can_ref'];
	$totDes+= $rego3['imp_des'];
	}

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


	include("DF10000.php");
	$can=round($rego2['tot_ven'],2);
	$parTot=explode(".","$can");
	if(isset($parTot[1])&&$parTot[1]==0 || isset($parTot[1])&&$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=\"4\">ARTICULOS DESPACHADOS: $numeroArticulos &nbsp;&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>";
    echo "    
	<tr>
      <td colspan=\"3\" class=\"tot\">NTRA ENTREGA X CTA : </td>
      <td class=\"tot\"><div align=\"right\">$".number_format($rego2['servicio'],2,'.',',')."</div></td>
    </tr>";
	$sql_bus_propi=mysqli_query($con ,"select * from $tip where fol_ven='".$_REQUEST['bot']."'");
	$reg_prop=mysqli_fetch_array($sql_bus_propi);
	echo "    
	<tr>
      <td colspan=\"3\" class=\"tot\">NTRA ENTREGA X CTA : </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>";
	//$cam=($tot_vta / 1.16)-$totDes;
	//$cam2=(($tot_vta / 1.16)-$totDes)*.16;
	//$cam3=$cam+$cam2;
	$cam=$tot_vta -$totDes;
	//
	$cam3=$cam;
	echo " 
	<tr>
      <td colspan=\"3\" class=\"tot\">TOTAL : </td>
      <td class=\"tot\"><div align=\"right\">$".number_format($fint=$cam3+$reg_prop['tip']+$rego2['servicio'],2,'.',',')."</div></td>
    </tr>";
	
    echo "<tr> <td colspan=\"4\">&nbsp;</td> </tr>";	
	@$re=mysqli_query($con ,"select $table.num_cli as CLIENTE,$taDet.tip_pag,dgtippag.desc_pag as tipp,$taDet.importe as pago from $taDet left join $table on ($table.n_rec=$taDet.n_rec) left join dgtippag on (dgtippag.tip_pag=$taDet.tip_pag)  where $table.pedido = '".$_REQUEST['bot']."'  and $table.n_rec=$taDet.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']);
	}

	echo "<tr> <td colspan=\"4\">&nbsp;</td> </tr>"; 
$vsm=isset($_SESSION['mesa'])?$_SESSION['mesa']:"";
$sql_h=mysqli_query($con ,"select * from fcomhues where cvmesa='".$vsm."' ");
$reh1=mysqli_fetch_array($sql_h);
if ($_SESSION['hb']!=''){
$sql_fh=mysqli_query($con ,"select * from valeryus19 where n_reg='".$_SESSION['hb']."' and status='HUESPED'");
$reh=mysqli_fetch_array($sql_fh);
}else {
$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']!=''){ 
$nom_hab="HABITACION :";
$habitacion=$reh['fnumcto'];
$nom_nom="NOMBRE :";
$nombre=$reh['fnombre'].' '.$reh['fapellido'];  
$nom_firma="FIRMA :";
$firma="_____________";
}else{ 
$habitacion=" "; 
$nom_hab=" ";
$nombre=" ";
$nom_nom=" ";
}

echo "    
	<tr>
      <td class=\"tot\">".$nom_hab." </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\">".$nom_nom."</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\">".$nom_firma."</td>
          <td colspan=\"3\"  class=\"tot\"><div align=\"left\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".$firma."</div></td>
          </tr>"; 
    
	echo "<tr> <td colspan=\"4\">&nbsp;</td>	</tr>";
	
	//$b2 = "1001|CONSUMO|NO APLICA||1|".number_format($imp2,4,'.','')."|0.0000|".$sinDes."| IVA 16% |16|NO APLICA|0|".$dt_empres['fec_alta']."";

$auxFec=explode("-",$rego1['fec_ven']); 
$auxHor=explode(":",$rego1['hor_ven']);

$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>
<?php
 } ?>
  
</form>
</body>
</html>