

<?php $__env->startSection('content'); ?>

    <div class="info-section">
        <h4>Manufacturing Run Information</h4>
        <div class="info-grid">
            <div>
                <div class="info-item">
                    <span class="info-label">M-Number:</span>
                    <?php echo e($run->m_number); ?>

                </div>
                <div class="info-item">
                    <span class="info-label">Status:</span>
                    <?php echo e(ucfirst(str_replace('_', ' ', $run->status))); ?>

                </div>
                <div class="info-item">
                    <span class="info-label">Planned Output:</span>
                    <?php echo e(number_format($run->planned_output_qty, 4)); ?> units
                </div>
                <?php if($run->actual_output_qty > 0): ?>
                <div class="info-item">
                    <span class="info-label">Actual Output:</span>
                    <?php echo e(number_format($run->actual_output_qty, 4)); ?> units
                </div>
                <?php endif; ?>
                <div class="info-item">
                    <span class="info-label">Scaling Factor:</span>
                    <?php echo e(number_format($run->scaling_factor, 6)); ?>

                </div>
            </div>
            <div>
                <div class="info-item">
                    <span class="info-label">Created:</span>
                    <?php echo e($run->created_at->format('M d, Y H:i:s')); ?>

                </div>
                <div class="info-item">
                    <span class="info-label">Created By:</span>
                    <?php echo e($run->creator ? $run->creator->name : 'N/A'); ?>

                </div>
                <?php if($run->due_date): ?>
                <div class="info-item">
                    <span class="info-label">Due Date:</span>
                    <?php echo e($run->due_date->format('M d, Y')); ?>

                </div>
                <?php endif; ?>
                <?php if($run->warehouse): ?>
                <div class="info-item">
                    <span class="info-label">Warehouse:</span>
                    <?php echo e($run->warehouse->name); ?>

                </div>
                <?php endif; ?>
            </div>
        </div>
    </div>

    <?php if($run->manufacturingBom): ?>
    <div class="info-section">
        <h4>BOM Information</h4>
        <div class="info-grid">
            <div>
                <div class="info-item">
                    <span class="info-label">BOM Name:</span>
                    <?php echo e($run->manufacturingBom->name); ?>

                </div>
                <div class="info-item">
                    <span class="info-label">Version:</span>
                    <?php echo e($run->manufacturingBom->version); ?>

                </div>
            </div>
            <div>
                <div class="info-item">
                    <span class="info-label">Finished Goods:</span>
                    <?php echo e($run->manufacturingBom->finishedGoods ? $run->manufacturingBom->finishedGoods->name : 'N/A'); ?>

                </div>
                <div class="info-item">
                    <span class="info-label">Basic Unit:</span>
                    <?php echo e($run->manufacturingBom->formatted_basic_unit); ?>

                </div>
            </div>
        </div>
    </div>
    <?php endif; ?>

    <?php if($run->bomHistory && $run->bomHistory->ingredients->count() > 0): ?>
    <div class="info-section">
        <h4>Required Ingredients</h4>
        <table class="table">
            <thead>
                <tr>
                    <th style="width: 5%;">#</th>
                    <th style="width: 25%;">Ingredient</th>
                    <th style="width: 15%;">SKU</th>
                    <th style="width: 10%;">Base Qty</th>
                    <th style="width: 8%;">Unit</th>
                    <th style="width: 10%;">Wastage</th>
                    <th style="width: 12%;">Required Qty</th>
                    <th style="width: 10%;">WAP</th>
                    <th style="width: 5%;">✓</th>
                </tr>
            </thead>
            <tbody>
                <?php $__currentLoopData = $run->bomHistory->ingredients; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $index => $ingredient): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <tr>
                    <td><?php echo e($index + 1); ?></td>
                    <td><?php echo e($ingredient->ingredient_name); ?></td>
                    <td><?php echo e($ingredient->ingredient_sku); ?></td>
                    <td style="text-align: right;"><?php echo e(number_format($ingredient->quantity_required, 4)); ?></td>
                    <td><?php echo e($ingredient->unit); ?></td>
                    <td style="text-align: right;"><?php echo e($ingredient->formatted_wastage); ?></td>
                    <td style="text-align: right; font-weight: bold;"><?php echo e(number_format($ingredient->required_qty, 4)); ?></td>
                    <td style="text-align: right;"><?php echo e(number_format($ingredient->current_wap, 4)); ?></td>
                    <td style="text-align: center;">□</td>
                </tr>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </tbody>
        </table>
    </div>
    <?php endif; ?>

    <?php if($run->stockLedgers && $run->stockLedgers->count() > 0): ?>
    <div class="info-section">
        <h4>Finished Goods Produced</h4>
        <table class="table">
            <thead>
                <tr>
                    <th style="width: 25%;">Item</th>
                    <th style="width: 15%;">Warehouse</th>
                    <th style="width: 15%; text-align: right;">Length</th>
                    <th style="width: 15%; text-align: right;">Qty (Pcs)</th>
                    <th style="width: 20%; text-align: right;">Total</th>
                    <th style="width: 10%;">Unit</th>
                </tr>
            </thead>
            <tbody>
                <?php $__currentLoopData = $run->stockLedgers; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $entry): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <tr>
                    <td><?php echo e($entry->item->name ?? 'N/A'); ?></td>
                    <td><?php echo e($entry->warehouse->name ?? 'N/A'); ?></td>
                    <td style="text-align: right;"><?php echo e($entry->length > 0 ? number_format($entry->length, 4) : '-'); ?></td>
                    <td style="text-align: right;"><?php echo e($entry->piece_quantity > 0 ? $entry->piece_quantity : '-'); ?></td>
                    <td><strong><?php echo e(number_format($entry->length * $entry->piece_quantity, 4)); ?></strong></td>
                    <td><?php echo e($run->unit_of_measurement); ?></td>
                </tr>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </tbody>
            <tfoot>
                <tr>
                    <td colspan="4" style="text-align: right; font-weight: bold;">Total Production:</td>
                    <td style="text-align: right; font-weight: bold;"><?php echo e(number_format($run->stockLedgers->sum('length') * $run->stockLedgers->sum('piece_quantity'), 4)); ?></td>
                    <td style="font-weight: bold;"><?php echo e($run->unit_of_measurement); ?></td>
                </tr>
            </tfoot>
        </table>
    </div>
    <?php endif; ?>

    <?php if($run->scrapBreakdowns && $run->scrapBreakdowns->count() > 0): ?>
    <div class="info-section">
        <h4>Scrap Breakdown</h4>
        <table class="table">
            <thead>
                <tr>
                    <th style="width: 30%;">Ingredient</th>
                    <th style="width: 15%; text-align: right;">Expected Qty</th>
                    <th style="width: 15%; text-align: right;">Actual Qty</th>
                    <th style="width: 15%; text-align: right;">Scrap Qty</th>
                    <th style="width: 15%; text-align: right;">Scrap %</th>
                    <th style="width: 10%;">Unit</th>
                </tr>
            </thead>
            <tbody>
                <?php $__currentLoopData = $run->scrapBreakdowns; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $scrap): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <tr>
                    <td><?php echo e($scrap->ingredientAccount ? $scrap->ingredientAccount->name : 'N/A'); ?></td>
                    <td style="text-align: right;"><?php echo e(number_format($scrap->expected_qty, 4)); ?></td>
                    <td style="text-align: right;"><?php echo e(number_format($scrap->actual_qty, 4)); ?></td>
                    <td style="text-align: right;"><?php echo e(number_format($scrap->scrap_qty, 4)); ?></td>
                    <td style="text-align: right;"><?php echo e(number_format($scrap->scrap_percentage, 2)); ?>%</td>
                    <td><?php echo e($scrap->unit ?? ($scrap->ingredientAccount && $scrap->ingredientAccount->uom ? $scrap->ingredientAccount->uom->name : 'N/A')); ?></td>
                </tr>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </tbody>
        </table>
    </div>
    <?php endif; ?>

    <?php if($run->notes): ?>
    <div class="info-section">
        <h4>Notes</h4>
        <p><?php echo e($run->notes); ?></p>
    </div>
    <?php endif; ?>

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

<?php echo $__env->make('manufacturing.pdfs.master', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\laragon\www\habibcables-ERP\resources\views\manufacturing\pdfs\pick-list.blade.php ENDPATH**/ ?>