source: pro-violet-viettel/sourcecode/application/modules/admin/models/reportmodel.php @ 757

Last change on this file since 757 was 757, checked in by quyenla, 10 years ago

report update

File size: 8.1 KB
Line 
1<?php
2
3if (!defined('BASEPATH'))
4    exit('No direct script access allowed');
5
6class Reportmodel extends MY_Model {
7
8    protected $table_name = 'tblpaidlog';
9    protected $id_name = 'id';
10
11    function __construct() {
12        parent::__construct();
13        $this->load->helper('language');
14        $this->lang->load('messages', 'message');
15    }
16
17    function getProvinces($input) {
18        $ext="";
19        if (isset($input['to_month']))
20        {
21            $ext="AND tblpaidlog.paid_time <'" . $input['to_year'] . "-" . $input['to_month'] . "-01 23:59:59'";
22        }
23        $provinces = lang('_PROVINCES_');
24        // Tinh doanh thu theo tinh theo nam
25        $sql = "SELECT *,SUM(amount) as total FROM tblpaidlog LEFT JOIN tbluser ON tbluser.us_id=tblpaidlog.us_id WHERE tblpaidlog.paid_time >'" . $input['year'] . "-01-01' AND tblpaidlog.paid_time <'" . ($input['year'] + 1) . "-01-01' GROUP BY tbluser.province";
26        $query = $this->db->query($sql);
27        $dtns = $query->result_array();
28        // tinh doanh thu theo thang
29        $sql = "SELECT *,SUM(amount) as total FROM tblpaidlog LEFT JOIN tbluser ON tbluser.us_id=tblpaidlog.us_id WHERE tblpaidlog.paid_time >'" . $input['year'] . "-" . $input['month'] . "-01' $ext  GROUP BY tbluser.province";
30        $query = $this->db->query($sql);
31        $dtts = $query->result_array();
32        // tinh doanh thu trong ngay hien tai
33        $sql = "SELECT *,SUM(amount) as total FROM tblpaidlog LEFT JOIN tbluser ON tbluser.us_id=tblpaidlog.us_id WHERE tblpaidlog.paid_time > '" . date('Y') . "-" . date('m') . "-".date('d')." 00:00:00' AND  tblpaidlog.paid_time <'" . date('Y') . "-" . date('m') . "-".date('d')." 23:59:59'  GROUP BY tbluser.province";
34        if (isset($input['to_month']))
35        {
36        $sql = "SELECT *,SUM(amount) as total FROM tblpaidlog LEFT JOIN tbluser ON tbluser.us_id=tblpaidlog.us_id WHERE tblpaidlog.paid_time > '" . $input['to_year'] . "-" . $input['to_month'] . "-".$input['to_date']." 00:00:00' AND  tblpaidlog.paid_time <'" . $input['to_year'] . "-" . $input['to_month'] . "-".$input['to_date']." 23:59:59'  GROUP BY tbluser.province";
37        }
38        $query = $this->db->query($sql);
39        $dtng = $query->result_array();
40
41        // Tinh thue bao theo tinh theo nam
42        $sql = "SELECT *,count(us_id) as total FROM tbluser WHERE tbluser.created_time >'" . $input['year'] . "-01-01' AND tbluser.created_time <'" . ($input['year'] + 1) . "-01-01' GROUP BY tbluser.province";
43        $query = $this->db->query($sql);
44        $tbns = $query->result_array();
45
46        // tinh thue bao theo thang
47        $sql = "SELECT *,count(us_id) as total FROM tbluser WHERE tbluser.created_time >'" . $input['year'] . "-" . $input['month'] . "-01'  $ext GROUP BY tbluser.province";
48        $query = $this->db->query($sql);
49        $tbts = $query->result_array();
50       
51         // tinh thue bao theo ngay
52        $sql = "SELECT *,count(us_id) as total FROM tbluser WHERE tbluser.created_time >'" . date('Y') . "-" . date('m') . "-".date('d')." 00:00:00' AND tbluser.created_time < '" . date('Y') . "-" . date('m') . "-".date('d')." 23:59:59'  GROUP BY tbluser.province";
53        if (isset($input['to_month']))
54        {
55            $sql = "SELECT *,count(us_id) as total FROM tbluser WHERE tbluser.created_time >'" . $input['to_year'] . "-" . $input['to_month'] . "-".$input['to_date']." 00:00:00' AND tbluser.created_time < '" . $input['to_year'] . "-" . $input['to_month'] . "-".$input['to_date']." 23:59:59'  GROUP BY tbluser.province";
56        }
57        $query = $this->db->query($sql);
58        $tbng = $query->result_array();
59       
60
61        $dem=1;
62        foreach ($provinces as $index2 => $province) {
63            $provinces[$index2] = array("stt" => ($dem), "province" => $province, "dtn" => 0, "dtt" => 0, "dtng" => 0, "tbn" => 0, "tbt" => 0, "tbng" => 0);
64            foreach ($dtns as $data) {
65                if ($index2 == $data['province']) {
66                    $provinces[$index2]['dtn'] = $data['total'];
67                }
68            }
69            foreach ($dtng as $data) {
70                if ($index2 == $data['province']) {
71                    $provinces[$index2]['dtng'] = $data['total'];
72                }
73            }
74            foreach ($dtts as $data) {
75                if ($index2 == $data['province']) {
76                    $provinces[$index2]['dtt'] = $data['total'];
77                   
78                }
79            }
80
81
82
83            foreach ($tbns as $data) {
84                if ($index2 == $data['province']) {
85                    $provinces[$index2]['tbn'] = $data['total'];
86                }
87            }
88            foreach ($tbng as $data) {
89                if ($index2 == $data['province']) {
90                    $provinces[$index2]['tbng'] = $data['total'];
91                }
92            }
93            foreach ($tbts as $data) {
94                if ($index2 == $data['province']) {
95                    $provinces[$index2]['tbt'] = $data['total'];
96                }
97            }
98            $dem++;
99        }
100       
101        return $provinces;
102    }
103
104    function getPackages($input) {
105
106        $provinces = lang('_PROVINCES_');
107        // tinh thue bao theo thang
108        $sql = "SELECT * FROM tbluser LEFT JOIN tblservicepackage ON tbluser.p_id=tblservicepackage.p_id  WHERE tbluser.created_time >'" . $input['year'] . "-" . $input['month'] . "-01' AND tbluser.created_time <'" . $input['year'] . "-" . $input['month'] . "-31' AND tblservicepackage.p_period > 0 ";
109        $query = $this->db->query($sql);
110        $users = $query->result_array();
111
112
113        $sql = "SELECT * FROM tblservicepackage WHERE p_period>0";
114        $query = $this->db->query($sql);
115        $packages = $query->result_array();
116        foreach ($packages as $index => $package) {
117            $packages[$index]['users'] = array();
118            foreach ($users as $user) {
119                if ($user['p_id'] == $package['p_id']) {
120                    $packages[$index]['users'][] = $user;
121                }
122            }
123        }
124
125        foreach ($provinces as $index => $province) {
126            $provinces[$index] = array("province" => $province);
127        }
128        $dem=1;
129        foreach ($provinces as $index => $province) {
130            $provinces[$index]['stt'] = $dem;
131            $provinces[$index]['total'] = 0;
132            $totaluser = 0;
133            foreach ($packages as $index2 => $package) {
134                $provinces[$index]['packages'][$package['p_name']]['users'] = array();
135                $provinces[$index]['packages'][$package['p_name']]['total'] = 0;
136                $total = 0;
137                foreach ($package['users'] as $user) {
138                    if ($index == $user['province']) {
139                        $total = $total + 1;
140                        $totaluser = $totaluser + 1;
141                        $provinces[$index]['total'] = $totaluser;
142                        $provinces[$index]['packages'][$package['p_name']]['total'] = $total;
143
144                        $provinces[$index]['packages'][$package['p_name']]['users'][] = $user;
145                    }
146                }
147            }
148            $dem++;
149        }
150        foreach ($provinces as $index => $province) {
151            foreach ($packages as $index2 => $package) {
152                $provinces[$index]['packages'][$package['p_name']]['percent'] = 0;
153                if ($provinces[$index]['packages'][$package['p_name']]['total'] > 0 && $province['total'] > 0) {
154                    $provinces[$index]['packages'][$package['p_name']]['percent'] = round($provinces[$index]['packages'][$package['p_name']]['total'] / $province['total'], 2) * 100;
155                }
156            }
157        }
158
159        $data['packages'] = $packages;
160        $data['provinces'] = $provinces;
161        return $data;
162    }
163    public function exportProvince($input)
164    {
165        //$input['month']=1;
166        //$input['year']=2014;
167        //$input['to_month']=1;
168        //$input['to_year']=2015;
169        //$input['to_date']=15;
170        $data=$this->getProvinces($input);
171        return $data;
172    }
173    public function exportPackage($input)
174    {
175        //$input['month']=1;
176        //svn  $input['year']=2014;
177        $data=$this->getPackages($input);
178        return $data;
179    }
180
181}
Note: See TracBrowser for help on using the repository browser.