add refund logic and fix books inventory logic
This commit is contained in:
@@ -161,7 +161,7 @@ class InvoiceLedgerServiceTest extends CIUnitTestCase
|
||||
|
||||
$this->assertSame('0.00', $calculation['balance']);
|
||||
$this->assertSame('15.00', $calculation['customer_credit']);
|
||||
$this->assertSame(-3500, $calculation['rawBalanceCents']);
|
||||
$this->assertSame(-1500, $calculation['rawBalanceCents']);
|
||||
}
|
||||
|
||||
public function testFullyRefundedOverpaymentClearsCustomerCredit(): void
|
||||
@@ -177,7 +177,7 @@ class InvoiceLedgerServiceTest extends CIUnitTestCase
|
||||
|
||||
$this->assertSame('0.00', $calculation['balance']);
|
||||
$this->assertSame('0.00', $calculation['customer_credit']);
|
||||
$this->assertSame(-5000, $calculation['rawBalanceCents']);
|
||||
$this->assertSame(0, $calculation['rawBalanceCents']);
|
||||
}
|
||||
|
||||
public function testPaymentAfterRefundCanRestorePaidStatus(): void
|
||||
@@ -392,7 +392,7 @@ class InvoiceLedgerServiceTest extends CIUnitTestCase
|
||||
$this->assertSame(FinancialStatus::INVOICE_PAID, $calculation['status']);
|
||||
}
|
||||
|
||||
public function testCashRefundDoesNotCreateBalanceAfterOverpaymentIsReturned(): void
|
||||
public function testCashRefundAboveOverpaymentCreatesBalanceDue(): void
|
||||
{
|
||||
$service = new InvoiceLedgerServiceHarness([
|
||||
'id' => 12,
|
||||
@@ -405,8 +405,8 @@ class InvoiceLedgerServiceTest extends CIUnitTestCase
|
||||
$calculation = $service->calculateInvoice(12);
|
||||
|
||||
$this->assertSame('0.00', $calculation['customer_credit']);
|
||||
$this->assertSame('0.00', $calculation['balance']);
|
||||
$this->assertSame(FinancialStatus::INVOICE_PAID, $calculation['status']);
|
||||
$this->assertSame('5.00', $calculation['balance']);
|
||||
$this->assertSame(FinancialStatus::INVOICE_PARTIALLY_PAID, $calculation['status']);
|
||||
}
|
||||
|
||||
public function testIssuedInvoiceUsesPaidRefundsAsCashOutInsteadOfAdditionalCredit(): void
|
||||
@@ -429,7 +429,7 @@ class InvoiceLedgerServiceTest extends CIUnitTestCase
|
||||
$this->assertSame(FinancialStatus::INVOICE_PAID, $calculation['status']);
|
||||
}
|
||||
|
||||
public function testRefundedWithdrawalInvoiceHasNoBalanceDue(): void
|
||||
public function testRefundedWithdrawalInvoiceShowsBalanceWhenRefundsExceedPaymentAgainstCharge(): void
|
||||
{
|
||||
$service = new InvoiceLedgerServiceHarness([
|
||||
'id' => 14,
|
||||
@@ -446,7 +446,7 @@ class InvoiceLedgerServiceTest extends CIUnitTestCase
|
||||
$this->assertSame('178.00', $calculation['paid_amount']);
|
||||
$this->assertSame('178.00', $calculation['refund_paid_total']);
|
||||
$this->assertSame('0.00', $calculation['customer_credit']);
|
||||
$this->assertSame('0.00', $calculation['balance']);
|
||||
$this->assertSame(FinancialStatus::INVOICE_PAID, $calculation['status']);
|
||||
$this->assertSame('280.00', $calculation['balance']);
|
||||
$this->assertSame(FinancialStatus::INVOICE_PARTIALLY_PAID, $calculation['status']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ class RefundEligibilityServiceHarness extends RefundEligibilityService
|
||||
return $this->completedPayoutCents;
|
||||
}
|
||||
|
||||
protected function calculateReservedAmountCents(string $sourceType, int $sourceId, ?int $excludeRefundId): int
|
||||
protected function calculateReservedAmountCents(string $sourceType, int $sourceId, ?int $excludeRefundId, ?int $invoiceId = null): int
|
||||
{
|
||||
return $this->reservedAmountCents;
|
||||
}
|
||||
@@ -60,17 +60,17 @@ class RefundEligibilityServiceTest extends CIUnitTestCase
|
||||
$this->assertContains('HAS_APPROVED_RESERVATIONS', $result->reasonCodes);
|
||||
}
|
||||
|
||||
public function testTuitionWithdrawalAvailableCreditSubtractsCompletedPayoutsAndReservations(): void
|
||||
public function testTuitionWithdrawalAvailableCreditUsesAdjustedInvoiceCreditWithoutDoubleSubtractingPayouts(): void
|
||||
{
|
||||
$service = new RefundEligibilityServiceHarness(20000, 2500, 1500);
|
||||
|
||||
$result = $service->calculateAvailableCredit(10, 20, 'tuition_withdrawal', 20);
|
||||
|
||||
$this->assertSame(20000, $result->sourceCreditCents);
|
||||
$this->assertSame(2500, $result->completedPayoutCents);
|
||||
$this->assertSame(0, $result->completedPayoutCents);
|
||||
$this->assertSame(1500, $result->reservedAmountCents);
|
||||
$this->assertSame(16000, $result->availableAmountCents);
|
||||
$this->assertContains('HAS_COMPLETED_PAYOUTS', $result->reasonCodes);
|
||||
$this->assertSame(18500, $result->availableAmountCents);
|
||||
$this->assertNotContains('HAS_COMPLETED_PAYOUTS', $result->reasonCodes);
|
||||
$this->assertContains('HAS_APPROVED_RESERVATIONS', $result->reasonCodes);
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ final class EnrollmentStatusServiceTest extends TestCase
|
||||
['payment pending', 1],
|
||||
['enrolled', 1],
|
||||
['withdraw under review', 1],
|
||||
['refund pending', 1],
|
||||
['refund pending', 0],
|
||||
['denied', 0],
|
||||
['withdrawn', 0],
|
||||
['waitlist', 0],
|
||||
|
||||
@@ -5,8 +5,51 @@ namespace Tests\App\Services;
|
||||
use App\Services\FeeCalculationService;
|
||||
use CodeIgniter\Test\CIUnitTestCase;
|
||||
|
||||
class FeeCalculationServiceRefundAdapterHarness extends FeeCalculationService
|
||||
{
|
||||
public array $previewedEnrollmentIds = [];
|
||||
|
||||
public function __construct(private array $latestByEnrollment, private array $previewByEnrollment)
|
||||
{
|
||||
}
|
||||
|
||||
protected function latestWithdrawalCalculation(int $enrollmentId): ?array
|
||||
{
|
||||
return $this->latestByEnrollment[$enrollmentId] ?? null;
|
||||
}
|
||||
|
||||
protected function previewWithdrawalCalculation(int $enrollmentId): array
|
||||
{
|
||||
$this->previewedEnrollmentIds[] = $enrollmentId;
|
||||
return $this->previewByEnrollment[$enrollmentId] ?? ['new_refund_request_cents' => 0];
|
||||
}
|
||||
}
|
||||
|
||||
class FeeCalculationServiceTest extends CIUnitTestCase
|
||||
{
|
||||
public function testRefundAdapterUsesWithdrawalFinancialPreviewAmounts(): void
|
||||
{
|
||||
$service = new FeeCalculationServiceRefundAdapterHarness(
|
||||
latestByEnrollment: [
|
||||
10 => ['status' => 'preview', 'new_refund_request_cents' => 12345],
|
||||
11 => ['status' => 'superseded', 'new_refund_request_cents' => 99999],
|
||||
],
|
||||
previewByEnrollment: [
|
||||
11 => ['status' => 'preview', 'new_refund_request_cents' => 500],
|
||||
]
|
||||
);
|
||||
|
||||
$refund = $service->calculateRefund([
|
||||
['id' => 10, 'parent_id' => 8, 'enrollment_status' => 'withdraw under review'],
|
||||
['id' => 11, 'parent_id' => 8, 'enrollment_status' => 'refund pending'],
|
||||
['id' => 12, 'parent_id' => 8, 'enrollment_status' => 'enrolled'],
|
||||
['id' => 13, 'parent_id' => 9, 'enrollment_status' => 'refund pending'],
|
||||
], 8);
|
||||
|
||||
$this->assertSame(128.45, $refund);
|
||||
$this->assertSame([11], $service->previewedEnrollmentIds);
|
||||
}
|
||||
|
||||
public function testRefundReversesLatestTuitionTierFirst(): void
|
||||
{
|
||||
$fees = $this->refundFeeStack(3, 2, 380.0, 280.0);
|
||||
|
||||
Reference in New Issue
Block a user