refs #392 fixed Account, Vendor, Customer currency issue
This commit is contained in:
		| @@ -219,9 +219,23 @@ class Accounts extends Controller | ||||
|  | ||||
|         $account = Account::find($account_id); | ||||
|          | ||||
|         // Get currency object | ||||
|         $currency = Currency::where('code', $account->currency_code)->first(); | ||||
|         $currency_code = $account->currency_code; | ||||
|  | ||||
|         $currency = false; | ||||
|         $currencies = Currency::enabled()->pluck('name', 'code')->toArray(); | ||||
|  | ||||
|         if (array_key_exists($currency_code, $currencies)) { | ||||
|             $currency = true; | ||||
|         } | ||||
|  | ||||
|         if (!$currency) {  | ||||
|             $currency_code = setting('general.default_currency'); | ||||
|         } | ||||
|  | ||||
|         // Get currency object | ||||
|         $currency = Currency::where('code', $currency_code)->first(); | ||||
|  | ||||
|         $account->currency_code = $currency_code; | ||||
|         $account->currency_rate = $currency->rate; | ||||
|  | ||||
|         return response()->json($account); | ||||
|   | ||||
| @@ -308,9 +308,23 @@ class Vendors extends Controller | ||||
|  | ||||
|         $vendor = Vendor::find($vendor_id); | ||||
|  | ||||
|         // Get currency object | ||||
|         $currency = Currency::where('code', $vendor->currency_code)->first(); | ||||
|         $currency_code = $vendor->currency_code; | ||||
|  | ||||
|         $currency = false; | ||||
|         $currencies = Currency::enabled()->pluck('name', 'code')->toArray(); | ||||
|  | ||||
|         if (array_key_exists($currency_code, $currencies)) { | ||||
|             $currency = true; | ||||
|         } | ||||
|  | ||||
|         if (!$currency) {  | ||||
|             $currency_code = setting('general.default_currency'); | ||||
|         } | ||||
|  | ||||
|         // Get currency object | ||||
|         $currency = Currency::where('code', $currency_code)->first(); | ||||
|  | ||||
|         $vendor->currency_code = $currency_code; | ||||
|         $vendor->currency_rate = $currency->rate; | ||||
|  | ||||
|         return response()->json($vendor); | ||||
|   | ||||
| @@ -344,9 +344,23 @@ class Customers extends Controller | ||||
|  | ||||
|         $customer = Customer::find($customer_id); | ||||
|  | ||||
|         // Get currency object | ||||
|         $currency = Currency::where('code', $customer->currency_code)->first(); | ||||
|         $currency_code = $customer->currency_code; | ||||
|  | ||||
|         $currency = false; | ||||
|         $currencies = Currency::enabled()->pluck('name', 'code')->toArray(); | ||||
|  | ||||
|         if (array_key_exists($currency_code, $currencies)) { | ||||
|             $currency = true; | ||||
|         } | ||||
|  | ||||
|         if (!$currency) {  | ||||
|             $currency_code = setting('general.default_currency'); | ||||
|         } | ||||
|  | ||||
|         // Get currency object | ||||
|         $currency = Currency::where('code', $currency_code)->first(); | ||||
|  | ||||
|         $customer->currency_code = $currency_code; | ||||
|         $customer->currency_rate = $currency->rate; | ||||
|  | ||||
|         return response()->json($customer); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user