<?
//--------------------------------------------------------------------------------------------------------------------------------- REPORTE RESUMEN GENERAL DE CONCEPTOS
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,30,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,'Nómina: '.$_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,$_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,'Nómina: '.$_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=mysql_query("select * from $payroll 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." 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." order by $payroll.concepto, $payroll.desconcepto";			
			$consulta=mysql_query($queryx) or die ($queryx.mysql_error());
		}
		
		$linea=0;
		$color=0;
		$tasig=0;
		$tdeduc=0;
		$bandera=0;
		$ttasig=0; $ttdeduc=0;
		while($row=mysql_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']=='DEDU'||$row['concepto']=='ASIG'?("D".substr($row['desconcepto'],0,4)):($row['concepto']));
			}

			$tconcepto1=($row['concepto']=='DEDU'||$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']=='DEDU'||$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']=='DEDU'||$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();
	} //================= 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=mysql_query("select * from $payroll 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." 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." order by $payroll.concepto, $payroll.desconcepto";			
			$consulta=mysql_query($queryx) or die ($queryx.mysql_error());
		}
		$linea=0;
		$color=0;
		$tasig=0;
		$tdeduc=0;
		$bandera=0;
		$ttasig=0; $ttdeduc=0;
		while($row=mysql_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']=='DEDU'||$row['concepto']=='ASIG'?("D".substr($row['desconcepto'],0,4)):($row['concepto']));
			}

			$tconcepto1=($row['concepto']=='DEDU'||$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']=='DEDU'||$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']=='DEDU'||$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 PDF
	
	
}

//--------------------------------------------------------------------------------------------------------------------------------- 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 Pagos':$_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,'Nómina: '.$_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)','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,15,55,25,25,25,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(224,235,255);
		$pdf->SetTextColor(0);
		if ($_POST['eshistorico']!=1) $consulta=mysql_query("select * from $payroll 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." 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." order by $payroll.cedula, $payroll.concepto, $payroll.desconcepto";			
			$consulta=mysql_query($queryx) or die ($queryx.mysql_error());
		}
		$linea=0;
		$color=0;
		$tasig=0;
		$tdeduc=0;
		$bandera=0;
		$ttasig=0; $ttdeduc=0;
		while($row=mysql_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="";
				$consul1=mysql_query("select nombres,apellidos,sso from personal where id='".$_SESSION['id_validar']."' and codigo=".$tcedula );
				if (mysql_num_rows($consul1)<>0) {
					$row1=mysql_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,0,'R',$color);
				$pdf->cell(31,5,"__________________",0,1,'R',$color);
				$pdf->ln(5);
				$color=!$color;
				$tasig=($row['tipo']=='A'?$row['monto']:0);
				$tdeduc=($row['tipo']=='D'?$row['monto']:0);
				$tcedula=$row['cedula'];
				$tnombre="";
				$consul1=mysql_query("select nombres,apellidos,sso from personal where id='".$_SESSION['id_validar']."' and codigo=".$tcedula );
				if (mysql_num_rows($consul1)<>0) {
					$row1=mysql_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,0,'R',$color);
		$pdf->cell(31,5,"__________________",0,1,'R',$color);
		$pdf->ln(5);
		$pdf->Cell(190,0,'',1,1,'C'); $pdf->ln(1);
		$pdf->cell(80,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();
	} //================= 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 Pagos':$_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 ($_POST['eshistorico']!=1) $consulta=mysql_query("select * from $payroll 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." 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." order by $payroll.cedula, $payroll.concepto, $payroll.desconcepto";			
			$consulta=mysql_query($queryx) or die ($queryx.mysql_error());
		}
		
		$linea=0;
		$color=0;
		$tasig=0;
		$tdeduc=0;
		$bandera=0;
		$ttasig=0; $ttdeduc=0;
		while($row=mysql_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="";
				$consul1=mysql_query("select nombres,apellidos,sso from personal where id='".$_SESSION['id_validar']."' and codigo=".$tcedula );
				if (mysql_num_rows($consul1)<>0) {
					$row1=mysql_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>";
				echo "<td width='120' align='right'><font face='verdana' color='black' size='3'>_________________</font></td>";
				echo "</tr>";

				$tasig=($row['tipo']=='A'?$row['monto']:0);
				$tdeduc=($row['tipo']=='D'?$row['monto']:0);
				$tcedula=$row['cedula'];
				$tnombre="";
				$consul1=mysql_query("select nombres,apellidos,sso from personal where id='".$_SESSION['id_validar']."' and codigo=".$tcedula );
				if (mysql_num_rows($consul1)<>0) {
					$row1=mysql_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>";
		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>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 "<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','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']==''?'Pago de Nómina 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,'Nómina: '.$_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 ($_POST['eshistorico']!=1) $consu="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) $consu="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 $consu="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=mysql_query($consu) or die($consu.mysql_error());
		
		$linea=0;
		$color=0;
		$tasig=0;
		$tdeduc=0;
		$bandera=0;
		$ttasig=0; $ttdeduc=0;
		while($row=mysql_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'];
				$tcargo=$row['cargo'];
				$concar=mysql_query("select * from tablas where tabla='CARGO' and codigo='".$tcargo."' and id='".$_SESSION['id_validar']."' "  );
				while($row1=mysql_fetch_array($concar))
					$tcargo=$row1['detalle'];
				$tnombre=trim($row['sso'])." ".trim($row['nombres']).',  '.trim($row['apellidos']).' - '.$tcargo.($row['cuenta']==''?'':' - cuenta bancaria: '.$row['cuenta']);					
				$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']) {
				$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=="DEDU"?number_format($tsaldo,2):""),0,1,'R',$color);
			}	
			else {
				$pdf->Cell(190,0,'',1,1,'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');
				$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=mysql_query("select * from tablas where tabla='CARGO' and codigo='".$tcargo."' and id='".$_SESSION['id_validar']."' "  );
				while($row1=mysql_fetch_array($concar))
					$tcargo=$row1['detalle'];
				$tnombre=trim($row['sso'])." ".trim($row['nombres']).',  '.trim($row['apellidos']).' - '.$tcargo.($row['cuenta']==''?'':' - cuenta bancaria: '.$row['cuenta']);					
				$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=="DEDU"?number_format($tsaldo,2):""),0,1,'R',$color);			
			}
			$color=!$color;
		}
		$pdf->Cell(190,0,'',1,1,'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');
		$pdf->Cell(190,0,'',1,1,'C'); 
		$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();
	} //========================= 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 Nómina 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 ($_POST['eshistorico']!=1) $consu="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) $consu="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 $consu="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=mysql_query($consu) or die($consu.mysql_error());
		
		$linea=0;
		$color=0;
		$tasig=0;
		$tdeduc=0;
		$bandera=0;
		$ttasig=0; $ttdeduc=0;
		while($row=mysql_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'];
				$tcargo=$row['cargo'];
				$concar=mysql_query("select * from tablas where tabla='CARGO' and codigo='".$tcargo."' and id='".$_SESSION['id_validar']."' "  );
				while($row1=mysql_fetch_array($concar))
					$tcargo=$row1['detalle'];
				$tnombre=" - Rif: ".trim($row['sso'])." - Nombre: ".trim($row['nombres']).',  '.trim($row['apellidos']).' - Cargo: '.$tcargo.($row['cuenta']==''?'':' - Cuenta Bancaria: '.$row['cuenta']);					
			
				echo "<tr><td colspan=1>".$tcedula."</td>";
				echo "<td colspan=5>".$tnombre."</td></tr>";			
				$color=0;
			}
			if ($tcedula==$row['cedula']) {
				$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='10'><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=="DEDU"?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>";
				
				$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=mysql_query("select * from tablas where tabla='CARGO' and codigo='".$tcargo."' and id='".$_SESSION['id_validar']."' "  );
				while($row1=mysql_fetch_array($concar))
					$tcargo=$row1['detalle'];
					$tnombre=" - Rif: ".trim($row['sso'])." - Nombre: ".trim($row['nombres']).',  '.trim($row['apellidos']).' - Cargo: '.$tcargo.($row['cuenta']==''?'':' - Cuenta Bancaria: '.$row['cuenta']);
				//$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>";			
				$color=0;
				
				if ($color) echo '<tr bgcolor="#E6E6E6" >';
				else echo '<tr bgcolor="#EEEFF3">';
				$color=!$color;	
		
				echo "<td width='10'><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=="DEDU"?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>";
		
		echo "<tr BGcolor='#464D77' style='color:#fff;' >";
		echo "<th ali=center colspan=3><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 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']==1)	{
			//Cuerpo //////////////////////////////////////////////
				$pdf=new PDF($orientation='P',$unit='mm',$format='letter');
				$pdf->AddPage();
				$pdf->AliasNbPages();
				$pdf->SetFont('helvetica','',10);
				if ($_POST['eshistorico']!=1) 
					$consulta=mysql_query("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 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." order by personal.codigo, $payroll.concepto, $payroll.desconcepto";			
					$consulta=mysql_query($queryx) or die ($queryx.mysql_error());
				}
				$linea=0;
				$color=0;
				$tasig=0;
				$tdeduc=0;
				$bandera=0;$salto=1;
				$ttasig=0; $ttdeduc=0;
				$tlinea=0;
				while($row=mysql_fetch_array($consulta)) {
					$ttasig+=($row['tipo']=='A'?$row['monto']:0);
					$ttdeduc+=($row['tipo']=='D'?$row['monto']:0);
					if ($bandera==0) {
						//===================================== inicio de cabecera 
						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']),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(),0,0,'R');
						$pdf->ln(3);
						//$pdf->Cell(100,5,$_POST['encabeza'],0,0,'R'); 
						$pdf->Cell(200,5,'Nómina: '.$_POST['empresa'],0,1,'R');
						//$pdf->Ln(2);
						$pdf->SetFont('arial','B',16); 
						$pdf->Cell(0,5,($_POST['titulo']==''?'Recibos de Pagos':$_POST['titulo']),0,1,'C');
						$pdf->SetFont('arial','',10);
						$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=mysql_query("select * from tablas where tabla='CARGO' and codigo='".$tcargo."' and id='".$_SESSION['id_validar']."' "  );
						while($row1=mysql_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']);
						
						//$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','',6); $pdf->cell(1);$pdf->cell(1,5,"Cedula: ".$tcedula." - Rif: ".$tnombresso,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']) {
						$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=="DEDU"?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:',0,0,'R');
						$pdf->SetFont('helvetica','',8);
						$pdf->cell(90,4,number_format($tasig-$tdeduc,2) ,0,1,'R');
						$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',7);
						$pdf->Cell(0,5,'Nomina: '.$_POST['nomina']." / ".'Periodo: '.$_POST['periodo'].' / Fec.Ingreso: '.$tfechai.' / Sueldo Mensual : '.number_format($sueldom,2),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 nómina, 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->SetFont('arial','B',8);
						$pdf->Ln(2);
						$pdf->Cell(200,5,($gerencia==1?substr($_POST['gerencia'],7,50):$_POST['empresal']),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(),0,0,'R');
						$pdf->ln(3);
						//$pdf->Cell(100,5,$_POST['encabeza'],0,0,'R'); 
						$pdf->Cell(200,5,'Nómina: '.$_POST['empresa'],0,1,'R');
						//$pdf->Ln(2);
						$pdf->SetFont('arial','B',16); 
						$pdf->Cell(0,5,($_POST['titulo']==''?'Recibos de Pagos':$_POST['titulo']),0,1,'C');
						$pdf->SetFont('arial','',10);
						$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 
							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']),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(),0,0,'R');
						$pdf->ln(3);
						//$pdf->Cell(100,5,$_POST['encabeza'],0,0,'R'); 
						$pdf->Cell(200,5,'Nómina: '.$_POST['empresa'],0,1,'R');
						//$pdf->Ln(2);
						$pdf->SetFont('arial','B',16); 
						$pdf->Cell(0,5,($_POST['titulo']==''?'Recibos de Pagos':$_POST['titulo']),0,1,'C');
						$pdf->SetFont('arial','',10);
						$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=mysql_query("select * from tablas where tabla='CARGO' and codigo='".$tcargo."' and id='".$_SESSION['id_validar']."' "  );
						while($row1=mysql_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']);
						
						$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','',6); $pdf->cell(1);$pdf->cell(1,5,"Cedula: ".$tcedula." - Rif: ".$tnombresso,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);
						$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=="DEDU"?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:',0,0,'R');
				$pdf->SetFont('helvetica','',8);
				$pdf->cell(90,5,number_format($tasig-$tdeduc,2) ,0,1,'R');
				$pdf->SetFont('helvetica','',10);
				$pdf->ln(10);
				$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');	
	
	} 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=mysql_query("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 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." order by personal.codigo, $payroll.concepto, $payroll.desconcepto";			
				$consulta=mysql_query($queryx) or die ($queryx.mysql_error());
			}
			$linea=0;
			$color=0;
			$tasig=0;
			$tdeduc=0;
			$bandera=0;
			$ttasig=0; $ttdeduc=0;
			$lineaxrecibo=0;
			$partedelrecibo=0;
			while($row=mysql_fetch_array($consulta)) {
				$ttasig+=($row['tipo']=='A'?$row['monto']:0);
				$ttdeduc+=($row['tipo']=='D'?$row['monto']:0);
				if ($bandera==0) {
				
					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','',12);
					$pdf->Cell(120,5,($gerencia==1?substr($_POST['gerencia'],7,50):$_POST['empresal']),0,0,'R'); 
					$pdf->Cell(20);
					$pdf->Cell(120,5,($gerencia==1?substr($_POST['gerencia'],7,50):$_POST['empresal']),0,1,'R'); 
					$pdf->SetFont('arial','',10);
					
					//===================================== inicio de cabecera rif
					$pdf->SetFont('arial','',12);
					$pdf->Cell(120,5,$_POST['encabeza'],0,0,'R'); 
					$pdf->Cell(20);
					$pdf->Cell(120,5,$_POST['encabeza'],0,0,'R'); 
					$pdf->SetFont('arial','',10);
					
					//===================================== inicio de cabecera linea 1
					$pdf->SetFont('arial','',10);
					$pdf->Cell(120,5,'Fecha: '.hoy(),0,0,'R');
					$pdf->Cell(20);
					$pdf->Cell(120,5,'Fecha: '.hoy(),0,1,'R');

					//===================================== inicio de cabecera linea 2
					$pdf->SetFont('arial','',10);
					$pdf->Cell(120,5,'Nómina: '.$_POST['empresa'],0,0,'R');
					$pdf->Cell(20);
					$pdf->Cell(120,5,'Nómina: '.$_POST['empresa'],0,1,'R');
					
					//===================================== inicio de cabecera linea 3
					$pdf->SetFont('arial','B',12); 
					$pdf->Cell(130,5,($_POST['titulo']==''?'Recibos de Pagos':$_POST['titulo']),0,0,'C');
					$pdf->Cell(10);
					$pdf->Cell(130,5,($_POST['titulo']==''?'Recibos de Pagos':$_POST['titulo']),0,1,'C');
					$pdf->Cell(130,5,$_POST['subtitulo'],0,0,'C');
					$pdf->Cell(10);
					$pdf->Cell(130,5,$_POST['subtitulo'],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=mysql_query("select * from tablas where tabla='CARGO' and codigo='".$tcargo."' and id='".$_SESSION['id_validar']."' "  );
					while($row1=mysql_fetch_array($concar))
						$tcargo=$row1['detalle'];
					$tnombre=trim($row['sso'])." ".trim($row['nombres']).',  '.trim($row['apellidos']).' - '.$tcargo;					
					if ($row['cuenta']!='') $tnombrec='Cuenta Bancaria: '.$row['cuenta'];					

					//===================================== inicio de cabecera linea 5
					$pdf->SetFont('Arial','',10);
					$pdf->ln(5);
					$pdf->cell(130,5,"[".$tcedula."] - ".$tnombre,0,0,'');
					$pdf->Cell(10);
					$pdf->cell(130,5,"[".$tcedula."] - ".$tnombre,0,1,'');

					if ($row['cuenta']!='') {
						$tnombrec='Cuenta Bancaria: '.$row['cuenta'];					
						$pdf->cell(130,5,$tnombrec,0,0,'');
						$pdf->Cell(10);
						$pdf->cell(130,5,$tnombrec,0,1,'');
					}
					
					$pdf->SetFont('Arial','',8);
					$header=array('Cod.','Descripción','Cantidad','Asignación','Deducción','Saldo');
					$pdf->SetDrawColor(128,0,0);
					$pdf->SetLineWidth(.3);
					$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('');
				}
				
				if ($tcedula==$row['cedula']) {
					$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=="DEDU"?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=="DEDU"?number_format($tsaldo,2):""),0,1,'R',$color);
				}	
				else {
					$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->cell(75,5,'Total a Cobrar:',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:',0,0,'R');
					$pdf->cell(45,5,number_format($tasig-$tdeduc,2) ,0,1,'R');
					
					$pdf->ln(10);
					$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 nómina, 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 nómina, 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','',12);
					$pdf->Cell(120,5,($gerencia==1?substr($_POST['gerencia'],7,50):$_POST['empresal']),0,0,'R'); 
					$pdf->Cell(20);
					$pdf->Cell(120,5,($gerencia==1?substr($_POST['gerencia'],7,50):$_POST['empresal']),0,1,'R'); 
					$pdf->SetFont('arial','',10);
					//===================================== inicio de cabecera rif
					$pdf->SetFont('arial','',12);
					$pdf->Cell(120,5,$_POST['encabeza'],0,0,'R'); 
					$pdf->Cell(20);
					$pdf->Cell(120,5,$_POST['encabeza'],0,0,'R'); 
					$pdf->SetFont('arial','',10);
					
					//===================================== inicio de cabecera linea 1
					$pdf->SetFont('arial','',10);
					$pdf->Cell(120,5,'Fecha: '.hoy(),0,0,'R');
					$pdf->Cell(20);
					$pdf->Cell(120,5,'Fecha: '.hoy(),0,1,'R');

					//===================================== inicio de cabecera linea 2
					$pdf->SetFont('arial','',10);
					$pdf->Cell(120,5,'Nómina: '.$_POST['empresa'],0,0,'R');
					$pdf->Cell(20);
					$pdf->Cell(120,5,'Nómina: '.$_POST['empresa'],0,1,'R');
					
					//===================================== inicio de cabecera linea 3
					$pdf->SetFont('arial','B',12); 
					$pdf->Cell(130,5,($_POST['titulo']==''?'Recibos de Pagos':$_POST['titulo']),0,0,'C');
						$pdf->Cell(10);
					$pdf->Cell(130,5,($_POST['titulo']==''?'Recibos de Pagos':$_POST['titulo']),0,1,'C');
					$pdf->Cell(130,5,$_POST['subtitulo'],0,0,'C');
						$pdf->Cell(10);
					$pdf->Cell(130,5,$_POST['subtitulo'],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=mysql_query("select * from tablas where tabla='CARGO' and codigo='".$tcargo."' and id='".$_SESSION['id_validar']."' "  );
					while($row1=mysql_fetch_array($concar))
						$tcargo=$row1['detalle'];
					$tnombre=trim($row['sso'])." ".trim($row['nombres']).',  '.trim($row['apellidos']).' - '.$tcargo;					
					if ($row['cuenta']!='') $tnombrec='Cuenta Bancaria: '.$row['cuenta'];					

					//===================================== inicio de cabecera linea 5
					$pdf->SetFont('Arial','',10);
					$pdf->ln(5);
					$pdf->cell(130,5,"[".$tcedula."] - ".$tnombre,0,0,'');
					$pdf->Cell(10);
					$pdf->cell(130,5,"[".$tcedula."] - ".$tnombre,0,1,'');

					if ($row['cuenta']!='') {
						$tnombrec='Cuenta Bancaria: '.$row['cuenta'];					
						$pdf->cell(130,5,$tnombrec,0,0,'');
						$pdf->Cell(10);
						$pdf->cell(130,5,$tnombrec,0,1,'');
					}
					
					$pdf->SetFont('Arial','',8);
					$pdf->SetDrawColor(128,0,0);
					$pdf->SetLineWidth(.3);
					$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->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=="DEDU"?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=="DEDU"?number_format($tsaldo,2):""),0,1,'R',$color);
				}
				$color=!$color;
			}
			$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->cell(75,5,'Total a Cobrar:',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:',0,0,'R');
			$pdf->cell(45,5,number_format($tasig-$tdeduc,2) ,0,1,'R');
					
			$pdf->ln(10);
			$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();
	
} // 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 = mysql_query($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,'Nómina: '.$_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');
				$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);
				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=mysql_query("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=mysql_query($queryx) or die ($queryx.mysql_error());
			}
			$linea=0;
			$color=0;
			$tasig=0;
			$tdeduc=0;
			$bandera=0;
			$ttasig=0; $ttdeduc=0;
			while($row=mysql_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'];
				}	
				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);
					$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'];
				}
			}
			$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(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();
		}	
	} //=========================== 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']==''?'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>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=mysql_query("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=mysql_query($queryx) or die ($queryx.mysql_error());
		}
		$linea=0;
		$color=0;
		$tasig=0;
		$tdeduc=0;
		$bandera=0;
		$ttasig=0; $ttdeduc=0;
		while($row=mysql_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'];
			}	
			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='#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'];
			}
		}
				
		$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='#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=3><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<>'DEDU' and concepto<>'ASIG'";
		$qempleado = mysql_query($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,'Nómina: '.$_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=mysql_query("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=mysql_query($queryx) or die ($queryx.mysql_error());
		}
		$linea=0;
		$color=0;
		$tasig=0;
		$tdeduc=0;
		$bandera=0;
		$tsdetalle1=0;
		$tsdetalle2=0;
		$ttasig=0; $ttdeduc=0;
		while($row=mysql_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();
	} //================================= 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 Automáticas (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<>'DEDU' and concepto<>'ASIG'";
		$qempleado = mysql_query($query) or die ($query);
		if ($_POST['eshistorico']!=1) $consulta=mysql_query("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=mysql_query($queryx) or die ($queryx.mysql_error());
		}
		$linea=0;
		$color=0;
		$tasig=0;
		$tdeduc=0;
		$bandera=0;
		$tsdetalle1=0;
		$tsdetalle2=0;
		$ttasig=0; $ttdeduc=0;
		while($row=mysql_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 
//--------------------------------------------------------------------------------------------------------------------------------- REPORTE AL BANCO
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,'Nómina: '.$_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=mysql_query("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=mysql_query($queryx) or die ($queryx.mysql_error());
		}
		$linea=0;
		$color=0;
		$tasig=0;
		$tdeduc=0;
		$bandera=0;
		$ttasig=0; $ttdeduc=0;
		while($row=mysql_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();
	} //======================================= 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 Nómina 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=mysql_query("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=mysql_query($queryx) or die ($queryx.mysql_error());
		}
		$linea=0;
		$color=0;
		$tasig=0;
		$tdeduc=0;
		$bandera=0;
		$ttasig=0; $ttdeduc=0;
		while($row=mysql_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
if ($_POST['treporte']==8) {	

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

	$consulta=mysql_query($linea);
	$consulta=mysql_query("delete from `".$sabana."`");
	
	//================================== cargo datos de payroll a sabana
	if ($_POST['eshistorico']!=1) $consulta=mysql_query("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=mysql_query($queryx) or die ($queryx.mysql_error());
	}
	$ttasig=0; $ttdeduc=0; $bandera=0;
	while($row=mysql_fetch_array($consulta)) {
		$filas=mysql_query("select * from $sabana where cedula='".$row['cedula']."'" );
		if (mysql_num_rows($filas)==0)
			$filas=mysql_query("insert into $sabana (cedula,nombre) values ('".$row['cedula']."','".(trim($row['nombres']).",".$row['apellidos'])."')" );
		if ($row['tipo']=='A') $tem=mysql_query("update $sabana set A".$row['concepto']."=".$row['monto']." where cedula='".$row['cedula']."'" );
		if ($row['tipo']=='D')  $tem=mysql_query("update $sabana set D".$row['concepto']."=".$row['monto']." where cedula='".$row['cedula']."'" );
		if ($row['concepto']=='ASIG')$tem=mysql_query("update $sabana set pasig=pasig+".$row['monto']." where cedula='".$row['cedula']."'" );
		if ($row['concepto']=='DEDU')$tem=mysql_query("update $sabana set pdedu=pdedu+".$row['monto']." where cedula='".$row['cedula']."'" );
	}
	
	//================================== totalizar campos de subtotales	
	$registros=mysql_query("select * from $sabana order by cedula");
	$cant=mysql_num_fields($registros) or die(mysql_error());
	$casig='';$cdedu='';
	for($f=0;$f<$cant;$f++)
	{
		$valor=mysql_field_name($registros,$f);
		if (strtoupper(substr($valor,0,1))=='A') $casig .= $valor."+";
		if (strtoupper(substr($valor,0,1))=='D') $cdedu .= $valor."+";
	}
	$casig .="pasig";
	$cdedu .="pdedu";
	while($row = mysql_fetch_row($registros)) 
	{ 
		$ced = $row[0];
		$tasigx=0; $tdedux=0;
		$registrosx=mysql_query("select sum(".$casig.") as total from $sabana where cedula='".$ced."'");
		while($rowx = mysql_fetch_row($registrosx)) {
			$tasigx=$rowx[0];			
		}
		$registrosx=mysql_query("select sum(".$cdedu.") as total from $sabana where cedula='".$ced."'");
		while($rowx = mysql_fetch_row($registrosx)) {
			$tdedux=$rowx[0];			
		}
		$registrosx=mysql_query("update $sabana set tasig='".$tasigx."', tdedu='".$tdedux."', monto='".($tasigx-$tdedux)."' where cedula='".$ced."'");
	}
	
	//================================== crear cabecera
	$registros=mysql_query("select * from $sabana order by cedula");
	$cant=mysql_num_fields($registros) or die(mysql_error());
	$casig='';$cdedu='';
	for($f=0;$f<$cant;$f++)
	{
		$valor=mysql_field_name($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(mysql_field_name($registros,$f),1,50));
			$consulta=mysql_query("select detalle from concepto where id='".$_SESSION['id_validar']."' and codigo='".$cod."'");
			while($row=mysql_fetch_array($consulta)) $valor = $row['detalle'];
		}
		$cabecera.=strtoupper($valor)."\t";
	}
	
	//================================== cargo datos a excel por columna
	while($fila = mysql_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 ($_POST['pago']=='2') {	
		if ($_POST['eshistorico']!=1) $consulta=mysql_query("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=mysql_query($queryx) or die ($queryx.mysql_error());
		}
		$linea=0;	$color=0;  $tlinea=1;	
		$tasig=0;	$tdeduc=0;
		$bandera=0;	$ttasig=0; $ttdeduc=0;
		$archivo='';$entrobanco=0;
		while($row=mysql_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']) {
				if (trim($row['banco'])=='1') {
					$entrobanco=1;
					$tasig+=($row['tipo']=='A'?$row['monto']:0);
					$tdeduc+=($row['tipo']=='D'?$row['monto']:0);
					$tnombre=trim(substr(trim($row['nombres']).' '.trim($row['apellidos']),0,39)).str_repeat('&nbsp;',39-strlen(trim(substr(trim($row['nombres']).' '.trim($row['apellidos']),0,39)))).'.';
					$tcedula=$row['cedula'];
					$tcuenta=$row['cuenta'];
					$tbanco=trim($row['banco']);
					$nacion=($row['nacionalidad'] != 'E' ? 'V' : 'E');
				}	
				if (trim($row['banco'])=='6') {
					$entrobanco=1;
					$tfecha = substr($row['desperiodo'],14,4).substr($row['desperiodo'],19,2).substr($row['desperiodo'],22,2) ;	
					$tasig+=($row['tipo']=='A'?$row['monto']:0);
					$tdeduc+=($row['tipo']=='D'?$row['monto']:0);
					$tbanco=trim($row['banco']);
					$tcedula=$row['cedula'];
					$tcuenta=$row['cuenta'];
				}	
			} else {
				if ($tbanco=='1') {
					$tmonto = str_replace(",","",number_format($tasig-$tdeduc,2));
					$tentero = substr($tmonto,0,strlen($tmonto)-3);
					$tentero = str_repeat('0',13-strlen($tentero)).$tentero;
					$tdecimal = substr($tmonto,strlen($tmonto)-2,2);
					echo $tcuenta.' '.$nacion.str_repeat('0',10-strlen($tcedula)).$tcedula.' '.$tentero.$tdecimal.' '.$tnombre.'<br>';					
					$tasig=($row['tipo']=='A'?$row['monto']:0);
					$tdeduc=($row['tipo']=='D'?$row['monto']:0);
					$tnombre=trim(substr(trim($row['nombres']).' '.trim($row['apellidos']),0,39)).str_repeat('&nbsp;',39-strlen(trim(substr(trim($row['nombres']).' '.trim($row['apellidos']),0,39)))).'.';
					$tcuenta=$row['cuenta'];
					$tbanco=trim($row['banco']);
					$nacion=($row['nacionalidad'] != 'E' ? 'V' : 'E');
				}	
				if ($tbanco=='6') {
					$tmonto = str_replace(",","",number_format($tasig-$tdeduc,2));
					$tentero = substr($tmonto,0,strlen($tmonto)-3);
					$tentero = str_repeat('0',10-strlen($tentero)).$tentero;
					$tdecimal = substr($tmonto,strlen($tmonto)-2,2);
					$tmonto=$tentero.$tdecimal;					
					echo '0884'.$tmonto.$tcuenta.str_repeat('0',10-strlen($tcedula)).$tcedula.'00000000<br>';				
					$tasig=($row['tipo']=='A'?$row['monto']:0);
					$tdeduc=($row['tipo']=='D'?$row['monto']:0);
					$tcedula=$row['cedula'];
					$tbanco=trim($row['banco']);
					$tcuenta=$row['cuenta'];
				}	
				$tcedula=$row['cedula'];
				$tlinea++;
			}
		}
		if ($entrobanco==1) {
			if ($tbanco=='1') {
				$tmonto = str_replace(",","",number_format($tasig-$tdeduc,2));
				$tentero = substr($tmonto,0,strlen($tmonto)-3);
				$tentero = str_repeat('0',13-strlen($tentero)).$tentero;
				$tdecimal = substr($tmonto,strlen($tmonto)-2,2);
				echo $tcuenta.' '.$nacion.str_repeat('0',10-strlen($tcedula)).$tcedula.' '.$tentero.$tdecimal.' '.$tnombre.'<br>';
			}
			if ($tbanco=='6') {
				$tmonto = str_replace(",","",number_format($tasig-$tdeduc,2));
				$tentero = substr($tmonto,0,strlen($tmonto)-3);
				$tentero = str_repeat('0',10-strlen($tentero)).$tentero;
				$tdecimal = substr($tmonto,strlen($tmonto)-2,2);
				$tmonto=$tentero.$tdecimal;					
				echo '0884'.$tmonto.$tcuenta.str_repeat('0',10-strlen($tcedula)).$tcedula.'00000000<br>';				
				
				$tmonto = str_replace(",","",number_format($ttasig-$ttdeduc,2));
				$tentero = substr($tmonto,0,strlen($tmonto)-3);
				$tentero = str_repeat('0',15-strlen($tentero)).$tentero;
				$tdecimal = substr($tmonto,strlen($tmonto)-2,2);
				$tmonto=$tentero.$tdecimal;					
				echo '01750159310072196023'.$tfecha.$tmonto.str_repeat('0',4-strlen($tlinea)).$tlinea.'<br>';									
			}	
		} else echo "<font color=#DD0044 size=3>**** Banco No posee definici&oacute;n de Archivo Texto...... LLame a CONSULTARH *****</font>";
		
	} else echo "<font color=#DD0044 size=3>**** Opci&oacute;n Valida solo para Forma de Pago: Deposito Bancario......Verifique *****</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,'Nómina: '.$_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 Pagos':$_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=mysql_query("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=mysql_query($queryx) or die ($queryx.mysql_error());
		}
		$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=mysql_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=mysql_query("select nombres,apellidos,sso from personal where id='".$_SESSION['id_validar']."' and codigo=".$tcedula );
				if (mysql_num_rows($consul1)<>0) {
					$row1=mysql_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=mysql_query("select nombres,apellidos,sso from personal where id='".$_SESSION['id_validar']."' and codigo=".$tcedula );
				if (mysql_num_rows($consul1)<>0) {
					$row1=mysql_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,'Nómina: '.$_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 Pagos':$_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=mysql_query("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=mysql_query($queryx) or die ($queryx.mysql_error());
		}
		$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=mysql_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=mysql_query("select nombres,apellidos,sso from personal where id='".$_SESSION['id_validar']."' and codigo=".$tcedula );
				if (mysql_num_rows($consul1)<>0) {
					$row1=mysql_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=mysql_query("select nombres,apellidos,sso from personal where id='".$_SESSION['id_validar']."' and codigo=".$tcedula );
				if (mysql_num_rows($consul1)<>0) {
					$row1=mysql_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
?>