Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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
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