<?php
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,740,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(265,780,13,"<b>(GLAKB)</b>");
$pdf->addText(230,755,12,"<b>(PRODUCT RATE LIST)</b>");
$pdf->ezSetDy(-80);

$date1=$_POST['strFrom']; 

$typee=$_POST['item3']; 
$date1=date('d-m-Y',strtotime($date1));


$pdf->addText(20,720,12,"<b>Effective From:</b>     $date1");
$pdf->addText(420,720,12,"<b>All Prices are in Liters </b>");


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


    //$pdf->addText(3,700,15,"___________________________________________________________________________________________________");

$date1=Date("j-n-Y");
//$pdf->addText(260,740,11,"<b>(As on $date1)</b>");

if(empty($typee))
{


$nResult = MySQLi_Query($link, "Select * from products order by Article ");

$count=0;
$one=1;
$bal=0;
$tdeb=0;
$tcre=0;

$currentCat2 = '';
$groupedData = array();

while ($rstRow = mysqli_fetch_array($nResult)) {
$cat2 = $rstRow['Category2']; // Group by this
$suf=$rstRow['Sufix'];
$cde=$rstRow['Item_Code'];
$code=$suf.$cde;



    // Prepare the data row
    $dataRow = array(
        'num'   => $count,
        'code'  => $code,
        'fname' => $rstRow['Full_Name'],
      
        'grade' => $rstRow['Grade'],
        'pack'  => $rstRow['Size'],
        'rrate' => $rstRow['R_Price'],
        'tpl'   => $rstRow['D_Price'],
        'tpl1'   => $rstRow['W_Price']

    );

    // Group data under each Category2
    $groupedData[$cat2][] = $dataRow;
}

// Column headings
$cols = array(
    'num'   => '<b>S. No</b>',
    'code'  => '<b>Code</b>',
    'fname' => '<b>Product Full Name</b>',
 
    'grade' => '<b>SAE / Grade</b>',
    'pack'  => '<b>Packing</b>',
    'rrate' => '<b>Retail Price</b>',
    'tpl'   => '<b>Dealer Price</b>',
    'tpl1'   => '<b>Wholesale Price</b>'

);

// Table options (only defined once)
$tableOptions = array(
    'xPos' => 20,
    'xOrientation' => 'right',
    'fontSize' =>9,
    'width' => 680,
    'showHeadings' => 1,
    'shaded' => 0,
    'showLines' => 2,
    'cols' => array(
        'num' => array('justification' => 'center', 'width' => 35),
        'code' => array('justification' => 'left', 'width' => 45),
        'fname' => array('justification' => 'left', 'width' => 215),
     
        'grade' => array('justification' => 'center', 'width' => 60),
        'pack' => array('justification' => 'center', 'width' => 55),
        'rrate' => array('justification' => 'center', 'width' => 55),
        'tpl' => array('justification' => 'center', 'width' => 50),
        'tpl1' => array('justification' => 'center', 'width' => 50),

    )
);
 $pdf->ezSetDy(-5);
foreach ($groupedData as $cat2 => $rows) {
    // Print category heading
     
    $pdf->ezText("<b>$cat2</b>", 11, array('justification' => 'center'));
 $pdf->ezSetDy(-5);
    // Add continuous serial numbers
    $data = array();
    foreach ($rows as $r) {
        $count++;
        $r['num'] = $count;
        $data[] = $r;
    }

    // Print table for this category
    $pdf->ezTable($data, $cols, '', $tableOptions);
   // $pdf->ezText("\n"); // space between groups
 
}

}




if($typee=='Retail')
{


$nResult = MySQLi_Query($link, "Select * from products order by Article ");

$count=0;
$one=1;
$bal=0;
$tdeb=0;
$tcre=0;

$currentCat2 = '';
$groupedData = array();

while ($rstRow = mysqli_fetch_array($nResult)) {
$cat2 = $rstRow['Category2']; // Group by this
$suf=$rstRow['Sufix'];
$cde=$rstRow['Item_Code'];
$code=$suf.$cde;



    // Prepare the data row
    $dataRow = array(
        'num'   => $count,
        'code'  => $code,
        'fname' => $rstRow['Full_Name'],
       'api' => $rstRow['API'],
        'grade' => $rstRow['Grade'],
        'pack'  => $rstRow['Size'],
       'rrate' => $rstRow['R_Price']
       
    );

    // Group data under each Category2
    $groupedData[$cat2][] = $dataRow;
}

// Column headings
$cols = array(
    'num'   => '<b>S. No</b>',
    'code'  => '<b>Code</b>',
    'fname' => '<b>Product Full Name</b>',
  'api'  => '<b>API</b>',
     'grade' => '<b>SAE / Grade</b>',
    'pack'  => '<b>Packing</b>',
    'rrate' => '<b>Retail Price</b>',
   
);

// Table options (only defined once)
$tableOptions = array(
    'xPos' => 20,
    'xOrientation' => 'right',
    'fontSize' =>9,
    'width' => 680,
    'showHeadings' => 1,
    'shaded' => 0,
    'showLines' => 2,
    'cols' => array(
        'num' => array('justification' => 'center', 'width' => 40),
        'code' => array('justification' => 'left', 'width' => 50),
        'fname' => array('justification' => 'left', 'width' => 225),
          'api' => array('justification' => 'center', 'width' => 60),
       
        'grade' => array('justification' => 'center', 'width' => 65),
        'pack' => array('justification' => 'center', 'width' => 60),
        'rrate' => array('justification' => 'center', 'width' => 65),
        
    )
);
 $pdf->ezSetDy(-5);
foreach ($groupedData as $cat2 => $rows) {
    // Print category heading
     
    $pdf->ezText("<b>$cat2</b>", 11, array('justification' => 'center'));
 $pdf->ezSetDy(-5);
    // Add continuous serial numbers
    $data = array();
    foreach ($rows as $r) {
        $count++;
        $r['num'] = $count;
        $data[] = $r;
    }

    // Print table for this category
    $pdf->ezTable($data, $cols, '', $tableOptions);
   // $pdf->ezText("\n"); // space between groups
 
}

}



if($typee=='Dealer')
{


$nResult = MySQLi_Query($link, "Select * from products order by Article ");

$count=0;
$one=1;
$bal=0;
$tdeb=0;
$tcre=0;

$currentCat2 = '';
$groupedData = array();

while ($rstRow = mysqli_fetch_array($nResult)) {
$cat2 = $rstRow['Category2']; // Group by this
$suf=$rstRow['Sufix'];
$cde=$rstRow['Item_Code'];
$code=$suf.$cde;



    // Prepare the data row
    $dataRow = array(
        'num'   => $count,
        'code'  => $code,
        'fname' => $rstRow['Full_Name'],
       'api' => $rstRow['API'],
        'grade' => $rstRow['Grade'],
        'pack'  => $rstRow['Size'],
       'rrate' => $rstRow['D_Price']
       
    );

    // Group data under each Category2
    $groupedData[$cat2][] = $dataRow;
}

// Column headings
$cols = array(
    'num'   => '<b>S. No</b>',
    'code'  => '<b>Code</b>',
    'fname' => '<b>Product Full Name</b>',
  'api'  => '<b>API</b>',
     'grade' => '<b>SAE / Grade</b>',
    'pack'  => '<b>Packing</b>',
    'rrate' => '<b>Dealer Price</b>',
   
);

// Table options (only defined once)
$tableOptions = array(
    'xPos' => 20,
    'xOrientation' => 'right',
    'fontSize' =>9,
    'width' => 680,
    'showHeadings' => 1,
    'shaded' => 0,
    'showLines' => 2,
    'cols' => array(
        'num' => array('justification' => 'center', 'width' => 40),
        'code' => array('justification' => 'left', 'width' => 50),
        'fname' => array('justification' => 'left', 'width' => 225),
          'api' => array('justification' => 'center', 'width' => 60),
       
        'grade' => array('justification' => 'center', 'width' => 65),
        'pack' => array('justification' => 'center', 'width' => 60),
        'rrate' => array('justification' => 'center', 'width' => 65),
        
    )
);
 $pdf->ezSetDy(-5);
foreach ($groupedData as $cat2 => $rows) {
    // Print category heading
     
    $pdf->ezText("<b>$cat2</b>", 11, array('justification' => 'center'));
 $pdf->ezSetDy(-5);
    // Add continuous serial numbers
    $data = array();
    foreach ($rows as $r) {
        $count++;
        $r['num'] = $count;
        $data[] = $r;
    }

    // Print table for this category
    $pdf->ezTable($data, $cols, '', $tableOptions);
   // $pdf->ezText("\n"); // space between groups
 
}

}




if($typee=='Whole Sale')
{


$nResult = MySQLi_Query($link, "Select * from products order by Article ");

$count=0;
$one=1;
$bal=0;
$tdeb=0;
$tcre=0;

$currentCat2 = '';
$groupedData = array();

while ($rstRow = mysqli_fetch_array($nResult)) {
$cat2 = $rstRow['Category2']; // Group by this
$suf=$rstRow['Sufix'];
$cde=$rstRow['Item_Code'];
$code=$suf.$cde;



    // Prepare the data row
    $dataRow = array(
        'num'   => $count,
        'code'  => $code,
        'fname' => $rstRow['Full_Name'],
       'api' => $rstRow['API'],
        'grade' => $rstRow['Grade'],
        'pack'  => $rstRow['Size'],
       'rrate' => $rstRow['W_Price']
       
    );

    // Group data under each Category2
    $groupedData[$cat2][] = $dataRow;
}

// Column headings
$cols = array(
    'num'   => '<b>S. No</b>',
    'code'  => '<b>Code</b>',
    'fname' => '<b>Product Full Name</b>',
  'api'  => '<b>API</b>',
     'grade' => '<b>SAE / Grade</b>',
    'pack'  => '<b>Packing</b>',
    'rrate' => '<b>Wholesale Price</b>',
   
);

// Table options (only defined once)
$tableOptions = array(
    'xPos' => 20,
    'xOrientation' => 'right',
    'fontSize' =>9,
    'width' => 680,
    'showHeadings' => 1,
    'shaded' => 0,
    'showLines' => 2,
    'cols' => array(
        'num' => array('justification' => 'center', 'width' => 40),
        'code' => array('justification' => 'left', 'width' => 50),
        'fname' => array('justification' => 'left', 'width' => 225),
          'api' => array('justification' => 'center', 'width' => 55),
       
        'grade' => array('justification' => 'center', 'width' => 65),
        'pack' => array('justification' => 'center', 'width' => 60),
        'rrate' => array('justification' => 'center', 'width' => 75),
        
    )
);
 $pdf->ezSetDy(-5);
foreach ($groupedData as $cat2 => $rows) {
    // Print category heading
     
    $pdf->ezText("<b>$cat2</b>", 11, array('justification' => 'center'));
 $pdf->ezSetDy(-5);
    // Add continuous serial numbers
    $data = array();
    foreach ($rows as $r) {
        $count++;
        $r['num'] = $count;
        $data[] = $r;
    }

    // Print table for this category
    $pdf->ezTable($data, $cols, '', $tableOptions);
   // $pdf->ezText("\n"); // space between groups
 
}

}


$pdf->ezSetDy(-20);
$pdf->ezText("<b>****GLAKB has Exclusive Rights to change the Price with / without Prior Notice.</b>", 12, array("justification" => 'left'));
$pdf->ezSetDy(-40);
$pdf->ezText("<b>Owner GLAKB</b>", 12, array("justification" => 'right'));
ob_clean();
$pdf->ezStream();
?>



