close #451 Finished: Format amount fields with respect to currency

This commit is contained in:
cuneytsenturk 2018-08-30 15:40:12 +03:00
parent 3589a0b5fc
commit a3a2cf55fe
2 changed files with 47 additions and 41 deletions

View File

@ -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;
}
}

View File

@ -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;
}
}