<?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 FPDF
{
	//Cabecera de Página
	function Header()
	{
	
		//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 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(20,0,5);
	    //Logotipo
	    $logo='logos/'.$_SESSION['base'].'.jpg';
		$this->Image($logo,70,0,65,20);
		$this->Cell(65,20,'',0,1,'C',0);
		//Arial Bold (14)
	    $this->SetFont('helvetica','B',7);
		
		$this->Ln(2);
		$this->SetFillColor(192,192,192);
		$this->Cell(170,3,$row_encabezado['nom_emp'],0,1,'C');
		$this->MultiCell(170,3,' '.$row_encabezado['calle']." No.".$row_encabezado['no_ext'].' Int.'.$row_encabezado['no_int'],0,'C');
		$this->MultiCell(170,3,'Col. '.$row_encabezado['des_col'].", ".$rowd_encabezado['des_delmun']." ".$rowe_encabezado['des_estado'],0,'C');
		$this->Cell(170,3,' C.P.'.$row_encabezado['cod_pos'].' Tel.: '.$row_encabezado['telefono01'].' Fax: '.$row_encabezado['fax01'],0,1,'C');
		$this->Cell(170,3,'RFC:'.$row_encabezado['rfc'],0,1,'C',0);
		$this->Ln(2);
		  $this->SetFont('helvetica','',7);
		$this->Cell(170,3,"ATENDIO ".$rego['nom_ven'] . ' ' . $rego['ap_pat_ven'],0,1,'C');
		$this->Cell(170,3,'  Venta: '.str_pad($rego1['pedido'],12,'0',STR_PAD_LEFT).'   Fecha: '.date('d/m/Y').' Hora: '.date('H:i:s'),0,1,'C');
		$this->SetFont('helvetica','B',7);
		$this->Ln(5);
		$this->Cell(20,3,'CANT.',0,0,'L');
		$this->Cell(20,3,'P.U.',0,0,'C');
		$this->Cell(20,3,'CVE. ART.',0,0,'C');
		$this->Cell(95,3,'ARTICULO',0,0,'C');
		$this->Cell(15,3,'TOTAL',0,1,'C');
		
	}
	//Pie de Página
	function Footer(){
	}
}
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+3*$noRegsDetalle;
$anchoPagina=75;
//$arrhoja=array($altoPagina,$anchoPagina);
$arrhoja=array(215.9,139.7);//media carta
$pdf=new PDF('p','mm',$arrhoja);
$pdf->AddPage();
$pdf->SetFont('helvetica','',8);
$pdf->SetFillColor(192,192,192);
$pdf->SetMargins(20,5,5);

$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(20,3,$rego3['can_ref'],0,0,'L');
	$pdf->Cell(20,3,number_format($rego3['pre_bas'],2,'.',','),0,0,'R');
	$pdf->Cell(20,3,$rego3['nparte1'],0,0,'C');
	$pdf->Cell(95,3,$regox['np_desc1'],0,0,'C');
	$pdf->Cell(15,3,number_format($rego3['total_cd'],2,'.',','),0,1,'R');
	$numeroArticulos +=$rego3['can_ref'];
}
$pdf->Ln(5);
//$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(155,3,'Total:   $',0,0,'R');
$pdf->Cell(15,3,number_format($rego1['imp_pag'],2,'.',','),0,1,'R');
$pdf->Cell(155,3,'Cambio:  $',0,0,'R');
$pdf->Cell(15,3,number_format($rego1['cambio'],2,'.',','),0,0,'R');
$pdf->Ln(5);
//$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(135,3,'Articulos Vendidos: '.$numeroArticulos,0,1,'C');
//$pdf->Cell(65,3,'Gracias por su compra',0,1,'C');
//$pdf->Cell(65,3,'**Vuelva Pronto**',0,1,'C');

$pdf->Output('tiket.pdf','I');
?> 
