Giao diện
payment / cod
Trang sinh tự động
Sinh từ ad83b0aea — chạy 820 migration lên PostgreSQL 17 rồi đọc pg_catalog. Mô tả bảng và cột lấy từ COMMENT ON. Không sửa tay: lần chạy docgen sau sẽ ghi đè.
5 bảng. Quay lại payment.
cod_collections
P3-06. One row per COD REMAINING obligation: DUE -> ASSIGNED -> DELIVERED -> COLLECTED -> REMITTED with set-once collection evidence; COLLECTED = delivered AND collected in full, never remitted by itself.
public.cod_collections · 28 cột · 12 check · 2 unique · 6 index · 1 policy · 5 trigger · RLS bật
| Cột | Kiểu | Khoá | Mô tả | |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
obligation_id | uuid | NOT NULL | FK → payment_obligations | |
order_id | uuid | NOT NULL | FK → orders | |
order_cycle_id | uuid | FK → order_cycles | ||
amount_due_vnd | bigint | NOT NULL | ||
status | text | NOT NULL | ||
shipment_id | uuid | FK → shipments | ||
collector_carrier_code | text | |||
assigned_at | timestamptz | |||
delivered_at | timestamptz | |||
collected_amount_vnd | bigint | |||
collected_at | timestamptz | |||
collector_type | text | |||
collector_ref | text | |||
collected_by | uuid | FK → accounts | ||
collection_evidence_ref | text | |||
collection_proof_media_id | uuid | FK → media | ||
collection_source_id | text | |||
collection_payload_hash | text | |||
collection_recorded_at | timestamptz | |||
completed_at | timestamptz | |||
change_source | text | NOT NULL | ||
change_source_id | text | NOT NULL | ||
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL | ||
version | integer | NOT NULL | ||
actor_label | text | |||
actor_roles | text[] |
Khoá chính: id
Trỏ ra (6):
collected_by→accounts·ON DELETE RESTRICTcollection_proof_media_id→media·ON DELETE RESTRICTobligation_id→payment_obligations·ON DELETE RESTRICTorder_cycle_id→order_cycles·ON DELETE RESTRICTorder_id→orders·ON DELETE RESTRICTshipment_id→shipments·ON DELETE RESTRICT
Được trỏ tới (3): cod_reconciliation_items, cod_remittances, order_return_cases
cod_reconciliation_runs
P3-14. One row per VN business date and rerun; immutable after COMPLETE/INCOMPLETE. Evidence and totals only: no tolerance, no COD/obligation/ledger write; collected is never remitted.
public.cod_reconciliation_runs · 20 cột · 11 check · 1 unique · 3 index · 4 policy · 4 trigger · RLS bật
| Cột | Kiểu | Khoá | Mô tả | |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
run_date_vn | date | NOT NULL | ||
run_version | integer | NOT NULL | ||
timezone | text | NOT NULL | ||
window_start | timestamptz | NOT NULL | ||
window_end | timestamptz | NOT NULL | ||
trigger_kind | text | NOT NULL | ||
requested_by | uuid | FK → accounts | ||
status | text | NOT NULL | ||
started_at | timestamptz | NOT NULL | ||
finished_at | timestamptz | |||
dataset_hash | bytea | |||
totals | jsonb | |||
error_code | text | |||
lease_owner | text | |||
lease_expires_at | timestamptz | |||
correlation_id | correlation_ref | NOT NULL | ||
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL | ||
version | integer | NOT NULL |
Khoá chính: id
Trỏ ra (1):
requested_by→accounts·ON DELETE RESTRICT
Được trỏ tới (2): cod_reconciliation_items, cod_remittance_gaps
cod_reconciliation_items
P3-14. One COD discrepancy of a run (the five sow/03 s12 types); evidence immutable, handling columns follow OPEN -> IN_PROGRESS -> RESOLVED (no handling command yet, GAP-102). Never edits COD/obligation/shipment rows.
public.cod_reconciliation_items · 21 cột · 11 check · 1 unique · 4 index · 3 policy · 5 trigger · RLS bật
| Cột | Kiểu | Khoá | Mô tả | |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
run_id | uuid | NOT NULL | FK → cod_reconciliation_runs | |
discrepancy_type | text | NOT NULL | ||
item_key | text | NOT NULL | ||
collection_id | uuid | NOT NULL | FK → cod_collections | |
shipment_id | uuid | FK → shipments | ||
local_status | text | NOT NULL | ||
carrier_status | text | |||
local_amount_vnd | bigint | |||
remote_amount_vnd | bigint | |||
evidence | jsonb | NOT NULL | ||
status | text | NOT NULL | ||
owner_account_id | uuid | FK → accounts | ||
note | text | |||
resolved_by | uuid | FK → accounts | ||
resolved_at | timestamptz | |||
resolution_note | text | |||
correlation_id | correlation_ref | NOT NULL | ||
created_at | timestamptz | NOT NULL | ||
updated_at | timestamptz | NOT NULL | ||
version | integer | NOT NULL |
Khoá chính: id
Trỏ ra (5):
collection_id→cod_collections·ON DELETE RESTRICTowner_account_id→accounts·ON DELETE RESTRICTresolved_by→accounts·ON DELETE RESTRICTrun_id→cod_reconciliation_runs·ON DELETE RESTRICTshipment_id→shipments·ON DELETE RESTRICT
Được trỏ tới: không có
cod_remittance_gaps
P3-14. Delivered / collected / remitted / awaiting-remittance counts and VND per carrier, collector and VN date of one run, as of its window end. Collected is not remitted; no overdue flag (no deadline sourced, GAP-78).
public.cod_remittance_gaps · 15 cột · 4 check · 1 unique · 3 index · 3 policy · 3 trigger · RLS bật
| Cột | Kiểu | Khoá | Mô tả | |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
run_id | uuid | NOT NULL | FK → cod_reconciliation_runs | |
carrier_code | text | NOT NULL | ||
collector_type | text | NOT NULL | ||
collector_ref | text | NOT NULL | ||
event_date_vn | date | NOT NULL | ||
delivered_not_collected_count | integer | NOT NULL | ||
delivered_not_collected_vnd | bigint | NOT NULL | ||
collected_count | integer | NOT NULL | ||
collected_vnd | bigint | NOT NULL | ||
remitted_count | integer | NOT NULL | ||
remitted_vnd | bigint | NOT NULL | ||
awaiting_remittance_count | integer | NOT NULL | ||
awaiting_remittance_vnd | bigint | NOT NULL | ||
created_at | timestamptz | NOT NULL |
Khoá chính: id
Trỏ ra (1):
run_id→cod_reconciliation_runs·ON DELETE RESTRICT
Được trỏ tới: không có
cod_remittances
P3-06. Append-only remittance evidence of one COLLECTED COD row (who/when/amount/reference/document); separate from collection; no funds/cashbook/settlement effect.
public.cod_remittances · 10 cột · 3 check · 3 unique · 5 index · 1 policy · 3 trigger · RLS bật
| Cột | Kiểu | Khoá | Mô tả | |
|---|---|---|---|---|
id | uuid | NOT NULL | PK | |
collection_id | uuid | NOT NULL | FK → cod_collections | |
remittance_ref | text | NOT NULL | ||
amount_vnd | bigint | NOT NULL | ||
remitted_at | timestamptz | NOT NULL | ||
recorded_by | uuid | NOT NULL | FK → accounts | |
proof_media_id | uuid | FK → media | ||
note | text | |||
source_id | text | NOT NULL | ||
created_at | timestamptz | NOT NULL |
Khoá chính: id
Trỏ ra (3):
collection_id→cod_collections·ON DELETE RESTRICTproof_media_id→media·ON DELETE RESTRICTrecorded_by→accounts·ON DELETE RESTRICT
Được trỏ tới: không có