<?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()
	{
	    include("DYIM_VER.php");
	    $this->SetFont('Arial','B',11);

		

		//$this->Cell(95,10,$_POST['txt_empresa'],1,1,'C');

	    $this->Ln(1);
	}
	
	//Pie de página
	function Footer()
	{
	    //Posición: a 1,5 cm del final
	    $this->SetY(-15);
	    //Arial italic 8
	    $this->SetFont('Arial','I',8);
	    //Número de página
	    $this->Cell(0,10, $this->PageNo().'de {nb}',0,0,'C');
	}
}


	$result = mysqli_query($GLOBALS['con'] ,"SELECT * FROM dgreqdev WHERE fol_ven = '".$_POST['bot']."'");

while($row = mysqli_fetch_array($result))
{
	$t_v=$row["tip_ven"];
	$f_v=$row["fec_ven"];
	$f=$row["fol_ven"];
	$e_v=$row["cod_ven"];
	$c=$row["cod_cli"];
	$v_a=$row["con_cre"];
	$sub=$row["sub_ven"];
	$iva=$row["iva_ven"];
	$total=$row["tot_ven"];
	$folio_con=$row["folio_control"];
} 
//ABRIR EL DOCTO
$num_elementos=count($data);
$pdf=new PDF();
$pdf->AddPage();
$pdf->AliasNbPages();
$pdf->SetFont('Arial','',8);
$pdf->SetFillColor(49,120, 200);

//Fecha
//$pdf->Cell(12,5,'FECHA:',0,0,'');
//$pdf->Cell(18,5,date("d/m/Y"),0,1,'C');

//Titulo
$pdf->Cell(190,5,'ENTRADAS VARIAS',0,1,'C');
//Empresa
//$pdf->Cell(190,5,'*** '.$_SESSION['ne'].' ***',0,1,'C');
$pdf->Cell(5,5,'',0,1,'C');

//Tipo de Compra
$pdf->Cell(34,5,'TIPO:',0,0,'R');
@$sql1 = mysqli_query($GLOBALS['con'] ,"select * from fproveedores where tip_car = '$t_v'");
@$reg1 = mysqli_fetch_array($sql1);
$pdf->Cell(60,5,$reg1['des_tipcar'],0,0,'');
$pdf->Cell(1,5,'',0,0,'C');

//Fecha de la Ordem
$fec1=$f_v;
include('DF20000.php');
$pdf->Cell(40,5,'FECHA:',0,0,'');
$pdf->Cell(20,5,$f_f,0,0,'');
$pdf->Cell(1,5,'',0,0,'C');

//Numero de la Orden
$pdf->Cell(25,5,'ENTRADA No.',0,0,'');
$pdf->Cell(15,5,$reg1['des_tipcar'],0,1,'');
//folio control
$pdf->Cell(25,5,'Folio control',0,0,'');
$pdf->Cell(15,5,$folio_con,0,1,'C');


//Proveedor
/*$pdf->Cell(34,5,'EJECUTIVO DE VENTAS:',0,0,'R');
@$sql2 = mysqli_query($GLOBALS['con'] ,"select * from dgcatven where cod_ven = '$e_v'");
@$reg2 = mysqli_fetch_array($sql2);
$pdf->Cell(80,5,$reg2['nom_ven'] . ' ' . $reg2['ap_pat_ven'] . ' ' . $reg2['ap_mat_ven'],0,1,'');

$pdf->Cell(34,5,'CLIENTE:',0,0,'R');
@$sql3 = mysqli_query($GLOBALS['con'] ,"select * from dgcatcli where cod_cli = '$c'");
@$reg3 = mysqli_fetch_array($sql3);
$pdf->Cell(66,5,$reg3['nom_cli'] . ' ' . $reg3['ap_pat_cli'] . ' ' . $reg3['ap_mat_cli'],0,1,'');

//Tipo Moneda
$pdf->Cell(34,5,'VENTA A:',0,0,'R');
if($v_a==1){
	$pdf->Cell(21,5,'CONTADO',0,1,'');
}elseif($v_a==2){
	$pdf->Cell(21,5,'CREDITO',0,1,'');
}else{
	$pdf->Cell(21,5,'',0,1,'');
}
*/
//Clave Moneda
/*$pdf->Cell(25,5,'CLAVE MONEDA:',0,0,'');
@$sql4 = mysqli_query($GLOBALS['con'] ,"select * from dxpaimon where cve_mon = '$c_m'");
@$reg4 = mysqli_fetch_array($sql4);
$pdf->Cell(25,5,$reg4['des_moneda'],0,0,'');

//Tipo de Cambio
include("DMMYSQLG.php");

$pdf->Cell(26,5,'TIPO DE CAMBIO:',0,0,'');
$pdf->Cell(20,5,'$ '.$tip_c,0,1,'');*/

$pdf->Cell(5,5,'',0,1,'C');

$pdf->SetFont('Arial','',7);
$pdf->SetFillColor(49,120, 200);

$pdf->Cell(10,5,'CANT',1,'','C',1);
$pdf->Cell(30,5,'ALMACEN',1,'','C',1);
$pdf->Cell(150,5,'PRODUCTO',1,1,'C',1);


	//Saca el Numero de Producto
		@$res = mysqli_query($GLOBALS['con'] ,"SELECT * FROM dgreqded WHERE cons_ven = '".$_REQUEST['bot']."'");
			while($row = mysqli_fetch_array($res))
			{
				$npr[]=$row["nparte1"];	
			}

	//Cuenta los Registros
	$num_elementos=count($npr);
	//Saca la Descripcion del Producto
	for($j=0;$j<=$num_elementos-1;$j++)
	{
		@$res=mysqli_query($GLOBALS['con'] ,"SELECT * FROM farticulos WHERE farticulos.modulo='".$_SESSION['mod_sis']."' AND   nparte1 = '$npr[$j]'");
		while($row = mysqli_fetch_array($res))
		{
			$dpr[]=$row["np_desc1"];	
		}
	}
	$num_elementos1=count($npr);
	for($y=0;$y<=$num_elementos1-1;$y++)
	{	
		//Muestra los Datos Encontrados de la Tabla dgrefodd
		@$res=mysqli_query($GLOBALS['con'] ,"select * from dgreqded where cons_ven = '".$_REQUEST['bot']."' and nparte1 = '$npr[$y]'");
		while($row = mysqli_fetch_array($res))
		{
			$pdf->Cell(10,5, $row["can_ref"],0,'','C');
			@$sqlxxz = mysqli_query($GLOBALS['con'] ,"select * from dgalmacen where almacen = '".$row['almacen']."'");
			@$regxxz = mysqli_fetch_array($sqlxxz);
			$pdf->Cell(30,5, $regxxz["desc_almacen"],0,'','C');
			//aqui sacar el almacen
			//--------------------------------->
			@$sqlxx = mysqli_query($GLOBALS['con'] ,"SELECT * FROM farticulos WHERE farticulos.modulo='".$_SESSION['mod_sis']."' AND   nparte1 = '".$row['nparte1']."'");
			@$regxx = mysqli_fetch_array($sqlxx);
			$pdf->Cell(55,5, $regxx["nparte1"] . ' / ' . $regxx["np_desc1"],0,1,'C');

			//$pdf->Cell(25,5,'$ ' . number_format($row["pre_uni"], 2, '.', ','),0,'','R');
			//--------------------------------->
			//aqui sacar el descuento
			//$pdf->Cell(20,5, $row["por_des"].' %',0,'','R');
			//$pdf->Cell(25,5,'$ ' . number_format($row["imp_des"], 2, '.', ','),0,'','R');
			//$pdf->Cell(25,5,'$ ' . number_format($row["subtotal"], 2, '.', ','),0,1,'R');
		}
	}
	/*$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,.1,'',1,1,'C');
	$pdf->Cell(5,5,'',0,1,'C');

	$pdf->Cell(134.8,5,'',0,1,'C');
	/*$pdf->Cell(21,5,'SUBTOTAL:',0,0,'R');
	$pdf->Cell(34,5,'$ ' . number_format($sub, 2, '.', ','),0,1,'R');
*/
	$pdf->Cell(39.9,5,'',0,0,'C');
	$pdf->Cell(20,5,'_______________',0,0,'C');
	$pdf->Cell(15,5,'',0,0,'C');
	$pdf->Cell(20,5,'_______________',0,0,'C');
	$pdf->Cell(39.9,5,'',0,1,'C');
/*
	$pdf->Cell(21,5,'IVA:',0,0,'R');
	$pdf->Cell(34,5,'$ ' . number_format($iva, 2, '.', ','),0,1,'R');
*/
	$pdf->Cell(39.9,5,'',0,0,'C');
	$pdf->Cell(20,5,'SOLICITADO',0,0,'C');
	$pdf->Cell(15,5,'',0,0,'C');
	$pdf->Cell(20,5,'AUTORIZADO',0,0,'C');
	$pdf->Cell(39.9,5,'',0,0,'C');

	//$pdf->Cell(21,5,'TOTAL NETO:',0,0,'R');
	//$pdf->Cell(34,5,'$ ' . number_format($total, 2, '.', ','),0,1,'R');

 mysqli_close($GLOBALS['con']);
$pdf->Output("Entradas_Varias.pdf","D");
?> 
