<?php
$ti=time();
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=donation_report".$ti.".xls");
header("Pragma: no-cache");
header("Expires: 0");
?>
<?php if($data_type == 'Excel Summary Data') { ?>
    <table class="table table-bordered table-striped data_table filterTable" id="filterTable">
            <tr>
                <th width="5%" class="align-center">S.No</th>
                <th class="align-center">Receipt No</th>
                <th class="align-center">Type</th>
                <th class="align-center">Booked Date</th>
                <th class="align-center">Name</th>
                <th class="align-center">Tamil Name</th>
                <th class="align-center">Contact No</th>
                <th class="align-center">Email</th>
                <th width="15%" class="align-center">Address</th>
                <th width="15%" class="align-center">Desc</th>
                <th class="align-center">Amount Type</th>
                <th class="align-center">Amount<?php echo ((!empty($pledge)) && $pledge == 1 && $pledge_type == 2) ? ' (grams)' :    '';?></th>
                 <th class="align-center">Paid Amount<?php echo ((!empty($pledge)) && $pledge == 1 && $pledge_type == 2) ? ' (grams)' : '';?></th>
            </tr>
            <?php if(count($results) > 0) { ?>
                <?php foreach($results as $key=>$value) {
                    $tooltip = ($value->status == 2) ? $value->del_reason : '';
                ?>
                    <tr data-toggle="tooltip" title="<?php echo $tooltip;?>">
                        <td><?php echo ++ $key;?></td>
                        <td><?php echo (($general->prefix == 1) ? $value->prefix : '') . $value->receipt_no;?></td>
                        <td><?php echo text($value->service_name);?></td>
                        <td><?php echo text(date('d-m-Y',strtotime($value->created_on)));?></td>
                        <td><?php echo text($value->name);?></td>
                        <td><?php echo (!empty($value->tamil_name)) ? '<span class="lang-tamil">' . $value->tamil_name . '</span>' : 'N/A';?></td>
                        <td><?php echo text($value->contact_no);?></td>
                        <td><?php echo text($value->email);?></td>
                        <td><?php echo text(nl2br($value->address));?></td>
                        <td><?php echo text(nl2br($value->desc));?></td>
                        <td><?php if($value->amount_type == 1) { echo 'Amount'; } elseif($value->amount_type == 2) { echo 'Item'; } elseif($value->amount_type == 3) { echo 'Ongoing';}?></td>
                        <td class="align-right"><?php echo text($value->total_amount);?></td>
                        <td class="align-right"><?php echo number_format($value->paid_amount,2,'.','');?></td>
                    </tr>
                <?php } ?>
            <?php } ?>
    </table>
<?php } else if($data_type == 'Excel Pledge Data') { ?>
    <table class="table table-bordered table-striped filterTable" id="filterTable">
            <tr>
                <th width="5%" class="align-center">&nbsp;</th>
                <th width="5%" class="align-center">S.No</th>
                <th class="align-center">Date</th>
                <th class="align-center">Type</th>
                <th class="align-center">Devotee Name</th>
                <th class="align-center">Contact No</th>
                <th class="align-center">Pledge Amount<?php echo ((!empty($pledge)) && $pledge == 1 && $pledge_type == 2) ? ' (grams)' : '';?></th>
                <th class="align-center">Paid Amount<?php echo ((!empty($pledge)) && $pledge == 1 && $pledge_type == 2) ? ' (grams)' : '';?></th>
                <th class="align-center">Balance Amount<?php echo ((!empty($pledge)) && $pledge == 1 && $pledge_type == 2) ? ' (grams)' : '';?></th>
            </tr>
            <?php if(count($results) > 0) { ?>
                <?php foreach($results as $key=>$value) { ?>
                    <?php $donation_trans = $this->donation_report_model->get_donation_pledge_transaction($value->service_id,$value->name,$value->contact_no,$value->amount_type,$start_date,$end_date,$value->id);?>
                    <tr>
                        <td>
                            <?php if(count($donation_trans) > 0) { ?>
                                <div class="expand_icon plus"></div>
                            <?php } ?>
                        </td>
                        <td><?php echo ++ $key;?></td>
                        <td><?php echo date('d-m-Y',strtotime($value->created_on));?></td>
                        <td><?php echo text($value->service_name);?></td>
                        <td><?php echo text($value->name);?></td>
                        <td><?php echo text($value->contact_no);?></td>
                        <td class="align-right"><?php echo text($value->pledge_amount);?></td>
                        <td class="align-right"><?php echo number_format($value->amount,2,'.','');?></td>
                        <td class="align-right"><?php echo number_format(($value->pledge_amount - $value->amount),2,'.','');?></td>
                    </tr>
                    <?php if(count($donation_trans) > 0) { ?>
                        <tr class="remove_container">
                            <td colspan="9" class="expand_container">
                                <div class="tbl-expand">
                                    <table class="table table-bordered table-striped" style="border: 3px solid #ddd !important;">
                                       <!--<thead>-->
                                            <tr>
                                                <th width="10%" class="align-center">S.No</th>
                                                <th class="align-center">Receipt No</th>
                                                <th class="align-center">Date</th>
                                                <th class="align-center">Amount<?php echo ((!empty($pledge)) && $pledge == 1 && $pledge_type == 2) ? ' (grams)' : '';?> </th>
                                            </tr>
                                        <!--</thead>-->
                                            <?php foreach($donation_trans as $k=>$row) { ?>
                                                <tr class="subTable">
                                                    <td><?php echo ++$k;?></td>
                                                    <td><?php echo text($row->receipt_no);?></td>
                                                    <td><?php echo text(date('d-m-Y',strtotime($row->pledge_date)));?></td>
                                                    <td class="align-right"><?php echo number_format($row->amount,2,'.','');?></td>
                                                </tr>
                                            <?php } ?>
                                    </table>
                                </div>
                            </td>
                        </tr>
                    <?php } ?>
                <?php } ?>
            <?php } ?>
        </tbody>
        <tfoot>
            
        </tfoot>
    </table>
<?php } ?>