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' }} +