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

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

api

File size: 7.0 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'  GROUP BY tbluser.province";
26        $query = $this->db->query($sql);
27        $dtts = $query->result_array();
28        // tinh doanh thu trong ngay hien tai
29        $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";
30       
31        $query = $this->db->query($sql);
32        $dtng = $query->result_array();
33
34        // Tinh thue bao theo tinh theo nam
35        $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";
36        $query = $this->db->query($sql);
37        $tbns = $query->result_array();
38
39        // tinh thue bao theo thang
40        $sql = "SELECT *,count(us_id) as total FROM tbluser WHERE tbluser.created_time >'" . $input['year'] . "-" . $input['month'] . "-01'  GROUP BY tbluser.province";
41        $query = $this->db->query($sql);
42        $tbts = $query->result_array();
43       
44         // tinh thue bao theo ngay
45        $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";
46        $query = $this->db->query($sql);
47        $tbng = $query->result_array();
48       
49
50
51        foreach ($provinces as $index2 => $province) {
52            $provinces[$index2] = array("stt" => ($index2 + 1), "province" => $province, "dtn" => 0, "dtt" => 0, "dtng" => 0, "tbn" => 0, "tbt" => 0, "tbng" => 0);
53            foreach ($dtns as $data) {
54                if ($province == $data['province']) {
55                    $provinces[$index2]['dtn'] = $data['total'];
56                }
57            }
58            foreach ($dtng as $data) {
59                if ($province == $data['province']) {
60                    $provinces[$index2]['dtng'] = $data['total'];
61                }
62            }
63            foreach ($dtts as $data) {
64                if ($province == $data['province']) {
65                    $provinces[$index2]['dtt'] = $data['total'];
66                   
67                }
68            }
69
70
71
72            foreach ($tbns as $data) {
73                if ($province == $data['province']) {
74                    $provinces[$index2]['tbn'] = $data['total'];
75                }
76            }
77            foreach ($tbng as $data) {
78                if ($province == $data['province']) {
79                    $provinces[$index2]['tbng'] = $data['total'];
80                }
81            }
82            foreach ($tbts as $data) {
83                if ($province == $data['province']) {
84                    $provinces[$index2]['tbt'] = $data['total'];
85                }
86            }
87        }
88       
89        return $provinces;
90    }
91
92    function getPackages($input) {
93
94        $provinces = lang('_PROVINCES_');
95        // tinh thue bao theo thang
96        $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 ";
97        $query = $this->db->query($sql);
98        $users = $query->result_array();
99
100
101        $sql = "SELECT * FROM tblservicepackage WHERE p_period>0";
102        $query = $this->db->query($sql);
103        $packages = $query->result_array();
104        foreach ($packages as $index => $package) {
105            $packages[$index]['users'] = array();
106            foreach ($users as $user) {
107                if ($user['p_id'] == $package['p_id']) {
108                    $packages[$index]['users'][] = $user;
109                }
110            }
111        }
112
113        foreach ($provinces as $index => $province) {
114            $provinces[$index] = array("province" => $province);
115        }
116
117        foreach ($provinces as $index => $province) {
118            $provinces[$index]['stt'] = $index + 1;
119            $provinces[$index]['total'] = 0;
120            $totaluser = 0;
121            foreach ($packages as $index2 => $package) {
122                $provinces[$index]['packages'][$package['p_name']]['users'] = array();
123                $provinces[$index]['packages'][$package['p_name']]['total'] = 0;
124                $total = 0;
125                foreach ($package['users'] as $user) {
126                    if ($province['province'] == $user['province']) {
127                        $total = $total + 1;
128                        $totaluser = $totaluser + 1;
129                        $provinces[$index]['total'] = $totaluser;
130                        $provinces[$index]['packages'][$package['p_name']]['total'] = $total;
131
132                        $provinces[$index]['packages'][$package['p_name']]['users'][] = $user;
133                    }
134                }
135            }
136        }
137        foreach ($provinces as $index => $province) {
138            foreach ($packages as $index2 => $package) {
139                $provinces[$index]['packages'][$package['p_name']]['percent'] = 0;
140                if ($provinces[$index]['packages'][$package['p_name']]['total'] > 0 && $province['total'] > 0) {
141                    $provinces[$index]['packages'][$package['p_name']]['percent'] = round($provinces[$index]['packages'][$package['p_name']]['total'] / $province['total'], 2) * 100;
142                }
143            }
144        }
145
146        $data['packages'] = $packages;
147        $data['provinces'] = $provinces;
148        return $data;
149    }
150    public function exportProvince($input)
151    {
152        //$input['month']=1;
153        //$input['year']=2014;
154        $data=$this->getProvinces($input);
155        return $data;
156    }
157    public function exportPackage($input)
158    {
159       // $input['month']=1;
160       // $input['year']=2014;
161        $data=$this->getPackages($input);
162        return $data;
163    }
164
165}
Note: See TracBrowser for help on using the repository browser.