diff --git a/app/Services/Manage/CuttingService.php b/app/Services/Manage/CuttingService.php index 6c4b5c6..1281dd8 100644 --- a/app/Services/Manage/CuttingService.php +++ b/app/Services/Manage/CuttingService.php @@ -969,7 +969,8 @@ private function filterActionsForUser(Cutting $cutting, User $user): array private function appendCostPreview(Cutting $cutting): void { - $cutting->setAttribute('total_result_pieces', (int) $cutting->results->sum('cutting_result')); + $totalResultPieces = (int) $cutting->results->sum('cutting_result'); + $cutting->setAttribute('total_result_pieces', $totalResultPieces); $cutting->setAttribute('total_material_usage', (float) $cutting->materials->sum(fn (CuttingMaterial $material) => (float) $material->material_usage)); $cutting->setAttribute('total_material_usage_summary_formatted', $this->formatMaterialUsageSummary($cutting)); @@ -978,9 +979,12 @@ private function appendCostPreview(Cutting $cutting): void $otherCost = (int) ($cutting->other_cost ?? 0); $totalProductionCost = $totalMaterialCost + $sewingCost + $otherCost; $costPerUnit = $cutting->cost_per_unit ?? $this->calculateCostPerUnit($cutting); + $materialCostPerProduct = $totalResultPieces > 0 ? (int) round($totalMaterialCost / $totalResultPieces) : 0; $cutting->setAttribute('total_material_cost', $totalMaterialCost); $cutting->setAttribute('total_material_cost_formatted', 'Rp '.number_format($totalMaterialCost, 0, ',', '.')); + $cutting->setAttribute('material_cost_per_product', $materialCostPerProduct); + $cutting->setAttribute('material_cost_per_product_formatted', 'Rp '.number_format($materialCostPerProduct, 0, ',', '.')); $cutting->setAttribute('sewing_cost', $sewingCost); $cutting->setAttribute('sewing_cost_formatted', 'Rp '.number_format($sewingCost, 0, ',', '.')); $cutting->setAttribute('other_cost', $otherCost); diff --git a/app/Services/Manage/StockService.php b/app/Services/Manage/StockService.php index 8b3ae40..3e4c0ca 100644 --- a/app/Services/Manage/StockService.php +++ b/app/Services/Manage/StockService.php @@ -322,7 +322,8 @@ private function applyResultPricesToProducts(Cutting $cutting): void private function appendCostPreview(Cutting $cutting): void { - $cutting->setAttribute('total_result_pieces', (int) $cutting->results->sum('cutting_result')); + $totalResultPieces = (int) $cutting->results->sum('cutting_result'); + $cutting->setAttribute('total_result_pieces', $totalResultPieces); $cutting->setAttribute('total_material_usage', (float) $cutting->materials->sum('material_usage')); $totalMaterialCost = $cutting->total_material_cost ?? 0; @@ -330,9 +331,12 @@ private function appendCostPreview(Cutting $cutting): void $otherCost = (int) ($cutting->other_cost ?? 0); $totalProductionCost = $totalMaterialCost + $sewingCost + $otherCost; $costPerUnit = $cutting->cost_per_unit ?? 0; + $materialCostPerProduct = $totalResultPieces > 0 ? (int) round($totalMaterialCost / $totalResultPieces) : 0; $cutting->setAttribute('total_material_cost', $totalMaterialCost); $cutting->setAttribute('total_material_cost_formatted', 'Rp '.number_format($totalMaterialCost, 0, ',', '.')); + $cutting->setAttribute('material_cost_per_product', $materialCostPerProduct); + $cutting->setAttribute('material_cost_per_product_formatted', 'Rp '.number_format($materialCostPerProduct, 0, ',', '.')); $cutting->setAttribute('sewing_cost', $sewingCost); $cutting->setAttribute('sewing_cost_formatted', 'Rp '.number_format($sewingCost, 0, ',', '.')); $cutting->setAttribute('other_cost', $otherCost); diff --git a/resources/js/pages/admin/manage/cuttings/table/CuttingCompletedSection.vue b/resources/js/pages/admin/manage/cuttings/table/CuttingCompletedSection.vue index 662bdb5..06f4606 100644 --- a/resources/js/pages/admin/manage/cuttings/table/CuttingCompletedSection.vue +++ b/resources/js/pages/admin/manage/cuttings/table/CuttingCompletedSection.vue @@ -123,6 +123,10 @@ const totalCompleted = computed(() => props.cuttings.length); Biaya Bahan: {{ cutting.total_material_cost_formatted ?? 'Rp 0' }} +
+ Biaya per Produk: + {{ cutting.material_cost_per_product_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 a3e1181..313a98f 100644 --- a/resources/js/pages/admin/manage/cuttings/table/CuttingGroupedTable.vue +++ b/resources/js/pages/admin/manage/cuttings/table/CuttingGroupedTable.vue @@ -139,6 +139,8 @@ function getGroupedResults(results: any[]): GroupedCuttingResults[] { }} Biaya Bahan {{ cutting.total_material_cost_formatted ?? 'Rp 0' }} + Biaya per Produk {{ + cutting.material_cost_per_product_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 35b77a2..f08d6df 100644 --- a/resources/js/pages/admin/manage/cuttings/table/CuttingInProgressSection.vue +++ b/resources/js/pages/admin/manage/cuttings/table/CuttingInProgressSection.vue @@ -97,6 +97,10 @@ defineProps<{ Biaya Bahan: {{ cutting.total_material_cost_formatted ?? 'Rp 0' }} +
+ Biaya per Produk: + {{ cutting.material_cost_per_product_formatted ?? 'Rp 0' }} +
diff --git a/resources/js/types/cutting.ts b/resources/js/types/cutting.ts index 0c17e32..41444f1 100644 --- a/resources/js/types/cutting.ts +++ b/resources/js/types/cutting.ts @@ -70,6 +70,8 @@ export type CuttingListItem = { created_at_formatted: string; total_material_cost?: number; total_material_cost_formatted?: string; + material_cost_per_product?: number; + material_cost_per_product_formatted?: string; sewing_cost?: number; sewing_cost_formatted?: string; other_cost?: number;