<?php

include('pdf/fpdf.php');
session_cache_limiter('private');
session_start();
$com = "I";
include("DMMYSQLG.php");
include("DSA3000.php");
include("DMMYSQLG.php");
require_once("DF80000.php");
class PDF extends FPDF{
//Cabecera de página
	function Header(){
	    //Logo
	         include("DYIM_VER.php");
	    //Arial bold 14
		$this->SetFont('Arial','B',12);
		//Título
		$this->Cell(6,5,'',0,0,'C',0);
		$this->Cell(200,5,'INVENTARIO FISICO DE ARTICULOS',0,1,'C',0);
		//Salto de línea
		$this->SetFont('Arial','I',10);
		$agrupador=mysqli_fetch_array(mysqli_query($GLOBALS['con'] ,"select * from fagrupadores where n_reg='".$_POST['agrupador']."'"));
		$this->Cell(55,5,''.$agrupador['n_reg'].' | '.$agrupador['np_desc1'].'',0,1,'C',0);
		$this->Ln(8);
		$this->SetFont('Arial','B',8);//establece tamaño de letra
		$this->SetFillColor(192,192,192);
		$this->Cell(4,5,'',0,0,'C',0);
		$this->cell(12,5,'CLAVE',1,0,'C',0);
		$this->cell(62,5,'ARTICULO',1,0,'C',0);
		$this->cell(20,5,'UNIDAD',1,0,'C',0);
		$this->Cell(18,5,'ALMACEN',1,0,'C',0);
		$this->Cell(16,5,'INV. INI.',1,0,'C',0);
		$this->Cell(18,5,'ENTRADAS',1,0,'C',0);
		$this->cell(20,5,'SALIDAS',1,0,'C',0);
		$this->cell(18,5,'EXISTENCIA',1,0,'C',0);
		$this->cell(18,5,'U. COSTO',1,0,'C',0);
		$this->cell(18,5,'PRECIO PROM',1,0,'C',0);
		$this->cell(18,5,'TOTAL',1,0,'C',0);
		$this->cell(18,5,'DIFERENCIA',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(),0,0,'C');
	}
}

$pdf=new PDF('P','mm','Letter');
$pdf->AddPage();

$pdf->SetFillColor(192,192,192);
$pdf->SetFont('Arial','',7);//establece tamaño de letra

//$tbus=mysqli_real_escape_string($GLOBALS['con'],$_POST['tbus']);

$mysql=mysqli_fetch_array(mysqli_query($GLOBALS['con'] ,"select * from fagrupadores where n_reg='".$_POST['agrupador']."'"));
	
	
	if($_POST['agrupador']!='T') {
		 $arrBus[]="WHERE t8='".$mysql['np_desc1']."'";		
	}
	if($_POST['sub']!='T') 
	{
	 	$arrBus[]="t7='".$_POST['sub']."'";
	    
	}else{
	    $sub=mysqli_query($GLOBALS['con'] ,"SELECT distinct(np_desc1) FROM fsubagrupadores where almacen='$selPais' and t1='ACTIVO'");
	}	
	
 	$WHERE=implode(" AND ",$arrBus);
	
	
	
	if ($_POST['sub']!='T'){
	
		
		$pdf->SetFont('Arial','',8);
    $pdf-> Cell(6,5,'',0,0,'C',0);
	$pdf-> Cell(47,5, $mysql["np_desc1"].'-'.$_POST['sub'],10,1,'L',0);
		
	}else{
	while($sql=mysqli_fetch_array($sub)){
	
	//echo "<tr>
      //    <td colspan='2' style='#9B0F1A'><div align='left'><strong>".$mysql['np_desc1']."-".$sql['np_desc1']."</strong></div></td>
       //   </tr>";
	}
	}
	
	$result = mysqli_query($GLOBALS['con'] ,"select * from farticulos $WHERE order by np_desc1");
	$c=0;
	while($reg = mysqli_fetch_array($result))
	{
	
	$pdf->SetFont('Arial','',8);
    $pdf-> Cell(4,5,'',0,0,'C',0);
	$pdf-> Cell(12,5, $reg["nparte1"],10,0,'C',0);
    $pdf-> Cell(62,5, $reg["np_desc1"],10,0,'L',0);
	$almacen=mysqli_fetch_array(mysqli_query($GLOBALS['con'] ,"select np_desc1 from falmacen where nparte1='".$reg['sub']."'"));
	$pdf-> Cell(20,5, $almacen["np_desc1"],10,0,'R',0);
	$pdf-> Cell(18,5,'$ '.number_format($reg["t3"],2,'.',','),10,0,'R',0);
	$pdf-> Cell(16,5,'$ '.number_format($reg["cos_prom"],2,'.',','),10,0,'R',0);
	$pdf-> Cell(18,5, number_format($reg["t5"],2,'.',','),10,0,'R',0);
	$pdf-> Cell(20,5,'____________  ',10,0,'L',0);
	$pdf-> Cell(18,5,'  ____________',10,1,'L',0);
			
		$c++;
		
	    }

        $pdf-> Cell(6,5,'',0,0,'C',0);
	    $pdf-> Cell(20,5,'Articulos Encontrados: ',10,0,'C',0);
        $pdf-> Cell(39,5, $c,10,1,'C',0);
		
$pdf->Output("Inventario_Fisico_De_Articulos.pdf","D");
//170 --> 100 ULTIMA ACTUALZACION
//148 --> 100 ULTIMA ACTUALZACION 15/DICIEMBRE/2011 TODO EN UN SOLO RENGLON
//182 --> 100 ULTIMA ACTUALZACION 6/ENERO/2012 AGRUPAR POR ORDENADOR.
//ULTIMA ACTUALIZACION 12/ENERO/2012 REPORTE DE CAMBIO DE HAB
?> 