- Timestamp:
- Mar 24, 2015 2:15:02 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pro-violet-viettel/sourcecode/application/modules/admin/models/reportmodel.php
r765 r818 45 45 46 46 // Tinh thue bao theo tinh theo nam 47 $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"; 48 $query = $this->db->query ( $sql ); 47 $sql = "SELECT *,count(us_id) as total FROM tbluser WHERE tbluser.created_time >= '" . $input ['year'] . "-01-01 00:00:00' AND tbluser.created_time <= '" . ($input ['year'] + 1) . "-01-01 23:59:59' GROUP BY tbluser.province"; 48 $query = $this->db->query ( $sql ); 49 write_file('./log/test.log', date('d-m-Y H:i:s').": ".$sql."\n", FOPEN_WRITE_CREATE); 49 50 $tbns = $query->result_array (); 50 51 51 52 // tinh thue bao theo thang 52 $sql = "SELECT *,count(us_id) as total FROM tbluser WHERE $from AND $to GROUP BY tbluser.province"; 53 //$sql = "SELECT *,count(us_id) as total FROM tbluser WHERE $from AND $to GROUP BY tbluser.province"; 54 $sql = "SELECT *,count(us_id) as total FROM tbluser WHERE created_time >= '" . $input ['year'] . "-" . $input ['month'] . "-" . '01 00:00:00' . "' AND created_time <= '" . $input ['to_year'] . "-" . $input ['to_month'] . "-" . $input ['to_date'] . " 23:59:59' GROUP BY tbluser.province"; 53 55 $query = $this->db->query ( $sql ); 54 56 $tbts = $query->result_array (); … … 56 58 // tinh thue bao theo ngay 57 59 $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"; 58 59 60 $query = $this->db->query ( $sql ); 60 61 $tbng = $query->result_array (); 61 62 62 $dem = 1; 63 64 $totalTbng = 0; 65 $totalTbth = 0; 66 $totalTbn = 0; 67 $totalDtng = 0; 68 $totalDtth = 0; 69 $totalDtn = 0; 63 70 64 71 foreach ( $provinces as $index2 => $province ) { … … 104 111 } 105 112 } 113 114 $totalTbng = $totalTbng + $provinces [$index2] ['tbng']; 115 $totalTbth = $totalTbth + $provinces [$index2] ['tbt']; 116 $totalTbn = $totalTbn + $provinces [$index2] ['tbn']; 117 118 $totalDtng = $totalDtng + $provinces [$index2] ['dtng']; 119 $totalDtth = $totalDtth + $provinces [$index2] ['dtt']; 120 $totalDtn = $totalDtn + $provinces [$index2] ['dtn']; 121 106 122 $dem ++; 107 123 } 108 109 return $provinces; 124 125 $data['provinces'] = $provinces; 126 127 $data['totalTbng'] = $totalTbng; 128 $data['totalTbth'] = $totalTbth; 129 $data['totalTbn'] = $totalTbn; 130 131 $data['totalDtng'] = $totalDtng; 132 $data['totalDtth'] = $totalDtth; 133 $data['totalDtn'] = $totalDtn; 134 135 //return $provinces; 136 return $data; 110 137 } 111 138 … … 118 145 $provinces = lang ( '_PROVINCES_' ); 119 146 // tinh thue bao theo thang 120 $sql = "SELECT * FROM tbluser LEFT JOIN tblservicepackage ON tbluser.p_id=tblservicepackage.p_id WHERE tbluser.created_time >= '" . $input ['year'] . "-" . $input ['month'] . "-" . $input ['date'] . "' AND tbluser.created_time <= '" . $input ['to_year'] . "-" . $input ['to_month'] . "-" . $input ['to_date'] . "' AND tblservicepackage.p_period > 0 "; 147 //$sql = "SELECT * FROM tbluser LEFT JOIN tblservicepackage ON tbluser.p_id=tblservicepackage.p_id LEFT JOIN tblregisterpackagelog ON tbluser.cellphone = tblregisterpackagelog.username WHERE tbluser.updated_time >= '" . $input ['year'] . "-" . $input ['month'] . "-" . $input ['date'] . "' AND tbluser.updated_time <= '" . $input ['to_year'] . "-" . $input ['to_month'] . "-" . $input ['to_date'] . "' AND tblregisterpackagelog.created_time >= '" . $input ['year'] . "-" . $input ['month'] . "-" . $input ['date'] . "' AND tblregisterpackagelog.created_time <= '" . $input ['to_year'] . "-" . $input ['to_month'] . "-" . $input ['to_date'] . "' AND tblservicepackage.p_period > 0 "; 148 $sql = "SELECT * FROM tbluser LEFT JOIN tblregisterpackagelog ON tbluser.cellphone = tblregisterpackagelog.username WHERE tbluser.updated_time >= '" . $input ['year'] . "-" . $input ['month'] . "-" . $input ['date'] . "' AND tbluser.updated_time <= '" . $input ['to_year'] . "-" . $input ['to_month'] . "-" . $input ['to_date'] . "' AND tblregisterpackagelog.created_time >= '" . $input ['year'] . "-" . $input ['month'] . "-" . $input ['date'] . "' AND tblregisterpackagelog.created_time <= '" . $input ['to_year'] . "-" . $input ['to_month'] . "-" . $input ['to_date'] . "'"; 121 149 $query = $this->db->query ( $sql ); 122 150 $users = $query->result_array (); … … 128 156 $packages [$index] ['users'] = array (); 129 157 foreach ( $users as $user ) { 130 if ($user ['p_ id'] == $package ['p_id']) {158 if ($user ['p_code'] == $package ['p_code']) { 131 159 $packages [$index] ['users'] [] = $user; 132 160 } 133 161 } 134 162 } 135 136 163 foreach ( $provinces as $index => $province ) { 137 164 $provinces [$index] = array ( … … 139 166 ); 140 167 } 168 141 169 $dem = 1; 170 142 171 foreach ( $provinces as $index => $province ) { 143 172 $provinces [$index] ['stt'] = $dem; … … 154 183 $provinces [$index] ['total'] = $totaluser; 155 184 $provinces [$index] ['packages'] [$package ['p_name']] ['total'] = $total; 185 $provinces [$index] ['packages'] [$package ['p_name']] ['users'] [] = $user; 156 186 157 $provinces [$index] ['packages'] [$package ['p_name']] ['users'] [] = $user;158 187 } 159 188 } … … 161 190 $dem ++; 162 191 } 192 193 $totalByVIP = array(); 194 195 foreach ($packages as $index => $package){ 196 $totalByVIP[$package ['p_name']] = 0; 197 foreach ( $provinces as $index=>$province){ 198 foreach ($province['packages'] as $index2 => $p){ 199 if ($index2 == $package['p_name']) 200 $totalByVIP[$package ['p_name']] = $totalByVIP[$package ['p_name']] + $p['total']; 201 } 202 } 203 } 204 205 $totalVip = 0; 206 207 foreach ($totalByVIP as $vipName=>$total){ 208 $totalVip = $totalVip + $total; 209 } 210 211 $totalByVIP['total'] = $totalVip; 212 163 213 foreach ( $provinces as $index => $province ) { 164 214 foreach ( $packages as $index2 => $package ) { … … 172 222 $data ['packages'] = $packages; 173 223 $data ['provinces'] = $provinces; 224 $data['totalVip'] = $totalByVIP; 174 225 return $data; 175 226 }
Note: See TracChangeset
for help on using the changeset viewer.