SPEC-ERD-CEC Rev 0.4.1 · 2026-08-03

Cane Agency · ERD Seriesสถาบันอ้อย · ชุดเอกสาร ERD

Data Model — Contractor (ผู้รับเหมา) Perspectivemodel ข้อมูล — มุมมองผู้รับเหมา

Documentเอกสาร
SPEC-ERD-CEC
Versionversion (เวอร์ชัน)
0.4.1 · Draftฉบับร่าง
Updatedปรับปรุงล่าสุด
2026-08-03
Parentเอกสารแม่
SPEC-ERD
Source of truthแหล่งความจริง
docs/graph/spec-graph.json v5.0

1. Perspective & authority1. มุมมองและอำนาจ

The contractor perspective owns twelve entities across four contexts — service_marketplace (ServiceOffering, ServiceRequest, ServiceQuote, ServicePayment), work_dispatch (Contractor, WorkOrder, WorkAssignment, Machine), reputation (Review, Endorsement) and books (LedgerAccount, JournalEntry) — and shares (reads under the owner's rules): Tenant, User, Farmer, Mill, Field, Crop, Season, Quota, Truck, FarmActivity, CreditLine, CreditItem, PaymentItem, ConsentGrant, CreditAssessment. One owner per entity; this document is the deep reference for its owned set and a view of the rest. Since v9.0 (PROP-010) books extends into a full financial system: the contractor additionally shares ChartTemplate, Invoice, Receipt, PaymentVoucher, CashAccount, BankTransaction, Reconciliation, FiscalPeriod, FinancialStatement and (v12.0, PROP-011) BooksProfile (owned under the mill reference; default unified edition, upgradeable to split via the books_split entitlement) and joins the receivables and cash_management contexts (WF-36 · WF-40); its P&L already auto-posts from verified work and service payments.

มุมมองผู้รับเหมาเป็นเจ้าของ entity สิบสองตัวในสี่บริบท — service_marketplace (ServiceOffering, ServiceRequest, ServiceQuote, ServicePayment), work_dispatch (Contractor, WorkOrder, WorkAssignment, Machine), reputation (Review, Endorsement) และ books (LedgerAccount, JournalEntry) — และใช้ร่วม (อ่านตามกฎของเจ้าของ): Tenant, User, Farmer, Mill, Field, Crop, Season, Quota, Truck, FarmActivity, CreditLine, CreditItem, PaymentItem, ConsentGrant, CreditAssessment หนึ่งเจ้าของต่อหนึ่ง entity; เอกสารนี้คืออ้างอิงเชิงลึกของชุดที่เป็นเจ้าของ และเป็นมุมมองของส่วนที่เหลือ ตั้งแต่ v9.0 (PROP-010) books ขยายเป็นระบบการเงินเต็ม: ผู้รับเหมาใช้ร่วม ChartTemplate, Invoice, Receipt, PaymentVoucher, CashAccount, BankTransaction, Reconciliation, FiscalPeriod, FinancialStatement และ (v12.0, PROP-011) BooksProfile (เป็นเจ้าของภายใต้มุมมองโรงงาน; ตั้งต้นรุ่น unified อัปเกรดเป็น split ผ่านสิทธิ์ books_split) และเข้าร่วมบริบท receivables และ cash_management (WF-36 · WF-40); งบกำไรขาดทุนของผู้รับเหมาลงอัตโนมัติจากงานที่ตรวจรับและค่าบริการอยู่แล้ว

2. Owned entities — catalogue2. Entity ที่เป็นเจ้าของ — บัญชีรายการ

Entity · codeEntity · รหัสAttributesแอตทริบิวต์Rules (normative in the graph)กฎ (บรรทัดฐานอยู่ใน graph (กราฟ))
Contractor
ผู้รับเหมา
CEC-#####
contractor_id, kind, tenant_id?, user_id?, name, base_province, service_area, phone, verified_status, rating_avg, rating_count, jobs_completed, member_sincekind: freelance | organization — exactly one of user_id/tenant_id set; upgrade keeps the record. Cached aggregates recomputed from Review, never edited. verified_status: unverified | id_verified | endorsed.kind: freelance | organization — กำหนด user_id/tenant_id อย่างใดอย่างหนึ่ง; อัปเกรดคงเรกคอร์ด ค่าสรุปแคชคำนวณใหม่จาก Review ห้ามแก้ตรง verified_status: unverified | id_verified | endorsed
ServiceOffering
รายการบริการ
SVO-######
offering_id, contractor_id, service_type, custom_label?, unit, price_min, price_max, service_area, season_window?, capacity_note?, status13-value service taxonomy (+other with custom_label); unit: per_rai | per_ton | per_km | per_day | per_job; the listed price is a public range — the binding price lives on the quote/work order.อนุกรมวิธาน 13 ค่า (+other พร้อม custom_label); unit: per_rai | per_ton | per_km | per_day | per_job; ราคาประกาศเป็นช่วงสาธารณะ — ราคาผูกพันอยู่บนใบเสนอราคา/ใบสั่งงาน
ServiceRequest
คำขอบริการ
SRQ-########
request_id, requester_tenant_type, requester_tenant_id, service_type, matching_mode, field_id?, crop_id?, quantity, unit, window_start, window_end, budget_max?, note?, status, awarded_quote_id?matching_mode: rfq | direct | broadcast — broadcast powers instant dispatch (จองด่วน). Anchoring to field/crop is what later verifies the work. status: open | quoted | awarded | expired | cancelled.matching_mode: rfq | direct | broadcast — broadcast ขับจองด่วน การยึดแปลง/อ้อยคือสิ่งที่ใช้ตรวจยืนยันงาน status: open | quoted | awarded | expired | cancelled
ServiceQuote
ใบเสนอราคา
SQT-########
quote_id, request_id, contractor_id, price, unit, terms?, valid_until, statusOne accepted quote per request; acceptance creates the WorkOrder atomically.คำขอหนึ่งมีใบเสนอราคาที่ตอบรับได้ใบเดียว; การตอบรับสร้าง WorkOrder แบบ atomic
WorkOrder
ใบสั่งงาน
WKO-25##-######
work_order_id, request_id, quote_id, contractor_id, requester_tenant_type, requester_tenant_id, service_type, field_id?, crop_id?, quantity, unit, agreed_price, payment_method, window_start, window_end, status, completed_at?, verified_by?, dispute_note?The contract of record; status runs the work-order state machine (SPEC-PWF-CEC Section 8). Escrow gate before scheduling; verification gates payment, review, FarmActivity auto-log and books posting.สัญญาหลักฐาน; สถานะเดินตาม state machine (SPEC-PWF-CEC ข้อ 8) ประตู escrow ก่อนจัดคิว; การตรวจรับเป็นประตูการจ่าย รีวิว การบันทึก FarmActivity และการลงบัญชี
WorkAssignment
การมอบหมายงาน
WKA-########
assignment_id, work_order_id, assignee_user_id, machine_id?, scheduled_date, progress_pct, work_log, statuswork_log is append-only {ts, note?, photo?, gps?, qty_done?} — the evidence chain. status: assigned | en_route | working | done.work_log ต่อท้ายเท่านั้น {ts, note?, photo?, gps?, qty_done?} — สายหลักฐาน status: assigned | en_route | working | done
Machine
เครื่องจักร
MCH-#####
machine_id, contractor_id, machine_type, brand_model?, capacity_note?, plate_no?, year?, statusmachine_type: harvester | tractor | truck | sprayer_drone | drip_rig | solar_pump_rig | implement | other. Reference target of the bank's machine collateral.machine_type: harvester | tractor | truck | sprayer_drone | drip_rig | solar_pump_rig | implement | other เป้าอ้างอิงหลักประกัน machine ของธนาคาร
ServicePayment
การชำระค่าบริการ
SPY-########
payment_id, work_order_id, payer_tenant_type, payer_tenant_id, payee_contractor_id, amount, fee_amount?, method, escrow_state?, credit_item_id?, payment_item_id?, status, paid_at?Four rails: escrow | cash_recorded | credit_financed | settlement_offset; escrow lifecycle funded | held | released | refunded; commission (fee_amount) on escrow only (NFR-11).สี่ช่องทาง: escrow | cash_recorded | credit_financed | settlement_offset; วงจร escrow funded | held | released | refunded; คอมมิชชัน (fee_amount) เฉพาะ escrow (NFR-11)
Review
รีวิว
RVW-########
review_id, work_order_id, contractor_id, rater_tenant_type, rater_tenant_id, score_completion, score_quality, score_timeliness, score_overall, comment?, reply?, replied_at?, created_at, statusAppend-only. Exactly one per verified order, authored by its requester (NFR-10); one public contractor reply; removal by platform_admin only, reason logged.ต่อท้ายเท่านั้น หนึ่งรีวิวต่อใบสั่งงานที่ตรวจรับ เขียนโดยผู้ว่าจ้าง (NFR-10); ผู้รับเหมาตอบกลับสาธารณะได้หนึ่งครั้ง; ลบได้เฉพาะ platform_admin พร้อมบันทึกเหตุผล
Endorsement
การรับรอง
END-######
endorsement_id, contractor_id, endorser_tenant_type, endorser_tenant_id, season_id?, note?, granted_at, statusendorser_tenant_type: sugar_factory | quota_farmer; withdrawable any time, append-only history.endorser_tenant_type: sugar_factory | quota_farmer; ถอนได้ทุกเมื่อ ประวัติต่อท้าย
LedgerAccount
บัญชีแยกประเภท
LGA-#####
account_id, owner_tenant_type, owner_tenant_id, code, name_th, name_en?, account_class, system_flag, statusaccount_class: asset | liability | equity | income | expense; system accounts locked; keyed by owner tenant — deliberately tenant-agnostic.account_class: asset | liability | equity | income | expense; บัญชีระบบล็อก; คีย์ด้วยผู้เป็นเจ้าของ — จงใจไม่ผูกกลุ่ม
JournalEntry
รายการสมุดรายวัน
JRN-########
entry_id, owner_tenant_type, owner_tenant_id, entry_date, memo?, source_type, source_id?, lines, status, reversal_of?Append-only double entry; lines {account_id, debit?, credit?, machine_id?, work_order_id?, service_type?} must balance; corrections post reversals (NFR-13).บัญชีคู่แบบต่อท้าย; lines {account_id, debit?, credit?, machine_id?, work_order_id?, service_type?} ต้องสมดุล; แก้ไขด้วยรายการกลับ (NFR-13)

3. Entity relationship diagram3. แผนภาพความสัมพันธ์ entity

Scoped view of the platform model from this perspective, rendered from the graph (entities · relationships · dataModeling, v0.4.0). Solid boxes are entities documented at full depth in this family — bold = primary key, gold = foreign key. Dashed boxes are shared entities; the label names their home document. Cardinalities read at each line end.

มุมมองเฉพาะด้านของ model ทั้ง platform render จาก graph (entities · relationships · dataModeling, v0.4.0) กล่องเส้นทึบคือ entity ที่บันทึกเชิงลึกในเอกสารตระกูลนี้ — ตัวหนา = primary key, สีทอง = foreign key กล่องเส้นประคือ entity ที่ใช้ร่วม โดยป้ายระบุเอกสาร home; อ่าน cardinality ที่ปลายเส้นแต่ละด้าน

10..*10..*10..*10..*10..*0..10..111..*0..10..*10..* Contractorผู้รับเหมาcontractor_id PKtenant_id FKnamebase_provinceservice_areaphoneverified_statusrating_avgrating_count+2 more…Machineเครื่องจักรmachine_id PKcontractor_id FKmachine_typebrand_model?capacity_note?plate_no?year?statusServiceOfferingรายการบริการoffering_id PKcontractor_id FKservice_typecustom_label?unitprice_minprice_maxservice_areaseason_window?+2 more…ServiceRequestคำขอบริการrequest_id PKrequester_tenant_id FKservice_typematching_modefield_id? FKcrop_id? FKquantityunitwindow_start+5 more…ServiceQuoteใบเสนอราคาquote_id PKrequest_id FKcontractor_id FKpriceunitterms?valid_untilstatusWorkOrderใบสั่งงานwork_order_id PKrequest_id FKquote_id FKcontractor_id FKrequester_tenant_id FKservice_typefield_id? FKcrop_id? FKquantity+9 more…WorkAssignmentการมอบหมายงานassignment_id PKwork_order_id FKassignee_membership_id FKmachine_id? FKscheduled_dateprogress_pctwork_logstatusServicePaymentการชำระค่าบริการpayment_id PKwork_order_id FKpayer_tenant_id FKpayee_contractor_id FKamountfee_amount?methodescrow_state?credit_item_id? FK+3 more…
Fig. 1 — Directory → RFQ → award → dispatch — a WorkOrder binds the awarded quote to crew assignments and a payment over one of the four rails (escrow / cash / เงินเกี๊ยว credit_financed / settlement offset).ภาพที่ 1 — ไดเรกทอรี → RFQ → มอบงาน → จ่ายงาน — WorkOrder ผูก quote ที่ชนะเข้ากับการมอบหมายทีมและการจ่ายผ่านหนึ่งในสี่ช่องทาง (escrow / เงินสด / เงินเกี๊ยว / หักจากการปิดงวด)
0..*10..10..10..*10..*10..*10..*10..10..10..*0..10..1 Tenanttenant · FEDCreditItemรายการสินเชื่อ/ปัจจัยการผลิต · CFQWorkOrderใบสั่งงาน · CECContractorผู้รับเหมา · CECReviewรีวิวreview_id PKwork_order_id FKcontractor_id FKrater_tenant_id FKscore_completionscore_qualityscore_timelinessscore_overallcomment?+4 more…Endorsementการรับรองendorsement_id PKcontractor_id FKendorser_tenant_id FKseason_id? FKnote?granted_atstatusFarmActivityกิจกรรมแปลง · CFCPaymentItemรายการจ่ายต่อการส่งมอบ · MILL
Fig. 2 — Verified completion gates the three-dimension review; endorsements are per endorser per season; completed work writes FarmActivity provenance back onto the crop.ภาพที่ 2 — งานที่จบและยืนยันแล้วจึงรีวิวสามมิติได้; การรับรองนับต่อผู้รับรองต่อฤดู; งานที่เสร็จเขียนที่มา FarmActivity กลับลงบน crop

4. Relationships4. ความสัมพันธ์

Edgeเส้นเชื่อมCardinalityภาวะเชิงจำนวนRuleกฎ
Tenant → Contractor0..1 — 0..1A contractor tenant is represented by exactly one Contractor (kind = organization).tenant ผู้รับเหมามี Contractor หนึ่งเรกคอร์ด (kind = organization)
User → Contractor0..1 — 0..1A freelance contractor is one individual account (kind = freelance).ฟรีแลนซ์คือบัญชีบุคคลเดียว (kind = freelance)
Contractor → ServiceOffering · ServiceQuote · WorkOrder · Machine · Endorsement1 — 0..*Ownership edges; at most one active endorsement per (contractor, endorser).เส้นความเป็นเจ้าของ; การรับรอง active ได้อย่างมากหนึ่งรายการต่อ (ผู้รับเหมา, ผู้รับรอง)
Farmer → ServiceRequest1 — 0..*Requester polymorphic (cane_farmer | quota_farmer via Farmer, sugar_factory via Tenant).ผู้ขอเป็นแบบหลายรูป (cane_farmer | quota_farmer ผ่าน Farmer, sugar_factory ผ่าน Tenant)
Field → ServiceRequest0..1 — 0..*Demand anchors to a real field (and optionally its crop).อุปสงค์ยึดกับแปลงจริง (และอ้อยของแปลงถ้ามี)
ServiceRequest → ServiceQuote → WorkOrder1 — 0..* · 0..1 — 0..1RFQ collects quotes; one accepted quote creates the order atomically; broadcast auto-accepts the first qualified acceptance.RFQ รวบใบเสนอราคา; ใบที่ตอบรับสร้างใบสั่งงานแบบ atomic; broadcast รับรายแรกที่ผ่านเกณฑ์อัตโนมัติ
WorkOrder → WorkAssignment1 — 1..*At least one assignment; freelancers self-assign; optional machine per assignment.อย่างน้อยหนึ่งการมอบหมาย; ฟรีแลนซ์มอบหมายตนเอง; เครื่องจักรต่อการมอบหมายไม่บังคับ
WorkOrder → ServicePayment · Review · FarmActivity1 — 0..* · 1 — 0..1 · 0..1 — 0..*Escrow release requires verified; one review per verified order; verification auto-logs the matching FarmActivity.ปล่อย escrow ต้อง verified; หนึ่งรีวิวต่อใบสั่งงานที่ตรวจรับ; การตรวจรับบันทึก FarmActivity อัตโนมัติ
CreditItem → WorkOrder0..1 — 0..1A financed service item links the เงินเกี๊ยว money to the delivering work order.รายการสินเชื่อบริการลิงก์เงินเกี๊ยวกับใบสั่งงานที่ส่งมอบจริง
PaymentItem → ServicePayment1 — 0..*Settlement offset posts the matching ServicePayment; ordering joins the PROP-003 Q4 priority stack.การหักกลบตอนปิดงวดบันทึก ServicePayment ที่ตรงกัน; ลำดับเข้าร่วมกอง Q4 ของ PROP-003
Machine → Collateral0..1 — 0..*collateral_type: machine — the equipment loan is secured by the machine itself.collateral_type: machine — สินเชื่อเครื่องจักรค้ำด้วยตัวเครื่องเอง
Contractor → LedgerAccount → JournalEntry1 — 0..* · 1 — 0..*Books owner keyed polymorphically; journal lines reference same-owner accounts and must balance.เจ้าของบัญชีคีย์แบบหลายรูป; รายการสมุดรายวันอ้างบัญชีเจ้าของเดียวกันและต้องสมดุล

5. Changed shared entities (v5.0)5. Entity ใช้ร่วมที่เปลี่ยน (v5.0)

EntityChangeการเปลี่ยนแปลง
Tenanttenant_type gains contractor.tenant_type เพิ่ม contractor
CreditItemOptional work_order_id? — financed service ↔ delivering work order.เพิ่ม work_order_id? — บริการผ่านสินเชื่อ ↔ ใบสั่งงานที่ส่งมอบ
FarmActivityOptional work_order_id? + performed_by_contractor_id?; auto-logged on verification.เพิ่ม work_order_id? + performed_by_contractor_id?; บันทึกอัตโนมัติเมื่อตรวจรับ
ConsentGrantgrantor_tenant_type gains contractor; scope gains work_history | ratings | fleet | earnings | books (books never bundled).grantor_tenant_type เพิ่ม contractor; scope เพิ่ม work_history | ratings | fleet | earnings | books (books ไม่พ่วงกับ scope อื่น)
CreditAssessment · LoanProduct · CollateralSubject/borrower kinds gain contractor; collateral_type gains machine.ผู้ถูกประเมิน/ผู้กู้เพิ่ม contractor; collateral_type เพิ่ม machine
TruckOptional operator_contractor_id? (Q6) — contractor-driven trucks traceable through delivery; a contractor's own vehicles live in Machine.เพิ่ม operator_contractor_id? (Q6) — รถที่ผู้รับเหมาเดินรถตามรอยได้ตลอดการส่งมอบ; ยานพาหนะของผู้รับเหมาเองอยู่ใน Machine

6. Persistence profile — home entities6. Persistence profile — entity ที่ home อยู่ฉบับนี้

Normative physical model for the 10 entities homed in this document, rendered from the graph's dataModeling block. Types derive from typeConventions (first rule wins): money = bigint satang · weights = integer kg · tonnage = numeric(12,3) · timestamps = timestamptz UTC · ids = uuid v7. Every FK is indexed by convention (ON DELETE RESTRICT); listed indexes are additional. Enum value sets live in the graph's entity and state-machine notes.

Model เชิงกายภาพที่เป็นบรรทัดฐานของ entity ทั้ง 10 รายการที่ home อยู่ในเอกสารนี้ render จาก block dataModeling ใน graph ชนิดข้อมูลอนุมานจาก typeConventions (กติกาแรกที่เข้าเป็นผล): เงิน = bigint สตางค์ · น้ำหนัก = integer กก. · ตัน = numeric(12,3) · เวลา = timestamptz UTC · id = uuid v7 ทุก FK มี index ตามข้อตกลง (ON DELETE RESTRICT); index ที่ระบุคือส่วนเพิ่ม ชุดค่า enum อยู่ในหมายเหตุ entity และ state machine ของ graph

Contractor ผู้รับเหมา mutable personal

table contractor  ·  aggregate Contractor  ·  code CEC-#####  ·  unique (tenant_id)  ·  index (base_province,verified_status) · (service_area (gin))

ColumnColumnTypeชนิดNullDefaultค่าตั้งต้นKey / refKey / อ้างอิง
contractor_iduuid—uuid_v7()PK
tenant_iduuid——FK → tenant
nametext——
base_provincesmallint——Province enum · TIS 1099-2548 (PROP-047)
service_areajsonb——
phonetext——
verified_statustext (enum)——
rating_avgnumeric(3,2)——
rating_countinteger——
jobs_completedinteger——
member_sincedate——

ServiceOffering รายการบริการ mutable operational

table service_offering  ·  aggregate Contractor  ·  code SVO-######  ·  unique (contractor_id,service_type,custom_label)  ·  index (service_type,status)

ColumnColumnTypeชนิดNullDefaultค่าตั้งต้นKey / refKey / อ้างอิง
offering_iduuid—uuid_v7()PK
contractor_iduuid——FK → contractor
service_typetext (enum)——
custom_labeltext✓—
unittext——
price_minbigint (satang)——
price_maxbigint (satang)——
service_areajsonb——
season_windowtext✓—
capacity_notetext✓—
statustext (enum)——

ServiceRequest คำขอบริการ immutable_after_state operational

table service_request  ·  aggregate ServiceRequest  ·  code SRQ-########  ·  index (requester_tenant_id,status) · (service_type,status,window_start) · (field_id)

ColumnColumnTypeชนิดNullDefaultค่าตั้งต้นKey / refKey / อ้างอิง
request_iduuid—uuid_v7()PK
requester_tenant_iduuid——FK → tenant
service_typetext (enum)——
matching_modetext (enum)——
field_iduuid✓—FK → field
crop_iduuid✓—FK → crop
quantitynumeric(12,2)——
unittext——
window_startdate——
window_enddate——
budget_maxbigint (satang)✓—
notetext✓—
statustext (enum)——
awarded_quote_iduuid✓—FK → service_quote

ServiceQuote ใบเสนอราคา immutable_after_state operational

table service_quote  ·  aggregate ServiceRequest  ·  code SQT-########  ·  unique (request_id,contractor_id)  ·  index (status,valid_until)

ColumnColumnTypeชนิดNullDefaultค่าตั้งต้นKey / refKey / อ้างอิง
quote_iduuid—uuid_v7()PK
request_iduuid——FK → service_request
contractor_iduuid——FK → contractor
pricebigint (satang)——
unittext——
termstext✓—
valid_untiltext——
statustext (enum)——

WorkOrder ใบสั่งงาน immutable_after_state operational

table work_order  ·  aggregate WorkOrder  ·  code WKO-25##-######  ·  unique (quote_id (partial: not null))  ·  index (contractor_id,status) · (requester_tenant_id,status) · (window_start)

ColumnColumnTypeชนิดNullDefaultค่าตั้งต้นKey / refKey / อ้างอิง
work_order_iduuid—uuid_v7()PK
request_iduuid——FK → service_request
quote_iduuid——FK → service_quote
contractor_iduuid——FK → contractor
requester_tenant_iduuid——FK → tenant
service_typetext (enum)——
field_iduuid✓—FK → field
crop_iduuid✓—FK → crop
quantitynumeric(12,2)——
unittext——
agreed_pricebigint (satang)——
payment_methodtext (enum)——
window_startdate——
window_enddate——
statustext (enum)——
completed_attimestamptz✓—
verified_byuuid✓—FK → membership
dispute_notetext✓—

WorkAssignment การมอบหมายงาน mutable operational

table work_assignment  ·  aggregate WorkOrder  ·  code WKA-########  ·  index (work_order_id,scheduled_date) · (assignee_membership_id,scheduled_date) · (machine_id)

ColumnColumnTypeชนิดNullDefaultค่าตั้งต้นKey / refKey / อ้างอิง
assignment_iduuid—uuid_v7()PK
work_order_iduuid——FK → work_order
assignee_membership_iduuid——FK → membership
machine_iduuid✓—FK → machine
scheduled_datedate——
progress_pctnumeric(5,2)——
work_logjsonb——
statustext (enum)——

Machine เครื่องจักร mutable operational

table machine  ·  aggregate Contractor  ·  code MCH-#####  ·  unique (plate_no (partial: not null))  ·  index (contractor_id,status)

ColumnColumnTypeชนิดNullDefaultค่าตั้งต้นKey / refKey / อ้างอิง
machine_iduuid—uuid_v7()PK
contractor_iduuid——FK → contractor
machine_typetext (enum)——
brand_modeltext✓—
capacity_notetext✓—
plate_notext✓—
yearinteger✓—
statustext (enum)——

ServicePayment การชำระค่าบริการ immutable_after_state operational

table service_payment  ·  aggregate WorkOrder  ·  code SPY-########  ·  index (work_order_id) · (payer_tenant_id) · (escrow_state (partial: held)) · (credit_item_id)

ColumnColumnTypeชนิดNullDefaultค่าตั้งต้นKey / refKey / อ้างอิง
payment_iduuid—uuid_v7()PK
work_order_iduuid——FK → work_order
payer_tenant_iduuid——FK → tenant
payee_contractor_iduuid——FK → contractor
amountbigint (satang)——
fee_amountbigint (satang)✓—
methodtext (enum)——
escrow_statetext (enum)✓—
credit_item_iduuid✓—FK → credit_item
payment_item_iduuid✓—FK → payment_item
statustext (enum)——
paid_attimestamptz✓—

Review รีวิว immutable_after_state operational

table review  ·  aggregate Review  ·  code RVW-########  ·  unique (work_order_id)  ·  index (contractor_id,created_at) · (status)

ColumnColumnTypeชนิดNullDefaultค่าตั้งต้นKey / refKey / อ้างอิง
review_iduuid—uuid_v7()PK
work_order_iduuid——FK → work_order
contractor_iduuid——FK → contractor
rater_tenant_iduuid——FK → tenant
score_completioninteger——
score_qualityinteger——
score_timelinessinteger——
score_overallinteger——
commenttext✓—
replytext✓—
replied_attimestamptz✓—
created_attimestamptz—now()
statustext (enum)——

Endorsement การรับรอง immutable_after_state operational

table endorsement  ·  aggregate Endorsement  ·  code END-######  ·  unique (contractor_id,endorser_tenant_id,season_id)

ColumnColumnTypeชนิดNullDefaultค่าตั้งต้นKey / refKey / อ้างอิง
endorsement_iduuid—uuid_v7()PK
contractor_iduuid——FK → contractor
endorser_tenant_iduuid——FK → tenant
season_iduuid✓—FK → season
notetext✓—
granted_attimestamptz——
statustext (enum)——

7. Keys, indexes & mutability7. Key, index และ mutability

One row per entity in this perspective. Mutability: mutable · immutable_after_state (frozen once a terminal/approved state is reached) · append_only (corrections supersede or reverse, never edit) · reference (catalogue). PDPA class: personal · consent_gated · confidential_wall · operational · public. Entities homed in a sibling document link to their full profile.

หนึ่งแถวต่อ entity ในมุมมองนี้ Mutability: mutable · immutable_after_state (ตรึงเมื่อถึงสถานะอนุมัติ/สุดท้าย) · append_only (การแก้คือออกฉบับแทนหรือกลับรายการ ไม่แก้ของเดิม) · reference (บัญชีอ้างอิง) ชั้น PDPA: personal · consent_gated · confidential_wall · operational · public Entity ที่ home อยู่เอกสารพี่น้อง link ไป profile ฉบับเต็ม

EntityTableตารางPKUniqueKey indexesIndex หลักMutabilityPDPAProfile
Contractorcontractorcontractor_id(tenant_id)(base_province,verified_status) (service_area (gin))mutablepersonalSection 6ข้อ 6
ServiceOfferingservice_offeringoffering_id(contractor_id,service_type,custom_label)(service_type,status)mutableoperationalSection 6ข้อ 6
ServiceRequestservice_requestrequest_id—(requester_tenant_id,status) (service_type,status,window_start) (field_id)immutable_after_stateoperationalSection 6ข้อ 6
ServiceQuoteservice_quotequote_id(request_id,contractor_id)(status,valid_until)immutable_after_stateoperationalSection 6ข้อ 6
WorkOrderwork_orderwork_order_id(quote_id (partial: not null))(contractor_id,status) (requester_tenant_id,status) (window_start)immutable_after_stateoperationalSection 6ข้อ 6
WorkAssignmentwork_assignmentassignment_id—(work_order_id,scheduled_date) (assignee_membership_id,scheduled_date) (machine_id)mutableoperationalSection 6ข้อ 6
Machinemachinemachine_id(plate_no (partial: not null))(contractor_id,status)mutableoperationalSection 6ข้อ 6
ServicePaymentservice_paymentpayment_id—(work_order_id) (payer_tenant_id) (escrow_state (partial: held)) (credit_item_id)immutable_after_stateoperationalSection 6ข้อ 6
Reviewreviewreview_id(work_order_id)(contractor_id,created_at) (status)immutable_after_stateoperationalSection 6ข้อ 6
Endorsementendorsementendorsement_id(contractor_id,endorser_tenant_id,season_id)—immutable_after_stateoperationalSection 6ข้อ 6
LedgerAccountledger_accountaccount_id(owner_tenant_id,code)(account_class) (template_id) (cash_account_id)mutableoperationalSPEC-ERD-MILL
JournalEntryjournal_entryentry_id(owner_tenant_id,source_type,source_id (partial: auto-posted))(owner_tenant_id,entry_date) (reversal_of)append_onlyoperationalSPEC-ERD-MILL

8. Consistency boundaries8. ขอบเขตความสอดคล้อง (aggregate)

Transaction boundaries touching this perspective, from graph dataModeling.aggregates. Inside a boundary the stated invariants commit atomically in one database transaction; across boundaries effects flow through domain events (eventual consistency). Repository and unit-of-work lifetimes for these aggregates are specified in the sibling SPEC-DDD document (scoped per request — see the component lifetime map).

ขอบเขต transaction ที่เกี่ยวกับมุมมองนี้ จาก dataModeling.aggregates ใน graph ภายในขอบเขต invariant ที่ระบุ commit แบบ atomic ใน database transaction เดียว; ข้ามขอบเขตผลไหลผ่าน domain event (eventual consistency) lifetime ของ repository และ unit of work ของ aggregate เหล่านี้กำหนดในเอกสาร SPEC-DDD พี่น้อง (scoped ต่อคำขอ — ดูผัง lifetime ของ component)

Aggregate rootMembersสมาชิกContextTransaction ruleกติกา transaction
ContractorContractor · ServiceOffering · Machinework_dispatchProfile, offerings and machines mutate under the contractor's verification status; rating_avg/rating_count are denormalized from Review events (eventual).โปรไฟล์ บริการ และเครื่องจักรแก้ภายใต้สถานะการยืนยันของผู้รับเหมา; rating_avg/rating_count denormalize จาก Review event (eventual)
ServiceRequestServiceRequest · ServiceQuoteservice_marketplaceAwarding sets awarded_quote_id and flips winning/losing quote statuses in one transaction.การมอบงานตั้ง awarded_quote_id และสลับสถานะ quote ที่ชนะ/แพ้ใน transaction เดียว
WorkOrderWorkOrder · WorkAssignment · ServicePaymentwork_dispatchTransitions follow the work-order state machine; escrow state changes commit with the order status; verified completion gates review eligibility (FR-55).เปลี่ยนสถานะตาม state machine ของ work order; สถานะ escrow commit พร้อมสถานะงาน; การจบงานที่ยืนยันแล้วเป็นเงื่อนไขให้รีวิวได้ (FR-55)
ReviewReviewreputationOne review per work order; reply/status only after creation.หนึ่งรีวิวต่อ work order; ตอบกลับ/สถานะแก้ได้หลังสร้างเท่านั้น
EndorsementEndorsementreputationOne endorsement per endorser per contractor per season; revocation is a status change.หนึ่งการรับรองต่อผู้รับรองต่อผู้รับเหมาต่อฤดู; การถอนเป็นการเปลี่ยนสถานะ
LedgerAccountLedgerAccountbooksPer-tenant chart row; system_flag accounts are template-seeded and rename-only.แถวผังบัญชีราย tenant; บัญชี system_flag seed จาก template แก้ได้เฉพาะชื่อ
JournalEntryJournalEntrybooksEvery entry balances (Σ debit = Σ credit inside lines) — validated before commit; corrections are reversals (reversal_of), never edits; auto-posts are idempotent per source (NFR-24).ทุก entry ดุล (Σ เดบิต = Σ เครดิตใน lines) — ตรวจก่อน commit; การแก้ไขคือการกลับรายการ (reversal_of) ไม่ใช่การแก้; การลงอัตโนมัติ idempotent ต่อแหล่ง (NFR-24)

9. Revision history9. ประวัติการแก้ไข

RevDateวันที่Changeการเปลี่ยนแปลง
1.02026-07-08Initial document — renders the contractor perspective from spec-graph v5.0 (PROP-004 accepted): 12 owned entities, marketplace/dispatch/reputation/books relationships, changed shared entities.ฉบับแรก — เรนเดอร์มุมมองผู้รับเหมาจาก spec-graph v5.0 (PROP-004 อนุมัติ): entity ที่เป็นเจ้าของ 12 ตัว ความสัมพันธ์ตลาด/จัดงาน/ชื่อเสียง/บัญชี และ entity ใช้ร่วมที่เปลี่ยน
1.12026-07-08PROP-005 (FED, spec v6.0): perspective re-keyed from customer group to capacity (document code unchanged); identity defers to the federation context (Person · Tenant · TenantCapacity · Membership); every *_tenant_type + *_tenant_id pair collapses to tenant_id.PROP-005 (FED, spec (สเปก) v6.0): มุมมองเปลี่ยนคีย์จากกลุ่มลูกค้าเป็น capacity (รหัสเอกสารคงเดิม); อัตลักษณ์อ้างอิงบริบท federation (Person · Tenant · TenantCapacity · Membership); คู่ *_tenant_type + *_tenant_id ทั้งหมดยุบเป็น tenant_id
1.22026-07-09PROP-010 (GL, spec v9.0): the contractor's books grow into a full financial system — shares the new ChartTemplate / Invoice / Receipt / PaymentVoucher / CashAccount / BankTransaction / Reconciliation / FiscalPeriod / FinancialStatement (mill-owned reference); joins receivables/cash_management (WF-36 · WF-40); the payer side of ServicePayment now auto-posts uniformly (NFR-24…26).PROP-010 (GL, spec v9.0): books ของผู้รับเหมาขยายเป็นระบบการเงินเต็ม — ใช้ร่วม ChartTemplate / Invoice / Receipt / PaymentVoucher / CashAccount / BankTransaction / Reconciliation / FiscalPeriod / FinancialStatement (อ้างอิงมุมมองโรงงาน); เข้าร่วม receivables/cash_management (WF-36 · WF-40); ด้านผู้จ่ายของ ServicePayment ลงอัตโนมัติอย่างเป็นหนึ่งเดียว (NFR-24…26)
1.32026-07-10PROP-011 (GL, spec v12.0): the contractor shares BooksProfile — default unified edition (P&L-first), upgradeable to split via the books_split entitlement; edition/view are packaging over the same ledger (NFR-32).PROP-011 (GL, spec v12.0): ผู้รับเหมาใช้ร่วม BooksProfile — ตั้งต้นรุ่น unified (เน้นงบกำไรขาดทุน) อัปเกรดเป็น split ผ่านสิทธิ์ books_split; รุ่น/มุมมองเป็นการจัดแพ็กเกจบนบัญชีเดียวกัน (NFR-32)
0.1.02026-07-11PROP-014 (spec v0.1.0): semantic versioning restarted at 0.1.0 (was Rev 1.3 · 2026-07-10); docnav updated for the gov_cluster split — GOV re-homed to docs/gov/ocsb/, new BOARD (กอน.) sibling added.PROP-014 (spec v0.1.0): รีสตาร์ท semantic versioning ที่ 0.1.0 (เดิม Rev 1.3 · 2026-07-10); ปรับ docnav ตามการแยก gov_cluster — ย้าย GOV ไป docs/gov/ocsb/ เพิ่มพี่น้อง BOARD (กอน.)
0.2.02026-07-13PROP-018 (spec v0.4.0): comprehensive perspective data modeling — scoped entity-relationship diagrams (Fig. 1–2), column-level persistence profiles for the 10 home entities (Section 6), keys / indexes / mutability & PDPA classes (Section 7) and aggregate consistency boundaries (Section 8) — all rendered from the graph's new dataModeling block.PROP-018 (spec v0.4.0): การ model ข้อมูลรายมุมมองฉบับครบ — แผนภาพความสัมพันธ์ entity เฉพาะมุมมอง (ภาพที่ 1–2), persistence profile ระดับ column ของ entity ที่ home อยู่ฉบับนี้ 10 รายการ (ข้อ 6), key / index / ชั้น mutability และ PDPA (ข้อ 7) และขอบเขตความสอดคล้องของ aggregate (ข้อ 8) ทั้งหมด render จาก block ใหม่ dataModeling ใน graph
0.3.02026-07-23PROP-047 (spec v0.19.0): Contractor.base_province re-typed text → smallint carrying the Province enum code (TIS 1099-2548); registry in the shared kernel, CHECK generated from the enum — no reference table / FK / seed. Index (base_province, verified_status) unchanged in shape; the service_area jsonb array carries enum codes, not names.PROP-047 (spec v0.19.0): Contractor.base_province เปลี่ยนชนิดจาก text → smallint เก็บรหัส enum Province (มอก. 1099-2548); ทะเบียนอยู่ใน shared kernel, CHECK generate จาก enum — ไม่มีตารางอ้างอิง / FK / seed index (base_province, verified_status) รูปทรงเดิม; array แบบ jsonb ของ service_area เก็บรหัส enum ไม่ใช่ชื่อ
0.4.02026-08-03PROP-073 (spec v0.47.0): one word — Tenant. Party → Tenant, party_id (and every prefixed form) → tenant_id, PartyCapacity/PartyQualification/PartyFounded → Tenant*, party context/switcher → tenant context/switcher, cross-party → cross-tenant, organisation → organization, and ผู้เล่น retired as the Thai gloss (the Latin word tenant instead, R-THAI). Hold list untouched: counterparty · third party · tripartite working group · Person*/person_id; display codes and token claims were held by R-NULL for one release and then MOVED at v0.47.1 on client decision (C-1), because no token has ever been SIGNED — no auth exists in the built ocsb/ocsf prototypes — and the only printed codes were eight fixture strings in apps/ocsf/fund-shell.jsx, swept in the same pass: PTY- → TNT-, TCA- → TCA-, TQL- → TQL-, claim tnt → tnt, claim dep → dep. Carried in the same pass: the PROP-075 rectification — the retired directory noun domain becomes department (A-82 R-ONETREE) and the dangling A-86/A-87/A-88 citations are re-pointed at the ids they were actually given, A-81/A-82/A-83.PROP-073 (spec v0.47.0): คำเดียว — Tenant Party → Tenant, party_id ทุกรูป → tenant_id, PartyCapacity/PartyQualification/PartyFounded → Tenant*, cross-party → cross-tenant และเลิกใช้ ผู้เล่น เป็นคำแทนวัตถุนี้ในภาษาไทย (ใช้คำละติน tenant ตาม R-THAI) รายการห้ามแตะไม่ถูกแตะ: คู่สัญญา · third party · คณะทำงานไตรภาคี · Person*/person_id รอบเดียวกันแก้ค้างจาก PROP-075: domain → department (A-82) และแก้การอ้าง A-86/A-87/A-88 ที่ไม่มีอยู่จริงเป็น A-81/A-82/A-83
0.4.12026-08-03PROP-073 PATCH 1 (spec v0.47.1 / v0.47.2 / v0.47.3 as applicable): the identifiers v0.47.0 had held, moved on client decision. PTY-######## → TNT-######## · PCA-######## → TCA-######## · PQL-######## → TQL-######## · token claim pty → tnt · token claim dom → dep (v0.47.1, C-1 — R-NULL had held them as a stored VALUE and a wire format; reversed because no token has ever been signed and the only printed codes were fixture strings). quota_org_officer → quota_officer · lead_org_officer → lead_officer (v0.47.2, C-2 — org is organization abbreviated, not a resemblance). The retired role LABEL swept as a phrase family and quota organization naming the tenant → quota group / กลุ่มโควตา (v0.47.3). All retired forms are in the FR-396 crosswalk and refused in new text by NFR-142.PROP-073 PATCH 1 (spec v0.47.1 / v0.47.2 / v0.47.3 ตามที่เกี่ยวข้อง): ตัวระบุที่ v0.47.0 คงไว้ ถูกย้ายตามการตัดสินของลูกค้า PTY- → TNT- · PCA- → TCA- · PQL- → TQL- · claim pty → tnt · claim dom → dep (v0.47.1, C-1) · quota_org_officer → quota_officer · lead_org_officer → lead_officer (v0.47.2, C-2) · ป้ายชื่อบทบาทที่เลิกใช้และ องค์กรโควตา ที่เรียก tenant → กลุ่มโควตา (v0.47.3) ทุกรูปที่เลิกใช้อยู่ในตารางแปลง FR-396