Skip to content

Commit

Permalink
close #451 Finished: Format amount fields with respect to currency
Browse files Browse the repository at this point in the history
  • Loading branch information
cuneytsenturk committed Aug 30, 2018
1 parent 3589a0b commit a3a2cf5
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 33 deletions.
20 changes: 11 additions & 9 deletions app/Http/Controllers/Expenses/Bills.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,11 @@ public function show(Bill $bill)
$_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;
Expand All @@ -82,16 +84,16 @@ public function show(Bill $bill)
$default_amount_model->currency_rate = $_currencies[$item->currency_code];

$default_amount = (double) $default_amount_model->getDivideConvertedAmount();
}

$convert_amount = new BillPayment();
$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];
$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();
$amount = (double) $convert_amount->getDynamicConvertedAmount();
}

$paid += $amount;
}
Expand Down
52 changes: 28 additions & 24 deletions app/Http/Controllers/Modals/BillPayments.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ public function store(Bill $bill, Request $request)

$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;
Expand All @@ -97,16 +99,16 @@ public function store(Bill $bill, Request $request)
$default_amount_model->currency_rate = $currencies[$request['currency_code']];

$default_amount = (double) $default_amount_model->getDivideConvertedAmount();
}

$convert_amount = new BillPayment();
$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];
$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();
$amount = (double) $convert_amount->getDynamicConvertedAmount();
}

if ($bill->payments()->count()) {
$total_amount -= $this->getPaid($bill);
Expand Down Expand Up @@ -134,16 +136,16 @@ public function store(Bill $bill, Request $request)
$error_amount_model->currency_rate = $currencies[$bill->currency_code];

$error_amount = (double) $error_amount_model->getDivideConvertedAmount();
}

$convert_amount = new BillPayment();
$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']];
$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();
$error_amount = (double) $convert_amount->getDynamicConvertedAmount();
}

$message = trans('messages.error.over_payment', ['amount' => money($error_amount, $request['currency_code'], true)]);

Expand Down Expand Up @@ -215,9 +217,11 @@ protected function getPaid($bill)
$_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;
Expand All @@ -226,16 +230,16 @@ protected function getPaid($bill)
$default_amount_model->currency_rate = $_currencies[$item->currency_code];

$default_amount = (double) $default_amount_model->getDivideConvertedAmount();
}

$convert_amount = new BillPayment();
$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];
$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();
$amount = (double) $convert_amount->getDynamicConvertedAmount();
}

$paid += $amount;
}
Expand Down

0 comments on commit a3a2cf5

Please sign in to comment.