<?php

include('pdf/fpdf.php');
session_cache_limiter('private');
session_start();
$com = "I";
include("DMMYSQLG.php");
include("DSA3000.php");
include("DMMYSQLG.php");
include('DF80000.php');
 
class PDF extends FPDF{
	//Cabecera de Página
	function Header(){
	    //Logotipo
	    include("DYIM_VER.php");
	    //Arial Bold (14)
	    $this->SetFont('Arial','B',12);
	    //Espacio
		
	    //Título 
//		$this->Ln(5);
		$rec = mysqli_fetch_array(mysqli_query($GLOBALS['con'] ,"select * from frecomp order by nparte1 desc limit 1"));
	    $this->Cell(250,3,'ORDEN DE COMPRA  '.$rec["nparte1"].'',0,1,'C');
		$this->Cell(250,3,'',0,1,'C');
		$this->SetFont('Arial','B',8);
		$this->Cell(250,3,'Del '.chfecha($rec['fec_ini_pro'],'Y-m-d','d/m/Y').' al '.chfecha($rec['fec_fin_pro'],'Y-m-d','d/m/Y').'',0,1,'C');
		$this->Cell(250,3,'',0,1,'C');
		$this->Cell(250,3,'DEPARTAMENTO:  '.$rec["np_desc1"].'',0,1,'C');
		$this->Cell(250,3,'ALMACEN:  '.$rec["descripcion"].'',0,1,'C');
	    //Salto de línea
	    $this->Ln(5);
		$this->SetFont('ARIAL','B',8);
		$this->SetFillColor(230,230,230);
		$this->Cell(10,5,'Clave',1,0,'C',1);
		$this->Cell(30,5,'Articulo',1,0,'C',1);
		$this->Cell(30,5,'Marca',1,0,'C',1);
		$this->Cell(30,5,'Proveedor',1,0,'C',1);	
		$this->Cell(15,5,'Cantidad',1,0,'C',1);
		$this->Cell(25,5,'Unidad de medida',1,0,'C',1);
		$this->Cell(25,5,'Costo promedio',1,0,'C',1);
		$this->Cell(25,5,'Costo por unidad',1,0,'C',1);
		$this->Cell(20,5,'Subtotal',1,0,'C',1);
		$this->Cell(25,5,'Fecha inicial',1,0,'C',1);
		$this->Cell(25,5,'Fecha final',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().'/{nb}',0,0,'C');
	}
}
$pdf;

$pdf=new PDF('L','mm','Letter');
$pdf->AddPage();
$pdf->AliasNbPages();
$binit=-1;
$pdf->SetFillColor(240,240,240);
$pdf->SetFont('Arial','',8);
@$sql = mysqli_query($GLOBALS['con'] ,"
	SELECT * FROM frecomart where codfre=(select nparte1 from frecomp order by nparte1 desc limit 1)");
echo mysqli_error($GLOBALS['con']);
while($reg = mysqli_fetch_array($sql)){

		$pdf->Cell(10,4,$reg['codart'],0,0,'C',0);
		$pdf->Cell(30,4,$reg['desc_art'],0,0,'C',0);					
		$pdf->Cell(30,4,$reg['nom_mar'],0,0,'C',0);
		$pdf->Cell(30,4,$reg['nom_prov'],0,0,'C',0);
		$pdf->Cell(15,4, number_format(($reg['cant']),2,'.',','),0,0,'R',0);					
		$pdf->Cell(25,4,$reg['uni_med'],0,0,'C',0);
		$pdf->Cell(25,4,number_format($reg['cos_prom'],2,'.',','),0,0,'R',0);
		$pdf->Cell(25,4,number_format($reg['precio'],2,'.',','),0,0,'R',0);
		$pdf->Cell(20,4,number_format($reg['subpre'],2,'.',','),0,0,'R',0);
		$pdf->Cell(25,4,chfecha($reg['fec_ini'],'Y-m-d','d/m/Y'),0,0,'C',0);
		$pdf->Cell(25,4,chfecha($reg['fec_fin'],'Y-m-d','d/m/Y'),0,1,'C',0);					
		$total +=$reg["subpre"];
	}
		$pdf->SetFont('ARIAL','B',8);
		$pdf->SetFillColor(210,210,210);
		$pdf->Cell(10,4,'',0,0,'C',1);
		$pdf->Cell(30,4,'',0,0,'C',1);					
		$pdf->Cell(30,4,'',0,0,'C',1);
		$pdf->Cell(30,4,'',0,0,'C',1);
		$pdf->Cell(15,4,'',0,0,'R',1);					
		$pdf->Cell(25,4,'',0,0,'C',1);
		$pdf->Cell(25,4,'',0,0,'R',1);
		$pdf->Cell(25,4,'',0,0,'R',1);
		$pdf->Cell(20,4,'',0,0,'R',1);
		$pdf->Cell(25,4,'TOTAL',0,0,'C',1);
		$pdf->Cell(25,4,number_format($total,2,'.',','),0,1,'R',1);


$pdf->Output("ORDEN DE COMPRA.pdf","D");
?>


