ranjith-dev #326
@@ -624,9 +624,7 @@ class InvoiceValidationResource extends Resource
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (! $validRowsFound) {
|
||||
} elseif (! $validRowsFound) {
|
||||
Notification::make()
|
||||
->title('Invalid Serial Invoice')
|
||||
->danger() // This makes the notification red to indicate an error
|
||||
@@ -641,9 +639,9 @@ class InvoiceValidationResource extends Resource
|
||||
|
||||
$uniqueCodes = array_unique($materialCodes);
|
||||
|
||||
$matchedItems = StickerMaster::with('item')
|
||||
->whereHas('item', function ($query) use ($uniqueCodes) {
|
||||
$query->whereIn('code', $uniqueCodes);
|
||||
$matchedItems = StickerMaster::with('item')->where('plant_id', $plantId)
|
||||
->whereHas('item', function ($query) use ($uniqueCodes, $plantId) {
|
||||
$query->whereIn('code', $uniqueCodes)->where('plant_id', $plantId);
|
||||
})
|
||||
->get();
|
||||
|
||||
@@ -654,7 +652,7 @@ class InvoiceValidationResource extends Resource
|
||||
if (! empty($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()
|
||||
->title('Unknown Item Codes')
|
||||
@@ -678,7 +676,7 @@ class InvoiceValidationResource extends Resource
|
||||
if (count($invalidCodes) > 10) {
|
||||
Notification::make()
|
||||
->title('Invalid item codes found')
|
||||
->body(''.count($invalidCodes).'item codes found have material type.')
|
||||
->body(''.count($invalidCodes).' item codes have material type.')
|
||||
->danger()
|
||||
->send();
|
||||
|
||||
@@ -920,9 +918,7 @@ class InvoiceValidationResource extends Resource
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (! empty($uniqueaplhaMat)) {
|
||||
} elseif (! empty($uniqueaplhaMat)) {
|
||||
Notification::make()
|
||||
->title('Invalid Material Quantity')
|
||||
->body('The following item codes material quantity must be a numeric values :<br>'.implode(', ', $uniqueaplhaMat))
|
||||
@@ -934,9 +930,7 @@ class InvoiceValidationResource extends Resource
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (! empty($uniqueZeroMat)) {
|
||||
} elseif (! empty($uniqueZeroMat)) {
|
||||
Notification::make()
|
||||
->title('Invalid Material Quantity')
|
||||
->body('The following item codes material quantity should be greater than 0:<br>'.implode(', ', $uniqueZeroMat))
|
||||
@@ -948,9 +942,7 @@ class InvoiceValidationResource extends Resource
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (! empty($uniqueEmptyMat)) {
|
||||
} elseif (! empty($uniqueEmptyMat)) {
|
||||
Notification::make()
|
||||
->title('Missing Material Quantity')
|
||||
->body("The following item codes doesn't have valid material quantity:<br>".implode(', ', $uniqueEmptyMat))
|
||||
@@ -962,9 +954,7 @@ class InvoiceValidationResource extends Resource
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (! $validRowsFound) {
|
||||
} elseif (! $validRowsFound) {
|
||||
Notification::make()
|
||||
->title('Invalid Material Invoice')
|
||||
->danger() // This makes the notification red to indicate an error
|
||||
@@ -980,9 +970,9 @@ class InvoiceValidationResource extends Resource
|
||||
|
||||
$uniqueCodes = array_unique($materialCodes);
|
||||
|
||||
$matchedItems = StickerMaster::with('item')
|
||||
->whereHas('item', function ($query) use ($uniqueCodes) {
|
||||
$query->whereIn('code', $uniqueCodes);
|
||||
$matchedItems = StickerMaster::with('item')->where('plant_id', $plantId)
|
||||
->whereHas('item', function ($query) use ($uniqueCodes, $plantId) {
|
||||
$query->whereIn('code', $uniqueCodes)->where('plant_id', $plantId);
|
||||
})
|
||||
->get();
|
||||
|
||||
@@ -993,9 +983,7 @@ class InvoiceValidationResource extends Resource
|
||||
if (! empty($missingCodes)) {
|
||||
$missingCount = count($missingCodes);
|
||||
|
||||
$message = $missingCount > 10
|
||||
? "'$missingCount' Item Codes are not found in sticker master."
|
||||
: 'Item Codes are not found in sticker master:<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()
|
||||
->title('Unknown Item Codes')
|
||||
@@ -1019,7 +1007,7 @@ class InvoiceValidationResource extends Resource
|
||||
$invalidCodes = array_unique($invalidCodes);
|
||||
Notification::make()
|
||||
->title('Invalid item codes found')
|
||||
->body(''.count($invalidCodes).'invalid item codes found have serial number.')
|
||||
->body(''.count($invalidCodes).' item codes have serial type.')
|
||||
->danger()
|
||||
->send();
|
||||
|
||||
|
||||
@@ -8,9 +8,6 @@ use Illuminate\Http\Request;
|
||||
|
||||
class CharacteristicApprovalController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function approve(Request $request)
|
||||
{
|
||||
return $this->updateStatus($request, 'Approved');
|
||||
@@ -55,11 +52,30 @@ class CharacteristicApprovalController extends Controller
|
||||
foreach ($levels as $lvl => $column) {
|
||||
if ($lvl != $level && in_array($record->$column, ['Approved', 'Rejected'])) {
|
||||
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 = [
|
||||
1 => 'Sent',
|
||||
2 => 'Sent-Mail2',
|
||||
@@ -69,8 +85,8 @@ class CharacteristicApprovalController extends Controller
|
||||
$expectedMailStatus = $allowedMailStatusByLevel[$level] ?? null;
|
||||
|
||||
if ($record->mail_status != $expectedMailStatus) {
|
||||
return view('approval.already-processed', [
|
||||
'status' => 'You are not authorized to act at this level',
|
||||
return view('approval.approve-level', [
|
||||
'status' => 'Your approval time limit has expired.',
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -80,7 +96,6 @@ class CharacteristicApprovalController extends Controller
|
||||
public function rejectForm(Request $request)
|
||||
{
|
||||
$id = $request->query('id');
|
||||
// $level = $request->query('level');
|
||||
$level = (int) $request->query('level');
|
||||
|
||||
$record = RequestCharacteristic::findOrFail($id);
|
||||
@@ -111,11 +126,30 @@ class CharacteristicApprovalController extends Controller
|
||||
foreach ($levels as $lvl => $column) {
|
||||
if ($lvl != $level && in_array($record->$column, ['Approved', 'Rejected'])) {
|
||||
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 = [
|
||||
1 => 'Sent',
|
||||
2 => 'Sent-Mail2',
|
||||
@@ -125,14 +159,90 @@ class CharacteristicApprovalController extends Controller
|
||||
$expectedMailStatus = $allowedMailStatusByLevel[$level] ?? null;
|
||||
|
||||
if ($record->mail_status != $expectedMailStatus) {
|
||||
return view('approval.already-processed', [
|
||||
'status' => 'You are not authorized to act at this level',
|
||||
return view('approval.approve-level', [
|
||||
'status'=> $currentStatus,
|
||||
'message' => 'Your approval time limit has expired.',
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
$request->validate([
|
||||
@@ -155,6 +265,17 @@ class CharacteristicApprovalController extends Controller
|
||||
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)
|
||||
{
|
||||
$requestId = $request->input('id');
|
||||
@@ -189,19 +310,27 @@ class CharacteristicApprovalController extends Controller
|
||||
})
|
||||
->get();
|
||||
|
||||
$alreadyProcessed = RequestCharacteristic::whereIn($statusColumn, ['Approved', 'Rejected'])->exists();
|
||||
$currentStatus = $record->$statusColumn;
|
||||
|
||||
if ($alreadyProcessed) {
|
||||
if ($returnView) {
|
||||
$levels = [
|
||||
1 => 'approver_status1',
|
||||
2 => 'approver_status2',
|
||||
3 => 'approver_status3',
|
||||
];
|
||||
|
||||
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' => 'Already processed',
|
||||
'status' => $record->$column,
|
||||
'message' => 'your request has already been processed by another approver',
|
||||
]);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'status' => false,
|
||||
'message' => 'This request has already been processed.',
|
||||
], 404);
|
||||
}
|
||||
|
||||
$allowedMailStatusByLevel = [
|
||||
@@ -214,8 +343,9 @@ class CharacteristicApprovalController extends Controller
|
||||
|
||||
if ($record->mail_status != $expectedMailStatus) {
|
||||
if ($returnView) {
|
||||
return view('approval.already-processed', [
|
||||
'status' => 'You are not authorized to act at this level',
|
||||
return view('approval.approve-level', [
|
||||
'status' => $currentStatus,
|
||||
'message' => 'Your approval time limit has expired.',
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -225,16 +355,20 @@ class CharacteristicApprovalController extends Controller
|
||||
], 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 = [
|
||||
$statusColumn => $status,
|
||||
$remarkColumn => $request->input('remark'),
|
||||
$approvedAtColumn => Carbon::now(),
|
||||
];
|
||||
|
||||
// if ($status == 'Approved') {
|
||||
// $updateData[$approvedAtColumn] = Carbon::now();
|
||||
// }
|
||||
|
||||
foreach ($pendingRecords as $rec) {
|
||||
$rec->update($updateData);
|
||||
}
|
||||
@@ -243,6 +377,10 @@ class CharacteristicApprovalController extends Controller
|
||||
$recd->update($updateData);
|
||||
}
|
||||
|
||||
foreach ($workflowRecords as $r) {
|
||||
$r->update($updateData);
|
||||
}
|
||||
|
||||
if ($returnView) {
|
||||
return match ($status) {
|
||||
'Approved' => view('approval.success'),
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user