DashboardEpormasController   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 10
c 1
b 0
f 0
dl 0
loc 84
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
C epormas() 0 82 10
1
<?php
2
3
namespace Bantenprov\DashboardEpormas\Http\Controllers;
4
5
use App\Http\Controllers\Controller;
0 ignored issues
show
Bug introduced by
The type App\Http\Controllers\Controller was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Illuminate\Http\Request;
0 ignored issues
show
Bug introduced by
The type Illuminate\Http\Request was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use Illuminate\Support\Facades\DB;
8
use Illuminate\Support\Facades\Input;
9
use Bantenprov\DashboardEpormas\Models\EpormasCounter;
10
use Bantenprov\DashboardEpormas\Models\EpormasCategory;
11
use Bantenprov\DashboardEpormas\Models\EpormasCity;
12
use Validator, Image, Session, File, Response, Redirect, Exception;
13
14
class DashboardEpormasController extends Controller
15
{
16
    public function epormas()
17
    {
18
      //Pegawai Epormas
19
      $grafikepormascounter = DB::table('epormas_counter')
20
                    ->select('tahun','bulan','city_id', DB::raw('SUM(count) as count'))
21
                    ->whereNull('deleted_at')->groupBy('tahun','bulan','city_id')->orderBy('bulan')->get();
22
      $grafiktahunepormascounter = DB::table('epormas_counter')
23
                    ->select('tahun', DB::raw('SUM(count) as count'))
24
                    ->whereNull('deleted_at')->groupBy('tahun')->orderBy('tahun')->get();
25
26
      $namaBulan = array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
27
      $namaBulans = array('Januari', 'Februari', 'Maret', 'April', 'Mei', 'Juni', 'Juli', 'Agustus', 'September', 'Oktober', 'November', 'Desember');
28
      $city = EpormasCity::all();
29
      $category = EpormasCategory::all();
30
      $countcity = count($city);
31
      $countcategory = count($category);
0 ignored issues
show
Unused Code introduced by
The assignment to $countcategory is dead and can be removed.
Loading history...
32
33
      $countgrafikepormascounter = count($grafikepormascounter);
34
      $countgrafiktahunepormascounter = count($grafiktahunepormascounter);
35
      $datagrafikepormascounter = [];
0 ignored issues
show
Unused Code introduced by
The assignment to $datagrafikepormascounter is dead and can be removed.
Loading history...
36
      $datagrafiktahunepormascounter = [];
37
      $datagrafikcountepormascounter = [];
38
      $datagrafiktotalepormascounter = [];
39
      $grafikcountepormascounter = [];
40
      $grafikbulanepormascounter = [];
41
      $grafiktotalepormascounter = [];
42
      $grafikpieepormascounter = [];
43
      for($q=0; $q<$countgrafiktahunepormascounter; $q++){
44
        $tahungrafikepormascounter = $grafiktahunepormascounter[$q]->tahun;
45
        $gcountepormascounter  = (int)$grafiktahunepormascounter[$q]->count;
46
        $totaldataepormascounter = $gcountepormascounter;
47
        array_push($datagrafiktahunepormascounter,$tahungrafikepormascounter);
48
        array_push($datagrafikcountepormascounter,$gcountepormascounter);
49
        array_push($datagrafiktotalepormascounter,$totaldataepormascounter);
50
51
        for($kota=1; $kota<=$countcity; $kota++){
52
            for ($index=0; $index<12; $index++) {
53
              $grafikcountepormascounter[$q][$kota][$index] = 0;
54
              $grafikbulanepormascounter[$q][$kota][$index] = 0;
55
              $grafiktotalepormascounter[$q][$kota][$index] = 0;
56
              $grafikpieepormascounter[$q][$kota][$index] = ['value'=>0,'name'=>$namaBulan[$index]];
57
              $totaldatagrafikepormascounter[$q][$index] = 0;
58
            }
59
        }
60
        for($r=0; $r<$countgrafikepormascounter; $r++){
61
          $tahunsepormascounter = $grafikepormascounter[$r]->tahun;
62
          $bulansepormascounter = $grafikepormascounter[$r]->bulan;
63
          $city_id = $grafikepormascounter[$r]->city_id;
0 ignored issues
show
Unused Code introduced by
The assignment to $city_id is dead and can be removed.
Loading history...
64
          if($bulansepormascounter < 10){
65
            $bulanepormascounter = substr($bulansepormascounter,1);
66
          }else {
67
            $bulanepormascounter = $bulansepormascounter;
68
          }
69
          if($tahungrafikepormascounter == $tahunsepormascounter){
70
              $totaldatagrafikepormascounter[$q][$bulanepormascounter-1] += $grafikepormascounter[$r]->count;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $totaldatagrafikepormascounter does not seem to be defined for all execution paths leading up to this point.
Loading history...
71
          }
72
        }
73
        for($r=0; $r<$countgrafikepormascounter; $r++){
74
          $tahunsepormascounter = $grafikepormascounter[$r]->tahun;
75
          $bulansepormascounter = $grafikepormascounter[$r]->bulan;
76
          $city_id = $grafikepormascounter[$r]->city_id;
77
          if($bulansepormascounter < 10){
78
            $bulanepormascounter = substr($bulansepormascounter,1);
79
          }else {
80
            $bulanepormascounter = $bulansepormascounter;
81
          }
82
          if($tahungrafikepormascounter == $tahunsepormascounter){
83
              $grafikcountepormascounter[$q][$city_id][$bulanepormascounter-1] = (int)$grafikepormascounter[$r]->count;
84
              $grafikbulanepormascounter[$q][$city_id][$bulanepormascounter-1] = $grafikepormascounter[$r]->bulan;
85
              $totaldatagrafikepormascounters = $totaldatagrafikepormascounter[$q][$bulanepormascounter-1];
86
              $grafiktotalepormascounter[$q][$city_id][$bulanepormascounter-1] = $totaldatagrafikepormascounters;
87
              $grafikpieepormascounter[$q][$city_id][$bulanepormascounter-1] = ['value'=>$totaldatagrafikepormascounters,'name'=>$namaBulan[$bulanepormascounter-1]];
88
          }
89
        }
90
      }
91
      $chartgrafikcountepormascounter = ['chartdata'=>$grafikcountepormascounter];
92
      $datagrafikepormascounter = ['count'=>$grafikcountepormascounter, 'bulan'=>$grafikbulanepormascounter, 'namabulan'=>$namaBulan, 'namabulans'=>$namaBulans, 'kategori'=>$category, 'kota'=>$city, 'total'=>$grafiktotalepormascounter, 'datatahun'=>['tahun'=>$datagrafiktahunepormascounter, 'count'=>$datagrafikcountepormascounter, 'totaldata'=>$datagrafiktotalepormascounter], 'datapie'=>$grafikpieepormascounter, 'seriesdata'=>[$chartgrafikcountepormascounter]];
93
      //end Pegawai Epormas
94
95
        return Response::json(array(
96
            //Jumlah Penduduk
97
            'datachartepormascounter' => $datagrafikepormascounter
98
            //end Jumlah Penduduk
99
        ));
100
    }
101
}
102