add tests batch 20

This commit is contained in:
root
2026-06-09 01:03:53 -04:00
parent 95efb9652e
commit 6be4875c5e
1502 changed files with 13797 additions and 11313 deletions
@@ -9,11 +9,11 @@ class RefundDecisionService
public function updateDecision(int $refundId, string $status, string $reason, int $actorId): array
{
$refund = Refund::query()->find($refundId);
if (! $refund) {
if (!$refund) {
return ['ok' => false, 'message' => 'Refund not found.'];
}
if (! in_array($status, [Refund::STATUS_APPROVED, Refund::STATUS_REJECTED], true)) {
if (!in_array($status, [Refund::STATUS_APPROVED, Refund::STATUS_REJECTED], true)) {
return ['ok' => false, 'message' => 'Invalid refund status.'];
}
@@ -46,7 +46,7 @@ class RefundDecisionService
public function cancel(int $refundId, int $actorId): array
{
$refund = Refund::query()->find($refundId);
if (! $refund) {
if (!$refund) {
return ['ok' => false, 'message' => 'Refund not found.'];
}
@@ -8,7 +8,9 @@ use App\Services\Discounts\DiscountInvoiceService;
class RefundInvoiceAdjustmentService
{
public function __construct(private DiscountInvoiceService $invoiceService) {}
public function __construct(private DiscountInvoiceService $invoiceService)
{
}
public function applyBookChargeAndUpdateInvoice(
Invoice $invoice,
@@ -21,7 +23,7 @@ class RefundInvoiceAdjustmentService
$bookChargeDesc = 'Book fee retained for withdrawals before the refund deadline.';
$bookPrice = (float) ($refundDetails['book_price'] ?? 0.0);
$eligible = ! empty($refundDetails['eligible']);
$eligible = !empty($refundDetails['eligible']);
$bookChargeDelta = 0.0;
$bookChargeAction = 'none';
@@ -15,7 +15,8 @@ class RefundOverpaymentService
public function __construct(
private RefundNotificationService $notifications,
private ApplicationUrlService $urls,
) {}
) {
}
public function recalculate(bool $triggerEvents = false, ?string $invoiceNumber = null, ?int $actorId = null): array
{
@@ -76,7 +77,7 @@ class RefundOverpaymentService
private function recalculateForInvoice(string $invoiceNumber, bool $triggerEvents, ?int $actorId): array
{
$invoice = Invoice::query()->where('invoice_number', $invoiceNumber)->first();
if (! $invoice) {
if (!$invoice) {
return ['ok' => false, 'message' => 'Invoice not found.'];
}
@@ -120,7 +121,6 @@ class RefundOverpaymentService
'updated_at' => utc_now(),
'updated_by' => $actorId,
]);
return ['ok' => true, 'message' => 'Overpayment updated for invoice.'];
}
@@ -204,7 +204,6 @@ class RefundOverpaymentService
'updated_by' => $actorId,
]);
$updated[] = (int) $openRow->id;
continue;
}
@@ -225,7 +224,6 @@ class RefundOverpaymentService
'updated_by' => $actorId,
]);
$updated[] = (int) $parentLevelOpen->id;
continue;
}
@@ -236,7 +234,7 @@ class RefundOverpaymentService
->orderByDesc('id')
->first();
if (! $existing || $existing->status === Refund::STATUS_PAID) {
if (!$existing || $existing->status === Refund::STATUS_PAID) {
$refund = Refund::query()->create([
'parent_id' => $pid,
'school_year' => $schoolYear,
+2 -3
View File
@@ -14,11 +14,11 @@ class RefundPayoutService
public function recordPayment(int $refundId, array $payload, int $actorId): array
{
$refund = Refund::query()->find($refundId);
if (! $refund) {
if (!$refund) {
return ['ok' => false, 'message' => 'Refund not found.'];
}
if (! in_array($refund->status, [Refund::STATUS_APPROVED, Refund::STATUS_PARTIAL], true)) {
if (!in_array($refund->status, [Refund::STATUS_APPROVED, Refund::STATUS_PARTIAL], true)) {
return ['ok' => false, 'message' => 'Refund must be Approved or Partial to pay.'];
}
@@ -126,7 +126,6 @@ class RefundPayoutService
return $latest ? (int) $latest->id : null;
} catch (\Throwable $e) {
Log::warning('Refund invoice assignment failed.', ['error' => $e->getMessage()]);
return null;
}
}
+7 -6
View File
@@ -14,7 +14,8 @@ class RefundPolicyService
public function __construct(
private FeeRefundDetailService $refundDetails,
private RefundInvoiceAdjustmentService $invoiceAdjustments
) {}
) {
}
public function processWithdrawalRefund(
int $parentId,
@@ -38,7 +39,7 @@ class RefundPolicyService
->orderByDesc('created_at')
->first();
if (! $invoice) {
if (!$invoice) {
return ['ok' => false, 'error' => 'No invoice found for refund processing.'];
}
@@ -115,14 +116,14 @@ class RefundPolicyService
$refundAmount = (float) ($details['refund_amount'] ?? 0.0);
$debitAmount = (float) ($details['debit_amount'] ?? 0.0);
$eligible = ! empty($details['eligible']);
$eligible = !empty($details['eligible']);
$status = $refundAmount > 0 ? Refund::STATUS_PENDING : Refund::STATUS_REJECTED;
$reason = null;
if ($refundAmount <= 0) {
if (! $eligible) {
if (!$eligible) {
$reason = 'No refund due to late withdrawal.';
} elseif (! empty($details['full_discount'])) {
} elseif (!empty($details['full_discount'])) {
$reason = 'No refund due to full discount.';
} elseif ($debitAmount > 0) {
$reason = 'No refund due; book fee balance remains.';
@@ -188,7 +189,7 @@ class RefundPolicyService
'updated_by' => $actorId,
]);
if (! $created) {
if (!$created) {
return ['ok' => false, 'error' => 'Failed to create refund record.'];
}
+9 -9
View File
@@ -16,7 +16,7 @@ class RefundQueryService
$sortDir = strtolower((string) ($filters['sort_dir'] ?? 'desc')) === 'asc' ? 'asc' : 'desc';
$allowedSorts = ['created_at', 'updated_at', 'refund_amount', 'status', 'parent_id', 'invoice_id'];
if (! in_array($sortBy, $allowedSorts, true)) {
if (!in_array($sortBy, $allowedSorts, true)) {
$sortBy = 'created_at';
}
@@ -29,25 +29,25 @@ class RefundQueryService
->leftJoin('users as parents', 'parents.id', '=', 'refunds.parent_id')
->leftJoin('users as approvers', 'approvers.id', '=', 'refunds.approved_by');
if (! empty($filters['status'])) {
if (!empty($filters['status'])) {
$query->where('refunds.status', $filters['status']);
}
if (! empty($filters['request'])) {
if (!empty($filters['request'])) {
$query->where('refunds.request', $filters['request']);
}
if (! empty($filters['parent_id'])) {
if (!empty($filters['parent_id'])) {
$query->where('refunds.parent_id', (int) $filters['parent_id']);
}
if (! empty($filters['invoice_id'])) {
if (!empty($filters['invoice_id'])) {
$query->where('refunds.invoice_id', (int) $filters['invoice_id']);
}
if (! empty($filters['school_year'])) {
if (!empty($filters['school_year'])) {
$query->where('refunds.school_year', (string) $filters['school_year']);
}
if (! empty($filters['semester'])) {
if (!empty($filters['semester'])) {
$query->where('refunds.semester', (string) $filters['semester']);
}
if (! empty($filters['q'])) {
if (!empty($filters['q'])) {
$term = trim((string) $filters['q']);
$query->where(function ($where) use ($term) {
$where->where('refunds.reason', 'like', "%{$term}%")
@@ -57,7 +57,7 @@ class RefundQueryService
});
}
$paginator = $query->orderBy('refunds.'.$sortBy, $sortDir)
$paginator = $query->orderBy('refunds.' . $sortBy, $sortDir)
->paginate($perPage, ['*'], 'page', $page);
return [
@@ -18,7 +18,8 @@ class RefundRequestService
private RefundSummaryService $summaryService,
private RefundNotificationService $notifications,
private ApplicationUrlService $urls,
) {}
) {
}
public function requestRefund(array $payload, int $actorId): array
{
@@ -29,12 +30,12 @@ class RefundRequestService
$paymentId = isset($payload['payment_id']) ? (int) $payload['payment_id'] : null;
$reason = $payload['reason'] ?? null;
if (! in_array($requestType, self::REQUEST_TYPES, true)) {
if (!in_array($requestType, self::REQUEST_TYPES, true)) {
return ['ok' => false, 'message' => 'Invalid refund request type.'];
}
$parent = User::query()->find($parentId);
if (! $parent) {
if (!$parent) {
return ['ok' => false, 'message' => 'Parent not found.'];
}
@@ -100,19 +101,18 @@ class RefundRequestService
'status' => Refund::STATUS_PENDING,
'reason' => $reason,
'request' => $requestType,
'note' => $paymentId ? ('duplicate-of-payment#'.$paymentId) : null,
'note' => $paymentId ? ('duplicate-of-payment#' . $paymentId) : null,
'requested_at' => utc_now(),
'created_at' => utc_now(),
'updated_at' => utc_now(),
'updated_by' => $actorId,
]);
if (! $refund) {
if (!$refund) {
Log::error('Failed to create refund request.', [
'parent_id' => $parentId,
'type' => $requestType,
]);
return ['ok' => false, 'message' => 'Failed to create refund request.'];
}