Skip to content

Commit

Permalink
Merge branch 'main' into 397-specialist-general-incorrect-user-permis…
Browse files Browse the repository at this point in the history
…sions-in-the-comunitatea-sunrise-section
  • Loading branch information
alexPopaCode4 authored Dec 17, 2024
2 parents 061ae5a + 415911e commit 4f72acb
Show file tree
Hide file tree
Showing 20 changed files with 144 additions and 36 deletions.
24 changes: 24 additions & 0 deletions app/Concerns/HasBirthdate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace App\Concerns;

use Carbon\Carbon;

trait HasBirthdate
{
public function initializeHasBirthdate()
{
$this->casts['birthdate'] = 'date';

$this->fillable[] = 'birthdate';
}

public function setBirthdateAttribute(?string $value = null): void
{
$date = $value ? Carbon::createFromFormat('d-m-Y', $value) : null;

$this->attributes['birthdate'] = $date?->format('Y-m-d');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use App\Enums\Gender;
use App\Enums\IDType;
use App\Filament\Organizations\Resources\BeneficiaryResource;
use App\Forms\Components\DatePicker;
use App\Forms\Components\DateInput;
use App\Forms\Components\Location;
use App\Forms\Components\Select;
use App\Forms\Components\Spacer;
Expand Down Expand Up @@ -136,7 +136,7 @@ public static function getBeneficiaryIdentityFormSchema(?Beneficiary $parentBene
return;
}

if (filled($birthdate = (new Cnp($state))->getBirthDateFromCNP())) {
if (filled($birthdate = (new Cnp($state))->getBirthDateFromCNP('d-m-Y'))) {
$set('birthdate', $birthdate);
}
});
Expand All @@ -154,10 +154,8 @@ public static function getBeneficiaryIdentityFormSchema(?Beneficiary $parentBene
->options(Gender::options())
->enum(Gender::class),

DatePicker::make('birthdate')
DateInput::make('birthdate')
->label(__('field.birthdate'))
->maxDate(today()->endOfDay())
->nullable()
->live(),

TextInput::make('birthplace')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ protected function identitySectionSection(): Section

TextEntry::make('birthdate')
->label(__('field.birthdate'))
->formatStateUsing(fn ($state) => $state === '-' ? $state : $state->toDateString()),
->formatStateUsing(fn ($state) => $state !== '-' ? $state->format('m-d-Y') : $state),

EnumEntry::make('gender')
->label(__('field.gender')),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ protected static function identitySchema(): array

TextEntry::make('birthdate')
->label(__('field.birthdate'))
->formatStateUsing(fn ($state) => $state !== '-' ? $state->format('Y-m-d') : $state),
->formatStateUsing(fn ($state) => $state !== '-' ? $state->format('d-m-Y') : $state),

TextEntry::make('birthplace')
->label(__('field.birthplace'))
Expand Down Expand Up @@ -278,7 +278,8 @@ public static function childrenSchema(): array
->label(__('field.gender')),

TextEntry::make('birthdate')
->label(__('field.birthdate')),
->label(__('field.birthdate'))
->formatStateUsing(fn ($state) => $state !== '-' ? $state->format('d-m-Y') : $state),

TextEntry::make('current_address')
->label(__('field.current_address')),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ class EditCommunityProfile extends EditRecord

protected static string $view = 'filament.organizations.pages.empty-page';

public function getBreadcrumbs(): array
{
return [];
}

public function getTitle(): string|Htmlable
{
return __('community.headings.empty_state_title');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ class ListCommunityProfiles extends ListRecords

protected static string $view = 'filament.organizations.pages.empty-page';

public function getBreadcrumbs(): array
{
return [];
}

public function getTitle(): string|Htmlable
{
return __('community.headings.empty_state_title');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use App\Models\Monitoring;
use App\Models\Specialist;
use App\Services\Breadcrumb\BeneficiaryBreadcrumb;
use Carbon\Carbon;
use Filament\Actions\Action;
use Filament\Forms\Components\Wizard;
use Filament\Forms\Set;
Expand Down Expand Up @@ -70,6 +71,10 @@ protected function afterFill(): void
->first()
?->load(['children', 'specialistsTeam']);
$this->children = $this->getChildren();
foreach ($this->children as &$child) {
$child['birthdate'] = $child['birthdate'] ? Carbon::parse($child['birthdate'])->format('d-m-Y') : null;
}

$this->specialistTeam = $this->getSpecialists();

$data = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use App\Enums\ChildAggressorRelationship;
use App\Enums\MaintenanceSources;
use App\Filament\Organizations\Resources\MonitoringResource;
use App\Forms\Components\DatePicker;
use App\Forms\Components\DateInput;
use App\Forms\Components\Repeater;
use App\Forms\Components\Select;
use App\Services\Breadcrumb\BeneficiaryBreadcrumb;
Expand Down Expand Up @@ -83,7 +83,7 @@ public static function getSchema(): array
->maxLength(2)
->mask('99'),

DatePicker::make('birthdate')
DateInput::make('birthdate')
->label(__('monitoring.labels.birthdate')),

Select::make('aggressor_relationship')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ public function infolist(Infolist $infolist): Infolist
->label(__('monitoring.labels.age')),

TextEntry::make('birthdate')
->label(__('monitoring.labels.birthdate')),
->label(__('monitoring.labels.birthdate'))
->formatStateUsing(fn ($state) => $state !== '-' ? $state->format('d-m-Y') : $state),

TextEntry::make('aggressor_relationship')
->label(__('monitoring.labels.aggressor_relationship')),
Expand Down
14 changes: 12 additions & 2 deletions app/Filament/Organizations/Resources/UserResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,18 @@ public static function getSchema(): array
->afterStateUpdated(self::setDefaultCaseAndNgoAdminPermissions()),

Placeholder::make('obs')
->content(new HtmlString(__('user.placeholders.obs')))
->label('')
->hiddenLabel()
->content(function (Get $get) {

foreach ($get('role_id') as $roleID) {
$role = self::getRole($roleID);
if ($role->case_permissions->contains(CasePermission::HAS_ACCESS_TO_ALL_CASES))
{
return new HtmlString(__('user.placeholders.user_role_with_permissions_for_all_cases'));
}
}
return new HtmlString(__('user.placeholders.user_role_without_permissions_for_all_cases'));
})
->columnSpanFull(),

Group::make()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,9 @@ protected function getHeaderActions(): array
Actions\CreateAction::make(),
];
}

public function getBreadcrumbs(): array
{
return [];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,13 @@ public function infolist(Infolist $infolist): Infolist
->label(__('user.labels.phone_number')),

TextEntry::make('rolesInOrganization.name')
->label(__('user.labels.select_roles'))
->columnSpanFull(),

TextEntry::make('obs')
->default(
Str::of(__('user.placeholders.obs'))
->toHtmlString()
)
->hiddenLabel()
->columnSpanFull(),
->label(__('user.labels.select_roles')),

TextEntry::make('can_be_case_manager')
->label(__('user.labels.can_be_case_manager'))
->state(fn (User $record) => Ternary::tryFrom((int)$record->canBeCaseManager())),



Group::make()
->columnSpanFull()
Expand Down
2 changes: 1 addition & 1 deletion app/Forms/Components/DateInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ protected function setUp(): void

$this->placeholder('dd-mm-yyyy');
$this->mask('99-99-9999');
$this->formatStateUsing(fn (string $state) => $state ? Carbon::parse($state)->format('d-m-Y') : null);
$this->formatStateUsing(fn (?string $state) => $state ? Carbon::parse($state)->format('d-m-Y') : null);
$this->rules([
'date_format:d-m-Y',
fn (): Closure => function (string $attribute, $value, Closure $fail) {
Expand Down
4 changes: 2 additions & 2 deletions app/Models/Beneficiary.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace App\Models;

use App\Concerns\BelongsToOrganization;
use App\Concerns\HasBirthdate;
use App\Concerns\HasCaseStatus;
use App\Concerns\HasCitizenship;
use App\Concerns\HasEffectiveAddress;
Expand Down Expand Up @@ -36,6 +37,7 @@ class Beneficiary extends Model
use LogsActivity;
use LogsActivityOptions;
use HasSpecialistsTeam;
use HasBirthdate;

protected $fillable = [
'initial_id',
Expand All @@ -47,7 +49,6 @@ class Beneficiary extends Model
'cnp',
'gender',

'birthdate',
'birthplace',
'ethnicity',

Expand Down Expand Up @@ -80,7 +81,6 @@ class Beneficiary extends Model

protected $casts = [
'id_type' => IDType::class,
'birthdate' => 'date',
'children_18_care_count' => 'integer',
'children_accompanying_count' => 'integer',
'children_care_count' => 'integer',
Expand Down
9 changes: 2 additions & 7 deletions app/Models/Children.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace App\Models;

use App\Concerns\BelongsToBeneficiary;
use App\Concerns\HasBirthdate;
use App\Enums\GenderShortValues;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Factories\HasFactory;
Expand All @@ -14,10 +15,10 @@ class Children extends Model
{
use HasFactory;
use BelongsToBeneficiary;
use HasBirthdate;

protected $fillable = [
'name',
'birthdate',
'current_address',
'status',
'gender',
Expand All @@ -34,10 +35,4 @@ public function getAgeAttribute(): int | string | null

return $age === 0 ? '<1' : $age;
}

public function setBirthdateAttribute(?string $value = null): void
{
$date = Carbon::createFromFormat('d-m-Y', $value);
$this->attributes['birthdate'] = $date->format('Y-m-d');
}
}
3 changes: 2 additions & 1 deletion app/Models/MonitoringChild.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Models;

use App\Concerns\HasBirthdate;
use App\Enums\ChildAggressorRelationship;
use App\Enums\MaintenanceSources;
use Illuminate\Database\Eloquent\Factories\HasFactory;
Expand All @@ -13,13 +14,13 @@
class MonitoringChild extends Model
{
use HasFactory;
use HasBirthdate;

protected $fillable = [
'monitoring_id',
'name',
'status',
'age',
'birthdate',
'aggressor_relationship',
'maintenance_sources',
'location',
Expand Down
1 change: 0 additions & 1 deletion database/factories/ChildrenFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public function definition(): array
{
return [
'name' => fake()->name(),
'age' => fake()->boolean() ? fake()->numberBetween(0, 20) : null,
'birthdate' => fake()->date(),
'current_address' => fake()->boolean() ? fake()->address() : null,
'status' => fake()->boolean() ? fake()->words(asText: true) : null,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('beneficiary_interventions', function (Blueprint $table) {
$table->dropColumn('start_date');
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('beneficiary_interventions', function (Blueprint $table) {
//
});
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('intervention_services', function (Blueprint $table) {
$table->dropColumn('start_date');
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('intervention_services', function (Blueprint $table) {
//
});
}
};
4 changes: 3 additions & 1 deletion lang/ro/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
'case_permissions' => 'Permisiuni cazuri',
'admin_permissions' => 'Permisiuni administrare',
'last_login_at_date_time' => 'Data și ora ultimei accesări',
'can_be_case_manager' => 'Poate lua rol de manager de caz',
],

'stats' => [
Expand All @@ -52,7 +53,8 @@
],

'placeholders' => [
'obs' => 'Acest tip de utilizator <span class="italic">are acces doar la cazurile din echipa cărora face parte</span> și nu deține drepturi de administrare ale sistemului. Puteți oferi permisiuni suplimentare din lista de mai jos.',
'user_role_without_permissions_for_all_cases' => 'Acest tip de utilizator <span class="italic">are acces doar la cazurile din echipa cărora face parte</span> și nu deține drepturi de administrare ale sistemului. Puteți oferi permisiuni suplimentare din lista de mai jos.',
'user_role_with_permissions_for_all_cases' => 'Acest tip de rol are acces <span class="italic">la toate cazurile din cadrul Centrului</span>, însă nu deține drepturi de administrare ale sistemului. Puteți oferi permisiuni suplimentare din lista de mai jos.',
'dashboard_cart' => 'Distribuția pe luni a numărului total de utilizatori activi Sunrise. Un utilizator este considerat activ dacă a avut cel puțin o accesare a platformei în luna calendaristică respectivă.',
],

Expand Down

0 comments on commit 4f72acb

Please sign in to comment.