diff --git a/app/Http/Controllers/Banking/Accounts.php b/app/Http/Controllers/Banking/Accounts.php index 8767e8022..95db6ba89 100644 --- a/app/Http/Controllers/Banking/Accounts.php +++ b/app/Http/Controllers/Banking/Accounts.php @@ -211,25 +211,26 @@ class Accounts extends Controller public function currency() { - $account_id = request('account_id'); + $account_id = (int) request('account_id'); if (empty($account_id)) { - $account_id = setting('general.default_account'); + return response()->json([]); } $account = Account::find($account_id); - - $currency_code = $account->currency_code; - $currency = false; - $currencies = Currency::enabled()->pluck('name', 'code')->toArray(); - - if (array_key_exists($currency_code, $currencies)) { - $currency = true; + if (empty($account)) { + return response()->json([]); } - if (!$currency) { - $currency_code = setting('general.default_currency'); + $currency_code = setting('general.default_currency'); + + if (isset($account->currency_code)) { + $currencies = Currency::enabled()->pluck('name', 'code')->toArray(); + + if (array_key_exists($account->currency_code, $currencies)) { + $currency_code = $account->currency_code; + } } // Get currency object diff --git a/app/Http/Controllers/Expenses/Vendors.php b/app/Http/Controllers/Expenses/Vendors.php index f3b9c7ece..d8506dc39 100644 --- a/app/Http/Controllers/Expenses/Vendors.php +++ b/app/Http/Controllers/Expenses/Vendors.php @@ -304,21 +304,26 @@ class Vendors extends Controller public function currency() { - $vendor_id = request('vendor_id'); + $vendor_id = (int) request('vendor_id'); + if (empty($vendor_id)) { + return response()->json([]); + } + $vendor = Vendor::find($vendor_id); - $currency_code = $vendor->currency_code; - - $currency = false; - $currencies = Currency::enabled()->pluck('name', 'code')->toArray(); - - if (array_key_exists($currency_code, $currencies)) { - $currency = true; + if (empty($vendor)) { + return response()->json([]); } - if (!$currency) { - $currency_code = setting('general.default_currency'); + $currency_code = setting('general.default_currency'); + + if (isset($vendor->currency_code)) { + $currencies = Currency::enabled()->pluck('name', 'code')->toArray(); + + if (array_key_exists($vendor->currency_code, $currencies)) { + $currency_code = $vendor->currency_code; + } } // Get currency object diff --git a/app/Http/Controllers/Incomes/Customers.php b/app/Http/Controllers/Incomes/Customers.php index 5404a4a6a..427e5bf78 100644 --- a/app/Http/Controllers/Incomes/Customers.php +++ b/app/Http/Controllers/Incomes/Customers.php @@ -340,21 +340,26 @@ class Customers extends Controller public function currency() { - $customer_id = request('customer_id'); + $customer_id = (int) request('customer_id'); + + if (empty($customer_id)) { + return response()->json([]); + } $customer = Customer::find($customer_id); - $currency_code = $customer->currency_code; - - $currency = false; - $currencies = Currency::enabled()->pluck('name', 'code')->toArray(); - - if (array_key_exists($currency_code, $currencies)) { - $currency = true; + if (empty($customer)) { + return response()->json([]); } - if (!$currency) { - $currency_code = setting('general.default_currency'); + $currency_code = setting('general.default_currency'); + + if (isset($customer->currency_code)) { + $currencies = Currency::enabled()->pluck('name', 'code')->toArray(); + + if (array_key_exists($customer->currency_code, $currencies)) { + $currency_code = $customer->currency_code; + } } // Get currency object