fix financials
Tests / PHPUnit (push) Failing after 1m21s

This commit is contained in:
root
2026-07-18 22:57:40 -04:00
parent 068e739408
commit a30c1398a1
61 changed files with 10908 additions and 1775 deletions
+8 -2
View File
@@ -25,6 +25,12 @@ class AdditionalChargeModel extends Model
'amount',
'due_date',
'status',
'applied_invoice_line_id',
'applied_by',
'applied_at',
'voided_by',
'voided_at',
'void_reason',
'created_by',
];
@@ -36,9 +42,9 @@ class AdditionalChargeModel extends Model
'charge_type' => 'required|in_list[add,deduct]',
'title' => 'required|string|min_length[2]|max_length[255]',
'description' => 'permit_empty|string',
'amount' => 'required|decimal',
'amount' => 'required|decimal|greater_than_equal_to[0]',
'due_date' => 'permit_empty|valid_date',
'status' => 'required|in_list[pending,applied,voided]',
'status' => 'required|in_list[pending,approved,applied,rejected,voided,reversed]',
'created_by' => 'permit_empty|integer',
];
+11 -2
View File
@@ -16,10 +16,16 @@ class DiscountUsageModel extends Model
'voucher_id',
'invoice_id',
'discount_amount',
'requested_discount_cents',
'eligible_base_cents',
'eligible_base_before_cents',
'applied_discount_cents',
'application_order',
'school_year',
'semester',
'updated_by',
'parent_id',
'description',
'used_at'
];
@@ -50,8 +56,12 @@ class DiscountUsageModel extends Model
{
$db = \Config\Database::connect();
$amountExpression = $db->fieldExists('applied_discount_cents', 'discount_usages')
? 'COALESCE(SUM(du.applied_discount_cents),0) / 100'
: 'COALESCE(SUM(du.discount_amount),0)';
$result = $db->table('discount_usages du')
->selectSum('du.discount_amount', 'total_discount')
->select($amountExpression . ' AS total_discount', false)
->join('invoices i', 'du.invoice_id = i.id')
->where('i.parent_id', $parentId)
->where('i.school_year', $schoolYear)
@@ -62,4 +72,3 @@ class DiscountUsageModel extends Model
}
}
+41
View File
@@ -0,0 +1,41 @@
<?php
namespace App\Models;
use CodeIgniter\Model;
class InvoiceLineModel extends Model
{
protected $table = 'invoice_lines';
protected $primaryKey = 'id';
protected $returnType = 'array';
protected $useTimestamps = false;
protected $allowedFields = [
'invoice_id',
'line_type',
'source_type',
'source_id',
'active_source_key',
'description',
'quantity',
'unit_amount_cents',
'line_amount_cents',
'discount_eligible',
'calculation_version',
'metadata_json',
'created_at',
'updated_at',
'voided_at',
];
protected $validationRules = [
'invoice_id' => 'required|integer',
'line_type' => 'required|max_length[50]',
'description' => 'required|max_length[255]',
'quantity' => 'required|decimal',
'unit_amount_cents' => 'required|integer',
'line_amount_cents' => 'required|integer',
'discount_eligible' => 'required|in_list[0,1]',
];
}
+27
View File
@@ -0,0 +1,27 @@
<?php
namespace App\Models;
use CodeIgniter\Model;
class PaymentCorrectionModel extends Model
{
protected $table = 'payment_corrections';
protected $primaryKey = 'id';
protected $returnType = 'array';
protected $useTimestamps = false;
protected $allowedFields = [
'payment_id',
'invoice_id',
'parent_id',
'correction_type',
'approved_refundable_cents',
'status',
'reason',
'approved_by',
'approved_at',
'created_at',
'updated_at',
];
}
+8 -2
View File
@@ -35,7 +35,10 @@ class PaymentModel extends Model
'installment_seq',
'transaction_id',
'idempotency_key',
'request_fingerprint_hash',
'check_file',
'evidence_status',
'evidence_failure_message',
'check_number',
'payment_method',
'payment_date',
@@ -76,7 +79,8 @@ class PaymentModel extends Model
'installment_seq' => 'permit_empty|integer|greater_than[0]',
'transaction_id' => 'required|max_length[100]',
'idempotency_key' => 'permit_empty|max_length[36]',
'idempotency_key' => 'permit_empty|max_length[100]',
'request_fingerprint_hash' => 'permit_empty|exact_length[64]',
'payment_method' => 'required|in_list[cash,check,card]',
'payment_date' => 'required|valid_date',
'school_year' => 'required|string|max_length[9]',
@@ -87,6 +91,8 @@ class PaymentModel extends Model
'voided_by' => 'permit_empty|integer',
'void_reason' => 'permit_empty|max_length[255]',
'check_file' => 'permit_empty|max_length[255]',
'evidence_status' => 'permit_empty|max_length[30]',
'evidence_failure_message' => 'permit_empty|max_length[255]',
'check_number' => 'permit_empty|max_length[100]',
'updated_by' => 'permit_empty|integer',
];
@@ -145,7 +151,7 @@ class PaymentModel extends Model
'greater_than' => 'Installment sequence must be greater than zero.',
],
'idempotency_key' => [
'max_length' => 'Idempotency key must not exceed 36 characters.',
'max_length' => 'Idempotency key must not exceed 100 characters.',
],
'check_number' => [
'max_length' => 'Check number must not exceed 100 characters.',
+2 -1
View File
@@ -15,6 +15,7 @@ class PurchaseOrderItemModel extends Model
'purchase_order_id' => 'required|is_natural_no_zero',
'supply_id' => 'required|is_natural_no_zero',
'quantity' => 'required|is_natural_no_zero',
'unit_cost' => 'required|decimal',
'received_qty' => 'if_exist|integer|greater_than_equal_to[0]',
'unit_cost' => 'required|decimal|greater_than_equal_to[0]',
];
}
+8
View File
@@ -17,6 +17,12 @@ class RefundModel extends Model
'school_year',
'invoice_id',
'refund_amount',
'requested_amount_cents',
'approved_amount_cents',
'reconciliation_status',
'reconciliation_reason',
'reconciliation_required_at',
'currency',
'requested_at',
'approved_at',
'refunded_at',
@@ -24,6 +30,8 @@ class RefundModel extends Model
'reason',
'refund_paid_amount',
'request',
'source_type',
'source_id',
'note',
'semester',
'school_year',
+47
View File
@@ -0,0 +1,47 @@
<?php
namespace App\Models;
use CodeIgniter\Model;
class RefundPayoutModel extends Model
{
protected $table = 'refund_payouts';
protected $primaryKey = 'id';
protected $returnType = 'array';
protected $useTimestamps = false;
protected $allowedFields = [
'refund_id',
'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',
'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]',
];
}
+5 -1
View File
@@ -4,6 +4,7 @@ namespace App\Models;
use CodeIgniter\Model;
use App\Models\Concerns\SchoolYearAutoFillTrait;
use App\Libraries\FinancialStatus;
class ReimbursementModel extends Model
{
@@ -24,10 +25,13 @@ class ReimbursementModel extends Model
'semester',
'check_number',
'reimbursement_method',
'batch_number'
'batch_number',
'updated_by',
];
protected $validationRules = [
'school_year' => 'required|string|max_length[9]',
'amount' => 'if_exist|decimal|greater_than[0]',
'status' => 'if_exist|in_list[' . FinancialStatus::REIMBURSEMENT_PENDING . ',' . FinancialStatus::REIMBURSEMENT_APPROVED . ',' . FinancialStatus::REIMBURSEMENT_PAID . ',' . FinancialStatus::REIMBURSEMENT_REJECTED . ',' . FinancialStatus::REIMBURSEMENT_REVERSED . ',Pending,Approved,Paid,Rejected,Reversed]',
];