diff --git a/app/Models/Purchase.php b/app/Models/Purchase.php index 8bd4e91..64d8f65 100644 --- a/app/Models/Purchase.php +++ b/app/Models/Purchase.php @@ -25,6 +25,7 @@ 'shipping_cost_formatted', 'subtotal_formatted', 'total_formatted', + 'total_quantity_formatted', ])] class Purchase extends Model implements HasMedia { @@ -78,6 +79,28 @@ public function totalFormatted(): Attribute ); } + public function totalQuantityFormatted(): Attribute + { + return Attribute::make( + get: function () { + $groups = []; + + foreach ($this->items as $item) { + $unit = $item->unit_abbreviation ?? $item->rawMaterialPrice?->rawMaterial?->unit?->abbreviation() ?? ''; + $groups[$unit] = ($groups[$unit] ?? 0) + (float) $item->quantity; + } + + return collect($groups) + ->filter(fn (float $total) => $total > 0) + ->map(function (float $total, string $unit) { + $formatted = rtrim(rtrim(number_format($total, 2, ',', '.'), '0'), ','); + return "{$formatted} {$unit}"; + }) + ->join(', '); + }, + ); + } + // 4. Other Methods public static function mediaModuleName(): string { diff --git a/resources/js/pages/admin/manage/purchases/table/PurchaseGroupedTable.vue b/resources/js/pages/admin/manage/purchases/table/PurchaseGroupedTable.vue index 4e4c0b7..3a6c961 100644 --- a/resources/js/pages/admin/manage/purchases/table/PurchaseGroupedTable.vue +++ b/resources/js/pages/admin/manage/purchases/table/PurchaseGroupedTable.vue @@ -145,6 +145,8 @@ function openVerificationDetail(requestId: number | undefined) {

+ Total Jumlah + {{ purchase.total_quantity_formatted }} Subtotal {{ purchase.subtotal_formatted }} Diskon {{ purchase.discount_formatted diff --git a/resources/js/types/purchase.ts b/resources/js/types/purchase.ts index 74a5cbd..c80704e 100644 --- a/resources/js/types/purchase.ts +++ b/resources/js/types/purchase.ts @@ -41,6 +41,7 @@ export type PurchaseListItem = { shipping_cost: number; shipping_cost_formatted: string; total_formatted: string; + total_quantity_formatted?: string; notes: string | null; created_at_formatted: string; created_by_name?: string;