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:
@@ -254,15 +254,19 @@ $buyerEmailDefault = trim((string) ($buyerAddr['email'] ?? $orderRow['buyer_emai
|
||||
}
|
||||
var d = res.data.data || {};
|
||||
if (d.tax_number) { nipInput.value = d.tax_number; }
|
||||
var fields = {
|
||||
buyer_company_name: d.company_name,
|
||||
// MF zwraca w `name` osobe fizyczna dla JDG (krs=null) lub legal name dla spolki (krs!=null).
|
||||
// Wpisujemy do wlasciwego pola wg flagi is_jdg; drugiego pola nie ruszamy.
|
||||
var nameTargetId = d.is_jdg ? 'buyer_name' : 'buyer_company_name';
|
||||
var addressFields = {
|
||||
buyer_street: d.street,
|
||||
buyer_postal_code: d.postal_code,
|
||||
buyer_city: d.city
|
||||
};
|
||||
Object.keys(fields).forEach(function (key) {
|
||||
var nameTargetEl = document.getElementById(nameTargetId);
|
||||
if (nameTargetEl && d.company_name) { nameTargetEl.value = d.company_name; }
|
||||
Object.keys(addressFields).forEach(function (key) {
|
||||
var el = document.getElementById(key);
|
||||
if (el && fields[key]) { el.value = fields[key]; }
|
||||
if (el && addressFields[key]) { el.value = addressFields[key]; }
|
||||
});
|
||||
})
|
||||
.catch(function (err) {
|
||||
|
||||
Reference in New Issue
Block a user