 <?php $__env->startSection('content'); ?>
<?php if(session()->has('create_message')): ?>
    <div class="alert alert-success alert-dismissible text-center"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><?php echo session()->get('create_message'); ?></div>
<?php endif; ?>
<?php if(session()->has('edit_message')): ?>
    <div class="alert alert-success alert-dismissible text-center"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><?php echo e(session()->get('edit_message')); ?></div>
<?php endif; ?>
<?php if(session()->has('message')): ?>
    <div class="alert alert-success alert-dismissible text-center"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><?php echo e(session()->get('message')); ?></div>
<?php endif; ?>
<?php if(session()->has('import_message')): ?>
    <div class="alert alert-success alert-dismissible text-center"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><?php echo session()->get('import_message'); ?></div>
<?php endif; ?>
<?php if(session()->has('not_permitted')): ?>
  <div class="alert alert-danger alert-dismissible text-center"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><?php echo e(session()->get('not_permitted')); ?></div>
<?php endif; ?>
<?php if($errors->any()): ?>
  <div class="alert alert-danger alert-dismissible text-center"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><?php echo e($errors->first()); ?></div>
<?php endif; ?>

<section>
    <div class="container-fluid">
        <div class="card">
            <div class="card-header d-flex flex-wrap align-items-center justify-content-between">
                <div>
                    <h4 class="mb-1"><?php echo e(trans('file.Customer List')); ?></h4>
                    <small class="text-muted">View customer contact information, outstanding balances, and payments.</small>
                </div>
                <?php if(in_array("customers-add", $all_permission)): ?>
                    <a href="<?php echo e(route('customer.create')); ?>" class="btn btn-primary mt-2 mt-md-0"><i class="dripicons-plus"></i> <?php echo e(trans('file.Add Customer')); ?></a>
                <?php endif; ?>
            </div>
            <div class="card-body">
                <div class="table-responsive">
        <table id="customer-table" class="table table-hover customer-list-table">
            <thead>
                <tr>
                    <th class="not-exported"></th>
                    <th><?php echo e(trans('file.name')); ?></th>
                    <th><?php echo e(trans('file.Phone Number')); ?></th>
                    <th><?php echo e(trans('file.Email')); ?></th>
                    <th><?php echo e(trans('file.Address')); ?></th>
                    <th>Total Paid</th>
                    <th><?php echo e(trans('file.Total Due')); ?></th>
                    <th class="not-exported"><?php echo e(trans('file.action')); ?></th>
                </tr>
            </thead>
            <tbody>
                <?php $__currentLoopData = $lims_customer_all; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $customer): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <tr data-id="<?php echo e($customer->id); ?>">
                    <td><?php echo e($key); ?></td>
                    <td>
                        <strong><?php echo e($customer->name); ?></strong>
                        <?php if($customer->company_name): ?>
                            <small class="d-block text-muted"><?php echo e($customer->company_name); ?></small>
                        <?php endif; ?>
                    </td>
                    <td>
                        <?php if($customer->phone_number): ?>
                            <a href="tel:<?php echo e($customer->phone_number); ?>"><?php echo e($customer->phone_number); ?></a>
                        <?php else: ?>
                            <span class="text-muted">—</span>
                        <?php endif; ?>
                    </td>
                    <td>
                        <?php if($customer->email): ?>
                            <a href="mailto:<?php echo e($customer->email); ?>"><?php echo e($customer->email); ?></a>
                        <?php else: ?>
                            <span class="text-muted">—</span>
                        <?php endif; ?>
                    </td>
                    <td>
                        <?php echo e($customer->address ?: '—'); ?>

                        <?php if($customer->city): ?><small class="d-block text-muted"><?php echo e($customer->city); ?></small><?php endif; ?>
                    </td>
                    <td data-order="<?php echo e($customer->calculated_total_paid); ?>">
                        <strong class="text-success"><?php echo e(number_format($customer->calculated_total_paid, 2)); ?> <?php echo e(config('currency')); ?></strong>
                    </td>
                    <td data-order="<?php echo e($customer->calculated_total_due); ?>">
                        <?php if($customer->calculated_total_due > 0): ?>
                            <strong class="text-danger"><?php echo e(number_format($customer->calculated_total_due, 2)); ?> <?php echo e(config('currency')); ?></strong>
                        <?php elseif($customer->calculated_total_due < 0): ?>
                            <strong class="text-success"><?php echo e(number_format($customer->calculated_total_due, 2)); ?> <?php echo e(config('currency')); ?></strong>
                        <?php else: ?>
                            <span class="text-muted">0.00 <?php echo e(config('currency')); ?></span>
                        <?php endif; ?>
                    </td>
                    <td>
                        <div class="btn-group">
                            <button type="button" class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><?php echo e(trans('file.action')); ?>

                                <span class="caret"></span>
                                <span class="sr-only">Toggle Dropdown</span>
                            </button>
                            <ul class="dropdown-menu edit-options dropdown-menu-right dropdown-default" user="menu">
                                <?php if(in_array("customers-edit", $all_permission)): ?>
                                <li>
                                    <a href="<?php echo e(route('customer.edit', $customer->id)); ?>" class="btn btn-link"><i class="dripicons-document-edit"></i> <?php echo e(trans('file.edit')); ?></a>
                                </li>
                                <?php endif; ?>
                                <li>
                                    <a href="<?php echo e(route('customer.statement', $customer->id)); ?>" class="btn btn-link"><i class="dripicons-pulse"></i> Customer Statement</a>
                                </li>
                                <?php if($customer->calculated_total_due > 0): ?>
                                    <li>
                                        <button type="button" data-id="<?php echo e($customer->id); ?>" data-name="<?php echo e($customer->name); ?>" data-due="<?php echo e($customer->calculated_total_due); ?>" class="clear-due btn btn-link" data-toggle="modal" data-target="#clearDueModal" ><i class="fa fa-money"></i> Record Payment</button>
                                    </li>
                                <?php endif; ?>
                                <li class="divider"></li>
                                <?php if(in_array("customers-delete", $all_permission)): ?>
                                <?php echo e(Form::open(['route' => ['customer.destroy', $customer->id], 'method' => 'DELETE'] )); ?>

                                <li>
                                    <button type="submit" class="btn btn-link" onclick="return confirmArchive()"><i class="dripicons-archive"></i> Archive Customer</button>
                                </li>
                                <?php echo e(Form::close()); ?>

                                <?php endif; ?>
                            </ul>
                        </div>
                    </td>
                </tr>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </tbody>
        </table>
                </div>
            </div>
        </div>
    </div>
</section>

<?php $__env->startPush('css'); ?>
<style>
    #customer-table_wrapper { width: 100%; margin-top: 0; }
    #customer-table_wrapper .customer-table-toolbar {
        padding: 4px 0 16px;
        border-bottom: 1px solid #eef0f4;
    }
    #customer-table_wrapper .dataTables_filter {
        float: none;
        width: 100%;
        text-align: left;
        margin: 0;
    }
    #customer-table_wrapper .dataTables_filter label {
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        gap: 6px;
        margin: 0;
        color: #4f566b;
        font-weight: 600;
    }
    #customer-table_wrapper .dataTables_filter input {
        width: 320px;
        max-width: 100%;
        height: 42px;
        margin: 0 !important;
        padding: 8px 12px;
        border: 1px solid #dfe3ea;
        border-radius: 7px;
        background: #fff;
    }
    #customer-table_wrapper .dt-buttons { display: inline-flex; float: none; width: auto; max-width: 100%; flex-wrap: nowrap; justify-content: flex-end; gap: 4px; margin: 0; white-space: nowrap; }
    #customer-table_wrapper .dt-buttons .btn { float: none; flex: 0 0 auto; margin: 0 !important; border-radius: 6px; }
    #customer-table_wrapper .customer-table-footer {
        padding: 16px 0 4px;
        border-top: 1px solid #eef0f4;
    }
    #customer-table_wrapper .customer-page-size,
    #customer-table_wrapper .dataTables_length {
        float: none;
        width: auto;
        margin-right: 14px;
    }
    #customer-table_wrapper .dataTables_length label {
        display: flex;
        align-items: center;
        gap: 8px;
        margin: 0;
        color: #6c7382;
        white-space: nowrap;
    }
    #customer-table_wrapper .dataTables_length select {
        min-width: 70px;
        height: 38px;
        margin: 0 !important;
        border-radius: 6px;
    }
    #customer-table_wrapper .dataTables_paginate,
    #customer-table_wrapper .dataTables_info {
        padding-top: 0;
    }
    #customer-table_wrapper .pagination {
        margin: 0;
    }
    @media (max-width: 767px) {
        #customer-table_wrapper .dataTables_filter input { width: 100%; }
        #customer-table_wrapper .customer-table-footer > div { justify-content: flex-start !important; margin-top: 10px; }
        #customer-table_wrapper .customer-table-toolbar > div:last-child { overflow-x: auto; padding-bottom: 4px; }
    }
</style>
<?php $__env->stopPush(); ?>

<div id="clearDueModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true" class="modal fade text-left">
    <div role="document" class="modal-dialog">
      <div class="modal-content">
        <?php echo Form::open(['route' => 'customer.clearDue', 'method' => 'post']); ?>

        <div class="modal-header">
          <h5 id="exampleModalLabel" class="modal-title">Record Customer Payment</h5>
          <button type="button" data-dismiss="modal" aria-label="Close" class="close"><span aria-hidden="true"><i class="dripicons-cross"></i></span></button>
        </div>
        <div class="modal-body">
            <div class="alert alert-light border">
                <strong id="payment-customer-name"></strong>
                <div>Total due: <strong id="payment-customer-due" class="text-danger"></strong></div>
            </div>
            <div class="form-group">
                <input type="hidden" name="customer_id">
                <label><?php echo e(trans('file.Amount')); ?> *</label>
                <input type="number" name="amount" min="0.01" step="0.01" class="form-control" required>
            </div>
            <div class="form-group">
                <label><?php echo e(trans('file.Note')); ?></label>
                <textarea name="note" rows="4" class="form-control"></textarea>
            </div>
            <input type="submit" value="Save Payment" class="btn btn-primary" id="submit-button">
        </div>
        <?php echo Form::close(); ?>

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

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

<?php $__env->startPush('scripts'); ?>
<script type="text/javascript">
    $("ul#people").siblings('a').attr('aria-expanded','true');
    $("ul#people").addClass("show");
    $("ul#people #customer-list-menu").addClass("active");

    function confirmArchive() {
      if (confirm("Archive this customer? Historical sales and payments will remain available.")) {
          return true;
      }
      return false;
    }

    var customer_id = [];
    var user_verified = <?php echo json_encode(env('USER_VERIFIED')) ?>;
    var all_permission = <?php echo json_encode($all_permission) ?>;

    $.ajaxSetup({
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        }
    });

  $(".clear-due").on("click", function() {
        var id = $(this).data('id').toString();
        var due = parseFloat($(this).data('due')) || 0;
        $("#clearDueModal input[name='customer_id']").val(id);
        $("#clearDueModal input[name='amount']").attr('max', due.toFixed(2)).val('');
        $("#payment-customer-name").text($(this).data('name'));
        $("#payment-customer-due").text(due.toFixed(2) + ' <?php echo e(config("currency")); ?>');
  });

    var table = $('#customer-table').DataTable( {
        "order": [],
        'language': {
            'lengthMenu': 'Rows per page: _MENU_',
             "info":      '<small><?php echo e(trans("file.Showing")); ?> _START_ - _END_ (_TOTAL_)</small>',
            "search":  'Search customers',
            "searchPlaceholder": 'Name, phone, email or address',
            'paginate': {
                    'previous': '<i class="dripicons-chevron-left"></i>',
                    'next': '<i class="dripicons-chevron-right"></i>'
            }
        },
        'columnDefs': [
            {
                "orderable": false,
                'targets': [0, 7]
            },
            {
                'render': function(data, type, row, meta){
                    if(type === 'display'){
                        data = '<div class="checkbox"><input type="checkbox" class="dt-checkboxes"><label></label></div>';
                    }

                   return data;
                },
                'checkboxes': {
                   'selectRow': true,
                   'selectAllRender': '<div class="checkbox"><input type="checkbox" class="dt-checkboxes"><label></label></div>'
                },
                'targets': [0]
            }
        ],
        'select': { style: 'multi',  selector: 'td:first-child'},
        'lengthMenu': [[10, 25, 50, -1], [10, 25, 50, "All"]],
        dom: '<"customer-table-toolbar row align-items-end mb-3"<"col-md-6"f><"col-md-6 d-flex justify-content-md-end mt-3 mt-md-0"B>>rt<"customer-table-footer row align-items-center"<"col-md-4"i><"col-md-8 d-flex flex-wrap justify-content-md-end align-items-center"<"customer-page-size"l>p>>',
        buttons: [
            {
                extend: 'pdf',
                text: '<i title="export to pdf" class="fa fa-file-pdf-o"></i>',
                exportOptions: {
                    columns: ':visible:Not(.not-exported)',
                    rows: ':visible'
                },
            },
            {
                extend: 'excel',
                text: '<i title="export to excel" class="dripicons-document-new"></i>',
                exportOptions: {
                    columns: ':visible:Not(.not-exported)',
                    rows: ':visible'
                },
            },
            {
                extend: 'csv',
                text: '<i title="export to csv" class="fa fa-file-text-o"></i>',
                exportOptions: {
                    columns: ':visible:Not(.not-exported)',
                    rows: ':visible'
                },
            },
            {
                extend: 'print',
                text: '<i title="print" class="fa fa-print"></i>',
                exportOptions: {
                    columns: ':visible:Not(.not-exported)',
                    rows: ':visible'
                },
            },
            {
                text: '<i title="archive selected customers" class="dripicons-archive"></i>',
                className: 'buttons-delete',
                action: function ( e, dt, node, config ) {
                    if(user_verified == '1') {
                        customer_id.length = 0;
                        $(':checkbox:checked').each(function(i){
                            if(i){
                                customer_id[i-1] = $(this).closest('tr').data('id');
                            }
                        });
                        if(customer_id.length && confirm("Archive the selected customers? Historical transactions will remain available.")) {
                            $.ajax({
                                type:'POST',
                                url:'customer/deletebyselection',
                                data:{
                                    customerIdArray: customer_id
                                },
                                success:function(data){
                                    alert(data);
                                }
                            });
                            dt.rows({ page: 'current', selected: true }).remove().draw(false);
                        }
                        else if(!customer_id.length)
                            alert('No customer is selected!');
                    }
                    else
                        alert('This feature is disable for demo!');
                }
            },
            {
                extend: 'colvis',
                text: '<i title="column visibility" class="fa fa-eye"></i>',
                columns: ':gt(0)'
            },
        ],
    } );

  $.ajaxSetup({
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        }
    });

  if(all_permission.indexOf("customers-delete") == -1)
        $('.buttons-delete').addClass('d-none');
</script>
<?php $__env->stopPush(); ?>

<?php echo $__env->make('backend.layout.main', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH C:\Users\MHNazary\Pictures\sellbox\resources\views\backend\customer\index.blade.php ENDPATH**/ ?>