Files
alrahma_sunday_school/app/Models/PaymentNotificationLogModel.php
T
root 716cc8b8d3
Tests / PHPUnit (push) Failing after 1m20s
fix school year for all tables
2026-07-18 14:45:38 -04:00

67 lines
1.6 KiB
PHP

<?php
namespace App\Models;
use CodeIgniter\Model;
use App\Models\Concerns\SchoolYearAutoFillTrait;
class PaymentNotificationLogModel extends Model
{
use SchoolYearAutoFillTrait;
protected $table = 'payment_notification_logs';
protected $primaryKey = 'id';
protected $returnType = 'array';
protected $useSoftDeletes = false;
protected $allowedFields = [
'parent_id',
'invoice_id',
'school_year',
'period_year',
'period_month',
'type',
'to_email',
'cc_email',
'head_fa_notified',
'subject',
'body',
'status',
'error_message',
'balance_snapshot',
'created_at',
'sent_at',
];
protected $validationRules = [
'school_year' => 'required|string|max_length[9]',
];
protected $useTimestamps = false;
public function existsForPeriod(int $parentId, int $year, int $month, string $type): bool
{
return $this->where('parent_id', $parentId)
->where('period_year', $year)
->where('period_month', $month)
->where('type', $type)
->first() !== null;
}
public function listLogs(?string $from = null, ?string $to = null, ?string $type = null): array
{
$builder = $this->orderBy('sent_at', 'DESC');
if ($from) {
$builder->where('sent_at >=', $from);
}
if ($to) {
$builder->where('sent_at <=', $to);
}
if ($type) {
$builder->where('type', $type);
}
return $builder->findAll();
}
}