
<div class="panel panel-default">

    <div class="panel-heading hidden-print">
        <h6 class="panel-title"><i class="fa fa-desktop"></i> Receive & Payment 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/receivepaymentreport'); ?>" 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)):

            $total_pvsdebit = '';
            $total_pvscredit = '';
            $total_pvsbalance = '';

            $total_debit = '';
            $total_credit = '';
            $total_balance = '';
            ?>

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

            <!-- Receive_Payment -->
            <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>RECEIVE &amp; PAYMENT 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>DATE</th>
                                <th>PARTICULARS</th>
                                <th>INFLOW</th>
                                <th>OUTFLOW</th>
                                <th>CASH IN HAND</th>
                                <th>BANK NAME/CNEE</th>
                                <th>NAME OF ACCOUNT</th>
                                <th>ACCOUNT NO.</th>
                                <th>CHEQUE NO.</th>
                                <th>REMARKS</th>
                            </tr>
                        </thead>
                        <tbody> 

                            <!-- PVS Balance -->
                            <?php
                            $this->db->where('date <', $from_date);
                            $query_pvs = $this->db->get('receive_payment')->result_array();
                            foreach ($query_pvs as $row_pvs):
                                if ($row_pvs['type'] == 'Inflow'):
                                    $total_pvscredit += $row_pvs['amount'];
                                endif;
                                if ($row_pvs['type'] == 'Outflow'):
                                    $total_pvsdebit += $row_pvs['amount'];
                                endif;
                                $total_pvsbalance = $total_pvscredit - $total_pvsdebit;
                            endforeach;
                            ?> 
                            <tr>
                                <td colspan="2" align="right"><strong>Previous Balance =</strong></td>
                                <td align="right"><strong>&#2547;<?php echo number_format((float) $total_pvscredit, 2, '.', ','); ?></strong></td>                                     
                                <td align="right"><strong>&#2547;<?php echo number_format((float) $total_pvsdebit, 2, '.', ','); ?></strong></td>                                     
                                <td align="right"><strong>&#2547;<?php echo number_format((float) $total_pvsbalance, 2, '.', ','); ?></strong></td> 
                                <td colspan="5"></td>
                            </tr> 
                            <!-- /PVS Balance -->

                            <!-- Search Balance -->
                            <?php
                            $this->db->where('date >=', $from_date);
                            $this->db->where('date <=', $to_date);
                            $query = $this->db->get('receive_payment')->result_array();
                            foreach ($query as $row):
                                ?>
                                <tr>
                                    <td><?php echo date('d.m.Y', strtotime($row['date'])); ?></td>                                 
                                    <td><?php echo $row['particular']; ?></td>
                                    <td align="right"><?php
                                        if ($row['type'] == 'Inflow'):
                                            echo number_format((float) $row['amount'], 2, '.', ',');
                                            $total_credit += $row['amount'];
                                        endif;
                                        ?></td>                                    
                                    <td align="right"><?php
                                        if ($row['type'] == 'Outflow'):
                                            echo number_format((float) $row['amount'], 2, '.', ',');
                                            $total_debit += $row['amount'];
                                        endif;
                                        ?></td>                                    
                                    <td align="right"><?php
                                        $total_balance = ($total_credit + $total_pvscredit) - ($total_debit + $total_pvsdebit);
                                        echo number_format((float) $total_balance, 2, '.', ',');
                                        ?></td> 
                                    <td><?php echo $row['bank_cnee']; ?></td>
                                    <td><?php echo $row['account_name']; ?></td>
                                    <td><?php echo $row['account_no']; ?></td>
                                    <td><?php echo $row['cheque_no']; ?></td>
                                    <td><?php echo $row['remark']; ?></td>
                                </tr>
                            <?php endforeach; ?>
                            <!-- /Search Balance -->

                        </tbody>
                        <tfoot><tr>
                                <td colspan="2" align="right"><strong>Total Balance =</strong></td>                             
                                <td align="right"><strong>&#2547;<?php echo number_format((float) $total_credit + $total_pvscredit, 2, '.', ','); ?></strong></td>
                                <td align="right"><strong>&#2547;<?php echo number_format((float) $total_debit + $total_pvsdebit, 2, '.', ','); ?></strong></td>
                                <td align="right"><strong>&#2547;<?php echo number_format((float) ($total_credit + $total_pvscredit) - ($total_debit + $total_pvsdebit), 2, '.', ','); ?></strong></td> 
                                <td colspan="5"></td>
                            </tr></tfoot>                            
                    </table> 
                </div>
            </div>
            <!-- /Receive_Payment -->

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


        <?php endif; ?>

    </div>

</div>
