feat: calculate and display material cost per product in cutting management
This commit is contained in:
parent
4466c61352
commit
2ed24a654b
@ -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);
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -123,6 +123,10 @@ const totalCompleted = computed(() => props.cuttings.length);
|
||||
<span class="text-muted-foreground">Biaya Bahan:</span>
|
||||
<span class="font-semibold tabular-nums">{{ cutting.total_material_cost_formatted ?? 'Rp 0' }}</span>
|
||||
</div>
|
||||
<div class="flex items-center justify-between text-[11px]">
|
||||
<span class="text-muted-foreground">Biaya per Produk:</span>
|
||||
<span class="font-semibold tabular-nums">{{ cutting.material_cost_per_product_formatted ?? 'Rp 0' }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="text-[11px] text-muted-foreground pt-2 border-t flex items-center justify-between">
|
||||
|
||||
@ -139,6 +139,8 @@ function getGroupedResults(results: any[]): GroupedCuttingResults[] {
|
||||
}}</strong></span>
|
||||
<span>Biaya Bahan <strong class="text-primary">{{
|
||||
cutting.total_material_cost_formatted ?? 'Rp 0' }}</strong></span>
|
||||
<span>Biaya per Produk <strong class="text-primary">{{
|
||||
cutting.material_cost_per_product_formatted ?? 'Rp 0' }}</strong></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -97,6 +97,10 @@ defineProps<{
|
||||
<span class="text-muted-foreground">Biaya Bahan:</span>
|
||||
<span class="font-semibold tabular-nums">{{ cutting.total_material_cost_formatted ?? 'Rp 0' }}</span>
|
||||
</div>
|
||||
<div class="flex items-center justify-between text-[11px]">
|
||||
<span class="text-muted-foreground">Biaya per Produk:</span>
|
||||
<span class="font-semibold tabular-nums">{{ cutting.material_cost_per_product_formatted ?? 'Rp 0' }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="text-[11px] text-muted-foreground pt-2 border-t flex items-center justify-between">
|
||||
|
||||
@ -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;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user