Test Setup Failed
Branch master (93675a)
by Mohamed
10:31
created
app/Console/Commands/callAddApprovedStudents.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -39,17 +39,17 @@
 block discarded – undo
39 39
      */
40 40
     public function handle()
41 41
     {
42
-        ini_set('memory_limit','2048');
42
+        ini_set('memory_limit', '2048');
43 43
         $institutions = $this->instituions->all()->chunk(50)->toArray();
44
-        array_walk($institutions,array($this,'addInstitutionStudents'));
44
+        array_walk($institutions, array($this, 'addInstitutionStudents'));
45 45
     }
46 46
 
47
-    protected function addInstitutionStudents($chunk){
48
-        array_walk($chunk,array($this,'callFunction'));
47
+    protected function addInstitutionStudents($chunk) {
48
+        array_walk($chunk, array($this, 'callFunction'));
49 49
 
50 50
     }
51 51
 
52
-    protected function callFunction($institution){
53
-        $this->call('admission:students',['institution' => $institution['code']]);
52
+    protected function callFunction($institution) {
53
+        $this->call('admission:students', ['institution' => $institution['code']]);
54 54
     }
55 55
 }
Please login to merge, or discard this patch.
app/Console/Commands/CloneConfigData.php 3 patches
Indentation   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -76,9 +76,9 @@  discard block
 block discarded – undo
76 76
         $this->end_time = microtime(TRUE);
77 77
 
78 78
 
79
-       $this->output->writeln('$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$');
80
-       $this->output->writeln('The cook took ' . ($this->end_time - $this->start_time) . ' seconds to complete');
81
-       $this->output->writeln('$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$');
79
+        $this->output->writeln('$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$');
80
+        $this->output->writeln('The cook took ' . ($this->end_time - $this->start_time) . ' seconds to complete');
81
+        $this->output->writeln('$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$');
82 82
 
83 83
     }
84 84
 
@@ -113,13 +113,13 @@  discard block
 block discarded – undo
113 113
                     $this->output->writeln('updating from '. $shiftId);
114 114
 
115 115
                 }catch (\Exception $e){
116
-                     Log::error($e->getMessage(),[$e]);
116
+                        Log::error($e->getMessage(),[$e]);
117 117
                 }
118 118
             }
119 119
 //            DB::commit();
120 120
         }catch (\Exception $e){
121 121
 //            DB::rollBack();
122
-             Log::error($e->getMessage(),[$e]);
122
+                Log::error($e->getMessage(),[$e]);
123 123
         }
124 124
     }
125 125
 
@@ -130,16 +130,16 @@  discard block
 block discarded – undo
130 130
      * @param $academicPeriod
131 131
      */
132 132
     public function insertInstitutionSubjects($subjects, $count,$academicPeriod){
133
-       try{
134
-           $subjects['academic_period_id'] = $academicPeriod->id;
135
-           $subjects['created'] = now();
136
-           unset($subjects['total_male_students']);
137
-           unset($subjects['total_female_students']);
138
-           unset($subjects['id']);
139
-           $classSubject = Institution_subject::create($subjects);
140
-       }catch (\Exception $e){
133
+        try{
134
+            $subjects['academic_period_id'] = $academicPeriod->id;
135
+            $subjects['created'] = now();
136
+            unset($subjects['total_male_students']);
137
+            unset($subjects['total_female_students']);
138
+            unset($subjects['id']);
139
+            $classSubject = Institution_subject::create($subjects);
140
+        }catch (\Exception $e){
141 141
             Log::error($e->getMessage(),[$e]);
142
-       }
142
+        }
143 143
     }
144 144
 
145 145
 
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
                 $this->insertInstitutionClassSubjects($institutionSubjects,$class);
182 182
 //                array_walk($classSubjects,array($this,'insertInstitutionClassSubjects'),$params);
183 183
             }catch (\Exception $e){
184
-                 Log::error($e->getMessage(),[$e]);
184
+                    Log::error($e->getMessage(),[$e]);
185 185
             }
186 186
     }
187 187
 
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
                 array_walk($subjects,array($this,'insertClassSubjects'),$class);
192 192
                 $this->output->writeln('updating subjects '. $class->name);
193 193
             }catch (\Exception $e){
194
-                 Log::error($e->getMessage(),[$e]);
194
+                    Log::error($e->getMessage(),[$e]);
195 195
             }
196 196
         };
197 197
     }
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
                 $this->institution_class_subjects->create($subjectobj);
210 210
             }
211 211
         }catch (\Exception $e){
212
-             Log::error($e->getMessage(),[$e]);
212
+                Log::error($e->getMessage(),[$e]);
213 213
         }
214 214
     }
215 215
 
Please login to merge, or discard this patch.
Spacing   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -48,8 +48,8 @@  discard block
 block discarded – undo
48 48
         $this->academic_period = new Academic_period();
49 49
         $this->institution_classes = new Institution_class();
50 50
         $this->institution_class_subjects = new Institution_class_subject();
51
-        $this->institution_subjects =  new Institution_subject();
52
-        $this->education_grade_subjects =  new Education_grades_subject();
51
+        $this->institution_subjects = new Institution_subject();
52
+        $this->education_grade_subjects = new Education_grades_subject();
53 53
         $this->output = new \Symfony\Component\Console\Output\ConsoleOutput();
54 54
     }
55 55
 
@@ -72,33 +72,33 @@  discard block
 block discarded – undo
72 72
             'previous_academic_period' => $previousAcademicPeriod
73 73
         ];
74 74
         // dd($shift);
75
-        array_walk($shift,array($this,'process'),$params);
75
+        array_walk($shift, array($this, 'process'), $params);
76 76
         $this->end_time = microtime(TRUE);
77 77
 
78 78
 
79 79
        $this->output->writeln('$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$');
80
-       $this->output->writeln('The cook took ' . ($this->end_time - $this->start_time) . ' seconds to complete');
80
+       $this->output->writeln('The cook took '.($this->end_time - $this->start_time).' seconds to complete');
81 81
        $this->output->writeln('$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$');
82 82
 
83 83
     }
84 84
 
85
-    public function array_walk($shift,$count,$params){
86
-        array_walk($shift,array($this,'process'),$params);
85
+    public function array_walk($shift, $count, $params) {
86
+        array_walk($shift, array($this, 'process'), $params);
87 87
     }
88 88
 
89
-    public function process($shift,$count,$params){
89
+    public function process($shift, $count, $params) {
90 90
         $year = $params['year'];
91 91
         $academicPeriod = $params['academic_period'];
92 92
         $previousAcademicPeriod = $params['previous_academic_period'];
93 93
 //        DB::beginTransaction();
94
-        try{
94
+        try {
95 95
             $shiftId = $this->updateShifts($year, $shift);
96 96
             $institutionClasses = $this->institution_classes->getShiftClasses($shift['id']);
97 97
             $institutionSubjects = $this->education_grade_subjects->getInstitutionSubjects($shift['institution_id']);
98
-            array_walk($institutionSubjects , array($this,'insertInstitutionSubjects'),$academicPeriod);
99
-            if (!empty($institutionClasses) && !is_null($shiftId) && !is_null($academicPeriod) ) {
98
+            array_walk($institutionSubjects, array($this, 'insertInstitutionSubjects'), $academicPeriod);
99
+            if (!empty($institutionClasses) && !is_null($shiftId) && !is_null($academicPeriod)) {
100 100
 
101
-                $newInstitutionClasses = $this->generateNewClass($institutionClasses,$shiftId,$academicPeriod->id);
101
+                $newInstitutionClasses = $this->generateNewClass($institutionClasses, $shiftId, $academicPeriod->id);
102 102
 
103 103
                 $params = [
104 104
                     'previous_academic_period_id' => $previousAcademicPeriod->id,
@@ -106,20 +106,20 @@  discard block
 block discarded – undo
106 106
                     'shift_id' =>$shiftId
107 107
                 ];
108 108
 
109
-                try{
110
-                    array_walk($newInstitutionClasses,array($this,'insertInstitutionClasses'),$params);
109
+                try {
110
+                    array_walk($newInstitutionClasses, array($this, 'insertInstitutionClasses'), $params);
111 111
                     $newInstitutionClasses = $this->institution_classes->getShiftClasses($shiftId);
112 112
                     $this->output->writeln('##########################################################################################################################');
113
-                    $this->output->writeln('updating from '. $shiftId);
113
+                    $this->output->writeln('updating from '.$shiftId);
114 114
 
115
-                }catch (\Exception $e){
116
-                     Log::error($e->getMessage(),[$e]);
115
+                }catch (\Exception $e) {
116
+                     Log::error($e->getMessage(), [$e]);
117 117
                 }
118 118
             }
119 119
 //            DB::commit();
120
-        }catch (\Exception $e){
120
+        }catch (\Exception $e) {
121 121
 //            DB::rollBack();
122
-             Log::error($e->getMessage(),[$e]);
122
+             Log::error($e->getMessage(), [$e]);
123 123
         }
124 124
     }
125 125
 
@@ -129,31 +129,31 @@  discard block
 block discarded – undo
129 129
      * @param $count
130 130
      * @param $academicPeriod
131 131
      */
132
-    public function insertInstitutionSubjects($subjects, $count,$academicPeriod){
133
-       try{
132
+    public function insertInstitutionSubjects($subjects, $count, $academicPeriod) {
133
+       try {
134 134
            $subjects['academic_period_id'] = $academicPeriod->id;
135 135
            $subjects['created'] = now();
136 136
            unset($subjects['total_male_students']);
137 137
            unset($subjects['total_female_students']);
138 138
            unset($subjects['id']);
139 139
            $classSubject = Institution_subject::create($subjects);
140
-       }catch (\Exception $e){
141
-            Log::error($e->getMessage(),[$e]);
140
+       }catch (\Exception $e) {
141
+            Log::error($e->getMessage(), [$e]);
142 142
        }
143 143
     }
144 144
 
145 145
 
146
-    public function  insertInstitutionClasses($class,$count,$param){
147
-            try{
146
+    public function  insertInstitutionClasses($class, $count, $param) {
147
+            try {
148 148
 
149 149
                 $academicPeriod = $param['academic_period_id'];
150 150
                 $educationGrdae = $class['education_grade_id'];
151 151
 
152 152
                 $classId = $class['id'];
153 153
                 unset($class['id']);
154
-                $institutionSubjects = Institution_subject::query()->where('education_grade_id',$class['education_grade_id'])
155
-                    ->where('institution_id',$class['institution_id'])
156
-                    ->where('academic_period_id',$academicPeriod)->get()->toArray();
154
+                $institutionSubjects = Institution_subject::query()->where('education_grade_id', $class['education_grade_id'])
155
+                    ->where('institution_id', $class['institution_id'])
156
+                    ->where('academic_period_id', $academicPeriod)->get()->toArray();
157 157
                 $params = [
158 158
                     'class'=>$class,
159 159
                     'subjects'=>$institutionSubjects,
@@ -166,38 +166,38 @@  discard block
 block discarded – undo
166 166
                 $class['no_of_students'] = $noOfStudents;
167 167
                 $class['created'] = now();
168 168
                 $class['institution_shift_id'] = $param['shift_id'];
169
-                $this->output->writeln('Create class:'. $class['name']);
169
+                $this->output->writeln('Create class:'.$class['name']);
170 170
                 $class = Institution_class::create($class);
171 171
                 $institutionClassGrdaeObj['institution_class_id'] = $class->id;
172 172
                 $institutionClassGrdaeObj['education_grade_id'] = $educationGrdae;
173 173
                 Institution_class_grade::create($institutionClassGrdaeObj);
174
-                $institutionSubjects = Institution_subject::query()->where('education_grade_id',$educationGrdae)
175
-                    ->where('institution_id',$class->institution_id)
176
-                    ->where('academic_period_id',$academicPeriod)
174
+                $institutionSubjects = Institution_subject::query()->where('education_grade_id', $educationGrdae)
175
+                    ->where('institution_id', $class->institution_id)
176
+                    ->where('academic_period_id', $academicPeriod)
177 177
                     ->groupBy('education_subject_id')
178 178
                     ->get()
179 179
                     ->toArray();
180 180
                 $params['class'] = $class;
181
-                $this->insertInstitutionClassSubjects($institutionSubjects,$class);
181
+                $this->insertInstitutionClassSubjects($institutionSubjects, $class);
182 182
 //                array_walk($classSubjects,array($this,'insertInstitutionClassSubjects'),$params);
183
-            }catch (\Exception $e){
184
-                 Log::error($e->getMessage(),[$e]);
183
+            }catch (\Exception $e) {
184
+                 Log::error($e->getMessage(), [$e]);
185 185
             }
186 186
     }
187 187
 
188
-    public function insertInstitutionClassSubjects($subjects,$class){
189
-        if(!empty($subjects)){
190
-            try{
191
-                array_walk($subjects,array($this,'insertClassSubjects'),$class);
192
-                $this->output->writeln('updating subjects '. $class->name);
193
-            }catch (\Exception $e){
194
-                 Log::error($e->getMessage(),[$e]);
188
+    public function insertInstitutionClassSubjects($subjects, $class) {
189
+        if (!empty($subjects)) {
190
+            try {
191
+                array_walk($subjects, array($this, 'insertClassSubjects'), $class);
192
+                $this->output->writeln('updating subjects '.$class->name);
193
+            }catch (\Exception $e) {
194
+                 Log::error($e->getMessage(), [$e]);
195 195
             }
196 196
         };
197 197
     }
198 198
 
199
-    public function insertClassSubjects($subject,$count,$newClassId){
200
-        try{
199
+    public function insertClassSubjects($subject, $count, $newClassId) {
200
+        try {
201 201
             $subjectobj['status'] = 1;
202 202
             $subjectobj['created_user_id'] = 1;
203 203
             $subjectobj['created'] = now();
@@ -205,11 +205,11 @@  discard block
 block discarded – undo
205 205
             $subjectobj['institution_class_id'] = $newClassId->id;
206 206
             $subjectobj['institution_subject_id'] = $subject['id'];
207 207
 
208
-            if(!$this->institution_class_subjects->isDuplicated($subjectobj)){
208
+            if (!$this->institution_class_subjects->isDuplicated($subjectobj)) {
209 209
                 $this->institution_class_subjects->create($subjectobj);
210 210
             }
211
-        }catch (\Exception $e){
212
-             Log::error($e->getMessage(),[$e]);
211
+        }catch (\Exception $e) {
212
+             Log::error($e->getMessage(), [$e]);
213 213
         }
214 214
     }
215 215
 
@@ -221,15 +221,15 @@  discard block
 block discarded – undo
221 221
      * @param $academicPeriod
222 222
      * @return array
223 223
      */
224
-    public function generateNewClass($classes,$shiftId,$academicPeriod){
224
+    public function generateNewClass($classes, $shiftId, $academicPeriod) {
225 225
         $newClasses = [];
226
-        foreach ( $classes as $class) {
226
+        foreach ($classes as $class) {
227 227
             $noOfStudents = $class['no_of_students'] == 0 ? 40 : $class['no_of_students'];
228 228
             $class['academic_period_id'] = $academicPeriod;
229 229
             $class['no_of_students'] = $noOfStudents;
230 230
             $class['created'] = now();
231 231
             $class['institution_shift_id'] = $shiftId;
232
-            array_push($newClasses,$class);
232
+            array_push($newClasses, $class);
233 233
         }
234 234
         return $newClasses;
235 235
     }
@@ -240,11 +240,11 @@  discard block
 block discarded – undo
240 240
      * @param $shift
241 241
      * @return mixed
242 242
      */
243
-    public function updateShifts($year,$shift){
243
+    public function updateShifts($year, $shift) {
244 244
         $academicPeriod = $this->academic_period->getAcademicPeriod($year);
245
-        $this->shifts->where('id',$shift['id'])->update(['cloned' => '2020']);
245
+        $this->shifts->where('id', $shift['id'])->update(['cloned' => '2020']);
246 246
         $shift['academic_period_id'] = $academicPeriod->id;
247 247
         $exist = $this->shifts->shiftExists($shift);
248
-        return $this->shifts->create((array)$shift)->id;
248
+        return $this->shifts->create((array) $shift)->id;
249 249
     }
250 250
 }
Please login to merge, or discard this patch.
Braces   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -112,12 +112,12 @@  discard block
 block discarded – undo
112 112
                     $this->output->writeln('##########################################################################################################################');
113 113
                     $this->output->writeln('updating from '. $shiftId);
114 114
 
115
-                }catch (\Exception $e){
115
+                } catch (\Exception $e){
116 116
                      Log::error($e->getMessage(),[$e]);
117 117
                 }
118 118
             }
119 119
 //            DB::commit();
120
-        }catch (\Exception $e){
120
+        } catch (\Exception $e){
121 121
 //            DB::rollBack();
122 122
              Log::error($e->getMessage(),[$e]);
123 123
         }
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
            unset($subjects['total_female_students']);
138 138
            unset($subjects['id']);
139 139
            $classSubject = Institution_subject::create($subjects);
140
-       }catch (\Exception $e){
140
+       } catch (\Exception $e){
141 141
             Log::error($e->getMessage(),[$e]);
142 142
        }
143 143
     }
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
                 $params['class'] = $class;
181 181
                 $this->insertInstitutionClassSubjects($institutionSubjects,$class);
182 182
 //                array_walk($classSubjects,array($this,'insertInstitutionClassSubjects'),$params);
183
-            }catch (\Exception $e){
183
+            } catch (\Exception $e){
184 184
                  Log::error($e->getMessage(),[$e]);
185 185
             }
186 186
     }
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
             try{
191 191
                 array_walk($subjects,array($this,'insertClassSubjects'),$class);
192 192
                 $this->output->writeln('updating subjects '. $class->name);
193
-            }catch (\Exception $e){
193
+            } catch (\Exception $e){
194 194
                  Log::error($e->getMessage(),[$e]);
195 195
             }
196 196
         };
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
             if(!$this->institution_class_subjects->isDuplicated($subjectobj)){
209 209
                 $this->institution_class_subjects->create($subjectobj);
210 210
             }
211
-        }catch (\Exception $e){
211
+        } catch (\Exception $e){
212 212
              Log::error($e->getMessage(),[$e]);
213 213
         }
214 214
     }
Please login to merge, or discard this patch.
app/Console/Commands/ImportStudents.php 3 patches
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -286,8 +286,8 @@  discard block
 block discarded – undo
286 286
 
287 287
 
288 288
     protected function getSheetCount($file){
289
-       $objPHPExcel = $this->setReader($file);
290
-       return $objPHPExcel->getSheetCount();
289
+        $objPHPExcel = $this->setReader($file);
290
+        return $objPHPExcel->getSheetCount();
291 291
     }
292 292
 
293 293
 
@@ -298,8 +298,8 @@  discard block
 block discarded – undo
298 298
      * @param $column
299 299
      */
300 300
     protected function import($file, $sheet, $column){
301
-             try {
302
-                 ini_set('memory_limit', '2048M');
301
+                try {
302
+                    ini_set('memory_limit', '2048M');
303 303
                 $this->getFileSize($file);
304 304
                 $user = User::find($file['security_user_id']);
305 305
                 $excelFile = '/sis-bulk-data-files/' . $file['filename'];
@@ -360,23 +360,23 @@  discard block
 block discarded – undo
360 360
                         break;
361 361
                 }
362 362
             }catch (\Maatwebsite\Excel\Validators\ValidationException $e) {
363
-                 $this->output->writeln( $e->getMessage());
364
-                 if($sheet == 1){
365
-                     self::writeErrors($e,$file,'Insert Students');
366
-                     DB::table('uploads')
367
-                         ->where('id', $file['id'])
368
-                         ->update(['insert' => 2,'updated_at' => now()]);
363
+                    $this->output->writeln( $e->getMessage());
364
+                    if($sheet == 1){
365
+                        self::writeErrors($e,$file,'Insert Students');
366
+                        DB::table('uploads')
367
+                            ->where('id', $file['id'])
368
+                            ->update(['insert' => 2,'updated_at' => now()]);
369 369
                     $this->processFailedEmail($file,$user,'Fresh Student Data Upload:Failed');
370
-                 }else if($sheet == 2){
371
-                     self::writeErrors($e,$file,'Update Students');
372
-                     DB::table('uploads')
373
-                         ->where('id', $file['id'])
374
-                         ->update(['update' => 2,'updated_at' => now()]);
370
+                    }else if($sheet == 2){
371
+                        self::writeErrors($e,$file,'Update Students');
372
+                        DB::table('uploads')
373
+                            ->where('id', $file['id'])
374
+                            ->update(['update' => 2,'updated_at' => now()]);
375 375
                     $this->processFailedEmail($file,$user, 'Existing Student Data Update:Failed');
376
-                 }
377
-                 DB::table('uploads')
378
-                     ->where('id',  $file['id'])
379
-                     ->update(['is_processed' =>2 , 'updated_at' => now()]);
376
+                    }
377
+                    DB::table('uploads')
378
+                        ->where('id',  $file['id'])
379
+                        ->update(['is_processed' =>2 , 'updated_at' => now()]);
380 380
 
381 381
             }
382 382
 
Please login to merge, or discard this patch.
Spacing   +164 added lines, -164 removed lines patch added patch discarded remove patch
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
      */
48 48
     public function __construct()
49 49
     {
50
-        $this->output =  new \Symfony\Component\Console\Output\ConsoleOutput();
50
+        $this->output = new \Symfony\Component\Console\Output\ConsoleOutput();
51 51
         parent::__construct();
52 52
     }
53 53
 
@@ -62,64 +62,64 @@  discard block
 block discarded – undo
62 62
 //        if(empty($files)){
63 63
 //            $files = $this->getTerminatedFiles();
64 64
 //        }
65
-        while ($this->checkTime()){
66
-            if($this->checkTime()){
65
+        while ($this->checkTime()) {
66
+            if ($this->checkTime()) {
67 67
                 try {
68
-                    if(!empty($files)){
68
+                    if (!empty($files)) {
69 69
                         $this->process($files);
70 70
                         unset($files);
71 71
                         exit();
72 72
 
73
-                    }else{
73
+                    }else {
74 74
                         $output = new \Symfony\Component\Console\Output\ConsoleOutput();
75 75
                         $this->output->writeln('No files found,Waiting for files');
76 76
                         exit();
77 77
 
78 78
                     }
79 79
 
80
-                }catch (Exception $e){
80
+                }catch (Exception $e) {
81 81
                     $output = new \Symfony\Component\Console\Output\ConsoleOutput();
82 82
                     $this->output->writeln($e);
83 83
                     sleep(300);
84 84
                     $this->handle();
85 85
 
86 86
                 }
87
-            }else{
87
+            }else {
88 88
                 exit();
89 89
             }
90 90
         }
91 91
     }
92 92
 
93 93
 
94
-    protected function  process($files){
94
+    protected function  process($files) {
95 95
         $time = Carbon::now()->tz('Asia/Colombo');
96 96
 //        array_walk($files, array($this,'processSheet'));
97 97
         $node = $this->argument('node');
98 98
         $files[0]['node'] = $node;
99 99
         $this->processSheet($files[0]);
100 100
         $now = Carbon::now()->tz('Asia/Colombo');
101
-        $this->output->writeln('=============== Time taken to batch ' .$now->diffInMinutes($time));
101
+        $this->output->writeln('=============== Time taken to batch '.$now->diffInMinutes($time));
102 102
 
103 103
     }
104 104
 
105
-    protected function getTerminatedFiles(){
105
+    protected function getTerminatedFiles() {
106 106
         $files = Upload::where('is_processed', '=', 3)
107 107
             ->where('updated_at', '<=', Carbon::now()->tz('Asia/Colombo')->subHours(3))
108 108
             ->limit(1)
109
-            ->orderBy('updated_at','desc')
109
+            ->orderBy('updated_at', 'desc')
110 110
             ->get()->toArray();
111
-        if(!empty($files)){
111
+        if (!empty($files)) {
112 112
             $this->output->writeln('******************* Processing a terminated file **********************');
113 113
             DB::beginTransaction();
114 114
             DB::table('uploads')
115 115
                 ->where('id', $files[0]['id'])
116
-                ->update(['is_processed' => 4,'updated_at' => now()]);
116
+                ->update(['is_processed' => 4, 'updated_at' => now()]);
117 117
             DB::commit();
118 118
         }
119 119
         return $files;
120 120
     }
121 121
 
122
-    protected function getFiles(){
122
+    protected function getFiles() {
123 123
         $files = Upload::where('is_processed', '=', 0)
124 124
             ->select('uploads.id', 'uploads.security_user_id', 'uploads.institution_class_id', 'uploads.model',
125 125
                 'uploads.filename', 'uploads.is_processed', 'uploads.deleted_at', 'uploads.created_at',
@@ -133,85 +133,85 @@  discard block
 block discarded – undo
133 133
             ->limit(1)
134 134
             ->get()->toArray();
135 135
         $node = $this->argument('node');
136
-        if(!empty($files)){
136
+        if (!empty($files)) {
137 137
             DB::beginTransaction();
138 138
             DB::table('uploads')
139 139
                 ->where('id', $files[0]['id'])
140
-                ->update(['is_processed' => 3,'updated_at' => now(),'node' => $node]);
140
+                ->update(['is_processed' => 3, 'updated_at' => now(), 'node' => $node]);
141 141
             DB::commit();
142 142
         }
143 143
         return $files;
144 144
     }
145 145
 
146
-    protected function checkTime(){
146
+    protected function checkTime() {
147 147
         $time = Carbon::now()->tz('Asia/Colombo');
148
-        $morning = Carbon::create($time->year, $time->month, $time->day, env('CRON_START_TIME',0), 29, 0)->tz('Asia/Colombo')->setHour(0); //set time to 05:59
148
+        $morning = Carbon::create($time->year, $time->month, $time->day, env('CRON_START_TIME', 0), 29, 0)->tz('Asia/Colombo')->setHour(0); //set time to 05:59
149 149
 
150
-        $evening = Carbon::create($time->year, $time->month, $time->day, env('CRON_END_TIME',0), 30, 0)->tz('Asia/Colombo')->setHour(23); //set time to 18:00
150
+        $evening = Carbon::create($time->year, $time->month, $time->day, env('CRON_END_TIME', 0), 30, 0)->tz('Asia/Colombo')->setHour(23); //set time to 18:00
151 151
 
152
-        $check = $time->between($morning,$evening, true);
152
+        $check = $time->between($morning, $evening, true);
153 153
         return true;
154 154
     }
155 155
 
156
-    public function processSuccessEmail($file,$user,$subject) {
156
+    public function processSuccessEmail($file, $user, $subject) {
157 157
         $file['subject'] = $subject;
158 158
         $this->output->writeln('Processing the file: '.$file['filename']);
159 159
         try {
160 160
             Mail::to($user->email)->send(new StudentImportSuccess($file));
161 161
             DB::table('uploads')
162 162
                     ->where('id', $file['id'])
163
-                    ->update(['is_processed' => 1, 'is_email_sent' => 1,'updated_at' => now()]);
164
-        } catch (\Exception $ex) {
165
-            $this->output->writeln( $ex->getMessage());
163
+                    ->update(['is_processed' => 1, 'is_email_sent' => 1, 'updated_at' => now()]);
164
+        }catch (\Exception $ex) {
165
+            $this->output->writeln($ex->getMessage());
166 166
             DB::table('uploads')
167 167
                     ->where('id', $file['id'])
168
-                    ->update(['is_processed' => 1, 'is_email_sent' => 2,'updated_at' => now()]);
168
+                    ->update(['is_processed' => 1, 'is_email_sent' => 2, 'updated_at' => now()]);
169 169
         }
170 170
     }
171 171
 
172
-    public function processFailedEmail($file,$user,$subject) {
172
+    public function processFailedEmail($file, $user, $subject) {
173 173
         $file['subject'] = $subject;
174 174
         try {
175 175
             Mail::to($user->email)->send(new StudentImportFailure($file));
176 176
             DB::table('uploads')
177 177
                     ->where('id', $file['id'])
178
-                    ->update(['is_processed' => 2, 'is_email_sent' => 1,'updated_at' => now()]);
179
-        } catch (\Exception $ex) {
180
-            $this->output->writeln( $ex->getMessage());
178
+                    ->update(['is_processed' => 2, 'is_email_sent' => 1, 'updated_at' => now()]);
179
+        }catch (\Exception $ex) {
180
+            $this->output->writeln($ex->getMessage());
181 181
             DB::table('uploads')
182 182
                     ->where('id', $file['id'])
183
-                    ->update(['is_processed' => 2, 'is_email_sent' => 2,'updated_at' => now()]);
183
+                    ->update(['is_processed' => 2, 'is_email_sent' => 2, 'updated_at' => now()]);
184 184
         }
185 185
     }
186 186
 
187
-    public function processEmptyEmail($file,$user,$subject) {
187
+    public function processEmptyEmail($file, $user, $subject) {
188 188
         $file['subject'] = $subject;
189 189
         try {
190 190
             Mail::to($user->email)->send(new EmptyFile($file));
191 191
             DB::table('uploads')
192 192
                 ->where('id', $file['id'])
193
-                ->update(['is_processed' => 2, 'is_email_sent' => 1,'updated_at' => now()]);
194
-        } catch (\Exception $ex) {
195
-            $this->output->writeln( $ex->getMessage());
193
+                ->update(['is_processed' => 2, 'is_email_sent' => 1, 'updated_at' => now()]);
194
+        }catch (\Exception $ex) {
195
+            $this->output->writeln($ex->getMessage());
196 196
             DB::table('uploads')
197 197
                 ->where('id', $file['id'])
198
-                ->update(['is_processed' => 2, 'is_email_sent' => 2,'updated_at' => now()]);
198
+                ->update(['is_processed' => 2, 'is_email_sent' => 2, 'updated_at' => now()]);
199 199
         }
200 200
     }
201 201
 
202
-    protected function checkNode($file){
202
+    protected function checkNode($file) {
203 203
         $node = $this->argument('node');
204
-        if($node == $file['node']){
204
+        if ($node == $file['node']) {
205 205
             $output = new \Symfony\Component\Console\Output\ConsoleOutput();
206
-            $this->output->writeln('Processing from:' . $node);
206
+            $this->output->writeln('Processing from:'.$node);
207 207
             return true;
208
-        }else{
208
+        }else {
209 209
             exit;
210 210
             return false;
211 211
         }
212 212
     }
213 213
 
214
-    protected function processSheet($file){
214
+    protected function processSheet($file) {
215 215
         $this->startTime = Carbon::now()->tz('Asia/Colombo');
216 216
         $user = User::find($file['security_user_id']);
217 217
         $this->checkNode($file);
@@ -219,39 +219,39 @@  discard block
 block discarded – undo
219 219
         $this->output->writeln('Processing the file: '.$file['filename']);
220 220
         if ($this->checkTime()) {
221 221
             try {
222
-                $this->import($file,1,'C');
222
+                $this->import($file, 1, 'C');
223 223
                 sleep(10);
224
-                $this->import($file,2,'B');
224
+                $this->import($file, 2, 'B');
225 225
 
226
-            } catch (\Maatwebsite\Excel\Validators\ValidationException $e) {
227
-                $this->output->writeln( $e->getMessage());
226
+            }catch (\Maatwebsite\Excel\Validators\ValidationException $e) {
227
+                $this->output->writeln($e->getMessage());
228 228
                 try {
229 229
                     Mail::to($user->email)->send(new IncorrectTemplate($file));
230 230
                     DB::table('uploads')
231 231
                             ->where('id', $file['id'])
232
-                            ->update(['is_processed' => 2, 'is_email_sent' => 1,'updated_at' => now()]);
233
-                } catch (\Exception $ex) {
234
-                    $this->output->writeln( $e->getMessage());
232
+                            ->update(['is_processed' => 2, 'is_email_sent' => 1, 'updated_at' => now()]);
233
+                }catch (\Exception $ex) {
234
+                    $this->output->writeln($e->getMessage());
235 235
                     $this->handle();
236 236
                     DB::table('uploads')
237 237
                             ->where('id', $file['id'])
238
-                            ->update(['is_processed' => 2, 'is_email_sent' => 2 ,'updated_at' => now()]);
238
+                            ->update(['is_processed' => 2, 'is_email_sent' => 2, 'updated_at' => now()]);
239 239
                 }
240 240
             }
241
-        } else {
241
+        }else {
242 242
             exit();
243 243
         }
244 244
     }
245 245
 
246
-    protected function getType($file){
247
-        $file =  storage_path() . '/app/sis-bulk-data-files/'.$file;
248
-        $inputFileType =  \PhpOffice\PhpSpreadsheet\IOFactory::identify($file);
246
+    protected function getType($file) {
247
+        $file = storage_path().'/app/sis-bulk-data-files/'.$file;
248
+        $inputFileType = \PhpOffice\PhpSpreadsheet\IOFactory::identify($file);
249 249
         return $inputFileType;
250 250
     }
251 251
 
252 252
 
253
-    protected function getSheetWriter($file,$reader){
254
-        switch ($this->getType($file['filename'])){
253
+    protected function getSheetWriter($file, $reader) {
254
+        switch ($this->getType($file['filename'])) {
255 255
             case 'Xlsx':
256 256
                 return new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($reader);
257 257
                 break;
@@ -267,8 +267,8 @@  discard block
 block discarded – undo
267 267
         }
268 268
     }
269 269
 
270
-    protected function getSheetType($file){
271
-        switch ($this->getType($file)){
270
+    protected function getSheetType($file) {
271
+        switch ($this->getType($file)) {
272 272
             case 'Xlsx':
273 273
                 return \Maatwebsite\Excel\Excel::XLSX;
274 274
                 break;
@@ -285,7 +285,7 @@  discard block
 block discarded – undo
285 285
     }
286 286
 
287 287
 
288
-    protected function getSheetCount($file){
288
+    protected function getSheetCount($file) {
289 289
        $objPHPExcel = $this->setReader($file);
290 290
        return $objPHPExcel->getSheetCount();
291 291
     }
@@ -297,205 +297,205 @@  discard block
 block discarded – undo
297 297
      * @param $sheet
298 298
      * @param $column
299 299
      */
300
-    protected function import($file, $sheet, $column){
300
+    protected function import($file, $sheet, $column) {
301 301
              try {
302 302
                  ini_set('memory_limit', '2048M');
303 303
                 $this->getFileSize($file);
304 304
                 $user = User::find($file['security_user_id']);
305
-                $excelFile = '/sis-bulk-data-files/' . $file['filename'];
306
-                $this->higestRow = $this->getHigestRow($file, $sheet,$column);
307
-                switch ($sheet){
305
+                $excelFile = '/sis-bulk-data-files/'.$file['filename'];
306
+                $this->higestRow = $this->getHigestRow($file, $sheet, $column);
307
+                switch ($sheet) {
308 308
                     case 1;
309
-                        $this->output->writeln( 'Trying to insert Students');
310
-                        if (($this->getSheetName($file,'Insert Students')) && $this->higestRow > 0)  { //
309
+                        $this->output->writeln('Trying to insert Students');
310
+                        if (($this->getSheetName($file, 'Insert Students')) && $this->higestRow > 0) { //
311 311
                             $import = new UsersImport($file);
312
-                            $import->import($excelFile,'local',$this->getSheetType($file['filename']));
312
+                            $import->import($excelFile, 'local', $this->getSheetType($file['filename']));
313 313
 //                            Excel::import($import, $excelFile, 'local');
314 314
                             DB::table('uploads')
315 315
                                 ->where('id', $file['id'])
316
-                                ->update(['insert' => 1,'is_processed' => 1,'updated_at' => now()]);
317
-                            if($import->failures()->count() > 0){
318
-                                self::writeErrors($import,$file,'Insert Students');
316
+                                ->update(['insert' => 1, 'is_processed' => 1, 'updated_at' => now()]);
317
+                            if ($import->failures()->count() > 0) {
318
+                                self::writeErrors($import, $file, 'Insert Students');
319 319
                                 DB::table('uploads')
320 320
                                     ->where('id', $file['id'])
321
-                                    ->update(['insert' => 3,'updated_at' => now()]);
322
-                                $this->processFailedEmail($file,$user,'Fresh Student Data Upload:Partial Success ');
323
-                                $this->stdOut('Insert Students',$this->higestRow);
324
-                            }else{
325
-                                $this->processSuccessEmail($file,$user,'Fresh Student Data Upload:Success ');
326
-                                $this->stdOut('Insert Students',$this->higestRow);
321
+                                    ->update(['insert' => 3, 'updated_at' => now()]);
322
+                                $this->processFailedEmail($file, $user, 'Fresh Student Data Upload:Partial Success ');
323
+                                $this->stdOut('Insert Students', $this->higestRow);
324
+                            }else {
325
+                                $this->processSuccessEmail($file, $user, 'Fresh Student Data Upload:Success ');
326
+                                $this->stdOut('Insert Students', $this->higestRow);
327 327
                             }
328
-                        }else if(($this->getSheetName($file,'Insert Students')) && $this->higestRow > 0) {
328
+                        }else if (($this->getSheetName($file, 'Insert Students')) && $this->higestRow > 0) {
329 329
                             DB::table('uploads')
330 330
                                 ->where('id', $file['id'])
331 331
                                 ->update(['is_processed' => 2]);
332
-                            $this->processEmptyEmail($file,$user, 'Fresh Student Data Upload ');
332
+                            $this->processEmptyEmail($file, $user, 'Fresh Student Data Upload ');
333 333
                         }
334 334
                         break;
335 335
                     case 2;
336
-                        $this->output->writeln( 'Trying to update Students');
337
-                        if (($this->getSheetName($file,'Update Students')) && $this->higestRow > 0) {
336
+                        $this->output->writeln('Trying to update Students');
337
+                        if (($this->getSheetName($file, 'Update Students')) && $this->higestRow > 0) {
338 338
                             $import = new StudentUpdate($file);
339
-                            $import->import($excelFile,'local',$this->getSheetType($file['filename']));
339
+                            $import->import($excelFile, 'local', $this->getSheetType($file['filename']));
340 340
                             DB::table('uploads')
341 341
                                 ->where('id', $file['id'])
342
-                                ->update(['update' => 1,'is_processed' => 1,'updated_at' => now()]);
343
-                            if($import->failures()->count() > 0){
344
-                                self::writeErrors($import,$file,'Update Students');
342
+                                ->update(['update' => 1, 'is_processed' => 1, 'updated_at' => now()]);
343
+                            if ($import->failures()->count() > 0) {
344
+                                self::writeErrors($import, $file, 'Update Students');
345 345
                                 DB::table('uploads')
346 346
                                     ->where('id', $file['id'])
347
-                                    ->update(['update' => 3,'is_processed' => 1,'updated_at' => now()]);
348
-                                $this->processFailedEmail($file,$user,'Existing Student Data Update:Partial Success ');
349
-                                $this->stdOut('Update Students',$this->higestRow);
350
-                            }else{
351
-                                $this->processSuccessEmail($file,$user, 'Existing Student Data Update:Success ');
352
-                                $this->stdOut('Update Students',$this->higestRow);
347
+                                    ->update(['update' => 3, 'is_processed' => 1, 'updated_at' => now()]);
348
+                                $this->processFailedEmail($file, $user, 'Existing Student Data Update:Partial Success ');
349
+                                $this->stdOut('Update Students', $this->higestRow);
350
+                            }else {
351
+                                $this->processSuccessEmail($file, $user, 'Existing Student Data Update:Success ');
352
+                                $this->stdOut('Update Students', $this->higestRow);
353 353
                             }
354
-                        }else if(($this->getSheetName($file,'Update Students')) && $this->higestRow == 0) {
354
+                        }else if (($this->getSheetName($file, 'Update Students')) && $this->higestRow == 0) {
355 355
                             DB::table('uploads')
356 356
                                 ->where('id', $file['id'])
357
-                                ->update(['is_processed' => 2,'updated_at' => now()]);
358
-                            $this->processEmptyEmail($file,$user, 'Existing Student Data Update');
357
+                                ->update(['is_processed' => 2, 'updated_at' => now()]);
358
+                            $this->processEmptyEmail($file, $user, 'Existing Student Data Update');
359 359
                         }
360 360
                         break;
361 361
                 }
362 362
             }catch (\Maatwebsite\Excel\Validators\ValidationException $e) {
363
-                 $this->output->writeln( $e->getMessage());
364
-                 if($sheet == 1){
365
-                     self::writeErrors($e,$file,'Insert Students');
363
+                 $this->output->writeln($e->getMessage());
364
+                 if ($sheet == 1) {
365
+                     self::writeErrors($e, $file, 'Insert Students');
366 366
                      DB::table('uploads')
367 367
                          ->where('id', $file['id'])
368
-                         ->update(['insert' => 2,'updated_at' => now()]);
369
-                    $this->processFailedEmail($file,$user,'Fresh Student Data Upload:Failed');
370
-                 }else if($sheet == 2){
371
-                     self::writeErrors($e,$file,'Update Students');
368
+                         ->update(['insert' => 2, 'updated_at' => now()]);
369
+                    $this->processFailedEmail($file, $user, 'Fresh Student Data Upload:Failed');
370
+                 }else if ($sheet == 2) {
371
+                     self::writeErrors($e, $file, 'Update Students');
372 372
                      DB::table('uploads')
373 373
                          ->where('id', $file['id'])
374
-                         ->update(['update' => 2,'updated_at' => now()]);
375
-                    $this->processFailedEmail($file,$user, 'Existing Student Data Update:Failed');
374
+                         ->update(['update' => 2, 'updated_at' => now()]);
375
+                    $this->processFailedEmail($file, $user, 'Existing Student Data Update:Failed');
376 376
                  }
377 377
                  DB::table('uploads')
378
-                     ->where('id',  $file['id'])
379
-                     ->update(['is_processed' =>2 , 'updated_at' => now()]);
378
+                     ->where('id', $file['id'])
379
+                     ->update(['is_processed' =>2, 'updated_at' => now()]);
380 380
 
381 381
             }
382 382
 
383 383
     }
384 384
 
385
-    protected function processErrors($failure){
386
-            $error_mesg = implode(',',$failure->errors());
385
+    protected function processErrors($failure) {
386
+            $error_mesg = implode(',', $failure->errors());
387 387
             $failure = [
388 388
                 'row'=> $failure->row(),
389
-                'errors' => [ $error_mesg],
389
+                'errors' => [$error_mesg],
390 390
                 'attribute' => $failure->attribute()
391 391
             ];
392 392
             return $failure;
393 393
 
394 394
     }
395 395
 
396
-    protected function  getFileSize($file){
397
-        $excelFile =  '/sis-bulk-data-files/' . $file['filename'];
396
+    protected function  getFileSize($file) {
397
+        $excelFile = '/sis-bulk-data-files/'.$file['filename'];
398 398
         $size = Storage::disk('local')->size($excelFile);
399 399
         $user = User::find($file['security_user_id']);
400
-        if( $size > 0){
400
+        if ($size > 0) {
401 401
             return true;
402
-        }else{
402
+        }else {
403 403
             DB::table('uploads')
404
-                ->where('id',  $file['id'])
405
-                ->update(['is_processed' =>2 , 'updated_at' => now()]);
406
-            $this->stdOut('No valid data found :Please re-upload the file',0);
407
-            $this->processEmptyEmail($file,$user, 'No valid data found :Please re-upload the file');
404
+                ->where('id', $file['id'])
405
+                ->update(['is_processed' =>2, 'updated_at' => now()]);
406
+            $this->stdOut('No valid data found :Please re-upload the file', 0);
407
+            $this->processEmptyEmail($file, $user, 'No valid data found :Please re-upload the file');
408 408
         }
409 409
     }
410 410
 
411
-    protected function setReader($file){
412
-        try{
413
-            $excelFile =  '/sis-bulk-data-files/processed/' . $file['filename'];
411
+    protected function setReader($file) {
412
+        try {
413
+            $excelFile = '/sis-bulk-data-files/processed/'.$file['filename'];
414 414
             $exists = Storage::disk('local')->exists($excelFile);
415
-            if(!$exists){
415
+            if (!$exists) {
416 416
 
417
-                $excelFile =  "/sis-bulk-data-files/" . $file['filename'];
417
+                $excelFile = "/sis-bulk-data-files/".$file['filename'];
418 418
             }
419
-            $excelFile = storage_path()."/app" . $excelFile;
419
+            $excelFile = storage_path()."/app".$excelFile;
420 420
             $reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($this->getType($file['filename']));
421
-            $objPHPExcel =  $reader->load($excelFile);
421
+            $objPHPExcel = $reader->load($excelFile);
422 422
             return $objPHPExcel;
423
-        }catch (Exception $e){
424
-            $this->output->writeln( $e->getMessage());
423
+        }catch (Exception $e) {
424
+            $this->output->writeln($e->getMessage());
425 425
             $user = User::find($file['security_user_id']);
426 426
             DB::table('uploads')
427
-                ->where('id',  $file['id'])
428
-                ->update(['is_processed' =>2 , 'updated_at' => now()]);
429
-            $this->stdOut('No valid data found :Please re-upload the file',0);
430
-            $this->processEmptyEmail($file,$user, 'No valid data found :Please re-upload the file');
427
+                ->where('id', $file['id'])
428
+                ->update(['is_processed' =>2, 'updated_at' => now()]);
429
+            $this->stdOut('No valid data found :Please re-upload the file', 0);
430
+            $this->processEmptyEmail($file, $user, 'No valid data found :Please re-upload the file');
431 431
         }
432 432
     }
433 433
 
434
-    protected function  getSheetName($file,$sheet){
435
-        try{;
434
+    protected function  getSheetName($file, $sheet) {
435
+        try {;
436 436
             $objPHPExcel = $this->setReader($file);
437
-            return $objPHPExcel->getSheetByName($sheet)  !== null;
438
-        }catch (Exception $e){
439
-            $this->output->writeln( $e->getMessage());
437
+            return $objPHPExcel->getSheetByName($sheet) !== null;
438
+        }catch (Exception $e) {
439
+            $this->output->writeln($e->getMessage());
440 440
             $user = User::find($file['security_user_id']);
441 441
             DB::table('uploads')
442
-                ->where('id',  $file['id'])
443
-                ->update(['is_processed' =>2 , 'updated_at' => now()]);
444
-            $this->stdOut('No valid data found :Please re-upload the file',0);
445
-            $this->processEmptyEmail($file,$user, 'No valid data found :Please re-upload the file');
442
+                ->where('id', $file['id'])
443
+                ->update(['is_processed' =>2, 'updated_at' => now()]);
444
+            $this->stdOut('No valid data found :Please re-upload the file', 0);
445
+            $this->processEmptyEmail($file, $user, 'No valid data found :Please re-upload the file');
446 446
         }
447 447
     }
448 448
 
449
-    protected function getHigestRow($file,$sheet,$column){
450
-        try{
449
+    protected function getHigestRow($file, $sheet, $column) {
450
+        try {
451 451
             $reader = $this->setReader($file);
452 452
             $reader->setActiveSheetIndex($sheet);
453 453
             $higestRow = 0;
454
-            $highestRow =  $reader->getActiveSheet()->getHighestRow($column);
454
+            $highestRow = $reader->getActiveSheet()->getHighestRow($column);
455 455
             for ($row = 3; $row <= $highestRow; $row++) {
456 456
                 $rowData = $reader->getActiveSheet()->getCell($column.$row)->getValue();
457 457
                 if (empty($rowData) || $rowData == null) {
458 458
                     continue;
459
-                } else {
459
+                }else {
460 460
                     $higestRow += 1;
461 461
                 }
462 462
             }
463 463
             return $higestRow;
464
-        }catch(\Exception $e){
465
-            $this->output->writeln( $e->getMessage());
464
+        }catch (\Exception $e) {
465
+            $this->output->writeln($e->getMessage());
466 466
             $user = User::find($file['security_user_id']);
467 467
             DB::beginTransaction();
468 468
             DB::table('uploads')
469 469
                 ->where('id', $file['id'])
470
-                ->update(['is_processed' => 2,'updated_at' => now()]);
470
+                ->update(['is_processed' => 2, 'updated_at' => now()]);
471 471
             DB::commit();
472
-            $this->processEmptyEmail($file,$user, 'No valid data found');
472
+            $this->processEmptyEmail($file, $user, 'No valid data found');
473 473
             exit();
474 474
         }
475 475
     }
476 476
 
477
-    protected function stdOut($title,$rows){
478
-        $this->output->writeln(   $title. ' Process completed at . '.' '. now());
477
+    protected function stdOut($title, $rows) {
478
+        $this->output->writeln($title.' Process completed at . '.' '.now());
479 479
         $now = Carbon::now()->tz('Asia/Colombo');
480
-        $this->output->writeln('Total Processed lines: ' . $rows);
481
-        $this->output->writeln( 'Time taken to process           : '.   $now->diffInSeconds($this->startTime) .' Seconds');
480
+        $this->output->writeln('Total Processed lines: '.$rows);
481
+        $this->output->writeln('Time taken to process           : '.$now->diffInSeconds($this->startTime).' Seconds');
482 482
         $this->output->writeln('--------------------------------------------------------------------------------------------------------------------------');
483 483
     }
484 484
 
485 485
 
486 486
 
487
-    protected function removeRows($row,$count,$params){
487
+    protected function removeRows($row, $count, $params) {
488 488
         $reader = $params['reader'];
489 489
         $sheet = $reader->getActiveSheet();
490
-        if(!in_array($row,$params['rows'])){
490
+        if (!in_array($row, $params['rows'])) {
491 491
             $output = new \Symfony\Component\Console\Output\ConsoleOutput();
492
-            $this->output->writeln(    ' removing row . '.' '. $row);
492
+            $this->output->writeln(' removing row . '.' '.$row);
493 493
             $reader->getActiveSheet()->getCellCollection()->removeRow($row);
494 494
         }
495 495
     }
496 496
 
497 497
 
498
-    protected function writeErrors($e,$file,$sheet){
498
+    protected function writeErrors($e, $file, $sheet) {
499 499
         try {
500 500
             ini_set('memory_limit', '2048M');
501 501
             $baseMemory = memory_get_usage();
@@ -510,39 +510,39 @@  discard block
 block discarded – undo
510 510
             $reader = $this->setReader($file);
511 511
             $reader->setActiveSheetIndexByName($sheet);
512 512
 
513
-            $failures = gettype($failures) == 'object' ? array_map(array($this,'processErrors'),iterator_to_array($failures)) : array_map(array($this,'processErrors'),($failures));
514
-            if(count($failures) > 0){
515
-                $rows = array_map('rows',$failures);
513
+            $failures = gettype($failures) == 'object' ? array_map(array($this, 'processErrors'), iterator_to_array($failures)) : array_map(array($this, 'processErrors'), ($failures));
514
+            if (count($failures) > 0) {
515
+                $rows = array_map('rows', $failures);
516 516
                 $rows = array_unique($rows);
517
-                $rowIndex =   range(3,$this->higestRow+2);
517
+                $rowIndex = range(3, $this->higestRow + 2);
518 518
                 $params = [
519 519
                     'rows' =>$rows,
520 520
                     'reader' => $reader
521 521
                 ];
522
-                array_walk($failures , 'append_errors_to_excel',$reader);
523
-                array_walk($rowIndex , array($this,'removeRows'),$params);
524
-                $objWriter = $this->getSheetWriter($file,$reader);
522
+                array_walk($failures, 'append_errors_to_excel', $reader);
523
+                array_walk($rowIndex, array($this, 'removeRows'), $params);
524
+                $objWriter = $this->getSheetWriter($file, $reader);
525 525
                 Storage::disk('local')->makeDirectory('sis-bulk-data-files/processed');
526
-                $objWriter->save(storage_path() . '/app/sis-bulk-data-files/processed/' . $file['filename']);
526
+                $objWriter->save(storage_path().'/app/sis-bulk-data-files/processed/'.$file['filename']);
527 527
                 $now = Carbon::now()->tz('Asia/Colombo');
528
-                $this->output->writeln(  $reader->getActiveSheet()->getTitle() . ' Process completed at . '.' '. now());
528
+                $this->output->writeln($reader->getActiveSheet()->getTitle().' Process completed at . '.' '.now());
529 529
                 $this->output->writeln('memory usage for the processes : '.(memory_get_usage() - $baseMemory));
530
-                $this->output->writeln( 'Time taken to process           : '.   $now->diffInSeconds($this->startTime) .' Seconds');
530
+                $this->output->writeln('Time taken to process           : '.$now->diffInSeconds($this->startTime).' Seconds');
531 531
                 $this->output->writeln(' errors reported               : '.count($failures));
532 532
                 $this->output->writeln('--------------------------------------------------------------------------------------------------------------------------');
533 533
                 unset($objWriter);
534 534
                 unset($failures);
535 535
             }
536 536
 
537
-        }catch (Eception $e){
538
-            $this->output->writeln( $e->getMessage());
537
+        }catch (Eception $e) {
538
+            $this->output->writeln($e->getMessage());
539 539
             $user = User::find($file['security_user_id']);
540 540
             DB::beginTransaction();
541 541
             DB::table('uploads')
542 542
                 ->where('id', $file['id'])
543
-                ->update(['is_processed' => 2,'updated_at' => now()]);
543
+                ->update(['is_processed' => 2, 'updated_at' => now()]);
544 544
             DB::commit();
545
-            $this->processEmptyEmail($file,$user, 'No valid data found');
545
+            $this->processEmptyEmail($file, $user, 'No valid data found');
546 546
             exit();
547 547
         }
548 548
     }
Please login to merge, or discard this patch.
Braces   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -70,21 +70,21 @@  discard block
 block discarded – undo
70 70
                         unset($files);
71 71
                         exit();
72 72
 
73
-                    }else{
73
+                    } else{
74 74
                         $output = new \Symfony\Component\Console\Output\ConsoleOutput();
75 75
                         $this->output->writeln('No files found,Waiting for files');
76 76
                         exit();
77 77
 
78 78
                     }
79 79
 
80
-                }catch (Exception $e){
80
+                } catch (Exception $e){
81 81
                     $output = new \Symfony\Component\Console\Output\ConsoleOutput();
82 82
                     $this->output->writeln($e);
83 83
                     sleep(300);
84 84
                     $this->handle();
85 85
 
86 86
                 }
87
-            }else{
87
+            } else{
88 88
                 exit();
89 89
             }
90 90
         }
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
             $output = new \Symfony\Component\Console\Output\ConsoleOutput();
206 206
             $this->output->writeln('Processing from:' . $node);
207 207
             return true;
208
-        }else{
208
+        } else{
209 209
             exit;
210 210
             return false;
211 211
         }
@@ -321,11 +321,11 @@  discard block
 block discarded – undo
321 321
                                     ->update(['insert' => 3,'updated_at' => now()]);
322 322
                                 $this->processFailedEmail($file,$user,'Fresh Student Data Upload:Partial Success ');
323 323
                                 $this->stdOut('Insert Students',$this->higestRow);
324
-                            }else{
324
+                            } else{
325 325
                                 $this->processSuccessEmail($file,$user,'Fresh Student Data Upload:Success ');
326 326
                                 $this->stdOut('Insert Students',$this->higestRow);
327 327
                             }
328
-                        }else if(($this->getSheetName($file,'Insert Students')) && $this->higestRow > 0) {
328
+                        } else if(($this->getSheetName($file,'Insert Students')) && $this->higestRow > 0) {
329 329
                             DB::table('uploads')
330 330
                                 ->where('id', $file['id'])
331 331
                                 ->update(['is_processed' => 2]);
@@ -347,11 +347,11 @@  discard block
 block discarded – undo
347 347
                                     ->update(['update' => 3,'is_processed' => 1,'updated_at' => now()]);
348 348
                                 $this->processFailedEmail($file,$user,'Existing Student Data Update:Partial Success ');
349 349
                                 $this->stdOut('Update Students',$this->higestRow);
350
-                            }else{
350
+                            } else{
351 351
                                 $this->processSuccessEmail($file,$user, 'Existing Student Data Update:Success ');
352 352
                                 $this->stdOut('Update Students',$this->higestRow);
353 353
                             }
354
-                        }else if(($this->getSheetName($file,'Update Students')) && $this->higestRow == 0) {
354
+                        } else if(($this->getSheetName($file,'Update Students')) && $this->higestRow == 0) {
355 355
                             DB::table('uploads')
356 356
                                 ->where('id', $file['id'])
357 357
                                 ->update(['is_processed' => 2,'updated_at' => now()]);
@@ -359,7 +359,7 @@  discard block
 block discarded – undo
359 359
                         }
360 360
                         break;
361 361
                 }
362
-            }catch (\Maatwebsite\Excel\Validators\ValidationException $e) {
362
+            } catch (\Maatwebsite\Excel\Validators\ValidationException $e) {
363 363
                  $this->output->writeln( $e->getMessage());
364 364
                  if($sheet == 1){
365 365
                      self::writeErrors($e,$file,'Insert Students');
@@ -367,7 +367,7 @@  discard block
 block discarded – undo
367 367
                          ->where('id', $file['id'])
368 368
                          ->update(['insert' => 2,'updated_at' => now()]);
369 369
                     $this->processFailedEmail($file,$user,'Fresh Student Data Upload:Failed');
370
-                 }else if($sheet == 2){
370
+                 } else if($sheet == 2){
371 371
                      self::writeErrors($e,$file,'Update Students');
372 372
                      DB::table('uploads')
373 373
                          ->where('id', $file['id'])
@@ -399,7 +399,7 @@  discard block
 block discarded – undo
399 399
         $user = User::find($file['security_user_id']);
400 400
         if( $size > 0){
401 401
             return true;
402
-        }else{
402
+        } else{
403 403
             DB::table('uploads')
404 404
                 ->where('id',  $file['id'])
405 405
                 ->update(['is_processed' =>2 , 'updated_at' => now()]);
@@ -420,7 +420,7 @@  discard block
 block discarded – undo
420 420
             $reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($this->getType($file['filename']));
421 421
             $objPHPExcel =  $reader->load($excelFile);
422 422
             return $objPHPExcel;
423
-        }catch (Exception $e){
423
+        } catch (Exception $e){
424 424
             $this->output->writeln( $e->getMessage());
425 425
             $user = User::find($file['security_user_id']);
426 426
             DB::table('uploads')
@@ -435,7 +435,7 @@  discard block
 block discarded – undo
435 435
         try{;
436 436
             $objPHPExcel = $this->setReader($file);
437 437
             return $objPHPExcel->getSheetByName($sheet)  !== null;
438
-        }catch (Exception $e){
438
+        } catch (Exception $e){
439 439
             $this->output->writeln( $e->getMessage());
440 440
             $user = User::find($file['security_user_id']);
441 441
             DB::table('uploads')
@@ -461,7 +461,7 @@  discard block
 block discarded – undo
461 461
                 }
462 462
             }
463 463
             return $higestRow;
464
-        }catch(\Exception $e){
464
+        } catch(\Exception $e){
465 465
             $this->output->writeln( $e->getMessage());
466 466
             $user = User::find($file['security_user_id']);
467 467
             DB::beginTransaction();
@@ -534,7 +534,7 @@  discard block
 block discarded – undo
534 534
                 unset($failures);
535 535
             }
536 536
 
537
-        }catch (Eception $e){
537
+        } catch (Eception $e){
538 538
             $this->output->writeln( $e->getMessage());
539 539
             $user = User::find($file['security_user_id']);
540 540
             DB::beginTransaction();
Please login to merge, or discard this patch.
app/Console/Commands/CallPromotionCommand.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -41,6 +41,6 @@
 block discarded – undo
41 41
     {
42 42
         $year = $this->argument('year');
43 43
         $institution = $this->instituion_grade->getInstitutionGradeList($year);
44
-        $this->call('promote:students',['year' => $year,'institution' => $institution->code]);
44
+        $this->call('promote:students', ['year' => $year, 'institution' => $institution->code]);
45 45
     }
46 46
 }
Please login to merge, or discard this patch.
app/Console/Kernel.php 1 patch
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -25,8 +25,8 @@
 block discarded – undo
25 25
      */
26 26
     protected function schedule(Schedule $schedule)
27 27
     {
28
-         $schedule->command('import:students')
29
-                  ->cron('* * * * * ');
28
+            $schedule->command('import:students')
29
+                    ->cron('* * * * * ');
30 30
     }
31 31
 
32 32
     /**
Please login to merge, or discard this patch.
app/Exports/UsersExport.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -31,12 +31,12 @@  discard block
 block discarded – undo
31 31
     public function __construct($class) {
32 32
 
33 33
         $this->class = $class;
34
-        $this->_file_name = time() . '_' . Auth::user()->id . '_' . 'student_upload.xls';
34
+        $this->_file_name = time().'_'.Auth::user()->id.'_'.'student_upload.xls';
35 35
     }
36 36
 
37 37
     public function registerEvents(): array {
38 38
         return [
39
-        BeforeSheet::class => function(BeforeSheet $event){
39
+        BeforeSheet::class => function(BeforeSheet $event) {
40 40
 //          dd($event->crea)  
41 41
         },
42 42
             BeforeWriting::class => function(BeforeWriting $event) {
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
         $class = $this->class;
64 64
         return Security_user::select('openemis_no', 'first_name', 'gender_id', 'date_of_birth', 'address', 'birthplace_area_id')
65 65
                         ->with(['class', 'special_needs'])
66
-                        ->whereHas('class', function ($query) use ($class) {
66
+                        ->whereHas('class', function($query) use ($class) {
67 67
                             $query->where('institution_class_id', '=', $class);
68 68
                         })
69 69
                         ->get();
Please login to merge, or discard this patch.
app/Models/User_body_mass.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@
 block discarded – undo
4 4
 
5 5
 use Illuminate\Database\Eloquent\Model;
6 6
 
7
-class User_body_mass extends Base_Model  {
7
+class User_body_mass extends Base_Model {
8 8
 
9 9
     /**
10 10
      * The database table used by the model.
Please login to merge, or discard this patch.
app/Models/Institution_staff.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 
5 5
 use Illuminate\Database\Eloquent\Model;
6 6
 
7
-class Institution_staff extends Model  {
7
+class Institution_staff extends Model {
8 8
 
9 9
     /**
10 10
      * The database table used by the model.
@@ -42,12 +42,12 @@  discard block
 block discarded – undo
42 42
     protected $dates = ['start_date', 'end_date', 'modified', 'created'];
43 43
 
44 44
 
45
-    public function staff_class(){
46
-        return $this->hasMany('App\Models\Institution_class','staff_id','staff_id');
45
+    public function staff_class() {
46
+        return $this->hasMany('App\Models\Institution_class', 'staff_id', 'staff_id');
47 47
     }
48 48
 
49
-    public function institution(){
50
-        return $this->belongsTo('App\Models\Institution','institution_id');
49
+    public function institution() {
50
+        return $this->belongsTo('App\Models\Institution', 'institution_id');
51 51
     }
52 52
 
53 53
 
Please login to merge, or discard this patch.
app/Models/Nationality.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@
 block discarded – undo
4 4
 
5 5
 use Illuminate\Database\Eloquent\Model;
6 6
 
7
-class Nationality extends Model  {
7
+class Nationality extends Model {
8 8
 
9 9
     /**
10 10
      * The database table used by the model.
Please login to merge, or discard this patch.