-- Seed data: two invoices for the same agent and month (Cut 1 and
-- Cut 2), so the new /invoices UI has real rows to render. Cut 2 folds
-- in a QPI line item alongside its normal hours/perks, since QPI is
-- never its own invoice. Not test fixtures for automated tests -- just
-- realistic sample data for manual review.

insert into invoices (
  id, invoice_number, agent_id, month, cut_number, weeks,
  items, subtotal, tax, total,
  rate_snapshot, usd_php_rate, hourly_rate_usd,
  profile_snapshot, bill_to,
  status, submitted_at, approved_at, approved_by,
  created_at, created_by
) values (
  'inv_agent_042_2026-06_c1',
  'EC-INV-2026-23',
  'agent_042',
  '2026-06',
  1,
  '["2026-W23"]'::jsonb,
  '[
    {"type": "hours", "label": "Billable Hours : Week 23 (June 1-7, 2026)", "quantity": 40, "amount": 12000.00, "meta": {"weekKey": "2026-W23", "rate": 300.00}},
    {"type": "nsd", "label": "Night Differential (10% on 16 hrs)", "quantity": 16, "amount": 480.00, "meta": {"rate": 30.00}},
    {"type": "perk", "label": "Internet Allowance", "quantity": 1, "amount": 1200.00, "meta": {}}
  ]'::jsonb,
  13680.00,
  0,
  13680.00,
  '{"usd": 6.00, "php": 348.00, "rate": 58.00, "rateFromLog": false, "cutoffRateLabel": null, "creditDaysUsed": 0}'::jsonb,
  58.00,
  6.00,
  '{
    "fullName": "Maria Santos",
    "email": "maria.santos@example.com",
    "address": "123 Rizal St, Quezon City, Philippines",
    "bank": {"name": "BDO", "address": "Manila, Philippines", "accountNumber": "001234567890", "swift": "BNORPHMM"}
  }'::jsonb,
  '{
    "company": "ECOMIQ Limited",
    "address": "Unit 1603, 16th Floor,\nThe L. Plaza\n367 - 375 Queen''s Road Central\nSheung Wan\nHong Kong",
    "registration": "79004106"
  }'::jsonb,
  'approved',
  '2026-06-16 10:15:00+08',
  '2026-06-17 09:02:00+08',
  'Quinty',
  '2026-06-16 09:00:00+08',
  'agent_042'
);

-- Cut 2 invoice for the same agent/month: June is a QPI-eligible month
-- (Mar/Jun/Sep/Dec), so alongside its normal hours + perks, it carries
-- a 'qpi' line item -- this is what agents actually see; QPI is never
-- its own invoice.
insert into invoices (
  id, invoice_number, agent_id, month, cut_number, weeks,
  items, subtotal, tax, total,
  rate_snapshot, usd_php_rate, hourly_rate_usd,
  profile_snapshot, bill_to,
  status, submitted_at, approved_at, approved_by, paid_at, paid_by,
  qpi_notes,
  created_at, created_by
) values (
  'inv_agent_042_2026-06_c2',
  'EC-INV-2026-24',
  'agent_042',
  '2026-06',
  2,
  '["2026-W24"]'::jsonb,
  '[
    {"type": "hours", "label": "Billable Hours : Week 24 (June 8-14, 2026)", "quantity": 40, "amount": 12000.00, "meta": {"weekKey": "2026-W24", "rate": 300.00}},
    {"type": "perk", "label": "Internet Allowance", "quantity": 1, "amount": 1200.00, "meta": {}},
    {"type": "perk", "label": "HMO Monthly Coverage", "quantity": 1, "amount": 1833.00, "meta": {}},
    {"type": "qpi", "label": "Quarterly Performance Incentive — Attendance (5%)", "quantity": 1, "amount": 850.00, "meta": {"_qpiKey": "attendance", "_qpiBase": 17000.00, "_qpiPct": 5}},
    {"type": "qpi", "label": "Quarterly Performance Incentive — Quality (3%)", "quantity": 1, "amount": 510.00, "meta": {"_qpiKey": "quality", "_qpiBase": 17000.00, "_qpiPct": 3}}
  ]'::jsonb,
  16393.00,
  0,
  16393.00,
  '{"usd": 6.00, "php": 348.00, "rate": 58.00, "rateFromLog": false, "cutoffRateLabel": null, "creditDaysUsed": 0}'::jsonb,
  58.00,
  6.00,
  '{
    "fullName": "Maria Santos",
    "email": "maria.santos@example.com",
    "address": "123 Rizal St, Quezon City, Philippines",
    "bank": {"name": "BDO", "address": "Manila, Philippines", "accountNumber": "001234567890", "swift": "BNORPHMM"}
  }'::jsonb,
  '{
    "company": "ECOMIQ Limited",
    "address": "Unit 1603, 16th Floor,\nThe L. Plaza\n367 - 375 Queen''s Road Central\nSheung Wan\nHong Kong",
    "registration": "79004106"
  }'::jsonb,
  'paid',
  '2026-07-01 10:00:00+08',
  '2026-07-02 09:15:00+08',
  'Quinty',
  '2026-07-05 08:30:00+08',
  'Edwin',
  E'Quarterly Performance Incentives (2026-Q2):\n\n✓ Attendance Incentive (5%) = ₱850.00\n✓ Quality Incentive (3%) = ₱510.00\n\nBillable base: ₱17,000.00 (approved hours-only invoices in 2026-Q2)',
  '2026-06-30 09:00:00+08',
  'agent_042'
);
