Skip to content

Commit

Permalink
Merge branch 'main' into 287-500-internal-server-error-when-attemptin…
Browse files Browse the repository at this point in the history
…g-to-create-an-existing-staff-account-in-a-different-center
  • Loading branch information
alexPopaCode4 authored Dec 2, 2024
2 parents a1f4af8 + 3a5097f commit b0539cd
Show file tree
Hide file tree
Showing 27 changed files with 512 additions and 131 deletions.
10 changes: 10 additions & 0 deletions app/Actions/ExportReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class ExportReport extends Action

protected bool | null $showMissingValues = false;

protected bool | null $addCasesInMonitoring = false;

protected function setUp(): void
{
parent::setUp();
Expand Down Expand Up @@ -58,13 +60,21 @@ public function setShowMissingValues(?bool $showMissingValues): self
return $this;
}

public function setAddCasesInMonitoring(?bool $addCasesInMonitoring): self
{
$this->addCasesInMonitoring = $addCasesInMonitoring;

return $this;
}

public function generateExport(): BinaryFileResponse
{
$service = new BeneficiariesV2();
$service->setReportType($this->reportType)
->setStartDate($this->startDate)
->setEndDate($this->endDate)
->setShowMissingValue($this->showMissingValues)
->setAddCasesInMonitoring($this->addCasesInMonitoring)
->composeReport();

$fileName = \sprintf('%s_%s_%s.xlsx', $this->startDate, $this->endDate, $this->reportType->value);
Expand Down
18 changes: 18 additions & 0 deletions app/Concerns/HasPermissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,22 @@ public function hasAccessToCommunity()

return (bool) $this->permissions?->admin_permissions->contains(AdminPermission::CAN_CHANGE_ORGANISATION_PROFILE);
}

public function canSearchBeneficiary(): bool
{
if ($this->isNgoAdmin()) {
return true;
}

return $this->permissions?->case_permissions->contains(CasePermission::CAN_SEARCH_AND_COPY_CASES_IN_ALL_CENTERS);
}

public function hasAccessToReports(): bool
{
if ($this->isNgoAdmin()) {
return true;
}

return (bool) $this->permissions?->case_permissions->contains(CasePermission::HAS_ACCESS_TO_STATISTICS);
}
}
7 changes: 7 additions & 0 deletions app/Concerns/LogsActivityOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace App\Concerns;

use App\Models\Activity;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Spatie\Activitylog\LogOptions;
use Spatie\Activitylog\Traits\LogsActivity;

Expand All @@ -31,4 +32,10 @@ public function tapActivity(Activity $activity, string $eventName)
$activity->event = $activity->subject_type;
$activity->subject()->associate($this->beneficiary);
}

public function activity(): HasMany
{
return $this->hasMany(Activity::class, 'subject_id')
->where('subject_type', 'beneficiary');
}
}
29 changes: 29 additions & 0 deletions app/Concerns/PreventMultipleSubmit.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace App\Concerns;

use Cache;
use Filament\Support\Exceptions\Halt;
use Illuminate\Support\Str;

trait PreventMultipleSubmit
{
public function beforeCreate(): void
{
$className = Str::replace(' ', '_', self::$resource::getTitleCaseModelLabel());
$className = Str::lower($className);
$cacheKey = \sprintf('create_%s_%d', $className, auth()->id());
$lock = Cache::lock($cacheKey, 5);

if (! $lock->get()) {
throw new Halt();
}
}

public function beforeSave(): void
{
$this->beforeCreate();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@

namespace App\Filament\Admin\Resources\BenefitResource\Pages;

use App\Concerns\PreventMultipleSubmit;
use App\Filament\Admin\Resources\BenefitResource;
use Filament\Resources\Pages\CreateRecord;
use Illuminate\Contracts\Support\Htmlable;

class CreateBenefit extends CreateRecord
{
use PreventMultipleSubmit;

protected static string $resource = BenefitResource::class;

protected static bool $canCreateAnother = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Filament\Admin\Resources\InstitutionResource\Pages;

use App\Concerns\PreventMultipleSubmit;
use App\Filament\Admin\Resources\InstitutionResource;
use App\Filament\Admin\Resources\UserInstitutionResource\Pages\EditUserInstitution;
use App\Forms\Components\Repeater;
Expand All @@ -17,6 +18,7 @@
class CreateInstitution extends CreateRecord
{
use HasWizard;
use PreventMultipleSubmit;

protected static string $resource = InstitutionResource::class;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@

namespace App\Filament\Admin\Resources\OrganizationResource\Pages;

use App\Concerns\PreventMultipleSubmit;
use App\Filament\Admin\Resources\OrganizationResource;
use Filament\Resources\Pages\CreateRecord;

class CreateOrganization extends CreateRecord
{
use PreventMultipleSubmit;

protected static string $resource = OrganizationResource::class;

protected static bool $canCreateAnother = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@

namespace App\Filament\Admin\Resources\ResultResource\Pages;

use App\Concerns\PreventMultipleSubmit;
use App\Filament\Admin\Resources\ResultResource;
use Filament\Resources\Pages\CreateRecord;
use Illuminate\Contracts\Support\Htmlable;

class CreateResult extends CreateRecord
{
use PreventMultipleSubmit;

protected static string $resource = ResultResource::class;

protected static bool $canCreateAnother = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@

namespace App\Filament\Admin\Resources\RoleResource\Pages;

use App\Concerns\PreventMultipleSubmit;
use App\Filament\Admin\Resources\RoleResource;
use Filament\Resources\Pages\CreateRecord;
use Illuminate\Contracts\Support\Htmlable;

class CreateRole extends CreateRecord
{
use PreventMultipleSubmit;

protected static string $resource = RoleResource::class;

protected static bool $canCreateAnother = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@

namespace App\Filament\Admin\Resources\ServiceResource\Pages;

use App\Concerns\PreventMultipleSubmit;
use App\Filament\Admin\Resources\ServiceResource;
use Filament\Resources\Pages\CreateRecord;
use Illuminate\Contracts\Support\Htmlable;

class CreateService extends CreateRecord
{
use PreventMultipleSubmit;

protected static string $resource = ServiceResource::class;

protected static bool $canCreateAnother = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@

namespace App\Filament\Admin\Resources\UserResource\Pages;

use App\Concerns\PreventMultipleSubmit;
use App\Filament\Admin\Resources\UserResource;
use Filament\Resources\Pages\CreateRecord;

class CreateUser extends CreateRecord
{
use PreventMultipleSubmit;

protected static string $resource = UserResource::class;

protected static bool $canCreateAnother = false;
Expand Down
47 changes: 39 additions & 8 deletions app/Filament/Organizations/Pages/ReportsPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,20 @@
use App\Enums\ReportType;
use App\Forms\Components\ReportTable;
use Filament\Forms;
use Filament\Forms\Components\Checkbox;
use Filament\Forms\Components\DatePicker;
use Filament\Forms\Components\Select;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Form;
use Filament\Forms\Get;
use Filament\Infolists\Components\Section;
use Filament\Infolists\Contracts\HasInfolists;
use Filament\Infolists\Infolist;
use Filament\Pages\Concerns\InteractsWithFormActions;
use Filament\Pages\Page;
use Illuminate\Contracts\Support\Htmlable;
use Illuminate\Contracts\View\View;
use Illuminate\Support\HtmlString;

class ReportsPage extends Page implements Forms\Contracts\HasForms, HasInfolists
{
Expand All @@ -37,6 +42,13 @@ class ReportsPage extends Page implements Forms\Contracts\HasForms, HasInfolists

public $show_missing_values;

public $add_cases_in_monitoring;

public static function canAccess(): bool
{
return auth()->user()->hasAccessToReports();
}

public static function getNavigationGroup(): ?string
{
return __('navigation.statistics._group');
Expand Down Expand Up @@ -69,22 +81,39 @@ protected function getFormSchema(): array
Forms\Components\Section::make()
->columns(4)
->schema([
Forms\Components\Select::make('report_type')
Select::make('report_type')
->key('report_type')
->label(__('report.labels.report_type'))
->columnSpan(2)
->options(ReportType::options())
->searchable(),

Forms\Components\DatePicker::make('start_date')
DatePicker::make('start_date')
->label(__('report.labels.start_date'))
->default(now()->startOfMonth()),
->default(now()->startOfMonth())
->maxDate(fn (Get $get) => $get('end_date') ? debug($get('end_date')) : now())
->live(),

Forms\Components\DatePicker::make('end_date')
DatePicker::make('end_date')
->label(__('report.labels.end_date'))
->default(now()),
->default(now())
->minDate(fn (Get $get) => $get('start_date') ?? null)
->maxDate(now())
->live(),

Checkbox::make('add_cases_in_monitoring')
->label(
new HtmlString(
\sprintf(
'<span class="heroicon heroicon-o-information-circle" title="%s">%s</span>',
__('report.helpers.add_cases_in_monitoring'),
__('report.labels.add_cases_in_monitoring'),
)
)
)
->columnSpan(2),

Forms\Components\Checkbox::make('show_missing_values')
Checkbox::make('show_missing_values')
->label(__('report.labels.show_missing_values'))
->default(true)
->columnSpan(2),
Expand All @@ -107,7 +136,8 @@ public function infolist(Infolist $infolist): Infolist
->setReportType($this->report_type)
->setStartDate($this->start_date)
->setEndDate($this->end_date)
->setShowMissingValues($this->show_missing_values),
->setShowMissingValues($this->show_missing_values)
->setAddCasesInMonitoring($this->add_cases_in_monitoring),
])
->schema([
$this->reportTable(),
Expand All @@ -121,7 +151,8 @@ public function reportTable(): ReportTable
->setReportType($this->report_type ? ReportType::tryFrom($this->report_type) : null)
->setStartDate($this->start_date)
->setEndDate($this->end_date)
->setShowMissingValue($this->show_missing_values);
->setShowMissingValue($this->show_missing_values)
->setAddCasesInMonitoring($this->add_cases_in_monitoring);
}

public function render(): View
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@

namespace App\Filament\Organizations\Resources\BeneficiaryInterventionResource\Pages;

use App\Concerns\PreventMultipleSubmit;
use App\Filament\Organizations\Resources\BeneficiaryInterventionResource;
use Filament\Resources\Pages\CreateRecord;

class CreateBeneficiaryIntervention extends CreateRecord
{
use PreventMultipleSubmit;

protected static string $resource = BeneficiaryInterventionResource::class;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Filament\Organizations\Resources\BeneficiaryResource\Pages\CloseFile;

use App\Concerns\PreventMultipleSubmit;
use App\Filament\Organizations\Resources\BeneficiaryResource;
use App\Models\Specialist;
use App\Services\Breadcrumb\BeneficiaryBreadcrumb;
Expand All @@ -18,6 +19,7 @@
class CreateCloseFile extends EditRecord
{
use HasWizard;
use PreventMultipleSubmit;

protected static string $resource = BeneficiaryResource::class;

Expand Down
Loading

0 comments on commit b0539cd

Please sign in to comment.