[702] | 1 | <?php |
---|
| 2 | |
---|
| 3 | if (!defined('BASEPATH')) |
---|
| 4 | exit('No direct script access allowed'); |
---|
| 5 | |
---|
| 6 | class 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 |
---|
[745] | 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"; |
---|
[702] | 26 | $query = $this->db->query($sql); |
---|
| 27 | $dtts = $query->result_array(); |
---|
[745] | 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(); |
---|
[702] | 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 |
---|
[745] | 40 | $sql = "SELECT *,count(us_id) as total FROM tbluser WHERE tbluser.created_time >'" . $input['year'] . "-" . $input['month'] . "-01' GROUP BY tbluser.province"; |
---|
[702] | 41 | $query = $this->db->query($sql); |
---|
| 42 | $tbts = $query->result_array(); |
---|
[745] | 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); |
---|
[747] | 47 | $tbng = $query->result_array(); |
---|
[745] | 48 | |
---|
[702] | 49 | |
---|
[755] | 50 | $dem=1; |
---|
[702] | 51 | foreach ($provinces as $index2 => $province) { |
---|
[755] | 52 | $provinces[$index2] = array("stt" => ($dem), "province" => $province, "dtn" => 0, "dtt" => 0, "dtng" => 0, "tbn" => 0, "tbt" => 0, "tbng" => 0); |
---|
[702] | 53 | foreach ($dtns as $data) { |
---|
[755] | 54 | if ($index2 == $data['province']) { |
---|
[702] | 55 | $provinces[$index2]['dtn'] = $data['total']; |
---|
| 56 | } |
---|
[745] | 57 | } |
---|
| 58 | foreach ($dtng as $data) { |
---|
[755] | 59 | if ($index2 == $data['province']) { |
---|
[745] | 60 | $provinces[$index2]['dtng'] = $data['total']; |
---|
| 61 | } |
---|
[702] | 62 | } |
---|
| 63 | foreach ($dtts as $data) { |
---|
[755] | 64 | if ($index2 == $data['province']) { |
---|
[702] | 65 | $provinces[$index2]['dtt'] = $data['total']; |
---|
[745] | 66 | |
---|
[702] | 67 | } |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | |
---|
| 71 | |
---|
| 72 | foreach ($tbns as $data) { |
---|
[755] | 73 | if ($index2 == $data['province']) { |
---|
[702] | 74 | $provinces[$index2]['tbn'] = $data['total']; |
---|
| 75 | } |
---|
| 76 | } |
---|
[745] | 77 | foreach ($tbng as $data) { |
---|
[755] | 78 | if ($index2 == $data['province']) { |
---|
[745] | 79 | $provinces[$index2]['tbng'] = $data['total']; |
---|
| 80 | } |
---|
| 81 | } |
---|
[702] | 82 | foreach ($tbts as $data) { |
---|
[755] | 83 | if ($index2 == $data['province']) { |
---|
[702] | 84 | $provinces[$index2]['tbt'] = $data['total']; |
---|
| 85 | } |
---|
| 86 | } |
---|
[755] | 87 | $dem++; |
---|
[702] | 88 | } |
---|
[728] | 89 | |
---|
[702] | 90 | return $provinces; |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | function getPackages($input) { |
---|
| 94 | |
---|
| 95 | $provinces = lang('_PROVINCES_'); |
---|
| 96 | // tinh thue bao theo thang |
---|
[728] | 97 | $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 "; |
---|
[702] | 98 | $query = $this->db->query($sql); |
---|
| 99 | $users = $query->result_array(); |
---|
| 100 | |
---|
| 101 | |
---|
| 102 | $sql = "SELECT * FROM tblservicepackage WHERE p_period>0"; |
---|
| 103 | $query = $this->db->query($sql); |
---|
| 104 | $packages = $query->result_array(); |
---|
| 105 | foreach ($packages as $index => $package) { |
---|
| 106 | $packages[$index]['users'] = array(); |
---|
| 107 | foreach ($users as $user) { |
---|
| 108 | if ($user['p_id'] == $package['p_id']) { |
---|
| 109 | $packages[$index]['users'][] = $user; |
---|
| 110 | } |
---|
| 111 | } |
---|
| 112 | } |
---|
| 113 | |
---|
| 114 | foreach ($provinces as $index => $province) { |
---|
| 115 | $provinces[$index] = array("province" => $province); |
---|
| 116 | } |
---|
[755] | 117 | $dem=1; |
---|
[702] | 118 | foreach ($provinces as $index => $province) { |
---|
[755] | 119 | $provinces[$index]['stt'] = $dem; |
---|
[702] | 120 | $provinces[$index]['total'] = 0; |
---|
| 121 | $totaluser = 0; |
---|
| 122 | foreach ($packages as $index2 => $package) { |
---|
| 123 | $provinces[$index]['packages'][$package['p_name']]['users'] = array(); |
---|
| 124 | $provinces[$index]['packages'][$package['p_name']]['total'] = 0; |
---|
| 125 | $total = 0; |
---|
| 126 | foreach ($package['users'] as $user) { |
---|
[755] | 127 | if ($index == $user['province']) { |
---|
[702] | 128 | $total = $total + 1; |
---|
| 129 | $totaluser = $totaluser + 1; |
---|
| 130 | $provinces[$index]['total'] = $totaluser; |
---|
| 131 | $provinces[$index]['packages'][$package['p_name']]['total'] = $total; |
---|
| 132 | |
---|
| 133 | $provinces[$index]['packages'][$package['p_name']]['users'][] = $user; |
---|
| 134 | } |
---|
| 135 | } |
---|
| 136 | } |
---|
[755] | 137 | $dem++; |
---|
[702] | 138 | } |
---|
| 139 | foreach ($provinces as $index => $province) { |
---|
| 140 | foreach ($packages as $index2 => $package) { |
---|
| 141 | $provinces[$index]['packages'][$package['p_name']]['percent'] = 0; |
---|
| 142 | if ($provinces[$index]['packages'][$package['p_name']]['total'] > 0 && $province['total'] > 0) { |
---|
| 143 | $provinces[$index]['packages'][$package['p_name']]['percent'] = round($provinces[$index]['packages'][$package['p_name']]['total'] / $province['total'], 2) * 100; |
---|
| 144 | } |
---|
| 145 | } |
---|
| 146 | } |
---|
[728] | 147 | |
---|
| 148 | $data['packages'] = $packages; |
---|
| 149 | $data['provinces'] = $provinces; |
---|
[702] | 150 | return $data; |
---|
| 151 | } |
---|
[749] | 152 | public function exportProvince($input) |
---|
| 153 | { |
---|
| 154 | //$input['month']=1; |
---|
| 155 | //$input['year']=2014; |
---|
| 156 | $data=$this->getProvinces($input); |
---|
| 157 | return $data; |
---|
| 158 | } |
---|
| 159 | public function exportPackage($input) |
---|
| 160 | { |
---|
| 161 | // $input['month']=1; |
---|
[755] | 162 | //svn $input['year']=2014; |
---|
[749] | 163 | $data=$this->getPackages($input); |
---|
| 164 | return $data; |
---|
| 165 | } |
---|
[702] | 166 | |
---|
| 167 | } |
---|