<div class="col-sm-8">
    <div class="row ">
        <div class="col-sm-12  text-left">
            <div class="col-sm-12 gray_ttc text-left">
                <a href="<?php echo base_url(); ?>">Dashboard</a> > My Billing
            </div>
        </div>

        <div class="col-sm-12"><br></div>
        <div class="form-group col-sm-12">
            <div class="form-group col-sm-8">
                <div class="form-group col-sm-6">
                    <div class="input-group date" id="datetimepicker1">
                        <input type="text" 
                               class="form-control text-input" 
                               name="start_date" id="start_date"
                               onblur="viewPaymentBYDate(this.value, end_date.value)"
                               aria-describedby="basic-addon1"
                               value=""
                               placeholder="Start Date" >
                        <span class="input-group-addon">
                            <span class="glyphicon glyphicon-calendar"></span>
                        </span>
                    </div>
                </div>
                <div class="form-group col-sm-6">
                    <div class="input-group date" id="datetimepicker2">
                        <input type="text" 
                               class="form-control text-input" 
                               name="end_date" id="end_date"
                               onblur="viewPaymentBYDate(start_date.value, this.value)"
                               aria-describedby="basic-addon1"
                               value=""
                               placeholder="End Date" >
                        <span class="input-group-addon">
                            <span class="glyphicon glyphicon-calendar"></span>
                        </span>
                    </div>
                </div>

                <script type="text/javascript">
                    //for Date   #datetimepicker1 is ID for Date Input Field     
                    $(function () {
                        $('#datetimepicker1').datetimepicker({
                            viewMode: 'years',
                            format: 'YYYY-MM-DD'
                        });
                        $('#datetimepicker2').datetimepicker({
                            viewMode: 'years',
                            format: 'YYYY-MM-DD'
                        });
                    });
                </script>
                <div class="form-group col-sm-12 text-left" id="errorMessage"></div>
                <input type="hidden" id="baseUrl" value="<?php echo base_url(); ?>">
            </div>
            <div class="form-group col-sm-4">
                <select class="form-control"
                        id="paymentStatus">
                    <option value=''>All</option>
                    <option value='1'>Paid</option>
                    <option value='2'>Partial Paid</option>
                    <option value='3'>Unpaid</option>
                    <option value='4'>Drop</option>
                    <option value='5'>Cancel</option>
                    <option value='6'>Pending</option>
                    <option value='7'>Refund Request</option>
                    <option value='8'>Refund</option>
                </select>
            </div>
        </div>

        <div class="col-sm-12">
            <div class="col-sm-12">
                <div class="col-sm-12 gray_ttc text-center" style="border-bottom: 2px solid #8CC73F;font-weight: bold">
                    <div class="col-sm-3 form-group">Invoice#</div>
                    <div class="col-sm-2 form-group">Invoice Date</div>
                    <div class="col-sm-2 form-group">Payment Date</div>
                    <div class="col-sm-2 form-group">Paid / Due</div>
                    <div class="col-sm-2 form-group">Status</div>
                    <div class="col-sm-1 form-group">Actions</div>
                </div>
                <div class="col-sm-12"><br></div> 

                <div class="col-sm-12 padding-zero text-center" id="viewInvoice">
                    <?php
                    //$this->load->library('ForeignExchange');
                    //$fx = new ForeignExchange('BDT', 'USD');
                    if ($invoice_info) {
                        $i =0;
                        foreach ($invoice_info as $value) {
                            $i++;
                            ?>
                            <div class="col-sm-12 <?php echo ($i % 2) ? 'gray' : 'white'; ?> text-center" >
                                <div class="col-sm-3 form-group"><?php echo '#tt-' . $random_id[$value->invoice_id]; ?></div>
                                <div class="col-sm-2 form-group"><?php echo date("F j, Y", strtotime($value->invoice_created_date)); ?></div>
                                <div class="col-sm-2 form-group"><?php
                                    if (isset($invoice_payment_info[$value->invoice_id])) {
                                        echo date('F j, Y', strtotime($invoice_payment_info[$value->invoice_id]->invoice_paid_date));
                                    } else {
                                        echo '-';
                                    }
                                    ?></div>
                                <div class="col-sm-2 form-group"><?php
                                    if (isset($invoice_payment_info[$value->invoice_id])) {
                                        if ($invoice_payment_info[$value->invoice_id]->currency_type == 1) {
                                            
                                            //echo 'BDT ' . round($invoice_payment_info[$value->invoice_id]->paid_amount) . ' / USD ' . round($this->tt_currency->set($invoice_payment_info[$value->invoice_id]->paid_amount, 'BDT', 'USD')->convert_currency()->get());
                                            echo 'BDT ' . round($invoice_payment_info[$value->invoice_id]->paid_amount);
                                        } else if ($invoice_payment_info[$value->invoice_id]->currency_type == 2) {
                                            
                                            //echo 'BDT ' . round($this->tt_currency->set($invoice_payment_info[$value->invoice_id]->paid_amount, 'USD', 'BDT')->convert_currency()->get()) . ' / USD ' . round($invoice_payment_info[$value->invoice_id]->paid_amount);
                                            echo ' USD ' . round($invoice_payment_info[$value->invoice_id]->paid_amount);
                                        }
                                    }                                         
                                    else{
                                        ?>
                                    <strong style="color:red">
                                    <?php 
                                        if ($value->payment_currency == 1) {
                                            
                                            //echo 'BDT ' . round($due_payment[$value->invoice_id]) . ' / USD ' . round($this->tt_currency->set($due_payment[$value->invoice_id], 'BDT', 'USD')->convert_currency()->get());
                                            echo 'BDT ' . round($due_payment[$value->invoice_id]);
                                        } else if ($value->payment_currency == 2) {
                                            
                                            //echo 'BDT ' . round($this->tt_currency->set($due_payment[$value->invoice_id], 'USD', 'BDT')->convert_currency()->get()) . ' / USD ' . round($due_payment[$value->invoice_id]);
                                            echo ' USD ' . round($due_payment[$value->invoice_id]);
                                        }
                                    ?>
                                    </strong>
                                    <?php }  ?>
                                </div>
                                <div class="col-sm-2 form-group">
                                    <strong>
                                        <?php
                                        switch ($value->payment_status) {
                                            case 1:
                                                echo 'Paid';
                                                break;
                                            case 2:
                                                echo 'Partial Paid';
                                                break;
                                            case 3:
                                                echo 'Unpaid';
                                                break;
                                            case 4:
                                                echo 'Drop';
                                                break;
                                            case 5:
                                                echo 'Cancel';
                                                break;
                                            case 6:
                                                echo 'Pending';
                                                break;
                                            case 7:
                                                echo 'Refund Request';
                                                break;
                                            case 8:
                                                echo 'Refunded';
                                                break;
                                            default :
                                                echo 'None';
                                                break;
                                        }
                                        ?>
                                    </strong>
                                </div>

                                <div class="col-sm-1 padding-zero text-center">
                                    <a href="<?php echo base_url('user/view-invoice/' . $random_id[$value->invoice_id]); ?>" target="_blank"><i class="fa fa-dollar" title="Details"></i></a>&nbsp;

                                    <?php
                                    //if (in_array($value->payment_status, [1, 2]) && $this->session->person_id == $value->person_id) {
                                        ?>
<!--                                        <a href="javascript:void(0)" id="refundRequestInvoice<?php //echo $random_id[$value->invoice_id]; ?>"><i class="fa fa-arrow-right" title="Refund Request" aria-hidden="true"></i></a>-->
                                    <?php //} ?>
                                </div>

                                <div class="modal fade" style="" id="viewRefundRequestInvoiceModal" tabindex="-1" role="dialog" aria-labelledby="changeRole" aria-hidden="true">
                                    <?php
                                    $message3 = '<span style="text-align:center">Are you sure you want to refund this Invoice?</span>';
                                    $this->cf->view_modal('refundImvoice', $message3);
                                    ?>
                                </div>

                                <input type="hidden" id="hiddenPaymentStatus<?php echo $random_id[$value->invoice_id]; ?>" value="<?php echo $value->payment_status ?>">
                            </div>
                            <?php
                        }
                        echo $paginzation_link;
                    }
                    ?> 
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript" src="<?php echo base_url() ?>front_end_resource/payment/view_invoice.js"></script>