|
|
@@ -166,7 +166,7 @@ class BillResource extends Resource
|
|
166
|
166
|
Forms\Components\Select::make('discount_method')
|
|
167
|
167
|
->label('Discount method')
|
|
168
|
168
|
->options(DocumentDiscountMethod::class)
|
|
169
|
|
- ->selectablePlaceholder(false)
|
|
|
169
|
+ ->softRequired()
|
|
170
|
170
|
->default($settings->discount_method)
|
|
171
|
171
|
->afterStateUpdated(function ($state, Forms\Set $set) {
|
|
172
|
172
|
$discountMethod = DocumentDiscountMethod::parse($state);
|
|
|
@@ -184,26 +184,26 @@ class BillResource extends Resource
|
|
184
|
184
|
->saveRelationshipsUsing(null)
|
|
185
|
185
|
->dehydrated(true)
|
|
186
|
186
|
->reorderable()
|
|
|
187
|
+ ->orderColumn('line_number')
|
|
187
|
188
|
->reorderAtStart()
|
|
188
|
189
|
->cloneable()
|
|
|
190
|
+ ->addActionLabel('Add an item')
|
|
189
|
191
|
->headers(function (Forms\Get $get) use ($settings) {
|
|
190
|
192
|
$hasDiscounts = DocumentDiscountMethod::parse($get('discount_method'))->isPerLineItem();
|
|
191
|
193
|
|
|
192
|
194
|
$headers = [
|
|
193
|
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
|
197
|
Header::make($settings->resolveColumnLabel('unit_name', 'Quantity'))
|
|
198
|
198
|
->width('10%'),
|
|
199
|
199
|
Header::make($settings->resolveColumnLabel('price_name', 'Price'))
|
|
200
|
200
|
->width('10%'),
|
|
201
|
|
- Header::make('Taxes')
|
|
202
|
|
- ->width($hasDiscounts ? '20%' : '30%'),
|
|
203
|
201
|
];
|
|
204
|
202
|
|
|
205
|
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
|
209
|
$headers[] = Header::make($settings->resolveColumnLabel('amount_name', 'Amount'))
|
|
|
@@ -213,61 +213,68 @@ class BillResource extends Resource
|
|
213
|
213
|
return $headers;
|
|
214
|
214
|
})
|
|
215
|
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
|
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
|
278
|
Forms\Components\TextInput::make('quantity')
|
|
272
|
279
|
->required()
|
|
273
|
280
|
->numeric()
|
|
|
@@ -281,32 +288,40 @@ class BillResource extends Resource
|
|
281
|
288
|
->live()
|
|
282
|
289
|
->maxValue(9999999999.99)
|
|
283
|
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
|
325
|
Forms\Components\Placeholder::make('total')
|
|
311
|
326
|
->hiddenLabel()
|
|
312
|
327
|
->extraAttributes(['class' => 'text-left sm:text-right'])
|