Skip to content

Commit 21c4109

Browse files
authored
feat: add support for non-standard cnp (#690)
1 parent 1561bce commit 21c4109

9 files changed

Lines changed: 80 additions & 8 deletions

app/Filament/Resources/Beneficiaries/Schemas/OcasionalBeneficiaryForm.php

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,16 @@ public static function configure(Schema $schema): Schema
7777
Group::make()
7878
->schema([
7979
TextInput::make('cnp')
80-
->label(__('field.cnp'))
81-
->placeholder(__('placeholder.cnp'))
80+
->label(fn (Get $get) => $get('has_non_standard_cnp')
81+
? __('field.non_standard_cnp')
82+
: __('field.cnp'))
83+
->placeholder(fn (Get $get) => $get('has_non_standard_cnp')
84+
? __('placeholder.non_standard_cnp')
85+
: __('placeholder.cnp'))
8286
->unique(ignoreRecord: true)
8387
->nullable()
84-
->rule(new ValidCNP)
88+
->maxLength(13)
89+
->rule(new ValidCNP, fn (Get $get): bool => ! $get('has_non_standard_cnp'))
8590
->disabled(function (Get $get) {
8691
return (bool) $get('does_not_have_cnp')
8792
|| (bool) $get('does_not_provide_cnp');
@@ -100,13 +105,23 @@ public static function configure(Schema $schema): Schema
100105
}
101106
}),
102107

108+
Checkbox::make('has_non_standard_cnp')
109+
->label(__('field.has_non_standard_cnp'))
110+
->default(false)
111+
->live()
112+
->afterStateUpdated(function (Set $set) {
113+
$set('does_not_have_cnp', false);
114+
$set('does_not_provide_cnp', false);
115+
}),
116+
103117
Checkbox::make('does_not_have_cnp')
104118
->label(__('field.does_not_have_cnp'))
105119
->default(false)
106120
->live()
107121
->afterStateUpdated(function (Set $set) {
108122
$set('cnp', null);
109123
$set('does_not_provide_cnp', false);
124+
$set('has_non_standard_cnp', false);
110125
}),
111126

112127
Checkbox::make('does_not_provide_cnp')
@@ -116,6 +131,7 @@ public static function configure(Schema $schema): Schema
116131
->afterStateUpdated(function (Set $set) {
117132
$set('cnp', null);
118133
$set('does_not_have_cnp', false);
134+
$set('has_non_standard_cnp', false);
119135
}),
120136
]),
121137
]),

app/Filament/Resources/Beneficiaries/Schemas/OcasionalBeneficiaryInfolist.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ public static function configure(Schema $schema): Schema
4444
->label(__('field.gender')),
4545

4646
TextEntry::make('cnp_with_fallback')
47-
->label(__('field.cnp')),
47+
->label(fn (Beneficiary $record) => $record->has_non_standard_cnp
48+
? __('field.non_standard_cnp')
49+
: __('field.cnp')),
4850
]),
4951
]),
5052

app/Filament/Resources/Beneficiaries/Schemas/RegularBeneficiaryForm.php

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,16 @@ public static function configure(Schema $schema, bool $includeProgram = false):
155155
Group::make()
156156
->components([
157157
TextInput::make('cnp')
158-
->label(__('field.cnp'))
159-
->placeholder(__('placeholder.cnp'))
158+
->label(fn (Get $get) => $get('has_non_standard_cnp')
159+
? __('field.non_standard_cnp')
160+
: __('field.cnp'))
161+
->placeholder(fn (Get $get) => $get('has_non_standard_cnp')
162+
? __('placeholder.non_standard_cnp')
163+
: __('placeholder.cnp'))
160164
->unique(ignoreRecord: true)
161165
->nullable()
162-
->rule(new ValidCNP)
166+
->maxLength(13)
167+
->rule(new ValidCNP, fn (Get $get): bool => ! $get('has_non_standard_cnp'))
163168
->disabled(function (Get $get) {
164169
return (bool) $get('does_not_have_cnp')
165170
|| (bool) $get('does_not_provide_cnp');
@@ -178,13 +183,23 @@ public static function configure(Schema $schema, bool $includeProgram = false):
178183
}
179184
}),
180185

186+
Checkbox::make('has_non_standard_cnp')
187+
->label(__('field.has_non_standard_cnp'))
188+
->default(false)
189+
->live()
190+
->afterStateUpdated(function (Set $set) {
191+
$set('does_not_have_cnp', false);
192+
$set('does_not_provide_cnp', false);
193+
}),
194+
181195
Checkbox::make('does_not_have_cnp')
182196
->label(__('field.does_not_have_cnp'))
183197
->default(false)
184198
->live()
185199
->afterStateUpdated(function (Set $set) {
186200
$set('cnp', null);
187201
$set('does_not_provide_cnp', false);
202+
$set('has_non_standard_cnp', false);
188203
}),
189204

190205
Checkbox::make('does_not_provide_cnp')
@@ -194,6 +209,7 @@ public static function configure(Schema $schema, bool $includeProgram = false):
194209
->afterStateUpdated(function (Set $set) {
195210
$set('cnp', null);
196211
$set('does_not_have_cnp', false);
212+
$set('has_non_standard_cnp', false);
197213
}),
198214
]),
199215

app/Filament/Resources/Beneficiaries/Schemas/RegularBeneficiaryInfolist.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ public static function configure(Schema $schema): Schema
9292
->label(__('field.last_name')),
9393

9494
TextEntry::make('cnp_with_fallback')
95-
->label(__('field.cnp')),
95+
->label(fn (Beneficiary $record) => $record->has_non_standard_cnp
96+
? __('field.non_standard_cnp')
97+
: __('field.cnp')),
9698

9799
TextEntry::make('id_type')
98100
->label(__('field.id_type')),

app/Models/Beneficiary.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class Beneficiary extends Model
6868

6969
'does_not_have_cnp',
7070
'does_not_provide_cnp',
71+
'has_non_standard_cnp',
7172
];
7273

7374
protected $casts = [
@@ -81,6 +82,7 @@ class Beneficiary extends Model
8182
'date_of_birth' => 'date',
8283
'does_not_have_cnp' => 'boolean',
8384
'does_not_provide_cnp' => 'boolean',
85+
'has_non_standard_cnp' => 'boolean',
8486
];
8587

8688
public function getActivitylogOptions(): LogOptions

database/factories/BeneficiaryFactory.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public function definition()
5050
'date_of_birth' => fake()->date(),
5151
'does_not_have_cnp' => ! $cnpMissingReason,
5252
'does_not_provide_cnp' => $cnpMissingReason,
53+
'has_non_standard_cnp' => false,
5354
'ethnicity' => fake()->boolean(25) ? fake()->randomElement(Ethnicity::values()) : null,
5455
'work_status' => fake()->boolean(25) ? fake()->randomElement(WorkStatus::values()) : null,
5556
];
@@ -155,6 +156,17 @@ public function withCNP(): static
155156
),
156157
'does_not_have_cnp' => false,
157158
'does_not_provide_cnp' => false,
159+
'has_non_standard_cnp' => false,
160+
]);
161+
}
162+
163+
public function withNonStandardCNP(): static
164+
{
165+
return $this->state(fn (array $attributes) => [
166+
'cnp' => fake()->numerify('#############'),
167+
'does_not_have_cnp' => false,
168+
'does_not_provide_cnp' => false,
169+
'has_non_standard_cnp' => true,
158170
]);
159171
}
160172

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Illuminate\Database\Migrations\Migration;
6+
use Illuminate\Database\Schema\Blueprint;
7+
use Illuminate\Support\Facades\Schema;
8+
9+
return new class extends Migration
10+
{
11+
public function up(): void
12+
{
13+
Schema::table('beneficiaries', function (Blueprint $table) {
14+
$table->boolean('has_non_standard_cnp')
15+
->default(false)
16+
->after('does_not_provide_cnp');
17+
});
18+
}
19+
};

lang/ro/field.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
'gp_phone' => 'Telefon medic de familie',
8080
'has_gp_agreement' => 'Există acord de parteneriat între angajator și medicul de familie?',
8181
'has_graduated_specialization' => 'Absolvire program',
82+
'has_non_standard_cnp' => 'Beneficiarul are CNP cu format non-standard',
8283
'has_participated_specialization' => 'Parcurgere program',
8384
'has_unknown_identity' => 'Identitate necunoscută beneficiar',
8485
'hour' => 'Oră',
@@ -97,6 +98,7 @@
9798
'location' => 'Locație',
9899
'mediator' => 'Mediator',
99100
'monitoring_recommendations' => 'Elemente de monitorizare / Acțiuni recomandate',
101+
'non_standard_cnp' => 'CNP non-standard',
100102
'notes' => 'Descriere / Observații',
101103
'nurse' => 'Asistent Medical Comunitar',
102104
'optional' => 'Câmp opțional',

lang/ro/placeholder.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
'no_segmentation_city' => 'Fără segmentare pe localitate',
4141
'no_segmentation_county' => 'Fără segmentare pe județ',
4242
'no_segmentation_gender' => 'Fără segmentare pe sex',
43+
'non_standard_cnp' => 'Introdu CNP-ul non-standard',
4344
'organizer' => 'Introdu organizatorul',
4445
'participants' => 'Introdu număr beneficiari',
4546
'phone' => 'Număr de telefon',

0 commit comments

Comments
 (0)