<?php
$ti=time();
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=Prasadam_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;?>
            <?php foreach($results as $key=>$value) {
                    $total_amt += $value->bp_amount;
                ?>
                <tr>
                    <td align="center" style="padding:1%;"><?php echo ++$key;?></td>
                    <?php if (in_array("Receipt No", $filters)) {?><td style="padding:1%;"><?php echo (($general->prefix == 1) ? $value->prefix : '') . $value->bp_rec_no; ?></td><?php } ?>
                    <?php if (in_array("Type", $filters)) {?><td style="padding:1%;"><?php echo text($value->service_name);?></td><?php } ?>
                    <?php if (in_array("Function Date", $filters)) {?><td style="padding:1%;"><?php echo text(date('d-m-Y',strtotime($value->bp_fn_date)));?></td><?php } ?>
                    <?php if (in_array("Booked Date", $filters)) {?><td style="padding:1%;"><?php echo text(date('d-m-Y',strtotime($value->created_on)));?></td><?php } ?>
                    <?php if (in_array("Period", $filters)) {?><td style="padding:1%;"><?php echo text($value->period_str);?></td><?php } ?>
                    <?php if (in_array("Name 1", $filters)) {?><td style="padding:1%;"><?php echo text($value->bp_dev_name_1);?></td><?php } ?>
                    <?php if (in_array("Tamil Name 1", $filters)) {?><td style="padding:1%;"><?php echo text($value->bp_tamil_name_1);?></td><?php } ?>
                    <?php if (in_array("Star 1", $filters)) {?><td style="padding:1%;"><?php echo text($value->star);?></td><?php } ?>
                    <?php if (in_array("Name 2", $filters)) {?><td style="padding:1%;"><?php echo text($value->bp_dev_name_2);?></td><?php } ?>
                    <?php if (in_array("Tamil Name 2", $filters)) {?><td style="padding:1%;"><?php echo text($value->bp_tamil_name_2);?></td><?php } ?>
                    <?php if (in_array("Star 2", $filters)) {?><td style="padding:1%;"><?php echo text($value->star2);?></td><?php } ?>
                    <?php if (in_array("Contact No", $filters)) {?><td style="padding:1%;"><?php echo text($value->bp_contact_no);?></td><?php } ?>
                    <?php if (in_array("Email", $filters)) {?><td style="padding:1%;"><?php echo text($value->bp_email);?></td><?php } ?>
                    <?php if (in_array("Particulars", $filters)) {?><td width="15%" style="padding:1%;"><?php echo text(nl2br($value->bp_desc));?></td><?php } ?>
                    <?php if (in_array("Amount", $filters)) {?><td style="padding:1%;" align="right"><?php echo $value->bp_amount;?></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_amt)) { ?>
             <tr>
                <td style="padding:1%;" colspan="<?php echo $field; ?>" align="right"><b>Total Price</b></td>
                <td style="padding:1%;" align="right"><b><?php echo number_format($total_amt,2,'.','');?></b></td>
            </tr>
        <?php } ?>
    </tfoot>
</table>                        