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

@@ -19,7 +19,7 @@ final class MfWhitelistApiClient
}
/**
* @return array{name: string, tax_no: string, regon: string, street: string, postal_code: string, city: string, country: string, status_vat: string, raw: array<string, mixed>}
* @return array{name: string, tax_no: string, regon: string, street: string, postal_code: string, city: string, country: string, status_vat: string, krs: string, is_jdg: bool, raw: array<string, mixed>}
*/
public function lookupByNip(string $nip, ?string $date = null): array
{
@@ -65,6 +65,8 @@ final class MfWhitelistApiClient
$address = trim((string) ($subject['workingAddress'] ?? $subject['residenceAddress'] ?? ''));
['street' => $street, 'postal_code' => $postalCode, 'city' => $city] = $this->parseAddress($address);
$krs = trim((string) ($subject['krs'] ?? ''));
return [
'name' => $name,
'tax_no' => trim((string) ($subject['nip'] ?? $cleanNip)),
@@ -74,6 +76,8 @@ final class MfWhitelistApiClient
'city' => $city,
'country' => 'PL',
'status_vat' => trim((string) ($subject['statusVat'] ?? '')),
'krs' => $krs,
'is_jdg' => $krs === '',
'raw' => $subject,
];
}

View File

@@ -55,6 +55,7 @@ final class InvoiceController
'country' => $data['country'],
'regon' => $data['regon'],
'status_vat' => $data['status_vat'],
'is_jdg' => (bool) ($data['is_jdg'] ?? false),
],
]);
}