+ Add currency

This commit is contained in:
Djery-Tom 2020-06-25 09:08:10 +01:00
parent 36b456108b
commit e0cf7cd903
11 changed files with 128 additions and 65 deletions

View File

@ -1541,6 +1541,7 @@ class Gestion extends CI_Controller
$this->historique($network_id,$this->input->get('d'),$this->input->get('f'),$this->input->get('history')); $this->historique($network_id,$this->input->get('d'),$this->input->get('f'),$this->input->get('history'));
}else{ }else{
$taux = $this->user_model->getTaux($network_id); $taux = $this->user_model->getTaux($network_id);
$data['currency'] = $this->user_model->getCurrency($network_id);
if ($taux != null) { if ($taux != null) {
$taux = $taux->first_row(); $taux = $taux->first_row();
$data['idConfig'] = $taux->id; $data['idConfig'] = $taux->id;

View File

@ -1,6 +1,11 @@
<?php <?php
defined('BASEPATH') or exit('No direct script access allowed'); defined('BASEPATH') or exit('No direct script access allowed');
use Brick\Money\CurrencyConverter;
use Brick\Money\ExchangeRateProvider\PDOProvider;
use Brick\Money\ExchangeRateProvider\PDOProviderConfiguration;
use Brick\Money\ExchangeRateProvider\BaseCurrencyProvider;
use Brick\Math\RoundingMode;
use Brick\Money\Money;
/** /**
* Created by PhpStorm. * Created by PhpStorm.
* User: Hanry Nzale * User: Hanry Nzale
@ -407,7 +412,7 @@ class Hyperviseur_dash extends CI_Controller
array_push($data['transactions'], $trans); array_push($data['transactions'], $trans);
} }
} }
$data["totalCommissionBanque"] = $totalCommissionBanque; $data["totalCommissionBanque"] = Money::of($totalCommissionBanque, $this->session->userdata('currency_code'))->formatTo('fr_FR');
} }
@ -419,9 +424,10 @@ class Hyperviseur_dash extends CI_Controller
} }
$row = $res->first_row(); $row = $res->first_row();
$data["commission"] = $row->balance_com; $data["commission"] = Money::of($row->balance_com, $this->session->userdata('currency_code'))->formatTo('fr_FR');
$data["principal"] = $row->balance_princ; $data["principal"] = Money::of($row->balance_princ, $this->session->userdata('currency_code'))->formatTo('fr_FR');
$data['wallet_id'] = $row->wallet_id; $data['wallet_id'] = $row->wallet_id;
$data['curreny_code'] = $this->session->userdata('currency_code');
$res = $this->user_model->getWalletPassword($id_network); $res = $this->user_model->getWalletPassword($id_network);
@ -929,6 +935,7 @@ class Hyperviseur_dash extends CI_Controller
function calculateFees1(array $paliers, $montant) function calculateFees1(array $paliers, $montant)
{ {
$size = sizeof($paliers); $size = sizeof($paliers);
if($size > 0){
$min = $paliers[0]->min; $min = $paliers[0]->min;
$max = $size > 0 ? $paliers[$size - 1]->max : 0; $max = $size > 0 ? $paliers[$size - 1]->max : 0;
$palier = null; $palier = null;
@ -948,6 +955,7 @@ class Hyperviseur_dash extends CI_Controller
return $max * $paliers[$size - 1]->taux / 100; return $max * $paliers[$size - 1]->taux / 100;
} }
} }
}
//Calcul des frais nationaux //Calcul des frais nationaux
function calculateFees2($min, $max, $taux, $montant) function calculateFees2($min, $max, $taux, $montant)

View File

@ -89,6 +89,7 @@
$this->session->set_userdata('lastname', $data->lastname); $this->session->set_userdata('lastname', $data->lastname);
$this->session->set_userdata('adresse', $data->adresse); $this->session->set_userdata('adresse', $data->adresse);
$this->session->set_userdata('agent_id', $data->agent_id); $this->session->set_userdata('agent_id', $data->agent_id);
$this->session->set_userdata('currency_code', $data->currency_code);
if($user_login['user_role']==1){ if($user_login['user_role']==1){
$this->session->set_userdata('country', $data->country); $this->session->set_userdata('country', $data->country);

View File

@ -396,4 +396,10 @@ $lang ['sharing_updated'] = 'Sharing rate updated';
$lang ['not_defined'] = 'Not defined'; $lang ['not_defined'] = 'Not defined';
$lang ['no_network'] = 'No network'; $lang ['no_network'] = 'No network';
$lang ['activated_countries'] = 'Countries activated'; $lang ['activated_countries'] = 'Countries activated';
$lang ['paying_networks_accounts'] = 'Paying network accounts';
$lang ['user_name'] = 'User name';
$lang ['fees'] = 'Fees';
$lang ['tax'] = 'Tax';
$lang ['customer_net_amount_init'] = 'Net customer amount from the country of departure';
$lang ['customer_net_amount_final'] = 'Net customer amount from the country of arrival';
?> ?>

View File

@ -412,4 +412,6 @@ $lang['paying_networks_accounts'] = 'Comptes des reseaux payeurs';
$lang['user_name'] = 'Nom de l\'utilisateur'; $lang['user_name'] = 'Nom de l\'utilisateur';
$lang['fees'] = 'Frais'; $lang['fees'] = 'Frais';
$lang['tax'] = 'Taxe'; $lang['tax'] = 'Taxe';
$lang['customer_net_amount_init'] = 'Montant net client du pays de départ';
$lang['customer_net_amount_final'] = 'Montant net client du pays d\'arrivée';
?> ?>

View File

@ -2498,7 +2498,7 @@ class User_model extends CI_Model
} }
public function getPayingNetworksByConfigWallet($id_config){ public function getPayingNetworksByConfigWallet($id_config){
$query = $this->db->query("SELECT n.name , n.id , cw.type , c.name as country , pw.taux_partage as rate , pw.balance_com FROM networks n INNER JOIN countries c ON n.country_id=c.id $query = $this->db->query("SELECT n.name , n.id , cw.type , c.name as country ,c.currency_code, pw.taux_partage as rate , pw.balance_com FROM networks n INNER JOIN countries_currencies c ON n.country_id=c.id
INNER JOIN configWallet cw ON cw.id_network = n.id INNER JOIN paying_networks pw ON pw.id_network = n.id WHERE n.id IN ( SELECT id_network FROM paying_networks pw WHERE id_configWallet = $id_config )"); INNER JOIN configWallet cw ON cw.id_network = n.id INNER JOIN paying_networks pw ON pw.id_network = n.id WHERE n.id IN ( SELECT id_network FROM paying_networks pw WHERE id_configWallet = $id_config )");
if($query->num_rows()>0){ if($query->num_rows()>0){
return $query; return $query;
@ -2529,4 +2529,14 @@ class User_model extends CI_Model
return false; return false;
} }
} }
public function getCurrency($id_network){
$query = $this->db->query("SELECT cc.currency_code as code FROM networks n INNER JOIN countries_currencies cc ON cc.id = n.country_id
WHERE n.id = '".$id_network."'");
if($query->num_rows()>0){
return $query->first_row();
}else{
return false;
}
}
} }

View File

@ -7,6 +7,7 @@
href="<?php echo base_url('bower_components/datatables.net-bs/css/dataTables.bootstrap.min.css') ?>"> href="<?php echo base_url('bower_components/datatables.net-bs/css/dataTables.bootstrap.min.css') ?>">
<?php <?php
use Brick\Money\Money;
function convertDate($date) function convertDate($date)
{ {
$month = null; $month = null;
@ -106,30 +107,30 @@ $depots = $this->db->query("SELECT * FROM infos_transaction
AND date_created BETWEEN '" . $startDate . "' AND '" . $endDate . "' AND date_created BETWEEN '" . $startDate . "' AND '" . $endDate . "'
AND type_transac='credit'"); AND type_transac='credit'");
if ($transactions != false) { //if ($transactions != false) {
$transac = $transactions->num_rows(); // $transac = $transactions->num_rows();
$array_transac = array(); // $array_transac = array();
$num = 0; // $num = 0;
if ($transac > 0) { // if ($transac > 0) {
foreach ($transactions->result() as $row) { // foreach ($transactions->result() as $row) {
$num++; // $num++;
$array_transac[] = $row->type_transac; // $array_transac[] = $row->type_transac;
} // }
$vals_transac = array_count_values($array_transac); // $vals_transac = array_count_values($array_transac);
$pieChart = array(); // $pieChart = array();
foreach (array_keys($vals_transac) as $paramName) { // foreach (array_keys($vals_transac) as $paramName) {
$color = dechex(rand(0x000000, 0xFFFFFF)); // $color = dechex(rand(0x000000, 0xFFFFFF));
$trash = array("value" => $vals_transac[$paramName], // $trash = array("value" => $vals_transac[$paramName],
"color" => "#" . $color, // "color" => "#" . $color,
"highlight" => "#" . $color, // "highlight" => "#" . $color,
"label" => $paramName); // "label" => $paramName);
//
$pieChart[] = $trash; // $pieChart[] = $trash;
} // }
} // }
} else { //} else {
$pieChart = array(); // $pieChart = array();
} //}
$fmt = new NumberFormatter( 'fr_FR', NumberFormatter::DECIMAL ); $fmt = new NumberFormatter( 'fr_FR', NumberFormatter::DECIMAL );
?> ?>
@ -174,7 +175,7 @@ $fmt = new NumberFormatter( 'fr_FR', NumberFormatter::DECIMAL );
<div class="col-lg-4 col-xs-6"> <div class="col-lg-4 col-xs-6">
<div class="small-box bg-green"> <div class="small-box bg-green">
<div class="inner"> <div class="inner">
<h3><?php echo $fmt->format($commission); ?><sup style="font-size: 20px">FCFA</sup></h3> <h3><?php echo Money::of($commission, $currency ? $currency->code : 'XAF')->formatTo('fr_FR'); ?></h3>
<p><?php echo $this->lang->line('Solde Commission') ?></p> <p><?php echo $this->lang->line('Solde Commission') ?></p>
</div> </div>
<div class="icon"> <div class="icon">

View File

@ -7,6 +7,7 @@
href="<?php echo base_url('bower_components/datatables.net-bs/css/dataTables.bootstrap.min.css') ?>"> href="<?php echo base_url('bower_components/datatables.net-bs/css/dataTables.bootstrap.min.css') ?>">
<?php <?php
use Brick\Money\Money;
function convertDate($date) function convertDate($date)
{ {
$month = null; $month = null;
@ -823,9 +824,9 @@ $fmt = new NumberFormatter( 'fr_FR', NumberFormatter::DECIMAL );
$fmt = new NumberFormatter( 'fr_FR', NumberFormatter::DECIMAL ); $fmt = new NumberFormatter( 'fr_FR', NumberFormatter::DECIMAL );
echo "<tr> echo "<tr>
<td>" . $walletHyper->first_row()->lastname . "</td> <td>" . $walletHyper->first_row()->lastname . "</td>
<td>" . $fmt->format($walletHyper->first_row()->balance_princ) . "</td> <td>" . Money::of($walletHyper->first_row()->balance_princ, $currency ? $currency->code : 'XAF')->formatTo('fr_FR'). "</td>
<td>" . $fmt->format($walletHyper->first_row()->balance_com) . "</td> <td>" .Money::of($walletHyper->first_row()->balance_com, $currency ? $currency->code : 'XAF')->formatTo('fr_FR'). "</td>
<td>" . $fmt->format($totalCommissionBanque) . "</td>"; <td>" .Money::of($totalCommissionBanque, $currency ? $currency->code : 'XAF')->formatTo('fr_FR') . "</td>";
echo "<td>" . $depots->num_rows() . "</td> echo "<td>" . $depots->num_rows() . "</td>
<td>" . $retraits->num_rows() . "</td> <td>" . $retraits->num_rows() . "</td>

View File

@ -92,6 +92,7 @@
} }
</style> </style>
<?php <?php
use Brick\Money\Money;
function convertDate($date){ function convertDate($date){
$month = null; $month = null;
switch ($date) { switch ($date) {
@ -261,7 +262,7 @@
<div class="col-lg-4 col-xs-6"> <div class="col-lg-4 col-xs-6">
<div class="small-box bg-aqua"> <div class="small-box bg-aqua">
<div class="inner"> <div class="inner">
<h3><?php echo $fmt->format($principal); ?><sup style="font-size: 20px">FCFA</sup></h3> <h3><?php echo $principal ?></h3>
<p><?php echo $this->lang->line('Solde Principal') ?></p> <p><?php echo $this->lang->line('Solde Principal') ?></p>
</div> </div>
<div class="icon"> <div class="icon">
@ -273,7 +274,7 @@
<div class="col-lg-4 col-xs-6"> <div class="col-lg-4 col-xs-6">
<div class="small-box bg-green"> <div class="small-box bg-green">
<div class="inner"> <div class="inner">
<h3><?php echo $fmt->format($commission); ?><sup style="font-size: 20px">FCFA</sup></h3> <h3><?php echo $commission; ?></h3>
<p><?php echo $this->lang->line('Solde Commission') ?></p> <p><?php echo $this->lang->line('Solde Commission') ?></p>
</div> </div>
<div class="icon"> <div class="icon">
@ -285,7 +286,7 @@
<div class="col-lg-4 col-xs-6"> <div class="col-lg-4 col-xs-6">
<div class="small-box bg-yellow"> <div class="small-box bg-yellow">
<div class="inner"> <div class="inner">
<h3><?php echo $fmt->format($totalCommissionBanque); ?><sup style="font-size: 20px">FCFA</sup></h3> <h3><?php echo $totalCommissionBanque; ?></h3>
<p><?php echo $this->lang->line('Total commission de la banque') ?></p> <p><?php echo $this->lang->line('Total commission de la banque') ?></p>
</div> </div>
<div class="icon"> <div class="icon">
@ -993,7 +994,6 @@
</thead> </thead>
<tbody> <tbody>
<?php <?php
if($superviseurs!=false){ if($superviseurs!=false){
foreach($superviseurs->result() as $row) { foreach($superviseurs->result() as $row) {
$wallet = null; $wallet = null;
@ -1011,8 +1011,8 @@
} }
echo "<tr> echo "<tr>
<td>".$row->lastname."</td> <td>".$row->lastname."</td>
<td>".$fmt->format($princ)."</td> <td>".Money::of($princ, $this->session->userdata('currency_code'))->formatTo('fr_FR')."</td>
<td>".$fmt->format($com)."</td>"; <td>".Money::of($com, $this->session->userdata('currency_code'))->formatTo('fr_FR')."</td>";
$nb_depots = 0; $nb_depots = 0;
$nb_retraits = 0; $nb_retraits = 0;
$commission_banque = 0; $commission_banque = 0;
@ -1028,7 +1028,7 @@
$commission_banque+= $retrait->commission_banque; $commission_banque+= $retrait->commission_banque;
} }
} }
echo "<td>".$fmt->format($commission_banque)."</td> echo "<td>".Money::of($commission_banque, $this->session->userdata('currency_code'))->formatTo('fr_FR')."</td>
<td>".$nb_depots."</td> <td>".$nb_depots."</td>
<td>".$nb_retraits."</td> <td>".$nb_retraits."</td>
</tr>"; </tr>";

View File

@ -11,6 +11,7 @@
<?php echo $this->lang->line('paying_networks_accounts')?> <?php echo $this->lang->line('paying_networks_accounts')?>
</h1> </h1>
<?php <?php
use Brick\Money\Money;
$site_url = base_url(); $site_url = base_url();
if ($alert == "ok") { if ($alert == "ok") {
@ -94,7 +95,7 @@
} }
?> ?>
<td> <td>
<?= $fmt->format($row->balance_com)?> <?= Money::of($row->balance_com, $row->currency_code ? $row->currency_code : 'XAF')->formatTo('fr_FR')?>
</td> </td>
<?php <?php
} }

View File

@ -7,6 +7,13 @@
<div class="content-wrapper"> <div class="content-wrapper">
<?php <?php
use Carbon\Carbon; use Carbon\Carbon;
use Brick\Money\CurrencyConverter;
use Brick\Money\ExchangeRateProvider\PDOProvider;
use Brick\Money\ExchangeRateProvider\PDOProviderConfiguration;
use Brick\Money\ExchangeRateProvider\BaseCurrencyProvider;
use Brick\Math\RoundingMode;
use Brick\Money\Money;
function toLocateDate($date , $timezone){ function toLocateDate($date , $timezone){
if($date){ if($date){
$carbon = Carbon::createFromFormat('Y-m-d H:i:s', $date, 'UTC'); $carbon = Carbon::createFromFormat('Y-m-d H:i:s', $date, 'UTC');
@ -49,6 +56,27 @@
<?php <?php
} }
} }
// 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);
?> ?>
</section> </section>
<section class="content"> <section class="content">
@ -93,7 +121,8 @@
<th align='center'>Type</th> <th align='center'>Type</th>
<th align='center'>Operation</th> <th align='center'>Operation</th>
<th><?php echo $this->lang->line('cart_number') ?></th> <th><?php echo $this->lang->line('cart_number') ?></th>
<th><?php echo $this->lang->line('customer_net_amount') ?></th> <th><?php echo $this->lang->line('customer_net_amount_init') ?></th>
<th><?php echo $this->lang->line('customer_net_amount_final') ?></th>
<th><?php echo $this->lang->line('fees') ?></th> <th><?php echo $this->lang->line('fees') ?></th>
<th><?php echo $this->lang->line('tax') ?></th> <th><?php echo $this->lang->line('tax') ?></th>
<th><?php echo $this->lang->line('Commission de la banque') ?></th> <th><?php echo $this->lang->line('Commission de la banque') ?></th>
@ -124,18 +153,21 @@
}else{ }else{
$net = $row->montant_retrait ; $net = $row->montant_retrait ;
} }
$moneyNetInit = Money::of($net, $row->init_currency );
$moneyNetFinal = $converter->convert($moneyNetInit, $row->final_currency ? $row->final_currency : 'XAF', RoundingMode::DOWN);
echo "<tr> echo "<tr>
<td align='center' >$row->id</td> <td align='center' >$row->id</td>
<td>".strtoupper($type)."</td> <td>".strtoupper($type)."</td>
<td>".strtoupper($row->acteur).' - '.$row->operation."</td> <td>".strtoupper($row->acteur).' - '.$row->operation."</td>
<td>".join(" ", str_split($row->numero_carte, 4))."</td> <td>".join(" ", str_split($row->numero_carte, 4))."</td>
<td>".$fmt->format($net)."</td> <td>".$moneyNetInit->formatTo('fr_FR')."</td>
<td>".$fmt->format( $row->frais)."</td> <td>".$moneyNetFinal->formatTo('fr_FR')."</td>
<td>".$fmt->format( $row->taxe)."</td> <td>".Money::of($row->frais, $row->init_currency)->formatTo('fr_FR')."</td>
<td>".$fmt->format( $row->commission_banque)."</td> <td>".Money::of($row->taxe, $row->init_currency)->formatTo('fr_FR')."</td>
<td>".$fmt->format( $row->commission_hyp)."</td> <td>".Money::of($row->commission_banque ? $row->commission_banque : 0, $row->init_currency)->formatTo('fr_FR')."</td>
<td>".$fmt->format( $row->commission_sup)."</td> <td>".Money::of($row->commission_hyp ? $row->commission_hyp : 0, $row->init_currency)->formatTo('fr_FR')."</td>
<td>".$fmt->format( $row->commission_ag)."</td> <td>".Money::of($row->commission_sup ? $row->commission_sup : 0 , $row->init_currency)->formatTo('fr_FR')."</td>
<td>".Money::of($row->commission_ag ? $row->commission_ag : 0, $row->init_currency)->formatTo('fr_FR')."</td>
<td>".$row->agent."</td> <td>".$row->agent."</td>
<td>".$row->user."</td> <td>".$row->user."</td>
<td>".toLocateDate($row->date,$this->session->userdata('timezone'))."</td>"; <td>".toLocateDate($row->date,$this->session->userdata('timezone'))."</td>";
@ -205,7 +237,7 @@
$('#transactions').DataTable({ $('#transactions').DataTable({
"aaSorting": [[ 0, "desc" ]], "aaSorting": [[ 0, "desc" ]],
"columnDefs": [ { "columnDefs": [ {
targets: 13, targets: 14,
render: $.fn.dataTable.render.moment( 'YYYY-MM-DD HH:mm:ss' , 'D MMMM YYYY HH:mm:ss', format) render: $.fn.dataTable.render.moment( 'YYYY-MM-DD HH:mm:ss' , 'D MMMM YYYY HH:mm:ss', format)
}] }]
}); });