Passed
Push — master ( c7379f...97417c )
by Esza
02:29
created
src/Http/Controllers/EpormasCounterController.php 1 patch
Indentation   +215 added lines, -215 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
-          $category = EpormasCategory::all();
62
-          $city = EpormasCity::all();
63
-          $error = false;
64
-          $statusCode = 200;
65
-          $title = 'Success';
66
-          $type = 'success';
67
-          $message = 'Success';
68
-      } catch (Exception $e) {
69
-          $category = 'Not Found';
70
-          $city = 'Not Found';
71
-          $error = true;
72
-          $statusCode = 404;
73
-          $title = 'Error';
74
-          $type = 'error';
75
-          $message = 'Error';
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
+            $category = EpormasCategory::all();
62
+            $city = EpormasCity::all();
63
+            $error = false;
64
+            $statusCode = 200;
65
+            $title = 'Success';
66
+            $type = 'success';
67
+            $message = 'Success';
68
+        } catch (Exception $e) {
69
+            $category = 'Not Found';
70
+            $city = 'Not Found';
71
+            $error = true;
72
+            $statusCode = 404;
73
+            $title = 'Error';
74
+            $type = 'error';
75
+            $message = 'Error';
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
             'category' => $category,
83 83
             'city' => $city,
84 84
             'message' => $message
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,49 +115,49 @@  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
         if($request->tanggal){
126
-          $formats = date('Y-m-d', strtotime(str_replace(' ','-',$request->tanggal)));
126
+            $formats = date('Y-m-d', strtotime(str_replace(' ','-',$request->tanggal)));
127 127
         }else {
128
-          $formats = '';
128
+            $formats = '';
129 129
         }
130 130
         $format = $formats;
131 131
         $resultcek = EpormasCounter::whereNull('deleted_at')
132
-                             ->where('tanggal','like','%'.$format.'%')
133
-                             ->where('category_id',$request->category_id)
134
-                             ->where('city_id',$request->city_id)
135
-                             ->groupBy('tahun','bulan','category_id','city_id')
136
-                             ->orderBy('bulan')
137
-                             ->count();
132
+                                ->where('tanggal','like','%'.$format.'%')
133
+                                ->where('category_id',$request->category_id)
134
+                                ->where('city_id',$request->city_id)
135
+                                ->groupBy('tahun','bulan','category_id','city_id')
136
+                                ->orderBy('bulan')
137
+                                ->count();
138 138
         if($resultcek > 0){
139
-          return Response::json(array(
140
-              'title' => 'Error',
141
-              'type'  => 'error',
142
-              'message' => 'Data has already been taken.'
143
-          ));
139
+            return Response::json(array(
140
+                'title' => 'Error',
141
+                'type'  => 'error',
142
+                'message' => 'Data has already been taken.'
143
+            ));
144 144
         }
145 145
 
146 146
         $date = explode("-",$format);
147 147
         $data = EpormasCounter::whereNull('deleted_at')
148
-                       ->where('tahun', $date[0])
149
-                       ->where('bulan', $date[1])
150
-                       ->where('category_id',$request->category_id)
151
-                       ->where('city_id',$request->city_id)
152
-                       ->groupBy('tahun','bulan','category_id','city_id')
153
-                       ->orderBy('bulan')
154
-                       ->count();
148
+                        ->where('tahun', $date[0])
149
+                        ->where('bulan', $date[1])
150
+                        ->where('category_id',$request->category_id)
151
+                        ->where('city_id',$request->city_id)
152
+                        ->groupBy('tahun','bulan','category_id','city_id')
153
+                        ->orderBy('bulan')
154
+                        ->count();
155 155
         if($data > 0){
156
-          return Response::json(array(
157
-              'title' => 'Error',
158
-              'type'  => 'error',
159
-              'message' => 'Data has already been taken.'
160
-          ));
156
+            return Response::json(array(
157
+                'title' => 'Error',
158
+                'type'  => 'error',
159
+                'message' => 'Data has already been taken.'
160
+            ));
161 161
         }
162 162
 
163 163
         $error = false;
@@ -176,23 +176,23 @@  discard block
 block discarded – undo
176 176
             'via' => $via
177 177
         ]);
178 178
         return Response::json(array(
179
-          'error' => $error,
180
-          'status' => $statusCode,
181
-          'title' => $title,
182
-          'type' => $type,
183
-          'message' => $message,
184
-          'result' => $result
179
+            'error' => $error,
180
+            'status' => $statusCode,
181
+            'title' => $title,
182
+            'type' => $type,
183
+            'message' => $message,
184
+            'result' => $result
185 185
         ));
186
-  }
186
+    }
187 187
 
188
-  /**
189
-   * Display the specified resource.
190
-   *
191
-   * @param  int  $id
192
-   * @return Response
193
-   */
194
-  public function show($version='', $id)
195
-  {
188
+    /**
189
+     * Display the specified resource.
190
+     *
191
+     * @param  int  $id
192
+     * @return Response
193
+     */
194
+    public function show($version='', $id)
195
+    {
196 196
         try {
197 197
             $error = false;
198 198
             $statusCode = 200;
@@ -212,24 +212,24 @@  discard block
 block discarded – undo
212 212
             $result = 'Not Found';
213 213
         } finally {
214 214
             return Response::json(array(
215
-              'error' => $error,
216
-              'status' => $statusCode,
217
-              'title' => $title,
218
-              'type' => $type,
219
-              'message' => $message,
220
-              'result' => $result
215
+                'error' => $error,
216
+                'status' => $statusCode,
217
+                'title' => $title,
218
+                'type' => $type,
219
+                'message' => $message,
220
+                'result' => $result
221 221
             ));
222 222
         }
223
-  }
223
+    }
224 224
 
225
-  /**
226
-   * Show the form for editing the specified resource.
227
-   *
228
-   * @param  int  $id
229
-   * @return Response
230
-   */
231
-  public function edit($id)
232
-  {
225
+    /**
226
+     * Show the form for editing the specified resource.
227
+     *
228
+     * @param  int  $id
229
+     * @return Response
230
+     */
231
+    public function edit($id)
232
+    {
233 233
         try {
234 234
             $category = EpormasCategory::all();
235 235
             $city = EpormasCity::all();
@@ -243,9 +243,9 @@  discard block
 block discarded – undo
243 243
                             ->with('getCategory')
244 244
                             ->find($id);
245 245
             if($result->tanggal){
246
-              $formats = date('Y-m-d', strtotime($result->tanggal));
246
+                $formats = date('Y-m-d', strtotime($result->tanggal));
247 247
             }else {
248
-              $formats = 'Not Found';
248
+                $formats = 'Not Found';
249 249
             }
250 250
             $format = $formats;
251 251
         } catch (Exception $e) {
@@ -260,27 +260,27 @@  discard block
 block discarded – undo
260 260
             $format = 'Not Found';
261 261
         } finally {
262 262
             return Response::json(array(
263
-              'error' => $error,
264
-              'status' => $statusCode,
265
-              'title' => $title,
266
-              'type' => $type,
267
-              'message' => $message,
268
-              'tanggal' => $format,
269
-              'city' => $city,
270
-              'category' => $category,
271
-              'result' => $result
263
+                'error' => $error,
264
+                'status' => $statusCode,
265
+                'title' => $title,
266
+                'type' => $type,
267
+                'message' => $message,
268
+                'tanggal' => $format,
269
+                'city' => $city,
270
+                'category' => $category,
271
+                'result' => $result
272 272
             ));
273 273
         }
274
-  }
274
+    }
275 275
 
276
-  /**
277
-   * Update the specified resource in storage.
278
-   *
279
-   * @param  int  $id
280
-   * @return Response
281
-   */
282
-  public function update(Request $request, $version='', $id)
283
-  {
276
+    /**
277
+     * Update the specified resource in storage.
278
+     *
279
+     * @param  int  $id
280
+     * @return Response
281
+     */
282
+    public function update(Request $request, $version='', $id)
283
+    {
284 284
         $result = EpormasCounter::whereNull('deleted_at')
285 285
                         ->with('getCity')
286 286
                         ->with('getCategory')
@@ -295,33 +295,33 @@  discard block
 block discarded – undo
295 295
 
296 296
         $validator = Validator::make($request->all(), $rules);
297 297
         if ($validator->fails()) {
298
-          return Response::json(array(
299
-              'title' => 'Error',
300
-              'type'  => 'error',
301
-              'message' => $validator->errors()->all()
302
-          ));
298
+            return Response::json(array(
299
+                'title' => 'Error',
300
+                'type'  => 'error',
301
+                'message' => $validator->errors()->all()
302
+            ));
303 303
         }
304 304
 
305 305
         if($request->tanggal){
306
-          $formats = date('Y-m-d', strtotime(str_replace(' ','-',$request->tanggal)));
306
+            $formats = date('Y-m-d', strtotime(str_replace(' ','-',$request->tanggal)));
307 307
         }else {
308
-          $formats = '';
308
+            $formats = '';
309 309
         }
310 310
         $format = $formats;
311 311
         if($result->city_id != $request->city_id || $result->category_id != $request->category_id){
312 312
             $resultcek = EpormasCounter::whereNull('deleted_at')
313
-                                 ->where('tanggal','like','%'.$format.'%')
314
-            		                 ->where('category_id',$request->category_id)
315
-            		                 ->where('city_id',$request->city_id)
316
-                                 ->groupBy('tahun','bulan','category_id','city_id')
317
-                                 ->orderBy('bulan')
318
-                                 ->count();
313
+                                    ->where('tanggal','like','%'.$format.'%')
314
+                                        ->where('category_id',$request->category_id)
315
+                                        ->where('city_id',$request->city_id)
316
+                                    ->groupBy('tahun','bulan','category_id','city_id')
317
+                                    ->orderBy('bulan')
318
+                                    ->count();
319 319
             if($resultcek > 0){
320
-              return Response::json(array(
321
-                  'title' => 'Error',
322
-                  'type'  => 'error',
323
-                  'message' => 'Data has already been taken.'
324
-              ));
320
+                return Response::json(array(
321
+                    'title' => 'Error',
322
+                    'type'  => 'error',
323
+                    'message' => 'Data has already been taken.'
324
+                ));
325 325
             }
326 326
         }
327 327
 
@@ -329,34 +329,34 @@  discard block
 block discarded – undo
329 329
         $dates = date('Y-m-d', strtotime($result->tanggal));
330 330
         if($dates != $format){
331 331
             $resultcek = EpormasCounter::whereNull('deleted_at')
332
-            		                 ->where('category_id',$request->category_id)
333
-            		                 ->where('city_id',$request->city_id)
334
-                                 ->where('tanggal','like','%'.$format.'%')
335
-                                 ->groupBy('tahun','bulan','category_id','city_id')
336
-                                 ->orderBy('bulan')
337
-                                 ->count();
332
+                                        ->where('category_id',$request->category_id)
333
+                                        ->where('city_id',$request->city_id)
334
+                                    ->where('tanggal','like','%'.$format.'%')
335
+                                    ->groupBy('tahun','bulan','category_id','city_id')
336
+                                    ->orderBy('bulan')
337
+                                    ->count();
338 338
             if($resultcek > 0){
339
-              return Response::json(array(
340
-                  'title' => 'Error',
341
-                  'type'  => 'error',
342
-                  'message' => 'Data has already been taken.'
343
-              ));
339
+                return Response::json(array(
340
+                    'title' => 'Error',
341
+                    'type'  => 'error',
342
+                    'message' => 'Data has already been taken.'
343
+                ));
344 344
             }
345 345
 
346 346
             $data = EpormasCounter::whereNull('deleted_at')
347
-                           ->where('tahun', $date[0])
348
-                           ->where('bulan', $date[1])
349
-            		           ->where('category_id',$request->category_id)
350
-            		           ->where('city_id',$request->city_id)
351
-                           ->groupBy('tahun','bulan','category_id','city_id')
352
-                           ->orderBy('bulan')
353
-                           ->count();
347
+                            ->where('tahun', $date[0])
348
+                            ->where('bulan', $date[1])
349
+                                ->where('category_id',$request->category_id)
350
+                                ->where('city_id',$request->city_id)
351
+                            ->groupBy('tahun','bulan','category_id','city_id')
352
+                            ->orderBy('bulan')
353
+                            ->count();
354 354
             if($data > 0){
355
-              return Response::json(array(
356
-                  'title' => 'Error',
357
-                  'type'  => 'error',
358
-                  'message' => 'Data has already been taken.'
359
-              ));
355
+                return Response::json(array(
356
+                    'title' => 'Error',
357
+                    'type'  => 'error',
358
+                    'message' => 'Data has already been taken.'
359
+                ));
360 360
             }
361 361
         }
362 362
 
@@ -366,13 +366,13 @@  discard block
 block discarded – undo
366 366
         $from = $result->via;
367 367
         $user_id = $result->user_id;
368 368
         if(in_array('api',$explode)){
369
-          $from = 'api';
370
-          $user_id = $request->user_id;
369
+            $from = 'api';
370
+            $user_id = $request->user_id;
371 371
         }
372 372
 
373 373
         $via = $from;
374 374
         if($version != '' && $version != 'update'){
375
-          $via .= '-'.$version;
375
+            $via .= '-'.$version;
376 376
         }
377 377
 
378 378
         $error = false;
@@ -391,36 +391,36 @@  discard block
 block discarded – undo
391 391
             'via' => $via
392 392
         ]);
393 393
         return Response::json(array(
394
-          'error' => $error,
395
-          'status' => $statusCode,
396
-          'title' => $title,
397
-          'type' => $type,
398
-          'message' => $message,
399
-          'result' => $result
394
+            'error' => $error,
395
+            'status' => $statusCode,
396
+            'title' => $title,
397
+            'type' => $type,
398
+            'message' => $message,
399
+            'result' => $result
400 400
         ));
401
-  }
401
+    }
402 402
 
403
-  /**
404
-   * Remove the specified resource from storage.
405
-   *
406
-   * @param  int  $id
407
-   * @return Response
408
-   */
409
-  public function destroy($id)
410
-  {
411
-      EpormasCounter::find($id)->delete();
412
-      $error = false;
413
-      $statusCode = 200;
414
-      $title = 'Success';
415
-      $type = 'success';
416
-      $message = 'Data deleted successfully';
417
-      return Response::json(array(
403
+    /**
404
+     * Remove the specified resource from storage.
405
+     *
406
+     * @param  int  $id
407
+     * @return Response
408
+     */
409
+    public function destroy($id)
410
+    {
411
+        EpormasCounter::find($id)->delete();
412
+        $error = false;
413
+        $statusCode = 200;
414
+        $title = 'Success';
415
+        $type = 'success';
416
+        $message = 'Data deleted successfully';
417
+        return Response::json(array(
418 418
         'error' => $error,
419 419
         'status' => $statusCode,
420 420
         'title' => $title,
421 421
         'type' => $type,
422 422
         'message' => $message
423
-      ));
424
-  }
423
+        ));
424
+    }
425 425
 
426 426
 }
Please login to merge, or discard this patch.