<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Monitor extends CI_Controller
{
    public function __construct()
    {
        parent::__construct();
    }


    function index()
    {
        $this->Model_squrity->getsqurity();
        $this->Model_squrity->cekmenu('monitor');

        $data['title'] = 'arifahpulsa';
        $data['halaman'] = 'Dashboard';


        $this->load->view('monitor', $data);
    }

    function aksi_transaksi()
    {
        $this->Model_squrity->getsqurity();
        $this->Model_squrity->cekmenu('dashboard');

        $db_arifahpulsa_api = $this->load->database('db_arifahpulsa_api', TRUE);

        //PENDAPATAN
        $pendapatan = $db_arifahpulsa_api->query("SELECT sum(trx_pendapatan_jumlah) as transaksi_pendapatan from tbl_trx_pendapatan");
        if ($pendapatan->num_rows() > 0) {
            foreach ($pendapatan->result() as $row) {
                $data['transaksi_pendapatan'] = number_format($row->transaksi_pendapatan, 0, ',', '.');
            }
        } else {
            $data['transaksi_pendapatan'] = '0';
        }

        //SALDO USER
        $saldo = $db_arifahpulsa_api->query("SELECT sum(mst_saldo_jumlah) as transaksi_saldo from tbl_mst_saldo");
        if ($saldo->num_rows() > 0) {
            foreach ($saldo->result() as $row) {
                $data['transaksi_saldo'] = number_format($row->transaksi_saldo, 0, ',', '.');
            }
        } else {
            $data['transaksi_saldo'] = '0';
        }

        //TRANSAKSI TOTAL
        $transaksi = $db_arifahpulsa_api->query("SELECT sum(trx_transaksi_jumlah) as transaksi_jumlah from tbl_trx_transaksi where trx_transaksi_rc in ('1','00','03')");
        if ($transaksi->num_rows() > 0) {
            foreach ($transaksi->result() as $row) {
                $data['transaksi_jumlah'] = number_format($row->transaksi_jumlah, 0, ',', '.');
            }
        } else {
            $data['transaksi_jumlah'] = '0';
        }

        //JUMLAH USER
        $user = $db_arifahpulsa_api->query("SELECT count(mst_user_kode) as transaksi_user from tbl_mst_user");
        if ($user->num_rows() > 0) {
            foreach ($user->result() as $row) {
                $data['transaksi_user'] = number_format($row->transaksi_user, 0, ',', '.');
            }
        } else {
            $data['transaksi_user'] = '0';
        }

        echo json_encode($data);
    }
}
