Fix Pint formatting

This commit is contained in:
root
2026-06-09 01:25:14 -04:00
parent 6be4875c5e
commit 20a0b6c4e5
1485 changed files with 11318 additions and 10273 deletions
+22 -11
View File
@@ -7,31 +7,33 @@ use App\Models\InvoiceInstallmentPlan;
use App\Models\PaymentInstallmentAllocation;
use Carbon\Carbon;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
class InstallmentPlanService
{
public function list(array $filters): array
{
$q = InvoiceInstallmentPlan::query();
foreach (['invoice_id','parent_id','school_year','status'] as $field) {
if (!empty($filters[$field])) $q->where($field, $filters[$field]);
foreach (['invoice_id', 'parent_id', 'school_year', 'status'] as $field) {
if (! empty($filters[$field])) {
$q->where($field, $filters[$field]);
}
}
return ['rows' => $q->orderByDesc('id')->paginate((int)($filters['per_page'] ?? 25))];
return ['rows' => $q->orderByDesc('id')->paginate((int) ($filters['per_page'] ?? 25))];
}
public function createForInvoice(int $invoiceId, array $payload, ?int $actorId): array
{
return DB::transaction(function () use ($invoiceId, $payload, $actorId) {
$invoice = DB::table('invoices')->where('id', $invoiceId)->first();
abort_if(!$invoice, 404, 'Invoice not found.');
abort_if(! $invoice, 404, 'Invoice not found.');
$total = (float) ($payload['total_amount'] ?? ($invoice->balance ?? $invoice->total_amount ?? 0));
$count = (int) $payload['number_of_installments'];
$plan = InvoiceInstallmentPlan::query()->create([
'invoice_id' => $invoiceId,
'parent_id' => $invoice->parent_id,
'school_year' => $invoice->school_year ?? null,
'plan_name' => $payload['plan_name'] ?? ('Invoice #' . $invoiceId . ' installment plan'),
'plan_name' => $payload['plan_name'] ?? ('Invoice #'.$invoiceId.' installment plan'),
'total_amount' => $total,
'number_of_installments' => $count,
'status' => 'draft',
@@ -65,6 +67,7 @@ class InstallmentPlanService
{
$plan = InvoiceInstallmentPlan::query()->findOrFail($id)->toArray();
$plan['installments'] = InvoiceInstallment::query()->where('installment_plan_id', $id)->orderBy('sequence')->get()->toArray();
return $plan;
}
@@ -73,6 +76,7 @@ class InstallmentPlanService
$plan = InvoiceInstallmentPlan::query()->findOrFail($id);
$plan->fill(['status' => 'active', 'approved_by' => $actorId])->save();
InvoiceInstallment::query()->where('installment_plan_id', $id)->where('status', 'pending')->update(['status' => 'due']);
return $this->show($id);
}
@@ -80,6 +84,7 @@ class InstallmentPlanService
{
InvoiceInstallmentPlan::query()->whereKey($id)->update(['status' => 'cancelled']);
InvoiceInstallment::query()->where('installment_plan_id', $id)->whereNotIn('status', ['paid'])->update(['status' => 'cancelled']);
return $this->show($id);
}
@@ -87,14 +92,16 @@ class InstallmentPlanService
{
return DB::transaction(function () use ($paymentId, $payload) {
$payment = DB::table('payments')->where('id', $paymentId)->first();
abort_if(!$payment, 404, 'Payment not found.');
abort_if(! $payment, 404, 'Payment not found.');
$allocations = $payload['installments'] ?? null;
if (!$allocations) {
if (! $allocations) {
$remaining = (float) ($payment->paid_amount ?? 0);
$installments = InvoiceInstallment::query()->where('invoice_id', $payment->invoice_id)->where('balance', '>', 0)->orderBy('due_date')->lockForUpdate()->get();
$allocations = [];
foreach ($installments as $inst) {
if ($remaining <= 0) break;
if ($remaining <= 0) {
break;
}
$amount = min($remaining, (float) $inst->balance);
$allocations[] = ['installment_id' => $inst->id, 'amount' => $amount];
$remaining -= $amount;
@@ -105,7 +112,9 @@ class InstallmentPlanService
foreach ($allocations as $a) {
$inst = InvoiceInstallment::query()->lockForUpdate()->findOrFail($a['installment_id']);
$amount = min((float) $a['amount'], (float) $inst->balance);
if ($amount <= 0) continue;
if ($amount <= 0) {
continue;
}
$created[] = PaymentInstallmentAllocation::query()->create([
'payment_id' => $paymentId,
'invoice_id' => $inst->invoice_id,
@@ -118,6 +127,7 @@ class InstallmentPlanService
$inst->paid_at = $inst->balance <= 0 ? now() : null;
$inst->save();
}
return ['allocations' => $created];
});
}
@@ -126,11 +136,12 @@ class InstallmentPlanService
{
$q = InvoiceInstallment::query()->where('balance', '>', 0);
$overdue ? $q->whereDate('due_date', '<', now()->toDateString()) : $q->whereDate('due_date', '>=', now()->toDateString());
return ['rows' => $q->orderBy('due_date')->get()->toArray()];
}
public function markOverdue(): int
{
return InvoiceInstallment::query()->where('balance', '>', 0)->whereDate('due_date', '<', now()->toDateString())->whereNotIn('status', ['paid','cancelled','waived'])->update(['status' => 'overdue']);
return InvoiceInstallment::query()->where('balance', '>', 0)->whereDate('due_date', '<', now()->toDateString())->whereNotIn('status', ['paid', 'cancelled', 'waived'])->update(['status' => 'overdue']);
}
}