<aside class="right-side">
    
    </section>
    <!-- Main content -->
    <section class="content">
        <div class="row">
            <div class="col-xs-12">
                
                <!-- /.box -->
                
                <div class="box box-primary">
                    <?php $general = get_general_setting();
                        if( !IS_KSK ) :
                        $basic = get_basic_setting();
                        $design = get_design_setting();
                    ?>
                    
                    <!--<button type="submit" id="print-btn" class="btn btn-primary btn-sm print" style="float: right; margin: 1%;"><i class="fa fa-print"></i> Print</button>-->
                    <!--<a class="print" style="float: right; cursor: pointer;"><img src="<?php echo base_url();?>assets/images/print.jpg" width="70px" height="35px;"/></a>-->
                    
                    <?php if($data_type == 'Print Pledge Data') { ?>
                        <input type="hidden" name="hidden_print_pledge" class="hidden_print_pledge" value="1" />
                    <?php } ?>
                    
                    <iframe name="report" id="report" src="#" style="display:none;"></iframe>
                    <div class="box-body table-responsive" style="clear:both;" id="print_data_container" >
                        <div>
                            <table border="0" width="1000" style="border-collapse:collapse;">
                                <tr>
                                    <td width="15%">&nbsp;</td>
                                   
                                    <td width="20%" style="border-right:1px solid #FFF;">
                                        <?php  if ((!empty($design->logo)) && (file_exists(FCPATH . DIR_COMPANY_LOGO . $design->logo))) {
                                            $image_url = base_url() . DIR_COMPANY_LOGO . $design->logo;
                                            $alt = $basic->temple_name;
                                        }
                                        else {
                                            $image_url = base_url() . 'assets/images/logo.png';
                                            $alt = 'Logo not found!';
                                        } ?>
                                        <div style="font-size: 14px;">
                                            <div><span style="float:left;width:155px;height:75px; margin:2px;"><img src="<?php echo $image_url;?>" alt="<?php echo $alt;?>" width="155" height="75" /></span></div>
                                        </div>
                                    </td>
                                    <td width="40%" align="center">
                                        <span style="float:left;font-family:Arial, Helvetica, sans-serif;font-weight:bold; margin-bottom: 20px;"><span style="font-size:24px;" class="lang-tamil"><?php echo $basic->tamil_name;?></span><br/><span style="font-size:16px;"><?php echo $basic->temple_name;?></span><br/><br/><span style="font-size:14px;"><?php echo nl2br($basic->address);?></span><br/><span style="font-size:14px;">Tel: <?php echo $basic->contact_no;?>&nbsp; Fax: <?php echo $basic->fax;?></span> <br/><span style="font-size:14px;">Email: <?php echo $basic->comp_email;?></span><br/><span style="font-size:14px;"><?php echo $basic->website_url;?></span><br/></span>
                                    </td>
                                    <td width="15%">&nbsp;</td>
                                    <td width="10%">&nbsp;</td>
                                </tr>
                                <tr>
                                    <td colspan="5" align="center" style="font-size:16px; font-weight:bold;"><?php echo ($data_type == 'Print Pledge Data') ?'Donation Pledging Report' : 'Donation Report';?></td>
                                
                                </tr>
                                <tr>
                                    <td colspan="2" align="center"><strong>Start Date : <?php echo date('d-m-Y',strtotime($start_date));?></strong></td>
                                    <td>&nbsp;</td>
                                    <td colspan="2" align="left"><strong>End Date : <?php echo date('d-m-Y',strtotime($end_date));?></strong></td>
                                </tr>
                            <?php else :?>
                                <table border="0" width="1000" style="border-collapse:collapse;">
                                    <tr>
                                        <td align="left"><strong>Start Date : <?php echo date('d-m-Y',strtotime($start_date));?></strong></td>
                                        <td>&nbsp;</td>
                                        <td align="right"><strong>End Date : <?php echo date('d-m-Y',strtotime($end_date));?></strong></td>
                                    </tr>
                            <?php endif;?>
                            </table>
                            <br/>
                            
                            <!-- Filtered Columns to send JS - Start -->
                            <input type="hidden" name="hidden_print" class="hidden_print" value="<?php echo (!empty($start_date)) ? 1 : 0 ;?>" />
                            <div class="col-xs-12" style="margin-bottom:4%; display: none;">
                               <div class="col-xs-12 blck" style="margin-bottom: -35px;">
                                    <div class="sub-title" style="color:#0B45B3; background:#f3f3f3 !important;" ><h4><i class="fa fa-fire" style="font-size: 14px;"></i> Filter Columns</h4><i class="ctrl opener opened fa fa-chevron-up" style="float: right; margin-top: -25px;"></i></div>
                                    <div class="blck-content col-xs-12" style="border-bottom: 1px inset rgba(209, 216, 216, 0.6); background: rgba(3, 12, 11, 0.05); margin-top: -15px;">
                                        <div id="grpChkBox" class="grpChkBox">
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <?php foreach($filters as $key=>$val) : ?>
                                <input type="hidden" name="hidden_filter_array[]" class="hidden_filter_array" value="<?php echo rtrim($val,' ');?>" />
                            <?php endforeach;?>
                            <!-- Filtered Columns to send JS - End -->
                            
                            <?php if($data_type == 'Print Summary Data') { ?>
                                <table width="1000" border="1" cellpadding="3" cellspacing="0" style="font-family:'Trebuchet MS', Arial, Helvetica, sans-serif; font-size:14px; width: 1000px; border-collapse:collapse;" class="filterTable" id="filterTable">
                                    <thead>
                                        <tr>
                                            <th>S.No</th>
                                            <th style="padding:1%;">Receipt No</th>
                                            <th style="padding:1%;">Type</th>
                                            <th style="padding:1%;">Booked Date</th>
                                            <th style="padding:1%;">Name</th>
                                            <th style="padding:1%;">Tamil Name</th>
                                            <th style="padding:1%;">Contact No</th>
                                            <th>Email</th>
                                            <th width="15%" style="padding:1%;">Address</th>
                                            <th width="15%" style="padding:1%;">Desc</th>
                                            <th style="padding:1%;">Amount Type</th>
                                            <th >Amount<?php echo ((!empty($pledge)) && $pledge == 1 && $pledge_type == 2) ? ' (grams)' :  '';?></th>
                                             <th style="padding:1%;">Paid Amount<?php echo ((!empty($pledge)) && $pledge == 1 && $pledge_type == 2) ? ' (grams)' : '';?></th>
                                        </tr>
                                    </thead>
                                    <?php $total_amt = 0; $paid_amt = 0; if(count($results) > 0) {  ?>
                                    <tbody>
                                        
                                        <?php foreach($results as $key=>$value) {
                                                $total_amt += $value->total_amount;
                                                $paid_amt += $value->paid_amount;
                                            ?>
                                            <tr>
                                                <td align="center" style="padding:1%;"><?php echo ++ $key;?></td>
                                                <td style="padding:1%;"><?php echo (($general->prefix == 1) ? $value->prefix : '') . $value->receipt_no;?></td>
                                                <td style="padding:1%;"><?php echo text($value->service_name);?></td>
                                                <td style="padding:1%;"><?php echo text(date('d-m-Y',strtotime($value->created_on)));?></td>
                                                <td style="padding:1%;"><?php echo text($value->name);?></td>
                                                <td style="padding:1%;"><?php echo (!empty($value->tamil_name)) ? '<span class="lang-tamil">' . $value->tamil_name .'<span>' : 'N/A';?></td>
                                                <td style="padding:1%;"><?php echo text($value->contact_no);?></td>
                                                <td style="padding:1%;"><?php echo text($value->email);?></td>
                                                <td style="padding:1%;"><?php echo text(nl2br($value->address));?></td>
                                                <td style="padding:1%;"><?php echo text(nl2br($value->desc));?></td>
                                                <td style="padding:1%;"><?php if($value->amount_type == 1) { echo 'Amount'; } elseif($value->amount_type == 2) { echo 'Item'; } elseif($value->amount_type == 3) { echo 'Ongoing';}?></td>
                                                <td style="padding:1%;" align="right"><?php echo $value->total_amount;?></td>
                                                <td style="padding:1%;" align="right"><?php echo number_format($value->paid_amount,2,'.','');?></td>
                                            </tr>
                                        <?php } ?>
                                    </tbody>
                                    <tfoot>
                                        <tr>
                                            <td style="padding:1%;" colspan="11" align="right"><b>Total Amount</b></td>
                                            <td align="right"><b><?php echo number_format($total_amt,2,'.','');?></b></td>
                                            <!--<td style="padding:1%;" align="right"><b><?php echo number_format($paid_amt,2,'.','');?></b></td>-->
                                        </tr>
                                    </tfoot>
                                    <?php } else {?>
                                        <tbody>
                                            <tr>
                                                <td colspan="13" style="color: #0B6CCB;"><center>No Records Found!</center></td>
                                            </tr>
                                        </tbody>
                                    <?php } ?>
                                </table>
                            <?php } elseif($data_type == 'Print Pledge Data') { ?>
                                <table width="1000" border="1" cellpadding="3" cellspacing="0" style="font-family:'Trebuchet MS', Arial, Helvetica, sans-serif; font-size:14px; width: 1000px; border-collapse:collapse;" class="filterTable" id="filterTable">
                                    <thead>
                                        <tr>
                                            <!--<th width="5%" class="align-center" style="display:none;">&nbsp;</th>-->
                                            <th style="padding:1%;">S.No</th>
                                            <th style="padding:1%;">Date</th>
                                            <th style="padding:1%;">Type</th>
                                            <th style="padding:1%;">Devotee Name</th>
                                            <th style="padding:1%;">Contact No</th>
                                            <th style="padding:1%;">Pledge Amount<?php echo ((!empty($pledge)) && $pledge == 1 && $pledge_type == 2) ? ' (grams)' : '';?></th>
                                            <th style="padding:1%;">Paid Amount<?php echo ((!empty($pledge)) && $pledge == 1 && $pledge_type == 2) ? ' (grams)' : '';?></th>
                                            <th style="padding:1%;">Balance Amount<?php echo ((!empty($pledge)) && $pledge == 1 && $pledge_type == 2) ? ' (grams)' : '';?></th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?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>  
                                                    <!--<th width="5%" class="align-center" style="display:none;">&nbsp;</th>-->
                                                    <td align="center" style="padding:1%;"><?php echo ++$key;?></td>
                                                    <td style="padding:1%;"><?php echo text(date('d-m-Y',strtotime($value->created_on))); ?></td>
                                                    <td style="padding:1%;"><?php echo text($value->service_name);?></td>
                                                    <td style="padding:1%;"><?php echo text($value->name);?></td>
                                                    <td style="padding:1%;"><?php echo text($value->contact_no);?></td>
                                                    <td style="padding:1%;" align="right"><?php echo text($value->pledge_amount);?></td>
                                                    <td style="padding:1%;" align="right"><?php echo number_format($value->amount,2,'.','');?></td>
                                                    <td style="padding:1%;" align="right"><?php echo number_format(($value->pledge_amount - $value->amount),2,'.','');?></td>
                                                </tr>
                                                
                                                <?php if(count($donation_trans) > 0) { ?>
                                                    <tr class="remove_container not_get_columns" >
                                                        <td colspan="8" class="expand_container">
                                                            <table width="970" border="1" cellpadding="3" cellspacing="0" style="font-family:'Trebuchet MS', Arial, Helvetica, sans-serif; font-size:14px; width: 970px; margin: 1.3%; border-collapse:collapse;" class="filterTable tableFilter2">
                                                                <thead>
                                                                    <tr>
                                                                        <th width="10%" align="center" style="padding:1%;">S.No</th>
                                                                        <th align="center" style="padding:0.8%;">Receipt No</th>
                                                                        <th align="center" style="padding:0.8%;">Date</th>
                                                                        <th align="center" style="padding:0.8%;">Amount<?php echo ((!empty($pledge)) && $pledge == 1 && $pledge_type == 2) ? ' (grams)' : '';?> </th>
                                                                    </tr>
                                                                </thead>
                                                                <tbody>
                                                                    <?php foreach($donation_trans as $k=>$row) { ?>
                                                                        <tr class="subTable">
                                                                            <td style="padding:0.8%;"><?php echo ++$k;?></td>
                                                                            <td style="padding:0.8%;"><?php echo text($row->receipt_no);?></td>
                                                                            <td style="padding:0.8%;"><?php echo text(date('d-m-Y',strtotime($row->pledge_date)));?></td>
                                                                            <td align="right" style="padding:0.8%;"><?php echo number_format($row->amount,2,'.','');?></td>
                                                                        </tr>
                                                                    <?php } ?>
                                                                </tbody>
                                                            </table>
                                                        </td>
                                                    </tr>
                                                <?php } ?>
                                                
                                            <?php } ?>
                                        <?php } else {?>
                                            <tr>
                                                <td colspan="8" style="color: #0B6CCB;"><center>No Records Found!</center></td>
                                            </tr>
                                        <?php } ?>
                                    </tbody>
                                </table>
                            <?php } ?>
                        </div>
                    </div>
                
                    
                </div><!-- /.box -->
            </div>
        </div>
    </section><!-- /.content -->
</aside><!-- /.right-side -->
<!-- ./wrapper -->
<?php if( !IS_KSK ) : ?>
<script type="text/javascript">
    window.onload = function() {
        print_layout();
    } 
    
    $(document).ready(function(){
        $('.print').click(function(){
            print_layout();
        });
    });
    
    function print_layout() {
        var body = $('#print_data_container').html();
        var newWin = document.getElementById('report').contentWindow;
        newWin.document.write(body);
        newWin.document.close(); //important!
        newWin.focus(); //IE fix
        newWin.print();
        window.location.href = "<?php echo base_url();?>donation_report"
    }
</script>
<?php endif;