<?php
$fee_head_table='fee_heads';
$acedemic_session_table='academic_session_details';
$course='';
$subject_stream='';
$fee_no=$this->uri->segment('3');
$table='transport_fee_deleted';
$get_item_data=$this->TransportModel->get_invoice_data($fee_no,$table);
if($get_item_data){
    foreach($get_item_data as $item_data){
        $sid=$item_data['sid'];
        $student_table='student';
        $acedemic_session=$item_data['acedemic_session'];
        $course_id='';
        $get_student_courses_data=$this->TransportModel->get_student_course_info($sid,$acedemic_session);
        if($get_student_courses_data){
            foreach($get_student_courses_data as $student_courses_data){
                $course_id=$student_courses_data['course_id'];
            }
        }
            $course_table='courses';
            $get_course_info=$this->TransportModel->get_item_data($course_id,$course_table);
            if($get_course_info){
                foreach($get_course_info as $course_info){
                    $course=$course_info['course'];
                    $subject_stream=$course_info['subject_stream'];                    
                }
            }
            
        $received_by="";    
        $emp_id=$item_data['cat_by'];
        $staff_table="school_staff";
        $get_staff_info=$this->TransportModel->get_item_data($emp_id,$staff_table);
        if($get_staff_info){
            foreach($get_staff_info as $emp_data){
                $received_by=$emp_data['salutation']." ".$emp_data['name'];
            }
        }
        $get_student_info=$this->TransportModel->get_item_data($sid,$student_table);
        if($get_student_info){
            foreach($get_student_info as $student_info){
                                

                $year_long='';
                $get_ac_sess_data=$this->TransportModel->get_item_data($item_data['acedemic_session'],$acedemic_session_table);
                if($get_ac_sess_data){
                    foreach($get_ac_sess_data as $ac_sess_data){
                        $year_long = $ac_sess_data['year_long'];
                    }
                }
?>

<!DOCTYPE html>
    <html>
        <head>
            <title>Fee Invoice</title>
            <style>
                .w-100{width:100%;}
                .w-50-1{width:50%;float:left;height:100%;}
                .w-50-2{width:50%;float:left;height:100%;}
                .w-2{width:0%;float:left;}
                img{height:80px;width:auto;}
                html{padding:0px;margin:0px;}
                body{
                    padding:15px;margin:0px;font-size:13px;
                    
                    
                    
                }
                table{
                    /*border-collapse:collapse;*/
                }
                
                .w-50-1{
                    background-image: url("<?php echo base_url(); ?>assets/deleted-watermark.png");
                    opacity: 0.3;
                    background-repeat: no-repeat;
                    background-size: 70% auto;
                    background-position: center;
                    z-index: -1;
                }
            </style>
        </head>
        <body>
            <div class="w-100">
                <div class="w-50-1" style="border-right:1px dotted black;">
                    <table style="width:100%;margin:0px;padding:0px;">
                        <tr style="width:100% !important;padding:0px !important;">
                            <td style="width:30%;background:;padding:0;border-bottom:1px solid black;text-align:center !important;padding-left:20px;">
                                <img src="<?php echo school_logo_full;?>" style="margin:auto;">
                            </td>
                            <td style="width:70%;height:80px;background:;margin:0px;text-align:center;padding:0px;border-bottom:1px solid black;padding-right:20px;">
                                <p style="padding:0px;margin:0px;font-size:16px;font-weight:600;"><?php echo school_full_name; ?></p>
                                <p style="padding:0px;margin:0px;font-size:15px;font-weight:500;"><?php echo school_affiliation; ?></p>
                                <p style="padding:0px;margin:0px;font-size:13px;font-weight:500;"><?php echo school_address;?></p>
                                <p style="padding:0px;margin:0px;font-size:13px;font-weight:500;">Contact : <?php echo contact1;?>, <?php echo contact2; ?></p>
                

                                <p style="text-align:center;padding:0px;margin:0px;font-size:13px;font-weight:500;">Academic Year : <?php echo $year_long;?></p>
                            </td>
                        </tr>
                    </table>
                                    
                    <table style="width:100%;margin:0px;padding:0px;">
                        <tr style="width:100% !important;padding:0px !important;">
                            <td style="height:;background:;margin:0px;text-align:left;padding:0px;padding-left:20px;">No. : <?php echo $fee_no;?></td>
                            <td style="width:;height:;background:;margin:0px;text-align:left;padding:0px;padding-right:20px;">Date : <?php echo date('d-m-Y',strtotime($item_data['fee_date']));?></td>
                        </tr>
                        <tr>
                            <td style="margin:0px;padding:0px;padding-left:20px;" colspan="2">Name : <?php echo $student_info['student_name'];?></td>
                        </tr>
                        <tr>
                        <?php
                        if($student_info['gender'] == 'male'){
                        ?>            
                            <td style="margin:0px;padding:0px;padding-left:20px;" colspan="2">S/o : <?php echo $student_info['father_name'];?>
                            </td>
                        <?php
                        }else if($student_info['gender'] == 'female'){
                        ?>
                            <td style="margin:0px;padding:0px;padding-left:20px;" colspan="2">D/o : <?php echo $student_info['father_name']; ?></td>
                            <?php
                            }else{
                            ?>
                            <td style="margin:0px;padding:0px;padding-left:20px;" colspan="2">Father's Name : <?php echo $student_info['father_name']; ?></td>
                            <?php
                            }
                            ?>

                        </tr>
                                        <tr>
                                            <td style="width:;height:;background:;margin:0px;text-align:left;padding:0px;padding-left:20px;">Class : <?php echo $course; echo " "; echo $subject_stream;?></td>
                                            <?php
                                            $fee_months=$item_data['fee_months'];
                                            $array = explode(",",$fee_months);
                                            $first_word = $array[0];
                                            $last_word  = $array[count($array)-1];
                                            $count_months=count($array);
                                            if($count_months >1){
                                            ?>
                                            <td style="padding-right:20px;">Months : <span style="text-transform:uppercase;"><?php 
                                                echo $first_word; echo '</span> to <span style="text-transform:uppercase;">'; echo $last_word;?></span>
                                            </td>

                                            <?php
                                            }else{
                                            ?>
                                            <td>Fee Months : <span style="text-transform:uppercase;"><?php echo $fee_months;?></span></td>
                                            <?php
                                            }
                                            ?>
                                        </tr>
                                    </table>
                                    <table style="width:100%;padding:0px;margin:0px;border-top:1px solid black;">
            
                                        <tr>
                                            <th style="text-align:left;border-right:1px solid black;border-bottom:1px solid black;padding-left:20px;">Particulars</th>
                                            <th style="text-align:left;border-bottom:1px solid black;padding-right:20px;">Total Rs.</th>
                                        </tr>
                                        <?php
                                        $get_fee_heads=$this->TransportModel->get_data($fee_head_table);
                                        if($get_fee_heads){
                                            foreach($get_fee_heads as $fee_head){
                                                echo '<tr style="">';
                                                    echo '<td style="border-right:1px solid black;border-bottom:1px solid black;padding-left:20px;">'.$fee_head['title'].'</td>';
                                                    echo "<td style='border-bottom:1px solid black;'></td>";
                                                echo "</tr>";
                                            }
                                        }
                                        
                                        ?>
                                        <tr>
                                            <td style="border-right:1px solid black;border-bottom:1px solid black;padding-left:20px;">Transport Fee</td>
                                            <td style='border-bottom:1px solid black;'><?php echo $item_data['esatimate_fee'];?></td>
                                        </tr>
                                        <?php 
                                        if($item_data['prev_bal_added'] !=0){
                                            ?>
                                        <tr>
                                            <td style="border-right:1px solid black;border-bottom:1px solid black;padding-left:20px;">Prev. Bal.</td>
                                            <td style='border-bottom:1px solid black;'><?php echo $item_data['prev_bal_added'];?></td>
                                        </tr>                                            
                                            <?php
                                        }
                                        if($item_data['extra_amount_used'] !=0){
                                            ?>
                                        <tr>
                                            <td style="border-right:1px solid black;border-bottom:1px solid black;padding-left:20px;">Prev. Extra.</td>
                                            <td style='border-bottom:1px solid black;'><?php echo $item_data['extra_amount_used'];?></td>
                                        </tr>                                            
                                            <?php
                                        }
                                        if($item_data['discount'] !=0){
                                            ?>
                                        <tr>
                                            <td style="border-right:1px solid black;border-bottom:1px solid black;padding-left:20px;">Discount</td>
                                            <td style='border-bottom:1px solid black;'><?php echo $item_data['discount'];?></td>
                                        </tr>                                            
                                            <?php
                                        }
                                        
                                        $total=$item_data['esatimate_fee'] + $item_data['prev_bal_added'] - $item_data['extra_amount_used'] - $item_data['discount']
                                        ?>
                                        
                                        <tr>
                                            <td style="border-right:1px solid black;border-bottom:1px solid black;padding-left:20px;"><b>Total</b></td>
                                            <td style='border-bottom:1px solid black;'><b><?php echo $total;?></b></td>
                                        </tr>
                                        
                                        <tr>
                                            <td style="border-right:1px solid black;border-bottom:1px solid black;padding-left:20px;"><b>Received</b></td>
                                            <td style='border-bottom:1px solid black;'><b><?php echo $item_data['received_fee'];?></b></td>
                                        </tr>
                                        <?php
                                        if($item_data['balance_fee'] !=0){
                                        ?>
                                        <tr>
                                            <td style="border-right:1px solid black;padding-left:20px;">Bal. Fee</td>
                                            <td style=''><?php echo $item_data['balance_fee']; ?></td>
                                        </tr>    
                                        <?php
                                        }
                                        if($item_data['extra_fee'] !=0){
                                        ?>
                                        <tr>
                                            <td style="border-right:1px solid black;padding-left:20px;">Extra. Fee</td>
                                            <td style=''><?php echo $item_data['extra_fee']; ?></td>
                                        </tr>    
                                        <?php
                                        }
                                        ?>
                                    </table> 
                                    <table style="margin:0px;width:100%;">
                                        <tr>
                                            <td style="padding-top:30px;padding-left:20px;margin:0px;font-size:14px;" ><b>Received By :</b></td>
                                            <td style="padding-top:30px;text-align:center;"><b><?php echo $received_by; ?></b></td>
                                        </tr>
                                        
                                        <tr>
                                            <td style="padding-top:0px;padding-left:20px;margin:0px;font-size:14px;" colspan="2"><b>Note : </b>Receipt should be reserved for the academic year.</td>
                                            
                                        </tr>
                                        
                                        <tr style="">
                                            <td style="padding:5px 0px;margin:0px;font-size:8px;text-align:center;border-top:1px dotted red;" colspan="2">Printed by : <?php echo $this->session->userdata("teacher_name"); ?> <?php echo date("d-M-Y h:i:sa"); ?></td>
                                        </tr>
                                        
                                    </table>
                                </div>
                                
                                
                                <div class="w-50-1" style="">
                                    <table style="width:100%;margin:0px;padding:0px;">
                                        <tr style="width:100% !important;padding:0px !important;">
                                            <td style="width:30%;background:;padding:0px;border-bottom:1px solid black;text-align:center !important;padding-left:20px;">
                                                <img src="<?php echo school_logo_full;?>" style="margin:auto;margin-left:auto;margin-right:auto;">
                                            </td>
                                            <td style="width:70%;height:80px;background:;margin:0px;text-align:center;padding:0px;border-bottom:1px solid black;padding-right:20px;">
                                                <p style="padding:0px;margin:0px;font-size:16px;font-weight:600;"><?php echo school_full_name; ?></p>
                                                <p style="padding:0px;margin:0px;font-size:15px;font-weight:500;"><?php echo school_affiliation; ?></p>
                                                <p style="padding:0px;margin:0px;font-size:13px;font-weight:500;"><?php echo school_address;?></p>
                                                <p style="padding:0px;margin:0px;font-size:13px;font-weight:500;">Contact : <?php echo contact1;?>, <?php echo contact2; ?></p>
                

                                                <p style="text-align:center;padding:0px;margin:0px;font-size:13px;font-weight:500;">Academic Year : <?php echo $year_long;?></p>
                                            </td>
                                        </tr>
                                    </table>
                                    <table style="width:100%;margin:0px;padding-left:;padding:0px;">
                                        <tr style="width:100% !important;padding:0px !important;">
                                            <td style="height:;background:;margin:0px;text-align:left;padding:0px;padding-left:20px;">No. : <?php echo $fee_no;?></td>
                                            <td style="width:;height:;background:;margin:0px;text-align:left;padding:0px;padding-right:20px;">Date : <?php echo date('d-m-Y',strtotime($item_data['fee_date']));?></td>
                                        </tr>
                                        <tr>
                                            <td style="margin:0px;padding:0px;padding-left:20px;" colspan="2">Name : <?php echo $student_info['student_name'];?></td>
                                        </tr>
                                        <tr>
                                            <?php
                                            if($student_info['gender'] == 'male'){
                                            ?>            
                                            <td style="margin:0px;padding:0px;padding-left:20px;" colspan="2">S/o : <?php echo $student_info['father_name'];?></td>
                                            <?php
                                            }else if($student_info['gender'] == 'female'){
                                            ?>
                                            <td style="margin:0px;padding:0px;padding-left:20px;" colspan="2">D/o : <?php echo $student_info['father_name']; ?></td>
                                            <?php
                                            }else{
                                            ?>
                                            <td style="margin:0px;padding:0px;padding-left:20px;" colspan="2">Father's Name : <?php echo $student_info['father_name']; ?></td>
                                            <?php
                                                }
                                            ?>

                                        </tr>
                                        <tr>
                                            <td style="width:;height:;background:;margin:0px;text-align:left;padding:0px;padding-left:20px;">Class : <?php echo $course; echo " "; echo $subject_stream;?></td>
                                            <?php
                                            $fee_months=$item_data['fee_months'];
                                            $array = explode(",",$fee_months);
                                            $first_word = $array[0];
                                            $last_word  = $array[count($array)-1];
                                            $count_months=count($array);
                                            if($count_months >1){
                                            ?>
                                            <td style="padding-right:20px;">Months : <span style="text-transform:uppercase;"><?php 
                                                echo $first_word; echo '</span> to <span style="text-transform:uppercase;">'; echo $last_word;?></span>
                                            </td>

                                            <?php
                                            }else{
                                            ?>
                                            <td>Fee Months : <span style="text-transform:uppercase;"><?php echo $fee_months;?></span></td>
                                            <?php
                                            }
                                            ?>
                                        </tr>
                                    </table>
                                    <table style="width:100%;padding:0px;margin:0px;border-top:1px solid black;">
            
                                        <tr>
                                            <th style="text-align:left;border-right:1px solid black;border-bottom:1px solid black;padding-left:20px;">Particulars</th>
                                            <th style="text-align:left;border-bottom:1px solid black;padding-right:20px;">Total Rs.</th>
                                        </tr>
                                        <?php
                                        $get_fee_heads=$this->TransportModel->get_data($fee_head_table);
                                        if($get_fee_heads){
                                            foreach($get_fee_heads as $fee_head){
                                                echo '<tr style="">';
                                                    echo '<td style="border-right:1px solid black;border-bottom:1px solid black;padding-left:20px;">'.$fee_head['title'].'</td>';
                                                    echo "<td style='border-bottom:1px solid black;'></td>";
                                                echo "</tr>";
                                            }
                                        }
                                        
                                        ?>
                                        <tr>
                                            <td style="border-right:1px solid black;border-bottom:1px solid black;padding-left:20px;">Transport Fee</td>
                                            <td style='border-bottom:1px solid black;'><?php echo $item_data['esatimate_fee'];?></td>
                                        </tr>
                                        <?php 
                                        if($item_data['prev_bal_added'] !=0){
                                            ?>
                                        <tr>
                                            <td style="border-right:1px solid black;border-bottom:1px solid black;padding-left:20px;">Prev. Bal.</td>
                                            <td style='border-bottom:1px solid black;'><?php echo $item_data['prev_bal_added'];?></td>
                                        </tr>                                            
                                            <?php
                                        }
                                        if($item_data['extra_amount_used'] !=0){
                                            ?>
                                        <tr>
                                            <td style="border-right:1px solid black;border-bottom:1px solid black;padding-left:20px;">Prev. Extra.</td>
                                            <td style='border-bottom:1px solid black;'><?php echo $item_data['extra_amount_used'];?></td>
                                        </tr>                                            
                                            <?php
                                        }
                                        if($item_data['discount'] !=0){
                                            ?>
                                        <tr>
                                            <td style="border-right:1px solid black;border-bottom:1px solid black;padding-left:20px;">Discount</td>
                                            <td style='border-bottom:1px solid black;'><?php echo $item_data['discount'];?></td>
                                        </tr>                                            
                                            <?php
                                        }
                                        
                                        $total=$item_data['esatimate_fee'] + $item_data['prev_bal_added'] - $item_data['extra_amount_used'] - $item_data['discount']
                                        ?>
                                        
                                        <tr>
                                            <td style="border-right:1px solid black;border-bottom:1px solid black;padding-left:20px;"><b>Total</b></td>
                                            <td style='border-bottom:1px solid black;'><b><?php echo $total;?></b></td>
                                        </tr>
                                        
                                        <tr>
                                            <td style="border-right:1px solid black;border-bottom:1px solid black;padding-left:20px;"><b>Received</b></td>
                                            <td style='border-bottom:1px solid black;'><b><?php echo $item_data['received_fee'];?></b></td>
                                        </tr>
                                        <?php
                                        if($item_data['balance_fee'] !=0){
                                        ?>
                                        <tr>
                                            <td style="border-right:1px solid black;padding-left:20px;">Bal. Fee</td>
                                            <td style=''><?php echo $item_data['balance_fee']; ?></td>
                                        </tr>    
                                        <?php
                                        }
                                        if($item_data['extra_fee'] !=0){
                                        ?>
                                        <tr>
                                            <td style="border-right:1px solid black;padding-left:20px;">Extra. Fee</td>
                                            <td style=''><?php echo $item_data['extra_fee']; ?></td>
                                        </tr>    
                                        <?php
                                        }
                                        ?>
                                        
                                    </table>  
                                    <table style="margin:0px;width:100%;">
                                        <tr>
                                            <td style="padding-top:30px;padding-left:20px;margin:0px;font-size:14px;" ><b>Received By :</b></td>
                                            <td style="padding-top:30px;text-align:center;"><b><?php echo $received_by; ?></b></td>
                                        </tr>
                                        
                                        <tr>
                                            <td style="padding-top:0px;padding-left:20px;margin:0px;font-size:14px;" colspan="2"><b>Note : </b>Receipt should be reserved for the academic year.</td>
                                        </tr>
                                        
                                        <tr style="">
                                            <td style="border-top:1px dotted red;padding:5px 0px;margin:0px;font-size:8px;text-align:center;" colspan="2">Printed by : <?php echo $this->session->userdata("teacher_name"); ?> <?php echo date("d-M-Y h:i:sa"); ?></td>
                                        </tr>
                                    </table>
                                </div>
                
                
                
            </div>
        </body>
    </html>
    
<?php
            }
        }
    }
}
?>