fix: 수주확정 되돌리기 시 매출 연동 해지 처리
- revertOrderConfirmation 메서드에 매출 연동 해지 로직 추가 - 수주확정 시 생성된 매출(source_type=order_confirm, status=draft)만 삭제 - 이미 확정된 매출은 연결만 해지하고 삭제하지 않음 - DB 트랜잭션으로 원자성 보장 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
use App\Models\Orders\Order;
|
||||
use App\Models\Production\WorkOrder;
|
||||
use App\Models\Quote\Quote;
|
||||
use App\Models\Tenants\Sale;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
@@ -540,16 +541,42 @@ public function revertOrderConfirmation(int $orderId): array
|
||||
throw new BadRequestHttpException(__('error.order.cannot_revert_not_confirmed'));
|
||||
}
|
||||
|
||||
// 상태 변경
|
||||
$previousStatus = $order->status_code;
|
||||
$order->status_code = Order::STATUS_DRAFT;
|
||||
$order->updated_by = $userId;
|
||||
$order->save();
|
||||
return DB::transaction(function () use ($order, $tenantId, $userId) {
|
||||
$deletedSaleId = null;
|
||||
|
||||
return [
|
||||
'order' => $order->load(['client:id,name', 'items']),
|
||||
'previous_status' => $previousStatus,
|
||||
];
|
||||
// 수주확정 시 생성된 매출이 있으면 삭제
|
||||
if ($order->sale_id) {
|
||||
$sale = Sale::where('tenant_id', $tenantId)
|
||||
->where('id', $order->sale_id)
|
||||
->first();
|
||||
|
||||
if ($sale) {
|
||||
// 수주확정 시 생성된 매출만 삭제 (draft 상태이고 order_confirm 타입)
|
||||
if ($sale->source_type === Sale::SOURCE_ORDER_CONFIRM
|
||||
&& $sale->status === 'draft') {
|
||||
$deletedSaleId = $sale->id;
|
||||
$sale->deleted_by = $userId;
|
||||
$sale->save();
|
||||
$sale->delete();
|
||||
}
|
||||
}
|
||||
|
||||
// 수주의 매출 연결 해지
|
||||
$order->sale_id = null;
|
||||
}
|
||||
|
||||
// 상태 변경
|
||||
$previousStatus = $order->status_code;
|
||||
$order->status_code = Order::STATUS_DRAFT;
|
||||
$order->updated_by = $userId;
|
||||
$order->save();
|
||||
|
||||
return [
|
||||
'order' => $order->load(['client:id,name', 'items']),
|
||||
'previous_status' => $previousStatus,
|
||||
'deleted_sale_id' => $deletedSaleId,
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user