Test Failed
Push — master ( b03845...859066 )
by Esza
02:22
created
src/Http/Controllers/EpormasCounterController.php 1 patch
Indentation   +209 added lines, -209 removed lines patch added patch discarded remove patch
@@ -14,67 +14,67 @@  discard block
 block discarded – undo
14 14
 class EpormasCounterController extends Controller
15 15
 {
16 16
 
17
-  /**
18
-   * Display a listing of the resource.
19
-   *
20
-   * @return Response
21
-   */
22
-  public function index()
23
-  {
24
-      try {
25
-          $error = false;
26
-          $statusCode = 200;
27
-          $title = 'Success';
28
-          $type = 'success';
29
-          $message = 'Success';
30
-          $result = EpormasCounter::whereNull('deleted_at')
31
-                          ->with('getCity')
32
-                          ->with('getCategory')
33
-                          ->get();
34
-      } catch (Exception $e) {
35
-          $error = true;
36
-          $statusCode = 404;
37
-          $title = 'Error';
38
-          $type = 'error';
39
-          $message = 'Error';
40
-          $result = 'Not Found';
41
-      } finally {
42
-          return Response::json(array(
17
+    /**
18
+     * Display a listing of the resource.
19
+     *
20
+     * @return Response
21
+     */
22
+    public function index()
23
+    {
24
+        try {
25
+            $error = false;
26
+            $statusCode = 200;
27
+            $title = 'Success';
28
+            $type = 'success';
29
+            $message = 'Success';
30
+            $result = EpormasCounter::whereNull('deleted_at')
31
+                            ->with('getCity')
32
+                            ->with('getCategory')
33
+                            ->get();
34
+        } catch (Exception $e) {
35
+            $error = true;
36
+            $statusCode = 404;
37
+            $title = 'Error';
38
+            $type = 'error';
39
+            $message = 'Error';
40
+            $result = 'Not Found';
41
+        } finally {
42
+            return Response::json(array(
43 43
             'error' => $error,
44 44
             'status' => $statusCode,
45 45
             'title' => $title,
46 46
             'type' => $type,
47 47
             'message' => $message,
48 48
             'result' => $result
49
-          ));
50
-      }
51
-  }
49
+            ));
50
+        }
51
+    }
52 52
 
53
-  /**
54
-   * Show the form for creating a new resource.
55
-   *
56
-   * @return Response
57
-   */
58
-  public function create()
59
-  {
60
-      try {
61
-          $error = false;
62
-          $statusCode = 200;
63
-          $title = 'Success';
64
-          $type = 'success';
65
-          $message = 'Success';
66
-          $city = EpormasCity::all();
67
-          $category = EpormasCategory::all();
68
-      } catch (Exception $e) {
69
-          $error = true;
70
-          $statusCode = 404;
71
-          $title = 'Error';
72
-          $type = 'error';
73
-          $message = 'Error';
74
-          $city = 'Not Found';
75
-          $category = 'Not Found';
76
-      } finally {
77
-          return Response::json(array(
53
+    /**
54
+     * Show the form for creating a new resource.
55
+     *
56
+     * @return Response
57
+     */
58
+    public function create()
59
+    {
60
+        try {
61
+            $error = false;
62
+            $statusCode = 200;
63
+            $title = 'Success';
64
+            $type = 'success';
65
+            $message = 'Success';
66
+            $city = EpormasCity::all();
67
+            $category = EpormasCategory::all();
68
+        } catch (Exception $e) {
69
+            $error = true;
70
+            $statusCode = 404;
71
+            $title = 'Error';
72
+            $type = 'error';
73
+            $message = 'Error';
74
+            $city = 'Not Found';
75
+            $category = 'Not Found';
76
+        } finally {
77
+            return Response::json(array(
78 78
             'error' => $error,
79 79
             'status' => $statusCode,
80 80
             'title' => $title,
@@ -82,31 +82,31 @@  discard block
 block discarded – undo
82 82
             'message' => $message,
83 83
             'city' => $city,
84 84
             'category' => $category
85
-          ));
86
-      }
87
-  }
85
+            ));
86
+        }
87
+    }
88 88
 
89
-  /**
90
-   * Store a newly created resource in storage.
91
-   *
92
-   * @return Response
93
-   */
94
-  public function store(Request $request, $version='')
95
-  {
89
+    /**
90
+     * Store a newly created resource in storage.
91
+     *
92
+     * @return Response
93
+     */
94
+    public function store(Request $request, $version='')
95
+    {
96 96
         $path = \Request::path();
97 97
         $explode = explode('/', $path);
98 98
 
99 99
         $from = 'form';
100 100
         if(in_array('api',$explode)){
101
-          $from = 'api';
101
+            $from = 'api';
102 102
         }
103 103
 
104 104
         $via = $from;
105 105
         if($version != '' && $version != 'store'){
106
-          $via .= '-'.$version;
106
+            $via .= '-'.$version;
107 107
         }
108 108
 
109
-      	$rules = [
109
+            $rules = [
110 110
             'count' => 'required|numeric',
111 111
             'city_id' => 'required|numeric',
112 112
             'category_id' => 'required|numeric',
@@ -115,44 +115,44 @@  discard block
 block discarded – undo
115 115
 
116 116
         $validator = Validator::make($request->all(), $rules);
117 117
         if ($validator->fails()) {
118
-          return Response::json(array(
119
-              'title' => 'Error',
120
-              'type'  => 'error',
121
-              'message' => $validator->errors()->all()
122
-          ));
118
+            return Response::json(array(
119
+                'title' => 'Error',
120
+                'type'  => 'error',
121
+                'message' => $validator->errors()->all()
122
+            ));
123 123
         }
124 124
 
125 125
         $format = date('Y-m-d', strtotime(str_replace(' ','-',$request->tanggal)));
126 126
         $resultcek = EpormasCounter::whereNull('deleted_at')
127
-                             ->where('tanggal','like','%'.$format.'%')
128
-                             ->where('category_id',$request->category_id)
129
-                             ->where('city_id',$request->city_id)
130
-                             ->groupBy('tahun','bulan','category_id','city_id')
131
-                             ->orderBy('bulan')
132
-                             ->count();
127
+                                ->where('tanggal','like','%'.$format.'%')
128
+                                ->where('category_id',$request->category_id)
129
+                                ->where('city_id',$request->city_id)
130
+                                ->groupBy('tahun','bulan','category_id','city_id')
131
+                                ->orderBy('bulan')
132
+                                ->count();
133 133
         if($resultcek > 0){
134
-          return Response::json(array(
135
-              'title' => 'Error',
136
-              'type'  => 'error',
137
-              'message' => 'Data has already been taken.'
138
-          ));
134
+            return Response::json(array(
135
+                'title' => 'Error',
136
+                'type'  => 'error',
137
+                'message' => 'Data has already been taken.'
138
+            ));
139 139
         }
140 140
 
141 141
         $date = explode("-",$format);
142 142
         $data = EpormasCounter::whereNull('deleted_at')
143
-                       ->where('tahun', $date[0])
144
-                       ->where('bulan', $date[1])
145
-                       ->where('category_id',$request->category_id)
146
-                       ->where('city_id',$request->city_id)
147
-                       ->groupBy('tahun','bulan','category_id','city_id')
148
-                       ->orderBy('bulan')
149
-                       ->count();
143
+                        ->where('tahun', $date[0])
144
+                        ->where('bulan', $date[1])
145
+                        ->where('category_id',$request->category_id)
146
+                        ->where('city_id',$request->city_id)
147
+                        ->groupBy('tahun','bulan','category_id','city_id')
148
+                        ->orderBy('bulan')
149
+                        ->count();
150 150
         if($data > 0){
151
-          return Response::json(array(
152
-              'title' => 'Error',
153
-              'type'  => 'error',
154
-              'message' => 'Data has already been taken.'
155
-          ));
151
+            return Response::json(array(
152
+                'title' => 'Error',
153
+                'type'  => 'error',
154
+                'message' => 'Data has already been taken.'
155
+            ));
156 156
         }
157 157
 
158 158
         $error = false;
@@ -171,23 +171,23 @@  discard block
 block discarded – undo
171 171
             'via' => $via
172 172
         ]);
173 173
         return Response::json(array(
174
-          'error' => $error,
175
-          'status' => $statusCode,
176
-          'title' => $title,
177
-          'type' => $type,
178
-          'message' => $message,
179
-          'result' => $result
174
+            'error' => $error,
175
+            'status' => $statusCode,
176
+            'title' => $title,
177
+            'type' => $type,
178
+            'message' => $message,
179
+            'result' => $result
180 180
         ));
181
-  }
181
+    }
182 182
 
183
-  /**
184
-   * Display the specified resource.
185
-   *
186
-   * @param  int  $id
187
-   * @return Response
188
-   */
189
-  public function show($version='', $id)
190
-  {
183
+    /**
184
+     * Display the specified resource.
185
+     *
186
+     * @param  int  $id
187
+     * @return Response
188
+     */
189
+    public function show($version='', $id)
190
+    {
191 191
         try {
192 192
             $error = false;
193 193
             $statusCode = 200;
@@ -207,24 +207,24 @@  discard block
 block discarded – undo
207 207
             $result = 'Not Found';
208 208
         } finally {
209 209
             return Response::json(array(
210
-              'error' => $error,
211
-              'status' => $statusCode,
212
-              'title' => $title,
213
-              'type' => $type,
214
-              'message' => $message,
215
-              'result' => $result
210
+                'error' => $error,
211
+                'status' => $statusCode,
212
+                'title' => $title,
213
+                'type' => $type,
214
+                'message' => $message,
215
+                'result' => $result
216 216
             ));
217 217
         }
218
-  }
218
+    }
219 219
 
220
-  /**
221
-   * Show the form for editing the specified resource.
222
-   *
223
-   * @param  int  $id
224
-   * @return Response
225
-   */
226
-  public function edit($id)
227
-  {
220
+    /**
221
+     * Show the form for editing the specified resource.
222
+     *
223
+     * @param  int  $id
224
+     * @return Response
225
+     */
226
+    public function edit($id)
227
+    {
228 228
         try {
229 229
             $error = false;
230 230
             $statusCode = 200;
@@ -250,27 +250,27 @@  discard block
 block discarded – undo
250 250
             $format = 'Not Found';
251 251
         } finally {
252 252
             return Response::json(array(
253
-              'error' => $error,
254
-              'status' => $statusCode,
255
-              'title' => $title,
256
-              'type' => $type,
257
-              'message' => $message,
258
-              'city' => $city,
259
-              'category' => $category,
260
-              'result' => $result,
261
-              'tanggal' => $format
253
+                'error' => $error,
254
+                'status' => $statusCode,
255
+                'title' => $title,
256
+                'type' => $type,
257
+                'message' => $message,
258
+                'city' => $city,
259
+                'category' => $category,
260
+                'result' => $result,
261
+                'tanggal' => $format
262 262
             ));
263 263
         }
264
-  }
264
+    }
265 265
 
266
-  /**
267
-   * Update the specified resource in storage.
268
-   *
269
-   * @param  int  $id
270
-   * @return Response
271
-   */
272
-  public function update(Request $request, $version='', $id)
273
-  {
266
+    /**
267
+     * Update the specified resource in storage.
268
+     *
269
+     * @param  int  $id
270
+     * @return Response
271
+     */
272
+    public function update(Request $request, $version='', $id)
273
+    {
274 274
         $result = EpormasCounter::whereNull('deleted_at')
275 275
                         ->with('getCity')
276 276
                         ->with('getCategory')
@@ -285,28 +285,28 @@  discard block
 block discarded – undo
285 285
 
286 286
         $validator = Validator::make($request->all(), $rules);
287 287
         if ($validator->fails()) {
288
-          return Response::json(array(
289
-              'title' => 'Error',
290
-              'type'  => 'error',
291
-              'message' => $validator->errors()->all()
292
-          ));
288
+            return Response::json(array(
289
+                'title' => 'Error',
290
+                'type'  => 'error',
291
+                'message' => $validator->errors()->all()
292
+            ));
293 293
         }
294 294
 
295 295
         $format = date('Y-m-d', strtotime(str_replace(' ','-',$request->tanggal)));
296 296
         if($result->city_id != $request->city_id || $result->category_id != $request->category_id){
297 297
             $resultcek = EpormasCounter::whereNull('deleted_at')
298
-                                 ->where('tanggal','like','%'.$format.'%')
299
-            		                 ->where('category_id',$request->category_id)
300
-            		                 ->where('city_id',$request->city_id)
301
-                                 ->groupBy('tahun','bulan','category_id','city_id')
302
-                                 ->orderBy('bulan')
303
-                                 ->count();
298
+                                    ->where('tanggal','like','%'.$format.'%')
299
+                                        ->where('category_id',$request->category_id)
300
+                                        ->where('city_id',$request->city_id)
301
+                                    ->groupBy('tahun','bulan','category_id','city_id')
302
+                                    ->orderBy('bulan')
303
+                                    ->count();
304 304
             if($resultcek > 0){
305
-              return Response::json(array(
306
-                  'title' => 'Error',
307
-                  'type'  => 'error',
308
-                  'message' => 'Data has already been taken.'
309
-              ));
305
+                return Response::json(array(
306
+                    'title' => 'Error',
307
+                    'type'  => 'error',
308
+                    'message' => 'Data has already been taken.'
309
+                ));
310 310
             }
311 311
         }
312 312
 
@@ -314,34 +314,34 @@  discard block
 block discarded – undo
314 314
         $dates = date('Y-m-d', strtotime($result->tanggal));
315 315
         if($dates != $format){
316 316
             $resultcek = EpormasCounter::whereNull('deleted_at')
317
-            		                 ->where('category_id',$request->category_id)
318
-            		                 ->where('city_id',$request->city_id)
319
-                                 ->where('tanggal','like','%'.$format.'%')
320
-                                 ->groupBy('tahun','bulan','category_id','city_id')
321
-                                 ->orderBy('bulan')
322
-                                 ->count();
317
+                                        ->where('category_id',$request->category_id)
318
+                                        ->where('city_id',$request->city_id)
319
+                                    ->where('tanggal','like','%'.$format.'%')
320
+                                    ->groupBy('tahun','bulan','category_id','city_id')
321
+                                    ->orderBy('bulan')
322
+                                    ->count();
323 323
             if($resultcek > 0){
324
-              return Response::json(array(
325
-                  'title' => 'Error',
326
-                  'type'  => 'error',
327
-                  'message' => 'Data has already been taken.'
328
-              ));
324
+                return Response::json(array(
325
+                    'title' => 'Error',
326
+                    'type'  => 'error',
327
+                    'message' => 'Data has already been taken.'
328
+                ));
329 329
             }
330 330
 
331 331
             $data = EpormasCounter::whereNull('deleted_at')
332
-                           ->where('tahun', $date[0])
333
-                           ->where('bulan', $date[1])
334
-            		           ->where('category_id',$request->category_id)
335
-            		           ->where('city_id',$request->city_id)
336
-                           ->groupBy('tahun','bulan','category_id','city_id')
337
-                           ->orderBy('bulan')
338
-                           ->count();
332
+                            ->where('tahun', $date[0])
333
+                            ->where('bulan', $date[1])
334
+                                ->where('category_id',$request->category_id)
335
+                                ->where('city_id',$request->city_id)
336
+                            ->groupBy('tahun','bulan','category_id','city_id')
337
+                            ->orderBy('bulan')
338
+                            ->count();
339 339
             if($data > 0){
340
-              return Response::json(array(
341
-                  'title' => 'Error',
342
-                  'type'  => 'error',
343
-                  'message' => 'Data has already been taken.'
344
-              ));
340
+                return Response::json(array(
341
+                    'title' => 'Error',
342
+                    'type'  => 'error',
343
+                    'message' => 'Data has already been taken.'
344
+                ));
345 345
             }
346 346
         }
347 347
 
@@ -351,13 +351,13 @@  discard block
 block discarded – undo
351 351
         $from = $result->via;
352 352
         $user_id = $result->user_id;
353 353
         if(in_array('api',$explode)){
354
-          $from = 'api';
355
-          $user_id = $request->user_id;
354
+            $from = 'api';
355
+            $user_id = $request->user_id;
356 356
         }
357 357
 
358 358
         $via = $from;
359 359
         if($version != '' && $version != 'update'){
360
-          $via .= '-'.$version;
360
+            $via .= '-'.$version;
361 361
         }
362 362
 
363 363
         $error = false;
@@ -376,37 +376,37 @@  discard block
 block discarded – undo
376 376
             'via' => $via
377 377
         ]);
378 378
         return Response::json(array(
379
-          'error' => $error,
380
-          'status' => $statusCode,
381
-          'title' => $title,
382
-          'type' => $type,
383
-          'message' => $message,
384
-          'result' => $result
379
+            'error' => $error,
380
+            'status' => $statusCode,
381
+            'title' => $title,
382
+            'type' => $type,
383
+            'message' => $message,
384
+            'result' => $result
385 385
         ));
386
-  }
386
+    }
387 387
 
388
-  /**
389
-   * Remove the specified resource from storage.
390
-   *
391
-   * @param  int  $id
392
-   * @return Response
393
-   */
394
-  public function destroy($id)
395
-  {
396
-      EpormasCounter::find($id)->delete();
397
-      $error = false;
398
-      $statusCode = 200;
399
-      $title = 'Success';
400
-      $type = 'success';
401
-      $message = 'Data deleted successfully';
402
-      return Response::json(array(
388
+    /**
389
+     * Remove the specified resource from storage.
390
+     *
391
+     * @param  int  $id
392
+     * @return Response
393
+     */
394
+    public function destroy($id)
395
+    {
396
+        EpormasCounter::find($id)->delete();
397
+        $error = false;
398
+        $statusCode = 200;
399
+        $title = 'Success';
400
+        $type = 'success';
401
+        $message = 'Data deleted successfully';
402
+        return Response::json(array(
403 403
         'error' => $error,
404 404
         'status' => $statusCode,
405 405
         'title' => $title,
406 406
         'type' => $type,
407 407
         'message' => $message
408
-      ));
409
-  }
408
+        ));
409
+    }
410 410
 
411 411
 }
412 412
 
Please login to merge, or discard this patch.