feat(126): invoice GUS field mapping fix (JDG/KRS heuristic)

MfWhitelistApiClient.lookupByNip() exposes is_jdg/krs from MF Biala Lista.
InvoiceController.nipLookup propagates is_jdg in JSON response.
invoice_form.php JS conditionally targets buyer_name (JDG) or
buyer_company_name (spolka z KRS); second field keeps zamowienie pre-fill.

Fixes apparent field swap on /orders/{id}/invoice/create after GUS lookup
for JDG (sole trader) where MF returns natural person in subject.name.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-12 22:29:55 +02:00
parent 2ab461aaae
commit c758ec7c92
10 changed files with 386 additions and 18 deletions

View File

@@ -12,6 +12,8 @@
- [Phase 125, Plan 01] Allegro rozszerzenie `shouldRequestInvoice()`: detekcja `invoice.naturalPerson=false`, `invoice.address.taxId`, `invoice.companyName` (wczesniej tylko `invoice.required`).
- [Phase 125, Plan 01] Migracja `20260513_000113_drop_orders_is_invoice_and_backfill_invoice_requested.sql` — idempotentna (information_schema guard); backfill 7 zamowien + DROP COLUMN `orders.is_invoice` (legacy z Phase 115).
- [Phase 125, Plan 01] Cleanup `is_invoice` z `OrderImportRepository` (INSERT/params/docstring) i `OrdersRepository` (SELECT/hydrate); usuniete `shouldRequestInvoice()` z `ShopproOrdersSyncService` (zastapione heurystyka mappera).
- [Phase 126, Plan 01] Bugfix `/orders/{id}/invoice/create` GUS lookup: dla JDG (MF `subject.krs=''`) nazwa z MF trafia do "Imie i nazwisko"; dla spolki z KRS — do "Nazwa firmy". Drugiego pola nie nadpisuje — pre-fill z `order_addresses.name` zachowany (czesto trzyma pelna nazwe firmy JDG, np. "Project-Pro Pyziak Jacek" vs MF "JACEK PYZIAK").
- [Phase 126, Plan 01] `MfWhitelistApiClient::lookupByNip()` zwraca dodatkowo `krs: string` i `is_jdg: bool` (true gdy `subject.krs === ''`). `InvoiceController::nipLookup` propaguje `is_jdg` w `data` JSON. JS `btn-gus-lookup` warunkowo wybiera target field.
## Zmienione pliki
@@ -47,3 +49,8 @@
- `database/migrations/20260513_000113_drop_orders_is_invoice_and_backfill_invoice_requested.sql`
- `.paul/phases/125-invoice-requested-import-fix/125-01-PLAN.md`
- `.paul/phases/125-invoice-requested-import-fix/125-01-SUMMARY.md`
- `src/Core/Http/MfWhitelistApiClient.php`
- `src/Modules/Accounting/InvoiceController.php`
- `resources/views/accounting/invoice_form.php`
- `.paul/phases/126-invoice-gus-field-mapping/126-01-PLAN.md`
- `.paul/phases/126-invoice-gus-field-mapping/126-01-SUMMARY.md`