<?
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=mysqli_query($enlace,"select * from empresa where id='".$_SESSION['id_validar']."' ");
		if (mysqli_num_rows($consulta)!=0){
			$row=mysqli_fetch_array($consulta);
			$_POST['empresal']=$_SESSION['empresa_validar'];
			$_POST['pie']=$row['pie'];
			$_POST['derecho']=$row['derecho'];
			$_POST['encabeza']=$row['encabeza'];
		}

		$query = "select * from pagos_bono_alimen where detalle='".$detalle."' and id='".$_SESSION['id_validar']."' ";
		$consulta = mysqli_query($enlace,$query) or die ("no se pudo realizar la consulta...");
		$row=mysqli_fetch_array($consulta);
		$_POST['subtitulo']=$row['detalle'];

		require('fpdf.php');
		class PDF extends FPDF {
		function Header()
		{
	    $this->Image($_SESSION['logo_validar'],10,10,30,30);
	    $this->SetFont('arial','B',11);
		$this->Ln(4);
	    $this->Cell(0,5,$_POST['empresal'],0,1,'R');
		$this->SetFont('arial','',7);
		$this->Cell(0,5,$_POST['encabeza'],0,1,'R');
		$this->Ln(5);
		$this->SetFont('arial','',9);
	    $this->Cell(0,5,'Fecha: '.hoy(),0,1,'R');
		$this->SetFont('arial','',7);
	    $this->Cell(0,5,'Hora: '.hora(),0,1,'R');
		$this->SetFont('arial','B',12);
		$this->Ln(5);
		$this->Cell(0,0,'REPORTE DE PAGO DE BONIFICACION ESPECIAL',0,1,'C');$this->Ln(5);
		$this->SetFont('arial','',10);
		$this->Cell(0,0,utf8_decode($_POST['subtitulo']),0,1,'C');$this->Ln(5);
		$this->SetFont('arial','',10);

	    $header=array('Cod.','Cedula','Nombres y Apellidos','Tipo','Concepto','Cantidad','Calculo','Asig. Bs.','Ded. Bs.');
	    $w=array(10,15,35,10,45,20,20,20,20);

	    $this->SetFillColor(70,77,119);
			$this->SetTextColor(255);
			$this->SetDrawColor(255,255,255);
			$this->SetLineWidth(.5);
	    $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: '.$_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','',7);
		$pdf->SetFillColor(238,239,243);
		$pdf->SetTextColor(0);

		$query = "select * from pagos_bono_alimen where detalle='".$detalle."' and id='".$_SESSION['id_validar']."' and fecha='".$pago."' order by cedula, concepto ASC";
		$consulta = mysqli_query($enlace,$query) or die ("no se pudo realizar la consulta...");
		$linea=0;
		$color=0;
		$tasig=0;
		$tusd=0;
		$tdedu=0;
		$bandera=0;
		$ttasig=0;
		$ttdedu=0;
		$t_tusd=0;
		$tced='';
		while($row=mysqli_fetch_array($consulta)) {
			//$ttasig+= ($row['concepto']=='7004'?$row['monto']:0);////TOTAL GENERAL CESTATICKET A PAGAR
			$ttdedu+= ($row['concepto']=='7003'?$row['monto']:0);////TOTAL GENERAL BONO ALIMENTACION A PAGAR
			$t_tusd+= (($row['concepto']=='7014' || $row['concepto']=='7015')?$row['monto']:0);////TOTAL GENERAL BONO ALIMENTACION A PAGAR

			$tnom="";$tcedx='';
			if ($tced!=$row['cedula']) {
				if ($linea>0) {
					$pdf->Cell(195,0,'',1,1,'C'); $pdf->ln(1);
					//$pdf->cell(155,5,'Cestaticket a pagar en Bs.',0,0,'R');
					//$pdf->cell(20,5,number_format($tasig,2) ,0,0,'R');
					//$pdf->cell(20,5,'' ,0,1,'R');
					//$pdf->cell(155,5,'Bono a pagar en Bs.',0,0,'R');
					//$pdf->cell(20,5,number_format($tdedu,2) ,0,0,'R');
					$pdf->cell(20,5,'',0,1,'R');
					$pdf->cell(155,5,'Total a pagar en $ (USD).',0,0,'R');
					$pdf->cell(20,5,number_format($tusd,2) ,0,0,'R');
					$pdf->cell(20,5,'',0,1,'R');
					$pdf->ln(5);
					$pdf->Cell(195,0,'',1,1,'C'); $pdf->ln(1);
					$color=0;
					$tasig=0;
					$tdedu=0;
					$tusd=0;
				}
				$tced=$row['cedula'];
				$tcedx=$row['cedula'];
				$consul1=mysqli_query($enlace,"select nombres,apellidos,sso from personal where id='".$_SESSION['id_validar']."' and codigo='".$tced."'" ) or die($consul1.mysqli_error($enlace));
				if (mysqli_num_rows($consul1)<>0) {
					$row1=mysqli_fetch_array($consul1);
					//$tnom=trim($row1['sso'])." ".trim($row1['nombres']).',  '.trim($row1['apellidos']);
					$tnom=trim($row1['nombres']).',  '.trim($row1['apellidos']);
				}
			}

			$tasig+= ($row['concepto']=='7004'?$row['monto']:0);////Monto a pagar cestticket por trabajador
			$tdedu+= ($row['concepto']=='7009'?$row['monto']:0);////Monto a pagar Bono Alimentaci�n por trabajador
			$tusd+=  (($row['concepto']=='7003' )?$row['monto']:0);////Monto a pagar en USD por trabajador
			$linea++;
			$pdf->cell(10,5,$row['concepto'],0,0,'C',$color);
			$pdf->cell(15,5,$tcedx,0,0,'',$color);
			$pdf->cell(35,5,$tnom,0,0,'',$color);
			$pdf->cell(10,5,$row['tipo_concepto'],0,0,'C',$color);
			$pdf->cell(45,5,substr($row['desconcepto'],0,40),0,0,'L',$color);
			$pdf->cell(20,5,number_format($row['cantidad'],2),0,0,'R',$color);
			$pdf->cell(20,5,($row['tipo_concepto']=='R'?number_format($row['monto'],2):''),0,0,'R',$color);
			$pdf->cell(20,5,($row['tipo_concepto']=='A'?number_format($row['monto'],2):''),0,0,'R',$color);
			$pdf->cell(20,5,($row['tipo_concepto']=='D'?number_format($row['monto'],2):''),0,1,'R',$color);
			$color=!$color;
		}
		$pdf->Cell(195,0,'',1,1,'C'); $pdf->ln(1);
		//$pdf->cell(155,5,'Cestaticket a pagar en Bs.',0,0,'R');
		//$pdf->cell(20,5,number_format($tasig,2) ,0,0,'R');
		//$pdf->cell(20,5,'',0,1,'R');
		//$pdf->cell(155,5,'Bono a pagar en Bs.',0,0,'R');
		//$pdf->cell(20,5,number_format($tdedu,2) ,0,0,'R');
		$pdf->cell(20,5,'' ,0,1,'R');
		$pdf->cell(155,5,'Total a pagar en $ (USD).',0,0,'R');
		$pdf->cell(20,5,number_format($tusd,2) ,0,0,'R');
		$pdf->cell(20,5,'' ,0,1,'R');

		$pdf->Cell(195,0,'',1,1,'C');
		$pdf->ln(5);
		$pdf->SetFont('Arial','',9);
		//$pdf->cell(155,5,'TOTAL CESTATICKET (Bs.)',0,0,'R');
		//$pdf->cell(20,5,'Bs. '.number_format($ttasig,2) ,0,0,'R');
		//$pdf->cell(20,5,'' ,0,1,'R');
		$pdf->cell(155,5,'TOTAL BONIFICACION (Bs.)',0,0,'R');
		$pdf->cell(20,5,'Bs. '.number_format($ttdedu,2) ,0,1,'R');
		$pdf->Cell(195,0,'',0,1,'C');
		$pdf->cell(155,5,'TOTAL PAGOS EN $ (USD.)',0,0,'R');
		$pdf->cell(20,5,'$. '.number_format($t_tusd,2),0,1,'R');
		$pdf->Cell(195,0,'',1,1,'C');
		$pdf->ln(1);
		$pdf->Cell(195,0,'',1,1,'C');
		$pdf->Output();
		mysqli_close($enlace);
?>
