
<div class="panel panel-default">

    <div class="panel-heading hidden-print">
        <h6 class="panel-title"><i class="fa fa-desktop"></i> Profit & Loss 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/plreport'); ?>" method="post" class="validate hidden-print" role="form">
            <div class="row form-group"> 

                <label class="col-xs-3 control-label text-right"><h5>Invoice No. | ATTN/Consignee <span class="mandatory">*</span></h5></label>
                <div class="col-xs-7">
                    <select data-placeholder="(:-- Invoice No. --:)" name="invoice_no" class="select-search">
                        <option value=""></option>
                        <option value="0">All</option>
                        <?php
                        $query_invno = $this->main_model->freight(); 
                        foreach($query_invno as $row_invno):
                        ?>
                        <option value="<?php echo $row_invno['invoice_no']; ?>" <?php if(isset($invoice_no) && $row_invno['invoice_no']==$invoice_no): ?> selected="selected" <?php endif; ?>>
                            <?php echo $row_invno['invoice_no']; ?> | <?php echo $row_invno['ATTN']; ?>
                        </option>													
                        <?php endforeach; ?>
                    </select> 
                </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($invoice_no) && $invoice_no!=0): ?>

            <p class="text-center hidden-print">
                <strong style="font-size: 16px;"><?php echo $this->main_model->company_name(); ?></strong>
            </p>
            <br />            
            
            <!-- Profit & Loss -->
            <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>Profit & Loss </strong></p>
                        </caption>
                        <thead><tr>
                            <td align="center"><strong>Date</strong></td>
                            <td align="center"><strong>Delivery Date</strong></td>
                            <td align="center"><strong>Period</strong></td>
                            <td align="center"><strong>Freight Invoice - Amount (In BDT.)</strong></td>
                            <td align="center"><strong>Debit Note - Amount (In BDT.)</strong></td>
                            <td align="center"><strong>Profit</strong></td>
                        </tr></thead>
                        <tbody> 
                        <?php
                        $balance = ''; 
                        $this->db->where('invoice_no', $invoice_no);
                        $query = $this->db->get('freight')->result_array();
                        foreach ($query as $row): 
                        ?>                              
                            <tr>
                                <td><?php echo date('d.m.Y', strtotime($row['date'])); ?></td>                                 
                                <td><?php echo date('d.m.Y', strtotime($row['del_date'])); ?></td>
                                <td><?php // echo date('d.m.Y', strtotime($row['del_date'])); ?></td>
                                <td><?php 
                                $freight = $this->main_model->freight_amount($row['freight_id']); 
                                echo number_format((float)$freight,2,'.',','); 
                                ?></td>
                                <td><?php 
                                $debit = $this->main_model->debit_amount($row['invoice_no']); 
                                echo number_format((float)$debit,2,'.',',');                                         
                                ?></td>
                                <td><?php 
                                $profit = $freight - $debit; 
                                echo number_format((float)$profit,2,'.',',');                                         
                                $balance += $profit; 
                                ?></td>                                
                            </tr>
                        <?php endforeach; ?>                          
                        </tbody>  
                        <tfoot>
                            <tr>
                                <td colspan="5" align="right"><strong>Total Profit =</strong></td>                             
                                <td align="right"><strong><?php echo number_format((float)$balance,2,'.',','); ?></strong></td>
                            </tr>
                        </tfoot>
                    </table> 
                </div>
            </div>
            <!-- /Profit & Loss -->   

            <br />
            <div class="hidden-print text-center">
                <strong><?php echo $this->main_model->company_address();?></strong>
            </div> 
            
<?php elseif(isset($invoice_no) && $invoice_no==0): ?>

            <p class="text-center hidden-print">
                <strong style="font-size: 16px;"><?php echo $this->main_model->company_name(); ?></strong>
            </p>
            <br />            
            
            <!-- Profit & Loss -->
            <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>Profit & Loss </strong></p>
                        </caption>
                        <thead><tr>
                            <td align="center"><strong>Date</strong></td>
                            <td align="center"><strong>Delivery Date</strong></td>
                            <td align="center"><strong>Period</strong></td>
                            <td align="center"><strong>Freight Invoice - Amount (In BDT.)</strong></td>
                            <td align="center"><strong>Debit Note - Amount (In BDT.)</strong></td>
                            <td align="center"><strong>Profit</strong></td>
                        </tr></thead>
                        <tbody> 
                        <?php
                        $balance = ''; 
                        $query = $this->db->get('freight')->result_array();
                        foreach ($query as $row): 
                        ?>                              
                            <tr>
                                <td><?php echo date('d.m.Y', strtotime($row['date'])); ?></td>                                 
                                <td><?php echo date('d.m.Y', strtotime($row['del_date'])); ?></td>
                                <td><?php // echo date('d.m.Y', strtotime($row['del_date'])); ?></td>
                                <td align="right"><?php 
                                $freight = $this->main_model->freight_amount($row['freight_id']); 
                                echo number_format((float)$freight,2,'.',','); 
                                ?></td>
                                <td align="right"><?php 
                                $debit = $this->main_model->debit_amount($row['invoice_no']); 
                                echo number_format((float)$debit,2,'.',',');                                         
                                ?></td>
                                <td align="right"><?php 
                                $profit = $freight - $debit; 
                                echo number_format((float)$profit,2,'.',',');                                         
                                $balance += $profit; 
                                ?></td>
                            </tr>
                        <?php endforeach; ?>                          
                        </tbody>  
                        <tfoot>
                            <tr>
                                <td colspan="5" align="right"><strong>Total Profit =</strong></td>                             
                                <td align="right"><strong><?php echo number_format((float)$balance,2,'.',','); ?></strong></td>
                            </tr>
                        </tfoot>
                    </table> 
                </div>
            </div>
            <!-- /Profit & Loss -->  

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

    </div>

</div>
