From a3a2cf55fe3f67e3e1358ae816b667275ae5ddb7 Mon Sep 17 00:00:00 2001 From: cuneytsenturk Date: Thu, 30 Aug 2018 15:40:12 +0300 Subject: [PATCH] close #451 Finished: Format amount fields with respect to currency --- app/Http/Controllers/Expenses/Bills.php | 24 ++++---- app/Http/Controllers/Modals/BillPayments.php | 64 +++++++++++--------- 2 files changed, 47 insertions(+), 41 deletions(-) diff --git a/app/Http/Controllers/Expenses/Bills.php b/app/Http/Controllers/Expenses/Bills.php index 20734ddb9..4054e1c02 100644 --- a/app/Http/Controllers/Expenses/Bills.php +++ b/app/Http/Controllers/Expenses/Bills.php @@ -71,9 +71,11 @@ class Bills extends Controller $_currencies = Currency::enabled()->pluck('rate', 'code')->toArray(); foreach ($bill->payments as $item) { - $default_amount = $item->amount; + $default_amount = (double) $item->amount; - if ($bill->currency_code != $item->currency_code) { + if ($bill->currency_code == $item->currency_code) { + $amount = $default_amount; + } else { $default_amount_model = new BillPayment(); $default_amount_model->default_currency_code = $bill->currency_code; @@ -82,17 +84,17 @@ class Bills extends Controller $default_amount_model->currency_rate = $_currencies[$item->currency_code]; $default_amount = (double) $default_amount_model->getDivideConvertedAmount(); + + $convert_amount = new BillPayment(); + + $convert_amount->default_currency_code = $item->currency_code; + $convert_amount->amount = $default_amount; + $convert_amount->currency_code = $bill->currency_code; + $convert_amount->currency_rate = $_currencies[$bill->currency_code]; + + $amount = (double) $convert_amount->getDynamicConvertedAmount(); } - $convert_amount = new BillPayment(); - - $convert_amount->default_currency_code = $item->currency_code; - $convert_amount->amount = $default_amount; - $convert_amount->currency_code = $bill->currency_code; - $convert_amount->currency_rate = $_currencies[$bill->currency_code]; - - $amount = (double) $convert_amount->getDynamicConvertedAmount(); - $paid += $amount; } } diff --git a/app/Http/Controllers/Modals/BillPayments.php b/app/Http/Controllers/Modals/BillPayments.php index b437ffbb2..0446ea9bf 100644 --- a/app/Http/Controllers/Modals/BillPayments.php +++ b/app/Http/Controllers/Modals/BillPayments.php @@ -88,7 +88,9 @@ class BillPayments extends Controller $default_amount = (double) $request['amount']; - if ($bill->currency_code != $request['currency_code']) { + if ($bill->currency_code == $request['currency_code']) { + $amount = $default_amount; + } else { $default_amount_model = new BillPayment(); $default_amount_model->default_currency_code = $bill->currency_code; @@ -97,17 +99,17 @@ class BillPayments extends Controller $default_amount_model->currency_rate = $currencies[$request['currency_code']]; $default_amount = (double) $default_amount_model->getDivideConvertedAmount(); + + $convert_amount = new BillPayment(); + + $convert_amount->default_currency_code = $request['currency_code']; + $convert_amount->amount = $default_amount; + $convert_amount->currency_code = $bill->currency_code; + $convert_amount->currency_rate = $currencies[$bill->currency_code]; + + $amount = (double) $convert_amount->getDynamicConvertedAmount(); } - $convert_amount = new BillPayment(); - - $convert_amount->default_currency_code = $request['currency_code']; - $convert_amount->amount = $default_amount; - $convert_amount->currency_code = $bill->currency_code; - $convert_amount->currency_rate = $currencies[$bill->currency_code]; - - $amount = (double) $convert_amount->getDynamicConvertedAmount(); - if ($bill->payments()->count()) { $total_amount -= $this->getPaid($bill); } @@ -134,17 +136,17 @@ class BillPayments extends Controller $error_amount_model->currency_rate = $currencies[$bill->currency_code]; $error_amount = (double) $error_amount_model->getDivideConvertedAmount(); + + $convert_amount = new BillPayment(); + + $convert_amount->default_currency_code = $bill->currency_code; + $convert_amount->amount = $error_amount; + $convert_amount->currency_code = $request['currency_code']; + $convert_amount->currency_rate = $currencies[$request['currency_code']]; + + $error_amount = (double) $convert_amount->getDynamicConvertedAmount(); } - $convert_amount = new BillPayment(); - - $convert_amount->default_currency_code = $bill->currency_code; - $convert_amount->amount = $error_amount; - $convert_amount->currency_code = $request['currency_code']; - $convert_amount->currency_rate = $currencies[$request['currency_code']]; - - $error_amount = (double) $convert_amount->getDynamicConvertedAmount(); - $message = trans('messages.error.over_payment', ['amount' => money($error_amount, $request['currency_code'], true)]); return response()->json([ @@ -215,9 +217,11 @@ class BillPayments extends Controller $_currencies = Currency::enabled()->pluck('rate', 'code')->toArray(); foreach ($bill->payments as $item) { - $default_amount = $item->amount; + $default_amount = (double) $item->amount; - if ($bill->currency_code != $item->currency_code) { + if ($bill->currency_code == $item->currency_code) { + $amount = $default_amount; + } else { $default_amount_model = new BillPayment(); $default_amount_model->default_currency_code = $bill->currency_code; @@ -226,17 +230,17 @@ class BillPayments extends Controller $default_amount_model->currency_rate = $_currencies[$item->currency_code]; $default_amount = (double) $default_amount_model->getDivideConvertedAmount(); + + $convert_amount = new BillPayment(); + + $convert_amount->default_currency_code = $item->currency_code; + $convert_amount->amount = $default_amount; + $convert_amount->currency_code = $bill->currency_code; + $convert_amount->currency_rate = $_currencies[$bill->currency_code]; + + $amount = (double) $convert_amount->getDynamicConvertedAmount(); } - $convert_amount = new BillPayment(); - - $convert_amount->default_currency_code = $item->currency_code; - $convert_amount->amount = $default_amount; - $convert_amount->currency_code = $bill->currency_code; - $convert_amount->currency_rate = $_currencies[$bill->currency_code]; - - $amount = (double) $convert_amount->getDynamicConvertedAmount(); - $paid += $amount; } }