<?php 
$def_ref_id=$this->uri->segment('3');
$course_id=$this->uri->segment('4');

$courses_table='courses';
$course='';
$subject_stream='';
$get_course_info=$this->NewFeeModel->get_item_data($course_id,$courses_table);
if($get_course_info){
    foreach($get_course_info as $course_info){
        $course=$course_info['course'];
        $subject_stream=$course_info['subject_stream'];
    }
}
$acedemic_session=$this->session->userdata('acedemic_session');
$get_all_course_students=$this->NewFeeModel->get_course_students_for_ac_sessionn($course_id,$acedemic_session);
$def_data_table='defaulter_requests';

$get_def_data_info=$this->NewFeeModel->get_item_data($def_ref_id,$def_data_table);
if($get_def_data_info){
    foreach($get_def_data_info as $def_data_info){
        
        $grand_total=0;
        
        $month_array=json_decode($def_data_info['month_array']);
        // var_dump($month_array);
        $apr_exist=0;
        $may_exist=0;
        $jun_exist=0;
        $jul_exist=0;
        $aug_exist=0;
        $sep_exist=0;
        $oct_exist=0;
        $nov_exist=0;
        $dec_exist=0;
        $jan_exist=0;
        $feb_exist=0;
        $mar_exist=0;
        
        $apr='april';
        $may='may';
        $jun='june';
        $jul='july';
        $aug='august';
        $sep='september';
        $oct='october';
        $nov='november';
        $dec='december';
        $jan='january';
        $feb='february';
        $mar='march';
        
        
        foreach($month_array as $month_arr){
            // echo $month_arr; echo "<br>";
            $month_no=$month_arr;
            if($month_no ==4){
                $apr_exist=1;
            }else if($month_no ==5){
                $apr_exist=1;
                $may_exist=1;
            }else if($month_no ==6){
                $apr_exist=1;
                $may_exist=1;
                $jun_exist=1;
            }else if($month_no ==7){
                $apr_exist=1;
                $may_exist=1;
                $jun_exist=1;
                $jul_exist=1;
            }else if($month_no ==8){
                $apr_exist=1;
                $may_exist=1;
                $jun_exist=1;
                $jul_exist=1;
                $aug_exist=1;
            }else if($month_no ==9){
                $apr_exist=1;
                $may_exist=1;
                $jun_exist=1;
                $jul_exist=1;
                $aug_exist=1;
                $sep_exist=1;
            }else if($month_no ==10){
                $apr_exist=1;
                $may_exist=1;
                $jun_exist=1;
                $jul_exist=1;
                $aug_exist=1;
                $sep_exist=1;
                $oct_exist=1;
            }else if($month_no ==11){
                $apr_exist=1;
                $may_exist=1;
                $jun_exist=1;
                $jul_exist=1;
                $aug_exist=1;
                $sep_exist=1;
                $oct_exist=1;
                $nov_exist=1;
            }else if($month_no ==12){
                $apr_exist=1;
                $may_exist=1;
                $jun_exist=1;
                $jul_exist=1;
                $aug_exist=1;
                $sep_exist=1;
                $oct_exist=1;
                $nov_exist=1;
                $dec_exist=1;
            }else if($month_no ==1){
                $apr_exist=1;
                $may_exist=1;
                $jun_exist=1;
                $jul_exist=1;
                $aug_exist=1;
                $sep_exist=1;
                $oct_exist=1;
                $nov_exist=1;
                $dec_exist=1;
                $jan_exist=1;
            }else if($month_no ==2){
                $apr_exist=1;
                $may_exist=1;
                $jun_exist=1;
                $jul_exist=1;
                $aug_exist=1;
                $sep_exist=1;
                $oct_exist=1;
                $nov_exist=1;
                $dec_exist=1;
                $jan_exist=1;
                $feb_exist=1;
            }else if($month_no ==3){
                $apr_exist=1;
                $may_exist=1;
                $jun_exist=1;
                $jul_exist=1;
                $aug_exist=1;
                $sep_exist=1;
                $oct_exist=1;
                $nov_exist=1;
                $dec_exist=1;
                $jan_exist=1;
                $feb_exist=1;
                $mar_exist=1;
            }
            
            
            
        }        
        
?>
<style>
    
</style>

<div class="container bg-white mt-3 mb-3 pt-3 pb-3">
    <div class="row">
        <div class="col-sm-12">
            <ul class="breadcrumb">
                <li class="breadcrumb-item"><a href="<?php echo base_url();?>Welcome">Home</a></li>
                <li class="breadcrumb-item"><a href="<?php echo base_url();?>Fee/all_students"></a>Fee</li>
                <li class="breadcrumb-item">Defaulter</li>
                <li class="breadcrumb-item"><?php echo $course; echo " "; echo $subject_stream; ?></li>
            </ul>
            
            <div style="width:100%;" class="mb-3"> 
                <a class="btn btn-sm btn-danger" href="<?php echo base_url();?>Fee/defaulter_manual_pdf/<?php echo $def_ref_id; echo "/"; echo $course_id; ?>">
                    <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-file-earmark-pdf-fill" viewBox="0 0 16 16">
                        <path d="M5.523 12.424c.14-.082.293-.162.459-.238a7.878 7.878 0 0 1-.45.606c-.28.337-.498.516-.635.572a.266.266 0 0 1-.035.012.282.282 0 0 1-.026-.044c-.056-.11-.054-.216.04-.36.106-.165.319-.354.647-.548zm2.455-1.647c-.119.025-.237.05-.356.078a21.148 21.148 0 0 0 .5-1.05 12.045 12.045 0 0 0 .51.858c-.217.032-.436.07-.654.114zm2.525.939a3.881 3.881 0 0 1-.435-.41c.228.005.434.022.612.054.317.057.466.147.518.209a.095.095 0 0 1 .026.064.436.436 0 0 1-.06.2.307.307 0 0 1-.094.124.107.107 0 0 1-.069.015c-.09-.003-.258-.066-.498-.256zM8.278 6.97c-.04.244-.108.524-.2.829a4.86 4.86 0 0 1-.089-.346c-.076-.353-.087-.63-.046-.822.038-.177.11-.248.196-.283a.517.517 0 0 1 .145-.04c.013.03.028.092.032.198.005.122-.007.277-.038.465z"/>
                        <path fill-rule="evenodd" d="M4 0h5.293A1 1 0 0 1 10 .293L13.707 4a1 1 0 0 1 .293.707V14a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V2a2 2 0 0 1 2-2zm5.5 1.5v2a1 1 0 0 0 1 1h2l-3-3zM4.165 13.668c.09.18.23.343.438.419.207.075.412.04.58-.03.318-.13.635-.436.926-.786.333-.401.683-.927 1.021-1.51a11.651 11.651 0 0 1 1.997-.406c.3.383.61.713.91.95.28.22.603.403.934.417a.856.856 0 0 0 .51-.138c.155-.101.27-.247.354-.416.09-.181.145-.37.138-.563a.844.844 0 0 0-.2-.518c-.226-.27-.596-.4-.96-.465a5.76 5.76 0 0 0-1.335-.05 10.954 10.954 0 0 1-.98-1.686c.25-.66.437-1.284.52-1.794.036-.218.055-.426.048-.614a1.238 1.238 0 0 0-.127-.538.7.7 0 0 0-.477-.365c-.202-.043-.41 0-.601.077-.377.15-.576.47-.651.823-.073.34-.04.736.046 1.136.088.406.238.848.43 1.295a19.697 19.697 0 0 1-1.062 2.227 7.662 7.662 0 0 0-1.482.645c-.37.22-.699.48-.897.787-.21.326-.275.714-.08 1.103z"/>
                    </svg>
                </a>
                <button class="btn btn-sm btn-info">CSV</button>
            </div>
            
            <div class="table-responsive">
                <table class="table table-bordered table-striped" id="mytable">
                    <thead>
                        <tr>
                            <th>#</th>
                            <th>Student Name</th>
                            <th>Father's Name</th>
                            <th>Contact No.</th>
                            <th>OP + CY</th>
                            <th>Fee Due for Months</th>
                            <!--<th></th>-->
                            <!--<th></th>-->
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                        $count=0;
                        if($get_all_course_students){
                            foreach($get_all_course_students as $course_students){
                                $sid=$course_students['sid'];
                                
                                $prev_acedemic_session=1;
                                $opening_fee_amount=0;
                                $opening_fee_received_amount=0;
                                $opening_fee_discount=0;
                                $get_opening_fee_info=$this->NewFeeModel->get_students_opening_fee($sid,$prev_acedemic_session);
                                if($get_opening_fee_info){
                                    foreach($get_opening_fee_info as $opening_fee_info){
                                        $opening_fee_amount=$opening_fee_amount + $opening_fee_info['opening_fee_amount'] ;
                                    }
                                }
                                
                                $get_received_opening_fee_data=$this->NewFeeModel->get_opening_fee_invoices($sid,$acedemic_session);
                                if($get_received_opening_fee_data){
                                    foreach($get_received_opening_fee_data as $opening_fee_data){
                                        $opening_fee_received_amount=$opening_fee_received_amount + $opening_fee_data['received_amount'];
                                        $opening_fee_discount=$opening_fee_discount + $opening_fee_data['discount'];
                                    }
                                }
                                $opening_bal_amount=$opening_fee_amount - ($opening_fee_received_amount + $opening_fee_discount);
                                
                                $student_display_status=0;
                                $apr_fee_status=0;
                                $may_fee_status=0;
                                $jun_fee_status=0;
                                $jul_fee_status=0;
                                $aug_fee_status=0;
                                $sep_fee_status=0;
                                $oct_fee_status=0;
                                $nov_fee_status=0;
                                $dec_fee_status=0;
                                $jan_fee_status=0;
                                $feb_fee_status=0;
                                $mar_fee_status=0;
                                
                                
                                $student_fee_data=$this->NewFeeModel->get_fee_data_for($sid,$acedemic_session);
                                if($student_fee_data){
                                    foreach($student_fee_data as $fee_data){
                                        if($fee_data['april'] == 1){
                                            $apr_fee_status=$apr_fee_status + 1;
                                        }
                                        if($fee_data['may'] == 1){
                                            $may_fee_status=$may_fee_status + 1;
                                        }
                                        if($fee_data['june'] == 1){
                                            $jun_fee_status=$jun_fee_status + 1;
                                        }
                                        if($fee_data['july'] == 1){
                                            $jul_fee_status=$jul_fee_status + 1;
                                        }
                                        if($fee_data['august'] == 1){
                                            $aug_fee_status=$aug_fee_status + 1;
                                        }
                                        if($fee_data['september'] == 1){
                                            $sep_fee_status=$sep_fee_status + 1;
                                        }
                                        if($fee_data['october'] == 1){
                                            $oct_fee_status=$oct_fee_status + 1;
                                        }
                                        if($fee_data['november'] == 1){
                                            $nov_fee_status=$nov_fee_status + 1;
                                        }
                                        if($fee_data['december'] == 1){
                                            $dec_fee_status=$dec_fee_status + 1;
                                        }
                                        if($fee_data['january'] == 1){
                                            $jan_fee_status=$jan_fee_status + 1;
                                        }
                                        if($fee_data['february'] == 1){
                                            $feb_fee_status=$feb_fee_status + 1;
                                        }
                                        if($fee_data['march'] == 1){
                                            $mar_fee_status=$mar_fee_status + 1;
                                        }
                                    }
                                }
                                if($apr_exist ==1 && $apr_fee_status == 0){
                                    $student_display_status = 1;
                                }else if($may_exist ==1 && $may_fee_status == 0){
                                    $student_display_status = 1;
                                }else if($jun_exist ==1 && $jun_fee_status == 0){
                                    $student_display_status = 1;
                                }else if($jul_exist ==1 && $jul_fee_status == 0){
                                    $student_display_status = 1;
                                }else if($aug_exist ==1 && $aug_fee_status == 0){
                                    $student_display_status = 1;
                                }else if($sep_exist ==1 && $sep_fee_status == 0){
                                    $student_display_status = 1;
                                }else if($oct_exist ==1 && $oct_fee_status == 0){
                                    $student_display_status = 1;
                                }else if($nov_exist ==1 && $nov_fee_status == 0){
                                    $student_display_status = 1;
                                }else if($dec_exist ==1 && $dec_fee_status == 0){
                                    $student_display_status = 1;
                                }else if($jan_exist ==1 && $jan_fee_status == 0){
                                    $student_display_status = 1;
                                }else if($feb_exist ==1 && $feb_fee_status == 0){
                                    $student_display_status = 1;
                                }else if($mar_exist ==1 && $mar_fee_status == 0){
                                    $student_display_status = 1;
                                }
                                
                                $student_cy_bal_fee=0;
                                $bal_amount=0;
                                $extra_amount=0;
                                
                                $get_balance_fee_invoices=$this->NewFeeModel->get_balance_fee_invoices($sid,$acedemic_session);
                                if($get_balance_fee_invoices){
                                    foreach($get_balance_fee_invoices as $balance_fee_invoices){
                                        $bal_amount=$bal_amount + $balance_fee_invoices['balance_amount'];
                                    }
                                }
                                
                                
                                $get_extra_fee_invoices=$this->NewFeeModel->get_extra_fee_invoices($sid,$acedemic_session);
                                if($get_extra_fee_invoices){
                                    foreach($get_extra_fee_invoices as $extra_fee_invoices){
                                        $extra_amount=$extra_amount + $extra_fee_invoices['extra_amount'];
                                    }
                                }
                                $student_cy_bal_fee=$student_cy_bal_fee + $bal_amount;
                                
                                $get_cy_fee_data=$this->NewFeeModel->fee_structure($course_id,$acedemic_session);
                                if($get_cy_fee_data){
                                    foreach($get_cy_fee_data as $data){
                                        if($apr_exist == 1 && $apr_fee_status == 0 && $data['april'] == 1){
                                            $student_cy_bal_fee=$student_cy_bal_fee + $data['amount'];
                                        }
                                        
                                        if($may_exist == 1 && $may_fee_status == 0 && $data['may'] == 1){
                                            $student_cy_bal_fee=$student_cy_bal_fee + $data['amount'];
                                        }
                                        
                                        if($jun_exist == 1 && $jun_fee_status == 0 && $data['june'] == 1){
                                            $student_cy_bal_fee=$student_cy_bal_fee + $data['amount'];
                                        }
                                        
                                        if($jul_exist == 1 && $jul_fee_status == 0 && $data['july'] == 1){
                                            $student_cy_bal_fee=$student_cy_bal_fee + $data['amount'];
                                        }
                                        
                                        if($aug_exist == 1 && $aug_fee_status == 0 && $data['august'] == 1){
                                            $student_cy_bal_fee=$student_cy_bal_fee + $data['amount'];
                                        }
                                        
                                        if($sep_exist == 1 && $sep_fee_status == 0 && $data['september'] == 1){
                                            $student_cy_bal_fee=$student_cy_bal_fee + $data['amount'];
                                        }
                                        
                                        if($oct_exist == 1 && $oct_fee_status == 0 && $data['october'] == 1){
                                            $student_cy_bal_fee=$student_cy_bal_fee + $data['amount'];
                                        }
                                        
                                        if($nov_exist == 1 && $nov_fee_status == 0 && $data['november'] == 1){
                                            $student_cy_bal_fee=$student_cy_bal_fee + $data['amount'];
                                        }
                                        
                                        if($dec_exist == 1 && $dec_fee_status == 0 && $data['december'] == 1){
                                            $student_cy_bal_fee=$student_cy_bal_fee + $data['amount'];
                                        }
                                        
                                        if($jan_exist == 1 && $jan_fee_status == 0 && $data['january'] == 1){
                                            $student_cy_bal_fee=$student_cy_bal_fee + $data['amount'];
                                        }
                                        
                                        if($feb_exist == 1 && $feb_fee_status == 0 && $data['february'] == 1){
                                            $student_cy_bal_fee=$student_cy_bal_fee + $data['amount'];
                                        }
                                        
                                        if($mar_exist == 1 && $mar_fee_status == 0 && $data['march'] == 1){
                                            $student_cy_bal_fee=$student_cy_bal_fee + $data['amount'];
                                        }
                                    }
                                }
                                
                                
                                // if($apr_exist == 1 && $apr_fee_status == 0){
                                       
                                //     if($get_cy_fee_data){
                                //         foreach($get_cy_fee_data as $cy_fee_data){
                                //             if($cy_fee_data['april'] == 1 ){
                                //                 $student_cy_bal_fee=$student_cy_bal_fee + $cy_fee_data['amount'];
                                //             }
                                //         }
                                //     }
                                // }
                                
                                // if($may_exist == 1 && $may_fee_status == 0){
                                       
                                //     if($get_cy_fee_data){
                                //         foreach($get_cy_fee_data as $cy_fee_data){
                                //             if($cy_fee_data['may'] == 1){
                                //                 $student_cy_bal_fee=$student_cy_bal_fee + $cy_fee_data['amount'];
                                //             }
                                //         }
                                //     }
                                // }
                                
                                // if($jun_exist ==1 && $jun_fee_status == 0){
                                       
                                //     if($get_cy_fee_data){
                                //         foreach($get_cy_fee_data as $cy_fee_data){
                                //             if($cy_fee_data['april'] == 1){
                                //                 $student_cy_bal_fee=$student_cy_bal_fee + $cy_fee_data['amount'];
                                //             }
                                //         }
                                //     }
                                // }
                                
                                // if($jul_exist ==1 && $jul_fee_status == 0){
                                       
                                //     if($get_cy_fee_data){
                                //         foreach($get_cy_fee_data as $cy_fee_data){
                                //             if($cy_fee_data['july'] == 1){
                                //                 $student_cy_bal_fee=$student_cy_bal_fee + $cy_fee_data['amount'];
                                //             }
                                //         }
                                //     }
                                // }
                                
                                // if($aug_exist ==1 && $aug_fee_status == 0){
                                       
                                //     if($get_cy_fee_data){
                                //         foreach($get_cy_fee_data as $cy_fee_data){
                                //             if($cy_fee_data['august'] == 1){
                                //                 $student_cy_bal_fee=$student_cy_bal_fee + $cy_fee_data['amount'];
                                //             }
                                //         }
                                //     }
                                // }
                                
                                // if($sep_exist ==1 && $sep_fee_status == 0){
                                       
                                //     if($get_cy_fee_data){
                                //         foreach($get_cy_fee_data as $cy_fee_data){
                                //             if($cy_fee_data['september'] == 1){
                                //                 $student_cy_bal_fee=$student_cy_bal_fee + $cy_fee_data['amount'];
                                //             }
                                //         }
                                //     }
                                // }
                                
                                // if($oct_exist ==1 && $oct_fee_status == 0){
                                       
                                //     if($get_cy_fee_data){
                                //         foreach($get_cy_fee_data as $cy_fee_data){
                                //             if($cy_fee_data['october'] == 1){
                                //                 $student_cy_bal_fee=$student_cy_bal_fee + $cy_fee_data['amount'];
                                //             }
                                //         }
                                //     }
                                // }
                                
                                // if($nov_exist ==1 && $nov_fee_status == 0){
                                       
                                //     if($get_cy_fee_data){
                                //         foreach($get_cy_fee_data as $cy_fee_data){
                                //             if($cy_fee_data['november'] == 1){
                                //                 $student_cy_bal_fee=$student_cy_bal_fee + $cy_fee_data['amount'];
                                //             }
                                //         }
                                //     }
                                // }
                                
                                // if($dec_exist ==1 && $dec_fee_status == 0){
                                       
                                //     if($get_cy_fee_data){
                                //         foreach($get_cy_fee_data as $cy_fee_data){
                                //             if($cy_fee_data['december'] == 1){
                                //                 $student_cy_bal_fee=$student_cy_bal_fee + $cy_fee_data['amount'];
                                //             }
                                //         }
                                //     }
                                // }
                                
                                // if($jan_exist ==1 && $jan_fee_status == 0){
                                       
                                //     if($get_cy_fee_data){
                                //         foreach($get_cy_fee_data as $cy_fee_data){
                                //             if($cy_fee_data['january'] == 1){
                                //                 $student_cy_bal_fee=$student_cy_bal_fee + $cy_fee_data['amount'];
                                //             }
                                //         }
                                //     }
                                // }
                                
                                // if($feb_exist ==1 && $feb_fee_status == 0){
                                       
                                //     if($get_cy_fee_data){
                                //         foreach($get_cy_fee_data as $cy_fee_data){
                                //             if($cy_fee_data['february'] == 1){
                                //                 $student_cy_bal_fee=$student_cy_bal_fee + $cy_fee_data['amount'];
                                //             }
                                //         }
                                //     }
                                // }
                                
                                // if($mar_exist ==1 && $mar_fee_status == 0){
                                       
                                //     if($get_cy_fee_data){
                                //         foreach($get_cy_fee_data as $cy_fee_data){
                                //             if($cy_fee_data['march'] == 1){
                                //                 $student_cy_bal_fee=$student_cy_bal_fee + $cy_fee_data['amount'];
                                //             }
                                //         }
                                //     }
                                // }
                                 $student_cy_bal_fee_total = $student_cy_bal_fee - $extra_amount;
                                
                                
                                if($student_display_status == 1 || $opening_bal_amount >0 || $bal_amount>0){
                                    $student_table='student';
                                    $get_student_info=$this->NewFeeModel->get_item_data($sid,$student_table);
                                    if($get_student_info){
                                        foreach($get_student_info as $student_info){
                                             
                                            
                                            
                                            // NEW OPENING BALANCE START
                                        $prev_ac_session=prev_acedemic_session;   
                                        $apr_status=0;
                                        $may_status=0;
                                        $jun_status=0;
                                        $jul_status=0;
                                        $aug_status=0;
                                        $sep_status=0;
                                        $oct_status=0;
                                        $nov_status=0;
                                        $dec_status=0;
                                        $jan_status=0;
                                        $feb_status=0;
                                        $mar_status=0;
                                        $bal_amount=0;
            
                                        $get_balance_fee_invoices=$this->NewFeeModel->get_balance_fee_invoices($sid,$prev_ac_session);
                                        if($get_balance_fee_invoices){
                                            foreach($get_balance_fee_invoices as $balance_fee_invoices){
                                            $bal_amount=$bal_amount + $balance_fee_invoices['balance_amount'];
                                            }
                                        }
                                    $extra_fee=0;
                                    $get_extra_fee_invoices=$this->NewFeeModel->get_extra_fee_invoices($sid,$prev_ac_session);
                                    if($get_extra_fee_invoices){
                                        foreach($get_extra_fee_invoices as $extra_fee_invoices){
                                            $extra_fee=$extra_fee + $extra_fee_invoices['extra_amount'];
                                        }
                                    }
            
            $get_student_fee_data=$this->NewFeeModel->get_fee_data_for($sid,$prev_ac_session);
            if($get_student_fee_data){
                foreach($get_student_fee_data as $fee_data){
                    $apr_status=$apr_status + $fee_data['april'];
                    $may_status=$may_status + $fee_data['may'];
                    $jun_status=$jun_status + $fee_data['june'];
                    $jul_status=$jul_status + $fee_data['july'];
                    $aug_status=$aug_status + $fee_data['august'];
                    $sep_status=$sep_status + $fee_data['september'];
                    $oct_status=$oct_status + $fee_data['october'];
                    $nov_status=$nov_status + $fee_data['november'];
                    $dec_status=$dec_status + $fee_data['december'];
                    $jan_status=$jan_status + $fee_data['january'];
                    $feb_status=$feb_status + $fee_data['february'];
                    $mar_status=$mar_status + $fee_data['march'];
                }
            }
            
                
                $get_previous_course_data=$this->NewFeeModel->get_studdents_current_course_data($sid,$prev_ac_session);
                $prev_course_id='';
                if($get_previous_course_data){
                    foreach($get_previous_course_data as $previous_course_data){
                        $prev_course_id=$previous_course_data['course_id'];
                   
                $get_fee_structure=$this->NewFeeModel->fee_structure($prev_course_id,$prev_ac_session);
                if($get_fee_structure){
                    foreach($get_fee_structure as $fee_structure){
                        if($apr_status == 0 && $fee_structure['april'] == 1){
                           $bal_amount = $bal_amount + $fee_structure['amount']; 
                        } 
                        if($may_status == 0 && $fee_structure['may'] == 1){
                           $bal_amount = $bal_amount + $fee_structure['amount']; 
                        } 
                        if($jun_status == 0 && $fee_structure['june'] == 1){
                            $bal_amount = $bal_amount + $fee_structure['amount']; 
                        } 
                        if($jul_status == 0 && $fee_structure['july'] == 1){
                            $bal_amount = $bal_amount + $fee_structure['amount']; 
                        } 
                        if($aug_status == 0 && $fee_structure['august'] == 1){
                            $bal_amount = $bal_amount + $fee_structure['amount']; 
                        }  
                        if($sep_status == 0 && $fee_structure['september'] == 1){
                            $bal_amount = $bal_amount + $fee_structure['amount']; 
                        } 
                        if($oct_status == 0 && $fee_structure['october'] == 1){
                            $bal_amount = $bal_amount + $fee_structure['amount']; 
                        } 
                        if($nov_status  == 0 && $fee_structure['november'] == 1){
                            $bal_amount = $bal_amount + $fee_structure['amount']; 
                        } 
                        if($dec_status ==0 && $fee_structure['december'] == 1){
                            $bal_amount = $bal_amount + $fee_structure['amount']; 
                        } 
                        if($jan_status == 0 && $fee_structure['january'] == 1){
                            $bal_amount = $bal_amount + $fee_structure['amount']; 
                        } 
                        if($feb_status == 0 && $fee_structure['february'] == 1){
                            $bal_amount = $bal_amount + $fee_structure['amount']; 
                        }
                        if($mar_status == 0 && $fee_structure['march'] == 1){
                            $bal_amount = $bal_amount + $fee_structure['amount']; 
                        }
                    }
                }
                
                    }
                }
                                
                                // NEW OPENING BALANCE END
                    // $grand_total=$grand_total + $student_cy_bal_fee_total + $bal_amount + $opening_bal_amount;    
                                            if($acedemic_session <=2 ){
                                                $grand_total=$grand_total + $student_cy_bal_fee_total + $opening_bal_amount;
                                            }else{
                                                $grand_total=$grand_total + $student_cy_bal_fee_total + $bal_amount + $opening_bal_amount;
                                            }
                                            
                                            
                                $rte_status=0;            
                                $check_rte_status=$this->NewFeeModel->check_student_rte_status($sid,$acedemic_session);
                                if($check_rte_status){
                                    $rte_status=$rte_status + 1;
                                }
                                            
                                if($rte_status == 0){
                                    
                                    $count=$count + 1;   
                                ?>
                                    <tr>
                                        <td><?php echo $count;?></td>
                                        <td><?php echo $student_info['student_name'];?></td>
                                        <td><?php echo $student_info['father_name'];?></td>
                                        <td><?php echo $student_info['contact_no'];?></td>
                                        
                                        <?php 
                                        if($acedemic_session <=2 ){
                                        ?>
                                        <td class="text-danger font-weight-bold"><?php echo "("; echo $opening_bal_amount; echo " + "; echo $student_cy_bal_fee_total; echo " ) = "; echo ($opening_bal_amount + $student_cy_bal_fee_total); ?></td>
                                        <?php
                                        }else{
                                        ?>
                                        <td class="text-danger font-weight-bold"><?php echo "("; echo $opening_bal_amount; echo " + "; echo $bal_amount; echo " + "; echo $student_cy_bal_fee_total; echo " ) = "; echo ($bal_amount + $student_cy_bal_fee_total + $opening_bal_amount); ?></td>
                                        <?php
                                        }
                                        ?>
                                        
                                        
                                        <td class="">
                                            <?php
                                            if($apr_exist ==1 && $apr_fee_status == 0){
                                                echo "Apr, ";
                                            }
                                            if($may_exist ==1 && $may_fee_status == 0){
                                                echo "May, ";
                                            }
                                            if($jun_exist ==1 && $jun_fee_status == 0){
                                                echo "Jun, ";
                                            }
                                            if($jul_exist ==1 && $jul_fee_status == 0){
                                                echo "Jul, ";
                                            }
                                            if($aug_exist ==1 && $aug_fee_status == 0){
                                                echo "Aug, ";
                                            }
                                            if($sep_exist ==1 && $sep_fee_status == 0){
                                                echo "Sep, ";
                                            }
                                            if($oct_exist ==1 && $oct_fee_status == 0){
                                                echo "Oct, ";
                                            }
                                            if($nov_exist ==1 && $nov_fee_status == 0){
                                                echo "Nov, ";
                                            }
                                            if($dec_exist ==1 && $dec_fee_status == 0){
                                                echo "Dec, ";
                                            }
                                            if($jan_exist ==1 && $jan_fee_status == 0){
                                                echo "Jan, ";
                                            }
                                            if($feb_exist ==1 && $feb_fee_status == 0){
                                                echo "Feb, ";
                                            }
                                            if($mar_exist ==1 && $mar_fee_status == 0){
                                                echo "Mar";
                                            }
                                            ?>
                                            
                                        </td>
                                    </tr>
                        <?php                                                        }
                                        }
                                    }
                                }
                                
                            
                            
                        ?>

                        <?php
                            }
                        }
                        ?>
                        
                    </tbody>
                </table>
                <table class="table table-bordered">
                    <tr>
                            <th colspan="4">Total</th>
                            <th><?php echo $grand_total;?></th>
                            <th></th>
                        </tr>
                </table>
            </div>
            
        </div>
    </div>
</div>

<?php
    }
}
?>