Skip to content

Commit

Permalink
refactor(frozen period): simplify exchange rates
Browse files Browse the repository at this point in the history
  • Loading branch information
KennethTrecy committed Aug 4, 2024
1 parent abe7126 commit 4a531ea
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions app/Controllers/FrozenPeriodController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use CodeIgniter\Validation\Validation;

use App\Casts\ModifierAction;
use App\Casts\RationalNumber;
use App\Contracts\OwnedResource;
use App\Entities\FlowCalculation;
use App\Entities\SummaryCalculation;
Expand Down Expand Up @@ -893,6 +894,18 @@ function ($raw_exchanges, $modifier) use ($raw_exchange_entries) {
[]
);
$raw_exchange_rates = array_values($raw_exchange_rates);
$raw_exchange_rates = array_map(
function ($raw_exchange_rate) {
$source = RationalNumber::get($raw_exchange_rate["source"]["value"]);
$destination = RationalNumber::get($raw_exchange_rate["destination"]["value"]);
$rate = $destination->dividedBy($source)->simplified();

$raw_exchange_rate["source"]["value"] = $rate->getDenominator();
$raw_exchange_rate["destination"]["value"] = $rate->getNumerator();
return $raw_exchange_rate;
},
$raw_exchange_rates
);

return $raw_exchange_rates;
}
Expand Down

0 comments on commit 4a531ea

Please sign in to comment.