

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

<?php $__env->startSection('content'); ?>
<div class="container-fluid">
    <div class="row">
        <div class="col-12">
            <div class="card">
                <div class="card-header d-flex justify-content-between align-items-center">
                    <h5 class="mb-0"><i class="fas fa-receipt"></i> Delivery Receipts</h5>
                    <a href="<?php echo e(route('delivery-receipts.create')); ?>" class="btn btn-primary">
                        <i class="fas fa-plus"></i> New Receipt
                    </a>
                </div>
                <div class="card-body">
                    <!-- Filters -->
                    <div class="row mb-3">
                        <div class="col-md-3">
                            <label class="form-label">Status</label>
                            <select class="form-select" id="statusFilter">
                                <option value="all">All Status</option>
                                <option value="draft">Draft</option>
                                <option value="submitted">Submitted</option>
                                <option value="processed">Processed</option>
                            </select>
                        </div>
                        <div class="col-md-3">
                            <label class="form-label">Invoice</label>
                            <select class="form-select" id="invoiceFilter">
                                <option value="">All Invoices</option>
                                <!-- Invoice options will be loaded dynamically -->
                            </select>
                        </div>
                        <div class="col-md-2">
                            <label class="form-label">From Date</label>
                            <input type="date" class="form-control" id="dateFromFilter">
                        </div>
                        <div class="col-md-2">
                            <label class="form-label">To Date</label>
                            <input type="date" class="form-control" id="dateToFilter">
                        </div>
                        <div class="col-md-2 d-flex align-items-end">
                            <button type="button" class="btn btn-outline-secondary w-100" onclick="clearFilters()">
                                <i class="fas fa-times"></i> Clear
                            </button>
                        </div>
                    </div>

                    <!-- DataTable -->
                    <div class="table-responsive">
                        <table class="table table-striped table-hover" id="receiptsTable">
                            <thead class="table-light">
                                <tr>
                                    <th>Receipt #</th>
                                    <th>Invoice</th>
                                    <th>Customer</th>
                                    <th>Delivery Man</th>
                                    <th>Delivery Date</th>
                                    <th>Status</th>
                                    <th>Actions</th>
                                </tr>
                            </thead>
                            <tbody></tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<?php $__env->stopSection(); ?>

<?php $__env->startPush('scripts'); ?>
<script>
$(document).ready(function() {
    // Initialize DataTable
    const table = $('#receiptsTable').DataTable({
        processing: true,
        serverSide: true,
        ajax: {
            url: '<?php echo e(route("delivery-receipts.data")); ?>',
            data: function(d) {
                d.status = $('#statusFilter').val();
                d.invoice_id = $('#invoiceFilter').val();
                d.date_from = $('#dateFromFilter').val();
                d.date_to = $('#dateToFilter').val();
            }
        },
        columns: [
            {
                data: 'id',
                render: function(data) {
                    return 'DR-' + String(data).padStart(4, '0');
                }
            },
            { data: 'invoice_number', orderable: false },
            { data: 'customer_name', orderable: false },
            { data: 'delivery_man', orderable: false },
            {
                data: 'delivery_date',
                render: function(data) {
                    return new Date(data).toLocaleDateString();
                }
            },
            { data: 'status_badge', orderable: false },
            { data: 'actions', orderable: false }
        ],
        order: [[4, 'desc']], // Sort by delivery date descending
        pageLength: 25,
        responsive: true
    });

    // Filter change handlers
    $('#statusFilter, #invoiceFilter, #dateFromFilter, #dateToFilter').on('change', function() {
        table.ajax.reload();
    });
});

function clearFilters() {
    $('#statusFilter').val('all');
    $('#invoiceFilter').val('');
    $('#dateFromFilter').val('');
    $('#dateToFilter').val('');
    $('#receiptsTable').DataTable().ajax.reload();
}
</script>
<?php $__env->stopPush(); ?>

<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\laragon\www\habibcables-ERP\resources\views\delivery-receipts_backup\index.blade.php ENDPATH**/ ?>