<?php
include ('class.ezpdf.php');
include 'includes/config.php';
include 'defs.php';
$pdf = new Cezpdf('legal','landscape');
$pdf->selectFont('fonts/Times-Roman.afm');
$pdf->addJpegFromFile('images/logo.jpg',30,540,80);
$pdf->addText(18,530,9,"MIS GENERATED REPORT");
$date1=Date("j-n-Y");
$pdf->ezSetDy(-120);
$pdf->ezStartPageNumbers(950, 16, 10, 'right', '', 1);

$pdf->addText(220,540,12,"<b>BALOCHISTAN TECHNICAL EDUCATION AND VOCATIONAL TRAINING AUTHORITY (B-TEVTA)</b>");
$pdf->addText(420,525,12,"<b>(RECEIPTS AND EXPENDITURE)</b>");
$usr=$_GET['usr']; 

$head=$_POST['item3'];
$frm=$_POST['strFrom'];
$to=$_POST['strTo'];
$val=$_POST['strn'];

$frm1=date('Y-m-d',strtotime($frm));
$to1=date('Y-m-d',strtotime($to));


$nResult = MySQLi_Query($link, "delete from temp_led");


$rst = MySQLi_Query($link, "Select Details from acc_heads where Name='$head'");
while($rstRow = mysqli_fetch_array($rst))
{
$desc=$rstRow['Details'];
}
$pdf->addText(30,500,12,"<b>Account Title: </b>       $head");
$pdf->addText(30,480,12,"<b>Account Details: </b>   $desc");



 

$header = $pdf->openObject();
$pdf->addText(20, 16, 10, "<b>Contact us @</b> Balochistan Technical Education and Vocational Training Authority. 355/125-B, Jinnah Town Samungli Road, Quetta ");
$pdf->addText(20, 30, 10, "<b>__________________________________________________________________________________________________________________________________________________________________________________________________</b>");

$pdf->closeObject();
$pdf->addObject($header, "all");




if($val=='oa')
{
$pdf->addText(880,470,12,"<b>As On:</b> $date1");

$rst6 = MySQLi_Query($link, "Select * from ledgers where Code='$head' order by D_Date");
$count=0;
$one=1;
$gtot=0;
$atot=0;

while($rstRow = mysqli_fetch_array($rst6))
{
$pdes=$rstRow['Payee']." - ".$rstRow['Payee_Id'];
$count=$one+$count;
$edate=date('d-m-Y',strtotime($rstRow['D_Date']));
$totd=$rstRow['Itax']+$rstRow['Stax']+$rstRow['Bsts']+$rstRow['Otax'];
$atot=$atot+$rstRow['Debit']-$rstRow['Credit'];
$at=$bal+$atot;
$data[] = array('num'=>$count,'inv'=>$rstRow['Exp_Id'],'ehead'=>$rstRow['Exp_Head'],'name'=>$pdes,'dr'=>number_format($rstRow['Debit'],0),'gamt'=>number_format($rstRow['Gamt'], 0),'itax'=>number_format($rstRow['Itax'],0),'stax'=>number_format($rstRow['Stax'],0),'bsts'=>number_format($rstRow['Bsts'],0),'otax'=>number_format($rstRow['Otax'],0),'totd'=>number_format($totd,0),'namt'=>number_format($rstRow['Credit'],0),'atot'=>number_format($at,0), 'pmode'=>$rstRow['Pmode'], 'chq'=>$rstRow['Chq'],'dte'=>$edate);
}

$cols = array('num'=>'<b>S. No</b>','inv'=>'<b>Account-ID</b>','ehead'=>'<b>Account-Head</b>','name'=>'<b>Name of Payee</b>','dr'=>'<b>Receipts</b>','gamt'=>'<b>Gross Amount</b>','itax'=>'<b>Income Tax</b>','stax'=>'<b>Sales Tax</b>','bsts'=>'<b>BSTS</b>','otax'=>'<b>Other Deductions</b>','totd'=>'<b>Total Deductions</b>','namt'=>'<b>Net Amount</b>','atot'=>'<b>Balance</b>','pmode'=>'<b>Payment Mode</b>','chq'=>'<b>Cheque#</b>','dte'=>'<b>Date</b>');

$pdf->ezTable($data,$cols,'',
        array('xPos'=>20,'xOrientation'=>'right','fontSize' => 9,'width'=>800,'showHeadings'=>1,'shaded'=>0, 'showLines'=>2,'cols'=>array(
                'num'=>array('justification'=>'center','width'=>35),
                 'inv'=>array('justification'=>'center','width'=>55),
                  'ehead'=>array('justification'=>'left','width'=>105),
                'name'=>array('justification'=>'left','width'=>105),
                'dr'=>array('justification'=>'right','width'=>62),
                
                'gamt'=>array('justification'=>'right','width'=>62),
                   
                 'itax'=>array('justification'=>'right','width'=>50),
                
               'stax'=>array('justification'=>'right','width'=>50),
                  
                 'bsts'=>array('justification'=>'right','width'=>50),
                 'otax'=>array('justification'=>'right','width'=>55),
                 'totd'=>array('justification'=>'right','width'=>55),
                
                 'namt'=>array('justification'=>'right','width'=>62),
                   'atot'=>array('justification'=>'right','width'=>62),
                 'pmode'=>array('justification'=>'center','width'=>55),
                 'chq'=>array('justification'=>'center','width'=>55),
                 'dte'=>array('justification'=>'center','width'=>55)
                         
                 
             )));
}


if($val=='dw')
{
  $fdate=date('d-m-Y',strtotime($frm));
$tdate=date('d-m-Y',strtotime($to));

  $pdf->ezSetDy(-20);
$nResult = MySQLi_Query($link, "Select sum(Debit-Credit) as bal from ledgers where Code='$head' and D_Date<'$frm1' group by Code");
while($rstRow = mysqli_fetch_array($nResult))
{
$bal=$rstRow['bal'];
}
$bal1=number_format($bal,0);
$pdf->addText(730,460,12,"<b>For the Period: </b>     $fdate to $tdate ");

$pdf->addText(30,460,12,"<b>Opening Balance: </b> $bal1");

$rst6 = MySQLi_Query($link, "Select * from ledgers where Code='$head' and D_Date between '$frm1' and '$to1' order by D_Date");
$count=0;
$one=1;
$gtot=0;
$atot=0;

while($rstRow = mysqli_fetch_array($rst6))
{
$pdes=$rstRow['Payee']." (".$rstRow['Payee_Id'].")";
$count=$one+$count;
$edate=date('d-m-Y',strtotime($rstRow['D_Date']));
$totd=$rstRow['Itax']+$rstRow['Stax']+$rstRow['Bsts']+$rstRow['Otax'];
$atot=$atot+$rstRow['Debit']-$rstRow['Credit'];
$at=$bal+$atot;
$data[] = array('num'=>$count,'inv'=>$rstRow['Exp_Id'],'ehead'=>$rstRow['Exp_Head'],'name'=>$pdes,'dr'=>number_format($rstRow['Debit'],0),'gamt'=>number_format($rstRow['Gamt'], 0),'itax'=>number_format($rstRow['Itax'],0),'stax'=>number_format($rstRow['Stax'],0),'bsts'=>number_format($rstRow['Bsts'],0),'otax'=>number_format($rstRow['Otax'],0),'totd'=>number_format($totd,0),'namt'=>number_format($rstRow['Credit'],0),'atot'=>number_format($at,0), 'pmode'=>$rstRow['Pmode'], 'chq'=>$rstRow['Chq'],'dte'=>$edate);
}

$cols = array('num'=>'<b>S. No</b>','inv'=>'<b>Account-ID</b>','ehead'=>'<b>Account-Head</b>','name'=>'<b>Name of Payee</b>','dr'=>'<b>Receipts</b>','gamt'=>'<b>Gross Amount</b>','itax'=>'<b>Income Tax</b>','stax'=>'<b>Sales Tax</b>','bsts'=>'<b>BSTS</b>','otax'=>'<b>Other Deductions</b>','totd'=>'<b>Total Deductions</b>','namt'=>'<b>Net Amount</b>','atot'=>'<b>Balance</b>','pmode'=>'<b>Payment Mode</b>','chq'=>'<b>Cheque#</b>','dte'=>'<b>Date</b>');

$pdf->ezTable($data,$cols,'',
        array('xPos'=>20,'xOrientation'=>'right','fontSize' => 9,'width'=>800,'showHeadings'=>1,'shaded'=>0, 'showLines'=>2,'cols'=>array(
                'num'=>array('justification'=>'center','width'=>35),
                 'inv'=>array('justification'=>'center','width'=>55),
                  'ehead'=>array('justification'=>'left','width'=>105),
                'name'=>array('justification'=>'left','width'=>105),
                'dr'=>array('justification'=>'right','width'=>62),
                
                'gamt'=>array('justification'=>'right','width'=>62),
                   
                 'itax'=>array('justification'=>'right','width'=>50),
                
               'stax'=>array('justification'=>'right','width'=>50),
                  
                 'bsts'=>array('justification'=>'right','width'=>50),
                 'otax'=>array('justification'=>'right','width'=>55),
                 'totd'=>array('justification'=>'right','width'=>55),
                
                 'namt'=>array('justification'=>'right','width'=>62),
                   'atot'=>array('justification'=>'right','width'=>62),
                 'pmode'=>array('justification'=>'center','width'=>55),
                 'chq'=>array('justification'=>'center','width'=>55),
                 'dte'=>array('justification'=>'center','width'=>55)
                         
                 
             )));
}



$pdf->ezSetDy(-30);

$pdf->ezText("<b>Raheel Ghori</b>", 12, array("justification" => 'right'));
$pdf->ezSetDy(-5);
$pdf->ezText("<b>Assiatnt Accounts Officer</b>", 12, array("justification" => 'right'));


ob_clean();
$pdf->ezStream();
?>
