feat(cooperation): auto reject when media not responding
This commit is contained in:
parent
f038da6735
commit
7915e1ce38
@ -2,8 +2,10 @@
|
|||||||
|
|
||||||
namespace App\Console\Commands;
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
use App\Enums\ApprovalStatus;
|
||||||
use App\Enums\CooperationStatus;
|
use App\Enums\CooperationStatus;
|
||||||
use App\Models\Cooperation;
|
use App\Models\Cooperation;
|
||||||
|
use App\Models\CooperationMedia;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
@ -36,6 +38,17 @@ public function handle()
|
|||||||
Log::info('Running UpdateCooperationStatusJob at '.now());
|
Log::info('Running UpdateCooperationStatusJob at '.now());
|
||||||
|
|
||||||
// 1. PENDING -> ASSIGNMENT (final_submission_date)
|
// 1. PENDING -> ASSIGNMENT (final_submission_date)
|
||||||
|
// Automatically reject media that haven't responded
|
||||||
|
$rejectedPendingMedia = CooperationMedia::whereHas('cooperation', function ($query) use ($today) {
|
||||||
|
$query->pending()->whereDate('final_submission_date', '<=', $today);
|
||||||
|
})
|
||||||
|
->pending()
|
||||||
|
->update(['status' => ApprovalStatus::REJECTED]);
|
||||||
|
|
||||||
|
if ($rejectedPendingMedia > 0) {
|
||||||
|
Log::info("Updated {$rejectedPendingMedia} media in PENDING cooperations to REJECTED because they didn't respond before final_submission_date.");
|
||||||
|
}
|
||||||
|
|
||||||
$updatedPending = Cooperation::pending()
|
$updatedPending = Cooperation::pending()
|
||||||
->whereDate('final_submission_date', '<=', $today)
|
->whereDate('final_submission_date', '<=', $today)
|
||||||
->update(['status' => CooperationStatus::ASSIGNMENT]);
|
->update(['status' => CooperationStatus::ASSIGNMENT]);
|
||||||
@ -45,6 +58,17 @@ public function handle()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 2. ASSIGNMENT -> VERIFICATION (assignment_deadline)
|
// 2. ASSIGNMENT -> VERIFICATION (assignment_deadline)
|
||||||
|
// Automatically reject media that haven't responded
|
||||||
|
$rejectedMedia = CooperationMedia::whereHas('cooperation', function ($query) use ($today) {
|
||||||
|
$query->assignment()->whereDate('assignment_deadline', '<=', $today);
|
||||||
|
})
|
||||||
|
->pending()
|
||||||
|
->update(['status' => ApprovalStatus::REJECTED]);
|
||||||
|
|
||||||
|
if ($rejectedMedia > 0) {
|
||||||
|
Log::info("Updated {$rejectedMedia} media assignments to REJECTED because they didn't respond before the deadline.");
|
||||||
|
}
|
||||||
|
|
||||||
$updatedAssignment = Cooperation::assignment()
|
$updatedAssignment = Cooperation::assignment()
|
||||||
->whereDate('assignment_deadline', '<=', $today)
|
->whereDate('assignment_deadline', '<=', $today)
|
||||||
->update(['status' => CooperationStatus::VERIFICATION]);
|
->update(['status' => CooperationStatus::VERIFICATION]);
|
||||||
@ -54,6 +78,17 @@ public function handle()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 3. VERIFICATION -> PAYMENT (verification_deadline)
|
// 3. VERIFICATION -> PAYMENT (verification_deadline)
|
||||||
|
// Automatically reject media that haven't responded
|
||||||
|
$rejectedVerificationMedia = CooperationMedia::whereHas('cooperation', function ($query) use ($today) {
|
||||||
|
$query->verification()->whereDate('verification_deadline', '<=', $today);
|
||||||
|
})
|
||||||
|
->pending()
|
||||||
|
->update(['status' => ApprovalStatus::REJECTED]);
|
||||||
|
|
||||||
|
if ($rejectedVerificationMedia > 0) {
|
||||||
|
Log::info("Updated {$rejectedVerificationMedia} media in VERIFICATION cooperations to REJECTED because they didn't respond before verification_deadline.");
|
||||||
|
}
|
||||||
|
|
||||||
$updatedVerification = Cooperation::verification()
|
$updatedVerification = Cooperation::verification()
|
||||||
->whereDate('verification_deadline', '<=', $today)
|
->whereDate('verification_deadline', '<=', $today)
|
||||||
->update(['status' => CooperationStatus::PAYMENT]);
|
->update(['status' => CooperationStatus::PAYMENT]);
|
||||||
|
|||||||
@ -53,10 +53,10 @@ public static function configure(Table $table): Table
|
|||||||
->sortable()
|
->sortable()
|
||||||
->date('l, d F Y')
|
->date('l, d F Y')
|
||||||
->description(
|
->description(
|
||||||
fn (Cooperation $record): string => now()->greaterThan($record->final_submission_date)
|
fn (Cooperation $record): string => now()->greaterThan($record->final_submission_date->copy()->endOfDay())
|
||||||
? 'Waktu Pengajuan Habis'
|
? 'Waktu Pengajuan Habis'
|
||||||
: 'Sisa waktu pengajuan: '.now()->diffForHumans(
|
: 'Sisa waktu pengajuan: '.now()->diffForHumans(
|
||||||
$record->final_submission_date,
|
$record->final_submission_date->copy()->endOfDay(),
|
||||||
['syntax' => CarbonInterface::DIFF_ABSOLUTE]
|
['syntax' => CarbonInterface::DIFF_ABSOLUTE]
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user