|
@@ -6,7 +6,7 @@ use App\Enums\{DocumentType, Font, PaymentTerms, Template};
|
6
|
6
|
use App\Models\Setting\DocumentDefault as InvoiceModel;
|
7
|
7
|
use Filament\Actions\{Action, ActionGroup};
|
8
|
8
|
use Filament\Forms\Components\{Checkbox, ColorPicker, Component, FileUpload, Group, Section, Select, TextInput, Textarea, ViewField};
|
9
|
|
-use Filament\Forms\{Form, Get};
|
|
9
|
+use Filament\Forms\{Form, Get, Set};
|
10
|
10
|
use Filament\Notifications\Notification;
|
11
|
11
|
use Filament\Pages\Concerns\InteractsWithFormActions;
|
12
|
12
|
use Filament\Pages\Page;
|
|
@@ -119,6 +119,7 @@ class Invoice extends Page
|
119
|
119
|
public function form(Form $form): Form
|
120
|
120
|
{
|
121
|
121
|
return $form
|
|
122
|
+ ->live()
|
122
|
123
|
->schema([
|
123
|
124
|
$this->getGeneralSection(),
|
124
|
125
|
$this->getContentSection(),
|
|
@@ -135,17 +136,15 @@ class Invoice extends Page
|
135
|
136
|
->schema([
|
136
|
137
|
TextInput::make('number_prefix')
|
137
|
138
|
->label('Number Prefix')
|
138
|
|
- ->live()
|
139
|
|
- ->required(),
|
|
139
|
+ ->nullable(),
|
140
|
140
|
Select::make('number_digits')
|
141
|
141
|
->label('Number Digits')
|
142
|
142
|
->options(InvoiceModel::availableNumberDigits())
|
|
143
|
+ ->selectablePlaceholder(false)
|
143
|
144
|
->native(false)
|
144
|
|
- ->live()
|
145
|
|
- ->required(),
|
|
145
|
+ ->rule('required'),
|
146
|
146
|
TextInput::make('number_next')
|
147
|
147
|
->label('Next Number')
|
148
|
|
- ->live()
|
149
|
148
|
->maxLength(static fn (Get $get) => $get('number_digits'))
|
150
|
149
|
->suffix(static function (Get $get, $state) {
|
151
|
150
|
$number_prefix = $get('number_prefix');
|
|
@@ -154,13 +153,13 @@ class Invoice extends Page
|
154
|
153
|
|
155
|
154
|
return InvoiceModel::getNumberNext(true, true, $number_prefix, $number_digits, $number_next);
|
156
|
155
|
})
|
157
|
|
- ->required(),
|
|
156
|
+ ->rule('required'),
|
158
|
157
|
Select::make('payment_terms')
|
159
|
158
|
->label('Payment Terms')
|
160
|
159
|
->options(PaymentTerms::class)
|
|
160
|
+ ->selectablePlaceholder(false)
|
161
|
161
|
->native(false)
|
162
|
|
- ->live()
|
163
|
|
- ->required(),
|
|
162
|
+ ->rule('required'),
|
164
|
163
|
])->columns();
|
165
|
164
|
}
|
166
|
165
|
|
|
@@ -170,19 +169,15 @@ class Invoice extends Page
|
170
|
169
|
->schema([
|
171
|
170
|
TextInput::make('header')
|
172
|
171
|
->label('Header')
|
173
|
|
- ->live()
|
174
|
|
- ->required(),
|
|
172
|
+ ->nullable(),
|
175
|
173
|
TextInput::make('subheader')
|
176
|
174
|
->label('Subheader')
|
177
|
|
- ->live()
|
178
|
175
|
->nullable(),
|
179
|
176
|
Textarea::make('terms')
|
180
|
177
|
->label('Terms')
|
181
|
|
- ->live()
|
182
|
178
|
->nullable(),
|
183
|
179
|
Textarea::make('footer')
|
184
|
180
|
->label('Footer / Notes')
|
185
|
|
- ->live()
|
186
|
181
|
->nullable(),
|
187
|
182
|
])->columns();
|
188
|
183
|
}
|
|
@@ -193,7 +188,6 @@ class Invoice extends Page
|
193
|
188
|
->description('Choose the template and edit the column names.')
|
194
|
189
|
->schema([
|
195
|
190
|
Group::make()
|
196
|
|
- ->live()
|
197
|
191
|
->schema([
|
198
|
192
|
FileUpload::make('logo')
|
199
|
193
|
->label('Logo')
|
|
@@ -231,12 +225,24 @@ class Invoice extends Page
|
231
|
225
|
->label('Template')
|
232
|
226
|
->native(false)
|
233
|
227
|
->options(Template::class)
|
234
|
|
- ->required(),
|
|
228
|
+ ->selectablePlaceholder(false)
|
|
229
|
+ ->rule('required'),
|
235
|
230
|
Select::make('item_name.option')
|
236
|
231
|
->label('Item Name')
|
237
|
232
|
->native(false)
|
238
|
|
- ->required()
|
239
|
|
- ->options(InvoiceModel::getAvailableItemNameOptions()),
|
|
233
|
+ ->options(InvoiceModel::getAvailableItemNameOptions())
|
|
234
|
+ ->selectablePlaceholder(false)
|
|
235
|
+ ->afterStateUpdated(static function (Get $get, Set $set, $state, $old) {
|
|
236
|
+ if ($state !== 'other' && $old === 'other' && filled($get('item_name.custom'))) {
|
|
237
|
+ $set('item_name.old_custom', $get('item_name.custom'));
|
|
238
|
+ $set('item_name.custom', null);
|
|
239
|
+ }
|
|
240
|
+
|
|
241
|
+ if ($state === 'other' && $old !== 'other') {
|
|
242
|
+ $set('item_name.custom', $get('item_name.old_custom'));
|
|
243
|
+ }
|
|
244
|
+ })
|
|
245
|
+ ->rule('required'),
|
240
|
246
|
TextInput::make('item_name.custom')
|
241
|
247
|
->hiddenLabel()
|
242
|
248
|
->disabled(static fn (callable $get) => $get('item_name.option') !== 'other')
|
|
@@ -244,8 +250,19 @@ class Invoice extends Page
|
244
|
250
|
Select::make('unit_name.option')
|
245
|
251
|
->label('Unit Name')
|
246
|
252
|
->native(false)
|
247
|
|
- ->required()
|
248
|
|
- ->options(InvoiceModel::getAvailableUnitNameOptions()),
|
|
253
|
+ ->options(InvoiceModel::getAvailableUnitNameOptions())
|
|
254
|
+ ->selectablePlaceholder(false)
|
|
255
|
+ ->afterStateUpdated(static function (Get $get, Set $set, $state, $old) {
|
|
256
|
+ if ($state !== 'other' && $old === 'other' && filled($get('unit_name.custom'))) {
|
|
257
|
+ $set('unit_name.old_custom', $get('unit_name.custom'));
|
|
258
|
+ $set('unit_name.custom', null);
|
|
259
|
+ }
|
|
260
|
+
|
|
261
|
+ if ($state === 'other' && $old !== 'other') {
|
|
262
|
+ $set('unit_name.custom', $get('unit_name.old_custom'));
|
|
263
|
+ }
|
|
264
|
+ })
|
|
265
|
+ ->rule('required'),
|
249
|
266
|
TextInput::make('unit_name.custom')
|
250
|
267
|
->hiddenLabel()
|
251
|
268
|
->disabled(static fn (callable $get) => $get('unit_name.option') !== 'other')
|
|
@@ -253,8 +270,19 @@ class Invoice extends Page
|
253
|
270
|
Select::make('price_name.option')
|
254
|
271
|
->label('Price Name')
|
255
|
272
|
->native(false)
|
256
|
|
- ->required()
|
257
|
|
- ->options(InvoiceModel::getAvailablePriceNameOptions()),
|
|
273
|
+ ->options(InvoiceModel::getAvailablePriceNameOptions())
|
|
274
|
+ ->afterStateUpdated(static function (Get $get, Set $set, $state, $old) {
|
|
275
|
+ if ($state !== 'other' && $old === 'other' && filled($get('price_name.custom'))) {
|
|
276
|
+ $set('price_name.old_custom', $get('price_name.custom'));
|
|
277
|
+ $set('price_name.custom', null);
|
|
278
|
+ }
|
|
279
|
+
|
|
280
|
+ if ($state === 'other' && $old !== 'other') {
|
|
281
|
+ $set('price_name.custom', $get('price_name.old_custom'));
|
|
282
|
+ }
|
|
283
|
+ })
|
|
284
|
+ ->selectablePlaceholder(false)
|
|
285
|
+ ->rule('required'),
|
258
|
286
|
TextInput::make('price_name.custom')
|
259
|
287
|
->hiddenLabel()
|
260
|
288
|
->disabled(static fn (callable $get) => $get('price_name.option') !== 'other')
|
|
@@ -262,8 +290,19 @@ class Invoice extends Page
|
262
|
290
|
Select::make('amount_name.option')
|
263
|
291
|
->label('Amount Name')
|
264
|
292
|
->native(false)
|
265
|
|
- ->required()
|
266
|
|
- ->options(InvoiceModel::getAvailableAmountNameOptions()),
|
|
293
|
+ ->options(InvoiceModel::getAvailableAmountNameOptions())
|
|
294
|
+ ->selectablePlaceholder(false)
|
|
295
|
+ ->afterStateUpdated(static function (Get $get, Set $set, $state, $old) {
|
|
296
|
+ if ($state !== 'other' && $old === 'other' && filled($get('amount_name.custom'))) {
|
|
297
|
+ $set('amount_name.old_custom', $get('amount_name.custom'));
|
|
298
|
+ $set('amount_name.custom', null);
|
|
299
|
+ }
|
|
300
|
+
|
|
301
|
+ if ($state === 'other' && $old !== 'other') {
|
|
302
|
+ $set('amount_name.custom', $get('amount_name.old_custom'));
|
|
303
|
+ }
|
|
304
|
+ })
|
|
305
|
+ ->rule('required'),
|
267
|
306
|
TextInput::make('amount_name.custom')
|
268
|
307
|
->hiddenLabel()
|
269
|
308
|
->disabled(static fn (callable $get) => $get('amount_name.option') !== 'other')
|