<style>
    h1{font-size:22px;text-align:center;font-weight:700;}
    .form-group-l{width:50%;float:left;padding:10px;}
    .form-group{padding:10px;}
</style>
<?php
$active_course_id='';
$sid=$this->uri->segment('3');
$doc_id=$this->uri->segment('4');
$doc_type='Fee Certificate';
$doc_table ='student_fee_certificate';
$sch_no ='';
$student_name ='';
$gender ='';
$father_name ='';
$section ='';
$roll_no ='';
$issuing_date ='';
$doc_fee ='';
$tution_fee ='';
$term_charge ='';
$discount ='';
$total_fee ='';
$doc_copy_order ='';

$ac_year_start='';
$ac_year_end='';

$mother_name="";


$form_submit_title='';
$acedemic_session=$this->session->userdata('acedemic_session');
$student_table='student';
$get_student_info=$this->CertificateModel->get_item_data($sid,$student_table);
$get_doc_data=$this->CertificateModel->get_item_data($doc_id,$doc_table);
if($get_doc_data){
    $form_submit_title='Update Certificate';
    foreach($get_doc_data as $doc_data){
        $sch_no=$doc_data['sch_no'];
        $student_name=$doc_data['student_name'];
        $gender=$doc_data['gender'];
        $father_name=$doc_data['father_name'];
        $section=$doc_data['section'];
        $roll_no=$doc_data['roll_no'];
        $issuing_date=$doc_data['issuing_date'];
        $doc_fee=$doc_data['doc_fee'];
        $tution_fee = $doc_data['tution_fee'];
        $term_charge=$doc_data['term_charges'];
        $discount = $doc_data['discount'];
        $total_fee = $doc_data['total_fee'];
        $doc_copy_order = $doc_data['doc_copy_order'];
        $ac_year_start = $doc_data['ac_year_start'];
        $ac_year_end = $doc_data['ac_year_end'];
        $mother_name=$doc_data['mother_name'];
        if($mother_name == ""){
            if($get_student_info){
                foreach($get_student_info as $student_info){
                    $mother_name=$student_info['mother_name'];
                }
            }
        }
        
    }
}else{
    $form_submit_title='Issue Certificate';
    $ac_year_start= $this->session->userdata('y1');
    $ac_year_end= $this->session->userdata('y2');
    if($get_student_info){
        foreach($get_student_info as $student_info){
            $sch_no=$student_info['sch_no'];
            $student_name=$student_info['student_name'];
            $gender=$student_info['gender'];
            $father_name=$student_info['father_name'];
            $mother_name=$student_info['mother_name'];
            
            $section=$student_info['section'];
            $roll_no=$student_info['roll_no'];
            $get_active_course_info=$this->CertificateModel->student_course_data($sid,$acedemic_session);
            if($get_active_course_info){
                foreach($get_active_course_info as $course_info){
                    $active_course_id=$course_info['course_id'];
                }
            }
        
        }
    }
}
    
$get_docs=$this->CertificateModel->get_doc($sid,$doc_type,$doc_table);
$doc_count=1;
if($doc_copy_order !=''){
    $doc_count=$doc_copy_order;
}else{
    if($get_docs){
        foreach($get_docs as $docs){
            $doc_count=$doc_count + 1;
        }
    }
}
?>
<div class="container mt-3 mb-3 pt-3 pb-3 bg-white">
    <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();?>Certificate/dashboard">Certificate</a></li>
                <li class="breadcrumb-item"><a href="#">Student Fee Certificate</a></li>
                <li class="breadcrumb-item"><a href="#">Issue Student Fee Certificate</a></li>
            </ul>
            
            <div class="table-responsive">
                <table class="table table-bordered table-striped">
                    <thead>
                        <tr>
                            <th>Sr. No</th>
                            <th>Student Name</th>
                            <th>Course</th>
                            <th>Date</th>
                            <th>Issued By</th>
                            <th>Copy</th>
                            <th>View</th>
                            <th>Action</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php 
                        $all_docs=$this->CertificateModel->get_doc($sid,$doc_type,$doc_table);
                        if($all_docs){
                            foreach($all_docs as $docs){
                                $tid=$docs['cat_by'];
                                $staff_table='school_staff';
                                $staff_name='';
                                $staff_info=$this->CertificateModel->get_item_data($tid,$staff_table);
                                if($staff_info){
                                    foreach($staff_info as $staffinfo){
                                        $staff_name=$staffinfo['name'];
                                    }
                                }
                        ?>
                        <tr>
                            <td><?php echo $docs['id'];?></td>
                            <td><?php echo $docs['student_name'];?></td>
                            <td><?php echo $docs['class'];?></td>
                            <td><?php echo date('d-M-Y',strtotime($docs['issuing_date']));?></td>
                            <td><?php echo $staff_name;?></td>
                            <td><?php echo $docs['doc_copy_order'];?></td>
                            <td><a href="<?php echo base_url();?>Certificate/student_fee_certificate/<?php echo $docs['id'];?>" class="btn btn-sm btn-info" target="_blank">View</a></td>
                            <td><a href="<?php echo base_url(); ?>Certificate/issue_fee_certificate/<?php echo $sid."/".$doc_id; ?>" class="btn btn-sm btn-warning bg-white">Edit</a></td>
                        </tr>
                        <?php
                            }
                        }
                        ?>
                        
                    </tbody>
                </table>
            </div>
            
            <form method="post" action="#">
                
                <h1 class="main-heading mt-3">Issue Student Fee Certificate</h1>
                <?php 
                if($success){
                ?>
                <div class="alert alert-success"><?php echo $success;?></div>    
                <?php
                }
                if($error){
                ?>
                <div class="alert alert-danger"><?php echo $error;?></div>
                <?php
                }
                
                ?>
                <hr>
                <input type="hidden" name="doc_id" value="<?php echo $doc_id; ?>">
                <input type="hidden" name="sid" value="<?php echo $sid; ?>">
                <div class="form-group form-group-l">
                    <label>Refrence Number</label>
                    <input type="text" name="refrence_number" class="form-control" placeholder="Refrence Number">
                </div>
                <div class="form-group form-group-l">
                    <label>Scholor Number</label>
                    <input type="number" name="sch_no" value="<?php echo $sch_no ?>" class="form-control">
                </div>
                
                <div class="form-group form-group-l">
                    <label>Student Name</label>
                    <input type="text" name="student_name" class="form-control" value="<?php echo $student_name;?>" readonly>
                </div>
                <div class="form-group form-group-l">
                    <label>Gender</label>
                    <select class="form-control" name="gender" required>
                        <option value="">-- select gender --</option>
                        <option value="male" <?php if($gender =="male"){echo "selected";}?>>Male</option>
                        <option value="female" <?php if($gender =="female"){echo "selected";}?>>Female</option>
                    </select>
                </div>
                <div class="form-group form-group-l">
                    <label>Salutation</label>
                    <select class="form-control" name="salutation">
                        <option value="Mr.">Mr.</option>
                    </select>
                    
                </div>
                <div class="form-group form-group-l">
                    <label>Father's Name</label>
                    <input type="text" name="father_name" class="form-control" value="<?php echo $father_name; ?>" readonly>
                </div>
                
                
                <div class="form-group form-group-l">
                    <label>Mother Name Salutation</label>
                    <select class="form-control" name="mother_name_salutation">
                        <option value="Mrs.">Mrs.</option>
                    </select>
                    
                </div>
                <div class="form-group form-group-l">
                    <label>Mother's Name</label>
                    <input type="text" name="mother_name" class="form-control" value="<?php echo $mother_name; ?>" readonly>
                </div>
                
                <div class="form-group form-group-l">
                    <label>Course</label>
                    <select class="form-control" name="course" required>
                        <?php
                        $courses_table='courses';
                        $all_courses=$this->CertificateModel->get_data($courses_table);
                        if($all_courses){
                            foreach($all_courses as $courses){
                        ?>
                        <option value="<?php echo $courses['id']; ?>" <?php if($active_course_id == $courses['id']){echo "selected";}?>><?php echo $courses['course']; echo " "; echo $courses['subject_stream'];?></option> 
                        <?php
                            }
                        }
                        ?>
                    </select>
                </div>
                <div class="form-group form-group-l">
                    <label>Section</label>
                    
                    <select class="form-control" name="section">
                        <option value="A" <?php if($section =="A"){ echo "selected"; } ?>>A</option>
                        <option value="B" <?php if($section =="B"){ echo "selected"; } ?>>B</option>
                        <option value="C" <?php if($section =="C"){ echo "selected"; } ?>>C</option>
                        <option value="D" <?php if($section =="D"){ echo "selected"; } ?>>D</option>
                        <option value="E" <?php if($section =="E"){ echo "selected"; } ?>>E</option>
                        <option value="F" <?php if($section =="F"){ echo "selected"; } ?>>F</option>
                        <option value="G" <?php if($section =="G"){ echo "selected"; } ?>>G</option>
                        <option value="H" <?php if($section =="H"){ echo "selected"; } ?>>H</option>
                    </select>
                </div>
                <div class="form-group form-group-l">
                    <label>Roll Number</label>
                    <input type="text" name="roll_no" class="form-control" placeholder="Roll Number" value="<?php echo $roll_no; ?>">
                </div>
                
                
                <div class="form-group form-group-l">
                    <label>Acedemic Session</label>
                    <select class="form-control" name="acedemic_session" required>
                        <?php
                        $acedemic_session_table='academic_session_details';
                        $all_ac_sessions=$this->CertificateModel->get_data($acedemic_session_table);
                        if($all_ac_sessions){
                            foreach($all_ac_sessions as $ac_sessions){
                        ?>
                        <option value="<?php echo $ac_sessions['id'];?>" <?php if($ac_sessions['id'] == $acedemic_session){echo "selected";}?>><?php echo $ac_sessions['year_long'];?></option>
                        <?php
                            }
                        }
                        ?>
                        
                        
                    </select>
                </div>
                
                
                
                <div class="form-group form-group-l">
                    <label>Acedemic Year Start</label>
                    <input type="text" name="ac_year_start" class="form-control" placeholder="Acedemic Year Start" value="<?php echo $ac_year_start; ?>">
                </div>
                
                <div class="form-group form-group-l">
                    <label>Acedemic Year End</label>
                    <input type="text" name="ac_year_end" class="form-control" placeholder="Acedemic Year End" value="<?php echo $ac_year_end; ?>">
                </div>
                <div class="form-group form-group-l">
                    <label>Document Type</label>
                    <select class="form-control" name="doc_type">
                        <option value="Fee Certificate">Fee Certificate</option>
                    </select>
                </div>
                <div class="form-group form-group-l">
                    <label>Document Copy</label>
                    <select class="form-control" name="doc_copy_order">
                        <option value="<?php echo $doc_count;?>"><?php echo $doc_count;?> Copy</option>
                    </select>
                </div>
                <div class="form-group form-group-l">
                    <label>Issuing Date</label>
                    <input type="date" class="form-control" name="issuing_date" value="<?php if($issuing_date){ echo $issuing_date; }else{ echo date('Y-m-d'); } ?>" required>
                </div>     
                
                <div class="form-group form-group-l">
                    <label>School Code</label>
                    <input type="text" value="<?php echo school_code; ?>" class="form-control" name="school_code" readonly>
                </div>
                
                <div class="form-group form-group-l">
                    <label>Pattern</label>
                    <input type="text" value="<?php echo pattern; ?>" class="form-control" name="pattern" readonly>
                </div>
                <div class="form-group form-group-l">
                    <label>Doc. Fee</label>
                    <input type="number" class="form-control" name="doc_fee" placeholder="Doc. Fee" value="<?php echo $doc_fee; ?>" required>
                </div>
                <div class="form-group form-group-l">
                    <label>Tution Fee</label>
                    <input type="number" class="form-control" name="tution_fee" placeholder="Tution Fee" value="<?php echo $tution_fee; ?>">
                </div>
                <div class="form-group form-group-l">
                    <label>Term Charge</label>
                    <input type="number" class="form-control" name="term_charge" placeholder="Term Charge" value="<?php echo $term_charge; ?>">
                </div>
                <div class="form-group form-group-l">
                    <label>Discount</label>
                    <input type="number" class="form-control" name="discount" placeholder="Discount" value="<?php echo $discount; ?>">
                </div>
                <div class="form-group form-group-l">
                    <label>Total Fee</label>
                    <input type="number" class="form-control" name="total_fee" placeholder="Total Fee" value="<?php echo $total_fee; ?>" >
                </div>
                <div class="form-group ">
                    <button type="submit" class="btn btn-sm btn-info" name="issue_fee_certificate"><?php echo $form_submit_title; ?></button>
                </div>      
            </form>
            
        </div>
    </div>
</div>