Skip to content

Commit

Permalink
add discount function and search
Browse files Browse the repository at this point in the history
  • Loading branch information
Thiritin committed Sep 16, 2024
1 parent 4d4cecc commit a90cd91
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 14 deletions.
14 changes: 6 additions & 8 deletions app/Filament/Resources/BadgeResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,16 @@ public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('custom_id')
->sortable()
->searchable()
->label('Fursuit'),
Tables\Columns\TextColumn::make('fursuit.user.attendee_id')
->sortable()
->searchable()
->label('Fursuit'),
Tables\Columns\TextColumn::make('fursuit.name')
->searchable()
->label('Fursuit'),
Tables\Columns\TextColumn::make('status')->badge()->colors([
Pending::$name => 'default',
Expand All @@ -77,14 +83,6 @@ public static function table(Table $table): Table
Tables\Filters\SelectFilter::make('status')
->options(BadgeStatusState::getStateMapping()->keys()->mapWithKeys(fn($key) => [ucfirst($key) => $key]))
->label('Badge Status'),
Tables\Filters\SelectFilter::make('fursuit_status')
->options(FursuitStatusState::getStateMapping()->keys()->mapWithKeys(fn($key) => [$key => ucfirst($key)]))
->query(function (Builder $query, array $data) {
$query->when($data, fn($query, $data) => $query->whereHas('fursuit', function (Builder $query) use ($data) {
$query->where('status', $data);
}));
})
->label('Fursuit Status'),
// Duplex Bool Filter
Tables\Filters\TernaryFilter::make('dual_side_print')
->label('Double Sided'),
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/BadgeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public function update(BadgeUpdateRequest $request, Badge $badge)
$badge->total = round($total);
$badge->subtotal = round($total / 1.19);
$badge->tax = round($badge->total - $badge->subtotal);
$badge->save();
$badge->saveQuietly();
// Difference needs to be paid
if ($previousTotal !== $total) {
$request->user()->forcePay($badge);
Expand Down
13 changes: 12 additions & 1 deletion app/Observers/BadgeObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace App\Observers;

use App\Models\Badge\Badge;
use App\Models\Fursuit\Fursuit;
use Illuminate\Routing\Route;

class BadgeObserver
{
Expand All @@ -12,7 +14,16 @@ public function updated(Badge $badge): void
if ($badge->isDirty('total')) {
$badge->subtotal = round($badge->total / 1.19,);
$badge->tax = round($badge->total - $badge->subtotal);
$badge->save();

$user = $badge->fursuit->user;
$originalTotal = $badge->getOriginal();
$newTotal = $badge->total;
$badge->total = $originalTotal;
$user->refund($badge);
$badge->total = $newTotal;
$user->forcePay($badge);

$badge->saveQuietly();
}
}
}
9 changes: 5 additions & 4 deletions app/Policies/BadgePolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,15 @@ public function create(User $user): bool

public function update(User $user, Badge $badge): bool
{
// Admin can override
if ($user->is_admin && request()->routeIs('filament.*', 'livewire.*')) {
return true;
}

// Copies cannot be edited
if ($badge->extra_copy_of !== null) {
return false;
}
// Admin can override
if ($user->is_admin && request()->routeIs('filament.*')) {
return true;
}

$event = \App\Models\Event::getActiveEvent();
return $this->delete($user, $badge);
Expand Down

0 comments on commit a90cd91

Please sign in to comment.