<?php
$currency_symbol = $this->customlib->getSchoolCurrencyFormat();
?>

<div class="content-wrapper" style="min-height: 946px;">
    <section class="content-header">
        <h1>
            <i class="fa fa-money"></i> <?php echo $this->lang->line('fees_collection'); ?> <small> <?php echo $this->lang->line('filter_by_name1'); ?></small></h1>
											<a href="<?php  echo base_url(); ?>uniformreport" class="col-md pull-right">Uniform Report</a>
								<b style="padding-left:5px;padding-right:5px;"class="pull-right"> | </b>												 
								 <a href="<?php  echo base_url(); ?>admin/payroll/payrollreport" class="col-md pull-right">Payroll Report</a> 
								 <b style="padding-left:5px;padding-right:5px;"class="pull-right"> | </b>
								 <a href="<?php  echo base_url(); ?>admin/transaction/searchtransaction" class="col-md pull-right">Transaction Report</a>	
								 <b style="padding-left:5px;padding-right:5px;"class="pull-right"> | </b>
								 <a href="<?php  echo base_url(); ?>admin/transaction/studentacademicreport" class="col-md pull-right">Balance Fees Report</a>	
								 <b style="padding-left:5px;padding-right:5px;"class="pull-right"> | </b>
								 <a href="<?php  echo base_url(); ?>studentfee/reportbyname" class="col-md pull-right">Fee Statement</a>	
								 <b style="padding-left:5px;padding-right:5px;"class="pull-right"> | </b>
								 <a href="<?php  echo base_url(); ?>admin/users/admissionreport" class="col-md pull-right">Learner History</a>	
								 <b style="padding-left:5px;padding-right:5px;"class="pull-right"> | </b>
								 <a href="<?php  echo base_url(); ?>student/studentreport" class="col-md pull-right">Learner Report</a>	
    </section>
    <!-- Main content -->
    <section class="content">
        <div class="row">
            <div class="col-md-12">
                <div class="box box-primary">
                    <div class="box-header with-border">
                        <h3 class="box-title"><i class="fa fa-search"></i> <?php echo $this->lang->line('select_criteria'); ?></h3>
                    </div>
                    <form action="<?php echo site_url('admin/transaction/studentacademicreport') ?>"  method="post" accept-charset="utf-8">
                        <div class="box-body">
                            <?php echo $this->customlib->getCSRF(); ?>
                            <div class="row">
                                <div class="col-md-3">
                                    <div class="form-group">
                                        <label for="exampleInputEmail1">Learner Level</label><small class="req"> *</small>
                                        <select autofocus="" id="class_id" name="class_id" class="form-control" >
                                            <option value=""><?php echo $this->lang->line('select'); ?></option>
                                            <?php
                                            foreach ($classlist as $class) {
                                                ?>
                                                <option value="<?php echo $class['id'] ?>" <?php if (set_value('class_id') == $class['id']) echo "selected=selected" ?>><?php echo $class['class'] ?></option>
                                                <?php
                                                $count++;
                                            }
                                            ?>
                                        </select>
                                        <span class="text-danger"><?php echo form_error('class_id'); ?></span>
                                    </div>
                                </div>
                                <div class="col-md-3">
                                    <div class="form-group">
                                        <label for="exampleInputEmail1">Learner Class</label><small class="req"> *</small>
                                        <select  id="section_id" name="section_id" class="form-control" >
                                            <option value=""><?php echo $this->lang->line('select'); ?></option>
                                        </select>
                                        <span class="text-danger"><?php echo form_error('section_id'); ?></span>
                                    </div>
                                </div> 
                                <div class="col-md-3">
                                    <div class="form-group">
                                            <label><?php echo $this->lang->line('date_from'); ?></label>
                                            <input autofocus="" id="datefrom" name="date_from" placeholder="" type="text" class="form-control date"  value="<?php echo set_value('date_from', date($this->customlib->getSchoolDateFormat())); ?>" readonly="readonly"/>
                                            <span class="text-danger"><?php echo form_error('date_from'); ?></span>
                                    </div>
                                </div>                                
								<div class="col-md-3">
                                    <div class="form-group">
                                            <label><?php echo $this->lang->line('date_to'); ?></label>
                                            <input id="dateto" name="date_to" placeholder="" type="text" class="form-control date"  value="<?php echo set_value('date_to', date($this->customlib->getSchoolDateFormat())); ?>" readonly="readonly"/>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="box-footer">

                            <button type="submit" class="btn btn-primary btn-sm pull-right"><i class="fa fa-search"></i> <?php echo $this->lang->line('search'); ?></button>   </div>
                    </form>
                </div>
                <?php
                if (isset($student_due_fee)) {
                    ?>
                    <div class="row">
                        <div class="col-xs-12">
                            <div class="box box-info" id="transfee">
                                <div class="box-header ptbnull">
                                    <h3 class="box-title titlefix"><i class="fa fa-users"></i> Learner Fees Report</h3>
                                </div>                              
                                <div class="box-body table-responsive">
                                    <div class="download_label">Learner Fees Report</div>    
                                    <table class="table table-striped table-bordered table-hover example">
                                        <thead>
                                            <tr>
                                                <th class="text text-left">Date</th>
                                                <th class="text text-left">Reference</th>
                                                <th class="text text-left">Learner Name</th>
                                                <th class="text text-left"><?php echo $date_from; echo $this->lang->line('admission_no'); ?></th>                                           
                                                <th class="text text-right"><?php echo $this->lang->line('discount'); ?> <span><?php echo "(" . $currency_symbol . ")"; ?></span></th>
                                                <th class="text text-right"><?php echo $this->lang->line('fine'); ?> <span><?php echo "(" . $currency_symbol . ")"; ?></span></th>
                                                 <th class="text text-right">Deposits</th>
												<th class="text text-right">Payments</th>
                                                <th class="text-right"><?php echo $this->lang->line('balance'); ?> <span><?php echo "(" . $currency_symbol . ")"; ?></span></th>
                                            </tr>
                                        </thead>  
                                        <tbody>   

                                            <?php
													$balance=0;
													$buffer =$balance;	
													$balance=$buffer;		
															$module = "Learner";																
															$this->db->select('*');
															$this->db->from('journal');
															$this->db->where('module = ', $module);
															$journal_results = $this->db->get();	
															
                                            $grd_total = 0;
                                            $grd_paid = 0;
                                            $grd_discount = 0;
                                            $grd_fine = 0;

											
                                            if (!empty($student_due_fee)) {
                                                foreach ($student_due_fee as $key => $student) {

                                                    if ($student->totalfee != "N/A") {

                                                        $grd_total = $grd_total + $student->totalfee;
                                                    }
                                                    if ($student->deposit != "N/A") {

                                                        $grd_paid = $grd_paid + $student->deposit;
                                                    }
                                                    if ($student->discount != "N/A") {

                                                        $grd_discount = $grd_discount + $student->discount;
                                                    }
                                                    if ($student->fine != "N/A") {

                                                        $grd_fine = $fine + $student->fine;
                                                    }
																												
													        $student_session_id = $student->student_session_id;																																							
															
															$this->db->select('*');
															$this->db->from('student_fees_master');
															$this->db->where('student_session_id',$student_session_id);
															//$this->db->where('fee_session_group_id ',$fee_groups_id );
															$query = $this->db->get();
															$result = $query->row();
															
															$invoice_number = $result->id;	
															$date_created = $result->created_at ;	
															
															$invoice_number_new = "INV" . sprintf('%04s', $invoice_number);
										      
																$this->db->select('*');
																$this->db->from('student_fees_deposite');
																$this->db->where('student_fees_master_id',$invoice_number);
																$query0 = $this->db->get();
																$result0 = $query0->row();
																
																$receipt_number  = $result0->receipt ;
																
													$balance=($balance + number_format($student->totalfee, 2, '.', ''))-( number_format($student->deposit, 2, '.', ''));
													$buffer =$balance;
													if($balance<0)
													{
													 $balance=$balance - ($balance*2);
													
                                                    ?>
													<!--INVOICES ROW -->
                                                    <tr>
                                                        <td><?php echo $student->created_at; ?>   </td>
                                                        <td><?php echo $invoice_number_new; ?>   </td>
                                                        <td><?php echo $student->name; ?>   </td>
                                                        <td><?php echo $student->admission_no; ?>   </td>
                                                        <td class="text text-right">

                                                            <?php
                                                            if ($student->discount === "N/A") {
                                                                echo $student->discount;
                                                                ?>

                                                                <span class="text text-red righttext">xxx</span>
                                                                <?php
                                                            } else {
                                                                echo (number_format($student->discount, 2, '.', ''));
                                                            }
                                                            ?>
                                                        </td>
                                                        <td class="text text-right">

                                                            <?php
                                                            if ($student->fine === "N/A") {
                                                                ?>
                                                                <span class="text text-red righttext">xxx</span>
                                                                <?php
                                                            } else {
                                                                echo (number_format($student->fine, 2, '.', ''));
                                                            }
                                                            ?>
                                                        </td>
                                                        <td class="text text-right">
                                                            <?php
                                                            if ($student->totalfee === "N/A") {
                                                                ?>
                                                                <span class="text text-red righttext">xxx</span>
                                                                <?php
                                                            } else {

                                                                echo (number_format($student->totalfee, 2, '.', ''));
                                                            }
                                                            ?>
                                                        </td>
                                                        <td class="text-right"><?php echo "(".$balance.")";?></td>
                                                    </tr>  
														<!--RECEIPTING PART-->
													<tr>
													    <td><?php echo $student->created_at; ?>   </td>
														<td><?php echo $receipt_number; ?>   </td>
                                                        <td><?php echo $student->name; ?>   </td>
                                                        <td><?php echo $student->admission_no; ?>   </td>
                                                        <td class="text text-right">

                                                            <?php
                                                            if ($student->discount === "N/A") {
                                                                echo $student->discount;
                                                                ?>

                                                                <span class="text text-red righttext">xxx</span>
                                                                <?php
                                                            } else {
                                                                echo (number_format($student->discount, 2, '.', ''));
                                                            }
                                                            ?>
                                                        </td>
                                                        <td class="text text-right">

                                                            <?php
                                                            if ($student->fine === "N/A") {
                                                                ?>
                                                                <span class="text text-red righttext">xxx</span>
                                                                <?php
                                                            } else {
                                                                echo (number_format($student->fine, 2, '.', ''));
                                                            }
                                                            ?>
                                                        </td>
														<td class="text text-right">

                                                        </td>
                                                        <td class="text text-right">
                                                            <?php
                                                            if ($student->deposit === "N/A") {
                                                                ?>
                                                                <span class="text text-red righttext">xxx</span>
                                                                <?php
                                                            } else {
                                                                echo (number_format($student->deposit, 2, '.', ''));
                                                            }
                                                            ?>
                                                        </td>
                                                       <td class="text-right"><?php echo $balance;?></td>
                                                    </tr>	                                                  
                                                    <?php
													$balance=$buffer;
                                                  }
												  else{ ?>
												  
												  
												  <!--INVOICES ROW -->
                                                    <tr>
                                                        <td><?php $student_session_id = $student->student_session_id;

																$this->db->select('*');
																$this->db->from('student_fees_master');
																$this->db->where('student_session_id',$student_session_id);
																$query0 = $this->db->get();
																$result0 = $query0->row();
																
																$created_at = $result0->created_at;	
																
																echo $created_at;

														?>   </td>	
														<td><?php echo $invoice_number_new; ?>   </td>
                                                        <td><?php echo $student->name; ?>   </td>
                                                        <td><?php echo $student->admission_no; ?>   </td>
                                                        <td class="text text-right">

                                                            <?php
                                                            if ($student->discount === "N/A") {
                                                                echo $student->discount;
                                                                ?>

                                                                <span class="text text-red righttext">xxx</span>
                                                                <?php
                                                            } else {
                                                                echo (number_format($student->discount, 2, '.', ''));
                                                            }
                                                            ?>
                                                        </td>
                                                        <td class="text text-right">

                                                            <?php
                                                            if ($student->fine === "N/A") {
                                                                ?>
                                                                <span class="text text-red righttext">xxx</span>
                                                                <?php
                                                            } else {
                                                                echo (number_format($student->fine, 2, '.', ''));
                                                            }
                                                            ?>
                                                        </td>
                                                        <td class="text text-right">
                                                            <?php
                                                            if ($student->totalfee === "N/A") {
                                                                ?>
                                                                <span class="text text-red righttext">xxx</span>
                                                                <?php
                                                            } else {

                                                                echo (number_format($student->totalfee, 2, '.', ''));
                                                            }
                                                            ?>
                                                        </td
                                                        <td class="text-right"><?php echo "(".$balance.")";?></td>
                                                    </tr>  
														<!--RECEIPTING PART-->
													<tr>
                                                        <td><?php $student_session_id = $student->student_session_id;

																$this->db->select('*');
																$this->db->from('student_fees_master');
																$this->db->where('student_session_id',$student_session_id);
																$query0 = $this->db->get();
																$result0 = $query0->row();
																
																$created_at = $result0->created_at;	
																
																echo $created_at;?>   </td>		
														<td><?php echo $receipt_number; ?>   </td>		
                                                        <td><?php echo $student->name; ?>   </td>
                                                        <td><?php echo $student->admission_no; ?>   </td>
                                                        <td class="text text-right">

                                                            <?php
                                                            if ($student->discount === "N/A") {
                                                                echo $student->discount;
                                                                ?>

                                                                <span class="text text-red righttext">xxx</span>
                                                                <?php
                                                            } else {
                                                                echo (number_format($student->discount, 2, '.', ''));
                                                            }
                                                            ?>
                                                        </td>
                                                        <td class="text text-right">

                                                            <?php
                                                            if ($student->fine === "N/A") {
                                                                ?>
                                                                <span class="text text-red righttext">xxx</span>
                                                                <?php
                                                            } else {
                                                                echo (number_format($student->fine, 2, '.', ''));
                                                            }
                                                            ?>
                                                        </td>
														<td class="text text-right">

                                                        </td>
                                                        <td class="text text-right">
                                                            <?php
                                                            if ($student->deposit === "N/A") {
                                                                ?>
                                                                <span class="text text-red righttext">xxx</span>
                                                                <?php
                                                            } else {
                                                                echo (number_format($student->deposit, 2, '.', ''));
                                                            }
                                                            ?>
                                                        </td>
                                                       <td class="text-right"><?php echo $balance;?></td>
                                                    </tr>												  
												  
												  <?php }
											}
                                        } else {
                                                ?>
                                            <tfoot>
                                                <tr>
                                                    <td colspan="8" class="text-danger text-center">
                                                        <span class="input input-danger"><?php echo $this->lang->line('no_record_found'); ?></span>
                                                    </td>
                                                </tr>
                                            </tfoot>
                                            <?php
                                        }
                                        ?>
									<?php 

										 foreach ($journal_results->result() as $row1)  
										 {				
										 
													 $balance=($balance + $row1->debit)-( $row1->credit);
													$buffer =$balance;  
													
											if($balance<0)
											{
											 $balance=$balance - ($balance*2);
											 ?>
															<tr>
																<td class="mailbox-name"><?php echo $row1->date;?></td>
																<td class="mailbox-name"><?php echo $row1->receipt;?></td>
																<td class="mailbox-name"><?php echo $row1->account;?></td>
																<td class="mailbox-name">----</td>
																<td class="mailbox-name">----</td>
																<td class="mailbox-name">----</td>
																<td class="text text-right"><?php if($row1->debit == 0){echo "";} else{ echo $row1->debit;}?></td>
																<td class="text text-right"><?php if($row1->credit == 0){echo "";} else{ echo $row1->credit;}?></td>    
																<td class="text text-right"><?php echo "(".$balance.")";?></td> 																		
															</tr>														 
											 <?php $balance=$buffer; 
												}else{   ?>
																<tr>
																<td class="mailbox-name"><?php echo $row1->date;?></td>
																<td class="mailbox-name"><?php echo $row1->receipt;?></td>
																<td class="mailbox-name"><?php echo $row1->account;?></td>
																<td class="mailbox-name">----</td>
																<td class="mailbox-name">----</td>
																<td class="mailbox-name">----</td>																
																<td class="text text-right"><?php if($row1->debit == 0){echo "";} else{ echo $row1->debit;}?></td>
																<td class="text text-right"><?php if($row1->credit == 0){echo "";} else{ echo $row1->credit;}?></td>    
																<td class="text text-right"><?php echo $balance;?></td> 																		
															</tr>															
												<?php }																
										 }													 
											?>										
                                        <tr  class="box box-solid total-bg">
                                            <td></td>
                                            <td></td>
                                            <td></td>

                                            <td class="text text-right">
                                                <?php echo $this->lang->line('grand_total'); ?>
                                            </td>

                                            <td class="text text-right">
                                                <?php echo ($currency_symbol . number_format($grd_discount, 2, '.', '') ); ?>
                                            </td>
                                            <td class="text text-right">
                                                <?php echo ($currency_symbol . number_format($grd_fine, 2, '.', '') ); ?>
                                            </td>
											<td class="text text-right">
                                                <?php echo ($currency_symbol . number_format($grd_total, 2, '.', '') ); ?>
                                            </td>
                                            <td class="text text-right">
                                                <?php echo ($currency_symbol . number_format($grd_paid, 2, '.', '') ); ?>
                                            </td> 

                                            <td class="text text-right">
                                                <?php echo $currency_symbol.''.$balance; ?>
                                            </td>
                                        </tr>
										<tr>
										     <td>           
		
													<div class="btn-group pull-right"> 														
                                                        <button  class="btn btn-xs btn-info printInv" 
																	data-class_id="<?php echo  $class_id; ?>" 
																	data-section_id="<?php echo $section_id;?>"  
																	data-date_from="<?php echo $date_from2; ?>"  
																	data-date_to="<?php echo $date_to2; ?>"                  
                                                                 title="<?php echo $this->lang->line('print'); ?>"
                                                                 ><i class="fa fa-print"></i> Print Statement</button>
                                                    </div> 
												</td>
										</tr>
                                        </tbody> 
                                    </table>
                                </div>                            
                            </div>                       
                        </div>
                    </div>
                    <?php
                }
                ?>
                </section>
            </div>
<script type="text/javascript">
    $(document).ready(function () {
        $(document).on('click', '.printDoc', function () {
            var main_invoice = $(this).data('main_invoice');
            var sub_invoice = $(this).data('sub_invoice');
            var student_session_id = '<?php echo $student_session_id; ?>';
            $.ajax({
                url: '<?php echo site_url("studentfee/printFeesByName") ?>',
                type: 'post',
                data: {'student_session_id': student_session_id, 'main_invoice': main_invoice, 'sub_invoice': sub_invoice},
                success: function (response) {
                    Popup(response);
                }
            });
        });
        $(document).on('click', '.printInv', function () {
            var class_id = $(this).data('class_id');
            var section_id = $(this).data('section_id');
            var date_from = $(this).data('date_from');
            var date_to = $(this).data('date_to');
            $.ajax({
                url: '<?php echo site_url("admin/transaction/printBalanceFeesByGroup") ?>',  
                type: 'post',
                data: {'class_id': class_id, 'section_id': section_id, 'date_from': date_from, 'date_to': date_to},
                success: function (response) {
                    Popup(response);
                }
            });
        });
    });
</script>

<script>

    var base_url = '<?php echo base_url() ?>';
    function Popup(data)
    {

        var frame1 = $('<iframe />');
        frame1[0].name = "frame1";
        frame1.css({"position": "absolute", "top": "-1000000px"});
        $("body").append(frame1);
        var frameDoc = frame1[0].contentWindow ? frame1[0].contentWindow : frame1[0].contentDocument.document ? frame1[0].contentDocument.document : frame1[0].contentDocument;
        frameDoc.document.open();
        //Create a new HTML document.
        frameDoc.document.write('<html>');
        frameDoc.document.write('<head>');
        frameDoc.document.write('<title></title>');
        frameDoc.document.write('<link rel="stylesheet" href="' + base_url + 'backend/bootstrap/css/bootstrap.min.css">');
        frameDoc.document.write('<link rel="stylesheet" href="' + base_url + 'backend/dist/css/font-awesome.min.css">');
        frameDoc.document.write('<link rel="stylesheet" href="' + base_url + 'backend/dist/css/ionicons.min.css">');
        frameDoc.document.write('<link rel="stylesheet" href="' + base_url + 'backend/dist/css/AdminLTE.min.css">');
        frameDoc.document.write('<link rel="stylesheet" href="' + base_url + 'backend/dist/css/skins/_all-skins.min.css">');
        frameDoc.document.write('<link rel="stylesheet" href="' + base_url + 'backend/plugins/iCheck/flat/blue.css">');
        frameDoc.document.write('<link rel="stylesheet" href="' + base_url + 'backend/plugins/morris/morris.css">');
        frameDoc.document.write('<link rel="stylesheet" href="' + base_url + 'backend/plugins/jvectormap/jquery-jvectormap-1.2.2.css">');
        frameDoc.document.write('<link rel="stylesheet" href="' + base_url + 'backend/plugins/datepicker/datepicker3.css">');
        frameDoc.document.write('<link rel="stylesheet" href="' + base_url + 'backend/plugins/daterangepicker/daterangepicker-bs3.css">');
        frameDoc.document.write('</head>');
        frameDoc.document.write('<body>');
        frameDoc.document.write(data);
        frameDoc.document.write('</body>');
        frameDoc.document.write('</html>');
        frameDoc.document.close();
        setTimeout(function () {
            window.frames["frame1"].focus();
            window.frames["frame1"].print();
            frame1.remove();
        }, 500);


        return true;
    }
    $(document).ready(function () {
        $('.delmodal').modal({
            backdrop: 'static',
            keyboard: false,
            show: false
        })
        $('#confirm-delete').on('show.bs.modal', function (e) {
            $('.invoice_no', this).text("");
            $('#main_invoice', this).val("");
            $('#sub_invoice', this).val("");

            $('.invoice_no', this).text($(e.relatedTarget).data('invoiceno'));
            $('#main_invoice', this).val($(e.relatedTarget).data('main_invoice'));
            $('#sub_invoice', this).val($(e.relatedTarget).data('sub_invoice'));


        });

        $('#confirm-discountdelete').on('show.bs.modal', function (e) {
            $('.discount_title', this).text("");
            $('#discount_id', this).val("");
            $('.discount_title', this).text($(e.relatedTarget).data('discounttitle'));
            $('#discount_id', this).val($(e.relatedTarget).data('discountid'));
        });

        $('#confirm-delete').on('click', '.btn-ok', function (e) {
            var $modalDiv = $(e.delegateTarget);
            var main_invoice = $('#main_invoice').val();
            var sub_invoice = $('#sub_invoice').val();

            $modalDiv.addClass('modalloading');
            $.ajax({
                type: "post",
                url: '<?php echo site_url("studentfee/deleteFee") ?>',
                dataType: 'JSON',
                data: {'main_invoice': main_invoice, 'sub_invoice': sub_invoice},
                success: function (data) {
                    $modalDiv.modal('hide').removeClass('modalloading');
                    location.reload(true);
                }
            });


        });

        $('#confirm-discountdelete').on('click', '.btn-discountdel', function (e) {
            var $modalDiv = $(e.delegateTarget);
            var discount_id = $('#discount_id').val();


            $modalDiv.addClass('modalloading');
            $.ajax({
                type: "post",
                url: '<?php echo site_url("studentfee/deleteStudentDiscount") ?>',
                dataType: 'JSON',
                data: {'discount_id': discount_id},
                success: function (data) {
                    $modalDiv.modal('hide').removeClass('modalloading');
                    location.reload(true);
                }
            });


        });


        $(document).on('click', '.btn-ok', function (e) {
            var $modalDiv = $(e.delegateTarget);
            var main_invoice = $('#main_invoice').val();
            var sub_invoice = $('#sub_invoice').val();

            $modalDiv.addClass('modalloading');
            $.ajax({
                type: "post",
                url: '<?php echo site_url("studentfee/deleteFee") ?>',
                dataType: 'JSON',
                data: {'main_invoice': main_invoice, 'sub_invoice': sub_invoice},
                success: function (data) {
                    $modalDiv.modal('hide').removeClass('modalloading');
                    location.reload(true);
                }
            });


        });


        $('.detail_popover').popover({
            placement: 'right',
            title: '',
            trigger: 'hover',
            container: 'body',
            html: true,
            content: function () {
                return $(this).closest('td').find('.fee_detail_popover').html();
            }
        });
    });



</script>

<script type="text/javascript">
    $(document).ready(function () {
        var date_format = '<?php echo $result = strtr($this->customlib->getSchoolDateFormat(), ['d' => 'dd', 'm' => 'mm', 'Y' => 'yyyy',]) ?>';
        $(".date").datepicker({
            format: date_format,
            autoclose: true,
            todayHighlight: true
        });
    });
</script>

<script type="text/javascript">


    $("#myFeesModal").on('shown.bs.modal', function (e) {
        console.log("sdrere");
        e.stopPropagation();
        var discount_group_dropdown = '<option value=""><?php echo $this->lang->line('select'); ?></option>';
        var data = $(e.relatedTarget).data();
        $('#discount_group').html("");
        $("span[id$='_error']").html("");
        $('.fees_title').html("");
        $('#amount').val("");
        $('#amount_discount').val("0");
        $('#amount_fine').val("0");
        var type = data.type;
        var amount = data.amount;
        var group = data.group;
        var fee_groups_feetype_id = data.fee_groups_feetype_id;
        var student_fees_master_id = data.student_fees_master_id;
        var student_session_id = data.student_session_id;

        $('.fees_title').html("<b>" + group + ":</b> " + type);
        $('#fee_groups_feetype_id').val(fee_groups_feetype_id);
        $('#student_fees_master_id').val(student_fees_master_id);



        $.ajax({
            type: "post",
            url: '<?php echo site_url("studentfee/geBalanceFee") ?>',
            dataType: 'JSON',
            data: {'fee_groups_feetype_id': fee_groups_feetype_id,
                'student_fees_master_id': student_fees_master_id,
                'student_session_id': student_session_id
            },
            success: function (data) {

                if (data.status == "success") {
                    fee_amount = data.balance;

                    $('#amount').val(data.balance);
                    console.log(data.discount_not_applied);

                    $.each(data.discount_not_applied, function (i, obj)
                    {
                        discount_group_dropdown += "<option value=" + obj.student_fees_discount_id + " data-disamount=" + obj.amount + ">" + obj.code + "</option>";
                    });
                    $('#discount_group').append(discount_group_dropdown);




                }
            }
        });


    });

</script>

<script type="text/javascript">

    $(document).ready(function () {
        $('.table-fixed-header').fixedHeader();
    });

//  $(window).on('resize', function () {
//    $('.header-copy').width($('.table-fixed-header').width())
//});

    (function ($) {

        $.fn.fixedHeader = function (options) {
            var config = {
                topOffset: 50
                        //bgColor: 'white'
            };
            if (options) {
                $.extend(config, options);
            }

            return this.each(function () {
                var o = $(this);

                var $win = $(window);
                var $head = $('thead.header', o);
                var isFixed = 0;
                var headTop = $head.length && $head.offset().top - config.topOffset;

                function processScroll() {
                    if (!o.is(':visible')) {
                        return;
                    }
                    if ($('thead.header-copy').size()) {
                        $('thead.header-copy').width($('thead.header').width());
                    }
                    var i;
                    var scrollTop = $win.scrollTop();
                    var t = $head.length && $head.offset().top - config.topOffset;
                    if (!isFixed && headTop !== t) {
                        headTop = t;
                    }
                    if (scrollTop >= headTop && !isFixed) {
                        isFixed = 1;
                    } else if (scrollTop <= headTop && isFixed) {
                        isFixed = 0;
                    }
                    isFixed ? $('thead.header-copy', o).offset({
                        left: $head.offset().left
                    }).removeClass('hide') : $('thead.header-copy', o).addClass('hide');
                }
                $win.on('scroll', processScroll);

                // hack sad times - holdover until rewrite for 2.1
                $head.on('click', function () {
                    if (!isFixed) {
                        setTimeout(function () {
                            $win.scrollTop($win.scrollTop() - 47);
                        }, 10);
                    }
                });

                $head.clone().removeClass('header').addClass('header-copy header-fixed').appendTo(o);
                var header_width = $head.width();
                o.find('thead.header-copy').width(header_width);
                o.find('thead.header > tr:first > th').each(function (i, h) {
                    var w = $(h).width();
                    o.find('thead.header-copy> tr > th:eq(' + i + ')').width(w);
                });
                $head.css({
                    margin: '0 auto',
                    width: o.width(),
                    'background-color': config.bgColor
                });
                processScroll();
            });
        };

    })(jQuery);
    $(document).ready(function () {
        $.extend($.fn.dataTable.defaults, {
            ordering: false,
            paging: false,
            bSort: false,
            info: false
        });
    });
</script>


<script type="text/javascript">
    $(document).ready(function () {
        $(document).on('click', '.printSelected', function () {
            var array_to_print = [];
            $.each($("input[name='fee_checkbox']:checked"), function () {
                var section_id = $(this).data('section_id');
                var class_id = $(this).data('class_id');
                var student_id = $(this).data('student_id');
                item = {}
                item ["section_id"] = section_id;
                item ["class_id"] = class_id;
                item ["student_id"] = student_id;

                array_to_print.push(item);
            });
            if (array_to_print.length == 0) {
                alert("no record selected");
            } else {
                $.ajax({
                    url: '<?php echo site_url("studentfee/printFeesStatementByGroup") ?>',
                    type: 'post',
                    data: {'data': JSON.stringify(array_to_print)},
                    success: function (response) {
                        Popup(response);
                    }
                });
            }
        });
    });


    $(function () {
        $(document).on('change', "#discount_group", function () {
            var amount = $('option:selected', this).data('disamount');

            var balance_amount = (parseFloat(fee_amount) - parseFloat(amount)).toFixed(2);
            if (typeof amount !== typeof undefined && amount !== false) {
                $('div#myFeesModal').find('input#amount_discount').prop('readonly', true).val(amount);
                $('div#myFeesModal').find('input#amount').val(balance_amount);

            } else {
                $('div#myFeesModal').find('input#amount').val(fee_amount);
                $('div#myFeesModal').find('input#amount_discount').prop('readonly', false).val(0);
            }

        });
    });
</script>

            <script type="text/javascript">
                function getSectionByClass(class_id, section_id) {
                    if (class_id != "" && section_id != "") {
                        $('#section_id').html("");
                        var base_url = '<?php echo base_url() ?>';
                        var div_data = '<option value=""><?php echo $this->lang->line('select'); ?></option>';
                        $.ajax({
                            type: "GET",
                            url: base_url + "sections/getByClass",
                            data: {'class_id': class_id},
                            dataType: "json",
                            success: function (data) {
                                $.each(data, function (i, obj)
                                {
                                    var sel = "";
                                    if (section_id == obj.section_id) {
                                        sel = "selected";
                                    }
                                    div_data += "<option value=" + obj.section_id + " " + sel + ">" + obj.section + "</option>";
                                });
                                $('#section_id').append(div_data);
                            }
                        });
                    }
                }
                $(document).ready(function () {
                    $(document).on('change', '#class_id', function (e) {
                        $('#section_id').html("");
                        var class_id = $(this).val();
                        var base_url = '<?php echo base_url() ?>';
                        var div_data = '<option value=""><?php echo $this->lang->line('select'); ?></option>';
                        $.ajax({
                            type: "GET",
                            url: base_url + "sections/getByClass",
                            data: {'class_id': class_id},
                            dataType: "json",
                            success: function (data) {
                                $.each(data, function (i, obj)
                                {
                                    div_data += "<option value=" + obj.section_id + ">" + obj.section + "</option>";
                                });

                                $('#section_id').append(div_data);
                            }
                        });
                    });
                    $(document).on('change', '#section_id', function (e) {
                        getStudentsByClassAndSection();
                    });
                    var class_id = $('#class_id').val();
                    var section_id = '<?php echo set_value('section_id') ?>';
                    getSectionByClass(class_id, section_id);
                });
                function getStudentsByClassAndSection() {
                    $('#student_id').html("");
                    var class_id = $('#class_id').val();
                    var section_id = $('#section_id').val();
                    var base_url = '<?php echo base_url() ?>';
                    var div_data = '<option value=""><?php echo $this->lang->line('select'); ?></option>';
                    $.ajax({
                        type: "GET",
                        url: base_url + "student/getByClassAndSection",
                        data: {'class_id': class_id, 'section_id': section_id},
                        dataType: "json",
                        success: function (data) {
                            $.each(data, function (i, obj)
                            {
                                div_data += "<option value=" + obj.id + ">" + obj.firstname + " " + obj.lastname + "</option>";
                            });
                            $('#student_id').append(div_data);
                        }
                    });
                }

                $(document).ready(function () {
                    $("ul.type_dropdown input[type=checkbox]").each(function () {
                        $(this).change(function () {
                            var line = "";
                            $("ul.type_dropdown input[type=checkbox]").each(function () {
                                if ($(this).is(":checked")) {
                                    line += $("+ span", this).text() + ";";
                                }
                            });
                            $("input.form-control").val(line);
                        });
                    });
                });
                $(document).ready(function () {
                    $.extend($.fn.dataTable.defaults, {
                        ordering: false,
                        paging: false,
                        bSort: false,
                        info: false
                    });
                });
            </script>


