Compare commits
	
		
			No commits in common. "9d41cdb0103044986025dd1af7682ec749f78644" and "741a4a24b7eaa85fb1a1d39988a71d7d00dd331d" have entirely different histories.
		
	
	
		
			9d41cdb010
			...
			741a4a24b7
		
	
		| 
						 | 
				
			
			@ -6,7 +6,6 @@ use App\Actions\DbMaintainAction;
 | 
			
		|||
use App\Form\Actions\PreventionRememberAction;
 | 
			
		||||
use App\Initialize\InitializeMembers;
 | 
			
		||||
use App\Invoice\Actions\InvoiceSendAction;
 | 
			
		||||
use App\Prevention\Actions\YearlyRememberAction;
 | 
			
		||||
use Illuminate\Console\Scheduling\Schedule;
 | 
			
		||||
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -22,7 +21,6 @@ class Kernel extends ConsoleKernel
 | 
			
		|||
        InitializeMembers::class,
 | 
			
		||||
        DbMaintainAction::class,
 | 
			
		||||
        PreventionRememberAction::class,
 | 
			
		||||
        YearlyRememberAction::class,
 | 
			
		||||
    ];
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
| 
						 | 
				
			
			@ -36,7 +34,6 @@ class Kernel extends ConsoleKernel
 | 
			
		|||
        $schedule->command(InitializeMembers::class)->dailyAt('03:00');
 | 
			
		||||
        $schedule->command(PreventionRememberAction::class)->dailyAt('11:00');
 | 
			
		||||
        $schedule->command(InvoiceSendAction::class)->dailyAt('10:00');
 | 
			
		||||
        $schedule->command(YearlyRememberAction::class)->dailyAt('09:00');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -13,18 +13,18 @@ class PreventionRememberAction
 | 
			
		|||
{
 | 
			
		||||
    use AsAction;
 | 
			
		||||
 | 
			
		||||
    public string $commandSignature = 'prevention:remember-forms';
 | 
			
		||||
    public string $commandSignature = 'prevention:remember';
 | 
			
		||||
 | 
			
		||||
    public function handle(): void
 | 
			
		||||
    {
 | 
			
		||||
        $query = Participant::whereHas(
 | 
			
		||||
            'form',
 | 
			
		||||
            fn($form) => $form
 | 
			
		||||
            fn ($form) => $form
 | 
			
		||||
                ->where('needs_prevention', true)
 | 
			
		||||
                ->where('from', '>=', now())
 | 
			
		||||
        )
 | 
			
		||||
            ->where(
 | 
			
		||||
                fn($q) => $q
 | 
			
		||||
                fn ($q) => $q
 | 
			
		||||
                    ->where('last_remembered_at', '<=', now()->subWeeks(2))
 | 
			
		||||
                    ->orWhereNull('last_remembered_at')
 | 
			
		||||
            );
 | 
			
		||||
| 
						 | 
				
			
			@ -33,7 +33,7 @@ class PreventionRememberAction
 | 
			
		|||
                continue;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if ($participant->getFields()->getMailRecipient() === null || $participant->preventions()->count() === 0) {
 | 
			
		||||
            if ($participant->getFields()->getMailRecipient() === null || count($participant->preventions()) === 0) {
 | 
			
		||||
                continue;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -41,7 +41,7 @@ class PreventionRememberAction
 | 
			
		|||
                ->placeholder('formname', $participant->form->name)
 | 
			
		||||
                ->append($participant->form->prevention_text);
 | 
			
		||||
 | 
			
		||||
            Mail::send(new PreventionRememberMail($participant, $body, $participant->preventions()));
 | 
			
		||||
            Mail::send(new PreventionRememberMail($participant, $body));
 | 
			
		||||
 | 
			
		||||
            $participant->update(['last_remembered_at' => now()]);
 | 
			
		||||
        }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -14,7 +14,6 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
 | 
			
		|||
use Illuminate\Database\Eloquent\Model;
 | 
			
		||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
 | 
			
		||||
use Illuminate\Database\Eloquent\Relations\HasMany;
 | 
			
		||||
use Illuminate\Support\Collection;
 | 
			
		||||
use Illuminate\Support\Facades\Mail;
 | 
			
		||||
use Laravel\Scout\Searchable;
 | 
			
		||||
use stdClass;
 | 
			
		||||
| 
						 | 
				
			
			@ -82,15 +81,20 @@ class Participant extends Model implements Preventable
 | 
			
		|||
        Mail::to($this->getMailRecipient())->queue(new ConfirmRegistrationMail($this));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function preventableLayout(): string
 | 
			
		||||
    {
 | 
			
		||||
        return 'mail.prevention.prevention-remember-participant';
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @inheritdoc
 | 
			
		||||
     */
 | 
			
		||||
    public function preventions(): Collection
 | 
			
		||||
    public function preventions(): array
 | 
			
		||||
    {
 | 
			
		||||
        return $this->member?->preventions($this->form->from) ?: collect([]);
 | 
			
		||||
        return $this->member?->preventions($this->form->from) ?: [];
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function getMailRecipient(): ?stdClass
 | 
			
		||||
    public function getMailRecipient(): stdClass
 | 
			
		||||
    {
 | 
			
		||||
        return $this->getFields()->getMailRecipient();
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -14,7 +14,8 @@ class EditorData extends Data implements Editorable
 | 
			
		|||
        public string $version,
 | 
			
		||||
        public array $blocks,
 | 
			
		||||
        public int $time
 | 
			
		||||
    ) {}
 | 
			
		||||
    ) {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function placeholder(string $search, string $replacement): self
 | 
			
		||||
    {
 | 
			
		||||
| 
						 | 
				
			
			@ -29,12 +30,7 @@ class EditorData extends Data implements Editorable
 | 
			
		|||
     */
 | 
			
		||||
    public function hasAll(array $wanted): bool
 | 
			
		||||
    {
 | 
			
		||||
        return collect($wanted)->doesntContain(fn($search) => !str(json_encode($this->blocks))->contains($search));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function hasNot(string $should): bool
 | 
			
		||||
    {
 | 
			
		||||
        return !str(json_encode($this->blocks))->contains($should);
 | 
			
		||||
        return collect($wanted)->first(fn ($search) => !str(json_encode($this->blocks))->contains($search)) === null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static function default(): self
 | 
			
		||||
| 
						 | 
				
			
			@ -69,7 +65,7 @@ class EditorData extends Data implements Editorable
 | 
			
		|||
                    'type' => 'list',
 | 
			
		||||
                    'data' => [
 | 
			
		||||
                        'style' => 'unordered',
 | 
			
		||||
                        'items' => collect($replacements)->map(fn($replacement) => [
 | 
			
		||||
                        'items' => collect($replacements)->map(fn ($replacement) => [
 | 
			
		||||
                            'content' => $replacement,
 | 
			
		||||
                            'items' => [],
 | 
			
		||||
                        ]),
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -48,7 +48,8 @@ class FilterScope extends ScoutFilter
 | 
			
		|||
        public ?bool $hasBirthday = null,
 | 
			
		||||
        public ?bool $hasSvk = null,
 | 
			
		||||
        public ?bool $hasVk = null,
 | 
			
		||||
    ) {}
 | 
			
		||||
    ) {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param array<string, mixed> $options
 | 
			
		||||
| 
						 | 
				
			
			@ -109,20 +110,20 @@ class FilterScope extends ScoutFilter
 | 
			
		|||
            }
 | 
			
		||||
            if ($this->subactivityIds && $this->activityIds) {
 | 
			
		||||
                $combinations = $this->combinations($this->activityIds, $this->subactivityIds)
 | 
			
		||||
                    ->map(fn($combination) => implode('|', $combination))
 | 
			
		||||
                    ->map(fn($combination) => str($combination)->wrap('"'));
 | 
			
		||||
                    ->map(fn ($combination) => implode('|', $combination))
 | 
			
		||||
                    ->map(fn ($combination) => str($combination)->wrap('"'));
 | 
			
		||||
                $filter->push($this->inExpression('memberships.both', $combinations));
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            foreach ($this->memberships as $membership) {
 | 
			
		||||
                $filter->push($this->inExpression('memberships.with_group', $this->possibleValuesForMembership($membership)->map(fn($value) => str($value)->wrap('"'))));
 | 
			
		||||
                $filter->push($this->inExpression('memberships.with_group', $this->possibleValuesForMembership($membership)->map(fn ($value) => str($value)->wrap('"'))));
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (count($this->exclude)) {
 | 
			
		||||
                $filter->push($this->notInExpression('id', $this->exclude));
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            $andFilter = $filter->map(fn($expression) => "($expression)")->implode(' AND ');
 | 
			
		||||
            $andFilter = $filter->map(fn ($expression) => "($expression)")->implode(' AND ');
 | 
			
		||||
 | 
			
		||||
            $options['filter'] = $this->implode(collect([$andFilter])->push($this->inExpression('id', $this->include)), 'OR');
 | 
			
		||||
            $options['sort'] = ['lastname:asc', 'firstname:asc'];
 | 
			
		||||
| 
						 | 
				
			
			@ -136,7 +137,7 @@ class FilterScope extends ScoutFilter
 | 
			
		|||
     */
 | 
			
		||||
    protected function implode(Collection $values, string $between): string
 | 
			
		||||
    {
 | 
			
		||||
        return $values->filter(fn($expression) => $expression)->implode(" {$between} ");
 | 
			
		||||
        return $values->filter(fn ($expression) => $expression)->implode(" {$between} ");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
| 
						 | 
				
			
			@ -176,7 +177,7 @@ class FilterScope extends ScoutFilter
 | 
			
		|||
        $membership['activity_ids'] = count($membership['activity_ids']) === 0 ? Activity::pluck('id')->toArray() : $membership['activity_ids'];
 | 
			
		||||
        $membership['subactivity_ids'] = count($membership['subactivity_ids']) === 0 ? Subactivity::pluck('id')->toArray() : $membership['subactivity_ids'];
 | 
			
		||||
        return $this->combinations($membership['group_ids'], $membership['activity_ids'], $membership['subactivity_ids'])
 | 
			
		||||
            ->map(fn($combination) => collect($combination)->implode('|'));
 | 
			
		||||
            ->map(fn ($combination) => collect($combination)->implode('|'));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
| 
						 | 
				
			
			@ -190,7 +191,7 @@ class FilterScope extends ScoutFilter
 | 
			
		|||
 | 
			
		||||
        if (!count($otherParts)) {
 | 
			
		||||
            /** @var Collection<int, Collection<int, int>> */
 | 
			
		||||
            return collect($firstPart)->map(fn($p) => [$p]);
 | 
			
		||||
            return collect($firstPart)->map(fn ($p) => [$p]);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /** @var Collection<int, mixed> */
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -13,8 +13,6 @@ use App\Nami\HasNamiField;
 | 
			
		|||
use App\Nationality;
 | 
			
		||||
use App\Payment\Subscription;
 | 
			
		||||
use App\Pdf\Sender;
 | 
			
		||||
use App\Prevention\Contracts\Preventable;
 | 
			
		||||
use App\Prevention\Data\PreventionData;
 | 
			
		||||
use App\Region;
 | 
			
		||||
use App\Setting\NamiSettings;
 | 
			
		||||
use Carbon\Carbon;
 | 
			
		||||
| 
						 | 
				
			
			@ -37,14 +35,12 @@ use Zoomyboy\Phone\HasPhoneNumbers;
 | 
			
		|||
use App\Prevention\Enums\Prevention;
 | 
			
		||||
use Database\Factories\Member\MemberFactory;
 | 
			
		||||
use Illuminate\Database\Eloquent\Relations\HasOne;
 | 
			
		||||
use Illuminate\Support\Collection;
 | 
			
		||||
use stdClass;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @property string $subscription_name
 | 
			
		||||
 * @property int    $pending_payment
 | 
			
		||||
 */
 | 
			
		||||
class Member extends Model implements Geolocatable, Preventable
 | 
			
		||||
class Member extends Model implements Geolocatable
 | 
			
		||||
{
 | 
			
		||||
    use Notifiable;
 | 
			
		||||
    use HasNamiField;
 | 
			
		||||
| 
						 | 
				
			
			@ -195,25 +191,7 @@ class Member extends Model implements Geolocatable, Preventable
 | 
			
		|||
 | 
			
		||||
    protected function getAusstand(): int
 | 
			
		||||
    {
 | 
			
		||||
        return (int) $this->invoicePositions()->whereHas('invoice', fn($query) => $query->whereNeedsPayment())->sum('price');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function getMailRecipient(): ?stdClass
 | 
			
		||||
    {
 | 
			
		||||
        if (!$this->fullname) {
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (!$this->email) {
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return (object) ['name' => $this->fullname, 'email' => $this->email];
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function preventableSubject(): string
 | 
			
		||||
    {
 | 
			
		||||
        return 'Nachweise erforderlich';
 | 
			
		||||
        return (int) $this->invoicePositions()->whereHas('invoice', fn ($query) => $query->whereNeedsPayment())->sum('price');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // ---------------------------------- Relations ----------------------------------
 | 
			
		||||
| 
						 | 
				
			
			@ -361,7 +339,7 @@ class Member extends Model implements Geolocatable, Preventable
 | 
			
		|||
        return $query->addSelect([
 | 
			
		||||
            'pending_payment' => InvoicePosition::selectRaw('SUM(price)')
 | 
			
		||||
                ->whereColumn('invoice_positions.member_id', 'members.id')
 | 
			
		||||
                ->whereHas('invoice', fn($query) => $query->whereNeedsPayment()),
 | 
			
		||||
                ->whereHas('invoice', fn ($query) => $query->whereNeedsPayment()),
 | 
			
		||||
        ]);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -372,7 +350,7 @@ class Member extends Model implements Geolocatable, Preventable
 | 
			
		|||
     */
 | 
			
		||||
    public function scopeWhereHasPendingPayment(Builder $query): Builder
 | 
			
		||||
    {
 | 
			
		||||
        return $query->whereHas('invoicePositions', fn($q) => $q->whereHas('invoice', fn($q) => $q->whereNeedsPayment()));
 | 
			
		||||
        return $query->whereHas('invoicePositions', fn ($q) => $q->whereHas('invoice', fn ($q) => $q->whereNeedsPayment()));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
| 
						 | 
				
			
			@ -386,47 +364,32 @@ class Member extends Model implements Geolocatable, Preventable
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @inheritdoc
 | 
			
		||||
     * @return array<int, Prevention>
 | 
			
		||||
     */
 | 
			
		||||
    public function preventions(?Carbon $date = null): Collection
 | 
			
		||||
    public function preventions(?Carbon $date = null): array
 | 
			
		||||
    {
 | 
			
		||||
        $date = $date ?: now();
 | 
			
		||||
 | 
			
		||||
        /** @var Collection<int, PreventionData> */
 | 
			
		||||
        $preventions = collect([]);
 | 
			
		||||
        /** @var array<int, Prevention> */
 | 
			
		||||
        $preventions = [];
 | 
			
		||||
 | 
			
		||||
        if ($this->efz === null || $this->efz->diffInYears($date) >= 5) {
 | 
			
		||||
            $preventions->push(PreventionData::from([
 | 
			
		||||
                'type' => Prevention::EFZ,
 | 
			
		||||
                'expires' => $this->efz === null ? now() : $this->efz->addYears(5)
 | 
			
		||||
            ]));
 | 
			
		||||
            $preventions[] = Prevention::EFZ;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (!$this->has_vk) {
 | 
			
		||||
            $preventions->push(PreventionData::from([
 | 
			
		||||
                'type' => Prevention::VK,
 | 
			
		||||
                'expires' => now(),
 | 
			
		||||
            ]));
 | 
			
		||||
            $preventions[] = Prevention::VK;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if ($this->more_ps_at === null) {
 | 
			
		||||
            if ($this->ps_at === null) {
 | 
			
		||||
                $preventions->push(PreventionData::from([
 | 
			
		||||
                    'type' => Prevention::PS,
 | 
			
		||||
                    'expires' => now(),
 | 
			
		||||
                ]));
 | 
			
		||||
                $preventions[] = Prevention::PS;
 | 
			
		||||
            } else if ($this->ps_at->diffInYears($date) >= 5) {
 | 
			
		||||
                $preventions->push(PreventionData::from([
 | 
			
		||||
                    'type' => Prevention::MOREPS,
 | 
			
		||||
                    'expires' => $this->ps_at->addYears(5),
 | 
			
		||||
                ]));
 | 
			
		||||
                $preventions[] = Prevention::MOREPS;
 | 
			
		||||
            }
 | 
			
		||||
        } else {
 | 
			
		||||
            if ($this->more_ps_at === null || $this->more_ps_at->diffInYears($date) >= 5) {
 | 
			
		||||
                $preventions->push(PreventionData::from([
 | 
			
		||||
                    'type' => Prevention::MOREPS,
 | 
			
		||||
                    'expires' => $this->more_ps_at->addYears(5),
 | 
			
		||||
                ]));
 | 
			
		||||
                $preventions[] = Prevention::MOREPS;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -536,7 +499,7 @@ class Member extends Model implements Geolocatable, Preventable
 | 
			
		|||
            'name' => $this->fullname,
 | 
			
		||||
            'address' => $this->address,
 | 
			
		||||
            'zipLocation' => $this->zip . ' ' . $this->location,
 | 
			
		||||
            'mglnr' => Lazy::create(fn() => 'Mglnr.: ' . $this->nami_id),
 | 
			
		||||
            'mglnr' => Lazy::create(fn () => 'Mglnr.: ' . $this->nami_id),
 | 
			
		||||
        ]);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -545,7 +508,7 @@ class Member extends Model implements Geolocatable, Preventable
 | 
			
		|||
     */
 | 
			
		||||
    public static function forSelect(): array
 | 
			
		||||
    {
 | 
			
		||||
        return static::select(['id', 'firstname', 'lastname'])->get()->map(fn($member) => ['id' => $member->id, 'name' => $member->fullname])->toArray();
 | 
			
		||||
        return static::select(['id', 'firstname', 'lastname'])->get()->map(fn ($member) => ['id' => $member->id, 'name' => $member->fullname])->toArray();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // -------------------------------- Geolocation --------------------------------
 | 
			
		||||
| 
						 | 
				
			
			@ -604,7 +567,7 @@ class Member extends Model implements Geolocatable, Preventable
 | 
			
		|||
            'age_group_icon' => $this->ageGroupMemberships->first()?->subactivity->slug,
 | 
			
		||||
            'is_leader' => $this->leaderMemberships()->count() > 0,
 | 
			
		||||
            'memberships' => $this->memberships()->active()->get()
 | 
			
		||||
                ->map(fn($membership) => [...$membership->only('activity_id', 'subactivity_id'), 'both' => $membership->activity_id . '|' . $membership->subactivity_id, 'with_group' => $membership->group_id . '|' . $membership->activity_id . '|' . $membership->subactivity_id]),
 | 
			
		||||
                ->map(fn ($membership) => [...$membership->only('activity_id', 'subactivity_id'), 'both' => $membership->activity_id . '|' . $membership->subactivity_id, 'with_group' => $membership->group_id . '|' . $membership->activity_id . '|' . $membership->subactivity_id]),
 | 
			
		||||
        ];
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -136,8 +136,8 @@ class MemberResource extends JsonResource
 | 
			
		|||
        $createActivities = Activity::remote()->with(['subactivities' => fn($q) => $q->remote()])->get();
 | 
			
		||||
 | 
			
		||||
        return [
 | 
			
		||||
            'filterActivities' => Activity::where('is_filterable', true)->get()->map(fn($a) => ['id' => $a->id, 'name' => $a->name]),
 | 
			
		||||
            'filterSubactivities' => Subactivity::where('is_filterable', true)->get()->map(fn($a) => ['id' => $a->id, 'name' => $a->name]),
 | 
			
		||||
            'filterActivities' => Activity::where('is_filterable', true)->pluck('name', 'id'),
 | 
			
		||||
            'filterSubactivities' => Subactivity::where('is_filterable', true)->pluck('name', 'id'),
 | 
			
		||||
            'formActivities' => $activities->pluck('name', 'id'),
 | 
			
		||||
            'formSubactivities' => $activities->map(function (Activity $activity) {
 | 
			
		||||
                return ['subactivities' => $activity->subactivities->pluck('name', 'id'), 'id' => $activity->id];
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,7 +2,6 @@
 | 
			
		|||
 | 
			
		||||
namespace App\Prevention\Actions;
 | 
			
		||||
 | 
			
		||||
use App\Prevention\Enums\Prevention;
 | 
			
		||||
use App\Prevention\PreventionSettings;
 | 
			
		||||
use Illuminate\Http\JsonResponse;
 | 
			
		||||
use Lorisleiva\Actions\Concerns\AsAction;
 | 
			
		||||
| 
						 | 
				
			
			@ -14,10 +13,7 @@ class SettingApiAction
 | 
			
		|||
    public function handle(): JsonResponse
 | 
			
		||||
    {
 | 
			
		||||
        return response()->json([
 | 
			
		||||
            'data' => app(PreventionSettings::class)->toFrontend(),
 | 
			
		||||
            'meta' => [
 | 
			
		||||
                'preventAgainsts' => Prevention::values(),
 | 
			
		||||
            ]
 | 
			
		||||
            'data' => app(PreventionSettings::class)->toArray(),
 | 
			
		||||
        ]);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,7 +4,6 @@ namespace App\Prevention\Actions;
 | 
			
		|||
 | 
			
		||||
use App\Lib\Editor\EditorData;
 | 
			
		||||
use App\Lib\Events\Succeeded;
 | 
			
		||||
use App\Member\FilterScope;
 | 
			
		||||
use App\Prevention\PreventionSettings;
 | 
			
		||||
use Lorisleiva\Actions\ActionRequest;
 | 
			
		||||
use Lorisleiva\Actions\Concerns\AsAction;
 | 
			
		||||
| 
						 | 
				
			
			@ -20,10 +19,6 @@ class SettingStoreAction
 | 
			
		|||
    {
 | 
			
		||||
        return [
 | 
			
		||||
            'formmail' => 'array',
 | 
			
		||||
            'yearlymail' => 'array',
 | 
			
		||||
            'weeks' => 'required|numeric|gte:0',
 | 
			
		||||
            'freshRememberInterval' => 'required|numeric|gte:0',
 | 
			
		||||
            'active' => 'boolean',
 | 
			
		||||
        ];
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -31,12 +26,6 @@ class SettingStoreAction
 | 
			
		|||
    {
 | 
			
		||||
        $settings = app(PreventionSettings::class);
 | 
			
		||||
        $settings->formmail = EditorData::from($request->formmail);
 | 
			
		||||
        $settings->yearlymail = EditorData::from($request->yearlymail);
 | 
			
		||||
        $settings->weeks = $request->weeks;
 | 
			
		||||
        $settings->freshRememberInterval = $request->freshRememberInterval;
 | 
			
		||||
        $settings->active = $request->active;
 | 
			
		||||
        $settings->yearlyMemberFilter = FilterScope::from($request->yearlyMemberFilter);
 | 
			
		||||
        $settings->preventAgainst = $request->preventAgainst;
 | 
			
		||||
        $settings->save();
 | 
			
		||||
 | 
			
		||||
        Succeeded::message('Einstellungen gespeichert.')->dispatch();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,79 +0,0 @@
 | 
			
		|||
<?php
 | 
			
		||||
 | 
			
		||||
namespace App\Prevention\Actions;
 | 
			
		||||
 | 
			
		||||
use App\Member\Member;
 | 
			
		||||
use App\Prevention\Data\PreventionData;
 | 
			
		||||
use App\Prevention\Mails\YearlyMail;
 | 
			
		||||
use App\Prevention\PreventionSettings;
 | 
			
		||||
use Illuminate\Support\Collection;
 | 
			
		||||
use Illuminate\Support\Facades\Cache;
 | 
			
		||||
use Illuminate\Support\Facades\Mail;
 | 
			
		||||
use Lorisleiva\Actions\Concerns\AsAction;
 | 
			
		||||
 | 
			
		||||
class YearlyRememberAction
 | 
			
		||||
{
 | 
			
		||||
    use AsAction;
 | 
			
		||||
 | 
			
		||||
    public string $commandSignature = 'prevention:remember-yearly';
 | 
			
		||||
 | 
			
		||||
    public function handle(): void
 | 
			
		||||
    {
 | 
			
		||||
        $settings = app(PreventionSettings::class);
 | 
			
		||||
        $expireDate = now()->addWeeks($settings->weeks);
 | 
			
		||||
 | 
			
		||||
        if (!$settings->active) {
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        foreach ($settings->yearlyMemberFilter->getQuery()->get() as $member) {
 | 
			
		||||
            // @todo add this check to FilterScope
 | 
			
		||||
            if ($member->getMailRecipient() === null) {
 | 
			
		||||
                continue;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            $noticePreventions = $member->preventions($expireDate)
 | 
			
		||||
                ->filter(fn($prevention) => $prevention->expiresAt($expireDate))
 | 
			
		||||
                ->filter(fn($p) => $p->appliesToSettings($settings));
 | 
			
		||||
 | 
			
		||||
            if ($noticePreventions->count() === 0) {
 | 
			
		||||
                continue;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            Mail::send($this->createMail($member, $noticePreventions));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        foreach ($settings->yearlyMemberFilter->getQuery()->get() as $member) {
 | 
			
		||||
            // @todo add this check to FilterScope
 | 
			
		||||
            if ($member->getMailRecipient() === null) {
 | 
			
		||||
                continue;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            $preventions = $member->preventions()
 | 
			
		||||
                ->filter(fn($prevention) => $prevention->expiresAt(now()))
 | 
			
		||||
                ->filter(fn($p) => $p->appliesToSettings($settings));
 | 
			
		||||
 | 
			
		||||
            if ($preventions->count() === 0) {
 | 
			
		||||
                continue;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            Cache::remember(
 | 
			
		||||
                'prevention-' . $member->id,
 | 
			
		||||
                (int) now()->diffInSeconds(now()->addWeeks($settings->freshRememberInterval)),
 | 
			
		||||
                function () use ($member, $preventions) {
 | 
			
		||||
                    Mail::send($this->createMail($member, $preventions));
 | 
			
		||||
                    return 0;
 | 
			
		||||
                }
 | 
			
		||||
            );
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param Collection<int, PreventionData> $preventions
 | 
			
		||||
     */
 | 
			
		||||
    protected function createMail(Member $member, Collection $preventions): YearlyMail
 | 
			
		||||
    {
 | 
			
		||||
        $body = app(PreventionSettings::class)->refresh()->yearlymail;
 | 
			
		||||
        return new YearlyMail($member, $body, $preventions);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -2,19 +2,19 @@
 | 
			
		|||
 | 
			
		||||
namespace App\Prevention\Contracts;
 | 
			
		||||
 | 
			
		||||
use App\Prevention\Data\PreventionData;
 | 
			
		||||
use Illuminate\Support\Collection;
 | 
			
		||||
use App\Prevention\Enums\Prevention;
 | 
			
		||||
use stdClass;
 | 
			
		||||
 | 
			
		||||
interface Preventable
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
    public function preventableLayout(): string;
 | 
			
		||||
    public function preventableSubject(): string;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @return Collection<int, PreventionData>
 | 
			
		||||
     * @return array<int, Prevention>
 | 
			
		||||
     */
 | 
			
		||||
    public function preventions(): Collection;
 | 
			
		||||
    public function preventions(): array;
 | 
			
		||||
 | 
			
		||||
    public function getMailRecipient(): ?stdClass;
 | 
			
		||||
    public function getMailRecipient(): stdClass;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,31 +0,0 @@
 | 
			
		|||
<?php
 | 
			
		||||
 | 
			
		||||
namespace App\Prevention\Data;
 | 
			
		||||
 | 
			
		||||
use App\Prevention\Enums\Prevention;
 | 
			
		||||
use App\Prevention\PreventionSettings;
 | 
			
		||||
use Carbon\Carbon;
 | 
			
		||||
use Spatie\LaravelData\Data;
 | 
			
		||||
 | 
			
		||||
class PreventionData extends Data
 | 
			
		||||
{
 | 
			
		||||
    public function __construct(public Prevention $type, public Carbon $expires) {}
 | 
			
		||||
 | 
			
		||||
    public function expiresAt(Carbon $date): bool
 | 
			
		||||
    {
 | 
			
		||||
        return $this->expires->isSameDay($date);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function text(): string
 | 
			
		||||
    {
 | 
			
		||||
        return str($this->type->text())->when(
 | 
			
		||||
            !$this->expiresAt(now()),
 | 
			
		||||
            fn($str) => $str->append(' (fällig am ' . $this->expires->format('d.m.Y') . ')')
 | 
			
		||||
        );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function appliesToSettings(PreventionSettings $settings): bool
 | 
			
		||||
    {
 | 
			
		||||
        return in_array($this->type->name, $settings->preventAgainst);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -2,7 +2,8 @@
 | 
			
		|||
 | 
			
		||||
namespace App\Prevention\Enums;
 | 
			
		||||
 | 
			
		||||
use App\Prevention\Data\PreventionData;
 | 
			
		||||
use App\Member\Member;
 | 
			
		||||
use Carbon\Carbon;
 | 
			
		||||
use Illuminate\Support\Collection;
 | 
			
		||||
 | 
			
		||||
enum Prevention
 | 
			
		||||
| 
						 | 
				
			
			@ -38,26 +39,15 @@ enum Prevention
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param Collection<int, PreventionData> $preventions
 | 
			
		||||
     * @param array<int, self> $preventions
 | 
			
		||||
     * @return Collection<int, array{letter: string, value: bool, tooltip: string}>
 | 
			
		||||
     */
 | 
			
		||||
    public static function items(Collection $preventions): Collection
 | 
			
		||||
    public static function items(array $preventions): Collection
 | 
			
		||||
    {
 | 
			
		||||
        return collect(static::cases())->map(fn($case) => [
 | 
			
		||||
        return collect(static::cases())->map(fn ($case) => [
 | 
			
		||||
            'letter' => $case->letter(),
 | 
			
		||||
            'value' => $preventions->pluck('type')->doesntContain($case),
 | 
			
		||||
            'tooltip' => $case->tooltip($preventions->pluck('type')->doesntContain($case)),
 | 
			
		||||
            'value' => !in_array($case, $preventions),
 | 
			
		||||
            'tooltip' => $case->tooltip(!in_array($case, $preventions)),
 | 
			
		||||
        ]);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @return array<int, string>
 | 
			
		||||
     */
 | 
			
		||||
    public static function values(): array
 | 
			
		||||
    {
 | 
			
		||||
        return collect(static::cases())->map(fn($case) => [
 | 
			
		||||
            'id' => $case->name,
 | 
			
		||||
            'name' => $case->text(),
 | 
			
		||||
        ])->toArray();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,14 +5,12 @@ namespace App\Prevention\Mails;
 | 
			
		|||
use App\Invoice\InvoiceSettings;
 | 
			
		||||
use App\Lib\Editor\EditorData;
 | 
			
		||||
use App\Prevention\Contracts\Preventable;
 | 
			
		||||
use App\Prevention\Data\PreventionData;
 | 
			
		||||
use Illuminate\Bus\Queueable;
 | 
			
		||||
use Illuminate\Mail\Attachment;
 | 
			
		||||
use Illuminate\Mail\Mailable;
 | 
			
		||||
use Illuminate\Mail\Mailables\Content;
 | 
			
		||||
use Illuminate\Mail\Mailables\Envelope;
 | 
			
		||||
use Illuminate\Queue\SerializesModels;
 | 
			
		||||
use Illuminate\Support\Collection;
 | 
			
		||||
 | 
			
		||||
class PreventionRememberMail extends Mailable
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			@ -22,13 +20,12 @@ class PreventionRememberMail extends Mailable
 | 
			
		|||
 | 
			
		||||
    /**
 | 
			
		||||
     * Create a new message instance.
 | 
			
		||||
     * @param Collection<int, PreventionData> $preventions
 | 
			
		||||
     */
 | 
			
		||||
    public function __construct(public Preventable $preventable, public EditorData $bodyText, public Collection $preventions)
 | 
			
		||||
    public function __construct(public Preventable $preventable, public EditorData $bodyText)
 | 
			
		||||
    {
 | 
			
		||||
        $this->settings = app(InvoiceSettings::class);
 | 
			
		||||
        $this->bodyText = $this->bodyText
 | 
			
		||||
            ->replaceWithList('wanted', $preventions->map(fn($prevention) => $prevention->text())->toArray());
 | 
			
		||||
            ->replaceWithList('wanted', collect($preventable->preventions())->map(fn ($prevention) => $prevention->text())->toArray());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
| 
						 | 
				
			
			@ -51,7 +48,7 @@ class PreventionRememberMail extends Mailable
 | 
			
		|||
    public function content()
 | 
			
		||||
    {
 | 
			
		||||
        return new Content(
 | 
			
		||||
            markdown: 'mail.prevention.prevention-remember-participant',
 | 
			
		||||
            markdown: $this->preventable->preventableLayout(),
 | 
			
		||||
        );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,67 +0,0 @@
 | 
			
		|||
<?php
 | 
			
		||||
 | 
			
		||||
namespace App\Prevention\Mails;
 | 
			
		||||
 | 
			
		||||
use App\Invoice\InvoiceSettings;
 | 
			
		||||
use App\Lib\Editor\EditorData;
 | 
			
		||||
use App\Prevention\Contracts\Preventable;
 | 
			
		||||
use App\Prevention\Data\PreventionData;
 | 
			
		||||
use Illuminate\Bus\Queueable;
 | 
			
		||||
use Illuminate\Mail\Attachment;
 | 
			
		||||
use Illuminate\Mail\Mailable;
 | 
			
		||||
use Illuminate\Mail\Mailables\Content;
 | 
			
		||||
use Illuminate\Mail\Mailables\Envelope;
 | 
			
		||||
use Illuminate\Queue\SerializesModels;
 | 
			
		||||
use Illuminate\Support\Collection;
 | 
			
		||||
 | 
			
		||||
class YearlyMail extends Mailable
 | 
			
		||||
{
 | 
			
		||||
    use Queueable, SerializesModels;
 | 
			
		||||
 | 
			
		||||
    public InvoiceSettings $settings;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Create a new message instance.
 | 
			
		||||
     * @param Collection<int, PreventionData> $preventions
 | 
			
		||||
     */
 | 
			
		||||
    public function __construct(public Preventable $preventable, public EditorData $bodyText, public Collection $preventions)
 | 
			
		||||
    {
 | 
			
		||||
        $this->settings = app(InvoiceSettings::class);
 | 
			
		||||
        $this->bodyText = $this->bodyText
 | 
			
		||||
            ->replaceWithList('wanted', $preventions->map(fn($prevention) => $prevention->text())->toArray());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get the message envelope.
 | 
			
		||||
     *
 | 
			
		||||
     * @return \Illuminate\Mail\Mailables\Envelope
 | 
			
		||||
     */
 | 
			
		||||
    public function envelope()
 | 
			
		||||
    {
 | 
			
		||||
        return (new Envelope(
 | 
			
		||||
            subject: $this->preventable->preventableSubject(),
 | 
			
		||||
        ))->to($this->preventable->getMailRecipient()->email, $this->preventable->getMailRecipient()->name);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get the message content definition.
 | 
			
		||||
     *
 | 
			
		||||
     * @return \Illuminate\Mail\Mailables\Content
 | 
			
		||||
     */
 | 
			
		||||
    public function content()
 | 
			
		||||
    {
 | 
			
		||||
        return new Content(
 | 
			
		||||
            markdown: 'mail.prevention.prevention-remember-participant',
 | 
			
		||||
        );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get the attachments for the message.
 | 
			
		||||
     *
 | 
			
		||||
     * @return array<int, Attachment>
 | 
			
		||||
     */
 | 
			
		||||
    public function attachments(): array
 | 
			
		||||
    {
 | 
			
		||||
        return [];
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -3,23 +3,12 @@
 | 
			
		|||
namespace App\Prevention;
 | 
			
		||||
 | 
			
		||||
use App\Lib\Editor\EditorData;
 | 
			
		||||
use App\Member\FilterScope;
 | 
			
		||||
use App\Setting\LocalSettings;
 | 
			
		||||
 | 
			
		||||
class PreventionSettings extends LocalSettings
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
    public EditorData $formmail;
 | 
			
		||||
    public EditorData $yearlymail;
 | 
			
		||||
    public int $weeks;
 | 
			
		||||
    public int $freshRememberInterval;
 | 
			
		||||
    public bool $active;
 | 
			
		||||
    public FilterScope $yearlyMemberFilter;
 | 
			
		||||
    /**
 | 
			
		||||
     * @var array<int, string>
 | 
			
		||||
     * @todo Create collection cast to Collection of enums
 | 
			
		||||
     */
 | 
			
		||||
    public array $preventAgainst;
 | 
			
		||||
 | 
			
		||||
    public static function group(): string
 | 
			
		||||
    {
 | 
			
		||||
| 
						 | 
				
			
			@ -38,17 +27,4 @@ class PreventionSettings extends LocalSettings
 | 
			
		|||
    {
 | 
			
		||||
        return [];
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @todo return int value here and handle this in vue with a number field that only expects integers
 | 
			
		||||
     * @return array<string, mixed>
 | 
			
		||||
     */
 | 
			
		||||
    public function toFrontend(): array
 | 
			
		||||
    {
 | 
			
		||||
        return [
 | 
			
		||||
            ...$this->toArray(),
 | 
			
		||||
            'weeks' => (string) $this->weeks,
 | 
			
		||||
            'freshRememberInterval' => (string) $this->freshRememberInterval,
 | 
			
		||||
        ];
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -8,5 +8,3 @@ sudo mysql adrema < db.tmp
 | 
			
		|||
rm db.tmp
 | 
			
		||||
 | 
			
		||||
echo 'app(\App\Form\FormSettings::class)->fill(["registerUrl" => "http://stammsilva.test/anmeldung/{slug}/register", "clearCacheUrl" => "http://stammsilva.test/adrema/clear-cache"])->save();' | php artisan tinker
 | 
			
		||||
 | 
			
		||||
exit 0
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -119,7 +119,7 @@ return [
 | 
			
		|||
 | 
			
		||||
        'options' => [
 | 
			
		||||
            'cluster' => env('REDIS_CLUSTER', 'redis'),
 | 
			
		||||
            'prefix' => env('REDIS_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_') . '_database_'),
 | 
			
		||||
            'prefix' => env('REDIS_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_database_'),
 | 
			
		||||
        ],
 | 
			
		||||
 | 
			
		||||
        'default' => [
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,17 +0,0 @@
 | 
			
		|||
<?php
 | 
			
		||||
 | 
			
		||||
use App\Member\FilterScope;
 | 
			
		||||
use Spatie\LaravelSettings\Migrations\SettingsMigration;
 | 
			
		||||
 | 
			
		||||
return new class extends SettingsMigration
 | 
			
		||||
{
 | 
			
		||||
    public function up(): void
 | 
			
		||||
    {
 | 
			
		||||
        $this->migrator->add('prevention.yearlymail', ['time' => 1, 'blocks' => [], 'version' => '1.0']);
 | 
			
		||||
        $this->migrator->add('prevention.weeks', 8);
 | 
			
		||||
        $this->migrator->add('prevention.freshRememberInterval', 12);
 | 
			
		||||
        $this->migrator->add('prevention.active', false);
 | 
			
		||||
        $this->migrator->add('prevention.yearlyMemberFilter', FilterScope::from([])->toArray());
 | 
			
		||||
        $this->migrator->add('prevention.preventAgainst', []);
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| 
						 | 
				
			
			@ -1,48 +0,0 @@
 | 
			
		|||
<template>
 | 
			
		||||
    <label class="flex flex-col group" :for="id" :class="sizeClass(size)">
 | 
			
		||||
        <f-label v-if="label" :required="false" :value="label"></f-label>
 | 
			
		||||
        <div class="relative flex-none flex">
 | 
			
		||||
            <ui-icon-button :class="[fieldHeight, fieldAppearance, paddingX]" icon="filter" @click="visible = true">Filtern</ui-icon-button>
 | 
			
		||||
            <f-hint v-if="hint" :value="hint"></f-hint>
 | 
			
		||||
        </div>
 | 
			
		||||
    </label>
 | 
			
		||||
 | 
			
		||||
    <ui-filter-sidebar v-model="visible">
 | 
			
		||||
        <member-filter-fields :model-value="modelValue" @update:model-value="$emit('update:modelValue', $event)" />
 | 
			
		||||
    </ui-filter-sidebar>
 | 
			
		||||
</template>
 | 
			
		||||
 | 
			
		||||
<script setup>
 | 
			
		||||
import {ref} from 'vue';
 | 
			
		||||
import useFieldSize from '../../composables/useFieldSize';
 | 
			
		||||
import MemberFilterFields from '../../views/member/MemberFilterFields.vue';
 | 
			
		||||
 | 
			
		||||
const {sizeClass, fieldHeight, fieldAppearance, paddingX} = useFieldSize();
 | 
			
		||||
 | 
			
		||||
const visible = ref(false);
 | 
			
		||||
 | 
			
		||||
defineEmits(['update:modelValue']);
 | 
			
		||||
 | 
			
		||||
const props = defineProps({
 | 
			
		||||
    modelValue: {
 | 
			
		||||
        type: Object,
 | 
			
		||||
        required: true,
 | 
			
		||||
    },
 | 
			
		||||
    label: {
 | 
			
		||||
        type: String,
 | 
			
		||||
        required: true,
 | 
			
		||||
    },
 | 
			
		||||
    id: {
 | 
			
		||||
        type: String,
 | 
			
		||||
        required: true,
 | 
			
		||||
    },
 | 
			
		||||
    size: {
 | 
			
		||||
        type: String,
 | 
			
		||||
        default: () => 'base',
 | 
			
		||||
    },
 | 
			
		||||
    hint: {
 | 
			
		||||
        type: String,
 | 
			
		||||
        default: () => '',
 | 
			
		||||
    },
 | 
			
		||||
});
 | 
			
		||||
</script>
 | 
			
		||||
| 
						 | 
				
			
			@ -1,17 +1,47 @@
 | 
			
		|||
<template>
 | 
			
		||||
    <ui-filter-sidebar v-model="visible">
 | 
			
		||||
        <slot name="fields"></slot>
 | 
			
		||||
    </ui-filter-sidebar>
 | 
			
		||||
    <div class="px-6 py-2 border-b border-gray-600 items-center space-x-3">
 | 
			
		||||
    <ui-popup v-if="visible === true" heading="Filtern" @close="visible = false">
 | 
			
		||||
        <div class="grid gap-3 md:grid-cols-2">
 | 
			
		||||
            <slot name="fields"></slot>
 | 
			
		||||
        </div>
 | 
			
		||||
    </ui-popup>
 | 
			
		||||
    <div class="px-6 py-2 border-b border-gray-600" :class="visibleDesktopBlock">
 | 
			
		||||
        <div class="flex items-end space-x-3">
 | 
			
		||||
            <slot name="buttons"></slot>
 | 
			
		||||
            <ui-icon-button v-if="filterable" icon="filter" @click="filterVisible = !filterVisible">Filtern</ui-icon-button>
 | 
			
		||||
        </div>
 | 
			
		||||
        <ui-box v-if="filterVisible" class="mt-3">
 | 
			
		||||
            <div class="grid grid-cols-4 gap-3 items-end">
 | 
			
		||||
                <slot name="fields"></slot>
 | 
			
		||||
                <ui-icon-button class="col-start-1" icon="close" @click="filterVisible = false">Schließen</ui-icon-button>
 | 
			
		||||
            </div>
 | 
			
		||||
        </ui-box>
 | 
			
		||||
    </div>
 | 
			
		||||
    <div class="px-6 py-2 border-b border-gray-600 items-center space-x-3" :class="visibleMobile">
 | 
			
		||||
        <div class="flex flex-col sm:flex-row items-stretch sm:items-end space-y-1 sm:space-y-0 sm:space-x-3">
 | 
			
		||||
            <slot name="buttons"></slot>
 | 
			
		||||
            <ui-icon-button v-if="!!$slots.fields" icon="filter" @click="visible = true">Filtern</ui-icon-button>
 | 
			
		||||
            <ui-icon-button v-if="filterable" icon="filter" @click="visible = true">Filtern</ui-icon-button>
 | 
			
		||||
        </div>
 | 
			
		||||
    </div>
 | 
			
		||||
</template>
 | 
			
		||||
 | 
			
		||||
<script setup>
 | 
			
		||||
import {ref} from 'vue';
 | 
			
		||||
import {defineProps, ref} from 'vue';
 | 
			
		||||
import useBreakpoints from '../../composables/useBreakpoints.js';
 | 
			
		||||
 | 
			
		||||
const visible = ref(false);
 | 
			
		||||
 | 
			
		||||
const filterVisible = ref(false);
 | 
			
		||||
 | 
			
		||||
const props = defineProps({
 | 
			
		||||
    breakpoint: {
 | 
			
		||||
        type: String,
 | 
			
		||||
        required: true,
 | 
			
		||||
    },
 | 
			
		||||
    filterable: {
 | 
			
		||||
        type: Boolean,
 | 
			
		||||
        default: () => true,
 | 
			
		||||
    },
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
const {visibleDesktopBlock, visibleMobile} = useBreakpoints(props);
 | 
			
		||||
</script>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,19 +0,0 @@
 | 
			
		|||
<template>
 | 
			
		||||
    <ui-sidebar :max="0" v-if="modelValue === true" @close="$emit('update:modelValue', false)">
 | 
			
		||||
        <page-header title="Filter" @close="$emit('update:modelValue', false)"> </page-header>
 | 
			
		||||
        <div class="grid gap-3 p-6">
 | 
			
		||||
            <slot></slot>
 | 
			
		||||
        </div>
 | 
			
		||||
    </ui-sidebar>
 | 
			
		||||
</template>
 | 
			
		||||
 | 
			
		||||
<script setup>
 | 
			
		||||
defineEmits(['update:modelValue']);
 | 
			
		||||
 | 
			
		||||
defineProps({
 | 
			
		||||
    modelValue: {
 | 
			
		||||
        type: Boolean,
 | 
			
		||||
        required: true,
 | 
			
		||||
    },
 | 
			
		||||
});
 | 
			
		||||
</script>
 | 
			
		||||
| 
						 | 
				
			
			@ -1,5 +1,6 @@
 | 
			
		|||
<template>
 | 
			
		||||
    <div class="fixed shadow-2xl bg-gray-600 right-0 top-0 h-full flex flex-col group is-bright" :class="widths[max]">
 | 
			
		||||
    <div
 | 
			
		||||
        class="fixed w-full w-[80vw] max-w-[40rem] shadow-2xl bg-gray-600 right-0 top-0 h-full flex flex-col group is-bright">
 | 
			
		||||
        <suspense>
 | 
			
		||||
            <slot></slot>
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -17,20 +18,4 @@
 | 
			
		|||
 | 
			
		||||
<script setup>
 | 
			
		||||
defineEmits(['close']);
 | 
			
		||||
 | 
			
		||||
const widths = {
 | 
			
		||||
    40: 'w-full w-[80vw] max-w-[40rem]',
 | 
			
		||||
    30: 'w-full w-[80vw] max-w-[30rem]',
 | 
			
		||||
    20: 'w-full w-[80vw] max-w-[20rem]',
 | 
			
		||||
    10: 'w-full w-[80vw] max-w-[10rem]',
 | 
			
		||||
    0: '',
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
defineProps({
 | 
			
		||||
    max: {
 | 
			
		||||
        default: () => 40,
 | 
			
		||||
        type: Number,
 | 
			
		||||
        required: false,
 | 
			
		||||
    },
 | 
			
		||||
});
 | 
			
		||||
</script>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,15 +1,9 @@
 | 
			
		|||
<template>
 | 
			
		||||
    <div class="flex-none w-maxc flex flex-col justify-between border-b-2 border-gray-500 group-[.is-popup]:border-zinc-500 mb-3">
 | 
			
		||||
    <div class="flex-none w-maxc flex flex-col justify-between border-b-2 group-[.is-popup]:border-zinc-500 mb-3">
 | 
			
		||||
        <div class="flex space-x-1 px-2">
 | 
			
		||||
            <a
 | 
			
		||||
                v-for="(item, index) in entries"
 | 
			
		||||
                :key="index"
 | 
			
		||||
                href="#"
 | 
			
		||||
                class="rounded-t-lg py-1 px-3 text-zinc-300"
 | 
			
		||||
                :class="index === modelValue ? `bg-gray-700 group-[.is-popup]:bg-zinc-600` : ''"
 | 
			
		||||
                @click.prevent="openMenu(index)"
 | 
			
		||||
                v-text="item.title"
 | 
			
		||||
            ></a>
 | 
			
		||||
            <a v-for="(item, index) in entries" :key="index" href="#" class="rounded-t-lg py-1 px-3 text-zinc-300"
 | 
			
		||||
                :class="index === modelValue ? `group-[.is-popup]:bg-zinc-600` : ''" @click.prevent="openMenu(index)"
 | 
			
		||||
                v-text="item.title"></a>
 | 
			
		||||
        </div>
 | 
			
		||||
    </div>
 | 
			
		||||
</template>
 | 
			
		||||
| 
						 | 
				
			
			@ -17,18 +11,9 @@
 | 
			
		|||
<script>
 | 
			
		||||
export default {
 | 
			
		||||
    props: {
 | 
			
		||||
        modelValue: {
 | 
			
		||||
            type: Number,
 | 
			
		||||
            required: true,
 | 
			
		||||
        },
 | 
			
		||||
        entries: {
 | 
			
		||||
            required: true,
 | 
			
		||||
            validator: function (entries) {
 | 
			
		||||
                return entries.filter((e) => e.title === undefined || typeof e.title !== 'string' || e.title.length === 0).length === 0;
 | 
			
		||||
            },
 | 
			
		||||
        },
 | 
			
		||||
        modelValue: {},
 | 
			
		||||
        entries: {},
 | 
			
		||||
    },
 | 
			
		||||
    emits: ['update:modelValue'],
 | 
			
		||||
    methods: {
 | 
			
		||||
        openMenu(index) {
 | 
			
		||||
            this.$emit('update:modelValue', index);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1,46 @@
 | 
			
		|||
import {computed} from 'vue';
 | 
			
		||||
 | 
			
		||||
export default function (props) {
 | 
			
		||||
    const visibleMobile = computed(() => {
 | 
			
		||||
        return {
 | 
			
		||||
            sm: 'flex sm:hidden',
 | 
			
		||||
            md: 'flex md:hidden',
 | 
			
		||||
            lg: 'flex lg:hidden',
 | 
			
		||||
            xl: 'flex xl:hidden',
 | 
			
		||||
        }[props.breakpoint];
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    const visibleDesktop = computed(() => {
 | 
			
		||||
        return {
 | 
			
		||||
            sm: 'hidden sm:flex',
 | 
			
		||||
            md: 'hidden md:flex',
 | 
			
		||||
            lg: 'hidden lg:flex',
 | 
			
		||||
            xl: 'hidden xl:flex',
 | 
			
		||||
        }[props.breakpoint];
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    const visibleMobileBlock = computed(() => {
 | 
			
		||||
        return {
 | 
			
		||||
            sm: 'block sm:hidden',
 | 
			
		||||
            md: 'block md:hidden',
 | 
			
		||||
            lg: 'block lg:hidden',
 | 
			
		||||
            xl: 'block xl:hidden',
 | 
			
		||||
        }[props.breakpoint];
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    const visibleDesktopBlock = computed(() => {
 | 
			
		||||
        return {
 | 
			
		||||
            sm: 'hidden sm:block',
 | 
			
		||||
            md: 'hidden md:block',
 | 
			
		||||
            lg: 'hidden lg:block',
 | 
			
		||||
            xl: 'hidden xl:block',
 | 
			
		||||
        }[props.breakpoint];
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    return {
 | 
			
		||||
        visibleMobile,
 | 
			
		||||
        visibleDesktop,
 | 
			
		||||
        visibleDesktopBlock,
 | 
			
		||||
        visibleMobileBlock,
 | 
			
		||||
    };
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -56,11 +56,6 @@ export function useIndex(props, siteName) {
 | 
			
		|||
        reload(true);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    function setFilterObject(o) {
 | 
			
		||||
        inner.filter.value = o;
 | 
			
		||||
        reload(true);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    startListener();
 | 
			
		||||
    onBeforeUnmount(() => stopListener());
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -75,8 +70,6 @@ export function useIndex(props, siteName) {
 | 
			
		|||
        toFilterString,
 | 
			
		||||
        reloadPage,
 | 
			
		||||
        axios,
 | 
			
		||||
        filter: inner.filter,
 | 
			
		||||
        setFilterObject,
 | 
			
		||||
    };
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -144,7 +144,7 @@
 | 
			
		|||
            <conditions-form id="filesettings" :single="single" :value="fileSettingPopup.properties.conditions" @save="saveFileConditions"> </conditions-form>
 | 
			
		||||
        </ui-popup>
 | 
			
		||||
 | 
			
		||||
        <page-filter>
 | 
			
		||||
        <page-filter breakpoint="xl" :filterable="false">
 | 
			
		||||
            <template #buttons>
 | 
			
		||||
                <f-text id="search" :model-value="getFilter('search')" label="Suchen …" size="sm" @update:model-value="setFilter('search', $event)"></f-text>
 | 
			
		||||
                <f-switch id="past" :model-value="getFilter('past')" label="vergangene zeigen" name="past" size="sm" @update:model-value="setFilter('past', $event)"></f-switch>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -21,7 +21,7 @@
 | 
			
		|||
                </div>
 | 
			
		||||
            </div>
 | 
			
		||||
        </ui-popup>
 | 
			
		||||
        <page-filter>
 | 
			
		||||
        <page-filter breakpoint="lg">
 | 
			
		||||
            <template #buttons>
 | 
			
		||||
                <f-text id="search" v-model="innerFilter.search" name="search" label="Suchen" size="sm"></f-text>
 | 
			
		||||
                <ui-icon-button icon="plus" @click="editing = {participant: null, preview: JSON.stringify(meta.form_config)}">Hinzufügen</ui-icon-button>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -72,7 +72,7 @@
 | 
			
		|||
                </section>
 | 
			
		||||
            </form>
 | 
			
		||||
        </ui-popup>
 | 
			
		||||
        <page-filter>
 | 
			
		||||
        <page-filter breakpoint="xl" :filterable="false">
 | 
			
		||||
            <template #buttons>
 | 
			
		||||
                <f-text id="search" :model-value="getFilter('search')" label="Suchen …" size="sm" @update:model-value="setFilter('search', $event)"></f-text>
 | 
			
		||||
                <f-multipleselect
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,48 +0,0 @@
 | 
			
		|||
<template>
 | 
			
		||||
    <f-switch v-show="hasModule('bill')" id="ausstand" name="ausstand" label="Nur Ausstände" size="sm" v-model="filter.ausstand"></f-switch>
 | 
			
		||||
    <f-select id="has_vk" name="has_vk" label="Verhaltenskodex unterschrieben" size="sm" :options="meta.boolean_filter" v-model="filter.has_vk"></f-select>
 | 
			
		||||
    <f-select id="has_svk" name="has_svk" label="SVK unterschrieben" size="sm" :options="meta.boolean_filter" v-model="filter.has_svk"></f-select>
 | 
			
		||||
    <f-multipleselect id="group_ids" :options="meta.groups" label="Gruppierungen" size="sm" v-model="filter.group_ids"></f-multipleselect>
 | 
			
		||||
    <f-select v-show="hasModule('bill')" id="billKinds" name="billKinds" :options="meta.billKinds" label="Rechnung" size="sm" v-model="filter.bill_kind"></f-select>
 | 
			
		||||
 | 
			
		||||
    <div class="mt-5">
 | 
			
		||||
        <f-checkboxes-label>nach Mitgliedschaften</f-checkboxes-label>
 | 
			
		||||
        <button class="btn btn-primary label mt-2" @click.prevent="filter.memberships = [...filter.memberships, {...meta.default_membership_filter}]">
 | 
			
		||||
            <ui-sprite class="w-3 h-3 xl:mr-2" src="plus"></ui-sprite>
 | 
			
		||||
            <span class="hidden xl:inline">Hinzufügen</span>
 | 
			
		||||
        </button>
 | 
			
		||||
        <template v-for="(filter, index) in filter.memberships" :key="index">
 | 
			
		||||
            <f-multipleselect :id="`group_ids-multiple-${index}`" class="mt-4" v-model="filter.group_ids" :options="meta.groups" label="Gruppierung" size="sm"></f-multipleselect>
 | 
			
		||||
            <f-multipleselect :id="`activity_ids-multiple-${index}`" v-model="filter.activity_ids" :options="meta.filterActivities" label="Tätigkeiten" size="sm"></f-multipleselect>
 | 
			
		||||
            <f-multipleselect :id="`subactivity_ids-multiple-${index}`" v-model="filter.subactivity_ids" :options="meta.filterSubactivities" label="Untertätigkeiten" size="sm"></f-multipleselect>
 | 
			
		||||
        </template>
 | 
			
		||||
    </div>
 | 
			
		||||
</template>
 | 
			
		||||
 | 
			
		||||
<script setup>
 | 
			
		||||
import {inject, ref, watch} from 'vue';
 | 
			
		||||
 | 
			
		||||
const axios = inject('axios');
 | 
			
		||||
 | 
			
		||||
const emit = defineEmits(['update:modelValue']);
 | 
			
		||||
 | 
			
		||||
const props = defineProps({
 | 
			
		||||
    modelValue: {
 | 
			
		||||
        type: Object,
 | 
			
		||||
        required: true,
 | 
			
		||||
    },
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
const metaResponse = await axios.post('/api/member/search', {});
 | 
			
		||||
const meta = ref(metaResponse.data.meta);
 | 
			
		||||
 | 
			
		||||
const filter = ref({...props.modelValue});
 | 
			
		||||
 | 
			
		||||
watch(
 | 
			
		||||
    filter,
 | 
			
		||||
    function (newValue) {
 | 
			
		||||
        emit('update:modelValue', newValue);
 | 
			
		||||
    },
 | 
			
		||||
    {deep: true}
 | 
			
		||||
);
 | 
			
		||||
</script>
 | 
			
		||||
| 
						 | 
				
			
			@ -18,14 +18,7 @@
 | 
			
		|||
            label="Untertätigkeit"
 | 
			
		||||
            @update:modelValue="setSubactivityId(single, $event)"
 | 
			
		||||
        ></f-select>
 | 
			
		||||
        <f-switch
 | 
			
		||||
            v-if="displayPromisedAt"
 | 
			
		||||
            id="has_promise"
 | 
			
		||||
            name="has_promise"
 | 
			
		||||
            :model-value="single.promised_at !== null"
 | 
			
		||||
            label="Hat Versprechen"
 | 
			
		||||
            @update:modelValue="setPromisedAtSwitch(single, $event)"
 | 
			
		||||
        ></f-switch>
 | 
			
		||||
        <f-switch v-if="displayPromisedAt" id="has_promise" :model-value="single.promised_at !== null" label="Hat Versprechen" @update:modelValue="setPromisedAtSwitch(single, $event)"></f-switch>
 | 
			
		||||
        <f-text v-show="displayPromisedAt && single.promised_at !== null" id="promised_at" v-model="single.promised_at" type="date" label="Versprechensdatum" size="sm"></f-text>
 | 
			
		||||
        <button type="submit" class="btn btn-primary">Absenden</button>
 | 
			
		||||
    </form>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -17,12 +17,80 @@
 | 
			
		|||
                </div>
 | 
			
		||||
            </div>
 | 
			
		||||
        </ui-popup>
 | 
			
		||||
        <page-filter>
 | 
			
		||||
        <ui-popup v-if="membershipFilters !== null" heading="Nach Mitgliedschaften filtern" full @close="membershipFilters = null">
 | 
			
		||||
            <button class="btn btn-primary label mt-2" @click.prevent="membershipFilters.push({...meta.default_membership_filter})">
 | 
			
		||||
                <ui-sprite class="w-3 h-3 xl:mr-2" src="plus"></ui-sprite>
 | 
			
		||||
                <span class="hidden xl:inline">Hinzufügen</span>
 | 
			
		||||
            </button>
 | 
			
		||||
            <div v-for="(filter, index) in membershipFilters" :key="index" class="flex space-x-2 mt-2">
 | 
			
		||||
                <f-multipleselect :id="`group_ids-multiple-${index}`" v-model="filter.group_ids" :options="meta.groups" label="Gruppierung" size="sm"></f-multipleselect>
 | 
			
		||||
                <f-multipleselect :id="`activity_ids-multiple-${index}`" v-model="filter.activity_ids" :options="meta.filterActivities" label="Tätigkeiten" size="sm"></f-multipleselect>
 | 
			
		||||
                <f-multipleselect :id="`subactivity_ids-multiple-${index}`" v-model="filter.subactivity_ids" :options="meta.filterSubactivities" label="Untertätigkeiten" size="sm"></f-multipleselect>
 | 
			
		||||
            </div>
 | 
			
		||||
            <button
 | 
			
		||||
                class="btn btn-primary label mt-3"
 | 
			
		||||
                @click.prevent="
 | 
			
		||||
                    setFilter('memberships', membershipFilters);
 | 
			
		||||
                    membershipFilters = null;
 | 
			
		||||
                "
 | 
			
		||||
            >
 | 
			
		||||
                <span class="hidden xl:inline">Anwenden</span>
 | 
			
		||||
            </button>
 | 
			
		||||
        </ui-popup>
 | 
			
		||||
        <page-filter breakpoint="xl">
 | 
			
		||||
            <template #fields>
 | 
			
		||||
                <member-filter-fields :model-value="filter" @update:model-value="setFilterObject($event)" />
 | 
			
		||||
                <f-switch
 | 
			
		||||
                    v-show="hasModule('bill')"
 | 
			
		||||
                    id="ausstand"
 | 
			
		||||
                    name="ausstand"
 | 
			
		||||
                    :model-value="getFilter('ausstand')"
 | 
			
		||||
                    label="Nur Ausstände"
 | 
			
		||||
                    size="sm"
 | 
			
		||||
                    @update:model-value="setFilter('ausstand', $event)"
 | 
			
		||||
                ></f-switch>
 | 
			
		||||
                <f-select
 | 
			
		||||
                    id="has_vk"
 | 
			
		||||
                    name="has_vk"
 | 
			
		||||
                    :model-value="getFilter('has_vk')"
 | 
			
		||||
                    label="Verhaltenskodex unterschrieben"
 | 
			
		||||
                    size="sm"
 | 
			
		||||
                    :options="meta.boolean_filter"
 | 
			
		||||
                    @update:model-value="setFilter('has_vk', $event)"
 | 
			
		||||
                ></f-select>
 | 
			
		||||
                <f-select
 | 
			
		||||
                    id="has_svk"
 | 
			
		||||
                    name="has_svk"
 | 
			
		||||
                    :model-value="getFilter('has_svk')"
 | 
			
		||||
                    label="SVK unterschrieben"
 | 
			
		||||
                    size="sm"
 | 
			
		||||
                    :options="meta.boolean_filter"
 | 
			
		||||
                    @update:model-value="setFilter('has_svk', $event)"
 | 
			
		||||
                ></f-select>
 | 
			
		||||
                <f-multipleselect
 | 
			
		||||
                    id="group_ids"
 | 
			
		||||
                    :options="meta.groups"
 | 
			
		||||
                    :model-value="getFilter('group_ids')"
 | 
			
		||||
                    label="Gruppierungen"
 | 
			
		||||
                    size="sm"
 | 
			
		||||
                    @update:model-value="setFilter('group_ids', $event)"
 | 
			
		||||
                ></f-multipleselect>
 | 
			
		||||
                <f-select
 | 
			
		||||
                    v-show="hasModule('bill')"
 | 
			
		||||
                    id="billKinds"
 | 
			
		||||
                    name="billKinds"
 | 
			
		||||
                    :options="meta.billKinds"
 | 
			
		||||
                    :model-value="getFilter('bill_kind')"
 | 
			
		||||
                    label="Rechnung"
 | 
			
		||||
                    size="sm"
 | 
			
		||||
                    @update:model-value="setFilter('bill_kind', $event)"
 | 
			
		||||
                ></f-select>
 | 
			
		||||
                <button class="btn btn-primary label mr-2" @click.prevent="membershipFilters = getFilter('memberships')">
 | 
			
		||||
                    <ui-sprite class="w-3 h-3 xl:mr-2" src="filter"></ui-sprite>
 | 
			
		||||
                    <span class="hidden xl:inline">Mitgliedschaften</span>
 | 
			
		||||
                </button>
 | 
			
		||||
            </template>
 | 
			
		||||
            <template #buttons>
 | 
			
		||||
                <f-text id="search" :model-value="filter.search" label="Suchen …" size="sm" @update:model-value="setFilterObject({...filter, search: $event})"></f-text>
 | 
			
		||||
                <f-text id="search" :model-value="getFilter('search')" label="Suchen …" size="sm" @update:model-value="setFilter('search', $event)"></f-text>
 | 
			
		||||
                <button class="btn btn-primary label mr-2" @click.prevent="exportMembers">
 | 
			
		||||
                    <ui-sprite class="w-3 h-3 xl:mr-2" src="save"></ui-sprite>
 | 
			
		||||
                    <span class="hidden xl:inline">Exportieren</span>
 | 
			
		||||
| 
						 | 
				
			
			@ -93,21 +161,21 @@
 | 
			
		|||
    </page-layout>
 | 
			
		||||
</template>
 | 
			
		||||
 | 
			
		||||
<script setup>
 | 
			
		||||
<script lang="js" setup>
 | 
			
		||||
import MemberInvoicePositions from './MemberInvoicePositions.vue';
 | 
			
		||||
import MemberMemberships from './MemberMemberships.vue';
 | 
			
		||||
import MemberCourses from './MemberCourses.vue';
 | 
			
		||||
import Tags from './Tags.vue';
 | 
			
		||||
import Actions from './index/Actions.vue';
 | 
			
		||||
import {indexProps, useIndex} from '../../composables/useIndex.js';
 | 
			
		||||
import {ref, defineProps} from 'vue';
 | 
			
		||||
import MemberFilterFields from './MemberFilterFields.vue';
 | 
			
		||||
import { indexProps, useIndex } from '../../composables/useIndex.js';
 | 
			
		||||
import { ref, defineProps } from 'vue';
 | 
			
		||||
 | 
			
		||||
const single = ref(null);
 | 
			
		||||
const deleting = ref(null);
 | 
			
		||||
const membershipFilters = ref(null);
 | 
			
		||||
 | 
			
		||||
const props = defineProps(indexProps);
 | 
			
		||||
var {router, data, meta, filter, setFilterObject, filterString, reloadPage} = useIndex(props.data, 'member');
 | 
			
		||||
var { router, data, meta, getFilter, setFilter, filterString, reloadPage } = useIndex(props.data, 'member');
 | 
			
		||||
 | 
			
		||||
function exportMembers() {
 | 
			
		||||
    window.open(`/member-export?filter=${filterString.value}`);
 | 
			
		||||
| 
						 | 
				
			
			@ -115,7 +183,7 @@ function exportMembers() {
 | 
			
		|||
 | 
			
		||||
async function remove(member) {
 | 
			
		||||
    new Promise((resolve, reject) => {
 | 
			
		||||
        deleting.value = {resolve, reject, member};
 | 
			
		||||
        deleting.value = { resolve, reject, member };
 | 
			
		||||
    })
 | 
			
		||||
        .then(() => {
 | 
			
		||||
            router.delete(`/member/${member.id}`);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,25 +3,13 @@
 | 
			
		|||
        <template #right>
 | 
			
		||||
            <f-save-button form="preventionform"></f-save-button>
 | 
			
		||||
        </template>
 | 
			
		||||
 | 
			
		||||
        <setting-layout v-if="loaded">
 | 
			
		||||
            <form id="preventionform" class="grow p-6" @submit.prevent="submit">
 | 
			
		||||
                <div class="col-span-full text-gray-100 mb-3">
 | 
			
		||||
                    <p class="text-sm">Hier kannst du Einstellungen zu Prävention setzen.</p>
 | 
			
		||||
                </div>
 | 
			
		||||
                <ui-tabs v-model="active" class="mt-2" :entries="tabs"></ui-tabs>
 | 
			
		||||
                <div v-if="active === 0">
 | 
			
		||||
                    <f-editor v-if="active === 0" id="formmail" v-model="data.formmail" label="E-Mail für Veranstaltungs-TN"></f-editor>
 | 
			
		||||
                </div>
 | 
			
		||||
                <div v-if="active === 1" class="grid gap-6">
 | 
			
		||||
                    <f-switch id="active" v-model="data.active" name="active" label="Regelmäßig an Präventionsunterlagen erinnern"></f-switch>
 | 
			
		||||
                    <div class="flex gap-6">
 | 
			
		||||
                        <f-text id="weeks" v-model="data.weeks" label="Vor Ablauf X Wochen vorher erinnern" type="number" />
 | 
			
		||||
                        <f-text id="fresh_remember_interval" v-model="data.freshRememberInterval" label="Bei Ablauf alle X Wochen erinnern" type="number" />
 | 
			
		||||
                    </div>
 | 
			
		||||
                    <f-editor v-if="active === 1" id="yearlymail" v-model="data.yearlymail" label="Jährliche Präventions-Erinnerung"></f-editor>
 | 
			
		||||
                    <f-member-filter id="yearly_member_filter" v-model="data.yearlyMemberFilter" label="nur für folgende Mitglieder erlauben" />
 | 
			
		||||
                    <f-multipleselect id="prevent_against" v-model="data.preventAgainst" :options="meta.preventAgainsts" label="An diese Dokumente erinnern" size="sm"></f-multipleselect>
 | 
			
		||||
                <div class="grid gap-4 mt-2">
 | 
			
		||||
                    <f-editor id="frommail" v-model="data.formmail" label="E-Mail für Veranstaltungs-TN"></f-editor>
 | 
			
		||||
                </div>
 | 
			
		||||
            </form>
 | 
			
		||||
        </setting-layout>
 | 
			
		||||
| 
						 | 
				
			
			@ -33,13 +21,7 @@ import { ref } from 'vue';
 | 
			
		|||
import { useApiIndex } from '../../composables/useApiIndex.js';
 | 
			
		||||
import SettingLayout from '../setting/Layout.vue';
 | 
			
		||||
 | 
			
		||||
const tabs = [
 | 
			
		||||
    { title: 'für Veranstaltungen' },
 | 
			
		||||
    { title: 'Jährlich' },
 | 
			
		||||
];
 | 
			
		||||
const active = ref(0);
 | 
			
		||||
 | 
			
		||||
const { axios, data, meta, reload } = useApiIndex('/api/prevention', 'prevention');
 | 
			
		||||
const { axios, data, reload } = useApiIndex('/api/prevention', 'prevention');
 | 
			
		||||
const loaded = ref(false);
 | 
			
		||||
 | 
			
		||||
async function load() {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,5 +1,5 @@
 | 
			
		|||
@component('mail::message')
 | 
			
		||||
# Hallo {{ $preventable->getMailRecipient()->name }},
 | 
			
		||||
# Hallo {{ $preventable->member->fullname }},
 | 
			
		||||
 | 
			
		||||
<x-mail-view::editor :content="$bodyText->toArray()['blocks']"></x-mail-view::editor>
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -139,8 +139,7 @@ class IndexTest extends EndToEndTestCase
 | 
			
		|||
        sleep(1);
 | 
			
		||||
        $this->get('/member')
 | 
			
		||||
            ->assertInertiaPath("data.meta.formSubactivities.{$activity->id}.{$subactivity->id}", 'Biber')
 | 
			
		||||
            ->assertInertiaPath("data.meta.filterSubactivities.0.name", 'Biber')
 | 
			
		||||
            ->assertInertiaPath("data.meta.filterSubactivities.0.id", $activity->id)
 | 
			
		||||
            ->assertInertiaPath("data.meta.filterSubactivities.{$subactivity->id}", 'Biber')
 | 
			
		||||
            ->assertInertiaPath("data.meta.formActivities.{$activity->id}", '€ Mitglied');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,445 +0,0 @@
 | 
			
		|||
<?php
 | 
			
		||||
 | 
			
		||||
namespace Tests\EndToEnd\Member;
 | 
			
		||||
 | 
			
		||||
use App\Prevention\Enums\Prevention;
 | 
			
		||||
use App\Form\Actions\PreventionRememberAction;
 | 
			
		||||
use App\Form\Enums\NamiType;
 | 
			
		||||
use App\Form\Enums\SpecialType;
 | 
			
		||||
use App\Form\Models\Form;
 | 
			
		||||
use App\Form\Models\Participant;
 | 
			
		||||
use App\Invoice\InvoiceSettings;
 | 
			
		||||
use App\Lib\Editor\Condition;
 | 
			
		||||
use App\Member\FilterScope;
 | 
			
		||||
use App\Prevention\Mails\PreventionRememberMail;
 | 
			
		||||
use App\Member\Member;
 | 
			
		||||
use App\Member\Membership;
 | 
			
		||||
use App\Prevention\Actions\YearlyRememberAction;
 | 
			
		||||
use App\Prevention\Mails\YearlyMail;
 | 
			
		||||
use App\Prevention\PreventionSettings;
 | 
			
		||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
 | 
			
		||||
use Illuminate\Support\Facades\Mail;
 | 
			
		||||
use Tests\EndToEndTestCase;
 | 
			
		||||
use Tests\Lib\CreatesFormFields;
 | 
			
		||||
use Tests\RequestFactories\EditorRequestFactory;
 | 
			
		||||
 | 
			
		||||
uses(DatabaseTransactions::class);
 | 
			
		||||
uses(CreatesFormFields::class);
 | 
			
		||||
uses(EndToEndTestCase::class);
 | 
			
		||||
 | 
			
		||||
beforeEach(function () {
 | 
			
		||||
    app(PreventionSettings::class)->fill(['preventAgainst' => array_column(Prevention::values(), 'id'), 'active' => true])->save();
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
function createForm(): Form
 | 
			
		||||
{
 | 
			
		||||
    return Form::factory()->fields([
 | 
			
		||||
        test()->textField('vorname')->namiType(NamiType::FIRSTNAME)->specialType(SpecialType::FIRSTNAME),
 | 
			
		||||
        test()->textField('nachname')->namiType(NamiType::FIRSTNAME)->specialType(SpecialType::LASTNAME),
 | 
			
		||||
        test()->textField('email')->namiType(NamiType::FIRSTNAME)->specialType(SpecialType::EMAIL),
 | 
			
		||||
    ])->create(['needs_prevention' => true]);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function createParticipant(Form $form): Participant
 | 
			
		||||
{
 | 
			
		||||
    return Participant::factory()->for($form)->data([
 | 
			
		||||
        'vorname' => 'Max',
 | 
			
		||||
        'nachname' => 'Muster',
 | 
			
		||||
        'email' => 'mail@a.de',
 | 
			
		||||
    ])->for(Member::factory()->defaults()->has(Membership::factory()->inLocal('€ LeiterIn', 'Wölfling')))->create();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function createMember(array $attributes): Member
 | 
			
		||||
{
 | 
			
		||||
    return Member::factory()->defaults()->has(Membership::factory()->inLocal('€ LeiterIn', 'Wölfling'))->create($attributes);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
dataset('attributes', fn() => [
 | 
			
		||||
    [
 | 
			
		||||
        ['has_vk' => false, 'efz' => null, 'ps_at' => null],
 | 
			
		||||
        [Prevention::EFZ, Prevention::VK, Prevention::PS]
 | 
			
		||||
    ],
 | 
			
		||||
 | 
			
		||||
    [
 | 
			
		||||
        ['has_vk' => true, 'efz' => null, 'ps_at' => now()],
 | 
			
		||||
        [Prevention::EFZ]
 | 
			
		||||
    ],
 | 
			
		||||
 | 
			
		||||
    [
 | 
			
		||||
        ['has_vk' => true, 'efz' => now(), 'ps_at' => null],
 | 
			
		||||
        [Prevention::PS]
 | 
			
		||||
    ],
 | 
			
		||||
 | 
			
		||||
    [
 | 
			
		||||
        ['has_vk' => true, 'efz' => now()->subDay(), 'ps_at' => now()],
 | 
			
		||||
        []
 | 
			
		||||
    ],
 | 
			
		||||
 | 
			
		||||
    [
 | 
			
		||||
        ['has_vk' => true, 'efz' => now(), 'ps_at' => now()->subDay()],
 | 
			
		||||
        []
 | 
			
		||||
    ],
 | 
			
		||||
 | 
			
		||||
    [
 | 
			
		||||
        ['has_vk' => true, 'efz' => now()->subYears(5)->subDay(), 'ps_at' => now()],
 | 
			
		||||
        [Prevention::EFZ]
 | 
			
		||||
    ],
 | 
			
		||||
 | 
			
		||||
    [
 | 
			
		||||
        ['has_vk' => true, 'efz' => now(), 'ps_at' => null],
 | 
			
		||||
        [Prevention::PS]
 | 
			
		||||
    ],
 | 
			
		||||
 | 
			
		||||
    [
 | 
			
		||||
        ['has_vk' => true, 'efz' => now(), 'ps_at' => now()->subYears(5)->subDay()],
 | 
			
		||||
        [Prevention::MOREPS]
 | 
			
		||||
    ],
 | 
			
		||||
 | 
			
		||||
    [
 | 
			
		||||
        ['has_vk' => true, 'efz' => now(), 'ps_at' => now()->subYears(5)->subDay(), 'more_ps_at' => now()],
 | 
			
		||||
        []
 | 
			
		||||
    ],
 | 
			
		||||
 | 
			
		||||
    [
 | 
			
		||||
        ['has_vk' => true, 'efz' => now(), 'ps_at' => now()->subYears(15), 'more_ps_at' => now()->subYears(5)->subDay()],
 | 
			
		||||
        [Prevention::MOREPS],
 | 
			
		||||
    ],
 | 
			
		||||
 | 
			
		||||
    [
 | 
			
		||||
        ['has_vk' => false, 'efz' => now(), 'ps_at' => now()],
 | 
			
		||||
        [Prevention::VK],
 | 
			
		||||
    ],
 | 
			
		||||
 | 
			
		||||
    [
 | 
			
		||||
        ['has_vk' => true, 'efz' => now(), 'ps_at' => now()->subYears(7)],
 | 
			
		||||
        [Prevention::MOREPS],
 | 
			
		||||
    ]
 | 
			
		||||
]);
 | 
			
		||||
 | 
			
		||||
it('testItRemembersWhenNotRememberedYet', function () {
 | 
			
		||||
    Mail::fake();
 | 
			
		||||
    $form = createForm();
 | 
			
		||||
    $participant = createParticipant($form);
 | 
			
		||||
 | 
			
		||||
    PreventionRememberAction::run();
 | 
			
		||||
 | 
			
		||||
    $this->assertEquals(now()->format('Y-m-d'), $participant->fresh()->last_remembered_at->format('Y-m-d'));
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
it('testItDoesntRememberPastEvents', function () {
 | 
			
		||||
    Mail::fake();
 | 
			
		||||
    $form = createForm();
 | 
			
		||||
    $participant = createParticipant($form);
 | 
			
		||||
    $form->update(['from' => now()->subDay()]);
 | 
			
		||||
 | 
			
		||||
    PreventionRememberAction::run();
 | 
			
		||||
 | 
			
		||||
    $this->assertNull($participant->fresh()->last_remembered_at);
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
it('testItDoesntRememberWhenConditionDoesntMatch', function () {
 | 
			
		||||
    Mail::fake();
 | 
			
		||||
    $form = createForm();
 | 
			
		||||
    $form->update(['prevention_conditions' => Condition::from(['mode' => 'all', 'ifs' => [['field' => 'vorname', 'comparator' => 'isEqual', 'value' => 'Max']]])]);
 | 
			
		||||
    $participant = createParticipant($form);
 | 
			
		||||
    $participant->update(['data' => [...$participant->data, 'vorname' => 'Jane']]);
 | 
			
		||||
 | 
			
		||||
    PreventionRememberAction::run();
 | 
			
		||||
 | 
			
		||||
    $this->assertNull($participant->fresh()->last_remembered_at);
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
it('testItRemembersWhenRememberIsDue', function () {
 | 
			
		||||
    Mail::fake();
 | 
			
		||||
    $form = createForm();
 | 
			
		||||
    $participant = tap(createParticipant($form), fn($p) => $p->update(['last_remembered_at' => now()->subWeeks(3)]));
 | 
			
		||||
 | 
			
		||||
    PreventionRememberAction::run();
 | 
			
		||||
 | 
			
		||||
    $this->assertEquals(now()->format('Y-m-d'), $participant->fresh()->last_remembered_at->format('Y-m-d'));
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
it('testItDoesntRememberWhenRememberingIsNotDue', function () {
 | 
			
		||||
    Mail::fake();
 | 
			
		||||
    $form = createForm();
 | 
			
		||||
    $participant = tap(createParticipant($form), fn($p) => $p->update(['last_remembered_at' => now()->subWeeks(1)]));
 | 
			
		||||
 | 
			
		||||
    PreventionRememberAction::run();
 | 
			
		||||
 | 
			
		||||
    $this->assertEquals(now()->subWeeks(1)->format('Y-m-d'), $participant->fresh()->last_remembered_at->format('Y-m-d'));
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
it('testItDoesntRememberWhenFormDoesntNeedPrevention', function () {
 | 
			
		||||
    Mail::fake();
 | 
			
		||||
    $form = tap(createForm(), fn($form) => $form->update(['needs_prevention' => false]));
 | 
			
		||||
    $participant = createParticipant($form);
 | 
			
		||||
 | 
			
		||||
    PreventionRememberAction::run();
 | 
			
		||||
 | 
			
		||||
    $this->assertNull($participant->fresh()->last_remembered_at);
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
it('testItDoesntRememberWhenParticipantDoesntHaveMember', function () {
 | 
			
		||||
    Mail::fake();
 | 
			
		||||
    $form = createForm();
 | 
			
		||||
    $participant = createParticipant($form);
 | 
			
		||||
    $participant->member->delete();
 | 
			
		||||
 | 
			
		||||
    PreventionRememberAction::run();
 | 
			
		||||
 | 
			
		||||
    $this->assertNull($participant->fresh()->last_remembered_at);
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
it('doesnt remember non leaders', function () {
 | 
			
		||||
    Mail::fake();
 | 
			
		||||
    $form = createForm();
 | 
			
		||||
    $participant = createParticipant($form);
 | 
			
		||||
    $participant->member->memberships->each->delete();
 | 
			
		||||
 | 
			
		||||
    PreventionRememberAction::run();
 | 
			
		||||
 | 
			
		||||
    $this->assertNotNull($participant->fresh()->last_remembered_at);
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
it('remembers event participant', function ($attrs, $preventions) {
 | 
			
		||||
    Mail::fake();
 | 
			
		||||
    $form = createForm();
 | 
			
		||||
    $participant = createParticipant($form);
 | 
			
		||||
    $participant->member->update($attrs);
 | 
			
		||||
 | 
			
		||||
    PreventionRememberAction::run();
 | 
			
		||||
 | 
			
		||||
    if (count($preventions)) {
 | 
			
		||||
        Mail::assertSent(PreventionRememberMail::class, fn($mail) => $mail->preventable->preventions()->pluck('type')->toArray() === $preventions);
 | 
			
		||||
        $this->assertNotNull($participant->fresh()->last_remembered_at);
 | 
			
		||||
    } else {
 | 
			
		||||
        Mail::assertNotSent(PreventionRememberMail::class);
 | 
			
		||||
        $this->assertNull($participant->fresh()->last_remembered_at);
 | 
			
		||||
    }
 | 
			
		||||
})->with('attributes');
 | 
			
		||||
 | 
			
		||||
it('sets due date in mail when not now', function () {
 | 
			
		||||
    Mail::fake();
 | 
			
		||||
    $form = createForm();
 | 
			
		||||
    $form->update(['from' => now()->addMonths(8)]);
 | 
			
		||||
    $participant = createParticipant($form);
 | 
			
		||||
    $participant->member->update(['efz' =>  now()->subYears(5)->addMonth(), 'ps_at' => now(), 'has_vk' => true]);
 | 
			
		||||
 | 
			
		||||
    PreventionRememberAction::run();
 | 
			
		||||
 | 
			
		||||
    Mail::assertSent(PreventionRememberMail::class, fn($mail) => $mail->preventable->preventions()->first()->expires->isSameDay(now()->addMonth()));
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
it('notices a few weeks before', function ($date, bool $shouldSend) {
 | 
			
		||||
    Mail::fake();
 | 
			
		||||
    app(PreventionSettings::class)->fill(['weeks' => 2])->save();
 | 
			
		||||
    createMember(['efz' => $date, 'ps_at' => now(), 'has_vk' => true]);
 | 
			
		||||
 | 
			
		||||
    sleep(2);
 | 
			
		||||
    YearlyRememberAction::run();
 | 
			
		||||
 | 
			
		||||
    $shouldSend
 | 
			
		||||
        ? Mail::assertSent(YearlyMail::class, fn($mail) => $mail->preventions->first()->expires->isSameDay(now()->addWeeks(2)))
 | 
			
		||||
        : Mail::assertNotSent(YearlyMail::class);
 | 
			
		||||
})->with([
 | 
			
		||||
    [fn() => now()->subYears(5)->addWeeks(2), true],
 | 
			
		||||
    [fn() => now()->subYears(5)->addWeeks(2)->addDay(), false],
 | 
			
		||||
    [fn() => now()->subYears(5)->addWeeks(2)->subDay(), false],
 | 
			
		||||
]);
 | 
			
		||||
 | 
			
		||||
it('remembers members yearly', function ($date, $shouldSend) {
 | 
			
		||||
    Mail::fake();
 | 
			
		||||
    createMember(['efz' => $date, 'ps_at' => now(), 'has_vk' => true]);
 | 
			
		||||
 | 
			
		||||
    sleep(2);
 | 
			
		||||
    YearlyRememberAction::run();
 | 
			
		||||
 | 
			
		||||
    $shouldSend
 | 
			
		||||
        ? Mail::assertSent(YearlyMail::class, fn($mail) => $mail->preventions->first()->expires->isSameDay(now()))
 | 
			
		||||
        : Mail::assertNotSent(YearlyMail::class);
 | 
			
		||||
})->with([
 | 
			
		||||
    [fn() => now()->subYears(5), true],
 | 
			
		||||
    [fn() => now()->subYears(5)->addDay(), false],
 | 
			
		||||
    [fn() => now()->subYears(5)->subDay(), false],
 | 
			
		||||
]);
 | 
			
		||||
 | 
			
		||||
it('remembers yearly only once', function () {
 | 
			
		||||
    Mail::fake();
 | 
			
		||||
    createMember(['efz' => now()->subYears(5), 'ps_at' => now(), 'has_vk' => true]);
 | 
			
		||||
 | 
			
		||||
    sleep(2);
 | 
			
		||||
    YearlyRememberAction::run();
 | 
			
		||||
    YearlyRememberAction::run();
 | 
			
		||||
    YearlyRememberAction::run();
 | 
			
		||||
 | 
			
		||||
    Mail::assertSentCount(1);
 | 
			
		||||
    Mail::assertSent(YearlyMail::class, fn($mail) => $mail->preventions->first()->expires->isSameDay(now()));
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
it('testItDoesntRememberParticipantThatHasNoMail', function () {
 | 
			
		||||
    Mail::fake();
 | 
			
		||||
    $form = createForm();
 | 
			
		||||
    $participant = createParticipant($form);
 | 
			
		||||
    $participant->update(['data' => [...$participant->data, 'email' => '']]);
 | 
			
		||||
 | 
			
		||||
    PreventionRememberAction::run();
 | 
			
		||||
 | 
			
		||||
    Mail::assertNotSent(PreventionRememberMail::class);
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
it('doesnt remember when prevent against doesnt match', function () {
 | 
			
		||||
    Mail::fake();
 | 
			
		||||
    app(PreventionSettings::class)->fill(['preventAgainst' => []])->save();
 | 
			
		||||
    createMember(['efz' => now()->subYears(5), 'ps_at' => now(), 'has_vk' => true]);
 | 
			
		||||
 | 
			
		||||
    sleep(2);
 | 
			
		||||
    YearlyRememberAction::run();
 | 
			
		||||
 | 
			
		||||
    Mail::assertNotSent(YearlyMail::class);
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
it('doesnt send yearly mail when member has no mail', function () {
 | 
			
		||||
    Mail::fake();
 | 
			
		||||
    createMember(['efz' => now()->subYears(5), 'ps_at' => now(), 'has_vk' => true, 'email' => '', 'email_parents' => '']);
 | 
			
		||||
 | 
			
		||||
    sleep(2);
 | 
			
		||||
    YearlyRememberAction::run();
 | 
			
		||||
 | 
			
		||||
    Mail::assertNotSent(YearlyMail::class);
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
it('doesnt send yearly mail when yearly sending is deactivated', function () {
 | 
			
		||||
    Mail::fake();
 | 
			
		||||
    app(PreventionSettings::class)->fill(['active' => false])->save();
 | 
			
		||||
    createMember(['efz' => now()->subYears(5), 'ps_at' => now(), 'has_vk' => true]);
 | 
			
		||||
 | 
			
		||||
    sleep(2);
 | 
			
		||||
    YearlyRememberAction::run();
 | 
			
		||||
 | 
			
		||||
    Mail::assertNotSent(YearlyMail::class);
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
it('doesnt send yearly mail when member doesnt match', function () {
 | 
			
		||||
    Mail::fake();
 | 
			
		||||
    app(PreventionSettings::class)->fill([
 | 
			
		||||
        'yearlyMemberFilter' => FilterScope::from(['search' => 'Lorem Ipsum']),
 | 
			
		||||
    ])->save();
 | 
			
		||||
    createMember(['efz' => now()->subYears(5), 'ps_at' => now(), 'has_vk' => true, 'firstname' => 'Max', 'lastname' => 'Muster']);
 | 
			
		||||
 | 
			
		||||
    sleep(2);
 | 
			
		||||
    YearlyRememberAction::run();
 | 
			
		||||
 | 
			
		||||
    Mail::assertNotSent(YearlyMail::class);
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
it('testItRendersSetttingMail', function () {
 | 
			
		||||
    Mail::fake();
 | 
			
		||||
    app(PreventionSettings::class)->fill([
 | 
			
		||||
        'formmail' => EditorRequestFactory::new()->paragraphs(["lorem lala {formname} g", "{wanted}", "bbb"])->toData()
 | 
			
		||||
    ])->save();
 | 
			
		||||
    $form = createForm();
 | 
			
		||||
    createParticipant($form);
 | 
			
		||||
 | 
			
		||||
    PreventionRememberAction::run();
 | 
			
		||||
 | 
			
		||||
    Mail::assertSent(PreventionRememberMail::class, fn($mail) => $mail->bodyText->hasAll([
 | 
			
		||||
        'lorem lala ' . $form->name,
 | 
			
		||||
        'erweitertes'
 | 
			
		||||
    ]) && $mail->bodyText->hasNot(now()->format('d.m.Y')));
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
it('testItAppendsTextOfForm', function () {
 | 
			
		||||
    Mail::fake();
 | 
			
		||||
    app(PreventionSettings::class)->fill([
 | 
			
		||||
        'formmail' => EditorRequestFactory::new()->paragraphs(["::first::"])->toData()
 | 
			
		||||
    ])->save();
 | 
			
		||||
    $form = createForm();
 | 
			
		||||
    $form->update(['prevention_text' => EditorRequestFactory::new()->paragraphs(['event'])->toData()]);
 | 
			
		||||
    createParticipant($form);
 | 
			
		||||
 | 
			
		||||
    PreventionRememberAction::run();
 | 
			
		||||
 | 
			
		||||
    Mail::assertSent(PreventionRememberMail::class, fn($mail) => $mail->bodyText->hasAll([
 | 
			
		||||
        'event'
 | 
			
		||||
    ]));
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
it('testItDoesntAppendTextTwice', function () {
 | 
			
		||||
    Mail::fake();
 | 
			
		||||
    app(PreventionSettings::class)->fill(['frommail' => EditorRequestFactory::new()->paragraphs(["::first::"])->toData()])->save();
 | 
			
		||||
    tap(createForm(), function ($f) {
 | 
			
		||||
        $f->update(['prevention_text' => EditorRequestFactory::new()->paragraphs(['oberhausen'])->toData()]);
 | 
			
		||||
        createParticipant($f);
 | 
			
		||||
    });
 | 
			
		||||
    tap(createForm(), function ($f) {
 | 
			
		||||
        $f->update(['prevention_text' => EditorRequestFactory::new()->paragraphs(['siegburg'])->toData()]);
 | 
			
		||||
        createParticipant($f);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    PreventionRememberAction::run();
 | 
			
		||||
 | 
			
		||||
    Mail::assertSent(PreventionRememberMail::class, fn($mail) => $mail->bodyText->hasAll(['oberhausen']) && !$mail->bodyText->hasAll(['siegburg']));
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
/* ----------------------------------------- Mail contents ----------------------------------------- */
 | 
			
		||||
it('displays body text in prevention remember mail', function () {
 | 
			
		||||
    $form = createForm();
 | 
			
		||||
    $participant = createParticipant($form);
 | 
			
		||||
 | 
			
		||||
    $mail = new PreventionRememberMail($participant, EditorRequestFactory::new()->paragraphs(['ggtt'])->toData(), collect([]));
 | 
			
		||||
    $mail->assertSeeInText('ggtt');
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
it('renders prevention mail for events with group name', function () {
 | 
			
		||||
    InvoiceSettings::fake(['from_long' => 'Stamm Beispiel']);
 | 
			
		||||
    $form = createForm();
 | 
			
		||||
    $participant = createParticipant($form);
 | 
			
		||||
    (new PreventionRememberMail($participant, app(PreventionSettings::class)->formmail, collect([])))
 | 
			
		||||
        ->assertSeeInText('Max')
 | 
			
		||||
        ->assertSeeInText('Muster')
 | 
			
		||||
        ->assertSeeInText('Stamm Beispiel');
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
it('renders yearly mail', function () {
 | 
			
		||||
    InvoiceSettings::fake(['from_long' => 'Stamm Beispiel']);
 | 
			
		||||
    $member = createMember([]);
 | 
			
		||||
    $mail = new YearlyMail($member, EditorRequestFactory::new()->paragraphs(['ggtt'])->toData(), collect([]));
 | 
			
		||||
    $mail
 | 
			
		||||
        ->assertSeeInText('ggtt')
 | 
			
		||||
        ->assertSeeInText('Stamm Beispiel');
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
it('renders setting of yearly mail', function () {
 | 
			
		||||
    Mail::fake();
 | 
			
		||||
    app(PreventionSettings::class)->fill([
 | 
			
		||||
        'yearlymail' => EditorRequestFactory::new()->paragraphs(["{wanted}", "bbb"])->toData()
 | 
			
		||||
    ])->save();
 | 
			
		||||
    $member = createMember((['efz' =>  now()->subYears(5), 'ps_at' => now(), 'has_vk' => true]));
 | 
			
		||||
 | 
			
		||||
    sleep(2);
 | 
			
		||||
    YearlyRememberAction::run();
 | 
			
		||||
 | 
			
		||||
    Mail::assertSent(
 | 
			
		||||
        YearlyMail::class,
 | 
			
		||||
        fn($mail) => $mail->bodyText->hasAll(['erweitertes', 'bbb'])
 | 
			
		||||
            && $mail->bodyText->hasNot(now()->format('d.m.Y'))
 | 
			
		||||
    );
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
it('renders expires at date for preventions', function () {
 | 
			
		||||
    Mail::fake();
 | 
			
		||||
    app(PreventionSettings::class)->fill([
 | 
			
		||||
        'yearlymail' => EditorRequestFactory::new()->paragraphs(["{wanted}"])->toData(),
 | 
			
		||||
        'weeks' => 4,
 | 
			
		||||
    ])->save();
 | 
			
		||||
    createMember((['efz' =>  now()->subYears(5)->addWeeks(4), 'ps_at' => now(), 'has_vk' => true]));
 | 
			
		||||
 | 
			
		||||
    sleep(2);
 | 
			
		||||
    YearlyRememberAction::run();
 | 
			
		||||
 | 
			
		||||
    Mail::assertSent(YearlyMail::class, fn($mail) => $mail->bodyText->hasAll([
 | 
			
		||||
        'erweitertes',
 | 
			
		||||
        'am ' . now()->addWeeks(4)->format('d.m.Y'),
 | 
			
		||||
    ]) && $mail->bodyText->hasNot(now()->format('d.m.Y')));
 | 
			
		||||
});
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,306 @@
 | 
			
		|||
<?php
 | 
			
		||||
 | 
			
		||||
namespace Tests\Feature\Member;
 | 
			
		||||
 | 
			
		||||
use App\Prevention\Enums\Prevention;
 | 
			
		||||
use App\Form\Actions\PreventionRememberAction;
 | 
			
		||||
use App\Form\Enums\NamiType;
 | 
			
		||||
use App\Form\Enums\SpecialType;
 | 
			
		||||
use App\Form\Models\Form;
 | 
			
		||||
use App\Form\Models\Participant;
 | 
			
		||||
use App\Invoice\InvoiceSettings;
 | 
			
		||||
use App\Lib\Editor\Condition;
 | 
			
		||||
use App\Prevention\Mails\PreventionRememberMail;
 | 
			
		||||
use App\Member\Member;
 | 
			
		||||
use App\Member\Membership;
 | 
			
		||||
use App\Prevention\PreventionSettings;
 | 
			
		||||
use Generator;
 | 
			
		||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
 | 
			
		||||
use Illuminate\Support\Facades\Mail;
 | 
			
		||||
use PHPUnit\Framework\Attributes\DataProvider;
 | 
			
		||||
use Tests\Lib\CreatesFormFields;
 | 
			
		||||
use Tests\RequestFactories\EditorRequestFactory;
 | 
			
		||||
use Tests\TestCase;
 | 
			
		||||
 | 
			
		||||
class PreventionTest extends TestCase
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
    use DatabaseTransactions;
 | 
			
		||||
    use CreatesFormFields;
 | 
			
		||||
 | 
			
		||||
    public function testItRemembersWhenNotRememberedYet(): void
 | 
			
		||||
    {
 | 
			
		||||
        Mail::fake();
 | 
			
		||||
        $form = $this->createForm();
 | 
			
		||||
        $participant = $this->createParticipant($form);
 | 
			
		||||
 | 
			
		||||
        PreventionRememberAction::run();
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals(now()->format('Y-m-d'), $participant->fresh()->last_remembered_at->format('Y-m-d'));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testItDoesntRememberPastEvents(): void
 | 
			
		||||
    {
 | 
			
		||||
        Mail::fake();
 | 
			
		||||
        $form = $this->createForm();
 | 
			
		||||
        $participant = $this->createParticipant($form);
 | 
			
		||||
        $form->update(['from' => now()->subDay()]);
 | 
			
		||||
 | 
			
		||||
        PreventionRememberAction::run();
 | 
			
		||||
 | 
			
		||||
        $this->assertNull($participant->fresh()->last_remembered_at);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testItDoesntRememberWhenConditionDoesntMatch(): void
 | 
			
		||||
    {
 | 
			
		||||
        Mail::fake();
 | 
			
		||||
        $form = $this->createForm();
 | 
			
		||||
        $form->update(['prevention_conditions' => Condition::from(['mode' => 'all', 'ifs' => [['field' => 'vorname', 'comparator' => 'isEqual', 'value' => 'Max']]])]);
 | 
			
		||||
        $participant = $this->createParticipant($form);
 | 
			
		||||
        $participant->update(['data' => [...$participant->data, 'vorname' => 'Jane']]);
 | 
			
		||||
 | 
			
		||||
        PreventionRememberAction::run();
 | 
			
		||||
 | 
			
		||||
        $this->assertNull($participant->fresh()->last_remembered_at);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testItRemembersWhenRememberIsDue(): void
 | 
			
		||||
    {
 | 
			
		||||
        Mail::fake();
 | 
			
		||||
        $form = $this->createForm();
 | 
			
		||||
        $participant = tap($this->createParticipant($form), fn ($p) => $p->update(['last_remembered_at' => now()->subWeeks(3)]));
 | 
			
		||||
 | 
			
		||||
        PreventionRememberAction::run();
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals(now()->format('Y-m-d'), $participant->fresh()->last_remembered_at->format('Y-m-d'));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testItDoesntRememberWhenRememberingIsNotDue(): void
 | 
			
		||||
    {
 | 
			
		||||
        Mail::fake();
 | 
			
		||||
        $form = $this->createForm();
 | 
			
		||||
        $participant = tap($this->createParticipant($form), fn ($p) => $p->update(['last_remembered_at' => now()->subWeeks(1)]));
 | 
			
		||||
 | 
			
		||||
        PreventionRememberAction::run();
 | 
			
		||||
 | 
			
		||||
        $this->assertEquals(now()->subWeeks(1)->format('Y-m-d'), $participant->fresh()->last_remembered_at->format('Y-m-d'));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testItDoesntRememberWhenFormDoesntNeedPrevention(): void
 | 
			
		||||
    {
 | 
			
		||||
        Mail::fake();
 | 
			
		||||
        $form = tap($this->createForm(), fn ($form) => $form->update(['needs_prevention' => false]));
 | 
			
		||||
        $participant = $this->createParticipant($form);
 | 
			
		||||
 | 
			
		||||
        PreventionRememberAction::run();
 | 
			
		||||
 | 
			
		||||
        $this->assertNull($participant->fresh()->last_remembered_at);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testItDoesntRememberWhenParticipantDoesntHaveMember(): void
 | 
			
		||||
    {
 | 
			
		||||
        Mail::fake();
 | 
			
		||||
        $form = $this->createForm();
 | 
			
		||||
        $participant = $this->createParticipant($form);
 | 
			
		||||
        $participant->member->delete();
 | 
			
		||||
 | 
			
		||||
        PreventionRememberAction::run();
 | 
			
		||||
 | 
			
		||||
        $this->assertNull($participant->fresh()->last_remembered_at);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testItRemembersNonLeaders(): void
 | 
			
		||||
    {
 | 
			
		||||
        Mail::fake();
 | 
			
		||||
        $form = $this->createForm();
 | 
			
		||||
        $participant = $this->createParticipant($form);
 | 
			
		||||
        $participant->member->memberships->each->delete();
 | 
			
		||||
 | 
			
		||||
        PreventionRememberAction::run();
 | 
			
		||||
 | 
			
		||||
        $this->assertNotNull($participant->fresh()->last_remembered_at);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static function attributes(): Generator
 | 
			
		||||
    {
 | 
			
		||||
        yield [
 | 
			
		||||
            'attrs' => ['has_vk' => true, 'efz' => null, 'ps_at' => now()],
 | 
			
		||||
            'preventions' => [Prevention::EFZ]
 | 
			
		||||
        ];
 | 
			
		||||
 | 
			
		||||
        yield [
 | 
			
		||||
            'attrs' => ['has_vk' => true, 'efz' => now(), 'ps_at' => null],
 | 
			
		||||
            'preventions' => [Prevention::PS]
 | 
			
		||||
        ];
 | 
			
		||||
 | 
			
		||||
        yield [
 | 
			
		||||
            'attrs' => ['has_vk' => true, 'efz' => now()->subDay(), 'ps_at' => now()],
 | 
			
		||||
            'preventions' => []
 | 
			
		||||
        ];
 | 
			
		||||
 | 
			
		||||
        yield [
 | 
			
		||||
            'attrs' => ['has_vk' => true, 'efz' => now(), 'ps_at' => now()->subDay()],
 | 
			
		||||
            'preventions' => []
 | 
			
		||||
        ];
 | 
			
		||||
 | 
			
		||||
        yield [
 | 
			
		||||
            'attrs' => ['has_vk' => true, 'efz' => now()->subYears(5)->subDay(), 'ps_at' => now()],
 | 
			
		||||
            'preventions' => [Prevention::EFZ]
 | 
			
		||||
        ];
 | 
			
		||||
 | 
			
		||||
        yield [
 | 
			
		||||
            'attrs' => ['has_vk' => true, 'efz' => now(), 'ps_at' => null],
 | 
			
		||||
            'preventions' => [Prevention::PS]
 | 
			
		||||
        ];
 | 
			
		||||
 | 
			
		||||
        yield [
 | 
			
		||||
            'attrs' => ['has_vk' => true, 'efz' => now(), 'ps_at' => now()->subYears(5)->subDay()],
 | 
			
		||||
            'preventions' => [Prevention::MOREPS]
 | 
			
		||||
        ];
 | 
			
		||||
 | 
			
		||||
        yield [
 | 
			
		||||
            'attrs' => ['has_vk' => true, 'efz' => now(), 'ps_at' => now()->subYears(5)->subDay(), 'more_ps_at' => now()],
 | 
			
		||||
            'preventions' => []
 | 
			
		||||
        ];
 | 
			
		||||
 | 
			
		||||
        yield [
 | 
			
		||||
            'attrs' => ['has_vk' => true, 'efz' => now(), 'ps_at' => now()->subYears(15), 'more_ps_at' => now()->subYears(5)->subDay()],
 | 
			
		||||
            'preventions' => [Prevention::MOREPS],
 | 
			
		||||
        ];
 | 
			
		||||
 | 
			
		||||
        yield [
 | 
			
		||||
            'attrs' => ['has_vk' => false, 'efz' => now(), 'ps_at' => now()],
 | 
			
		||||
            'preventions' => [Prevention::VK],
 | 
			
		||||
        ];
 | 
			
		||||
 | 
			
		||||
        yield [
 | 
			
		||||
            'attrs' => ['has_vk' => true, 'efz' => now(), 'ps_at' => now()->subYears(7)],
 | 
			
		||||
            'preventions' => [Prevention::MOREPS],
 | 
			
		||||
        ];
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param array<int, Prevention> $preventions
 | 
			
		||||
     * @param array<string, mixed> $memberAttributes
 | 
			
		||||
     */
 | 
			
		||||
    #[DataProvider('attributes')]
 | 
			
		||||
    public function testItRemembersMember(array $attrs, array $preventions): void
 | 
			
		||||
    {
 | 
			
		||||
        Mail::fake();
 | 
			
		||||
        $form = $this->createForm();
 | 
			
		||||
        $participant = $this->createParticipant($form);
 | 
			
		||||
        $participant->member->update($attrs);
 | 
			
		||||
 | 
			
		||||
        PreventionRememberAction::run();
 | 
			
		||||
 | 
			
		||||
        if (count($preventions)) {
 | 
			
		||||
            Mail::assertSent(PreventionRememberMail::class, fn ($mail) => $mail->preventable->preventions() === $preventions);
 | 
			
		||||
            $this->assertNotNull($participant->fresh()->last_remembered_at);
 | 
			
		||||
        } else {
 | 
			
		||||
            Mail::assertNotSent(PreventionRememberMail::class);
 | 
			
		||||
            $this->assertNull($participant->fresh()->last_remembered_at);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testItDoesntRememberParticipantThatHasNoMail(): void
 | 
			
		||||
    {
 | 
			
		||||
        Mail::fake();
 | 
			
		||||
        $form = $this->createForm();
 | 
			
		||||
        $participant = $this->createParticipant($form);
 | 
			
		||||
        $participant->update(['data' => [...$participant->data, 'email' => '']]);
 | 
			
		||||
 | 
			
		||||
        PreventionRememberAction::run();
 | 
			
		||||
 | 
			
		||||
        Mail::assertNotSent(PreventionRememberMail::class);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testItRendersMail(): void
 | 
			
		||||
    {
 | 
			
		||||
        InvoiceSettings::fake(['from_long' => 'Stamm Beispiel']);
 | 
			
		||||
        $form = $this->createForm();
 | 
			
		||||
        $participant = $this->createParticipant($form);
 | 
			
		||||
        (new PreventionRememberMail($participant, app(PreventionSettings::class)->formmail))
 | 
			
		||||
            ->assertSeeInText($participant->member->firstname)
 | 
			
		||||
            ->assertSeeInText($participant->member->lastname)
 | 
			
		||||
            ->assertSeeInText('Stamm Beispiel');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testItRendersSetttingMail(): void
 | 
			
		||||
    {
 | 
			
		||||
        Mail::fake();
 | 
			
		||||
        app(PreventionSettings::class)->fill([
 | 
			
		||||
            'formmail' => EditorRequestFactory::new()->paragraphs(["lorem lala {formname} g", "{wanted}", "bbb"])->toData()
 | 
			
		||||
        ])->save();
 | 
			
		||||
        $form = $this->createForm();
 | 
			
		||||
        $this->createParticipant($form);
 | 
			
		||||
 | 
			
		||||
        PreventionRememberAction::run();
 | 
			
		||||
 | 
			
		||||
        Mail::assertSent(PreventionRememberMail::class, fn ($mail) => $mail->bodyText->hasAll([
 | 
			
		||||
            'lorem lala ' . $form->name,
 | 
			
		||||
            'erweitertes'
 | 
			
		||||
        ]));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testItAppendsTextOfForm(): void
 | 
			
		||||
    {
 | 
			
		||||
        Mail::fake();
 | 
			
		||||
        app(PreventionSettings::class)->fill([
 | 
			
		||||
            'formmail' => EditorRequestFactory::new()->paragraphs(["::first::"])->toData()
 | 
			
		||||
        ])->save();
 | 
			
		||||
        $form = $this->createForm();
 | 
			
		||||
        $form->update(['prevention_text' => EditorRequestFactory::new()->paragraphs(['event'])->toData()]);
 | 
			
		||||
        $this->createParticipant($form);
 | 
			
		||||
 | 
			
		||||
        PreventionRememberAction::run();
 | 
			
		||||
 | 
			
		||||
        Mail::assertSent(PreventionRememberMail::class, fn ($mail) => $mail->bodyText->hasAll([
 | 
			
		||||
            'event'
 | 
			
		||||
        ]));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testItDoesntAppendTextTwice(): void
 | 
			
		||||
    {
 | 
			
		||||
        Mail::fake();
 | 
			
		||||
        app(PreventionSettings::class)->fill(['frommail' => EditorRequestFactory::new()->paragraphs(["::first::"])->toData()])->save();
 | 
			
		||||
        tap($this->createForm(), function ($f) {
 | 
			
		||||
            $f->update(['prevention_text' => EditorRequestFactory::new()->paragraphs(['oberhausen'])->toData()]);
 | 
			
		||||
            $this->createParticipant($f);
 | 
			
		||||
        });
 | 
			
		||||
        tap($this->createForm(), function ($f) {
 | 
			
		||||
            $f->update(['prevention_text' => EditorRequestFactory::new()->paragraphs(['siegburg'])->toData()]);
 | 
			
		||||
            $this->createParticipant($f);
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
        PreventionRememberAction::run();
 | 
			
		||||
 | 
			
		||||
        Mail::assertSent(PreventionRememberMail::class, fn ($mail) => $mail->bodyText->hasAll(['oberhausen']) && !$mail->bodyText->hasAll(['siegburg']));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testItDisplaysBodyTextInMail(): void
 | 
			
		||||
    {
 | 
			
		||||
        $form = $this->createForm();
 | 
			
		||||
        $participant = $this->createParticipant($form);
 | 
			
		||||
 | 
			
		||||
        $mail = new PreventionRememberMail($participant, EditorRequestFactory::new()->paragraphs(['ggtt'])->toData());
 | 
			
		||||
        $mail->assertSeeInText('ggtt');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected function createForm(): Form
 | 
			
		||||
    {
 | 
			
		||||
        return Form::factory()->fields([
 | 
			
		||||
            $this->textField('vorname')->namiType(NamiType::FIRSTNAME)->specialType(SpecialType::FIRSTNAME),
 | 
			
		||||
            $this->textField('nachname')->namiType(NamiType::FIRSTNAME)->specialType(SpecialType::LASTNAME),
 | 
			
		||||
            $this->textField('email')->namiType(NamiType::FIRSTNAME)->specialType(SpecialType::EMAIL),
 | 
			
		||||
        ])->create(['needs_prevention' => true]);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected function createParticipant(Form $form): Participant
 | 
			
		||||
    {
 | 
			
		||||
        return Participant::factory()->for($form)->data([
 | 
			
		||||
            'vorname' => 'Max',
 | 
			
		||||
            'nachname' => 'Muster',
 | 
			
		||||
            'email' => 'mail@a.de',
 | 
			
		||||
        ])->for(Member::factory()->defaults()->has(Membership::factory()->inLocal('€ LeiterIn', 'Wölfling')))->create();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -2,73 +2,39 @@
 | 
			
		|||
 | 
			
		||||
namespace Tests\Feature\Prevention;
 | 
			
		||||
 | 
			
		||||
use App\Member\FilterScope;
 | 
			
		||||
use App\Prevention\Enums\Prevention;
 | 
			
		||||
use App\Prevention\PreventionSettings;
 | 
			
		||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
 | 
			
		||||
use Tests\RequestFactories\EditorRequestFactory;
 | 
			
		||||
use Tests\TestCase;
 | 
			
		||||
 | 
			
		||||
uses(DatabaseTransactions::class);
 | 
			
		||||
class SettingTest extends TestCase
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
it('testItOpensSettingsPage', function () {
 | 
			
		||||
    test()->withoutExceptionHandling();
 | 
			
		||||
    test()->login()->loginNami();
 | 
			
		||||
    use DatabaseTransactions;
 | 
			
		||||
 | 
			
		||||
    test()->get('/setting/prevention')->assertComponent('setting/Prevention')->assertOk();
 | 
			
		||||
});
 | 
			
		||||
    public function testItOpensSettingsPage(): void
 | 
			
		||||
    {
 | 
			
		||||
        $this->login()->loginNami();
 | 
			
		||||
 | 
			
		||||
it('receives settings', function () {
 | 
			
		||||
    test()->login()->loginNami();
 | 
			
		||||
        $this->get('/setting/prevention')->assertComponent('setting/Prevention')->assertOk();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    $text = EditorRequestFactory::new()->text(50, 'lorem ipsum')->toData();
 | 
			
		||||
    $yearlyMail = EditorRequestFactory::new()->text(50, 'lala dd')->toData();
 | 
			
		||||
    app(PreventionSettings::class)->fill([
 | 
			
		||||
        'formmail' => $text,
 | 
			
		||||
        'yearlymail' => $yearlyMail,
 | 
			
		||||
        'weeks' => 9,
 | 
			
		||||
        'freshRememberInterval' => 11,
 | 
			
		||||
        'active' => true,
 | 
			
		||||
        'preventAgainst' => [Prevention::MOREPS->name],
 | 
			
		||||
        'yearlyMemberFilter' => FilterScope::from([
 | 
			
		||||
            'memberships' => [['group_ids' => [33]]],
 | 
			
		||||
            'search' => 'searchstring',
 | 
			
		||||
        ]),
 | 
			
		||||
    ])->save();
 | 
			
		||||
    public function testItReceivesSettings(): void
 | 
			
		||||
    {
 | 
			
		||||
        $this->login()->loginNami();
 | 
			
		||||
 | 
			
		||||
    test()->get('/api/prevention')
 | 
			
		||||
        ->assertJsonPath('data.formmail.blocks.0.data.text', 'lorem ipsum')
 | 
			
		||||
        ->assertJsonPath('data.yearlymail.blocks.0.data.text', 'lala dd')
 | 
			
		||||
        ->assertJsonPath('data.weeks', '9')
 | 
			
		||||
        ->assertJsonPath('data.active', true)
 | 
			
		||||
        ->assertJsonPath('data.freshRememberInterval', '11')
 | 
			
		||||
        ->assertJsonPath('data.yearlyMemberFilter.search', 'searchstring')
 | 
			
		||||
        ->assertJsonPath('data.yearlyMemberFilter.memberships.0.group_ids.0', 33)
 | 
			
		||||
        ->assertJsonPath('data.preventAgainst', ['MOREPS'])
 | 
			
		||||
        ->assertJsonPath('meta.preventAgainsts.0.name', 'erweitertes Führungszeugnis')
 | 
			
		||||
        ->assertJsonPath('meta.preventAgainsts.0.id', 'EFZ');
 | 
			
		||||
});
 | 
			
		||||
        $text = EditorRequestFactory::new()->text(50, 'lorem ipsum')->toData();
 | 
			
		||||
        app(PreventionSettings::class)->fill(['formmail' => $text])->save();
 | 
			
		||||
 | 
			
		||||
it('testItStoresSettings', function () {
 | 
			
		||||
    test()->login()->loginNami();
 | 
			
		||||
        $this->get('/api/prevention')
 | 
			
		||||
            ->assertJsonPath('data.formmail.blocks.0.data.text', 'lorem ipsum');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    test()->post('/api/prevention', [
 | 
			
		||||
        'formmail' => EditorRequestFactory::new()->text(50, 'new lorem')->create(),
 | 
			
		||||
        'yearlymail' => EditorRequestFactory::new()->text(50, 'lala dd')->create(),
 | 
			
		||||
        'weeks' => 9,
 | 
			
		||||
        'freshRememberInterval' => 11,
 | 
			
		||||
        'active' => true,
 | 
			
		||||
        'preventAgainst' => ['EFZ'],
 | 
			
		||||
        'yearlyMemberFilter' => [
 | 
			
		||||
            'memberships' => [['group_ids' => 33]],
 | 
			
		||||
            'search' => 'searchstring',
 | 
			
		||||
        ],
 | 
			
		||||
    ])->assertOk();
 | 
			
		||||
    test()->assertTrue(app(PreventionSettings::class)->formmail->hasAll(['new lorem']));
 | 
			
		||||
    test()->assertTrue(app(PreventionSettings::class)->yearlymail->hasAll(['lala dd']));
 | 
			
		||||
    test()->assertEquals(9, app(PreventionSettings::class)->weeks);
 | 
			
		||||
    test()->assertEquals(11, app(PreventionSettings::class)->freshRememberInterval);
 | 
			
		||||
    test()->assertTrue(app(PreventionSettings::class)->active);
 | 
			
		||||
    test()->assertEquals([['group_ids' => 33]], app(PreventionSettings::class)->yearlyMemberFilter->memberships);
 | 
			
		||||
    test()->assertEquals('searchstring', app(PreventionSettings::class)->yearlyMemberFilter->search);
 | 
			
		||||
    test()->assertEquals('EFZ', app(PreventionSettings::class)->preventAgainst[0]);
 | 
			
		||||
});
 | 
			
		||||
    public function testItStoresSettings(): void
 | 
			
		||||
    {
 | 
			
		||||
        $this->login()->loginNami();
 | 
			
		||||
 | 
			
		||||
        $this->post('/api/prevention', ['formmail' => EditorRequestFactory::new()->text(50, 'new lorem')->create()])->assertOk();
 | 
			
		||||
        $this->assertTrue(app(PreventionSettings::class)->formmail->hasAll(['new lorem']));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue