

<?php $__env->startSection('title', 'Returned Devices'); ?>

<?php $__env->startSection('content'); ?>

    <div class="page-heading">

         

        <section class="section">

            <div class="card">

                <div class="card-header">

                    <h4 class="card-title">
                        Device Returns
                    </h4>

                </div>

                <div class="card-body">

                    <div class="table-responsive">

                        <div class="table-responsive">
                            <table class="table table-striped" id="returnsTable">

                                <thead>

                                    <tr>

                                        <th>Return No</th>

                                        <th>Devices</th>

                                        <th>Source</th>

                                        <th>Returned By</th>

                                        <th>Date</th>

                                        <th>Status</th>

                                        <th>Action</th>

                                    </tr>

                                </thead>

                                <tbody>

                                    <?php $__currentLoopData = $returns; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $return): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <tr>

                                            <td>
                                                <?php echo e($return->return_no); ?>

                                            </td>

                                            <td>
                                                <?php echo e($return->total_devices); ?>

                                            </td>

                                            <td>

                                                <?php if($return->return_source == 'sales'): ?>
                                                    <span class="badge bg-primary">
                                                        SALES
                                                    </span>
                                                <?php else: ?>
                                                    <span class="badge bg-info">
                                                        BORDER
                                                    </span>
                                                <?php endif; ?>

                                            </td>

                                            <td>
                                                <?php echo e($return->returnedBy?->name ?? '-'); ?>

                                            </td>
                                            <td>
                                                <?php echo e($return->returned_at ? $return->returned_at->format('d M Y H:i:s') : '-'); ?>

                                            </td>

                                            <td>

                                                <?php if($return->status == 'pending'): ?>
                                                    <span class="badge bg-warning">
                                                        PENDING
                                                    </span>
                                                <?php else: ?>
                                                    <span class="badge bg-success">
                                                        RECEIVED
                                                    </span>
                                                <?php endif; ?>

                                            </td>

                                            <td>

                                                <button class="btn btn-info btn-sm view-return"
                                                    data-return-no="<?php echo e($return->return_no); ?>">
                                                    <i class="bi bi-eye"></i>
                                                </button>

                                            </td>

                                        </tr>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

                                </tbody>

                            </table>



                        </div>

                    </div>

                </div>

        </section>
    </div>


    <div class="modal fade" id="viewReturnModal">

        <div class="modal-dialog modal-lg">

            <div class="modal-content">

                <div class="modal-header">

                    <h5>
                        Returned Devices
                    </h5>

                    <button type="button" class="btn-close" data-bs-dismiss="modal"></button>

                </div>

                <div class="modal-body">

                    <div class="row mb-3">

                        <div class="col-md-6">

                            <strong>
                                Return No:
                            </strong>

                            <span id="returnNo"></span>

                        </div>

                        <div class="col-md-6">

                            <strong>
                                Returned By:
                            </strong>

                            <span id="returnedBy"></span>

                        </div>

                        <div class="col-md-6">

                            <strong>
                                Source:
                            </strong>

                            <span id="returnSource"></span>

                        </div>

                        <div class="col-md-6">

                            <strong>
                                Return Date:
                            </strong>

                            <span id="returnDate"></span>

                        </div>

                    </div>

                    <table class="table table-bordered">

                        <thead>

                            <tr>

                                <th>#</th>

                                <th>Device Number</th>

                                <th>IMEI</th>

                                <th>Status</th>

                            </tr>

                        </thead>

                        <tbody id="returnDevicesBody">

                        </tbody>

                    </table>

                    <div class="mt-3" id="receiveReturnSection">

                    </div>

                </div>

            </div>

        </div>
    </div>

<?php $__env->stopSection(); ?>

<?php $__env->startPush('scripts'); ?>
    <script>
        $(document).ready(function() {

            $('#returnsTable').DataTable({

                order: [
                    [1, 'desc']
                ],

                pageLength: 25,

                responsive: true,

                dom: 'Bfrtip',

                buttons: [

                    'copy',
                    'excel',
                    'csv',
                    'print'

                ]

            });

        });



        $('.view-return').on('click', function() {

            let returnNo = $(this).data('return-no');

            $.get('/returns/' + returnNo, function(res) {

                $('#returnNo').text(res.return_no);
                $('#returnedBy').text(res.returned_by);
                $('#returnSource').text(res.return_source);
                $('#returnDate').text(res.returned_at);

                let rows = '';

                res.devices.forEach(function(device, index) {

                    rows += `
                <tr>
                    <td>${index + 1}</td>
                    <td>${device.device_number ?? '-'}</td>
                    <td>${device.imei ?? '-'}</td>
                    <td>${device.status}</td>
                </tr>
            `;
                });

                $('#returnDevicesBody').html(rows);

                if (res.status === 'pending') {

                    $('#receiveReturnSection').html(`
                <form method="POST"
                    action="/returns/${res.return_no}/receive">
                    <?php echo csrf_field(); ?>
                    <button class="btn btn-success">
                        Receive Devices
                    </button>
                </form>
            `);

                } else {

                    $('#receiveReturnSection').html(`
                <span class="badge bg-success">
                    RECEIVED
                </span>
            `);
                }

                $('#viewReturnModal').modal('show');
            });
        });
    </script>
<?php $__env->stopPush(); ?>

<?php echo $__env->make('layouts.master', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH D:\Projects\lms-ects\resources\views/returns/index.blade.php ENDPATH**/ ?>