modified logic in process order
This commit is contained in:
@@ -612,13 +612,20 @@ class PdfController extends Controller
|
|||||||
// $lastRecord = $processOrderRecords->first();
|
// $lastRecord = $processOrderRecords->first();
|
||||||
$item = $lastRecord->item;
|
$item = $lastRecord->item;
|
||||||
|
|
||||||
if ($totalReceivedQty == $proOrdAgPlant->order_quantity || $totalReceivedQty > $proOrdAgPlant->order_quantity) {
|
if ($totalReceivedQty == $proOrdAgPlant->order_quantity) {
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'status_code' => 'ERROR',
|
'status_code' => 'ERROR',
|
||||||
'status_description' => "Process order '{$processOrder}' for plant '{$plantCode}' has already reached its order quantity."
|
'status_description' => "Process order '{$processOrder}' for plant '{$plantCode}' has already reached its order quantity."
|
||||||
], 400);
|
], 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if ($totalReceivedQty > $proOrdAgPlant->order_quantity) {
|
||||||
|
// return response()->json([
|
||||||
|
// 'status_code' => 'ERROR',
|
||||||
|
// 'status_description' => "Process order '{$processOrder}' for plant '{$plantCode}' received quantity is more than its order quantity."
|
||||||
|
// ], 400);
|
||||||
|
// }
|
||||||
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'item_code' => $item?->code ?? "",
|
'item_code' => $item?->code ?? "",
|
||||||
'description' => $item?->description ?? "",
|
'description' => $item?->description ?? "",
|
||||||
@@ -647,7 +654,6 @@ class PdfController extends Controller
|
|||||||
$plantCode = $request->header('plant-code');
|
$plantCode = $request->header('plant-code');
|
||||||
$processOrder = $request->header('process-order');
|
$processOrder = $request->header('process-order');
|
||||||
|
|
||||||
|
|
||||||
if (!$plantCode || !$processOrder) {
|
if (!$plantCode || !$processOrder) {
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'status_code' => 'ERROR',
|
'status_code' => 'ERROR',
|
||||||
@@ -707,6 +713,32 @@ class PdfController extends Controller
|
|||||||
], 409);
|
], 409);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$alreadyReceived = ProcessOrder::where('plant_id', $plant->id)
|
||||||
|
->where('process_order', $processOrder)
|
||||||
|
->where('item_id', $item->id)
|
||||||
|
->sum('received_quantity');
|
||||||
|
|
||||||
|
$newReceived = $validated['received_quantity'] ?? 0;
|
||||||
|
$orderQty = $validated['order_quantity'] ?? 0;
|
||||||
|
|
||||||
|
if ($orderQty == 0) {
|
||||||
|
$orderQty = ProcessOrder::where('plant_id', $plant->id)
|
||||||
|
->where('process_order', $processOrder)
|
||||||
|
->where('item_id', $item->id)
|
||||||
|
->value('order_quantity') ?? 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
$total = $alreadyReceived + $newReceived;
|
||||||
|
|
||||||
|
if ($total > $orderQty) {
|
||||||
|
return response()->json([
|
||||||
|
'status_code' => 'ERROR',
|
||||||
|
'status_description' => "Received quantity cannot exceed order quantity.
|
||||||
|
Order Qty = {$orderQty}, Already Received = {$alreadyReceived},
|
||||||
|
Trying to Insert = {$newReceived}"
|
||||||
|
], 404);
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ProcessOrder::Create(
|
ProcessOrder::Create(
|
||||||
|
|||||||
Reference in New Issue
Block a user