

<?php $__env->startSection('content'); ?>
<?php echo $__env->make('components.notification', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
<form action="">
    <div class="row">
        <div class="col-md-3">
            <label for="">Dari Tanggal</label>
            <input type="date" name="dari" id="" class="form-control" value="<?php echo e(isset($_GET['dari']) ? $_GET['dari'] : date('Y-m-d')); ?>">
        </div>
        <div class="col-md-3">
            <label for="">Sampai Tanggal</label>
            <input type="date" name="sampai" id="" class="form-control" value="<?php echo e(isset($_GET['sampai']) ? $_GET['sampai'] : date('Y-m-d')); ?>">
        </div>
        <div class="col-md-3">
            <label for="">Cabang</label>
            <select name="cabang" id="" class="form-control select2">
                <option value="">---Pilih Cabang---</option>
                <?php $__currentLoopData = $branch; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <option value="<?php echo e($item->id); ?>" <?php echo e(Request::get('cabang') == $item->id ? 'selected' : ''); ?>><?php echo e($item->cabang); ?></option>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </select>
        </div>
        <div class="col-md-2">
            <label for="" class="d-block">&nbsp;</label>
            <button type="submit" class="btn btn-primary"><span class="fa fa-filter"></span> Filter</button>
        </div>
    </div>
</form>
<?php if(isset($_GET['dari'])): ?>
<br>
<?php echo $__env->make('transaction._table-redeem', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
<?php endif; ?>
</div>
<?php $__env->stopSection(); ?>

<?php $__env->startPush('custom-script'); ?>
<?php if(isset($_GET['dari'])): ?>
<script type="text/javascript">
    $(function() {
        var no = 1
        var table = $('.myTable').DataTable({
            processing: true,
            serverSide: true,
            orderable: false,
            ajax: "<?= url('redeem?dari=' . $_GET['dari'] . '&sampai=' . $_GET['sampai']) . '&cabang=' . $_GET['cabang'] ?>",
            columns: [{
                    data: 'DT_RowIndex',
                    name: 'DT_RowIndex',
                },
                {
                    data: 'trx_code',
                    name: 'trx_code'
                },
                {
                    data: 'nama',
                    name: 'nama'
                },
                {
                    data: 'tgl_trx',
                    render: function(data, type, row) {
                        return indoDate(data)
                    }
                },
                {
                    data: 'cabang',
                    render: function(data, type, row) {
                        return data == '' || data == null ? 'Semua Cabang' : data
                    }
                },
                {
                    data: 'voucher_code',
                    render: function(data, type, row) {
                        return data == '' || data == null ? '-' : data
                    }
                },
                {
                    data: 'voucher_price',
                    render: function(data, type, row) {
                        return row.voucher_code == '' || row.voucher_code == null ? '-' : new Intl.NumberFormat("id-ID", {
                            style: "currency",
                            currency: "IDR"
                        }).format(data);
                    }
                },
                {
                    data: 'amount',
                    render: function(data, type, row) {
                        return new Intl.NumberFormat("id-ID", {
                            style: "currency",
                            currency: "IDR"
                        }).format(data);
                    }
                },
                // {
                //     data: 'poin_earned',
                //     render: function(data, type, row) {
                //         return row.tipe == 'Transaksi POS' ? new Intl.NumberFormat("id-ID", {
                //             style: "currency",
                //             currency: "IDR"
                //         }).format(data) : '-';
                //     }
                // },
                // {
                //     data: 'tipe',
                //     name: 'tipe'
                // },
                // {
                //     data: 'action',
                //     name: 'action',
                //     orderable: false,
                //     searchable: false
                // },
            ],
            order: [
                [0, 'asc']
            ],
        });
    });

    function indoDate(newDate) {
        const today = new Date(newDate);
        const yyyy = today.getFullYear();
        let mm = today.getMonth() + 1; // Months start at 0!
        let dd = today.getDate();
        let hh = newDate.substr(11, 2);
        let ii = newDate.substr(14, 2);

        if (dd < 10) dd = '0' + dd;
        if (mm < 10) mm = '0' + mm;

        const formattedToday = dd + '-' + mm + '-' + yyyy + ' ' + hh + ':' + ii;
        return formattedToday
    }
</script>
<?php endif; ?>
<?php $__env->stopPush(); ?>
<?php echo $__env->make('layouts.template', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/coffeeto/public_html/member/resources/views/transaction/redeem.blade.php ENDPATH**/ ?>