#!/usr/bin/env python3 """ Redesign the ScheduledGivingDonationResource table columns. Replace the old columns with campaign-aware, care-focused columns. """ import os BASE = '/home/forge/app.charityright.org.uk' path = os.path.join(BASE, 'app/Filament/Resources/ScheduledGivingDonationResource.php') with open(path, 'r') as f: c = f.read() old_columns = """ ->columns([ IconColumn::make('donationConfirmation.confirmed_at') ->label('Confirmed ?') ->searchable() ->boolean(), TextColumn::make('total_amount') ->label('Total') ->numeric() ->money('gbp') ->searchable() ->sortable(), TextColumn::make('amount_admin') ->label('Admin') ->numeric() ->money('gbp') ->searchable() ->sortable(), TextColumn::make('customer.name') ->label('Customer') ->description(fn (ScheduledGivingDonation $donation) => $donation->customer?->email) ->sortable() ->searchable(true, function (Builder $query, string $search) { $query ->whereHas('customer', function (Builder $query) use ($search) { $query ->where('first_name', 'like', "%{$search}%") ->orWhere('last_name', 'like', "%{$search}%") ->orWhere('email', 'like', "%{$search}%"); }); }), TextColumn::make('provider_reference') ->searchable() ->label('Provider Reference'), TextColumn::make('appeal.name') ->numeric() ->toggleable(isToggledHiddenByDefault: true) ->sortable(), TextColumn::make('created_at') ->dateTime() ->sortable() ->toggleable(isToggledHiddenByDefault: true), TextColumn::make('updated_at') ->dateTime() ->sortable() ->toggleable(isToggledHiddenByDefault: true), ])""" new_columns = """ ->columns([ IconColumn::make('is_active') ->label('') ->boolean() ->trueIcon('heroicon-o-check-circle') ->falseIcon('heroicon-o-x-circle') ->trueColor('success') ->falseColor('danger') ->tooltip(fn (ScheduledGivingDonation $r) => $r->is_active ? 'Active' : 'Cancelled'), TextColumn::make('customer.name') ->label('Donor') ->description(fn (ScheduledGivingDonation $d) => $d->customer?->email) ->sortable() ->searchable(query: function (Builder $query, string $search) { $query->whereHas('customer', fn (Builder $q) => $q ->where('first_name', 'like', "%{$search}%") ->orWhere('last_name', 'like', "%{$search}%") ->orWhere('email', 'like', "%{$search}%")); }), TextColumn::make('scheduledGivingCampaign.title') ->label('Campaign') ->badge() ->color(fn ($state) => match ($state) { '30 Nights of Giving' => 'primary', '10 Days of Giving' => 'success', 'Night of Power' => 'warning', default => 'gray', }), TextColumn::make('total_amount') ->label('Per Night') ->money('gbp', divideBy: 100) ->sortable(), TextColumn::make('payments_count') ->label('Progress') ->counts('payments') ->formatStateUsing(function ($state, ScheduledGivingDonation $record) { $paid = $record->payments()->where('is_paid', true)->count(); $total = $state; if ($total === 0) return 'No payments'; $pct = round($paid / $total * 100); return "{$paid}/{$total} ({$pct}%)"; }) ->color(function (ScheduledGivingDonation $record) { $total = $record->payments()->count(); if ($total === 0) return 'gray'; $paid = $record->payments()->where('is_paid', true)->count(); $pct = $paid / $total * 100; return $pct >= 80 ? 'success' : ($pct >= 40 ? 'warning' : 'danger'); }) ->badge(), TextColumn::make('created_at') ->label('Signed Up') ->date('d M Y') ->description(fn (ScheduledGivingDonation $d) => $d->created_at?->diffForHumans()) ->sortable(), TextColumn::make('reference_code') ->label('Ref') ->searchable() ->fontFamily('mono') ->copyable() ->toggleable(isToggledHiddenByDefault: true), ])""" c = c.replace(old_columns, new_columns) with open(path, 'w') as f: f.write(c) print('Table columns updated')