feat: add updateCombinationResult method to CuttingDraftItemController and corresponding route
This commit is contained in:
parent
6cbb6f7cbb
commit
0070d0c49e
@ -61,6 +61,15 @@ public function destroyCombination(Request $request, int $combinationId): JsonRe
|
|||||||
return response()->json(['ok' => true]);
|
return response()->json(['ok' => true]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function updateCombinationResult(Request $request, int $combinationId): JsonResponse
|
||||||
|
{
|
||||||
|
$result = $request->input('material_result');
|
||||||
|
|
||||||
|
$this->cuttingService->updateDraftCombinationResult($request->user(), $combinationId, $result);
|
||||||
|
|
||||||
|
return response()->json(['ok' => true]);
|
||||||
|
}
|
||||||
|
|
||||||
public function quickCreateProduct(CuttingQuickCreateProductRequest $request): JsonResponse
|
public function quickCreateProduct(CuttingQuickCreateProductRequest $request): JsonResponse
|
||||||
{
|
{
|
||||||
$product = $this->cuttingService->quickCreateProduct($request->validated());
|
$product = $this->cuttingService->quickCreateProduct($request->validated());
|
||||||
|
|||||||
@ -411,6 +411,23 @@ public function removeDraftCombination(User $user, int $combinationId): void
|
|||||||
$combination->forceDelete();
|
$combination->forceDelete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function updateDraftCombinationResult(User $user, int $combinationId, mixed $result): void
|
||||||
|
{
|
||||||
|
$combination = CuttingMaterialCombination::query()
|
||||||
|
->whereNull('cutting_id')
|
||||||
|
->where('user_id', $user->id)
|
||||||
|
->where('id', $combinationId)
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if ($combination === null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$materialResult = $result !== null ? (int) $result : null;
|
||||||
|
|
||||||
|
$combination->update(['material_result' => $materialResult]);
|
||||||
|
}
|
||||||
|
|
||||||
public function create(array $validated, User $user): Cutting
|
public function create(array $validated, User $user): Cutting
|
||||||
{
|
{
|
||||||
$cutting = $this->runInTransaction(
|
$cutting = $this->runInTransaction(
|
||||||
|
|||||||
@ -65,6 +65,7 @@ const {
|
|||||||
resultCart,
|
resultCart,
|
||||||
filteredRawMaterials,
|
filteredRawMaterials,
|
||||||
totalMaterialCost,
|
totalMaterialCost,
|
||||||
|
totalMaterialResult,
|
||||||
totalResultPieces,
|
totalResultPieces,
|
||||||
materialLineCost,
|
materialLineCost,
|
||||||
setCarts,
|
setCarts,
|
||||||
@ -150,6 +151,13 @@ if (isCreateMode.value && resultCart.value.length === 0) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
watch(totalMaterialResult, (newVal) => {
|
||||||
|
const val = newVal > 0 ? String(newVal) : null;
|
||||||
|
resultCart.value.forEach((item) => {
|
||||||
|
item.cutting_result = val;
|
||||||
|
});
|
||||||
|
}, { immediate: true });
|
||||||
|
|
||||||
function buildFormData(): FormData {
|
function buildFormData(): FormData {
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
|
|
||||||
|
|||||||
@ -84,6 +84,24 @@ export function useCuttingPosCart(options: {
|
|||||||
materialCart.value.reduce((sum, item) => sum + materialLineCost(item), 0),
|
materialCart.value.reduce((sum, item) => sum + materialLineCost(item), 0),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const totalMaterialResult = computed(() => {
|
||||||
|
const seenCombinations = new Set<number>();
|
||||||
|
let total = 0;
|
||||||
|
|
||||||
|
materialCart.value.forEach((item) => {
|
||||||
|
if (item.combination_id) {
|
||||||
|
if (!seenCombinations.has(item.combination_id)) {
|
||||||
|
seenCombinations.add(item.combination_id);
|
||||||
|
total += Number(item.combination_material_result) || 0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
total += Number(item.material_result) || 0;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return total;
|
||||||
|
});
|
||||||
|
|
||||||
const totalResultPieces = computed(() =>
|
const totalResultPieces = computed(() =>
|
||||||
resultCart.value.reduce(
|
resultCart.value.reduce(
|
||||||
(sum, item) => sum + (Number(item.cutting_result) || 0),
|
(sum, item) => sum + (Number(item.cutting_result) || 0),
|
||||||
@ -195,6 +213,17 @@ export function useCuttingPosCart(options: {
|
|||||||
item.combination_material_result = result;
|
item.combination_material_result = result;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (toValue(options.isCreateMode)) {
|
||||||
|
try {
|
||||||
|
await apiFetch(draft_combinations.update_result.url(combinationId), {
|
||||||
|
method: 'PUT',
|
||||||
|
body: JSON.stringify({ material_result: result }),
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
toast.error(error instanceof Error ? error.message : 'Gagal menyimpan hasil kombinasi.');
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getMaterialCartItem(priceId: number): CuttingMaterialCartItem | undefined {
|
function getMaterialCartItem(priceId: number): CuttingMaterialCartItem | undefined {
|
||||||
@ -310,6 +339,7 @@ export function useCuttingPosCart(options: {
|
|||||||
resultCart,
|
resultCart,
|
||||||
filteredRawMaterials,
|
filteredRawMaterials,
|
||||||
totalMaterialCost,
|
totalMaterialCost,
|
||||||
|
totalMaterialResult,
|
||||||
totalResultPieces,
|
totalResultPieces,
|
||||||
estimatedCostPerUnit,
|
estimatedCostPerUnit,
|
||||||
materialLineCost,
|
materialLineCost,
|
||||||
|
|||||||
@ -404,6 +404,10 @@
|
|||||||
->middleware('permission:'.Permission::CUTTINGS_CREATE->value)
|
->middleware('permission:'.Permission::CUTTINGS_CREATE->value)
|
||||||
->name('draft_combinations.destroy');
|
->name('draft_combinations.destroy');
|
||||||
|
|
||||||
|
Route::put('draft-combinations/{combinationId}/result', [CuttingDraftItemController::class, 'updateCombinationResult'])
|
||||||
|
->middleware('permission:'.Permission::CUTTINGS_CREATE->value)
|
||||||
|
->name('draft_combinations.update_result');
|
||||||
|
|
||||||
Route::post('quick-create-product', [CuttingDraftItemController::class, 'quickCreateProduct'])
|
Route::post('quick-create-product', [CuttingDraftItemController::class, 'quickCreateProduct'])
|
||||||
->middleware('permission:'.Permission::CUTTINGS_CREATE->value)
|
->middleware('permission:'.Permission::CUTTINGS_CREATE->value)
|
||||||
->name('quick_create_product');
|
->name('quick_create_product');
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user