|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Models; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Support\Facades\DB; |
|
6
|
|
|
use Illuminate\Database\Eloquent\Model; |
|
7
|
|
|
use Illuminate\Database\Schema\Blueprint; |
|
8
|
|
|
use Staudenmeir\LaravelMigrationViews\Facades\Schema; |
|
9
|
|
|
use Illuminate\Support\Facades\Schema as DbSchema; |
|
10
|
|
|
|
|
11
|
|
|
class DashboardViews extends Model |
|
12
|
|
|
{ |
|
13
|
|
|
|
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* create or update student's count |
|
17
|
|
|
* |
|
18
|
|
|
* @return void |
|
19
|
|
|
*/ |
|
20
|
|
|
public static function createOrUpdateStudentCount() |
|
21
|
|
|
{ |
|
22
|
|
|
try { |
|
23
|
|
|
$output = new \Symfony\Component\Console\Output\ConsoleOutput(); |
|
24
|
|
|
$output->writeln('creating : students_count_view'); |
|
25
|
|
|
$query = DB::table('institution_students as ist') |
|
26
|
|
|
->select( |
|
27
|
|
|
'ins.id as institution_id', |
|
28
|
|
|
DB::raw('count(ist.id) as total'), |
|
29
|
|
|
DB::raw("SUM(CASE WHEN security_users.gender_id = 1 THEN 1 ELSE 0 END) AS male"), |
|
30
|
|
|
DB::raw("SUM(CASE WHEN security_users.gender_id = 2 THEN 1 ELSE 0 END) AS female") |
|
31
|
|
|
) |
|
32
|
|
|
->leftJoin('institution_students as ist', 'ins.id', 'ist.institution_id') |
|
33
|
|
|
->leftJoin('security_users', 'security_users.id', 'ist.student_id') |
|
34
|
|
|
->groupBy('ins.id'); |
|
35
|
|
|
Schema::createOrReplaceView('students_count_view', $query); |
|
36
|
|
|
DbSchema::dropIfExists('students_count_view_table'); |
|
37
|
|
|
DB::statement('CREATE TABLE students_count_view_table AS (select * from students_count_view)'); |
|
38
|
|
|
$output->writeln('creat : students_count_view'); |
|
39
|
|
|
} catch (\Throwable $th) { |
|
40
|
|
|
$output->writeln($th->getMessage()); |
|
41
|
|
|
} |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* create student list |
|
46
|
|
|
* |
|
47
|
|
|
* @return void |
|
48
|
|
|
*/ |
|
49
|
|
|
public static function createOrUpdateStudentList() |
|
50
|
|
|
{ |
|
51
|
|
|
try { |
|
52
|
|
|
$output = new \Symfony\Component\Console\Output\ConsoleOutput(); |
|
53
|
|
|
$output->writeln('creating : students_list_view'); |
|
54
|
|
|
$query = DB::table('security_users as stu') |
|
55
|
|
|
->select( |
|
56
|
|
|
"i.id as institution_id", |
|
57
|
|
|
DB::raw("eg.name as `Grade`"), |
|
58
|
|
|
DB::raw("stu.openemis_no as `Student ID`"), |
|
59
|
|
|
DB::raw("stu.first_name as `Full Name`"), |
|
60
|
|
|
DB::raw("GROUP_CONCAT(DISTINCT edus.name) as `Subjects`"), |
|
61
|
|
|
DB::raw("IFNULL(LEFT(RIGHT(count(DISTINCT edus.id),8),4),'NA') as `Number of Subjects`"), |
|
62
|
|
|
DB::raw("DATE_FORMAT(stu.date_of_birth ,'%W, %M %e, %Y ' ) as `Date of Birth`"), |
|
63
|
|
|
DB::raw("g.name as `Gender`"), |
|
64
|
|
|
DB::raw("IFNULL(nati.name, 'NA') as `Nationality`"), |
|
65
|
|
|
DB::raw("IFNULL(idt.national_code, 'NA') as `Identity Type`"), |
|
66
|
|
|
DB::raw("IFNULL(LEFT(RIGHT(stu.identity_number,8),4),'NA') as `Identity Number`"), |
|
67
|
|
|
DB::raw("IFNULL (stu.identity_number,'na') as `Testing`"), |
|
68
|
|
|
DB::raw("ic.name as `Class`"), |
|
69
|
|
|
DB::raw("IFNULL(special_need_types.name, 'NA') as `Special Need Type`"), |
|
70
|
|
|
DB::raw("IFNULL(special_need_difficulties.name, 'NA') as `Special Need`"), |
|
71
|
|
|
DB::raw("IFNULL(stu.address, 'NA') as `Address`"), |
|
72
|
|
|
DB::raw("IFNULL(acp.name, 'NA') as `BMI Academic Period`"), |
|
73
|
|
|
DB::raw("DATE_FORMAT(bmit.date,'%W, %M %e, %Y ') as `BMI Date`"), |
|
74
|
|
|
DB::raw("IFNULL(bmit.height, 'NA') as `Height`"), |
|
75
|
|
|
DB::raw("IFNULL(bmit.weight, 'NA') as `Weight`"), |
|
76
|
|
|
DB::raw("IFNULL(acps.name, 'NA') as `Academic Periods`"), |
|
77
|
|
|
DB::raw("DATE_FORMAT(ist.start_date,'%W, %M %e, %Y ') as `Start Date`"), |
|
78
|
|
|
DB::raw("IFNULL(bro.name, 'NA') as `Birth Registrar Office`"), |
|
79
|
|
|
DB::raw("IFNULL(ds.name, 'NA') as `DS Office`"), |
|
80
|
|
|
DB::raw("stu.address_area_id"), |
|
81
|
|
|
DB::raw("IFNULL(sufu.first_name, 'NA') as `Father's Name`"), |
|
82
|
|
|
DB::raw("IFNULL(natif.name, 'NA') as `Father's Nationality`"), |
|
83
|
|
|
DB::raw("DATE_FORMAT(sufu.date_of_birth,'%W, %M %e, %Y ') as `Father's Date Of Birth`"), |
|
84
|
|
|
DB::raw("IFNULL(sufu.address , 'N/A') as `Father's Address`"), |
|
85
|
|
|
DB::raw("IFNULL(idtf.national_code, 'NA') as `Father's Identity Type`"), |
|
86
|
|
|
DB::raw("IFNULL(sufu.identity_number, 'NA') as `Father's Identity Number` "), |
|
87
|
|
|
DB::raw("IFNULL(sumu.first_name, 'N/A') as `Mothers's Name`"), |
|
88
|
|
|
DB::raw("IFNULL(natim.name, 'NA') as `Mothers's Nationality`"), |
|
89
|
|
|
DB::raw("DATE_FORMAT(sumu.date_of_birth,'%W, %M %e, %Y ') as `Mothers's Date Of Birth`"), |
|
90
|
|
|
DB::raw("IFNULL(sumu.address , 'N/A') as `Mothers's Address`"), |
|
91
|
|
|
DB::raw("IFNULL(idtm.national_code, 'NA') as `Mothers's Identity Type`"), |
|
92
|
|
|
DB::raw("IFNULL(sumu.identity_number, 'NA') as `Mother's Identity Number`"), |
|
93
|
|
|
DB::raw("IFNULL(sugu.first_name , 'N/A') as `Guardian's Name`"), |
|
94
|
|
|
DB::raw("IFNULL(natig.name, 'NA') as `Guardian's Nationality`"), |
|
95
|
|
|
DB::raw("DATE_FORMAT(sugu.date_of_birth,'%W, %M %e, %Y ') as `Guardian's Date Of Birth`"), |
|
96
|
|
|
DB::raw("IFNULL(sugu.address , 'N/A') as `Guardian's Address`"), |
|
97
|
|
|
DB::raw("IFNULL(idtg.national_code, 'NA') as `Guardian's Identity Type`"), |
|
98
|
|
|
DB::raw("IFNULL(sugu.identity_number, 'NA') as `Guardian's Identity Number`"), |
|
99
|
|
|
DB::raw("IFNULL(ubm.body_mass_index , 'N/A') as `BMI`") |
|
100
|
|
|
) |
|
101
|
|
|
->leftJoin("institution_students as ist", "ist.student_id", "stu.id") |
|
102
|
|
|
->leftJoin("institutions as i", "ist.institution_id", "i.id") |
|
103
|
|
|
->leftJoin("education_grades as eg", "eg.id", "i.id") |
|
104
|
|
|
->leftJoin("institution_class_students as ics", "ist.student_id", "ics.student_id") |
|
105
|
|
|
->leftJoin("institution_classes as ic", "ic.id", "ics.institution_class_id") |
|
106
|
|
|
->leftJoin("student_guardians as sgf", function ($join) { |
|
107
|
|
|
$join->on("sgf.student_id", "stu.id"); |
|
108
|
|
|
$join->where("sgf.guardian_relation_id", 1); |
|
109
|
|
|
}) |
|
110
|
|
|
->leftJoin("security_users as sufu", "sgf.guardian_id", "sufu.id") |
|
111
|
|
|
->leftJoin("student_guardians as sgm", function ($join) { |
|
112
|
|
|
$join->on("sgm.student_id", "stu.id"); |
|
113
|
|
|
$join->where("sgm.guardian_relation_id", 2); |
|
114
|
|
|
}) |
|
115
|
|
|
->leftJoin("security_users as sumu", "sgm.guardian_id", "sumu.id") |
|
116
|
|
|
->leftJoin("student_guardians as sg", function ($join) { |
|
117
|
|
|
$join->on("sg.student_id", "stu.id"); |
|
118
|
|
|
$join->where("sg.guardian_relation_id", 3); |
|
119
|
|
|
}) |
|
120
|
|
|
->leftJoin("security_users as sugu", "sg.guardian_id", "sugu.id") |
|
121
|
|
|
->leftJoin("user_body_masses as ubm", "ubm.security_user_id", "ist.student_id") |
|
122
|
|
|
->leftJoin("genders as g", "stu.gender_id", "g.id") |
|
123
|
|
|
->leftJoin("area_administratives as bro", "stu.birthplace_area_id", "bro.id") |
|
124
|
|
|
->leftJoin("area_administratives as ds", "stu.address_area_id", "ds.id") |
|
125
|
|
|
->leftJoin("nationalities as nati", "stu.nationality_id", "nati.id") |
|
126
|
|
|
->leftJoin("identity_types as idt", "stu.nationality_id", "idt.id") |
|
127
|
|
|
->leftJoin("user_special_needs", "ist.id", "user_special_needs.security_user_id") |
|
128
|
|
|
->leftJoin("special_need_types", "special_need_types.id", "user_special_needs.special_need_type_id") |
|
129
|
|
|
->leftJoin("special_need_difficulties", "special_need_difficulties.id", "user_special_needs.special_need_difficulty_id") |
|
130
|
|
|
->leftJoin("user_body_masses as bmit", "stu.id", "bmit.security_user_id") |
|
131
|
|
|
->leftJoin("academic_periods as acp", "acp.id", "bmit.academic_period_id") |
|
132
|
|
|
->leftJoin("academic_periods as acps", "acps.id", "ist.academic_period_id") |
|
133
|
|
|
->leftJoin("institution_subject_students as iss", "stu.id", "iss.student_id") |
|
134
|
|
|
->leftJoin("education_subjects as edus", "edus.id", "iss.education_subject_id") |
|
135
|
|
|
->leftJoin("nationalities as natif", function ($join) { |
|
136
|
|
|
$join->on("sufu.nationality_id", "natif.id"); |
|
137
|
|
|
$join->where("sgf.guardian_relation_id", 1); |
|
138
|
|
|
}) |
|
139
|
|
|
->leftJoin("nationalities as natim", function ($join) { |
|
140
|
|
|
$join->on("sumu.nationality_id", "natim.id"); |
|
141
|
|
|
$join->where("sgm.guardian_relation_id", 2); |
|
142
|
|
|
}) |
|
143
|
|
|
->leftJoin("nationalities as natig", function ($join) { |
|
144
|
|
|
$join->on("sugu.nationality_id", "natig.id"); |
|
145
|
|
|
$join->where("sg.guardian_relation_id", 3); |
|
146
|
|
|
}) |
|
147
|
|
|
->leftJoin("identity_types as idtf", function ($join) { |
|
148
|
|
|
$join->on("sufu.nationality_id", "idtf.id"); |
|
149
|
|
|
$join->where("sgf.guardian_relation_id", 1); |
|
150
|
|
|
}) |
|
151
|
|
|
->leftJoin("identity_types as idtm", function ($join) { |
|
152
|
|
|
$join->on("sumu.nationality_id", "idtm.id"); |
|
153
|
|
|
$join->where("sgm.guardian_relation_id", 2); |
|
154
|
|
|
}) |
|
155
|
|
|
->leftJoin("identity_types as idtg", function ($join) { |
|
156
|
|
|
$join->on("sugu.nationality_id", "idtg.id"); |
|
157
|
|
|
$join->where("sg.guardian_relation_id", 3); |
|
158
|
|
|
}) |
|
159
|
|
|
->groupBy("stu.openemis_no") |
|
160
|
|
|
->groupBy("i.id"); |
|
161
|
|
|
Schema::dropIfExists("students_list_view"); |
|
162
|
|
|
Schema::createOrReplaceView('students_list_view', $query); |
|
163
|
|
|
$exist = Schema::hasTable('students_list_view_table'); |
|
|
|
|
|
|
164
|
|
|
Schema::dropIfExists('students_list_view_table'); |
|
165
|
|
|
DB::statement('CREATE TABLE students_list_view_table select * from students_list_view;'); |
|
166
|
|
|
DB::statement('CREATE INDEX user_institution ON students_list_view_table (institution_id);'); |
|
167
|
|
|
$output->writeln('created : students_list_view_table'); |
|
168
|
|
|
$output->writeln('created : students_list_view'); |
|
169
|
|
|
} catch (\Throwable $th) { |
|
170
|
|
|
$output->writeln($th->getMessage()); |
|
171
|
|
|
} |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
/** |
|
175
|
|
|
* Create or update Upload list view |
|
176
|
|
|
* |
|
177
|
|
|
* @return void |
|
178
|
|
|
*/ |
|
179
|
|
|
public static function createOrUpdateUploadList() |
|
180
|
|
|
{ |
|
181
|
|
|
try { |
|
182
|
|
|
$output = new \Symfony\Component\Console\Output\ConsoleOutput(); |
|
183
|
|
|
$output->writeln('creating : upload_list_view'); |
|
184
|
|
|
$query = DB::table("uploads as up") |
|
185
|
|
|
->select( |
|
186
|
|
|
"i.id as institution_id", |
|
187
|
|
|
"i.name as Name", |
|
188
|
|
|
"i.code as Census", |
|
189
|
|
|
"ic.name as Class Name", |
|
190
|
|
|
"eg.name as Grade", |
|
191
|
|
|
"up.filename as Filename", |
|
192
|
|
|
DB::raw("(CASE |
|
193
|
|
|
WHEN up.is_processed = 0 then 'Not Processed' |
|
194
|
|
|
WHEN up.is_processed = 1 then 'Success' |
|
195
|
|
|
WHEN up.is_processed = 2 then 'Failed' |
|
196
|
|
|
WHEN up.is_processed = 3 and up.updated_at > (hour(now())-2) then 'Terminated' |
|
197
|
|
|
WHEN up.is_processed = 3 and up.updated_at < (hour(now())-2) then 'Processing' |
|
198
|
|
|
end) as Status "), |
|
199
|
|
|
DB::raw("(CASE |
|
200
|
|
|
WHEN up.insert = 0 then 'No Process' |
|
201
|
|
|
WHEN up.insert = 1 then 'Success' |
|
202
|
|
|
WHEN up.insert = 2 then 'Failed' |
|
203
|
|
|
WHEN up.insert = 3 and up.updated_at < (hour(now())-2) then 'Processing' |
|
204
|
|
|
WHEN up.insert = 3 and up.updated_at > (hour(now())-2) then 'Terminated' |
|
205
|
|
|
end) as 'Insert Students'"), |
|
206
|
|
|
DB::raw("(CASE |
|
207
|
|
|
WHEN up.update = 0 then 'No Process' |
|
208
|
|
|
WHEN up.update = 1 then 'Success' |
|
209
|
|
|
WHEN up.update = 2 then 'Failed' |
|
210
|
|
|
WHEN up.update = 3 and up.updated_at < (hour(now())-2) then 'Processing' |
|
211
|
|
|
WHEN up.update = 3 and up.updated_at > (hour(now())-2) then 'Terminated' |
|
212
|
|
|
end) as 'Create Students'"), |
|
213
|
|
|
DB::raw("(CASE |
|
214
|
|
|
WHEN up.is_email_sent = 0 then 'Not Send' |
|
215
|
|
|
WHEN up.is_email_sent = 1 then 'Email Sent' |
|
216
|
|
|
WHEN up.is_email_sent = 2 then 'Failed' |
|
217
|
|
|
end) as 'Email Status'"), |
|
218
|
|
|
"up.created_at as Uploaded Date", |
|
219
|
|
|
"up.updated_at as Last Processed Date" |
|
220
|
|
|
) |
|
221
|
|
|
->join('institution_classes as ic', 'up.institution_class_id', 'ic.id') |
|
222
|
|
|
->join('institutions as i', 'ic.institution_id', 'i.id') |
|
223
|
|
|
->join('institution_class_grades as icg', 'ic.id', 'icg.institution_class_id') |
|
224
|
|
|
->join('education_grades as eg', 'eg.id', 'icg.education_grade_id') |
|
225
|
|
|
->groupBy('up.id'); |
|
226
|
|
|
Schema::createOrReplaceView('upload_list_view', $query); |
|
227
|
|
|
Schema::disableForeignKeyConstraints('upload_list_view'); |
|
|
|
|
|
|
228
|
|
|
$output->writeln('created : upload_list_view'); |
|
229
|
|
|
} catch (\Throwable $th) { |
|
230
|
|
|
$output->writeln($th->getMessage()); |
|
231
|
|
|
} |
|
232
|
|
|
} |
|
233
|
|
|
|
|
234
|
|
|
/** |
|
235
|
|
|
* Create or update upload counts |
|
236
|
|
|
* |
|
237
|
|
|
* @return void |
|
238
|
|
|
*/ |
|
239
|
|
|
public static function createOrUpdateUploadCount() |
|
240
|
|
|
{ |
|
241
|
|
|
try { |
|
242
|
|
|
$output = new \Symfony\Component\Console\Output\ConsoleOutput(); |
|
243
|
|
|
$output->writeln('creating : upload_count_view'); |
|
244
|
|
|
$query = DB::table("uploads as up") |
|
245
|
|
|
->select( |
|
246
|
|
|
"i.id as institution_id", |
|
247
|
|
|
"i.name as School", |
|
248
|
|
|
"i.code as Census", |
|
249
|
|
|
DB::raw('count(*) as total'), |
|
250
|
|
|
DB::raw("SUM(CASE WHEN up.is_processed != 0 THEN 1 ELSE 0 END) as 'Total Processed'"), |
|
251
|
|
|
DB::raw("SUM(CASE WHEN up.insert = 1 THEN 1 ELSE 0 END) AS 'Success Insert'"), |
|
252
|
|
|
DB::raw("SUM(CASE WHEN up.insert = 2 THEN 1 ELSE 0 END) AS 'Failed Insert'"), |
|
253
|
|
|
DB::raw("SUM(CASE WHEN up.insert = 3 THEN 1 ELSE 0 END) AS 'Processing Insert'"), |
|
254
|
|
|
DB::raw("SUM(CASE WHEN up.update = 0 THEN 1 ELSE 0 END) AS 'Success update'"), |
|
255
|
|
|
DB::raw("SUM(CASE WHEN up.update = 2 THEN 1 ELSE 0 END) AS 'Failed update'"), |
|
256
|
|
|
DB::raw("SUM(CASE WHEN up.update = 3 THEN 1 ELSE 0 END) AS 'Processing update'") |
|
257
|
|
|
) |
|
258
|
|
|
->join('institution_classes as ic', 'up.institution_class_id', 'ic.id') |
|
259
|
|
|
->join('institutions as i', 'ic.institution_id', 'i.id') |
|
260
|
|
|
->groupBy('i.id'); |
|
261
|
|
|
Schema::dropIfExists("upload_count_view"); |
|
262
|
|
|
Schema::createOrReplaceView("upload_count_view", $query); |
|
263
|
|
|
$output->writeln('created : upload_count_view'); |
|
264
|
|
|
} catch (\Throwable $th) { |
|
265
|
|
|
$output->writeln($th->getMessage()); |
|
266
|
|
|
} |
|
267
|
|
|
} |
|
268
|
|
|
|
|
269
|
|
|
/** |
|
270
|
|
|
* Create or update Institution Infor |
|
271
|
|
|
* |
|
272
|
|
|
* @return void |
|
273
|
|
|
*/ |
|
274
|
|
|
public static function createOrUpdateInstitutionInfo() |
|
275
|
|
|
{ |
|
276
|
|
|
try { |
|
277
|
|
|
$output = new \Symfony\Component\Console\Output\ConsoleOutput(); |
|
278
|
|
|
$output->writeln('creating : institution_info_view'); |
|
279
|
|
|
$query = DB::table("institutions as i") |
|
280
|
|
|
->select( |
|
281
|
|
|
"i.id as institution_id", |
|
282
|
|
|
"i.name as School Name", |
|
283
|
|
|
"i.code as Census Code", |
|
284
|
|
|
"i.address as Address", |
|
285
|
|
|
"a.name as Zone" |
|
286
|
|
|
) |
|
287
|
|
|
->join("areas as a", "a.id", "i.area_id"); |
|
288
|
|
|
Schema::dropIfExists("institution_info_view"); |
|
289
|
|
|
Schema::createOrReplaceView("institution_info_view", $query); |
|
290
|
|
|
$output->writeln('created : institution_info_view'); |
|
291
|
|
|
} catch (\Throwable $th) { |
|
292
|
|
|
$output->writeln($th->getMessage()); |
|
293
|
|
|
} |
|
294
|
|
|
} |
|
295
|
|
|
|
|
296
|
|
|
/** |
|
297
|
|
|
* Create or update students count by grade view |
|
298
|
|
|
* |
|
299
|
|
|
* @return void |
|
300
|
|
|
*/ |
|
301
|
|
|
public static function createOrUpdateStudentsCountByGrade() |
|
302
|
|
|
{ |
|
303
|
|
|
try { |
|
304
|
|
|
$output = new \Symfony\Component\Console\Output\ConsoleOutput(); |
|
305
|
|
|
$output->writeln('creating : students_count_by_grade_view'); |
|
306
|
|
|
$query = DB::table('institution_students as ist') |
|
307
|
|
|
->select( |
|
308
|
|
|
"ist.institution_id", |
|
309
|
|
|
DB::raw("(count(CASE WHEN eg.code = 'G1' THEN ist.student_id END)) as `G-1`"), |
|
310
|
|
|
DB::raw("(count(CASE WHEN eg.code = 'G2' THEN ist.student_id END)) as `G-2`"), |
|
311
|
|
|
DB::raw("(count(CASE WHEN eg.code = 'G3' THEN ist.student_id END)) as `G-3`"), |
|
312
|
|
|
DB::raw("(count(CASE WHEN eg.code = 'G4' THEN ist.student_id END)) as `G-4`"), |
|
313
|
|
|
DB::raw("(count(CASE WHEN eg.code = 'G5' THEN ist.student_id END)) as `G-5`"), |
|
314
|
|
|
DB::raw("(count(CASE WHEN eg.code = 'G6' THEN ist.student_id END)) as `G-6`"), |
|
315
|
|
|
DB::raw("(count(CASE WHEN eg.code = 'G7' THEN ist.student_id END)) as `G-7`"), |
|
316
|
|
|
DB::raw("(count(CASE WHEN eg.code = 'G8' THEN ist.student_id END)) as `G-8`"), |
|
317
|
|
|
DB::raw("(count(CASE WHEN eg.code = 'G9' THEN ist.student_id END)) as `G-9`"), |
|
318
|
|
|
DB::raw("(count(CASE WHEN eg.code = 'G10' THEN ist.student_id END)) as `G-10`"), |
|
319
|
|
|
DB::raw("(count(CASE WHEN eg.code = 'G11' THEN ist.student_id END)) as `G-11`"), |
|
320
|
|
|
DB::raw("(count(CASE WHEN eg.code like '%G12%' THEN ist.student_id END)) as `G-12`"), |
|
321
|
|
|
DB::raw("(count(CASE WHEN eg.code like '%G13%' THEN ist.student_id END)) as `G-13`") |
|
322
|
|
|
) |
|
323
|
|
|
->join('education_grades as eg', 'eg.id', 'ist.education_grade_id') |
|
324
|
|
|
->groupBy('ist.institution_id'); |
|
325
|
|
|
|
|
326
|
|
|
Schema::dropIfExists("students_count_by_grade_view"); |
|
327
|
|
|
Schema::createOrReplaceView('students_count_by_grade_view', $query); |
|
328
|
|
|
$output->writeln('created : students_count_by_grade_view'); |
|
329
|
|
|
} catch (\Throwable $th) { |
|
330
|
|
|
$output->writeln($th->getMessage()); |
|
331
|
|
|
} |
|
332
|
|
|
} |
|
333
|
|
|
|
|
334
|
|
|
/** |
|
335
|
|
|
* cerate or update students count by bmi |
|
336
|
|
|
* |
|
337
|
|
|
* @return void |
|
338
|
|
|
*/ |
|
339
|
|
|
public static function createOrUpdateStudentCountByBMI() |
|
340
|
|
|
{ |
|
341
|
|
|
try { |
|
342
|
|
|
$output = new \Symfony\Component\Console\Output\ConsoleOutput(); |
|
343
|
|
|
$output->writeln('creating : students_count_by_bmi_view'); |
|
344
|
|
|
$query = DB::table('institution_students as ist') |
|
345
|
|
|
->select( |
|
346
|
|
|
"ist.institution_id", |
|
347
|
|
|
DB::raw("count(CASE WHEN ubm.body_mass_index < 13 THEN ubm.body_mass_index END) as `Underweight`"), |
|
348
|
|
|
DB::raw("count(CASE WHEN ubm.body_mass_index > 13 and ubm.body_mass_index <= 16 THEN ubm.body_mass_index END) as `Normal`"), |
|
349
|
|
|
DB::raw("count(CASE WHEN ubm.body_mass_index > 16 and ubm.body_mass_index <= 18.25 THEN ubm.body_mass_index END) as `Overweight`"), |
|
350
|
|
|
DB::raw("count(CASE WHEN ubm.body_mass_index > 18.25 THEN ubm.body_mass_index END) as `Severely obese`"), |
|
351
|
|
|
"ist.created" |
|
352
|
|
|
) |
|
353
|
|
|
->join("institutions as i", "i.id", "ist.institution_id") |
|
354
|
|
|
->join('user_body_masses as ubm', function ($join) { |
|
355
|
|
|
$join->on('ubm.security_user_id', 'ist.student_id'); |
|
356
|
|
|
$join->where('ubm.academic_period_id', 'ist.academic_period_id'); |
|
357
|
|
|
}) |
|
358
|
|
|
->groupBy("i.id"); |
|
359
|
|
|
Schema::dropIfExists("students_count_by_bmi_view"); |
|
360
|
|
|
Schema::createOrReplaceView("students_count_by_bmi_view", $query); |
|
361
|
|
|
$output->writeln('created : students_count_by_bmi_view'); |
|
362
|
|
|
} catch (\Throwable $th) { |
|
363
|
|
|
$output->writeln($th->getMessage()); |
|
364
|
|
|
} |
|
365
|
|
|
} |
|
366
|
|
|
|
|
367
|
|
|
/** |
|
368
|
|
|
* create or update the students count by class |
|
369
|
|
|
* |
|
370
|
|
|
* @return void |
|
371
|
|
|
*/ |
|
372
|
|
|
public static function createOrUpdateStudentCountByClass() |
|
373
|
|
|
{ |
|
374
|
|
|
try { |
|
375
|
|
|
$output = new \Symfony\Component\Console\Output\ConsoleOutput(); |
|
376
|
|
|
$output->writeln('creating : student_count_by_class_view'); |
|
377
|
|
|
$query = DB::table("institution_students as ist") |
|
378
|
|
|
->select( |
|
379
|
|
|
"ist.institution_id", |
|
380
|
|
|
"eg.name as Grade", |
|
381
|
|
|
"ic.name as Class", |
|
382
|
|
|
"st.first_name as 'Class Teacher'", |
|
383
|
|
|
DB::raw("format(count(*),0) as 'No of Students'") |
|
384
|
|
|
) |
|
385
|
|
|
->distinct(['ist.institution_id,ist.student_id,ist.academic_period_id']) |
|
|
|
|
|
|
386
|
|
|
->join("institutions as i", "i.id", "ist.institution_id") |
|
387
|
|
|
->join('education_grades as eg', 'eg.id', 'ist.education_grade_id') |
|
388
|
|
|
->join('institution_student_admission as isa', 'isa.student_id', 'ist.student_id') |
|
389
|
|
|
->join('institution_classes as ic', 'ic.id', 'isa.institution_class_id') |
|
390
|
|
|
->leftJoin('security_users as st', "st.id", "ic.staff_id") |
|
391
|
|
|
->groupBy("ic.id"); |
|
392
|
|
|
Schema::dropIfExists("student_count_by_class_view"); |
|
393
|
|
|
Schema::createOrReplaceView('student_count_by_class_view', $query); |
|
394
|
|
|
$output->writeln('created : student_count_by_class_view'); |
|
395
|
|
|
} catch (\Throwable $th) { |
|
396
|
|
|
$output->writeln($th->getMessage()); |
|
397
|
|
|
} |
|
398
|
|
|
} |
|
399
|
|
|
} |
|
400
|
|
|
|