
<?php $this->load->view('site/layout'); ?>
<link href="<?php echo base_url() ?>public/plugins/custom/datatables/datatables.bundle.css" rel="stylesheet" type="text/css" />

<link href="<?php echo base_url() ?>public/css/custom_css.css" rel="stylesheet" type="text/css" />
<style>
    .select2_plug{
        width: 100%;
    }
    .alert.alert-light .alert-text hr{
        border-top-color: #ccc;
    }
</style>

<?php $this->load->view('site/navbar'); ?>
<div class="kt-content  kt-grid__item kt-grid__item--fluid kt-grid kt-grid--hor" id="kt_content">
    <!-- begin:: Content Head -->
    <div class="kt-subheader  kt-grid__item" id="kt_subheader">
        <div class="kt-container  kt-container--fluid ">
            <div class="kt-subheader__main">
                <h3 class="kt-subheader__title"><a href="<?php echo base_url() ?>Dashboard/"><?php echo $this->lang->line('dashboard'); ?></a></h3>
                <span class="kt-subheader__separator kt-subheader__separator--v"></span>
                <span class="kt-subheader__desc"><?php echo $this->lang->line('pay_orders'); ?></span>
            </div>

        </div>
    </div>
</div>
<!-- 
        <div class="row">
     <div class="col-md-12">
<div  style="float:right">

        </div>   </div>
    </div> -->


<div class="kt-container  kt-container--fluid  kt-grid__item kt-grid__item--fluid" >
    <button class="btn btn-primary mb-3" onclick="toggle_filter()"><?= $this->lang->line('show_hide_filter') ?></button>
    <div class="alert alert-light alert-elevate" role="alert" id="filter_container">
        <div class="alert-text">
            <form method="post" action="" >
                <div class="row">
                    <div class="col-md-6">

                        <div class="form-group row">
                            <lable class="col-2 col-form-label"><?php echo $this->lang->line('date-added') ?></lable> 
                            <div class="col-9">
                                <input type="text" class="form-control" name="start_expiry" id="start_expiry" value="<?= $this->input->post() ? $this->input->post('start_expiry') : '' ?>">
                            </div>
                            <div class="col-1" style="padding-left: 0px;padding-right: 0px">
                                <a onclick="clear_date()" class="btn btn-light btn-text-primary btn-hover-text-primary font-weight-bold"><?= $this->lang->line('clear') ?></a>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="row" >
                    <div  class="col-md-6">
                        <div class="form-group">
                            <button class="btn btn-primary" ><?php echo $this->lang->line('search') ?></button> 
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<div class="kt-portlet kt-portlet--mobile">
    <?php if ($this->session->flashdata('msg')) { ?>
        <div class="alert alert-success">
            <a href="#" class="close" data-dismiss="alert" aria-label="close" title="close">×</a>
            <?= $this->session->flashdata('msg') ?>
        </div>
    <?php } ?>
    <?php if ($this->session->flashdata('error')) { ?>
        <div class="alert alert-danger">
            <a href="#" class="close" data-dismiss="alert" aria-label="close" title="close">×</a>
            <?= $this->session->flashdata('error') ?>
        </div>
    <?php } ?>
    <div class="kt-portlet__head kt-portlet__head--lg">
        <div class="kt-portlet__head-label">
            <span class="kt-portlet__head-icon">
                <i class="kt-font-brand flaticon2-line-chart"></i>
            </span>
            <h3 class="kt-portlet__head-title">
                <?php echo $this->lang->line('pay_orders'); ?>
            </h3>
        </div> <div class="kt-portlet__head-toolbar">
            <div class="kt-portlet__head-wrapper">
                <div class="kt-portlet__head-actions">
                    &nbsp;
                    <?php if (get_ap('add_pay_order', $this->operator_id) == 1) { ?>
                        <a href="<?= base_url() ?>/payment/add_pay_order/" class="btn btn-brand btn-elevate btn-icon-sm">
                            <i class="la la-plus"></i>
                            <?php echo $this->lang->line('add') . ' ' . $this->lang->line('pay_order') ?>
                        </a>
                    <?php } ?>
                </div>
            </div>
        </div>
    </div>
    <div class="kt-portlet__body">

        <!--begin: Datatable -->
        <table class="table table-bordered table-hover" id="list_table" > <!-- style="display: inline-block;overflow-x: scroll" -->
            <thead>
                <tr>
                    <th><?php echo $this->lang->line('sno') ?></th>
                    <th><?= $this->lang->line('date-added') ?></th>
                    <th><?php echo $this->lang->line('client_name') ?></th>
                    <th><?php echo $this->lang->line('amount') ?></th>
                    <th><?php echo $this->lang->line('phone') ?></th>
                    <th class="text-center"><?php echo $this->lang->line('payment') ?></th>
                    <th><?php echo $this->lang->line('payment_time') ?></th>
                    <th><?php echo $this->lang->line('payment_method') ?></th>
                    <th class="text-center"><?php echo $this->lang->line('action'); ?></th>
            </thead>
            <tbody>     <?php
                $count = 1;
                foreach ($pay_orders as $row) {
                    ?>
                    <tr>
                        <td><?php echo $count++; ?></td>
                        <td class="dir_ltr"><?= date('Y/m/d H:i', strtotime($row['created_at'])) ?></td>
                        <td><?= $row['client_name']; ?></td>
                        <td><?= $row['amount']; ?></td>
                        <td style="direction: ltr;"><?= $row['phone_code'] . $row['phone']; ?></td>
                        <td class="text-center"><?= $row['payment_time'] != NULL ? '<span class="fa fa-check text-success fa-lg" title="' . $this->lang->line('payment-is-made') . '"></span>' : '<span class="fas fa-times fa-lg text-danger" title="' . $this->lang->line('not-paid') . '"></span>' ?></td>
                        <td class="dir_ltr"><?= $row['payment_time'] ? date("Y/m/d H:i", strtotime($row['payment_time'])) : '---'; ?></td>
                        <td><?= $row['payment_method'] ? $row['payment_method'] : '---'; ?></td>
                        <td class="text-center"> 
                            <a href="<?= base_url() ?>payment/show_pay_order/<?= $row['id'] ?>" class="btn btn-icon btn-warning" title="<?= $this->lang->line('show') ?>">
                                <i class="fa fa-eye"></i>
                            </a>
                            <?php if ($row['payment_time'] != NULL) { ?>
                                <a href="<?= base_url() ?>payment/show_receipt/<?= $row['id'] ?>" class="btn btn-icon btn-success" title="Show Payment Details">
                                    <i class="fas fa-coins"></i>
                                </a>
                            <?php } ?>
                            <?php if (get_ap('edit_pay_order', $this->operator_id) == 1 && !$row['payment_time']) { ?>
                                <a href="<?= base_url() ?>/payment/edit_pay_order/<?= $row['id'] ?>" class="btn btn-icon btn-primary" title="<?= $this->lang->line('delete') ?>">
                                    <i class="fa fa-edit"></i>
                                </a>
                            <?php } ?>
                            <?php if (!$row['payment_time'] && $payment_sett && $payment_sett->status) { ?>
                                <a onclick="show_payment_link('<?php echo urlencode(base64_encode($row['id'])) . '/' . urlencode(base64_encode('1')) ?>')" class="btn btn-icon btn-success" title="<?= $this->lang->line('copy') . ' ' . $this->lang->line('payment_link') ?>">
                                    <i class="fas fa-copy"></i>
                                </a>
                            <?php } ?>

                            <?php if (get_ap('delete_pay_order', $this->operator_id) == 1) { ?>
                                <a onclick="alert_box(<?= $row['id'] ?>)" class="btn btn-icon btn-danger" title="<?= $this->lang->line('delete') ?>">
                                    <i class="fa fa-trash"></i>
                                </a>
                            <?php } ?>
                        </td>
                    </tr>
                <?php } ?>
            </tbody>
        </table>

        <!--end: Datatable -->
    </div>
</div>

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="exampleModalLabel"><?= $this->lang->line('payment_link') ?></h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <i aria-hidden="true" class="ki ki-close"></i>
                </button>
            </div>
            <div class="modal-body">
                <div class="form-group row">
                    <label for="example-email-input" class="col-2 col-form-label"><?= $this->lang->line('payment_link') ?> : </label>
                    <div class="col-10 mt-3">
                        <p id="payment_link"></p>  
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-light-primary font-weight-bold" data-dismiss="modal">Close</button>
                <button class="btn btn-primary font-weight-bold" onclick="copyToClipboard()"><?= $this->lang->line('copy') ?></button>
            </div> 
        </div>
    </div>
</div>

<?php $this->load->view('site/footer_2'); ?>


<script>function clear_date() {
        $("#start_expiry").val('');
    }
</script>
<script>
    $("#filter_container").hide();
    $(".select2_plug").select2();
    function alert_box(id) {
        var result = confirm("Are You Confirm!")
        if (result) {
            window.location.href = "<?= base_url('payment/del/') ?>" + id;
        }
    }
    function show_payment_link(order_id_encoded) {
        $("#payment_link").text('<?= base_url() ?>' + 'payment/pay/' + order_id_encoded);
        $("#myModal").modal('show');
    }
    function copyToClipboard() {
        var $temp = $("<div>");
        $("body").append($temp);
        $temp.attr("contenteditable", true)
                .html($("#payment_link").text()).select()
                .on("focus", function () {
                    document.execCommand('selectAll', false, null);
                })
                .focus();
        document.execCommand("copy");
        $temp.remove();
        $("#myModal").modal('hide');
        alert('Copied to the clipboard');
    }
    function toggle_filter() {
        $("#filter_container").toggle();
        $(".select2_plug").select2();
    }

    function show_desc(desc) {
        $("#block_reason").text(desc);
        $("#block_reason_modal").modal('show');
    }

    $(function () {
        $("#list_table").DataTable({dom: 'Bfrtip',
            destroy: true,
            buttons: [
                {
                    extend: 'excelHtml5',
                    charset: 'UTF-16LE',
                    fieldSeparator: '\t',
                    bom: true
                },
                {
                    extend: 'csvHtml5',
                    charset: 'UTF-16LE',
                    fieldSeparator: '\t',
                    bom: true
                },
                {
                    extend: 'pdfHtml5',
                    charset: 'UTF-16LE',
                    fieldSeparator: '\t',
                    bom: true
                },
                {
                    extend: 'print',
                    autoPrint: false,
                    footer: true
                }

            ]
        });
//            buttons: [
//                'copyHtml5',
//                'excelHtml5',
//                'csvHtml5',
//                'pdfHtml5'
//            ]
    });


</script>