<header>
    <div class="row">
        <div class="col-12">
            <div class="t-corp pull-left">
                <div class="t-corp-logo">
                    <img src="<?php echo base_url().'assets/images/logo/salihin-logo.png'; ?>" alt="company logo" />
                </div>
                <div class="t-corp-name"><b>SPS</b> | SERVICE FORM</div>
            </div>
            <div class="report-title pull-right" style="padding-top: 30px;">
                <h5 class="text-uppercase"><?php echo (isset($title) ? $title : 'Report'); ?></h5>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-12">
            <table class="company">
                <tr>
                    <td class="divider">
                        <span class="line">&nbsp;</span>
                    </td>
                    <td class="details">
                        <span><b>SALIHIN (AF 1426)</b></span>
                        <span>555, Jalan Samudra Utara 1, Taman Samudra, Batu Caves,</span>
                        <span>68100, Batu Caves, Selangor</span>
                        <span>Phone: 03-6185 9970 &nbsp;&nbsp; Fax: 03-6185 9970</span>
                        <span>Website: salihin.com.my</span>
                    </td>
                    <?php if(!empty($ID)) { ?>
                        <td class="divider">
                            <span class="line">&nbsp;</span>
                        </td>
                    <?php } else { ?>
                        <td class="divider">
                            <span class="line">&nbsp;</span>
                            <table>
                                <tr>
                                    <td><span><b>BOOKING FORM</b></span></td>
                                    <td><span><b style="padding-left: 2rem;">:</b></span></td>
                                    <?php if(!empty($this->session->userdata($sv_filter.'_filter_title')) && ($this->session->userdata($sv_filter.'_filter_title') != 'ALL')) { ?>
                                        <td><span><b class="text-uppercase" style="padding-left: 1rem;"><?php echo explode('-',$booking_form[0]['title'])[0]; ?></b></span></td>
                                    <?php }else{ ?>
                                        <td><span><b class="text-uppercase" style="padding-left: 1rem;">ALL</b></span></td>
                                    <?php } ?>
                                </tr>
                                <tr>
                                    <td><span><b>YEAR</b></span></td>
                                    <td><span><b style="padding-left: 2rem;">:</b></span></td>
                                    <td><span><b style="padding-left: 1rem;"><?php echo (!empty($this->session->userdata($sv_filter.'_filter_year')))?($this->session->userdata($sv_filter.'_filter_year')):date('Y'); ?></b></span></td>
                                </tr>
                                <tr>
                                    <td><span><b>MONTH</b></span></td>
                                    <td><span><b style="padding-left: 2rem;">:</b></span></td>
                                    <td><span><b class="text-uppercase" style="padding-left: 1rem;"><?php echo (!empty($this->session->userdata('sv_summary_filter_month')))?date('M',strtotime('01-'.($this->session->userdata($sv_filter.'_filter_month')).'-'.($this->session->userdata($sv_filter.'_filter_year')))):'ALL'; ?></b></span></td>
                                </tr>
                                <tr>
                                    <td><span><b>DEPARTMENT</b></span></td>
                                    <td><span><b style="padding-left: 2rem;">:</b></span></td>
                                    <?php if(!empty($this->session->userdata($sv_filter.'_filter_department')) && ($this->session->userdata($sv_filter.'_filter_department') != '') && ($this->session->userdata($sv_filter.'_filter_department') > 0)) { ?>
                                        <td><span><b class="text-uppercase" style="padding-left: 1rem;">
                                            <?php echo $department['name'].' / '.$department['branch_name']; debug($mode); ?>
                                        </b></span></td>
                                    <?php }else{ ?>
                                        <td><span><b class="text-uppercase" style="padding-left: 1rem;">ALL</b></span></td>
                                    <?php } ?>
                                </tr>
                            </table>
                        </td>
                    <?php } ?>
                </tr>
            </table>
        </div>
    </div>
</header>

<div class="col-12 table-responsive " style="margin-top:2rem">
    <table class="table table-bordered p-0 m-0" width="100%">
        <thead>
            <th class="text-center" style="width: 5px;">#</th>
            <th class="text-center" style="width: 30px;">Service Form</th>
            <th class="text-center" style="width: 30px;">Department</th>
            <th class="text-center" style="width: 10px;">Price Per Pax</th>
            <th class="text-center" style="width: 15px;"><?php echo ($_SESSION['user']['division_id'] == 4)?"Total Request":"Pax"; ?></th>
            <th class="text-center" style="width: 10px;">Total</th>
        </thead>

        <tbody>
            <?php $total_pax = 0; $total_charge = 0;
            if($booking_form) foreach($booking_form as $key => $row){
                $charge_per_pax = $row['price'];
            ?>
                <tr>
                    <td class="text-center"><?php echo $key+1; ?></td>
                    <td><?php echo $row['title']; ?></td>
                    <td><?php echo $row['department_name']; ?></td>
                    <td class="text-center"><?php echo 'RM'.number_format($row['price'],2); ?></td>
                    <td class="text-center">
                        <?php 
                            if(isset($_SESSION[$sv_filter.'_filter_title']) && $_SESSION[$sv_filter.'_filter_title'] == 20)
                            {
                                if($row['type'])
                                {
                                    $type_explode = explode('-', $row['type']);
                                    $total_pax += end($type_explode); 
                                    echo end($type_explode);
                                }                                                            
                            }else{
                                $total_pax += $row['total']; 
                                echo $row['total'];
                            }
                        ?>
                    </td>
                    <td class="text-center">
                        <?php
                            if(isset($_SESSION[$sv_filter.'_filter_title']) && $_SESSION[$sv_filter.'_filter_title'] == 20)
                            {
                                if($row['type'])
                                {
                                    $type_explode = explode('-', $row['type']);
                                    $total_pax += end($type_explode); 
                                    $total_charge += ($row['price'] * end($type_explode));
                                    echo 'RM'.number_format($row['price'] * end($type_explode),2);
                                }                                                            
                            }else{
                                $total_charge += ($charge_per_pax * $row['total']);
                                echo 'RM'.number_format(($charge_per_pax * $row['total']),2);
                            }
                        ?>
                    </td>
                    <!-- <td class="text-center">
                        <?php 
                            //$total_pax += $row['total']; 
                            //echo $row['total'];
                        ?>
                    </td>
                    <td class="text-center">
                        <?php
                            //$total_charge += ($charge_per_pax * $row['total']);
                            //echo 'RM'.number_format(($charge_per_pax * $row['total']),2);
                        ?>
                    </td> -->
                </tr>
            <?php } ?>
            <tr>
                <td class="text-center" colspan="4"><strong>TOTAL</strong></td>
                <td class="text-center"><strong><?php echo $total_pax; ?></strong></td>
                <td class="text-center"><strong><?php echo 'RM'.number_format($total_charge,2); ?></strong></td>
            </tr>
        </tbody>
    </table>
</div>