<?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()
	{
	    //Logotipo
	    $this->Image('logos/logo1.jpg',10,8,200,33);
	    //Arial Bold (14)
	    $this->SetFont('Arial','B',12);
	    //Espacio
		$this->Ln(30);
	    //Título
	    $this->Cell(0,10,'FACTURA DE VENTA EN CAJA',0,1,'C');
		$this->SetFont('Times','',7);
	    //Salto de línea
	   // $this->Ln(5);
/* 		$this->SetFont('Times','',7);
		$this->SetFillColor(192,192, 192);
		$this->Cell(8,5,'',0,0,'C');
		$this->Cell(15,5,'Dias',1,0,'C',1);
		$this->Cell(25,5,'Ventas Salvador',1,0,'C',1);
		$this->Cell(25,5,'Ventas Bolivar',1,0,'C',1);
		$this->Cell(25,5,'Total x Dia',1,0,'C',1);
		$this->Cell(25,5,'Acumulado',1,1,'C',1); 
*/
	}
	//Pie de Página
	function Footer()
	{
	    //Posición: 1,5 cm del Final
	    $this->SetY(-15);
	    //Arial Italic 8
	    $this->SetFont('Arial','I',8);
	    //Número de página
	    $this->Cell(0,0, $this->PageNo(),0,0,'C');
	}
}

$pdf=new PDF();
$pdf->AddPage();

//Consulta Datos Empresa
@$row_encabezado = mysqli_fetch_array(mysqli_query($con ,"SELECT * FROM geoyos_jc.dxempres where cla_emp = '".$_SESSION['empresa']."'"));
$cvdm = intval($row_encabezado['cve_delmun']);
$cves = intval($row_encabezado['cve_estado']);
//Consulta Datos Del/Mun
@$rowd_encabezado = mysqli_fetch_array(mysqli_query($con ,"SELECT * FROM geoyos_jc.dxdelmun where cve_delmun = '$cvdm'"));
//Consulta Datos Estado 
@$rowe_encabezado = mysqli_fetch_array(mysqli_query($con ,"SELECT * FROM geoyos_jc.dxestado where cve_estado = '$cves'"));

@$resu1=mysqli_query($con ,"select * from dgger_cajerosj where n_rec = '".$_SESSION['rec_caj']."'");
@$rego1=mysqli_fetch_array($resu1);
//savcar los datos de la venta
@$resu2=mysqli_query($con ,"select * from dgpemema where fol_ven = '".$rego1['pedido']."'");
@$rego2=mysqli_fetch_array($resu2);
//sacar al cliente del catalogo
@$resu23=mysqli_query($con ,"select * from dgcatcli where cod_cli = '".$rego2['cod_cli']."'");
@$rego23=mysqli_fetch_array($resu23);
$pdf->SetFont('Times','',7);
$pdf->Cell(0,5,"Col. ".$row_encabezado['des_col']." ".$rowd_encabezado['des_delmun']." ".$rowe_encabezado['des_estado']." AL" . date("j"). " DE ". date("m")." DEL ". date("Y"),0,1);
$pdf->Cell(190,5,"NOMBRE: " . $rego23['nom_cli'] . ' ' . $rego23['ap_pat_cli'] . ' ' . $rego23['ap_mat_cli'],0,1);
//sacar al cliente completo
@$resu233=mysqli_query($con ,"select * from dxbascps where codigo = '".$rego23['codigo']."'");
@$rego233=mysqli_fetch_array($resu233);
include("DMMYSQLG.php");
//colonia
@$resu6=mysqli_query($con ,"select * from dxcoloni where cve_col = '".$rego233['des_clonia']."'");
@$rego6=mysqli_fetch_array($resu6);
//municipio o delegacion
@$resu7=mysqli_query($con ,"select * from dxdelmun where cve_delmun = '".$rego233['cve_delmun']."'");
@$rego7=mysqli_fetch_array($resu7);
//estado
@$resu8=mysqli_query($con ,"select * from dxestado where cve_estado = '".$rego233['cve_estado']."'");
@$rego8=mysqli_fetch_array($resu8);
include("DMMYSQLG.php");
if($rego233['calle'] == ""){
	$pdf->MultiCell(0,5,'DIRECCION: ');
}else{
	$pdf->MultiCell(0,5,'DIRECCION: C.'.$rego233['calle'].' #int '.$rego233['no_int'].' #Ext '.$rego233['no_ext'].' entre calle '.$rego233['entre_calle'].' y calle '.$rego233['y_calle'].' '.$rego6['des_colonia'].' '.$rego7['des_delmun']. ' CP: ' . $rego233['cod_pos']);
}

$pdf->Cell(90,5,'CIUDAD: '.$rego6['des_estado'],0,0);
$pdf->Cell(20,5,'RFC: '.$rego23['rfc_cli'] ,0,1);

@$resu3=mysqli_query($con ,"select * from dgpememd where cons_ven = '".$rego1['pedido']."'");
$pdf->Cell(30,5,'CANTIDAD',1,0,'C');
$pdf->Cell(100,5,'DESCRIPCION',1,0,'C');
$pdf->Cell(30,5,'PRECIO UNITARIO',1,0,'C');
$pdf->Cell(30,5,'IMPORTE',1,1,'C');
while(@$rego3=mysqli_fetch_array($resu3)){
	$num_elementos1 += 1;
	$pdf->Cell(.01,5,'',1,0,'C');
	$pdf->Cell(29.99,5,$rego3['can_ref'],0,0,'C');
	@$resux=mysqli_query($con ,"SELECT * FROM dginvent WHERE dginvent.modulo='".$_SESSION['mod_sis']."' AND   nparte1 = '".$rego3['nparte1']."'");
	@$regox=mysqli_fetch_array($resux);
	$pdf->Cell(100,5,$regox['np_desc1'],0,0);
	$pdf->Cell(30,5,'$  ' . number_format($rego3['pre_uni'], 2, '.', ','),0,0,'C');
	$pdf->Cell(29.99,5,'$  ' . number_format($rego3['total_cd'], 2, '.', ','),0,0,'C');
	$pdf->Cell(.01,5,'',1,1,'C');
}
$dif = 30 - $num_elementos1;
	if ($dif<=30){
		for($y=0;$y<=$dif;$y++){
			$pdf->Cell(.01,5,'',1,0,'C');
			$pdf->Cell(189.98,5,'',0,0,'C');
			$pdf->Cell(.01,5,'',1,1,'C');
		}
	}
	$pdf->SetFillColor(49,120, 200);
	$pdf->Cell(189.8,.01,'',1,1,'C');
	$pdf->Cell(5,5,'',0,1,'C');

	$pdf->Cell(134.8,5,'',0,0,'C');
	$pdf->Cell(21,5,'SUBTOTAL:',0,0,1);
	$pdf->Cell(4,5, '$',0,0,'C');
	$pdf->Cell(30,5,'$  ' . number_format($rego2['sub_ven'], 2, '.', ','),0,1,'R');

	$pdf->Cell(134.8,5,'',0,0,'C');
	$pdf->Cell(21,5,'IVA:',0,0,1);
	$pdf->Cell(4,5, '$',0,0,'C');
	$pdf->Cell(30,5,'$  ' . number_format($rego2['iva_ven'], 2, '.', ','),0,1,'R');
	
	include("DF10000.php");
	$can = $rego2['tot_ven'] + .1;
	$pre_let=num2letras(number_format($can, 2, '.', ','));
	
	$pdf->Cell(134.8,5,$pre_let.' PESOS M.N.',0,0,'C');
	$pdf->Cell(21,5,'TOTAL NETO:',0,0,1);
	$pdf->Cell(4,5, '$',0,0,'C');
	$pdf->Cell(30,5,'$  ' . number_format($rego2['tot_ven'], 2, '.', ','),0,1,'R');
	$pdf->Output();
?>