+ Fix bugs convert money

This commit is contained in:
Djery-Tom 2020-06-25 11:18:46 +01:00
parent 482487643f
commit 67f46c363a
1 changed files with 4 additions and 3 deletions

View File

@ -16,6 +16,7 @@ use Brick\Money\Money;
use Brick\Math\RoundingMode; use Brick\Math\RoundingMode;
use PDO; use PDO;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use Brick\Money\Context\AutoContext;
trait Helper trait Helper
{ {
@ -53,14 +54,14 @@ trait Helper
$currency = collect(DB::select('SELECT cu.code FROM networks n INNER JOIN countries c ON c.id = n.country_id INNER JOIN currencies cu ON cu.id = c.idCurrency $currency = collect(DB::select('SELECT cu.code FROM networks n INNER JOIN countries c ON c.id = n.country_id INNER JOIN currencies cu ON cu.id = c.idCurrency
WHERE n.id = :id',['id'=>$id_network]))->first(); WHERE n.id = :id',['id'=>$id_network]))->first();
$money = Money::of(round($amount, 0),$currency ? $currency->code : 'XAF'); $money = Money::of(round($amount, 0),$currency ? $currency->code : 'XAF',new AutoContext());
return $money->formatTo('fr_FR'); return $money->formatTo('fr_FR');
} }
public function toMoney($amount, $id_country) public function toMoney($amount, $id_country)
{ {
$country = Country::findOrFail($id_country); $country = Country::findOrFail($id_country);
$money = Money::of(round($amount, 0),$country->currency->code); $money = Money::of(round($amount, 0),$country->currency->code,new AutoContext());
return $money->formatTo('fr_FR'); return $money->formatTo('fr_FR');
} }
@ -89,7 +90,7 @@ trait Helper
$converter = new CurrencyConverter($provider); $converter = new CurrencyConverter($provider);
$init_country = Country::findOrFail($init_country); $init_country = Country::findOrFail($init_country);
$final_country = Country::findOrFail($final_country); $final_country = Country::findOrFail($final_country);
$init_money = Money::of(round($amount, 0),$init_country->currency->code);; $init_money = Money::of(round($amount, 0),$init_country->currency->code,new AutoContext());
return $converter->convert($init_money, $final_country->currency->code, RoundingMode::DOWN); return $converter->convert($init_money, $final_country->currency->code, RoundingMode::DOWN);
} }