<?php

include('pdf/MC_TABLE.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 PDF_MC_Table{
		//Cabecera de página
		function Header(){
			//Logo
			include("DYIM_VER.php");
			//Arial bold 14
			$this->SetFont('Arial','B',10);
			//Espacio
			
			//Título
			$this->SetFillColor(248);
			$this->Cell(195,5,'LISTADO DE TRASPASO',0,1,'C');
			$this->SetFont('Arial','B',8);
			$this->Cell(195,5,'DEL '.trim($_POST['fecini']).' AL '.trim($_POST['fecfin']),0,1,'C');
			//Salto de línea
			$this->Ln(5);
			$this->SetFont('Arial','B',6);
			$this->Cell(97.5,5,'Origen',1,0,'C',1);
			$this->Cell(97.5,5,'Destino',1,1,'C',1);
			
			$this->Cell(18,5,'Almacen',1,0,'C',1);
			$this->Cell(10,5,'Cantidad',1,0,'C',1);
			$this->Cell(18,5,'Clave',1,0,'C',1);
			$this->Cell(51.5,5,'Producto',1,0,'C',1);
			
			$this->Cell(18,5,'Almacen',1,0,'C',1);
			$this->Cell(10,5,'Cantidad',1,0,'C',1);
			$this->Cell(18,5,'Clave',1,0,'C',1);
			$this->Cell(51.5,5,'Producto',1,1,'C',1);			
			//establece tamaño de letra
			$this->Ln(2);
			$this->SetFont('Times','',7);
		}
		
		//Pie de página
		function Footer(){
			//Posición: a 1,5 cm del final
			$this->SetY(-15);
			//Arial italic 8
			$this->SetFont('Arial','I',6);
			//Número de página
			$this->Cell(0,10, $this->PageNo().'/{nb}',0,0,'C');
		}
	}

	
	$pdf=new PDF('P','mm','letter');
	$pdf->AddPage();
	$pdf->SetFillColor(240);
	$pdf->AliasNbPages();
	$pdf->SetAutoPageBreak(10);
	/***tabla1***/ 
	//ancho 195
	$fecIni=chfecha(trim($_POST['fecini']),'d/m/Y','Y-m-d');
	$fecFin=chfecha(trim($_POST['fecfin']),'d/m/Y','Y-m-d');
	$busg = mysqli_query($GLOBALS['con'] ,"SELECT * FROM dgtraspe where acc_fec between '$fecIni' AND '$fecFin'");
	
	$pdf->SetFontSize('6');
	$pdf->SetWidths(array(18,10,18,51.5,18,10,18,51.5));
	$pdf->SetAligns(array('L','R','L','L','L','R','L','L'));
	$pdf->SetDrawColor(255);	

	while($resg = mysqli_fetch_array($busg)){
		$pdf->Cell(25,5,'Observaciones:',0,0,'C',1);
		$pdf->Cell(170,5,$resg["obse"],0,1,'L');
		
		$pdf->Cell(32.5,5,'FOLIO: '.$resg['fol_tra'],0,'L');//centra
		$pdf->Cell(25,5,'Fecha:',1,0,'C',1);
		$pdf->Cell(25,5,chfecha($resg["acc_fec"],'Y-m-d','d/m/Y'),1,0,'C');
		
		$pdf->Cell(10,5,'Operador:',1,0,'C',1);
		$sqln=mysqli_query($GLOBALS['con'] ,"SELECT * FROM geoyos_jc.dxopemaex where oper = '".$resg['usuario']."'");
		$resn=mysqli_fetch_array($sqln);
		$pdf->Cell(70,5,$resn["nombre"],1,1,'C');
		/***Termina tabla1***/
	
		/***Inicia tabla2***/
		//Encabezados
		$pdf->Ln(3);

		$sqla=mysqli_query($GLOBALS['con'] ,"SELECT * FROM dgtraspd where fol_tra1 = '".$resg['fol_tra']."'");
		while($rega = mysqli_fetch_array($sqla)){
			//almacen origen
			$row1 = mysqli_fetch_array(mysqli_query($GLOBALS['con'] ,"SELECT * FROM dgalmacen WHERE almacen = '".$rega['alm_ori']."'"));
			$re = mysqli_fetch_array(mysqli_query($GLOBALS['con'] ,"SELECT * FROM dginvent WHERE dginvent.modulo='".$_SESSION['mod_sis']."' AND   nparte1 = '".$rega['nparte1']."'"));
			$row2 = mysqli_fetch_array(mysqli_query($GLOBALS['con'] ,"SELECT * FROM dgalmacen WHERE almacen = '".$rega['alm_des']."'"));
			$re2 = mysqli_fetch_array(mysqli_query($GLOBALS['con'] ,"SELECT * FROM dginvent WHERE dginvent.modulo='".$_SESSION['mod_sis']."' AND   nparte1 = '".$rega['nparte2']."'"));
	
			$pdf->Row(array(
				$row1["desc_almacen"],
				$rega["can_ori"],
				$rega["nparte1"],
				$re["np_desc1"],
				$row2["desc_almacen"],
				$rega["can_des"],
				$rega["nparte2"],
				$re2["np_desc1"]
			));
		}
	}
$pdf->Output("Listado_de_Traspasos.pdf","D");

?>
