Skip to content

Commit

Permalink
- Add method currentTargetAmountForPeriodicity() on branch model clas…
Browse files Browse the repository at this point in the history
…s to calculate specified amount from its current target

- Implement new method controller() from route facade class on web routes
  • Loading branch information
ianriizky committed Feb 15, 2022
1 parent ce471ab commit 437f86c
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 26 deletions.
16 changes: 16 additions & 0 deletions app/Models/Branch.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Models;

use App\Enum\Periodicity;
use App\Infrastructure\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;

Expand All @@ -21,4 +22,19 @@ class Branch extends Model
'name',
'address',
];

/**
* Return the specified amount from this current target based on the given periodicity.
*
* @param \App\Enum\Periodicity $periodicity
* @return int
*/
public function currentTargetAmountForPeriodicity(Periodicity $periodicity): int
{
if (is_null($this->currentTarget)) {
return 0;
}

return $this->currentTarget->amount->amountForPeriodicity($periodicity);
}
}
4 changes: 1 addition & 3 deletions app/Repositories/ReportRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ public function chartLaporanPencapaianNewCin(Carbon $startDate, Carbon $endDate,
);

$branchesTargetAmount = $branches->map(fn (Branch $branch) =>
$branch->currentTarget
? $branch->currentTarget->amount->amountForPeriodicity($periodicity)
: 0
$branch->currentTargetAmountForPeriodicity($periodicity)
);

return [
Expand Down
44 changes: 21 additions & 23 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@
Route::prefix('/master')->name('master.')->group(function () {
Route::view('/', 'master.index')->name('index')->middleware('can:view-master');

Route::prefix('/branch')->name('branch.')->group(function () {
Route::post('/datatable', [BranchController::class, 'datatable'])->name('datatable');
Route::delete('/multiple', [BranchController::class, 'destroyMultiple'])->name('destroy-multiple');
Route::prefix('/branch')->name('branch.')->controller(BranchController::class)->group(function () {
Route::post('/datatable', 'datatable')->name('datatable');
Route::delete('/multiple', 'destroyMultiple')->name('destroy-multiple');
});
Route::resource('/branch', BranchController::class);

Route::prefix('/user')->name('user.')->group(function () {
Route::post('/datatable', [UserController::class, 'datatable'])->name('datatable');
Route::delete('/multiple', [UserController::class, 'destroyMultiple'])->name('destroy-multiple');
Route::prefix('/user')->name('user.')->controller(UserController::class)->group(function () {
Route::post('/datatable', 'datatable')->name('datatable');
Route::delete('/multiple', 'destroyMultiple')->name('destroy-multiple');
});
Route::resource('/user', UserController::class);
});
Expand All @@ -68,21 +68,21 @@
Route::prefix('/monitoring')->name('monitoring.')->group(function () {
Route::view('/', 'monitoring.index')->name('index');

Route::prefix('/target')->name('target.')->group(function () {
Route::post('/datatable', [TargetController::class, 'datatable'])->name('datatable');
Route::delete('/multiple', [TargetController::class, 'destroyMultiple'])->name('destroy-multiple');
Route::prefix('/target')->name('target.')->controller(TargetController::class)->group(function () {
Route::post('/datatable', 'datatable')->name('datatable');
Route::delete('/multiple', 'destroyMultiple')->name('destroy-multiple');
});
Route::resource('/target', TargetController::class);

Route::prefix('/event')->name('event.')->group(function () {
Route::post('/datatable', [EventController::class, 'datatable'])->name('datatable');
Route::delete('/multiple', [EventController::class, 'destroyMultiple'])->name('destroy-multiple');
Route::prefix('/event')->name('event.')->controller(EventController::class)->group(function () {
Route::post('/datatable', 'datatable')->name('datatable');
Route::delete('/multiple', 'destroyMultiple')->name('destroy-multiple');
});
Route::resource('/event', EventController::class);

Route::prefix('/achievement')->name('achievement.')->group(function () {
Route::post('/datatable', [AchievementController::class, 'datatable'])->name('datatable');
Route::delete('/multiple', [AchievementController::class, 'destroyMultiple'])->name('destroy-multiple');
Route::prefix('/achievement')->name('achievement.')->controller(AchievementController::class)->group(function () {
Route::post('/datatable', 'datatable')->name('datatable');
Route::delete('/multiple', 'destroyMultiple')->name('destroy-multiple');
});
Route::resource('/achievement', AchievementController::class);
});
Expand All @@ -95,16 +95,14 @@
Route::post('/chart', 'laporanPencapaianNewCinChart')->name('chart');
});

Route::prefix('/dashboard-growth-new-cin')->name('dashboard-growth-new-cin.')->group(function () {
Route::view('/', 'report.dashboard-growth-new-cin')->name('index');
});
Route::get('/dashboard-growth-new-cin', 'dashboardGrowthNewCin')->name('dashboard-growth-new-cin.index');

Route::prefix('/dashboard-penutupan-cin')->name('dashboard-penutupan-cin.')->group(function () {
Route::view('/', 'report.dashboard-penutupan-cin')->name('index');
});
Route::get('/dashboard-penutupan-cin', 'dashboardPenutupanCin')->name('dashboard-penutupan-cin.index');
});

Route::get('/profile', [ProfileController::class, 'edit'])->name('profile.edit');
Route::put('/profile', [ProfileController::class, 'update'])->name('profile.update');
Route::prefix('/profile')->name('profile.')->controller(ProfileController::class)->group(function () {
Route::get('/', 'edit')->name('edit');
Route::put('/', 'update')->name('update');
});
});

0 comments on commit 437f86c

Please sign in to comment.