<link rel="stylesheet" href="<?php echo base_url('bower_components/jvectormap/jquery-jvectormap.css') ?>">
<link rel="stylesheet" href="<?php echo base_url('bower_components/bootstrap-datepicker/dist/css/bootstrap-datepicker.min.css') ?>">
<link rel="stylesheet" href="<?php echo base_url('bower_components/bootstrap-daterangepicker/daterangepicker.css') ?>">
<link rel="stylesheet" href="<?php echo base_url('plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.min.css') ?>">
<link rel="stylesheet" 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="https://fonts.googleapis.com/css?family=Roboto|Varela+Round|Open+Sans">
<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

use Brick\Money\Context\CustomContext;
use Brick\Money\Money;
$context = new \Brick\Money\Context\AutoContext();
    function convertDate($date){
        $month = null;
        switch ($date) {
            case "Jan":
                $month = 1;
                break;
            case "Feb":
                $month = 2;
                break;
            case "Mar":
                $month = 3;
                break;
            case "Apr":
                $month = 4;
                break;
            case "May":
                $month = 5;
                break;
            case "Jun":
                $month = 6;
                break;
            case "Jul":
                $month = 7;
                break;
            case "Aug":
                $month = 8;
                break;
            case "Sep":
                $month = 9;
                break;
            case "Oct":
                $month = 10;
                break;
            case "Nov":
                $month = 11;
                break;
            case "Dec":
                $month = 12;
                break;
        }
        return $month;
    }

    $month = time();
    $months[]=convertDate(date("M"));
    $label_months [] = date("M")." ".date("Y");
    $years[]= date("Y");
    for ($i = 1; $i <= 11; $i++) {
        $month = strtotime('last month', $month);
        $months [] = convertDate(date("M", $month));
        $years[] = date("Y", $month);
        $label_months [] = date("M", $month)." ".date("Y", $month);
    }

    /**
    ** Retraits
    **/
    $date = date("Y");

    $retraits_data[] = '';
    $retraits_data =array();
    for ($i = 1; $i <= 12; $i++) {
    	$retraits_query_mounth = array_filter($transactions, function ($trans) use ($i, $months ,$years){
			$month = date("m",strtotime($trans->date));
			$year = date("Y",strtotime($trans->date));
    		return $month == $months[$i-1] && $year == $years[$i-1] && $trans->type_transaction == 'retrait' ;
		});
        $retraits_data[] = sizeof($retraits_query_mounth);
    }

	$startDate = (new DateTime('01-'.$months[11].'-'.$years[11]))-> format('Y-m-d H:i:s');
	$endDate = date_create_from_format ('m/Y',$months[0].'/'.$years[0])-> format('Y-m-d H:i:s');

	$retraits = array_filter($transactions, function ($trans) use ($i, $endDate ,$startDate){
		$date = strtotime($trans->date);
//		return $date >= strtotime($startDate) && $date <= strtotime($endDate) && $trans->type == 'debit' ;
		return $trans->type_transaction == 'retrait' ;
	});

    /**
    ** Dépots
    **/
    $date = date("Y");

    $depots_data[] = '';
    $depots_data =array();
    for ($i = 1; $i <= 12; $i++) {
		$depots_query_mounth= array_filter($transactions, function ($trans) use ($i, $months ,$years){
			$month = date("m",strtotime($trans->date));
			$year = date("Y",strtotime($trans->date));
			return $month == $months[$i-1] && $year == $years[$i-1] && $trans->type_transaction == 'depot' ;
		});
        $depots_data[] = sizeof($depots_query_mounth);
    }
	$depots = array_filter($transactions, function ($trans) use ($i, $endDate ,$startDate){
		$date = strtotime($trans->date);
//		return $date >= strtotime($startDate) && $date <= strtotime($endDate) && $trans->type == 'credit' ;
		return $trans->type_transaction == 'depot' ;
	});

    if($transactions!=false){
        $transac=sizeof($transactions);
        $array_transac = array();
        $num = 0;
        if ($transac > 0) {
            foreach($transactions as $row) {
                $num++;
                $array_transac[] = $row->type_transaction;
            }
            $vals_transac = array_count_values($array_transac);
            $pieChart = array();
            foreach(array_keys($vals_transac) as $paramName) {
                $color = dechex(rand(0x000000, 0xFFFFFF));
                $trash = array("value" => $vals_transac[$paramName],
                    "color"    => "#".$color,
                    "highlight" => "#".$color,
                    "label" => $paramName);
    
                $pieChart[]= $trash;
            }
        }
    }else{
        $pieChart = array();
    }

	$fmt = new NumberFormatter( 'fr_FR', NumberFormatter::DECIMAL );
?>

<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">

        <h1>
            Wallet <?php echo $network . ' - ' .$country; ?>
        </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-lg-4 col-xs-6">
				<div class="small-box bg-aqua">
					<div class="inner">
						<h3><?php echo $principal ?></h3>
						<p><?php echo $this->lang->line('Solde Principal') ?></p>
					</div>
					<div class="icon">
						<i class="ion ion-cash"></i>
					</div>
				</div>
			</div>

			<div class="col-lg-4 col-xs-6">
                <div class="small-box bg-green">
                    <div class="inner">
                        <h3><?php echo $commission; ?></h3>
						<p><?php echo $this->lang->line('Solde Commission') ?></p>
                    </div>
                    <div class="icon">
                        <i class="ion ion-cash"></i>
                    </div>
				</div>
            </div>

			<div class="col-lg-4 col-xs-6">
				<div class="small-box bg-yellow">
					<div class="inner">
						<h3><?php echo $totalCommissionBanque; ?></h3>
						<p><?php echo $this->lang->line('Total commission de la banque') ?></p>
					</div>
					<div class="icon">
						<i class="ion ion-cash"></i>
					</div>
				</div>
			</div>
		</div>
		<div class="row">
			<div class="col-lg-4">
				<div class="margin">
					<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#modal-update"
							style="width: 100%"><?php echo $this->lang->line('Modifier la configuration') ?></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 class="col-lg-4">
				<div class="margin">
					<a href="<?php echo current_url().($network_id ? '?config=paying_networks' : '')?>" class="btn btn-success"
							style="width: 100%"><?php echo $this->lang->line('edit_paying_networks') ?></a>
				</div>
			</div>
		</div>
		<div class="row centered">
			<div class="col-lg-2  col-xs-6">
				<button type="button" class="btn btn-primary btn-block" data-toggle="modal" data-target="#rechargeAccount" style="white-space: normal;"><?php echo $this->lang->line('recharge_hypervisor_account') ?> </button>
			</div>
			<div class="col-lg-2 col-xs-6">
				<div class="small-box bg-aqua-active">
					<div class="inner">
						<h3><?php echo $taux_u_w_cart; ?><sup style="font-size: 20px">%</sup></h3>
						<p><?php echo $this->lang->line('rate_com_user_wallet_cart') ?> </p>
					</div>
					<div class="icon">
						<i class="ion ion-android-arrow-up"></i>
					</div>
				</div>
			</div>

			<div class="col-lg-2 col-xs-6">
				<div class="small-box bg-aqua-active">
					<div class="inner">
						<h3><?php echo $taux_u_c_w; ?><sup style="font-size: 20px">%</sup></h3>
						<p><?php echo $this->lang->line('rate_com_user_cart_wallet') ?></p>
					</div>
					<div class="icon">
						<i class="ion ion-android-arrow-up"></i>
					</div>
				</div>
			</div>

			<div class="col-lg-2 col-xs-6">
				<div class="small-box bg-aqua-active">
					<div class="inner">
						<h3><?php echo $taux_u_c_c; ?><sup style="font-size: 20px">%</sup></h3>
						<p><?php echo $this->lang->line('rate_com_user_cart_cash') ?></p>
					</div>
					<div class="icon">
						<i class="ion ion-android-arrow-up"></i>
					</div>
				</div>
			</div>
			<div class="col-lg-2 col-xs-6">
				<div class="small-box bg-aqua-active">
					<div class="inner">
						<h3><?php echo $taux_ag_d_c_c; ?><sup style="font-size: 20px">%</sup></h3>
						<p><?php echo $this->lang->line('rate_com_agent_depot_cash_cart') ?> </p>
					</div>
					<div class="icon">
						<i class="ion ion-android-arrow-up"></i>
					</div>
				</div>
			</div>
		</div>
		<div class="row">
<!--			répartition commission du réseau opération envoi et retrait de cash-->
			<div class="col-lg-2 col-xs-6">
				<div class="small-box bg-yellow-active">
					<div class="inner">
						<h3><?php echo $taux_ag_s_c; ?><sup style="font-size: 20px">%</sup></h3>
						<p><?php echo $this->lang->line('rate_com_agent_send_cash') ?></p>
					</div>
					<div class="icon">
						<i class="ion ion-android-arrow-up"></i>
					</div>
					<!--                    <a href="#" data-toggle="modal" data-target="#modal-update" data-type="taux_client_d" class="small-box-footer openModal">Modifier <i class="fa fa-arrow-circle-right"></i></a>-->
				</div>
			</div>

			<div class="col-lg-2 col-xs-6">
				<div class="small-box bg-yellow-active">
					<div class="inner">
						<h3><?php echo $taux_sup_s_c; ?><sup style="font-size: 20px">%</sup></h3>
						<p><?php echo $this->lang->line('rate_com_sup_send_cash') ?> </p>
					</div>
					<div class="icon">
						<i class="ion ion-android-arrow-up"></i>
					</div>
					<!--					<a href="#" data-toggle="modal" data-target="#modal-update" data-type="frais_d" class="small-box-footer openModal">Modifier <i class="fa fa-arrow-circle-right"></i></a>-->
				</div>
			</div>

			<div class="col-lg-2 col-xs-6">
				<div class="small-box bg-yellow-active">
					<div class="inner">
						<h3><?php echo $taux_hyp_s_c; ?><sup style="font-size: 20px">%</sup></h3>
						<p><?php echo $this->lang->line('rate_com_hyp_send_cash') ?> </p>
					</div>
					<div class="icon">
						<i class="ion ion-android-arrow-up"></i>
					</div>
					<!--                    <a href="#" data-toggle="modal" data-target="#modal-update" data-type="taux_ag_d" class="small-box-footer openModal">Modifier <i class="fa fa-arrow-circle-right"></i></a>-->
				</div>
			</div>

			<div class="col-lg-2 col-xs-6">
				<div class="small-box bg-red-active">
					<div class="inner">
						<h3><?php echo $taux_ag_r_c; ?><sup style="font-size: 20px">%</sup></h3>
						<p><?php echo $this->lang->line('rate_com_agent_remove_cash') ?> </p>
					</div>
					<div class="icon">
						<i class="ion ion-android-arrow-down"></i>
					</div>
					<!--					<a href="#" data-toggle="modal" data-target="#modal-update" data-type="taux_sup_d" class="small-box-footer openModal">Modifier <i class="fa fa-arrow-circle-right"></i></a>-->
				</div>
			</div>


			<div class="col-lg-2 col-xs-6">
				<div class="small-box bg-red-active">
					<div class="inner">
						<h3><?php echo $taux_sup_r_c; ?><sup style="font-size: 20px">%</sup></h3>
						<p><?php echo $this->lang->line('rate_com_sup_remove_cash') ?> </p>
					</div>
					<div class="icon">
						<i class="ion ion-android-arrow-down"></i>
					</div>
				</div>
			</div>

			<div class="col-lg-2 col-xs-6">
				<div class="small-box bg-red-active">
					<div class="inner">
						<h3><?php echo $taux_hyp_r_c; ?><sup style="font-size: 20px">%</sup></h3>
						<p><?php echo $this->lang->line('rate_com_hyp_remove_cash') ?> </p>
					</div>
					<div class="icon">
						<i class="ion ion-android-arrow-down"></i>
					</div>
				</div>
			</div>

		</div>
		<div class="row">
			<!--Taux  commission wallet agent carte client et Taux  commission wallet agent carte client-->
			<div class="col-lg-2 col-xs-6">
				<div class="small-box bg-green">
					<div class="inner">
						<h3><?php echo $taux_ag_cart_c; ?><sup style="font-size: 20px">%</sup></h3>
						<p><?php echo $this->lang->line('rate_com_agent_cart_cash') ?></p>
					</div>
					<div class="icon">
						<i class="ion ion-android-arrow-up"></i>
					</div>
				</div>
			</div>

			<div class="col-lg-2 col-xs-6">
				<div class="small-box bg-green">
					<div class="inner">
						<h3><?php echo $taux_ag_cash_c; ?><sup style="font-size: 20px">%</sup></h3>
						<p><?php echo $this->lang->line('rate_com_agent_cash_cart') ?> </p>
					</div>
					<div class="icon">
						<i class="ion ion-android-arrow-up"></i>
					</div>
					<!--					<a href="#" data-toggle="modal" data-target="#modal-update" data-type="frais_d" class="small-box-footer openModal">Modifier <i class="fa fa-arrow-circle-right"></i></a>-->
				</div>
			</div>

			<div class="col-lg-2 col-xs-6">
				<div class="small-box bg-olive-active">
					<div class="inner">
						<h3><?php echo $taux_ag_d_c; ?><sup style="font-size: 20px">%</sup></h3>
						<p><?php echo $this->lang->line('rate_com_agent_depot_cart') ?> </p>
					</div>
					<div class="icon">
						<i class="ion ion-android-arrow-down"></i>
					</div>
				</div>
			</div>

			<div class="col-lg-2 col-xs-6">
				<div class="small-box bg-olive-active">
					<div class="inner">
						<h3><?php echo $taux_sup_d_c; ?><sup style="font-size: 20px">%</sup></h3>
						<p><?php echo $this->lang->line('rate_com_sup_depot_cart') ?> </p>
					</div>
					<div class="icon">
						<i class="ion ion-android-arrow-down"></i>
					</div>
					<!--					<a href="#" data-toggle="modal" data-target="#modal-update" data-type="taux_sup_d" class="small-box-footer openModal">Modifier <i class="fa fa-arrow-circle-right"></i></a>-->
				</div>
			</div>


			<div class="col-lg-2 col-xs-6">
				<div class="small-box bg-olive-active">
					<div class="inner">
						<h3><?php echo $taux_hyp_d_c; ?><sup style="font-size: 20px">%</sup></h3>
						<p><?php echo $this->lang->line('rate_com_hyp_depot_cart') ?> </p>
					</div>
					<div class="icon">
						<i class="ion ion-android-arrow-down"></i>
					</div>
				</div>
			</div>

			<div class="col-lg-2 col-xs-6">
				<div class="small-box bg-olive-active">
					<div class="inner">
						<h3><?php echo $taux_bq_d_c; ?><sup style="font-size: 20px">%</sup></h3>
						<p><?php echo $this->lang->line('rate_com_bq_depot_cart') ?> </p>
					</div>
					<div class="icon">
						<i class="ion ion-android-arrow-down"></i>
					</div>
				</div>
			</div>

		</div>
		<div class="row">
			<!--Taux  commission wallet agent carte client et Taux  commission wallet agent carte client-->
			<div class="col-lg-2 col-lg-offset-2 col-xs-6">
				<div class="small-box bg-orange">
					<div class="inner">
						<h3><?php echo $taux_ag_r_cart; ?><sup style="font-size: 20px">%</sup></h3>
						<p><?php echo $this->lang->line('rate_com_agent_remove_cart') ?> </p>
					</div>
					<div class="icon">
						<i class="ion ion-android-arrow-up"></i>
					</div>
				</div>
			</div>

			<div class="col-lg-2 col-xs-6">
				<div class="small-box bg-orange">
					<div class="inner">
						<h3><?php echo $taux_sup_r_cart; ?><sup style="font-size: 20px">%</sup></h3>
						<p><?php echo $this->lang->line('rate_com_sup_remove_cart') ?> </p>
					</div>
					<div class="icon">
						<i class="ion ion-android-arrow-up"></i>
					</div>
				</div>
			</div>


			<div class="col-lg-2 col-xs-6">
				<div class="small-box bg-orange">
					<div class="inner">
						<h3><?php echo $taux_hyp_r_cart; ?><sup style="font-size: 20px">%</sup></h3>
						<p><?php echo $this->lang->line('rate_com_hyp_remove_cart') ?> </p>
					</div>
					<div class="icon">
						<i class="ion ion-android-arrow-up"></i>
					</div>
				</div>
			</div>

			<div class="col-lg-2 col-xs-6">
				<div class="small-box bg-orange">
					<div class="inner">
						<h3><?php echo $taux_bq_r_cart; ?><sup style="font-size: 20px">%</sup></h3>
						<p><?php echo $this->lang->line('rate_com_bq_remove_cart') ?> </p>
					</div>
					<div class="icon">
						<i class="ion ion-android-arrow-up"></i>
					</div>
				</div>
			</div>
		</div>
		<div class="row">
			<!--Taux  commission wallet agent carte client et Taux  commission wallet agent carte client-->
			<div class="col-lg-2 col-lg-offset-2 col-xs-6">
				<div class="small-box bg-light-blue-active">
					<div class="inner">
						<h3><?php echo $taux_hyp_s_wallet_cart_ilink; ?><sup style="font-size: 20px">%</sup></h3>
						<p><?php echo $this->lang->line('rate_com_hyp_send_wallet_cart_ilink') ?> </p>
					</div>
					<div class="icon">
						<i class="ion ion-android-arrow-up"></i>
					</div>
				</div>
			</div>

			<div class="col-lg-2 col-xs-6">
				<div class="small-box bg-light-blue-active">
					<div class="inner">
						<h3><?php echo $taux_bq_s_wallet_cart_ilink; ?><sup style="font-size: 20px">%</sup></h3>
						<p><?php echo $this->lang->line('rate_com_bq_send_wallet_cart_ilink') ?> </p>
					</div>
					<div class="icon">
						<i class="ion ion-android-arrow-up"></i>
					</div>
				</div>
			</div>


			<div class="col-lg-2 col-xs-6">
				<div class="small-box bg-teal-active">
					<div class="inner">
						<h3><?php echo $taux_hyp_r_cart_ilink; ?><sup style="font-size: 20px">%</sup></h3>
						<p><?php echo $this->lang->line('rate_com_hyp_remove_cart_ilink') ?> </p>
					</div>
					<div class="icon">
						<i class="ion ion-android-arrow-up"></i>
					</div>
				</div>
			</div>

			<div class="col-lg-2 col-xs-6">
				<div class="small-box bg-teal-active">
					<div class="inner">
						<h3><?php echo $taux_bq_r_cart_ilink; ?><sup style="font-size: 20px">%</sup></h3>
						<p><?php echo $this->lang->line('rate_com_bq_remove_cart_ilink') ?> </p>
					</div>
					<div class="icon">
						<i class="ion ion-android-arrow-up"></i>
					</div>
				</div>
			</div>
		</div>
		<div class="row centered">
			<div class="col-lg-3  col-xs-12">
				<div class="box">
					<div class="box-header">
						<h3 class="box-title"><?php echo $this->lang->line('rate_com_user_wallet_wallet_international'); ?></h3>
					</div>
					<!-- /.box-header -->
					<div class="box-body table-responsive" style="overflow-x:auto;">
						<table class="table table-hover">
							<tbody>
							<tr>
								<th>Min</th>
								<th>Max</th>
								<th>Taux (%)</th>
							</tr>
							<?php
							if($plr_user_wallet_wallet!=false){
								foreach($plr_user_wallet_wallet->result() as $row) {
									echo "<tr>
																	<td>".$fmt->format($row->min)."</td>
																	<td>".$fmt->format($row->max)."</td>
																	  <td>".$row->taux."</td>".'
																	 </tr>';
								}
							}
							?>
							</tbody>
						</table>
					</div>
					<!-- /.box-body -->
				</div>
				<div class="box">
					<div class="box-header">
						<h3 class="box-title"><?php echo $this->lang->line('rate_com_user_wallet_wallet_national'); ?></h3>
					</div>
					<!-- /.box-header -->
					<div class="box-body table-responsive" style="overflow-x:auto;">
						<table class="table table-hover">
							<tbody>
							<tr>
								<th>Min</th>
								<th>Max</th>
								<th>Taux (%)</th>
							</tr>
							<?php
							if($plr_user_wallet_wallet_national!=false){
								foreach($plr_user_wallet_wallet_national->result() as $row) {
									echo "<tr>
																	<td>".$fmt->format($row->min)."</td>
																	<td>".$fmt->format($row->max)."</td>
																	  <td>".$row->taux."</td>".'
																	 </tr>';
								}
							}
							?>
							</tbody>
						</table>
					</div>
					<!-- /.box-body -->
				</div>
			</div>
			<div class="col-lg-3  col-xs-12">
				<div class="box">
					<div class="box-header">
						<h3 class="box-title"><?php echo $this->lang->line('rate_com_user_wallet_cash_international'); ?></h3>
					</div>
					<!-- /.box-header -->
					<div class="box-body table-responsive" style="overflow-x:auto;">
						<table class="table table-hover">
							<tbody>
							<tr>
								<th>Min</th>
								<th>Max</th>
								<th>Taux (%)</th>
							</tr>
							<?php
							if($plr_user_wallet_cash!=false){
								foreach($plr_user_wallet_cash->result() as $row) {
									echo "<tr>
																		<td>".$fmt->format($row->min)."</td>
																		<td>".$fmt->format($row->max)."</td>
																		  <td>".$row->taux."</td>".'
																		 </tr>';
								}
							}
							?>
							</tbody>
						</table>
					</div>
					<!-- /.box-body -->
				</div>
				<div class="box">
					<div class="box-header">
						<h3 class="box-title"><?php echo $this->lang->line('rate_com_user_wallet_cash_national'); ?></h3>
					</div>
					<!-- /.box-header -->
					<div class="box-body table-responsive" style="overflow-x:auto;">
						<table class="table table-hover">
							<tbody>
							<tr>
								<th>Min</th>
								<th>Max</th>
								<th>Taux (%)</th>
							</tr>
							<?php
							if($plr_user_wallet_cash_national!=false){
								foreach($plr_user_wallet_cash_national->result() as $row) {
									echo "<tr>
																		<td>".$fmt->format($row->min)."</td>
																		<td>".$fmt->format($row->max)."</td>
																		  <td>".$row->taux."</td>".'
																		 </tr>';
								}
							}
							?>
							</tbody>
						</table>
					</div>
					<!-- /.box-body -->
				</div>
			</div>
			<div class="col-lg-3  col-xs-12">
				<div class="box">
					<div class="box-header">
						<h3 class="box-title"><?php echo $this->lang->line('rate_com_agent_depot_wallet_international'); ?></h3>
					</div>
					<!-- /.box-header -->
					<div class="box-body table-responsive" style="overflow-x:auto;">
						<table class="table table-hover">
							<tbody>
							<tr>
								<th>Min</th>
								<th>Max</th>
								<th>Taux (%)</th>
							</tr>
							<?php
							if($plr_agent_depot_wallet_ilink!=false){
								foreach($plr_agent_depot_wallet_ilink->result() as $row) {
									echo "<tr>
																		<td>".$fmt->format($row->min)."</td>
																		<td>".$fmt->format($row->max)."</td>
																		  <td>".$row->taux."</td>".'
																		 </tr>';
								}
							}
							?>
							</tbody>
						</table>
					</div>
					<!-- /.box-body -->
				</div>
				<div class="box">
					<div class="box-header">
						<h3 class="box-title"><?php echo $this->lang->line('rate_com_agent_depot_wallet_national'); ?></h3>
					</div>
					<!-- /.box-header -->
					<div class="box-body table-responsive" style="overflow-x:auto;">
						<table class="table table-hover">
							<tbody>
							<tr>
								<th>Min</th>
								<th>Max</th>
								<th>Taux (%)</th>
							</tr>
							<?php
							if($plr_agent_depot_wallet_ilink_national!=false){
								foreach($plr_agent_depot_wallet_ilink_national->result() as $row) {
									echo "<tr>
																		<td>".$fmt->format($row->min)."</td>
																		<td>".$fmt->format($row->max)."</td>
																		  <td>".$row->taux."</td>".'
																		 </tr>';
								}
							}
							?>
							</tbody>
						</table>
					</div>
					<!-- /.box-body -->
				</div>
			</div>
			<div class="col-lg-3  col-xs-12">
				<div class="box">
					<div class="box-header">
						<h3 class="box-title"><?php echo $this->lang->line('rate_com_agent_depot_autre_wallet_international'); ?></h3>
					</div>
					<!-- /.box-header -->
					<div class="box-body table-responsive" style="overflow-x:auto;">
						<table class="table table-hover">
							<tbody>
							<tr>
								<th>Min</th>
								<th>Max</th>
								<th>Taux (%)</th>
							</tr>
							<?php
							if($plr_agent_depot_autre_wallet!=false){
								foreach($plr_agent_depot_autre_wallet->result() as $row) {
									echo "<tr>
																		<td>".$fmt->format($row->min)."</td>
																		<td>".$fmt->format($row->max)."</td>
																		  <td>".$row->taux."</td>".'
																		 </tr>';
								}
							}
							?>
							</tbody>
						</table>
					</div>
					<!-- /.box-body -->
				</div>
				<div class="box">
					<div class="box-header">
						<h3 class="box-title"><?php echo $this->lang->line('rate_com_agent_depot_autre_wallet_national'); ?></h3>
					</div>
					<!-- /.box-header -->
					<div class="box-body table-responsive" style="overflow-x:auto;">
						<table class="table table-hover">
							<tbody>
							<tr>
								<th>Min</th>
								<th>Max</th>
								<th>Taux (%)</th>
							</tr>
							<?php
							if($plr_agent_depot_autre_wallet_national!=false){
								foreach($plr_agent_depot_autre_wallet_national->result() as $row) {
									echo "<tr>
																		<td>".$fmt->format($row->min)."</td>
																		<td>".$fmt->format($row->max)."</td>
																		  <td>".$row->taux."</td>".'
																		 </tr>';
								}
							}
							?>
							</tbody>
						</table>
					</div>
					<!-- /.box-body -->
				</div>
			</div>
		</div>
		<div class="row centered">
			<div class="col-lg-4 col-lg-offset-2 col-xs-12">
				<div class="box">
					<div class="box-header">
						<h3 class="box-title"><?php echo $this->lang->line('rate_com_agent_cash_cash_international'); ?></h3>
					</div>
					<!-- /.box-header -->
					<div class="box-body table-responsive" style="overflow-x:auto;">
						<table class="table table-hover">
							<tbody>
							<tr>
								<th>Min</th>
								<th>Max</th>
								<th>Taux (%)</th>
							</tr>
							<?php
							if($plr_agent_cash_cash!=false){
								foreach($plr_agent_cash_cash->result() as $row) {
									echo "<tr>
																			<td>".$fmt->format($row->min)."</td>
																			<td>".$fmt->format($row->max)."</td>
																			  <td>".$row->taux."</td>".'
																			 </tr>';
								}
							}
							?>
							</tbody>
						</table>
					</div>
					<!-- /.box-body -->
				</div>
				<div class="box">
					<div class="box-header">
						<h3 class="box-title"><?php echo $this->lang->line('rate_com_agent_cash_cash_national'); ?></h3>
					</div>
					<!-- /.box-header -->
					<div class="box-body table-responsive" style="overflow-x:auto;">
						<table class="table table-hover">
							<tbody>
							<tr>
								<th>Min</th>
								<th>Max</th>
								<th>Taux (%)</th>
							</tr>
							<?php
							if($plr_agent_cash_cash_national!=false){
								foreach($plr_agent_cash_cash_national->result() as $row) {
									echo "<tr>
																			<td>".$fmt->format($row->min)."</td>
																			<td>".$fmt->format($row->max)."</td>
																			  <td>".$row->taux."</td>".'
																			 </tr>';
								}
							}
							?>
							</tbody>
						</table>
					</div>
					<!-- /.box-body -->
				</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_taxes'); ?></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>
								<th>Destination</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>".$row->destination."</td>".'
																	 </tr>';
								}
							}
							?>
							</tbody>
						</table>
					</div>
				</div>
			</div>
		</div>

		<div class="row">
            <div class="col-xs-12">
                <div class="box box-success">
                    <div class="box-header with-border">
                        <h3 class="box-title"><?php echo $this->lang->line('Historique des 12 derniers mois'); ?></h3>
						<div class="box-tools">
							<a class="btn btn-success" href="<?php echo current_url().($network_id ? '?show=paying_networks' : '')?>">
								<?php echo $this->lang->line('paying_networks_accounts'); ?>
							</a>
							<a class="btn btn-primary" href="<?php echo current_url().($network_id ? '?history=transaction_ilink' : '')?>">
								<?php echo $this->lang->line('transactions_historic'); ?>
							</a>
							<a class="btn btn-info" href="<?php echo current_url().($network_id ? '?history=recharge' : '')?>">
								<?php echo $this->lang->line('recharge_historic'); ?>
							</a>
						</div>
                    </div>
                    <div class="box-body">
                        <div class="chart" id="chart">
                            <canvas id="barChart" style="height:230px"></canvas>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-xs-6">
                <div class="box box-danger">
                    <div class="box-header with-border">
                        <h3 class="box-title"><?php echo $this->lang->line("Parts dépots & retraits"); ?></h3>
                    </div>
                    <div class="box-body" id="chart2">
                        <canvas id="pieChart" style="height:250px"></canvas>
                    </div>
                </div>
            </div>

            <div class="col-xs-6">
                <div class="box">
                    <div class="box-header">
                        <h3 class="box-title"><?php echo  $this->lang->line('Commissions Superviseurs') ?></h3>
                    </div>
                    <div class="box-body" style="overflow-x:auto;">
                        <table id="example1" class="table table-bordered table-hover">
                            <thead>
                            <tr>
								<?php
								   echo "<th>".$this->lang->line('Nom')."</th>
									<th>".$this->lang->line('Solde Principal')."</th>
									<th>".$this->lang->line('Solde Commission')."</th>
									<th>".$this->lang->line('Commission banque')."</th>
									<th>".$this->lang->line('DEPOT'). 's'."</th>
									<th>".$this->lang->line('RETRAIT').'s'."</th>";
								?>
                            </tr>
                            </thead>
                            <tbody>
                            <?php
                                if($superviseurs!=false){
                                        foreach($superviseurs->result() as $row) {
                                        	$wallet = null;
											foreach ($agentWalletInfos->result() as $value) {
												if ($value->agent_id == $row->agent_id) {
													$wallet = $value;
													break;
												}
											}
											$com = 0;
											$princ = 0;
											if($wallet) {
												$com = $wallet->balance_com;
												$princ = $wallet->balance_princ;
											}
                                            echo "<tr>
                                                    <td>".$row->lastname."</td>
                                                    <td>".Money::of(round($princ,2), $this->session->userdata('currency_code'),$context)->formatTo('fr_FR')."</td>
                                                      <td>".Money::of(round($com,2), $this->session->userdata('currency_code'),$context)->formatTo('fr_FR')."</td>";
											$nb_depots = 0;
											$nb_retraits = 0;
											$commission_banque = 0;
                                            foreach($depots as $depot){
                                                if($depot->code_parrain == $row->member_code) {
													$nb_depots ++;
													$commission_banque+= $depot->commission_banque;
												}
                                            }
											foreach($retraits as $retrait){
												if($retrait->code_parrain == $row->member_code) {
													$nb_retraits ++;
													$commission_banque+= $retrait->commission_banque;
												}
											}
											echo "<td>".Money::of(round($commission_banque,2), $this->session->userdata('currency_code'),$context)->formatTo('fr_FR')."</td>
												  <td>".$nb_depots."</td>
                                				  <td>".$nb_retraits."</td>
                                                 </tr>";
                                        }

                                }
                            ?>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
			<div class="modal fade" id="modal-update">
				<div class="modal-dialog" style="max-width: 1300px; width: 100%;">
					<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('Configuration du wallet'); ?></h3>
						</div>
						<div class="modal-body">
							<form id="walletForm">
							<div class="row">
								<div class="col-lg-4">
										<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('rate_com_user_wallet_wallet_international') ; ?></label>
													</div>
													<div class="col-sm-4">
														<button type="button" class="btn btn-info add-new new1"><i class="fa fa-plus"></i> <?php echo $this->lang->line('new_level') ; ?></button>
													</div>
												</div>
											</div>
											<table id="user_wallet_wallet" class="table table-bordered">
												<thead>
												<tr>
													<th>Min</th>
													<th>Max</th>
													<th><?php echo $this->lang->line('rate') ; ?> (%) </th>
													<th>Actions</th>
												</tr>
												</thead>
												<tbody>
												<?php
													if($plr_user_wallet_wallet!=false){
														foreach($plr_user_wallet_wallet->result() as $row) {
															echo "<tr>
																	<td>".$row->min."</td>
																	<td>".$row->max."</td>
																	  <td>".$row->taux."</td>".'
																	  <td>
																		<a class="add add1" title="Add" data-toggle="tooltip"><i class="material-icons">&#xE03B;</i></a>
																		<a class="edit edit1" title="Edit" data-toggle="tooltip"><i class="material-icons">&#xE254;</i></a>
																		<a class="delete delete1" title="Delete" data-toggle="tooltip"><i class="material-icons">&#xE872;</i></a>
																	</td>
																	 </tr>';
														}
													}
												?>
												</tbody>
											</table>
										</div>
										<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('rate_com_user_wallet_wallet_national') ; ?></label>
													</div>
													<div class="col-sm-4">
														<button type="button" class="btn btn-info add-new new7"><i class="fa fa-plus"></i> <?php echo $this->lang->line('new_level') ; ?></button>
													</div>
												</div>
											</div>
											<table id="user_wallet_wallet_national" class="table table-bordered">
												<thead>
												<tr>
													<th>Min</th>
													<th>Max</th>
													<th><?php echo $this->lang->line('rate') ; ?> (%) </th>
													<th>Actions</th>
												</tr>
												</thead>
												<tbody>
												<?php
												if($plr_user_wallet_wallet_national!=false){
													foreach($plr_user_wallet_wallet_national->result() as $row) {
														echo "<tr>
																	<td>".$row->min."</td>
																	<td>".$row->max."</td>
																	  <td>".$row->taux."</td>".'
																	  <td>
																		<a class="add add7" title="Add" data-toggle="tooltip"><i class="material-icons">&#xE03B;</i></a>
																		<a class="edit edit7" title="Edit" data-toggle="tooltip"><i class="material-icons">&#xE254;</i></a>
																		<a class="delete delete7" title="Delete" data-toggle="tooltip"><i class="material-icons">&#xE872;</i></a>
																	</td>
																	 </tr>';
													}
												}
												?>
												</tbody>
											</table>
										</div>
										<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('rate_com_user_wallet_cash_international') ; ?></label>
													</div>
													<div class="col-sm-4">
														<button type="button" class="btn btn-info add-new new2"><i class="fa fa-plus"></i> <?php echo $this->lang->line('new_level') ; ?></button>
													</div>
												</div>
											</div>
											<table id="user_wallet_cash" class="table table-bordered">
												<thead>
												<tr>
													<th>Min</th>
													<th>Max</th>
													<th><?php echo $this->lang->line('rate') ; ?> (%) </th>
													<th>Actions</th>
												</tr>
												</thead>
												<tbody>
													<?php
													if($plr_user_wallet_cash!=false){
														foreach($plr_user_wallet_cash->result() as $row) {
															echo "<tr>
																		<td>".$row->min."</td>
																		<td>".$row->max."</td>
																		  <td>".$row->taux."</td>".'
																		  <td>
																			<a class="add add2" title="Add" data-toggle="tooltip"><i class="material-icons">&#xE03B;</i></a>
																			<a class="edit edit2" title="Edit" data-toggle="tooltip"><i class="material-icons">&#xE254;</i></a>
																			<a class="delete delete3" title="Delete" data-toggle="tooltip"><i class="material-icons">&#xE872;</i></a>
																		</td>
																		 </tr>';
														}
													}
													?>
												</tbody>
											</table>
										</div>
										<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('rate_com_user_wallet_cash_national') ; ?></label>
													</div>
													<div class="col-sm-4">
														<button type="button" class="btn btn-info add-new new8"><i class="fa fa-plus"></i> <?php echo $this->lang->line('new_level') ; ?></button>
													</div>
												</div>
											</div>
											<table id="user_wallet_cash_national" class="table table-bordered">
												<thead>
												<tr>
													<th>Min</th>
													<th>Max</th>
													<th><?php echo $this->lang->line('rate') ; ?> (%) </th>
													<th>Actions</th>
												</tr>
												</thead>
												<tbody>
												<?php
												if($plr_user_wallet_cash_national!=false){
													foreach($plr_user_wallet_cash_national->result() as $row) {
														echo "<tr>
																		<td>".$row->min."</td>
																		<td>".$row->max."</td>
																		  <td>".$row->taux."</td>".'
																		  <td>
																			<a class="add add8" title="Add" data-toggle="tooltip"><i class="material-icons">&#xE03B;</i></a>
																			<a class="edit edit8" title="Edit" data-toggle="tooltip"><i class="material-icons">&#xE254;</i></a>
																			<a class="delete delete8" title="Delete" data-toggle="tooltip"><i class="material-icons">&#xE872;</i></a>
																		</td>
																		 </tr>';
													}
												}
												?>
												</tbody>
											</table>
										</div>
										<div class="form-group">
											<label for="taux_u_w_cart"
												   class="col-form-label"><?php echo $this->lang->line('rate_com_user_wallet_cart') . ' (%)'; ?></label>
											<input type="number" min="0" step=".01" required class="form-control" id="taux_u_w_cart"
												   name="taux_u_w_cart" value="<?=$taux_u_w_cart?>">
										</div>
										<div class="form-group">
											<label for="taux_u_c_w"
												   class="col-form-label"><?php echo $this->lang->line('rate_com_user_cart_wallet') . ' (%)'; ?></label>
											<input type="number" min="0" step=".01" required class="form-control"
												   id="taux_u_c_w" name="taux_u_c_w" value="<?=$taux_u_c_w?>">
										</div>
										<div class="form-group">
											<label for="taux_u_c_c"
												   class="col-form-label"><?php echo $this->lang->line('rate_com_user_cart_cash') . ' (%)'; ?></label>
											<input type="number" min="0" step=".01" required class="form-control"
												   name="taux_u_c_c" id="taux_u_c_c" value="<?=$taux_u_c_c?>">
										</div>
								</div>
								<div class="col-lg-4">
									<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('rate_com_agent_depot_wallet_national') ; ?></label>
												</div>
												<div class="col-sm-4">
													<button type="button" class="btn btn-info add-new new9"><i class="fa fa-plus"></i> <?php echo $this->lang->line('new_level') ; ?></button>
												</div>
											</div>
										</div>
										<table id="agent_depot_wallet_national" class="table table-bordered">
											<thead>
											<tr>
												<th>Min</th>
												<th>Max</th>
												<th><?php echo $this->lang->line('rate') ; ?> (%) </th>
												<th>Actions</th>
											</tr>
											</thead>
											<tbody>
											<?php
											if($plr_agent_depot_wallet_ilink_national!=false){
												foreach($plr_agent_depot_wallet_ilink_national->result() as $row) {
													echo "<tr>
																		<td>".$row->min."</td>
																		<td>".$row->max."</td>
																		  <td>".$row->taux."</td>".'
																		  <td>
																			<a class="add add9" title="Add" data-toggle="tooltip"><i class="material-icons">&#xE03B;</i></a>
																			<a class="edit edit9" title="Edit" data-toggle="tooltip"><i class="material-icons">&#xE254;</i></a>
																			<a class="delete delete9" title="Delete" data-toggle="tooltip"><i class="material-icons">&#xE872;</i></a>
																		</td>
																		 </tr>';
												}
											}
											?>
											</tbody>
										</table>
										</div>
									<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('rate_com_agent_depot_wallet_international') ; ?></label>
												</div>
												<div class="col-sm-4">
													<button type="button" class="btn btn-info add-new new3"><i class="fa fa-plus"></i> <?php echo $this->lang->line('new_level') ; ?></button>
												</div>
											</div>
										</div>
										<table id="agent_depot_wallet" class="table table-bordered">
											<thead>
											<tr>
												<th>Min</th>
												<th>Max</th>
												<th><?php echo $this->lang->line('rate') ; ?> (%) </th>
												<th>Actions</th>
											</tr>
											</thead>
											<tbody>
											<?php
											if($plr_agent_depot_wallet_ilink!=false){
												foreach($plr_agent_depot_wallet_ilink->result() as $row) {
													echo "<tr>
																		<td>".$row->min."</td>
																		<td>".$row->max."</td>
																		  <td>".$row->taux."</td>".'
																		  <td>
																			<a class="add add3" title="Add" data-toggle="tooltip"><i class="material-icons">&#xE03B;</i></a>
																			<a class="edit edit3" title="Edit" data-toggle="tooltip"><i class="material-icons">&#xE254;</i></a>
																			<a class="delete delete3" title="Delete" data-toggle="tooltip"><i class="material-icons">&#xE872;</i></a>
																		</td>
																		 </tr>';
												}
											}
											?>
											</tbody>
										</table>
									</div>
									<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('rate_com_agent_depot_autre_wallet_national') ; ?></label>
												</div>
												<div class="col-sm-4">
													<button type="button" class="btn btn-info add-new new10"><i class="fa fa-plus"></i> <?php echo $this->lang->line('new_level') ; ?></button>
												</div>
											</div>
										</div>
										<table id="agent_depot_autre_wallet_national" class="table table-bordered">
											<thead>
											<tr>
												<th>Min</th>
												<th>Max</th>
												<th><?php echo $this->lang->line('rate') ; ?> (%) </th>
												<th>Actions</th>
											</tr>
											</thead>
											<tbody>
											<?php
											if($plr_agent_depot_autre_wallet_national!=false){
												foreach($plr_agent_depot_autre_wallet_national->result() as $row) {
													echo "<tr>
																		<td>".$row->min."</td>
																		<td>".$row->max."</td>
																		  <td>".$row->taux."</td>".'
																		  <td>
																			<a class="add add10" title="Add" data-toggle="tooltip"><i class="material-icons">&#xE03B;</i></a>
																			<a class="edit edit10" title="Edit" data-toggle="tooltip"><i class="material-icons">&#xE254;</i></a>
																			<a class="delete delete10" title="Delete" data-toggle="tooltip"><i class="material-icons">&#xE872;</i></a>
																		</td>
																		 </tr>';
												}
											}
											?>
											</tbody>
										</table>
									</div>
									<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('rate_com_agent_depot_autre_wallet_international') ; ?></label>
												</div>
												<div class="col-sm-4">
													<button type="button" class="btn btn-info add-new new6"><i class="fa fa-plus"></i> <?php echo $this->lang->line('new_level') ; ?></button>
												</div>
											</div>
										</div>
										<table id="agent_depot_autre_wallet" class="table table-bordered">
											<thead>
											<tr>
												<th>Min</th>
												<th>Max</th>
												<th><?php echo $this->lang->line('rate') ; ?> (%) </th>
												<th>Actions</th>
											</tr>
											</thead>
											<tbody>
											<?php
											if($plr_agent_depot_autre_wallet!=false){
												foreach($plr_agent_depot_autre_wallet->result() as $row) {
													echo "<tr>
																		<td>".$row->min."</td>
																		<td>".$row->max."</td>
																		  <td>".$row->taux."</td>".'
																		  <td>
																			<a class="add add6" title="Add" data-toggle="tooltip"><i class="material-icons">&#xE03B;</i></a>
																			<a class="edit edit6" title="Edit" data-toggle="tooltip"><i class="material-icons">&#xE254;</i></a>
																			<a class="delete delete6" title="Delete" data-toggle="tooltip"><i class="material-icons">&#xE872;</i></a>
																		</td>
																		 </tr>';
												}
											}
											?>
											</tbody>
										</table>
									</div>
									<div class="form-group">
											<label for="taux_ag_d_c_c"
												   class="col-form-label"><?php echo $this->lang->line('rate_com_agent_depot_cash_cart') . ' (%)'; ?></label>
											<input type="number" min="0" step=".01" required class="form-control"
												   name="taux_ag_d_c_c" id="taux_ag_d_c_c" value="<?=$taux_ag_d_c_c?>">
										</div>
									<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('rate_com_agent_cash_cash_national') ; ?></label>
												</div>
												<div class="col-sm-4">
													<button type="button" class="btn btn-info add-new new11"><i class="fa fa-plus"></i> <?php echo $this->lang->line('new_level') ; ?></button>
												</div>
											</div>
										</div>
										<table id="agent_cash_cash_national" class="table table-bordered">
											<thead>
											<tr>
												<th>Min</th>
												<th>Max</th>
												<th><?php echo $this->lang->line('rate') ; ?> (%) </th>
												<th>Actions</th>
											</tr>
											</thead>
											<tbody>
											<?php
											if($plr_agent_cash_cash_national!=false){
												foreach($plr_agent_cash_cash_national->result() as $row) {
													echo "<tr>
																			<td>".$row->min."</td>
																			<td>".$row->max."</td>
																			  <td>".$row->taux."</td>".'
																			  <td>
																				<a class="add add11" title="Add" data-toggle="tooltip"><i class="material-icons">&#xE03B;</i></a>
																				<a class="edit edit11" title="Edit" data-toggle="tooltip"><i class="material-icons">&#xE254;</i></a>
																				<a class="delete delete11" title="Delete" data-toggle="tooltip"><i class="material-icons">&#xE872;</i></a>
																			</td>
																			 </tr>';
												}
											}
											?>
											</tbody>
										</table>
									</div>
									<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('rate_com_agent_cash_cash_international') ; ?></label>
												</div>
												<div class="col-sm-4">
													<button type="button" class="btn btn-info add-new new4"><i class="fa fa-plus"></i> <?php echo $this->lang->line('new_level') ; ?></button>
												</div>
											</div>
										</div>
										<table id="agent_cash_cash" class="table table-bordered">
											<thead>
											<tr>
												<th>Min</th>
												<th>Max</th>
												<th><?php echo $this->lang->line('rate') ; ?> (%) </th>
												<th>Actions</th>
											</tr>
											</thead>
											<tbody>
												<?php
												if($plr_agent_cash_cash!=false){
													foreach($plr_agent_cash_cash->result() as $row) {
														echo "<tr>
																			<td>".$row->min."</td>
																			<td>".$row->max."</td>
																			  <td>".$row->taux."</td>".'
																			  <td>
																				<a class="add add4" title="Add" data-toggle="tooltip"><i class="material-icons">&#xE03B;</i></a>
																				<a class="edit edit4" title="Edit" data-toggle="tooltip"><i class="material-icons">&#xE254;</i></a>
																				<a class="delete delete4" title="Delete" data-toggle="tooltip"><i class="material-icons">&#xE872;</i></a>
																			</td>
																			 </tr>';
													}
												}
												?>
											</tbody>
										</table>
									</div>
									<div class="form-group">
											<label for="taux_ag_cart_c"
												   class="col-form-label"><?php echo $this->lang->line('rate_com_agent_cart_cash') . ' (%)'; ?></label>
											<input type="number" min="0" step=".01" required class="form-control"
												   id="taux_ag_cart_c" name="taux_ag_cart_c" value="<?= $taux_ag_cart_c ?>">
										</div>
									<div class="form-group">
											<label for="taux_ag_cash_c"
												   class="col-form-label"><?php echo $this->lang->line('rate_com_agent_cash_cart') . ' (%)'; ?></label>
											<input type="number" min="0" step=".01" required class="form-control"
												   name="taux_ag_cash_c" id="taux_ag_cash_c" value="<?= $taux_ag_cash_c ?>">
										</div>

								</div>
								<div class="col-lg-4">

										<div class="form-group">
											<label for="taux_ag_s_c"
												   class="col-form-label"><?php echo $this->lang->line('rate_com_agent_send_cash') . ' (%)'; ?></label>
											<input type="number" min="0" step=".01" required class="form-control"
												   id="taux_ag_s_c" name="taux_ag_s_c" value="<?=$taux_ag_s_c?>">
										</div>
										<div class="form-group">
											<label for="taux_sup_s_c"
												   class="col-form-label"><?php echo $this->lang->line('rate_com_sup_send_cash') . ' (%)'; ?></label>
											<input type="number" min="0" step=".01" required class="form-control"
												   name="taux_sup_s_c" id="taux_sup_s_c" value="<?=$taux_sup_s_c?>">
										</div>
										<div class="form-group">
											<label for="taux_hyp_s_c"
												   class="col-form-label"><?php echo $this->lang->line('rate_com_hyp_send_cash') . ' (%)'; ?></label>
											<input type="number" min="0" step=".01" required class="form-control"
												   name="taux_hyp_s_c" id="taux_hyp_s_c" value="<?=$taux_hyp_s_c?>">
										</div>
										<div class="form-group">
											<label for="taux_ag_r_c"
												   class="col-form-label"><?php echo $this->lang->line('rate_com_agent_remove_cash') . ' (%)'; ?></label>
											<input type="number" min="0" step=".01" required class="form-control" id="taux_ag_r_c"
												   name="taux_ag_r_c" value="<?=$taux_ag_r_c?>">
										</div>
										<div class="form-group">
											<label for="taux_sup_r_c"
												   class="col-form-label"><?php echo $this->lang->line('rate_com_sup_remove_cash') . ' (%)'; ?></label>
											<input type="number" min="0" step=".01" required class="form-control"
												   id="taux_sup_r_c" name="taux_sup_r_c" value="<?=$taux_sup_r_c?>">
										</div>
										<div class="form-group">
											<label for="taux_hyp_r_c"
												   class="col-form-label"><?php echo $this->lang->line('rate_com_hyp_remove_cash') . ' (%)'; ?></label>
											<input type="number" min="0" required class="form-control" id="taux_hyp_r_c"
												   name="taux_hyp_r_c" value="<?= $taux_hyp_r_c?>">
										</div>
										<div class="form-group">
											<label for="taux_ag_d_c"
												   class="col-form-label"><?php echo $this->lang->line('rate_com_agent_depot_cart') . ' (%)'; ?></label>
											<input type="number" min="0" step=".01" required class="form-control"
												   id="taux_ag_d_c" name="taux_ag_d_c" value="<?=$taux_ag_d_c?>">
										</div>
										<div class="form-group">
											<label for="taux_sup_d_c"
												   class="col-form-label"><?php echo $this->lang->line('rate_com_sup_depot_cart') . ' (%)'; ?></label>
											<input type="number" min="0" step=".01" required class="form-control"
												   name="taux_sup_d_c" id="taux_sup_d_c" value="<?= $taux_sup_d_c?>">
										</div>
									<div class="form-group">
										<label for="taux_hyp_d_c"
											   class="col-form-label"><?php echo $this->lang->line('rate_com_hyp_depot_cart') . ' (%)'; ?></label>
										<input type="number" min="0" step=".01" required class="form-control"
											   name="taux_hyp_d_c" id="taux_hyp_d_c" value="<?= $taux_hyp_d_c?>">
									</div>
									<div class="form-group">
										<label for="taux_bq_d_c"
											   class="col-form-label"><?php echo $this->lang->line('rate_com_bq_depot_cart') . ' (%)'; ?></label>
										<input type="number" min="0" step=".01" required class="form-control"
											   name="taux_bq_d_c" id="taux_bq_d_c" value="<?= $taux_bq_d_c ?>">
									</div>
									<div class="form-group">
										<label for="taux_ag_r_cart"
											   class="col-form-label"><?php echo $this->lang->line('rate_com_agent_remove_cart') . ' (%)'; ?></label>
										<input type="number" min="0" step=".01" required class="form-control"
											   name="taux_ag_r_cart" id="taux_ag_r_cart" value="<?= $taux_ag_r_cart ?>">
									</div>
									<div class="form-group">
										<label for="taux_sup_r_cart"
											   class="col-form-label"><?php echo $this->lang->line('rate_com_sup_remove_cart') . ' (%)'; ?></label>
										<input type="number" min="0" step=".01" required class="form-control"
											   name="taux_sup_r_cart" id="taux_sup_r_cart" value="<?= $taux_sup_r_cart ?>">
									</div>
									<div class="form-group">
										<label for="taux_hyp_r_cart"
											   class="col-form-label"><?php echo $this->lang->line('rate_com_hyp_remove_cart') . ' (%)'; ?></label>
										<input type="number" min="0" step=".01" required class="form-control"
											   name="taux_hyp_r_cart" id="taux_hyp_r_cart" value="<?= $taux_hyp_r_cart ?>">
									</div>
									<div class="form-group">
										<label for="taux_bq_r_cart"
											   class="col-form-label"><?php echo $this->lang->line('rate_com_bq_remove_cart') . ' (%)'; ?></label>
										<input type="number" min="0" step=".01" required class="form-control"
											   name="taux_bq_r_cart" id="taux_bq_r_cart" value="<?= $taux_bq_r_cart ?>">
									</div>
									<div class="form-group">
										<label for="taux_hyp_r_cart_ilink"
											   class="col-form-label"><?php echo $this->lang->line('rate_com_hyp_remove_cart_ilink') . ' (%)'; ?></label>
										<input type="number" min="0" step=".01" required class="form-control"
											   name="taux_hyp_r_cart_ilink" id="taux_hyp_r_cart_ilink" value="<?= $taux_hyp_r_cart_ilink ?>">
									</div>
									<div class="form-group">
										<label for="taux_bq_r_cart_ilink"
											   class="col-form-label"><?php echo $this->lang->line('rate_com_bq_remove_cart_ilink') . ' (%)'; ?></label>
										<input type="number" min="0" step=".01" required class="form-control"
											   name="taux_bq_r_cart_ilink" id="taux_bq_r_cart_ilink" value="<?= $taux_bq_r_cart_ilink ?>">
									</div>
									<div class="form-group">
										<label for="taux_hyp_s_wallet_cart_ilink"
											   class="col-form-label"><?php echo $this->lang->line('rate_com_hyp_send_wallet_cart_ilink') . ' (%)'; ?></label>
										<input type="number" min="0" step=".01" required class="form-control"
											   name="taux_hyp_s_wallet_cart_ilink" id="taux_hyp_s_wallet_cart_ilink" value="<?= $taux_hyp_s_wallet_cart_ilink ?>">
									</div>
									<div class="form-group">
										<label for="taux_bq_s_wallet_cart_ilink"
											   class="col-form-label"><?php echo $this->lang->line('rate_com_bq_send_wallet_cart_ilink') . ' (%)'; ?></label>
										<input type="number" min="0" step=".01" required class="form-control"
											   name="taux_bq_s_wallet_cart_ilink" id="taux_bq_s_wallet_cart_ilink" value="<?= $taux_bq_s_wallet_cart_ilink ?>">
									</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="updateWallet" 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('configuration_of_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_taxes') ; ?></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_tax') ; ?></button>
											</div>
										</div>
									</div>
									<table id="transactions_taxes" class="table table-bordered">
										<thead>
										<tr>
											<th><?php echo $this->lang->line('Nom') ; ?> </th>
											<th>Type</th>
											<th>Valeur</th>
											<th>Destination</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>".$row->destination."</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>
							</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>
			<div class="modal fade" id="rechargeAccount" tabindex="-1" role="dialog" aria-hidden="true">
				<div class="modal-dialog" role="document">
					<div class="modal-content">
						<div class="modal-header">
							<h3 class="modal-title"><?php echo $this->lang->line('recharge_hypervisor_account'); ?></h3>
						</div>
						<div class="modal-body">
							<?php if ($walletPassword != null) { ?>
								<form id="rechargeAccountForm">
									<div class="form-group">
										<label for="montant" class="col-form-label"><?php echo $this->lang->line('Montant') ?></label>
										<input type="text"  required class="form-control" id="montant"  name="montant" >
									</div>
<!--									<div class="form-group">-->
<!--										<label for="password" class="col-form-label">--><?php //echo $this->lang->line('mot de passe') ?><!--</label>-->
<!--										<input type="password" required class="form-control" name="password" id="password">-->
<!--									</div>-->
									<div class="form-group">
										<label><?php echo $this->lang->line('mot de passe') ?></label>
										<div class="input-group" id="show_hide_password">
											<input class="form-control"  name="password" id="password" type="password">
											<div class="input-group-addon">
												<a href=""><i class="fa fa-eye-slash" aria-hidden="true"></i></a>
											</div>
										</div>
									</div>
									<div class="clearfix">
										<a href="#" id="resetPassword" class="pull-right forgot-password" data-wallet_password_id="<?php echo $walletPassword->id ?>" data-network="<?php echo $network ?>" data-country="<?php echo $country ?>"
										   data-email="<?php echo $walletPassword->email ?>">
											<?php echo $this->lang->line('i_forgot_password') ?>
										</a>
									</div>
								</form>
							<?php }else{ ?>
								<div class="text-center">
									<h4> <?php echo $this->lang->line('no_wallet_password') ?></h4>
									<a href="<?php echo base_url('index.php/Hyperviseur_dash/walletPassword') ?>"  alt="" class="btn btn-primary"><?php echo $this->lang->line('click_here') ?></a>
								</div>
							<?php } ?>
						</div>
						<div class="modal-footer">
							<button type="button" class="btn btn-secondary" data-dismiss="modal"><?php echo $this->lang->line('Fermer'); ?></button>
							<?php if ($walletPassword != null) { ?>
								<button type="button" class="btn btn-primary" data-wallet_id="<?php echo $wallet_id ?>" data-salt="<?php echo $walletPassword->salt ?>" data-encrypted_password="<?php echo $walletPassword->encrypted_password ?>" id="rechargeWallet" >
									<?php echo $this->lang->line('recharge'); ?>
								</button>
							<?php }?>
						</div>
					</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/moment/min/moment.min.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://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.47/js/bootstrap-datetimepicker.min.js"></script>
<!-- ChartJS -->
<script src="<?php echo base_url('bower_components/chart.js/Chart.js') ?>"></script>
<script src="<?php echo base_url('bower_components/toastr/toastr.js') ?>"></script>
<script src="<?php echo base_url('dist/js/sweetalert2.js') ?>"></script>
<script src="https://cdn.jsdelivr.net/npm/autonumeric@4.5.4"></script>

<script>
  $(function () {
	  $('#example1').DataTable();
	  anElement = new AutoNumeric('#montant', '', {digitGroupSeparator: ' ', decimalPlaces:'0', minimumValue : '1' , maximumValue: '99999999999999999999999999'});

	  $("#show_hide_password a").on('click', function(event) {
		  event.preventDefault();
		  if($('#show_hide_password input').attr("type") == "text"){
			  $('#show_hide_password input').attr('type', 'password');
			  $('#show_hide_password i').addClass( "fa-eye-slash" );
			  $('#show_hide_password i').removeClass( "fa-eye" );
		  }else if($('#show_hide_password input').attr("type") == "password"){
			  $('#show_hide_password input').attr('type', 'text');
			  $('#show_hide_password i').removeClass( "fa-eye-slash" );
			  $('#show_hide_password i').addClass( "fa-eye" );
		  }
	  });
	  // $('#example1').DataTable({
    //   "aLengthMenu": [[5, 10, 15, -1], [5, 10, 5, "All"]],
    //   "iDisplayLength": 5
    // });
    // $('#example2').DataTable({
    //   'paging'      : true,
    //   'lengthChange': false,
    //   'searching'   : false,
    //   'ordering'    : true,
    //   'info'        : true,
    //   'autoWidth'   : false
    // })
  })
</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>
	var serializeArray = function (form) {
		// Setup our serialized data
		var serialized = [];

		// Loop through each field in the form
		var elements = document.getElementById(form).elements;
		for (var i = 0, field; field = elements[i++];) {

			// Don't serialize fields without a name, submits, buttons, file and reset inputs, and disabled fields
			if (!field.name || field.disabled || field.type === 'file' || field.type === 'reset' || field.type === 'submit' || field.type === 'button') continue;

			// If a multi-select, get all selections
			if (field.type === 'select-multiple') {
				for (var n = 0; n < field.options.length; n++) {
					if (!field.options[n].selected) continue;
					serialized.push({
						name: field.name,
						value: field.options[n].value
					});
				}
			}

			// Convert field data to a query string
			else if ((field.type !== 'checkbox' && field.type !== 'radio') || field.checked) {
				serialized.push({
					name: field.name,
					value: field.value
				});
			}
		}

		return serialized;
	};

</script>
<script>
	toastr.options.closeButton = true;
	toastr.options.closeMethod = 'fadeOut';
	toastr.options.closeDuration = 5000;
	toastr.options.closeEasing = 'swing';

	$('#updateWallet').click(function () {
		const network_id = $(this).data('network-id');
		const id_config = $(this).data('id-config');

		// Verification des taux de commission
		// total répartition commission du réseau opération envoi-cash (les frais)
		const total1 = parseFloat($('#taux_ag_s_c').val()) + parseFloat($('#taux_sup_s_c').val()) + parseFloat($('#taux_hyp_s_c').val());

		// total répartition commission du réseau opération retrait-cash (les frais)
		const total2 = parseFloat($('#taux_ag_r_c').val()) + parseFloat($('#taux_sup_r_c').val()) + parseFloat($('#taux_hyp_r_c').val());

		// total répartition commission réseau dépôt cash-carte chez agent (frais)
		const total3 = parseFloat($('#taux_ag_d_c').val()) + parseFloat($('#taux_sup_d_c').val()) + parseFloat($('#taux_hyp_d_c').val())
						+ parseFloat($('#taux_bq_d_c').val());

		// total répartition commission réseau retrait carte-cash  chez agent (retrait)
		const total4 = parseFloat($('#taux_ag_r_cart').val()) + parseFloat($('#taux_sup_r_cart').val()) + parseFloat($('#taux_hyp_r_cart').val())
				+ parseFloat($('#taux_bq_r_cart').val());

// total répartition commission réseau retrait carte-cash  utilisateur ilink (retrait)
		const total5 =  parseFloat($('#taux_hyp_r_cart_ilink').val()) + parseFloat($('#taux_bq_r_cart_ilink').val());

		// total répartition commission réseau d'envoi de wallet vers carte  utilisateur ilink (retrait)
		const total6 = parseFloat($('#taux_hyp_s_wallet_cart_ilink').val()) + parseFloat($('#taux_bq_s_wallet_cart_ilink').val());



		if(total1 != 100){
			toastr.error("<?php echo $this->lang->line('ilink_first_rule')?>", "<?php echo $this->lang->line('management_rule')?>");
		} else if (total2 != 100) {
			toastr.error("<?php echo $this->lang->line('ilink_second_rule')?>", "<?php echo $this->lang->line('management_rule')?>");
		} else if (total3 != 100) {
			toastr.error("<?php echo $this->lang->line('ilink_third_rule')?>", "<?php echo $this->lang->line('management_rule')?>");
		} else if (total4 != 100) {
			toastr.error("<?php echo $this->lang->line('ilink_fourth_rule')?>", "<?php echo $this->lang->line('management_rule')?>");
		} else if (total5 != 100) {
			toastr.error("<?php echo $this->lang->line('ilink_fifth_rule')?>", "<?php echo $this->lang->line('management_rule')?>");
		} else if (total6 != 100) {
			toastr.error("<?php echo $this->lang->line('ilink_sixth_rule')?>", "<?php echo $this->lang->line('management_rule')?>");
		} else {
			if ($('#walletForm')[0].checkValidity()) {

				// Paliers
				var plr_user_wallet_wallet = [];
				var plr_user_wallet_cash = [];
				var plr_agent_depot_wallet_ilink = [];
				var plr_agent_depot_autre_wallet = [];
				var plr_agent_cash_cash = [];

				var plr_user_wallet_wallet_national = [];
				var plr_user_wallet_cash_national = [];
				var plr_agent_depot_wallet_ilink_national = [];
				var plr_agent_depot_autre_wallet_national = [];
				var plr_agent_cash_cash_national = [];
				// var headers = [];
				// $('#user_wallet_wallet th').each(function(index, item) {
				// 	headers[index] = $(item).html();
				// });
				$('#user_wallet_wallet tr').has('td').each(function() {
					var arrayItem = {};
					$('td', $(this)).each(function(index, item) {
						if(index < 3)
							arrayItem[index] = parseFloat($(item).html());
					});
					plr_user_wallet_wallet.push(arrayItem);
				});
				$('#user_wallet_cash tr').has('td').each(function() {
					var arrayItem = {};
					$('td', $(this)).each(function(index, item) {
						if(index < 3)
							arrayItem[index] = parseFloat($(item).html());
					});
					plr_user_wallet_cash.push(arrayItem);
				});
				$('#agent_depot_wallet tr').has('td').each(function() {
					var arrayItem = {};
					$('td', $(this)).each(function(index, item) {
						if(index < 3)
							arrayItem[index] = parseFloat($(item).html());
					});
					plr_agent_depot_wallet_ilink.push(arrayItem);
				});
				$('#agent_depot_autre_wallet tr').has('td').each(function() {
					var arrayItem = {};
					$('td', $(this)).each(function(index, item) {
						if(index < 3)
							arrayItem[index] = parseFloat($(item).html());
					});
					plr_agent_depot_autre_wallet.push(arrayItem);
				});
				$('#agent_cash_cash tr').has('td').each(function() {
					var arrayItem = {};
					$('td', $(this)).each(function(index, item) {
						if(index < 3)
							arrayItem[index] = parseFloat($(item).html());
					});
					plr_agent_cash_cash.push(arrayItem);
				});

				$('#user_wallet_wallet_national tr').has('td').each(function() {
					var arrayItem = {};
					$('td', $(this)).each(function(index, item) {
						if(index < 3)
							arrayItem[index] = parseFloat($(item).html());
					});
					plr_user_wallet_wallet_national.push(arrayItem);
				});
				$('#user_wallet_cash_national tr').has('td').each(function() {
					var arrayItem = {};
					$('td', $(this)).each(function(index, item) {
						if(index < 3)
							arrayItem[index] = parseFloat($(item).html());
					});
					plr_user_wallet_cash_national.push(arrayItem);
				});
				$('#agent_depot_wallet_national tr').has('td').each(function() {
					var arrayItem = {};
					$('td', $(this)).each(function(index, item) {
						if(index < 3)
							arrayItem[index] = parseFloat($(item).html());
					});
					plr_agent_depot_wallet_ilink_national.push(arrayItem);
				});
				$('#agent_depot_autre_wallet_national tr').has('td').each(function() {
					var arrayItem = {};
					$('td', $(this)).each(function(index, item) {
						if(index < 3)
							arrayItem[index] = parseFloat($(item).html());
					});
					plr_agent_depot_autre_wallet_national.push(arrayItem);
				});
				$('#agent_cash_cash_national tr').has('td').each(function() {
					var arrayItem = {};
					$('td', $(this)).each(function(index, item) {
						if(index < 3)
							arrayItem[index] = parseFloat($(item).html());
					});
					plr_agent_cash_cash_national.push(arrayItem);
				});


				$.ajax({
					url: '<?php echo base_url('index.php/Gestion/config_wallet/update')?>',
					type: 'POST',
					dataType: 'json',
					data: {
						"type" : "ilink",
						"network_id": network_id,"id_config" : id_config,
						"plr_user_wallet_wallet" : plr_user_wallet_wallet ,
						"plr_user_wallet_cash": plr_user_wallet_cash ,
						"plr_agent_depot_wallet_ilink":plr_agent_depot_wallet_ilink,
						"plr_agent_depot_autre_wallet":plr_agent_depot_autre_wallet,
						"plr_agent_cash_cash" :plr_agent_cash_cash,
						"plr_user_wallet_wallet_national" : plr_user_wallet_wallet_national ,
						"plr_user_wallet_cash_national": plr_user_wallet_cash_national ,
						"plr_agent_depot_wallet_ilink_national":plr_agent_depot_wallet_ilink_national,
						"plr_agent_depot_autre_wallet_national":plr_agent_depot_autre_wallet_national,
						"plr_agent_cash_cash_national" :plr_agent_cash_cash_national,
						"fields":serializeArray('walletForm')
					},
					success: function (data) {
						if(data=='200'){
							Swal.fire({
								icon: 'success',
								title: "<?php echo $this->lang->line('wallet_update')?>",
								text:"<?php echo $this->lang->line('informations_updated')?>",
								timer: 3000
							}).then(()=>{
								location.reload();
							});
							// alert("Les informations ont été mises à jour.") ? "" :
						}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 {
				$('#walletForm')[0].reportValidity();
			}
		}

		});

	$('#saveTaxes').click(function () {
		const network_id = $(this).data('network-id');
		const id_config = $(this).data('id-config');
		// Paliers
		var taxes = [];

		$('#transactions_taxes tr').has('td').each(function() {
			var arrayItem = {};
			$('td', $(this)).each(function(index, item) {
				if(index < 4){
					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: {
					"network_id": network_id,"id_config" : id_config,
					"taxes" : taxes ,
				},
				success: function (data) {
					if(data=='200'){
						Swal.fire({
							icon: 'success',
							title: "<?php echo $this->lang->line('wallet_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();
		}

	});

	$('#resetPassword').click(function () {
		const wallet_password_id = $(this).data('wallet_password_id');
		const network = $(this).data('network');
		const country = $(this).data('country');
		const email = $(this).data('email');
		$.ajax({
			url: '<?php echo base_url('index.php/Hyperviseur_dash/resetWalletPassword')?>',
			type: 'POST',
			dataType: 'json',
			data: {
				"wallet_password_id": wallet_password_id,
				"email": email,
				"network" : network ,
				"country" : country
			},
			success: function (data) {
				if(data=='200'){
					Swal.fire({
						icon: 'success',
						title: "<?php echo $this->lang->line('password_has_been_reset')?>",
						text:"<?php echo $this->lang->line('informations_updated')?>",
						timer: 3000
					}).then(()=>{
						location.reload();
					});
					// alert("Les informations ont été mises à jour.") ? "" :
				}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')?>");

			}
		});
	});

	$('#rechargeWallet').click(function () {

		const wallet_id = $(this).data('wallet_id');
		const salt = $(this).data('salt');
		const encrypted_password = $(this).data('encrypted_password');

		if ($('#rechargeAccountForm')[0].checkValidity()) {
			const montant = anElement.getNumber();  //parseFloat($('#montant').val());
			const password = $('#password').val();

			$.ajax({
				url: '<?php echo base_url('index.php/Hyperviseur_dash/recharge_wallet')?>',
				type: 'POST',
				dataType: 'json',
				data: {
					"wallet_id": wallet_id,
					"montant": montant ,
					"password": password,
					"salt" : salt,
					"encrypted_password" : encrypted_password
				},
				success: function (data) {
					if(data=='200'){
						Swal.fire({
							icon: 'success',
							title: "<?php echo $this->lang->line('account_recharged')?>",
							text: "<?php echo $this->lang->line('informations_updated')?>",
							timer: 3000
						}).then(()=>{
							location.reload();
						});
						// alert("Les informations ont été mises à jour.") ? "" :
					}else if(data == '400'){
						toastr.error("<?php echo $this->lang->line('incorrect_password')?>" , "<?php echo $this->lang->line('request_error')?>");
					}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 {
			$('#rechargeAccountForm')[0].reportValidity();
		}

	});
</script>
<script type="text/javascript">
	// Paliers scripts
	$(document).ready(function(){
		$('[data-toggle="tooltip"]').tooltip();
		var actions1 = $("#user_wallet_wallet td:last-child").html();
		// Append table with add row form on add new button click
		$(".new1").click(function(){
			if(!actions1){
				actions1 = '<a class="add add1" title="Add" data-toggle="tooltip"><i class="material-icons">&#xE03B;</i></a>\n' +
						'                            <a class="edit edit1" title="Edit" data-toggle="tooltip"><i class="material-icons">&#xE254;</i></a>\n' +
						'                            <a class="delete delete1" title="Delete" data-toggle="tooltip"><i class="material-icons">&#xE872;</i></a>';
			}
			$(this).attr("disabled", "disabled");
			var index = $("#user_wallet_wallet tbody tr:last-child").index();
			var row = '<tr>' +
					'<td><input type="number" required min="0" class="form-control" name="min" id="min"></td>' +
					'<td><input type="number"  required class="form-control" name="max" id="max"></td>' +
					'<td><input type="number" required class="form-control" min="0" name="taux" id="taux"></td>' +
					'<td> ' + actions1 +'</td>' +
					'</tr>';
			$("#user_wallet_wallet").append(row);
			$("#user_wallet_wallet tbody tr").eq(index + 1).find(".add, .edit").toggle();
			$('[data-toggle="tooltip"]').tooltip();
		});
		// Add row on add button click
		$(document).on("click", ".add1", function(){
			var empty = false;
			var input = $(this).parents("tr").find('input[type="number"]');
			var min = parseFloat($(this).parents("tr").find('input[id="min"]').first().val());
			var max = parseFloat($(this).parents("tr").find('input[id="max"]').first().val());

			input.each(function(){
				if($(this).attr('id') == 'min'){
					if(min >= max){
						$(this).addClass("error");
						$(this)[0].reportValidity();
						empty = true;
					} else{
						$(this).removeClass("error");
					}
				}else if($(this).attr('id') == 'max'){
					if(max <= min){
						$(this).addClass("error");
						$(this)[0].reportValidity();
						empty = true;
					} else{
						$(this).removeClass("error");
					}
				}else{
					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){
				input.each(function(){
					$(this).parent("td").html($(this).val());
				});
				$(this).parents("tr").find(".add, .edit").toggle();
				$(".new1").removeAttr("disabled");
			}
		});
		// Edit row on edit button click
		$(document).on("click", ".edit1", function(){
			$(this).parents("tr").find("td:not(:last-child)").each(function(index){
				if(index == 0)
					$(this).html('<input type="number" required class="form-control" min="0" id="min" value="' + $(this).text() + '">');
				if(index == 1)
					$(this).html('<input type="number" required class="form-control" id="max" value="' + $(this).text() + '">');
				if(index == 2)
					$(this).html('<input type="number" required class="form-control"  min="0" value="' + $(this).text() + '">');
			});
			$(this).parents("tr").find(".add, .edit").toggle();
			$(".new1").attr("disabled", "disabled");
		});
		// Delete row on delete button click
		$(document).on("click", ".delete1", function(){
			$(this).parents("tr").remove();
			$(".new1").removeAttr("disabled");
		});

		// Table 2
		var actions2 = $("#user_wallet_cash td:last-child").html();
		// Append table with add row form on add new button click
		$(".new2").click(function(){
			if(!actions2){
				actions2 = '<a class="add add2" title="Add" data-toggle="tooltip"><i class="material-icons">&#xE03B;</i></a>\n' +
						'                            <a class="edit edit2" title="Edit" data-toggle="tooltip"><i class="material-icons">&#xE254;</i></a>\n' +
						'                            <a class="delete delete2" title="Delete" data-toggle="tooltip"><i class="material-icons">&#xE872;</i></a>';
			}
			$(this).attr("disabled", "disabled");
			var index = $("#user_wallet_cash tbody tr:last-child").index();
			var row = '<tr>' +
					'<td><input type="number" required min="0" class="form-control" name="min" id="min"></td>' +
					'<td><input type="number" required class="form-control" name="max" id="max"></td>' +
					'<td><input type="number" required class="form-control" name="taux" id="taux"></td>' +
					'<td> ' + actions2 +'</td>' +
					'</tr>';
			$("#user_wallet_cash").append(row);
			$("#user_wallet_cash tbody tr").eq(index + 1).find(".add, .edit").toggle();
			$('[data-toggle="tooltip"]').tooltip();
		});
		// Add row on add button click
		$(document).on("click", ".add2", function(){
			var empty = false;
			var input = $(this).parents("tr").find('input[type="number"]');
			var min = parseFloat($(this).parents("tr").find('input[id="min"]').first().val());
			var max = parseFloat($(this).parents("tr").find('input[id="max"]').first().val());

			input.each(function(){
				if($(this).attr('id') == 'min'){
					if(min >= max){
						$(this).addClass("error");
						$(this)[0].reportValidity();
						empty = true;
					} else{
						$(this).removeClass("error");
					}
				}else if($(this).attr('id') == 'max'){
					if(max <= min){
						$(this).addClass("error");
						$(this)[0].reportValidity();
						empty = true;
					} else{
						$(this).removeClass("error");
					}
				}else{
					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){
				input.each(function(){
					$(this).parent("td").html($(this).val());
				});
				$(this).parents("tr").find(".add, .edit").toggle();
				$(".new2").removeAttr("disabled");
			}
		});
		// Edit row on edit button click
		$(document).on("click", ".edit2", function(){
			$(this).parents("tr").find("td:not(:last-child)").each(function(index){
				if(index == 0)
					$(this).html('<input type="number" required class="form-control" min="0" id="min" value="' + $(this).text() + '">');
				if(index == 1)
					$(this).html('<input type="number" required class="form-control" id="max" value="' + $(this).text() + '">');
				if(index == 2)
					$(this).html('<input type="number" required class="form-control"  min="0" value="' + $(this).text() + '">');
			});
			$(this).parents("tr").find(".add, .edit").toggle();
			$(".new2").attr("disabled", "disabled");
		});
		// Delete row on delete button click
		$(document).on("click", ".delete2", function(){
			$(this).parents("tr").remove();
			$(".new2").removeAttr("disabled");
		});

		// Table 3
		var actions3 = $("#agent_depot_wallet td:last-child").html();
		// Append table with add row form on add new button click
		$(".new3").click(function(){
			if(!actions3){
				actions3 = '<a class="add add3" title="Add" data-toggle="tooltip"><i class="material-icons">&#xE03B;</i></a>\n' +
						'                            <a class="edit edit3" title="Edit" data-toggle="tooltip"><i class="material-icons">&#xE254;</i></a>\n' +
						'                            <a class="delete delete3" title="Delete" data-toggle="tooltip"><i class="material-icons">&#xE872;</i></a>';
			}
			$(this).attr("disabled", "disabled");
			var index = $("#agent_depot_wallet tbody tr:last-child").index();
			var row = '<tr>' +
					'<td><input type="number" required min="0" class="form-control" name="min" id="min"></td>' +
					'<td><input type="number" required class="form-control" name="max" id="max"></td>' +
					'<td><input type="number" required class="form-control" name="taux" id="taux"></td>' +
					'<td> ' + actions3 +'</td>' +
					'</tr>';
			$("#agent_depot_wallet").append(row);
			$("#agent_depot_wallet tbody tr").eq(index + 1).find(".add, .edit").toggle();
			$('[data-toggle="tooltip"]').tooltip();
		});
		// Add row on add button click
		$(document).on("click", ".add3", function(){
			var empty = false;
			var input = $(this).parents("tr").find('input[type="number"]');
			var min = parseFloat($(this).parents("tr").find('input[id="min"]').first().val());
			var max = parseFloat($(this).parents("tr").find('input[id="max"]').first().val());

			input.each(function(){
				if($(this).attr('id') == 'min'){
					if(min >= max){
						$(this).addClass("error");
						$(this)[0].reportValidity();
						empty = true;
					} else{
						$(this).removeClass("error");
					}
				}else if($(this).attr('id') == 'max'){
					if(max <= min){
						$(this).addClass("error");
						$(this)[0].reportValidity();
						empty = true;
					} else{
						$(this).removeClass("error");
					}
				}else{
					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){
				input.each(function(){
					$(this).parent("td").html($(this).val());
				});
				$(this).parents("tr").find(".add, .edit").toggle();
				$(".new3").removeAttr("disabled");
			}
		});
		// Edit row on edit button click
		$(document).on("click", ".edit3", function(){
			$(this).parents("tr").find("td:not(:last-child)").each(function(index){
				if(index == 0)
					$(this).html('<input type="number" required class="form-control" min="0" id="min" value="' + $(this).text() + '">');
				if(index == 1)
					$(this).html('<input type="number" required class="form-control" id="max" value="' + $(this).text() + '">');
				if(index == 2)
					$(this).html('<input type="number" required class="form-control"  min="0" value="' + $(this).text() + '">');
			});
			$(this).parents("tr").find(".add, .edit").toggle();
			$(".new3").attr("disabled", "disabled");
		});
		// Delete row on delete button click
		$(document).on("click", ".delete3", function(){
			$(this).parents("tr").remove();
			$(".new3").removeAttr("disabled");
		});

		// Table 4
		var actions4 = $("#agent_cash_cash td:last-child").html();
		// Append table with add row form on add new button click
		$(".new4").click(function(){
			if(!actions4){
				actions4 = '<a class="add add4" title="Add" data-toggle="tooltip"><i class="material-icons">&#xE03B;</i></a>\n' +
						'                            <a class="edit edit4" title="Edit" data-toggle="tooltip"><i class="material-icons">&#xE254;</i></a>\n' +
						'                            <a class="delete delete4" title="Delete" data-toggle="tooltip"><i class="material-icons">&#xE872;</i></a>';
			}
			$(this).attr("disabled", "disabled");
			var index = $("#agent_cash_cash tbody tr:last-child").index();
			var row = '<tr>' +
					'<td><input type="number" required min="0" class="form-control" name="min" id="min"></td>' +
					'<td><input type="number" required class="form-control" name="max" id="max"></td>' +
					'<td><input type="number" required class="form-control" name="taux" id="taux"></td>' +
					'<td> ' + actions4 +'</td>' +
					'</tr>';
			$("#agent_cash_cash").append(row);
			$("#agent_cash_cash tbody tr").eq(index + 1).find(".add, .edit").toggle();
			$('[data-toggle="tooltip"]').tooltip();
		});
		// Add row on add button click
		$(document).on("click", ".add4", function(){
			var empty = false;
			var input = $(this).parents("tr").find('input[type="number"]');
			var min = parseFloat($(this).parents("tr").find('input[id="min"]').first().val());
			var max = parseFloat($(this).parents("tr").find('input[id="max"]').first().val());

			input.each(function(){
				if($(this).attr('id') == 'min'){
					if(min >= max){
						$(this).addClass("error");
						$(this)[0].reportValidity();
						empty = true;
					} else{
						$(this).removeClass("error");
					}
				}else if($(this).attr('id') == 'max'){
					if(max <= min){
						$(this).addClass("error");
						$(this)[0].reportValidity();
						empty = true;
					} else{
						$(this).removeClass("error");
					}
				}else{
					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){
				input.each(function(){
					$(this).parent("td").html($(this).val());
				});
				$(this).parents("tr").find(".add, .edit").toggle();
				$(".new4").removeAttr("disabled");
			}
		});
		// Edit row on edit button click
		$(document).on("click", ".edit4", function(){
			$(this).parents("tr").find("td:not(:last-child)").each(function(index){
				if(index == 0)
					$(this).html('<input type="number" required class="form-control" min="0" id="min" value="' + $(this).text() + '">');
				if(index == 1)
					$(this).html('<input type="number" required class="form-control" id="max" value="' + $(this).text() + '">');
				if(index == 2)
					$(this).html('<input type="number" required class="form-control"  min="0" value="' + $(this).text() + '">');
			});
			$(this).parents("tr").find(".add, .edit").toggle();
			$(".new4").attr("disabled", "disabled");
		});
		// Delete row on delete button click
		$(document).on("click", ".delete4", function(){
			$(this).parents("tr").remove();
			$(".new4").removeAttr("disabled");
		});

		// Table 6
		var actions6 = $("#agent_depot_autre_wallet td:last-child").html();
// Append table with add row form on add new button click
		$(".new6").click(function(){
			if(!actions6){
				actions6 = '<a class="add add6" title="Add" data-toggle="tooltip"><i class="material-icons">&#xE06B;</i></a>\n' +
						'                            <a class="edit edit6" title="Edit" data-toggle="tooltip"><i class="material-icons">&#xE254;</i></a>\n' +
						'                            <a class="delete delete6" title="Delete" data-toggle="tooltip"><i class="material-icons">&#xE872;</i></a>';
			}
			$(this).attr("disabled", "disabled");
			var index = $("#agent_depot_autre_wallet tbody tr:last-child").index();
			var row = '<tr>' +
					'<td><input type="number" required min="0" class="form-control" name="min" id="min"></td>' +
					'<td><input type="number" required class="form-control" name="max" id="max"></td>' +
					'<td><input type="number" required class="form-control" name="taux" id="taux"></td>' +
					'<td> ' + actions6 +'</td>' +
					'</tr>';
			$("#agent_depot_autre_wallet").append(row);
			$("#agent_depot_autre_wallet tbody tr").eq(index + 1).find(".add, .edit").toggle();
			$('[data-toggle="tooltip"]').tooltip();
		});
// Add row on add button click
		$(document).on("click", ".add6", function(){
			var empty = false;
			var input = $(this).parents("tr").find('input[type="number"]');
			var min = parseFloat($(this).parents("tr").find('input[id="min"]').first().val());
			var max = parseFloat($(this).parents("tr").find('input[id="max"]').first().val());

			input.each(function(){
				if($(this).attr('id') == 'min'){
					if(min >= max){
						$(this).addClass("error");
						$(this)[0].reportValidity();
						empty = true;
					} else{
						$(this).removeClass("error");
					}
				}else if($(this).attr('id') == 'max'){
					if(max <= min){
						$(this).addClass("error");
						$(this)[0].reportValidity();
						empty = true;
					} else{
						$(this).removeClass("error");
					}
				}else{
					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){
				input.each(function(){
					$(this).parent("td").html($(this).val());
				});
				$(this).parents("tr").find(".add, .edit").toggle();
				$(".new6").removeAttr("disabled");
			}
		});
// Edit row on edit button click
		$(document).on("click", ".edit6", function(){
			$(this).parents("tr").find("td:not(:last-child)").each(function(index){
				if(index == 0)
					$(this).html('<input type="number" required class="form-control" min="0" id="min" value="' + $(this).text() + '">');
				if(index == 1)
					$(this).html('<input type="number" required class="form-control" id="max" value="' + $(this).text() + '">');
				if(index == 2)
					$(this).html('<input type="number" required class="form-control"  min="0" value="' + $(this).text() + '">');
			});
			$(this).parents("tr").find(".add, .edit").toggle();
			$(".new6").attr("disabled", "disabled");
		});
// Delete row on delete button click
		$(document).on("click", ".delete6", function(){
			$(this).parents("tr").remove();
			$(".new6").removeAttr("disabled");
		});

		// Paliers nationaux

// Table 7
		var actions7 = $("#user_wallet_wallet_national td:last-child").html();
// Append table with add row form on add new button click
		$(".new7").click(function(){
			if(!actions7){
				actions7 = '<a class="add add7" title="Add" data-toggle="tooltip"><i class="material-icons">&#xE07B;</i></a>\n' +
						'                            <a class="edit edit7" title="Edit" data-toggle="tooltip"><i class="material-icons">&#xE254;</i></a>\n' +
						'                            <a class="delete delete7" title="Delete" data-toggle="tooltip"><i class="material-icons">&#xE872;</i></a>';
			}
			$(this).attr("disabled", "disabled");
			var index = $("#user_wallet_wallet_national tbody tr:last-child").index();
			var row = '<tr>' +
					'<td><input type="number" required min="0" class="form-control" name="min" id="min"></td>' +
					'<td><input type="number" required class="form-control" name="max" id="max"></td>' +
					'<td><input type="number" required class="form-control" name="taux" id="taux"></td>' +
					'<td> ' + actions7 +'</td>' +
					'</tr>';
			$("#user_wallet_wallet_national").append(row);
			$("#user_wallet_wallet_national tbody tr").eq(index + 1).find(".add, .edit").toggle();
			$('[data-toggle="tooltip"]').tooltip();
		});
// Add row on add button click
		$(document).on("click", ".add7", function(){
			var empty = false;
			var input = $(this).parents("tr").find('input[type="number"]');
			var min = parseFloat($(this).parents("tr").find('input[id="min"]').first().val());
			var max = parseFloat($(this).parents("tr").find('input[id="max"]').first().val());

			input.each(function(){
				if($(this).attr('id') == 'min'){
					if(min >= max){
						$(this).addClass("error");
						$(this)[0].reportValidity();
						empty = true;
					} else{
						$(this).removeClass("error");
					}
				}else if($(this).attr('id') == 'max'){
					if(max <= min){
						$(this).addClass("error");
						$(this)[0].reportValidity();
						empty = true;
					} else{
						$(this).removeClass("error");
					}
				}else{
					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){
				input.each(function(){
					$(this).parent("td").html($(this).val());
				});
				$(this).parents("tr").find(".add, .edit").toggle();
				$(".new7").removeAttr("disabled");
			}
		});
// Edit row on edit button click
		$(document).on("click", ".edit7", function(){
			$(this).parents("tr").find("td:not(:last-child)").each(function(index){
				if(index == 0)
					$(this).html('<input type="number" required class="form-control" min="0" id="min" value="' + $(this).text() + '">');
				if(index == 1)
					$(this).html('<input type="number" required class="form-control" id="max" value="' + $(this).text() + '">');
				if(index == 2)
					$(this).html('<input type="number" required class="form-control"  min="0" value="' + $(this).text() + '">');
			});
			$(this).parents("tr").find(".add, .edit").toggle();
			$(".new7").attr("disabled", "disabled");
		});
// Delete row on delete button click
		$(document).on("click", ".delete7", function(){
			$(this).parents("tr").remove();
			$(".new7").removeAttr("disabled");
		});

		// Table 8
		var actions8 = $("#user_wallet_cash_national td:last-child").html();
// Append table with add row form on add new button click
		$(".new8").click(function(){
			if(!actions8){
				actions8 = '<a class="add add8" title="Add" data-toggle="tooltip"><i class="material-icons">&#xE08B;</i></a>\n' +
						'                            <a class="edit edit8" title="Edit" data-toggle="tooltip"><i class="material-icons">&#xE254;</i></a>\n' +
						'                            <a class="delete delete8" title="Delete" data-toggle="tooltip"><i class="material-icons">&#xE882;</i></a>';
			}
			$(this).attr("disabled", "disabled");
			var index = $("#user_wallet_cash_national tbody tr:last-child").index();
			var row = '<tr>' +
					'<td><input type="number" required min="0" class="form-control" name="min" id="min"></td>' +
					'<td><input type="number" required class="form-control" name="max" id="max"></td>' +
					'<td><input type="number" required class="form-control" name="taux" id="taux"></td>' +
					'<td> ' + actions8 +'</td>' +
					'</tr>';
			$("#user_wallet_cash_national").append(row);
			$("#user_wallet_cash_national tbody tr").eq(index + 1).find(".add, .edit").toggle();
			$('[data-toggle="tooltip"]').tooltip();
		});
// Add row on add button click
		$(document).on("click", ".add8", function(){
			var empty = false;
			var input = $(this).parents("tr").find('input[type="number"]');
			var min = parseFloat($(this).parents("tr").find('input[id="min"]').first().val());
			var max = parseFloat($(this).parents("tr").find('input[id="max"]').first().val());

			input.each(function(){
				if($(this).attr('id') == 'min'){
					if(min >= max){
						$(this).addClass("error");
						$(this)[0].reportValidity();
						empty = true;
					} else{
						$(this).removeClass("error");
					}
				}else if($(this).attr('id') == 'max'){
					if(max <= min){
						$(this).addClass("error");
						$(this)[0].reportValidity();
						empty = true;
					} else{
						$(this).removeClass("error");
					}
				}else{
					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){
				input.each(function(){
					$(this).parent("td").html($(this).val());
				});
				$(this).parents("tr").find(".add, .edit").toggle();
				$(".new8").removeAttr("disabled");
			}
		});
// Edit row on edit button click
		$(document).on("click", ".edit8", function(){
			$(this).parents("tr").find("td:not(:last-child)").each(function(index){
				if(index == 0)
					$(this).html('<input type="number" required class="form-control" min="0" id="min" value="' + $(this).text() + '">');
				if(index == 1)
					$(this).html('<input type="number" required class="form-control" id="max" value="' + $(this).text() + '">');
				if(index == 2)
					$(this).html('<input type="number" required class="form-control"  min="0" value="' + $(this).text() + '">');
			});
			$(this).parents("tr").find(".add, .edit").toggle();
			$(".new8").attr("disabled", "disabled");
		});
// Delete row on delete button click
		$(document).on("click", ".delete8", function(){
			$(this).parents("tr").remove();
			$(".new8").removeAttr("disabled");
		});

		// Table 9
		var actions9 = $("#agent_depot_wallet_national td:last-child").html();
// Append table with add row form on add new button click
		$(".new9").click(function(){
			if(!actions9){
				actions9 = '<a class="add add9" title="Add" data-toggle="tooltip"><i class="material-icons">&#xE09B;</i></a>\n' +
						'                            <a class="edit edit9" title="Edit" data-toggle="tooltip"><i class="material-icons">&#xE254;</i></a>\n' +
						'                            <a class="delete delete9" title="Delete" data-toggle="tooltip"><i class="material-icons">&#xE992;</i></a>';
			}
			$(this).attr("disabled", "disabled");
			var index = $("#agent_depot_wallet_national tbody tr:last-child").index();
			var row = '<tr>' +
					'<td><input type="number" required min="0" class="form-control" name="min" id="min"></td>' +
					'<td><input type="number" required class="form-control" name="max" id="max"></td>' +
					'<td><input type="number" required class="form-control" name="taux" id="taux"></td>' +
					'<td> ' + actions9 +'</td>' +
					'</tr>';
			$("#agent_depot_wallet_national").append(row);
			$("#agent_depot_wallet_national tbody tr").eq(index + 1).find(".add, .edit").toggle();
			$('[data-toggle="tooltip"]').tooltip();
		});
// Add row on add button click
		$(document).on("click", ".add9", function(){
			var empty = false;
			var input = $(this).parents("tr").find('input[type="number"]');
			var min = parseFloat($(this).parents("tr").find('input[id="min"]').first().val());
			var max = parseFloat($(this).parents("tr").find('input[id="max"]').first().val());

			input.each(function(){
				if($(this).attr('id') == 'min'){
					if(min >= max){
						$(this).addClass("error");
						$(this)[0].reportValidity();
						empty = true;
					} else{
						$(this).removeClass("error");
					}
				}else if($(this).attr('id') == 'max'){
					if(max <= min){
						$(this).addClass("error");
						$(this)[0].reportValidity();
						empty = true;
					} else{
						$(this).removeClass("error");
					}
				}else{
					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){
				input.each(function(){
					$(this).parent("td").html($(this).val());
				});
				$(this).parents("tr").find(".add, .edit").toggle();
				$(".new9").removeAttr("disabled");
			}
		});
// Edit row on edit button click
		$(document).on("click", ".edit9", function(){
			$(this).parents("tr").find("td:not(:last-child)").each(function(index){
				if(index == 0)
					$(this).html('<input type="number" required class="form-control" min="0" id="min" value="' + $(this).text() + '">');
				if(index == 1)
					$(this).html('<input type="number" required class="form-control" id="max" value="' + $(this).text() + '">');
				if(index == 2)
					$(this).html('<input type="number" required class="form-control"  min="0" value="' + $(this).text() + '">');
			});
			$(this).parents("tr").find(".add, .edit").toggle();
			$(".new9").attr("disabled", "disabled");
		});
// Delete row on delete button click
		$(document).on("click", ".delete9", function(){
			$(this).parents("tr").remove();
			$(".new9").removeAttr("disabled");
		});

		// Table 10
		var actions10 = $("#agent_depot_autre_wallet_national td:last-child").html();
// Append table with add row form on add new button click
		$(".new10").click(function(){
			if(!actions10){
				actions10 = '<a class="add add10" title="Add" data-toggle="tooltip"><i class="material-icons">&#xE010B;</i></a>\n' +
						'                            <a class="edit edit10" title="Edit" data-toggle="tooltip"><i class="material-icons">&#xE254;</i></a>\n' +
						'                            <a class="delete delete10" title="Delete" data-toggle="tooltip"><i class="material-icons">&#xE10102;</i></a>';
			}
			$(this).attr("disabled", "disabled");
			var index = $("#agent_depot_autre_wallet_national tbody tr:last-child").index();
			var row = '<tr>' +
					'<td><input type="number" required min="0" class="form-control" name="min" id="min"></td>' +
					'<td><input type="number" required class="form-control" name="max" id="max"></td>' +
					'<td><input type="number" required class="form-control" name="taux" id="taux"></td>' +
					'<td> ' + actions10 +'</td>' +
					'</tr>';
			$("#agent_depot_autre_wallet_national").append(row);
			$("#agent_depot_autre_wallet_national tbody tr").eq(index + 1).find(".add, .edit").toggle();
			$('[data-toggle="tooltip"]').tooltip();
		});
// Add row on add button click
		$(document).on("click", ".add10", function(){
			var empty = false;
			var input = $(this).parents("tr").find('input[type="number"]');
			var min = parseFloat($(this).parents("tr").find('input[id="min"]').first().val());
			var max = parseFloat($(this).parents("tr").find('input[id="max"]').first().val());

			input.each(function(){
				if($(this).attr('id') == 'min'){
					if(min >= max){
						$(this).addClass("error");
						$(this)[0].reportValidity();
						empty = true;
					} else{
						$(this).removeClass("error");
					}
				}else if($(this).attr('id') == 'max'){
					if(max <= min){
						$(this).addClass("error");
						$(this)[0].reportValidity();
						empty = true;
					} else{
						$(this).removeClass("error");
					}
				}else{
					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){
				input.each(function(){
					$(this).parent("td").html($(this).val());
				});
				$(this).parents("tr").find(".add, .edit").toggle();
				$(".new10").removeAttr("disabled");
			}
		});
// Edit row on edit button click
		$(document).on("click", ".edit10", function(){
			$(this).parents("tr").find("td:not(:last-child)").each(function(index){
				if(index == 0)
					$(this).html('<input type="number" required class="form-control" min="0" id="min" value="' + $(this).text() + '">');
				if(index == 1)
					$(this).html('<input type="number" required class="form-control" id="max" value="' + $(this).text() + '">');
				if(index == 2)
					$(this).html('<input type="number" required class="form-control"  min="0" value="' + $(this).text() + '">');
			});
			$(this).parents("tr").find(".add, .edit").toggle();
			$(".new10").attr("disabled", "disabled");
		});
// Delete row on delete button click
		$(document).on("click", ".delete10", function(){
			$(this).parents("tr").remove();
			$(".new10").removeAttr("disabled");
		});

		// Table 11
		var actions11 = $("#agent_cash_cash_national td:last-child").html();
// Append table with add row form on add new button click
		$(".new11").click(function(){
			if(!actions11){
				actions11 = '<a class="add add11" title="Add" data-toggle="tooltip"><i class="material-icons">&#xE011B;</i></a>\n' +
						'                            <a class="edit edit11" title="Edit" data-toggle="tooltip"><i class="material-icons">&#xE254;</i></a>\n' +
						'                            <a class="delete delete11" title="Delete" data-toggle="tooltip"><i class="material-icons">&#xE11112;</i></a>';
			}
			$(this).attr("disabled", "disabled");
			var index = $("#agent_cash_cash_national tbody tr:last-child").index();
			var row = '<tr>' +
					'<td><input type="number" required min="0" class="form-control" name="min" id="min"></td>' +
					'<td><input type="number" required class="form-control" name="max" id="max"></td>' +
					'<td><input type="number" required class="form-control" name="taux" id="taux"></td>' +
					'<td> ' + actions11 +'</td>' +
					'</tr>';
			$("#agent_cash_cash_national").append(row);
			$("#agent_cash_cash_national tbody tr").eq(index + 1).find(".add, .edit").toggle();
			$('[data-toggle="tooltip"]').tooltip();
		});
// Add row on add button click
		$(document).on("click", ".add11", function(){
			var empty = false;
			var input = $(this).parents("tr").find('input[type="number"]');
			var min = parseFloat($(this).parents("tr").find('input[id="min"]').first().val());
			var max = parseFloat($(this).parents("tr").find('input[id="max"]').first().val());

			input.each(function(){
				if($(this).attr('id') == 'min'){
					if(min >= max){
						$(this).addClass("error");
						$(this)[0].reportValidity();
						empty = true;
					} else{
						$(this).removeClass("error");
					}
				}else if($(this).attr('id') == 'max'){
					if(max <= min){
						$(this).addClass("error");
						$(this)[0].reportValidity();
						empty = true;
					} else{
						$(this).removeClass("error");
					}
				}else{
					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){
				input.each(function(){
					$(this).parent("td").html($(this).val());
				});
				$(this).parents("tr").find(".add, .edit").toggle();
				$(".new11").removeAttr("disabled");
			}
		});
// Edit row on edit button click
		$(document).on("click", ".edit11", function(){
			$(this).parents("tr").find("td:not(:last-child)").each(function(index){
				if(index == 0)
					$(this).html('<input type="number" required class="form-control" min="0" id="min" value="' + $(this).text() + '">');
				if(index == 1)
					$(this).html('<input type="number" required class="form-control" id="max" value="' + $(this).text() + '">');
				if(index == 2)
					$(this).html('<input type="number" required class="form-control"  min="0" value="' + $(this).text() + '">');
			});
			$(this).parents("tr").find(".add, .edit").toggle();
			$(".new11").attr("disabled", "disabled");
		});
// Delete row on delete button click
		$(document).on("click", ".delete11", function(){
			$(this).parents("tr").remove();
			$(".new11").removeAttr("disabled");
		});

	});

</script>

<script>
	// Taxes
	$(document).ready(function() {
		$('[data-toggle="tooltip"]').tooltip();
		var actions5 = $("#transactions_taxes 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 = $("#transactions_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> <select class='form-control' id='destination' required> <option value='national'> national </option> <option value='international'> international </option> </select> </td>" +
					"<td>" + actions5 + "</td>" +
					"</tr>";
			$("#transactions_taxes").append(row);
			$("#transactions_taxes 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="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() + '">');
				if(index == 3)
					$(this).html("<select class='form-control' id='destination' required> <option value='national'> national </option> <option value='international'> international </option> </select>");
			});
			$(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>
<!-- Page script -->
<script src="<?php echo base_url('dist/js/custom.js') ?>"></script>
