dsh-progress-payment 0.0.0-stage → 0.1.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README-es.md ADDED
@@ -0,0 +1,13 @@
1
+ <div align="center">
2
+
3
+ # dsh-progress-payment
4
+
5
+ > **Repositorio oficial. El único repositorio oficial de este paquete, mantenido por PerryLink. Apache-2.0.**
6
+
7
+ </div>
8
+
9
+ Audita una declaración de pago por avance de obra contra la línea base del contrato: importes en céntimos enteros, ratio acumulado y lista de problemas (exceso de cantidad, precio distinto, partidas duplicadas), con exportación a CSV. Todo se ejecuta localmente.
10
+
11
+ ## Documentación completa
12
+
13
+ La documentación completa (instalación, permisos, ejemplos y solución de problemas) está en [README.md](README.md) y [README-zh.md](README-zh.md).
package/README-hi.md ADDED
@@ -0,0 +1,13 @@
1
+ <div align="center">
2
+
3
+ # dsh-progress-payment
4
+
5
+ > **आधिकारिक रिपॉज़िटरी। इस पैकेज की एकमात्र आधिकारिक रिपॉज़िटरी, PerryLink द्वारा अनुरक्षित। Apache-2.0.**
6
+
7
+ </div>
8
+
9
+ निर्माण प्रगति-भुगतान घोषणा की अनुबंध आधार-रेखा से जाँच: पूर्णांक पैसे में राशि, संचयी अनुपात, तथा अधिक मात्रा / भिन्न दर / दोहराई गई मदों की सूची, CSV निर्यात के साथ। सब कुछ लोकल चलता है।
10
+
11
+ ## पूरा दस्तावेज़
12
+
13
+ पूरा दस्तावेज़ (इंस्टॉल, अनुमतियाँ, उदाहरण और समस्या-निवारण) [README.md](README.md) और [README-zh.md](README-zh.md) में है।
package/README-pt.md ADDED
@@ -0,0 +1,13 @@
1
+ <div align="center">
2
+
3
+ # dsh-progress-payment
4
+
5
+ > **Repositório oficial. O único repositório oficial deste pacote, mantido por PerryLink. Apache-2.0.**
6
+
7
+ </div>
8
+
9
+ Audita uma declaração de pagamento por medição de obra contra a linha de base do contrato: valores em centavos inteiros, razão acumulada e lista de problemas (quantidade excedida, preço divergente, itens duplicados), com exportação para CSV. Tudo roda localmente.
10
+
11
+ ## Documentação completa
12
+
13
+ A documentação completa (instalação, permissões, exemplos e solução de problemas) está em [README.md](README.md) e [README-zh.md](README-zh.md).
package/README-zh.md ADDED
@@ -0,0 +1,205 @@
1
+ <div align="center">
2
+
3
+ # dsh-progress-payment
4
+
5
+ > **官方仓库。** 本包唯一官方仓库,由 PerryLink 维护;其他账号下的同名仓库与本项目无关。Apache-2.0。
6
+
7
+ [![npm](https://img.shields.io/npm/v/dsh-progress-payment)](https://www.npmjs.com/package/dsh-progress-payment)
8
+ [![CI](https://github.com/PerryLink/dsh-progress-payment/actions/workflows/ci.yml/badge.svg)](https://github.com/PerryLink/dsh-progress-payment/actions)
9
+ [![License](https://img.shields.io/badge/license-Apache--2.0-blue)](LICENSE)
10
+
11
+ **按合同基准确认本期进度款:金额整数分、累计比例、超量/单价/重复项问题清单 → 审核底稿 CSV。**
12
+
13
+ > **状态:alpha / 公开合成 / partial / not counted / 非 GA。** 不含客户数据、客户证据,也不作生产可用声明。
14
+
15
+ [English](README.md) · [简体中文](README-zh.md) · [Español](README-es.md) · [Português](README-pt.md) · [हिन्दी](README-hi.md)
16
+
17
+ ```sh
18
+ dsh plugin --profile <profile> add dsh-progress-payment
19
+ ```
20
+
21
+ </div>
22
+
23
+ ## 一句话
24
+
25
+ 把本期进度款申报按合同基准逐项核对,算出本期金额和累计比例,列出超量、单价不符和重复清单项,再导出审核底稿 CSV。
26
+
27
+ ## 适合 / 不适合
28
+
29
+ - **适合**:总包、分包、业主方的造价和监理人员,每期几十到几千条清单项的进度款申报;先核对量和单价,再决定本期签认多少;把申报、合同基准和问题清单留成一份可复核的 CSV 底稿。
30
+ - **不适合**:替代计价软件、结算审核或法律意见;没有合同基准的手工报量;判断变更签证是否成立(本包只按合同基准提示超量,不替你做变更审批);扫描件/PDF/图片的 OCR(只收 CSV)。
31
+
32
+ ## 输入
33
+
34
+ - **申报 CSV**:UTF-8,表头含 `清单编码,名称,单位,合同量,合同单价,本期完成量,累计完成量`;也接受英文表头 `item_code,item_name,unit,contract_qty,contract_unit_price,period_qty,cumulative_qty`,列顺序随意。
35
+ - **合同基准 CSV**(可选):`清单编码,合同量,合同单价`(英文 `item_code,contract_qty,contract_unit_price`)。给了基准就以基准为权威;不给就用申报里的合同量/单价。
36
+ - **格式约定**:数量最多 3 位小数,单价/金额最多 2 位小数;金额内部按**整数分**计算,不用浮点累加。
37
+ - **样例**:`samples/quickstart/input/declaration-2026-10.csv`(7 行 / 6 个清单项)和 `contract-baseline.csv`(6 项),全部为合成数据(虚构清单编码和金额)。
38
+
39
+ ## 输出
40
+
41
+ - `progress.ingest`:`batch_id`、行数、清单项数、合同基准项数;只存在当前会话内存里,不落盘。
42
+ - `progress.audit`:每个清单项的合同量/单价、本期完成量、累计完成量、本期金额、累计金额、累计比例,加一份按行号排序的问题清单(`E_PROGRESS_*`);金额都是整数分。
43
+ - `progress.export`:审核底稿 CSV(UTF-8 BOM,Excel 直接打开不乱码),一行一条申报记录,重复行标 `是否计入=否`;写到 `$DSH_HOME/dsh-progress-payment/exports/`,返回路径、行数、字节数和 sha256。
44
+ - **不改原 CSV**,不上传、不联网、不调用模型。
45
+
46
+ ## 示例
47
+
48
+ 直接复制下面这句:
49
+
50
+ > 帮我审一下这期进度款申报,按合同基准核对超量和单价,把问题清单导成底稿。
51
+
52
+ 用自带样例复跑并核对金标:
53
+
54
+ ```sh
55
+ node samples/quickstart/run.mjs --check
56
+ ```
57
+
58
+ ![dsh-progress-payment quickstart 真实运行输出](docs/assets/quickstart.png)
59
+
60
+ 样例是一次真实运行:7 行申报 / 6 个清单项,本期金额 **50,763.60 CNY**,累计 **614,145.00 CNY(84.62%)**,3 个阻塞问题——矩形柱累计 101.5 m³ 超合同量 95 m³、基础模板申报单价 65.00 与合同基准 55.00 不符、挖沟槽土方重复出现 2 次。金标 `samples/quickstart/expected/result.json` 由 `node samples/quickstart/run.mjs --json` 真实产生,不是手写。
61
+
62
+ ## 权限
63
+
64
+ 读:用户指定的申报 CSV 和合同基准 CSV(样例 `samples/quickstart/input/`);不读其他目录。
65
+ 写:`$DSH_HOME/dsh-progress-payment/exports/`(审核底稿 CSV);不改原文件。
66
+ 联网:否。
67
+ 外部系统:无。
68
+
69
+ `progress.ingest`、`progress.audit` 标 **R0**(只读;`ingest` 只写入当前会话内存,不落盘);`progress.export` 标 **R1**(本地写,只写 `$DSH_HOME/dsh-progress-payment` 下的 `exports/`)。可用 `DSH_PROGRESS_PAYMENT_HOME` 覆盖本地写根目录(测试用),默认严格等于 `$DSH_HOME/dsh-progress-payment`。
70
+
71
+ ## FAQ
72
+
73
+ ### 1. 为什么本期金额和我自己算的不一样?
74
+
75
+ 本包按**合同基准单价**计算本期金额,不用申报里填的单价。申报单价和基准不一致时会报 `E_PROGRESS_PRICE_MISMATCH`,并把“按申报单价算的金额”和“按合同单价算的金额”都列出来,差额在 `summary.price_adjustment_cents` 里。数量×单价按分四舍五入到整数分,不累加浮点误差。
76
+
77
+ ### 2. “超合同量”到底按哪一版合同量?
78
+
79
+ 给了合同基准就以基准为准;没给才用申报里的合同量。本期完成量超过合同量、累计完成量超过合同量都会报 `E_PROGRESS_OVER_QTY`,两者用 `kind` 区分(`period_over_contract` / `cumulative_over_contract`)。超量部分不会自动扣减合同额,需要走变更或结算。
80
+
81
+ ### 3. 重复清单项会重复算钱吗?
82
+
83
+ 不会。同一清单编码出现多次时,只按第一次出现的行计入本期金额,其余行在底稿里标 `是否计入=否`,并报 `E_PROGRESS_DUP_ITEM`。但哪一行才是“本期应报的”需要你确认,本包不自动挑。
84
+
85
+ ### 4. 会改我的 CSV 或上传数据吗?
86
+
87
+ 不会。只读用户指定的 CSV;只在本地 `exports/` 写底稿;不联网、不调用模型、不上传。
88
+
89
+ ### 5. 能直接读 Excel 吗?
90
+
91
+ 不能。请先在 Excel“另存为 → CSV UTF-8”。如果表头是中文且用 Excel 保存,文件可能带 BOM,本包能正确识别。
92
+
93
+ ## 版本
94
+
95
+ `0.1.0-alpha.1` · 32 项测试通过(`node --test test/*.test.mjs`)。
96
+
97
+ > ⭐ 如果它帮到了你,点个 star 会让下一个人更容易找到它;没有任何功能被 star 解锁。
98
+
99
+ ## 安装
100
+
101
+ ```sh
102
+ dsh plugin --profile <profile> add dsh-progress-payment
103
+ dsh --profile <profile> --dump-config | grep dsh-progress-payment
104
+ ```
105
+
106
+ 卸载:
107
+
108
+ ```sh
109
+ dsh plugin --profile <profile> remove dsh-progress-payment
110
+ ```
111
+
112
+ ### 安装通道
113
+
114
+ - **npm(推荐):** `dsh plugin --profile <profile> add dsh-progress-payment`
115
+ - **git 通道:** `dsh plugin --profile <profile> add github:PerryLink/dsh-progress-payment`
116
+ - **tarball:** `pnpm pack`,然后 `dsh plugin --profile <profile> add ./dsh-progress-payment-<version>.tgz`
117
+
118
+ ## 工具
119
+
120
+ 工具名是稳定 API;说明保留英文以匹配运行时输出。
121
+
122
+ | 工具 | 用途 | 风险 |
123
+ |---|---|---|
124
+ | `progress.ingest` | 导入本期申报 CSV 与可选合同基准 CSV,返回 `batch_id`;只写会话内存 | R0 |
125
+ | `progress.audit` | 审核:本期金额、累计比例、超合同量、单价不符、累计>合同量、重复清单项;返回问题清单,金额整数分 | R0 |
126
+ | `progress.export` | 重跑审核并写审核底稿 CSV(UTF-8 BOM),返回路径、行数、sha256 | R1 local write |
127
+
128
+ ## 审核规则
129
+
130
+ 1. **金额**:`本期金额 = 本期完成量 × 合同单价`,按整数分四舍五入;累计金额同理。
131
+ 2. **累计比例**:`累计金额 ÷ 合同金额 × 100`,保留 2 位小数;合同金额为 0 时返回 0。
132
+ 3. **超合同量**:`本期完成量 > 合同量` 或 `累计完成量 > 合同量` → `E_PROGRESS_OVER_QTY`。
133
+ 4. **单价不符**:申报合同单价 ≠ 合同基准单价 → `E_PROGRESS_PRICE_MISMATCH`;可用 `price_tolerance_bps` 放宽容差(默认 0,精确比对)。
134
+ 5. **累计 > 合同量**:同 3 的 `cumulative_over_contract`,累计比例会超过 100%。
135
+ 6. **重复清单项**:同一 `清单编码` 出现多次 → `E_PROGRESS_DUP_ITEM`;仅第一次出现计入金额。
136
+ 7. **合同基准缺失 / 合同量不符**:`E_PROGRESS_CONTRACT_MISSING` / `E_PROGRESS_CONTRACT_MISMATCH`。
137
+ 8. **累计小于本期**:`E_PROGRESS_QTY_INCONSISTENT`,通常是上期累计填错。
138
+
139
+ ## 快速开始
140
+
141
+ ```sh
142
+ # 1) 导入申报(工具面)
143
+ # progress.ingest({ declaration_csv, contract_csv })
144
+
145
+ # 2) 审核(工具面)
146
+ # progress.audit({ batch_id })
147
+
148
+ # 3) 导出底稿(工具面)
149
+ # progress.export({ batch_id, filename: "progress-audit-2026-10.csv" })
150
+ ```
151
+
152
+ 用样例直接跑:
153
+
154
+ ```sh
155
+ node samples/quickstart/run.mjs --check
156
+ ```
157
+
158
+ ## 验收证据
159
+
160
+ 公开/合成 fixture 在 `samples/quickstart/`;`ACCEPTANCE.csv` 记录检查,除 quickstart 行外均为 `counted=false`。
161
+
162
+ | req_id | metric | threshold | actual | pass | source | counted |
163
+ |---|---|---|---|---|---|---|
164
+ | PG-A02 | 本期金额(分) | 5076360 | 5076360 | true | public/synthetic | false |
165
+ | PG-A06 | 单价不符 | E_PROGRESS_PRICE_MISMATCH x1 | 1 | true | public/synthetic | false |
166
+ | PS1-QS01 | quickstart 金标 | 1/1 | 1 | true | synthetic/quickstart | true |
167
+
168
+ *这是 fixture 支撑的验收行,不是客户运行;没有编造输出。*
169
+
170
+ ## 边界与已知限制
171
+
172
+ - **只做量价核对**:不判断变更签证、索赔、质量扣款、税率和支付比例是否合理;这些仍需合同条款和人工判断。
173
+ - **单价只有一个口径**:申报里的 `合同单价` 是本期计价依据;没有“本期单价/信息价”列。
174
+ - **不自动挑选重复行**:重复清单项会全部列出并只计第一行,哪行应报需要人工确认。
175
+ - **金额上限**:单行金额需落在 JavaScript 安全整数范围内;超出会报 `E_PROGRESS_CSV_ROW`。
176
+ - **只收 CSV**:不支持 xlsx、PDF、扫描件;Excel 请先另存为 CSV。
177
+ - 仅公开/合成样例;alpha/partial、not counted,不作 GA 或生产可用声明。
178
+
179
+ ## 开发
180
+
181
+ ```sh
182
+ pnpm install --frozen-lockfile
183
+ pnpm build && pnpm lint && pnpm typecheck
184
+ node --test test/*.test.mjs
185
+ node scripts/gate.mjs
186
+ ```
187
+
188
+ ## 兼容性
189
+
190
+ | 维度 | 状态 |
191
+ |---|---|
192
+ | Harness | `dsh >=0.2.1-rc.3 <0.4.0` |
193
+ | Node | `>=24.9.0 <25` |
194
+ | Platforms | All; local files only |
195
+ | 数据 | No network, no model call, no upload |
196
+
197
+ ## 相关项目
198
+
199
+ - [dsh-ifc-qto](https://github.com/PerryLink/dsh-ifc-qto)(模型工程量,可作为申报量的对照)
200
+ - [dsh-ap-three-way](https://github.com/PerryLink/dsh-ap-three-way)(付款单三单匹配)
201
+ - [领域索引](https://perrylink.github.io/dsh-plugins/)
202
+
203
+ ## 许可证
204
+
205
+ Apache-2.0. See `LICENSE`, `NOTICE`, `THIRD-PARTY-NOTICES`.
package/README.md CHANGED
@@ -1,3 +1,205 @@
1
- # Temporary Holding Version
1
+ <div align="center">
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ # dsh-progress-payment
4
+
5
+ > **Official repository.** The only official repository of this package, maintained by PerryLink. Same-name repositories under other accounts are not affiliated. Apache-2.0.
6
+
7
+ [![npm](https://img.shields.io/npm/v/dsh-progress-payment)](https://www.npmjs.com/package/dsh-progress-payment)
8
+ [![CI](https://github.com/PerryLink/dsh-progress-payment/actions/workflows/ci.yml/badge.svg)](https://github.com/PerryLink/dsh-progress-payment/actions)
9
+ [![License](https://img.shields.io/badge/license-Apache--2.0-blue)](LICENSE)
10
+
11
+ **Audit a construction progress-payment declaration against the contract baseline: integer-cent amounts, cumulative ratio, over-quantity / price / duplicate issues → review worksheet CSV.**
12
+
13
+ > **Status: alpha / public-synthetic / partial / not counted / not GA.** No customer data, customer evidence, or production-readiness claim.
14
+
15
+ [English](README.md) · [简体中文](README-zh.md) · [Español](README-es.md) · [Português](README-pt.md) · [हिन्दी](README-hi.md)
16
+
17
+ ```sh
18
+ dsh plugin --profile <profile> add dsh-progress-payment
19
+ ```
20
+
21
+ </div>
22
+
23
+ ## One-liner
24
+
25
+ Check this period's declared quantities and prices against the contract, compute the period and cumulative amounts plus the cumulative ratio, list over-quantity, price-mismatch and duplicate bill items, and export a review worksheet CSV.
26
+
27
+ ## Fit / not a fit
28
+
29
+ - **Fits:** quantity surveyors, cost engineers and site supervisors who audit a monthly progress payment with tens to thousands of bill items; checking quantity and unit price before signing the certificate; keeping the declaration, contract baseline and issue list in one reviewable CSV.
30
+ - **Does not fit:** replacing estimating/settlement software or legal advice; declarations with no contract baseline; deciding whether a change order is valid (this package flags over-quantity but does not approve variations); OCR of scanned PDFs (CSV only).
31
+
32
+ ## Input
33
+
34
+ - **Declaration CSV:** UTF-8, header `清单编码,名称,单位,合同量,合同单价,本期完成量,累计完成量` (Chinese) or `item_code,item_name,unit,contract_qty,contract_unit_price,period_qty,cumulative_qty` (English). Column order is free.
35
+ - **Contract baseline CSV (optional):** `清单编码,合同量,合同单价` (or `item_code,contract_qty,contract_unit_price`). When supplied it is authoritative; otherwise the declared contract quantity/price is used.
36
+ - **Precision:** quantities up to 3 decimals, prices/amounts up to 2 decimals. Money is computed in **integer cents**, never float accumulation.
37
+ - **Sample:** `samples/quickstart/input/declaration-2026-10.csv` (7 rows / 6 bill items) and `contract-baseline.csv` (6 items). Synthetic only.
38
+
39
+ ## Output
40
+
41
+ - `progress.ingest`: `batch_id`, rows, item count, contract-item count. Session memory only; no file is written.
42
+ - `progress.audit`: per item the contract quantity/price, period quantity, cumulative quantity, period amount, cumulative amount, cumulative ratio, plus a row-ordered issue list (`E_PROGRESS_*`). Amounts are integer cents.
43
+ - `progress.export`: review worksheet CSV (UTF-8 BOM, opens cleanly in Excel), one row per declaration line with duplicate rows marked `是否计入=否`; written to `$DSH_HOME/dsh-progress-payment/exports/`; returns path, rows, bytes and sha256.
44
+ - The source CSVs are never modified; no upload, no network, no model call.
45
+
46
+ ## Example
47
+
48
+ Paste this one line into the agent:
49
+
50
+ > 帮我审一下这期进度款申报,按合同基准核对超量和单价,把问题清单导成底稿。
51
+
52
+ Reproduce the bundled sample and compare with the golden file:
53
+
54
+ ```sh
55
+ node samples/quickstart/run.mjs --check
56
+ ```
57
+
58
+ ![dsh-progress-payment quickstart terminal output](docs/assets/quickstart.png)
59
+
60
+ This is a real run: 7 declaration rows / 6 bill items, period amount **50,763.60 CNY**, cumulative **614,145.00 CNY (84.62%)**, and 3 blocking issues — the rectangular column exceeded its contract quantity (101.5 vs 95 m³), the formwork price was 65.00 against a 55.00 baseline, and one item code appeared twice. `samples/quickstart/expected/result.json` is the real stdout of `node samples/quickstart/run.mjs --json`, not hand-written.
61
+
62
+ ## Permissions
63
+
64
+ Read: the declaration CSV and contract baseline CSV the user names (sample: `samples/quickstart/input/`); nothing else.
65
+ Write: `$DSH_HOME/dsh-progress-payment/exports/` (review worksheet CSV) only; source files are not modified.
66
+ Network: no.
67
+ External systems: none.
68
+
69
+ `progress.ingest` and `progress.audit` are **R0** (read-only; `ingest` keeps the batch in session memory). `progress.export` is **R1** (local write under `$DSH_HOME/dsh-progress-payment`). `DSH_PROGRESS_PAYMENT_HOME` can override the local write root for tests.
70
+
71
+ ## FAQ
72
+
73
+ ### 1. Why does the period amount differ from my own calculation?
74
+
75
+ The audit prices every line at the **contract baseline unit price**, not the declared price. A declared price that differs raises `E_PROGRESS_PRICE_MISMATCH` and both amounts are reported; the delta is `summary.price_adjustment_cents`. Quantity × price is rounded half-up to whole cents.
76
+
77
+ ### 2. Which contract quantity is the ceiling?
78
+
79
+ The contract baseline wins when supplied; the declared contract quantity is used only when no baseline is given. Both `period_qty > contract_qty` and `cumulative_qty > contract_qty` raise `E_PROGRESS_OVER_QTY`, distinguished by `kind` (`period_over_contract` / `cumulative_over_contract`). Over-quantity is not silently deducted — it needs a variation or settlement.
80
+
81
+ ### 3. Do duplicate item codes get paid twice?
82
+
83
+ No. Only the first occurrence counts toward the period amount; the other rows are marked `是否计入=否` in the worksheet and raise `E_PROGRESS_DUP_ITEM`. Which row is the right one still needs a human decision.
84
+
85
+ ### 4. Does it modify or upload my CSV?
86
+
87
+ No. It reads the named CSVs, writes only under `$DSH_HOME/dsh-progress-payment/exports/`, and never uses the network or a model call.
88
+
89
+ ### 5. Can it read Excel directly?
90
+
91
+ No. Save the sheet as **CSV UTF-8** first. Excel-written UTF-8 CSVs with a BOM are accepted.
92
+
93
+ ## Version
94
+
95
+ `0.1.0-alpha.1` · 32 tests pass (`node --test test/*.test.mjs`).
96
+
97
+ > ⭐ If this helps, a star makes it easier for the next person to find it. Nothing is gated behind it.
98
+
99
+ ## Install
100
+
101
+ ```sh
102
+ dsh plugin --profile <profile> add dsh-progress-payment
103
+ dsh --profile <profile> --dump-config | grep dsh-progress-payment
104
+ ```
105
+
106
+ Uninstall:
107
+
108
+ ```sh
109
+ dsh plugin --profile <profile> remove dsh-progress-payment
110
+ ```
111
+
112
+ ### Install channels
113
+
114
+ - **npm (recommended):** `dsh plugin --profile <profile> add dsh-progress-payment`
115
+ - **git channel:** `dsh plugin --profile <profile> add github:PerryLink/dsh-progress-payment`
116
+ - **tarball:** `pnpm pack`, then `dsh plugin --profile <profile> add ./dsh-progress-payment-<version>.tgz`
117
+
118
+ ## Tools
119
+
120
+ Tool names are stable API; descriptions stay in English to match runtime output.
121
+
122
+ | Tool | Purpose | Risk |
123
+ |---|---|---|
124
+ | `progress.ingest` | Import a declaration CSV and an optional contract baseline; returns `batch_id`; session memory only | R0 |
125
+ | `progress.audit` | Period amount, cumulative ratio, over-quantity, price mismatch, cumulative-over-contract and duplicate items; returns the issue list; integer cents | R0 |
126
+ | `progress.export` | Re-run the audit and write the review worksheet CSV (UTF-8 BOM); returns path, rows, sha256 | R1 local write |
127
+
128
+ ## Audit rules
129
+
130
+ 1. **Amount:** `period amount = period qty × contract unit price`, rounded half-up to whole cents; cumulative is computed the same way.
131
+ 2. **Cumulative ratio:** `cumulative amount ÷ contract amount × 100`, two decimals; a zero contract amount yields 0.
132
+ 3. **Over quantity:** `period_qty > contract_qty` or `cumulative_qty > contract_qty` → `E_PROGRESS_OVER_QTY`.
133
+ 4. **Price mismatch:** declared contract unit price ≠ baseline unit price → `E_PROGRESS_PRICE_MISMATCH`; `price_tolerance_bps` relaxes it (default 0 = exact).
134
+ 5. **Cumulative > contract quantity:** the `cumulative_over_contract` kind; the ratio can exceed 100%.
135
+ 6. **Duplicate item:** the same `item_code` appears more than once → `E_PROGRESS_DUP_ITEM`; only the first occurrence is counted.
136
+ 7. **Missing / mismatched baseline:** `E_PROGRESS_CONTRACT_MISSING` / `E_PROGRESS_CONTRACT_MISMATCH`.
137
+ 8. **Cumulative below period:** `E_PROGRESS_QTY_INCONSISTENT`, usually a wrong opening cumulative.
138
+
139
+ ## Quick start
140
+
141
+ ```sh
142
+ # 1) import the declaration (tool surface)
143
+ # progress.ingest({ declaration_csv, contract_csv })
144
+
145
+ # 2) audit (tool surface)
146
+ # progress.audit({ batch_id })
147
+
148
+ # 3) export the worksheet (tool surface)
149
+ # progress.export({ batch_id, filename: "progress-audit-2026-10.csv" })
150
+ ```
151
+
152
+ Or run the sample:
153
+
154
+ ```sh
155
+ node samples/quickstart/run.mjs --check
156
+ ```
157
+
158
+ ## Acceptance evidence
159
+
160
+ Public/synthetic fixtures live in `samples/quickstart/`; `ACCEPTANCE.csv` records the checks. Every row is `counted=false` except the quickstart row.
161
+
162
+ | req_id | metric | threshold | actual | pass | source | counted |
163
+ |---|---|---|---|---|---|---|
164
+ | PG-A02 | period amount (cents) | 5076360 | 5076360 | true | public/synthetic | false |
165
+ | PG-A06 | price mismatch | E_PROGRESS_PRICE_MISMATCH x1 | 1 | true | public/synthetic | false |
166
+ | PS1-QS01 | quickstart golden | 1/1 | 1 | true | synthetic/quickstart | true |
167
+
168
+ *Fixture-backed rows, not a customer run; no output is invented.*
169
+
170
+ ## Limits and known limitations
171
+
172
+ - **Quantity/price only:** no judgement on variations, claims, retention, tax or pay ratios; those still need the contract and a human.
173
+ - **One price basis:** the declaration's `contract_unit_price` is the pricing basis; there is no current-price or index-price column.
174
+ - **No automatic duplicate choice:** duplicates are listed and only the first row is counted; a human must pick the right one.
175
+ - **Amount ceiling:** a single line must stay inside the JavaScript safe-integer range; otherwise `E_PROGRESS_CSV_ROW`.
176
+ - **CSV only:** no xlsx, PDF or scanned documents.
177
+ - Public/synthetic samples only; alpha/partial, not counted, no GA or production-readiness claim.
178
+
179
+ ## Development
180
+
181
+ ```sh
182
+ pnpm install --frozen-lockfile
183
+ pnpm build && pnpm lint && pnpm typecheck
184
+ node --test test/*.test.mjs
185
+ node scripts/gate.mjs
186
+ ```
187
+
188
+ ## Compatibility
189
+
190
+ | Surface | Status |
191
+ |---|---|
192
+ | Harness | `dsh >=0.2.1-rc.3 <0.4.0` |
193
+ | Node | `>=24.9.0 <25` |
194
+ | Platforms | All; local files only |
195
+ | Data | No network, no model call, no upload |
196
+
197
+ ## Related work
198
+
199
+ - [dsh-ifc-qto](https://github.com/PerryLink/dsh-ifc-qto) (model quantities, a cross-check for declared quantities)
200
+ - [dsh-ap-three-way](https://github.com/PerryLink/dsh-ap-three-way) (payment invoice / PO / GRN three-way match)
201
+ - [Domain index](https://perrylink.github.io/dsh-plugins/)
202
+
203
+ ## License
204
+
205
+ Apache-2.0. See `LICENSE`, `NOTICE`, `THIRD-PARTY-NOTICES`.