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
+25 -22
View File
@@ -2,7 +2,6 @@
namespace App\Models;
use App\Models\BaseModel;
use Illuminate\Support\Facades\DB;
class Payment extends BaseModel
@@ -34,16 +33,16 @@ class Payment extends BaseModel
];
protected $casts = [
'parent_id' => 'integer',
'invoice_id' => 'integer',
'number_of_installments' => 'integer',
'updated_by' => 'integer',
'parent_id' => 'integer',
'invoice_id' => 'integer',
'number_of_installments' => 'integer',
'updated_by' => 'integer',
'total_amount' => 'decimal:2',
'paid_amount' => 'decimal:2',
'balance' => 'decimal:2',
'total_amount' => 'decimal:2',
'paid_amount' => 'decimal:2',
'balance' => 'decimal:2',
'payment_date' => 'datetime',
'payment_date' => 'datetime',
];
/* Optional relationships */
@@ -84,18 +83,20 @@ class Payment extends BaseModel
{
/** @var self|null $payment */
$payment = static::query()->find($paymentId);
if (!$payment) return false;
if (! $payment) {
return false;
}
$newBalance = (float)$payment->balance - (float)$amountPaid;
$newBalance = (float) $payment->balance - (float) $amountPaid;
// keep precision stable
$paidAmount = (float)$payment->paid_amount + (float)$amountPaid;
$paidAmount = (float) $payment->paid_amount + (float) $amountPaid;
$affected = static::query()
->whereKey($paymentId)
->update([
'paid_amount' => $paidAmount,
'balance' => $newBalance,
'balance' => $newBalance,
]);
return $affected > 0;
@@ -116,21 +117,21 @@ class Payment extends BaseModel
public static function generateNewTransactionId(): string
{
$currentYear = date('Y');
$prefix = $currentYear . '-';
$prefix = $currentYear.'-';
$latest = static::query()
->where('transaction_id', 'like', $prefix . '%')
->where('transaction_id', 'like', $prefix.'%')
->orderByDesc('transaction_id')
->first();
if ($latest && !empty($latest->transaction_id)) {
$lastNumber = (int) str_replace($prefix, '', (string)$latest->transaction_id);
if ($latest && ! empty($latest->transaction_id)) {
$lastNumber = (int) str_replace($prefix, '', (string) $latest->transaction_id);
$newNumber = $lastNumber + 1;
} else {
$newNumber = 1;
}
return $prefix . str_pad((string)$newNumber, 6, '0', STR_PAD_LEFT);
return $prefix.str_pad((string) $newNumber, 6, '0', STR_PAD_LEFT);
}
/**
@@ -139,11 +140,13 @@ class Payment extends BaseModel
*/
public static function getPaymentsByInvoice($invoiceIds): array
{
if (!is_array($invoiceIds)) {
if (! is_array($invoiceIds)) {
$invoiceIds = [$invoiceIds];
}
$invoiceIds = array_values(array_unique(array_map('intval', array_filter($invoiceIds))));
if (empty($invoiceIds)) return [];
if (empty($invoiceIds)) {
return [];
}
// Subquery: latest payment_date per invoice (Full/Partial only)
$latestSub = DB::table('payments')
@@ -155,7 +158,7 @@ class Payment extends BaseModel
$rows = DB::table('payments as p')
->joinSub($latestSub, 'latest', function ($join) {
$join->on('latest.invoice_id', '=', 'p.invoice_id')
->on('latest.max_date', '=', 'p.payment_date');
->on('latest.max_date', '=', 'p.payment_date');
})
->whereIn('p.invoice_id', $invoiceIds)
->whereIn('p.status', ['Full', 'Paid', 'Partially Paid'])
@@ -169,4 +172,4 @@ class Payment extends BaseModel
return $rows->map(fn ($r) => (array) $r)->all();
}
}
}