<?php

include('pdf/fpdf.php');
session_cache_limiter('private');
session_start();
$com = "I";
include("DMMYSQLG.php");
include("DSA3000.php");
include("DMMYSQLG.php");
 
class PDF extends FPDF
{
	var $nomemp;
	//Cabecera de Página
	function Header()
	{
	    //Logotipo
	    //Consulta Datos Empresa
		include("DMMYSQLG.php");
		$sql_encabezado = mysqli_query($GLOBALS['con'] ,"SELECT * FROM dxempres where cla_emp = $_SESSION['empresa']");
		$row_encabezado = mysqli_fetch_array($sql_encabezado);
		
		$cvdm = intval($row_encabezado['cve_delmun']);
		$cves = intval($row_encabezado['cve_estado']);
		
		//Consulta Datos Del/Mun
		$sqld_encabezado = mysqli_query($GLOBALS['con'] ,"SELECT * FROM dxdelmun where cve_delmun = $cvdm");
		$rowd_encabezado = mysqli_fetch_array($sqld_encabezado);
		
		//Consulta Datos Estado 
		$sqle_encabezado = mysqli_query($GLOBALS['con'] ,"SELECT * FROM dxestado where cve_estado = $cves");
		$rowe_encabezado = mysqli_fetch_array($sqle_encabezado);
		
		$this->SetFont('Arial','B',8);
		
		//Empresa
		$this->Cell(180,3,'',0,1,'L');
		$this->Cell(190,3,$row_encabezado['nom_emp'],0,1,'C');
		$this->nomemp=$row_encabezado['nom_emp'];
		//Domicilio
		$this->SetFont('Arial','B',5);
		$tamx=40;
		$this->Cell(180,1,'',0,1,'L');
		$this->Cell($tamx,1,'Domicilio.',0,0,'R');
		$this->MultiCell(140,1,' '.$row_encabezado['calle'].' '.$row_encabezado['no_ext'].' '.$row_encabezado['no_int'],0,1,'L');
		$this->Cell(180,1,'',0,1,'L');
		$this->Cell($tamx,1,'Colonia.',0,0,'R');
		$this->MultiCell(140,1,' '.$row_encabezado['des_col'].' Del-Mun. '.$rowd_encabezado['des_delmun'].' Edo. '.$rowe_encabezado['des_estado'],0,1,'L');
		
		//Telefonos
		$this->Cell(180,1,'',0,1,'L');
		$this->Cell($tamx,1,'C.P.',0,0,'R');
		$this->Cell(140,1,' '.$row_encabezado['cod_pos'].' Telefono: '.$row_encabezado['telefono01'].' Fax: '.$row_encabezado['fax01'],0,1,'L');
		
		//Registro Federal de Comtribuyentes
		$this->Cell(180,1,'',0,1,'L');
		$this->Cell($tamx,1,'R.F.C.',0,0,'R');
		$this->Cell(140,1,' '.$row_encabezado['rfc'],0,1,'L');
		$this->Cell($tamx,1,'',0,1,'R');
		$this->Cell($tamx,1,'Fecha:',0,0,'R');
		$this->Cell(25,1,date("d/m/Y"),0,0,'');
		$this->Cell(15,1,'Hora:',0,0,'R');
		$this->Cell(25,1,date('H:i:s'),0,0,'');
		// ---------------IMAGEN--------------- //
		$logo='logos/'.$_SESSION['base'].'.jpg';
		$this->Image($logo,10,13,($tamx-10),15);
		$this->Ln(5);
		//include("DYIM_VER.php");
	    //Arial Bold (14)
		include("DMMYSQLG.php");
	    $this->SetFont('Arial','B',7);
	    //Espacio
		$this->Cell(190,3,'PER./DED. ACUMULADAS',0,1,'C');
		$this->SetFillColor(225,225, 225);
		$this->SetFont('Arial','',7);
		$nonom=$_POST['tenonom2'];
		$periodo='MES - AÑO ('.$_SESSION['m_a'].')';
		$sqtipnom=mysqli_fetch_array(mysqli_query($GLOBALS['con'] ,"select * from dntipnom where cve_nomi = '".$_POST['setipnom']."'"));
		$dncapxx=mysqli_fetch_array(mysqli_query($GLOBALS['con'] ,"select * from dncatper where no_pd = '".$_POST['secatpd']."'  and operac='".$_POST['seperded']."' order by operac desc"));
		$this->Cell(30,3,'',0,0,'L');
		$this->Cell(50,3,'TIPO NOMINA',1,0,'C',1);
		$this->Cell(50,3,'MOVIMIENTO',1,0,'C',1);
		$this->Cell(30,3,'FECHA',1,1,'C',1);
		$this->Cell(30,3,'',0,0,'L');
		$this->Cell(50,3,$sqtipnom["des_nomi"],1,0,'C');
		$this->Cell(50,3,$dncapxx['operac'].'|'.$dncapxx['no_pd'].'|'.$dncapxx['des_perc'],1,0,'C');
		$this->Cell(30,3,$periodo,1,1,'C');
		$this->SetFont('Arial','',5);
		$this->Cell(32.5,3,'',0,0,'L',0);
		$this->Cell(15,3,'NO. NOMINA',1,0,'L',1);
		$this->Cell(50,3,'NOMBRE',1,'0','L',1);
		$this->Cell(30,3,'CAN. MOV. ',1,'0','L',1);
		$this->Cell(30,3,'IMP. MOV. ',1,'1','L',1);
	    //Salto de línea
	    $this->Ln(3);
	}
	//Pie de Página
	function Footer()
	{
	    //Posición: 1,5 cm del Final
	    $this->SetY(-15);
	    //Arial Italic 8
	    $this->SetFont('Arial','I',5);
	    //Número de página
	    $this->Cell(0,0, $this->PageNo(),0,0,'C');
	}
	
	function empresa(){
	return $this->nomemp;
	}
}
$m=substr($_SESSION['m_a'],0,2);
$a=substr($_SESSION['m_a'],2,4);
include("DN53000_CL.php");
include('DF10000.php');
$arrhoja=array(215,280);
$pdf=new PDF('P','mm',$arrhoja);
$nomusu = new clase('dnnommen',$a,$m,$_POST['setipnom'],-1,$_POST['seperded'],$_POST['secatpd'],$_SESSION['num_usu']);
$norec=0;
$pdf->AddPage();
$result=$nomusu->listaElem();
$cchck=$nomusu->conReg();
$pdf->SetFillColor(230,230, 230);

$pdf->SetFont('Times','',6);
for($dfi=0; $dfi<$cchck; $dfi++) 
{
	$norec++;
	$lab="P";
	$ent=-1;
	$cont=0;
	$cont1=0;
	$cont2=0;
	$totpd=array(0,0);
	//Busquedas de c/trbajador
	$chboxes=mysqli_fetch_array($result);
	$nomusu->modEmp("$chboxes['no_nom']");
	$noEmp = $nomusu->getEmp();
	$sqbusqx=mysqli_query($GLOBALS['con'] ,"select * from dntrab_a where no_trab = '$noEmp'");
	$arbusq=mysqli_fetch_array($sqbusqx);
	$sqbusqxdat=mysqli_query($GLOBALS['con'] ,"select * from dndatnom where no_nom = '$noEmp'");
	$sqbusqxx=mysqli_query($GLOBALS['con'] ,"select * from dntrab_b where no_nom = '$noEmp'");
	$detnom=$nomusu->listaBusq();
	$arbusqxdat=mysqli_fetch_array($sqbusqxdat);
	$arbusqx=mysqli_fetch_array($sqbusqxx);
	$buspue=mysqli_fetch_array(mysqli_query($GLOBALS['con'] ,"select * from dncatpue where no_puesto = '".$arbusqxdat['puesto']."'"));
	$busdep=mysqli_fetch_array(mysqli_query($GLOBALS['con'] ,"select * from dncatdep where no_depto = '".$arbusqxdat['depto']."'"));
	if($_REQUEST['ra_imp']=='dep'){
		if($depto!=$chboxes['depto']){
			$ct_dncatdep=mysqli_fetch_array(mysqli_query($GLOBALS['con'] ,"select * from dncatdep where no_depto = '".$chboxes['depto']."'"));
			if($dfi>0) impTot($totdep,$pdf);
			$totdep=NULL;
			$pdf->Cell(32.5,3,'',0,1,'L');
			$pdf->Cell(32.5,3,'',0,0,'L');
			$pdf->Cell(125,1,$ct_dncatdep['no_depto'].'-'.$ct_dncatdep['des_depto'],0,1,'C',1);
			$depto= $chboxes['depto'];
		}
	}
	$perded=NULL;
	$pdf->SetFillColor(0,0,0);
	$pdf->SetFillColor(230,230, 230);
	
	if($ent==-1) $ent=0;
	if($_POST['seperded']!=$lab) $ent=1;
	while($adetnom=mysqli_fetch_array($detnom)){//Inicia separa detalles de trabajador per/ded
		llenaDet($adetnom,$togen);
		llenaDet($adetnom,$perded);
		if($_REQUEST['ra_imp']=='dep'){
			llenaDet($adetnom,$totdep);
		}
	}//Termina separa detalles de trabajador per/ded
	$pdf->Cell(32.5,3,'',0,0,'L');
	$pdf->Cell(15,3,$arbusq["no_nom"],0,0,'L');
	if($arbusqxdat['status']=='A') $pdf->Cell(50,3,$arbusq["nom"].' '.$arbusq["ape_pat"].' '.$arbusq["ape_mat"],0,'0','L');
	else  $pdf->Cell(50,3,$arbusq["nom"].' '.$arbusq["ape_pat"].' '.$arbusq["ape_mat"].'(Inactivo)',0,'0','L');
	$pdf->Cell(30,3,number_format($perded[2],2,'.',','),0,0,'L');
	$pdf->Cell(30,3,number_format($perded[3],2,'.',','),0,1,'L');
} 

if($_REQUEST['ra_imp']=='dep'){
		if($dfi>0) impTot($totdep,$pdf);
		$totdep=NULL;
}
///*Se añade pagina para imprimir resumen de detalles con valores totales y neto*/
$pdf->SetFont('Times','B',7);
$pdf->Cell(190,3,'RESUMEN',0,1,'C');
impTot($togen,$pdf);
$pdf->Output();

function llenaDet($adetnom,&$perded){
	$dncapxx=mysqli_fetch_array(mysqli_query($GLOBALS['con'] ,"select * from dncatper where no_pd = '".$adetnom['no_pd']."'  and operac='".$adetnom['operac']."' and cve_mae = '".$adetnom['cve_mae']."' order by operac desc"));
	$perded[0]=$adetnom["no_pd"];
	$perded[1]=$dncapxx["des_perc"];
	$perded[2]+=$adetnom["can_mov"];
	$perded[3]+=$adetnom["imp_mov"];
}

function impTot($togen,&$pdf){
	$pdf->Cell(32.5,3,'',0,0,'L');
	$pdf->Cell(65,3,'TOTAL : ',0,0,'R');
	$pdf->Cell(30,3,number_format($togen[2],2,'.',','),0,0,'L');
	$pdf->Cell(30,3,number_format($togen[3],2,'.',','),0,1,'L');
}
?> 