ソースを参照

add reorderable and clonable line items

3.x
Andrew Wallo 5ヶ月前
コミット
938fd6b82e

+ 93
- 78
app/Filament/Company/Resources/Purchases/BillResource.php ファイルの表示

166
                                 Forms\Components\Select::make('discount_method')
166
                                 Forms\Components\Select::make('discount_method')
167
                                     ->label('Discount method')
167
                                     ->label('Discount method')
168
                                     ->options(DocumentDiscountMethod::class)
168
                                     ->options(DocumentDiscountMethod::class)
169
-                                    ->selectablePlaceholder(false)
169
+                                    ->softRequired()
170
                                     ->default($settings->discount_method)
170
                                     ->default($settings->discount_method)
171
                                     ->afterStateUpdated(function ($state, Forms\Set $set) {
171
                                     ->afterStateUpdated(function ($state, Forms\Set $set) {
172
                                         $discountMethod = DocumentDiscountMethod::parse($state);
172
                                         $discountMethod = DocumentDiscountMethod::parse($state);
184
                             ->saveRelationshipsUsing(null)
184
                             ->saveRelationshipsUsing(null)
185
                             ->dehydrated(true)
185
                             ->dehydrated(true)
186
                             ->reorderable()
186
                             ->reorderable()
187
+                            ->orderColumn('line_number')
187
                             ->reorderAtStart()
188
                             ->reorderAtStart()
188
                             ->cloneable()
189
                             ->cloneable()
190
+                            ->addActionLabel('Add an item')
189
                             ->headers(function (Forms\Get $get) use ($settings) {
191
                             ->headers(function (Forms\Get $get) use ($settings) {
190
                                 $hasDiscounts = DocumentDiscountMethod::parse($get('discount_method'))->isPerLineItem();
192
                                 $hasDiscounts = DocumentDiscountMethod::parse($get('discount_method'))->isPerLineItem();
191
 
193
 
192
                                 $headers = [
194
                                 $headers = [
193
                                     Header::make($settings->resolveColumnLabel('item_name', 'Items'))
195
                                     Header::make($settings->resolveColumnLabel('item_name', 'Items'))
194
-                                        ->width($hasDiscounts ? '15%' : '20%'),
195
-                                    Header::make('Description')
196
-                                        ->width($hasDiscounts ? '15%' : '20%'),
196
+                                        ->width('30%'),
197
                                     Header::make($settings->resolveColumnLabel('unit_name', 'Quantity'))
197
                                     Header::make($settings->resolveColumnLabel('unit_name', 'Quantity'))
198
                                         ->width('10%'),
198
                                         ->width('10%'),
199
                                     Header::make($settings->resolveColumnLabel('price_name', 'Price'))
199
                                     Header::make($settings->resolveColumnLabel('price_name', 'Price'))
200
                                         ->width('10%'),
200
                                         ->width('10%'),
201
-                                    Header::make('Taxes')
202
-                                        ->width($hasDiscounts ? '20%' : '30%'),
203
                                 ];
201
                                 ];
204
 
202
 
205
                                 if ($hasDiscounts) {
203
                                 if ($hasDiscounts) {
206
-                                    $headers[] = Header::make('Discounts')->width('20%');
204
+                                    $headers[] = Header::make('Adjustments')->width('30%');
205
+                                } else {
206
+                                    $headers[] = Header::make('Taxes')->width('30%');
207
                                 }
207
                                 }
208
 
208
 
209
                                 $headers[] = Header::make($settings->resolveColumnLabel('amount_name', 'Amount'))
209
                                 $headers[] = Header::make($settings->resolveColumnLabel('amount_name', 'Amount'))
213
                                 return $headers;
213
                                 return $headers;
214
                             })
214
                             })
215
                             ->schema([
215
                             ->schema([
216
-                                CreateOfferingSelect::make('offering_id')
217
-                                    ->label('Item')
218
-                                    ->required()
219
-                                    ->live()
220
-                                    ->purchasable()
221
-                                    ->afterStateUpdated(function (Forms\Set $set, Forms\Get $get, $state, ?DocumentLineItem $record) {
222
-                                        $offeringId = $state;
223
-                                        $discountMethod = DocumentDiscountMethod::parse($get('../../discount_method'));
224
-                                        $isPerLineItem = $discountMethod->isPerLineItem();
216
+                                Forms\Components\Group::make([
217
+                                    CreateOfferingSelect::make('offering_id')
218
+                                        ->label('Item')
219
+                                        ->hiddenLabel()
220
+                                        ->placeholder('Select item')
221
+                                        ->required()
222
+                                        ->live()
223
+                                        ->inlineSuffix()
224
+                                        ->purchasable()
225
+                                        ->afterStateUpdated(function (Forms\Set $set, Forms\Get $get, $state, ?DocumentLineItem $record) {
226
+                                            $offeringId = $state;
227
+                                            $discountMethod = DocumentDiscountMethod::parse($get('../../discount_method'));
228
+                                            $isPerLineItem = $discountMethod->isPerLineItem();
229
+
230
+                                            $existingTaxIds = [];
231
+                                            $existingDiscountIds = [];
232
+
233
+                                            if ($record) {
234
+                                                $existingTaxIds = $record->purchaseTaxes()->pluck('adjustments.id')->toArray();
235
+                                                if ($isPerLineItem) {
236
+                                                    $existingDiscountIds = $record->purchaseDiscounts()->pluck('adjustments.id')->toArray();
237
+                                                }
238
+                                            }
225
 
239
 
226
-                                        $existingTaxIds = [];
227
-                                        $existingDiscountIds = [];
240
+                                            $with = [
241
+                                                'purchaseTaxes' => static function ($query) use ($existingTaxIds) {
242
+                                                    $query->where(static function ($query) use ($existingTaxIds) {
243
+                                                        $query->where('status', AdjustmentStatus::Active)
244
+                                                            ->orWhereIn('adjustments.id', $existingTaxIds);
245
+                                                    });
246
+                                                },
247
+                                            ];
228
 
248
 
229
-                                        if ($record) {
230
-                                            $existingTaxIds = $record->purchaseTaxes()->pluck('adjustments.id')->toArray();
231
                                             if ($isPerLineItem) {
249
                                             if ($isPerLineItem) {
232
-                                                $existingDiscountIds = $record->purchaseDiscounts()->pluck('adjustments.id')->toArray();
250
+                                                $with['purchaseDiscounts'] = static function ($query) use ($existingDiscountIds) {
251
+                                                    $query->where(static function ($query) use ($existingDiscountIds) {
252
+                                                        $query->where('status', AdjustmentStatus::Active)
253
+                                                            ->orWhereIn('adjustments.id', $existingDiscountIds);
254
+                                                    });
255
+                                                };
233
                                             }
256
                                             }
234
-                                        }
235
 
257
 
236
-                                        $with = [
237
-                                            'purchaseTaxes' => static function ($query) use ($existingTaxIds) {
238
-                                                $query->where(static function ($query) use ($existingTaxIds) {
239
-                                                    $query->where('status', AdjustmentStatus::Active)
240
-                                                        ->orWhereIn('adjustments.id', $existingTaxIds);
241
-                                                });
242
-                                            },
243
-                                        ];
244
-
245
-                                        if ($isPerLineItem) {
246
-                                            $with['purchaseDiscounts'] = static function ($query) use ($existingDiscountIds) {
247
-                                                $query->where(static function ($query) use ($existingDiscountIds) {
248
-                                                    $query->where('status', AdjustmentStatus::Active)
249
-                                                        ->orWhereIn('adjustments.id', $existingDiscountIds);
250
-                                                });
251
-                                            };
252
-                                        }
258
+                                            $offeringRecord = Offering::with($with)->find($offeringId);
253
 
259
 
254
-                                        $offeringRecord = Offering::with($with)->find($offeringId);
255
-
256
-                                        if (! $offeringRecord) {
257
-                                            return;
258
-                                        }
260
+                                            if (! $offeringRecord) {
261
+                                                return;
262
+                                            }
259
 
263
 
260
-                                        $unitPrice = CurrencyConverter::convertToFloat($offeringRecord->price, $get('../../currency_code') ?? CurrencyAccessor::getDefaultCurrency());
264
+                                            $unitPrice = CurrencyConverter::convertToFloat($offeringRecord->price, $get('../../currency_code') ?? CurrencyAccessor::getDefaultCurrency());
261
 
265
 
262
-                                        $set('description', $offeringRecord->description);
263
-                                        $set('unit_price', $unitPrice);
264
-                                        $set('purchaseTaxes', $offeringRecord->purchaseTaxes->pluck('id')->toArray());
266
+                                            $set('description', $offeringRecord->description);
267
+                                            $set('unit_price', $unitPrice);
268
+                                            $set('purchaseTaxes', $offeringRecord->purchaseTaxes->pluck('id')->toArray());
265
 
269
 
266
-                                        if ($isPerLineItem) {
267
-                                            $set('purchaseDiscounts', $offeringRecord->purchaseDiscounts->pluck('id')->toArray());
268
-                                        }
269
-                                    }),
270
-                                Forms\Components\TextInput::make('description'),
270
+                                            if ($isPerLineItem) {
271
+                                                $set('purchaseDiscounts', $offeringRecord->purchaseDiscounts->pluck('id')->toArray());
272
+                                            }
273
+                                        }),
274
+                                    Forms\Components\TextInput::make('description')
275
+                                        ->placeholder('Enter item description')
276
+                                        ->hiddenLabel(),
277
+                                ])->columnSpan(1),
271
                                 Forms\Components\TextInput::make('quantity')
278
                                 Forms\Components\TextInput::make('quantity')
272
                                     ->required()
279
                                     ->required()
273
                                     ->numeric()
280
                                     ->numeric()
281
                                     ->live()
288
                                     ->live()
282
                                     ->maxValue(9999999999.99)
289
                                     ->maxValue(9999999999.99)
283
                                     ->default(0),
290
                                     ->default(0),
284
-                                CreateAdjustmentSelect::make('purchaseTaxes')
285
-                                    ->label('Taxes')
286
-                                    ->category(AdjustmentCategory::Tax)
287
-                                    ->type(AdjustmentType::Purchase)
288
-                                    ->adjustmentsRelationship('purchaseTaxes')
289
-                                    ->saveRelationshipsUsing(null)
290
-                                    ->dehydrated(true)
291
-                                    ->preload()
292
-                                    ->multiple()
293
-                                    ->live()
294
-                                    ->searchable(),
295
-                                CreateAdjustmentSelect::make('purchaseDiscounts')
296
-                                    ->label('Discounts')
297
-                                    ->category(AdjustmentCategory::Discount)
298
-                                    ->type(AdjustmentType::Purchase)
299
-                                    ->adjustmentsRelationship('purchaseDiscounts')
300
-                                    ->saveRelationshipsUsing(null)
301
-                                    ->dehydrated(true)
302
-                                    ->multiple()
303
-                                    ->live()
304
-                                    ->hidden(function (Forms\Get $get) {
305
-                                        $discountMethod = DocumentDiscountMethod::parse($get('../../discount_method'));
291
+                                Forms\Components\Group::make([
292
+                                    CreateAdjustmentSelect::make('purchaseTaxes')
293
+                                        ->label('Taxes')
294
+                                        ->hiddenLabel()
295
+                                        ->placeholder('Select taxes')
296
+                                        ->category(AdjustmentCategory::Tax)
297
+                                        ->type(AdjustmentType::Purchase)
298
+                                        ->adjustmentsRelationship('purchaseTaxes')
299
+                                        ->saveRelationshipsUsing(null)
300
+                                        ->dehydrated(true)
301
+                                        ->inlineSuffix()
302
+                                        ->preload()
303
+                                        ->multiple()
304
+                                        ->live()
305
+                                        ->searchable(),
306
+                                    CreateAdjustmentSelect::make('purchaseDiscounts')
307
+                                        ->label('Discounts')
308
+                                        ->hiddenLabel()
309
+                                        ->placeholder('Select discounts')
310
+                                        ->category(AdjustmentCategory::Discount)
311
+                                        ->type(AdjustmentType::Purchase)
312
+                                        ->adjustmentsRelationship('purchaseDiscounts')
313
+                                        ->saveRelationshipsUsing(null)
314
+                                        ->dehydrated(true)
315
+                                        ->inlineSuffix()
316
+                                        ->multiple()
317
+                                        ->live()
318
+                                        ->hidden(function (Forms\Get $get) {
319
+                                            $discountMethod = DocumentDiscountMethod::parse($get('../../discount_method'));
306
 
320
 
307
-                                        return $discountMethod->isPerDocument();
308
-                                    })
309
-                                    ->searchable(),
321
+                                            return $discountMethod->isPerDocument();
322
+                                        })
323
+                                        ->searchable(),
324
+                                ])->columnSpan(1),
310
                                 Forms\Components\Placeholder::make('total')
325
                                 Forms\Components\Placeholder::make('total')
311
                                     ->hiddenLabel()
326
                                     ->hiddenLabel()
312
                                     ->extraAttributes(['class' => 'text-left sm:text-right'])
327
                                     ->extraAttributes(['class' => 'text-left sm:text-right'])

+ 93
- 78
app/Filament/Company/Resources/Sales/EstimateResource.php ファイルの表示

164
                                 Forms\Components\Select::make('discount_method')
164
                                 Forms\Components\Select::make('discount_method')
165
                                     ->label('Discount method')
165
                                     ->label('Discount method')
166
                                     ->options(DocumentDiscountMethod::class)
166
                                     ->options(DocumentDiscountMethod::class)
167
-                                    ->selectablePlaceholder(false)
167
+                                    ->softRequired()
168
                                     ->default($settings->discount_method)
168
                                     ->default($settings->discount_method)
169
                                     ->afterStateUpdated(function ($state, Forms\Set $set) {
169
                                     ->afterStateUpdated(function ($state, Forms\Set $set) {
170
                                         $discountMethod = DocumentDiscountMethod::parse($state);
170
                                         $discountMethod = DocumentDiscountMethod::parse($state);
182
                             ->saveRelationshipsUsing(null)
182
                             ->saveRelationshipsUsing(null)
183
                             ->dehydrated(true)
183
                             ->dehydrated(true)
184
                             ->reorderable()
184
                             ->reorderable()
185
+                            ->orderColumn('line_number')
185
                             ->reorderAtStart()
186
                             ->reorderAtStart()
186
                             ->cloneable()
187
                             ->cloneable()
188
+                            ->addActionLabel('Add an item')
187
                             ->headers(function (Forms\Get $get) use ($settings) {
189
                             ->headers(function (Forms\Get $get) use ($settings) {
188
                                 $hasDiscounts = DocumentDiscountMethod::parse($get('discount_method'))->isPerLineItem();
190
                                 $hasDiscounts = DocumentDiscountMethod::parse($get('discount_method'))->isPerLineItem();
189
 
191
 
190
                                 $headers = [
192
                                 $headers = [
191
                                     Header::make($settings->resolveColumnLabel('item_name', 'Items'))
193
                                     Header::make($settings->resolveColumnLabel('item_name', 'Items'))
192
-                                        ->width($hasDiscounts ? '15%' : '20%'),
193
-                                    Header::make('Description')
194
-                                        ->width($hasDiscounts ? '15%' : '20%'),
194
+                                        ->width('30%'),
195
                                     Header::make($settings->resolveColumnLabel('unit_name', 'Quantity'))
195
                                     Header::make($settings->resolveColumnLabel('unit_name', 'Quantity'))
196
                                         ->width('10%'),
196
                                         ->width('10%'),
197
                                     Header::make($settings->resolveColumnLabel('price_name', 'Price'))
197
                                     Header::make($settings->resolveColumnLabel('price_name', 'Price'))
198
                                         ->width('10%'),
198
                                         ->width('10%'),
199
-                                    Header::make('Taxes')
200
-                                        ->width($hasDiscounts ? '20%' : '30%'),
201
                                 ];
199
                                 ];
202
 
200
 
203
                                 if ($hasDiscounts) {
201
                                 if ($hasDiscounts) {
204
-                                    $headers[] = Header::make('Discounts')->width('20%');
202
+                                    $headers[] = Header::make('Adjustments')->width('30%');
203
+                                } else {
204
+                                    $headers[] = Header::make('Taxes')->width('30%');
205
                                 }
205
                                 }
206
 
206
 
207
                                 $headers[] = Header::make($settings->resolveColumnLabel('amount_name', 'Amount'))
207
                                 $headers[] = Header::make($settings->resolveColumnLabel('amount_name', 'Amount'))
211
                                 return $headers;
211
                                 return $headers;
212
                             })
212
                             })
213
                             ->schema([
213
                             ->schema([
214
-                                CreateOfferingSelect::make('offering_id')
215
-                                    ->label('Item')
216
-                                    ->required()
217
-                                    ->live()
218
-                                    ->sellable()
219
-                                    ->afterStateUpdated(function (Forms\Set $set, Forms\Get $get, $state, ?DocumentLineItem $record) {
220
-                                        $offeringId = $state;
221
-                                        $discountMethod = DocumentDiscountMethod::parse($get('../../discount_method'));
222
-                                        $isPerLineItem = $discountMethod->isPerLineItem();
214
+                                Forms\Components\Group::make([
215
+                                    CreateOfferingSelect::make('offering_id')
216
+                                        ->label('Item')
217
+                                        ->hiddenLabel()
218
+                                        ->placeholder('Select item')
219
+                                        ->required()
220
+                                        ->live()
221
+                                        ->inlineSuffix()
222
+                                        ->sellable()
223
+                                        ->afterStateUpdated(function (Forms\Set $set, Forms\Get $get, $state, ?DocumentLineItem $record) {
224
+                                            $offeringId = $state;
225
+                                            $discountMethod = DocumentDiscountMethod::parse($get('../../discount_method'));
226
+                                            $isPerLineItem = $discountMethod->isPerLineItem();
227
+
228
+                                            $existingTaxIds = [];
229
+                                            $existingDiscountIds = [];
230
+
231
+                                            if ($record) {
232
+                                                $existingTaxIds = $record->salesTaxes()->pluck('adjustments.id')->toArray();
233
+                                                if ($isPerLineItem) {
234
+                                                    $existingDiscountIds = $record->salesDiscounts()->pluck('adjustments.id')->toArray();
235
+                                                }
236
+                                            }
223
 
237
 
224
-                                        $existingTaxIds = [];
225
-                                        $existingDiscountIds = [];
238
+                                            $with = [
239
+                                                'salesTaxes' => static function ($query) use ($existingTaxIds) {
240
+                                                    $query->where(static function ($query) use ($existingTaxIds) {
241
+                                                        $query->where('status', AdjustmentStatus::Active)
242
+                                                            ->orWhereIn('adjustments.id', $existingTaxIds);
243
+                                                    });
244
+                                                },
245
+                                            ];
226
 
246
 
227
-                                        if ($record) {
228
-                                            $existingTaxIds = $record->salesTaxes()->pluck('adjustments.id')->toArray();
229
                                             if ($isPerLineItem) {
247
                                             if ($isPerLineItem) {
230
-                                                $existingDiscountIds = $record->salesDiscounts()->pluck('adjustments.id')->toArray();
248
+                                                $with['salesDiscounts'] = static function ($query) use ($existingDiscountIds) {
249
+                                                    $query->where(static function ($query) use ($existingDiscountIds) {
250
+                                                        $query->where('status', AdjustmentStatus::Active)
251
+                                                            ->orWhereIn('adjustments.id', $existingDiscountIds);
252
+                                                    });
253
+                                                };
231
                                             }
254
                                             }
232
-                                        }
233
 
255
 
234
-                                        $with = [
235
-                                            'salesTaxes' => static function ($query) use ($existingTaxIds) {
236
-                                                $query->where(static function ($query) use ($existingTaxIds) {
237
-                                                    $query->where('status', AdjustmentStatus::Active)
238
-                                                        ->orWhereIn('adjustments.id', $existingTaxIds);
239
-                                                });
240
-                                            },
241
-                                        ];
242
-
243
-                                        if ($isPerLineItem) {
244
-                                            $with['salesDiscounts'] = static function ($query) use ($existingDiscountIds) {
245
-                                                $query->where(static function ($query) use ($existingDiscountIds) {
246
-                                                    $query->where('status', AdjustmentStatus::Active)
247
-                                                        ->orWhereIn('adjustments.id', $existingDiscountIds);
248
-                                                });
249
-                                            };
250
-                                        }
251
-
252
-                                        $offeringRecord = Offering::with($with)->find($offeringId);
256
+                                            $offeringRecord = Offering::with($with)->find($offeringId);
253
 
257
 
254
-                                        if (! $offeringRecord) {
255
-                                            return;
256
-                                        }
258
+                                            if (! $offeringRecord) {
259
+                                                return;
260
+                                            }
257
 
261
 
258
-                                        $unitPrice = CurrencyConverter::convertToFloat($offeringRecord->price, $get('../../currency_code') ?? CurrencyAccessor::getDefaultCurrency());
262
+                                            $unitPrice = CurrencyConverter::convertToFloat($offeringRecord->price, $get('../../currency_code') ?? CurrencyAccessor::getDefaultCurrency());
259
 
263
 
260
-                                        $set('description', $offeringRecord->description);
261
-                                        $set('unit_price', $unitPrice);
262
-                                        $set('salesTaxes', $offeringRecord->salesTaxes->pluck('id')->toArray());
264
+                                            $set('description', $offeringRecord->description);
265
+                                            $set('unit_price', $unitPrice);
266
+                                            $set('salesTaxes', $offeringRecord->salesTaxes->pluck('id')->toArray());
263
 
267
 
264
-                                        if ($isPerLineItem) {
265
-                                            $set('salesDiscounts', $offeringRecord->salesDiscounts->pluck('id')->toArray());
266
-                                        }
267
-                                    }),
268
-                                Forms\Components\TextInput::make('description'),
268
+                                            if ($isPerLineItem) {
269
+                                                $set('salesDiscounts', $offeringRecord->salesDiscounts->pluck('id')->toArray());
270
+                                            }
271
+                                        }),
272
+                                    Forms\Components\TextInput::make('description')
273
+                                        ->placeholder('Enter item description')
274
+                                        ->hiddenLabel(),
275
+                                ])->columnSpan(1),
269
                                 Forms\Components\TextInput::make('quantity')
276
                                 Forms\Components\TextInput::make('quantity')
270
                                     ->required()
277
                                     ->required()
271
                                     ->numeric()
278
                                     ->numeric()
278
                                     ->live()
285
                                     ->live()
279
                                     ->maxValue(9999999999.99)
286
                                     ->maxValue(9999999999.99)
280
                                     ->default(0),
287
                                     ->default(0),
281
-                                CreateAdjustmentSelect::make('salesTaxes')
282
-                                    ->label('Taxes')
283
-                                    ->category(AdjustmentCategory::Tax)
284
-                                    ->type(AdjustmentType::Sales)
285
-                                    ->adjustmentsRelationship('salesTaxes')
286
-                                    ->saveRelationshipsUsing(null)
287
-                                    ->dehydrated(true)
288
-                                    ->preload()
289
-                                    ->multiple()
290
-                                    ->live()
291
-                                    ->searchable(),
292
-                                CreateAdjustmentSelect::make('salesDiscounts')
293
-                                    ->label('Discounts')
294
-                                    ->category(AdjustmentCategory::Discount)
295
-                                    ->type(AdjustmentType::Sales)
296
-                                    ->adjustmentsRelationship('salesDiscounts')
297
-                                    ->saveRelationshipsUsing(null)
298
-                                    ->dehydrated(true)
299
-                                    ->multiple()
300
-                                    ->live()
301
-                                    ->hidden(function (Forms\Get $get) {
302
-                                        $discountMethod = DocumentDiscountMethod::parse($get('../../discount_method'));
288
+                                Forms\Components\Group::make([
289
+                                    CreateAdjustmentSelect::make('salesTaxes')
290
+                                        ->label('Taxes')
291
+                                        ->hiddenLabel()
292
+                                        ->placeholder('Select taxes')
293
+                                        ->category(AdjustmentCategory::Tax)
294
+                                        ->type(AdjustmentType::Sales)
295
+                                        ->adjustmentsRelationship('salesTaxes')
296
+                                        ->saveRelationshipsUsing(null)
297
+                                        ->dehydrated(true)
298
+                                        ->inlineSuffix()
299
+                                        ->preload()
300
+                                        ->multiple()
301
+                                        ->live()
302
+                                        ->searchable(),
303
+                                    CreateAdjustmentSelect::make('salesDiscounts')
304
+                                        ->label('Discounts')
305
+                                        ->hiddenLabel()
306
+                                        ->placeholder('Select discounts')
307
+                                        ->category(AdjustmentCategory::Discount)
308
+                                        ->type(AdjustmentType::Sales)
309
+                                        ->adjustmentsRelationship('salesDiscounts')
310
+                                        ->saveRelationshipsUsing(null)
311
+                                        ->dehydrated(true)
312
+                                        ->inlineSuffix()
313
+                                        ->multiple()
314
+                                        ->live()
315
+                                        ->hidden(function (Forms\Get $get) {
316
+                                            $discountMethod = DocumentDiscountMethod::parse($get('../../discount_method'));
303
 
317
 
304
-                                        return $discountMethod->isPerDocument();
305
-                                    })
306
-                                    ->searchable(),
318
+                                            return $discountMethod->isPerDocument();
319
+                                        })
320
+                                        ->searchable(),
321
+                                ])->columnSpan(1),
307
                                 Forms\Components\Placeholder::make('total')
322
                                 Forms\Components\Placeholder::make('total')
308
                                     ->hiddenLabel()
323
                                     ->hiddenLabel()
309
                                     ->extraAttributes(['class' => 'text-left sm:text-right'])
324
                                     ->extraAttributes(['class' => 'text-left sm:text-right'])

+ 94
- 79
app/Filament/Company/Resources/Sales/RecurringInvoiceResource.php ファイルの表示

90
                                 Forms\Components\Select::make('discount_method')
90
                                 Forms\Components\Select::make('discount_method')
91
                                     ->label('Discount method')
91
                                     ->label('Discount method')
92
                                     ->options(DocumentDiscountMethod::class)
92
                                     ->options(DocumentDiscountMethod::class)
93
-                                    ->selectablePlaceholder(false)
93
+                                    ->softRequired()
94
                                     ->default($settings->discount_method)
94
                                     ->default($settings->discount_method)
95
                                     ->afterStateUpdated(function ($state, Forms\Set $set) {
95
                                     ->afterStateUpdated(function ($state, Forms\Set $set) {
96
                                         $discountMethod = DocumentDiscountMethod::parse($state);
96
                                         $discountMethod = DocumentDiscountMethod::parse($state);
108
                             ->saveRelationshipsUsing(null)
108
                             ->saveRelationshipsUsing(null)
109
                             ->dehydrated(true)
109
                             ->dehydrated(true)
110
                             ->reorderable()
110
                             ->reorderable()
111
+                            ->orderColumn('line_number')
111
                             ->reorderAtStart()
112
                             ->reorderAtStart()
112
                             ->cloneable()
113
                             ->cloneable()
114
+                            ->addActionLabel('Add an item')
113
                             ->headers(function (Forms\Get $get) use ($settings) {
115
                             ->headers(function (Forms\Get $get) use ($settings) {
114
                                 $hasDiscounts = DocumentDiscountMethod::parse($get('discount_method'))->isPerLineItem();
116
                                 $hasDiscounts = DocumentDiscountMethod::parse($get('discount_method'))->isPerLineItem();
115
 
117
 
116
                                 $headers = [
118
                                 $headers = [
117
                                     Header::make($settings->resolveColumnLabel('item_name', 'Items'))
119
                                     Header::make($settings->resolveColumnLabel('item_name', 'Items'))
118
-                                        ->width($hasDiscounts ? '15%' : '20%'),
119
-                                    Header::make('Description')
120
-                                        ->width($hasDiscounts ? '15%' : '20%'),
120
+                                        ->width('30%'),
121
                                     Header::make($settings->resolveColumnLabel('unit_name', 'Quantity'))
121
                                     Header::make($settings->resolveColumnLabel('unit_name', 'Quantity'))
122
                                         ->width('10%'),
122
                                         ->width('10%'),
123
                                     Header::make($settings->resolveColumnLabel('price_name', 'Price'))
123
                                     Header::make($settings->resolveColumnLabel('price_name', 'Price'))
124
                                         ->width('10%'),
124
                                         ->width('10%'),
125
-                                    Header::make('Taxes')
126
-                                        ->width($hasDiscounts ? '20%' : '30%'),
127
                                 ];
125
                                 ];
128
 
126
 
129
                                 if ($hasDiscounts) {
127
                                 if ($hasDiscounts) {
130
-                                    $headers[] = Header::make('Discounts')->width('20%');
128
+                                    $headers[] = Header::make('Adjustments')->width('30%');
129
+                                } else {
130
+                                    $headers[] = Header::make('Taxes')->width('30%');
131
                                 }
131
                                 }
132
 
132
 
133
                                 $headers[] = Header::make($settings->resolveColumnLabel('amount_name', 'Amount'))
133
                                 $headers[] = Header::make($settings->resolveColumnLabel('amount_name', 'Amount'))
137
                                 return $headers;
137
                                 return $headers;
138
                             })
138
                             })
139
                             ->schema([
139
                             ->schema([
140
-                                CreateOfferingSelect::make('offering_id')
141
-                                    ->label('Item')
142
-                                    ->required()
143
-                                    ->live()
144
-                                    ->sellable()
145
-                                    ->afterStateUpdated(function (Forms\Set $set, Forms\Get $get, $state, ?DocumentLineItem $record) {
146
-                                        $offeringId = $state;
147
-                                        $discountMethod = DocumentDiscountMethod::parse($get('../../discount_method'));
148
-                                        $isPerLineItem = $discountMethod->isPerLineItem();
140
+                                Forms\Components\Group::make([
141
+                                    CreateOfferingSelect::make('offering_id')
142
+                                        ->label('Item')
143
+                                        ->hiddenLabel()
144
+                                        ->placeholder('Select item')
145
+                                        ->required()
146
+                                        ->live()
147
+                                        ->inlineSuffix()
148
+                                        ->sellable()
149
+                                        ->afterStateUpdated(function (Forms\Set $set, Forms\Get $get, $state, ?DocumentLineItem $record) {
150
+                                            $offeringId = $state;
151
+                                            $discountMethod = DocumentDiscountMethod::parse($get('../../discount_method'));
152
+                                            $isPerLineItem = $discountMethod->isPerLineItem();
153
+
154
+                                            $existingTaxIds = [];
155
+                                            $existingDiscountIds = [];
156
+
157
+                                            if ($record) {
158
+                                                $existingTaxIds = $record->salesTaxes()->pluck('adjustments.id')->toArray();
159
+                                                if ($isPerLineItem) {
160
+                                                    $existingDiscountIds = $record->salesDiscounts()->pluck('adjustments.id')->toArray();
161
+                                                }
162
+                                            }
149
 
163
 
150
-                                        $existingTaxIds = [];
151
-                                        $existingDiscountIds = [];
164
+                                            $with = [
165
+                                                'salesTaxes' => static function ($query) use ($existingTaxIds) {
166
+                                                    $query->where(static function ($query) use ($existingTaxIds) {
167
+                                                        $query->where('status', AdjustmentStatus::Active)
168
+                                                            ->orWhereIn('adjustments.id', $existingTaxIds);
169
+                                                    });
170
+                                                },
171
+                                            ];
152
 
172
 
153
-                                        if ($record) {
154
-                                            $existingTaxIds = $record->salesTaxes()->pluck('adjustments.id')->toArray();
155
                                             if ($isPerLineItem) {
173
                                             if ($isPerLineItem) {
156
-                                                $existingDiscountIds = $record->salesDiscounts()->pluck('adjustments.id')->toArray();
174
+                                                $with['salesDiscounts'] = static function ($query) use ($existingDiscountIds) {
175
+                                                    $query->where(static function ($query) use ($existingDiscountIds) {
176
+                                                        $query->where('status', AdjustmentStatus::Active)
177
+                                                            ->orWhereIn('adjustments.id', $existingDiscountIds);
178
+                                                    });
179
+                                                };
157
                                             }
180
                                             }
158
-                                        }
159
-
160
-                                        $with = [
161
-                                            'salesTaxes' => static function ($query) use ($existingTaxIds) {
162
-                                                $query->where(static function ($query) use ($existingTaxIds) {
163
-                                                    $query->where('status', AdjustmentStatus::Active)
164
-                                                        ->orWhereIn('adjustments.id', $existingTaxIds);
165
-                                                });
166
-                                            },
167
-                                        ];
168
-
169
-                                        if ($isPerLineItem) {
170
-                                            $with['salesDiscounts'] = static function ($query) use ($existingDiscountIds) {
171
-                                                $query->where(static function ($query) use ($existingDiscountIds) {
172
-                                                    $query->where('status', AdjustmentStatus::Active)
173
-                                                        ->orWhereIn('adjustments.id', $existingDiscountIds);
174
-                                                });
175
-                                            };
176
-                                        }
177
 
181
 
178
-                                        $offeringRecord = Offering::with($with)->find($offeringId);
182
+                                            $offeringRecord = Offering::with($with)->find($offeringId);
179
 
183
 
180
-                                        if (! $offeringRecord) {
181
-                                            return;
182
-                                        }
184
+                                            if (! $offeringRecord) {
185
+                                                return;
186
+                                            }
183
 
187
 
184
-                                        $unitPrice = CurrencyConverter::convertToFloat($offeringRecord->price, $get('../../currency_code') ?? CurrencyAccessor::getDefaultCurrency());
188
+                                            $unitPrice = CurrencyConverter::convertToFloat($offeringRecord->price, $get('../../currency_code') ?? CurrencyAccessor::getDefaultCurrency());
185
 
189
 
186
-                                        $set('description', $offeringRecord->description);
187
-                                        $set('unit_price', $unitPrice);
188
-                                        $set('salesTaxes', $offeringRecord->salesTaxes->pluck('id')->toArray());
190
+                                            $set('description', $offeringRecord->description);
191
+                                            $set('unit_price', $unitPrice);
192
+                                            $set('salesTaxes', $offeringRecord->salesTaxes->pluck('id')->toArray());
189
 
193
 
190
-                                        if ($isPerLineItem) {
191
-                                            $set('salesDiscounts', $offeringRecord->salesDiscounts->pluck('id')->toArray());
192
-                                        }
193
-                                    }),
194
-                                Forms\Components\TextInput::make('description'),
194
+                                            if ($isPerLineItem) {
195
+                                                $set('salesDiscounts', $offeringRecord->salesDiscounts->pluck('id')->toArray());
196
+                                            }
197
+                                        }),
198
+                                    Forms\Components\TextInput::make('description')
199
+                                        ->placeholder('Enter item description')
200
+                                        ->hiddenLabel(),
201
+                                ])->columnSpan(1),
195
                                 Forms\Components\TextInput::make('quantity')
202
                                 Forms\Components\TextInput::make('quantity')
196
                                     ->required()
203
                                     ->required()
197
                                     ->numeric()
204
                                     ->numeric()
204
                                     ->live()
211
                                     ->live()
205
                                     ->maxValue(9999999999.99)
212
                                     ->maxValue(9999999999.99)
206
                                     ->default(0),
213
                                     ->default(0),
207
-                                CreateAdjustmentSelect::make('salesTaxes')
208
-                                    ->label('Taxes')
209
-                                    ->category(AdjustmentCategory::Tax)
210
-                                    ->type(AdjustmentType::Sales)
211
-                                    ->adjustmentsRelationship('salesTaxes')
212
-                                    ->saveRelationshipsUsing(null)
213
-                                    ->dehydrated(true)
214
-                                    ->preload()
215
-                                    ->multiple()
216
-                                    ->live()
217
-                                    ->searchable(),
218
-                                CreateAdjustmentSelect::make('salesDiscounts')
219
-                                    ->label('Discounts')
220
-                                    ->category(AdjustmentCategory::Discount)
221
-                                    ->type(AdjustmentType::Sales)
222
-                                    ->adjustmentsRelationship('salesDiscounts')
223
-                                    ->saveRelationshipsUsing(null)
224
-                                    ->dehydrated(true)
225
-                                    ->multiple()
226
-                                    ->live()
227
-                                    ->hidden(function (Forms\Get $get) {
228
-                                        $discountMethod = DocumentDiscountMethod::parse($get('../../discount_method'));
229
-
230
-                                        return $discountMethod->isPerDocument();
231
-                                    })
232
-                                    ->searchable(),
214
+                                Forms\Components\Group::make([
215
+                                    CreateAdjustmentSelect::make('salesTaxes')
216
+                                        ->label('Taxes')
217
+                                        ->hiddenLabel()
218
+                                        ->placeholder('Select taxes')
219
+                                        ->category(AdjustmentCategory::Tax)
220
+                                        ->type(AdjustmentType::Sales)
221
+                                        ->adjustmentsRelationship('salesTaxes')
222
+                                        ->saveRelationshipsUsing(null)
223
+                                        ->dehydrated(true)
224
+                                        ->inlineSuffix()
225
+                                        ->preload()
226
+                                        ->multiple()
227
+                                        ->live()
228
+                                        ->searchable(),
229
+                                    CreateAdjustmentSelect::make('salesDiscounts')
230
+                                        ->label('Discounts')
231
+                                        ->hiddenLabel()
232
+                                        ->placeholder('Select discounts')
233
+                                        ->category(AdjustmentCategory::Discount)
234
+                                        ->type(AdjustmentType::Sales)
235
+                                        ->adjustmentsRelationship('salesDiscounts')
236
+                                        ->saveRelationshipsUsing(null)
237
+                                        ->dehydrated(true)
238
+                                        ->inlineSuffix()
239
+                                        ->multiple()
240
+                                        ->live()
241
+                                        ->hidden(function (Forms\Get $get) {
242
+                                            $discountMethod = DocumentDiscountMethod::parse($get('../../discount_method'));
243
+
244
+                                            return $discountMethod->isPerDocument();
245
+                                        })
246
+                                        ->searchable(),
247
+                                ])->columnSpan(1),
233
                                 Forms\Components\Placeholder::make('total')
248
                                 Forms\Components\Placeholder::make('total')
234
                                     ->hiddenLabel()
249
                                     ->hiddenLabel()
235
                                     ->extraAttributes(['class' => 'text-left sm:text-right'])
250
                                     ->extraAttributes(['class' => 'text-left sm:text-right'])

読み込み中…
キャンセル
保存