feat: enhance raw material stock display by adding breakdown by unit in DashboardController and updating Dashboard.vue for improved inventory insights
This commit is contained in:
parent
740a06ca29
commit
3bb6baffa6
@ -69,9 +69,20 @@ private function getRawMaterialStock(): array
|
||||
->selectRaw('SUM(stock) as total_stock, SUM(stock * price) as total_value')
|
||||
->first();
|
||||
|
||||
$byUnit = RawMaterialPrice::query()
|
||||
->join('raw_materials', 'raw_material_prices.raw_material_id', '=', 'raw_materials.id')
|
||||
->selectRaw('raw_materials.unit, SUM(raw_material_prices.stock) as total_stock')
|
||||
->groupBy('raw_materials.unit')
|
||||
->get()
|
||||
->mapWithKeys(fn ($item) => [
|
||||
$item->unit => (float) $item->total_stock,
|
||||
])
|
||||
->toArray();
|
||||
|
||||
return [
|
||||
'total_stock' => (float) ($data->total_stock ?? 0),
|
||||
'total_value' => (int) ($data->total_value ?? 0),
|
||||
'by_unit' => $byUnit,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@ -30,6 +30,7 @@ interface DashboardProps {
|
||||
rawMaterialStock: {
|
||||
total_stock: number;
|
||||
total_value: number;
|
||||
by_unit: Record<string, number>;
|
||||
};
|
||||
productStock: {
|
||||
total_stock: number;
|
||||
@ -390,12 +391,35 @@ const totalCashBalance = computed(() => {
|
||||
<Package class="text-muted-foreground size-4" />
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div class="text-2xl font-bold">
|
||||
{{ rawMaterialStock.total_stock.toLocaleString('id-ID') }}
|
||||
<div class="space-y-3">
|
||||
<div>
|
||||
<p class="text-muted-foreground text-xs">Total Stok</p>
|
||||
<p class="text-xl font-bold">{{ rawMaterialStock.total_stock.toLocaleString('id-ID') }}</p>
|
||||
<p class="text-muted-foreground text-xs">
|
||||
{{ formatRupiah(rawMaterialStock.total_value) }}
|
||||
</p>
|
||||
</div>
|
||||
<div class="grid grid-cols-3 gap-2 pt-2 border-t">
|
||||
<div>
|
||||
<Badge variant="outline" class="mb-1 bg-blue-500/10 text-blue-600 border-blue-500/20">
|
||||
Yard
|
||||
</Badge>
|
||||
<p class="text-sm font-semibold">{{ (rawMaterialStock.by_unit?.yard ?? 0).toLocaleString('id-ID') }}</p>
|
||||
</div>
|
||||
<div>
|
||||
<Badge variant="outline" class="mb-1 bg-green-500/10 text-green-600 border-green-500/20">
|
||||
Meter
|
||||
</Badge>
|
||||
<p class="text-sm font-semibold">{{ (rawMaterialStock.by_unit?.meter ?? 0).toLocaleString('id-ID') }}</p>
|
||||
</div>
|
||||
<div>
|
||||
<Badge variant="outline" class="mb-1 bg-purple-500/10 text-purple-600 border-purple-500/20">
|
||||
Kg
|
||||
</Badge>
|
||||
<p class="text-sm font-semibold">{{ (rawMaterialStock.by_unit?.kilogram ?? 0).toLocaleString('id-ID') }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<p class="text-muted-foreground text-xs">
|
||||
Total nilai: {{ formatRupiah(rawMaterialStock.total_value) }}
|
||||
</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user