diff --git a/resources/js/pages/admin/manage/cuttings/table/CuttingCompletedSection.vue b/resources/js/pages/admin/manage/cuttings/table/CuttingCompletedSection.vue index e4084b3..a2aa1e3 100644 --- a/resources/js/pages/admin/manage/cuttings/table/CuttingCompletedSection.vue +++ b/resources/js/pages/admin/manage/cuttings/table/CuttingCompletedSection.vue @@ -12,18 +12,6 @@ import { } from '@/components/ui/empty'; import type { CuttingListItem } from '@/types/cutting'; -function formatTotalMaterialUsage(totalUsage: number | null | undefined): string { - if (!totalUsage) { - return '0'; - } - - return String(parseFloat(totalUsage.toFixed(2))); -} - -function getTotalMaterialUsageUnit(materials: any[]): string { - return materials[0]?.raw_material_price?.raw_material?.unit_abbreviation ?? ''; -} - function formatMaterialUsage(mat: any): string { return String(parseFloat(Number(mat.material_usage ?? 0).toFixed(2))); } @@ -32,6 +20,28 @@ function getMaterialUnit(mat: any): string { return mat.raw_material_price?.raw_material?.unit_abbreviation ?? ''; } +interface MaterialUsageGroup { + total: string; + unit: string; +} + +function getGroupedMaterialUsage(materials: any[]): MaterialUsageGroup[] { + const groups: Record = {}; + + materials.forEach((mat) => { + const unit = mat.raw_material_price?.raw_material?.unit_abbreviation ?? ''; + const usage = Number(mat.material_usage ?? 0); + groups[unit] = (groups[unit] ?? 0) + usage; + }); + + return Object.entries(groups) + .filter(([, total]) => total > 0) + .map(([unit, total]) => ({ + total: String(parseFloat(total.toFixed(2))), + unit, + })); +} + const props = defineProps<{ cuttings: CuttingListItem[]; }>(); @@ -105,9 +115,13 @@ const totalCompleted = computed(() => props.cuttings.length); Total Hasil Cutting: {{ cutting.total_result_pieces ?? 0 }} pcs -
+
Total Pemakaian Bahan: - {{ formatTotalMaterialUsage(cutting.total_material_usage) }} {{ getTotalMaterialUsageUnit(cutting.materials) }} + {{ getGroupedMaterialUsage(cutting.materials).map(g => `${g.total} ${g.unit}`).join(', ') }} +
+
+ Biaya Bahan: + {{ cutting.total_material_cost_formatted ?? 'Rp 0' }}
diff --git a/resources/js/pages/admin/manage/cuttings/table/CuttingGroupedTable.vue b/resources/js/pages/admin/manage/cuttings/table/CuttingGroupedTable.vue index 2b700eb..fb28e31 100644 --- a/resources/js/pages/admin/manage/cuttings/table/CuttingGroupedTable.vue +++ b/resources/js/pages/admin/manage/cuttings/table/CuttingGroupedTable.vue @@ -137,16 +137,26 @@ function getMaterialUnit(materials: any[]): string | undefined { return materials[0]?.raw_material_price?.raw_material?.unit_abbreviation; } -function formatTotalMaterialUsage(totalUsage: number | null | undefined): string { - if (!totalUsage) { - return '0'; - } - - return String(parseFloat(totalUsage.toFixed(2))); +interface MaterialUsageGroup { + total: string; + unit: string; } -function getTotalMaterialUsageUnit(materials: any[]): string { - return materials[0]?.raw_material_price?.raw_material?.unit_abbreviation ?? ''; +function getGroupedMaterialUsage(materials: any[]): MaterialUsageGroup[] { + const groups: Record = {}; + + materials.forEach((mat) => { + const unit = mat.raw_material_price?.raw_material?.unit_abbreviation ?? ''; + const usage = Number(mat.material_usage ?? 0); + groups[unit] = (groups[unit] ?? 0) + usage; + }); + + return Object.entries(groups) + .filter(([, total]) => total > 0) + .map(([unit, total]) => ({ + total: String(parseFloat(total.toFixed(2))), + unit, + })); } @@ -185,9 +195,7 @@ function getTotalMaterialUsageUnit(materials: any[]): string {
Total Hasil Cutting {{ cutting.total_result_pieces ?? 0 }} pcs - Total Pemakaian Bahan {{ - formatTotalMaterialUsage(cutting.total_material_usage) }} - {{ getTotalMaterialUsageUnit(cutting.materials) }} + Total Pemakaian Bahan {{ getGroupedMaterialUsage(cutting.materials).map(g => `${g.total} ${g.unit}`).join(', ') }} Biaya Bahan {{ cutting.total_material_cost_formatted ?? 'Rp 0' }}
diff --git a/resources/js/pages/admin/manage/cuttings/table/CuttingInProgressSection.vue b/resources/js/pages/admin/manage/cuttings/table/CuttingInProgressSection.vue index 70a3284..5f7a63d 100644 --- a/resources/js/pages/admin/manage/cuttings/table/CuttingInProgressSection.vue +++ b/resources/js/pages/admin/manage/cuttings/table/CuttingInProgressSection.vue @@ -3,18 +3,6 @@ import { Card } from '@/components/ui/card'; import type { CuttingListItem } from '@/types/cutting'; import DataTableActions from './data-table-actions.vue'; -function formatTotalMaterialUsage(totalUsage: number | null | undefined): string { - if (!totalUsage) { - return '0'; - } - - return String(parseFloat(totalUsage.toFixed(2))); -} - -function getTotalMaterialUsageUnit(materials: any[]): string { - return materials[0]?.raw_material_price?.raw_material?.unit_abbreviation ?? ''; -} - function formatMaterialUsage(mat: any): string { return String(parseFloat(Number(mat.material_usage ?? 0).toFixed(2))); } @@ -23,6 +11,28 @@ function getMaterialUnit(mat: any): string { return mat.raw_material_price?.raw_material?.unit_abbreviation ?? ''; } +interface MaterialUsageGroup { + total: string; + unit: string; +} + +function getGroupedMaterialUsage(materials: any[]): MaterialUsageGroup[] { + const groups: Record = {}; + + materials.forEach((mat) => { + const unit = mat.raw_material_price?.raw_material?.unit_abbreviation ?? ''; + const usage = Number(mat.material_usage ?? 0); + groups[unit] = (groups[unit] ?? 0) + usage; + }); + + return Object.entries(groups) + .filter(([, total]) => total > 0) + .map(([unit, total]) => ({ + total: String(parseFloat(total.toFixed(2))), + unit, + })); +} + defineProps<{ cuttings: CuttingListItem[]; }>(); @@ -80,9 +90,13 @@ defineProps<{ {{ cutting.total_result_pieces ?? 0 }} pcs -
+
Total Pemakaian Bahan: - {{ formatTotalMaterialUsage(cutting.total_material_usage) }} {{ getTotalMaterialUsageUnit(cutting.materials) }} + {{ getGroupedMaterialUsage(cutting.materials).map(g => `${g.total} ${g.unit}`).join(', ') }} +
+
+ Biaya Bahan: + {{ cutting.total_material_cost_formatted ?? 'Rp 0' }}