fix tests

This commit is contained in:
root
2026-06-11 11:46:12 -04:00
parent c91fa2ce4d
commit 5ead80fdc7
1489 changed files with 11349 additions and 10305 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,9 +8,7 @@ use App\Services\Discounts\DiscountInvoiceService;
class RefundInvoiceAdjustmentService
{
public function __construct(private DiscountInvoiceService $invoiceService)
{
}
public function __construct(private DiscountInvoiceService $invoiceService) {}
public function applyBookChargeAndUpdateInvoice(
Invoice $invoice,
@@ -23,7 +21,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,8 +15,7 @@ class RefundOverpaymentService
public function __construct(
private RefundNotificationService $notifications,
private ApplicationUrlService $urls,
) {
}
) {}
public function recalculate(bool $triggerEvents = false, ?string $invoiceNumber = null, ?int $actorId = null): array
{
@@ -77,7 +76,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.'];
}
@@ -121,6 +120,7 @@ class RefundOverpaymentService
'updated_at' => utc_now(),
'updated_by' => $actorId,
]);
return ['ok' => true, 'message' => 'Overpayment updated for invoice.'];
}
@@ -209,6 +209,7 @@ class RefundOverpaymentService
'updated_by' => $actorId,
]);
$updated[] = (int) $openRow->id;
continue;
}
@@ -229,6 +230,7 @@ class RefundOverpaymentService
'updated_by' => $actorId,
]);
$updated[] = (int) $parentLevelOpen->id;
continue;
}
@@ -239,7 +241,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,
+3 -2
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,6 +126,7 @@ class RefundPayoutService
return $latest ? (int) $latest->id : null;
} catch (\Throwable $e) {
Log::warning('Refund invoice assignment failed.', ['error' => $e->getMessage()]);
return null;
}
}
+6 -7
View File
@@ -14,8 +14,7 @@ class RefundPolicyService
public function __construct(
private FeeRefundDetailService $refundDetails,
private RefundInvoiceAdjustmentService $invoiceAdjustments
) {
}
) {}
public function processWithdrawalRefund(
int $parentId,
@@ -39,7 +38,7 @@ class RefundPolicyService
->orderByDesc('created_at')
->first();
if (!$invoice) {
if (! $invoice) {
return ['ok' => false, 'error' => 'No invoice found for refund processing.'];
}
@@ -116,14 +115,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.';
@@ -189,7 +188,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,8 +18,7 @@ class RefundRequestService
private RefundSummaryService $summaryService,
private RefundNotificationService $notifications,
private ApplicationUrlService $urls,
) {
}
) {}
public function requestRefund(array $payload, int $actorId): array
{
@@ -30,12 +29,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.'];
}
@@ -101,18 +100,19 @@ 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.'];
}