Skip to content

Commit 9c8d366

Browse files
simonhampclaude
andauthored
Add column totals to the admin payout and sales tables (#502)
Sums the Paid and Due to Seller columns on both the Payouts and Third-Party Sales list screens. Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 45e3f59 commit 9c8d366

4 files changed

Lines changed: 64 additions & 0 deletions

File tree

‎app/Filament/Resources/PluginPayoutResource.php‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,13 @@ public static function table(Table $table): Table
132132
Tables\Columns\TextColumn::make('gross_amount')
133133
->label('Paid')
134134
->formatStateUsing(fn (int $state): string => '$'.number_format($state / 100, 2))
135+
->summarize(Tables\Columns\Summarizers\Sum::make('sum')->money('USD', divideBy: 100))
135136
->sortable(),
136137

137138
Tables\Columns\TextColumn::make('developer_amount')
138139
->label('Due to Seller')
139140
->formatStateUsing(fn (int $state): string => '$'.number_format($state / 100, 2))
141+
->summarize(Tables\Columns\Summarizers\Sum::make('sum')->money('USD', divideBy: 100))
140142
->sortable(),
141143

142144
Tables\Columns\TextColumn::make('status')

‎app/Filament/Resources/ThirdPartySaleResource.php‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,13 @@ public static function table(Table $table): Table
7979
Tables\Columns\TextColumn::make('price_paid')
8080
->label('Paid')
8181
->formatStateUsing(fn (int $state): string => '$'.number_format($state / 100, 2))
82+
->summarize(Tables\Columns\Summarizers\Sum::make('sum')->money('USD', divideBy: 100))
8283
->sortable(),
8384

8485
Tables\Columns\TextColumn::make('payout.developer_amount')
8586
->label('Due to Seller')
8687
->formatStateUsing(fn (?int $state): string => $state === null ? '—' : '$'.number_format($state / 100, 2))
88+
->summarize(Tables\Columns\Summarizers\Sum::make('sum')->money('USD', divideBy: 100))
8789
->placeholder('—'),
8890

8991
Tables\Columns\TextColumn::make('payout_status')

‎tests/Feature/Filament/PluginPayoutResourceTest.php‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,29 @@ public function test_list_page_shows_plugin_customer_and_amounts(): void
6666
->assertSee('$14.00');
6767
}
6868

69+
public function test_list_page_totals_paid_and_due_to_seller(): void
70+
{
71+
PluginPayout::factory()->create([
72+
'gross_amount' => 2000,
73+
'platform_fee' => 600,
74+
'developer_amount' => 1400,
75+
]);
76+
77+
PluginPayout::factory()->create([
78+
'gross_amount' => 5000,
79+
'platform_fee' => 1500,
80+
'developer_amount' => 3500,
81+
]);
82+
83+
Livewire::actingAs($this->admin)
84+
->test(ListPluginPayouts::class)
85+
->assertSuccessful()
86+
->assertTableColumnSummarySet('gross_amount', 'sum', 7000)
87+
->assertTableColumnSummarySet('developer_amount', 'sum', 4900)
88+
->assertSee('$70.00')
89+
->assertSee('$49.00');
90+
}
91+
6992
public function test_view_page_renders_successfully(): void
7093
{
7194
$payout = PluginPayout::factory()->failed()->create();

‎tests/Feature/Filament/ThirdPartySaleResourceTest.php‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,43 @@ public function test_excludes_grandfathered_licenses(): void
122122
->assertCanNotSeeTableRecords([$granted]);
123123
}
124124

125+
public function test_totals_paid_and_due_to_seller(): void
126+
{
127+
$plugin = $this->createThirdPartyPlugin();
128+
129+
$first = PluginLicense::factory()->create([
130+
'plugin_id' => $plugin->id,
131+
'price_paid' => 2000,
132+
]);
133+
PluginPayout::factory()->create([
134+
'plugin_license_id' => $first->id,
135+
'developer_account_id' => $plugin->developer_account_id,
136+
'gross_amount' => 2000,
137+
'platform_fee' => 600,
138+
'developer_amount' => 1400,
139+
]);
140+
141+
$second = PluginLicense::factory()->create([
142+
'plugin_id' => $plugin->id,
143+
'price_paid' => 5000,
144+
]);
145+
PluginPayout::factory()->create([
146+
'plugin_license_id' => $second->id,
147+
'developer_account_id' => $plugin->developer_account_id,
148+
'gross_amount' => 5000,
149+
'platform_fee' => 1500,
150+
'developer_amount' => 3500,
151+
]);
152+
153+
Livewire::actingAs($this->admin)
154+
->test(ListThirdPartySales::class)
155+
->assertSuccessful()
156+
->assertTableColumnSummarySet('price_paid', 'sum', 7000)
157+
->assertTableColumnSummarySet('payout.developer_amount', 'sum', 4900)
158+
->assertSee('$70.00')
159+
->assertSee('$49.00');
160+
}
161+
125162
public function test_filters_sales_missing_payouts(): void
126163
{
127164
$plugin = $this->createThirdPartyPlugin();

0 commit comments

Comments
 (0)