智慧水务管理系统 - 精河县供水工程综合管理平台

V_invoice_account.sql 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. -- =============================================
  2. -- 智慧水务管理系统 - 电子发票 + 应收应付 + 催缴 DDL
  3. -- 版本: V_invoice_account
  4. -- =============================================
  5. -- 电子发票表
  6. CREATE TABLE IF NOT EXISTS rev_invoice (
  7. id BIGSERIAL PRIMARY KEY,
  8. invoice_no VARCHAR(30) UNIQUE NOT NULL,
  9. invoice_type VARCHAR(20) NOT NULL DEFAULT 'electronic', -- normal/special/electronic
  10. customer_id BIGINT NOT NULL,
  11. customer_name VARCHAR(100),
  12. customer_tax_no VARCHAR(30),
  13. amount DECIMAL(12,2) NOT NULL,
  14. tax_rate DECIMAL(5,2) DEFAULT 6.00,
  15. tax_amount DECIMAL(12,2) NOT NULL,
  16. total_amount DECIMAL(12,2) NOT NULL,
  17. content VARCHAR(500),
  18. bill_id BIGINT,
  19. status VARCHAR(20) NOT NULL DEFAULT 'draft', -- draft/issued/sent/cancelled/red
  20. issue_date DATE,
  21. push_status VARCHAR(20) DEFAULT 'none', -- none/email/sms/both
  22. push_time TIMESTAMP,
  23. email VARCHAR(100),
  24. phone VARCHAR(20),
  25. cancel_reason VARCHAR(500),
  26. original_invoice_id BIGINT, -- 红冲关联的原发票
  27. operator_id BIGINT,
  28. operator_name VARCHAR(50),
  29. remark VARCHAR(500),
  30. deleted SMALLINT DEFAULT 0,
  31. created_at TIMESTAMP DEFAULT NOW(),
  32. updated_at TIMESTAMP DEFAULT NOW()
  33. );
  34. COMMENT ON TABLE rev_invoice IS '电子发票表';
  35. CREATE INDEX IF NOT EXISTS idx_invoice_customer ON rev_invoice(customer_id);
  36. CREATE INDEX IF NOT EXISTS idx_invoice_bill ON rev_invoice(bill_id);
  37. CREATE INDEX IF NOT EXISTS idx_invoice_status ON rev_invoice(status);
  38. CREATE INDEX IF NOT EXISTS idx_invoice_issue_date ON rev_invoice(issue_date);
  39. -- 应收账款表
  40. CREATE TABLE IF NOT EXISTS rev_receivable (
  41. id BIGSERIAL PRIMARY KEY,
  42. receivable_no VARCHAR(30) UNIQUE NOT NULL,
  43. bill_period VARCHAR(10) NOT NULL, -- 2026-06
  44. customer_id BIGINT NOT NULL,
  45. customer_name VARCHAR(100),
  46. amount DECIMAL(12,2) NOT NULL,
  47. received_amount DECIMAL(12,2) DEFAULT 0,
  48. unreceived_amount DECIMAL(12,2) NOT NULL,
  49. status VARCHAR(20) NOT NULL DEFAULT 'pending', -- pending/partial/completed/overdue/cancelled
  50. bill_id BIGINT,
  51. due_date DATE,
  52. overdue_days INT DEFAULT 0,
  53. collection_count INT DEFAULT 0,
  54. last_collection_time TIMESTAMP,
  55. operator_id BIGINT,
  56. remark VARCHAR(500),
  57. deleted SMALLINT DEFAULT 0,
  58. created_at TIMESTAMP DEFAULT NOW(),
  59. updated_at TIMESTAMP DEFAULT NOW()
  60. );
  61. COMMENT ON TABLE rev_receivable IS '应收账款表';
  62. CREATE INDEX IF NOT EXISTS idx_receivable_customer ON rev_receivable(customer_id);
  63. CREATE INDEX IF NOT EXISTS idx_receivable_period ON rev_receivable(bill_period);
  64. CREATE INDEX IF NOT EXISTS idx_receivable_status ON rev_receivable(status);
  65. CREATE INDEX IF NOT EXISTS idx_receivable_due_date ON rev_receivable(due_date);
  66. -- 应付账款表
  67. CREATE TABLE IF NOT EXISTS rev_payable (
  68. id BIGSERIAL PRIMARY KEY,
  69. payable_no VARCHAR(30) UNIQUE NOT NULL,
  70. bill_period VARCHAR(10) NOT NULL, -- 2026-06
  71. supplier_id BIGINT NOT NULL,
  72. supplier_name VARCHAR(100),
  73. amount DECIMAL(12,2) NOT NULL,
  74. paid_amount DECIMAL(12,2) DEFAULT 0,
  75. unpaid_amount DECIMAL(12,2) NOT NULL,
  76. status VARCHAR(20) NOT NULL DEFAULT 'pending', -- pending/partial/completed/cancelled
  77. expense_type VARCHAR(30), -- electricity/chemical/maintenance/equipment/other
  78. due_date DATE,
  79. invoice_no VARCHAR(50),
  80. contract_no VARCHAR(50),
  81. operator_id BIGINT,
  82. remark VARCHAR(500),
  83. deleted SMALLINT DEFAULT 0,
  84. created_at TIMESTAMP DEFAULT NOW(),
  85. updated_at TIMESTAMP DEFAULT NOW()
  86. );
  87. COMMENT ON TABLE rev_payable IS '应付账款表';
  88. CREATE INDEX IF NOT EXISTS idx_payable_supplier ON rev_payable(supplier_id);
  89. CREATE INDEX IF NOT EXISTS idx_payable_period ON rev_payable(bill_period);
  90. CREATE INDEX IF NOT EXISTS idx_payable_status ON rev_payable(status);
  91. CREATE INDEX IF NOT EXISTS idx_payable_due_date ON rev_payable(due_date);
  92. -- 对账记录表
  93. CREATE TABLE IF NOT EXISTS rev_reconciliation (
  94. id BIGSERIAL PRIMARY KEY,
  95. reconciliation_no VARCHAR(30) UNIQUE NOT NULL,
  96. bill_period VARCHAR(10) NOT NULL,
  97. reconciliation_type VARCHAR(20) DEFAULT 'all', -- receivable/payable/all
  98. total_receivable DECIMAL(14,2) DEFAULT 0,
  99. total_received DECIMAL(14,2) DEFAULT 0,
  100. total_payable DECIMAL(14,2) DEFAULT 0,
  101. total_paid DECIMAL(14,2) DEFAULT 0,
  102. difference DECIMAL(14,2) DEFAULT 0,
  103. status VARCHAR(20) NOT NULL DEFAULT 'draft', -- draft/pending/approved/rejected/completed
  104. start_date DATE,
  105. end_date DATE,
  106. exception_count INT DEFAULT 0,
  107. exception_note TEXT,
  108. auditor_id BIGINT,
  109. auditor_name VARCHAR(50),
  110. audit_time TIMESTAMP,
  111. operator_id BIGINT,
  112. operator_name VARCHAR(50),
  113. remark VARCHAR(500),
  114. deleted SMALLINT DEFAULT 0,
  115. created_at TIMESTAMP DEFAULT NOW(),
  116. updated_at TIMESTAMP DEFAULT NOW()
  117. );
  118. COMMENT ON TABLE rev_reconciliation IS '对账记录表';
  119. CREATE INDEX IF NOT EXISTS idx_reconciliation_period ON rev_reconciliation(bill_period);
  120. CREATE INDEX IF NOT EXISTS idx_reconciliation_status ON rev_reconciliation(status);
  121. -- 催缴记录表
  122. CREATE TABLE IF NOT EXISTS rev_collection_record (
  123. id BIGSERIAL PRIMARY KEY,
  124. collection_no VARCHAR(30) UNIQUE NOT NULL,
  125. customer_id BIGINT NOT NULL,
  126. customer_name VARCHAR(100),
  127. overdue_amount DECIMAL(12,2) NOT NULL,
  128. overdue_days INT DEFAULT 0,
  129. collection_type VARCHAR(20) NOT NULL, -- sms/phone/visit/letter
  130. collection_result VARCHAR(20), -- success/promised/failed/unreachable/refused
  131. contact_person VARCHAR(50),
  132. contact_phone VARCHAR(20),
  133. contact_email VARCHAR(100),
  134. collection_time TIMESTAMP,
  135. promised_date DATE,
  136. collector_id BIGINT,
  137. collector_name VARCHAR(50),
  138. receivable_id BIGINT,
  139. remark VARCHAR(500),
  140. status VARCHAR(20) DEFAULT 'pending', -- pending/in_progress/completed/cancelled
  141. deleted SMALLINT DEFAULT 0,
  142. created_at TIMESTAMP DEFAULT NOW(),
  143. updated_at TIMESTAMP DEFAULT NOW()
  144. );
  145. COMMENT ON TABLE rev_collection_record IS '催缴记录表';
  146. CREATE INDEX IF NOT EXISTS idx_collection_customer ON rev_collection_record(customer_id);
  147. CREATE INDEX IF NOT EXISTS idx_collection_receivable ON rev_collection_record(receivable_id);
  148. CREATE INDEX IF NOT EXISTS idx_collection_status ON rev_collection_record(status);
  149. CREATE INDEX IF NOT EXISTS idx_collection_time ON rev_collection_record(collection_time);
  150. CREATE INDEX IF NOT EXISTS idx_collection_type ON rev_collection_record(collection_type);