add test batches
This commit is contained in:
@@ -10,7 +10,6 @@ use Illuminate\Support\Facades\Log;
|
||||
class DiscountApplyService
|
||||
{
|
||||
private DiscountContextService $context;
|
||||
|
||||
private DiscountInvoiceService $invoiceService;
|
||||
|
||||
public function __construct(DiscountContextService $context, DiscountInvoiceService $invoiceService)
|
||||
@@ -25,7 +24,7 @@ class DiscountApplyService
|
||||
$semester = $this->context->getSemester();
|
||||
|
||||
$voucher = DiscountVoucher::query()->find($voucherId);
|
||||
if (! $voucher) {
|
||||
if (!$voucher) {
|
||||
return ['ok' => false, 'message' => 'Voucher not found.'];
|
||||
}
|
||||
|
||||
@@ -44,7 +43,7 @@ class DiscountApplyService
|
||||
return ['ok' => false, 'message' => 'This voucher has reached its maximum allowed uses.'];
|
||||
}
|
||||
|
||||
if (! $allowAdditional) {
|
||||
if (!$allowAdditional) {
|
||||
$rows = DB::table('discount_usages as du')
|
||||
->select('i.parent_id')
|
||||
->join('invoices as i', 'i.id', '=', 'du.invoice_id')
|
||||
@@ -56,7 +55,7 @@ class DiscountApplyService
|
||||
->all();
|
||||
|
||||
$blockedParentIds = array_map(static fn ($r) => (int) ($r['parent_id'] ?? 0), $rows);
|
||||
if (! empty($blockedParentIds)) {
|
||||
if (!empty($blockedParentIds)) {
|
||||
$parentIds = array_values(array_diff(array_map('intval', $parentIds), $blockedParentIds));
|
||||
}
|
||||
if (empty($parentIds)) {
|
||||
@@ -82,7 +81,6 @@ class DiscountApplyService
|
||||
'parent_id' => (int) $parentId,
|
||||
'voucher_id' => $voucherId,
|
||||
]);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -101,7 +99,7 @@ class DiscountApplyService
|
||||
continue;
|
||||
}
|
||||
|
||||
if (! $allowAdditional) {
|
||||
if (!$allowAdditional) {
|
||||
$exists = DB::table('discount_usages as du')
|
||||
->join('invoices as i', 'du.invoice_id', '=', 'i.id')
|
||||
->where('du.voucher_id', $voucherId)
|
||||
@@ -199,7 +197,6 @@ class DiscountApplyService
|
||||
DB::commit();
|
||||
} catch (\Throwable $e) {
|
||||
DB::rollBack();
|
||||
|
||||
return ['ok' => false, 'message' => 'Voucher application failed. Transaction rolled back.'];
|
||||
}
|
||||
|
||||
@@ -289,7 +286,7 @@ class DiscountApplyService
|
||||
event('paymentReceived', [$eventData, $studentData]);
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
Log::warning('paymentReceived hook failed: '.$e->getMessage());
|
||||
Log::warning('paymentReceived hook failed: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,12 +17,13 @@ class DiscountInvoiceService
|
||||
{
|
||||
public function __construct(
|
||||
private ApplicationUrlService $urls,
|
||||
) {}
|
||||
) {
|
||||
}
|
||||
|
||||
public function getCurrentInvoiceBalance(int $invoiceId, string $schoolYear): float
|
||||
{
|
||||
$invoice = Invoice::query()->find($invoiceId);
|
||||
if (! $invoice) {
|
||||
if (!$invoice) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
@@ -65,14 +66,13 @@ class DiscountInvoiceService
|
||||
$totalRefundPaid = (float) ($rowRefund['total_refund_paid'] ?? 0);
|
||||
|
||||
$total = (float) ($invoice->total_amount ?? 0);
|
||||
|
||||
return max(0.0, round($total - $totalPaid - $totalDisc - $totalRefundPaid, 2));
|
||||
}
|
||||
|
||||
public function recalculateInvoice(int $invoiceId, string $schoolYear): void
|
||||
{
|
||||
$invoice = Invoice::query()->find($invoiceId);
|
||||
if (! $invoice) {
|
||||
if (!$invoice) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ class DiscountInvoiceService
|
||||
}
|
||||
|
||||
$tuitionStudents = $registered;
|
||||
if (! $refundAllowed) {
|
||||
if (!$refundAllowed) {
|
||||
$tuitionStudents = array_merge($tuitionStudents, $withdrawn);
|
||||
}
|
||||
|
||||
@@ -129,7 +129,7 @@ class DiscountInvoiceService
|
||||
|
||||
foreach ($tuitionStudents as &$s) {
|
||||
$name = null;
|
||||
if (! empty($s['class_section_id'])) {
|
||||
if (!empty($s['class_section_id'])) {
|
||||
$name = ClassSection::getClassSectionNameBySectionId($s['class_section_id']);
|
||||
}
|
||||
$s['grade_name'] = is_string($name) ? strtoupper(trim($name)) : 'N/A';
|
||||
@@ -236,13 +236,13 @@ class DiscountInvoiceService
|
||||
public function updateEnrollmentStatusIfPaid(int $invoiceId, string $schoolYear): int
|
||||
{
|
||||
$invoice = Invoice::query()->find($invoiceId);
|
||||
if (! $invoice) {
|
||||
if (!$invoice) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$total = (float) ($invoice->total_amount ?? 0);
|
||||
$balance = (float) ($invoice->balance ?? 0);
|
||||
if (! ($total > 0 && $balance < $total)) {
|
||||
if (!($total > 0 && $balance < $total)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -281,7 +281,7 @@ class DiscountInvoiceService
|
||||
->orWhereRaw("LOWER(TRIM(REPLACE(enrollment_status, CHAR(160), ' '))) = 'payment pending'");
|
||||
});
|
||||
|
||||
if (! empty($paidEnrollmentIds)) {
|
||||
if (!empty($paidEnrollmentIds)) {
|
||||
$query->whereIn('id', array_values(array_unique($paidEnrollmentIds)));
|
||||
}
|
||||
|
||||
@@ -314,7 +314,7 @@ class DiscountInvoiceService
|
||||
string $semester
|
||||
): array {
|
||||
$invoice = Invoice::query()->find($invoiceId);
|
||||
if (! $invoice) {
|
||||
if (!$invoice) {
|
||||
throw new \RuntimeException("Invoice {$invoiceId} not found");
|
||||
}
|
||||
|
||||
@@ -380,7 +380,6 @@ class DiscountInvoiceService
|
||||
|
||||
if (preg_match('/^Y(?:OUTH)?\\s*(\\d+)?$/', $g, $m)) {
|
||||
$n = isset($m[1]) && $m[1] !== '' ? max(1, (int) $m[1]) : 1;
|
||||
|
||||
return $gradeFee + $n;
|
||||
}
|
||||
|
||||
@@ -396,7 +395,6 @@ class DiscountInvoiceService
|
||||
if (function_exists('local_date') && function_exists('utc_now')) {
|
||||
return (string) local_date(utc_now(), $format);
|
||||
}
|
||||
|
||||
return now()->format($format);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,6 @@ class DiscountVoucherService
|
||||
$voucher = DiscountVoucher::query()->findOrFail($id);
|
||||
$voucher->fill($payload);
|
||||
$voucher->save();
|
||||
|
||||
return $voucher;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user