<?php
include "config/init.php";
include "template/header.php";
//Main Header
include "template/main-header.php";
//Left side column. contains the logo and sidebar -->
include "template/main-sidebar.php";
?>

<?php
$curl = curl_init();

        curl_setopt_array($curl, array(
        CURLOPT_URL => 'https://main.payappglobal.com/admin/system/super/super-api-index.php',
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING => '',
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_TIMEOUT => 0,
        CURLOPT_FOLLOWLOCATION => true,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST => 'POST',
        CURLOPT_POSTFIELDS =>'{
                    "action": "WalletBalance",
                    "momoNumber": "' . "" .'",
                    "channel": "' . "" . '"
        }',
        CURLOPT_HTTPHEADER => array(
            'ck:  ' . "1111v" . '',
            'sk:  ' . "2222v"  . '',
            'Content-Type: application/json'
        ),
        ));

        $response = curl_exec($curl);

        curl_close($curl);
        $result = json_decode($response, true);
//var_dump($result["balance"]);
?>

    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <h1>
                Dashboard For <?=($_SESSION["userCountry"]=="lr" or $_SESSION["userCountry"]=="lr1")? substr(strtoupper(get_system_country_by_countryCode($dbc,$_SESSION["userCountry"])['countryName']),0,-5) : strtoupper(get_system_country_by_countryCode($dbc,$_SESSION["userCountry"])['countryName']) ;?>
            </h1>
            <ol class="breadcrumb">
                <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
                <li class="active">Dashboard</li>
            </ol>
        </section>

        <!-- Main content -->
        <section class="content">
            <div class="row">
                <div class="col-md-6">
                    <canvas id="ctx_daily_reg"></canvas>
                </div>
            </div>
            <div class="row">
				<?php 
				if($_SESSION["userCountry"]=="gh"){
					
				?>
				
                <div class="col-md-12">
                    <div class="small-box bg-yellow-gradient">
                        <div class="inner">
                            <h4><?=total_customers_by_country($dbc,'gh')?></h4>
                            <p>Users in Ghana</p>
                        </div>
                        <div class="icon">
                            <i class="fa fa-users"></i>
                        </div>
                        <a href="#" class="small-box-footer">More info <i class="fa fa-arrow-circle-right"></i></a>
                    </div>
                </div>
<?php } ?>
				
				<?php 
				if($_SESSION["userCountry"]=="lr" or $_SESSION["userCountry"]=="lr1"){
					
				?>
                <div class="col-md-12">
                    <div class="small-box bg-aqua-gradient">
                        <div class="inner">
                            <h4><?=(total_customers_by_country($dbc,'lr') + total_customers_by_country($dbc,'lr1'))?></h4>
                            <p>Users in Liberia</p>
                        </div>
                        <div class="icon">
                            <i class="fa fa-users"></i>
                        </div>
                        <a href="#" class="small-box-footer">More info <i class="fa fa-arrow-circle-right"></i></a>
                    </div>
                </div>
				
				<?php } ?>
				
                <?php 
				if($_SESSION["userCountry"]=="us"){
					
				?>
                <div class="col-md-12">
                    <div class="small-box bg-gray">
                        <div class="inner">
                            <h4><?=total_customers_by_country($dbc,'us')?></h4>
                            <p>Users in United States</p>
                        </div>
                        <div class="icon">
                            <i class="fa fa-users"></i>
                        </div>
                        <a href="#" class="small-box-footer">More info <i class="fa fa-arrow-circle-right"></i></a>
                    </div>
                </div>
				
				<?php } ?>
				
                <?php 
				if($_SESSION["userCountry"]=="gb"){
					
				?>
                <div class="col-md-12">
                    <div class="small-box bg-red-gradient">
                        <div class="inner">
                            <h4><?=total_customers_by_country($dbc,'gb')?></h4>
                            <p>Users in United Kingdom</p>
                        </div>
                        <div class="icon">
                            <i class="fa fa-users"></i>
                        </div>
                        <a href="#" class="small-box-footer">More info <i class="fa fa-arrow-circle-right"></i></a>
                    </div>
                </div>
			
				<?php } ?>
				
            </div>
            <div class="row">
                <?php 
				if($_SESSION["userCountry"]=="ag"){
					
				?>
                <div class="col-md-12">
                    <div class="small-box bg-green-gradient">
                        <div class="inner">
                            <h4><?=total_customers_by_country($dbc,'ag')?></h4>
                            <p>Users in Antigua and Barbuda</p>
                        </div>
                        <div class="icon">
                            <i class="fa fa-users"></i>
                        </div>
                        <a href="#" class="small-box-footer">More info <i class="fa fa-arrow-circle-right"></i></a>
                    </div>
                </div>
				
				<?php } ?>
				
            </div>

            <div class="row">
                <div class="col-md-12">
					<?php 
				if($_SESSION["userCountry"]=="gh"){
					
				?>
                    <div class="row">
                        <!-- All Ghana Transactions -->
                        <div class="col-md-3">
                            <div class="info-box">
                                <span class="info-box-icon bg-yellow"><i class="fa fa-money"></i></span>

                                <div class="info-box-content">
                                    <span class="info-box-text">GH Main Transaction</span>
                                    <span class="info-box-number"><?=moneyFormat(total_daily_main_transaction_by_country($dbc,'gh'))?></span>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-3">
                            <div class="info-box">
                                <span class="info-box-icon bg-yellow"><i class="fa fa-money"></i></span>

                                <div class="info-box-content">
                                    <span class="info-box-text">GH Airtime Transaction</span>
                                    <span class="info-box-number"><?=moneyFormat(total_daily_airtime_transaction_by_country($dbc,'gh'))?></span>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-3">
                            <div class="info-box">
                                <span class="info-box-icon bg-yellow"><i class="fa fa-money"></i></span>

                                <div class="info-box-content">
                                    <span class="info-box-text">GH Bank Transaction</span>
                                    <span class="info-box-number"><?=moneyFormat(total_daily_bank_transaction_by_country($dbc))?></span>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-3">
                            <div class="info-box">
                                <span class="info-box-icon bg-yellow"><i class="fa fa-money"></i></span>
                                <div class="info-box-content">
                                    <span class="info-box-text">GH Commission</span>
                                    <span class="info-box-number"><?=moneyFormat(total_daily_commission_by_country($dbc,'gh'))?></span>
                                </div>
                            </div>
                        </div>
                    </div>
					
					<?php } ?>
					
					<?php 
				if($_SESSION["userCountry"]=="lr" or $_SESSION["userCountry"]=="lr1"){
					
				?>
					
                    <div class="row">
                        <!-- All Liberia Transactions -->
                        <div class="col-md-4">
                            <div class="info-box">
                                <span class="info-box-icon bg-light-blue"><i class="fa fa-money"></i></span>

                                <div class="info-box-content">
                                    <span class="info-box-text">LR Main Transaction</span>
                                    <span class="info-box-number">USD <?=moneyFormat(total_daily_main_transaction_by_country($dbc,'lr'))?> / LRD <?=moneyFormat(total_daily_main_transaction_by_country($dbc,'lr1'))?></span>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-4">
                            <div class="info-box">
                                <span class="info-box-icon bg-light-blue"><i class="fa fa-money"></i></span>

                                <div class="info-box-content">
                                    <span class="info-box-text">LR Airtime Transaction</span>
                                    <span class="info-box-number">USD <?=moneyFormat(total_daily_airtime_transaction_by_country($dbc,'lr'))?>  /  LRD <?=moneyFormat(total_daily_airtime_transaction_by_country($dbc,'lr1'))?></span>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-4">
                            <div class="info-box">
                                <span class="info-box-icon bg-light-blue"><i class="fa fa-money"></i></span>
                                <div class="info-box-content">
                                    <span class="info-box-text">LR Commission</span>
                                    <span class="info-box-number">USD <?=moneyFormat(total_daily_commission_by_country($dbc,'lr'))?>  /  LRD <?=moneyFormat(total_daily_commission_by_country($dbc,'lr1'))?></span>
                                </div>
                            </div>
                        </div>
                    </div>
					
					<?php } ?>
					
					<?php 
				if($_SESSION["userCountry"]=="us"){
					
				?>
					
                    <div class="row">
                        <!-- All United States Transactions -->
                        <div class="col-md-4">
                            <div class="info-box">
                                <span class="info-box-icon bg-gray-light"><i class="fa fa-money"></i></span>

                                <div class="info-box-content">
                                    <span class="info-box-text">USA Main Transaction</span>
                                    <span class="info-box-number"><?=moneyFormat(total_daily_main_transaction_by_country($dbc,'us'))?></span>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-4">
                            <div class="info-box">
                                <span class="info-box-icon bg-gray-light"><i class="fa fa-money"></i></span>

                                <div class="info-box-content">
                                    <span class="info-box-text">USA Airtime Transaction</span>
                                    <span class="info-box-number"><?=moneyFormat(total_daily_airtime_transaction_by_country($dbc,'us'))?></span>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-4">
                            <div class="info-box">
                                <span class="info-box-icon bg-gray-light"><i class="fa fa-money"></i></span>
                                <div class="info-box-content">
                                    <span class="info-box-text">USA Commission</span>
                                    <span class="info-box-number"><?=moneyFormat(total_daily_commission_by_country($dbc,'us'))?></span>
                                </div>
                            </div>
                        </div>
                    </div>
					
					<?php } ?>
					
						<?php 
				if($_SESSION["userCountry"]=="gb"){
					
				?>
					
					
                    <div class="row">
                        <!-- All United Kingdom Transactions -->
                        <div class="col-md-3">
                            <div class="info-box">
                                <span class="info-box-icon bg-red"><i class="fa fa-money"></i></span>

                                <div class="info-box-content">
                                    <span class="info-box-text">UK Bank Transaction</span>
                                    <span class="info-box-number">GBP <?=moneyFormat(get_main_transaction_by_bank($dbc,'gb'))?></span>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-3">
                            <div class="info-box">
                                <span class="info-box-icon bg-red"><i class="fa fa-money"></i></span>

                                <div class="info-box-content">
                                    <span class="info-box-text">UK Airtime Transaction</span>
                                    <span class="info-box-number">GBP <?=moneyFormat(get_main_transaction_by_airtime($dbc,'gb'))?></span>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-3">
                            <div class="info-box">
                                <span class="info-box-icon bg-red"><i class="fa fa-money"></i></span>
                                <div class="info-box-content">
                                    <span class="info-box-text">UK Momo Transaction</span>
                                    <span class="info-box-number">GBP <?=moneyFormat(get_main_transaction_by_momo($dbc,'gb'))?></span>
                                </div>
                            </div>
                        </div>
						
						<div class="col-md-3">
                            <div class="info-box">
                                <span class="info-box-icon bg-blue"><i class="fa fa-money"></i></span>
                                <div class="info-box-content">
                                    <span class="info-box-text">Remittance Wallet Balance</span>
                                    <span class="info-box-number">USD <?=moneyFormat($result["balance"])?></span>
                                </div>
                            </div>
                        </div>
                    </div>
					
					<?php } ?>					
					
                </div>
            </div>
            <div class="row">
                <?php 
				if($_SESSION["userCountry"]=="gh"){
					
				?>
                <div class="col-md-12">
                    <div class="myBox bg-red">
                        <h4> GHC <?=moneyFormat(total_main_transactions_country($dbc,'gh'))?></h4>
                        <h5>GH Main Transaction</h5>
                    </div>
                </div>
				
				<?php } ?>	
				<?php 
				if($_SESSION["userCountry"]=="gb"){
					
				?>
                <div class="col-md-12">
                    <div class="myBox bg-red">
                        <h4> GBP <?=moneyFormat(get_main_transaction_by_airtime($dbc,'gb')+get_main_transaction_by_bank($dbc,'gb')+get_main_transaction_by_momo($dbc,'gb'))?></h4>
                        <h5>GB/UK Main Transaction</h5>
                    </div>
                </div>
				<?php } ?>
				
				<?php 
				if($_SESSION["userCountry"]=="lr" or $_SESSION["userCountry"]=="lr1"){
					
				?>
                <div class="col-md-12">
                    <div class="myBox bg-red">
                        <h4> USD <?=moneyFormat(total_main_transactions_country($dbc,'lr'))?> / LRD <?=moneyFormat(total_main_transactions_country($dbc,'lr1'))?> </h4>
                        <h5>LR Main Transaction</h5>
                    </div>
                </div>
				
				<?php } ?>
				
                <?php 
				if($_SESSION["userCountry"]=="us"){
					
				?>
                <div class="col-md-12">
                    <div class="myBox bg-red">
                        <h4> USD <?=moneyFormat(total_main_transactions_country($dbc,'us'))?></h4>
                        <h5>US Main Transaction</h5>
                    </div>
                </div>
				
				<?php } ?>

            </div>
            <div class="row">
                <?php 
				if($_SESSION["userCountry"]=="ag"){
					
				?>
                <div class="col-md-12">
                    <div class="myBox bg-red">
                        <h4> ECD <?=moneyFormat(total_main_transactions_country($dbc,'ag'))?></h4>
                        <h5>AG Main Transaction</h5>
                    </div>
                </div>
				
				<?php } ?>

            </div>
        </section>
        <!-- /.content -->
    </div>
    <!-- /.content-wrapper -->

<?php include "template/footer.php"?>
<script>
    $.ajax({
        url: "/admin/config/ajax/ajax-chart-daily_registration.php",
        method: "GET",
        dataType: "JSON",
        success: function(data) {
            console.log(data);
            var myDay = [];
            var myNum = [];

            for(var i in data){
                myDay.push("Day " + data[i].Day);
                myNum.push(data[i].Num)
            }

            var chartData = {
                labels: myDay,
                datasets: [
                    {
                        label : 'Daily Customer Registration',
                        backgroundColor: 'rgba(222, 198, 43, 1)',
                        borderColor: 'rgba(200,200,200,0.75)',
                        hoverBackgroundColor: 'rgba(200,200,200,1)',
                        hoverBorderColor: 'rgba(200,200,200,0.75)',
                        data: myNum

                    }
                ]
            }

            var ctx = $('#ctx_daily_reg');

            var barGraph = new Chart(ctx,{
                type: 'bar',
                data: chartData
            });
        },
        error: function (data) {
            console.log(data);
        }

    });
</script>

