+ Add Configuration of taxes and interest rates in Nano credit

This commit is contained in:
Djery-Tom 2020-08-14 17:21:08 +01:00
parent 945db8569b
commit 7afc3c28fd
6 changed files with 699 additions and 76 deletions

View File

@ -1778,8 +1778,9 @@ class Gestion extends CI_Controller
if($this->isLogged()) { if($this->isLogged()) {
if(isset($_POST)) { if(isset($_POST)) {
$idConfig = $_POST['id_config']; $idConfig = $_POST['id_config'];
$taxes = isset($_POST['taxes']) ? $_POST['taxes'] : null ; $taxes = isset($_POST['taxes']) ? $_POST['taxes'] : null;
$this->insertTaxes($taxes, $idConfig); $categorie = isset($_POST['categorie']) ? $_POST['categorie'] : 'wallet';
$this->insertTaxes($taxes, $idConfig, $categorie);
$res = true; $res = true;
if ($res) { if ($res) {
@ -1802,7 +1803,7 @@ class Gestion extends CI_Controller
foreach ($palier as $p) { foreach ($palier as $p) {
$array = json_decode(json_encode($p), true); $array = json_decode(json_encode($p), true);
$row = []; $row = [];
foreach ($array as $key => $value){ foreach ($array as $key => $value) {
$row[] = $value; $row[] = $value;
} }
$this->user_model->addPalierConfigWallet($name, $idConfig, $row[0], $row[1], $row[2]); $this->user_model->addPalierConfigWallet($name, $idConfig, $row[0], $row[1], $row[2]);
@ -1810,21 +1811,25 @@ class Gestion extends CI_Controller
} }
} }
private function insertTaxes($palier , $idConfig){ private function insertTaxes($palier, $idConfig, $categorie)
{
$exist = $this->user_model->getTaxes($idConfig); $exist = $this->user_model->getTaxes($idConfig, $categorie);
if($exist){ if ($exist) {
$this->user_model->deleteTaxes($idConfig); $this->user_model->deleteTaxes($idConfig, $categorie);
} }
if($palier) { if ($palier) {
foreach ($palier as $p) { foreach ($palier as $p) {
$array = json_decode(json_encode($p), true); $array = json_decode(json_encode($p), true);
$row = []; $row = [];
foreach ($array as $key => $value){ foreach ($array as $key => $value) {
$row[] = $value; $row[] = $value;
} }
if ($categorie == 'wallet')
$this->user_model->addTaxe($idConfig, $row[0], $row[1], $row[2], $row[3]); $this->user_model->addTaxe($idConfig, $row[0], $row[1], $row[2], $row[3]);
else
$this->user_model->addTaxe($idConfig, $row[0], $row[1], $row[2], 'national', $categorie);
} }
} }
} }

View File

@ -1192,6 +1192,9 @@ class Hyperviseur_dash extends CI_Controller
if ($this->isLogged()) { if ($this->isLogged()) {
$data['hasWallet'] = $this->user_model->getConfigWallet($this->session->userdata('network_id')); $data['hasWallet'] = $this->user_model->getConfigWallet($this->session->userdata('network_id'));
$data['groups'] = $this->user_model->getUsersGroups($this->session->userdata('network_id')); $data['groups'] = $this->user_model->getUsersGroups($this->session->userdata('network_id'));
$data['idConfig'] = $data['hasWallet']->first_row()->id;
$data['rates'] = $this->user_model->getNanoCreditRates($data['idConfig']);
$data['taxes'] = $this->user_model->getTaxes($data['idConfig'], 'nano_credit');
$data['active'] = "nano_credit"; $data['active'] = "nano_credit";
$data['alert'] = ""; $data['alert'] = "";
$data['game_pays'] = $this->user_model->getGameCountry(); $data['game_pays'] = $this->user_model->getGameCountry();
@ -1231,6 +1234,44 @@ class Hyperviseur_dash extends CI_Controller
} }
} }
} }
public function saveNanoCreditRates()
{
if ($this->isLogged()) {
if (isset($_POST)) {
$idConfig = $_POST['id_config'];
$rates = isset($_POST['rates']) ? $_POST['rates'] : null;
$this->insertNanoCreditRates($rates, $idConfig);
$res = true;
if ($res) {
echo json_encode("200");
} else {
echo json_encode("500");
}
}
}
}
private function insertNanoCreditRates($palier, $idConfig)
{
$exist = $this->user_model->getNanoCreditRates($idConfig);
if ($exist) {
$this->user_model->deleteNanoCreditRates($idConfig);
}
if ($palier) {
foreach ($palier as $p) {
$array = json_decode(json_encode($p), true);
$row = [];
foreach ($array as $key => $value) {
$row[] = $value;
}
$this->user_model->addNanoCreditRates($idConfig, $row[0], $row[1]);
}
}
}
} }
class Operation class Operation

View File

@ -456,4 +456,16 @@ $lang['credit_limit'] = 'Credit limit';
$lang['nano_credit_removal'] = 'Removal of nano credit'; $lang['nano_credit_removal'] = 'Removal of nano credit';
$lang['set_credit_limit'] = 'Set the credit limit'; $lang['set_credit_limit'] = 'Set the credit limit';
$lang['nano_credit_deleted'] = 'Nano credit deleted'; $lang['nano_credit_deleted'] = 'Nano credit deleted';
$lang['users_groups'] = 'Customer groups';
$lang['nano_credit_history'] = 'History of nano credits';
$lang['group_code'] = 'Group code';
$lang['creator'] = 'Creator';
$lang['credit_limit'] = 'Credit limit';
$lang['wallet_management'] = 'Wallet management';
$lang['nano_credit_management'] = 'Management of nano credit';
$lang['change_interest_rates'] = 'Change interest rates';
$lang['interest_rates'] = 'Interest rate';
$lang['interest_rates_period'] = 'Period (in months)';
$lang['nano_credit_update'] = 'Update nano credit';
$lang['transaction_nano_credit'] = 'Taxes on nano credit';
?> ?>

View File

@ -475,4 +475,9 @@ $lang['creator'] = 'Createur';
$lang['credit_limit'] = 'Limite de credit'; $lang['credit_limit'] = 'Limite de credit';
$lang['wallet_management'] = 'Gestion du wallet'; $lang['wallet_management'] = 'Gestion du wallet';
$lang['nano_credit_management'] = 'Gestion du nano credit'; $lang['nano_credit_management'] = 'Gestion du nano credit';
$lang['change_interest_rates'] = 'Modifier les taux d\'intérêts';
$lang['interest_rates'] = 'Taux d\'intérêts';
$lang['interest_rates_period'] = 'Période (en mois)';
$lang['nano_credit_update'] = 'Mise à jour du nano crédit';
$lang['transaction_nano_credit'] = 'Taxes sur le nano crédit';
?> ?>

View File

@ -2263,47 +2263,53 @@ class User_model extends CI_Model
} }
// Wallet ilink // Wallet ilink
public function addPalierConfigWallet($type , $idConfig ,$min, $max ,$taux){ public function addPalierConfigWallet($type, $idConfig, $min, $max, $taux)
{
$sql = "INSERT INTO `paliersConfigWallet` (`type`, `min`, `max`, `taux`, `idConfig`) VALUES (?,?,?,?,?);"; $sql = "INSERT INTO `paliersConfigWallet` (`type`, `min`, `max`, `taux`, `idConfig`) VALUES (?,?,?,?,?);";
$query = $this->db->query($sql , array($type,$min, $max , $taux ,$idConfig)); $query = $this->db->query($sql, array($type, $min, $max, $taux, $idConfig));
return $query; return $query;
} }
public function addTaxe($idConfig ,$nom, $type ,$valeur , $destination){ public function addTaxe($idConfig, $nom, $type, $valeur, $destination, $categorie = 'wallet')
$sql = "INSERT INTO `taxes` (`nom`, `type`, `valeur`, `destination`, `idConfig`) VALUES (?,?,?,?,?);"; {
$query = $this->db->query($sql , array($nom,$type, $valeur , $destination ,$idConfig)); $sql = "INSERT INTO `taxes` (`nom`, `type`, `valeur`, `destination`,`categorie`, `idConfig`) VALUES (?,?,?,?,?,?);";
$query = $this->db->query($sql, array($nom, $type, $valeur, $destination, $categorie, $idConfig));
return $query; return $query;
} }
public function updatePalierConfigWallet($id ,$min , $max ,$taux){ public function updatePalierConfigWallet($id, $min, $max, $taux)
{
$sql = "UPDATE `paliersConfigWallet` SET `min` = ? , `max` = ? , `taux` = ? WHERE (`id` = ?);"; $sql = "UPDATE `paliersConfigWallet` SET `min` = ? , `max` = ? , `taux` = ? WHERE (`id` = ?);";
$query = $this->db->query($sql , array($min, $max , $taux , $id)); $query = $this->db->query($sql, array($min, $max, $taux, $id));
return $query; return $query;
} }
public function getPalierConfigWallet($type , $idConfig){ public function getPalierConfigWallet($type, $idConfig)
{
$sql = "SELECT * FROM `paliersConfigWallet` WHERE (`type` = ? AND `idConfig` = ? );"; $sql = "SELECT * FROM `paliersConfigWallet` WHERE (`type` = ? AND `idConfig` = ? );";
$query = $this->db->query($sql , array($type,$idConfig)); $query = $this->db->query($sql, array($type, $idConfig));
if($query->num_rows()>0){ if ($query->num_rows() > 0) {
return $query; return $query;
}else{ } else {
return false; return false;
} }
} }
public function getTaxes($idConfig){ public function getTaxes($idConfig, $categorie = 'wallet')
$sql = "SELECT * FROM `taxes` WHERE (`idConfig` = ? );"; {
$query = $this->db->query($sql , array($idConfig)); $sql = "SELECT * FROM `taxes` WHERE (`idConfig` = ? AND `categorie` = ? );";
if($query->num_rows()>0){ $query = $this->db->query($sql, array($idConfig, $categorie));
if ($query->num_rows() > 0) {
return $query; return $query;
}else{ } else {
return false; return false;
} }
} }
public function getOnePalierConfigWallet($id){ public function getOnePalierConfigWallet($id)
{
$sql = "SELECT * FROM `paliersConfigWallet` WHERE (`id` = ?);"; $sql = "SELECT * FROM `paliersConfigWallet` WHERE (`id` = ?);";
$query = $this->db->query($sql , array($id)); $query = $this->db->query($sql, array($id));
if($query->num_rows()>0){ if($query->num_rows()>0){
return $query; return $query;
}else{ }else{
@ -2311,23 +2317,26 @@ class User_model extends CI_Model
} }
} }
public function deletePalierConfigWallet($type , $idConfig){ public function deletePalierConfigWallet($type, $idConfig)
{
$sql = "DELETE FROM `paliersConfigWallet` WHERE (`type` = ? AND `idConfig` = ? );"; $sql = "DELETE FROM `paliersConfigWallet` WHERE (`type` = ? AND `idConfig` = ? );";
$query = $this->db->query($sql , array($type,$idConfig)); $query = $this->db->query($sql, array($type, $idConfig));
return $query; return $query;
} }
public function deleteTaxes($idConfig){ public function deleteTaxes($idConfig, $categorie = 'wallet')
$sql = "DELETE FROM `taxes` WHERE (`idConfig` = ? );"; {
$query = $this->db->query($sql , array($idConfig)); $sql = "DELETE FROM `taxes` WHERE (`idConfig` = ? AND `categorie` = ? );";
$query = $this->db->query($sql, array($idConfig, $categorie));
return $query; return $query;
} }
public function updateConfigWalletIlink_a_s_c($taux_ag_s_c,$taux_sup_s_c,$taux_hyp_s_c,$idConfig){ public function updateConfigWalletIlink_a_s_c($taux_ag_s_c, $taux_sup_s_c, $taux_hyp_s_c, $idConfig)
{
$sql = "UPDATE `configWallet` SET `taux_com_ag_envoi_cash` = ?, `taux_com_sup_envoi_cash` = ?, `taux_com_hyp_envoi_cash` = ? WHERE (`id` = ?);"; $sql = "UPDATE `configWallet` SET `taux_com_ag_envoi_cash` = ?, `taux_com_sup_envoi_cash` = ?, `taux_com_hyp_envoi_cash` = ? WHERE (`id` = ?);";
$query = $this->db->query($sql , array($taux_ag_s_c,$taux_sup_s_c,$taux_hyp_s_c,$idConfig)); $query = $this->db->query($sql, array($taux_ag_s_c, $taux_sup_s_c, $taux_hyp_s_c, $idConfig));
return $query; return $query;
} }
@ -2693,4 +2702,29 @@ class User_model extends CI_Model
return false; return false;
} }
} }
public function getNanoCreditRates($idConfig)
{
$sql = "SELECT * FROM `paliersConfigNanoCredit` WHERE (`idConfig` = ? );";
$query = $this->db->query($sql, array($idConfig));
if ($query->num_rows() > 0) {
return $query;
} else {
return false;
}
}
public function deleteNanoCreditRates($idConfig)
{
$sql = "DELETE FROM `paliersConfigNanoCredit` WHERE (`idConfig` = ? );";
$query = $this->db->query($sql, array($idConfig));
return $query;
}
public function addNanoCreditRates($idConfig, $duree, $valeur)
{
$sql = "INSERT INTO `paliersConfigNanoCredit` (`duree_mois`, `taux`, `idConfig`) VALUES (?,?,?);";
$query = $this->db->query($sql, array($duree, $valeur, $idConfig));
return $query;
}
} }

View File

@ -6,7 +6,109 @@
<link rel="stylesheet" <link rel="stylesheet"
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') ?>">
<link rel="stylesheet" href="<?php echo base_url('bower_components/toastr/toastr.css') ?>"> <link rel="stylesheet" href="<?php echo base_url('bower_components/toastr/toastr.css') ?>">
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<style type="text/css">
.table-wrapper {
width: 700px;
margin: 30px auto;
background: #fff;
padding: 20px;
box-shadow: 0 1px 1px rgba(0, 0, 0, .05);
}
.table-title {
padding-bottom: 10px;
margin: 0 0 10px;
}
.table-title h2 {
margin: 6px 0 0;
font-size: 22px;
}
.table-title .add-new {
float: right;
height: 30px;
font-weight: bold;
font-size: 12px;
text-shadow: none;
min-width: 100px;
border-radius: 50px;
line-height: 13px;
}
.table-title .add-new i {
margin-right: 4px;
}
table.table {
table-layout: fixed;
}
table.table tr th, table.table tr td {
border-color: #e9e9e9;
}
table.table th i {
font-size: 13px;
margin: 0 5px;
cursor: pointer;
}
table.table th:last-child {
width: 100px;
}
table.table td a {
cursor: pointer;
display: inline-block;
margin: 0 5px;
min-width: 24px;
}
table.table td a.add {
color: #27C46B;
}
table.table td a.edit {
color: #FFC107;
}
table.table td a.delete {
color: #E34724;
}
table.table td i {
font-size: 19px;
}
table.table td a.add i {
font-size: 24px;
margin-right: -1px;
position: relative;
top: 3px;
}
table.table .form-control {
height: 32px;
line-height: 32px;
box-shadow: none;
border-radius: 2px;
}
/*table.table .form-control.error {*/
/* border-color: #f50000;*/
/*}*/
.error {
border-color: #f50000;
}
table.table td .add {
display: none;
}
</style>
<?php <?php
use Brick\Money\Money; use Brick\Money\Money;
@ -78,12 +180,87 @@ $context = new \Brick\Money\Context\AutoContext();
</div> </div>
<div class="row"> <div class="row">
<div class="col-lg-12"> <div class="col-lg-4">
<div class="margin"> <div class="margin">
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#modal-limit" <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#modal-limit"
style="width: 100%"><?php echo $this->lang->line('change_the_credit_limit') ?></button> style="width: 100%"><?php echo $this->lang->line('change_the_credit_limit') ?></button>
</div> </div>
</div> </div>
<div class="col-lg-4">
<div class="margin">
<button type="button" class="btn btn-success" data-toggle="modal" data-target="#modal-rates"
style="width: 100%"><?php echo $this->lang->line('change_interest_rates') ?></button>
</div>
</div>
<div class="col-lg-4">
<div class="margin">
<button type="button" class="btn btn-info" data-toggle="modal" data-target="#modal-tax"
style="width: 100%"><?php echo $this->lang->line('edit_tax') ?></button>
</div>
</div>
</div>
<div class="row centered">
<div class="col-lg-3 col-lg-offset-2 col-xs-12">
<div class="box">
<div class="box-header">
<h3 class="box-title"><?php echo $this->lang->line('interest_rates'); ?></h3>
</div>
<div class="box-body table-responsive" style="overflow-x:auto;">
<table class="table table-hover">
<thead>
<tr>
<th><?php echo $this->lang->line('interest_rates_period'); ?> </th>
<th><?php echo $this->lang->line('rate'); ?> </th>
</tr>
</thead>
<tbody>
<?php
if ($rates != false) {
foreach ($rates->result() as $row) {
echo "<tr>
<td>" . $row->duree_mois . "</td>
<td>" . $row->taux . "</td>" . '
</tr>';
}
}
?>
</tbody>
</table>
</div>
</div>
</div>
<div class="col-lg-4 col-xs-12">
<div class="box">
<div class="box-header">
<h3 class="box-title"><?php echo $this->lang->line('transaction_nano_credit'); ?></h3>
</div>
<div class="box-body table-responsive" style="overflow-x:auto;">
<table class="table table-hover">
<thead>
<tr>
<th><?php echo $this->lang->line('Nom'); ?> </th>
<th>Type</th>
<th>Valeur</th>
</tr>
</thead>
<tbody>
<?php
if ($taxes != false) {
foreach ($taxes->result() as $row) {
echo "<tr>
<td>" . $row->nom . "</td>
<td>" . $row->type . "</td>
<td>" . $row->valeur . "</td>" . '
</tr>';
}
}
?>
</tbody>
</table>
</div>
</div>
</div>
</div> </div>
<div class="row"> <div class="row">
@ -198,6 +375,140 @@ $context = new \Brick\Money\Context\AutoContext();
</div> </div>
</div> </div>
</div> </div>
<div class="modal fade" id="modal-rates">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
<h3 class="modal-title"><?php echo $this->lang->line('change_interest_rates'); ?></h3>
</div>
<div class="modal-body">
<form id="ratesForm">
<div class="row">
<div class="col-lg-12">
<div class="form-group">
<div class="table-title">
<div class="row">
<div class="col-sm-8">
<label for="nom"
class="col-form-label"><?php echo $this->lang->line('interest_rates'); ?></label>
</div>
<div class="col-sm-4">
<button type="button" class="btn btn-info add-new new5"><i
class="fa fa-plus"></i> <?php echo $this->lang->line('new_rate'); ?>
</button>
</div>
</div>
</div>
<table id="rates" class="table table-bordered">
<thead>
<tr>
<th><?php echo $this->lang->line('interest_rates_period'); ?></th>
<th><?php echo $this->lang->line('rate'); ?></th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php
if ($rates != false) {
foreach ($rates->result() as $row) {
echo "<tr>
<td>" . $row->duree_mois . "</td>
<td>" . $row->taux . "</td>" . '
<td>
<a class="add add5" title="Add" data-toggle="tooltip"><i class="material-icons">&#xE03B;</i></a>
<a class="edit edit5" title="Edit" data-toggle="tooltip"><i class="material-icons">&#xE254;</i></a>
<a class="delete delete5" title="Delete" data-toggle="tooltip"><i class="material-icons">&#xE872;</i></a>
</td>
</tr>';
}
}
?>
</tbody>
</table>
</div>
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default pull-left"
data-dismiss="modal"><?php echo $this->lang->line('Fermer'); ?></button>
<button type="button" id="saveRates" data-network-id="<?= $network_id ?>"
data-id-config="<?= $idConfig ?>"
class="btn btn-primary"><?php echo $this->lang->line('Continuer'); ?></button>
</div>
</div>
</div>
</div>
<div class="modal fade" id="modal-tax">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
<h3 class="modal-title"><?php echo $this->lang->line('edit_tax'); ?></h3>
</div>
<div class="modal-body">
<form id="taxForm">
<div class="form-group" style="overflow-x:auto;">
<div class="table-title">
<div class="row">
<div class="col-sm-8">
<label for="nom"
class="col-form-label"><?php echo $this->lang->line('transaction_nano_credit'); ?></label>
</div>
<div class="col-sm-4">
<button type="button" class="btn btn-info add-new new51"><i
class="fa fa-plus"></i> <?php echo $this->lang->line('new_tax'); ?>
</button>
</div>
</div>
</div>
<table id="nano_credit_taxes" class="table table-bordered">
<thead>
<tr>
<th><?php echo $this->lang->line('Nom'); ?> </th>
<th>Type</th>
<th>Valeur</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php
if ($taxes != false) {
foreach ($taxes->result() as $row) {
echo "<tr>
<td>" . $row->nom . "</td>
<td>" . $row->type . "</td>
<td>" . $row->valeur . "</td>" . '
<td>
<a class="add add51" title="Add" data-toggle="tooltip"><i class="material-icons">&#xE03B;</i></a>
<a class="edit edit51" title="Edit" data-toggle="tooltip"><i class="material-icons">&#xE254;</i></a>
<a class="delete delete51" title="Delete" data-toggle="tooltip"><i class="material-icons">&#xE872;</i></a>
</td>
</tr>';
}
}
// ?>
</tbody>
</table>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default pull-left"
data-dismiss="modal"><?php echo $this->lang->line('Fermer'); ?></button>
<button type="button" id="saveTaxes" data-network-id="<?= $network_id ?>"
data-id-config="<?= $idConfig ?>"
class="btn btn-primary"><?php echo $this->lang->line('Continuer'); ?></button>
</div>
</div>
</div>
</div>
</section> </section>
</div> </div>
<!-- jQuery 3 --> <!-- jQuery 3 -->
@ -250,43 +561,7 @@ $context = new \Brick\Money\Context\AutoContext();
}); });
}) })
</script> </script>
<script>
var areaChartData = {
labels: <?php echo json_encode($label_months) ?>,
datasets: [
{
label: 'Electronics',
fillColor: 'rgba(255, 162, 0, 1)',
strokeColor: 'rgba(255, 162, 0, 1)',
pointColor: 'rgba(255, 162, 0, 1)',
pointStrokeColor: '#ffa200',
pointHighlightFill: '#fff',
pointHighlightStroke: 'rgba(220,220,220,1)',
data: <?php echo json_encode($depots_data) ?>
},
{
label: 'Digital Goods',
fillColor: 'rgba(0, 187, 255, 1)',
strokeColor: 'rgba(0, 187, 255, 1)',
pointColor: '#00bbff',
pointStrokeColor: 'rgba(0, 187, 255, 1)',
pointHighlightFill: '#fff',
pointHighlightStroke: 'rgba(0, 187, 255, 1)',
data: <?php echo json_encode($retraits_data) ?>
}
]
};
var Pie = '<?php echo json_encode($pieChart) ?>';
if (Pie === '[]') {
var select = document.getElementById('chart2');
$(select.children).hide();
$(select).append("<p>Aucune transaction</p>");
} else {
Pie = JSON.parse(Pie);
}
</script>
<script> <script>
toastr.options.closeButton = true; toastr.options.closeButton = true;
toastr.options.closeMethod = 'fadeOut'; toastr.options.closeMethod = 'fadeOut';
@ -315,7 +590,7 @@ $context = new \Brick\Money\Context\AutoContext();
if (data == '200') { if (data == '200') {
Swal.fire({ Swal.fire({
icon: 'success', icon: 'success',
title: "<?php echo $this->lang->line('activate_nano_credit')?>", title: "<?php echo $this->lang->line('update_credit_limit')?>",
text: "<?php echo $this->lang->line('informations_updated')?>", text: "<?php echo $this->lang->line('informations_updated')?>",
timer: 3000 timer: 3000
}).then(() => { }).then(() => {
@ -342,6 +617,257 @@ $context = new \Brick\Money\Context\AutoContext();
} }
}); });
$('#saveRates').click(function () {
const network_id = $(this).data('network-id');
const id_config = $(this).data('id-config');
// Paliers
var rates = [];
$('#rates tr').has('td').each(function () {
var arrayItem = {};
$('td', $(this)).each(function (index, item) {
if (index < 2) {
if (index == 1)
arrayItem[index] = parseFloat($(item).html());
arrayItem[index] = parseInt($(item).html());
}
});
rates.push(arrayItem);
});
if ($('#ratesForm')[0].checkValidity()) {
console.log(rates)
$.ajax({
url: '<?php echo base_url('index.php/Hyperviseur_dash/saveNanoCreditRates')?>',
type: 'POST',
dataType: 'json',
data: {
"id_config": id_config,
"rates": rates,
},
success: function (data) {
if (data == '200') {
Swal.fire({
icon: 'success',
title: "<?php echo $this->lang->line('nano_credit_update')?>",
text: "<?php echo $this->lang->line('informations_updated')?>",
timer: 3000
}).then(() => {
location.reload();
});
} else {
toastr.error("<?php echo $this->lang->line('error_message')?>", "<?php echo $this->lang->line('request_error')?>");
}
},
error: function (resultat, statut, error) {
console.log(resultat + " " + error);
toastr.error("<?php echo $this->lang->line('error_message')?>", "<?php echo $this->lang->line('request_error')?>");
}
});
} else {
$('#ratesForm')[0].reportValidity();
}
});
$('#saveTaxes').click(function () {
const network_id = $(this).data('network-id');
const id_config = $(this).data('id-config');
// Paliers
var taxes = [];
$('#nano_credit_taxes tr').has('td').each(function () {
var arrayItem = {};
$('td', $(this)).each(function (index, item) {
if (index < 3) {
if (index == 2)
arrayItem[index] = parseFloat($(item).html());
arrayItem[index] = $(item).html();
}
});
taxes.push(arrayItem);
});
if ($('#taxForm')[0].checkValidity()) {
$.ajax({
url: '<?php echo base_url('index.php/Gestion/saveTaxes')?>',
type: 'POST',
dataType: 'json',
data: {
"categorie": 'nano_credit', "id_config": id_config,
"taxes": taxes,
},
success: function (data) {
if (data == '200') {
Swal.fire({
icon: 'success',
title: "<?php echo $this->lang->line('nano_credit_update')?>",
text: "<?php echo $this->lang->line('informations_updated')?>",
timer: 3000
}).then(() => {
location.reload();
});
} else {
toastr.error("<?php echo $this->lang->line('error_message')?>", "<?php echo $this->lang->line('request_error')?>");
}
},
error: function (resultat, statut, error) {
console.log(resultat + " " + error);
toastr.error("<?php echo $this->lang->line('error_message')?>", "<?php echo $this->lang->line('request_error')?>");
}
});
} else {
$('#taxForm')[0].reportValidity();
}
});
</script>
<script>
// Interets nano credits
$(document).ready(function () {
$('[data-toggle="tooltip"]').tooltip();
var actions5 = $("#rates td:last-child").html();
// Append table with add row form on add new button click
$(".new5").click(function () {
if (!actions5) {
actions5 = '<a class="add add5" title="Add" data-toggle="tooltip"><i class="material-icons">&#xE03B;</i></a>\n' +
' <a class="edit edit5" title="Edit" data-toggle="tooltip"><i class="material-icons">&#xE254;</i></a>\n' +
' <a class="delete delete5" title="Delete" data-toggle="tooltip"><i class="material-icons">&#xE872;</i></a>';
}
$(this).attr("disabled", "disabled");
var index = $("#rates tbody tr:last-child").index();
var row = "<tr> <td><input type='number' min='1' required class='form-control' name='time' id='time'></td> " +
"<td><input type='number' required class='form-control' name='rate' id='rate'></td>" +
"<td>" + actions5 + "</td>" +
"</tr>";
$("#rates").append(row);
$("#rates tbody tr").eq(index + 1).find(".add, .edit").toggle();
$('[data-toggle="tooltip"]').tooltip();
});
// Add row on add button click
$(document).on("click", ".add5", function () {
var empty = false;
var input = $(this).parents("tr").find('input');
var select = $(this).parents("tr").find('select');
input.each(function () {
if (!$(this)[0].checkValidity()) {
$(this).addClass("error");
$(this)[0].reportValidity();
empty = true;
} else {
$(this).removeClass("error");
}
});
$(this).parents("tr").find(".error").first().focus();
if (!empty) {
select.each(function () {
$(this).parent("td").html($(this).val());
});
input.each(function () {
$(this).parent("td").html($(this).val());
});
$(this).parents("tr").find(".add, .edit").toggle();
$(".new5").removeAttr("disabled");
}
});
// Edit row on edit button click
$(document).on("click", ".edit5", function () {
$(this).parents("tr").find("td:not(:last-child)").each(function (index) {
if (index == 0)
$(this).html('<input type="number" required class="form-control" value="' + $(this).text() + '">');
if (index == 1)
$(this).html('<input type="number" required class="form-control" value="' + $(this).text() + '">');
});
$(this).parents("tr").find(".add, .edit").toggle();
$(".new5").attr("disabled", "disabled");
});
// Delete row on delete button click
$(document).on("click", ".delete5", function () {
$(this).parents("tr").remove();
$(".new5").removeAttr("disabled");
});
});
</script>
<script>
// Taxes nano credit
$(document).ready(function () {
$('[data-toggle="tooltip"]').tooltip();
var actions51 = $("#nano_credit_taxes td:last-child").html();
// Append table with add row form on add new button click
$(".new51").click(function () {
if (!actions51) {
actions51 = '<a class="add add51" title="Add" data-toggle="tooltip"><i class="material-icons">&#xE03B;</i></a>\n' +
' <a class="edit edit51" title="Edit" data-toggle="tooltip"><i class="material-icons">&#xE2514;</i></a>\n' +
' <a class="delete delete51" title="Delete" data-toggle="tooltip"><i class="material-icons">&#xE872;</i></a>';
}
$(this).attr("disabled", "disabled");
var index = $("#nano_credit_taxes tbody tr:last-child").index();
var row = "<tr> <td><input type='text' required class='form-control' name='nom' id='nom'></td> " +
"<td> <select class='form-control' id='type' required> <option value='%'> % </option> <option value='fixe'> fixe </option> </select> </td> " +
"<td><input type='number' required class='form-control' min='0' name='valeur' id='valeur'></td>" +
"<td>" + actions51 + "</td>" +
"</tr>";
$("#nano_credit_taxes").append(row);
$("#nano_credit_taxes tbody tr").eq(index + 1).find(".add, .edit").toggle();
$('[data-toggle="tooltip"]').tooltip();
});
// Add row on add button click
$(document).on("click", ".add51", function () {
var empty = false;
var input = $(this).parents("tr").find('input');
var select = $(this).parents("tr").find('select');
input.each(function () {
if (!$(this)[0].checkValidity()) {
$(this).addClass("error");
$(this)[0].reportValidity();
empty = true;
} else {
$(this).removeClass("error");
}
});
$(this).parents("tr").find(".error").first().focus();
if (!empty) {
select.each(function () {
$(this).parent("td").html($(this).val());
});
input.each(function () {
$(this).parent("td").html($(this).val());
});
$(this).parents("tr").find(".add, .edit").toggle();
$(".new51").removeAttr("disabled");
}
});
// Edit row on edit button click
$(document).on("click", ".edit51", function () {
$(this).parents("tr").find("td:not(:last-child)").each(function (index) {
if (index == 0)
$(this).html('<input type="text" required class="form-control" value="' + $(this).text() + '">');
if (index == 1)
$(this).html("<select class='form-control' id='type' required> <option value='%' > % </option> <option value='fixe'> fixe </option> </select>");
if (index == 2)
$(this).html('<input type="number" required class="form-control" min="0" value="' + $(this).text() + '">');
});
$(this).parents("tr").find(".add, .edit").toggle();
$(".new51").attr("disabled", "disabled");
});
// Delete row on delete button click
$(document).on("click", ".delete51", function () {
$(this).parents("tr").remove();
$(".new51").removeAttr("disabled");
});
});
</script> </script>
<!-- Page script --> <!-- Page script -->
<!--<script src="--><?php //echo base_url('dist/js/custom.js') ?><!--"></script>--> <!--<script src="--><?php //echo base_url('dist/js/custom.js') ?><!--"></script>-->