source: pro-violet-viettel/sourcecode/application/modules/admin/models/collabolator_model.php

Last change on this file was 906, checked in by namnd, 10 years ago
File size: 25.0 KB
RevLine 
[373]1<?php
2if (!defined('BASEPATH'))
3    exit('No direct script access allowed');
[328]4
[373]5class Collabolator_model extends MY_Model {
[328]6
[373]7    protected $table_name = 'tblcollaborator';
8    protected $id_name = 'id';
[360]9
[373]10    function __construct() {
11        parent::__construct();
12    }
13
[401]14    function getCollaborators($data) {
[373]15        $sql = "SELECT * FROM " . $this->table_name;
16        if ($data['keyword']) {
17            if ($data['search_field'] == "cellphone") {
[690]18                                if(strlen($data['daterange_start'])>0){
[838]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']."')";
[690]20                                }else{
[838]21                                        $sql.=" WHERE (cellphone LIKE '%" . $data['keyword'] . "%' OR full_name LIKE '%".$data['keyword']."%' OR district LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%')";
[690]22                                }
[373]23            } else {
[690]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                                }
[360]29            }
[690]30        }else{
31                        if(strlen($data['daterange_start'])>0){
32                                $sql.=" WHERE created_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."'";
33                        }
34                }
[373]35
36        $order = "";
37        if ($data['sorting_order'] != "sorting") {
[420]38           
[373]39                $sort = "DESC";
40                if ($data['sorting_order'] == "sorting_asc")
41                    $sort = "ASC";
42                $order = "ORDER BY " . $data['sorting_field'] . " " . $sort;
[420]43           
[373]44        }
45       
46        return $this->db->query($sql . " " . $order . " LIMIT " . $data['start'] . ", " . $data['perpage'] . " ")->result_array();
47    }
[737]48
[464]49    function getAllCollaboratorUser($from,$id=false)
[461]50    {
[906]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        }
[464]61        $where="";
62        if ($id)
63        {
[906]64            //$where = " AND tbluser.collaborator = $id ";
65                        $where = " AND tblcollaborator.id = $id ";
[464]66        }
[737]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."";
[906]69               
[461]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        }
[741]75       
[461]76        return $result;
77    }
[464]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") {
[690]92                $where.=" WHERE (tblcollaborator.cellphone LIKE '%" . $data['keyword'] . "%' OR district LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%')";
[464]93            } else {
[690]94                $where.=" WHERE (full_name LIKE '%" . $data['keyword'] . "%' OR login_name LIKE '%" . $data['keyword'] . "%' OR district LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%') ";
[464]95            }
96        }
97       // $from = date("Y-m-d 00:00:00",$from);
[737]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." ";
[464]101       
102        $result = $this->db->query($sql)->result_array();
103       
104
105        return count($result);
106    }
[461]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") {
[690]121                $where.=" WHERE (tblcollaborator.cellphone LIKE '%" . $data['keyword'] . "%' OR district LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%')";
122                               
[461]123            } else {
[690]124                $where.=" WHERE (full_name LIKE '%" . $data['keyword'] . "%' OR login_name LIKE '%" . $data['keyword'] . "%' OR district LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%') ";
[461]125            }
126        }
[690]127               
[461]128       // $from = date("Y-m-d 00:00:00",$from);
[737]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'] . " ";
[464]130       
[737]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'] . " ";
[906]132               
[461]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    }
[464]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") {
[690]156                $where.=" WHERE (tbluser.cellphone LIKE '%" . $data['keyword'] . "%' OR district LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%')";
[464]157            }
158        }
159       // $from = date("Y-m-d 00:00:00",$from);
[737]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."";
[742]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."";
[906]165                }
166                //write_file('./log/sql.log', date('d-m-Y H:i:s').": ".$sql."\n", FOPEN_WRITE_CREATE);         
[737]167                $result = $this->db->query($sql)->result_array();
[906]168               
[464]169        foreach ($result as $index=>$paidlog)
170        {
171            $result[$index]['time']=  strtotime($paidlog['user_created_time']);
172        }
[906]173               
[464]174        return count($result);
175    }
[906]176       
177        function getCountCollaboratorUsers($data)
[464]178    {
179        $order = "";
[906]180        if ($data['sorting_order'] != "sorting") {       
[464]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="";
[906]188               
[464]189        if ($data['keyword']) {
190            if ($data['search_field'] == "cellphone") {
[742]191                $where.=" WHERE (tbluser.cellphone LIKE '%" . $data['keyword'] . "%' OR tblcollaborator.district LIKE '%".$data['keyword']."%' OR tblcollaborator.province LIKE '%".$data['keyword']."%')";
[478]192            }
[464]193        }
[906]194               
[464]195       // $from = date("Y-m-d 00:00:00",$from);
[737]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'] . " ";
[906]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                        }
[742]205                }else{
[906]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                        }
[742]211                }
[737]212                $result = $this->db->query($sql)->result_array();
[464]213        foreach ($result as $index=>$paidlog)
214        {
215            $result[$index]['time']=  strtotime($paidlog['user_created_time']);
216        }
217
218        return $result;
219    }
220   
[373]221    function isExist($data) {
[401]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) {
[373]230            return true;
231        } else {
232            return false;
[360]233        }
[373]234    }
235
236    function countCollaborator($data) {
237        $sql = "SELECT COUNT(id) as total FROM " . $this->table_name;
[374]238        if ($data['keyword']) {
239            if ($data['search_field'] == "cellphone") {
[690]240                                if(strlen($data['daterange_start'])>0){
[838]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']."')";
[690]242                                }else{
[838]243                                        $sql.=" WHERE (cellphone LIKE '%" . $data['keyword'] . "%' OR full_name LIKE '%".$data['keyword']."%' OR district LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%')";
[690]244                                }
[374]245            } else {
[690]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                                }
[374]251            }
[690]252        }else{
253                        if(strlen($data['daterange_start'])>0){
254                                $sql.=" WHERE created_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."'";
255                        }
256                }
[401]257        $result = $this->db->query($sql)->row_array();
258        return $result['total'];
[373]259    }
[401]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    }
[594]266    function getStatistics()
267    {
[741]268     
269       $day = date('w');
[594]270        $data = array();
[741]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");
[373]273
[741]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");
[594]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
[741]298        $lastmonth = strtotime(date("Y-m-d", mktime(0, 0, 0, date("m")-1, 1, date("Y"))));
299        $thismonth = strtotime(date('Y-m-01'));
[594]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;
[741]311       
[594]312        foreach ($paidlogs as $paidlog) {
313
314           
315            if (($paidlog['time'] < $last_week['end']) && ($paidlog['time'] > $last_week['start'])) {
[741]316               
[594]317                $revenue['last_week']+=$paidlog['amount'];
318            }
319            if (($paidlog['time'] < $last_month['end']) && ($paidlog['time'] > $last_month['start'])) {
[741]320           
[594]321                $revenue['last_month']+=$paidlog['amount'];
322            }
323            if (($paidlog['time'] < $last_quarter['end']) && ($paidlog['time'] > $last_quarter['start'])) {
[741]324             
[594]325                $revenue['last_quarter']+=$paidlog['amount'];
326            }
327            if (($paidlog['time'] < $last_year['end']) && ($paidlog['time'] > $last_year['start'])) {
[741]328             
[594]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)) {
[741]368             
369                $charts['this_month'][0] += $paidlog['amount'];
[594]370            }
371            if (($paidlog['time'] < $thismonth + (14 * 24 * 60 * 60)) && ($paidlog['time'] > $thismonth + (7 * 24 * 60 * 60))) {
[741]372               
[594]373                $charts['this_month'][1]+=$paidlog['amount'];
374            }
375            if (($paidlog['time'] < $thismonth + (21 * 24 * 60 * 60)) && ($paidlog['time'] > $thismonth + (14 * 24 * 60 * 60))) {
[741]376               
[594]377                $charts['this_month'][2]+=$paidlog['amount'];
378            }
379            if (($paidlog['time'] < $thismonth + (28 * 24 * 60 * 60)) && ($paidlog['time'] > $thismonth + (21 * 24 * 60 * 60))) {
[741]380               
[594]381                $charts['this_month'][3]+=$paidlog['amount'];
382            }
383            if (($paidlog['time'] < $thismonth + (31 * 24 * 60 * 60)) && ($paidlog['time'] > $thismonth + (28 * 24 * 60 * 60))) {
[741]384               
[594]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        }
[741]403     
[594]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;
[741]437        $data['max'] = $max;
[594]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);
[741]440         
[594]441        $data['chard'] = $chard;
[741]442       
[594]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
[838]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       
[906]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        }
[373]491}
Note: See TracBrowser for help on using the repository browser.