

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

<?php $__env->startSection('content'); ?>
<div class="container-fluid">
    <div class="row">
        <div class="col-12">
            <div class="card">
                <div class="card-header">
                    <h3 class="card-title"><?php echo e($manufacturingBom->name); ?> - Version <?php echo e($manufacturingBom->version); ?></h3>
                    <div class="card-tools">
                        <a href="<?php echo e(route('manufacturing.boms.edit', $manufacturingBom->id)); ?>" class="btn btn-warning btn-sm">
                            <i class="fas fa-edit"></i> Edit
                        </a>
                        <a href="<?php echo e(route('manufacturing.boms.index')); ?>" class="btn btn-secondary btn-sm">
                            <i class="fas fa-arrow-left"></i> Back to BOMs
                        </a>
                    </div>
                </div>
                <div class="card-body">
                    <!-- BOM Information -->
                    <div class="row mb-4">
                        <div class="col-md-6">
                            <h5>BOM Information</h5>
                            <table class="table table-sm">
                                <tr>
                                    <td><strong>Name:</strong></td>
                                    <td><?php echo e($manufacturingBom->name); ?></td>
                                </tr>
                                <tr>
                                    <td><strong>Version:</strong></td>
                                    <td><?php echo e($manufacturingBom->version); ?></td>
                                </tr>
                                <tr>
                                    <td><strong>Status:</strong></td>
                                    <td>
                                        <?php if($manufacturingBom->is_active): ?>
                                        <span class="badge badge-success">Active</span>
                                        <?php else: ?>
                                        <span class="badge badge-secondary">Inactive</span>
                                        <?php endif; ?>
                                    </td>
                                </tr>
                                <tr>
                                    <td><strong>Created By:</strong></td>
                                    <td><?php echo e($manufacturingBom->creator ? $manufacturingBom->creator->name : 'N/A'); ?></td>
                                </tr>
                                <tr>
                                    <td><strong>Created At:</strong></td>
                                    <td><?php echo e($manufacturingBom->created_at->format('d-m-Y h:i A')); ?></td>
                                </tr>
                            </table>
                        </div>
                        <div class="col-md-6">
                            <h5>Finished Goods</h5>
                            <table class="table table-sm">
                                <tr>
                                    <td><strong>Product:</strong></td>
                                    <td><?php echo e($manufacturingBom->finishedGoods ? $manufacturingBom->finishedGoods->name : 'N/A'); ?></td>
                                </tr>
                                <tr>
                                    <td><strong>SKU:</strong></td>
                                    <td><?php echo e($manufacturingBom->finishedGoods ? $manufacturingBom->finishedGoods->sku : 'N/A'); ?></td>
                                </tr>
                                <?php
                                $unit = $manufacturingBom->finishedGoods && $manufacturingBom->finishedGoods->uom
                                ? $manufacturingBom->finishedGoods->uom->name
                                : ($manufacturingBom->basic_unit ?? 'N/A');
                                ?>

                                <tr>
                                    <td><strong>Basic Unit Amount:</strong></td>
                                    <td>
                                        <?php echo e(number_format($manufacturingBom->basic_unit_amount, 2)); ?>

                                        <?php echo e($unit); ?>

                                    </td>
                                </tr>


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

                    <div class="row mb-4">
                        <div class="col-12">
                            <h5>Description</h5>
                            <p><?php echo e($manufacturingBom->description ?: 'No description provided.'); ?></p>
                        </div>
                    </div>

                    <!-- Steps Section -->
                    <?php if($manufacturingBom->steps->count() > 0): ?>
                    <div class="row mb-4">
                        <div class="col-12">
                            <h5>Manufacturing Steps</h5>
                            <div class="accordion" id="stepsAccordion">
                                <?php $__currentLoopData = $manufacturingBom->steps; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $index => $step): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <div class="card">
                                    <div class="card-header" id="heading<?php echo e($step->id); ?>">
                                        <h6 class="mb-0">
                                            <button class="btn btn-link" type="button" data-toggle="collapse"
                                                data-target="#collapse<?php echo e($step->id); ?>" aria-expanded="<?php echo e($index === 0 ? 'true' : 'false'); ?>"
                                                aria-controls="collapse<?php echo e($step->id); ?>">
                                                Step <?php echo e($step->sequence_order); ?>: <?php echo e($step->step_name); ?>

                                                <span class="badge badge-info ml-2"><?php echo e($step->ingredients->count()); ?> ingredients</span>
                                            </button>
                                        </h6>
                                    </div>
                                    <div id="collapse<?php echo e($step->id); ?>" class="collapse <?php echo e($index === 0 ? 'show' : ''); ?>"
                                        aria-labelledby="heading<?php echo e($step->id); ?>" data-parent="#stepsAccordion">
                                        <div class="card-body">
                                            <p><strong>Instruction:</strong> <?php echo e($step->instruction ?: 'No instruction provided.'); ?></p>

                                            <?php if($step->ingredients->count() > 0): ?>
                                            <h6>Step Ingredients:</h6>
                                            <div class="table-responsive">
                                                <table class="table table-sm table-bordered">
                                                    <thead>
                                                        <tr>
                                                            <th>Ingredient</th>
                                                            <th>SKU</th>
                                                            <th>Quantity Required</th>
                                                            <th>Unit</th>
                                                            <th>Wastage</th>
                                                            <th>Effective Quantity</th>
                                                        </tr>
                                                    </thead>
                                                    <tbody>
                                                        <?php $__currentLoopData = $step->ingredients; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $ing): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                        <tr>
                                                            <td><?php echo e($ing->ingredient->name); ?></td>
                                                            <td><?php echo e($ing->ingredient->sku); ?></td>
                                                            <td><?php echo e($ing->formatted_quantity); ?></td>
                                                            <!-- <td><?php echo e($ing->unit); ?></td> -->
                                                             <td>
    <?php echo e(optional($ing->ingredient->uom)->name ?? ($ing->unit ?? 'N/A')); ?>

</td>

                                                            <!-- <td>
                                                                <?php echo e($ing->ingredient && $ing->ingredient->uom
                                                                  ? $ing->ingredient->uom->name
                                                                 : ($ing->unit ?? 'N/A')); ?>

                                                            </td> -->

                                                            <td><?php echo e($ing->formatted_wastage); ?></td>
                                                            <td><?php echo e(number_format($ing->effective_quantity, 4)); ?></td>
                                                        </tr>
                                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                    </tbody>
                                                </table>
                                            </div>
                                            <?php else: ?>
                                            <p class="text-muted">No ingredients assigned to this step.</p>
                                            <?php endif; ?>
                                        </div>
                                    </div>
                                </div>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </div>
                        </div>
                    </div>
                    <?php endif; ?>

                    <!-- Direct Ingredients Section -->
                    <?php if($manufacturingBom->ingredients()->directIngredients()->count() > 0): ?>
                    <div class="row mb-4">
                        <div class="col-12">
                            <h5>Direct Ingredients (Not assigned to steps)</h5>
                            <div class="table-responsive">
                                <table class="table table-bordered">
                                    <thead>
                                        <tr>
                                            <th>Ingredient</th>
                                            <th>SKU</th>
                                            <th>Quantity Required</th>
                                            <th>Unit</th>
                                            <th>Wastage</th>
                                            <th>Effective Quantity</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php $__currentLoopData = $manufacturingBom->ingredients()->directIngredients()->with('ingredient')->get(); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $ingredient): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <tr>
                                            <td><?php echo e($ingredient->ingredient->name); ?></td>
                                            <td><?php echo e($ingredient->ingredient->sku); ?></td>
                                            <td><?php echo e($ingredient->formatted_quantity); ?></td>
                                            <td><?php echo e(optional($ingredient->ingredient->uom)->name ?? ($ing->unit ?? 'N/A')); ?></td>
                                            <td><?php echo e($ingredient->formatted_wastage); ?></td>
                                            <td><?php echo e(number_format($ingredient->effective_quantity, 4)); ?></td>
                                        </tr>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                    <?php endif; ?>

                    <!-- Summary -->
                    <div class="row">
                        <div class="col-12">
                            <h5>BOM Summary</h5>
                            <div class="row">
                                <div class="col-md-3">
                                    <div class="info-box">
                                        <span class="info-box-icon bg-info"><i class="fas fa-list"></i></span>
                                        <div class="info-box-content">
                                            <span class="info-box-text">Total Steps</span>
                                            <span class="info-box-number"><?php echo e($manufacturingBom->steps->count()); ?></span>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-md-3">
                                    <div class="info-box">
                                        <span class="info-box-icon bg-success"><i class="fas fa-box"></i></span>
                                        <div class="info-box-content">
                                            <span class="info-box-text">Total Ingredients</span>
                                            <span class="info-box-number"><?php echo e($manufacturingBom->ingredients->count()); ?></span>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-md-3">
                                    <div class="info-box">
                                        <span class="info-box-icon bg-warning"><i class="fas fa-layer-group"></i></span>
                                        <div class="info-box-content">
                                            <span class="info-box-text">Direct Ingredients</span>
                                            <span class="info-box-number"><?php echo e($manufacturingBom->ingredients()->directIngredients()->count()); ?></span>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-md-3">
                                    <div class="info-box">
                                        <span class="info-box-icon bg-primary"><i class="fas fa-cube"></i></span>
                                        <div class="info-box-content">
                                            <span class="info-box-text">Unique Ingredients</span>
                                            <span class="info-box-number"><?php echo e($manufacturingBom->ingredients()->distinct('ingredient_account_id')->count()); ?></span>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<?php $__env->stopSection(); ?>

<?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\show.blade.php ENDPATH**/ ?>