<?

include ('class.ezpdf.php');
include('includes/config.php');
include 'defs.php';
$pdf = new Cezpdf('A4','portrait');
$pdf->selectFont('fonts/Times-Roman.afm');
$pdf->addJpegFromFile('images/logo1.jpg',30,750,70);
//$pdf->addText(18,750,9,"MIS GENERATED REPORT");
$date1=Date("j-n-Y");
//$pdf->ezStartPageNumbers(526, 16, 10, 'right', '', 1);
$pdf->setColor(0.72, 0.72, 0.72);
$pdf->filledRectangle(220, 770, 160, 30, 'rgb');
$pdf->setColor(0,0,0);
$pdf->addText(270,780,13,"<b>(GLAKB)</b>");
$pdf->addText(235,755,12,"<b>(JOURNAL VOUCHER)</b>");
$pdf->addText(3,720,15,"___________________________________________________________________________________________________");
$pdf->ezSetDy(-105);
$header = $pdf->openObject();
$pdf->addText(20, 16, 9, "<b>Contact us @</b> Sabzal Road Block No 3 STN Colony Near Spini Road Quetta (+92 81 2873538)");
$pdf->addText(12, 30, 10, "<b>__________________________________________________________________________________________________________________</b>");

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

  $usr=$_GET['usr'];


$qer = MySQLi_Query($link, "Select MAX(vch_number) as val2 from ledgers where L_Type='JV' ");

while($rtrow = mysqli_fetch_array($qer))
                {
                $vch_number = $rtrow['val2'];
                }



                
$nResult1 = MySQLi_Query($link, "Select D_Date, vch from ledgers where vch_number='$vch_number'");

while($rstRow1 = mysqli_fetch_array($nResult1))
                {
                $ndate = $rstRow1['D_Date'];
                   $vno = $rstRow1['vch'];
                }
                   $date1=date('d-m-Y',strtotime($ndate));
                

$pdf->addText(20,725,11,"<b>Journal Voucher #</b>     $vno");
$pdf->addText(400,725,11,"<b>Voucher Date:</b>           $date1");
$nResult = MySQLi_Query($link, "select * from ledgers where vch_number='$vch_number' order by Id");
$count=0;
$one=1;
$deb=0;
$cre=0;

$data = array();
$gt_debit = 0;
$gt_credit = 0;

while($rstRow = mysqli_fetch_array($nResult))
{
    $count = $one + $count;

    $gt_debit += $rstRow['Debit'];     // accumulate debit
    $gt_credit += $rstRow['Credit'];   // accumulate credit

    $debit = number_format($rstRow['Debit'], 2);          
    $credit = number_format($rstRow['Credit'], 2);          

    $data[] = array(
        'num'  => $count,
        'md'   => $rstRow['M_Head'],
        'idd'  => $rstRow['A_Id'],
        'pgrp' => $rstRow['Code'],
        'id'   => $rstRow['Details'],
        'item' => $debit,
        'pack' => $credit
    );
}

// 👉 ADD GRAND TOTAL ROW
$data[] = array(
    'num'  => '',
    'md'   => '',
    'idd'  => '',
    'pgrp' => '',
    'id'   => '<b>Grand Total</b>',
    'item' => '<b>' . number_format($gt_debit, 2) . '</b>',
    'pack' => '<b>' . number_format($gt_credit, 2) . '</b>'
);

$cols = array(
    'num'=>'<b>S. No</b>',
    'md'=>'<b>Category</b>',
    'idd'=>'<b>Code</b>',
    'pgrp'=>'<b>Accounts Head</b>',
    'id'=>'<b>Remarks</b>',
    'item'=>'<b>Debit</b>',
    'pack'=>'<b>Credit</b>'
);

$pdf->ezTable($data,$cols,'',
    array(
        'xPos'=>20,'xOrientation'=>'right','fontSize'=>9,'width'=>680,
        'showHeadings'=>1,'shaded'=>0,'showLines'=>2,
        'cols'=>array(
            'num'=>array('justification'=>'center','width'=>38),
            'md'=>array('justification'=>'center','width'=>60),
            'idd'=>array('justification'=>'center','width'=>75),
            'pgrp'=>array('justification'=>'left','width'=>150),
            'id'=>array('justification'=>'left','width'=>132),
            'item'=>array('justification'=>'right','width'=>60),
            'pack'=>array('justification'=>'right','width'=>60)
        )
    )
);






        ob_clean();

        $pdf->ezStream();
?>
