<?php

 $db_host = 'localhost';
$db_name = 'rblcomve_inventiolite';
$db_user = 'rblcomve_root';
$db_pass = '$0WBF2agJ.G_';

$connect = new mysqli ($db_host, $db_user, $db_pass, $db_name);

$inicial=$_POST['inicial'];
$final=$_POST['final'];

require_once('fpdf.php');

$pdf = new FPDF();
$pdf->SetMargins(20, 20, 20); 
$pdf->SetAutoPageBreak(true,74);
$pdf->AddPage();


    $pdf->SetFillColor(102,178,255);
    $pdf->SetFont('Arial','B',8.4);

 $result=mysqli_query($connect, "SELECT name, rif_ci, forma_pago FROM `nomina_historica` WHERE fecha_inicio= '$inicial' and fecha_final= '$final' and cobro=2
      group by name, rif_ci, forma_pago order by rif_ci asc");

 $total_total2=''; 
 while($row = mysqli_fetch_array($result))
{  

 $id = $row['id'];
 $name = $row['name'];
 $rif_ci = $row['rif_ci'];
 $fecha_movimiento = $row['fecha_movimiento'];
 $monto = $row['monto'];
 $fecha_inicio = $row['fecha_inicio'];
 $fecha_inicio = $row['deno_transaccion'];
 $monto = $row['monto'];
 
 $forma_pago = $row['forma_pago'];





    $pdf->SetFont('Arial','B',12);
    $pdf->Cell(0,5,'RECIBO DE PAGO DE EMPLEADOS RBL C.A. / RIF: J-40386981-2','LTR',1,'C',true);
    $pdf->Cell(0,5,'DEL DIA '.$inicial.' HASTA EL DIA '.$final,'LRB',1,'C',true);
    $pdf->SetFont('Arial','B',10);
    $pdf->Cell(115,8,'EMPLEADO: '.$name,'LR',0,'L');
      $pdf->SetFont('Arial','B',12);
    $pdf->Cell(55,8,'CEDULA/RIF: '.$rif_ci,'LR',1,'L');
    $pdf->Cell(20,5.5,'Cod. T. ','LTRB',0,'C');
    $pdf->Cell(53,5.5,'Deno. Transaccion ','LTRB',0,'C');
    $pdf->Cell(20,5.5,'Dias/H','LTRB',0,'C');
    $pdf->Cell(36.9,5.5,'Monto ','LTRB',0,'C');
    $pdf->Cell(40,5.5,'Observaciones ','LTRB',1,'C');

    $result2=mysqli_query($connect, "SELECT * FROM `nomina_historica` WHERE 
         monto<>0.00  and cobro=2 
    and fecha_inicio= '$inicial' and fecha_final= '$final' and rif_ci='$rif_ci'
     ORDER BY `cod_tipo_transaccion` ASC ");


  


     while($row2 = mysqli_fetch_array($result2))
{  
$pdf->SetFont('Arial','',12);

 $cod_transaccion = $row2['cod_transaccion'];
 $deno_transaccion = $row2['deno_transaccion'];
 $dh = $row2['dh'];
 $monto = $row2['monto'];
    $pdf->Cell(20,5.5,$cod_transaccion,'LTRB',0,'C');
    $pdf->Cell(53,5.5,utf8_decode($deno_transaccion),'LTRB',0,'C');
    $pdf->Cell(20,5.5,$dh,'LTRB',0,'C');
    $pdf->Cell(36.9,5.5,number_format($monto,2, ',', '.'),'LTRB',0,'C');
   if ($cod_transaccion==12 || $cod_transaccion==11) {
    $pdf->Cell(40,5.5,'No Suma ','LTRB',1,'C');
   }else{
     $pdf->Cell(40,5.5,' ','LTRB',1,'C');
   }
   

  }

  $result22=mysqli_query($connect, "SELECT sum(monto), rif_ci, name
    FROM `nomina_historica` WHERE
       cobro=2
     and cod_transaccion not in (12,11)
    and fecha_inicio= '$inicial' and fecha_final= '$final' and cod_tipo_transaccion=2 and rif_ci='$rif_ci' and name='$name' GROUP by rif_ci , name");

while($row22 = mysqli_fetch_array($result22)){  
 $suma_deducciones = $row22['sum(monto)'];
  }


    $result33=mysqli_query($connect, "SELECT sum(monto) as Asignaciones, rif_ci , name
        FROM `nomina_historica` WHERE
      cobro=2
    and fecha_inicio= '$inicial' and fecha_final= '$final' and cod_tipo_transaccion=1 and rif_ci='$rif_ci' GROUP by rif_ci , name ");
while($row23 = mysqli_fetch_array($result33)){  
 $suma_asignaciones = $row23['Asignaciones'];
  }


  $pdf->SetFont('Arial','B',12);
$pdf->Cell(56.8,5.5,'Total Asignaciones: ','LTRB',0,'C');
$pdf->Cell(56.8,5.5,'Total Deducciones: ','LTRB',0,'C');
$pdf->Cell(56.3,5.5,'Neto a cobrar: ','LTRB',1,'C');
$pdf->SetFont('Arial','',12);
$pdf->Cell(56.8,5.5,number_format($suma_asignaciones,2, ',', '.'),'LTRB',0,'C');
$pdf->Cell(56.8,5.5,number_format($suma_deducciones,2, ',', '.'),'LTRB',0,'C');
$pdf->Cell(56.3,5.5,number_format($suma_asignaciones-$suma_deducciones,2, ',', '.'),'LTRB',1,'C');



    if ($forma_pago==1) {
    $pdf->Cell(0,6,'Forma de Pago: EFECTIVO','LBR',1,'C');
     }if ($forma_pago==2) {
    
        $pdf->Cell(0,6,'Forma de Pago: TRANSFERENCIA','LBR',1,'C');
     }if ($forma_pago==3) {

        $pdf->Cell(0,6,'Forma de Pago: CHEQUE','LBR',1,'C');
     }if ($forma_pago==4) {

        $pdf->Cell(0,6,'Forma de Pago: DEPOSITO','LBR',1,'C');
     }
   $pdf->Cell(85,8,'Firma Empresa:____________________','LBR',0,'L');
   $pdf->Cell(85,8,'Firma Empleado:____________________ ','LBR',1,'L');
    //$pdf->Image('logo.png',30,15, 55, 10);
     $pdf->Ln(10);
   }   























































$pdf->AddPage();
$pdf->SetMargins(20, 20, 20); 
$pdf->SetAutoPageBreak(true,120);

    $pdf->SetFillColor(102,178,255);
    $pdf->SetFont('Arial','B',8.4);

 $result=mysqli_query($connect, "SELECT name, rif_ci, forma_pago FROM `nomina_historica` WHERE  fecha_inicio= '$inicial' and fecha_final= '$final' and cobro=1
      group by name, rif_ci, forma_pago order by rif_ci asc");

 $total_total2=''; 
 while($row = mysqli_fetch_array($result))
{  

 $id = $row['id'];
 $name = $row['name'];
 $rif_ci = $row['rif_ci'];
 $fecha_movimiento = $row['fecha_movimiento'];
 $monto = $row['monto'];
 $cod_transaccion = $row['cod_transaccion'];
 $deno_transaccion = $row['deno_transaccion'];
 $monto = $row['monto'];
 
 $forma_pago = $row['forma_pago'];





    $pdf->SetFont('Arial','B',12);
    $pdf->Cell(0,5,'RECIBO DE PAGO DE EMPLEADOS RBL C.A. / RIF: J-40386981-2','LTR',1,'C',true);
    $pdf->Cell(0,5,'DEL DIA '.$inicial.' HASTA EL DIA '.$final,'LRB',1,'C',true);
    $pdf->SetFont('Arial','B',10);
    $pdf->Cell(115,8,'EMPLEADO: '.$name,'LR',0,'L');
      $pdf->SetFont('Arial','B',12);
    $pdf->Cell(55,8,'CEDULA/RIF: '.$rif_ci,'LR',1,'L');
    $pdf->Cell(20,5.5,'Cod. T. ','LTRB',0,'C');
    $pdf->Cell(53,5.5,'Deno. Transaccion ','LTRB',0,'C');
    $pdf->Cell(20,5.5,'Dias/H','LTRB',0,'C'); 
    $pdf->Cell(36.9,5.5,'Monto ','LTRB',0,'C');
    $pdf->Cell(40,5.5,'Observaciones ','LTRB',1,'C');

    $result2=mysqli_query($connect, "SELECT * FROM `nomina_historica` WHERE 
         monto<>0.00  and cobro=1 and fecha_inicio= '$inicial' and fecha_final= '$final' and rif_ci='$rif_ci'
     ORDER BY `cod_transaccion` ASC ");


  


     while($row2 = mysqli_fetch_array($result2))
{  
$pdf->SetFont('Arial','',12);

 $cod_transaccion = $row2['cod_transaccion'];
 $deno_transaccion = $row2['deno_transaccion'];
 $dh = $row2['dh'];
 $monto = $row2['monto'];
    $pdf->Cell(20,5.5,$cod_transaccion,'LTRB',0,'C');
    $pdf->Cell(53,5.5,utf8_decode($deno_transaccion),'LTRB',0,'C');
    $pdf->Cell(20,5.5,$dh,'LTRB',0,'C');
    $pdf->Cell(36.9,5.5,number_format($monto,2, ',', '.'),'LTRB',0,'C');
   if ($cod_transaccion==12 || $cod_transaccion==11) {
    $pdf->Cell(40,5.5,'No Suma ','LTRB',1,'C');
   }else{
     $pdf->Cell(40,5.5,' ','LTRB',1,'C');
   }
   

  }

  $result22=mysqli_query($connect, "SELECT sum(monto), rif_ci, name
    FROM `nomina_historica` WHERE  cobro=1 and cod_transaccion not in (12,11)
    and fecha_inicio= '$inicial' and fecha_final= '$final' and cod_tipo_transaccion=2 and rif_ci='$rif_ci' and name='$name' GROUP by rif_ci , name");

while($row22 = mysqli_fetch_array($result22)){  
 $suma_deducciones2 = $row22['sum(monto)'];
  }


    $result33=mysqli_query($connect, "SELECT sum(monto) as Asignaciones, rif_ci , name
        FROM `nomina_historica` WHERE cobro=1
    and fecha_inicio= '$inicial' and fecha_final= '$final' and cod_tipo_transaccion=1 and rif_ci='$rif_ci' GROUP by rif_ci , name ");
while($row23 = mysqli_fetch_array($result33)){  
 $suma_asignaciones = $row23['Asignaciones'];
  }


  $pdf->SetFont('Arial','B',12);
$pdf->Cell(56.8,5.5,'Total Asignaciones: ','LTRB',0,'C');
$pdf->Cell(56.8,5.5,'Total Deducciones: ','LTRB',0,'C');
$pdf->Cell(56.3,5.5,'Neto a cobrar: ','LTRB',1,'C');
$pdf->SetFont('Arial','',12);
$pdf->Cell(56.8,5.5,$suma_asignaciones,'LTRB',0,'C');
$pdf->Cell(56.8,5.5,$suma_deducciones2,'LTRB',0,'C');
$pdf->Cell(56.3,5.5,number_format($suma_asignaciones-$suma_deducciones2,2, ',', '.'),'LTRB',1,'C');



    if ($forma_pago==1) {
    $pdf->Cell(0,6,'Forma de Pago: EFECTIVO','LBR',1,'C');
     }if ($forma_pago==2) {
    
        $pdf->Cell(0,6,'Forma de Pago: TRANSFERENCIA','LBR',1,'C');
     }if ($forma_pago==3) {

        $pdf->Cell(0,6,'Forma de Pago: CHEQUE','LBR',1,'C');
     }if ($forma_pago==4) {

        $pdf->Cell(0,6,'Forma de Pago: DEPOSITO','LBR',1,'C');
     }
   $pdf->Cell(85,8,'Firma Empresa:____________________','LBR',0,'L');
   $pdf->Cell(85,8,'Firma Empleado:____________________ ','LBR',1,'L');
    //$pdf->Image('logo.png',30,15, 55, 10);
     $pdf->Ln(25);
   }   

mysqli_close($connect);
   

$pdf->Output('recibosdepago.pdf','D');
?>