<div class="container-fluid bg-white">
    <div class="row">
        <div class="col-sm-12 pt-3 pb-3">
            <div class="table-responsive">
                <table class="table table-bordered table-striped">
                    <thead>
                        <tr>
                            <th colspan="8" class="text-center text-success">Opening Balance 2020-2021</th>
                        </tr>
                        <tr>
                            <th>Course</th>
                            <th>Strength</th>
                            <th>Exp. Fee</th>
                            <th>Received</th>
                            <th>Discount</th>
                            <th>Due</th>
                            <th>View / PDF / Excel</th>
                            <th>Monthly Fee</th>
                            
                        </tr>
                    </thead>
                    <tbody>
                        <?php 
                        $table='courses';
                            $course_exp_grand_total=0;
                            $received_fee_grand_total=0;
                            $discount_grand_total=0;
                            $course_due_fee_grand_total=0;
                        $all_courses=$this->WelcomeModel->get_data($table);
                        if($all_courses){
                            foreach($all_courses as $courses){
                                $course_id=$courses['id'];
                                $d_count=0;
                                ?>
                        <tr>
                            <td>
                                
                            <?php 
                            echo $courses['course'];
                            if($courses['subject_stream'] !=''){
                                    echo " ("; echo             $courses['subject_stream']; echo ")";
                                }
                            ?>
                            
                            </td>
                            <?php
                            $course=$courses['course'];
                            $acedemic_session=$this->session->userdata('acedemic_session');
                            ?>
                            
                            
                            <?php
                                // echo $get_strength_for_course=$this->OpeningBalanceModel->get_course_strength($course,$acedemic_session);
                            ?>
                            
                            <?php
                            $get_student_courses_data=$this->OpeningBalanceModel->get_student_courses_data($course_id,$acedemic_session);
                            $expected_course_fee=0;
                            $received_fee=0;
                            $discount=0;
                            $s_count=0;
                            
                            if($get_student_courses_data){
                                foreach($get_student_courses_data as $courses_data){
                                    $s_count=$s_count + 1;
                                    $sid=$courses_data['sid'];
                                    $opening_fee_table='opening_balance';
                                    $get_opening_expected_balance=$this->OpeningBalanceModel->get_student_opening_fee($sid,$opening_fee_table);
                                    if($get_opening_expected_balance){
                                        foreach($get_opening_expected_balance as $expected_balance){
                                            $d_count=$d_count + 1;
                                            $expected_course_fee=$expected_course_fee + $expected_balance['opening_fee_amount'];
                                        }
                                    }
                                
                            
                            
                                $get_received_fee=$this->OpeningBalanceModel->get_received_opening_fee_for_student($sid);
                                    if($get_received_fee){
                                        foreach($get_received_fee as $fee){
                                            $received_fee=$received_fee + $fee['received_amount'];
                                            $discount=$discount + $fee['discount'];
                                        }
                                    }
                                }
                            }
                            $course_due_fee=($expected_course_fee - $received_fee - $discount);
                            
                            $course_exp_grand_total=$course_exp_grand_total + $expected_course_fee;
                            $received_fee_grand_total=$received_fee_grand_total + $received_fee;
                            $discount_grand_total=$discount_grand_total + $discount;
                            $course_due_fee_grand_total=$course_due_fee_grand_total + $course_due_fee;
                            ?>
                            <td>
                                
                                <?php echo $s_count; echo "/"; echo $d_count;?></td>
                            <td><?php echo $expected_course_fee;?></td>
                            <td class="text-success"><?php echo $received_fee;?></td>
                            <td><?php echo $discount;?></td>
                            <td class="text-danger"><?php echo $course_due_fee;?></td>
                            <td class="text-center">
                                <a href="<?php echo base_url();?>OpeningFee/course_students_opening_fee_info/<?php echo $course_id; ?>" class="btn btn-sm btn-success" >
                                    <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-eye-fill" viewBox="0 0 16 16">
                                        <path d="M10.5 8a2.5 2.5 0 1 1-5 0 2.5 2.5 0 0 1 5 0z"/>
                                        <path d="M0 8s3-5.5 8-5.5S16 8 16 8s-3 5.5-8 5.5S0 8 0 8zm8 3.5a3.5 3.5 0 1 0 0-7 3.5 3.5 0 0 0 0 7z"/>
                                    </svg>
                                </a>
                                <a href="<?php echo base_url();?>OpeningFee/course_opening_fee_pdf/<?php echo $course_id; ?>" class="btn btn-sm btn-danger">
                                    <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-file-pdf-fill" viewBox="0 0 16 16">
                                        <path d="M5.523 10.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.035 21.035 0 0 0 .5-1.05 11.96 11.96 0 0 0 .51.858c-.217.032-.436.07-.654.114zm2.525.939a3.888 3.888 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 4.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 0h8a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V2a2 2 0 0 1 2-2zm.165 11.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.64 11.64 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.707 19.707 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>
                                <a href="<?php echo base_url();?>Export/course_opening_fee/<?php echo $course_id;?>" class="btn btn-sm btn-info" >
                                    <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-file-spreadsheet-fill" viewBox="0 0 16 16">
                                        <path d="M12 0H4a2 2 0 0 0-2 2v4h12V2a2 2 0 0 0-2-2zm2 7h-4v2h4V7zm0 3h-4v2h4v-2zm0 3h-4v3h2a2 2 0 0 0 2-2v-1zm-5 3v-3H6v3h3zm-4 0v-3H2v1a2 2 0 0 0 2 2h1zm-3-4h3v-2H2v2zm0-3h3V7H2v2zm4 0V7h3v2H6zm0 1h3v2H6v-2z"/>
                                    </svg>
                                </a>
                                
                                
                                <!--<div class="dropdown">-->
                                <!--    <button class="btn btn-success dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">-->
                                <!--        View-->
                                <!--    </button>-->
                                <!--    <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">-->
                                <!--        <a href="<?php echo base_url();?>OpeningFee/course_students_opening_fee_info/<?php echo $course_id; ?>" class="dropdown-item" style="border-bottom:1px solid silver;">View</a>-->
                                <!--        <a href="<?php echo base_url();?>OpeningFee/course_opening_fee_pdf/<?php echo $course_id; ?>" class="dropdown-item" style="border-bottom:1px solid silver;">Pdf</a>-->
                                <!--        <a href="<?php echo base_url();?>Export/course_opening_fee/<?php echo $course_id;?>" class="dropdown-item" >Excel</a>-->
                                <!--    </div>-->
                                <!--</div>-->

                                </td>
                            <td class="text-center">
                                <a href="<?php echo base_url();?>FeeManagement/course_fee_data/<?php echo $course_id;?>" class="btn btn-sm btn-info">View</a>
                            </td>
                        </tr>             
                                <?php
                            }
                        }
                        ?>
                        <tr>
                            <th>Total</th>
                            <th></th>
                            <th class="text-danger"><?php echo $course_exp_grand_total;?></th>
                            <th class="text-success"><?php echo $received_fee_grand_total;?></th>
                            <th class="text-warning"><?php echo $discount_grand_total;?></th>
                            <th class="text-danger"><?php echo $course_due_fee_grand_total;?></th>
                            <th></th>
                            <th></th>
                            <?php

                            
                            ?>
                        </tr>
                    </tbody>
                </table>
            </div>
            
            
        </div>
    </div>
</div>