<script src="<?php echo site_url(); ?>assets/js/plugin/datatables1_10_7/jquery.dataTables.min.js"></script>
<script src="<?php echo site_url(); ?>assets/js/plugin/datatables/dataTables.colReorder.min.js"></script>
<script src="<?php echo site_url(); ?>assets/js/plugin/datatables/dataTables.colVis.min.js"></script>
<script src="<?php echo site_url(); ?>assets/js/plugin/datatables/dataTables.tableTools.min.js"></script>
<script src="<?php echo site_url(); ?>assets/js/plugin/datatables/dataTables.bootstrap.min.js"></script>
<script src="<?php echo site_url(); ?>assets/js/plugin/datatable-responsive/datatables.responsive.min.js"></script>

<script src="//cdn.datatables.net/buttons/1.6.1/js/dataTables.buttons.min.js" crossorigin="anonymous"></script>
<script src="//cdn.datatables.net/buttons/1.6.1/js/buttons.flash.min.js" crossorigin="anonymous"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js" crossorigin="anonymous"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/pdfmake.min.js" crossorigin="anonymous"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/vfs_fonts.js" crossorigin="anonymous"></script>
<script src="//cdn.datatables.net/buttons/1.6.1/js/buttons.html5.min.js" crossorigin="anonymous"></script>
<script src="//cdn.datatables.net/buttons/1.6.1/js/buttons.print.min.js" crossorigin="anonymous"></script>
<script src="//cdn.datatables.net/buttons/1.6.1/js/buttons.colVis.min.js" crossorigin="anonymous"></script>

<!-- MAIN PANEL -->
<div id="main" role="main">

    <!-- MAIN CONTENT -->
    <div id="content" style=" padding-top: 0px; ">

        <div class="row">

            <div class="col col-lg-12 table-responsive">

                <h1>
                    <?php echo $customers[0]->customerName; ?>
                </h1>
                <hr />
                <br />
                <br />
            </div>
            <div class="col col-lg-8">
                <div class="table_wrap">
                    <table class="table table-bordered table-hover" id="dt_basic222">
                        <thead>
                            <th>#</th>
                            <th><?php echo $this->lang->line('transilla_invoice_tax'); ?></th>
                            <th><?php echo $this->lang->line('payment_method'); ?></th>
                            <th><?php echo $this->lang->line('type'); ?></th>
                            <th><?php echo $this->lang->line('debit'); ?></th>
                            <th><?php echo $this->lang->line('balance_credit'); ?></th>
                            <th><?php echo $this->lang->line('balance'); ?></th>
                            <th><?php echo $this->lang->line('note'); ?></th>
                            <th><?php echo $this->lang->line('date'); ?></th>
                            <th></th>
                        </thead>
                    </table>
                </div>
            </div>
            <div class="col col-lg-4">
                <div class="well well-light">
                    <h2>
                        <?php echo $this->lang->line('customer_balance'); ?>
                    </h2>
                    <h1><strong><?php echo number_format($full_balance, 2); ?></strong> ₪</h1>
                </div>
                <hr />
                <h2>
                    <?php echo $this->lang->line('invoice_customer'); ?>
                </h2>
                <div class="well well-light">
                    <table class="table table-stiped table-bordered" id="dt_basic">
                        <thead>
                            <th>#</th>
                            <th><?php echo $this->lang->line('sum'); ?></th>
                            <th><?php echo $this->lang->line('paid'); ?></th>
                            <th><?php echo $this->lang->line('balance'); ?></th>
                            <th><?php echo $this->lang->line('date'); ?></th>
                        </thead>
                        <tbody>
                            <?php foreach ($invoices as $invoice) { ?>
                                <tr>
                                    <td><?php echo $invoice->invoice_id; ?></td>
                                    <td><?php echo $invoice->total; ?></td>
                                    <td><?php echo $invoice->payed_amount; ?></td>
                                    <td><?php echo $invoice->invoice_balance; ?></td>
                                    <td><?php echo date('d/m/Y', strtotime($invoice->invoice_date)); ?></td>
                                </tr>
                            <?php }; ?>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
        <!-- END MAIN CONTENT -->
    </div>
</div>

<style>
    .dt-buttons {
        float: left;
        text-align: right;
    }

    .dt-button {
        background: transparent;
        border: 1px solid #a90329;
        padding: 5px;
        padding-right: 20px;
        padding-left: 20px;
        font-weight: bold;
        border-radius: 25px;
        color: #a90329;
    }

    .dt-button-collection .dt-button {
        background: #ffffff;
        float: right;
        opacity: 0.5;
    }

    .dt-button-collection {
        margin-top: 7px;
        position: absolute;
        z-index: 9999;
        background: #0000007a;
        width: 140%;
        right: 100px;
        padding: 7px;
        border-radius: 25px;
    }

    button.dt-button.buttons-columnVisibility.active {
        background: white;
        opacity: 1;
    }
</style>

<div class="modal fade" id="edit_comment_modal" tabindex="-1" role="dialog" aria-labelledby="convert_boxModal" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="createPaymentModalTitle">
                    <?php echo $this->lang->line('update_notes'); ?>
                </h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <form action="no-action" method="POST" class="smart-form" id="edit_commentForm">

                    <div class="row">
                        <input type="hidden" class="" value="" id="edited_note_id" />
                        <div class="col col-lg-12 col-sm-12 col-md-12">
                            <label for="notes"> <?php echo $this->lang->line('notes '); ?>
                            </label>
                            <label class="input">
                                <input class="" value="" id="edited_note" />
                            </label>
                            <br />
                        </div>

                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal"><?php echo $this->lang->line('close'); ?></button>
                <button type="button" class="btn btn-primary" id="add_comment_to_payment" style="float:left;"><?php echo $this->lang->line('save'); ?></button>
            </div>
        </div>
    </div>
</div>

<style>
    .dt-toolbar-footer div:nth-child(2) {
        width: 100% !important;
    }

    .dataTables_filter {
        width: 120%;
    }

    ul.select2-result-sub {
        padding-right: 5px !important;
    }

    .select2-result-sub li {
        border-right: 4px solid #dadada;
    }

    .select2-results li.select2-result-with-children>.select2-result-label {
        font-weight: bold;
        background: #F44336;
        color: white;
    }

    .remove_this_item,
    .remove_this_payment {
        position: absolute;
        right: 0px;
        margin-top: 15px;
    }

    .remove_this_item:active,
    .remove_this_payment:active {
        position: absolute;
        top: auto !important;
        left: auto !important;
        right: 0px !important;
    }
</style>

<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.8.4/moment.min.js"></script>
<script src="https://cdn.datatables.net/plug-ins/1.10.21/sorting/datetime-moment.js"></script>

<script type="text/javascript">
<?php
            $url = '';
            if( $this->session->userdata('site_lang') == 'hebrew' ){
                $url = '//cdn.datatables.net/plug-ins/9dcbecd42ad/i18n/Hebrew.json';
            }else if( $this->session->userdata('site_lang') == 'arabic' ){
                $url = '//cdn.datatables.net/plug-ins/9dcbecd42ad/i18n/Arabic.json';
            }else if( $this->session->userdata('site_lang') == 'english' ){
                $url = '//cdn.datatables.net/plug-ins/9dcbecd42ad/i18n/English.json';
            }else{
                $url = '//cdn.datatables.net/plug-ins/9dcbecd42ad/i18n/Hebrew.json';
            }
        ?>
    $(document).ready(function() {
        $.fn.dataTable.moment('DD/MM/YYYY');
        var data_multi = {};
        var data_main = {};
        var oTbl1 = $('#dt_basic222').DataTable({
            "sDom": "<'dt-toolbar'<'col-xs-12 col-sm-6'f><'dt-buttons col-sm-6 col-xs-12 hidden-xs'l>r>" +
                "t" +
                "<'dt-toolbar-footer'<'col-sm-6 col-xs-12 hidden-xs'i><'col-xs-12 col-sm-6'p>>",
            "buttons": ['copyHtml5', 'excelHtml5', 'csvHtml5', 'colvis'],
            "processing": false,
            "bStateSave": false,
            "dom": 'Bfrtip',
            "pagingType": "full_numbers",
            "lengthMenu": [
                [5, 10, 25, 50, -1],
                [5, 10, 25, 50, "<?php echo $this->lang->line('Everything'); ?>"]
            ],
            "pageLength": 25,
            "sPaginationType": "full_numbers",
            "iDisplayLength": 25,
            "language": {
                    "url": "<?php echo $url; ?>"
                },
            "order": [
                [8, "desc"]
            ]
        });
        var currentSum = 0;
        oTbl1.buttons().container().appendTo('.dataTables_filter');

        $('input[aria-controls="dt_basic2"]').attr('placeholder', 'חיפוש...');
        $('#dt_basic2_info').css('float', 'left').parent().css('float', 'left');
        $('.dataTables_paginate ').parent().css('float', 'right');
        $('.dataTables_paginate ').css('text-align', 'right');
        $(document).on('click', 'a.edit_comment', function() {
            var payment_id = $(this).attr('rel-id');
            var currentText = $(this).parent().parent().find('.notes2_saved').text();
            $('#edited_note').val(currentText + " ");
            $('#edited_note_id').val(payment_id);
            $('#edit_comment_modal').modal('show');
            $('#edited_note').focus();
        });
        $('#edit_comment_modal').on('shown.bs.modal', function() {
            $('#edited_note').focus();
        });
        $('#add_comment_to_payment').on('click', function() {

            var data = {};
            data.payment_id = $('#edited_note_id').val();
            data.comment = $('#edited_note').val();

            $.post(root + 'admin/invoices/addCommentToPayment', data, function(d) {

                if (d.result == true) {
                    alert("<?php echo $this->lang->line('Done'); ?>!");
                    location.reload();
                } else {
                    alert("<?php echo $this->lang->line('Error'); ?>!");
                }

            }, 'json');
        });

    });
</script>