<?session_start();
//RESTRICCIÓN DE ACCESO A TRABAJADOR (ACCESO INDIVIDUAL) 
if (isset($_SESSION['tipousuario']))
		{if ($_SESSION['tipousuario']=='1')
		header ('location:menu_personal.php');
		}
if  (trim($_SESSION['nombre_validar'])=='') header ('location:index.php');
		include ("fphp.php");
		$enlace=cargar_conexion();
		$detalle=$_REQUEST["detalle"];
		$pago=$_REQUEST["pago"];
	
		/////////////////////////////////////////////// imprimir PAYROLL
		$consulta=mysql_query("select * from empresa where id='".$_SESSION['id_validar']."' ");
		if (mysql_num_rows($consulta)!=0){
			$row=mysql_fetch_array($consulta);
			$_POST['empresal']=$_SESSION['empresa_validar'];
			$_POST['pie']=$row['pie'];
			$_POST['derecho']=$row['derecho'];
			$_POST['encabeza']=$row['encabeza'];
		}   

		$query = "select * from utilidades where detalle='".$detalle."' and id='".$_SESSION['id_validar']."' ";
		$consulta = mysql_query($query) or die ("no se pudo realizar la consulta...");	
		$row=mysql_fetch_array($consulta);
		$_POST['subtitulo']=$row['detalle'];
		
		require('fpdf.php');
		class PDF extends FPDF {
		function Header()
		{
	    $this->Image($_SESSION['logo_validar'],10,10,40,20);
	    $this->SetFont('arial','',12);
		$this->Ln(4);
	    $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,1,'L');
	    $this->Cell(0,5,'Hora: '.hora(),0,1,'L');
		$this->SetFont('arial','B',12); 
		$this->Ln(5);
		$this->Cell(0,0,'Reporte de Pago de Bonificación de Fin de Año (Utilidades)',0,1,'C');$this->Ln(5);
		$this->Cell(0,0,$_POST['subtitulo'],0,1,'C');$this->Ln(5);
		$this->SetFont('arial','',10); 
	    $header=array('Cod.','Cedula','Nombres y Apellidos','Dias a Pagar','Monto','INCE','Total Bs.');
	    $this->SetFillColor(224,235,255);
	    $this->SetTextColor(0);
	    $this->SetDrawColor(128,0,0);
	    $this->SetLineWidth(.3);
	    $this->SetFont('','');
		$this->SetFont('arial','B',8);
	    $w=array(10,15,55,25,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: '.$_SESSION['nombre_validar'].' - Página '.$this->PageNo().'/{nb} - Derechos: '.$_POST['derecho'],0,0,'C');
		}
		}
		//Cuerpo ///////////////////////////////
		$pdf=new PDF($orientacion='P',$unit='mm',$format='letter');
		$pdf->AddPage();
		$pdf->AliasNbPages();
		$pdf->SetFont('Arial','',8);
		$pdf->SetFillColor(224,235,255);
		$pdf->SetTextColor(0);
		$query = "select * from utilidades where id='".$_SESSION['id_validar']."' and fecha='".$pago."' order by cedula";
		$consulta = mysql_query($query) or die ("no se pudo realizar la consulta...");	
		$linea=0;
		$color=0;
		$tasig=0;
		$tdeduc=0;
		$bandera=0;
		$ttasig=0; $ttdeduc=0;
		while($row=mysql_fetch_array($consulta)) {
			$ttasig+=$row['monto'];
			$ttdeduc+=($row['monto']*$row['ince']/100);
			$tced=$row['cedula'];
			$tpor=$row['ince'];
			$tmon=$row['monto'];
			$tcan=$row['cantidad'];
			$tnom="";
			$consul1=mysql_query("select nombres,apellidos,sso from personal where id='".$_SESSION['id_validar']."' and codigo='".$tced."'" );
			if (mysql_num_rows($consul1)<>0) {
				$row1=mysql_fetch_array($consul1);
				$tnom=trim($row1['sso'])." ".trim($row1['nombres']).',  '.trim($row1['apellidos']);
			}
			$linea++;
			$pdf->cell(10,5,$linea,0,0,'C',$color);
			$pdf->cell(15,5,$tced,0,0,'',$color);
			$pdf->cell(55,5,$tnom,0,0,'',$color);
			$pdf->cell(25,5,number_format($tcan,2),0,0,'R',$color);
			$pdf->cell(30,5,number_format($tmon,2),0,0,'R',$color);
			$pdf->cell(30,5,number_format($tmon*$tpor/100,2),0,0,'R',$color);
			$pdf->cell(30,5,number_format($tmon+($tmon*$tpor/100),2),0,1,'R',$color);
			$color=!$color;
		}
		$pdf->Cell(195,0,'',1,1,'C'); $pdf->ln(1);
		$pdf->cell(105,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(195,0,'',1,1,'C'); $pdf->ln(1); 
		$pdf->Cell(195,0,'',1,1,'C'); 
		$pdf->Output();
		mysql_close($enlace);
?>