<div class="panel panel-default">

    <div class="panel-heading hidden-print">
        <h6 class="panel-title"><i class="fa fa-desktop"></i> Statement Information</h6> 
        <a onclick="window.print();" style="cursor:pointer;" class="pull-right btn btn-circle btn-xs btn-default hidden-print"><i class="fa fa-print"></i> Print</a> 					
    </div>
    <div class="panel-body">

        <form action="<?php echo site_url('everbright/statementreport'); ?>" method="post" class="validate hidden-print" role="form">
            <div class="row form-group"> 

                <label class="col-xs-1 col-xs-offset-2 control-label text-right">
                    <h5>From<span class="mandatory">*</span></h5>
                </label>
                <div class="col-xs-2">
                    <input type="text" placeholder="From Date" class="form-control required datepicker" name="from_date" >
                </div>

                <label class="col-xs-1 control-label text-right">
                    <h5>To<span class="mandatory">*</span></h5>
                </label>
                <div class="col-xs-2">
                    <input type="text" placeholder="To Date" class="form-control required datepicker" name="to_date" >
                </div>

                <div class="col-xs-2">
                    <button type="submit" name="search" value="Search" class="pull-left btn btn-circle btn-xs btn-default"><i class="fa fa-search"></i> Search</button>
                </div>
            </div> 
            <hr />
        </form> 



        <?php
        if (isset($from_date) AND isset($to_date)):
            $profit = '';
            ?>

            <p class="text-center hidden-print">
                <strong style="font-size: 16px;"><?php echo $this->main_model->company_name(); ?></strong>
            </p>
            <br />            
            

            <!-- Statement -->
            <div class="row">
                <div class="col-xs-12">
                    <table class="report-page-setup table table-bordered">
                        <caption>
                            <p class="text-center" style="font-size: 13px;"><strong>STATEMENT REPORT [From: <?php echo date('F d, Y', strtotime($from_date)); ?> - To: <?php echo date('F d, Y', strtotime($to_date)); ?>]</strong></p>
                        </caption>
                        <thead>
                            <tr>
                                <th>Job No.</th>
                                <th>HBL</th>
                                <th>CNEE Name</th>
                                <th>L/C No.</th>
                                <th>VOL</th>
                                <th>POL/POD</th>
                                <th>Master B/L</th>
                                <th>ETD</th>
                                <th>ETA</th>
                                <th>Dr. Note Receive</th>
								
                                <th>Ocean Freight</th>
                                <th>NOC from Ctg/Dha</th>
                                <th>Total</th>

                                <th>Debit Note</th>
                                <th>Ex. Rate</th>
                                <th>Total Costing</th>
								
                                <th>Profit</th>
                            </tr></thead>
                        <tbody> 
                            <?php
                            $this->db->where('date >=', $from_date);
                            $this->db->where('date <=', $to_date);
                            $query = $this->db->get('statement')->result_array();
                            foreach ($query as $row):


                                $total_debit = '';
                                $total_credit = '';
                                $total_balance = '';
                                $query_freight_info = $this->db->get_where('freight', array('freight_id' => $row['job_no']))->result_array();
                                foreach ($query_freight_info as $freight_info_value):
                                    ?>                              
                                    <tr>
                                        <td><?php echo $freight_info_value['job_no']; ?></td>                                 
                                        <td><?php echo $freight_info_value['HBLNO']; ?></td>                                 
                                        <td><?php echo $this->main_model->freight_to($freight_info_value['freight_id']); ?></td> 
                                        <td><?php echo $this->main_model->freight_lcno($freight_info_value['freight_id']); ?></td> 
                                        <td><?php echo $freight_info_value['vol']; ?></td>                                 
                                        <td><?php echo $freight_info_value['pol_pod']; ?></td> 
                                        <td><?php echo $row['master_bill']; ?></td>                                 
                                        <td><?php echo $row['ETD']; ?></td> 
                                        <td><?php echo $row['ETA']; ?></td> 
                                        <td><?php echo $row['DrNoteRec']; ?></td> 
										
                                        <td align="right"><?php $ocean_freight = $row['Ocean_Freight'] * $row['ofex_rate']; echo number_format((float)$ocean_freight, 2, '.', ','); ?></td> 
                                        <td align="right"><?php echo number_format((float) $row['NOC_from'], 2, '.', ','); ?></td> 
                                        <td align="right">
                                            <strong><?php
                                                $total_credit = $ocean_freight + $row['NOC_from'];
                                                echo number_format((float) $total_credit, 2, '.', ',');
                                                ?>
                                            </strong>
                                        </td> 
										
                                        <td align="right"><?php echo $row['Debit_Note']; ?></td> 
                                        <td align="right"><?php echo $row['ex_rate']; ?></td>
                                        <td align="right">
                                            <strong><?php
                                                $total_debit = $row['Debit_Note'] * $row['ex_rate'];
                                                echo number_format((float) $total_debit, 2, '.', ',');
                                                ?>
                                            </strong>
                                        </td> 
										
                                        <td align="right">
                                            <strong><?php
                                                $total_balance = $total_credit - $total_debit;
                                                echo number_format((float) $total_balance, 2, '.', ',');
                                                $profit += $total_balance;
                                                ?>
                                            </strong>
                                        </td>
										
                                    </tr>
                                <?php endforeach; ?>    
                            <?php endforeach; ?>                            
                        </tbody>  
                        <tfoot>
                            <tr>
                                <td colspan="16" align="right"><strong>Total Profit =</strong></td>                             
                                <td align="right"><strong><?php echo number_format((float) $profit, 2, '.', ','); ?></strong></td>
                            </tr>
                        </tfoot>
                    </table> 
                </div>
            </div>
            <!-- /Statement -->   

            <br />
            <div class="hidden-print text-center">
                <strong><?php echo $this->main_model->company_address();?></strong>
            </div>
            
        <?php endif; ?>

    </div>

</div>
