Files
unsupervised-scheduler/tests/Unit/Payment/PaymentReportTest.php
T
thatguygriff 553cfafa49
CI / Tests (PHP 8.1) (pull_request) Successful in 51s
CI / Coding Standards (pull_request) Successful in 1m1s
CI / Tests (PHP 8.2) (pull_request) Successful in 58s
CI / No Debug Code (pull_request) Successful in 4s
CI / PHPStan (pull_request) Successful in 1m16s
CI / Tests (PHP 8.3) (pull_request) Successful in 45s
CI / Build Plugin Zip (pull_request) Has been skipped
Add HST/tax support and payment reporting with HST aggregation
Studio Settings gains a default HST rate; the rate is frozen onto each
payment at booking and computed against the pre-tax subtotal, with the
total billed as subtotal + tax. The rate is overridable per booking on
My Lessons while unpaid (recomputing the tax amount), comped
registrations are never taxed, and receipts break out subtotal/HST/total.

Builds the payments report (roadmap #8) from us_payments: a monthly
per-instructor view with subtotal, HST collected, and grand-total
aggregation, plus a nonce-protected CSV export via admin-post. Studio
admins see all instructors and can filter; instructors are scoped to
their own rows. The Payment Report menu is gated on export_payments so
instructors (who lack manage_billing) can reach it.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-08 11:29:48 -03:00

84 lines
2.7 KiB
PHP

<?php
declare(strict_types=1);
namespace Unsupervised\Schedular\Tests\Unit\Payment;
use Unsupervised\Schedular\Payment\PaymentReport;
use Unsupervised\Schedular\Tests\Unit\TestCase;
class PaymentReportTest extends TestCase
{
/**
* @return list<array{date: string, student: string, instructor: string, method: string, status: string, amount: float, tax_rate: float, tax_amount: float, total: float}>
*/
private function rows(): array
{
return [
[
'date' => '2026-06-02',
'student' => 'Ada',
'instructor' => 'Pat',
'method' => 'etransfer',
'status' => 'paid',
'amount' => 100.00,
'tax_rate' => 13.0,
'tax_amount' => 13.00,
'total' => 113.00,
],
[
'date' => '2026-06-09',
'student' => 'Grace',
'instructor' => 'Pat',
'method' => 'card',
'status' => 'paid',
'amount' => 50.00,
'tax_rate' => 13.0,
'tax_amount' => 6.50,
'total' => 56.50,
],
];
}
public function testTotalsAggregateAmountsAndTax(): void
{
$report = new PaymentReport($this->rows());
self::assertSame(2, $report->count());
self::assertSame(150.00, $report->totalAmount());
self::assertSame(19.50, $report->totalTax());
self::assertSame(169.50, $report->grandTotal());
}
public function testEmptyReportHasZeroTotals(): void
{
$report = new PaymentReport([]);
self::assertSame(0, $report->count());
self::assertSame(0.0, $report->totalTax());
self::assertSame(0.0, $report->grandTotal());
}
public function testCsvIncludesHeaderRowsAndTotals(): void
{
$csv = (new PaymentReport($this->rows()))->toCsv();
$lines = explode("\n", trim($csv));
// header + 2 data rows + totals row.
self::assertCount(4, $lines);
self::assertStringContainsString('"Date","Student","Instructor"', $lines[0]);
self::assertStringContainsString('"Ada"', $lines[1]);
self::assertStringContainsString('"Totals"', $lines[3]);
self::assertStringContainsString('"19.50"', $lines[3]);
self::assertStringContainsString('"169.50"', $lines[3]);
}
public function testCsvEscapesEmbeddedQuotes(): void
{
$rows = $this->rows();
$rows[0]['student'] = 'Ada "The Great"';
$csv = (new PaymentReport($rows))->toCsv();
self::assertStringContainsString('"Ada ""The Great"""', $csv);
}
}