diff --git a/app/Http/Controllers/InvoiceApiController.php b/app/Http/Controllers/InvoiceApiController.php index c7e8803fdc69..42cd837a5d17 100644 --- a/app/Http/Controllers/InvoiceApiController.php +++ b/app/Http/Controllers/InvoiceApiController.php @@ -149,6 +149,7 @@ class InvoiceApiController extends BaseAPIController 'country_id', 'private_notes', 'currency_code', + 'country_code', ] as $field) { if (isset($data[$field])) { $clientData[$field] = $data[$field]; diff --git a/app/Ninja/Repositories/ClientRepository.php b/app/Ninja/Repositories/ClientRepository.php index 1a2b247d6018..b01db1225da2 100644 --- a/app/Ninja/Repositories/ClientRepository.php +++ b/app/Ninja/Repositories/ClientRepository.php @@ -106,6 +106,17 @@ class ClientRepository extends BaseRepository } } + // convert country code to id + if (isset($data['country_code'])) { + $countryCode = strtolower($data['country_code']); + $country = Cache::get('countries')->filter(function ($item) use ($countryCode) { + return strtolower($item->iso_3166_2) == $countryCode || strtolower($item->iso_3166_3) == $countryCode; + })->first(); + if ($country) { + $data['country_id'] = $country->id; + } + } + $client->fill($data); $client->save();