<?php
session_start();





require_once('fpdf.php');
class PDF extends FPDF{
	function Header()
{ 
  
}
function Footer()
{
    $this->SetY(15);
    $this->SetFont('Arial','I',12);
}
}

   $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',10);
    $pdf->SetXY(10, 45);
    $pdf->Cell(17,10,utf8_decode('ID Mov.'),'LTRB',0,'C',true);
    $pdf->Cell(27,10,utf8_decode('Fecha Mov.'),'LTRB',0,'C',true);
    $pdf->Cell(73,10,utf8_decode('Denominación'),'LTRB',0,'C',true);
    $pdf->Cell(43,10,utf8_decode('Monto'),'LTRB',1,'C',true);

 





 $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 mov_contable=2 and forma_pago not in(6) and fecha_movimiento= '$inicial' ");

$result2=mysqli_query($connect, "select * from financiero where mov_contable=1 and fecha_movimiento= '$inicial' ");



     $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 DIARIO DE RBL C.A.','',1,'C');
       $pdf->SetFont('Arial','B',10);
    $pdf->Ln(3);


$fecha = $inicial;
$ano = substr($fecha, -10, 4);
$mes = substr($fecha, -5, 2);
$dia = substr($fecha, -2, 2);

$fecha2 = $querys_pdf->FECHA_BAUTISMO;
$ano2 = substr($fecha2, -10, 4);
$mes2 = substr($fecha2, -5, 2);
$dia2 = substr($fecha2, -2, 2);

if ($mes=='01'){
    $mes_le='Enero';
}elseif ($mes=='02'){
    $mes_le='Febrero';
}elseif ($mes=='03'){
    $mes_le='Marzo';
}elseif ($mes=='04'){
    $mes_le='Abril';
}elseif ($mes=='05'){
    $mes_le='Mayo';
}elseif ($mes=='06'){
    $mes_le='Junio';
}elseif ($mes=='07'){
    $mes_le='Julio';
}elseif ($mes=='08'){
    $mes_le='Agosto';
}elseif ($mes=='09'){
    $mes_le='Septiembre';
}elseif ($mes=='10'){
    $mes_le='Octubre';
}elseif ($mes=='11'){
    $mes_le='Noviembre';
}elseif ($mes=='12'){
    $mes_le='Diciembre';
}





    $pdf->Cell(0,7,'Santa Ana de Coro, '.$dia.' de '.$mes_le.' del '.$ano ,'',1,'R');
    $pdf->Ln(4);
    $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');
 }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(3);
$result99=mysqli_query($connect, "select * from financiero where mov_contable=2 and forma_pago=6 and fecha_movimiento= '$inicial' ");

 $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);

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

   while($row44 = mysqli_fetch_array($esult4)){  
     $mont11 = $row44['monto1'];  }

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

   while($row33 = mysqli_fetch_array($esult3)){  
     $mont22 = $row33['monto1'];  }

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

   while($row77 = mysqli_fetch_array($esult7)){  
     $mont33 = $row77['monto1'];  }

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

   while($row88 = mysqli_fetch_array($esult8)){  
     $mont44 = $row88['monto1'];  }

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

   while($row99 = mysqli_fetch_array($esult9)){  
     $mont55 = $row99['monto1'];  }
    $pdf->AddPage();
 $pdf->SetFont('Arial','B',8.4);
    $pdf->Ln(4);
    $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($mont11,2, ',', '.'),'LTRB',0,'C');

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

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

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

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



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

   while($row4 = mysqli_fetch_array($result4)){  
     $mont1 = $row4['monto1'];  }

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

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

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

   while($row7 = mysqli_fetch_array($result7)){  
     $mont3 = $row7['monto1'];  }

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

   while($row8 = mysqli_fetch_array($result8)){  
     $mont4 = $row8['monto1'];  }

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

   while($row9 = mysqli_fetch_array($result9)){  
     $mont5 = $row9['monto1'];  }

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


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

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

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

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

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

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


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

$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= '$inicial' 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');


$pdf->Ln(1);

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

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

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

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

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

     $pdf->Cell(37,7,number_format($mont55-$mont5,2, ',', '.'),'LTRB',1,'C');



mysqli_close($connect);
   

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