first(function ($c) use ($iso_3_code) { /** @var \App\Models\Country $c */ return $c->iso_3166_3 == $iso_3_code || $c->name == $iso_3_code; }); return $country ? (string) $country->id : $this->company->settings->country_id; } public function resolveCurrency(string $currency_code): string { /** @var \App\Models\Currency $currency */ $currency = app('currencies')->first(function ($c) use ($currency_code) { /** @var \App\Models\Currency $c */ return $c->code == $currency_code; }); return $currency ? (string) $currency->id : $this->company->settings->currency_id; } public function resolveTimezone(?string $timezone_name): string { if (empty($timezone_name)) { return (string) $this->company->settings->timezone_id; } /** @var \App\Models\Timezone $timezone */ $timezone = app('timezones')->first(function ($t) use ($timezone_name) { /** @var \App\Models\Timezone $t */ return $t->name === $timezone_name; }); return $timezone ? (string) $timezone->id : (string) $this->company->settings->timezone_id; } public function getShipAddrCountry($data, $field) { return is_null(($c = $this->getString($data, $field))) ? null : $this->getCountryId($c); } public function getBillAddrCountry($data, $field) { return is_null(($c = $this->getString($data, $field))) ? null : $this->getCountryId($c); } public function getClientId($customer_reference_id): ?int { $client = Client::query() ->withTrashed() ->where('company_id', $this->company->id) // ->where('number', $customer_reference_id) ->where('sync->qb_id', $customer_reference_id) ->first(); return $client ? $client->id : null; } public function getVendorId($customer_reference_id): ?int { $vendor = Vendor::query() ->withTrashed() ->where('company_id', $this->company->id) ->where('number', $customer_reference_id) ->first(); return $vendor ? $vendor->id : null; } }