Skip to content

Commit

Permalink
feat: ✨ added statistics on commodity index page
Browse files Browse the repository at this point in the history
  • Loading branch information
mrizkimaulidan committed Dec 25, 2024
1 parent 1dc569f commit 4658983
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 4 deletions.
25 changes: 21 additions & 4 deletions app/Http/Controllers/CommodityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
use App\Http\Requests\StoreCommodityRequest;
use App\Http\Requests\UpdateCommodityRequest;
use App\Imports\CommoditiesImport;
use App\Repositories\CommodityRepository;
use Barryvdh\DomPDF\Facade\Pdf;
use Maatwebsite\Excel\Facades\Excel;

class CommodityController extends Controller
{
public function __construct()
{
public function __construct(
private CommodityRepository $commodityRepository,
) {
$this->authorizeResource(Commodity::class, 'commodity');
}

Expand Down Expand Up @@ -57,6 +59,20 @@ public function index()
$commodity_acquisitions = CommodityAcquisition::orderBy('name', 'ASC')->get();
$commodity_locations = CommodityLocation::orderBy('name', 'ASC')->get();

$commodity_condition_count = $this->commodityRepository->countCommodityCondition()->map(function ($commodity) {
return collect([
'condition_name' => $commodity->getConditionName(),
'count' => $commodity->count,
]);
});

$commodity_counts = [
'commodity_in_total' => $commodity_condition_count->sum('count') ?? 0,
'commodity_in_good_condition' => $commodity_condition_count->firstWhere('condition_name', 'Baik')['count'] ?? 0,
'commodity_in_not_good_condition' => $commodity_condition_count->firstWhere('condition_name', 'Kurang Baik')['count'] ?? 0,
'commodity_in_heavily_damage_condition' => $commodity_condition_count->firstWhere('condition_name', 'Rusak Berat')['count'] ?? 0,
];

return view(
'commodities.index',
compact(
Expand All @@ -65,7 +81,8 @@ public function index()
'commodity_locations',
'year_of_purchases',
'commodity_brands',
'commodity_materials'
'commodity_materials',
'commodity_counts'
)
);
}
Expand Down Expand Up @@ -135,7 +152,7 @@ public function export()
{
$this->authorize('export barang');

return Excel::download(new CommoditiesExport, 'daftar-barang-'.date('d-m-Y').'.xlsx');
return Excel::download(new CommoditiesExport, 'daftar-barang-' . date('d-m-Y') . '.xlsx');
}

/**
Expand Down
63 changes: 63 additions & 0 deletions resources/views/commodities/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,69 @@
<x-slot name="title">Halaman Daftar Barang</x-slot>
<x-slot name="page_heading">Daftar Barang</x-slot>

<div class="row">
<div class="col-lg-3 col-md-6 col-sm-6 col-12">
<div class="card card-statistic-1">
<div class="card-icon bg-primary">
<i class="fas fa-columns"></i>
</div>
<div class="card-wrap">
<div class="card-header">
<h4>Total Barang</h4>
</div>
<div class="card-body">
{{ $commodity_counts['commodity_in_total'] }}
</div>
</div>
</div>
</div>
<div class="col-lg-3 col-md-6 col-sm-6 col-12">
<div class="card card-statistic-1">
<div class="card-icon bg-success">
<i class="fas fa-fw fa-check-circle"></i>
</div>
<div class="card-wrap">
<div class="card-header">
<h4>Kondisi Baik</h4>
</div>
<div class="card-body">
{{ $commodity_counts['commodity_in_good_condition'] }}
</div>
</div>
</div>
</div>
<div class="col-lg-3 col-md-6 col-sm-6 col-12">
<div class="card card-statistic-1">
<div class="card-icon bg-warning">
<i class="fas fa-fw fa-exclamation-circle"></i>
</div>
<div class="card-wrap">
<div class="card-header">
<h4>Kondisi Rusak Ringan</h4>
</div>
<div class="card-body">
{{ $commodity_counts['commodity_in_not_good_condition'] }}
</div>
</div>
</div>
</div>
<div class="col-lg-3 col-md-6 col-sm-6 col-12">
<div class="card card-statistic-1">
<div class="card-icon bg-danger">
<i class="fas fa-fw fa-times-circle"></i>
</div>
<div class="card-wrap">
<div class="card-header">
<h4>Kondisi Rusak Berat</h4>
</div>
<div class="card-body">
{{ $commodity_counts['commodity_in_heavily_damage_condition'] }}
</div>
</div>
</div>
</div>
</div>

<div class="card">
<div class="card-body">
@include('utilities.alert')
Expand Down

0 comments on commit 4658983

Please sign in to comment.