backoffice/application/views/calculator.php

303 lines
11 KiB
PHP
Raw Normal View History

<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;
$config = $hasWallet->first_row();
2020-06-09 15:06:44 +00:00
$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 = $plr_agent_depot_wallet ? $plr_agent_depot_wallet->result() : [];
$plr_agent_cash_cash = $plr_agent_cash_cash ? $plr_agent_cash_cash->result() : [];
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){
2020-06-09 15:06:44 +00:00
return (($palier->min + $palier->max)/2 * $palier->taux /100 );
}else{
if($montant < $min)
return $min* $paliers[0]->taux /100;
else if ($montant > $max)
2020-06-09 15:06:44 +00:00
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);
?>
<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">
<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 ><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,0), @$d->currency_code);
$money2 = $converter->convert($money2, @$f->currency_code, RoundingMode::DOWN);
$moneyFrais = Money::of(round(@$frais,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>
<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>
</div>
</div>
</div>
</div>
</div>
<?php }?>
<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';"
})
</script>