Created
October 5, 2023 13:26
-
-
Save emmexx/818ece716c353e9c282aaa0a89117228 to your computer and use it in GitHub Desktop.
Example of a filament wizard
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use... [omitted] | |
class CreateMembership extends CreateRecord | |
{ | |
use CreateRecord\Concerns\HasWizard; | |
protected static string $resource = MembershipResource::class; | |
protected function getSteps(): array | |
{ | |
return [ | |
Step::make('Long text') | |
->icon('heroicon-m-document-text') | |
->schema([ | |
Placeholder::make('Text loaded from view file') | |
->content(view('filament.myapp.pages.conditions')), | |
Toggle::make('Accept conditions') | |
->accepted() | |
->Label(__('Accept the conditions')) | |
->helperText(__('You have to accept the conditions')), | |
]), | |
Step::make('Member info') | |
->icon('heroicon-m-ticket') | |
->schema([ | |
Section::make(__('Tax info')) | |
->compact() | |
->columns(3) | |
->schema([ | |
TextInput::make('company') | |
->columnspan(2) | |
->required() | |
->Label(__('Company name')), | |
Select::make('tax status') | |
->columnSpan(1) | |
->options( | |
[ | |
'persona_fisica' => 'persona fisica', | |
'impresa_individuale' => 'impresa (ditta) individuale', | |
'snc' => 'società in nome collettivo (s.n.c.)', | |
'sas' => 'società in accomandita semplice (s.a.s.)', | |
'societa_semplice' => 'società semplice (s.s.)', | |
'spa' => 'società per azioni (s.p.a.)', | |
'srl' => 'società a responsabilità limitata (s.r.l.)', | |
'sapa' => 'società in accomandita per azioni (s.a.p.a.)', | |
'ssa' => 'società semplice agricola', | |
'aps' => 'associazione di promozione sociale (a.p.s.)', | |
'ente_religioso' => 'ente religioso', | |
'associazione' => 'associazione', | |
'associazione_sportiva' => 'associazione sportiva', | |
'coop' => 'società cooperativa', | |
'scs' => 'società cooperativa sociale', | |
'altro' => 'altro (indicarlo nel campo note)', | |
]) | |
->required() | |
->Label(__('Tax status')), | |
Select::make('billing_id') | |
->columnSpan(2) | |
->label('Billing address') | |
->helperText('Select the billing address') | |
->relationship(name: 'billings', titleAttribute: 'addressee') | |
->createOptionForm( | |
MembershipResource::getAddressFormFields() //4 field components to fill the modal | |
) | |
->searchable() | |
->preload(), | |
TextInput::make('Name') | |
->Label(__('Name of the member')) | |
->helperText(__('A person to contact')), | |
TextInput::make('tax number') | |
->minLength(11) | |
->maxLength(13) | |
->Label(__('Tax number')) | |
->rules([ | |
function() | |
{ | |
return function (string $attribute, $value, Closure $fail) { | |
if(strlen($value) !== 11 && strlen($value) !== 13) | |
{ | |
$fail(':attribute is not correct'); | |
return; | |
} | |
if(!$this->checkTaxNumber($value)) //a function that checks if the tax number is formally valid | |
{ | |
$fail(':attribute is not correct'); | |
} | |
}; | |
} | |
]), | |
TextInput::make('SSN') | |
->required() | |
->minLength(11) | |
->maxLength(16) | |
->Label(__('SSN')) | |
->rules([ | |
function() | |
{ | |
return function (string $attribute, $value, Closure $fail) { | |
$lunghezza = strlen($value); | |
if($lunghezza !== 16 && $lunghezza !== 11 && $lunghezza !== 13) | |
{ | |
$fail(':attribute is not correct'); | |
return; | |
} | |
// 2 casi | |
if($lunghezza == 11 || $lunghezza == 13) | |
{ | |
if(!$this->checkTaxNumber($value)) | |
{ | |
$fail(':attribute is not correct'); | |
} | |
return; | |
} | |
// Check regex | |
if (!preg_match('/^[a-z]{6}[0-9]{2}[a-z][0-9]{2}[a-z][0-9]{3}[a-z]$/i', $value)) | |
{ | |
$fail(':attribute not correct'); | |
return; | |
} | |
$listEvenChar = array('0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' => 0, 'B' => 1, 'C' => 2, 'D' => 3, 'E' => 4, 'F' => 5, 'G' => 6, 'H' => 7, 'I' => 8, 'J' => 9, 'K' => 10, 'L' => 11, 'M' => 12, 'N' => 13, 'O' => 14, 'P' => 15, 'Q' => 16, 'R' => 17, 'S' => 18, 'T' => 19, 'U' => 20, 'V' => 21, 'W' => 22, 'X' => 23, 'Y' => 24, 'Z' => 25); | |
$listOddChar = array('0' => 1, '1' => 0, '2' => 5, '3' => 7, '4' => 9, '5' => 13, '6' => 15, '7' => 17, '8' => 19, '9' => 21, 'A' => 1, 'B' => 0, 'C' => 5, 'D' => 7, 'E' => 9, 'F' => 13, 'G' => 15, 'H' => 17, 'I' => 19, 'J' => 21, 'K' => 2, 'L' => 4, 'M' => 18, 'N' => 20, 'O' => 11, 'P' => 3, 'Q' => 6, 'R' => 8, 'S' => 12, 'T' => 14, 'U' => 16, 'V' => 10, 'W' => 22, 'X' => 25, 'Y' => 24, 'Z' => 23); | |
$listCtrlCode = array(0 => 'A', 1 => 'B', 2 => 'C', 3 => 'D', 4 => 'E', 5 => 'F', 6 => 'G', 7 => 'H', 8 => 'I', 9 => 'J', 10 => 'K', 11 => 'L', 12 => 'M', 13 => 'N', 14 => 'O', 15 => 'P', 16 => 'Q', 17 => 'R', 18 => 'S', 19 => 'T', 20 => 'U', 21 => 'V', 22 => 'W', 23 => 'X', 24 => 'Y', 25 => 'Z'); | |
$cFCharList = str_split(strtoupper($value)); | |
$pari = 0; | |
$dispari = $listOddChar[$cFCharList[14]]; | |
// loop first 14 char, step 2 | |
for ($i = 0; $i < 13; $i += 2) { | |
$dispari = $dispari + $listOddChar[$cFCharList[$i]]; | |
$pari = $pari + $listEvenChar[$cFCharList[$i + 1]]; | |
} | |
// verify first 15 char with checksum char (char 16) | |
if (!($listCtrlCode[($pari + $dispari) % 26] === $cFCharList[15])) { | |
$fail(':attribute is not correct'); | |
} | |
}; | |
} | |
]), | |
]), | |
Section::make(__('Other tax info')) | |
->compact() | |
->columns(3) | |
->schema([ | |
TextInput::make('pec') | |
->email() | |
->Label(__('PEC')), | |
TextInput::make('tax code') | |
->maxLength(7) | |
->Label(__('tax code')) | |
->helperText(__('Enter here your tax code')), | |
TextInput::make('email') | |
->required() | |
->email() | |
->Label('Send bill to this email'), | |
TextInput::make('email2') | |
->email() | |
->Label('Email for info') | |
->helperText(__('Email to use for info about membership')), | |
TextInput::make('phone') | |
->tel() | |
->Label(__('Phone')) | |
->helperText(__('Phone number for our staff')), | |
]), | |
Select::make('shipping_id') | |
->label('Shipping address') | |
->helperText('Select the shipping address.') | |
->relationship(name: 'billings', titleAttribute: 'addressee') | |
->createOptionForm( | |
AlMembershipResource::getIndirizzoFormFields() | |
) | |
->searchable() | |
->preload(), | |
TextArea::make('notes') | |
->columnSpanFull() | |
->helperText(__('Other info')), | |
]), | |
]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment