

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

<?php $__env->startPush('plugin-styles'); ?>
<link href="<?php echo e(asset('theme/vendors/datatables.net-bs5/dataTables.bootstrap5.css')); ?>" rel="stylesheet">
<?php $__env->stopPush(); ?>

<?php $__env->startPush('plugin-scripts'); ?>
<script src="<?php echo e(asset('theme/vendors/datatables.net/jquery.dataTables.js')); ?>"></script>
<script src="<?php echo e(asset('theme/vendors/datatables.net-bs5/dataTables.bootstrap5.js')); ?>"></script>
<?php $__env->stopPush(); ?>

<?php $__env->startSection('content'); ?>
<?php if(session('success')): ?>
    <div class="alert alert-success alert-dismissible fade show" role="alert">
        <i class="fas fa-check-circle me-2"></i><?php echo e(session('success')); ?>

        <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
    </div>
<?php endif; ?>

<div class="container-fluid">
    <div class="row">
        <div class="col-12">
            <div class="card">
                <div class="card-header">
                    <h3 class="card-title">Manufacturing Runs</h3>
                    <div class="card-tools">
                        <a href="<?php echo e(route('manufacturing.start')); ?>" class="btn btn-primary btn-sm">
                            <i class="fas fa-plus"></i> Start New Run
                        </a>
                    </div>
                </div>
                <div class="card-body">
                    <div class="table-responsive">
                        <table id="runs-table" class="table table-bordered table-striped">
                            <thead>
                                <tr>
                                    <th>M-Number</th>
                                    <th>BOM Name</th>
                                    <th>Finished Goods</th>
                                    <th>Planned Qty</th>
                                    <th>Scaling Factor</th>
                                    <th>Machine</th>
                                    <th>Supervisor</th>
                                    <!-- <th>Warehouse</th> -->
                                    <th>Status</th>
                                    <th>Created By</th>
                                    <th>Created At</th>
                                    <th>Actions</th>
                                </tr>
                            </thead>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<?php $__env->stopSection(); ?>

<?php $__env->startPush('scripts'); ?>
<script>
$(document).ready(function() {
    const urlParams = new URLSearchParams(window.location.search);
    const statusFilter = urlParams.get('status') || '';

    $('#runs-table').DataTable({
        processing: true,
        serverSide: true,
        ajax: {
            url: "<?php echo e(route('manufacturing.runs.index')); ?>",
            type: 'GET',
            data: function(d) {
                d.status = statusFilter; 
            }
        },
        
        columns: [
            { data: 'm_number', name: 'm_number' },
            { data: 'bom_name', name: 'bom_name' },
            { data: 'finished_goods', name: 'finished_goods' },
            { data: 'planned_output_qty', name: 'planned_output_qty' },
            { data: 'scaling_factor', name: 'scaling_factor' },
            { data: 'machine_name', name: 'machine_name' },
            { data: 'supervisor_name', name: 'supervisor_name' },
            { data: 'status_badge', name: 'status' },
            { data: 'creator_name', name: 'creator_name' },
            { data: 'created_at', name: 'created_at' },
            { data: 'actions', orderable: false, searchable: false }
        ],


        // columns: [
        //     { data: 'm_number', name: 'm_number' },
        //     { data: 'bom_name', name: 'bom_name', searchable: false },
        //     { data: 'finished_goods', name: 'finished_goods', searchable: false },
        //     { data: 'planned_output_qty', name: 'planned_output_qty' },
        //     { data: 'scaling_factor', name: 'scaling_factor' },
        //     { data: 'machine_name', name: 'machine_name', searchable: false },
        //     { data: 'supervisor_name', name: 'supervisor_name', searchable: false },
        //     // { data: 'warehouse_name', name: 'warehouse_name', searchable: false },
        //     { data: 'status_badge', name: 'status', searchable: false },
        //     { data: 'creator_name', name: 'creator_name', searchable: false },
        //     {
        //     data: 'created_at',
        //     name: 'created_at',
        //     render: function (data, type, row) {
        //         if (!data) return '';

        //         const date = new Date(data);

        //         const day = String(date.getDate()).padStart(2, '0');
        //         const month = String(date.getMonth() + 1).padStart(2, '0');
        //         const year = date.getFullYear();

        //         let hours = date.getHours();
        //         const minutes = String(date.getMinutes()).padStart(2, '0');
        //         const ampm = hours >= 12 ? 'PM' : 'AM';
        //         hours = hours % 12;
        //         hours = hours ? hours : 12; // convert 0 to 12
        //         const formattedTime = `${String(hours).padStart(2, '0')}:${minutes} ${ampm}`;

        //         return `${day}-${month}-${year} ${formattedTime}`;
        //     }
        // },
        //     { data: 'actions', name: 'actions', orderable: false, searchable: false }
        // ],
        order: [[0, 'desc']],
        pageLength: 25,
        responsive: true,
        language: {
            processing: "Loading manufacturing runs..."
        }
    });
});
</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/manufacturing/runs/index.blade.php ENDPATH**/ ?>