<?php
require_once('includes/load.php');
page_require_level(3); // Hanya user dengan level 3+ yang bisa mengakses

if(isset($_GET['picking_no'])) {
    $picking_no = $db->escape($_GET['picking_no']);
    
    $components = $db->query("
        SELECT 
            mf.component,
            p.new_code,
            p.name as component_name,
            p.uom,
            mf.quantity_needed,
            mf.picking_no
        FROM material_forecasts mf
        LEFT JOIN products p ON mf.component = p.part_number
        WHERE mf.picking_no = '{$picking_no}'
        ORDER BY p.name
    ");
    
    if($db->num_rows($components) > 0) {
        while($comp = $db->fetch_assoc($components)) {
            echo '<tr>';
            echo '<td>'.htmlspecialchars($comp['component']).'</td>';
            echo '<td>'.htmlspecialchars($comp['new_code']).'</td>';
            echo '<td>'.htmlspecialchars($comp['component_name']).'</td>';
            echo '<td class="text-center">'.htmlspecialchars($comp['uom']).'</td>';
            echo '<td class="text-right">'.number_format($comp['quantity_needed'], 2).'</td>';
            echo '</tr>';
        }
    } else {
        echo '<tr><td colspan="5" class="text-center">Tidak ada data komponen</td></tr>';
    }
} else {
    echo '<tr><td colspan="5" class="text-center text-danger">Picking number tidak valid</td></tr>';
}
?>