

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

<?php $__env->startSection('content'); ?>
<?php if(session('success')): ?><div class="alert alert-success"><?php echo e(session('success')); ?></div><?php endif; ?>
<?php if($errors->any()): ?><div class="alert alert-danger"><?php echo e(print_r($errors->all(), true)); ?></div><?php endif; ?>


<div class="card">
    <div class="card-header">
        <h3 class="card-title">Manufacturing BOMs</h3>
        <div class="card-tools">
            <a href="<?php echo e(route('manufacturing.boms.create')); ?>" class="btn btn-primary btn-sm">
                <i class="fas fa-plus"></i> Create BOM
            </a>
        </div>
    </div>
    <div class="card-body">
        <div class="table-responsive">
            <table id="boms-table" class="table table-bordered table-striped">
                <thead>
                    <tr>
                        <th>ID</th>
                        <th>Name</th>
                        <th>Version</th>
                        <th>Finished Goods</th>
                        <th>Basic Unit</th>
                        <!-- <th>Steps</th> -->
                        <th>Ingredients</th>
                        <th>Status</th>
                        <th>Created By</th>
                        <th>Created At</th>
                        <th>Actions</th>
                    </tr>
                </thead>
            </table>
        </div>
    </div>
</div>
<?php $__env->stopSection(); ?>

<?php $__env->startPush('plugin-scripts'); ?>
<script>
$(document).ready(function() {
    $('#boms-table').DataTable({
        processing: true,
        serverSide: true,
        ajax: {
            url: "<?php echo e(route('manufacturing.boms.index')); ?>",
            type: 'GET'
        },
        columns: [
            { data: 'id', name: 'id' },
            { data: 'name', name: 'name' },
            { data: 'version', name: 'version' },
            { data: 'finished_goods', name: 'finished_goods', searchable: false },
            { data: 'basic_unit_info', name: 'basic_unit_info', searchable: false },
            // { data: 'total_steps', name: 'total_steps', searchable: false },
            { data: 'total_ingredients', name: 'total_ingredients', searchable: false },
            { data: 'status_badge', name: 'is_active', 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);

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

        // Extract and format time
        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}`;

        // Final format: DD-MM-YYYY hh:mm A
        return `${day}-${month}-${year} ${formattedTime}`;
    }
},

            { data: 'actions', name: 'actions', orderable: false, searchable: false }
        ],
        order: [[0, 'desc']],
        pageLength: 25,
        responsive: true,
        language: {
            processing: "Loading BOMs..."
        }
    });
});
</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/boms/index.blade.php ENDPATH**/ ?>