<?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',6);
	    //Espacio
		
	    $this->Cell(190,3,'RECIBO DE NOMINA',0,1,'C');
	    //Salto de línea
	    $this->Ln(5);
	}
	//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;
	}
}
include("DN51000_CL.php");
$arrhoja=array(215,140);
$pdf=new PDF('P','mm',$arrhoja);
$norec=0;
$pdf->AddPage();
$sqbusqx=mysqli_query($GLOBALS['con'] ,"select * from dntrab_a where no_nom = '".$_POST['bot']."'");
$busproc=mysqli_query($GLOBALS['con'] ,"select * from dnpargen");
$arbusproc=mysqli_fetch_array($busproc);
//$mesproc=$arbusproc["mes_pro"];
//$fecproc=$arbusproc["axo_pro"].'-'.$armes[$mesproc].'-01';
$nonom=$_POST['tenonom2'];
$periodo=$_POST['tefecini'].' al '.$_POST['tefecfin'];
$sql = mysqli_query ($sqw); 
$pdf->SetFont('Times','',5);
while($arbusq=mysqli_fetch_array($sqbusqx))
{
	$norec++;
	$nomusu = new clase('dnnomina',$arbusproc["axo_pro"],$arbusproc["mes_pro"],$_POST['setipnom'],$_POST['tenonom2'],$_POST['bot'],$_SESSION['num_usu']);
	$sqbusqxdat=mysqli_query($GLOBALS['con'] ,"select * from dndatnom where no_nom = '".$_POST['bot']."'");
	$sqbusqxx=mysqli_query($GLOBALS['con'] ,"select * from dntrab_b where no_nom = '".$_POST['bot']."'");
	$detnom=$nomusu->listaBusq();

	$arbusqxdat=mysqli_fetch_array($sqbusqxdat);
	$arbusqx=mysqli_fetch_array($sqbusqxx);
	
	$pdf->SetFillColor(230,230, 230);
	$pdf->Cell(20,2,'NO. RECIBO',0,0,'L',1);
	$pdf->Cell(75,2,$norec,0,1,'L');
	
	$pdf->Cell(20,2,'NO. NOMINA',0,0,'L',1);
	$pdf->Cell(50,2,$arbusq["no_nom"],0,0,'L');
	$pdf->Cell(73,2,'',0,0,'C',0);
	$pdf->Cell(20,2,'CTA. BANCO',0,0,'L',1);
	$pdf->Cell(30,2,$arbusqxdat['cta_sdopag'],0,1,'L');
	
	$pdf->Cell(20,2,'NOMBRE',0,'0','L',1);
	$pdf->Cell(50,2,$arbusq["nom"].' '.$arbusq["ape_pat"].' '.$arbusq["ape_mat"],0,'0','L');
	$pdf->Cell(73,2,'',0,0,'C',0);
	$pdf->Cell(20,2,'TIPO NOMINA',0,0,'L',1);
	$pdf->Cell(30,2,$arbusqxdat['tip_nom'],0,1,'L');
	
	$pdf->Cell(20,2,'R.F.C.',0,0,'L',1);
	$pdf->Cell(50,2,$arbusqx["rfc"],0,0,'L');
	$pdf->Cell(73,2,'',0,0,'C',0);
	$pdf->Cell(20,2,'PERIODO',0,0,'L',1);
	$pdf->Cell(30,2,'No.:'.$nonom.'   del '.$periodo,0,1,'L');
	
	$pdf->Cell(20,2,'I.M.S.S.',0,'0','L',1);
	$pdf->Cell(50,2,$arbusqx["seg_soc"],0,'0','L');
	$pdf->Cell(73,2,'',0,0,'C',0);
	$pdf->Cell(20,2,'DEPARTAMENTO',0,0,'L',1);
	$pdf->Cell(30,2,$arbusqxdat['depto'],0,1,'L');
	
	$pdf->Cell(20,2,'SUELDO DIA',0,'0','L',1);
	$pdf->Cell(50,2,$arbusqxdat['sal_diario'],0,'0','L');
	$pdf->Cell(73,2,'',0,0,'C',0);
	$pdf->Cell(20,2,'PUESTO',0,0,'L',1);
	$pdf->Cell(30,2,$arbusqxdat['puesto'],0,1,'L');
	
	$pdf->SetFillColor(0,0,0);
	$pdf->Cell(193,2,' ',0,1,'C');
	$pdf->Cell(193,0.3,' ',0,1,'C',1);
	$pdf->Cell(193,2,' ',0,1,'C');
	
	$pdf->SetFillColor(230,230, 230);
	$pdf->Cell(10,3,'NO.',1,0,'C',1);
	$pdf->Cell(50,3,'DES. PERCEPCIONES',1,0,'C',1);
	$pdf->Cell(15,3,'CANTIDAD',1,0,'C',1);
	$pdf->Cell(15,3,'IMPORTE',1,0,'C',1);
	$pdf->Cell(13,3,'',0,0,'C');
	$pdf->Cell(10,3,'NO.',1,0,'C',1);
	$pdf->Cell(50,3,'DES. DEDUCCIONES',1,0,'C',1);
	$pdf->Cell(15,3,'CANTIDAD',1,0,'C',1);
	$pdf->Cell(15,3,'IMPORTE',1,1,'C',1);
	$lab="P";
	$ent=-1;
	$cont=0;
	$cont1=0;
	$cont2=0;
	$totdp=array(0,0);
	while($adetnom=mysqli_fetch_array($detnom)){
		if($ent==-1) $ent=0;
		if($adetnom["operac"]!=$lab){
			$lab=$adetnom["operac"];
			$ent=1;
		}
		$dncapx=mysqli_query($GLOBALS['con'] ,"select * from dncatper where no_pd = '".$adetnom['no_pd']."' order by operac desc");
		$dncapxx=mysqli_fetch_array($dncapx);
		if($ent==0){ 
			$perded[$ent][$cont1][]=$adetnom["no_pd"];
			$perded[$ent][$cont1][]=$dncapxx["des_perc"];
			$perded[$ent][$cont1][]=$adetnom["can_mov"];
			$perded[$ent][$cont1][]=$adetnom["imp_mov"];
			$totpd[$ent] +=$adetnom["imp_mov"];
			$cont1++;
		}
		elseif($ent==1){ 
			$perded[$ent][$cont2][]=$adetnom["no_pd"];
			$perded[$ent][$cont2][]=$dncapxx["des_perc"];
			$perded[$ent][$cont2][]=$adetnom["can_mov"];
			$perded[$ent][$cont2][]=$adetnom["imp_mov"];
			$totpd[$ent] +=$adetnom["imp_mov"];
			$cont2++;
		}
	}
	if($GLOBALS['con']t1<=$cont2) $cont=$cont2;
	else $cont=$cont1;
	for($i=0; $i<$cont; $i++){
		if($GLOBALS['con']t1>$i){
			$pdf->Cell(10,3,$perded[0][$i][0],1,0,'C');
			$pdf->Cell(50,3,$perded[0][$i][1],1,0,'L');
			$pdf->Cell(15,3,$perded[0][$i][2],1,0,'C');
			$pdf->Cell(15,3,$perded[0][$i][3],1,0,'C');
		}
		else 
			$pdf->Cell(90,3,'',0,0,'C');
		$pdf->Cell(13,3,'',0,0,'C');
		if($GLOBALS['con']t2>$i){
			$pdf->Cell(10,3,$perded[1][$i][0],1,0,'C');
			$pdf->Cell(50,3,$perded[1][$i][1],1,0,'L');
			$pdf->Cell(15,3,$perded[1][$i][2],1,0,'C');
			$pdf->Cell(15,3,$perded[1][$i][3],1,1,'C');
		}
		else
			$pdf->Cell(90,3,'',0,1,'C');
	}
	$pdf->Cell(15,1,'',0,1,'C',0);
	$pdf->Cell(75,3,'TOTAL DE PERCEPCIONES: ',1,0,'C',0);
	$pdf->Cell(15,3,$totpd[0],1,0,'C');
	$pdf->Cell(13,3,'',0,0,'C');
	$pdf->Cell(75,3,'TOTAL DE DEDUCCIONES: ',1,0,'C',0);		
	$pdf->Cell(15,3,$totpd[1],1,1,'C');
	$pdf->Cell(193,1,'',0,1,'C');
	
	$netopag=$totpd[0]-$totpd[1];
	$intneto=floor($netopag);
	$decneto=ceil(($netopag-$intneto)*100);
	 
	if(($salto=40-$cont*3)>=3);
	else{
		$salto=0;
		$pdf->AddPage();
	}
	$pdf->Cell(20,$salto,'',0,1,'C');
	$pdf->SetFont('Times','',6);
	$pdf->SetFillColor(240,240, 240);
	$pdf->Cell(125,3,'RECIBI DE: '.$pdf->empresa(),0,1,'L',1);
	include('DF10000.php');
	$pdf->Cell(125,3,'( '.num2letras($intneto).' PESOS '.$decneto.'/'.'100 M. N.'.' )',0,0,'L',1);
	$pdf->Cell(20,3,'',0,0,'C');
	$pdf->Cell(20,3,'NETO A PAGAR: ',0,0,'L',1);
	$pdf->Cell(25,3,$netopag,0,1,'C',1);
	$pdf->Ln(4);
	$pdf->Cell(125,3,'Recibí de la compañía arriba mencionada el pago de mi sueldo y/o tiempo extra u otras prestaciones, hago constar mi conformidad con la anterior',0,1,'L',1);
	$pdf->Cell(125,3,'liquidación y la recibo a mi entera satisfacción, declarando que a la fecha no se me adeuda cantiad alguna.',0,0,'L',1);
	$pdf->Cell(20,3,'',0,0,'C');
	$pdf->Cell(45,3,'FIRMA EMPLEADO________________________',0,0,'L');
} 
$pdf->Output();
?> 