first_row(); if(isset($save)) { $showResult = true; switch($operation) { case 1: //Envoi wallet à wallet $frais = ($init_country != $final_country) ? calculateFees1($plr_user_wallet_wallet, $montant) : calculateFees2($config->taux_com_user_wallet_wallet_min , $config->taux_com_user_wallet_wallet_max, $config->taux_com_user_wallet_wallet, $montant); break; case '-': $res=$fn-$sn; break; } } function calculateFees1(array $paliers , $montant){ $size = sizeof($paliers); $min = $paliers[0]->min ; $max= $size > 0 ? $paliers[$size-1]->max : 0; $palier = null; foreach ($paliers as $p){ if($montant >= $p->min && $montant <= $p->max){ $palier = $p; break; } } if($palier){ return (($palier->min * $palier->taux /100 ) + ($palier->max * $palier->taux /100 ))/2; }else{ if($montant < $min) return $min* $paliers[0]->taux /100; else if ($montant > $max) return $max* $paliers[$size-1]->taux /100; } } function calculateFees2($min , $max , $taux , $montant){ if($montant < $min) return $min* $taux /100; else if ($montant > $max) return $max*$taux /100; else return $montant * $taux /100; } // set to whatever your rates are relative to $baseCurrency = 'USD'; // use your own credentials, or re-use your existing PDO connection $pdo = new PDO('mysql:host='.$this->db->hostname.';dbname='.$this->db->database, $this->db->username, $this->db->password); $configuration = new PDOProviderConfiguration(); $configuration->tableName = 'exchange_rate'; $configuration->exchangeRateColumnName = 'exchange_rate'; $configuration->targetCurrencyColumnName = 'target_currency'; $configuration->sourceCurrencyCode = $baseCurrency; // this provider loads exchange rates from your database $provider = new PDOProvider($pdo, $configuration); // this provider calculates exchange rates relative to the base currency $provider = new BaseCurrencyProvider($provider, $baseCurrency); // this currency converter can now handle any currency pair $converter = new CurrencyConverter($provider); //$money = Money::of('1', 'USD'); //$mone2 = $converter->convert($money, 'XAF', RoundingMode::DOWN); ?>