backoffice/application/views/calculator.php

572 lines
24 KiB
PHP
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<link rel="stylesheet"
href="<?php echo base_url('bower_components/datatables.net-bs/css/dataTables.bootstrap.min.css') ?>">
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-multiselect/0.9.15/css/bootstrap-multiselect.css">
<link rel="stylesheet" href="<?php echo base_url('bower_components/toastr/toastr.css') ?>">
<?php
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;
extract($_POST);
//$showResult = false;
//$frais = 0;
//$taxe = 0;
//$config = $hasWallet->first_row();
////Simulateur
//$com_ag = $this->session->userdata('com_ag') ? $this->session->userdata('com_ag') : 0 ;
//$com_sup = $this->session->userdata('com_sup') ? $this->session->userdata('com_sup') : 0 ;
//$com_hyp = $this->session->userdata('com_hyp') ? $this->session->userdata('com_hyp') : 0 ;
//$com_bq = $this->session->userdata('com_bq') ? $this->session->userdata('com_bq') : 0 ;
//$frais_retrait = $this->session->userdata('frais_retrait') ? $this->session->userdata('frais_retrait') : 0 ;
//$plr_user_wallet_wallet = $plr_user_wallet_wallet ? $plr_user_wallet_wallet->result() : [];
//$plr_user_wallet_cash = $plr_user_wallet_cash ? $plr_user_wallet_cash->result() : [];
//$plr_agent_depot_wallet_ilink = $plr_agent_depot_wallet_ilink ? $plr_agent_depot_wallet_ilink->result() : [];
//$plr_agent_depot_autre_wallet = $plr_agent_depot_autre_wallet ? $plr_agent_depot_autre_wallet->result() : [];
//$plr_agent_cash_cash = $plr_agent_cash_cash ? $plr_agent_cash_cash->result() : [];
//
//$plr_user_wallet_wallet_national = $plr_user_wallet_wallet_national ? $plr_user_wallet_wallet_national->result() : [];
//$plr_user_wallet_cash_national = $plr_user_wallet_cash_national ? $plr_user_wallet_cash_national->result() : [];
//$plr_agent_depot_wallet_ilink_national = $plr_agent_depot_wallet_ilink_national ? $plr_agent_depot_wallet_ilink_national->result() : [];
//$plr_agent_depot_autre_wallet_national = $plr_agent_depot_autre_wallet_national ? $plr_agent_depot_autre_wallet_national->result() : [];
//$plr_agent_cash_cash_national = $plr_agent_cash_cash_national ? $plr_agent_cash_cash_national->result() : [];
//
//$taxes = $taxes ? $taxes->result() : [];
//$taxesNationales = array_filter($taxes, function ($tax) {
// return $tax->destination == 'national';
//});
//
//$taxesInternationales = array_filter($taxes, function ($tax) {
// return $tax->destination == 'international';
//});
//
//if (isset($save)) {
// $showResult = true;
// switch ($operation) {
// case 1: //Envoi wallet à wallet
// $frais = ($init_country != $final_country) ? calculateFees1($plr_user_wallet_wallet, $montant) : calculateFees1($plr_user_wallet_wallet_national, $montant);
// $taxe = ($init_country != $final_country) ? calculateTax($taxesInternationales , $frais) : calculateTax($taxesNationales ,$frais);
//
// $com_hyp += $frais ;
// $this->session->set_userdata('com_hyp',$com_hyp);
// break;
// case 2: //Envoi de wallet à carte
// $frais = $montant * $config->taux_com_user_wallet_carte / 100;
//// $taxe = ($init_country != $final_country) ? calculateTax($taxesInternationales , $frais) : calculateTax($taxesNationales ,$frais);
//
// $com_hyp += $frais ;
// $this->session->set_userdata('com_hyp',$com_hyp);
// break;
// case 3: //Envoi de wallet à cash
// $frais = ($init_country != $final_country) ? calculateFees1($plr_user_wallet_cash, $montant) : calculateFees1($plr_user_wallet_cash_national, $montant);
// $taxe = ($init_country != $final_country) ? calculateTax($taxesInternationales , $frais) : calculateTax($taxesNationales ,$frais);
//
// $com_hyp += $frais ;
// $this->session->set_userdata('com_hyp',$com_hyp);
// $this->session->set_userdata('frais_retrait',$frais);
// break;
// case 4: //Envoi de wallet à banque
// // Non disponible
// //Pas de taxes
// break;
//// case 5: //Envoi de carte à wallet
//// $frais =$montant * $config->taux_com_user_carte_wallet / 100;
////// $taxe = ($init_country != $final_country) ? calculateTax($taxesInternationales , $frais) : calculateTax($taxesNationales ,$frais);
//// break;
//// case 6: //Envoi de carte à cash
//// $frais =$montant * $config->taux_com_user_carte_cash / 100;
////// $taxe = ($init_country != $final_country) ? calculateTax($taxesInternationales , $frais) : calculateTax($taxesNationales ,$frais);
//// break;
// case 9: // Retrait de wallet en cash
// $frais = ($init_country != $final_country) ? calculateFees1($plr_user_wallet_cash, $montant) : calculateFees1($plr_user_wallet_cash_national, $montant);
// $taxe = ($init_country != $final_country) ? calculateTax($taxesInternationales , $frais) : calculateTax($taxesNationales ,$frais);
//
// $com_hyp += $frais ;
// $this->session->set_userdata('com_hyp',$com_hyp);
// break;
// case 10: //Retrait de carte vers wallet
// $frais = $montant * $config->taux_com_user_carte_wallet / 100;
//
// $com_hyp += $frais * $config->taux_com_hyp_retrait_carte_cash / 100 ;
// $com_bq += $frais * $config->taux_com_banque_retrait_carte_cash / 100 ;
// $this->session->set_userdata('com_hyp',$com_hyp);$this->session->set_userdata('com_bq',$com_bq);
// break;
// case 11: // Retrait de carte vers cash
// $frais = $montant * $config->taux_com_user_carte_cash / 100;
//
// $com_hyp += $frais * $config->taux_com_hyp_retrait_carte_cash / 100 ;
// $com_bq += $frais * $config->taux_com_banque_retrait_carte_cash / 100 ;
// $this->session->set_userdata('com_hyp',$com_hyp);$this->session->set_userdata('com_bq',$com_bq);
// break;
// case 12: // Agent - Retrait en cash
//// empty
////Sauvegarder les frais lors de chaque operation d'envoi
// $com_ag += $frais_retrait * $config->taux_com_ag_retrait_cash/ 100 ;
// $com_sup += $frais_retrait * $config->taux_com_sup_retrait_cash/ 100 ;
// $com_hyp -= ($com_ag + $com_sup);
// $this->session->set_userdata('com_ag',$com_ag);$this->session->set_userdata('com_sup',$com_sup);
// $this->session->set_userdata('com_hyp',$com_hyp);
// break;
// case 13: // Agent - Retrait de la carte vers cash
// $frais = $montant * $config->taux_com_wallet_ag_carte_cash / 100;
//
// $com_ag += $frais * $config->taux_com_ag_retrait_carte_cash/ 100 ;
// $com_sup += $frais * $config->taux_com_sup_retrait_carte_cash / 100 ;
// $com_hyp += $frais * $config->taux_com_hyp_retrait_carte_cash / 100 ;
// $com_bq += $frais * $config->taux_com_banque_retrait_carte_cash / 100 ;
// $this->session->set_userdata('com_ag',$com_ag);$this->session->set_userdata('com_sup',$com_sup);
// $this->session->set_userdata('com_hyp',$com_hyp);$this->session->set_userdata('com_bq',$com_bq);
// break;
// case 14: // Agent - Envoi de cash vers wallet iLink
// $frais = ($init_country != $final_country) ? calculateFees1($plr_agent_depot_wallet_ilink, $montant) : calculateFees1($plr_agent_depot_wallet_ilink_national, $montant);
// $taxe = ($init_country != $final_country) ? calculateTax($taxesInternationales , $frais) : calculateTax($taxesNationales ,$frais);
// $com_ag += $frais * $config->taux_com_ag_envoi_cash / 100 ;
// $com_sup += $frais * $config->taux_com_sup_envoi_cash / 100 ;
// $com_hyp += $frais * $config->taux_com_hyp_envoi_cash / 100 ;
// $this->session->set_userdata('com_ag',$com_ag);$this->session->set_userdata('com_sup',$com_sup);
// $this->session->set_userdata('com_hyp',$com_hyp);
// break;
// case 15: // Agent - Envoi de cash vers autre wallet
// $frais = ($init_country != $final_country) ? calculateFees1($plr_agent_depot_autre_wallet, $montant) : calculateFees1($plr_agent_depot_autre_wallet_national, $montant);
// $taxe = ($init_country != $final_country) ? calculateTax($taxesInternationales , $frais) : calculateTax($taxesNationales ,$frais);
// $com_ag += $frais * $config->taux_com_ag_envoi_cash / 100 ;
// $com_sup += $frais * $config->taux_com_sup_envoi_cash / 100 ;
// $com_hyp += $frais * $config->taux_com_hyp_envoi_cash / 100 ;
// $this->session->set_userdata('com_ag',$com_ag);$this->session->set_userdata('com_sup',$com_sup);
// $this->session->set_userdata('com_hyp',$com_hyp);
// break;
// case 16: // Agent - Envoi de cash vers une carte visa
// $frais = $montant * $config->taux_com_wallet_ag_envoi_cash_carte / 100;
// $com_ag += $frais * $config->taux_com_ag_depot_cash_carte/ 100 ;
// $com_sup += $frais * $config->taux_com_sup_depot_cash_carte / 100 ;
// $com_hyp += $frais * $config->taux_com_hyp_depot_cash_carte / 100 ;
// $com_bq += $frais * $config->taux_com_banque_depot_cash_carte / 100 ;
// $this->session->set_userdata('com_ag',$com_ag);$this->session->set_userdata('com_sup',$com_sup);
// $this->session->set_userdata('com_hyp',$com_hyp);$this->session->set_userdata('com_bq',$com_bq);
// break;
// case 17: // Agent - Envoi de cash vers cash
// $frais = ($init_country != $final_country) ? calculateFees1($plr_agent_cash_cash, $montant) : calculateFees1($plr_agent_cash_cash_national, $montant);
// $taxe = ($init_country != $final_country) ? calculateTax($taxesInternationales , $frais) : calculateTax($taxesNationales ,$frais);
// $com_ag += $frais * $config->taux_com_ag_envoi_cash / 100 ;
// $com_sup += $frais * $config->taux_com_sup_envoi_cash / 100 ;
// $com_hyp += $frais * $config->taux_com_hyp_envoi_cash / 100 ;
// $this->session->set_userdata('com_ag',$com_ag);$this->session->set_userdata('com_sup',$com_sup);
// $this->session->set_userdata('com_hyp',$com_hyp);
// break;
// case 18: // Agent - Envoi de cash vers banque
// // Indisponible
// break;
// }
//}
////Calcul des frais internationaux
//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->max) / 2 * $palier->taux / 100);
// } else {
// if ($montant < $min)
// return $min * $paliers[0]->taux / 100;
// else if ($montant > $max)
// return $max * $paliers[$size - 1]->taux / 100;
// }
//}
//
////Calcul des frais nationaux
//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;
//}
//
////Calcul des taxes
//function calculateTax(array $taxes, $frais)
//{
// $sommeTaux = 0;
// $sommeFixe = 0;
// foreach ($taxes as $tax) {
// if ($tax->type == '%')
// $sommeTaux += $tax->valeur;
//
// if ($tax->type == 'fixe')
// $sommeFixe += $tax->valeur;
// }
// return ($frais * $sommeTaux / 100) + $sommeFixe;
//}
// 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);
?>
<div class="content-wrapper">
<!-- Content Header (Page header) -->
<section class="content-header">
<h1>
<?php echo $this->lang->line('calculator'); ?>
</h1>
<?php
$site_url = base_url();
if ($alert == "ok") {
if (!$success == "ok") {
?>
<div class='alert alert-danger alert-dismissible col-xs-6'>
<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×</button>
<h4><i class='icon fa fa-ban'></i> Erreur!</h4>
<?php echo $message; ?>
</div>
<?php
} else {
?>
<div class="alert alert-success alert-dismissible col-xs-6">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
<h4><i class="icon fa fa-check"></i> Success!</h4>
<?php echo $message; ?>
</div>
<?php
}
}
?>
</section>
<section class="content">
<div class="row">
<div class="col-xs-12">
<div class="box">
<!-- <div class="box-header">-->
<!---->
<!-- </div>-->
<div class="box-body">
<form id="calculatorForm" class="form-content" method="post" action="<?php echo base_url('index.php/Hyperviseur_dash/calculator') ?>">
<div class="form-group">
<div class="row">
<div class="col-lg-3">
<label for="montant"> <?php echo $this->lang->line('Montant') ?></label>
<input type="text" required class="form-control" id="montant"
name="montant" value="<?php echo @$montant; ?>">
</div>
<div class="col-lg-3">
<?php
$result = $countries;
if ($result) {
$numrows = $result->num_rows();
if ($numrows > 0) { ?>
<label for="init_country"><?php echo $this->lang->line('departure_country') ?></label>
<select class="form-control" name="init_country" id="init_country"
required>
<?php foreach ($result->result() as $row) {
echo "<option value='" . $row->id . "'>" . $row->name . "</option>";
} ?>
</select>
<?php } else {
echo $this->lang->line('no_country');
}
?>
<?php } else {
echo $this->lang->line('no_country');
} ?>
</div>
<div class="col-lg-3">
<?php
$result = $operations;
if ($result) {
$numrows = sizeof($result);
if ($numrows > 0) { ?>
<label for="operation">Operation</label>
<select class="form-control" name="operation"
id="operation" <?php echo @$operation; ?> required>
<?php foreach ($result as $row) {
echo "<option value='" . $row->id . "'>" . $row->name . "</option>";
} ?>
</select>
<?php } else {
echo $this->lang->line('no_operation');
}
?>
<?php } else {
echo $this->lang->line('no_operation');
} ?>
</div>
<div class="col-lg-3">
<?php
$result = $countries;
if ($result) {
$numrows = $result->num_rows();
if ($numrows > 0) { ?>
<label for="final_country"><?php echo $this->lang->line('country_of_destination') ?></label>
<select class="form-control" name="final_country" id="final_country"
required>
<?php foreach ($result->result() as $row) {
echo "<option value='" . $row->id . "'>" . $row->name . "</option>";
} ?>
</select>
<?php } else {
echo $this->lang->line('no_country');
}
?>
<?php } else {
echo $this->lang->line('no_country');
} ?>
</div>
</div>
</div>
<?php if ($showResult) {
$r1 = array_filter($operations, function ($op) use ($operation) {
return $op->id == $operation;
});
$r2 = array_filter($countries->result(), function ($c) use ($init_country) {
return $c->id == $init_country;
});
$r3 = array_filter($countries->result(), function ($c) use ($final_country) {
return $c->id == $final_country;
});
$op = reset($r1);
$d = reset($r2);
$f = reset($r3);
?>
<div class="login-box" style="width: 600px;">
<h5 id="result" data-operation="<?=$op->id?>"><strong style="text-decoration: underline;">Resultat</strong>
: <?= @$op->name . ' du ' . $d->name . ' vers ' . $f->name ?></h5>
<div class="login-box-body">
<div class="row">
<?php
$money = Money::of(@$montant, @$d->currency_code);
$money2 = Money::of(round(@$montant - @$frais - @$taxe, 0), @$d->currency_code);
$money3 = Money::of(round(@$montant - @$frais - @$taxe, 0), @$d->currency_code);
$moneyTaxe = Money::of(round(@$taxe, 0), @$d->currency_code);
$money2 = $converter->convert($money2, @$f->currency_code, RoundingMode::DOWN);
$money3 = $converter->convert($money3, @$d->currency_code, RoundingMode::DOWN);
$moneyFrais = Money::of(round(@$frais, 0), @$d->currency_code);
$moneyTotalTaxe = Money::of(round(@$frais + @$taxe, 0), @$d->currency_code);
?>
<div class="col-lg-6 col-md-6">
<div>
<label> <?php echo $this->lang->line('amount_departure_country') ?></label>
<h4><?= $money->formatTo('fr_FR') ?></h4>
</div>
<div>
<label> Frais de la transaction</label>
<h4><?= $moneyFrais->formatTo('fr_FR') ?></h4>
</div>
<div>
<label>Taxe de la transaction </label>
<h4><?= $moneyTaxe->formatTo('fr-FR') ?></h4>
</div>
<div>
<label>Total frais + taxe de la transaction </label>
<h4><?= $moneyTotalTaxe->formatTo('fr-FR') ?></h4>
</div>
</div>
<div class="col-lg-6 col-md-6">
<div>
<label> <?php echo $this->lang->line('amount_country_of_destination') ?></label>
<h4><?= $money2->formatTo('fr_FR') ?></h4>
<h4><?= $money3->formatTo('fr_FR') ?></h4>
</div>
</div>
</div>
</div>
</div>
<?php } ?>
<div class="login-box" style="width: 600px;">
<h5><strong style="text-decoration: underline;">Simulateur</strong></h5>
<div class="login-box-body">
<div class="row" style="margin-bottom: 10px">
<div class="row">
<div class="col-lg-6" id="codePanel">
<label for="code">Code de retrait</label>
<input type="text" class="form-control" id="code"
name="code" value="">
</div>
<?php if(isset($error_simulateur)) {?>
<div class="col-lg-6">
<label for="code" class="text-red"><?= $error_simulateur?></label>
</div>
<?php } ?>
<?php if(isset($message_code)) {?>
<div class="col-lg-6">
<label for="code" class="text-green">Votre code de retrait</label>
<h4 class="text-green"><?= $message_code?></h4>
</div>
<?php } ?>
</div>
<?php if(isset($montant_retrait)) {
$currency = @$d->currency_code ? @$d->currency_code : 'XAF';
$moneyMontantRetrait = Money::of(round(@$montant_retrait, 0),$currency);
$moneyInit = Money::of(round(@$montant_init, 0),$currency);
$moneyFraisRetrait = Money::of(round(@$frais_retrait, 0),$currency);
?>
<div class="row" style="margin-top: 15px">
<div class="col-lg-4">
<label for="code">Montant de la transaction</label>
<h4> <?= $moneyInit->formatTo('fr_FR')?></h4>
</div>
<div class="col-lg-4">
<label for="code">Montant de retrait</label>
<h4><?= $moneyMontantRetrait->formatTo('fr_FR')?></h4>
</div>
<div class="col-lg-4">
<label for="code">Frais</label>
<h4><?= $moneyFraisRetrait->formatTo('fr_FR')?></h4>
</div>
</div>
<?php } ?>
</div>
<div class="row">
<?php
$currency = @$d->currency_code ? @$d->currency_code : 'XAF';
$moneyComAg = Money::of(round(@$com_ag, 0),$currency);
$moneyComSup = Money::of(round(@$com_sup, 0),$currency);
$moneyComHyp = Money::of(round(@$com_hyp, 0),$currency);
$moneyComBq = Money::of(round(@$com_bq, 0),$currency);
?>
<div class="col-lg-3 col-md-6">
<div>
<label>Commission de l'agent</label>
<h4> <?= $moneyComAg->formatTo('fr_FR')?></h4>
</div>
</div>
<div class="col-lg-3 col-md-6">
<div>
<label>Commission du superviseur</label>
<h4> <?= $moneyComSup->formatTo('fr_FR')?></h4>
</div>
</div>
<div class="col-lg-3 col-md-6">
<div>
<label>Commission de l'hyperviseur </label>
<h4> <?= $moneyComHyp->formatTo('fr_FR')?> </h4>
</div>
</div>
<div class="col-lg-3 col-md-6">
<div>
<label>Commission de la banque </label>
<h4> <?= $moneyComBq->formatTo('fr_FR')?> </h4>
</div>
</div>
</div>
</div>
</div>
<button type="submit"
name="save"
class="btn btn-warning btn-block openModal"><?php echo $this->lang->line('calculate'); ?></button>
</form>
</div>
</div>
</div>
</div>
</section>
</div>
<!-- jQuery 3 -->
<script src="<?php echo base_url('bower_components/jquery/dist/jquery.min.js') ?>"></script>
<!-- Bootstrap 3.3.7 -->
<script src="<?php echo base_url('bower_components/bootstrap/dist/js/bootstrap.min.js') ?>"></script>
<!-- DataTables -->
<script src="<?php echo base_url('bower_components/datatables.net/js/jquery.dataTables.min.js') ?>"></script>
<script src="<?php echo base_url('bower_components/datatables.net-bs/js/dataTables.bootstrap.min.js') ?>"></script>
<!-- Slimscroll -->
<script src="<?php echo base_url('bower_components/jquery-slimscroll/jquery.slimscroll.min.js') ?>"></script>
<!-- FastClick -->
<script src="<?php echo base_url('bower_components/fastclick/lib/fastclick.js') ?>"></script>
<!-- AdminLTE App -->
<script src="<?php echo base_url('dist/js/adminlte.min.js') ?>"></script>
<!-- AdminLTE for demo purposes -->
<script src="<?php echo base_url('dist/js/demo.js') ?>"></script>
<script src="<?php echo base_url('bower_components/toastr/toastr.js') ?>"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-multiselect/0.9.15/js/bootstrap-multiselect.js"></script>
<script src="<?php echo base_url('dist/js/sweetalert2.js') ?>"></script>
<script src="<?php echo base_url('bower_components/bootstrap-daterangepicker/daterangepicker.js') ?>"></script>
<script src="<?php echo base_url('bower_components/bootstrap-datepicker/dist/js/bootstrap-datepicker.min.js') ?>"></script>
<script src="https://cdn.jsdelivr.net/npm/autonumeric@4.5.4"></script>
<script>
$(function () {
anElement = new AutoNumeric('#montant', '', {
digitGroupSeparator: ' ',
decimalPlaces: '0',
minimumValue: '0',
maximumValue: '99999999999999999999999999'
});
$("#calculatorForm").submit(function (eventObj) {
var txt = document.getElementById('montant');
const montant = anElement.getNumber();
txt.value = montant;
return true;
});
//onLoad="document.getElementById('leave').options[0].selected = 'selected';"
var idOp = parseInt($('#result').data('operation'));
if(idOp == 12){
$('#codePanel').show();
}else{
$('#codePanel').hide();
}
$('#operation').change(function(){
if($(this).val() == 12){
$('#codePanel').show();
}else{
$('#codePanel').hide();
}
});
})
</script>