-
Notifications
You must be signed in to change notification settings - Fork 170
Expand file tree
/
Copy pathdashboard_model.php
More file actions
executable file
·136 lines (128 loc) · 6.14 KB
/
dashboard_model.php
File metadata and controls
executable file
·136 lines (128 loc) · 6.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<?php
// ##############################################################################
// ASTPP - Open Source VoIP Billing Solution
//
// Copyright (C) 2016 iNextrix Technologies Pvt. Ltd.
// Samir Doshi <samir.doshi@inextrix.com>
// ASTPP Version 3.0 and above
// License https://www.gnu.org/licenses/agpl-3.0.html
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
// ##############################################################################
class Dashboard_model extends CI_Model {
function __construct() {
parent::__construct ();
}
function get_recent_recharge() {
$accountinfo = $this->session->userdata ( 'accountinfo' );
$userlevel_logintype = $this->session->userdata ( 'userlevel_logintype' );
$where_arr = array (
'payment_by' => - 1
);
if ($userlevel_logintype == 1) {
$where_arr = array (
'payment_by' => $accountinfo ['id']
);
}
if ($userlevel_logintype == 0 || $userlevel_logintype == 3) {
$where_arr = array (
'accountid' => $accountinfo ['id']
);
}
$this->db->where ( $where_arr );
$this->db->select ( 'id,accountid,credit,payment_date' );
$this->db->limit ( 12 );
$this->db->order_by ( 'payment_date', 'desc' );
return $this->db->get ( 'payments' );
}
function get_call_statistics($table, $parent_id, $start_date = '', $end_date = '', $group_flag = true) {
// ASTPPCOM-891 Ashish start
$this->db->select ( "sum(total_calls) as sum,
SUM(total_answered_call) as answered,
MAX(mcd) AS mcd,
SUM(billseconds) AS duration,
SUM(total_fail_call) as failed,
SUM(billseconds) as billable,
sum(debit-cost) as profit,
sum(debit) as debit,
sum(cost) as cost,
SUM(total_answered_call) as completed,
calldate as day", false );
// ASTPPCOM-891 Ashish end
$this->db->where ( 'calldate >=', $start_date . " 00:00:00" );
$this->db->where ( 'calldate <=', $end_date . " 23:59:59" );
$this->db->where ( 'reseller_id', $parent_id );
if ($group_flag)
$this->db->group_by ( "DAY(calldate)" );
$result = $this->db->get ( $table );
return $result;
}
function get_customer_maximum_callminutes($start_date, $end_date) {
$start_date = $start_date . " 00:00:00";
$end_date = $end_date . " 23:59:59";
$accountinfo = $this->session->userdata ( 'accountinfo' );
$parent_id = ($accountinfo ['type'] == 1) ? $accountinfo ['id'] : 0;
if ($this->session->userdata ( 'userlevel_logintype' ) != 0 && $this->session->userdata ( 'userlevel_logintype' ) != 3) {
$where = "reseller_id ='$parent_id'";
} else {
$where = "accountid ='$parent_id'";
}
$where = $where . " AND calldate >= '" . $start_date . "' AND calldate <= '" . $end_date . "'";
$select_query = "SELECT sum( billseconds ) AS billseconds,account_id FROM (cdrs_day_by_summary) WHERE $where group by account_id order by sum(billseconds) desc limit 10";
return $this->db->query ( $select_query );
}
function get_customer_maximum_countryminutes($start_date, $end_date) {
$start_date = $start_date . " 00:00:00";
$end_date = $end_date . " 23:59:59";
$accountinfo = $this->session->userdata ( 'accountinfo' );
$parent_id = ($accountinfo ['type'] == 1) ? $accountinfo ['id'] : 0;
if ($this->session->userdata ( 'userlevel_logintype' ) != 0 && $this->session->userdata ( 'userlevel_logintype' ) != 3) {
$where = "reseller_id ='$parent_id'";
} else {
$where = "accountid ='$parent_id'";
}
$where = $where . " AND country_id != '0' AND calldate >= '" . $start_date . "' AND calldate <= '" . $end_date . "'";
$select_query = "SELECT sum( billseconds ) AS billseconds,country_id FROM (cdrs_day_by_summary) WHERE $where group by country_id order by sum(billseconds) desc limit 10";
return $this->db->query ( $select_query );
}
function get_customer_maximum_callcount($start_date, $end_date) {
$start_date = $start_date . " 00:00:00";
$end_date = $end_date . " 23:59:59";
$accountinfo = $this->session->userdata ( 'accountinfo' );
$parent_id = ($accountinfo ['type'] == 1) ? $accountinfo ['id'] : 0;
if ($this->session->userdata ( 'userlevel_logintype' ) != 0 && $this->session->userdata ( 'userlevel_logintype' ) != 3) {
$where = "reseller_id ='$parent_id'";
} else {
$where = "accountid ='$parent_id'";
}
$where = $where . " AND calldate >= '" . $start_date . "' AND calldate <= '" . $end_date . "'";
$select_query = "SELECT SUM(total_calls) as call_count, `account_id` FROM (`cdrs_day_by_summary`) WHERE $where GROUP BY `account_id` ORDER BY `call_count` desc LIMIT 10";
return $this->db->query ( $select_query );
}
function get_customer_maximum_countrycount($start_date, $end_date) {
$start_date = $start_date . " 00:00:00";
$end_date = $end_date . " 23:59:59";
$accountinfo = $this->session->userdata ( 'accountinfo' );
$parent_id = ($accountinfo ['type'] == 1) ? $accountinfo ['id'] : 0;
if ($this->session->userdata ( 'userlevel_logintype' ) != 0 && $this->session->userdata ( 'userlevel_logintype' ) != 3) {
$where = "reseller_id ='$parent_id'";
} else {
$where = "accountid ='$parent_id'";
}
$where = $where . " AND country_id != '0' AND calldate >= '" . $start_date . "' AND calldate <= '" . $end_date . "'";
$select_query = "SELECT SUM(total_calls) as call_count, `country_id` FROM (`cdrs_day_by_summary`) WHERE $where GROUP BY `country_id` ORDER BY `call_count` desc LIMIT 10";
return $this->db->query ( $select_query );
}
}
?>