<?php

include('pdf/fpdf.php');
session_cache_limiter('private');
session_start();
$com = "I";
include("DMMYSQLG.php");
include("DSA3000.php");
$f_f="";
$s=0;
 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(),0,0,'C');
	}
}
$vpb=(isset($_POST['bot']))?$_POST['bot']:"";
	$result = mysqli_query($GLOBALS['con'] ,"SELECT * FROM dgrequie WHERE fol_ven = '".$vpb."'");
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"];
	
	$sub=$row["sub_ven"];
	$iva=$row["iva_ven"];
	$total=$row["tot_ven"];
	$folio_con=$row["folio_control"];
} 
//ABRIR EL DOCTO
$vd=(isset($data))?$data:"";
$num_elementos=count($vd);
$pdf=new PDF();
$pdf->AddPage();
$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,'SALIDAS 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,'DEPARTAMENTO:',0,0,'R');
@$sql1 = mysqli_query($GLOBALS['con'] ,"select * from fdepartamento where nparte1 = '$t_v'");
@$reg1 = mysqli_fetch_array($sql1);
$pdf->Cell(50,5,$reg1['np_desc1'],0,0,'');
$pdf->Cell(1,5,'',0,0,'C');
//Fecha de la Ordem
$vf=(isset($f_v))?$f_v:"";
$fec1=$vf;
include('DF20000.php');
$pdf->Cell(15,5,'FECHA:',0,0,'');
$pdf->Cell(20,5,$f_f,0,0,'L');
$pdf->Cell(1,5,'',0,0,'C');
//Numero de la Orden
$pdf->Cell(25,5,'REQUISICION Nº',0,0,'');
$vfc=(isset($folio_con))?$folio_con:0;
$pdf->Cell(15,5,$vfc,0,1,'C');
//folio control
//$pdf->Cell(25,5,'Folio control',0,0,'');
//$pdf->Cell(15,5,$folio_con,0,1,'C');

//Proveedor

$pdf->Cell(5,5,'',0,1,'C');
$pdf->SetFont('Arial','',8);
$pdf->SetFillColor(50,120, 200);
//$pdf->Cell(10,5,'CANT',1,'','C',1);
$pdf->Cell(80,5,'PRODUCTO',1,'','C',1);
$pdf->Cell(30,5,'PRECIO UNITARIO',1,'','C',1);
$pdf->Cell(30,5,'CANTIDAD',1,'','C',1);
$pdf->Cell(30,5,'IMPORTE TOTAL',1,1,'C',1);
//$pdf->Cell(30,5,'PRODUCTO',1,'','C',1);
//$pdf->Cell(30,5,'PRODUCTO',1,1,'C',1);
//$pdf->Cell(150,5,'PRODUCTO',1,1,'C',1);
/*$pdf->Cell(25,5,'PRECIO/UNI',1,'','C',1);
$pdf->Cell(20,5,'% DES',1,'','C',1);
$pdf->Cell(25,5,'PRECIO/DES',1,'','C',1);
$pdf->Cell(25,5,'SUBTOTAL',1,1,'C',1);*/
	//Saca el Numero de Producto
		@$res = mysqli_query($GLOBALS['con'] ,"SELECT * FROM dgrequid WHERE cons_ven = '".$_REQUEST['bot']."'");
			while($row = mysqli_fetch_array($res))
			{
				$npr[]=$row["nparte1"];	
			}
	//Cuenta los Registros
           $vnp=(isset($npr))?$npr:"";             
	$num_elementos=count($vnp);
	//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($vnp);
	for($y=0;$y<=$num_elementos1-1;$y++)
	{	
		//Muestra los Datos Encontrados de la Tabla dgrefodd
		@$res=mysqli_query($GLOBALS['con'] ,"select * from dgrequid where cons_ven = '".$_REQUEST['bot']."' and nparte1 = '$npr[$y]'");
		while($row = mysqli_fetch_array($res))
		{
			
			//@$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(80,5, $regxx["nparte1"] . ' / ' . $regxx["np_desc1"],0,0,'C');

			$pdf->Cell(30,5,'$ ' . number_format($row["pre_uni"], 2, '.', ','),0,'','R');
			$pdf->Cell(30,5, $row["can_ref"],0,'','C');
			$sbt = $row['pre_uni'] * $row['can_ref'];
			$pdf->Cell(30,5, '$ ' . number_format($sbt,2,'.',','),0,'1','R');
			$s = $s + $sbt;
			//--------------------------------->
			//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');
		}
	}
	
	$pdf->SetFillColor(192,192, 192);
	$pdf->Cell(189.8,.1,'',1,1,'C');
	$pdf->Cell(5,5,'',0,1,'C');
	$pdf->Cell(134.8,5,'',0,1,'C');
	
	$pdf->SetFont('Arial','B',8);
	$pdf->SetFillColor(225,225, 225);
                $pdf->Cell(10,5, '',0,'0','C',0);
				$pdf->Cell(60,5, 'SUB-GRUPO',1,'0','C',1);
				$pdf->Cell(20,5, 'TOTALES',1,'1','C',1);
	
	@$rpo = mysqli_query($GLOBALS['con'] ,"SELECT 
	distinct(farticulos.t7) as sUb 
	FROM 
	dgrequid 
	inner join farticulos on dgrequid.nparte1=farticulos.nparte1
	WHERE 
	cons_ven = '".$_POST['bot']."'");
			while($rows = mysqli_fetch_array($rpo))
			{
				$pdf->SetFont('Arial','',8);
				
                $pdf->Cell(10,5, '',0,'','C');
				$pdf->Cell(60,5, utf8_decode($rows["sUb"]),1,'0','C',0);
				
				@$rpos = mysqli_query($GLOBALS['con'] ,"SELECT 
				
				
	sum(dgrequid.can_ref * dgrequid.pre_uni) as suBtotal
	
	FROM 
	dgrequid 
	inner join farticulos on dgrequid.nparte1=farticulos.nparte1
	WHERE 
	cons_ven = '".$_POST['bot']."'
	and farticulos.t7='".$rows['+[a-z_]+']."'");
			while($dfdsa=mysqli_fetch_array($rpos)){
			$tcd2=$dfdsa["suBtotal"];
			$pdf->Cell(20,5, '$'.number_format($tcd2,2,'.',','),1,1,'C',0);
			}
			}
	$pdf->SetFont('Arial','B',8);
	$pdf->SetFillColor(225,225, 225);
                $pdf->Cell(10,5, '',0,'0','C',0);
				$pdf->Cell(120,5, '',0,'0','C',0);
				$pdf->Cell(20,5, 'TOTAL',1,'0','C',0);
                                $vs=(isset($s))?$s:0;
				$pdf->Cell(20,5, '$ ' . number_format($vs,2,'.',','),1,'1','C',0);		
    
	
	
 mysqli_close($GLOBALS['con']);
$pdf->Output("Salidas_Varias.pdf","D");
?> 
