1 | <?php
|
---|
2 | if (!defined('BASEPATH'))
|
---|
3 | exit('No direct script access allowed');
|
---|
4 |
|
---|
5 | class Collabolator_model extends MY_Model {
|
---|
6 |
|
---|
7 | protected $table_name = 'tblcollaborator';
|
---|
8 | protected $id_name = 'id';
|
---|
9 |
|
---|
10 | function __construct() {
|
---|
11 | parent::__construct();
|
---|
12 | }
|
---|
13 |
|
---|
14 | function getCollaborators($data) {
|
---|
15 | $sql = "SELECT * FROM " . $this->table_name;
|
---|
16 | if ($data['keyword']) {
|
---|
17 | if ($data['search_field'] == "cellphone") {
|
---|
18 | if(strlen($data['daterange_start'])>0){
|
---|
19 | $sql.=" WHERE (cellphone LIKE '%" . $data['keyword'] . "%' OR full_name LIKE '%".$data['keyword']."%' OR district LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%') AND (created_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."')";
|
---|
20 | }else{
|
---|
21 | $sql.=" WHERE (cellphone LIKE '%" . $data['keyword'] . "%' OR full_name LIKE '%".$data['keyword']."%' OR district LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%')";
|
---|
22 | }
|
---|
23 | } else {
|
---|
24 | if(strlen($data['daterange_start'])>0){
|
---|
25 | $sql.=" WHERE (full_name LIKE '%" . $data['keyword'] . "%' OR login_name LIKE '%" . $data['keyword'] . "%' OR district LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%') AND (created_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."')";
|
---|
26 | }else{
|
---|
27 | $sql.=" WHERE (full_name LIKE '%" . $data['keyword'] . "%' OR login_name LIKE '%" . $data['keyword'] . "%' OR district LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%')";
|
---|
28 | }
|
---|
29 | }
|
---|
30 | }else{
|
---|
31 | if(strlen($data['daterange_start'])>0){
|
---|
32 | $sql.=" WHERE created_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."'";
|
---|
33 | }
|
---|
34 | }
|
---|
35 |
|
---|
36 | $order = "";
|
---|
37 | if ($data['sorting_order'] != "sorting") {
|
---|
38 |
|
---|
39 | $sort = "DESC";
|
---|
40 | if ($data['sorting_order'] == "sorting_asc")
|
---|
41 | $sort = "ASC";
|
---|
42 | $order = "ORDER BY " . $data['sorting_field'] . " " . $sort;
|
---|
43 |
|
---|
44 | }
|
---|
45 |
|
---|
46 | return $this->db->query($sql . " " . $order . " LIMIT " . $data['start'] . ", " . $data['perpage'] . " ")->result_array();
|
---|
47 | }
|
---|
48 |
|
---|
49 | function getAllCollaboratorUser($from,$id=false)
|
---|
50 | {
|
---|
51 | $from = date("Y-m-d 00:00:00",$from);
|
---|
52 | $order = "";
|
---|
53 | if ($data['sorting_order'] != "sorting") {
|
---|
54 |
|
---|
55 | $sort = "DESC";
|
---|
56 | if ($data['sorting_order'] == "sorting_asc")
|
---|
57 | $sort = "ASC";
|
---|
58 | $order = "ORDER BY " . $data['sorting_field'] . " " . $sort;
|
---|
59 |
|
---|
60 | }
|
---|
61 | $where="";
|
---|
62 | if ($id)
|
---|
63 | {
|
---|
64 | //$where = " AND tbluser.collaborator = $id ";
|
---|
65 | $where = " AND tblcollaborator.id = $id ";
|
---|
66 | }
|
---|
67 | //$sql="SELECT *,tblcollaborator.created_time as collaborator_created_time, tbluser.created_time as user_created_time FROM ".$this->table_name." INNER JOIN tbluser ON tbluser.collaborator = tblcollaborator.id WHERE tbluser.created_time > '".$from."'".$where."";
|
---|
68 | $sql="SELECT *,tblcollaborator.created_time as collaborator_created_time, tbluser.created_time as user_created_time FROM ".$this->table_name." INNER JOIN tbluser ON tbluser.collaborator = tblcollaborator.cellphone WHERE tbluser.created_time > '".$from."'".$where."";
|
---|
69 |
|
---|
70 | $result = $this->db->query($sql)->result_array();
|
---|
71 | foreach ($result as $index=>$paidlog)
|
---|
72 | {
|
---|
73 | $result[$index]['time']= strtotime($paidlog['user_created_time']);
|
---|
74 | }
|
---|
75 |
|
---|
76 | return $result;
|
---|
77 | }
|
---|
78 | function countCountCollaboratorUser($data)
|
---|
79 | {
|
---|
80 | $order = "";
|
---|
81 | if ($data['sorting_order'] != "sorting") {
|
---|
82 |
|
---|
83 | $sort = "DESC";
|
---|
84 | if ($data['sorting_order'] == "sorting_asc")
|
---|
85 | $sort = "ASC";
|
---|
86 | $order = "ORDER BY " . $data['sorting_field'] . " " . $sort;
|
---|
87 |
|
---|
88 | }
|
---|
89 | $where="";
|
---|
90 | if ($data['keyword']) {
|
---|
91 | if ($data['search_field'] == "cellphone") {
|
---|
92 | $where.=" WHERE (tblcollaborator.cellphone LIKE '%" . $data['keyword'] . "%' OR district LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%')";
|
---|
93 | } else {
|
---|
94 | $where.=" WHERE (full_name LIKE '%" . $data['keyword'] . "%' OR login_name LIKE '%" . $data['keyword'] . "%' OR district LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%') ";
|
---|
95 | }
|
---|
96 | }
|
---|
97 | // $from = date("Y-m-d 00:00:00",$from);
|
---|
98 | //$sql="SELECT *,tblcollaborator.created_time as collaborator_created_time,tblcollaborator.cellphone as collaborator_cellphone, tbluser.created_time as user_created_time, COUNT(tbluser.collaborator) as total_user FROM ".$this->table_name." INNER JOIN tbluser ON tbluser.collaborator = tblcollaborator.id ".$where." GROUP BY tblcollaborator.id ".$order." ";
|
---|
99 |
|
---|
100 | $sql="SELECT *,tblcollaborator.created_time as collaborator_created_time,tblcollaborator.cellphone as collaborator_cellphone, tbluser.created_time as user_created_time, COUNT(tbluser.collaborator) as total_user FROM ".$this->table_name." INNER JOIN tbluser ON tbluser.collaborator = tblcollaborator.cellphone ".$where." GROUP BY tblcollaborator.id ".$order." ";
|
---|
101 |
|
---|
102 | $result = $this->db->query($sql)->result_array();
|
---|
103 |
|
---|
104 |
|
---|
105 | return count($result);
|
---|
106 | }
|
---|
107 | function getCountCollaboratorUser($data)
|
---|
108 | {
|
---|
109 | $order = "";
|
---|
110 | if ($data['sorting_order'] != "sorting") {
|
---|
111 |
|
---|
112 | $sort = "DESC";
|
---|
113 | if ($data['sorting_order'] == "sorting_asc")
|
---|
114 | $sort = "ASC";
|
---|
115 | $order = "ORDER BY " . $data['sorting_field'] . " " . $sort;
|
---|
116 |
|
---|
117 | }
|
---|
118 | $where="";
|
---|
119 | if ($data['keyword']) {
|
---|
120 | if ($data['search_field'] == "cellphone") {
|
---|
121 | $where.=" WHERE (tblcollaborator.cellphone LIKE '%" . $data['keyword'] . "%' OR district LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%')";
|
---|
122 |
|
---|
123 | } else {
|
---|
124 | $where.=" WHERE (full_name LIKE '%" . $data['keyword'] . "%' OR login_name LIKE '%" . $data['keyword'] . "%' OR district LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%') ";
|
---|
125 | }
|
---|
126 | }
|
---|
127 |
|
---|
128 | // $from = date("Y-m-d 00:00:00",$from);
|
---|
129 | //$sql="SELECT *,tblcollaborator.created_time as collaborator_created_time,tblcollaborator.cellphone as collaborator_cellphone, tbluser.created_time as user_created_time, COUNT(tbluser.collaborator) as total_user FROM ".$this->table_name." INNER JOIN tbluser ON tbluser.collaborator = tblcollaborator.id ".$where." GROUP BY tblcollaborator.id ".$order." LIMIT " . $data['start'] . ", " . $data['perpage'] . " ";
|
---|
130 |
|
---|
131 | $sql="SELECT *,tblcollaborator.created_time as collaborator_created_time,tblcollaborator.cellphone as collaborator_cellphone, tbluser.created_time as user_created_time, COUNT(tbluser.collaborator) as total_user FROM ".$this->table_name." INNER JOIN tbluser ON tbluser.collaborator = tblcollaborator.cellphone ".$where." GROUP BY tblcollaborator.id ".$order." LIMIT " . $data['start'] . ", " . $data['perpage'] . " ";
|
---|
132 |
|
---|
133 | $result = $this->db->query($sql)->result_array();
|
---|
134 | foreach ($result as $index=>$paidlog)
|
---|
135 | {
|
---|
136 | $result[$index]['time']= strtotime($paidlog['user_created_time']);
|
---|
137 | }
|
---|
138 |
|
---|
139 | return $result;
|
---|
140 | }
|
---|
141 |
|
---|
142 | function countCountCollaboratorUsers($data)
|
---|
143 | {
|
---|
144 | $order = "";
|
---|
145 | if ($data['sorting_order'] != "sorting") {
|
---|
146 |
|
---|
147 | $sort = "DESC";
|
---|
148 | if ($data['sorting_order'] == "sorting_asc")
|
---|
149 | $sort = "ASC";
|
---|
150 | $order = "ORDER BY " . $data['sorting_field'] . " " . $sort;
|
---|
151 |
|
---|
152 | }
|
---|
153 | $where="";
|
---|
154 | if ($data['keyword']) {
|
---|
155 | if ($data['search_field'] == "cellphone") {
|
---|
156 | $where.=" WHERE (tbluser.cellphone LIKE '%" . $data['keyword'] . "%' OR district LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%')";
|
---|
157 | }
|
---|
158 | }
|
---|
159 | // $from = date("Y-m-d 00:00:00",$from);
|
---|
160 | //$sql="SELECT *,tblcollaborator.created_time as collaborator_created_time,tbluser.cellphone as user_cellphone,tblcollaborator.cellphone as collaborator_cellphone, tbluser.created_time as user_created_time FROM ".$this->table_name." INNER JOIN tbluser ON tbluser.collaborator = tblcollaborator.id ".$where." AND tbluser.collaborator = ".$data['id']." ".$order."";
|
---|
161 | if(strlen($data['daterange_start'])>0){
|
---|
162 | $sql="SELECT *,tblcollaborator.created_time as collaborator_created_time,tbluser.cellphone as user_cellphone,tblcollaborator.cellphone as collaborator_cellphone, tbluser.created_time as user_created_time FROM ".$this->table_name." INNER JOIN tbluser ON tbluser.collaborator = tblcollaborator.cellphone ".$where." AND (tbluser.created_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."') AND tblcollaborator.id = ".$data['id']." ".$order."";
|
---|
163 | }else{
|
---|
164 | $sql="SELECT *,tblcollaborator.created_time as collaborator_created_time,tbluser.cellphone as user_cellphone,tblcollaborator.cellphone as collaborator_cellphone, tbluser.created_time as user_created_time FROM ".$this->table_name." INNER JOIN tbluser ON tbluser.collaborator = tblcollaborator.cellphone ".$where." AND tblcollaborator.id = ".$data['id']." ".$order."";
|
---|
165 | }
|
---|
166 | //write_file('./log/sql.log', date('d-m-Y H:i:s').": ".$sql."\n", FOPEN_WRITE_CREATE);
|
---|
167 | $result = $this->db->query($sql)->result_array();
|
---|
168 |
|
---|
169 | foreach ($result as $index=>$paidlog)
|
---|
170 | {
|
---|
171 | $result[$index]['time']= strtotime($paidlog['user_created_time']);
|
---|
172 | }
|
---|
173 |
|
---|
174 | return count($result);
|
---|
175 | }
|
---|
176 |
|
---|
177 | function getCountCollaboratorUsers($data)
|
---|
178 | {
|
---|
179 | $order = "";
|
---|
180 | if ($data['sorting_order'] != "sorting") {
|
---|
181 | $sort = "DESC";
|
---|
182 | if ($data['sorting_order'] == "sorting_asc")
|
---|
183 | $sort = "ASC";
|
---|
184 | $order = "ORDER BY " . $data['sorting_field'] . " " . $sort;
|
---|
185 |
|
---|
186 | }
|
---|
187 | $where="";
|
---|
188 |
|
---|
189 | if ($data['keyword']) {
|
---|
190 | if ($data['search_field'] == "cellphone") {
|
---|
191 | $where.=" WHERE (tbluser.cellphone LIKE '%" . $data['keyword'] . "%' OR tblcollaborator.district LIKE '%".$data['keyword']."%' OR tblcollaborator.province LIKE '%".$data['keyword']."%')";
|
---|
192 | }
|
---|
193 | }
|
---|
194 |
|
---|
195 | // $from = date("Y-m-d 00:00:00",$from);
|
---|
196 | // $sql="SELECT *,tblcollaborator.created_time as collaborator_created_time,tbluser.cellphone as user_cellphone,tblcollaborator.cellphone as collaborator_cellphone, tbluser.created_time as user_created_time FROM ".$this->table_name." INNER JOIN tbluser ON tbluser.collaborator = tblcollaborator.id ".$where." AND tbluser.collaborator = ".$data['id']." ".$order." LIMIT " . $data['start'] . ", " . $data['perpage'] . " ";
|
---|
197 |
|
---|
198 | if($data['daterange_start']){
|
---|
199 |
|
---|
200 | if ($data['perpage']){
|
---|
201 | $sql="SELECT *,tblcollaborator.created_time as collaborator_created_time,tbluser.cellphone as user_cellphone,tblcollaborator.cellphone as collaborator_cellphone, tbluser.created_time as user_created_time FROM ".$this->table_name." INNER JOIN tbluser ON tbluser.collaborator = tblcollaborator.cellphone ".$where." AND (tbluser.created_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."') AND tblcollaborator.id = ".$data['id']." ".$order." LIMIT " . $data['start'] . ", " . $data['perpage'] . " ";
|
---|
202 | }else{
|
---|
203 | $sql="SELECT *,tblcollaborator.created_time as collaborator_created_time,tbluser.cellphone as user_cellphone,tblcollaborator.cellphone as collaborator_cellphone, tbluser.created_time as user_created_time FROM ".$this->table_name." INNER JOIN tbluser ON tbluser.collaborator = tblcollaborator.cellphone ".$where." AND (tbluser.created_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."') AND tblcollaborator.id = ".$data['id']." ".$order;
|
---|
204 | }
|
---|
205 | }else{
|
---|
206 | if ($data['perpage']){
|
---|
207 | $sql="SELECT *,tblcollaborator.created_time as collaborator_created_time,tbluser.cellphone as user_cellphone,tblcollaborator.cellphone as collaborator_cellphone, tbluser.created_time as user_created_time FROM ".$this->table_name." INNER JOIN tbluser ON tbluser.collaborator = tblcollaborator.cellphone ".$where." AND tblcollaborator.id = ".$data['id']." ".$order." LIMIT " . $data['start'] . ", " . $data['perpage'] . " ";
|
---|
208 | }else{
|
---|
209 | $sql="SELECT *,tblcollaborator.created_time as collaborator_created_time,tbluser.cellphone as user_cellphone,tblcollaborator.cellphone as collaborator_cellphone, tbluser.created_time as user_created_time FROM ".$this->table_name." INNER JOIN tbluser ON tbluser.collaborator = tblcollaborator.cellphone ".$where." AND tblcollaborator.id = ".$data['id']." ".$order;
|
---|
210 | }
|
---|
211 | }
|
---|
212 | $result = $this->db->query($sql)->result_array();
|
---|
213 | foreach ($result as $index=>$paidlog)
|
---|
214 | {
|
---|
215 | $result[$index]['time']= strtotime($paidlog['user_created_time']);
|
---|
216 | }
|
---|
217 |
|
---|
218 | return $result;
|
---|
219 | }
|
---|
220 |
|
---|
221 | function isExist($data) {
|
---|
222 | $sql = "SELECT COUNT(id) as total FROM " . $this->table_name . " WHERE " . $data['field'] . " = '" . $data['value'] . "'";
|
---|
223 | if (isset($data['id']))
|
---|
224 | {
|
---|
225 | $id=$data['id'];
|
---|
226 | $sql.=" AND id <> ".$id." LIMIT 1";
|
---|
227 | }
|
---|
228 | $result = $this->db->query($sql)->row_array();
|
---|
229 | if ($result['total'] == 1) {
|
---|
230 | return true;
|
---|
231 | } else {
|
---|
232 | return false;
|
---|
233 | }
|
---|
234 | }
|
---|
235 |
|
---|
236 | function countCollaborator($data) {
|
---|
237 | $sql = "SELECT COUNT(id) as total FROM " . $this->table_name;
|
---|
238 | if ($data['keyword']) {
|
---|
239 | if ($data['search_field'] == "cellphone") {
|
---|
240 | if(strlen($data['daterange_start'])>0){
|
---|
241 | $sql.=" WHERE (cellphone LIKE '%" . $data['keyword'] . "%' OR full_name LIKE '%".$data['keyword']."%' OR district LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%') AND (created_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."')";
|
---|
242 | }else{
|
---|
243 | $sql.=" WHERE (cellphone LIKE '%" . $data['keyword'] . "%' OR full_name LIKE '%".$data['keyword']."%' OR district LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%')";
|
---|
244 | }
|
---|
245 | } else {
|
---|
246 | if(strlen($data['daterange_start'])>0){
|
---|
247 | $sql.=" WHERE (full_name LIKE '%" . $data['keyword'] . "%' OR login_name LIKE '%" . $data['keyword'] . "%' OR district LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%') AND (created_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."')";
|
---|
248 | }else{
|
---|
249 | $sql.=" WHERE (full_name LIKE '%" . $data['keyword'] . "%' OR login_name LIKE '%" . $data['keyword'] . "%' OR district LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%') ";
|
---|
250 | }
|
---|
251 | }
|
---|
252 | }else{
|
---|
253 | if(strlen($data['daterange_start'])>0){
|
---|
254 | $sql.=" WHERE created_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."'";
|
---|
255 | }
|
---|
256 | }
|
---|
257 | $result = $this->db->query($sql)->row_array();
|
---|
258 | return $result['total'];
|
---|
259 | }
|
---|
260 | function getCollaborator($id)
|
---|
261 | {
|
---|
262 | $sql="SELECT * FROM ".$this->table_name." WHERE id=".$id." LIMIT 1";
|
---|
263 | $result = $this->db->query($sql)->row_array();
|
---|
264 | return $result;
|
---|
265 | }
|
---|
266 | function getStatistics()
|
---|
267 | {
|
---|
268 |
|
---|
269 | $day = date('w');
|
---|
270 | $data = array();
|
---|
271 | $last_month['start'] = strtotime(date("Y-m-d", strtotime(date("Y-m-d", mktime(0, 0, 0, date("m")-1, 1, date("Y"))))) . " 00:00:00");
|
---|
272 | $last_month['end'] = strtotime(date("Y-m-d", strtotime(date("Y-m-d", mktime(0, 0, 0, date("m"), 0, date("Y"))))) . " 23:59:59");
|
---|
273 |
|
---|
274 | $last_week['start'] = strtotime(date("Y-m-d", strtotime(date('m-d-Y', strtotime('-'.$day.' days')))) . " 00:00:00");
|
---|
275 | $last_week['end'] = strtotime(date("Y-m-d", strtotime(date('m-d-Y', strtotime('+'.(6-$day).' days')))) . " 23:59:59");
|
---|
276 |
|
---|
277 | $last_week['end'] = strtotime('last sunday') + (24 * 60 * 60 - 1);
|
---|
278 | $last_week['start'] = ($last_week['end'] - 7 * 24 * 60 * 60 + 1);
|
---|
279 |
|
---|
280 | $last_year['start'] = strtotime((date("Y") - 1) . "-01-01 00:00:00");
|
---|
281 | $last_year['end'] = strtotime((date("Y") - 1) . "-12-31 23:59:59");
|
---|
282 |
|
---|
283 |
|
---|
284 |
|
---|
285 | $last_quarter = $this->getLastquarter();
|
---|
286 | $last_quarter['start'] = $last_quarter['start'];
|
---|
287 | $last_quarter['end'] = $last_quarter['end'];
|
---|
288 |
|
---|
289 |
|
---|
290 | $this->load->model('paidlog_model');
|
---|
291 | $paidlogs = $this->paidlog_model->getAllPaidlogs($last_year['start']);
|
---|
292 |
|
---|
293 | $revenue['last_week'] = 0;
|
---|
294 | $revenue['last_month'] = 0;
|
---|
295 | $revenue['last_quarter'] = 0;
|
---|
296 | $revenue['last_year'] = 0;
|
---|
297 |
|
---|
298 | $lastmonth = strtotime(date("Y-m-d", mktime(0, 0, 0, date("m")-1, 1, date("Y"))));
|
---|
299 | $thismonth = strtotime(date('Y-m-01'));
|
---|
300 | $charts['last_month'] = array(0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0);
|
---|
301 | $charts['this_month'] = array(0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0);
|
---|
302 |
|
---|
303 | $top['last_month']['user']=0;
|
---|
304 | $top['last_month']['sms']=0;
|
---|
305 | $top['last_month']['card']=0;
|
---|
306 | $top['last_month']['collaborator']=0;
|
---|
307 | $top['this_month']['user']=0;
|
---|
308 | $top['this_month']['sms']=0;
|
---|
309 | $top['this_month']['card']=0;
|
---|
310 | $top['this_month']['collaborator']=0;
|
---|
311 |
|
---|
312 | foreach ($paidlogs as $paidlog) {
|
---|
313 |
|
---|
314 |
|
---|
315 | if (($paidlog['time'] < $last_week['end']) && ($paidlog['time'] > $last_week['start'])) {
|
---|
316 |
|
---|
317 | $revenue['last_week']+=$paidlog['amount'];
|
---|
318 | }
|
---|
319 | if (($paidlog['time'] < $last_month['end']) && ($paidlog['time'] > $last_month['start'])) {
|
---|
320 |
|
---|
321 | $revenue['last_month']+=$paidlog['amount'];
|
---|
322 | }
|
---|
323 | if (($paidlog['time'] < $last_quarter['end']) && ($paidlog['time'] > $last_quarter['start'])) {
|
---|
324 |
|
---|
325 | $revenue['last_quarter']+=$paidlog['amount'];
|
---|
326 | }
|
---|
327 | if (($paidlog['time'] < $last_year['end']) && ($paidlog['time'] > $last_year['start'])) {
|
---|
328 |
|
---|
329 | $revenue['last_year']+=$paidlog['amount'];
|
---|
330 | }
|
---|
331 |
|
---|
332 |
|
---|
333 | if (($paidlog['time'] < $lastmonth + (7 * 24 * 60 * 60)) && ($paidlog['time'] > $lastmonth)) {
|
---|
334 | $charts['last_month'][0]+=$paidlog['amount'];
|
---|
335 | }
|
---|
336 | if (($paidlog['time'] < $lastmonth + (14 * 24 * 60 * 60)) && ($paidlog['time'] > $lastmonth + (7 * 24 * 60 * 60))) {
|
---|
337 | $charts['last_month'][1]+=$paidlog['amount'];
|
---|
338 | }
|
---|
339 | if (($paidlog['time'] < $lastmonth + (21 * 24 * 60 * 60)) && ($paidlog['time'] > $lastmonth + (14 * 24 * 60 * 60))) {
|
---|
340 | $charts['last_month'][2]+=$paidlog['amount'];
|
---|
341 | }
|
---|
342 | if (($paidlog['time'] < $lastmonth + (28 * 24 * 60 * 60)) && ($paidlog['time'] > $lastmonth + (21 * 24 * 60 * 60))) {
|
---|
343 | $charts['last_month'][3]+=$paidlog['amount'];
|
---|
344 | }
|
---|
345 | if (($paidlog['time'] < $thismonth) && ($paidlog['time'] > $lastmonth + (28 * 24 * 60 * 60))) {
|
---|
346 | $charts['last_month'][4]+=$paidlog['amount'];
|
---|
347 | }
|
---|
348 |
|
---|
349 | if (($paidlog['time'] < $thismonth) && ($paidlog['time'] > $lastmonth)) {
|
---|
350 | $top['last_month']['user']++;
|
---|
351 | if ($paidlog['paid_type']==1)
|
---|
352 | {
|
---|
353 | $top['last_month']['sms']+=$paidlog['amount'];
|
---|
354 | }
|
---|
355 | if ($paidlog['paid_type']==2)
|
---|
356 | {
|
---|
357 | $top['last_month']['card']+=$paidlog['amount'];
|
---|
358 | }
|
---|
359 | if ($paidlog['collaborator']!="")
|
---|
360 | {
|
---|
361 | $top['last_month']['collaborator']+=$paidlog['amount'];
|
---|
362 | }
|
---|
363 | }
|
---|
364 |
|
---|
365 |
|
---|
366 |
|
---|
367 | if (($paidlog['time'] < $thismonth + (7 * 24 * 60 * 60)) && ($paidlog['time'] > $thismonth)) {
|
---|
368 |
|
---|
369 | $charts['this_month'][0] += $paidlog['amount'];
|
---|
370 | }
|
---|
371 | if (($paidlog['time'] < $thismonth + (14 * 24 * 60 * 60)) && ($paidlog['time'] > $thismonth + (7 * 24 * 60 * 60))) {
|
---|
372 |
|
---|
373 | $charts['this_month'][1]+=$paidlog['amount'];
|
---|
374 | }
|
---|
375 | if (($paidlog['time'] < $thismonth + (21 * 24 * 60 * 60)) && ($paidlog['time'] > $thismonth + (14 * 24 * 60 * 60))) {
|
---|
376 |
|
---|
377 | $charts['this_month'][2]+=$paidlog['amount'];
|
---|
378 | }
|
---|
379 | if (($paidlog['time'] < $thismonth + (28 * 24 * 60 * 60)) && ($paidlog['time'] > $thismonth + (21 * 24 * 60 * 60))) {
|
---|
380 |
|
---|
381 | $charts['this_month'][3]+=$paidlog['amount'];
|
---|
382 | }
|
---|
383 | if (($paidlog['time'] < $thismonth + (31 * 24 * 60 * 60)) && ($paidlog['time'] > $thismonth + (28 * 24 * 60 * 60))) {
|
---|
384 |
|
---|
385 | $charts['this_month'][4]+=$paidlog['amount'];
|
---|
386 | }
|
---|
387 | if (($paidlog['time'] < $thismonth + (31 * 24 * 60 * 60)) && ($paidlog['time'] > $thismonth )) {
|
---|
388 | $top['this_month']['user']++;
|
---|
389 | if ($paidlog['paid_type']==1)
|
---|
390 | {
|
---|
391 | $top['this_month']['sms']+=$paidlog['amount'];
|
---|
392 | }
|
---|
393 | if ($paidlog['paid_type']==2)
|
---|
394 | {
|
---|
395 | $top['this_month']['card']+=$paidlog['amount'];
|
---|
396 | }
|
---|
397 | if ($paidlog['collaborator']!="")
|
---|
398 | {
|
---|
399 | $top['this_month']['collaborator']+=$paidlog['amount'];
|
---|
400 | }
|
---|
401 | }
|
---|
402 | }
|
---|
403 |
|
---|
404 | $percent=array();
|
---|
405 | foreach ($top['this_month'] as $index=>$value)
|
---|
406 | {
|
---|
407 | $percent[$index]['class']="down";
|
---|
408 | $percent[$index]['display']="giảm";
|
---|
409 | $percent[$index]['value']="n/a";
|
---|
410 | if (($top['this_month'][$index]>0)&&($top['last_month'][$index]>0))
|
---|
411 | {
|
---|
412 | $percent[$index]['value']=round((($top['this_month'][$index] / $top['last_month'][$index])*100),1);
|
---|
413 | if ($top['this_month'][$index] > $top['last_month'][$index])
|
---|
414 | {
|
---|
415 | $percent[$index]['class']="up";
|
---|
416 | $percent[$index]['display']="tăng";
|
---|
417 | }
|
---|
418 | }
|
---|
419 | }
|
---|
420 | $data['percent']=$percent;
|
---|
421 | $data['top']=$top;
|
---|
422 | $max = 0;
|
---|
423 | foreach ($charts['last_month'] as $index => $total) {
|
---|
424 | if ($total > $max) {
|
---|
425 | $max = $total;
|
---|
426 | }
|
---|
427 | $chart_last_month[] = array($index, $total);
|
---|
428 | }
|
---|
429 | foreach ($charts['this_month'] as $index => $total) {
|
---|
430 | if ($total > $max) {
|
---|
431 | $max = $total;
|
---|
432 | }
|
---|
433 | $chart_this_month[] = array($index, $total);
|
---|
434 | }
|
---|
435 |
|
---|
436 | $data['revenue'] = $revenue;
|
---|
437 | $data['max'] = $max;
|
---|
438 | $chard[] = array("color" => "#e67e22", "label" => "Tháng hiện tại", "data" => $chart_this_month);
|
---|
439 | $chard[] = array("color" => "#1abc9c", "label" => "Tháng trước", "data" => $chart_last_month);
|
---|
440 |
|
---|
441 | $data['chard'] = $chard;
|
---|
442 |
|
---|
443 | return $data;
|
---|
444 | }
|
---|
445 | public function getLastquarter() {
|
---|
446 | $current_month = date('m');
|
---|
447 | $current_year = date('Y');
|
---|
448 |
|
---|
449 | if ($current_month >= 1 && $current_month <= 3) {
|
---|
450 | $start_date = strtotime('1-October-' . ($current_year - 1)); // timestamp or 1-October Last Year 12:00:00 AM
|
---|
451 | $end_date = strtotime('1-Janauary-' . $current_year); // // timestamp or 1-January 12:00:00 AM means end of 31 December Last year
|
---|
452 | } else if ($current_month >= 4 && $current_month <= 6) {
|
---|
453 | $start_date = strtotime('1-January-' . $current_year); // timestamp or 1-Janauray 12:00:00 AM
|
---|
454 | $end_date = strtotime('1-April-' . $current_year); // timestamp or 1-April 12:00:00 AM means end of 31 March
|
---|
455 | } else if ($current_month >= 7 && $current_month <= 9) {
|
---|
456 | $start_date = strtotime('1-April-' . $current_year); // timestamp or 1-April 12:00:00 AM
|
---|
457 | $end_date = strtotime('1-July-' . $current_year); // timestamp or 1-July 12:00:00 AM means end of 30 June
|
---|
458 | } else if ($current_month >= 10 && $current_month <= 12) {
|
---|
459 | $start_date = strtotime('1-July-' . $current_year); // timestamp or 1-July 12:00:00 AM
|
---|
460 | $end_date = strtotime('1-October-' . $current_year); // timestamp or 1-October 12:00:00 AM means end of 30 September
|
---|
461 | }
|
---|
462 | return array("start" => $start_date, "end" => $end_date);
|
---|
463 | }
|
---|
464 |
|
---|
465 | function check_login($login_name, $password)
|
---|
466 | {
|
---|
467 | $hash_password = md5($password);
|
---|
468 | $query = "SELECT * FROM tblcollaborator WHERE login_name = ? AND passwd = ?";
|
---|
469 | $result = $this->db->query($query, array($login_name, $hash_password));
|
---|
470 | if($result->num_rows() == 1){
|
---|
471 | $collaborator = $result->row(0);
|
---|
472 | return $collaborator;
|
---|
473 |
|
---|
474 | }else
|
---|
475 | {
|
---|
476 | return null;
|
---|
477 | }
|
---|
478 | }
|
---|
479 |
|
---|
480 | public function createRandomPassword()
|
---|
481 | {
|
---|
482 | $alphabet = "0123456789";
|
---|
483 | $pass = array ();
|
---|
484 | $alphaLength = strlen ( $alphabet ) - 1;
|
---|
485 | for($i = 0; $i < 6; $i ++) {
|
---|
486 | $n = rand ( 0, $alphaLength );
|
---|
487 | $pass [] = $alphabet [$n];
|
---|
488 | }
|
---|
489 | return implode ( $pass );
|
---|
490 | }
|
---|
491 | }
|
---|