fix: add task assignment existence checks in cooperation actions and update visibility logic for task creation
This commit is contained in:
parent
925fbe0bd7
commit
59b9a8ce92
@ -66,6 +66,10 @@ protected function setUp(): void
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! $record->taskAssignment()->exists()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$cooperationMedia = $record->cooperationMedia()
|
||||
->whereHas('partnerMedia.company', function (Builder $query): void {
|
||||
$query->where('user_id', auth()->id());
|
||||
|
||||
@ -37,8 +37,7 @@ protected function setUp(): void
|
||||
->placeholder(fn (): string => now()->translatedFormat('l, d F Y'))
|
||||
->native(false)
|
||||
->displayFormat('l, d F Y')
|
||||
->required()
|
||||
->minDate($record->final_submission_date),
|
||||
->required(),
|
||||
|
||||
DatePicker::make('end_date')
|
||||
->label('Tanggal Selesai')
|
||||
@ -46,8 +45,7 @@ protected function setUp(): void
|
||||
->native(false)
|
||||
->displayFormat('l, d F Y')
|
||||
->required()
|
||||
->after('start_date')
|
||||
->minDate($record->final_submission_date),
|
||||
->afterOrEqual('start_date'),
|
||||
|
||||
TextInput::make('report_amount')
|
||||
->label('Jumlah Bukti Tayang')
|
||||
@ -111,7 +109,7 @@ protected function setUp(): void
|
||||
|
||||
return $user && ! $user->hasRole(RoleEnum::PERUSAHAAN->value)
|
||||
&& ! $record->taskAssignment()->exists()
|
||||
&& $record->status === CooperationStatus::ASSIGNMENT;
|
||||
&& in_array($record->status, [CooperationStatus::PENDING, CooperationStatus::ASSIGNMENT]);
|
||||
})
|
||||
->modalWidth(Width::Large);
|
||||
}
|
||||
|
||||
@ -59,6 +59,10 @@ protected function setUp(): void
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! $record->taskAssignment()->exists()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$cooperationMedia = $record->cooperationMedia()
|
||||
->whereHas('partnerMedia.company', function ($query) {
|
||||
$query->where('user_id', auth()->id());
|
||||
|
||||
@ -22,6 +22,8 @@ class TaskAssignmentRelationManager extends RelationManager
|
||||
|
||||
protected static ?string $title = 'Media Order';
|
||||
|
||||
protected static bool $shouldSkipAuthorization = true;
|
||||
|
||||
public static function canViewForRecord(Model $ownerRecord, string $pageClass): bool
|
||||
{
|
||||
if (auth()->user()->hasRole(RoleEnum::PERUSAHAAN->value)) {
|
||||
@ -62,10 +64,38 @@ public function table(Table $table): Table
|
||||
CreateAction::make()
|
||||
->label('Buat Media Order')
|
||||
->visible(function (): bool {
|
||||
$user = auth()->user();
|
||||
|
||||
if (! $user->hasRole(RoleEnum::PERUSAHAAN->value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$cooperation = $this->getOwnerRecord();
|
||||
|
||||
return $cooperation->proposal()->accepted()->exists()
|
||||
&& ! $cooperation->taskAssignment()->exists();
|
||||
$isPartner = $cooperation->cooperationMedia()
|
||||
->whereHas('partnerMedia.company', function ($query) use ($user) {
|
||||
$query->where('user_id', $user->id);
|
||||
})
|
||||
->accepted()
|
||||
->exists();
|
||||
|
||||
if (! $isPartner) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$hasAcceptedProposal = $cooperation->proposal()->accepted()->exists();
|
||||
|
||||
if (! $hasAcceptedProposal) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$taskAssignment = $cooperation->taskAssignment;
|
||||
|
||||
if (! $taskAssignment) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $taskAssignment->reports()->count() < $taskAssignment->report_amount;
|
||||
})
|
||||
->successNotification(
|
||||
fn () => CheerfulNotification::success(
|
||||
|
||||
@ -29,4 +29,3 @@
|
||||
expect(CooperationStatus::values())->toEqual([1, 2, 3, 4]);
|
||||
expect(CooperationStatus::comment())->toBe('1: Menunggu, 2: Media Order, 3: Pembayaran, 4: Selesai');
|
||||
});
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user