<aside class="right-side">
    <section class="content-header">
        <div class="title_bar">
            <h1 class="major_txt_color"><?php echo $title;?></h1>
            <div class="breadcrumb_container"><?php echo breadcrumb_links();?></div>
        </div>
    </section>
    <?php $general = get_general_setting();?>
    <!-- Main content -->
    <section class="content">
        <div class="row">
            <div class="col-xs-12">
                <!-- /.box -->
                <div class="box box-primary">
                    <div class="box-body table-responsive">
                        <form name="get_data_search" action="<?php echo $form_action;?>" method="post" class="search_form validate_form">
                            <input type="hidden" name="hidden_id" class="hidden_id" value="<?php echo (!empty($hidden_id)) ? $hidden_id : '';?>" />
                            
                            <!-- Filtered Columns to send JS - Start -->
                            <input type="hidden" name="hidden_print" class="hidden_print" value="<?php echo (!empty($start_date)) ? 1 : 0 ;?>" />
                            <?php foreach($filters as $key=>$val) : ?>
                                <input type="hidden" name="hidden_filter_array[]" class="hidden_filter_array" value="<?php echo $val;?>" />
                            <?php endforeach;?>
                            <!-- Filtered Columns to send JS - End -->
                            
                            <div class="col-xs-12">
                                <div class="col-md-4">
                                    <div class="form-group">
                                        <label >Start Date</label>
                                        <div class="input-group">
                                            
                                            <div class="input-group-addon">
                                                <i class="fa fa-calendar"></i>
                                            </div>
                                            <input type="text" class="start_date" placeholder="DD-MM-YYYY" style="padding: 6px 12px;margin-right:5%;width:100%;" id="start_date" name="start_date" value="<?php echo (!empty($start_date)) ? $start_date : date('d-m-Y');?>" autocomplete="off" >
                                            
                                        </div>
                                    </div>
                                    
                                </div>
                                <div class="col-md-4">
                                    <div class="form-group">
                                        <label >End Date</label>
                                        <div class="input-group">
                                            
                                            <div class="input-group-addon">
                                                <i class="fa fa-calendar"></i>
                                            </div>
                                            <input type="text" class="end_date" placeholder="DD-MM-YYYY" style="padding: 6px 12px;margin-right:5%;width:100%;"  id="end_date" name="end_date" value="<?php echo (!empty($end_date)) ? $end_date : date('d-m-Y');?>" autocomplete="off" >
                                        </div>
                                    </div>
                                </div>
                                
                                <div class="col-md-4">
                                    <div class="form-group">
                                        <label >Type</label>
                                        <div class="input-group">
                                            <div class="input-group-addon">
                                                <i class="fa fa-soccer-ball-o"></i>
                                            </div>
                                            <select name="type_id" class="form-control select2">
                                                <option value="">Select Type</option>
                                                <?php foreach($types as $key=>$row) {?>
                                                    <option value="<?php echo $row->id;?>" <?php echo ($row->id == $type_id) ? 'selected' : '';?>><?php echo $row->service_name;?></option>
                                                <?php } ?>
                                            </select>
                                        </div>    
                                    </div>
                                </div>                                
                            </div>
                            
                            <div class="col-xs-12">
                                <div class="col-md-4">
                                    <div class="form-group">
                                        <label>Contact No</label>
                                        <input type="text" class="form-control mobile_no" style="padding: 6px 12px;" id="mobile_no" name="mobile_no" value="<?php echo (!empty($mobile_no)) ? $mobile_no : '';?>" autocomplete="off" placeholder="Devotee Mobile No" >
                                    </div>
                                    
                                </div>
                                <div class="col-md-4">
                                    <div class="form-group">
                                        <label>Is Pledge</label>
                                            <select name="pledge" class="form-control select2">
                                            <option value="1" <?php echo ((!empty($pledge)) && $pledge == 1) ? 'selected' : '';?>>Pledge</option>
                                            <option value="2" <?php echo ((!empty($pledge)) && $pledge == 2) ? 'selected' : '';?>>Not Pledge</option>
                                        </select>
                                    </div>
                                </div>
                                
                                <div class="col-md-4">
                                    <div class="form-group show_pledge_type" style="display: <?php echo ($pledge == 1) ? 'block' : 'none';?>">
                                        <label>Pledge Type</label>
                                        <div style="clear: both; padding-top: 2%;">
                                            <label for="status" style="width: 32%;"><input type="radio" name="pledge_type" value="1" <?php echo ($pledge_type == 1 || (empty($pledge_type))) ? 'checked' : '';?> /> &nbsp;&nbsp;Amount</label> 
                                            <label for="status" style="width: 32%;"><input type="radio" name="pledge_type" value="2" <?php echo ($pledge_type == 2) ? 'checked' : '';?> /> &nbsp;&nbsp;Item</label> 
                                        </div>
                                    </div>
                                </div>
                            </div>
                            
                            <div class="col-xs-12">
                                <div class="col-md-2">&nbsp;</div>
                                <div class="col-md-2">
                                    <input type="submit" value="Get Summary Data" name="submit" class="btn btn-danger btn-sm" style="background-color: #e33739;
    border-color: #e33739;" />
                                </div>
                                <div class="col-md-2">
                                    <input type="submit" value="Print Summary Data" name="submit" class="btn btn-primary btn-sm" />
                                </div>
                                <div class="col-md-2">
                                    <input type="submit" value="Get Pledge Data" name="submit" class="btn btn-danger btn-sm pledge_btn" style="background-color: #e33739;
    border-color: #e33739;" <?php echo (!empty($pledge) && $pledge == 2) ? 'disabled' : '';?> />
                                </div>
                                <div class="col-md-2">
                                    <input type="submit" value="Print Pledge Data" name="submit" class="btn btn-primary btn-sm pledge_btn" <?php echo (!empty($pledge) && $pledge == 2) ? 'disabled' : '';?> />
                                </div>
                                <div class="col-md-2">&nbsp;</div>
                            </div>
                            <div class="col-xs-12">&nbsp;</div>
                            
                            <!-- Filtered Columns to send JS - Start -->                            
                            <div class="col-xs-12" style="margin-bottom:4%;">
                                <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>
                            <!-- Filtered Columns to send JS - End -->
                            
                        </form>
                    </div>
                    <div class="box-body table-responsive">
                        <?php if($data_type == 'Get Summary Data') { ?>
                            <table class="table table-bordered table-striped data_table filterTable" id="filterTable">
                                <thead>
                                    <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>
                                </thead>
                                <tbody>
                                    <?php if(count($results) > 0) { $total_amt = 0;?>
                                        <?php foreach($results as $key=>$value) {
                                            $total_amt += $value->total_amount;
                                            $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 } ?>
                                </tbody>
                                <tfoot>
                                <?php if(!empty($total_amt)) { ?>
                                    <tr>
                                        <td colspan="18" align="right"><b>Total</b></td>
                                        <td align="right"><b><?php echo number_format($total_amt,2,'.','');?></b></td>
                                    </tr>
                                <?php } ?>  
                                </tfoot>
                            </table>
                        <?php } else if($data_type == 'Get Pledge Data') { ?>
                            <table class="table table-bordered table-striped filterTable" id="filterTable">
                                <thead>
                                    <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>
                                </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>
                                                <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>-->
                                                                <tbody>
                                                                    <?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 } ?>
                                                                </tbody>
                                                            </table>
                                                        </div>
                                                    </td>
                                                </tr>
                                            <?php } ?>
                                        <?php } ?>
                                    <?php } else {?>
                                        <tr>
                                            <td colspan="9" style="color: #0B6CCB;"><center>No Records Found!</center></td>
                                        </tr>
                                    <?php } ?>
                                </tbody>
                                <tfoot>
                                    
                                </tfoot>
                            </table>
                        <?php } ?>
                        
                    </div><!-- /.box-body -->
                </div><!-- /.box -->
            </div>
        </div>
    </section><!-- /.content -->
</aside><!-- /.right-side -->
<!-- ./wrapper -->

<script type="text/javascript">
    $(document).ready(function() {
        $('.start_date').bootstrapMaterialDatePicker({ 
            time: false, 
            format: 'DD-MM-YYYY'
        }). on('change', function(e, date) {
            if($('.end_date').val() != '') {
                $('.end_date').val('');
                var cur_date = new Date(date);
                $('.end_date').val(getTwoDigits(cur_date.getDate()) + '-'+ getTwoDigits((cur_date.getMonth() + 1)) + '-'+ cur_date.getFullYear());
                change_todate(getTwoDigits(cur_date.getDate()) + '-'+ getTwoDigits((cur_date.getMonth() + 1)) + '-'+ cur_date.getFullYear());
            }
        });
        
        
        $('.end_date').bootstrapMaterialDatePicker({ 
            time: false, 
            format: 'DD-MM-YYYY'
        });
        
        var date = $('.start_date').val();
        change_todate(date);
        
        if($('select[name="pledge"]').val() == 1) {
            $('.show_pledge_type').show();
        }
        
        $('select[name="pledge"]').change(function(){
            if($(this).val() == 1) {
                $('.show_pledge_type').show();
                $('.pledge_btn').removeAttr('disabled');
            } else {
                $('.show_pledge_type').hide();
                $('.pledge_btn').attr('disabled','disabled');
            }
        });
        
        $('.expand_icon').on('click', function() {
            if ($(this).closest('tr').next().children().children().hasClass('tbl-expand')) {
                if ($(this).hasClass('plus')) {
                    $(this).closest('tr').next().children().children().slideDown('1000');
                    $(this).removeClass('plus').addClass('minus');
                }
                else {
                    $(this).closest('tr').next().children().children().slideUp();
                    $(this).removeClass('minus').addClass('plus');
                }
            }
        });
    });
   
    function change_todate(date) {
       $('.end_date').bootstrapMaterialDatePicker('setMinDate', date);
    }    
</script>