<?
session_start();
include("opendb.php");
include('mysqli_table.php');
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='inde.php'; </script>";
 return;
}
$bnk=$_REQUEST['bnk'];
$dfrom=$_REQUEST['dfrom'];
$dto=$_REQUEST['dto'];
$df=implode('-', array_reverse(explode('-',$dfrom)));
$dt=implode('-', array_reverse(explode('-',$dto)));


$brqry="select brname from branch where brcode='$brcode'";
$brrs=mysqli_query($db,$brqry);
$brrw=mysqli_fetch_array($brrs);
$brnchnm=$brrw[0];


$dfrm=implode('-', array_reverse(explode('-', $df)));
$dto=implode('-', array_reverse(explode('-', $dt)));


      //$pdf = new FPDF();
      $pdf = new FPDF('P','mm','A4');
      $pdf->AddPage();
      $pdf->SetFont('Arial','B',10);
      $pdf->SetFont('','B');
      $dedres1=mysqli_query($db,"select brname from branch where brcode='$brcode'") or die("er5:".mysqli_error($db));
      $br_1=mysqli_fetch_array($dedres1);
      $pdf->SetFont('','BU');
      $pdf->Cell(200,5,'KERALA KHADI & VILLAGE INDUSTRIES BOARD',0,1,'C');
      $pdf->SetFont('Arial','',11);
      $brnchnm=strtoupper($brnchnm);
                     $pdf->Cell(200,5,'CENTER NAME :'.$brnchnm,0,1,'C');
                     //$pdf->Ln(4);
       //$pdf->Ln(4);
      $pagno=1;
                     $pdf->Cell(200,5,'Bank Report '.$dfrm.' to '.$dto,0,1,'C');$pdf->Cell(20,5,'Page '.$pagno,0,1,'C');
                     $pdf->SetFont('Arial','',10);
                     $pdf->Cell(20,10,'Date.','LTR');
					 $pdf->Cell(80,10,'Bank Name','LTR');
					 $pdf->Cell(30,10,'Amount','LTR');
					 $pdf->Cell(60,10,'Narration','LTR');
                     //$pdf->Ln(4);
                     $pdf->Ln(4);
                     $pdf->Ln(4);
include_once("../opendb.php");
$mtot = 0;
$flg=1;
$sq1=mysqli_query($db,"select * from journal2 where brcode='$brcode' and date >= '$df' and date <= '$dt' order by date");
while($row1=mysqli_fetch_array($sq1))
{
  $sq=mysqli_query($db,"select * from ledger where led ='$row1[partic]' and brcode = '$brcode'");
  $row=mysqli_fetch_array($sq);
  if($row[grp]=='Bank Accounts')
  {
    $dfrm=implode('-', array_reverse(explode('-', $row1[date])));
    if($row1[dramt]>0)
	  {
		$pdf->Cell(20,6,$dfrm,'LTR',0, 'L');
		$pdf->Cell(80,6,$row1[partic],'LTR',0, 'R');
		$pdf->Cell(30,6,$row1[dramt],'LTR',0, 'R');
        $pdf->Cell(60,6,$row1[narr],'LTR',0, 'R');
		$pdf->Ln(6);
		++$flg;
		$mtot = $mtot + $row1[dramt];
		if($flg>39)
       {
         $flg = 1;
         $new_page = 1;
       }
		if($new_page==1)
          {
					 $pdf->Cell(190,0,'','LTR',0, 'R');
					 $pagno++;
					 $pdf->AddPage();
					 $pdf->Cell(20,5,'Page '.$pagno,0,1,'C');
                     $pdf->SetFont('Arial','',10);
                     $pdf->Cell(20,10,'Date.','LTR');
					 $pdf->Cell(80,10,'Bank Name','LTR');
					 $pdf->Cell(30,10,'Amount','LTR');
					 $pdf->Cell(60,10,'Narration','LTR');
                     //$pdf->Ln(4);
                     $pdf->Ln(4);
                     $pdf->Ln(4);
					 $new_page = 0;
		  }
	  }
		
  }
  
  
}

$pdf->Cell(100,5,'T O T A L','LTRB',0, 'L');
$pdf->Cell(30,5,number_format($mtot,2,'.',','),'LTRB',0, 'R');
$pdf->Cell(60,5,'','LTRB',0, 'R');
$pdf->Ln(4);
$pdf->Output();
?>
