0ac3a8375e
- load global semester helpers consistently and use date-based semester defaults - fix grading and daily attendance duplicate student/section rows - keep attendance violations scoped to the current semester by default - update invoice, refund, discount, payment, and financial aid flows - add configuration cleanup migrations for duplicate calendar/semester keys - refresh parent registration/report-card and print request handling - update related models, services, views, cron notes, and test coverage
88 lines
2.6 KiB
PHP
88 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use CodeIgniter\Database\ConnectionInterface;
|
|
use CodeIgniter\Model;
|
|
use App\Models\Concerns\SchoolYearAutoFillTrait;
|
|
use CodeIgniter\Validation\ValidationInterface;
|
|
|
|
class RefundPayoutModel extends Model
|
|
{
|
|
use SchoolYearAutoFillTrait;
|
|
|
|
protected $table = 'refund_payouts';
|
|
protected $primaryKey = 'id';
|
|
protected $returnType = 'array';
|
|
protected $useTimestamps = false;
|
|
|
|
protected $allowedFields = [
|
|
'refund_id',
|
|
'school_year',
|
|
'amount_cents',
|
|
'currency',
|
|
'payout_type',
|
|
'payment_method',
|
|
'status',
|
|
'external_reference',
|
|
'check_number',
|
|
'check_date',
|
|
'evidence_path',
|
|
'idempotency_key',
|
|
'operation_type',
|
|
'request_fingerprint_hash',
|
|
'processed_by',
|
|
'processed_at',
|
|
'reversed_payout_id',
|
|
'failure_code',
|
|
'failure_message',
|
|
'created_at',
|
|
'updated_at',
|
|
];
|
|
|
|
protected $validationRules = [
|
|
'refund_id' => 'required|integer',
|
|
'school_year' => 'required|string|max_length[9]',
|
|
'amount_cents' => 'required|integer|greater_than[0]',
|
|
'currency' => 'required|exact_length[3]',
|
|
'payout_type' => 'required|in_list[cash_out,account_credit,reversal]',
|
|
'status' => 'required|max_length[30]',
|
|
'idempotency_key' => 'required|max_length[100]',
|
|
'operation_type' => 'permit_empty|max_length[50]',
|
|
'request_fingerprint_hash' => 'permit_empty|exact_length[64]',
|
|
];
|
|
|
|
private array $refundPayoutColumns = [];
|
|
|
|
public function __construct(?ConnectionInterface $db = null, ?ValidationInterface $validation = null)
|
|
{
|
|
parent::__construct($db, $validation);
|
|
|
|
$this->refundPayoutColumns = $this->getTableColumns($this->table);
|
|
$this->allowedFields = array_values(array_filter(
|
|
$this->allowedFields,
|
|
fn (string $field): bool => in_array($field, $this->refundPayoutColumns, true)
|
|
));
|
|
|
|
foreach (array_keys($this->validationRules) as $field) {
|
|
if (!in_array($field, $this->allowedFields, true)) {
|
|
unset($this->validationRules[$field]);
|
|
}
|
|
}
|
|
}
|
|
|
|
private function getTableColumns(string $table): array
|
|
{
|
|
try {
|
|
return $this->db->getFieldNames($table);
|
|
} catch (\Throwable $e) {
|
|
log_message('error', '[RefundPayoutModel] Could not read table columns for {table}: {error}', [
|
|
'table' => $table,
|
|
'error' => $e->getMessage(),
|
|
]);
|
|
|
|
return [];
|
|
}
|
|
}
|
|
}
|