FilamentF
Filament2y ago
3 replies
Pablo Torres

Summary to calculate VAT if not exempt.

Please, I have the following code in my DealsRelationManager.php in my Bookings edit page.

Tables\Columns\TextColumn::make('price')
                    ->money('gbp', divideBy: 100)
                    ->searchable(isIndividual: true)
                    ->sortable()

                    ->summarize(Sum::make()
                        ->label('Sub Total')
                        ->money('gbp', divideBy: 100))

                    ->summarize(
                        Summarizer::make()
                            ->label('VAT')
                            ->money('gbp', divideBy: 100)
                            ->using(function (\Illuminate\Database\Query\Builder $query) {
                                $booking = Booking::where('id', 2)->firstOrFail();
                                $exemptFromVat = $booking->exempt_from_vat;
                                if (!$exemptFromVat) {
                                    $vatValue = Setting::where('id', 1)->firstOrFail()->bookings_vat;
                                    return $query->sum(DB::raw("price * $vatValue / 100"));
                                } else {
                                    return 0;
                                }
                            })
                    )

I need to update the code so the hard-coded id '2'
In line: $booking = Booking::where('id', 2)->firstOrFail();
is dynamically loaded. Any suggestions, thanks."
Was this page helpful?