4 Commits

Author SHA1 Message Date
2a2bf8db4c Merge pull request 'ranjith-dev' (#326) from ranjith-dev into master
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled
Reviewed-on: #326
2026-02-10 10:52:08 +00:00
dhanabalan
d885af0843 Updated item code validations and warning messages on import
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled
Gemini PR Review / Gemini PR Review (pull_request) Has been cancelled
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Has been cancelled
Laravel Larastan / larastan (pull_request) Has been cancelled
Laravel Pint / pint (pull_request) Has been cancelled
2026-02-10 16:03:36 +05:30
dhanabalan
54e1404ff7 Refactor approval process: enhance hold and reject forms, improve status messages, and add approveSave method
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled
2026-02-10 14:38:38 +05:30
dhanabalan
4da20051f6 Added request-type parameter and some validation on GET and POST
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled
2026-02-10 14:36:49 +05:30
3 changed files with 1094 additions and 1198 deletions

View File

@@ -624,9 +624,7 @@ class InvoiceValidationResource extends Resource
} }
return; return;
} } elseif (! $validRowsFound) {
if (! $validRowsFound) {
Notification::make() Notification::make()
->title('Invalid Serial Invoice') ->title('Invalid Serial Invoice')
->danger() // This makes the notification red to indicate an error ->danger() // This makes the notification red to indicate an error
@@ -641,9 +639,9 @@ class InvoiceValidationResource extends Resource
$uniqueCodes = array_unique($materialCodes); $uniqueCodes = array_unique($materialCodes);
$matchedItems = StickerMaster::with('item') $matchedItems = StickerMaster::with('item')->where('plant_id', $plantId)
->whereHas('item', function ($query) use ($uniqueCodes) { ->whereHas('item', function ($query) use ($uniqueCodes, $plantId) {
$query->whereIn('code', $uniqueCodes); $query->whereIn('code', $uniqueCodes)->where('plant_id', $plantId);
}) })
->get(); ->get();
@@ -654,7 +652,7 @@ class InvoiceValidationResource extends Resource
if (! empty($missingCodes)) { if (! empty($missingCodes)) {
$missingCount = count($missingCodes); $missingCount = count($missingCodes);
$message = $missingCount > 10 ? "'$missingCount' item codes are not found in database." : 'The following item codes are not found in database:<br>'.implode(', ', $missingCodes); $message = $missingCount > 10 ? "'$missingCount' item codes are not found in sticker master." : 'The following item codes are not found in sticker master:<br>'.implode(', ', $missingCodes);
Notification::make() Notification::make()
->title('Unknown Item Codes') ->title('Unknown Item Codes')
@@ -678,7 +676,7 @@ class InvoiceValidationResource extends Resource
if (count($invalidCodes) > 10) { if (count($invalidCodes) > 10) {
Notification::make() Notification::make()
->title('Invalid item codes found') ->title('Invalid item codes found')
->body(''.count($invalidCodes).'item codes found have material type.') ->body(''.count($invalidCodes).' item codes have material type.')
->danger() ->danger()
->send(); ->send();
@@ -920,9 +918,7 @@ class InvoiceValidationResource extends Resource
} }
return; return;
} } elseif (! empty($uniqueaplhaMat)) {
if (! empty($uniqueaplhaMat)) {
Notification::make() Notification::make()
->title('Invalid Material Quantity') ->title('Invalid Material Quantity')
->body('The following item codes material quantity must be a numeric values :<br>'.implode(', ', $uniqueaplhaMat)) ->body('The following item codes material quantity must be a numeric values :<br>'.implode(', ', $uniqueaplhaMat))
@@ -934,9 +930,7 @@ class InvoiceValidationResource extends Resource
} }
return; return;
} } elseif (! empty($uniqueZeroMat)) {
if (! empty($uniqueZeroMat)) {
Notification::make() Notification::make()
->title('Invalid Material Quantity') ->title('Invalid Material Quantity')
->body('The following item codes material quantity should be greater than 0:<br>'.implode(', ', $uniqueZeroMat)) ->body('The following item codes material quantity should be greater than 0:<br>'.implode(', ', $uniqueZeroMat))
@@ -948,9 +942,7 @@ class InvoiceValidationResource extends Resource
} }
return; return;
} } elseif (! empty($uniqueEmptyMat)) {
if (! empty($uniqueEmptyMat)) {
Notification::make() Notification::make()
->title('Missing Material Quantity') ->title('Missing Material Quantity')
->body("The following item codes doesn't have valid material quantity:<br>".implode(', ', $uniqueEmptyMat)) ->body("The following item codes doesn't have valid material quantity:<br>".implode(', ', $uniqueEmptyMat))
@@ -962,9 +954,7 @@ class InvoiceValidationResource extends Resource
} }
return; return;
} } elseif (! $validRowsFound) {
if (! $validRowsFound) {
Notification::make() Notification::make()
->title('Invalid Material Invoice') ->title('Invalid Material Invoice')
->danger() // This makes the notification red to indicate an error ->danger() // This makes the notification red to indicate an error
@@ -980,9 +970,9 @@ class InvoiceValidationResource extends Resource
$uniqueCodes = array_unique($materialCodes); $uniqueCodes = array_unique($materialCodes);
$matchedItems = StickerMaster::with('item') $matchedItems = StickerMaster::with('item')->where('plant_id', $plantId)
->whereHas('item', function ($query) use ($uniqueCodes) { ->whereHas('item', function ($query) use ($uniqueCodes, $plantId) {
$query->whereIn('code', $uniqueCodes); $query->whereIn('code', $uniqueCodes)->where('plant_id', $plantId);
}) })
->get(); ->get();
@@ -993,9 +983,7 @@ class InvoiceValidationResource extends Resource
if (! empty($missingCodes)) { if (! empty($missingCodes)) {
$missingCount = count($missingCodes); $missingCount = count($missingCodes);
$message = $missingCount > 10 $message = $missingCount > 10 ? "'$missingCount' item codes are not found in sticker master." : 'The following item codes are not found in sticker master:<br>'.implode(', ', $missingCodes);
? "'$missingCount' Item Codes are not found in sticker master."
: 'Item Codes are not found in sticker master:<br>'.implode(', ', $missingCodes);
Notification::make() Notification::make()
->title('Unknown Item Codes') ->title('Unknown Item Codes')
@@ -1019,7 +1007,7 @@ class InvoiceValidationResource extends Resource
$invalidCodes = array_unique($invalidCodes); $invalidCodes = array_unique($invalidCodes);
Notification::make() Notification::make()
->title('Invalid item codes found') ->title('Invalid item codes found')
->body(''.count($invalidCodes).'invalid item codes found have serial number.') ->body(''.count($invalidCodes).' item codes have serial type.')
->danger() ->danger()
->send(); ->send();

View File

@@ -8,9 +8,6 @@ use Illuminate\Http\Request;
class CharacteristicApprovalController extends Controller class CharacteristicApprovalController extends Controller
{ {
/**
* Display a listing of the resource.
*/
public function approve(Request $request) public function approve(Request $request)
{ {
return $this->updateStatus($request, 'Approved'); return $this->updateStatus($request, 'Approved');
@@ -55,11 +52,30 @@ class CharacteristicApprovalController extends Controller
foreach ($levels as $lvl => $column) { foreach ($levels as $lvl => $column) {
if ($lvl != $level && in_array($record->$column, ['Approved', 'Rejected'])) { if ($lvl != $level && in_array($record->$column, ['Approved', 'Rejected'])) {
return view('approval.already-processed', [ return view('approval.already-processed', [
'status' => 'Already processed by another approver', 'status' => $record->$column,
'message' => 'Your request has already been processed by another approver',
]); ]);
} }
} }
// foreach ($levels as $lvl => $column) {
// if ($record->$column == 'Hold') {
// if ($lvl == $level) {
// return view('approval.already-processed', [
// 'status' => 'On Hold',
// ]);
// }
// else
// {
// return view('approval.already-processed', [
// 'status' => 'Hold',
// 'message' => 'On Hold',
// ]);
// }
// }
// }
$allowedMailStatusByLevel = [ $allowedMailStatusByLevel = [
1 => 'Sent', 1 => 'Sent',
2 => 'Sent-Mail2', 2 => 'Sent-Mail2',
@@ -69,8 +85,8 @@ class CharacteristicApprovalController extends Controller
$expectedMailStatus = $allowedMailStatusByLevel[$level] ?? null; $expectedMailStatus = $allowedMailStatusByLevel[$level] ?? null;
if ($record->mail_status != $expectedMailStatus) { if ($record->mail_status != $expectedMailStatus) {
return view('approval.already-processed', [ return view('approval.approve-level', [
'status' => 'You are not authorized to act at this level', 'status' => 'Your approval time limit has expired.',
]); ]);
} }
@@ -80,7 +96,6 @@ class CharacteristicApprovalController extends Controller
public function rejectForm(Request $request) public function rejectForm(Request $request)
{ {
$id = $request->query('id'); $id = $request->query('id');
// $level = $request->query('level');
$level = (int) $request->query('level'); $level = (int) $request->query('level');
$record = RequestCharacteristic::findOrFail($id); $record = RequestCharacteristic::findOrFail($id);
@@ -111,11 +126,30 @@ class CharacteristicApprovalController extends Controller
foreach ($levels as $lvl => $column) { foreach ($levels as $lvl => $column) {
if ($lvl != $level && in_array($record->$column, ['Approved', 'Rejected'])) { if ($lvl != $level && in_array($record->$column, ['Approved', 'Rejected'])) {
return view('approval.already-processed', [ return view('approval.already-processed', [
'status' => 'Already processed by another approver', 'status' => $record->$column,
'message' => 'Your request has already been processed by another approver',
]); ]);
} }
} }
// foreach ($levels as $lvl => $column) {
// if ($record->$column == 'Hold') {
// if ($lvl == $level) {
// return view('approval.reject-form', compact('id', 'level'));
// }
// else
// {
// return view('approval.already-processed', [
// 'status' => 'Hold',
// 'message' => 'On Hold',
// ]);
// }
// }
// }
$allowedMailStatusByLevel = [ $allowedMailStatusByLevel = [
1 => 'Sent', 1 => 'Sent',
2 => 'Sent-Mail2', 2 => 'Sent-Mail2',
@@ -125,14 +159,90 @@ class CharacteristicApprovalController extends Controller
$expectedMailStatus = $allowedMailStatusByLevel[$level] ?? null; $expectedMailStatus = $allowedMailStatusByLevel[$level] ?? null;
if ($record->mail_status != $expectedMailStatus) { if ($record->mail_status != $expectedMailStatus) {
return view('approval.already-processed', [ return view('approval.approve-level', [
'status' => 'You are not authorized to act at this level', 'status'=> $currentStatus,
'message' => 'Your approval time limit has expired.',
]); ]);
} }
return view('approval.reject-form', compact('id', 'level')); return view('approval.reject-form', compact('id', 'level'));
} }
public function approveForm(Request $request)
{
$id = $request->query('id');
$level = (int) $request->query('level');
$record = RequestCharacteristic::findOrFail($id);
[$statusColumn, $approvedAtColumn, $remarkColumn] = match ($level) {
1 => ['approver_status1', 'approved1_at', 'approver_remark1'],
2 => ['approver_status2', 'approved2_at', 'approver_remark2'],
3 => ['approver_status3', 'approved3_at', 'approver_remark3'],
default => abort(403, 'Invalid approver level'),
};
$levels = [
1 => 'approver_status1',
2 => 'approver_status2',
3 => 'approver_status3',
];
$currentStatusColumn = $levels[$level];
$currentStatus = $record->$statusColumn;
if (in_array($currentStatus, ['Approved', 'Rejected'])) {
return view('approval.already-processed', [
'status' => $currentStatus,
]);
}
foreach ($levels as $lvl => $column) {
if ($lvl != $level && in_array($record->$column, ['Approved', 'Rejected'])) {
return view('approval.already-processed', [
'status' => $record->$column,
'message' => 'Your request has already been processed by another approver',
]);
}
}
// foreach ($levels as $lvl => $column) {
// if ($record->$column == 'Hold') {
// if ($lvl == $level) {
// return view('approval.reject-form', compact('id', 'level'));
// }
// else
// {
// return view('approval.already-processed', [
// 'status' => 'Hold',
// 'message' => 'On Hold',
// ]);
// }
// }
// }
$allowedMailStatusByLevel = [
1 => 'Sent',
2 => 'Sent-Mail2',
3 => 'Sent-Mail3',
];
$expectedMailStatus = $allowedMailStatusByLevel[$level] ?? null;
if ($record->mail_status != $expectedMailStatus) {
return view('approval.approve-level', [
'status'=> $currentStatus,
'message' => 'Your approval time limit has expired.',
]);
}
return view('approval.approve-form', compact('id', 'level'));
}
public function holdSave(Request $request) public function holdSave(Request $request)
{ {
$request->validate([ $request->validate([
@@ -155,6 +265,17 @@ class CharacteristicApprovalController extends Controller
return $this->updateStatus($request, 'Rejected', false); return $this->updateStatus($request, 'Rejected', false);
} }
public function approveSave(Request $request)
{
$request->validate([
'id' => 'required|integer',
'level' => 'required|integer',
'remark' => 'nullable|string',
]);
return $this->updateStatus($request, 'Approved', false);
}
protected function updateStatus(Request $request, string $status, bool $returnView = true) protected function updateStatus(Request $request, string $status, bool $returnView = true)
{ {
$requestId = $request->input('id'); $requestId = $request->input('id');
@@ -189,19 +310,27 @@ class CharacteristicApprovalController extends Controller
}) })
->get(); ->get();
$alreadyProcessed = RequestCharacteristic::whereIn($statusColumn, ['Approved', 'Rejected'])->exists(); $currentStatus = $record->$statusColumn;
if ($alreadyProcessed) { $levels = [
if ($returnView) { 1 => 'approver_status1',
2 => 'approver_status2',
3 => 'approver_status3',
];
if (in_array($currentStatus, ['Approved', 'Rejected'])) {
return view('approval.already-processed', [ return view('approval.already-processed', [
'status' => 'Already processed', 'status' => $currentStatus,
]); ]);
} }
return response()->json([ foreach ($levels as $lvl => $column) {
'status' => false, if ($lvl != $level && in_array($record->$column, ['Approved', 'Rejected'])) {
'message' => 'This request has already been processed.', return view('approval.already-processed', [
], 404); 'status' => $record->$column,
'message' => 'your request has already been processed by another approver',
]);
}
} }
$allowedMailStatusByLevel = [ $allowedMailStatusByLevel = [
@@ -214,8 +343,9 @@ class CharacteristicApprovalController extends Controller
if ($record->mail_status != $expectedMailStatus) { if ($record->mail_status != $expectedMailStatus) {
if ($returnView) { if ($returnView) {
return view('approval.already-processed', [ return view('approval.approve-level', [
'status' => 'You are not authorized to act at this level', 'status' => $currentStatus,
'message' => 'Your approval time limit has expired.',
]); ]);
} }
@@ -225,16 +355,20 @@ class CharacteristicApprovalController extends Controller
], 403); ], 403);
} }
$workflowRecords = RequestCharacteristic::where('plant_id', $record->plant_id)
->where('machine_id', $record->machine_id)
->where('aufnr', $record->aufnr)
->where('work_flow_id', $record->work_flow_id)
->get();
$updateData = [ $updateData = [
$statusColumn => $status, $statusColumn => $status,
$remarkColumn => $request->input('remark'), $remarkColumn => $request->input('remark'),
$approvedAtColumn => Carbon::now(), $approvedAtColumn => Carbon::now(),
]; ];
// if ($status == 'Approved') {
// $updateData[$approvedAtColumn] = Carbon::now();
// }
foreach ($pendingRecords as $rec) { foreach ($pendingRecords as $rec) {
$rec->update($updateData); $rec->update($updateData);
} }
@@ -243,6 +377,10 @@ class CharacteristicApprovalController extends Controller
$recd->update($updateData); $recd->update($updateData);
} }
foreach ($workflowRecords as $r) {
$r->update($updateData);
}
if ($returnView) { if ($returnView) {
return match ($status) { return match ($status) {
'Approved' => view('approval.success'), 'Approved' => view('approval.success'),

File diff suppressed because it is too large Load Diff