<?php
session_start();





require_once('fpdf.php');
class PDF extends FPDF{
	function Header()
{ 

}
function Footer()
{
    $this->SetY(15);
    $this->SetFont('Arial','I',12);
}
}


 $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'];

$result=mysqli_query($connect, "select * from financiero where forma_pago <> 6 and mov_contable=2 and fecha_movimiento between '$inicial' and '$final' order by fecha_movimiento, forma_pago asc ");

$result2=mysqli_query($connect, "select * from financiero where mov_contable=1 and fecha_movimiento between '$inicial' and '$final' order by fecha_movimiento,  forma_pago asc ");

$result3=mysqli_query($connect, "SELECT mov_contable, forma_pago, SUM(monto) as monto1 FROM financiero 
  WHERE mov_contable=1 and fecha_movimiento between '$inicial' and '$final' GROUP by forma_pago, mov_contable order by mov_contable");

$se="SELECT mov_contable, forma_pago, SUM(monto) as monto1 FROM financiero 
  WHERE mov_contable=2 and fecha_movimiento between '$inicial' and '$final' GROUP by forma_pago, mov_contable order by mov_contable";
//echo json_encode($se);


    $pdf = new PDF('P','mm','A4');
    $pdf->SetMargins(12,12,12);
    $pdf->SetAutoPageBreak(true,29);
    $pdf->AddPage();

     
 $pdf->Image('logo.png',70,15, 65, 40);


    $pdf->SetFillColor(102,178,255);
    $pdf->SetFont('Arial','B',8.4);
    $pdf->SetXY(10, 45);
 
    $pdf->SetFont('Arial','B',12);
    $pdf->Cell(0,7,'CONTROL GASTOS E INGRESOS SEMANAL DE RBL C.A.','',1,'C');
       $pdf->SetFont('Arial','B',10);
    $pdf->Ln(2);
    $pdf->Cell(0,7,'SEMENA DEL: '.$inicial.' AL: '.$final.'','',1,'C');
    $pdf->Ln(1);
    $pdf->SetFont('Arial','B',8.4);
 $pdf->Cell(0,7,'INGRESOS:','',1,'C');
    $pdf->Cell(13,7,utf8_decode('# Mov.'),'LTRB',0,'C',true);
    $pdf->Cell(23,7,utf8_decode('Fecha Mov.'),'LTRB',0,'C',true);
    $pdf->Cell(93,7,utf8_decode('Denominación'),'LTRB',0,'C',true);
    $pdf->Cell(33,7,utf8_decode('Monto'),'LTRB',0,'C',true);
    $pdf->Cell(23,7,utf8_decode('Tipo Pago:'),'LTRB',1,'C',true);
$total_total='';
 while($row2 = mysqli_fetch_array($result2))
{  

 $id = $row2['id'];
 $fecha_movimiento = $row2['fecha_movimiento'];
 $monto = $row2['monto'];
 $denominacion = $row2['denominacion'];
 $forma_pago = $row2['forma_pago'];



 $pdf->Cell(13,7,$id,'LTRB',0,'C');
 $pdf->Cell(23,7,$fecha_movimiento,'LTRB',0,'C');
 $pdf->Cell(93,7,$denominacion,'LTRB',0,'C');
 $pdf->Cell(33,7,number_format($monto,2, ',', '.'),'LTRB',0,'C');
  $pdf->SetFont('Arial','B',6);
 if ($forma_pago==1) {
 $pdf->Cell(23,7,'EFECTIVO','LTRB',1,'C');
 }if ($forma_pago==2) {
 $pdf->Cell(23,7,'TRANSFERENCIA','LTRB',1,'C');
 }if ($forma_pago==3) {
 $pdf->Cell(23,7,'CHEQUE','LTRB',1,'C');
 }if ($forma_pago==4) {
 $pdf->Cell(23,7,'DEPOSITO','LTRB',1,'C');
 }if ($forma_pago==5) {
 $pdf->Cell(23,7,'PUNTO DE VENTA','LTRB',1,'C');
 }
 $pdf->SetFont('Arial','B',8.4);
   $total_total+=$monto;
}
    $pdf->Cell(13,7,'','',0,'C',true);
    $pdf->Cell(23,7,'','',0,'C',true);
    $pdf->Cell(93,7,'TOTALES:','',0,'R',true);
    $pdf->Cell(33,7,number_format($total_total,2, ',', '.'),'LTRB',0,'C',true);
    $pdf->Cell(23,7,'','L',1,'C',true);






 $pdf->SetFont('Arial','B',8.4);
    $pdf->Cell(0,7,'GASTOS:','',1,'C');
    $pdf->Cell(13,7,utf8_decode('# Mov.'),'LTRB',0,'C',true);
    $pdf->Cell(23,7,utf8_decode('Fecha Mov.'),'LTRB',0,'C',true);
    $pdf->Cell(93,7,utf8_decode('Denominación'),'LTRB',0,'C',true);
    $pdf->Cell(33,7,utf8_decode('Monto'),'LTRB',0,'C',true);
    $pdf->Cell(23,7,utf8_decode('Tipo Pago:'),'LTRB',1,'C',true);
   $total_total2=''; 
 while($row = mysqli_fetch_array($result))
{  

 $id = $row['id'];
 $fecha_movimiento = $row['fecha_movimiento'];
 $monto = $row['monto'];
 $denominacion = $row['denominacion'];
 $forma_pago = $row['forma_pago'];


 $pdf->Cell(13,7,$id,'LTRB',0,'C');
 $pdf->Cell(23,7,$fecha_movimiento,'LTRB',0,'C');
 $pdf->Cell(93,7,$denominacion,'LTRB',0,'C');
 $pdf->Cell(33,7,number_format($monto,2, ',', '.'),'LTRB',0,'C');
  $pdf->SetFont('Arial','B',6);
 if ($forma_pago==1) {
 $pdf->Cell(23,7,'EFECTIVO','LTRB',1,'C');
 }if ($forma_pago==2) {
 $pdf->Cell(23,7,'TRANSFERENCIA','LTRB',1,'C');
 }if ($forma_pago==3) {
 $pdf->Cell(23,7,'CHEQUE','LTRB',1,'C');
 }if ($forma_pago==4) {
 $pdf->Cell(23,7,'DEPOSITO','LTRB',1,'C');
 }if ($forma_pago==5) {
 $pdf->Cell(23,7,'PUNTO DE VENTA','LTRB',1,'C');
 }
 $pdf->SetFont('Arial','B',8.4);
   $total_total2+=$monto;
}

 $pdf->Cell(13,7,'','',0,'C',true);
    $pdf->Cell(23,7,'','',0,'C',true);
    $pdf->Cell(93,7,'TOTALES:','',0,'R',true);
    $pdf->Cell(33,7,number_format($total_total2,2, ',', '.'),'LTRB',0,'C',true);
    $pdf->Cell(23,7,'','L',1,'C',true);

$pdf->Ln(3);
$result99=mysqli_query($connect, "select * from financiero where mov_contable=2 and forma_pago=6 and fecha_movimiento between '$inicial' and '$final'");


 $pdf->SetFont('Arial','B',8.4);
    $pdf->Cell(0,7,'MOVIMIENTOS ESPECIALES:','',1,'C');
    $pdf->Cell(13,7,utf8_decode('# Mov.'),'LTRB',0,'C',true);
    $pdf->Cell(23,7,utf8_decode('Fecha Mov.'),'LTRB',0,'C',true);
    $pdf->Cell(93,7,utf8_decode('Denominación'),'LTRB',0,'C',true);
    $pdf->Cell(33,7,utf8_decode('Monto'),'LTRB',0,'C',true);
    $pdf->Cell(23,7,utf8_decode('Tipo Pago:'),'LTRB',1,'C',true);
 $total_total2=''; 
 while($row = mysqli_fetch_array($result99))
{  

 $id = $row['id'];
 $fecha_movimiento = $row['fecha_movimiento'];
 $monto = $row['monto'];
 $denominacion = $row['denominacion'];
 $forma_pago = $row['forma_pago'];


 $pdf->Cell(13,7,$id,'LTRB',0,'C');
 $pdf->Cell(23,7,$fecha_movimiento,'LTRB',0,'C');
 $pdf->Cell(93,7,$denominacion,'LTRB',0,'C');
 $pdf->Cell(33,7,number_format($monto,2, ',', '.'),'LTRB',0,'C');
  $pdf->SetFont('Arial','B',6);
 if ($forma_pago==1) {
 $pdf->Cell(23,7,'EFECTIVO','LTRB',1,'C');
 }if ($forma_pago==2) {
 $pdf->Cell(23,7,'TRANSFERENCIA','LTRB',1,'C');
 }if ($forma_pago==3) {
 $pdf->Cell(23,7,'CHEQUE','LTRB',1,'C');
 }if ($forma_pago==4) {
 $pdf->Cell(23,7,'DEPOSITO','LTRB',1,'C');
 }if ($forma_pago==5) {
 $pdf->Cell(23,7,'PUNTO DE VENTA','LTRB',1,'C');
 }if ($forma_pago==6) {
 $pdf->Cell(23,7,'MOVIMIENTO ESP.','LTRB',1,'C');
 }
 $pdf->SetFont('Arial','B',8.4);
   $total_total2+=$monto;
}


 $pdf->Cell(13,7,'','',0,'C',true);
    $pdf->Cell(23,7,'','',0,'C',true);
    $pdf->Cell(93,7,'TOTALES:','',0,'R',true);
    $pdf->Cell(33,7,number_format($total_total2,2, ',', '.'),'LTRB',0,'C',true);
    $pdf->Cell(23,7,'','L',1,'C',true);



$pdf->Ln(1);
//echo json_encode($cosa);






$pdf->AddPage();

$pdf->SetMargins(12,12,12);
$pdf->SetAutoPageBreak(true,29);










 $pdf->SetFont('Arial','B',8.4);
    $pdf->Ln(2);
    $pdf->Cell(185,7,'TOTALES INGRESOS:','',1,'C',true);
    $pdf->Cell(37,7,utf8_decode('EFECTIVO'),'LTRB',0,'C');
    $pdf->Cell(37,7,utf8_decode('TRANSFERENCIA'),'LTRB',0,'C');
    $pdf->Cell(37,7,utf8_decode('CHEQUE'),'LTRB',0,'C');
    $pdf->Cell(37,7,utf8_decode('DEPOSITO'),'LTRB',0,'C');
    $pdf->Cell(37,7,utf8_decode('PUNTO DE VENTA'),'LTRB',1,'C');
 

$monto1=[];
   while($row3 = mysqli_fetch_array($result3))
{  

 $mov_contable = $row3['mov_contable'];
 $forma_pago = $row3['forma_pago'];
 $monto1[] = $row3['monto1'];

}

     $pdf->Cell(37,7,number_format($monto1[0],2, ',', '.'),'LTRB',0,'C');

     $pdf->Cell(37,7,number_format($monto1[1],2, ',', '.'),'LTRB',0,'C');

     $pdf->Cell(37,7,number_format($monto1[2],2, ',', '.'),'LTRB',0,'C');

     $pdf->Cell(37,7,number_format($monto1[3],2, ',', '.'),'LTRB',0,'C');

     $pdf->Cell(37,7,number_format($monto1[4],2, ',', '.'),'LTRB',1,'C');



$result4=mysqli_query($connect, "SELECT mov_contable, forma_pago, SUM(monto) as monto1 FROM financiero 
  WHERE  mov_contable=2 and  fecha_movimiento between '$inicial' and '$final' GROUP by forma_pago, mov_contable order by forma_pago asc");

$cosa=[];

   while($row4 = mysqli_fetch_array($result4))
{  

 $mov_contable4 = $row4['mov_contable'];
 $forma_pago4 = $row4['forma_pago'];
 $cosa[] = $row4['monto1'];

}


     $pdf->Cell(185,7,'TOTALES GASTOS:','',1,'C', true);
     $pdf->Ln(1);

     $pdf->Cell(37,7,number_format($cosa[0],2, ',', '.'),'LTRB',0,'C');

     $pdf->Cell(37,7,number_format($cosa[1],2, ',', '.'),'LTRB',0,'C');

     $pdf->Cell(37,7,number_format($cosa[2],2, ',', '.'),'LTRB',0,'C');

     $pdf->Cell(37,7,number_format($cosa[3],2, ',', '.'),'LTRB',0,'C');

     $pdf->Cell(37,7,number_format($cosa[4],2, ',', '.'),'LTRB',1,'C');


$pdf->Ln(1);

$result99=mysqli_query($connect, "SELECT mov_contable, forma_pago, SUM(monto) as monto1 FROM financiero 
  WHERE mov_contable=2 and forma_pago=6 and  fecha_movimiento between '$inicial' and '$final'  GROUP by forma_pago, mov_contable order by forma_pago asc");

   while($row99 = mysqli_fetch_array($result99)){  
     $mont99 = $row99['monto1'];  }

$pdf->Cell(185,7,'MOVIMIENTOS ESPECIALES DE EFECTIVO:','',1,'C',true);
     $pdf->Ln(1);

     $pdf->Cell(37,7,number_format($mont99,2, ',', '.'),'LTRB',0,'C');

     $pdf->Cell(37,7,'','LTRB',0,'C');

     $pdf->Cell(37,7,'','LTRB',0,'C');

     $pdf->Cell(37,7,'','LTRB',0,'C');

     $pdf->Cell(37,7,'','LTRB',1,'C');
//echo json_encode($cosa);
     $pdf->Ln(1);

     $pdf->Cell(185,7,'DISPONIBILIDADES:','',1,'C', true);
     $pdf->Ln(1);

     $pdf->Cell(37,7,number_format($monto1[0]-$cosa[0]-$mont99,2, ',', '.'),'LTRB',0,'C');

     $pdf->Cell(37,7,number_format($monto1[1]-$cosa[1]+$mont99,2, ',', '.'),'LTRB',0,'C');

     $pdf->Cell(37,7,number_format($monto1[2]-$cosa[2],2, ',', '.'),'LTRB',0,'C');

     $pdf->Cell(37,7,number_format($monto1[3]-$cosa[3],2, ',', '.'),'LTRB',0,'C');

     $pdf->Cell(37,7,number_format($monto1[4]-$cosa[4],2, ',', '.'),'LTRB',1,'C');


   $pdf->Ln(1);






$result11=mysqli_query($connect, "SELECT mov_contable,  SUM(monto) as monto1 FROM financiero 
  WHERE mov_contable=1  and cuenta_bancaria=1 and fecha_movimiento between '$inicial' and '$final' 
  GROUP by  mov_contable ");
$cosa=[];
while($row11 = mysqli_fetch_array($result11)){  
$cosa[] = $row11['monto1']; }



$result22=mysqli_query($connect, "SELECT mov_contable,  SUM(monto) as monto1 FROM financiero 
  WHERE mov_contable=1  and cuenta_bancaria=2 and fecha_movimiento between '$inicial' and '$final' 
  GROUP by  mov_contable ");
$cosa22=[];
while($row22 = mysqli_fetch_array($result22)){  
$cosa22[] = $row22['monto1']; }


$result33=mysqli_query($connect, "SELECT mov_contable,  SUM(monto) as monto1 FROM financiero 
  WHERE mov_contable=1  and cuenta_bancaria=3 and fecha_movimiento between '$inicial' and '$final' 
  GROUP by  mov_contable ");
$cosa33=[];
while($row33 = mysqli_fetch_array($result33)){  
$cosa33[] = $row33['monto1']; }






$result44=mysqli_query($connect, "SELECT mov_contable,  SUM(monto) as monto1 FROM financiero 
  WHERE mov_contable=2  and cuenta_bancaria=1 and fecha_movimiento between '$inicial' and '$final' 
  GROUP by  mov_contable ");
$cosa44=[];
while($row44 = mysqli_fetch_array($result44)){  
$cosa44[] = $row44['monto1']; }



$result55=mysqli_query($connect, "SELECT mov_contable,  SUM(monto) as monto1 FROM financiero 
  WHERE mov_contable=2  and cuenta_bancaria=2 and fecha_movimiento between '$inicial' and '$final' 
  GROUP by  mov_contable ");
$cosa55=[];
while($row55 = mysqli_fetch_array($result55)){  
$cosa55[] = $row55['monto1']; }


$result66=mysqli_query($connect, "SELECT mov_contable,  SUM(monto) as monto1 FROM financiero 
  WHERE mov_contable=2  and cuenta_bancaria=3 and fecha_movimiento between '$inicial' and '$final' 
  GROUP by  mov_contable ");
$cosa66=[];
while($row66 = mysqli_fetch_array($result66)){  
$cosa66[] = $row66['monto1']; }


    $pdf->Cell(185,7,'INGRESOS A LAS CUENTAS BANCARIAS:','',1,'C', true);
     $pdf->Ln(1);
    
     $pdf->Cell(61.6,7,'BANESCO, BANCO UNIVERSAL','LTRB',0,'C');

     $pdf->Cell(61.6,7,'BANCO VENEZUELA','LTRB',0,'C');

     $pdf->Cell(61.6,7,'BANCO MERCANTIL','LTRB',1,'C');



     $pdf->Cell(61.6,7,number_format($cosa[0],2, ',', '.'),'LTRB',0,'C');

     $pdf->Cell(61.6,7,number_format($cosa22[0],2, ',', '.'),'LTRB',0,'C');

     $pdf->Cell(61.6,7,number_format($cosa33[0],2, ',', '.'),'LTRB',1,'C');


$pdf->Ln(1);

    $pdf->Cell(185,7,'GASTOS DE LAS CUENTAS BANCARIAS:','',1,'C', true);
     $pdf->Ln(1);
    
     $pdf->Cell(61.6,7,'BANESCO, BANCO UNIVERSAL','LTRB',0,'C');

     $pdf->Cell(61.6,7,'BANCO VENEZUELA','LTRB',0,'C');

     $pdf->Cell(61.6,7,'BANCO MERCANTIL','LTRB',1,'C');



     $pdf->Cell(61.6,7,number_format($cosa44[0],2, ',', '.'),'LTRB',0,'C');

     $pdf->Cell(61.6,7,number_format($cosa55[0],2, ',', '.'),'LTRB',0,'C');

     $pdf->Cell(61.6,7,number_format($cosa66[0],2, ',', '.'),'LTRB',1,'C');


mysqli_close($connect);
   

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