Changed logic in post api and get api of process order
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 14s
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Successful in 14s
Gemini PR Review / Gemini PR Review (pull_request) Successful in 20s
Laravel Pint / pint (pull_request) Failing after 2m33s
Laravel Larastan / larastan (pull_request) Failing after 3m29s
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 14s
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Successful in 14s
Gemini PR Review / Gemini PR Review (pull_request) Successful in 20s
Laravel Pint / pint (pull_request) Failing after 2m33s
Laravel Larastan / larastan (pull_request) Failing after 3m29s
This commit is contained in:
@@ -7,6 +7,7 @@ use App\Models\GrMaster;
|
||||
use App\Models\Item;
|
||||
use App\Models\ItemCharacteristic;
|
||||
use App\Models\Line;
|
||||
use App\Models\Machine;
|
||||
use App\Models\Plant;
|
||||
use App\Models\ProcessOrder;
|
||||
use App\Models\StickerDetail;
|
||||
@@ -540,7 +541,7 @@ class PdfController extends Controller
|
||||
|
||||
$processOrder = $request->header('process-order');
|
||||
|
||||
// $machineName = $request->header('machine-name');
|
||||
$machineName = $request->header('machine-name');
|
||||
|
||||
if (! $plantCode) {
|
||||
return response()->json([
|
||||
@@ -575,6 +576,7 @@ class PdfController extends Controller
|
||||
|
||||
$proOrdAgPlant = ProcessOrder::where('plant_id', $plantId)
|
||||
->where('process_order', $processOrder)
|
||||
->latest()
|
||||
->first();
|
||||
|
||||
if (! $proOrdAgPlant) {
|
||||
@@ -584,61 +586,185 @@ class PdfController extends Controller
|
||||
], 404);
|
||||
}
|
||||
|
||||
$item = $proOrdAgPlant->item;
|
||||
$coil = $proOrdAgPlant->coil_number;
|
||||
|
||||
$processOrderRecords = ProcessOrder::with('item')
|
||||
->where('plant_id', $plant->id)
|
||||
if($coil != 0){
|
||||
$proOrdAgPlantMachine = ProcessOrder::where('plant_id', $plantId)
|
||||
->where('process_order', $processOrder)
|
||||
->get();
|
||||
|
||||
$lastRecord = ProcessOrder::with('item')
|
||||
->where('plant_id', $plant->id)
|
||||
->where('process_order', $processOrder)
|
||||
->orderBy('id', 'desc')
|
||||
->where('machine_name', $machineName)
|
||||
->first();
|
||||
|
||||
$lastRecord1 = ProcessOrder::with('item')
|
||||
->where('plant_id', $plant->id)
|
||||
->where('process_order', $processOrder)
|
||||
->where('rework_status', 0)
|
||||
->orderBy('id', 'desc')
|
||||
->first();
|
||||
if (!$proOrdAgPlantMachine) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => 'Machine name not found in process order!',
|
||||
], 404);
|
||||
}
|
||||
|
||||
$totalReceivedQty = $processOrderRecords->sum('received_quantity');
|
||||
// $lastRecord = $processOrderRecords->first();
|
||||
$item = $lastRecord->item;
|
||||
$item = $proOrdAgPlant->item;
|
||||
|
||||
$processOrderRecords = ProcessOrder::with('item')
|
||||
->where('plant_id', $plant->id)
|
||||
->where('process_order', $processOrder)
|
||||
->where('machine_name', $machineName)
|
||||
->get();
|
||||
|
||||
$lastRecord = ProcessOrder::with('item')
|
||||
->where('plant_id', $plant->id)
|
||||
->where('process_order', $processOrder)
|
||||
->where('machine_name', $machineName)
|
||||
->orderBy('id', 'desc')
|
||||
->first();
|
||||
|
||||
$lastRecord1 = ProcessOrder::with('item')
|
||||
->where('plant_id', $plant->id)
|
||||
->where('process_order', $processOrder)
|
||||
->where('machine_name', $machineName)
|
||||
->where('rework_status', 0)
|
||||
->orderBy('id', 'desc')
|
||||
->first();
|
||||
|
||||
$totalReceivedQty = $processOrderRecords->sum('received_quantity');
|
||||
// $lastRecord = $processOrderRecords->first();
|
||||
$item = $lastRecord->item;
|
||||
|
||||
if ($totalReceivedQty == $proOrdAgPlant->order_quantity) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Process order '{$processOrder}' for plant '{$plantCode}' has already reached its order quantity.",
|
||||
], 404);
|
||||
}
|
||||
|
||||
$itemId = $lastRecord->item_id;
|
||||
|
||||
$line = ProcessOrder::where('plant_id', $plantId)->where('process_order', $processOrder)->where('item_id',$itemId)->first();
|
||||
|
||||
$lineId = $line->line_id;
|
||||
|
||||
$lineName = Line::where('plant_id', $plantId)->where('id', $lineId)->value('name');
|
||||
|
||||
|
||||
// $workCenter = Machine::where('plant_id', $plantId)->where('work_center', $machineName)->first();
|
||||
|
||||
$currentCoil = ($lastRecord->rework_status == 1) ? (string) $lastRecord1->coil_number : (string) $lastRecord->coil_number;
|
||||
|
||||
$machine = Machine::where('plant_id', $plantId)->where('line_id', $lineId)->where('work_center', $machineName)->first();
|
||||
$machineId = $machine->id;
|
||||
|
||||
if(!$machine){
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Machine not found in machine table.",
|
||||
], 404);
|
||||
}
|
||||
|
||||
// if ($totalReceivedQty > $proOrdAgPlant->order_quantity) {
|
||||
// return responses()->json([
|
||||
// 'status_code' => 'ERROR',
|
||||
// 'status_description' => "Process order '{$processOrder}' for plant '{$plantCode}' received quantity is more than its order quantity."
|
||||
// ], 404);
|
||||
// }
|
||||
|
||||
$okQty = CharacteristicValue::where('plant_id', $plant->id)->where('process_order', $processOrder)->where('machine_id', $machineId)->where('status', 'Ok')->get()->count();
|
||||
|
||||
$notOkQty = CharacteristicValue::where('plant_id', $plant->id)->where('process_order', $processOrder)->where('machine_id', $machineId)->where('status', 'NotOk')->get()->count();
|
||||
|
||||
$currentCoil = ($lastRecord->rework_status == 1) ? (string) $lastRecord1->coil_number : (string) $lastRecord->coil_number;
|
||||
|
||||
if ($totalReceivedQty == $proOrdAgPlant->order_quantity) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Process order '{$processOrder}' for plant '{$plantCode}' has already reached its order quantity.",
|
||||
], 404);
|
||||
'item_code' => $item?->code ?? '',
|
||||
'description' => $item?->description ?? '',
|
||||
'line_name' => $lineName ?? '',
|
||||
// 'coil_number' => $proOrdAgPlant->coil_number ?? "",
|
||||
// 'order_quantity' => (string)$proOrdAgPlant->order_quantity ?? "",
|
||||
'coil_number' => $currentCoil,
|
||||
'order_quantity' => (string) $lastRecord->updated_order_quantity ?? '0.000',
|
||||
'ok_quantity' => (string) $okQty ?? '0',
|
||||
'not_ok_quantity' => (string) $notOkQty ?? '0',
|
||||
'received_quantity' => (string) (($totalReceivedQty == 0) ? '0.000' : $totalReceivedQty) ?? '0.000',
|
||||
]);
|
||||
}
|
||||
else{
|
||||
|
||||
$proOrdAgPlant = ProcessOrder::where('plant_id', $plantId)
|
||||
->where('process_order', $processOrder)
|
||||
->first();
|
||||
|
||||
if (!$proOrdAgPlant) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => 'process order not found!',
|
||||
], 404);
|
||||
}
|
||||
|
||||
$item = $proOrdAgPlant->item;
|
||||
|
||||
$processOrderRecords = ProcessOrder::with('item')
|
||||
->where('plant_id', $plant->id)
|
||||
->where('process_order', $processOrder)
|
||||
->get();
|
||||
|
||||
$lastRecord = ProcessOrder::with('item')
|
||||
->where('plant_id', $plant->id)
|
||||
->where('process_order', $processOrder)
|
||||
->orderBy('id', 'desc')
|
||||
->first();
|
||||
|
||||
$lastRecord1 = ProcessOrder::with('item')
|
||||
->where('plant_id', $plant->id)
|
||||
->where('process_order', $processOrder)
|
||||
->where('rework_status', 0)
|
||||
->orderBy('id', 'desc')
|
||||
->first();
|
||||
|
||||
$totalReceivedQty = $processOrderRecords->sum('received_quantity');
|
||||
// $lastRecord = $processOrderRecords->first();
|
||||
$item = $lastRecord->item;
|
||||
|
||||
if ($totalReceivedQty == $proOrdAgPlant->order_quantity) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Process order '{$processOrder}' for plant '{$plantCode}' has already reached its order quantity.",
|
||||
], 404);
|
||||
}
|
||||
|
||||
$itemId = $lastRecord->item_id;
|
||||
|
||||
$line = ProcessOrder::where('plant_id', $plantId)->where('process_order', $processOrder)->where('item_id',$itemId)->first();
|
||||
|
||||
$lineId = $line->line_id;
|
||||
|
||||
$lineName = Line::where('plant_id', $plantId)->where('id', $lineId)->value('name');
|
||||
|
||||
$currentCoil = ($lastRecord->rework_status == 1) ? (string) $lastRecord1->coil_number : (string) $lastRecord->coil_number;
|
||||
|
||||
// if ($totalReceivedQty > $proOrdAgPlant->order_quantity) {
|
||||
// return responses()->json([
|
||||
// 'status_code' => 'ERROR',
|
||||
// 'status_description' => "Process order '{$processOrder}' for plant '{$plantCode}' received quantity is more than its order quantity."
|
||||
// ], 404);
|
||||
// }
|
||||
|
||||
$okQty = CharacteristicValue::where('plant_id', $plant->id)->where('process_order', $processOrder)->where('status', 'Ok')->get()->count();
|
||||
|
||||
$notOkQty = CharacteristicValue::where('plant_id', $plant->id)->where('process_order', $processOrder)->where('status', 'NotOk')->get()->count();
|
||||
|
||||
$currentCoil = ($lastRecord->rework_status == 1) ? (string) $lastRecord1->coil_number : (string) $lastRecord->coil_number;
|
||||
|
||||
return response()->json([
|
||||
'item_code' => $item?->code ?? '',
|
||||
'description' => $item?->description ?? '',
|
||||
'line_name' => $lineName ?? '',
|
||||
// 'coil_number' => $proOrdAgPlant->coil_number ?? "",
|
||||
// 'order_quantity' => (string)$proOrdAgPlant->order_quantity ?? "",
|
||||
'coil_number' => $currentCoil,
|
||||
'order_quantity' => (string) $lastRecord->updated_order_quantity ?? '0.000',
|
||||
'ok_quantity' => (string) $okQty ?? '0',
|
||||
'not_ok_quantity' => (string) $notOkQty ?? '0',
|
||||
'received_quantity' => (string) (($totalReceivedQty == 0) ? '0.000' : $totalReceivedQty) ?? '0.000',
|
||||
]);
|
||||
}
|
||||
|
||||
// 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."
|
||||
// ], 404);
|
||||
// }
|
||||
|
||||
$okQty = CharacteristicValue::where('plant_id', $plant->id)->where('process_order', $processOrder)->where('status', 'Ok')->get()->count();
|
||||
|
||||
$notOkQty = CharacteristicValue::where('plant_id', $plant->id)->where('process_order', $processOrder)->where('status', 'NotOk')->get()->count();
|
||||
|
||||
$currentCoil = ($lastRecord->rework_status == 1) ? (string) $lastRecord1->coil_number : (string) $lastRecord->coil_number;
|
||||
|
||||
return response()->json([
|
||||
'item_code' => $item?->code ?? '',
|
||||
'description' => $item?->description ?? '',
|
||||
// 'coil_number' => $proOrdAgPlant->coil_number ?? "",
|
||||
// 'order_quantity' => (string)$proOrdAgPlant->order_quantity ?? "",
|
||||
'coil_number' => $currentCoil,
|
||||
'order_quantity' => (string) $lastRecord->updated_order_quantity ?? '0.000',
|
||||
'ok_quantity' => (string) $okQty ?? '0',
|
||||
'not_ok_quantity' => (string) $notOkQty ?? '0',
|
||||
'received_quantity' => (string) (($totalReceivedQty == 0) ? '0.000' : $totalReceivedQty) ?? '0.000',
|
||||
]);
|
||||
}
|
||||
|
||||
public function storeProcessOrderData(Request $request)
|
||||
@@ -691,7 +817,7 @@ class PdfController extends Controller
|
||||
$plantId = $plant->id;
|
||||
|
||||
$itemCode = $data['item_code'] ?? '';
|
||||
$lineName = $data['line_name'] ?? '';
|
||||
// $lineName = $data['line_name'] ?? '';
|
||||
$coilNo = $data['coil_number'] ?? '';
|
||||
$updatedOrderQty = $data['order_quantity'] ?? 0;
|
||||
$receivedQty = $data['received_quantity'] ?? 0;
|
||||
@@ -699,18 +825,9 @@ class PdfController extends Controller
|
||||
$sfgNo = $data['sfg_number'] ?? '';
|
||||
$machineId = $data['machine_id'] ?? '';
|
||||
$rework = $data['rework'] ?? '';
|
||||
$operationNo = $data['operation_number'] ?? '';
|
||||
$createdBy = $data['created_by'] ?? '';
|
||||
|
||||
// $validated = $request->validate([
|
||||
// 'item_code' => 'nullable|integer',
|
||||
// 'coil_number' => 'nullable|string',
|
||||
// 'order_quantity' => 'nullable|integer',
|
||||
// 'received_quantity' => 'nullable|numeric',
|
||||
// 'sfg_number' => 'nullable|string',
|
||||
// 'machine_id' => 'nullable|string',
|
||||
// 'created_by' => 'nullable|string',
|
||||
// ]);
|
||||
|
||||
if ($itemCode == null || $itemCode == '' || ! $itemCode) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
@@ -728,13 +845,39 @@ class PdfController extends Controller
|
||||
], 404);
|
||||
}
|
||||
|
||||
if ($lineName == null || $lineName == '' || ! $lineName) {
|
||||
$item = Item::where('plant_id', $plantId)->where('code', $itemCode)->first();
|
||||
|
||||
if(!$item){
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Line name can't be empty!",
|
||||
'status_description' => "Item Code not found!",
|
||||
], 404);
|
||||
}
|
||||
|
||||
if($item){
|
||||
$lineIdExist = $item->line_id ?? '';
|
||||
|
||||
if ($lineIdExist) {
|
||||
|
||||
$line = Line::where('id', $lineIdExist)->where('plant_id', $plantId)->first();
|
||||
|
||||
if ($line) {
|
||||
$lineId = $line->id;
|
||||
} else {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Line not found!",
|
||||
], 404);
|
||||
}
|
||||
|
||||
} else {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Line not mapped for item code '$itemCode'!",
|
||||
], 404);
|
||||
}
|
||||
}
|
||||
|
||||
if ($scrapQty == null || $scrapQty == '') {
|
||||
$scrapQty = 0;
|
||||
}
|
||||
@@ -746,28 +889,6 @@ class PdfController extends Controller
|
||||
], 404);
|
||||
}
|
||||
|
||||
$line = Line::where('name', $lineName)->first();
|
||||
|
||||
if (! $line) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Line name '{$lineName}' not found!",
|
||||
], 404);
|
||||
}
|
||||
|
||||
$lineNamePlant = Line::where('name', $lineName)
|
||||
->where('plant_id', $plantId)
|
||||
->first();
|
||||
|
||||
if (! $lineNamePlant) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Line name '{$lineName}' not found for the plant code '{$plantCode}'!",
|
||||
], 404);
|
||||
}
|
||||
|
||||
$lineNamePlantId = $lineNamePlant->id;
|
||||
|
||||
if ($coilNo == null || $coilNo == '') {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
@@ -781,19 +902,12 @@ class PdfController extends Controller
|
||||
], 404);
|
||||
}
|
||||
|
||||
// if ($sfgNo == null || $sfgNo == '' || ! $sfgNo) {
|
||||
// return response()->json([
|
||||
// 'status_code' => 'ERROR',
|
||||
// 'status_description' => "SFG number can't be empty!",
|
||||
// ], 404);
|
||||
// }
|
||||
|
||||
// if ($machineId == null || $machineId == '' || ! $machineId) {
|
||||
// return response()->json([
|
||||
// 'status_code' => 'ERROR',
|
||||
// 'status_description' => "Machine ID can't be empty!",
|
||||
// ], 404);
|
||||
// }
|
||||
if ($operationNo == null || $operationNo == '' || ! $operationNo) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Operation Number can't be empty!",
|
||||
], 404);
|
||||
}
|
||||
|
||||
if ($createdBy == null || $createdBy == '' || ! $createdBy) {
|
||||
return response()->json([
|
||||
@@ -942,9 +1056,8 @@ class PdfController extends Controller
|
||||
|
||||
$existingCoil = ProcessOrder::where('plant_id', $plantId)
|
||||
->where('process_order', $processOrder)
|
||||
->where('line_id', $lineNamePlantId)
|
||||
->where('line_id', $lineId)
|
||||
->where('coil_number', $coilMain)
|
||||
// ->where('machine_name', $machineId)
|
||||
->first();
|
||||
|
||||
if (! $existingCoil) {
|
||||
@@ -968,16 +1081,15 @@ class PdfController extends Controller
|
||||
|
||||
$existingCoil = ProcessOrder::where('plant_id', $plantId)
|
||||
->where('process_order', $processOrder)
|
||||
->where('line_id', $lineNamePlantId)
|
||||
->where('line_id', $lineId)
|
||||
->where('coil_number', $coilNo)
|
||||
// ->where('machine_name', $machineId)
|
||||
->first();
|
||||
|
||||
if (! $existingCoil) {
|
||||
ProcessOrder::Create(
|
||||
[
|
||||
'plant_id' => $plantId,
|
||||
'line_id' => $lineNamePlantId,
|
||||
'line_id' => $lineId,
|
||||
'process_order' => $processOrder,
|
||||
'item_id' => $itemId,
|
||||
'coil_number' => $coilNo,
|
||||
@@ -987,6 +1099,7 @@ class PdfController extends Controller
|
||||
'scrap_quantity' => $scrapQty,
|
||||
'sfg_number' => $sfgNo,
|
||||
'machine_name' => $machineId,
|
||||
'operation_number' => $operationNo,
|
||||
'rework_status' => 1,
|
||||
'created_by' => $createdBy,
|
||||
]
|
||||
@@ -999,12 +1112,13 @@ class PdfController extends Controller
|
||||
} else {
|
||||
$updated = ProcessOrder::where('plant_id', $plantId)
|
||||
->where('process_order', $processOrder)
|
||||
->where('line_id', $lineNamePlantId)
|
||||
->where('line_id', $lineId)
|
||||
->where('coil_number', $coilNo)
|
||||
->update([
|
||||
// 'order_quantity' => $orderQty,
|
||||
'received_quantity' => $receivedQty,
|
||||
'scrap_quantity' => $scrapQty,
|
||||
'operation_number' => $operationNo,
|
||||
// 'sfg_number' => $sfgNo,
|
||||
// 'machine_name' => $machineId,
|
||||
'rework_status' => 1,
|
||||
@@ -1030,7 +1144,7 @@ class PdfController extends Controller
|
||||
|
||||
$existingCoil = ProcessOrder::where('plant_id', $plantId)
|
||||
->where('process_order', $processOrder)
|
||||
->where('line_id', $lineNamePlantId)
|
||||
->where('line_id', $lineId)
|
||||
->where('coil_number', $coilNo)
|
||||
->first();
|
||||
|
||||
@@ -1056,13 +1170,13 @@ class PdfController extends Controller
|
||||
|
||||
$updated = ProcessOrder::where('plant_id', $plantId)
|
||||
->where('process_order', $processOrder)
|
||||
->where('line_id', $lineNamePlantId)
|
||||
->where('line_id', $lineId)
|
||||
->where('coil_number', $coilNo)
|
||||
->where('machine_name', $machineId)
|
||||
->update([
|
||||
// 'order_quantity' => $orderQty,
|
||||
'received_quantity' => $receivedQty,
|
||||
'scrap_quantity' => $scrapQty,
|
||||
'operation_number' => $operationNo,
|
||||
// 'sfg_number' => $sfgNo,
|
||||
// 'machine_name' => $machineId,
|
||||
'rework_status' => 1,
|
||||
@@ -1093,14 +1207,12 @@ class PdfController extends Controller
|
||||
$existing = ProcessOrder::where('plant_id', $plantId)
|
||||
->where('process_order', $processOrder)
|
||||
->where('coil_number', $coilNo)
|
||||
->where('machine_name', $machineId)
|
||||
->first();
|
||||
|
||||
if ($existing) {
|
||||
return response()->json([
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Coil number '{$coilNo}' already exist against plant code '{$plantCode}' and process order '{$processOrder}'!",
|
||||
// "Process order '{$processOrder}' with coil number '{$coilNo}' already exist for the plant code '{$plantCode}'!",
|
||||
], 404);
|
||||
}
|
||||
|
||||
@@ -1129,7 +1241,7 @@ class PdfController extends Controller
|
||||
ProcessOrder::Create(
|
||||
[
|
||||
'plant_id' => $plantId,
|
||||
'line_id' => $lineNamePlantId,
|
||||
'line_id' => $lineId,
|
||||
'process_order' => $processOrder,
|
||||
'item_id' => $itemId,
|
||||
'coil_number' => $coilNo,
|
||||
@@ -1139,6 +1251,7 @@ class PdfController extends Controller
|
||||
'scrap_quantity' => $scrapQty,
|
||||
'sfg_number' => $sfgNo,
|
||||
'machine_name' => $machineId,
|
||||
'operation_number' => $operationNo,
|
||||
'rework_status' => 0,
|
||||
'created_by' => $createdBy,
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user