<?php

include('pdf/fpdf.php');
session_cache_limiter('private');
session_start();
$com = "I";
include("DMMYSQLG.php");
include("DSA3000.php");
 $f_v="";
 $f_f="";
 $cantidades=0;
 $total=0;
 $descuentos=0;
 $ivas=0;
 $tot=0;
 $total_cd=0;
class PDF extends FPDF
{
	//Cabecera de página 
	function Header()
	{
	    include("DYIM_VER.php");
            $vpb=(isset($_POST['bot']))?$_POST['bot']:"";
            if($vpb==""){
                
            }else{
			$result = mysqli_query($GLOBALS['con'] ,"SELECT * FROM dgreqdev WHERE fol_ven = '".$vpb."'");
while($row = mysqli_fetch_array($result))
{
     // print_r($row);
	$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"];
}
	    $this->SetFont('Arial','B',11);
		$this->Cell(200,10,'ENTRADAS VARIAS','',1,'C');
	    $this->Ln(5);
	    $this->SetFont('Arial','B',10);
            $vf=(isset($f))?$f:"";
          
		$bus=mysqli_fetch_array(mysqli_query($GLOBALS['con'] ,"select trefe from dgreqdev where fol_ven='".$vf."' "));
		$this->Cell(20,5,'','','','C');
		$this->Cell(40,5,'No. FACTURA:'.'  '.$bus['trefe'].'','','','C');
                $vfv=(isset($f_v))?$f_v:"";
		$fec1=$vfv;
		include('DF20000.php');
		$this->Cell(65,5,'      FECHA:'.'  '.$f_f.'','','','C');
		$vfc=(isset($folio_con))?$folio_con:0;
                if ($folio_con!=0)
                     
		$this->Cell(75,5,'ORDEN DE SERVICIO:'.'  '.$vfc.'','','1','C');
		else 	
		$this->Cell(75,5,'ORDEN DE SERVICIO:----','','1','C');
		$this->Cell(20,5,'','','','C');
		@$sql1 = mysqli_query($GLOBALS['con'] ,"select * from fproveedores where nparte1 = '$t_v'");
		@$reg1 = mysqli_fetch_array($sql1);
		$this->Cell(70,5,'  PROVEEDOR:'.'  '.$reg1['np_desc1'].'','','1','C');
		
		$this->Ln(5);
		$this->SetFont('ARIAL','B',8);
		$this->SetFillColor(225,225, 225);
		$this->Cell(5,5,'',0,0,'C','');
		$this->Cell(14,5,'CLAVE',1,0,'C',0);
		$this->Cell(60,5,'ARTICULO',1,0,'C',0);
		$this->Cell(10,5,'TIPO',1,0,'C',0);
		$this->Cell(18,5,'COSTO UNI.',1,0,'C',0);
		$this->Cell(12,5,'CANT',1,0,'C',0);
		$this->Cell(20,5,'IMPORTE',1,0,'C',0);
		$this->Cell(13,5,'DESC',1,0,'C',0);
		$this->Cell(13,5,'IVA',1,0,'C',0);
		
		$this->Cell(20,5,'TOTAL',1,1,'C',0);
		
	}
	
	//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');
	}
}}


//ABRIR EL DOCTO
$vd=(isset($data))?$data:"";
$num_elementos=count($vd);
$pdf=new PDF('P','mm','A4');
$pdf->AddPage();
$pdf->AliasNbPages();
$pdf->SetFont('Arial','',8);
$pdf->SetFillColor(233,233, 233);




	//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
                     $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 dgreqded where cons_ven = '".$_REQUEST['bot']."' and nparte1 = '$npr[$y]'");
		while($row = mysqli_fetch_array($res))
		{
			//--------------------------------->
			@$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(5,5, '',0,'','C');
			$pdf->Cell(14,5, $regxx["nparte1"] ,0,'','C');
			$pdf->Cell(60,5, utf8_decode($regxx["np_desc1"]),0,'','L');
			$almacen=mysqli_fetch_array(mysqli_query($GLOBALS['con'] ,"select np_desc1 from falmacen where nparte1='".$regxx['sub']."'"));
			$pdf->Cell(10,5, substr($almacen["np_desc1"],0,3),0,'','L');
			//$pdf->Cell(25,5,'$ ' . number_format($row["pre_uni"], 2, '.', ','),0,'','R');
			//--------------------------------->
			$pdf->Cell(18,5, number_format($row["pre_uni"], 2, '.', ','),0,'','R');
			$pdf->Cell(12,5, number_format($row["can_ref"],2,'.',','),0,'','R');
			
			$tcd=$row["subtotal"]-$row["des"]+$row["iva_pre"];
			
			$pdf->Cell(20,5, number_format($row["subtotal"], 2, '.', ','),0,'0','R');
			$pdf->Cell(13,5, number_format($row["des"], 2, '.', ','),0,'','R');
			$pdf->Cell(13,5, number_format($row["iva_pre"], 2, '.', ','),0,'','R');
			
			$pdf->Cell(20,5, number_format($tcd, 2, '.', ','),0,'1','R');
			
			$total +=$row["subtotal"];
			$tot +=$tcd;
			$cantidades +=$row["can_ref"];
			$descuentos +=$row["des"];
			$ivas +=$row["iva_pre"];
			$total_cd +=$row["total_cd"];
			//aqui sacar el almacen
			}
	}
	
	$pdf->SetFillColor(225,225, 225);
$pdf->Cell(5,5, '',0,'','C');
			$pdf->Cell(102,5, 'TOTALES:',1,'','R',0);
			//$pdf->Cell(35,5,'',1,'','R',0);
			$pdf->Cell(12,5,  number_format($cantidades, 2, '.', ','),1,'','R',0);
			$pdf->Cell(20,5,  number_format($total, 2, '.', ','),1,'0','R',0);
			$pdf->Cell(13,5,  number_format($descuentos, 2, '.', ','),1,'','R',0);
			$pdf->Cell(13,5,  number_format($ivas, 2, '.', ','),1,'','R',0);
			
			$pdf->Cell(20,5,  number_format($tot, 2, '.', ','),1,'1','R',0);

	$pdf->Cell(30,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',0);
				$pdf->Cell(20,5, 'TOTALES',1,'1','C',0);
				
	
	
	
	@$rpo = mysqli_query($GLOBALS['con'] ,"SELECT 
	distinct(farticulos.t7) as sUb 
	FROM 
	dgreqded 
	inner join farticulos on dgreqded.nparte1=farticulos.nparte1
	WHERE 
	cons_ven = '".$_REQUEST['bot']."'");
			while($rows = mysqli_fetch_array($rpo))
			{
				$pdf->SetFont('Arial','',8);
				$pdf->SetFillColor(225,225, 225);
                $pdf->Cell(10,5, '',0,'','C');
				$pdf->Cell(60,5, $rows["sUb"],1,'0','C',0);
				
				@$rpos = mysqli_query($GLOBALS['con'] ,"SELECT 
				
				
	sum(dgreqded.subtotal) as suBtotal,
	sum(dgreqded.des) as deScuento
	FROM 
	dgreqded 
	inner join farticulos on dgreqded.nparte1=farticulos.nparte1
	WHERE 
	cons_ven = '".$_REQUEST['bot']."'
	and farticulos.t7='".$rows['+[a-z_]+']."'");
			while($dfdsa=mysqli_fetch_array($rpos)){
			$tcd2=$dfdsa["suBtotal"]-$dfdsa["deScuento"];
			$pdf->Cell(20,5, '$'.number_format($tcd2,2,'.',','),1,'1','C',0);
			}
			}
   
   $pdf->SetFont('Arial','B',8);
	$pdf->SetFillColor(225,225, 225);
                $pdf->Cell(140,5, '',0,'0','C',0);
				$pdf->Cell(25,5, 'Sub-total',1,'0','C',0);
				$pdf->Cell(20,5, '$'.number_format($total, 2, '.', ','),1,'1','C',0);
				$pdf->Cell(140,5, '',0,'0','C',0);
				$pdf->Cell(25,5, 'Descuento',1,'0','C',0);
				$pdf->Cell(20,5, '$'.number_format($descuentos, 2, '.', ','),1,'1','C',0);
				$pdf->Cell(140,5, '',0,'0','C',0);
				$pdf->Cell(25,5, 'Total',1,'0','C',0);
				$pdf->Cell(20,5, '$'.number_format($tot, 2, '.', ','),1,'1','C',0);
				$pdf->Cell(140,5, '',0,'0','C',0);
				$pdf->Cell(25,5, 'I.V.A',1,'0','C',0);
				$pdf->Cell(20,5, '$'.number_format($ivas, 2, '.', ','),1,'1','C',0);
				$pdf->Cell(140,5, '',0,'0','C',0);
				$pdf->Cell(25,5, 'Neto',1,'0','C',0);
				$pdf->Cell(20,5, '$'.number_format($total_cd, 2, '.', ','),1,'1','C',0);
 mysqli_close($GLOBALS['con']);
$pdf->Output("Entradas_Varias.pdf","D");

?> 
