money.materialized_billable_xact_summary
|
Data-Modifying Triggers: This table has BEFORE ROW trigger(s) that modify row data before write. Values you INSERT or UPDATE may differ from what is actually stored. See the Triggers section below. |
|
Written by External Triggers: This table can receive writes triggered by operations on other tables:
|
Columns
| Column | Type | Nullable | Default | Notes |
|---|---|---|---|---|
id PK |
|
No |
||
usr |
|
Yes |
||
xact_start |
|
Yes |
||
xact_finish |
|
Yes |
||
total_paid |
|
Yes |
||
last_payment_ts |
|
Yes |
||
last_payment_note |
|
Yes |
||
last_payment_type |
|
Yes |
||
total_owed |
|
Yes |
||
last_billing_ts |
|
Yes |
||
last_billing_note |
|
Yes |
||
last_billing_type |
|
Yes |
||
balance_owed |
|
Yes |
||
xact_type |
|
Yes |
Indexes
| Index | Method | Definition |
|---|---|---|
|
btree |
|
|
btree |
|
|
btree |
|
Triggers
| Trigger | Timing | Event | Level | Function |
|---|---|---|---|---|
|
BEFORE |
UPDATE |
ROW |
Trigger Bodies
mat_summary_refund_balance_check_tgr
Function: money.mbts_refundable_balance_check()
Timing: BEFORE UPDATE ROW
|
This trigger modifies the row before it is written (returns a modified |
BEGIN
-- Check if the raw xact balance has gone negative (balance_owed may be adjusted by this very trigger!)
IF NEW.total_owed - NEW.total_paid < 0.0 THEN
-- If negative (a refund), we increase it by the non-refundable payment total, but only up to 0.0
SELECT LEAST(
COALESCE(SUM(amount),0.0) -- non-refundable payment total
+ (NEW.total_owed - NEW.total_paid), -- raw balance
0.0
) INTO NEW.balance_owed -- update the NEW record
FROM money.payment_view
WHERE NOT refundable
AND xact = NEW.id
AND NOT voided;
END IF;
RETURN NEW;
END;