<?php

require('pdf/pdf_js.php');
//include('pdf/fpdf.php');
session_cache_limiter('private');
session_start();
$com = "I";
include("DMMYSQLG.php");
//include("DSA3000.php");
include("DMMYSQLG.php");
 
class PDF extends PDF_JavaScript
{
	//Cabecera de Página
	function Header()
	{
	
		//Consulta Datos Empresa
		$dt_empres = mysqli_fetch_array(mysqli_query($con ,"SELECT * FROM geoyos_jc.dxempres where cla_emp = '".$_SESSION['empresa']."'"));
				
		$sql_encabezado = mysqli_query($con ,"SELECT * FROM dgtipven where tip_ven = '".$_SESSION['tipven']."'");
		@$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 dgger_cajerosj where n_rec = '".$_REQUEST['rec_caj']."'");
		@$rego1=mysqli_fetch_array($resu1);
		@$resu=mysqli_query($con ,"select * from dgcatven where cod_ven = '".$rego1['vendedor']."'");
		@$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,$dt_empres['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['telefono'],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,"VEND: ".$rego1['vendedor'],0,1,'C');
		//$this->Cell(65,4,"CAJERO: ".$rego['nom_ven'] . ' ' . $rego['ap_pat_ven'],0,1,'C');
		$this->Cell(63,3,'  VEN:'.str_pad($rego1['pedido'],5,'0',STR_PAD_LEFT).' '.date('d/m/y').' '.date('H:i:s'),0,1,'L');
		//$this->SetFont('arial','',8);
		$this->Ln(2);
		$this->Cell(9,4,'CANT.',0,0,'L');
		$this->Cell(23,4,'ARTICULO',0,0,'C');
		$this->Cell(16,4,'PU.',0,0,'C');
		$this->Cell(16,4,'TOTAL',0,1,'C');
		$this->Ln(2);
	}
	//Pie de Página
	function Footer(){
	}
	
	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);
	}
}
if(!isset($_REQUEST['rec_caj']))
	$_REQUEST['rec_caj']=$_REQUEST['bot'];
@$resu1=mysqli_query($con ,"select * from dgger_cajerosj where n_rec = '".$_REQUEST['rec_caj']."'");
@$rego1=mysqli_fetch_array($resu1);

@$resu2=mysqli_query($con ,"select * from dgpemema where fol_ven = '".$rego1['pedido']."'");
@$rego2=mysqli_fetch_array($resu2);

@$resu3=mysqli_query($con ,"select * from dgpememd where cons_ven = '".$rego1['pedido']."'");

$noRegsDetalle=mysqli_num_rows($resu3);

$altoPagina=115+9*$noRegsDetalle;
$anchoPagina=75;
$arrhoja=array($altoPagina,$anchoPagina);
$pdf=new PDF('L','mm',$arrhoja);
$pdf->SetMargins(0,0,5);
$fontName='sfpixelateddd';
$pdf->AddFont($fontName);
$pdf->SetFont('sfpixelateddd','',9);
$pdf->AddPage();
$pdf->SetFillColor(192,192,192);


$numeroArticulos=0;
while(@$rego3=mysqli_fetch_array($resu3)){
	@$resux=mysqli_query($con ,"SELECT * FROM dginvent WHERE dginvent.modulo='".$_SESSION['mod_sis']."' AND   nparte1 = '".$rego3['nparte1']."'");
	@$regox=mysqli_fetch_array($resux);
	$pdf->Cell(9,3,$rego3['can_ref'],0,0,'L');
	$pdf->MultiCell(55,3,$regox['np_desc1'],0,'C');
	$pdf->Cell(32,3,$rego3['nparte1'],0,0,'C');
	$pdf->Cell(16,3,number_format($rego3['pre_bas'],2,'.',',')."",0,0,'L');
	$pdf->Cell(16,3,number_format($rego3['total_cd'],2,'.',',')."",0,1,'C');
	$numeroArticulos++;
	$pdf->Ln(3);
}
$pdf->Ln(3);
//$cc = $rego1['imp_pag']/1.15;
//$pdf->Cell(65,3,'Subtotal:$'.number_format($cc,2,'.',','),0,1,'C');

//$ii = $cc*.15;
//$pdf->Cell(65,3,'IVA:     $'.number_format($ii,2,'.',','),0,1,'C');
//$pdf->Cell(30,3,'Cambio:  $'.number_format($rego1['cambio'],2,'.',','),0,0,'L');
$pdf->SetFont($fontName,'',9);

$pdf->Cell(45,4,'TOTAL : $',0,0,'R');
$pdf->Cell(18,4,str_pad(number_format($rego1['imp_pag'],2,'.',','),12,' ',STR_PAD_LEFT),0,1,'R');
$pdf->Cell(45,4,'RECIBE: $',0,0,'R');
$pdf->Cell(18,4,str_pad(number_format(($rego1['imp_pag']+$rego1['cambio']),2,'.',','),12,' ',STR_PAD_LEFT),0,1,'R');
$pdf->Cell(45,4,'CAMBIO: $',0,0,'R');
$pdf->Cell(18,4,str_pad(number_format($rego1['cambio'],2,'.',','),12,' ',STR_PAD_LEFT),0,1,'R');
$pdf->Ln(3);
//$pdf->Cell(65,3,'** E = Exento o tasa cero',0,1,'L');
//$pdf->Cell(65,3,'Q = IVA 15.00%',0,1,'L');
$pdf->Cell(65,5,"ARTICULOS VENDIDOS: $numeroArticulos",0,1,'C');
$pdf->Cell(65,4,'GRACIAS POR SU COMPRA',0,1,'C');
//$pdf->Cell(65,3,'**Vuelva Pronto**',0,1,'C');
$pdf->AutoPrint(true);
//$pdf-> AutoPrintToPrinter('ESDPRT001','EPSON TM-U220 Receipt');
$pdf->Output('tiket.pdf','I');
?> 