<?php

require('pdf/pdf_js.php');
session_cache_limiter('private');
session_start();
$com = "I";
include("DMMYSQLG.php");
//include("DSA3000.php");
include("DMMYSQLG.php");
require_once("DF80000.php"); 
class PDF extends PDF_JavaScript{
	function AutoPrint($dialog=false){
		//Open the print dialog or start printing immediately on the standard printer
		$param=($dialog ? 'true' : 'false');
		$script="print($param);";
		$this->IncludeJS($script);
	}
	function AutoPrintToPrinter($server, $printer, $dialog=false){
		//Print on a shared printer (requires at least Acrobat 6)
		$script = "var pp = getPrintParams();";
		if($dialog)
			$script .= "pp.interactive = pp.constants.interactionLevel.full;";
		else
			$script .= "pp.interactive = pp.constants.interactionLevel.automatic;";
		$script .= "pp.printerName = '\\\\\\\\".$server."\\\\".$printer."';";
		$script .= "print(pp);";
		$this->IncludeJS($script);
	}

	//Cabecera de Página
	function headTicket(){
	
		//Consulta Datos Empresa
		$sql_encabezado = mysqli_query($con ,"SELECT * FROM geoyos_jc.dxempres where cla_emp = '".$_SESSION['empresa']."'");
		@$row_encabezado = mysqli_fetch_array($sql_encabezado);
		$cvdm = intval($row_encabezado['cve_delmun']);
		$cves = intval($row_encabezado['cve_estado']);
		
		//Consulta Datos Del/Mun
		$sqld_encabezado = mysqli_query($con ,"SELECT * FROM geoyos_jc.dxdelmun where cve_delmun = '$cvdm'");
		@$rowd_encabezado = mysqli_fetch_array($sqld_encabezado);
		
		//Consulta Datos Estado 
		$sqle_encabezado = mysqli_query($con ,"SELECT * FROM geoyos_jc.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);
		$fecCor=$_REQUEST['t1'];	
		//@$resu1=mysqli_query($con ,"select * from dgger_cajerosj where n_rec = '".$_REQUEST['rec_caj']."'");
		//@$rego1=mysqli_fetch_array($resu1);
		//@$resu=mysqli_query($con ,"select * from dgcatven where cod_ven = '".$rego1['cod_ven']."'");
		//@$rego=mysqli_fetch_array($resu);
		
		$this->SetMargins(0,0,5);
	    //Logotipo
	   	/*$logo='logos/'.$_SESSION['base'].'.jpg';
		$this->Image($logo,0,0,65,20);
		$this->Cell(65,20,'',0,1,'C',0);*/
		//Arial Bold (14)
		
	    $this->SetFontSize(14);
		
		$this->Ln(2);
		$this->SetFillColor(192,192,192);
		$this->MultiCell(63,6,$row_encabezado['nom_emp'],0,'C');
		$this->SetFontSize(9);
		$this->MultiCell(63,4,' '.$row_encabezado['calle']." ".$row_encabezado['no_ext'],0,'C');
		$this->MultiCell(63,4,'COL. '.$row_encabezado['des_col'].", ".$rowd_encabezado['des_delmun']." ".$rowe_encabezado['des_estado'],0,'C');
		$this->Cell(63,3,' C.P.'.$row_encabezado['cod_pos'].' TEL: '.$row_encabezado['telefono01'],0,1,'C');
		$this->SetFontSize(9);
		$this->Cell(63,4,'RFC:'.$row_encabezado['rfc'],0,1,'C',0);
		$this->Ln(2);
		  //$this->SetFont('arial','',8);
		$this->Cell(63,4,"CORTE DE CAJA",0,1,'C');
		//$this->Cell(65,4,"CAJERO: ".$rego['nom_ven'] . ' ' . $rego['ap_pat_ven'],0,1,'C');
		$this->Cell(63,3,$fecCor,0,1,'C');
		//$this->SetFont('arial','',8);
		//$this->Ln(2);
		$this->Cell(45,4,'No. VENTA',0,0,'C');
//		$this->Cell(30,4,'CLIENTE',0,0,'C');
		$this->Cell(20,4,'TOTAL',0,1,'C');
		$this->Ln(2);
		
	}
	//Pie de Página
	function Footer(){
	}
}


$f_m=chfecha($_REQUEST['t1'],'d/m/Y','Y-m-d');
$tipVen=$_SESSION['tipven'];
	if ($_REQUEST['select2'] == "TODOS"){
		@$sql=mysqli_query($con ,"select * from dgger_cajerosj where corte <> 0 and fec_rec = '$f_m' AND tip_caj='$tipVen' AND cancelado='0' group by fol_unp order by pedido");
	}else{
		@$sql=mysqli_query($con ,"select * from dgger_cajerosj where fec_rec = '$f_m' and corte = '".$_REQUEST['select2']."' AND tip_caj='$tipVen' AND cancelado='0' group by fol_unp order by pedido");
	}

$noRegsDetalle=mysqli_num_rows($sql);

$altoPagina=300;
$anchoPagina=75;
$arrhoja=array($altoPagina,$anchoPagina);
$pdf=new PDF('L','mm',$arrhoja);
$pdf->SetMargins(0,0,5);
$pdf->SetAutoPageBreak(true,1);
$fontName='sfpixelateddd';
$pdf->AddFont($fontName);
$pdf->SetFont('sfpixelateddd','',9);
$pdf->AddPage();
$pdf->headTicket();
$pdf->SetFillColor(192,192,192);

$tipMov=array(1=>'COBRO DE PEDIDOS','COBRO DE FACTURAS','ANTICIPOS','DEVOLUCION DE VENTAS','OTROS');
while($reg = mysqli_fetch_array($sql)){
	$dt_catcli = mysqli_fetch_array( mysqli_query($con ,"select * from dgcatcli where cod_cli = '".$reg['num_cli']."'"));
	$nomCli=substr($dt_catcli['nom_cli'].' ' .$dt_catcli['ap_pat_cli'].' ' .$dt_catcli['ap_mat_cli'],0,13);
	$sq_fm=mysqli_query($con ,"select con_ven from dgger_cajerosj left join dgpemema on (dgpemema.fol_ven=dgger_cajerosj.pedido) where dgger_cajerosj.n_rec='".$reg['n_rec']."'");	
	$rfol=mysqli_fetch_array($sq_fm);
	$pdf->Cell(45,4,$rfol['con_ven'],0,0,'C',0);
//	$pdf->Cell(30,4,$nomCli,0,0,'L',0);
	$pdf->Cell(20,4,number_format($reg['imp_pag'],2,'.',','),0,1,'R',0);
	$totCorCaj +=$reg['imp_pag'];
}
$pdf->Ln(3);
$pdf->Cell(30,5,"TOTAL: $",0,0,'R',0);
$pdf->Cell(35,5,number_format($totCorCaj,2,'.',','),0,1,'R',0);
$pdf->Cell(30,5,"Num. Ven.: ",0,0,'R',0);
$pdf->Cell(35,5,$noRegsDetalle,0,1,'R',0);
			
//$pdf->AutoPrint(true);
$pdf->Output('tiket.pdf','D');
?> 