<?
//--------------------------------------------------------------------------------------------------------------------------------- REPORTE RESUMEN GENERAL DE CONCEPTOS
if (isset($_SESSION['tipousuario']))
		{if ($_SESSION['tipousuario']=='1')
		header ('location:menu_personal.php');
		}

if ($_POST['treporte']==1) {
	if ($_POST['salida']=='1') {
		require('fpdf.php');
		class PDF extends FPDF {
		function Header()
		{
			//$this->Image($_SESSION['logo_validar'],10,10,40,40);
			$this->Image($_SESSION['logo_validar'],90,6,40,30);

			$this->SetFont('arial','B',12);
			$this->Ln(2);
			if ($_POST['cierre']==0) $this->Cell(0,5,'Reporte de PRE-CIERRE',0,0,'L'); else $this->Cell(0,5,'CIERRE AUDITADO',0,0,'L');
			$this->SetFont('arial','B',10);
			$this->Cell(0,5,'Nomina: '.$_POST['empresa'],0,1,'R');
			$this->SetFont('arial','',8);
			$this->Cell(0,5,$_POST['empresal'],0,0,'L'); $this->Cell(0,5,'Fecha: '.hoy(),0,1,'R');
			$this->Cell(0,5,'Rif: '.$_POST['encabeza'],0,0,'L'); $this->Cell(0,5,'Hora: '.hora(),0,1,'R');
			$this->Ln(5);
			//$this->SetFont('arial','',10);
			//$this->Cell(0,5,'Fecha: '.hoy(),0,0,'L');
			//$this->Cell(0,5,'Nomina: '.$_POST['empresa'],0,1,'R');
			//$this->Cell(0,5,'Hora: '.hora(),0,1,'L');
			$this->Ln(20);
			$this->SetFont('arial','B',12);
			$this->Cell(0,0,($_POST['titulo']==''?'RESUMEN GENERAL DE CONCEPTOS':$_POST['titulo']),0,1,'C');$this->Ln(5);
			$this->Cell(0,0,$_POST['subtitulo'],0,1,'C');$this->Ln(5);
			$this->SetFont('arial','',8);
			$this->Cell(0,0,'Periodo: '.$_POST['periodo'],0,1,'L');$this->Ln(5);
			if ($_POST['gerencia']!="") {
				$this->Cell(0,0,'Gerencia: '.$_POST['gerencia'],0,1,'L');$this->Ln(5);
			}
			if ($_POST['division']!="") {
				$this->Cell(0,0,'División: '.$_POST['division'],0,1,'L');$this->Ln(5);
			}
			if ($_POST['departamento']!="") {
				$this->Cell(0,0,'Departamento: '.$_POST['departamento'],0,1,'L');$this->Ln(5);
			}
			$header=array('Cod.','Descripción','Asignación','Deducción','# Personas');
			$this->SetFillColor(70,77,119);
			$this->SetTextColor(255);
			$this->SetDrawColor(255,255,255);
			$this->SetLineWidth(.5);
			$this->SetFont('','');
			//Cabecera
			$this->SetFont('arial','B',8);
			$w=array(10,90,30,30,30);
			for($i=0;$i<count($header);$i++)
				$this->Cell($w[$i],4,$header[$i],1,0,'C',1);
			$this->Ln();
			$this->SetFont('');
		}
		function Footer()
		{
		$this->SetY(-20);
		$this->Cell(0,0,'',1,1,'C');
		$this->SetFont('Times','I',8);
		$this->ln(2);
		$this->Cell(0,0,$_POST['pie'],0,1,'C');
		$this->Cell(0,10,'Usuario: '.$_POST['usuario'].' - Página '.$this->PageNo().'/{nb} - Derechos: '.$_POST['derecho'],0,0,'C');
		}
		}
		//Cuerpo ////////////////////////////////////////
		$pdf=new PDF();
		$pdf->AddPage();
		$pdf->AliasNbPages();
		$pdf->SetFont('arial','',8);
		$pdf->SetFillColor(238,239,243);
		$pdf->SetTextColor(0);


		if ($_POST['eshistorico']!=1) $consulta=mysqli_query($enlace,"select * from $payroll WHERE substr($payroll.concepto,1,1)!=5 AND substr($payroll.concepto,1,1)!=6 AND substr($payroll.concepto,1,1)!=4 AND concepto NOT IN(2000,2001,2002,2003,2004,2005,2006,2007,2010,2012) order by $payroll.concepto,$payroll.desconcepto"  );
		else {
			if ($gerencia==1) $queryx="select $payroll.* from $payroll,personal where personal.id='".$_SESSION['id_validar']."' and $payroll.cedula=personal.codigo ".$queryy." AND substr($payroll.concepto,1,1)!=5 AND substr($payroll.concepto,1,1)!=6 AND substr($payroll.concepto,1,1)!=4 AND concepto NOT IN(2000,2001,2002,2003,2004,2005,2006,2007,2010,2012) order by $payroll.concepto, $payroll.desconcepto";
			else $queryx="select $payroll.* from $payroll,personal where personal.id='".$_SESSION['id_validar']."' and $payroll.tipo<>'R' and $payroll.cedula=personal.codigo ".$queryy." AND substr($payroll.concepto,1,1)!=5 AND substr($payroll.concepto,1,1)!=6 AND substr($payroll.concepto,1,1)!=4 AND concepto NOT IN(2000,2001,2002,2003,2004,2005,2006,2007,2010,2012) order by $payroll.concepto, $payroll.desconcepto";
			$consulta=mysqli_query($enlace,$queryx) or die ($queryx.mysqli_error($enlace));
		}

		$linea=0;
		$color=0;
		$tasig=0;
		$tdeduc=0;
		$bandera=0;
		$ttasig=0; $ttdeduc=0;
		while($row=mysqli_fetch_array($consulta)) {
			$ttasig+=($row['tipo']=='A'?$row['monto']:0);
			$ttdeduc+=($row['tipo']=='D'?$row['monto']:0);
			if ($bandera==0) {
				$bandera=1;
				$tconcepto=($row['concepto']=='2200'||$row['concepto']=='ASIG'?("D".substr($row['desconcepto'],0,4)):($row['concepto']));
			}

			$tconcepto1=($row['concepto']=='2200'||$row['concepto']=='ASIG'?("D".substr($row['desconcepto'],0,4)):($row['concepto']));

			if ($tconcepto==$tconcepto1) {
				$tasig+=($row['tipo']=='A'?$row['monto']:0);
				$tdeduc+=($row['tipo']=='D'?$row['monto']:0);
				$tconcepto=($row['concepto']=='2200'||$row['concepto']=='ASIG'?("D".substr($row['desconcepto'],0,4)):($row['concepto']));
				$tdetalle=substr($row['desconcepto'],0,50);
				$linea++;
			}
			else {
				$pdf->cell(10,5,$tconcepto,0,0,'',$color);
				$pdf->cell(60,5,$tdetalle,0,0,'',$color);
				$pdf->cell(60,5,number_format($tasig,2),0,0,'R',$color);
				$pdf->cell(30,5,number_format($tdeduc,2),0,0,'R',$color);
				$pdf->cell(30,5,number_format($linea),0,1,'R',$color);
				$color=!$color;
				$linea=1;
				$tasig=($row['tipo']=='A'?$row['monto']:0);
				$tdeduc=($row['tipo']=='D'?$row['monto']:0);
				$tconcepto=($row['concepto']=='2200'||$row['concepto']=='ASIG'?("D".substr($row['desconcepto'],0,4)):($row['concepto']));
				$tdetalle=substr($row['desconcepto'],0,50);
			}
		}
		$pdf->cell(10,5,$tconcepto,0,0,'',$color);
		$pdf->cell(60,5,$tdetalle,0,0,'',$color);
		$pdf->cell(60,5,number_format($tasig,2),0,0,'R',$color);
		$pdf->cell(30,5,number_format($tdeduc,2),0,0,'R',$color);
		$pdf->cell(30,5,number_format($linea),0,1,'R',$color);
		$pdf->Cell(190,0,'',1,1,'C');
		$pdf->cell(100,5,'Sub-Totales',0,0,'R');
		$pdf->cell(30,5,number_format($ttasig,2) ,0,0,'R');
		$pdf->cell(30,5,number_format($ttdeduc,2) ,0,1,'R');
		$pdf->Cell(190,0,'',1,1,'C'); $pdf->ln(1);
		$pdf->Cell(190,0,'',1,1,'R'); $pdf->ln(1);
		$pdf->cell(100,5,'Total General',0,0,'R');
		$pdf->cell(90,5,number_format($ttasig-$ttdeduc,2) ,0,1,'R');
		$pdf->Output('Resumen_General_de_Conceptos.pdf','D');
	} //================= salida PDF

	if ($_POST['salida']=='2') {
		echo "<center>";
		echo "<font face='verdana' color='black' size='5'>";
		echo "<br>".$_POST['empresal'];

		echo "<font face='verdana' color='black' size='3'>";
		echo "<br>".$_POST['encabeza'];
		if ($_POST['cierre']==0) echo '<br>Reporte de PRE-CIERRE';
		else echo '<br>CIERRE AUDITADO';

		echo "<font face='verdana' color='black' size='3'>";
		echo "<br>".$_POST['periodo'];

		echo "<font face='verdana' color='black' size='4'>";
		echo "<br><br>".($_POST['titulo']==''?'RESUMEN GENERAL DE CONCEPTOS':$_POST['titulo']);
		echo "</center></font>";

		echo "<table  cellpadding=2 cellspacing=0 align='center'>";
		echo "<tr BGcolor='#464D77' style='color:#fff;' >";
			echo "<th ali=center><font face='verdana' size=2>C&oacute;digo</font></th> ";
			echo "<th ali=center><font face='verdana' size=2>Detalle</font></th>";
			echo "<th ali=center><font face='verdana' size=2>Asignaci&oacute;n</font></th>";
			echo "<th ali=center><font face='verdana' size=2>Deducci&oacute;n</font></th>";
			echo "<th ali=center><font face='verdana' size=2># Personas</font></th>";
		echo "</tr>";

		if ($_POST['eshistorico']!=1) $consulta=mysqli_query($enlace,"select * from $payroll WHERE substr($payroll.concepto,1,1)!=5  AND substr($payroll.concepto,1,1)!=6 AND substr($payroll.concepto,1,1)!=4 AND concepto NOT IN(2000,2001,2002,2003,2004,2005,2006,2007,2010,2012) order by $payroll.concepto,$payroll.desconcepto"  );
		else {
			if ($gerencia==1) $queryx="select $payroll.* from $payroll,personal where personal.id='".$_SESSION['id_validar']."' and $payroll.cedula=personal.codigo ".$queryy." AND  substr($payroll.concepto,1,1)!=9 AND substr($payroll.concepto,1,1)!=6 AND substr($payroll.concepto,1,1)!=9  order by $payroll.concepto, $payroll.desconcepto";
			else $queryx="select $payroll.* from $payroll,personal where personal.id='".$_SESSION['id_validar']."' and $payroll.tipo<>'R' and $payroll.cedula=personal.codigo ".$queryy." and substr($payroll.concepto,1,1)!=9 AND substr($payroll.concepto,1,1)!=9 AND substr($payroll.concepto,1,1)!=9  order by $payroll.concepto, $payroll.desconcepto";
			$consulta=mysqli_query($enlace,$queryx) or die ($queryx.mysqli_error($enlace));
		}
		$linea=0;
		$color=0;
		$tasig=0;
		$tdeduc=0;
		$bandera=0;
		$ttasig=0; $ttdeduc=0;
		while($row=mysqli_fetch_array($consulta)) {
			$ttasig+=($row['tipo']=='A'?$row['monto']:0);
			$ttdeduc+=($row['tipo']=='D'?$row['monto']:0);
			if ($bandera==0) {
				$bandera=1;
				$tconcepto=($row['concepto']=='2200'||$row['concepto']=='ASIG'?("D".substr($row['desconcepto'],0,4)):($row['concepto']));
			}

			$tconcepto1=($row['concepto']=='2200'||$row['concepto']=='ASIG'?("D".substr($row['desconcepto'],0,4)):($row['concepto']));

			if ($tconcepto==$tconcepto1) {
				$tasig+=($row['tipo']=='A'?$row['monto']:0);
				$tdeduc+=($row['tipo']=='D'?$row['monto']:0);
				$tconcepto=($row['concepto']=='2200'||$row['concepto']=='ASIG'?("D".substr($row['desconcepto'],0,4)):($row['concepto']));
				$tdetalle=substr($row['desconcepto'],0,50);
				$linea++;
			}
			else {

				if ($color) echo '<tr bgcolor="white" >';
				else echo '<tr bgcolor="#EEEFF3">';
				$color=!$color;

				echo "<td width='60' align='center'><font face='verdana' color='black' size='3'>".$tconcepto."</font></td>";
				echo "<td width='320'><font face='verdana' color='black' size='3'>".$tdetalle."</font></td>";
				echo "<td width='160' align='right'><font face='verdana' color='#36C1E2' size='3'><b>".number_format($tasig,2)."</font></b></td>";
				echo "<td width='160' align='right'><font face='verdana' color='#DD0044' size='3'>".number_format($tdeduc,2)."</font></td>";
				echo "<td width='160' align='right'><font face='verdana' color='black' size='3'>".number_format($linea,0)."</font></td>";

				$linea=1;
				$tasig=($row['tipo']=='A'?$row['monto']:0);
				$tdeduc=($row['tipo']=='D'?$row['monto']:0);
				$tconcepto=($row['concepto']=='2200'||$row['concepto']=='ASIG'?("D".substr($row['desconcepto'],0,4)):($row['concepto']));
				$tdetalle=substr($row['desconcepto'],0,50);

				echo "</tr>";
			}
		}
		if ($color) echo '<tr bgcolor="white" >';
		else echo '<tr bgcolor="#EEEFF3">';
		echo "<td width='60' align='center'><font face='verdana' color='black' size='3'>".$tconcepto."</font></td>";
		echo "<td width='320'><font face='verdana' color='black' size='3'>".$tdetalle."</font></td>";
		echo "<td width='160' align='right'><font face='verdana' color='#36C1E2' size='3'><b>".number_format($tasig,2)."</font></b></td>";
		echo "<td width='160' align='right'><font face='verdana' color='#DD0044' size='3'>".number_format($tdeduc,2)."</font></td>";
		echo "<td width='160' align='right'><font face='verdana' color='black' size='3'>".number_format($linea,0)."</font></td>";

		echo "<tr BGcolor='#464D77' style='color:#fff;' >";
		echo "<th ali=center colspan=2><font face='verdana' size=3>Totales Bs.</font></th> ";
		echo "<td width='120' align='right'><font face='verdana' size='3'><b>".number_format($ttasig,2)."</font></b></td>";
		echo "<td width='120' align='right'><font face='verdana'  size='3'>".number_format($ttdeduc,2)."</font></td>";
		echo "<th align='right'><font face='verdana' size=3>".number_format($ttasig-$ttdeduc,2)."</font></th>";
		echo "</tr>";
	} //================= salida PANTALLA


}

//--------------------------------------------------------------------------------------------------------------------------------- REPORTE
//--------------------------------------------------------------------------------------------------------------------------------- RESUMEN INDIVIDUAL
if ($_POST['treporte']==2) {
	if ($_POST['salida']==1) {
		require('fpdf.php');
		class PDF extends FPDF {
		function Header()
		{
	    $this->Image($_SESSION['logo_validar'],10,10,30,30);
	    $this->SetFont('arial','B',8);
		$this->Ln(2);
		if ($_POST['cierre']==0) $this->Cell(0,5,'Reporte de PRE-CIERRE',0,1,'R'); else $this->Cell(0,5,'CIERRE AUDITADO',0,1,'R');
		$this->SetFont('arial','B',10);
	    $this->Cell(0,5,$_POST['empresal'],0,1,'R');
		$this->SetFont('arial','',6);
		$this->Cell(0,5,$_POST['encabeza'],0,1,'R');
		$this->Ln(2);
		$this->SetFont('arial','',7);
	    $this->Cell(0,5,'Fecha: '.hoy(),0,1,'R');
		$this->Cell(0,5,'Hora: '.hora(),0,1,'R');

	    $this->Ln(5);
		$this->SetFont('arial','B',12);
		$this->Cell(0,0,($_POST['titulo']==''?'Resumen Individual de Pago de Nomina':$_POST['titulo']),0,1,'C');$this->Ln(5);
		$this->Cell(0,0,$_POST['subtitulo'],0,1,'C');$this->Ln(5);
		$this->SetFont('arial','',7);
		$this->Cell(0,0,'Nomina: '.$_POST['empresa'],0,0,'L');
		$this->Cell(0,0,'Periodo: '.$_POST['periodo'],0,1,'R');$this->Ln(3);
		if ($_POST['gerencia']!="") {
			$this->Cell(0,0,'Gerencia: '.$_POST['gerencia'],0,1,'L');$this->Ln(5);
		}
		if ($_POST['division']!="") {
			$this->Cell(0,0,'División: '.$_POST['division'],0,1,'L');$this->Ln(5);
		}
		if ($_POST['departamento']!="") {
			$this->Cell(0,0,'Departamento: '.$_POST['departamento'],0,1,'L');$this->Ln(5);
		}
		    $header=array('Cod.','Cedula','Nombres y Apellidos','Asignación','Deducción','Total Neto (BS)');
		    $this->SetFillColor(70,77,119);
			$this->SetTextColor(255);
			$this->SetDrawColor(255,255,255);
			$this->SetLineWidth(.5);
		    $this->SetFont('','');
			$this->SetFont('arial','B',8);
		    $w=array(10,15,55,25,25,25);
			for($i=0;$i<count($header);$i++)
		        $this->Cell($w[$i],4,$header[$i],1,0,'C',1);
		    $this->Ln();
		    $this->SetFont('');
		}
		function Footer()
		{
		$this->SetY(-20);
		$this->Cell(0,0,'',1,1,'C');
		$this->SetFont('Times','I',8);
		$this->ln(2);
		$this->Cell(0,0,$_POST['pie'],0,1,'C');
		$this->Cell(0,10,'Usuario: '.$_POST['usuario'].' - Página '.$this->PageNo().'/{nb} - Derechos: '.$_POST['derecho'],0,0,'C');
		}
		}
		//Cuerpo ///////////////////////////////
		$pdf=new PDF();
		$pdf->AddPage();
		$pdf->AliasNbPages();
		$pdf->SetFont('Arial','',8);
		$pdf->SetFillColor(224,235,255);
		$pdf->SetTextColor(0);
		if ($_POST['eshistorico']!=1) $consulta=mysqli_query($enlace,"select * from $payroll WHERE substr($payroll.concepto,1,1)!=5  AND substr($payroll.concepto,1,1)!=6 AND substr($payroll.concepto,1,1)!=4 AND concepto NOT IN(2000,2001,2002,2003,2004,2005,2006,2007,2010,2012) order by cedula"  );
		else {
			if ($gerencia==1) $queryx="select $payroll.* from $payroll,personal where personal.id='".$_SESSION['id_validar']."' and $payroll.cedula=personal.codigo ".$queryy." AND substr($payroll.concepto,1,1)!=5 AND substr($payroll.concepto,1,1)!=6 AND substr($payroll.concepto,1,1)!=4 AND concepto NOT IN(2000,2001,2002,2003,2004,2005,2006,2007,2010,2012) order by $payroll.cedula,$payroll.concepto, $payroll.desconcepto";
			else $queryx="select $payroll.* from $payroll,personal where personal.id='".$_SESSION['id_validar']."' and $payroll.tipo<>'R' and $payroll.cedula=personal.codigo ".$queryy." AND substr($payroll.concepto,1,1)!=5 AND substr($payroll.concepto,1,1)!=6 AND substr($payroll.concepto,1,1)!=4 AND concepto NOT IN(2000,2001,2002,2003,2004,2005,2006,2007,2010,2012) order by $payroll.cedula, $payroll.concepto, $payroll.desconcepto";
			$consulta=mysqli_query($enlace,$queryx) or die ($queryx.mysqli_error($enlace));
		}

		$linea=0;
		$color=0;
		$tasig=0;
		$tdeduc=0;
		$bandera=0;
		$ttasig=0; $ttdeduc=0;
		$extra=array();
		$prestac=false;
		$textra=0;
		while($row=mysqli_fetch_array($consulta)) {
			$ttasig+=(($row['tipo']=='A'&& $row['concepto']!='5008'&& $row['concepto']!='5009')?$row['monto']:0);
			$ttdeduc+=($row['tipo']=='D'?$row['monto']:0);
			if ($bandera==0) {
				$bandera=1;
				$tcedula=$row['cedula'];
			}
			if ($tcedula==$row['cedula']) {
				if($row['concepto']!=="5008"&&$row['concepto']!=="5009"){
					$tasig+=($row['tipo']=='A'?$row['monto']:0);
				}
				/*
				else{
					$prestac=true;
					$textra+=$row['monto'];
					$extra['monto']=$row['monto'];
					$extra['detalle']=substr($row['desconcepto'],0,37);
				}
				*/
				$tdeduc+=($row['tipo']=='D'?$row['monto']:0);
				$tnombre="";
				$consul1=mysqli_query($enlace,"select nombres,apellidos,sso from personal where id='".$_SESSION['id_validar']."' and codigo=".$tcedula );
				if (mysqli_num_rows($consul1)<>0) {
					$row1=mysqli_fetch_array($consul1);
					$tnombre=trim($row['sso'])." ".trim($row1['nombres']).',  '.trim($row1['apellidos']);
				}
				$tcedula=$row['cedula'];
			}
			else {
				$linea++;
				$pdf->cell(10,5,$linea,0,0,'C',$color);
				$pdf->cell(15,5,$tcedula,0,0,'',$color);
				$pdf->cell(55,5,$tnombre,0,0,'',$color);
				$pdf->cell(25,5,number_format($tasig,2),0,0,'R',$color);
				$pdf->cell(25,5,number_format($tdeduc,2),0,0,'R',$color);
				$pdf->cell(25,5,number_format($tasig-$tdeduc,2),0,1,'R',$color);


				/*agregado por victor*/
				/*
				if(count($extra)>0 && $prestac)
				{
			        $prestac=false;
					$pdf->cell(10,5,'',0,0,'C',$color);
					$pdf->cell(15,5,'',0,0,'',$color);
					$pdf->cell(55,5,$extra['detalle'],0,0,'',$color);
					$pdf->cell(25,5,number_format($extra['monto'],2),0,0,'R',$color);
					$pdf->cell(25,5,'',0,0,'R',$color);
					$pdf->cell(25,5,number_format($extra['monto'],2),0,1,'R',$color);
				}
				*/



				//$pdf->cell(31,5,"__________________",0,1,'R',0);
				$pdf->ln(5);
				$color=!$color;
				$tasig=0;
				if($row['concepto']!=="5008"&&$row['concepto']!=="5009"){
					$tasig=($row['tipo']=='A'?$row['monto']:0);
				}
				/*
				else{
					$prestac=true;
					$textra+=$row['monto'];
					$extra['monto']=$row['monto'];
					$extra['detalle']=substr($row['desconcepto'],0,37);
				}
				*/
				$tdeduc=($row['tipo']=='D'?$row['monto']:0);
				$tcedula=$row['cedula'];
				$tnombre="";
				$consul1=mysqli_query($enlace,"select nombres,apellidos,sso from personal where id='".$_SESSION['id_validar']."' and codigo=".$tcedula );
				if (mysqli_num_rows($consul1)<>0) {
					$row1=mysqli_fetch_array($consul1);
					$tnombre=trim($row['sso'])." ".trim($row1['nombres']).',  '.trim($row1['apellidos']);
				}
			}
		}
		$linea++;
		$pdf->cell(10,5,$linea,0,0,'C',$color);
		$pdf->cell(15,5,$tcedula,0,0,'',$color);
		$pdf->cell(55,5,$tnombre,0,0,'',$color);
		$pdf->cell(25,5,number_format($tasig,2),0,0,'R',$color);
		$pdf->cell(25,5,number_format($tdeduc,2),0,0,'R',$color);
		$pdf->cell(25,5,number_format($tasig-$tdeduc,2),0,1,'R',$color);


		/*agregado por victor*/
		/*if(count($extra)>0&& $prestac)
		{
			$prestac=false;
			$pdf->cell(10,5,'',0,0,'C',$color);
			$pdf->cell(15,5,'',0,0,'',$color);
			$pdf->cell(55,5,$extra['detalle'],0,0,'',$color);
			$pdf->cell(25,5,number_format($extra['monto'],2),0,0,'R',$color);
			$pdf->cell(25,5,'',0,0,'R',$color);
			$pdf->cell(25,5,number_format($extra['monto'],2),0,1,'R',$color);
		}
		*/



		//$pdf->cell(31,5,"__________________",0,1,'R',0);
		$pdf->ln(5);
		$pdf->Cell(190,0,'',1,1,'C'); $pdf->ln(1);
		$pdf->cell(80,5,'Total Nomina',0,0,'R');
		$pdf->cell(25,5,number_format($ttasig-$textra,2) ,0,0,'R');
		$pdf->cell(25,5,number_format($ttdeduc,2) ,0,0,'R');
		$pdf->cell(25,5,number_format($ttasig-$textra-$ttdeduc,2) ,0,1,'R');
		$pdf->cell(80,5,'Total '.$extra['detalle'],0,0,'R');
		$pdf->cell(25,5,number_format($textra,2) ,0,0,'R');
		$pdf->cell(25,5,'' ,0,0,'R');
		$pdf->cell(25,5,number_format($textra,2) ,0,1,'R');

		$pdf->Cell(190,0,'',1,1,'C'); $pdf->ln(1);
		$pdf->Cell(190,0,'',1,1,'C');
		$pdf->Output('Resumen_Individual_Pago_por_Trabajador.pdf','D');
	} //================= salida PDF

	if ($_POST['salida']=='2') {
		echo "<center>";
		echo "<font face='verdana' color='black' size='5'>";
		echo "<br>".$_POST['empresal'];

		echo "<font face='verdana' color='black' size='3'>";
		echo "<br>".$_POST['encabeza'];
		if ($_POST['cierre']==0) echo '<br>Reporte de PRE-CIERRE';
		else echo '<br>CIERRE AUDITADO';

		echo "<font face='verdana' color='black' size='3'>";
		echo "<br>".$_POST['periodo'];

		echo "<font face='verdana' color='black' size='4'>";
		echo "<br><br>".($_POST['titulo']==''?'Resumen Individual de Pago de Nomina':$_POST['titulo']);
		echo "</center></font>";

		echo "<table  cellpadding=2 cellspacing=0 align='center'>";
		echo "<tr BGcolor='#464D77' style='color:#fff;' >";
			echo "<th ali=center><font face='verdana' size=2>C&oacute;d</font></th> ";
			echo "<th ali=center><font face='verdana' size=2>C&eacute;dula</font></th> ";
			echo "<th ali=center><font face='verdana' size=2>Nombres y Apellidos</font></th>";
			echo "<th ali=center><font face='verdana' size=2>Asignaci&oacute;n</font></th>";
			echo "<th ali=center><font face='verdana' size=2>Deducci&oacute;n</font></th>";
			echo "<th ali=center><font face='verdana' size=2>Total Neto</font></th> ";
			echo "<th ali=center><font face='verdana' size=2>Firma</font></th>";
		echo "</tr>";

		if (obtener_valor_diccionario($_POST,'eshistorico')!=1) $consulta=mysqli_query($enlace,"select * from $payroll WHERE substr($payroll.concepto,1,1)!=5 AND substr($payroll.concepto,1,1)!=6 AND substr($payroll.concepto,1,1)!=4 AND concepto NOT IN(2000,2001,2002,2003,2004,2005,2006,2007,2010,2012) order by cedula"  );
		else {
			if ($gerencia==1) $queryx="select $payroll.* from $payroll,personal where personal.id='".$_SESSION['id_validar']."' and $payroll.cedula=personal.codigo ".$queryy." AND substr($payroll.concepto,1,1)!=5 AND substr($payroll.concepto,1,1)!=6 AND substr($payroll.concepto,1,1)!=4 AND concepto NOT IN(2000,2001,2002,2003,2004,2005,2006,2007,2010,2012) order by $payroll.cedula,$payroll.concepto, $payroll.desconcepto";
			else $queryx="select $payroll.* from $payroll,personal where personal.id='".$_SESSION['id_validar']."' and $payroll.tipo<>'R' and $payroll.cedula=personal.codigo ".$queryy."  AND substr($payroll.concepto,1,1)!=5 AND substr($payroll.concepto,1,1)!=6 AND substr($payroll.concepto,1,1)!=4 AND concepto NOT IN(2000,2001,2002,2003,2004,2005,2006,2007,2010,2012) order by $payroll.cedula, $payroll.concepto, $payroll.desconcepto";
			$consulta=mysqli_query($enlace,$queryx) or die ($queryx.mysqli_error($enlace));
		}

		$linea=0;
		$color=0;
		$tasig=0;
		$tdeduc=0;
		$bandera=0;
		$ttasig=0; $ttdeduc=0;
		$extra=array();
		$prestac=false;
		$textra=0;
		$tcedula='';
		$tnombre='';
		while($row=mysqli_fetch_array($consulta)) {
			$ttasig+=(($row['tipo']=='A'&& $row['concepto']!='5008'&& $row['concepto']!='5009')?$row['monto']:0);
			$ttdeduc+=($row['tipo']=='D'?$row['monto']:0);
			if ($bandera==0) {
				$bandera=1;
				$tcedula=$row['cedula'];
			}
			if ($tcedula==$row['cedula']) {
				if($row['concepto']!=="5008"&&$row['concepto']!=="5009"){
					$tasig+=($row['tipo']=='A'?$row['monto']:0);
				}
				/*
				else{
					$prestac=true;
					$textra+=$row['monto'];
					$extra['monto']=$row['monto'];
					$extra['detalle']=substr($row['desconcepto'],0,37);
				}
				*/
				$tdeduc+=($row['tipo']=='D'?$row['monto']:0);
				$tnombre="";
				$consul1=mysqli_query($enlace,"select nombres,apellidos,sso from personal where id='".$_SESSION['id_validar']."' and codigo=".$tcedula );
				if (mysqli_num_rows($consul1)<>0) {
					$row1=mysqli_fetch_array($consul1);
					$tnombre=trim($row['sso'])." ".trim($row1['nombres']).',  '.trim($row1['apellidos']);
				}
				$tcedula=$row['cedula'];
			}
			else {
				$linea++;
				if ($color) echo '<tr bgcolor="white" >';
				else echo '<tr bgcolor="#EEEFF3">';
				$color=!$color;

				echo "<td width='10'><font face='verdana' color='black' size='3'>".$linea."</font></td>";
				echo "<td width='100'><font face='verdana' color='black' size='3'>".$tcedula."</font></td>";
				echo "<td width='220'><font face='verdana' color='black' size='3'>".$tnombre."</font></td>";
				echo "<td width='150' align='right'><font face='verdana' color='#36C1E2' size='3'><b>".number_format($tasig,2)."</font></b></td>";
				echo "<td width='150' align='right'><font face='verdana' color='#DD0044' size='3'>".number_format($tdeduc,2)."</font></td>";
				echo "<td width='150' align='right'><font face='verdana' color='black' size='3'>".number_format($tasig-$tdeduc,2)."</font></td>";


                /*agregado por victor*/
				/*
				if(count($extra)>0&&$prestac)
				{
					$prestac=false;
					echo "<td width='120' align='right'></td>";
				    echo "</tr>";
					if (!$color) echo '<tr bgcolor="white" >';
				    else echo '<tr bgcolor="#EEEFF3">';
					echo "<td width='10'><font face='verdana' color='black' size='3'></font></td>";
					echo "<td width='100'><font face='verdana' color='black' size='3'></font></td>";
					echo "<td width='220'><font face='verdana' color='black' size='3'>".$extra['detalle']."</font></td>";
					echo "<td width='150' align='right'><font face='verdana' color='#36C1E2' size='3'><b>".number_format($extra['monto'],2)."</font></b></td>";
					echo "<td width='150' align='right'><font face='verdana' color='#DD0044' size='3'></font></td>";
					echo "<td width='150' align='right'><font face='verdana' color='black' size='3'>".number_format($extra['monto'],2)."</font></td>";
				}
				*/

				echo "<td width='120' align='right'><font face='verdana' color='black' size='3'>_________________</font></td>";
				echo "</tr>";

				if($row['concepto']!=="5008"&&$row['concepto']!=="5009"){
					$tasig=($row['tipo']=='A'?$row['monto']:0);
				}
				/*
				else{
					$prestac=true;
					$textra+=$row['monto'];
					$extra['monto']=$row['monto'];
					$extra['detalle']=substr($row['desconcepto'],0,37);
				}
				*/

				$tdeduc=($row['tipo']=='D'?$row['monto']:0);
				$tcedula=$row['cedula'];
				$tnombre="";
				$consul1=mysqli_query($enlace,"select nombres,apellidos,sso from personal where id='".$_SESSION['id_validar']."' and codigo=".$tcedula );
				if (mysqli_num_rows($consul1)<>0) {
					$row1=mysqli_fetch_array($consul1);
					$tnombre=trim($row['sso'])." ".trim($row1['nombres']).',  '.trim($row1['apellidos']);
				}
			}
		}
		$linea++;
		if ($color) echo '<tr bgcolor="white" >';
		else echo '<tr bgcolor="#EEEFF3">';
		echo "<td width='10'><font face='verdana' color='black' size='3'>".$linea."</font></td>";
		echo "<td width='10'><font face='verdana' color='black' size='3'>".$tcedula."</font></td>";
		echo "<td width='220'><font face='verdana' color='black' size='3'>".$tnombre."</font></td>";
		echo "<td width='120' align='right'><font face='verdana' color='#36C1E2' size='3'><b>".number_format($tasig,2)."</font></b></td>";
		echo "<td width='120' align='right'><font face='verdana' color='#DD0044' size='3'>".number_format($tdeduc,2)."</font></td>";
		echo "<td width='120' align='right'><font face='verdana' color='black' size='3'>".number_format($tasig-$tdeduc,2)."</font></td>";

		/*agregado por victor*/
		/*
		if(count($extra)>0 && $prestac)
		{
			$prestac=false;
			echo "<td width='120' align='right'></td>";
			echo "</tr>";
			if (!$color) echo '<tr bgcolor="white" >';
			else echo '<tr bgcolor="#EEEFF3">';
			echo "<td width='10'><font face='verdana' color='black' size='3'></font></td>";
			echo "<td width='100'><font face='verdana' color='black' size='3'></font></td>";
			echo "<td width='220'><font face='verdana' color='black' size='3'>".$extra['detalle']."</font></td>";
			echo "<td width='150' align='right'><font face='verdana' color='#36C1E2' size='3'><b>".number_format($extra['monto'],2)."</font></b></td>";
			echo "<td width='150' align='right'><font face='verdana' color='#DD0044' size='3'></font></td>";
			echo "<td width='150' align='right'><font face='verdana' color='black' size='3'>".number_format($extra['monto'],2)."</font></td>";
		}
		*/

		echo "<td width='120' align='right'><font face='verdana' color='black' size='3'>_________________</font></td>";
		echo "</tr>";

		echo "<tr BGcolor='#464D77' style='color:#fff;' >";
		echo "<th ali=center colspan=3><font face='verdana' size=3>TOTAL GENERAL DE NOMINA Bs.</font></th> ";
		echo "<td width='120' align='right'><font face='verdana' size='3'><b>".number_format($ttasig-$textra,2)."</font></b></td>";
		echo "<td width='120' align='right'><font face='verdana'  size='3'>".number_format($ttdeduc,2)."</font></td>";
		echo "<td width='120' align='right'><font face='verdana'  size='3'>".number_format($ttasig-$textra-$ttdeduc,2)."</font></td>";
		echo "<th ali=center><font face='verdana' size=2>&nbsp;</font></th>";
		echo "</tr>";

		/*
		echo "<tr BGcolor='#464D77' style='color:#fff;' >";
		echo "<th ali=center colspan=3><font face='verdana' size=3>Total CESTATICKET SOCIALISTA Bs.</font></th> ";
		echo "<td width='120' align='right'><font face='verdana' size='3'><b>".number_format($textra,2)."</font></b></td>";
		echo "<td width='120' align='right'><font face='verdana'  size='3'></font></td>";
		echo "<td width='120' align='right'><font face='verdana'  size='3'>".number_format($textra,2)."</font></td>";
		echo "<th ali=center><font face='verdana' size=2>&nbsp;</font></th>";
		echo "</tr>";
		*/
	} //================= salida TEXTO

} // fin de REPORTE INDIVIDUAL REPORTE=2

//--------------------------------------------------------------------------------------------------------------------------------- REPORTE
//--------------------------------------------------------------------------------------------------------------------------------- PRENOMINA PAYROLL
if ($_POST['treporte']==3) {
	if ($_POST['salida']==1) {
		require('fpdf.php');
		class PDF extends FPDF {
		function Header()
		{
	    $this->Image($_SESSION['logo_validar'],10,10,30,30);
		$this->SetFont('arial','',7);
	    $this->Cell(0,5,'Fecha: '.hoy().' / Hora: '.hora(),0,1,'R');
		//$this->Cell(0,5,'Hora: '.hora(),0,1,'R');
	    $this->SetFont('arial','B',8);
		//$this->Ln(1);
		if ($_POST['cierre']==0) $this->Cell(0,5,'Reporte de PRE-CIERRE',0,1,'R'); else $this->Cell(0,5,'CIERRE AUDITADO',0,1,'R');
		$this->SetFont('arial','B',10);
	    $this->Cell(0,5,$_POST['empresal'],0,1,'R');
		$this->SetFont('arial','',6);
		$this->Cell(0,5,$_POST['encabeza'],0,1,'R');
		$this->Ln(2);


	    $this->Ln(5);
		$this->SetFont('arial','B',12);
		$this->Cell(0,0,($_POST['titulo']==''?'Pago de Nomina General':$_POST['titulo']),0,1,'C');$this->Ln(5);
		$this->Cell(0,0,$_POST['subtitulo'],0,1,'C');$this->Ln(5);
		$this->SetFont('arial','',7);
		$this->Cell(0,5,'Nomina: '.$_POST['empresa'],0,1,'R');$this->Ln(1);
		$this->Cell(0,0,'Periodo: '.$_POST['periodo'],0,1,'R');$this->Ln(3);
		if ($_POST['gerencia']!="") {
			$this->Cell(0,0,'Gerencia: '.$_POST['gerencia'],0,1,'L');$this->Ln(5);
		}
		if ($_POST['division']!="") {
			$this->Cell(0,0,'División: '.$_POST['division'],0,1,'L');$this->Ln(5);
		}
		if ($_POST['departamento']!="") {
			$this->Cell(0,0,'Departamento: '.$_POST['departamento'],0,1,'L');$this->Ln(5);
		}
	    $this->SetFillColor(224,235,255);
	    $this->SetTextColor(0);
	    $this->SetFont('');
		}
		function Footer()
		{
		$this->SetY(-20);
		$this->Cell(0,0,'',1,1,'C');
		$this->SetFont('Times','I',8);
		$this->ln(2);
		$this->Cell(0,0,$_POST['pie'],0,1,'C');
		$this->Cell(0,10,'Usuario: '.$_POST['usuario'].' - Página '.$this->PageNo().'/{nb} - Derechos: '.$_POST['derecho'],0,0,'C');
		}
		}
		//Cuerpo //////////////////////////////////////////////
		$pdf=new PDF();
		$pdf->AddPage();
		$pdf->AliasNbPages();
		$pdf->SetFont('Arial','',8);
		//$pdf->SetFillColor(224,235,255);
		//$pdf->SetTextColor(0);
		if (obtener_valor_diccionario($_POST,'eshistorico')!=1) {
			$consu="select * from personal,$payroll where personal.id='".$_SESSION['id_validar']."' and $payroll.cedula=personal.codigo AND substr($payroll.concepto,1,1)!=6 AND substr($payroll.concepto,1,1)!=4 AND concepto NOT IN(2000,2001,2002,2003,2004,2005,2006,2007,2010,2012) order by personal.codigo, $payroll.concepto, $payroll.desconcepto  ";
		}else {
			if ($gerencia==1) {
				$consu="select * from personal,$payroll where personal.id='".$_SESSION['id_validar']."' and $payroll.cedula=personal.codigo ".$queryy." AND substr($payroll.concepto,1,1)!=6 AND substr($payroll.concepto,1,1)!=4 AND concepto NOT IN(2000,2001,2002,2003,2004,2005,2006,2007,2010,2012) order by $payroll.cedula,$payroll.concepto, $payroll.desconcepto";
				
				}else {
					$consu="select * from personal,$payroll where personal.id='".$_SESSION['id_validar']."' and $payroll.tipo<>'R' and $payroll.cedula=personal.codigo ".$queryy." AND substr($payroll.concepto,1,1)!=6 AND substr($payroll.concepto,1,1)!=4 AND concepto NOT IN(2000,2001,2002,2003,2004,2005,2006,2007,2010,2012) order by $payroll.cedula, $payroll.concepto, $payroll.desconcepto";
				}
		}

		$consulta=mysqli_query($enlace,$consu) or die($consu.mysqli_error($enlace));

		$linea=0;
		$color=0;
		$tasig=0;
		$tdeduc=0;
		$bandera=0;
		$ttasig=0; $ttdeduc=0;
		$textra=0;
		$prestac=false;
		while($row=mysqli_fetch_array($consulta)) {
			$ttasig+=($row['tipo']=='A'?$row['monto']:0);
			$ttdeduc+=($row['tipo']=='D'?$row['monto']:0);
			if ($bandera==0) {
				/*Agregado por victor*/
				$extra=array();
				$bandera=1;
				$prestac=false;
				$tcedula=$row['cedula'];
				$tcargo=$row['cargo'];
				$concar=mysqli_query($enlace,"select * from tablas where tabla='CARGO' and codigo='".$tcargo."' and id='".$_SESSION['id_validar']."' "  );
				while($row1=mysqli_fetch_array($concar))
					$tcargo=$row1['detalle'];
				$tnombre=trim($row['nombres']).',  '.trim($row['apellidos']).' - '.$tcargo.'- Fec. Ingreso: '.$row['fechai'];
				$pdf->cell(1);$pdf->cell(1,5,"[".$tcedula."]",0,0,'');
				$pdf->cell(15);$pdf->cell(1,5,$tnombre,0,1,'');
				$header=array('Cod.','Descripción','Cantidad','Asignación','Deducción','Saldo');

				$pdf->SetFillColor(70,77,119);
				$pdf->SetTextColor(255);
				$pdf->SetDrawColor(255,255,255);
				$pdf->SetLineWidth(.5);
				$pdf->SetFont('','');
				//Cabecera
				$pdf->SetFont('arial','B',8);
				$w=array(10,70,20,30,30,30);
				for($i=0;$i<count($header);$i++)
					$pdf->Cell($w[$i],4,$header[$i],1,0,'C',1);
				$pdf->Ln();
				//Restauraci�n de colores y fuentes
				$pdf->SetFillColor(224,235,255);
				$pdf->SetTextColor(0);
				$pdf->SetFont('');
				$color=0;
			}
			if ($tcedula==$row['cedula']) {
				 if($row['concepto']==="5008"||$row['concepto']==="5009"||$row['concepto']==="5010"||$row['concepto']==="5011"|| $row['concepto']==="5508"||$row['concepto']==="5509"||$row['concepto']==="5510"||$row['concepto']==="5511" ){
					$prestac=true;
					$textra+=$row['monto'];
					$extra['tipo']=$row['tipo'];
					$extra['monto']=$row['monto'];
					$extra['concepto']=$row['concepto'];
					$extra['detalle']=substr($row['desconcepto'],0,37);
					$extra['sueldo']=$row['smes'];
					$extra['fechai']=mostrar_fecha($row['fechai']);
					$extra['saldo']=$row['saldo'];
					$extra['cantidad']=$row['cantidad'];
					$extra['cedula']=$row['cedula'];
				}
				else{
					$tasig+=($row['tipo']=='A'?$row['monto']:0);
					$tdeduc+=($row['tipo']=='D'?$row['monto']:0);
					$tasigx=($row['tipo']=='A'?$row['monto']:0);
					$tdeducx=($row['tipo']=='D'?$row['monto']:0);
					$tnombre=trim($row['nombres']).',  '.trim($row['apellidos']);
					$tconcepto=$row['concepto'];
					$tdetalle=$row['desconcepto'];
					$tsaldo=$row['saldo'];
					$tcantidad=$row['cantidad'];
					$tcedula=$row['cedula'];
					$pdf->cell(10,5,$tconcepto,0,0,'',$color);
					$pdf->cell(60,5,$tdetalle,0,0,'',$color);
					$pdf->cell(30,5,number_format($tcantidad,2),0,0,'R',$color);
					$pdf->cell(30,5,number_format($tasigx,2),0,0,'R',$color);
					$pdf->cell(30,5,number_format($tdeducx,2),0,0,'R',$color);
					$pdf->cell(30,5,($tconcepto=="2200"?number_format($tsaldo,2):""),0,1,'R',$color);
				}
			}
			else {
				$pdf->SetDrawColor(70,77,119);
$pdf->SetLineWidth(.2);
$pdf->Cell(190,0,'',1,0,'C');
 $pdf->ln(1);
				$pdf->cell(100,5,'Sub-Total',0,0,'R');
				$pdf->cell(30,5,number_format($tasig,2) ,0,0,'R');
				$pdf->cell(30,5,number_format($tdeduc,2) ,0,0,'R');
				$pdf->cell(30,5,number_format($tasig-$tdeduc,2) ,0,1,'R');

				/*agreado por victor*/
				if(count($extra)>0&&$prestac)
				{
					$prestac=false;
					$pdf->Cell(190,0,'',1,1,'C');

					$pdf->cell(10,5,$extra['concepto'],0,0,'',1);
					$pdf->cell(60,5,$extra['detalle'],0,0,'',1);
					$pdf->cell(30,5,number_format($extra['cantidad'],2),0,0,'R',1);
					$pdf->cell(30,5,number_format($extra['monto'],2),0,0,'R',1);
					$pdf->cell(30,5,"",0,0,'R',1);
					$pdf->cell(30,5,number_format($extra['monto'],2),0,1,'R',1);
				}
				$pdf->Cell(190,0,'',1,1,'C');

				if($row['concepto']==="5008"||$row['concepto']==="5009" ||$row['concepto']==="5010"||$row['concepto']==="5011"|| $row['concepto']==="5508"||$row['concepto']==="5509"||$row['concepto']==="5510"||$row['concepto']==="5511" ){
					$prestac=true;
					$textra+=$row['monto'];
					$extra['tipo']=$row['tipo'];
					$extra['monto']=$row['monto'];
					$extra['concepto']=$row['concepto'];
					$extra['detalle']=substr($row['desconcepto'],0,37);
					$extra['sueldo']=$row['smes'];
					$extra['fechai']=mostrar_fecha($row['fechai']);
					$extra['saldo']=$row['saldo'];
					$extra['cantidad']=$row['cantidad'];
					$extra['cedula']=$row['cedula'];
				}
				else
				{
					$tasig=($row['tipo']=='A'?$row['monto']:0);
					$tdeduc=($row['tipo']=='D'?$row['monto']:0);
					$tasigx=($row['tipo']=='A'?$row['monto']:0);
					$tdeducx=($row['tipo']=='D'?$row['monto']:0);
					$tconcepto=$row['concepto'];
					$tdetalle=$row['desconcepto'];
					$tcantidad=$row['cantidad'];
					$tcedula=$row['cedula'];
					$tcargo=$row['cargo'];
					$concar=mysqli_query($enlace,"select * from tablas where tabla='CARGO' and codigo='".$tcargo."' and id='".$_SESSION['id_validar']."' "  );
					while($row1=mysqli_fetch_array($concar))
						$tcargo=$row1['detalle'];
					$tnombre=trim($row['nombres']).',  '.trim($row['apellidos']).' - '.$tcargo.'- Fec. Ingreso: '.$row['fechai'];
					$pdf->Ln(5);
					$pdf->cell(1);$pdf->cell(1,5,"[".$tcedula."]",0,0,'');
					$pdf->cell(15);$pdf->cell(1,5,$tnombre,0,1,'');

					$pdf->SetFillColor(70,77,119);
					$pdf->SetTextColor(255);
					$pdf->SetDrawColor(255,255,255);
					$pdf->SetLineWidth(.5);
					$pdf->SetFont('','');


					//Cabecera
					$pdf->SetFont('arial','B',8);
					for($i=0;$i<count($header);$i++)
						$pdf->Cell($w[$i],4,$header[$i],1,0,'C',1);
					$pdf->Ln(5);
					//Restauraci�n de colores y fuentes
					$pdf->SetFillColor(224,235,255);
					$pdf->SetTextColor(0);
					$pdf->SetFont('');
					$color=0;
					$pdf->cell(10,5,$tconcepto,0,0,'',$color);
					$pdf->cell(60,5,$tdetalle,0,0,'',$color);
					$pdf->cell(30,5,number_format($tcantidad,2),0,0,'R',$color);
					$pdf->cell(30,5,number_format($tasigx,2),0,0,'R',$color);
					$pdf->cell(30,5,number_format($tdeducx,2),0,0,'R',$color);
					$pdf->cell(30,5,($tconcepto=="2200"?number_format($tsaldo,2):""),0,1,'R',$color);

				}

			}
			$color=!$color;
		}
		$pdf->SetDrawColor(70,77,119);
		$pdf->SetLineWidth(.2);
		$pdf->Cell(190,0,'',1,0,'C');
		$pdf->ln(1);

		$pdf->cell(100,5,'Sub-Total',0,0,'R');

		$pdf->cell(30,5,number_format($tasig,2),0,0,'R');
		$pdf->cell(30,5,number_format($tdeduc,2),0,0,'R');
		$pdf->cell(30,5,number_format($tasig-$tdeduc,2),0,1,'R');



		/*agreado por victor*/
		if(count($extra)>0&&$prestac)
		{   $prestac=false;
			$pdf->Cell(190,0,'',1,1,'C');
			$pdf->cell(10,5,$extra['concepto'],0,0,'',1);
			$pdf->cell(60,5,$extra['detalle'],0,0,'',1);
			$pdf->cell(30,5,number_format($extra['cantidad'],2),0,0,'R',1);
			$pdf->cell(30,5,number_format($extra['monto'],2),0,0,'R',1);
			$pdf->cell(30,5,"",0,0,'R',1);
			$pdf->cell(30,5,number_format($extra['monto'],2),0,1,'R',1);
		}

		$pdf->ln(10);
		$pdf->Cell(190,0,'',1,1,'C');
		$pdf->cell(100,5,'TOTAL GENERAL DE NOMINA',0,0,'R');
		$pdf->cell(30,5,number_format($ttasig-$textra,2) ,0,0,'R');
		$pdf->cell(30,5,number_format($ttdeduc,2) ,0,0,'R');
		$pdf->cell(30,5,number_format($ttasig-$textra-$ttdeduc,2) ,0,1,'R');

		$pdf->cell(100,5,'TOTAL PRESTACIONES SOCIALES',0,0,'R');//.$extra['detalle']
		$pdf->cell(30,5,number_format($textra,2) ,0,0,'R');
		$pdf->cell(30,5,'' ,0,0,'R');
		$pdf->cell(30,5,number_format($textra,2) ,0,1,'R');

		$pdf->Cell(190,0,'',1,1,'C'); $pdf->ln(1);
		$pdf->Cell(190,0,'',1,1,'C');
		$pdf->Output('Reporte_General_PRENOMINA.pdf','D');
	} //========================= PDF

	if ($_POST['salida']==2) {
		echo "<center>";
		echo "<font face='verdana' color='black' size='5'>";
		echo "<br>".$_POST['empresal'];

		echo "<font face='verdana' color='black' size='3'>";
		echo "<br>".$_POST['encabeza'];
		if ($_POST['cierre']==0) echo '<br>Reporte de PRE-CIERRE';
		else echo '<br>CIERRE AUDITADO';

		echo "<font face='verdana' color='black' size='3'>";
		echo "<br>".$_POST['periodo'];

		echo "<font face='verdana' color='black' size='4'>";
		echo "<br><br>".($_POST['titulo']==''?'Pago de Nomina General':$_POST['titulo']);
		echo "</center></font>";

		echo "<table  cellpadding=2 cellspacing=0 align='center'>";
		echo "<tr BGcolor='#464D77' style='color:#fff;' >";
			echo "<th ali=center><font face='verdana' size=2>C&oacute;digo</font></th> ";
			echo "<th ali=center><font face='verdana' size=2>Detalle</font></th>";
			echo "<th ali=center><font face='verdana' size=2>Cantidad</font></th>";
			echo "<th ali=center><font face='verdana' size=2>Asignaci&oacute;n</font></th>";
			echo "<th ali=center><font face='verdana' size=2>Deducci&oacute;n</font></th>";
			echo "<th ali=center><font face='verdana' size=2>Saldo</font></th>";
		echo "</tr>";

		if (obtener_valor_diccionario($_POST,'eshistorico')!=1) {

			$consu="select * from personal,$payroll where personal.id='".$_SESSION['id_validar']."' and $payroll.cedula=personal.codigo AND substr($payroll.concepto,1,1)!=6 AND substr($payroll.concepto,1,1)!=4  AND concepto NOT IN(2000,2001,2002,2003,2004,2005,2006,2007,2010,2012) order by personal.codigo, $payroll.concepto, $payroll.desconcepto  ";

		}else {
			if ($gerencia==1) {

				$consu="select * from personal,$payroll where personal.id='".$_SESSION['id_validar']."' and $payroll.cedula=personal.codigo ".$queryy." AND substr($payroll.concepto,1,1)!=6  AND substr($payroll.concepto,1,1)!=4  AND concepto NOT IN(2000,2001,2002,2003,2004,2005,2006,2007,2010,2012) order by $payroll.cedula,$payroll.concepto, $payroll.desconcepto";

			}else {

				$consu="select * from personal,$payroll where personal.id='".$_SESSION['id_validar']."' and $payroll.tipo<>'R' and $payroll.cedula=personal.codigo ".$queryy." AND substr($payroll.concepto,1,1)!=6   AND substr($payroll.concepto,1,1)!=4  AND concepto NOT IN(2000,2001,2002,2003,2004,2005,2006,2007,2010,2012) order by $payroll.cedula, $payroll.concepto, $payroll.desconcepto";
			}
		}
		$consulta=mysqli_query($enlace,$consu) or die($consu.mysqli_error($enlace));

		$linea=0;
		$color=0;
		$tasig=0;
		$tdeduc=0;
		$bandera=0;
		$ttasig=0; $ttdeduc=0;
		$textra=0;
		$prestac=false;
		while($row=mysqli_fetch_array($consulta)) {
			$ttasig+=($row['tipo']=='A'?$row['monto']:0);
			$ttdeduc+=($row['tipo']=='D'?$row['monto']:0);
			if ($bandera==0) {
				$bandera=1;
				/*Agregado por victor*/
				$extra=array();
				$prestac=false;
				$tcedula=$row['cedula'];
				$tcargo=$row['cargo'];
				$tJornada=$row['turno'];
				$concar=mysqli_query($enlace,"select * from tablas where tabla='CARGO' and codigo='".$tcargo."' and id='".$_SESSION['id_validar']."' "  );
				while($row1=mysqli_fetch_array($concar))
					$tcargo=$row1['detalle'];
				$tnombre="Nombre: ".trim($row['nombres']).',  '.trim($row['apellidos']).' - Cargo: '.$tcargo.' - Fec. Ingreso: '.$row['fechai'];

				if($nominaX == 100){
				$tnombre2="Sueldo Diario: ".number_format($row['sdia'],2,',','.')." +Bono Lider Manuf: ".number_format($row['bono1'],2,',','.')." +Bono Lider Grupo: ".number_format($row['bono2'],2,',','.');
				}
				else{
				$tnombre2="Sueldo Mensual: ".number_format($row['smes'],2,',','.');
				}
				//$tnombre2="Sueldo Diario: ".number_format($row['sdia']+$row['bono1']+$row['bono2'],2,',','.').',  Jornada: '.$tJornada;

				echo "<tr><td colspan=1>".$tcedula."</td>";
				echo "<td colspan=5>".$tnombre."</td></tr>";
				echo "<td colspan=5>".$tnombre2."</td></tr>";
				$color=0;
			}
			if ($tcedula==$row['cedula']) {
				if(substr($row['concepto'],0,1)==='5'){
					$prestac=true;
					$textra+=$row['monto'];
					$extra['tipo']=$row['tipo'];
					$extra['monto']=$row['monto'];
					$extra['concepto']=$row['concepto'];
					$extra['detalle']=substr($row['desconcepto'],0,37);
					$extra['sueldo']=$row['smes'];
					$extra['fechai']=mostrar_fecha($row['fechai']);
					$extra['saldo']=$row['saldo'];
					$extra['cantidad']=$row['cantidad'];
					$extra['cedula']=$row['cedula'];
				}
				else
				{
					$tasig+=($row['tipo']=='A'?$row['monto']:0);
					$tdeduc+=($row['tipo']=='D'?$row['monto']:0);
					$tasigx=($row['tipo']=='A'?$row['monto']:0);
					$tdeducx=($row['tipo']=='D'?$row['monto']:0);
					$tnombre=trim($row['nombres']).',  '.trim($row['apellidos']);
					$tconcepto=$row['concepto'];
					$tdetalle=$row['desconcepto'];
					$tsaldo=$row['saldo'];
					$tcantidad=$row['cantidad'];
					$tcedula=$row['cedula'];

					if ($color) echo '<tr bgcolor="#E6E6E6" >';
					else echo '<tr bgcolor="#EEEFF3">';
					$color=!$color;

					echo "<td width='2'><font face='verdana' color='black' size='3'>".$tconcepto."</font></td>";
					echo "<td width='300'><font face='verdana' color='black' size='3'>".$tdetalle."</font></td>";
					echo "<td width='120' align='right'><font face='verdana' color='black' size='2'><b>".number_format($tcantidad,2)."</font></b></td>";
					echo "<td width='120' align='right'><font face='verdana' color='#36C1E2' size='3'>".number_format($tasigx,2)."</font></td>";
					echo "<td width='120' align='right'><font face='verdana' color='#DD0044' size='3'>".number_format($tdeducx,2)."</font></td>";
					echo "<td width='120' align='right'><font face='verdana' color='black' size='3'>".($tconcepto=="2200"?number_format($tsaldo,2):"")."</font></td>";
					echo "</tr>";
			    }
			}
			else {

				echo "<tr BGcolor='#464D77' style='color:#fff;' >";
				echo "<th ali=center colspan=3><font face='verdana' size=3>Sub-Totales Bs.</font></th> ";
				echo "<td width='120' align='right'><font face='verdana'  size='3'><b>".number_format($tasig,2)."</font></b></td>";
				echo "<td width='120' align='right'><font face='verdana'  size='3'>".number_format($tdeduc,2)."</font></td>";
				echo "<td width='120' align='right'><font face='verdana'  size='3'>".number_format($tasig-$tdeduc,2)."</font></td>";
				echo "</tr>";

                /*agreado por victor*/
				if(count($extra)>0&&$prestac)
				{   $prestac=false;
					echo "<tr BGcolor='#464D77' style='color:#fff;'>";
					echo "<td width='2'><font face='verdana'  size='3'>".$extra['concepto']."</font></td>";
					echo "<td width='300'><font face='verdana' size='3'>".$extra['detalle']."</font></td>";
					echo "<td width='120' align='right'><font face='verdana'  size='2'><b>".number_format($extra['cantidad'],2)."</font></b></td>";
					echo "<td width='120' align='right'><font face='verdana'  size='3'>".number_format($extra['monto'],2)."</font></td>";
					echo "<td width='120' align='right'><font face='verdana'  size='3'></font></td>";
					echo "<td width='120' align='right'><font face='verdana'  size='3'>".number_format($extra['monto'],2)."</font></td>";
					echo "</tr>";

				}


				if($row['concepto']==="5008"||$row['concepto']==="5009" ||$row['concepto']==="5010"||$row['concepto']==="5011"|| $row['concepto']==="5508"||$row['concepto']==="5509"||$row['concepto']==="5510"||$row['concepto']==="5511"){
					$prestac=true;
					$textra+=$row['monto'];
					$extra['tipo']=$row['tipo'];
					$extra['monto']=$row['monto'];
					$extra['concepto']=$row['concepto'];
					$extra['detalle']=substr($row['desconcepto'],0,37);
					$extra['sueldo']=$row['smes'];
					$extra['fechai']=mostrar_fecha($row['fechai']);
					$extra['saldo']=$row['saldo'];
					$extra['cantidad']=$row['cantidad'];
					$extra['cedula']=$row['cedula'];
				}
				else{
					$tasig=($row['tipo']=='A'?$row['monto']:0);
					$tdeduc=($row['tipo']=='D'?$row['monto']:0);
					$tasigx=($row['tipo']=='A'?$row['monto']:0);
					$tdeducx=($row['tipo']=='D'?$row['monto']:0);
					$tconcepto=$row['concepto'];
					$tdetalle=$row['desconcepto'];
					$tcantidad=$row['cantidad'];
					$tcedula=$row['cedula'];
					$tcargo=$row['cargo'];
					$tJornada=$row['turno'];
					$concar=mysqli_query($enlace,"select * from tablas where tabla='CARGO' and codigo='".$tcargo."' and id='".$_SESSION['id_validar']."' "  );
					while($row1=mysqli_fetch_array($concar))
						$tcargo=$row1['detalle'];
						$tnombre="Nombre: ".trim($row['nombres']).',  '.trim($row['apellidos']).' - Cargo: '.$tcargo.' - Fec. Ingreso: '.$row['fechai'];
						if($nominaX == 100){
						$tnombre2="Sueldo Diario: ".number_format($row['sdia'],2,',','.')." +Bono Lider Manuf: ".number_format($row['bono1'],2,',','.')." +Bono Lider Grupo: ".number_format($row['bono2'],2,',','.');
						}
						else{
						$tnombre2="Sueldo Mensual: ".number_format($row['smes'],2,',','.');
						}
						//$tnombre2="Sueldo Diario: ".number_format($row['sdia']+$row['bono1']+$row['bono2'],2,',','.').',  Jornada: '.$tJornada;

					//$tnombre=trim($row['sso'])." ".trim($row['nombres']).',  '.trim($row['apellidos']).' - '.$tcargo.($row['cuenta']==''?'':' - cuenta bancaria: '.$row['cuenta']);

					echo "<tr><td colspan=1>".$tcedula."</td>";
					echo "<td colspan=5>".$tnombre."</td></tr>";
					echo "<td colspan=5>".$tnombre2."</td></tr>";

					$color=0;

					if ($color) echo '<tr bgcolor="#E6E6E6" >';
					else echo '<tr bgcolor="#EEEFF3">';
					$color=!$color;

					echo "<td width='2'><font face='verdana' color='black' size='3'>".$tconcepto."</font></td>";
					echo "<td width='300'><font face='verdana' color='black' size='3'>".$tdetalle."</font></td>";
					echo "<td width='120' align='right'><font face='verdana' color='black' size='2'><b>".number_format($tcantidad,2)."</font></b></td>";
					echo "<td width='120' align='right'><font face='verdana' color='#36C1E2' size='3'>".number_format($tasigx,2)."</font></td>";
					echo "<td width='120' align='right'><font face='verdana' color='#DD0044' size='3'>".number_format($tdeducx,2)."</font></td>";
					echo "<td width='120' align='right'><font face='verdana' color='black' size='3'>".($tconcepto=="2200"?number_format($tsaldo,2):"")."</font></td>";
					echo "</tr>";
				}
			}
		}

		echo "<tr BGcolor='#464D77' style='color:#fff;' >";
		echo "<th ali=center colspan=3><font face='verdana' size=3>Sub-Totales Bs.</font></th> ";
		echo "<td width='120' align='right'><font face='verdana'  size='3'><b>".number_format($tasig,2)."</font></b></td>";
		echo "<td width='120' align='right'><font face='verdana'  size='3'>".number_format($tdeduc,2)."</font></td>";
		echo "<td width='120' align='right'><font face='verdana'  size='3'>".number_format($tasig-$tdeduc,2)."</font></td>";
		echo "</tr>";

		/*agreado por victor*/
		if(count($extra)>0&&$prestac)
		{    $prestac=false;
			echo "<tr BGcolor='#464D77' style='color:#fff;'>";
			echo "<td width='2'><font face='verdana'  size='3'>".$extra['concepto']."</font></td>";
			echo "<td width='300'><font face='verdana' size='3'>".$extra['detalle']."</font></td>";
			echo "<td width='120' align='right'><font face='verdana'  size='2'><b>".number_format($extra['cantidad'],2)."</font></b></td>";
			echo "<td width='120' align='right'><font face='verdana'  size='3'>".number_format($extra['monto'],2)."</font></td>";
			echo "<td width='120' align='right'><font face='verdana'  size='3'></font></td>";
			echo "<td width='120' align='right'><font face='verdana'  size='3'>".number_format($extra['monto'],2)."</font></td>";
			echo "</tr>";

		}

		echo "<tr BGcolor='#464D77' style='color:#fff;' >";
		echo "<th ali=center colspan=3><font face='verdana' size=3>TOTAL GENERAL DE NOMINA Bs.</font></th> ";
		echo "<td width='120' align='right'><font face='verdana' size='3'><b>".number_format($ttasig-$textra,2)."</font></b></td>";
		echo "<td width='120' align='right'><font face='verdana'  size='3'>".number_format($ttdeduc,2)."</font></td>";
		echo "<td width='120' align='right'><font face='verdana'  size='3'>".number_format($ttasig-$textra-$ttdeduc,2)."</font></td>";
		echo "</tr>";
		echo "<tr BGcolor='#464D77' style='color:#fff;' >";
		echo "<th ali=center colspan=3><font face='verdana' size=3>Total PRESTACIONES SOCIALES Bs.</font></th> ";
		echo "<td width='120' align='right'><font face='verdana' size='3'><b>".number_format($textra,2)."</font></b></td>";
		echo "<td width='120' align='right'><font face='verdana'  size='3'></font></td>";
		echo "<td width='120' align='right'><font face='verdana'  size='3'>".number_format($textra,2)."</font></td>";
		echo "</tr>";
	} //================= salida TEXTO


} // fin de reporte 3 payroll

//--------------------------------------------------------------------------------------------------------------------------------- REPORTE
//--------------------------------------------------------------------------------------------------------------------------------- RECIBOS DE PAGOS
if ($_POST['treporte']==4) {
	require('fpdf.php');
	class PDF extends FPDF {
	function Header()
	{
	}
	function Footer()
	{
	$this->SetY(-20);
	}
	}
	//============ eliminar linea si quiere que salgan los dos reportes
	//$_POST['forma']=2;

	if ($_POST['forma']==2)	{
			//Cuerpo //////////////////////////////////////////////
				$pdf=new PDF($orientation='P',$unit='mm',$format='letter');
				$pdf->AddPage();
				$pdf->AliasNbPages();
				$pdf->SetFont('helvetica','',10);
				if ($_POST['eshistorico']!=1)
					$consulta=mysqli_query($enlace,"select * from personal,$payroll where personal.id='".$_SESSION['id_validar']."' and $payroll.cedula=personal.codigo AND substr($payroll.concepto,1,1)!=6 AND substr($payroll.concepto,1,1)!=4 AND concepto NOT IN(2000,2001,2002,2003,2004,2005,2006,2007,2010,2012) order by personal.codigo, $payroll.concepto, $payroll.desconcepto  "  );
				else {
					if ($gerencia==1) $queryx="select * from personal,$payroll where personal.id='".$_SESSION['id_validar']."' and $payroll.cedula=personal.codigo ".$queryy." AND substr($payroll.concepto,1,1)!=6 AND substr($payroll.concepto,1,1)!=4 AND concepto NOT IN(2000,2001,2002,2003,2004,2005,2006,2007,2010,2012) order by personal.codigo,$payroll.concepto, $payroll.desconcepto";
					else $queryx="select * from personal,$payroll where personal.id='".$_SESSION['id_validar']."' and $payroll.tipo<>'R' and $payroll.cedula=personal.codigo ".$queryy." AND substr($payroll.concepto,1,1)!=6  AND substr($payroll.concepto,1,1)!=4 AND concepto NOT IN(2000,2001,2002,2003,2004,2005,2006,2007,2010,2012) order by personal.codigo, $payroll.concepto, $payroll.desconcepto";
					$consulta=mysqli_query($enlace,$queryx) or die ($queryx.mysqli_error($enlace));
				}
				$linea=0;
				$color=0;
				$tasig=0;
				$tdeduc=0;
				$bandera=0;$salto=1;
				$ttasig=0; $ttdeduc=0;
				$tlinea=0;
				$prestac=false;
				while($row=mysqli_fetch_array($consulta)) {

					$ttasig+=($row['tipo']=='A'?$row['monto']:0);
					$ttdeduc+=($row['tipo']=='D'?$row['monto']:0);
					if ($bandera==0) {
						/*Agregado por victor*/
				        $extra=array();
						$prestac=false;
						//===================================== inicio de cabecera
						//$pdf->Image($_SESSION['logo_validar'],10,10,20,20);
						if ($_POST['logosino']==0) //$pdf->Image($_SESSION['logo_validar'],10,10,20,20);
						$pdf->SetFont('arial','B',8);
						//$pdf->Ln(2);
						$pdf->Cell(200,5,($gerencia==1?substr($_POST['gerencia'],7,50):$_POST['empresal']).' / '.$_POST['encabeza'],0,0,'R');
						$pdf->ln(3);
						//$pdf->Cell(200,5,$_POST['encabeza'],0,1,'R');
						$pdf->SetFont('arial','',7);
						$pdf->Cell(200,5,'Fecha: '.hoy().' / Nomina: '.$_POST['empresa'],0,0,'R');
						$pdf->ln(3);
						//$pdf->Cell(100,5,$_POST['encabeza'],0,0,'R');
						//$pdf->Cell(200,5,'Nomina: '.$_POST['empresa'],0,1,'R');
						//$pdf->Ln(2);
						$pdf->SetFont('arial','B',16);
						$pdf->Cell(0,5,($_POST['titulo']==''?'Recibo de Pago':$_POST['titulo']),0,1,'C');
						$pdf->SetFont('arial','',8);
						$pdf->Cell(0,3,'(ART. 106 L.O.T.T.T. )',0,1,'C');
						$pdf->Cell(0,5,$_POST['subtitulo'],0,1,'C');
						if ($gerencia==0)
							if ($_POST['gerencia']!="") $pdf->Cell(130,5,'Gerencia: '.$_POST['gerencia'],0,1,'L');
						if ($_POST['division']!="") $pdf->Cell(130,5,'División: '.$_POST['division'],0,1,'L');
						if ($_POST['departamento']!="") $pdf->Cell(130,5,'Departamento: '.$_POST['departamento'],0,1,'L');
						//===================================== final de cabecera
						$bandera=1;
						$tcedula=$row['cedula'];
						$tfechai=mostrar_fecha($row['fechai']);
						$tcargo=$row['cargo'];
						$concar=mysqli_query($enlace,"select * from tablas where tabla='CARGO' and codigo='".$tcargo."' and id='".$_SESSION['id_validar']."' "  );
						while($row1=mysqli_fetch_array($concar)) $tcargo=$row1['detalle'];
						$tnombre=trim($row['sso'])." ".trim($row['nombres']).',  '.trim($row['apellidos']).' - '.$tcargo;
						$tnombresso=trim($row['sso']); $tnombrenom=trim($row['nombres']); $tnombreape=trim($row['apellidos']);
						if ($row['cuenta']!='') $tnombrec='Cuenta Bancaria: '.$row['cuenta'];

						//$pdf->ln(2);
						//$pdf->SetFont('helvetica','',10);
						//$pdf->cell(1);$pdf->cell(1,5,"[".$tcedula."] - ".$tnombre,0,1,'');
						$pdf->SetFont('helvetica','B',10); $pdf->cell(1);$pdf->cell(1,5,$tnombrenom." ".$tnombreape." - ".$tcargo,0,0,'L');
						$pdf->ln(4);
						$pdf->SetFont('helvetica','',8); $pdf->cell(1);$pdf->cell(1,5,"Cedula: ".$tcedula." - Rif: ".$tnombresso.' / '.$tnombrec,0,1,'L');
						//$pdf->SetFont('helvetica','B',8); $pdf->cell(1);$pdf->cell(1,5,$tnombrec,0,1,'L');

						$pdf->SetFont('helvetica','',10);
						$header=array('Cod.','Descripción','Cantidad','Asignación(BS)','Deducción(BS)','Saldo(BS)');
						$pdf->SetFont('helvetica','',8);
						$w=array(10,70,20,30,30,30);
						for($i=0;$i<count($header);$i++) $pdf->Cell($w[$i],4,$header[$i],1,0,'C',0);
						$pdf->Ln();
						$pdf->SetFont('');
					}
					if ($tcedula==$row['cedula']) {
						if($row['concepto']==="5008"||$row['concepto']==="5009"||$row['concepto']==="5010"||$row['concepto']==="5011"||$row['concepto']==="5508"||$row['concepto']==="5509"||$row['concepto']==="5510"||$row['concepto']==="5511"){
							$prestac=true;
							$extra['tipo']=$row['tipo'];
							$extra['monto']=$row['monto'];
							$extra['concepto']=$row['concepto'];
							$extra['detalle']=substr($row['desconcepto'],0,37);
							$extra['sueldo']=$row['smes'];
							$extra['fechai']=mostrar_fecha($row['fechai']);
							$extra['saldo']=$row['saldo'];
							$extra['cantidad']=$row['cantidad'];
							$extra['cedula']=$row['cedula'];
				        }
						else
						{
							$tasig+=($row['tipo']=='A'?$row['monto']:0);
							$tdeduc+=($row['tipo']=='D'?$row['monto']:0);
							$tasigx=($row['tipo']=='A'?$row['monto']:0);
							$tdeducx=($row['tipo']=='D'?$row['monto']:0);
							$tnombre=trim($row['nombres']).',  '.trim($row['apellidos']);
							$tconcepto=$row['concepto'];
							$tdetalle=$row['desconcepto'];
							$tfechai=$row['fechai'];
							$tsaldo=$row['saldo'];
							$sueldom=$row['smes'];
							$tcantidad=$row['cantidad'];
							$tcedula=$row['cedula'];
							$pdf->cell(10,4,$tconcepto,0,0,'',$color);
							$pdf->cell(60,4,$tdetalle,0,0,'',$color);
							$pdf->SetFont('helvetica','',8);
							$pdf->cell(30,4,number_format($tcantidad,2),0,0,'R',$color);
							$pdf->cell(30,4,number_format($tasigx,2),0,0,'R',$color);
							$pdf->cell(30,4,number_format($tdeducx,2),0,0,'R',$color);
							$pdf->cell(30,4,($tconcepto=="2200"?number_format($tsaldo,2):""),0,1,'R',$color);
							$pdf->SetFont('helvetica','',8);
							$tlinea++;
						}

					} else {
						$pdf->Cell(190,0,'',1,1,'C'); $pdf->ln(1);
						$pdf->cell(100,5,'Sub-Total',0,0,'R');
						$pdf->SetFont('helvetica','',8);
						$pdf->cell(30,4,number_format($tasig,2),0,0,'R');
						$pdf->cell(30,4,number_format($tdeduc,2),0,0,'R');
						$pdf->cell(30,4,number_format($tasig-$tdeduc,2),0,1,'R');
						//$pdf->Cell(190,0,'',1,1,'C'); $pdf->ln(1);
						$pdf->SetFont('helvetica','',8);
						$pdf->cell(100,4,'Total a Cobrar Nomina:',0,0,'R');
						$pdf->SetFont('helvetica','',8);
						$pdf->cell(90,4,number_format($tasig-$tdeduc,2) ,0,1,'R');
						$pdf->Cell(190,0,'',1,1,'C'); $pdf->ln(1);
						if(count($extra)>0&&$prestac){
							$prestac=false;
							$pdf->cell(10,4,$extra['concepto'],0,0,'',$color);
							$pdf->cell(60,4,$extra['detalle'],0,0,'',$color);
							$pdf->SetFont('helvetica','',8);
							$pdf->cell(30,4,number_format($extra['cantidad'],2),0,0,'R',$color);
							$pdf->cell(30,4,number_format($extra['monto'],2),0,0,'R',$color);
							$pdf->cell(30,4,'',0,0,'R',$color);
							$pdf->cell(30,4,number_format($extra['monto'],2),0,1,'R',$color);
							$pdf->SetFont('helvetica','',8);
							$pdf->cell(100,4,'Depósito Fideicomiso '.$extra['detalle'].':',0,0,'R');
							$pdf->SetFont('helvetica','',8);
							$pdf->cell(90,4,number_format($extra['monto'],2) ,0,1,'R');
							$pdf->Cell(190,0,'',1,1,'C'); $pdf->ln(1);
						}


						$pdf->SetFont('helvetica','',10);
						$pdf->ln(6);
						$pdf->cell(190,5,'-----------------------------------------------',0,0,'R');
						$pdf->ln(3);
						$pdf->cell(185,5,'Firma / Cedula de Recibido',0,0,'R');
						$pdf->ln(7);
						$pdf->SetFont('helvetica','B',7);
						//$pdf->Cell(0,5,'Nomina: '.$_POST['nomina']." / ".'Periodo: '.$_POST['periodo'].' / Fec.Ingreso: '.$tfechai.' / Sueldo Mensual : '.number_format($sueldom,2),0,0,'L');
						$pdf->Cell(0,5,'Nomina: '.$_POST['nomina']." / ".'Periodo: '.$_POST['periodo'].' / Fec.Ingreso: '.$tfechai,0,0,'L');

						$pdf->SetFont('helvetica','',5);
						$pdf->ln(4);
						//$pdf->Cell(0,5,'Gaceta Oficial Extraordinaria N� 6.296 del 01/05/2017, Decreto N� 27, en su Art�culo N� 3 establece que el Beneficio de CESTATICKET SOCIALISTA  ser� pagado  a cada trabajador en efectivo, ',0,0,'L');
						//$pdf->ln(2);
						//$pdf->Cell(0,5,'o mediante abono en su cuenta Nomina, expresando  que el mismo no genera incidencia salarial alguna.',0,0,'L');

						$pdf->SetFont('helvetica','',10);
						$pdf->ln(4);
						$pdf->Cell(0,5,'-----------------------------------------------------------------------------------------------------------------------------------',0,0,'C');


						if ($salto==1) {
							for ($t=0; $t<=10-$tlinea;$t++) $pdf->ln(1);
							$tlinea=1;
							if ($_POST['logosino']==0) //$pdf->Image($_SESSION['logo_validar'],10,100,20,20);
							//$pdf->SetFont('arial','',12);
							//$pdf->Ln(2);
							//===================================== inicio de cabecera
							//$pdf->Image($_SESSION['logo_validar'],10,10,20,20);
							$pdf->SetFont('arial','B',8);
						$pdf->Ln(2);
						$pdf->Cell(200,5,($gerencia==1?substr($_POST['gerencia'],7,50):$_POST['empresal']).' / '.$_POST['encabeza'],0,0,'R');
						$pdf->ln(3);
						//$pdf->Cell(200,5,$_POST['encabeza'],0,1,'R');
						$pdf->SetFont('arial','',7);
						$pdf->Cell(200,5,'Fecha: '.hoy().' / Nomina: '.$_POST['empresa'],0,0,'R');
						$pdf->ln(3);
						//$pdf->Cell(100,5,$_POST['encabeza'],0,0,'R');
						//$pdf->Cell(200,5,'Nomina: '.$_POST['empresa'],0,1,'R');
						//$pdf->Ln(2);
						$pdf->SetFont('arial','B',16);
						$pdf->Cell(0,5,($_POST['titulo']==''?'Recibo de Pago':$_POST['titulo']),0,1,'C');
						$pdf->SetFont('arial','',8);
						$pdf->Cell(0,3,'(ART. 106 L.O.T.T.T. )',0,1,'C');
						$pdf->Cell(0,5,$_POST['subtitulo'],0,1,'C');
							if ($gerencia==0)
								if ($_POST['gerencia']!="") $pdf->Cell(130,5,'Gerencia: '.$_POST['gerencia'],0,1,'L');
							if ($_POST['division']!="") $pdf->Cell(130,5,'División: '.$_POST['division'],0,1,'L');
							if ($_POST['departamento']!="") $pdf->Cell(130,5,'Departamento: '.$_POST['departamento'],0,1,'L');
							//===================================== final de cabecera
							$salto=0;
						} else {
							$pdf->AddPage();
							//===================================== inicio de cabecera
							//$pdf->Image($_SESSION['logo_validar'],10,10,20,20);
							if ($_POST['logosino']==0) //$pdf->Image($_SESSION['logo_validar'],10,10,30,30);
							$pdf->SetFont('arial','B',8);
						$pdf->Ln(2);
						$pdf->Cell(200,5,($gerencia==1?substr($_POST['gerencia'],7,50):$_POST['empresal']).' / '.$_POST['encabeza'],0,0,'R');
						$pdf->ln(3);
						//$pdf->Cell(200,5,$_POST['encabeza'],0,1,'R');
						$pdf->SetFont('arial','',7);
						$pdf->Cell(200,5,'Fecha: '.hoy().' / Nomina: '.$_POST['empresa'],0,0,'R');
						$pdf->ln(3);
						//$pdf->Cell(100,5,$_POST['encabeza'],0,0,'R');
						//$pdf->Cell(200,5,'Nomina: '.$_POST['empresa'],0,1,'R');
						//$pdf->Ln(2);
						$pdf->SetFont('arial','B',16);
						$pdf->Cell(0,5,($_POST['titulo']==''?'Recibo de Pago':$_POST['titulo']),0,1,'C');
						$pdf->SetFont('arial','',8);
						$pdf->Cell(0,3,'(ART. 106 L.O.T.T.T. )',0,1,'C');
						$pdf->Cell(0,5,$_POST['subtitulo'],0,1,'C');
							if ($gerencia==0)
								if ($_POST['gerencia']!="") $pdf->Cell(130,5,'Gerencia: '.$_POST['gerencia'],0,1,'L');
							if ($_POST['division']!="") $pdf->Cell(130,5,'División: '.$_POST['division'],0,1,'L');
							if ($_POST['departamento']!="") $pdf->Cell(130,5,'Departamento: '.$_POST['departamento'],0,1,'L');
							//===================================== final de cabecera
							$tlinea=1;
							$salto=1;
						}
						$tasig=($row['tipo']=='A'?$row['monto']:0);
						$tdeduc=($row['tipo']=='D'?$row['monto']:0);
						$tasigx=($row['tipo']=='A'?$row['monto']:0);
						$tdeducx=($row['tipo']=='D'?$row['monto']:0);
						$tconcepto=$row['concepto'];
						$tdetalle=$row['desconcepto'];
						$tcantidad=$row['cantidad'];
						$sueldom=$row['smes'];
						$tfechai=mostrar_fecha($row['fechai']);
						$tcedula=$row['cedula'];
						$tcargo=$row['cargo'];
						$concar=mysqli_query($enlace,"select * from tablas where tabla='CARGO' and codigo='".$tcargo."' and id='".$_SESSION['id_validar']."' "  );
						while($row1=mysqli_fetch_array($concar))
							$tcargo=$row1['detalle'];
						$tnombre=trim($row['sso'])." ".trim($row['nombres']).',  '.trim($row['apellidos']).' - '.$tcargo;
						$tnombresso=trim($row['sso']); $tnombrenom=trim($row['nombres']); $tnombreape=trim($row['apellidos']);
						if ($row['cuenta']!='') $tnombrec='Cuenta Bancaria: '.$row['cuenta'];

						$pdf->ln(2);
						//$pdf->SetFont('helvetica','',10);
						//$pdf->cell(1);$pdf->cell(1,5,"[".$tcedula."] - ".$tnombre,0,1,'');
						$pdf->SetFont('helvetica','B',10); $pdf->cell(1);$pdf->cell(1,5,$tnombrenom." ".$tnombreape." - ".$tcargo,0,0,'L');
						$pdf->ln(4);
						$pdf->SetFont('helvetica','',8); $pdf->cell(1);$pdf->cell(1,5,"Cedula: ".$tcedula." - Rif: ".$tnombresso.' / '.$tnombrec,0,1,'L');
						//$pdf->SetFont('helvetica','B',8); $pdf->cell(1);$pdf->cell(1,5,$tnombrec,0,1,'L');

						$pdf->SetFont('helvetica','',8);
						for($i=0;$i<count($header);$i++)
							$pdf->Cell($w[$i],4,$header[$i],1,0,'C',0);
						$pdf->Ln(5);
						if($row['concepto']==="5008"||$row['concepto']==="5009"||$row['concepto']==="5010"||$row['concepto']==="5011"||$row['concepto']==="5508"||$row['concepto']==="5509"||$row['concepto']==="5510"||$row['concepto']==="5511"){
							$prestac=true;
							$extra['tipo']=$row['tipo'];
							$extra['monto']=$row['monto'];
							$extra['concepto']=$row['concepto'];
							$extra['detalle']=substr($row['desconcepto'],0,37);
							$extra['sueldo']=$row['smes'];
							$extra['fechai']=mostrar_fecha($row['fechai']);
							$extra['saldo']=$row['saldo'];
							$extra['cantidad']=$row['cantidad'];
							$extra['cedula']=$row['cedula'];
					    }
						else{
							$pdf->cell(10,5,$tconcepto,0,0,'',$color);
							$pdf->cell(60,5,$tdetalle,0,0,'',$color);
							$pdf->SetFont('helvetica','',8);
							$pdf->cell(30,5,number_format($tcantidad,2),0,0,'R',$color);
							$pdf->cell(30,5,number_format($tasigx,2),0,0,'R',$color);
							$pdf->cell(30,5,number_format($tdeducx,2),0,0,'R',$color);
							$pdf->cell(30,5,($tconcepto=="2200"?number_format($tsaldo,2):""),0,1,'R',$color);
							$pdf->SetFont('helvetica','',8);
						}
					}
				}
				$pdf->Cell(190,0,'',1,1,'C'); $pdf->ln(1);
				$pdf->cell(100,5,'Sub-Total',0,0,'R');
				$pdf->SetFont('helvetica','',8);
				$pdf->cell(30,5,number_format($tasig,2),0,0,'R');
				$pdf->cell(30,5,number_format($tdeduc,2),0,0,'R');
				$pdf->cell(30,5,number_format($tasig-$tdeduc,2),0,1,'R');
				$pdf->SetFont('helvetica','',8);
				//$pdf->Cell(190,0,'',1,1,'C');
				$pdf->cell(100,5,'Total a Cobrar Nomina:',0,0,'R');
				$pdf->SetFont('helvetica','',8);
				$pdf->cell(90,5,number_format($tasig-$tdeduc,2) ,0,1,'R');
				$pdf->Cell(190,0,'',1,1,'C'); $pdf->ln(1);

				if(count($extra)>0&&$prestac){
					$prestac=false;
					$pdf->cell(10,5,$extra['concepto'],0,0,'',$color);
					$pdf->cell(60,5,$extra['detalle'],0,0,'',$color);
					$pdf->SetFont('helvetica','',8);
					$pdf->cell(30,5,number_format($extra['cantidad'],2),0,0,'R',$color);
					$pdf->cell(30,5,number_format($extra['monto'],2),0,0,'R',$color);
					$pdf->cell(30,5,'',0,0,'R',$color);
					$pdf->cell(30,5,number_format($extra['monto'],2),0,1,'R',$color);
					$pdf->SetFont('helvetica','',8);
					$pdf->cell(100,5,'Depósito Fideicomiso '.$extra['detalle'].':',0,0,'R');
					$pdf->SetFont('helvetica','',8);
					$pdf->cell(90,5,number_format($extra['monto'],2) ,0,1,'R');
					$pdf->Cell(190,0,'',1,1,'C'); $pdf->ln(1);
				}



				$pdf->SetFont('helvetica','',10);
				$pdf->ln(8);
				$pdf->cell(190,5,'-----------------------------------------------',0,0,'R');
				$pdf->ln(3);
				$pdf->cell(185,5,'Firma / Cedula de Recibido',0,0,'R');
				$pdf->ln(7);
				$pdf->SetFont('helvetica','B',8);
				//$pdf->Cell(0,5,'Nomina: '.$_POST['nomina']." - ".'Periodo: '.$_POST['periodo'].'  -  Fecha de Ingreso: '.$tfechai.'  -  Sueldo Mensual Bs.: '.number_format($sueldom,2),0,1,'L');
				$pdf->Cell(0,5,'Nomina: '.$_POST['nomina']." - ".'Periodo: '.$_POST['periodo'].'  -  Fecha de Ingreso: '.$tfechai,0,1,'L');

	}
	else {

			//Cuerpo //////////////////////////////////////////////
			$pdf=new PDF($orientation='L',$unit='mm',$format='letter');
			$pdf->AddPage();
			$pdf->AliasNbPages();
			$pdf->SetFont('Arial','',8);
			$pdf->SetFillColor(224,235,255);
			$pdf->SetTextColor(0);
			if ($_POST['eshistorico']!=1)
				$consulta=mysqli_query($enlace,"select * from personal,$payroll where personal.id='".$_SESSION['id_validar']."' and $payroll.cedula=personal.codigo AND substr($payroll.concepto,1,1)!=6 AND substr($payroll.concepto,1,1)!=4 AND concepto NOT IN(2000,2001,2002,2003,2004,2005,2006,2007,2010,2012) order by personal.codigo, $payroll.concepto, $payroll.desconcepto  "  );
			else {
				if ($gerencia==1) $queryx="select * from personal,$payroll where personal.id='".$_SESSION['id_validar']."' and $payroll.cedula=personal.codigo ".$queryy." AND substr($payroll.concepto,1,1)!=6 AND substr($payroll.concepto,1,1)!=4 AND concepto NOT IN(2000,2001,2002,2003,2004,2005,2006,2007,2010,2012) order by personal.codigo,$payroll.concepto, $payroll.desconcepto";
				else $queryx="select * from personal,$payroll where personal.id='".$_SESSION['id_validar']."' and $payroll.tipo<>'R' and $payroll.cedula=personal.codigo ".$queryy." AND substr($payroll.concepto,1,1)!=6 AND substr($payroll.concepto,1,1)!=4 AND concepto NOT IN(2000,2001,2002,2003,2004,2005,2006,2007,2010,2012) order by personal.codigo, $payroll.concepto, $payroll.desconcepto";
				$consulta=mysqli_query($enlace,$queryx) or die ($queryx.mysqli_error($enlace));
			}
			$linea=0;
			$color=0;
			$tasig=0;
			$tdeduc=0;
			$bandera=0;
			$ttasig=0; $ttdeduc=0;
			$lineaxrecibo=0;
			$partedelrecibo=0;
			$prestac=false;
			while($row=mysqli_fetch_array($consulta)) {
				$ttasig+=($row['tipo']=='A'?$row['monto']:0);
				$ttdeduc+=($row['tipo']=='D'?$row['monto']:0);
				if ($bandera==0) {
				    /*Agregado por victor*/
				    $extra=array();
				    $prestac=false;
					if ($_POST['logosino']==0) {
						$pdf->Image($_SESSION['logo_validar'],10,10,30,30);
						$pdf->Image($_SESSION['logo_validar'],150,10,30,30);
						$pdf->Ln(2);
					}
					//===================================== inicio de cabecera linea 1
					$pdf->SetFont('arial','B',10);
					$pdf->Cell(120,3,($gerencia==1?substr($_POST['gerencia'],7,50):$_POST['empresal']),0,0,'R');
					$pdf->Cell(20);
					$pdf->Cell(120,3,($gerencia==1?substr($_POST['gerencia'],7,50):$_POST['empresal']),0,1,'R');
					$pdf->SetFont('arial','',10);

					//===================================== inicio de cabecera rif
					$pdf->SetFont('arial','',6);
					$pdf->Cell(120,3,$_POST['encabeza'],0,0,'R');
					$pdf->Cell(20);
					$pdf->Cell(120,3,$_POST['encabeza'],0,0,'R');
					$pdf->SetFont('arial','',10);

					//===================================== inicio de cabecera linea 1
					$pdf->SetFont('arial','',8);
					$pdf->Cell(120,3,'Fecha: '.hoy(),0,0,'R');
					$pdf->Cell(20);
					$pdf->Cell(120,3,'Fecha: '.hoy(),0,1,'R');

					//===================================== inicio de cabecera linea 2
					$pdf->SetFont('arial','',8);
					$pdf->Cell(120,3,'Nomina: '.$_POST['empresa'],0,0,'R');
					$pdf->Cell(20);
					$pdf->Cell(120,3,'Nomina: '.$_POST['empresa'],0,1,'R');

					//===================================== inicio de cabecera linea 3
					$pdf->ln(15);
					$pdf->SetFont('arial','B',16);
					$pdf->Cell(130,5,($_POST['titulo']==''?'RECIBO DE PAGO':$_POST['titulo']),0,0,'C');
					$pdf->Cell(10);
					$pdf->Cell(130,5,($_POST['titulo']==''?'RECIBO DE PAGO':$_POST['titulo']),0,1,'C');
					$pdf->SetFont('arial','',8);
					$pdf->Cell(130,0,$_POST['subtitulo'],0,0,'C');
					$pdf->Cell(10);
					$pdf->Cell(130,0,$_POST['subtitulo'],0,1,'C');
					$pdf->Cell(130,3,'(ART. 106 L.O.T.T.T. )',0,0,'C');
					$pdf->Cell(10);
					$pdf->Cell(130,3,'(ART. 106 L.O.T.T.T. )',0,1,'C');

					//===================================== inicio de cabecera linea 4
					if ($gerencia==0) {
						if ($_POST['gerencia']!="") {
							$pdf->Cell(130,5,'Gerencia: '.$_POST['gerencia'],0,0,'L');
							$pdf->Cell(10);
							$pdf->Cell(130,5,'Gerencia: '.$_POST['gerencia'],0,1,'L');
						}
					}
					if ($_POST['division']!="") {
						$pdf->Cell(130,5,'División: '.$_POST['division'],0,0,'L');
						$pdf->Cell(10);
						$pdf->Cell(130,5,'División: '.$_POST['division'],0,1,'L');
					}
					if ($_POST['departamento']!="") {
						$pdf->Cell(130,5,'Departamento: '.$_POST['departamento'],0,0,'L');
						$pdf->Cell(10);
						$pdf->Cell(130,5,'Departamento: '.$_POST['departamento'],0,1,'L');
					}
					//===================================== final de cabecera

					$bandera=1;
					$tcedula=$row['cedula'];
					$tcargo=$row['cargo'];
					$concar=mysqli_query($enlace,"select * from tablas where tabla='CARGO' and codigo='".$tcargo."' and id='".$_SESSION['id_validar']."' "  );
					while($row1=mysqli_fetch_array($concar))
						$tcargo=$row1['detalle'];
					//$tnombre=trim($row['sso'])." ".trim($row['nombres']).',  '.trim($row['apellidos']).' - '.$tcargo;
					$tnombre=trim($row['nombres']).',  '.trim($row['apellidos']).' - '.$tcargo;
					$trif=trim($row['sso']);
					if ($row['cuenta']!='') $tnombrec='Cuenta Bancaria: '.$row['cuenta'];

					//===================================== inicio de cabecera linea 5
					$pdf->SetFont('Arial','B',10);
					$pdf->ln(8);
					$pdf->cell(130,5,$tnombre,0,0,'');
					$pdf->Cell(10);
					$pdf->cell(130,5,$tnombre,0,1,'');
					$pdf->SetFont('Arial','B',8);
					$pdf->cell(130,2,"Cedula: ".$tcedula." - Rif: ".$trif,0,0,'');
					$pdf->Cell(10);
					$pdf->cell(130,2,"Cedula: ".$tcedula." - Rif: ".$trif,0,1,'');

					if ($row['cuenta']!='') {
						$pdf->SetFont('Arial','',8);
						$tnombrec='Cuenta Bancaria: '.$row['cuenta'];
						$pdf->cell(130,3,$tnombrec,0,0,'');
						$pdf->Cell(10);
						$pdf->cell(130,3,$tnombrec,0,1,'');
					}
					$pdf->ln(3);
					$pdf->SetFont('Arial','',8);
					$header=array('Cod.','Descripción','Cantidad','Asignación','Deducción','Saldo');
					$pdf->SetFillColor(70,77,119);
					$pdf->SetTextColor(255);
					$pdf->SetDrawColor(255,255,255);
					$pdf->SetLineWidth(.5);
					$pdf->SetFont('','');
					$pdf->SetFont('arial','B',7);
					$w=array(10,50,15,15,15,15);
					for($i=0;$i<count($header);$i++)
						$pdf->Cell($w[$i],4,$header[$i],1,0,'C',1);
					$pdf->Cell(20);
					for($i=0;$i<count($header);$i++)
						$pdf->Cell($w[$i],4,$header[$i],1,0,'C',1);
					$pdf->Ln();
					$pdf->SetFont('');
				}

				$pdf->SetFillColor(238,239,243);
				$pdf->SetTextColor(0);

				if ($tcedula==$row['cedula']) {
				    if($row['concepto']==="5008"||$row['concepto']==="5009" ||$row['concepto']==="5010"||$row['concepto']==="5011"||$row['concepto']==="5508"||$row['concepto']==="5509"||$row['concepto']==="5510"||$row['concepto']==="5511"){
						$prestac=true;
					    $extra['tipo']=$row['tipo'];
						$extra['monto']=$row['monto'];
						$extra['concepto']=$row['concepto'];
						$extra['detalle']=substr($row['desconcepto'],0,37);
						$extra['sueldo']=$row['smes'];
						$extra['fechai']=mostrar_fecha($row['fechai']);
						$extra['saldo']=$row['saldo'];
						$extra['cantidad']=$row['cantidad'];
						$extra['cedula']=$row['cedula'];
				    }
					else{
						$tasig+=($row['tipo']=='A'?$row['monto']:0);
						$tdeduc+=($row['tipo']=='D'?$row['monto']:0);
						$tasigx=($row['tipo']=='A'?$row['monto']:0);
						$tdeducx=($row['tipo']=='D'?$row['monto']:0);
						$tnombre=trim($row['nombres']).',  '.trim($row['apellidos']);
						$tconcepto=$row['concepto'];
						$tdetalle=substr($row['desconcepto'],0,37);
						$sueldom=$row['smes'];
						$tfechai=mostrar_fecha($row['fechai']);
						$tsaldo=$row['saldo'];
						$tcantidad=$row['cantidad'];
						$tcedula=$row['cedula'];
						$pdf->cell(10,5,$tconcepto,0,0,'',$color);
						$pdf->cell(50,5,$tdetalle,0,0,'',$color);
						$pdf->cell(15,5,number_format($tcantidad,2),0,0,'R',$color);
						$pdf->cell(15,5,number_format($tasigx,2),0,0,'R',$color);
						$pdf->cell(15,5,number_format($tdeducx,2),0,0,'R',$color);
						$pdf->cell(15,5,($tconcepto=="2200"?number_format($tsaldo,2):""),0,0,'R',$color);
						$pdf->Cell(20);
						$pdf->cell(10,5,$tconcepto,0,0,'',$color);
						$pdf->cell(50,5,$tdetalle,0,0,'',$color);
						$pdf->cell(15,5,number_format($tcantidad,2),0,0,'R',$color);
						$pdf->cell(15,5,number_format($tasigx,2),0,0,'R',$color);
						$pdf->cell(15,5,number_format($tdeducx,2),0,0,'R',$color);
						$pdf->cell(15,5,($tconcepto=="2200"?number_format($tsaldo,2):""),0,1,'R',$color);
				   }
				}
				else {
					$pdf->SetDrawColor(70,77,119);
					$pdf->SetLineWidth(.2);
					$pdf->Cell(120,0,'',1,0,'C');
					$pdf->Cell(20);
					$pdf->Cell(120,0,'',1,1,'C'); $pdf->ln(1);


					$pdf->cell(75,5,'Sub-Total',0,0,'R');
					$pdf->cell(15,5,number_format($tasig,2),0,0,'R');
					$pdf->cell(15,5,number_format($tdeduc,2),0,0,'R');
					$pdf->cell(15,5,number_format($tasig-$tdeduc,2),0,0,'R');
					$pdf->Cell(20);
					$pdf->cell(75,5,'Sub-Total',0,0,'R');
					$pdf->cell(15,5,number_format($tasig,2),0,0,'R');
					$pdf->cell(15,5,number_format($tdeduc,2),0,0,'R');
					$pdf->cell(15,5,number_format($tasig-$tdeduc,2),0,1,'R');

					$pdf->Cell(120,0,'',1,0,'C');
					$pdf->Cell(20);
					$pdf->Cell(120,0,'',1,1,'C'); $pdf->ln(1);

					$pdf->SetDrawColor(255,255,255);

					$pdf->cell(75,5,'Total a Cobrar Nomina:',0,0,'R');
					$pdf->cell(45,5,number_format($tasig-$tdeduc,2) ,0,0,'R');
					$pdf->Cell(20);
					$pdf->cell(75,5,'Total a Cobrar Nomina:',0,0,'R');
					$pdf->cell(45,5,number_format($tasig-$tdeduc,2) ,0,1,'R');

					/*Agregado por victor*/
					if(count($extra)>0&&$prestac)
				    {   $prestac=false;
						$pdf->SetDrawColor(70,77,119);
						$pdf->Cell(120,0,'',1,0,'C');
						$pdf->Cell(20);
						$pdf->Cell(120,0,'',1,1,'C'); $pdf->ln(1);

						$tasigx=($extra['tipo']=='A'?$extra['monto']:0);
						$tdeducx=($extra['tipo']=='D'?$extra['monto']:0);
						$pdf->cell(10,5,$extra['concepto'],0,0,'',1);
						$pdf->cell(50,5,$extra['detalle'],0,0,'',1);
						$pdf->cell(15,5,number_format($extra['cantidad'],2),0,0,'R',1);
						$pdf->cell(15,5,"",0,0,'R',1);
						$pdf->cell(15,5,"",0,0,'R',1);
						$pdf->cell(15,5,number_format($tasigx,2),0,0,'R',1);
						$pdf->Cell(20);
						$pdf->cell(10,5,$extra['concepto'],0,0,'',1);
						$pdf->cell(50,5,$extra['detalle'],0,0,'',1);
						$pdf->cell(15,5,number_format($extra['cantidad'],2),0,0,'R',1);
						$pdf->cell(15,5,"",0,0,'R',1);
						$pdf->cell(15,5,"",0,0,'R',1);
						$pdf->cell(15,5,number_format($tasigx,2),0,1,'R',1);

						$pdf->Cell(120,0,'',1,0,'C');
						$pdf->Cell(20);
						$pdf->Cell(120,0,'',1,1,'C'); $pdf->ln(1);
						$pdf->SetDrawColor(255,255,255);

						$pdf->cell(75,5,'Depósito Fideicomiso '.$extra['detalle'].':',0,0,'R');
						$pdf->cell(45,5,number_format($tasigx,2) ,0,0,'R');
						$pdf->Cell(20);
						$pdf->cell(75,5,'Depósito Fideicomiso '.$extra['detalle'].':',0,0,'R');
						$pdf->cell(45,5,number_format($tasigx,2) ,0,1,'R');
					}

					$pdf->ln(8);
					$pdf->cell(120,5,'-----------------------------------------------',0,0,'R');
					$pdf->Cell(20);
					$pdf->cell(120,5,'-----------------------------------------------',0,1,'R');
					$pdf->cell(120,5,'Firma / Cedula de Recibido',0,0,'R');
					$pdf->Cell(20);
					$pdf->cell(120,5,'Firma / Cedula de Recibido',0,1,'R');

					$pdf->Cell(130,5,'Nomina: '.$_POST['nomina']." - ".'Periodo: '.$_POST['periodo'],0,0,'L');
					$pdf->Cell(10);
					$pdf->Cell(130,5,'Nomina: '.$_POST['nomina']." - ".'Periodo: '.$_POST['periodo'],0,1,'L');

					//$pdf->Cell(130,5,'Fecha de Ingreso: '.$tfechai,0,0,'L');
					//$pdf->Cell(10);
					//$pdf->Cell(130,5,'Fecha de Ingreso: '.$tfechai,0,1,'L');

					//$pdf->Cell(130,5,'Sueldo Mensual Bs.: '.number_format($sueldom,2),0,0,'L');
					//$pdf->Cell(10);
					//$pdf->Cell(130,5,'Sueldo Mensual Bs.: '.number_format($sueldom,2),0,1,'L');
					$pdf->ln(5);

					/*$pdf->Cell(130,5,'Gaceta Oficial Extraordinaria N� 6.296 del 01/05/2017, Decreto N� 27, en su Art�culo N� 3',0,0,'L');
					$pdf->Cell(10);
					$pdf->Cell(130,5,'Gaceta Oficial Extraordinaria N� 6.296 del 01/05/2017, Decreto N� 27, en su Art�culo N� 3',0,1,'L');

					$pdf->Cell(130,5,'establece que el Beneficio de CESTATICKET SOCIALISTA  ser� pagado  a cada trabajador en efectivo,',0,0,'L');
					$pdf->Cell(10);
					$pdf->Cell(130,5,'establece que el Beneficio de CESTATICKET SOCIALISTA  ser� pagado  a cada trabajador en efectivo,',0,1,'L');

					$pdf->Cell(130,5,'o mediante abono en su cuenta Nomina, expresando  que el mismo no genera incidencia salarial alguna.',0,0,'L');
					$pdf->Cell(10);
					$pdf->Cell(130,5,'o mediante abono en su cuenta Nomina, expresando  que el mismo no genera incidencia salarial alguna.',0,1,'L');*/

					$pdf->AddPage();

					$tasig=($row['tipo']=='A'?$row['monto']:0);
					$tdeduc=($row['tipo']=='D'?$row['monto']:0);
					$tasigx=($row['tipo']=='A'?$row['monto']:0);
					$tdeducx=($row['tipo']=='D'?$row['monto']:0);
					$tconcepto=$row['concepto'];
					$tdetalle=substr($row['desconcepto'],0,37);
					$tfechai=mostrar_fecha($row['fechai']);
					$sueldom=$row['smes'];
					$tcantidad=$row['cantidad'];
					$tcedula=$row['cedula'];
					$tcargo=$row['cargo'];




					if ($_POST['logosino']==0) {
						$pdf->Image($_SESSION['logo_validar'],10,10,30,30);
						$pdf->Image($_SESSION['logo_validar'],150,10,30,30);
						$pdf->Ln(2);
					}
					//===================================== inicio de cabecera linea 1
					$pdf->SetFont('arial','B',10);
					$pdf->Cell(120,3,($gerencia==1?substr($_POST['gerencia'],7,50):$_POST['empresal']),0,0,'R');
					$pdf->Cell(20);
					$pdf->Cell(120,3,($gerencia==1?substr($_POST['gerencia'],7,50):$_POST['empresal']),0,1,'R');
					$pdf->SetFont('arial','',10);
					//===================================== inicio de cabecera rif
					$pdf->SetFont('arial','',6);
					$pdf->Cell(120,3,$_POST['encabeza'],0,0,'R');
					$pdf->Cell(20);
					$pdf->Cell(120,3,$_POST['encabeza'],0,0,'R');
					$pdf->SetFont('arial','',10);

					//===================================== inicio de cabecera linea 1
					$pdf->SetFont('arial','',8);
					$pdf->Cell(120,3,'Fecha: '.hoy(),0,0,'R');
					$pdf->Cell(20);
					$pdf->Cell(120,3,'Fecha: '.hoy(),0,1,'R');

					//===================================== inicio de cabecera linea 2
					$pdf->SetFont('arial','',8);
					$pdf->Cell(120,3,'Nomina: '.$_POST['empresa'],0,0,'R');
					$pdf->Cell(20);
					$pdf->Cell(120,3,'Nomina: '.$_POST['empresa'],0,1,'R');

					//===================================== inicio de cabecera linea 3
					$pdf->ln(15);
					$pdf->SetFont('arial','B',16);
					$pdf->Cell(130,5,($_POST['titulo']==''?'RECIBO DE PAGO':$_POST['titulo']),0,0,'C');
					$pdf->Cell(10);
					$pdf->Cell(130,5,($_POST['titulo']==''?'RECIBO DE PAGO':$_POST['titulo']),0,1,'C');
					$pdf->SetFont('arial','',8);
					$pdf->Cell(130,0,$_POST['subtitulo'],0,0,'C');
					$pdf->Cell(10);
					$pdf->Cell(130,0,$_POST['subtitulo'],0,1,'C');
					$pdf->Cell(130,3,'(ART. 106 L.O.T.T.T. )',0,0,'C');
					$pdf->Cell(10);
					$pdf->Cell(130,3,'(ART. 106 L.O.T.T.T. )',0,1,'C');

					//===================================== inicio de cabecera linea 4
					if ($gerencia==0) {
						if ($_POST['gerencia']!="") {
							$pdf->Cell(130,5,'Gerencia: '.$_POST['gerencia'],0,0,'L');
							$pdf->Cell(10);
							$pdf->Cell(130,5,'Gerencia: '.$_POST['gerencia'],0,1,'L');
						}
					}
					if ($_POST['division']!="") {
						$pdf->Cell(130,5,'División: '.$_POST['division'],0,0,'L');
						$pdf->Cell(10);
						$pdf->Cell(130,5,'División: '.$_POST['division'],0,1,'L');
					}
					if ($_POST['departamento']!="") {
						$pdf->Cell(130,5,'Departamento: '.$_POST['departamento'],0,0,'L');
						$pdf->Cell(10);
						$pdf->Cell(130,5,'Departamento: '.$_POST['departamento'],0,1,'L');
					}
					//===================================== final de cabecera

					$bandera=1;
					$tcedula=$row['cedula'];
					$tcargo=$row['cargo'];
					$concar=mysqli_query($enlace,"select * from tablas where tabla='CARGO' and codigo='".$tcargo."' and id='".$_SESSION['id_validar']."' "  );
					while($row1=mysqli_fetch_array($concar))
						$tcargo=$row1['detalle'];
					//$tnombre=trim($row['sso'])." ".trim($row['nombres']).',  '.trim($row['apellidos']).' - '.$tcargo;
					$tnombre=trim($row['nombres']).',  '.trim($row['apellidos']).' - '.$tcargo;
					$trif=trim($row['sso']);
					if ($row['cuenta']!='') $tnombrec='Cuenta Bancaria: '.$row['cuenta'];

					//===================================== inicio de cabecera linea 5
					$pdf->SetFont('Arial','B',10);
					$pdf->ln(8);
					$pdf->cell(130,5,$tnombre,0,0,'');
					$pdf->Cell(10);
					$pdf->cell(130,5,$tnombre,0,1,'');
					$pdf->SetFont('Arial','B',8);
					$pdf->cell(130,2,"Cedula: ".$tcedula." - Rif: ".$trif,0,0,'');
					$pdf->Cell(10);
					$pdf->cell(130,2,"Cedula: ".$tcedula." - Rif: ".$trif,0,1,'');

					if ($row['cuenta']!='') {
						$pdf->SetFont('Arial','',8);
						$tnombrec='Cuenta Bancaria: '.$row['cuenta'];
						$pdf->cell(130,3,$tnombrec,0,0,'');
						$pdf->Cell(10);
						$pdf->cell(130,3,$tnombrec,0,1,'');
					}
					$pdf->ln(3);

					$pdf->SetFont('Arial','',8);
					$pdf->SetFillColor(70,77,119);
					$pdf->SetTextColor(255);
					$pdf->SetDrawColor(255,255,255);
					$pdf->SetLineWidth(.5);
					$pdf->SetFont('','');
					$pdf->SetFont('arial','B',7);
					$w=array(10,50,15,15,15,15);
					for($i=0;$i<count($header);$i++)
						$pdf->Cell($w[$i],4,$header[$i],1,0,'C',1);
					$pdf->Cell(20);
					for($i=0;$i<count($header);$i++)
						$pdf->Cell($w[$i],4,$header[$i],1,0,'C',1);
					if($tconcepto==="5008"||$tconcepto==="5009" ||$row['concepto']==="5010"||$row['concepto']==="5011"||$row['concepto']==="5508"||$row['concepto']==="5509"||$row['concepto']==="5510"||$row['concepto']==="5511"){
						$prestac=true;
					    $extra['tipo']=$row['tipo'];
						$extra['monto']=$row['monto'];
						$extra['concepto']=$row['concepto'];
						$extra['detalle']=substr($row['desconcepto'],0,37);
						$extra['sueldo']=$row['smes'];
						$extra['fechai']=mostrar_fecha($row['fechai']);
						$extra['saldo']=$row['saldo'];
						$extra['cantidad']=$row['cantidad'];
						$extra['cedula']=$row['cedula'];
					}
					else{
						$pdf->Ln();

						$pdf->SetFillColor(238,239,243);
						$pdf->SetTextColor(0);
						$pdf->SetFont('');

						$pdf->cell(10,5,$tconcepto,0,0,'',$color);
						$pdf->cell(50,5,$tdetalle,0,0,'',$color);
						$pdf->cell(15,5,number_format($tcantidad,2),0,0,'R',$color);
						$pdf->cell(15,5,number_format($tasigx,2),0,0,'R',$color);
						$pdf->cell(15,5,number_format($tdeducx,2),0,0,'R',$color);
						$pdf->cell(15,5,($tconcepto=="2200"?number_format($tsaldo,2):""),0,0,'R',$color);
						$pdf->Cell(20);
						$pdf->cell(10,5,$tconcepto,0,0,'',$color);
						$pdf->cell(50,5,$tdetalle,0,0,'',$color);
						$pdf->cell(15,5,number_format($tcantidad,2),0,0,'R',$color);
						$pdf->cell(15,5,number_format($tasigx,2),0,0,'R',$color);
						$pdf->cell(15,5,number_format($tdeducx,2),0,0,'R',$color);
						$pdf->cell(15,5,($tconcepto=="2200"?number_format($tsaldo,2):""),0,1,'R',$color);
					}

				}
				$color=!$color;
			}
			$pdf->SetDrawColor(70,77,119);
					$pdf->SetLineWidth(.2);

			$pdf->Cell(120,0,'',1,0,'C');
			$pdf->Cell(20);
			$pdf->Cell(120,0,'',1,1,'C'); $pdf->ln(1);

			$pdf->cell(75,5,'Sub-Total',0,0,'R');
			$pdf->cell(15,5,number_format($tasig,2),0,0,'R');
			$pdf->cell(15,5,number_format($tdeduc,2),0,0,'R');
			$pdf->cell(15,5,number_format($tasig-$tdeduc,2),0,0,'R');
			$pdf->Cell(20);
			$pdf->cell(75,5,'Sub-Total',0,0,'R');
			$pdf->cell(15,5,number_format($tasig,2),0,0,'R');
			$pdf->cell(15,5,number_format($tdeduc,2),0,0,'R');
			$pdf->cell(15,5,number_format($tasig-$tdeduc,2),0,1,'R');

			$pdf->Cell(120,0,'',1,0,'C');
			$pdf->Cell(20);
			$pdf->Cell(120,0,'',1,1,'C'); $pdf->ln(1);
			$pdf->SetDrawColor(255,255,255);

			$pdf->cell(75,5,'Total a Cobrar Nomina:',0,0,'R');
			$pdf->cell(45,5,number_format($tasig-$tdeduc,2) ,0,0,'R');
			$pdf->Cell(20);
			$pdf->cell(75,5,'Total a Cobrar Nomina:',0,0,'R');
			$pdf->cell(45,5,number_format($tasig-$tdeduc,2) ,0,1,'R');

			/*Agregado por victor*/
			if(count($extra)>0&&$prestac)
			{    $prestac=false;
				$pdf->SetDrawColor(70,77,119);
				$pdf->Cell(120,0,'',1,0,'C');
				$pdf->Cell(20);
				$pdf->Cell(120,0,'',1,1,'C'); $pdf->ln(1);

				$tasigx=($extra['tipo']=='A'?$extra['monto']:0);
				$tdeducx=($extra['tipo']=='D'?$extra['monto']:0);
				$pdf->cell(10,5,$extra['concepto'],0,0,'',1);
				$pdf->cell(50,5,$extra['detalle'],0,0,'',1);
				$pdf->cell(15,5,number_format($extra['cantidad'],2),0,0,'R',1);
				$pdf->cell(15,5,"",0,0,'R',1);
				$pdf->cell(15,5,"",0,0,'R',1);
				$pdf->cell(15,5,number_format($tasigx,2),0,0,'R',1);
				$pdf->Cell(20);
				$pdf->cell(10,5,$extra['concepto'],0,0,'',1);
				$pdf->cell(50,5,$extra['detalle'],0,0,'',1);
				$pdf->cell(15,5,number_format($extra['cantidad'],2),0,0,'R',1);
				$pdf->cell(15,5,"",0,0,'R',1);
				$pdf->cell(15,5,"",0,0,'R',1);
				$pdf->cell(15,5,number_format($tasigx,2),0,1,'R',1);

				$pdf->Cell(120,0,'',1,0,'C');
				$pdf->Cell(20);
				$pdf->Cell(120,0,'',1,1,'C'); $pdf->ln(1);
				$pdf->SetDrawColor(255,255,255);

				$pdf->cell(75,5,'Depósito Fideicomiso '.$extra['detalle'].':',0,0,'R');
				$pdf->cell(45,5,number_format($tasigx,2) ,0,0,'R');
				$pdf->Cell(20);
				$pdf->cell(75,5,'Depósito Fideicomiso '.$extra['detalle'].':',0,0,'R');
				$pdf->cell(45,5,number_format($tasigx,2) ,0,1,'R');
			}

			$pdf->ln(8);
			$pdf->cell(120,5,'-----------------------------------------------',0,0,'R');
			$pdf->Cell(20);
			$pdf->cell(120,5,'-----------------------------------------------',0,1,'R');
			$pdf->cell(120,5,'Firma / Cedula de Recibido',0,0,'R');
			$pdf->Cell(20);
			$pdf->cell(120,5,'Firma / Cedula de Recibido',0,1,'R');

			$pdf->Cell(130,5,'Nomina: '.$_POST['nomina']." - ".'Periodo: '.$_POST['periodo'],0,0,'L');
			$pdf->Cell(10);
			$pdf->Cell(130,5,'Nomina: '.$_POST['nomina']." - ".'Periodo: '.$_POST['periodo'],0,1,'L');


			//$pdf->Cell(130,5,'Fecha de Ingreso: '.$tfechai,0,0,'L');
			//$pdf->Cell(10);
			//$pdf->Cell(130,5,'Fecha de Ingreso: '.$tfechai,0,1,'L');

			//$pdf->Cell(130,5,'Sueldo Mensual Bs.: '.number_format($sueldom,2),0,0,'L');
			//$pdf->Cell(10);
			//$pdf->Cell(130,5,'Sueldo Mensual Bs.: '.number_format($sueldom,2),0,1,'L');

	}
	$pdf->Output('Recibos_pago_nomina.pdf','D');

} // fin de reporte 4 recibos de pagos

//--------------------------------------------------------------------------------------------------------------------------------- REPORTE
//--------------------------------------------------------------------------------------------------------------------------------- DETALLES DE CONCEPTOS
if ($_POST['treporte']==5) {
	if ($_POST['salida']=='1') {
		if ($_POST['concepto']=='') {
			echo "<html><head><script language='JavaScript' src='fscript.js'></script></head>";
			echo "<body>";
			echo 'Debe elegir un (1) Concepto...';
			echo "</body></html>";
		} else {
			$query="delete from $payroll where concepto<>'".substr($_POST['concepto'],0,4)."'";
			$qempleado = mysqli_query($enlace,$query) or die ($query);
			require('fpdf.php');
			class PDF extends FPDF {
			function Header()
			{
			$this->Image($_SESSION['logo_validar'],10,10,30,30);
			$this->SetFont('arial','B',8);
		$this->Ln(2);
			if ($_POST['cierre']==0) $this->Cell(0,5,'Reporte de PRE-CIERRE',0,1,'R'); else $this->Cell(0,5,'CIERRE AUDITADO',0,1,'R');
		$this->SetFont('arial','B',10);
	    $this->Cell(0,5,$_POST['empresal'],0,1,'R');
		$this->SetFont('arial','',6);
		$this->Cell(0,5,$_POST['encabeza'],0,1,'R');
		$this->Ln(2);
		$this->SetFont('arial','',7);
	    $this->Cell(0,5,'Fecha: '.hoy(),0,1,'R');
		$this->Cell(0,5,'Hora: '.hora(),0,1,'R');

			$this->SetFont('arial','B',12);
			$this->Cell(0,0,($_POST['titulo']==''?'Detalles por Conceptos' :$_POST['titulo']),0,1,'C');$this->Ln(5);
			$this->Cell(0,0,$_POST['subtitulo']." ".$_POST['concepto'],0,1,'C');$this->Ln(5);
			$this->SetFont('arial','',7);
		$this->Cell(0,0,'Nomina: '.$_POST['empresa'],0,0,'L');
		$this->Cell(0,0,'Periodo: '.$_POST['periodo'],0,1,'R');$this->Ln(3);
			if ($_POST['gerencia']!="") {
				$this->Cell(0,0,'Gerencia: '.$_POST['gerencia'],0,1,'L');$this->Ln(5);
			}
			if ($_POST['division']!="") {
				$this->Cell(0,0,'División: '.$_POST['division'],0,1,'L');$this->Ln(5);
			}
			if ($_POST['departamento']!="") {
				$this->Cell(0,0,'Departamento: '.$_POST['departamento'],0,1,'L');$this->Ln(5);
			}
				$header=array('Cod.','Cedula','Nombres y Apellidos','Cantidad','Asignación','Deducción','Total Neto');
				$this->SetFillColor(70,77,119);
			$this->SetTextColor(255);
			$this->SetDrawColor(255,255,255);
			$this->SetLineWidth(.5);
				$this->SetFont('','');
				$this->SetFont('arial','B',8);
				$w=array(10,15,55,50,30,30);
				$w=array(10,15,55,20,30,30,30);
				for($i=0;$i<count($header);$i++)
					$this->Cell($w[$i],4,$header[$i],1,0,'C',1);
				$this->Ln();
				$this->SetFillColor(224,235,255);
				$this->SetTextColor(0);
				$this->SetFont('');
			}
			//Pie de Página ////////////////////////
			function Footer()
			{
			$this->SetY(-20);
			$this->Cell(0,0,'',1,1,'C');
			$this->SetFont('Times','I',8);
			$this->ln(2);
			$this->Cell(0,0,$_POST['pie'],0,1,'C');
			$this->Cell(0,10,'Usuario: '.$_POST['usuario'].' - Página '.$this->PageNo().'/{nb} - Derechos: '.$_POST['derecho'],0,0,'C');
			}
			}
			//Cuerpo ///////////////////////////////
			$pdf=new PDF();
			$pdf->AddPage();
			$pdf->AliasNbPages();
			$pdf->SetFont('Arial','',8);
			$pdf->SetFillColor(224,235,255);
			$pdf->SetTextColor(0);
			if ($_POST['eshistorico']!=1) $consulta=mysqli_query($enlace,"select * from personal,$payroll where personal.id='".$_SESSION['id_validar']."' and $payroll.cedula=personal.codigo order by personal.codigo ");
			else {
				if ($gerencia==1) $queryx="select * from personal,$payroll where personal.id='".$_SESSION['id_validar']."' and $payroll.cedula=personal.codigo ".$queryy." order by $payroll.cedula,$payroll.concepto, $payroll.desconcepto";
				else $queryx="select * from personal,$payroll where personal.id='".$_SESSION['id_validar']."' and $payroll.tipo<>'R' and $payroll.cedula=personal.codigo ".$queryy." order by $payroll.cedula, $payroll.concepto, $payroll.desconcepto";
				$consulta=mysqli_query($enlace,$queryx) or die ($queryx.mysqli_error($enlace));
			}

			$linea=0;
			$color=0;
			$tasig=0;
			$tdeduc=0;
			$bandera=0;
			$ttasig=0; $ttdeduc=0;
			while($row=mysqli_fetch_array($consulta)) {
				$ttasig+=($row['tipo']=='A'?$row['monto']:0);
				$ttdeduc+=($row['tipo']=='D'?$row['monto']:0);
				if ($bandera==0) {
					$bandera=1;
					$tcedula=$row['cedula'];
				}
				if ($tcedula==$row['cedula']) {
					$tasig+=($row['tipo']=='A'?$row['monto']:0);
					$tdeduc+=($row['tipo']=='D'?$row['monto']:0);
					$tnombre=trim($row['sso'])." ".trim($row['nombres']).',  '.trim($row['apellidos']);
					$tcedula=$row['cedula'];
					$cantidad=$row['cantidad'];
				}
				else {
					$linea++;
					/*$pdf->cell(10,5,$linea,0,0,'C',$color);
					$pdf->cell(20,5,$tcedula,0,0,'',$color);
					$pdf->cell(70,5,$tnombre,0,0,'',$color);
					$pdf->cell(30,5,number_format($tasig,2),0,0,'R',$color);
					$pdf->cell(30,5,number_format($tdeduc,2),0,0,'R',$color);
					$pdf->cell(30,5,number_format($tasig-$tdeduc,2),0,1,'R',$color);*/
					$pdf->cell(10,5,$linea,0,0,'C',$color);
					$pdf->cell(15,5,$tcedula,0,0,'',$color);
					$pdf->cell(55,5,$tnombre,0,0,'',$color);
					$pdf->cell(20,5,$cantidad,0,0,'R',$color);
					$pdf->cell(30,5,number_format($tasig,2),0,0,'R',$color);
					$pdf->cell(30,5,number_format($tdeduc,2),0,0,'R',$color);
					$pdf->cell(30,5,number_format($tasig-$tdeduc,2),0,1,'R',$color);
					$color=!$color;
					$tasig=($row['tipo']=='A'?$row['monto']:0);
					$tdeduc=($row['tipo']=='D'?$row['monto']:0);
					$tnombre=trim($row['sso'])." ".trim($row['nombres']).',  '.trim($row['apellidos']);
					$tcedula=$row['cedula'];
					$cantidad=$row['cantidad'];
				}
			}
			$linea++;
			$pdf->cell(10,5,$linea,0,0,'C',$color);
			$pdf->cell(15,5,$tcedula,0,0,'',$color);
			$pdf->cell(55,5,$tnombre,0,0,'',$color);
			$pdf->cell(20,5,$cantidad,0,0,'R',$color);
			$pdf->cell(30,5,number_format($tasig,2),0,0,'R',$color);
			$pdf->cell(30,5,number_format($tdeduc,2),0,0,'R',$color);
			$pdf->cell(30,5,number_format($tasig-$tdeduc,2),0,1,'R',$color);
			/*$pdf->cell(10,5,$linea,0,0,'C',$color);
			$pdf->cell(20,5,$tcedula,0,0,'',$color);
			$pdf->cell(70,5,$tnombre,0,0,'',$color);
			$pdf->cell(30,5,number_format($tasig,2),0,0,'R',$color);
			$pdf->cell(30,5,number_format($tdeduc,2),0,0,'R',$color);
			$pdf->cell(30,5,number_format($tasig-$tdeduc,2),0,1,'R',$color);*/
			$pdf->Cell(190,0,'',1,1,'C'); $pdf->ln(1);
			$pdf->cell(100,5,'Totales',0,0,'R');
			$pdf->cell(30,5,number_format($ttasig,2),0,0,'R');
			$pdf->cell(30,5,number_format($ttdeduc,2),0,0,'R');
			$pdf->cell(30,5,number_format($ttasig-$ttdeduc,2),0,1,'R');
			$pdf->Cell(190,0,'',1,1,'C'); $pdf->ln(1);
			$pdf->Cell(190,0,'',1,1,'C');
			$pdf->Output('Detalle_por_Conceptos.pdf','D');
		}
	} //=========================== pdf

	if ($_POST['salida']==2) {
		if ($_POST['concepto']=='') {
			echo "<html><head><script language='JavaScript' src='fscript.js'></script></head>";
			echo "<body>";
			echo 'Debe elegir un (1) Concepto...';
			echo "</body></html>";
		} else {
		  $query="delete from $payroll where concepto<>'".substr($_POST['concepto'],0,4)."'";
		  $qempleado = mysqli_query($enlace,$query) or die ($query);
		}
		echo "<center>";
		echo "<font face='verdana' color='black' size='5'>";
		echo "<br>".$_POST['empresal'];

		echo "<font face='verdana' color='black' size='3'>";
		echo "<br>".$_POST['encabeza'];
		if ($_POST['cierre']==0) echo '<br>Reporte de PRE-CIERRE';
		else echo '<br>CIERRE AUDITADO';

		echo "<font face='verdana' color='black' size='3'>";
		echo "<br>".$_POST['periodo'];

		echo "<font face='verdana' color='black' size='4'>";
		echo "<br><br>".($_POST['titulo']==''?'Detalles por Conceptos':$_POST['titulo']);
		echo "<br>".($_POST['subtitulo']." ".$_POST['concepto']);
		echo "</center></font>";

		echo "<table  cellpadding=2 cellspacing=0 align='center'>";
		echo "<tr BGcolor='#464D77' style='color:#fff;' >";
			echo "<th ali=center><font face='verdana' size=2>C&oacute;digo</font></th> ";
			echo "<th ali=center><font face='verdana' size=2>C&eacute;dula</font></th>";
			echo "<th ali=center><font face='verdana' size=2>Nombres y Apellidos</font></th>";
			echo "<th ali=center><font face='verdana' size=2>Cantidad</font></th>";
			echo "<th ali=center><font face='verdana' size=2>Asignaci&oacute;n</font></th>";
			echo "<th ali=center><font face='verdana' size=2>Deducci&oacute;n</font></th>";
			echo "<th ali=center><font face='verdana' size=2>Total Neto</font></th>";
		echo "</tr>";

		if ($_POST['eshistorico']!=1) $consulta=mysqli_query($enlace,"select * from personal,$payroll where personal.id='".$_SESSION['id_validar']."' and $payroll.cedula=personal.codigo order by personal.codigo ");
		else {
			if ($gerencia==1) $queryx="select * from personal,$payroll where personal.id='".$_SESSION['id_validar']."' and $payroll.cedula=personal.codigo ".$queryy." order by $payroll.cedula,$payroll.concepto, $payroll.desconcepto";
			else $queryx="select * from personal,$payroll where personal.id='".$_SESSION['id_validar']."' and $payroll.tipo<>'R' and $payroll.cedula=personal.codigo ".$queryy." order by $payroll.cedula, $payroll.concepto, $payroll.desconcepto";
			$consulta=mysqli_query($enlace,$queryx) or die ($queryx.mysqli_error($enlace));
		}

		$linea=0;
		$color=0;
		$tasig=0;
		$tdeduc=0;
		$bandera=0;
		$ttasig=0; $ttdeduc=0;


		while($row=mysqli_fetch_array($consulta)) {
			$ttasig+=($row['tipo']=='A'?$row['monto']:0);
			$ttdeduc+=($row['tipo']=='D'?$row['monto']:0);
			if ($bandera==0) {
				$bandera=1;
				$tcedula=$row['cedula'];
			}
			if ($tcedula==$row['cedula']) {
				$tasig+=($row['tipo']=='A'?$row['monto']:0);
				$tdeduc+=($row['tipo']=='D'?$row['monto']:0);
				//$tnombre='Rif: '.trim($row['sso'])." ".trim($row['nombres']).',  '.trim($row['apellidos']);
				$tnombre=trim($row['nombres']).',  '.trim($row['apellidos']);
				$tcedula=$row['cedula'];
				$cantidad=$row['cantidad'];
			}
			else {
				$linea++;
				if ($color) echo '<tr bgcolor="#E6E6E6" >';
				else echo '<tr bgcolor="#EEEFF3">';
				$color=!$color;

				echo "<td width='10'><font face='verdana' color='black' size='3'>".$linea."</font></td>";
				echo "<td width='100'><font face='verdana' color='black' size='3'>".$tcedula."</font></td>";
				echo "<td width='300'><font face='verdana' color='black' size='3'>".$tnombre."</font></td>";
				echo "<td width='120' align='right'><font face='verdana' color='black' size='3'>".$cantidad."</font></td>";
				echo "<td width='120' align='right'><font face='verdana' color='#36C1E2' size='3'>".number_format($tasig,2)."</font></td>";
				echo "<td width='120' align='right'><font face='verdana' color='#DD0044' size='3'>".number_format($tdeduc,2)."</font></td>";
				echo "<td width='120' align='right'><font face='verdana' color='#DD0044' size='3'>".number_format($tasig-$tdeduc,2)."</font></td>";
				echo "</tr>";
				$tasig=($row['tipo']=='A'?$row['monto']:0);
				$tdeduc=($row['tipo']=='D'?$row['monto']:0);
				$tnombre='Rif: '.trim($row['sso'])." ".trim($row['nombres']).',  '.trim($row['apellidos']);
				$tnombre=trim($row['nombres']).',  '.trim($row['apellidos']);
				$tcedula=$row['cedula'];
				$cantidad=$row['cantidad'];
			}
		}

		$linea++;
		if ($color) echo '<tr bgcolor="#E6E6E6" >';
		else echo '<tr bgcolor="#EEEFF3">';
		$color=!$color;

		echo "<td width='10'><font face='verdana' color='black' size='3'>".$linea."</font></td>";
		echo "<td width='10'><font face='verdana' color='black' size='3'>".$tcedula."</font></td>";
		echo "<td width='300'><font face='verdana' color='black' size='3'>".$tnombre."</font></td>";
		echo "<td width='120' align='right'><font face='verdana' color='black' size='3'>".$cantidad."</font></td>";
		echo "<td width='120' align='right'><font face='verdana' color='#36C1E2' size='3'>".number_format($tasig,2)."</font></td>";
		echo "<td width='120' align='right'><font face='verdana' color='#DD0044' size='3'>".number_format($tdeduc,2)."</font></td>";
		echo "<td width='120' align='right'><font face='verdana' color='#DD0044' size='3'>".number_format($tasig-$tdeduc,2)."</font></td>";
		echo "</tr>";

		echo "<tr BGcolor='#464D77' style='color:#fff;' >";
		echo "<th ali=center colspan=4><font face='verdana' size=3>Totales Bs.</font></th> ";
		echo "<td width='120' align='right'><font face='verdana' size='3'><b>".number_format($ttasig,2)."</font></b></td>";
		echo "<td width='120' align='right'><font face='verdana'  size='3'>".number_format($ttdeduc,2)."</font></td>";
		echo "<td width='120' align='right'><font face='verdana'  size='3'>".number_format($ttasig-$ttdeduc,2)."</font></td>";
		echo "</tr>";
	} //================= salida TEXTO


} // fin de REPORTE de conceptos

//--------------------------------------------------------------------------------------------------------------------------------- REPORTE
//--------------------------------------------------------------------------------------------------------------------------------- DEDUCCIONES AUTOMATICAS
if ($_POST['treporte']==6) {

	if ($_POST['salida']==1) {
		$query="delete from $payroll where concepto<>'2200' and concepto<>'ASIG'";
		$qempleado = mysqli_query($enlace,$query) or die ($query);
		require('fpdf.php');
		class PDF extends FPDF {
		function Header()
		{
	    $this->Image($_SESSION['logo_validar'],10,10,30,30);
	    $this->SetFont('arial','B',8);
		$this->Ln(2);
		if ($_POST['cierre']==0) $this->Cell(0,5,'Reporte de PRE-CIERRE',0,1,'R'); else $this->Cell(0,5,'CIERRE AUDITADO',0,1,'R');
		$this->SetFont('arial','B',10);
	    $this->Cell(0,5,$_POST['empresal'],0,1,'R');
		$this->SetFont('arial','',6);
		$this->Cell(0,5,$_POST['encabeza'],0,1,'R');
		$this->Ln(2);
		$this->SetFont('arial','',7);
	    $this->Cell(0,5,'Fecha: '.hoy(),0,1,'R');
		$this->Cell(0,5,'Hora: '.hora(),0,1,'R');

		$this->SetFont('arial','B',12);
		$this->Cell(0,0,($_POST['titulo']==''?'Deducciones Automáticas (Prestamos Personales)':$_POST['titulo']),0,1,'C');$this->Ln(5);
		$this->Cell(0,0,$_POST['subtitulo'],0,1,'C');$this->Ln(5);
		$this->SetFont('arial','',7);
		$this->Cell(0,0,'Nomina: '.$_POST['empresa'],0,0,'L');
		$this->Cell(0,0,'Periodo: '.$_POST['periodo'],0,1,'R');$this->Ln(3);
		if ($_POST['gerencia']!="") {
			$this->Cell(0,0,'Gerencia: '.$_POST['gerencia'],0,1,'L');$this->Ln(5);
		}
		if ($_POST['division']!="") {
			$this->Cell(0,0,'División: '.$_POST['division'],0,1,'L');$this->Ln(5);
		}
		if ($_POST['departamento']!="") {
			$this->Cell(0,0,'Departamento: '.$_POST['departamento'],0,1,'L');$this->Ln(5);
		}
	    //$header=array('Cod.','Cedula','Nombres y Apellidos','Detalle','Asignaciones','Deducciones');
		$header=array('Cod.','Cedula','Rif','Nombres y Apellidos','Detalle','Deducciones');
	    $this->SetFillColor(70,77,119);
			$this->SetTextColor(255);
			$this->SetDrawColor(255,255,255);
			$this->SetLineWidth(.5);
	    $this->SetFont('','');
		$this->SetFont('arial','B',8);
		//$w=array(10,15,60,45,30,30);
	    $w=array(10,15,20,45,70,30);
		for($i=0;$i<count($header);$i++)
		        $this->Cell($w[$i],4,$header[$i],1,0,'C',1);
	    $this->Ln();
	    $this->SetFillColor(224,235,255);
	    $this->SetTextColor(0);
	    $this->SetFont('');
		}
		//Pie de Página ////////////////////////
		function Footer()
		{
		$this->SetY(-20);
		$this->Cell(0,0,'',1,1,'C');
		$this->SetFont('Times','I',8);
		$this->ln(2);
		$this->Cell(0,0,$_POST['pie'],0,1,'C');
		$this->Cell(0,10,'Usuario: '.$_POST['usuario'].' - Página '.$this->PageNo().'/{nb} - Derechos: '.$_POST['derecho'],0,0,'C');
		}
		}
		//Cuerpo ///////////////////////////////
		$pdf=new PDF();
		$pdf->AddPage();
		$pdf->AliasNbPages();
		$pdf->SetFont('Arial','',8);
		$pdf->SetFillColor(224,235,255);
		$pdf->SetTextColor(0);
		if ($_POST['eshistorico']!=1) $consulta=mysqli_query($enlace,"select * from personal,$payroll where personal.id='".$_SESSION['id_validar']."' and $payroll.cedula=personal.codigo order by $payroll.desconcepto,personal.codigo ");
		else {
			if ($gerencia==1) $queryx="select * from personal,$payroll where personal.id='".$_SESSION['id_validar']."' and $payroll.cedula=personal.codigo ".$queryy." order by $payroll.cedula,$payroll.concepto, $payroll.desconcepto";
			else $queryx="select * from personal,$payroll where personal.id='".$_SESSION['id_validar']."' and $payroll.tipo<>'R' and $payroll.cedula=personal.codigo ".$queryy." order by $payroll.cedula, $payroll.concepto, $payroll.desconcepto";
			$consulta=mysqli_query($enlace,$queryx) or die ($queryx.mysqli_error($enlace));
		}
		$linea=0;
		$color=0;
		$tasig=0;
		$tdeduc=0;
		$bandera=0;
		$tsdetalle1=0;
		$tsdetalle2=0;
		$ttasig=0; $ttdeduc=0;
		while($row=mysqli_fetch_array($consulta)) {
			$ttasig+=($row['tipo']=='A'?$row['monto']:0);
			$ttdeduc+=($row['tipo']=='D'?$row['monto']:0);
			$tasig=($row['tipo']=='A'?$row['monto']:0);
			$tdeduc=($row['tipo']=='D'?$row['monto']:0);
			$trif=trim($row['sso']);
			$tnombre=trim($row['nombres']).',  '.trim($row['apellidos']);
			//$tnombre=trim($row['sso'])." ".trim($row['nombres']).',  '.trim($row['apellidos']);
			$tcedula=$row['cedula'];
			$tdetalle=$row['desconcepto'];
			//$tsdetalle1=$tsdetalle1+($row['tipo']=='A'?$row['monto']:0);
			$tsdetalle2=$tsdetalle2+($row['tipo']=='D'?$row['monto']:0);

			if ($linea==0) {
				$detalle=substr($row['desconcepto'],0,6);
			}
			if ($detalle!=substr($row['desconcepto'],0,6)) {
				$pdf->cell(160,5,"Sub-Total...",0,0,'R',$color);
				//$pdf->cell(30,5,number_format($tsdetalle1,2),0,0,'R',$color);
				$pdf->cell(30,5,number_format($tsdetalle2,2),0,1,'R',$color);
				$pdf->ln(3);
				$tsdetalle1=0;
				$tsdetalle2=0;
				$detalle=substr($row['desconcepto'],0,6);
			}

			$linea++;
			$pdf->cell(10,5,$linea,0,0,'C',$color);
			$pdf->cell(15,5,$tcedula,0,0,'',$color);
			$pdf->cell(20,5,$trif,0,0,'',$color);
			$pdf->cell(45,5,substr($tnombre,0,30),0,0,'',$color);
			$pdf->cell(70,5,$tdetalle,0,0,'',$color);
			//$pdf->cell(30,5,number_format($tasig,2),0,0,'R',$color);
			$pdf->cell(30,5,number_format($tdeduc,2),0,1,'R',$color);
		}
		$pdf->Cell(190,0,'',1,1,'C'); $pdf->ln(1);
		$pdf->cell(160,5,'Totales',0,0,'R');
		//$pdf->cell(60,5,number_format($ttasig,2),0,0,'R');
		$pdf->cell(30,5,number_format($ttdeduc,2),0,1,'R');
		$pdf->Cell(190,0,'',1,1,'C'); $pdf->ln(1);
		$pdf->Cell(190,0,'',1,1,'C');
		$pdf->Output('Deducciones_Automaticas_Prestamos.pdf','D');
	} //================================= pdf

	if ($_POST['salida']==2) {
		echo "<center>";
		echo "<font face='verdana' color='black' size='5'>";
		echo "<br>".$_POST['empresal'];

		echo "<font face='verdana' color='black' size='3'>";
		echo "<br>".$_POST['encabeza'];
		if ($_POST['cierre']==0) echo '<br>Reporte de PRE-CIERRE';
		else echo '<br>CIERRE AUDITADO';

		echo "<font face='verdana' color='black' size='3'>";
		echo "<br>".$_POST['periodo'];

		echo "<font face='verdana' color='black' size='4'>";
		echo "<br><br>".($_POST['titulo']==''?'Deducciones Automaticas (Prestamos Personales)':$_POST['titulo']);
		echo "</center></font>";

		echo "<table  cellpadding=2 cellspacing=0 align='center'>";
		echo "<tr BGcolor='#464D77' style='color:#fff;' >";
			echo "<th ali=center><font face='verdana' size=2>C&oacute;digo</font></th> ";
			echo "<th ali=center><font face='verdana' size=2>C&eacute;dula</font></th>";
			echo "<th ali=center><font face='verdana' size=2>RIF</font></th>";
			echo "<th ali=center><font face='verdana' size=2>Nombres y Apellidos</font></th>";
			echo "<th ali=center><font face='verdana' size=2>Detalles</font></th>";
			//echo "<th ali=center><font face='verdana' size=2>Asignaci&oacute;n</font></th>";
			echo "<th ali=center><font face='verdana' size=2>Deducci&oacute;n</font></th>";
		echo "</tr>";

		$query="delete from $payroll where concepto<>'2200' and concepto<>'ASIG'";
		$qempleado = mysqli_query($enlace,$query) or die ($query);
		if ($_POST['eshistorico']!=1) $consulta=mysqli_query($enlace,"select * from personal,$payroll where personal.id='".$_SESSION['id_validar']."' and $payroll.cedula=personal.codigo order by $payroll.desconcepto,personal.codigo ");
		else {
			if ($gerencia==1) $queryx="select * from personal,$payroll where personal.id='".$_SESSION['id_validar']."' and $payroll.cedula=personal.codigo ".$queryy." order by $payroll.cedula,$payroll.concepto, $payroll.desconcepto";
			else $queryx="select * from personal,$payroll where personal.id='".$_SESSION['id_validar']."' and $payroll.tipo<>'R' and $payroll.cedula=personal.codigo ".$queryy." order by $payroll.cedula, $payroll.concepto, $payroll.desconcepto";
			$consulta=mysqli_query($enlace,$queryx) or die ($queryx.mysqli_error($enlace));
		}
		$linea=0;
		$color=0;
		$tasig=0;
		$tdeduc=0;
		$bandera=0;
		$tsdetalle1=0;
		$tsdetalle2=0;
		$ttasig=0; $ttdeduc=0;
		while($row=mysqli_fetch_array($consulta)) {
			$ttasig+=($row['tipo']=='A'?$row['monto']:0);
			$ttdeduc+=($row['tipo']=='D'?$row['monto']:0);
			$tasig=($row['tipo']=='A'?$row['monto']:0);
			$tdeduc=($row['tipo']=='D'?$row['monto']:0);
			$trif=trim($row['sso']);
			$tnombre=trim($row['nombres']).',  '.trim($row['apellidos']);
			$tcedula=$row['cedula'];
			$tdetalle=$row['desconcepto'];
			$tsdetalle1=$tsdetalle1+($row['tipo']=='A'?$row['monto']:0);
			$tsdetalle2=$tsdetalle2+($row['tipo']=='D'?$row['monto']:0);

			if ($linea==0) {
					$detalle=substr($row['desconcepto'],0,6);
			}
			if ($detalle!=substr($row['desconcepto'],0,6)) {
					echo "<tr BGcolor='#464D77' style='color:#fff;' >";
					echo "<th align='right' colspan=4><font face='verdana' size=3>Sub-Totales Bs.</font></th> ";
					//echo "<td width='120' align='right'><font face='verdana' color='#36C1E2' size='3'><b>".number_format($tsdetalle1,2)."</font></b></td>";
					echo "<td width='120' align='right'></td>";
					echo "<td width='120' align='right'><font face='verdana' color='#DD0044' size='3'><b>".number_format($tsdetalle2,2)."</b></font></td>";
					echo "</tr>";
					$tsdetalle1=0;
					$tsdetalle2=0;
					$detalle=substr($row['desconcepto'],0,6);
			}

			$linea++;
			if ($color) echo '<tr bgcolor="#E6E6E6" >';
			else echo '<tr bgcolor="#EEEFF3">';
			$color=!$color;

			echo "<td width='10'><font face='verdana' color='black' size='3'>".$linea."</font></td>";
			echo "<td width='70'><font face='verdana' color='black' size='2'>".$tcedula."</font></td>";
			echo "<td width='70'><font face='verdana' color='black' size='2'>".$trif."</font></td>";
			echo "<td width='260'><font face='verdana' color='black' size='2'>".$tnombre."</font></td>";
			echo "<td width='350'><font face='verdana' color='black' size='2'>".$tdetalle."</font></td>";
			//echo "<td width='120' align='right'><font face='verdana' color='#36C1E2' size='3'>".number_format($tasig,2)."</font></td>";
			echo "<td width='120' align='right'><font face='verdana' color='#DD0044' size='2'>".number_format($tdeduc,2)."</font></td>";
			echo "</tr>";

		}

		echo "<tr BGcolor='#464D77' style='color:#fff;' >";
		echo "<th align='right' colspan=4><font face='verdana' size=3>Totales Bs.</font></th> ";
		//echo "<td width='120' align='right'><font face='verdana' size='3'><b>".number_format($ttasig,2)."</font></b></td>";
		echo "<td width='120' align='right'></td>";
		echo "<td width='120' align='right'><font face='verdana'  size='3'><b>".number_format($ttdeduc,2)."</b></font></td>";
		echo "</tr>";

	} //================= salida TEXTO

} // fin de REPORTE de deducciones automaticas

//--------------------------------------------------------------------------------------------------------------------------------- REPORTE
//--------------------------------------------------------------------------------------------------------------------------------- RESUMEN DE PAGOS BANCARIOS
if ($_POST['treporte']==7) {
	if ($_POST['salida']==1) {
		require('fpdf.php');
		class PDF extends FPDF {
		function Header()
		{
	    $this->Image($_SESSION['logo_validar'],10,10,30,30);
	    $this->SetFont('arial','B',8);
		$this->Ln(2);
		if ($_POST['cierre']==0) $this->Cell(0,5,'Reporte de PRE-CIERRE',0,1,'R'); else $this->Cell(0,5,'CIERRE AUDITADO',0,1,'R');
		$this->SetFont('arial','B',10);
	    $this->Cell(0,5,$_POST['empresal'],0,1,'R');
		$this->SetFont('arial','',6);
		$this->Cell(0,5,$_POST['encabeza'],0,1,'R');
		$this->Ln(2);
		$this->SetFont('arial','',7);
	    $this->Cell(0,5,'Fecha: '.hoy(),0,1,'R');
		$this->Cell(0,5,'Hora: '.hora(),0,1,'R');
		$this->SetFont('arial','B',12);
		$this->Cell(0,0,($_POST['titulo']==''?'Resumen de Pagos Bancarios':$_POST['titulo']),0,1,'C');$this->Ln(5);
		$this->Cell(0,0,$_POST['subtitulo'],0,1,'C');$this->Ln(5);
		$this->SetFont('arial','',7);
		$this->Cell(0,0,'Nomina: '.$_POST['empresa'],0,0,'L');
		$this->Cell(0,0,'Periodo: '.$_POST['periodo'],0,1,'R');$this->Ln(3);
		if ($_POST['gerencia']!="") {
			$this->Cell(0,0,'Gerencia: '.$_POST['gerencia'],0,1,'L');$this->Ln(5);
		}
		if ($_POST['division']!="") {
			$this->Cell(0,0,'División: '.$_POST['division'],0,1,'L');$this->Ln(5);
		}
		if ($_POST['departamento']!="") {
			$this->Cell(0,0,'Departamento: '.$_POST['departamento'],0,1,'L');$this->Ln(5);
		}
		    $header=array('Cod.','Cedula','Nombres y Apellidos','Cuenta Bancaria','Total Neto','Firma');
		    $this->SetFillColor(70,77,119);
			$this->SetTextColor(255);
			$this->SetDrawColor(255,255,255);
			$this->SetLineWidth(.5);
		    $this->SetFont('','');
			$this->SetFont('arial','B',8);
		    $w=array(10,20,60,40,30,30);
			for($i=0;$i<count($header);$i++)
		        $this->Cell($w[$i],4,$header[$i],1,0,'C',1);
		    $this->Ln();
		    $this->SetFillColor(224,235,255);
		    $this->SetTextColor(0);
		    $this->SetFont('');
		}
		//Pie de Página ////////////////////////
		function Footer()
		{
		$this->SetY(-20);
		$this->Cell(0,0,'',1,1,'C');
		$this->SetFont('Times','I',8);
		$this->ln(2);
		$this->Cell(0,0,$_POST['pie'],0,1,'C');
		$this->Cell(0,10,'Usuario: '.$_POST['usuario'].' - Página '.$this->PageNo().'/{nb} - Derechos: '.$_POST['derecho'],0,0,'C');
		}
		}
		//Cuerpo ///////////////////////////////
		$pdf=new PDF();
		$pdf->AddPage();
		$pdf->AliasNbPages();
		$pdf->SetFont('Arial','',8);
		$pdf->SetFillColor(224,235,255);
		$pdf->SetTextColor(0);
		if ($_POST['eshistorico']!=1) $consulta=mysqli_query($enlace,"select * from personal,$payroll where personal.id='".$_SESSION['id_validar']."' and $payroll.cedula=personal.codigo order by personal.codigo"  );
		else {
			if ($gerencia==1) $queryx="select * from personal,$payroll where personal.id='".$_SESSION['id_validar']."' and $payroll.cedula=personal.codigo ".$queryy." order by $payroll.cedula,$payroll.concepto, $payroll.desconcepto";
			else $queryx="select * from personal,$payroll where personal.id='".$_SESSION['id_validar']."' and $payroll.tipo<>'R' and $payroll.cedula=personal.codigo ".$queryy." order by $payroll.cedula, $payroll.concepto, $payroll.desconcepto";
			$consulta=mysqli_query($enlace,$queryx) or die ($queryx.mysqli_error($enlace));
		}
		$linea=0;
		$color=0;
		$tasig=0;
		$tdeduc=0;
		$bandera=0;
		$ttasig=0; $ttdeduc=0;
		while($row=mysqli_fetch_array($consulta)) {
			$ttasig+=($row['tipo']=='A'?$row['monto']:0);
			$ttdeduc+=($row['tipo']=='D'?$row['monto']:0);
			if ($bandera==0) {
				$bandera=1;
				$tcedula=$row['cedula'];
			}
			if ($tcedula==$row['cedula']) {
				$tasig+=($row['tipo']=='A'?$row['monto']:0);
				$tdeduc+=($row['tipo']=='D'?$row['monto']:0);
				$tnombre=trim($row['sso'])." ".trim($row['nombres']).',  '.trim($row['apellidos']);
				$tcedula=$row['cedula'];
				$tcuenta=$row['cuenta'];
				$tbanco=$row['banco'];
			}
			else {
				$linea++;
				$pdf->cell(10,7,$linea,0,0,'C',$color);
				$pdf->cell(20,7,$tcedula,0,0,'',$color);
				$pdf->cell(60,7,$tnombre,0,0,'',$color);
				$pdf->cell(40,7,$tcuenta,0,0,'',$color);
				$pdf->cell(30,7,number_format($tasig-$tdeduc,2),0,0,'R',$color);
				$pdf->cell(30,7,'',1,1,'',$color);
				$color=!$color;
				$tasig=($row['tipo']=='A'?$row['monto']:0);
				$tdeduc=($row['tipo']=='D'?$row['monto']:0);
				$tnombre=trim($row['nombres']).',  '.trim($row['apellidos']);
				$tcedula=$row['cedula'];
				$tcuenta=$row['cuenta'];
				$tbanco=$row['banco'];
			}
		}

		$linea++;
		$pdf->cell(10,7,$linea,0,0,'C',$color);
		$pdf->cell(20,7,$tcedula,0,0,'',$color);
		$pdf->cell(60,7,$tnombre,0,0,'',$color);
		$pdf->cell(40,7,$tcuenta,0,0,'',$color);
		$pdf->cell(30,7,number_format($tasig-$tdeduc,2),0,0,'R',$color);
		$pdf->cell(30,7,'',1,1,'',$color);
		$pdf->Cell(190,0,'',1,1,'C'); $pdf->ln(1);

		$pdf->cell(130,7,'Totales',0,0,'R');
		$pdf->cell(30,7,number_format($ttasig-$ttdeduc,2),0,0,'R');
		$pdf->cell(30,7,'',0,1,'');

		$pdf->Cell(190,0,'',1,1,'C'); $pdf->ln(1);
		$pdf->Cell(190,0,'',1,1,'C');
		$pdf->Output('Resumen_de_Pagos_Bancarios.pdf','D');
	} //======================================= pdf

	if ($_POST['salida']==2) {
		echo "<center>";
		echo "<font face='verdana' color='black' size='5'>";
		echo "<br>".$_POST['empresal'];

		echo "<font face='verdana' color='black' size='3'>";
		echo "<br>".$_POST['encabeza'];
		if ($_POST['cierre']==0) echo '<br>Reporte de PRE-CIERRE';
		else echo '<br>CIERRE AUDITADO';

		echo "<font face='verdana' color='black' size='3'>";
		echo "<br>".$_POST['periodo'];

		echo "<font face='verdana' color='black' size='4'>";
		echo "<br><br>".($_POST['titulo']==''?'Pago de Nomina General':$_POST['titulo']);
		echo "</center></font>";

		echo "<table  cellpadding=2 cellspacing=0 align='center'>";
		echo "<tr BGcolor='#464D77' style='color:#fff;' >";
			echo "<th ali=center><font face='verdana' size=2>C&oacute;digo</font></th> ";
			echo "<th ali=center><font face='verdana' size=2>Cedula</font></th>";
			echo "<th ali=center><font face='verdana' size=2>Nombre</font></th>";
			echo "<th ali=center><font face='verdana' size=2>Cuenta Bancaria</font></th>";
			echo "<th ali=center><font face='verdana' size=2>Saldo</font></th>";
		echo "</tr>";

		if ($_POST['eshistorico']!=1) $consulta=mysqli_query($enlace,"select * from personal,$payroll where personal.id='".$_SESSION['id_validar']."' and $payroll.cedula=personal.codigo order by personal.codigo"  );
		else {
			if ($gerencia==1) $queryx="select * from personal,$payroll where personal.id='".$_SESSION['id_validar']."' and $payroll.cedula=personal.codigo ".$queryy." order by $payroll.cedula,$payroll.concepto, $payroll.desconcepto";
			else $queryx="select * from personal,$payroll where personal.id='".$_SESSION['id_validar']."' and $payroll.tipo<>'R' and $payroll.cedula=personal.codigo ".$queryy." order by $payroll.cedula, $payroll.concepto, $payroll.desconcepto";
			$consulta=mysqli_query($enlace,$queryx) or die ($queryx.mysqli_error($enlace));
		}
		$linea=0;
		$color=0;
		$tasig=0;
		$tdeduc=0;
		$bandera=0;
		$ttasig=0; $ttdeduc=0;
		while($row=mysqli_fetch_array($consulta)) {
			$ttasig+=($row['tipo']=='A'?$row['monto']:0);
			$ttdeduc+=($row['tipo']=='D'?$row['monto']:0);
			if ($bandera==0) {
				$bandera=1;
				$tcedula=$row['cedula'];
			}
			if ($tcedula==$row['cedula']) {
				$tasig+=($row['tipo']=='A'?$row['monto']:0);
				$tdeduc+=($row['tipo']=='D'?$row['monto']:0);
				//$tnombre=trim($row['sso'])." ".trim($row['nombres']).',  '.trim($row['apellidos']);
				$tnombre=trim($row['nombres']).',  '.trim($row['apellidos']);
				$tcedula=$row['cedula'];
				$tcuenta=$row['cuenta'];
				$tbanco=$row['banco'];
			}
			else {
				$linea++;
				if ($color) echo '<tr bgcolor="#E6E6E6" >';
				else echo '<tr bgcolor="#EEEFF3">';
				$color=!$color;

				echo "<td width='10'><font face='verdana' color='black' size='3'>".$linea."</font></td>";
				echo "<td width='100'><font face='verdana' color='black' size='3'>".$tcedula."</font></td>";
				echo "<td width='300'><font face='verdana' color='black' size='3'>".$tnombre."</font></td>";
				echo "<td width='300'><font face='verdana' color='black' size='3'>".$tcuenta."</font></td>";
				echo "<td width='120' align='right'><font face='verdana' color='#DD0044' size='3'>".number_format($tasig-$tdeduc,2)."</font></td>";
				echo "</tr>";

				$color=!$color;
				$tasig=($row['tipo']=='A'?$row['monto']:0);
				$tdeduc=($row['tipo']=='D'?$row['monto']:0);
				$tnombre=trim($row['nombres']).',  '.trim($row['apellidos']);
				$tcedula=$row['cedula'];
				$tcuenta=$row['cuenta'];
				$tbanco=$row['banco'];
			}
		}
		$linea++;
		if ($color) echo '<tr bgcolor="#E6E6E6" >';
		else echo '<tr bgcolor="#EEEFF3">';
		$color=!$color;

		echo "<td width='10'><font face='verdana' color='black' size='3'>".$linea."</font></td>";
		echo "<td width='10'><font face='verdana' color='black' size='3'>".$tcedula."</font></td>";
		echo "<td width='300'><font face='verdana' color='black' size='3'>".$tnombre."</font></td>";
		echo "<td width='200'><font face='verdana' color='black' size='3'>".$tcuenta."</font></td>";
		echo "<td width='120' align='right'><font face='verdana' color='#DD0044' size='3'>".number_format($tasig-$tdeduc,2)."</font></td>";
		echo "</tr>";

		echo "<tr BGcolor='#464D77' style='color:#fff;' >";
		echo "<th ali=center colspan=4><font face='verdana' size=3>Totales Bs.</font></th> ";
		echo "<td width='120' align='right'><font face='verdana'  size='3'>".number_format($ttasig-$ttdeduc,2)."</font></td>";
		echo "</tr></table>";
	} //================= salida TEXTO

} // fin de REPORTE CARTA BANCARIA

//--------------------------------------------------------------------------------------------------------------------------------- REPORTE
//--------------------------------------------------------------------------------------------------------------------------------- SABANA EXCEL
if ($_POST['treporte']==8) {

	//================================== creao tabla sabana
	$sabana="zs_".trim($_SESSION['usuario_validar']);
	$borroTabla="DROP TABLE IF EXISTS `".$sabana."` ";
	$linea="create table if not exists `".$sabana."` (
			  `cedula` varchar(8) NOT NULL,
			  `rif` varchar(20) NOT NULL,
			  `nombre` varchar(50) NOT NULL,
			  `dpto` varchar(50) NOT NULL,
			  `cargo` varchar(50) NOT NULL,
			  ";
    $bandera=1;
	$consulta=mysqli_query($enlace,"select codigo,tipo from concepto where (tipo='A' or tipo='D') and id='".$_SESSION['id_validar']."'  order by tipo,codigo");
	while($row=mysqli_fetch_array($consulta)) {
		if ($row['tipo']=='A') $linea .= "`".($row['tipo'].$row['codigo'])."` decimal(18,2) not null default 0, ";
		else {
			if ($bandera==1) {
				$bandera=0;
				$linea .= "`pasig` decimal(18,2) not null default 0, ";
				$linea .= "`tasig` decimal(18,2) not null default 0, ";
			}
			$linea .= "`".($row['tipo'].$row['codigo'])."` decimal(18,2) not null default 0, ";
		}
	}
	$linea .= "`pdedu` decimal(18,2) not null default 0, ";
	$linea .= "`tdedu` decimal(18,2) not null default 0, ";
	$linea .= "`monto` decimal(18,2) not null default 0) ENGINE=MyISAM DEFAULT CHARSET=latin1; ";

	$consulta=mysqli_query($enlace,$linea);
	$consulta=mysqli_query($enlace,"delete from `".$sabana."`");

	//================================== cargo datos de payroll a sabana

	if ($_POST['eshistorico']!=1){
		$consulta=mysqli_query($enlace,"select * from personal,$payroll where personal.id='".$_SESSION['id_validar']."' and $payroll.cedula=personal.codigo order by personal.codigo, $payroll.concepto, $payroll.desconcepto  "  );

	}
	else {
		if ($gerencia==1) $queryx="select * from personal,$payroll where personal.id='".$_SESSION['id_validar']."' and $payroll.cedula=personal.codigo ".$queryy." order by $payroll.cedula,$payroll.concepto, $payroll.desconcepto";
		else $queryx="select * from personal,$payroll where personal.id='".$_SESSION['id_validar']."' and $payroll.tipo<>'R' and $payroll.cedula=personal.codigo ".$queryy." order by $payroll.cedula, $payroll.concepto, $payroll.desconcepto";
		$consulta=mysqli_query($enlace,$queryx) or die ($queryx.mysqli_error($enlace));
	}
	$ttasig=0; $ttdeduc=0; $bandera=0;
	while($row=mysqli_fetch_array($consulta)) {
		$filas=mysqli_query($enlace,"select * from $sabana where cedula='".$row['cedula']."'" );

		if (mysqli_num_rows($filas)==0){
			$codigoCargo = $row['cargo'];
			$codigoDepartamento = $row['departamento'];
			$id = $_SESSION['id_validar'];

			$queryCargo = "SELECT detalle FROM tablas WHERE codigo = '$codigoCargo' AND UPPER(tabla) = 'CARGO' AND id = '$id'";
			$resultadoCargo=mysqli_query($enlace, $queryCargo ) or die ("No se pudo consultar el cargo");
			$filaCargo = mysqli_fetch_array($resultadoCargo);
			$finalCargo = $filaCargo['detalle'];
			$queryDepartamento = "SELECT detalle FROM tablas WHERE codigo = '$codigoDepartamento' AND UPPER(tabla) = 'DEPARTAMENTO' AND id = '$id'";
			$resultadoDepartamento=mysqli_query($enlace, $queryDepartamento ) or die ("No se pudo consultar el departamento");
			$filaDepartamento = mysqli_fetch_array($resultadoDepartamento);
			$finalDepartamento = $filaDepartamento['detalle'];

			$filas=mysqli_query($enlace,"insert into $sabana (cedula,rif,nombre, dpto,cargo) values ('".$row['cedula']."','".$row['sso']."','".(trim($row['nombres']).",".$row['apellidos'])."','".$finalDepartamento."','".$finalCargo."')" );
			// $filas=mysqli_query($enlace,"insert into $sabana (cedula,rif,nombre, dpto,cargo) values ('".$row['cedula']."','".$row['sso']."','".(trim($row['nombres']).",".$row['apellidos'])."','".$row['departamento']."','".$row['cargo']."')" );
		}
		if ($row['tipo']=='A') $tem=mysqli_query($enlace,"update $sabana set A".$row['concepto']."=".$row['monto']." where cedula='".$row['cedula']."'" );
		if ($row['tipo']=='D')  $tem=mysqli_query($enlace,"update $sabana set D".$row['concepto']."=".$row['monto']." where cedula='".$row['cedula']."'" );
		if ($row['concepto']=='ASIG')$tem=mysqli_query($enlace,"update $sabana set pasig=pasig+".$row['monto']." where cedula='".$row['cedula']."'" );
		if ($row['concepto']=='2200')$tem=mysqli_query($enlace,"update $sabana set pdedu=pdedu+".$row['monto']." where cedula='".$row['cedula']."'" );
	}

	//================================== totalizar campos de subtotales
	$registros=mysqli_query($enlace,"select * from $sabana order by cedula");
	$cant=mysqli_num_fields($registros) or die(mysqli_error($enlace));
	$casig='';$cdedu='';
	for($f=0;$f<$cant;$f++)
	{
		$valor=mysqli_fetch_field_direct($registros,$f);
		if (strtoupper(substr($valor,0,1))=='A') $casig .= $valor."+";
		if (substr($valor,0,1)==='D') $cdedu .= $valor."+";
	}
	$casig .="pasig";
	$cdedu .="pdedu";
	while($row = mysqli_fetch_row($registros))
	{
		$ced = $row[0];
		$tasigx=0; $tdedux=0;
		$registrosx=mysqli_query($enlace,"select sum(".$casig.") as total from $sabana where cedula='".$ced."'");
		while($rowx = mysqli_fetch_row($registrosx)) {
			$tasigx=$rowx[0];
		}
		$registrosx=mysqli_query($enlace,"select sum(".$cdedu.") as total from $sabana where cedula='".$ced."'");
		while($rowx = mysqli_fetch_row($registrosx)) {
			$tdedux=$rowx[0];
		}
		$registrosx=mysqli_query($enlace,"update $sabana set tasig='".$tasigx."', tdedu='".$tdedux."', monto='".($tasigx-$tdedux)."' where cedula='".$ced."'");
	}

	//include_once ('reporteExcel.php'); // se debe verificar en toda la libreria PHPExcel para corregir los campos/columnas que trae por �ste m�todo


	//================================== crear cabecera
	$registros=mysqli_query($enlace,"select * from $sabana order by cedula");
	$cant=mysqli_num_fields($registros) or die(mysqli_error($enlace));
	$casig='';$cdedu='';
	for($f=0;$f<$cant;$f++)
	{
		$valor=mysqli_fetch_field_direct($registros,$f);
		if (strtoupper(substr($valor,0,1))=='A') $casig .= $valor."+";
		if (strtoupper(substr($valor,0,1))=='D') $cdedu .= $valor."+";
		if (strtoupper(substr($valor,0,1))=='A' || strtoupper(substr($valor,0,1))=='D') {
			$cod=trim(substr(mysqli_fetch_field_direct($registros,$f),1,50));
			$consulta=mysqli_query($enlace,"select detalle from concepto where id='".$_SESSION['id_validar']."' and codigo='".$cod."'");
			while($row=mysqli_fetch_array($consulta)) $valor = $row['detalle'];
		}
		$cabecera.=strtoupper($valor)."\t";
	}

	//================================== cargo datos a excel por columna
	while($fila = mysqli_fetch_row($registros))
	{
		  $linea = '';
		  foreach($fila as $valor)
		  {
			if ((!isset($valor)) || ($valor == "")) $valor = "\t";
			else {
			  $valor = str_replace('"', '""', $valor);
			  $valor = '"' . $valor . '"' . "\t";
			}
			$valor = str_replace(".",",",$valor);
			$valor = stripslashes($valor);
			$linea .= $valor;
		  }
		  $datos .= trim($linea)."\n";
	}

	$linea1=$_POST['empresal']."\n";
	$linea2=$_POST['encabeza']."\n\n";
	if ($_POST['cierre']==0) $linea3 = 'Reporte de PRE-CIERRE'."\n";
	$linea3 = 'CIERRE AUDITADO'."\n";
	$linea4 = "Periodo: ".$_POST['periodo']."\n\n";
	$linea5 = "Reporte General de Pago (Sabana)"."\n";
	$linea6 = "\n";

	//================================== mostrar por pantalla
	$datos = str_replace("\r","",$datos);
	if ($datos == "") $datos = "\n (0) registros encontrados!\n";
	$nomarchivo='Pago_Nomina.xls';
	header("Content-type: application/x-msdownload");
	header("Content-Disposition: attachment; filename=$nomarchivo");
	header("Pragma: no-cache");
	header("Expires: 0");
	print "$linea1$linea2$linea3$linea4$linea5$linea6$cabecera\n$datos";


} // fin de reporte 8 sabana


//--------------------------------------------------------------------------------------------------------------------------------- REPORTE
//--------------------------------------------------------------------------------------------------------------------------------- TEXTO BANCARIO
if ($_POST['treporte']==9){

	if ($_SESSION['id_validar']==104 || $_SESSION['id_validar']==106 || $_SESSION['id_validar']==107){ //////Aplica para Mersan, GSC y IGM Banco PROVINCIAL

		if ($_POST['bancopaga']==1) { //////////pago de banco provincial a trabajadores con banco provincial

			$queryx="SELECT per.tipo AS tipo_cuenta, pay.tipo AS tipo_concepto, SUM(pay.monto) as monto, pay.cedula, per.banco, pay.desperiodo, per.nombres, per.apellidos, per.cuenta, per.nacionalidad, per.mensaje FROM personal AS per, $payroll AS pay WHERE per.id = '".$_SESSION['id_validar']."' AND pay.tipo <> 'R' AND pay.cedula = per.codigo AND SUBSTR(pay.concepto, 1, 1) != 4 AND SUBSTR(pay.concepto, 1, 1) != 5 AND SUBSTR(pay.concepto, 1, 1) != 6 AND concepto NOT IN(2000,2001,2002,2003,2004,2005,2006,2007,2010,2012) AND per.banco = '0108' GROUP BY cedula,tipo_concepto ORDER BY pay.cedula, pay.concepto, pay.desconcepto";
			$consulta=mysqli_query($enlace,$queryx) or die ($queryx.mysqli_error($enlace));
			$cant_emp_pagar = mysqli_num_rows($consulta);

			$total_pagar=0;$asignaciones=0;$deducciones=0;

			while($rows_reporte=mysqli_fetch_array($consulta)){
				$array_reg[] = $rows_reporte;
			}

			$nombre_archivo = "bancos.txt";
			$file = fopen($nombre_archivo, "w+");


			for($i=0;$i<count($array_reg);$i++){
				$cedula = $array_reg[$i]['cedula'];
				$nombres = $array_reg[$i]['nombres'];
				$apellidos = $array_reg[$i]['apellidos'];
				$nacionalidad = $array_reg[$i]['nacionalidad'];
				$mensaje = $array_reg[$i]['mensaje'];
				$cuenta = $array_reg[$i]['cuenta'];
				$tipo_cuenta = $array_reg[$i]['tipo_cuenta'];
				$banco = $array_reg[$i]['banco'];
				$desperiodo = $array_reg[$i]['desperiodo'];
				$tipo_concepto = $array_reg[$i]['tipo_concepto'];
				$monto = $array_reg[$i]['monto'];

				if ($tipo_concepto == 'A'){
					$asignaciones+= $monto;
				}else if ($tipo_concepto == 'D'){
					$deducciones+= $monto;
				}

				$total_pagar = $asignaciones - $deducciones;

				if($array_reg[$i]['cedula']!=$array_reg[$i+1]['cedula']){ //Si el siguiente registro es de otra persona, entonces imprime

					if ($total_pagar != 0){
						$total_pagar = str_replace(".","",number_format($total_pagar,2,'.','')); //Formateo monto a pagar

						//Inicia a imprimir
						fwrite($file, str_pad($cuenta, 20, "0", STR_PAD_LEFT));
						fwrite($file, str_pad("", 1, " ", STR_PAD_RIGHT));
						fwrite($file, $nacionalidad);
						fwrite($file, str_pad($cedula, 10, "0", STR_PAD_LEFT));
						fwrite($file, str_pad("", 1, " ", STR_PAD_RIGHT));
				 		fwrite($file, str_pad($total_pagar, 15, "0", STR_PAD_LEFT));
						fwrite($file, str_pad("", 1, " ", STR_PAD_RIGHT));
						fwrite($file, str_pad($nombres." ".$apellidos, 35, " ", STR_PAD_RIGHT)); //Imprime nombres con espacios hasta 60 caracteres
						fwrite($file, "\r\n"); //Nueva Linea


						//echo str_pad($nombres." ".$apellidos, 35, &nbsp;, STR_PAD_RIGHT); //Imprime nombres con espacios hasta 50 caracteres
	 				  //echo "\r\n"; //Nueva linea
						//echo "<br>";
						$total_pagar = 0; $asignaciones = 0;  $deducciones =0; //Limpia variables
					}
				}
			}
			fclose($file);

			header('Content-Description: File Transfer');
	    header('Content-Disposition: attachment; filename=' . $nombre_archivo);
	    header('Expires: 0');
	    header('Cache-Control: must-revalidate');
	    header('Pragma: public');
	    header('Content-Length: ' . filesize($nombre_archivo));
			readfile($nombre_archivo);
			unlink($nombre_archivo);


		 	if (count($array_reg)==0){
				echo "<font color=#DD0044 size=3>**** Banco No posee definici&oacute;n de Archivo Texto...... LLame a CONSULTARH *****</font>";
			}
		}//////Fin de pago de banco provincial a trabajadores con banco provincial
		elseif ($_POST['bancopaga']==2) {////////////////////////pago de banco PROVINCIAL a trabajadores con OTRO BANCO
			$queryx="SELECT per.tipo AS tipo_cuenta, pay.tipo AS tipo_concepto, SUM(pay.monto) as monto, pay.cedula, per.banco, pay.desperiodo, per.nombres, per.apellidos, per.cuenta, per.nacionalidad, per.mensaje FROM personal AS per, $payroll AS pay WHERE per.id = '".$_SESSION['id_validar']."' AND pay.tipo <> 'R' AND pay.cedula = per.codigo AND SUBSTR(pay.concepto, 1, 1) != 4 AND SUBSTR(pay.concepto, 1, 1) != 5 AND SUBSTR(pay.concepto, 1, 1) != 6 AND concepto NOT IN(2000,2001,2002,2003,2004,2005,2006,2007,2010,2012) AND per.banco != '0108' AND per.banco != '' GROUP BY cedula,tipo_concepto ORDER BY pay.cedula, pay.concepto, pay.desconcepto";

			$consulta=mysqli_query($enlace,$queryx) or die ($queryx.mysqli_error($enlace));
			$cant_emp_pagar = mysqli_num_rows($consulta);

			$total_pagar=0;$asignaciones=0;$deducciones=0;

			while($rows_reporte=mysqli_fetch_array($consulta)){
				$array_reg[] = $rows_reporte;
			}

			$nombre_archivo = "bancos.txt";
			$file = fopen($nombre_archivo, "w+");


			for($i=0;$i<count($array_reg);$i++){
				$cedula = $array_reg[$i]['cedula'];
				$nombres = $array_reg[$i]['nombres'];
				$apellidos = $array_reg[$i]['apellidos'];
				$nacionalidad = $array_reg[$i]['nacionalidad'];
				$mensaje = $array_reg[$i]['mensaje'];
				$cuenta = $array_reg[$i]['cuenta'];
				$tipo_cuenta = $array_reg[$i]['tipo_cuenta'];
				$banco = $array_reg[$i]['banco'];
				$desperiodo = $array_reg[$i]['desperiodo'];
				$tipo_concepto = $array_reg[$i]['tipo_concepto'];
				$monto = $array_reg[$i]['monto'];

				if ($tipo_concepto == 'A'){
					$asignaciones+= $monto;
				}else if ($tipo_concepto == 'D'){
					$deducciones+= $monto;
				}

				$total_pagar = $asignaciones - $deducciones;

				if($array_reg[$i]['cedula']!=$array_reg[$i+1]['cedula']){ //Si el siguiente registro es de otra persona, entonces imprime

					if ($total_pagar != 0){
						$total_pagar = str_replace(".","",number_format($total_pagar,2,'.','')); //Formateo monto a pagar

						//Inicia a imprimir
						fwrite($file, str_pad($cuenta, 20, "0", STR_PAD_LEFT));
						fwrite($file, str_pad("", 1, " ", STR_PAD_RIGHT));
						fwrite($file, $nacionalidad);
						fwrite($file, str_pad($cedula, 10, "0", STR_PAD_LEFT));
						fwrite($file, str_pad("", 1, " ", STR_PAD_RIGHT));
				 		fwrite($file, str_pad($total_pagar, 15, "0", STR_PAD_LEFT));
						fwrite($file, str_pad("", 1, " ", STR_PAD_RIGHT));
						fwrite($file, str_pad($nombres." ".$apellidos, 35, " ", STR_PAD_RIGHT)); //Imprime nombres con espacios hasta 60 caracteres
						fwrite($file, "\r\n"); //Nueva Linea


						//echo str_pad($nombres." ".$apellidos, 35, &nbsp;, STR_PAD_RIGHT); //Imprime nombres con espacios hasta 50 caracteres
	 				  //echo "\r\n"; //Nueva linea
						//echo "<br>";
						$total_pagar = 0; $asignaciones = 0;  $deducciones =0; //Limpia variables
					}
				}
			}
			fclose($file);

			header('Content-Description: File Transfer');
	    header('Content-Disposition: attachment; filename=' . $nombre_archivo);
	    header('Expires: 0');
	    header('Cache-Control: must-revalidate');
	    header('Pragma: public');
	    header('Content-Length: ' . filesize($nombre_archivo));
			readfile($nombre_archivo);
			unlink($nombre_archivo);

		 	if (count($array_reg)==0){
				echo "<font color=#DD0044 size=3>**** Banco No posee definici&oacute;n de Archivo Texto...... LLame a CONSULTARH *****</font>";
			}
		}///////////Fin de pago de banco PROVINCIAL a trabajadores con OTRO BANCO
		elseif ($_POST['bancopaga']==5) {///////Inicia pago de banco BNC
			$consultaEmpresa="select nombre,encabeza from empresa where id='".$_SESSION['id_validar']."' ";
			$consultaEmpresa=mysqli_query($enlace,$consultaEmpresa) or die ($consultaEmpresa.mysqli_error($enlace));
			$rowEmpresa = mysqli_fetch_array($consultaEmpresa);
			$nombreEmpresa = $rowEmpresa['nombre'];
			$rifEmpresa   = $rowEmpresa['encabeza'];
			$rifEmpresa = preg_replace('([^A-Za-z0-9])', '', $rifEmpresa);



			////////Calculo la suma total a pagar
				$queryx="select * from personal,$payroll where personal.id='".$_SESSION['id_validar']."' and $payroll.tipo<>'R' and $payroll.cedula=personal.codigo ".$queryy." AND personal.banco = '0191' AND personal.banco <> '' AND SUBSTR(concepto, 1, 1) != 4 AND SUBSTR(concepto, 1, 1) != 5 AND SUBSTR(concepto, 1, 1) != 6 AND concepto NOT IN(2000,2001,2002,2003,2004,2005,2006,2007,2010,2012)
				GROUP BY $payroll.cedula,$payroll.concepto order by $payroll.cedula, $payroll.concepto, $payroll.desconcepto ";


				$consulta=mysqli_query($enlace,$queryx) or die ($queryx.mysqli_error($enlace));
				$cant_emp_pagar = mysqli_num_rows($consulta);
				$linea=0;	$color=0;  $tlinea=1;
				$tasig=0;	$tdeduc=0;
				$bandera=0;	$ttasig=0; $ttdeduc=0;
				$archivo='';$entrobanco=0;
				while($row=mysqli_fetch_array($consulta))
				{
					$ttasig+=($row['tipo']=='A'?$row['monto']:0);
					$ttdeduc+=($row['tipo']=='D'?$row['monto']:0);
				$tmonto = str_replace(".","",number_format(($ttasig-$ttdeduc),2,'.',''));
			
				}
				

			$queryx="SELECT per.tipo AS tipo_cuenta, pay.tipo AS tipo_concepto, SUM(pay.monto) as monto, pay.cedula, per.banco, pay.desperiodo, per.nombres, per.apellidos, per.cuenta, per.nacionalidad, per.mensaje FROM personal AS per, $payroll AS pay WHERE per.id = '".$_SESSION['id_validar']."' AND pay.tipo <> 'R' AND pay.cedula = per.codigo AND SUBSTR(pay.concepto, 1, 1) != 4 AND SUBSTR(pay.concepto, 1, 1) != 5 AND SUBSTR(pay.concepto, 1, 1) != 6 AND concepto NOT IN(2000,2001,2002,2003,2004,2005,2006,2007,2010,2012) AND per.banco = '0191' GROUP BY cedula,tipo_concepto ORDER BY pay.cedula, pay.concepto, pay.desconcepto";
			$consulta=mysqli_query($enlace,$queryx) or die ($queryx.mysqli_error($enlace));
			$cant_emp_pagar = mysqli_num_rows($consulta);

			$total_pagar=0;$asignaciones=0;$deducciones=0;

			while($rows_reporte=mysqli_fetch_array($consulta)){
			$array_reg[] = $rows_reporte;
			}
			$fecha_pago = date('d/m/y');
			$nombre_archivo = "bancos.txt";
			$file = fopen($nombre_archivo, "w+");
			fwrite($file, "ND");
			fwrite($file, " ");
				if($_SESSION['id_validar']==107) ////IGM
				{
					
				fwrite($file, "01910085562185137626");
				
				}else if ($_SESSION['id_validar']==104) ///MERSAN
				{
				fwrite($file, "01910085532185049069");	
				} else {
					fwrite($file, "NO TIENE CUENTA BNC");	
				}
			fwrite($file, str_repeat("0",13-strlen($tmonto)));
			fwrite($file, $tmonto);
			fwrite($file, $rifEmpresa);
			fwrite($file, "\r\n"); //Nueva Linea

			for($i=0;$i<count($array_reg);$i++){
				$cedula = $array_reg[$i]['cedula'];
				$nombres = $array_reg[$i]['nombres'];
				$apellidos = $array_reg[$i]['apellidos'];
				$nacionalidad = $array_reg[$i]['nacionalidad'];
				$mensaje = $array_reg[$i]['mensaje'];
				$cuenta = $array_reg[$i]['cuenta'];
				$tipo_cuenta = $array_reg[$i]['tipo_cuenta'];
				$tipo_cuenta = $tipo_cuenta-1;//este -1 es para que coincida con el tipo de cuenta del txt banco Vzla qu es cta-crrte=1 y cta-ahorr=0--Miguelangel
				$banco = $array_reg[$i]['banco'];
				$desperiodo = $array_reg[$i]['desperiodo'];
				$tipo_concepto = $array_reg[$i]['tipo_concepto'];
				$monto = $array_reg[$i]['monto'];

				if ($tipo_concepto == 'A'){
					$asignaciones+= $monto;
				}else if ($tipo_concepto == 'D'){
					$deducciones+= $monto;
				}

				$total_pagar = $asignaciones - $deducciones;

				if($array_reg[$i]['cedula']!=$array_reg[$i+1]['cedula']){ //Si el siguiente registro es de otra persona, entonces imprime

					//
					if ($total_pagar != 0){
						$total_pagar = str_replace(".","",number_format($total_pagar,2,'.','')); //Formateo monto a pagar pa

						//Inicia a imprimir

						fwrite($file, "NC");
						fwrite($file, " ");
						fwrite($file, str_pad($cuenta, 20, "0", STR_PAD_LEFT));
						fwrite($file, str_pad($total_pagar, 13, "0", STR_PAD_LEFT));
						fwrite($file, $nacionalidad);
						fwrite($file, str_pad($cedula, 9, "0", STR_PAD_LEFT));
						
						fwrite($file, "\r\n"); //Nueva Linea


						//echo str_pad($nombres." ".$apellidos, 35, &nbsp;, STR_PAD_RIGHT); //Imprime nombres con espacios hasta 50 caracteres
	 				  //echo "\r\n"; //Nueva linea
						//echo "<br>";
						$total_pagar = 0; $asignaciones = 0;  $deducciones =0; //Limpia variables
					}
				}
			}
			fclose($file);

			header('Content-Description: File Transfer');
	    header('Content-Disposition: attachment; filename=' . $nombre_archivo);
	    header('Expires: 0');
	    header('Cache-Control: must-revalidate');
	    header('Pragma: public');
	    header('Content-Length: ' . filesize($nombre_archivo));
			readfile($nombre_archivo);
			unlink($nombre_archivo);


		 	if (count($array_reg)==0){
				echo "<font color=#DD0044 size=3>**** Banco No posee definici&oacute;n de Archivo Texto...... LLame a CONSULTARH *****</font>";
			}
		} ///////FIN pago de banco BNC
	}
	////////////////Fin de Id = 104 Mersan

	///////Inicia id = 105 FINTECH con banco
	if ($_SESSION['id_validar']==105 ){ //////Aplica para FINTECH Banco VENEZUELA

		if ($_POST['bancopaga']==3) { //////////pago de banco VENEZUELA a trabajadores con banco VENEZUELA

			$consultaEmpresa="select nombre from empresa where id='".$_SESSION['id_validar']."' ";
			$consultaEmpresa=mysqli_query($enlace,$consultaEmpresa) or die ($consultaEmpresa.mysqli_error($enlace));
			$rowEmpresa = mysqli_fetch_array($consultaEmpresa);
			$nombreEmpresa=$rowEmpresa['nombre'];



			////////Calculo la suma total a pagar
				$queryx="select * from personal,$payroll where personal.id='".$_SESSION['id_validar']."' and $payroll.tipo<>'R' and $payroll.cedula=personal.codigo ".$queryy." AND personal.banco = '0102' AND personal.banco <> '' AND SUBSTR(concepto, 1, 1) != 4 AND SUBSTR(concepto, 1, 1) != 5 AND SUBSTR(concepto, 1, 1) != 6 AND concepto NOT IN(2000,2001,2002,2003,2004,2005,2006,2007,2010,2012)
				GROUP BY $payroll.cedula,$payroll.concepto order by $payroll.cedula, $payroll.concepto, $payroll.desconcepto ";


				$consulta=mysqli_query($enlace,$queryx) or die ($queryx.mysqli_error($enlace));
				$cant_emp_pagar = mysqli_num_rows($consulta);
				$linea=0;	$color=0;  $tlinea=1;
				$tasig=0;	$tdeduc=0;
				$bandera=0;	$ttasig=0; $ttdeduc=0;
				$archivo='';$entrobanco=0;
				while($row=mysqli_fetch_array($consulta))
				{
					$ttasig+=($row['tipo']=='A'?$row['monto']:0);
					$ttdeduc+=($row['tipo']=='D'?$row['monto']:0);
				$tmonto = str_replace(".","",number_format(($ttasig-$ttdeduc),2,'.',''));

				}

			$queryx="SELECT per.tipo AS tipo_cuenta, pay.tipo AS tipo_concepto, SUM(pay.monto) as monto, pay.cedula, per.banco, pay.desperiodo, per.nombres, per.apellidos, per.cuenta, per.nacionalidad, per.mensaje FROM personal AS per, $payroll AS pay WHERE per.id = '".$_SESSION['id_validar']."' AND pay.tipo <> 'R' AND pay.cedula = per.codigo AND SUBSTR(pay.concepto, 1, 1) != 4 AND SUBSTR(pay.concepto, 1, 1) != 5 AND SUBSTR(pay.concepto, 1, 1) != 6 AND concepto NOT IN(2000,2001,2002,2003,2004,2005,2006,2007,2010,2012) AND per.banco = '0102' GROUP BY cedula,tipo_concepto ORDER BY pay.cedula, pay.concepto, pay.desconcepto";
			$consulta=mysqli_query($enlace,$queryx) or die ($queryx.mysqli_error($enlace));
			$cant_emp_pagar = mysqli_num_rows($consulta);

			$total_pagar=0;$asignaciones=0;$deducciones=0;


			//echo "H";


			//echo $nombreEmpresa;



			//echo str_repeat(' ',40-strlen($nombreEmpresa));
			//echo"<br>";
			while($rows_reporte=mysqli_fetch_array($consulta)){
			$array_reg[] = $rows_reporte;
			}
			$fecha_pago = date('d/m/y');
			$nombre_archivo = "bancos.txt";
			$file = fopen($nombre_archivo, "w+");
			fwrite($file, "H");
			fwrite($file, $nombreEmpresa);
			fwrite($file, str_repeat(" ",40-strlen($nombreEmpresa)));
			fwrite($file, "01020759250000054933");
			fwrite($file, "08");
			fwrite($file, $fecha_pago);
			fwrite($file, str_repeat("0",13-strlen($tmonto)));
			fwrite($file, $tmonto);
			fwrite($file, "03291");
			fwrite($file, " ");

			fwrite($file, "\r\n"); //Nueva Linea

			for($i=0;$i<count($array_reg);$i++){
				$cedula = $array_reg[$i]['cedula'];
				$nombres = $array_reg[$i]['nombres'];
				$apellidos = $array_reg[$i]['apellidos'];
				$nacionalidad = $array_reg[$i]['nacionalidad'];
				$mensaje = $array_reg[$i]['mensaje'];
				$cuenta = $array_reg[$i]['cuenta'];
				$tipo_cuenta = $array_reg[$i]['tipo_cuenta'];
				$tipo_cuenta = $tipo_cuenta-1;//este -1 es para que coincida con el tipo de cuenta del txt banco Vzla qu es cta-crrte=1 y cta-ahorr=0--Miguelangel
				$banco = $array_reg[$i]['banco'];
				$desperiodo = $array_reg[$i]['desperiodo'];
				$tipo_concepto = $array_reg[$i]['tipo_concepto'];
				$monto = $array_reg[$i]['monto'];

				if ($tipo_concepto == 'A'){
					$asignaciones+= $monto;
				}else if ($tipo_concepto == 'D'){
					$deducciones+= $monto;
				}

				$total_pagar = $asignaciones - $deducciones;

				if($array_reg[$i]['cedula']!=$array_reg[$i+1]['cedula']){ //Si el siguiente registro es de otra persona, entonces imprime

					//
					if ($total_pagar != 0){
						$total_pagar = str_replace(".","",number_format($total_pagar,2,'.',',')); //Formateo monto a pagar

						//Inicia a imprimir

						fwrite($file, $tipo_cuenta);
						fwrite($file, str_pad($cuenta, 20, "0", STR_PAD_LEFT));
						fwrite($file, str_pad($total_pagar, 11, "0", STR_PAD_LEFT));
						fwrite($file, $tipo_cuenta);
						//fwrite($file, $nacionalidad);
						fwrite($file, "770");
						fwrite($file, str_pad($nombres." ".$apellidos, 40, " ", STR_PAD_RIGHT)); //Imprime nombres con espacios hasta 60 caracteres
						fwrite($file, str_pad($cedula, 10, "0", STR_PAD_LEFT));
						fwrite($file, "003291");
						fwrite($file, "  ");


						fwrite($file, "\r\n"); //Nueva Linea


						//echo str_pad($nombres." ".$apellidos, 35, &nbsp;, STR_PAD_RIGHT); //Imprime nombres con espacios hasta 50 caracteres
	 				  //echo "\r\n"; //Nueva linea
						//echo "<br>";
						$total_pagar = 0; $asignaciones = 0;  $deducciones =0; //Limpia variables
					}
				}
			}
			fclose($file);

			header('Content-Description: File Transfer');
	    header('Content-Disposition: attachment; filename=' . $nombre_archivo);
	    header('Expires: 0');
	    header('Cache-Control: must-revalidate');
	    header('Pragma: public');
	    header('Content-Length: ' . filesize($nombre_archivo));
			readfile($nombre_archivo);
			unlink($nombre_archivo);


		 	if (count($array_reg)==0){
				echo "<font color=#DD0044 size=3>**** Banco No posee definici&oacute;n de Archivo Texto...... LLame a CONSULTARH *****</font>";
			}
		}

	}
} // fin de REPORTE CARTA BANCARIA TEXTO

//----------------------------------------------------------------------------------------------------------- REPORTE
//----------------------------------------------------------------------------------------------------------- RESUMEN INDIVIDUAL REPORTE ESPECIAL
if ($_POST['treporte']=='A') {
		require('fpdf.php');
		class PDF extends FPDF {
		function Header()
		{
	    $this->Image($_SESSION['logo_validar'],10,10,30,30);
	    $this->SetFont('arial','',12);
		$this->Ln(2);
		if ($_POST['cierre']==0) $this->Cell(0,5,'Reporte de PRE-CIERRE',0,1,'R'); else $this->Cell(0,5,'CIERRE AUDITADO',0,1,'R');
	    $this->Cell(0,5,$_POST['empresal'],0,1,'R');
		$this->Cell(0,5,$_POST['encabeza'],0,1,'R');
		$this->Ln(5);
		$this->SetFont('arial','',10);
	    $this->Cell(0,5,'Fecha: '.hoy(),0,0,'L');
	    $this->Cell(0,5,'Nomina: '.$_POST['empresa'],0,1,'R');
	    $this->Cell(0,5,'Hora: '.hora(),0,1,'L');
		$this->SetFont('arial','B',12);
		$this->Cell(0,0,($_POST['titulo']==''?'Resumen Individual de Pago de Nomina':$_POST['titulo']),0,1,'C');$this->Ln(5);
		$this->Cell(0,0,$_POST['subtitulo'],0,1,'C');$this->Ln(5);
		$this->SetFont('arial','',10);
		$this->Cell(0,0,'Periodo: '.$_POST['periodo'],0,1,'L');$this->Ln(5);
		if ($_POST['gerencia']!="") {
			$this->Cell(0,0,'Gerencia: '.$_POST['gerencia'],0,1,'L');$this->Ln(5);
		}
		if ($_POST['division']!="") {
			$this->Cell(0,0,'División: '.$_POST['division'],0,1,'L');$this->Ln(5);
		}
		if ($_POST['departamento']!="") {
			$this->Cell(0,0,'Departamento: '.$_POST['departamento'],0,1,'L');$this->Ln(5);
		}
		    $header=array('Cod.','Cedula','Nombres y Apellidos','Asignación','Sobre','Otra','Deducción','Vale','Total Bs.','Firma');
		    $w=array(10,15,50,20,15,15,15,15,20);
		    $this->SetFillColor(224,235,255);
		    $this->SetTextColor(0);
		    $this->SetDrawColor(128,0,0);
		    $this->SetLineWidth(.3);
		    $this->SetFont('','');
			$this->SetFont('arial','B',8);
			for($i=0;$i<count($header);$i++)
		        $this->Cell($w[$i],4,$header[$i],1,0,'C',1);
		    $this->Ln();
		    $this->SetFont('');
		}
		function Footer()
		{
		$this->SetY(-20);
		$this->Cell(0,0,'',1,1,'C');
		$this->SetFont('Times','I',8);
		$this->ln(2);
		$this->Cell(0,0,$_POST['pie'],0,1,'C');
		$this->Cell(0,10,'Usuario: '.$_POST['usuario'].' - Página '.$this->PageNo().'/{nb} - Derechos: '.$_POST['derecho'],0,0,'C');
		}
		}
		//Cuerpo ///////////////////////////////
		$pdf=new PDF();
		$pdf->AddPage();
		$pdf->AliasNbPages();
		$pdf->SetFont('Arial','',8);
		$pdf->SetFillColor(224,235,255);
		$pdf->SetTextColor(0);
		if ($_POST['eshistorico']!=1) $consulta=mysqli_query($enlace,"select * from $payroll order by cedula"  );
		else {
			if ($gerencia==1) $queryx="select * from personal,$payroll where personal.id='".$_SESSION['id_validar']."' and $payroll.cedula=personal.codigo ".$queryy." order by $payroll.cedula,$payroll.concepto, $payroll.desconcepto";
			else $queryx="select * from personal,$payroll where personal.id='".$_SESSION['id_validar']."' and $payroll.tipo<>'R' and $payroll.cedula=personal.codigo ".$queryy." order by $payroll.cedula, $payroll.concepto, $payroll.desconcepto";
			$consulta=mysqli_query($enlace,$queryx) or die ($queryx.mysqli_error($enlace));
		}
		$linea=0;
		$color=0;
		$tasig=0;
		$tdeduc=0;
		$bandera=0;
		$ttasig=0; $ttdeduc=0;
		$tcon01=0; $tcon02=0; $tcon05=0;
		$ttcon01=0; $ttcon02=0;
		while($row=mysqli_fetch_array($consulta)) {
			$ttasig+=($row['tipo']=='A'?$row['monto']:0);
			$ttdeduc+=($row['tipo']=='D'?$row['monto']:0);
			$ttcon01+=($row['concepto']==$conger01?$row['monto']:0);
			$ttcon02+=($row['concepto']==$conger02?$row['monto']:0);
			$ttcon05+=($row['concepto']==$conger05?$row['monto']:0);
			if ($bandera==0) {
				$bandera=1;
				$tcedula=$row['cedula'];
			}
			if ($tcedula==$row['cedula']) {
				$tasig+=($row['tipo']=='A'?$row['monto']:0);
				$tdeduc+=($row['tipo']=='D'?$row['monto']:0);
				$tcon01+=($row['concepto']==$conger01?$row['monto']:0);
				$tcon02+=($row['concepto']==$conger02?$row['monto']:0);
				$tcon05+=($row['concepto']==$conger05?$row['monto']:0);
				$tnombre="";
				$consul1=mysqli_query($enlace,"select nombres,apellidos,sso from personal where id='".$_SESSION['id_validar']."' and codigo=".$tcedula );
				if (mysqli_num_rows($consul1)<>0) {
					$row1=mysqli_fetch_array($consul1);
					$tnombre=trim($row['sso'])." ".trim($row1['nombres']).',  '.trim($row1['apellidos']);
				}
				$tcedula=$row['cedula'];
			}
			else {
				$linea++;
				$pdf->cell(10,8,$linea,0,0,'C',$color);
				$pdf->cell(15,8,$tcedula,0,0,'',$color);
				$pdf->cell(50,8,$tnombre,0,0,'',$color);
				$pdf->cell(20,8,number_format($tasig,2),0,0,'R',$color);
				$pdf->cell(15,8,number_format($tcon01,2),0,0,'R',$color);
				$pdf->cell(15,8,number_format($tcon05,2),0,0,'R',$color);
				$pdf->cell(15,8,number_format(-$tdeduc,2),0,0,'R',$color);
				$pdf->cell(15,8,number_format(-$tcon02,2),0,0,'R',$color);
				$pdf->SetFont('Arial','B',10);
				$pdf->cell(20,8,number_format($tasig+$tcon01+$tcon05-$tdeduc-$tcon02,2),0,0,'R',$color);
				$pdf->SetFont('Arial','',8);
				$pdf->cell(15,8,"",1,1,'R',$color);
				$color=!$color;
				$tasig=($row['tipo']=='A'?$row['monto']:0);
				$tdeduc=($row['tipo']=='D'?$row['monto']:0);
				$tcon01=($row['concepto']==$conger01?$row['monto']:0);
				$tcon02=($row['concepto']==$conger02?$row['monto']:0);
				$tcon05=($row['concepto']==$conger05?$row['monto']:0);
				$tcedula=$row['cedula'];
				$tnombre="";
				$consul1=mysqli_query($enlace,"select nombres,apellidos,sso from personal where id='".$_SESSION['id_validar']."' and codigo=".$tcedula );
				if (mysqli_num_rows($consul1)<>0) {
					$row1=mysqli_fetch_array($consul1);
					$tnombre=trim($row['sso'])." ".trim($row1['nombres']).',  '.trim($row1['apellidos']);
				}
			}
		}
		$linea++;
		$pdf->cell(10,8,$linea,0,0,'C',$color);
		$pdf->cell(15,8,$tcedula,0,0,'',$color);
		$pdf->cell(50,8,$tnombre,0,0,'',$color);
		$pdf->cell(20,8,number_format($tasig,2),0,0,'R',$color);
		$pdf->cell(15,8,number_format($tcon01,2),0,0,'R',$color);
		$pdf->cell(15,8,number_format($tcon05,2),0,0,'R',$color);
		$pdf->cell(15,8,number_format(-$tdeduc,2),0,0,'R',$color);
		$pdf->cell(15,8,number_format(-$tcon02,2),0,0,'R',$color);
		$pdf->SetFont('Arial','B',10);
		$pdf->cell(20,8,number_format($tasig+$tcon01+$tcon05-$tdeduc-$tcon02,2),0,0,'R',$color);
		$pdf->SetFont('Arial','',8);
		$pdf->cell(15,8,"",1,1,'R',$color);
		$pdf->Cell(195,0,'',1,1,'C'); $pdf->ln(1);

		$pdf->cell(75,5,'Totales',0,0,'R');
		$pdf->cell(20,5,number_format($ttasig,2) ,0,0,'R');
		$pdf->cell(15,5,number_format($ttcon01,2) ,0,0,'R');
		$pdf->cell(15,5,number_format($ttcon05,2) ,0,0,'R');
		$pdf->cell(15,5,number_format(-$ttdeduc,2) ,0,0,'R');
		$pdf->cell(15,5,number_format(-$ttcon02,2) ,0,0,'R');
		$pdf->cell(20,5,number_format($ttasig+$ttcon01+$ttcon05-$ttdeduc-$ttcon02,2) ,0,1,'R');
		$pdf->Cell(195,0,'',1,1,'C'); $pdf->ln(1);
		$pdf->Cell(195,0,'',1,1,'C');
		$pdf->Output();

} // fin de REPORTE INDIVIDUAL REPORTE=10 (A) reporte especial

//----------------------------------------------------------------------------------------------------------- REPORTE
//----------------------------------------------------------------------------------------------------------- RESUMEN INDIVIDUAL REPORTE ESPECIAL
if ($_POST['treporte']=='B') {
		require('fpdf.php');
		class PDF extends FPDF {
		function Header()
		{
	    $this->Image($_SESSION['logo_validar'],10,10,30,30);
	    $this->SetFont('arial','',12);
		$this->Ln(2);
		if ($_POST['cierre']==0) $this->Cell(0,5,'Reporte de PRE-CIERRE',0,1,'R'); else $this->Cell(0,5,'CIERRE AUDITADO',0,1,'R');
	    $this->Cell(0,5,$_POST['empresal'],0,1,'R');
		$this->Cell(0,5,$_POST['encabeza'],0,1,'R');
		$this->Ln(5);
		$this->SetFont('arial','',10);
	    $this->Cell(0,5,'Fecha: '.hoy(),0,0,'L');
	    $this->Cell(0,5,'Nomina: '.$_POST['empresa'],0,1,'R');
	    $this->Cell(0,5,'Hora: '.hora(),0,1,'L');
		$this->SetFont('arial','B',12);
		$this->Cell(0,0,($_POST['titulo']==''?'Resumen Individual de Pago de Nomina':$_POST['titulo']),0,1,'C');$this->Ln(5);
		$this->Cell(0,0,$_POST['subtitulo'],0,1,'C');$this->Ln(5);
		$this->SetFont('arial','',10);
		$this->Cell(0,0,'Periodo: '.$_POST['periodo'],0,1,'L');$this->Ln(5);
		if ($_POST['gerencia']!="") {
			$this->Cell(0,0,'Gerencia: '.$_POST['gerencia'],0,1,'L');$this->Ln(5);
		}
		if ($_POST['division']!="") {
			$this->Cell(0,0,'División: '.$_POST['division'],0,1,'L');$this->Ln(5);
		}
		if ($_POST['departamento']!="") {
			$this->Cell(0,0,'Departamento: '.$_POST['departamento'],0,1,'L');$this->Ln(5);
		}
	    $header=array('Cod.','Cedula','Nombres y Apellidos','Monto','Comi.','Con-01','Deducción','Con-02','Total Bs.','Firma');
	    $w=array(10,15,50,20,15,15,15,15,20,15);
	    $this->SetFillColor(224,235,255);
	    $this->SetTextColor(0);
	    $this->SetDrawColor(128,0,0);
	    $this->SetLineWidth(.3);
	    $this->SetFont('','');
		$this->SetFont('arial','B',8);
		for($i=0;$i<count($header);$i++)
	        $this->Cell($w[$i],4,$header[$i],1,0,'C',1);
	    $this->Ln();
	    $this->SetFont('');
		}
		function Footer()
		{
		$this->SetY(-20);
		$this->Cell(0,0,'',1,1,'C');
		$this->SetFont('Times','I',8);
		$this->ln(2);
		$this->Cell(0,0,$_POST['pie'],0,1,'C');
		$this->Cell(0,10,'Usuario: '.$_POST['usuario'].' - Página '.$this->PageNo().'/{nb} - Derechos: '.$_POST['derecho'],0,0,'C');
		}
		}
		//Cuerpo ///////////////////////////////
		$pdf=new PDF();
		$pdf->AddPage();
		$pdf->AliasNbPages();
		$pdf->SetFont('Arial','',8);
		$pdf->SetFillColor(224,235,255);
		$pdf->SetTextColor(0);
		if ($_POST['eshistorico']!=1) $consulta=mysqli_query($enlace,"select * from $payroll order by cedula"  );
		else {
			if ($gerencia==1) $queryx="select * from personal,$payroll where personal.id='".$_SESSION['id_validar']."' and $payroll.cedula=personal.codigo ".$queryy." order by $payroll.cedula,$payroll.concepto, $payroll.desconcepto";
			else $queryx="select * from personal,$payroll where personal.id='".$_SESSION['id_validar']."' and $payroll.tipo<>'R' and $payroll.cedula=personal.codigo ".$queryy." order by $payroll.cedula, $payroll.concepto, $payroll.desconcepto";
			$consulta=mysqli_query($enlace,$queryx) or die ($queryx.mysqli_error($enlace));
		}
		$linea=0;
		$color=0;
		$tasig=0;
		$tdeduc=0;
		$bandera=0;
		$ttasig=0; $ttdeduc=0;
		$tcon01=0; $tcon02=0;$dcon3=0;
		$ttcon01=0; $ttcon02=0;
		$ttcon03=0; $ttcon04=0;
		$ttcon05=0; $ttcon06=0;
		while($row=mysqli_fetch_array($consulta)) {
			$ttasig+=($row['tipo']=='A'?$row['monto']:0);
			$ttdeduc+=($row['tipo']=='D'?$row['monto']:0);
			$ttcon01+=($row['concepto']==$conger01?$row['monto']:0);
			$ttcon02+=($row['concepto']==$conger02?$row['monto']:0);
			$ttcon03+=($row['concepto']==$conger03?$row['monto']:0);
			$tdcon03+=($row['concepto']==$conger03?$row['cantidad']:0);
			$ttcon04+=($row['concepto']==$conger04?$row['monto']:0);
			$ttcon05+=($row['concepto']==$conger05?$row['monto']:0);
			$ttcon06+=($row['concepto']==$conger06?$row['monto']:0);
			if ($bandera==0) {
				$bandera=1;
				$tcedula=$row['cedula'];
			}
			if ($tcedula==$row['cedula']) {
				$tasig+=($row['tipo']=='A'?$row['monto']:0);
				$tdeduc+=($row['tipo']=='D'?$row['monto']:0);
				$tcon01+=($row['concepto']==$conger01?$row['monto']:0);
				$tcon02+=($row['concepto']==$conger02?$row['monto']:0);
				$tcon03+=($row['concepto']==$conger03?$row['monto']:0);
				$dcon03+=($row['concepto']==$conger03?$row['cantidad']:0);
				$tcon04+=($row['concepto']==$conger04?$row['monto']:0);
				$tcon05+=($row['concepto']==$conger05?$row['monto']:0);
				$tcon06+=($row['concepto']==$conger06?$row['monto']:0);
				$tnombre="";
				$consul1=mysqli_query($enlace,"select nombres,apellidos,sso from personal where id='".$_SESSION['id_validar']."' and codigo=".$tcedula );
				if (mysqli_num_rows($consul1)<>0) {
					$row1=mysqli_fetch_array($consul1);
					$tnombre=trim($row['sso'])." ".trim($row1['nombres']).',  '.trim($row1['apellidos']);
				}
				$tcedula=$row['cedula'];
			}
			else {
				$linea++;
				$pdf->cell(10,8,$linea,0,0,'C',$color);
				$pdf->cell(15,8,$tcedula,0,0,'',$color);
				$pdf->cell(50,8,$tnombre,0,0,'',$color);
				$pdf->cell(20,8,number_format($dcon03,2),0,0,'R',$color);
				$pdf->cell(15,8,number_format($tcon03,2),0,0,'R',$color);
				$pdf->cell(15,8,number_format($tcon05,2),0,0,'R',$color);
				$pdf->cell(15,8,number_format(-$tcon04,2),0,0,'R',$color);
				$pdf->cell(15,8,number_format(-$tcon02,2),0,0,'R',$color);
				$pdf->SetFont('Arial','B',10);
				$pdf->cell(20,8,number_format($tcon03+$tcon05-$tcon04-$tcon02,2),0,0,'R',$color);
				$pdf->SetFont('Arial','',8);
				$pdf->cell(15,8,"",1,1,'R',$color);
				$color=!$color;
				$tasig=($row['tipo']=='A'?$row['monto']:0);
				$tdeduc=($row['tipo']=='D'?$row['monto']:0);
				$tcon01=($row['concepto']==$conger01?$row['monto']:0);
				$tcon02=($row['concepto']==$conger02?$row['monto']:0);
				$tcon03=($row['concepto']==$conger03?$row['monto']:0);
				$dcon03=($row['concepto']==$conger03?$row['cantidad']:0);
				$tcon04=($row['concepto']==$conger04?$row['monto']:0);
				$tcon05=($row['concepto']==$conger05?$row['monto']:0);
				$tcon06=($row['concepto']==$conger06?$row['monto']:0);
				$tcedula=$row['cedula'];
				$tnombre="";
				$consul1=mysqli_query($enlace,"select nombres,apellidos,sso from personal where id='".$_SESSION['id_validar']."' and codigo=".$tcedula );
				if (mysqli_num_rows($consul1)<>0) {
					$row1=mysqli_fetch_array($consul1);
					$tnombre=trim($row['sso'])." ".trim($row1['nombres']).',  '.trim($row1['apellidos']);
				}
			}
		}
		$linea++;
		$pdf->cell(10,8,$linea,0,0,'C',$color);
		$pdf->cell(15,8,$tcedula,0,0,'',$color);
		$pdf->cell(50,8,$tnombre,0,0,'',$color);
		$pdf->cell(20,8,number_format($dcon03,2),0,0,'R',$color);
		$pdf->cell(15,8,number_format($tcon03,2),0,0,'R',$color);
		$pdf->cell(15,8,number_format($tcon05,2),0,0,'R',$color);
		$pdf->cell(15,8,number_format(-$tcon04,2),0,0,'R',$color);
		$pdf->cell(15,8,number_format(-$tcon02,2),0,0,'R',$color);
		$pdf->SetFont('Arial','B',10);
		$pdf->cell(20,8,number_format($tcon03+$tcon05-$tcon04-$tcon02,2),0,0,'R',$color);
		$pdf->SetFont('Arial','',8);
		$pdf->cell(15,8,"",1,1,'R',$color);
		$pdf->Cell(195,0,'',1,1,'C'); $pdf->ln(1);

		$pdf->cell(75,5,'Totales',0,0,'R');
		$pdf->cell(20,5,number_format($tdcon03,2) ,0,0,'R');
		$pdf->cell(15,5,number_format($ttcon03,2) ,0,0,'R');
		$pdf->cell(15,5,number_format($ttcon05,2) ,0,0,'R');
		$pdf->cell(15,5,number_format(-$ttcon04,2) ,0,0,'R');
		$pdf->cell(15,5,number_format(-$ttcon02,2) ,0,0,'R');
		$pdf->cell(20,5,number_format($ttcon03+$ttcon05-$ttcon04-$ttcon02,2) ,0,1,'R');
		$pdf->Cell(195,0,'',1,1,'C'); $pdf->ln(1);
		$pdf->Cell(195,0,'',1,1,'C');
		$pdf->Output();

} // fin de REPORTE INDIVIDUAL REPORTE=10 (B) reporte especial
?>
