<style>
/* The container */
.check-container {
display: block;position: relative;padding-left: 35px;margin-bottom: 12px;cursor: pointer;font-size: 22px;user-select: none;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
}

/* Hide the browser's default checkbox */
.check-container input {position: absolute;opacity: 0;cursor: pointer;height: 0;width: 0;}

/* Create a custom checkbox */
.checkmark {
position: absolute;top: 0;left: 0;height: 25px;width: 25px;background-color: #eee;}

/* On mouse-over, add a grey background color */
.check-container:hover input ~ .checkmark {background-color: #ccc;}

/* When the checkbox is checked, add a blue background */
.check-container input:checked ~ .checkmark {background-color: #2196F3;}

/* Create the checkmark/indicator (hidden when not checked) */
.checkmark:after {content: "";position: absolute;display: none;}

/* Show the checkmark when checked */
.check-container input:checked ~ .checkmark:after {display: block;}

/* Style the checkmark/indicator */
.check-container .checkmark:after {
left: 9px;top: 5px;width: 5px;height: 10px;border: solid white;border-width: 0 3px 3px 0;
-webkit-transform: rotate(45deg);
-ms-transform: rotate(45deg);transform: rotate(45deg);
}
.fee-months label{float:left;width:25%;}

body{background:#F8F9FA;}
.fee-panel{background:#fff;}
h1{font-weight:700; font-size:24px;color:#FF5030;}
h2{font-weight:600; font-size:18px;color:#FF5030;border-bottom:2px solid #FF5030;}
</style>
<?php
$course_id=$this->uri->segment('3');
$course_table='courses';
$course='';
$course_stream='';

$get_course_info=$this->NewFeeModel->get_item_data($course_id,$course_table);
if($get_course_info){
    foreach($get_course_info as $course_info){
        $course=$course_info['course'];
        $course_stream=$course_info['subject_stream'];
    }
}
$ac_session_id=$this->uri->segment('4');
?>


<div class="container-fluid fee-panel mt-3 mb-3">
    <div class="row">
        <div class="col-sm-12 pt-3 pb-3 ">
            <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_acedemic_sessions"; ?>">All Acedemic Sessions</a>
                </li>
                <li class="breadcrumb-item">Fee Structure</li>
                <li class="breadcrumb-item">Update Fee Structure</li>
            </ul>
<div class="">
<form method="post">
<?php
$session_table='academic_session_details';
$get_ac_session_data=$this->NewFeeModel->get_item_data($ac_session_id,$session_table);
if($get_ac_session_data){
foreach($get_ac_session_data as $session_data){
?>
<h1 class="text-center">Academic Session <?php echo $session_data['y1']; echo "-"; echo $session_data['y2'];?></h1>
<?php
}
}
?>

<h2 class="text-center">Class <?php echo $course; echo " "; echo $course_stream; ?> fee structure</h2>

<?php
$fee_heads_table='fee_heads';

$get_all_fee_heads=$this->NewFeeModel->get_ac_session_active_fee_heads($fee_heads_table);
if($get_all_fee_heads){
foreach($get_all_fee_heads as $fee_heads){

?>

<div class="form-group">
<label></label>
<input type="hidden"  name="fee_head_id">
</div>

<?php 
$april_s=0;
$may_s=0;
$june_s=0;
$july_s=0;
$august_s=0;
$september_s=0;
$october_s=0;
$november_s=0;
$december_s=0;
$january_s=0;
$february_s=0;
$march_s=0;

$structure_amount=0;
$get_fee_structure=$this->NewFeeModel->check_fee_structure_exist_for_course_id($course_id,$ac_session_id,$fee_heads['id']);
if($get_fee_structure){
foreach($get_fee_structure as $structure){
$structure_amount=$structure_amount + $structure['amount'];
$april_s=$structure['april'];
$may_s=$structure['may'];
$june_s=$structure['june'];
$july_s=$structure['july'];
$august_s=$structure['august'];
$september_s=$structure['september'];
$october_s=$structure['october'];
$november_s=$structure['november'];
$december_s=$structure['december'];
$january_s=$structure['january'];
$february_s=$structure['february'];
$march_s=$structure['march'];
}    
}
?>
<div class="form-group">
<label><?php echo $fee_heads['title']; ?></label>
<input type="number" class="form-control" id="fee-<?php echo $fee_heads['id']; ?>" placeholder="<?php echo $fee_heads['title']; ?> Fee Amount" value="<?php echo $structure_amount;?>">
</div>



<?php 
if($fee_heads['fee_type'] == 'monthly'){
?>

<div class="form-group fee-months" >
<label class="check-container">April
<input type="checkbox" class="fee-<?php echo $fee_heads['id']; ?>" month="april"  <?php if($april_s ==1){echo "checked";} ?>>
<span class="checkmark"></span>
</label>


<label class="check-container">May
<input type="checkbox" class="fee-<?php echo $fee_heads['id']; ?>" month="may" <?php if($may_s ==1){echo "checked";} ?>>
<span class="checkmark"></span>
</label>


<label class="check-container">June
<input type="checkbox" class="fee-<?php echo $fee_heads['id']; ?>" month="june" <?php if($june_s ==1){echo "checked";} ?>>
<span class="checkmark"></span>
</label>


<label class="check-container">July
<input type="checkbox" class="fee-<?php echo $fee_heads['id']; ?>" month="july" <?php if($july_s ==1){echo "checked";} ?>>
<span class="checkmark"></span>
</label>
    
    
<label class="check-container">August
<input type="checkbox" class="fee-<?php echo $fee_heads['id']; ?>" month="august" <?php if($august_s ==1){echo "checked";} ?>>
<span class="checkmark"></span>
</label>


<label class="check-container">September
<input type="checkbox" class="fee-<?php echo $fee_heads['id']; ?>" month="september" <?php if($september_s ==1){echo "checked";} ?>>
<span class="checkmark"></span>
</label>


<label class="check-container">October
<input type="checkbox" class="fee-<?php echo $fee_heads['id']; ?>" month="october" <?php if($october_s ==1){echo "checked";} ?>>
<span class="checkmark"></span>
</label>



<label class="check-container">November
<input type="checkbox" class="fee-<?php echo $fee_heads['id']; ?>" month="november" <?php if($november_s ==1){echo "checked";} ?>>
<span class="checkmark"></span>
</label>


<label class="check-container">December
<input type="checkbox" class="fee-<?php echo $fee_heads['id']; ?>" month="december" <?php if($december_s ==1){echo "checked";} ?>>
<span class="checkmark"></span>
</label>



<label class="check-container">January
<input type="checkbox" class="fee-<?php echo $fee_heads['id']; ?>" month="january" <?php if($january_s ==1){echo "checked";} ?>>
<span class="checkmark"></span>
</label>



<label class="check-container">February
<input type="checkbox" class="fee-<?php echo $fee_heads['id']; ?>" month="february" <?php if($february_s ==1 ){echo "checked";} ?>>
<span class="checkmark"></span>
</label>


<label class="check-container">March
<input type="checkbox" class="fee-<?php echo $fee_heads['id']; ?>" month="march" <?php if($march_s ==1 ){echo "checked";} ?>>
<span class="checkmark"></span>
</label>
</div>
<?php



}
?>


<?php
}
}
?>




<div class="form-group">
<button class="btn btn-sm btn-info" id="fee_submit" type="button">Submit</button>
</div>


</form>
</div>


</div>
</div>
</div>

<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
<script>
$(document).ready(function(){
$("#fee_submit").click(function (){
    
    var fee_amount=[];    
    var fee_month = [];
    var fee_amounts=[];    
    var fee_months = [];

<?php
$get_all_fee_heads=$this->NewFeeModel->get_ac_session_active_fee_heads($fee_heads_table);
if($get_all_fee_heads){
foreach($get_all_fee_heads as $fee_heads){
?>

var status_4 =0;
var status_5= 0;
var status_6 =0;
var status_7 =0;
var status_8 =0;
var status_9 =0;
var status_10 =0;
var status_11 =0;
var status_12 =0;
var status_1 =0;
var status_2 =0;
var status_3 =0;

var course_id =<?php echo $course_id;?>;
var fee_head_id=<?php echo $fee_heads['id'];?>;
var course='<?php echo $course;?>';
var ac_session=<?php echo $ac_session_id;?>;
var fee_value=$("#fee-<?php echo $fee_heads['id']; ?>").val();
$.each($("input[class='fee-<?php echo $fee_heads['id']; ?>']:checked"), function(){
var month_name;
fee_amounts.push($(this).val());
fee_months.push($(this).attr("month"));
month_name = $(this).attr("month");
if(month_name == 'april'){status_4 = 1;}else if(month_name == 'may'){status_5 = 1;}else if(month_name == 'june'){status_6 = 1;}else if(month_name == 'july'){status_7 = 1;}else if(month_name == 'august'){status_8 = 1;}else if(month_name == 'september'){status_9 = 1;}else if(month_name == 'october'){status_10 = 1;}else if(month_name == 'november'){status_11 = 1;}else if(month_name == 'december'){status_12 = 1;}else if(month_name == 'january'){status_1 = 1;}else if(month_name == 'february'){status_2 = 1;}else if(month_name == 'march'){status_3 = 1;}




});
$.ajax({
url: '<?php echo base_url(); ?>Fee/add_structure',
type: 'POST', 
data: {course_id:course_id,fee_value:fee_value,fee_head_id:fee_head_id,course:course,ac_session:ac_session,status_1:status_1,status_2:status_2,status_3:status_3,status_4:status_4,status_5:status_5,status_6:status_6,status_7:status_7,status_8:status_8,status_9:status_9,status_10:status_10,status_11:status_11,status_12:status_12},
success: function(data){
// location.reload(); 
// alert(data);


}
});
<?php
}
}
?>
alert("Updated Succesfully");
});
});
</script>
