<?php
$ti=time();
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=Outdoor_service_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->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->receipt_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("Date", $filters)) {?><td style="padding:1%;"><?php echo date('d-m-Y',strtotime($value->date));?></td><?php } ?>
                    <?php if (in_array("Period", $filters)) {?><td style="padding:1%;"><?php echo text($value->period_str);?></td><?php } ?>
                    <?php if (in_array("Time", $filters)) {?><td style="padding:1%;"><?php echo text(date('H:i',strtotime($value->from_time)) . ' - ' . date('H:i',strtotime($value->to_time)));?></td><?php } ?>
                    <?php if (in_array("Name", $filters)) {?><td style="padding:1%;"><?php echo text($value->devotee_name);?></td><?php } ?>
                    <?php if (in_array("Tamil Name", $filters)) {?><td style="padding:1%;"><?php echo text($value->tamil_name);?></td><?php } ?>
                    <?php if (in_array("Contact No 1", $filters)) {?><td style="padding:1%;"><?php echo text($value->contact_no1);?></td><?php } ?>
                    <?php if (in_array("Contact No 2", $filters)) {?><td style="padding:1%;"><?php echo text($value->contact_no2);?></td><?php } ?>
                    <?php if (in_array("Email", $filters)) {?><td style="padding:1%;"><?php echo text($value->email);?></td><?php } ?>
                    <?php if (in_array("Address", $filters)) {?><td width="15%" style="padding:1%;"><?php echo text(nl2br($value->address));?></td><?php } ?>
                    <?php if (in_array("Postal Code", $filters)) {?><td style="padding:1%;"><?php echo text($value->postal_code);?></td><?php } ?>
                    <?php if (in_array("Priest Name", $filters)) {?><td style="padding:1%;"><?php echo text($value->priest);?></td><?php } ?>
                    <?php if (in_array("Melam", $filters)) {?><td style="padding:1%;"><?php echo text($value->melam);?></td><?php } ?>
                    <?php if (in_array("Nathaswaram", $filters)) {?><td style="padding:1%;"><?php echo text($value->nathaswaram);?></td><?php } ?>
                    <?php if (in_array("Desc", $filters)) {?><td width="15%" style="padding:1%;"><?php echo text(nl2br($value->desc));?></td><?php } ?>
                    <?php if (in_array("Amount", $filters)) {?><td style="padding:1%;" align="right"><?php echo $value->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 Amount</b></td>
            <td style="padding:1%;" align="right"><b><?php echo number_format($total_amt,2,'.','');?></b></td>
        </tr>
    <?php } ?>
    </tfoot>
</table>                       