

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

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

    <div class="card">

        <div class="card-header">

            <div class="d-flex justify-content-between">

                <h4 class="mb-0">
                    Customers
                </h4>

                <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('settings.edit')): ?>
                    <button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addCustomerModal">

                        <i class="bi bi-plus-circle"></i>
                        Add Customer

                    </button>
                <?php endif; ?>

            </div>

        </div>

        <div class="card-body">

            <div class="table-responsive">

                <table class="table table-striped" id="customerTable">

                    <thead>

                        <tr>

                            <th>S/N</th>

                            <th>Name</th>

                            <th>Contact Person</th>

                            <th>Phone</th>

                            <th>Master Price</th>

                            <th>Slave Price</th>

                            <th>Status</th>

                            <th>Action</th>

                        </tr>

                    </thead>

                    <tbody>

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

                                <td>
                                    <?php echo e($loop->iteration); ?>

                                </td>

                                <td>
                                    <?php echo e($customer->name); ?>

                                </td>

                                <td>
                                    <?php echo e($customer->contact_person); ?>

                                </td>

                                <td>
                                    <?php echo e($customer->phone); ?>

                                </td>

                                <td>
                                    <?php echo e(number_format($customer->master_price)); ?>

                                </td>

                                <td>
                                    <?php echo e(number_format($customer->slave_price)); ?>

                                </td>

                                <td>

                                    <?php if($customer->status): ?>
                                        <span class="badge bg-success">
                                            ACTIVE
                                        </span>
                                    <?php else: ?>
                                        <span class="badge bg-danger">
                                            DISABLED
                                        </span>
                                    <?php endif; ?>

                                </td>

                                <td>

                                    <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('settings.edit')): ?>
                                        <button class="btn btn-primary btn-sm edit-customer" data-id="<?php echo e($customer->id); ?>"
                                            data-name="<?php echo e($customer->name); ?>"
                                            data-contact_person="<?php echo e($customer->contact_person); ?>"
                                            data-phone="<?php echo e($customer->phone); ?>" data-email="<?php echo e($customer->email); ?>"
                                            data-tin="<?php echo e($customer->tin); ?>" data-vrn="<?php echo e($customer->vrn); ?>"
                                            data-address="<?php echo e($customer->address); ?>"
                                            data-master_price="<?php echo e($customer->master_price); ?>"
                                            data-slave_price="<?php echo e($customer->slave_price); ?>"
                                            data-status="<?php echo e($customer->status); ?>" data-bs-toggle="modal"
                                            data-bs-target="#editCustomerModal">

                                            <i class="bi bi-pencil"></i>

                                        </button>
                                    <?php endif; ?>

                                </td>

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

                    </tbody>

                </table>

            </div>

        </div>

    </div>

    <?php echo $__env->make('customers.partials.add-customer-modal', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>

    <?php echo $__env->make('customers.partials.edit-customer-modal', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>

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

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

            $('#customerTable').DataTable();

        });

        $(document).on(
            'click',
            '.edit-customer',
            function() {

                let id = $(this).data('id');

                $('#editCustomerForm').attr(
                    'action',
                    '/customers/' + id
                );

                $('#edit_name').val(
                    $(this).data('name')
                );

                $('#edit_contact_person').val(
                    $(this).data('contact_person')
                );

                $('#edit_phone').val(
                    $(this).data('phone')
                );

                $('#edit_email').val(
                    $(this).data('email')
                );

                $('#edit_tin').val(
                    $(this).data('tin')
                );

                $('#edit_vrn').val(
                    $(this).data('vrn')
                );

                $('#edit_address').val(
                    $(this).data('address')
                );

                $('#edit_master_price').val(
                    $(this).data('master_price')
                );

                $('#edit_slave_price').val(
                    $(this).data('slave_price')
                );

                $('#edit_status').val(
                    $(this).data('status')
                );

            }
        );
    </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/customers/index.blade.php ENDPATH**/ ?>