Added automatic rejection logic and added template quality characteristics
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled
This commit is contained in:
@@ -5,9 +5,12 @@ namespace App\Console\Commands;
|
|||||||
use App\Mail\CharacteristicApprovalMail;
|
use App\Mail\CharacteristicApprovalMail;
|
||||||
use App\Models\CharacteristicApproverMaster;
|
use App\Models\CharacteristicApproverMaster;
|
||||||
use App\Models\RequestCharacteristic;
|
use App\Models\RequestCharacteristic;
|
||||||
|
use App\Models\TempClassCharacteristic;
|
||||||
|
// use App\Models\TempClassCharacteristic;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use Illuminate\Support\Facades\Mail;
|
use Illuminate\Support\Facades\Mail;
|
||||||
use Illuminate\Support\Carbon;
|
use Illuminate\Support\Carbon;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
class TriggerPendingApprovalMails extends Command
|
class TriggerPendingApprovalMails extends Command
|
||||||
{
|
{
|
||||||
@@ -40,6 +43,8 @@ class TriggerPendingApprovalMails extends Command
|
|||||||
|
|
||||||
public $subjectLine;
|
public $subjectLine;
|
||||||
|
|
||||||
|
// public $tempCharacteristics = [];
|
||||||
|
|
||||||
public $wfId;
|
public $wfId;
|
||||||
|
|
||||||
public function handle()
|
public function handle()
|
||||||
@@ -195,6 +200,38 @@ class TriggerPendingApprovalMails extends Command
|
|||||||
$updateData['mail_status'] = 'Sent-Mail3';
|
$updateData['mail_status'] = 'Sent-Mail3';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$totalMinutes =
|
||||||
|
$this->convertToMinutes($approver->duration1 ?? 0) +
|
||||||
|
$this->convertToMinutes($approver->duration2 ?? 0) +
|
||||||
|
$this->convertToMinutes($approver->duration3 ?? 0);
|
||||||
|
|
||||||
|
$expiryTime = Carbon::parse($first->created_at)
|
||||||
|
->copy()
|
||||||
|
->addMinutes($totalMinutes);
|
||||||
|
|
||||||
|
$ids = $groupRecords->pluck('id');
|
||||||
|
|
||||||
|
$this->info("Expiry Time for ID {$first->id}: {$expiryTime}, Now: {$now}");
|
||||||
|
|
||||||
|
// --- AUTO REJECT ---
|
||||||
|
if (
|
||||||
|
$first->mail_status == 'Sent-Mail3' &&
|
||||||
|
(is_null($first->approver_status1) || $first->approver_status1 == 'Hold') &&
|
||||||
|
(is_null($first->approver_status2) || $first->approver_status2 == 'Hold') &&
|
||||||
|
(is_null($first->approver_status3) || $first->approver_status3 == 'Hold') &&
|
||||||
|
$now->gte($expiryTime)
|
||||||
|
) {
|
||||||
|
RequestCharacteristic::whereIn('id', $ids)
|
||||||
|
->update([
|
||||||
|
'approver_status3' => 'Rejected',
|
||||||
|
'approver_remark3' => 'Time Limit Reached',
|
||||||
|
'approved3_at' => now(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->info("Auto Rejected ID: {$first->id}");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (!$level || !$mail) {
|
if (!$level || !$mail) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -203,6 +240,8 @@ class TriggerPendingApprovalMails extends Command
|
|||||||
|
|
||||||
$subjectLine = 'Characteristic Approval Mail';
|
$subjectLine = 'Characteristic Approval Mail';
|
||||||
|
|
||||||
|
// $emails = array_map('trim', explode(',', $mail));
|
||||||
|
|
||||||
Mail::to($mail)->send(
|
Mail::to($mail)->send(
|
||||||
new CharacteristicApprovalMail(
|
new CharacteristicApprovalMail(
|
||||||
$first,
|
$first,
|
||||||
@@ -251,6 +290,23 @@ class TriggerPendingApprovalMails extends Command
|
|||||||
return $approver && $approver->approver_type == 'Quality';
|
return $approver && $approver->approver_type == 'Quality';
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// $approvers = CharacteristicApproverMaster::where('approver_type', 'Quality')
|
||||||
|
// ->get()
|
||||||
|
// ->keyBy('id');
|
||||||
|
|
||||||
|
// $qualityRecords = RequestCharacteristic::where(function ($q) {
|
||||||
|
// $q->whereNull('approver_status1')->orWhere('approver_status1', 'Hold');
|
||||||
|
// })
|
||||||
|
// ->where(function ($q) {
|
||||||
|
// $q->whereNull('approver_status2')->orWhere('approver_status2', 'Hold');
|
||||||
|
// })
|
||||||
|
// ->where(function ($q) {
|
||||||
|
// $q->whereNull('approver_status3')->orWhere('approver_status3', 'Hold');
|
||||||
|
// })
|
||||||
|
// ->whereIn('characteristic_approver_master_id', $approvers->keys())
|
||||||
|
// ->get();
|
||||||
|
|
||||||
|
|
||||||
if ($qualityRecords->isEmpty()) {
|
if ($qualityRecords->isEmpty()) {
|
||||||
$this->info('No quality pending approvals');
|
$this->info('No quality pending approvals');
|
||||||
return;
|
return;
|
||||||
@@ -283,6 +339,43 @@ class TriggerPendingApprovalMails extends Command
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$columns = Schema::getColumnListing('temp_class_characteristics');
|
||||||
|
|
||||||
|
$exclude = ['id', 'plant_id', 'machine_id', 'item_id', 'aufnr', 'class', 'arbid', 'gamng', 'lmnga', 'zz1_cn_bill_ord', 'zmm_heading', 'created_at', 'updated_at', 'deleted_at', 'has_work_flow_id', 'model_type', 'created_by', 'updated_by' ];
|
||||||
|
|
||||||
|
$filteredColumns = array_diff($columns, $exclude);
|
||||||
|
|
||||||
|
$row1 = TempClassCharacteristic::where('plant_id', $first->plant_id)
|
||||||
|
->where('machine_id', $first->machine_id)
|
||||||
|
->where('aufnr', $first->aufnr)
|
||||||
|
->where('model_type', $first->model_type)
|
||||||
|
->latest()
|
||||||
|
->first();
|
||||||
|
|
||||||
|
$this->info(json_encode([
|
||||||
|
'id' => $row1->id,
|
||||||
|
'plant_id' => $row1->plant_id,
|
||||||
|
'machine_id' => $row1->machine_id,
|
||||||
|
'aufnr' => $row1->aufnr,
|
||||||
|
'motor_speed' => $row1->zmm_motor_speed,
|
||||||
|
'all_data' => $row1->toArray(),
|
||||||
|
]));
|
||||||
|
|
||||||
|
$data = [];
|
||||||
|
|
||||||
|
if ($row1) {
|
||||||
|
foreach ($filteredColumns as $column) {
|
||||||
|
|
||||||
|
$value = $row1->getAttribute($column);
|
||||||
|
|
||||||
|
if ($value != null && $value != '') {
|
||||||
|
$data[$column] = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$characteristics = $data;
|
||||||
|
|
||||||
$level = null;
|
$level = null;
|
||||||
$mail = null;
|
$mail = null;
|
||||||
$name = null;
|
$name = null;
|
||||||
@@ -359,6 +452,38 @@ class TriggerPendingApprovalMails extends Command
|
|||||||
$updateData['mail_status'] = 'Sent-Mail3';
|
$updateData['mail_status'] = 'Sent-Mail3';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$totalMinutes =
|
||||||
|
$this->convertToMinutes($approver->duration1 ?? 0) +
|
||||||
|
$this->convertToMinutes($approver->duration2 ?? 0) +
|
||||||
|
$this->convertToMinutes($approver->duration3 ?? 0);
|
||||||
|
|
||||||
|
$expiryTime = Carbon::parse($first->created_at)
|
||||||
|
->copy()
|
||||||
|
->addMinutes($totalMinutes);
|
||||||
|
|
||||||
|
$ids = $groupRecords->pluck('id');
|
||||||
|
|
||||||
|
$this->info("Expiry Time for ID {$first->id}: {$expiryTime}, Now: {$now}");
|
||||||
|
|
||||||
|
// --- AUTO REJECT ---
|
||||||
|
if (
|
||||||
|
$first->mail_status == 'Sent-Mail3' &&
|
||||||
|
(is_null($first->approver_status1) || $first->approver_status1 == 'Hold') &&
|
||||||
|
(is_null($first->approver_status2) || $first->approver_status2 == 'Hold') &&
|
||||||
|
(is_null($first->approver_status3) || $first->approver_status3 == 'Hold') &&
|
||||||
|
$now->gte($expiryTime)
|
||||||
|
) {
|
||||||
|
RequestCharacteristic::whereIn('id', $ids)
|
||||||
|
->update([
|
||||||
|
'approver_status3' => 'Rejected',
|
||||||
|
'approver_remark3' => 'Time Limit Reached',
|
||||||
|
'approved3_at' => now(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->info("Auto Rejected ID: {$first->id}");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (!$level || !$mail) {
|
if (!$level || !$mail) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -381,8 +506,8 @@ class TriggerPendingApprovalMails extends Command
|
|||||||
$pdfPath,
|
$pdfPath,
|
||||||
$pendingApprovers,
|
$pendingApprovers,
|
||||||
$approverNameFromMaster,
|
$approverNameFromMaster,
|
||||||
$subjectLine
|
$subjectLine,
|
||||||
// $characteristics
|
$characteristics
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -406,4 +531,16 @@ class TriggerPendingApprovalMails extends Command
|
|||||||
|
|
||||||
$this->info('Approval mail job completed');
|
$this->info('Approval mail job completed');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function convertToMinutes($duration)
|
||||||
|
{
|
||||||
|
if (!$duration) return 0;
|
||||||
|
|
||||||
|
$parts = explode('.', (string)$duration);
|
||||||
|
|
||||||
|
$hours = (int)($parts[0] ?? 0);
|
||||||
|
$minutes = (int)($parts[1] ?? 0);
|
||||||
|
|
||||||
|
return ($hours * 60) + $minutes;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user