Skip to content

Commit 8216fe0

Browse files
committed
update metric and lenses
1 parent d294b99 commit 8216fe0

File tree

5 files changed

+201
-91
lines changed

5 files changed

+201
-91
lines changed

app/Nova/Filters/BulanKontrak.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ public function options(NovaRequest $request)
3838
}
3939

4040
/**
41-
* The default value of the filter.
42-
*
43-
* @var string
44-
*/
45-
public function default()
46-
{
47-
return Date('m');
48-
}
41+
* The default value of the filter.
42+
*
43+
* @var string
44+
*/
45+
public function default()
46+
{
47+
return Date('m');
48+
}
4949
}

app/Nova/Lenses/RekapHonorMitra.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use App\Nova\Filters\BulanKontrak;
77
use App\Nova\Filters\JenisKontrak;
88
use App\Nova\Metrics\JumlahKegiatan;
9+
use App\Nova\Metrics\JumlahMitra;
910
use Laravel\Nova\Fields\Boolean;
1011
use Laravel\Nova\Fields\Currency;
1112
use Laravel\Nova\Fields\Number;
@@ -46,7 +47,8 @@ public static function query(LensRequest $request, $query)
4647
->join('honor_kegiatans', 'honor_kegiatans.id', '=', 'daftar_honor_mitras.honor_kegiatan_id')
4748
->join('jenis_kontraks', 'jenis_kontraks.id', '=', 'honor_kegiatans.jenis_kontrak_id')
4849
->join('mitras', 'mitras.id', '=', 'daftar_honor_mitras.mitra_id')
49-
->groupBy(['bulan','mitra_id', 'nama', 'nik', 'sbml', 'jenis_kontrak_id'])
50+
->groupBy(['bulan', 'mitra_id', 'nama', 'nik', 'sbml', 'jenis_kontrak_id'])
51+
->orderBy('bulan', 'desc')
5052
->orderBy('nilai_kontrak', 'desc'));
5153
}
5254

@@ -59,11 +61,11 @@ public function fields(NovaRequest $request)
5961
{
6062
return [
6163
Text::make('Jenis Kontrak', 'jenis_kontrak_id')
62-
->displayUsing(fn ($value) => Helper::getPropertyFromCollection(Helper::getJenisKontrakById($value),'jenis'))
64+
->displayUsing(fn ($value) => Helper::getPropertyFromCollection(Helper::getJenisKontrakById($value), 'jenis'))
6365
->readOnly(),
6466
Text::make('Bulan', 'bulan')
6567
->displayUsing(fn ($value) => Helper::$bulan[$value])
66-
->readOnly(),
68+
->readOnly(),
6769
Text::make('Nama', 'nama')
6870
->readOnly(),
6971
Number::make('Jumlah Kegiatan', 'jumlah_kegiatan')
@@ -88,13 +90,9 @@ public function fields(NovaRequest $request)
8890
public function cards(NovaRequest $request)
8991
{
9092
return [
91-
//TODO Jumlah kegiatan pakai value
92-
JumlahKegiatan::make(),
93-
//TODO Jumlah mitra pakai trends
94-
JumlahKegiatan::make(),
95-
// TODO honor per jenis kontrak pakai partition
96-
JumlahKegiatan::make(),
97-
];
93+
JumlahKegiatan::make()->width('1/2')->help('Jumlah kegiatan yang tertuang dalam kontrak bulanan mitra'),
94+
JumlahMitra::make()->width('1/2')->help('Jumlah mitra yang berkontrak tiap bulan di semua kegiatan'),
95+
];
9896
}
9997

10098
/**

app/Nova/Metrics/JumlahKegiatan.php

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,23 @@
22

33
namespace App\Nova\Metrics;
44

5+
use App\Helpers\Helper;
6+
use Illuminate\Support\Facades\DB;
57
use Laravel\Nova\Http\Requests\NovaRequest;
68
use Laravel\Nova\Metrics\Value;
79
use Laravel\Nova\Nova;
810

911
class JumlahKegiatan extends Value
1012
{
13+
/**
14+
* Get the displayable name of the metric
15+
*
16+
* @return string
17+
*/
18+
public function name()
19+
{
20+
return 'Jumlah Kegiatan Bulan '.Helper::$bulan[date('m')];
21+
}
1122
/**
1223
* Calculate the value of the metric.
1324
*
@@ -16,7 +27,26 @@ class JumlahKegiatan extends Value
1627
*/
1728
public function calculate(NovaRequest $request)
1829
{
19-
return $this->result(100)->previous(50)->suffix('Kegiatan');
30+
$bulan_ini = DB::table('daftar_honor_mitras')
31+
->select('honor_kegiatans.id')
32+
->join('honor_kegiatans', 'honor_kegiatans.id', '=', 'daftar_honor_mitras.honor_kegiatan_id')
33+
->where('jenis_honor', 'Kontrak Mitra Bulanan')
34+
->where('tahun', session('year'))
35+
->where('bulan', date('m'))
36+
->distinct('honor_kegiatans.id')
37+
->count();
38+
$bulan_lalu = DB::table('daftar_honor_mitras')
39+
->select('honor_kegiatans.id')
40+
->join('honor_kegiatans', 'honor_kegiatans.id', '=', 'daftar_honor_mitras.honor_kegiatan_id')
41+
->where('jenis_honor', 'Kontrak Mitra Bulanan')
42+
->where('tahun', session('year'))
43+
->where('bulan', date('m')-1)
44+
->distinct('honor_kegiatans.id')
45+
->count();
46+
return $this->result($bulan_ini)
47+
->previous($bulan_lalu)
48+
->suffix('Kegiatan')
49+
->withoutSuffixInflection();
2050

2151
}
2252

app/Nova/Metrics/JumlahMitra.php

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
3+
namespace App\Nova\Metrics;
4+
5+
use App\Helpers\Helper;
6+
use Illuminate\Support\Facades\DB;
7+
use Laravel\Nova\Http\Requests\NovaRequest;
8+
use Laravel\Nova\Metrics\Trend;
9+
use Laravel\Nova\Metrics\TrendResult;
10+
11+
class JumlahMitra extends Trend
12+
{
13+
/**
14+
* Get the displayable name of the metric
15+
*
16+
* @return string
17+
*/
18+
public function name()
19+
{
20+
return 'Jumlah Mitra Per Bulan '.session('year');
21+
}
22+
23+
/**
24+
* Calculate the value of the metric.
25+
*
26+
* @return mixed
27+
*/
28+
public function calculate(NovaRequest $request)
29+
{
30+
$arr = [];
31+
foreach (Helper::$bulan as $key => $value) {
32+
$arr[$value] = DB::table('daftar_honor_mitras')
33+
->select('mitra_id')
34+
->join(
35+
'honor_kegiatans',
36+
'honor_kegiatans.id',
37+
'=',
38+
'daftar_honor_mitras.honor_kegiatan_id'
39+
)
40+
->where('jenis_honor', 'Kontrak Mitra Bulanan')
41+
->where('tahun', session('year'))
42+
->where('bulan', $key)
43+
->distinct('mitra_id')
44+
->count();
45+
}
46+
47+
return (new TrendResult)->trend($arr)
48+
->result($arr[Helper::$bulan[date('m')]])
49+
->suffix('Mitra')
50+
->withoutSuffixInflection();
51+
}
52+
53+
/**
54+
* Get the ranges available for the metric.
55+
*
56+
* @return array
57+
*/
58+
public function ranges()
59+
{
60+
return [
61+
];
62+
}
63+
64+
/**
65+
* Determine the amount of time the results of the metric should be cached.
66+
*
67+
* @return \DateTimeInterface|\DateInterval|float|int|null
68+
*/
69+
public function cacheFor()
70+
{
71+
// return now()->addMinutes(5);
72+
}
73+
74+
/**
75+
* Get the URI key for the metric.
76+
*
77+
* @return string
78+
*/
79+
public function uriKey()
80+
{
81+
return 'jumlah-mitra';
82+
}
83+
}

0 commit comments

Comments
 (0)