<?php
include ('class.ezpdf.php');
include 'includes/config.php';
include 'defs.php';
$pdf = new Cezpdf('A4','landscape');
$pdf->selectFont('fonts/Times-Roman.afm');
$pdf->addJpegFromFile('images/logo1.jpg',40,520,55);
$date1=Date("j-n-Y");
$pdf->ezSetDy(-90);
$pdf->ezStartPageNumbers(800, 16, 9, 'right', '', 1);
$pdf->setColor(0.72, 0.72, 0.72);
$pdf->filledRectangle(220, 805, 160, 20, 'rgb');
$pdf->setColor(0,0,0);
$pdf->addText(290,560,13,"<b>GULF LUBE AHMAD ULLAH KHAN BROTHERS</b>");
$pdf->addText(330,545,12,"<b>(SALES INVOICES WAREHOUSE-WISE)</b>");

$usr=$_GET['usr'];
$strFrom=$_POST['strFrom'];
$strTo=$_POST['strTo'];
$ware=$_POST['sman']; 





if ($strFrom=='')
{
$nResult = MySQLi_Query($link, "select MIN(Inv_Date) as dte from cust_sales");
while($rstRow = mysqli_fetch_array($nResult))
{
$strFrom=$rstRow['dte'];
}
}

$fdate=date('d-m-Y',strtotime($strFrom));
$tdate=date('d-m-Y',strtotime($strTo));



$header = $pdf->openObject();
$pdf->addText(20, 16, 10, "<b>Contact us @</b> Sabzal Road - Block No 3, STN Colony, Near Spini Road, Quetta (+92 81 2873538)");
$pdf->addText(20, 30, 10, "<b>_________________________________________________________________________________________________________________________________________________________________</b>");

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




if(!$ware)
{
$pdf->addText(20,500,11,"<b>Warehouses = </b> Karachi - Lahore - Quetta");

$pdf->addText(20,485,11,"<b>From = </b>            $fdate <b> To: </b> $tdate ");

$count=0;
$one=1;
$nResult = MySQLi_Query($link, "Select * from s_details where Inv_Date between '$strFrom' and '$strTo' order by Inv_Date, Inv_No  ");
while($rstRow = mysqli_fetch_array($nResult))
{
$tamt=$rstRow['N_Total']+$tamt;

$idate=$rstRow['Inv_Date'];
$invv=$rstRow['Inv_No'];
$idate=strtotime($idate);
$idate = date("d-m-Y", $idate);
$invDet=$rstRow['Inv_Det'];

$count=$one+$count;
 $link = "<c:alink:inv_sales1.php?inv=$invv&cust=1>$invDet</c:alink>";

    $data[] = array(
        'num'   => $count,
        'dte'   => $idate,
        'inv'   => $link,
        'cust'  => $rstRow['Customer'],
        'ware'  => $rstRow['Warehouse'],
        'tot'   => $rstRow['Total'],
        'dis'   => $rstRow['Dis'],
        'ntot'  => $rstRow['N_Total'],
        'sman1' => $rstRow['Salesman']
    );
   
}

$cols = array(
    'num'   => '<b>S. No</b>',
    'dte'   => '<b>Date</b>',
    'inv'   => '<b>Invoice#</b>',
    'cust'  => '<b>Customer Name</b>',
    'ware'  => '<b>Warehouse</b>',
    'tot'   => '<b>Total Amount</b>',
    'dis'   => '<b>Discount</b>',
    'ntot'  => '<b>Net Amount</b>',
    'sman1' => '<b>Salesman</b>'
);

$pdf->ezTable(
    $data,
    $cols,
    '',
    array(
        'xPos' => 20,
        'xOrientation' => 'right',
        'fontSize' => 10,
        'width' => 680,
        'showHeadings' => 1,
        'shaded' => 0,
        'showLines' => 2,
        'cols' => array(
            'num' => array('justification' => 'center', 'width' => 40),
            'dte' => array('justification' => 'center', 'width' => 65),
            'inv' => array('justification' => 'center', 'width' => 80),
            'cust' => array('justification' => 'left', 'width' => 210),
            'ware' => array('justification' => 'center', 'width' => 70),
            'tot' => array('justification' => 'right', 'width' => 75),
            'dis' => array('justification' => 'right', 'width' => 70),
            'ntot' => array('justification' => 'right', 'width' => 70),
            'sman1' => array('justification' => 'left', 'width' => 130),
        )
    )
);

$tamt1=number_format($tamt,1);


$pdf->ezSetDy(-10);
$pdf->ezText("<b>Total Sales Amount = </b> $tamt1", 10, array("justification" => 'left'));

}




else
{
$pdf->addText(20,500,11,"<b>Warehouse = </b>  $ware");

$pdf->addText(20,485,11,"<b>From = </b>            $fdate <b> To: </b> $tdate ");

$count=0;
$one=1;
$nResult = MySQLi_Query($link, "Select * from s_details where Inv_Date between '$strFrom' and '$strTo' and Warehouse='$ware' order by Inv_Date, Inv_No  ");
while($rstRow = mysqli_fetch_array($nResult))
{
$tamt=$rstRow['N_Total']+$tamt;

$idate=$rstRow['Inv_Date'];
$invv=$rstRow['Inv_No'];
$idate=strtotime($idate);
$idate = date("d-m-Y", $idate);
$invDet=$rstRow['Inv_Det'];

$count=$one+$count;
 $link = "<c:alink:inv_sales1.php?inv=$invv&cust=1>$invDet</c:alink>";

    $data[] = array(
        'num'   => $count,
        'dte'   => $idate,
        'inv'   => $link,
        'cust'  => $rstRow['Customer'],
        'ware'  => $rstRow['Warehouse'],
        'tot'   => $rstRow['Total'],
        'dis'   => $rstRow['Dis'],
        'ntot'  => $rstRow['N_Total'],
        'sman1' => $rstRow['Salesman']
    );
   }

$cols = array(
    'num'   => '<b>S. No</b>',
    'dte'   => '<b>Date</b>',
    'inv'   => '<b>Invoice#</b>',
    'cust'  => '<b>Customer Name</b>',
    'ware'  => '<b>Warehouse</b>',
    'tot'   => '<b>Total Amount</b>',
    'dis'   => '<b>Discount</b>',
    'ntot'  => '<b>Net Amount</b>',
    'sman1' => '<b>Salesman</b>'
);

$pdf->ezTable(
    $data,
    $cols,
    '',
    array(
        'xPos' => 20,
        'xOrientation' => 'right',
        'fontSize' => 10,
        'width' => 680,
        'showHeadings' => 1,
        'shaded' => 0,
        'showLines' => 2,
        'cols' => array(
            'num' => array('justification' => 'center', 'width' => 40),
            'dte' => array('justification' => 'center', 'width' => 65),
            'inv' => array('justification' => 'center', 'width' => 80),
            'cust' => array('justification' => 'left', 'width' => 210),
            'ware' => array('justification' => 'center', 'width' => 70),
            'tot' => array('justification' => 'right', 'width' => 75),
            'dis' => array('justification' => 'right', 'width' => 70),
            'ntot' => array('justification' => 'right', 'width' => 70),
            'sman1' => array('justification' => 'left', 'width' => 130),
        )
    )
);

$tamt1=number_format($tamt,1);


$pdf->ezSetDy(-10);
$pdf->ezText("<b>Total Sales Amount = </b> $tamt1", 10, array("justification" => 'left'));
}




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



