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

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

user

File size: 5.7 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
19        $provinces = lang('_PROVINCES_');
20        // Tinh doanh thu theo tinh theo nam
21        $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";
22        $query = $this->db->query($sql);
23        $dtns = $query->result_array();
24        // tinh doanh thu theo thang
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'] . "-" . $input['month'] . "-01' AND tblpaidlog.paid_time <'" . $input['year'] . "-" . $input['month'] . "-31' GROUP BY tbluser.province";
26        $query = $this->db->query($sql);
27        $dtts = $query->result_array();
28
29
30        // Tinh thue bao theo tinh theo nam
31        $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";
32        $query = $this->db->query($sql);
33        $tbns = $query->result_array();
34
35        // tinh thue bao theo thang
36        $sql = "SELECT *,count(us_id) as total FROM tbluser WHERE tbluser.created_time >'" . $input['year'] . "-" . $input['month'] . "-01' AND tbluser.created_time <'" . $input['year'] . "-" . $input['month'] . "-31' GROUP BY tbluser.province";
37        $query = $this->db->query($sql);
38        $tbts = $query->result_array();
39
40
41        foreach ($provinces as $index2 => $province) {
42            $provinces[$index2] = array("stt" => ($index2 + 1), "province" => $province, "dtn" => 0, "dtt" => 0, "dtng" => 0, "tbn" => 0, "tbt" => 0, "tbng" => 0);
43            foreach ($dtns as $data) {
44                if ($province == $data['province']) {
45                    $provinces[$index2]['dtn'] = $data['total'];
46                }
47            }
48            foreach ($dtts as $data) {
49                if ($province == $data['province']) {
50                    $provinces[$index2]['dtt'] = $data['total'];
51                    $provinces[$index2]['dtng'] = round($data['total'] / $input['month_days'], 2);
52                }
53            }
54
55
56
57            foreach ($tbns as $data) {
58                if ($province == $data['province']) {
59                    $provinces[$index2]['tbn'] = $data['total'];
60                }
61            }
62            foreach ($tbts as $data) {
63                if ($province == $data['province']) {
64                    $provinces[$index2]['tbt'] = $data['total'];
65                    $provinces[$index2]['tbng'] = round($data['total'] / $input['month_days'], 2);
66                }
67            }
68        }
69       
70        return $provinces;
71    }
72
73    function getPackages($input) {
74
75        $provinces = lang('_PROVINCES_');
76        // tinh thue bao theo thang
77        $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 ";
78        $query = $this->db->query($sql);
79        $users = $query->result_array();
80
81
82        $sql = "SELECT * FROM tblservicepackage WHERE p_period>0";
83        $query = $this->db->query($sql);
84        $packages = $query->result_array();
85        foreach ($packages as $index => $package) {
86            $packages[$index]['users'] = array();
87            foreach ($users as $user) {
88                if ($user['p_id'] == $package['p_id']) {
89                    $packages[$index]['users'][] = $user;
90                }
91            }
92        }
93
94        foreach ($provinces as $index => $province) {
95            $provinces[$index] = array("province" => $province);
96        }
97
98        foreach ($provinces as $index => $province) {
99            $provinces[$index]['stt'] = $index + 1;
100            $provinces[$index]['total'] = 0;
101            $totaluser = 0;
102            foreach ($packages as $index2 => $package) {
103                $provinces[$index]['packages'][$package['p_name']]['users'] = array();
104                $provinces[$index]['packages'][$package['p_name']]['total'] = 0;
105                $total = 0;
106                foreach ($package['users'] as $user) {
107                    if ($province['province'] == $user['province']) {
108                        $total = $total + 1;
109                        $totaluser = $totaluser + 1;
110                        $provinces[$index]['total'] = $totaluser;
111                        $provinces[$index]['packages'][$package['p_name']]['total'] = $total;
112
113                        $provinces[$index]['packages'][$package['p_name']]['users'][] = $user;
114                    }
115                }
116            }
117        }
118        foreach ($provinces as $index => $province) {
119            foreach ($packages as $index2 => $package) {
120                $provinces[$index]['packages'][$package['p_name']]['percent'] = 0;
121                if ($provinces[$index]['packages'][$package['p_name']]['total'] > 0 && $province['total'] > 0) {
122                    $provinces[$index]['packages'][$package['p_name']]['percent'] = round($provinces[$index]['packages'][$package['p_name']]['total'] / $province['total'], 2) * 100;
123                }
124            }
125        }
126
127        $data['packages'] = $packages;
128        $data['provinces'] = $provinces;
129        return $data;
130    }
131
132}
Note: See TracBrowser for help on using the repository browser.