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