<?php
$ti=time();
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=Prasadam_sale_report".$ti.".xls");
header("Pragma: no-cache");
header("Expires: 0");

//echo "<pre>";print_r($filters);
#echo "<pre>";print_r($dataType);echo "<br>";print_r($results);echo "</pre>";
#echo "</br> : ".count($item);
#echo "HERE"
#exit;

$field = count($filters);
?>
<table width="1000" border="1" cellpadding="3" cellspacing="0" class="filterTable" id="filterTable">
    <thead>
        <tr>
            <th style="padding:1%;">S.No</th>
            <?php
                foreach($filters as $value){
                   echo '<th style="padding:1%;">'.$value.'</th>';
                }
            ?>
        </tr>
    </thead>
    <tbody>
        <?php if(count($results) > 0) {  $total_amt = 0; $total_qty = 0;?>
            <?php foreach($results as $key=>$value) {
                    $total_amt += $value->total;
                    $total_qty += $value->qty;
                ?>
                <tr>
                    <td align="center" style="padding:1%;"><?php echo ++$key;?></td>
                    <?php if (in_array("Date", $filters)) {?><td style="padding:1%;"><?php echo text(date('d-m-Y',strtotime($value->bp_fn_date))); ?></td><?php } ?>
                    <?php if (in_array("Prasadam Name", $filters)) {?><td style="padding:1%;"><?php echo text($value->prasadam);?></td><?php } ?>
                    <?php if (in_array("Quantity", $filters)) {?><td style="padding:1%;" align="center"><?php echo text($value->qty);?></td><?php } ?>
                    <?php if (in_array("Amount", $filters)) {?><td style="padding:1%;" align="right"><?php echo text($value->total);?></td><?php } ?>
                </tr>
            <?php } ?>
        <?php } else {?>
            <tr>
                <td colspan="<?php echo $field+1; ?>" style="color: #0B6CCB;"><center>No Records Found!</center></td>
            </tr>
        <?php } ?>
    </tbody>
    <tfoot>
        <?php if(!empty($total_qty) || !empty($total_amt)) { ?>
             <tr>
                <td style="padding:1%;" colspan="<?php echo $field-1; ?>" align="right"><b>Total</b></td>
                <td style="padding:1%;" align="center"><b><?php echo $total_qty;?></b></td>
                <td style="padding:1%;" align="right"><b><?php echo number_format($total_amt,2,'.','');?></b></td>
            </tr>
        <?php } ?>
    </tfoot>
</table>                        