-- ============================================================
-- SEED DATA: Production Sourcing (Make/Buy) + Confirmations
-- Covers all 3 production orders so /manufacturing/sourcing
-- and /manufacturing/confirmations show data for every PO.
-- ============================================================

-- ============================================================
-- 1. PRODUCTION SOURCING
-- ============================================================

-- PROD-1 (COMPLETED — mostly make, one buy)
INSERT INTO production_sourcing
(company_id, production_order_id, operation_name, operation_type, execution_mode, contractor_id, award_id, allocation_pct, planned_qty, produced_qty, status, fg_warehouse_id, rate, total_cost) VALUES
(1, 1, 'Front Panel Cut',   'cutting',   'internal', NULL, NULL, 100.00, 4000, 4000, 'completed', NULL, 0.15, 600.00),
(1, 1, 'Back Panel Cut',    'cutting',   'internal', NULL, NULL, 100.00, 4000, 4000, 'completed', NULL, 0.15, 600.00),
(1, 1, 'Shoulder Seam',     'sewing',    'internal', NULL, NULL, 100.00, 4000, 4000, 'completed', NULL, 0.12, 480.00),
(1, 1, 'Label Attach',      'sewing',    'internal', NULL, NULL, 100.00, 4000, 4000, 'completed', NULL, 0.10, 400.00),
(1, 1, 'Trim & Thread Cut', 'finishing', 'external', 5,    NULL, 100.00, 4000, 4000, 'completed', 10,   0.08, 320.00),
(1, 1, 'Fold & Polybag',    'packing',   'internal', NULL, NULL, 100.00, 4000, 4000, 'completed', NULL, 0.10, 400.00);

-- PROD-2 (IN PROGRESS — sewing split across make + 2 contractors, external wash)
INSERT INTO production_sourcing
(company_id, production_order_id, operation_name, operation_type, execution_mode, contractor_id, award_id, allocation_pct, planned_qty, produced_qty, status, fg_warehouse_id, rate, total_cost) VALUES
(1, 2, 'Front Panel Cut', 'cutting',   'internal', NULL, NULL, 100.00, 4000, 4000, 'completed',   NULL, 0.15, 600.00),
(1, 2, 'Shoulder Seam',   'sewing',    'internal', NULL, NULL,  40.00, 1600, 1600, 'in_progress', NULL, 0.12, 192.00),
(1, 2, 'Shoulder Seam',   'sewing',    'external', 1,    NULL,  35.00, 1400,  900, 'in_progress', 6,    0.14, 196.00),
(1, 2, 'Shoulder Seam',   'sewing',    'external', 3,    NULL,  25.00, 1000,  400, 'in_progress', 8,    0.15, 150.00),
(1, 2, 'Side Seam',       'sewing',    'external', 1,    NULL, 100.00, 4000, 1500, 'in_progress', 6,    0.13, 520.00),
(1, 2, 'Garment Wash',    'washing',   'external', 4,    NULL, 100.00, 4000,  800, 'in_progress', 9,    0.20, 800.00),
(1, 2, 'Fold & Polybag',  'packing',   'internal', NULL, NULL, 100.00, 4000, 1200, 'in_progress', NULL, 0.10, 400.00);

-- PROD-3 (IN PROGRESS — early stage, some buy decisions pending)
INSERT INTO production_sourcing
(company_id, production_order_id, operation_name, operation_type, execution_mode, contractor_id, award_id, allocation_pct, planned_qty, produced_qty, status, fg_warehouse_id, rate, total_cost) VALUES
(1, 3, 'Front Panel Cut', 'cutting',   'internal', NULL, NULL, 100.00, 4000, 4000, 'completed',   NULL, 0.15, 600.00),
(1, 3, 'Sleeve Cut',      'cutting',   'internal', NULL, NULL, 100.00, 4000, 2500, 'in_progress', NULL, 0.13, 520.00),
(1, 3, 'Shoulder Seam',   'sewing',    'external', 2,    NULL, 100.00, 4000,    0, 'planned',     7,    0.14, 560.00),
(1, 3, 'Hem Bottom',      'sewing',    'external', 3,    NULL, 100.00, 4000,    0, 'planned',     8,    0.12, 480.00);

-- ============================================================
-- 2. PRODUCTION CONFIRMATIONS
-- (yield_pct is a STORED GENERATED column — do not insert)
-- ============================================================

-- PROD-1 (COMPLETED)
INSERT INTO production_confirmations
(company_id, production_order_id, process_order_id, operation_id, bundle_id, confirmation_type, input_qty, output_qty, rejected_qty, rework_qty, scrap_qty, confirmed_by, confirmed_at, notes) VALUES
(1, 1, NULL,  1,  NULL, 'operation', 4000, 3990,  8, 2, 0, 3, '2026-07-16 08:30:00', 'Front panel cutting completed'),
(1, 1, NULL,  4,  NULL, 'operation', 3990, 3980,  6, 3, 1, 4, '2026-07-18 14:00:00', 'Shoulder seam batch'),
(1, 1, NULL,  8,  NULL, 'operation', 3980, 3970,  7, 2, 1, 5, '2026-07-22 16:30:00', 'Hem bottom output'),
(1, 1, NULL, 12,  NULL, 'operation', 3970, 3955, 10, 4, 1, 3, '2026-07-25 10:00:00', 'Inline quality check'),
(1, 1,    1,  13,  NULL, 'final',     3955, 3950,  5, 0, 0, 4, '2026-07-30 17:00:00', 'Final QC passed, ready for shipment');

-- PROD-2 (IN PROGRESS — 3 existing rows kept, adding more coverage)
INSERT INTO production_confirmations
(company_id, production_order_id, process_order_id, operation_id, bundle_id, confirmation_type, input_qty, output_qty, rejected_qty, rework_qty, scrap_qty, confirmed_by, confirmed_at, notes) VALUES
(1, 2, NULL, 14, NULL, 'operation', 4000, 3995,  5, 0, 0, 3, '2026-07-21 08:00:00', 'Cutting batch done'),
(1, 2, NULL, 16, NULL, 'operation', 3995, 3980, 10, 3, 2, 5, '2026-07-23 09:15:00', 'Sleeve cut batch'),
(1, 2, NULL, 20, NULL, 'operation', 3980, 3960, 15, 4, 1, 4, '2026-07-28 11:00:00', 'Side seam mid-line'),
(1, 2,    3, NULL, NULL, 'process',  4000, 3800, 25, 10, 5, 6, '2026-07-30 13:20:00', 'Dyeing process confirmation'),
(1, 2, NULL, 22, NULL, 'operation', 3960, 3500, 12, 3, 1, 3, '2026-07-31 10:30:00', 'Hem bottom output');

-- PROD-3 (IN PROGRESS — early stage)
INSERT INTO production_confirmations
(company_id, production_order_id, process_order_id, operation_id, bundle_id, confirmation_type, input_qty, output_qty, rejected_qty, rework_qty, scrap_qty, confirmed_by, confirmed_at, notes) VALUES
(1, 3, NULL, 27, NULL, 'operation', 4000, 3990, 6, 2, 2, 3, '2026-08-01 08:15:00', 'Front panel cutting'),
(1, 3, NULL, 28, NULL, 'operation', 3990, 3980, 8, 1, 1, 4, '2026-08-01 10:00:00', 'Back panel cutting'),
(1, 3, NULL, 29, NULL, 'operation', 3980, 2500, 9, 3, 1, 5, '2026-08-02 09:45:00', 'Sleeve cut in progress');
