opc-finance-mcp 0.1.2 → 0.2.0

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.
Files changed (3) hide show
  1. package/README.md +8 -0
  2. package/package.json +1 -1
  3. package/src/index.js +130 -0
package/README.md CHANGED
@@ -73,11 +73,19 @@ npm run inspect
73
73
  | `finance_health_check` | 数据体检(借贷平衡、异常余额) | 只读 |
74
74
  | `finance_query_tax` | 申报期参数与销售额 | 只读 |
75
75
  | `finance_list_attachments` | 票据资料 | 只读 |
76
+ | `finance_set_attachment_kind` | 给票据打业务标签(进项/销项/流水…) | 传票 |
77
+ | `finance_list_employees` | 员工档案(社保基数、公积金比例、专项附加扣除) | 只读 |
78
+ | `finance_calc_payroll` | 算一期工资(个税用累计预扣预缴法),**不落库** | 只读 |
79
+ | `finance_get_payroll` | 已保存的工资表 + 计提/发放两套分录 | 只读 |
76
80
  | `finance_create_voucher` | 新增凭证 | 可写 |
77
81
  | `finance_reverse_voucher` | 红冲凭证 | 可写 |
82
+ | `finance_save_payroll` | 保存一期工资表 | 可写 |
78
83
  | `finance_upload_attachment` | 上传本地文件到票据库 | 传票 |
79
84
  | `finance_link_attachments` | 把票据挂到凭证(只加不减) | 可写 |
80
85
 
86
+ 工资与个税的口径见 `finance_calc_payroll` 的描述,或直接看 Skill 的
87
+ `workflows/工资与个税.md` —— 个税算错不会让账不平,但年底汇算会爆。
88
+
81
89
  ## 五、几条硬规则(AI 也绕不过)
82
90
 
83
91
  1. **借贷必平**:后端校验,不平直接拒,不会「先存着」。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opc-finance-mcp",
3
- "version": "0.1.2",
3
+ "version": "0.2.0",
4
4
  "description": "OPC智能财务 MCP Server —— 让 AI 客户端直接查账、记账、传票",
5
5
  "license": "UNLICENSED",
6
6
  "private": false,
package/src/index.js CHANGED
@@ -651,6 +651,136 @@ tool('finance_query_tax', {
651
651
  ].join('\n'));
652
652
  });
653
653
 
654
+ /* ================================================================
655
+ * 工资与个税
656
+ * ================================================================ */
657
+
658
+ tool('finance_list_employees', {
659
+ title: '查看员工档案',
660
+ description: '列出在职员工及其社保基数、公积金比例、六项专项附加扣除。'
661
+ + '算工资前先看一眼:基数或扣除填错,个税就跟着错。',
662
+ inputSchema: {},
663
+ }, async () => {
664
+ const d = await request('/api/employees');
665
+ const rows = d.rows || [];
666
+ if (!rows.length) return ok('还没有员工。先在网页「工资 → 新增员工」建档。');
667
+ return ok([
668
+ `# 在职员工(${rows.length} 人)`,
669
+ '',
670
+ '| id | 姓名 | 社保基数 | 公积金基数 | 公积金(个人/单位) | 专项附加扣除合计/月 |',
671
+ '| --- | --- | --- | --- | --- | --- |',
672
+ ...rows.map(e => {
673
+ const add = Number(e.deduct_child || 0) + Number(e.deduct_edu || 0) + Number(e.deduct_housing || 0)
674
+ + Number(e.deduct_rent || 0) + Number(e.deduct_elder || 0) + Number(e.deduct_medical || 0);
675
+ return `| ${e.id} | ${e.name} | ${e.si_base ?? '—'} | ${e.hf_base ?? '—'} | `
676
+ + `${e.hf_rate_p ?? '—'} / ${e.hf_rate_c ?? '—'} | ${add} |`;
677
+ }),
678
+ ].join('\n'));
679
+ });
680
+
681
+ tool('finance_calc_payroll', {
682
+ title: '算一期工资(预览,不落库)',
683
+ description: '按累计预扣预缴法算某月每个人的社保公积金、个税与实发。'
684
+ + '只算不改,可以放心反复调。改完确认无误再用 finance_save_payroll 保存。'
685
+ + '不传 items 时按在职员工档案出一张空表。',
686
+ inputSchema: {
687
+ period: z.string().regex(/^\d{4}-\d{2}$/).describe('工资所属期间,如 2026-10'),
688
+ items: z.array(z.object({
689
+ employee_id: z.number().int().positive(),
690
+ base_pay: z.number().min(0).optional().describe('基本工资'),
691
+ post_pay: z.number().min(0).optional().describe('岗位工资'),
692
+ perf_pay: z.number().min(0).optional().describe('绩效工资'),
693
+ overtime_pay: z.number().min(0).optional().describe('加班工资'),
694
+ allowance: z.number().min(0).optional().describe('津贴补贴'),
695
+ bonus: z.number().min(0).optional().describe('奖金'),
696
+ other_pay: z.number().min(0).optional().describe('其他收入'),
697
+ other_deduct: z.number().min(0).optional().describe('其他扣款(如借款扣回)'),
698
+ })).optional().describe('每人本月收入;不填的员工本月不发薪,会被整行跳过'),
699
+ },
700
+ }, async ({ period, items }) => {
701
+ const d = await request('/api/payroll/preview', { method: 'POST', body: { period, items } });
702
+ const rows = (d.rows || []).filter(r => Number(r.gross || 0) > 0);
703
+ if (!rows.length) return ok(`${period} 没有人发薪。`);
704
+ const t = d.totals || {};
705
+ return ok([
706
+ `# ${period} 工资表(预览,未保存)`,
707
+ '',
708
+ '| 姓名 | 应发 | 社保(个人) | 公积金(个人) | 个税 | 实发 |',
709
+ '| --- | --- | --- | --- | --- | --- |',
710
+ ...rows.map(r => `| ${r.name} | ${money(r.gross)} | ${money(r.si_personal)} | `
711
+ + `${money(r.hf_personal)} | ${money(r.tax)} | ${money(r.net)} |`),
712
+ '',
713
+ `合计 ${t.headcount ?? rows.length} 人:应发 ${money(t.gross)},`
714
+ + `个税 ${money(t.tax)},实发 ${money(t.net)},单位社保公积金 ${money((t.si_company || 0) + (t.hf_company || 0))}。`,
715
+ '',
716
+ '个税按累计预扣预缴法算的(2019 年起口径),已含本年以往月份的累计。',
717
+ '确认无误后用 finance_save_payroll 保存,再用 finance_create_voucher 出凭证。',
718
+ ].join('\n'));
719
+ });
720
+
721
+ tool('finance_save_payroll', {
722
+ title: '保存一期工资表',
723
+ description: '把算好的工资表落到账套里。期间必须未结账;已发放的期间会拒绝(409)。',
724
+ inputSchema: {
725
+ period: z.string().regex(/^\d{4}-\d{2}$/).describe('工资所属期间,如 2026-10'),
726
+ items: z.array(z.object({
727
+ employee_id: z.number().int().positive(),
728
+ base_pay: z.number().min(0).optional(),
729
+ post_pay: z.number().min(0).optional(),
730
+ perf_pay: z.number().min(0).optional(),
731
+ overtime_pay: z.number().min(0).optional(),
732
+ allowance: z.number().min(0).optional(),
733
+ bonus: z.number().min(0).optional(),
734
+ other_pay: z.number().min(0).optional(),
735
+ other_deduct: z.number().min(0).optional(),
736
+ })).min(1).describe('每人本月收入'),
737
+ },
738
+ }, async ({ period, items }) => {
739
+ const d = await request('/api/payroll', { method: 'POST', body: { period, items } });
740
+ const t = d.totals || {};
741
+ return ok([
742
+ `✅ 已保存 ${period} 工资表(${t.headcount ?? items.length} 人):`
743
+ + `应发 ${money(t.gross)},实发 ${money(t.net)},个税 ${money(t.tax)}。`,
744
+ '',
745
+ '下一步:出凭证。计提记在归属月、发放记在实际发薪日(通常次月),**必须分两张**,',
746
+ '混成一张会让申报期费用数与银行流水对不上。',
747
+ `分录用 finance_get_payroll({ period: '${period}' }) 取,或到网页「工资」页点按钮生成。`,
748
+ ].join('\n'));
749
+ });
750
+
751
+ tool('finance_get_payroll', {
752
+ title: '读取已保存的工资表',
753
+ description: '读某期已保存的工资表,含每个人的明细与整套计提/发放分录。'
754
+ + '想看「这期工资该怎么做凭证」就用它。',
755
+ inputSchema: {
756
+ period: z.string().regex(/^\d{4}-\d{2}$/).describe('期间,如 2026-10'),
757
+ },
758
+ }, async ({ period }) => {
759
+ const d = await request('/api/payroll' + qs({ period }));
760
+ if (!d.exists) return ok(`${period} 还没有保存过工资表。`);
761
+ const t = d.totals || {};
762
+ const lines = [
763
+ `# ${period} 工资表(已保存,状态 ${d.run?.status || '?'})`,
764
+ '',
765
+ '| 姓名 | 应发 | 社保(个人) | 公积金(个人) | 个税 | 实发 |',
766
+ '| --- | --- | --- | --- | --- | --- |',
767
+ ...(d.rows || []).filter(r => Number(r.gross || 0) > 0)
768
+ .map(r => `| ${r.name} | ${money(r.gross)} | ${money(r.si_personal)} | `
769
+ + `${money(r.hf_personal)} | ${money(r.tax)} | ${money(r.net)} |`),
770
+ '',
771
+ `合计:应发 ${money(t.gross)},实发 ${money(t.net)},个税 ${money(t.tax)}。`,
772
+ ];
773
+ for (const [label, key] of [['计提凭证', 'accrue'], ['发放凭证', 'pay']]) {
774
+ const es = (d.voucher || {})[key] || [];
775
+ if (!es.length) continue;
776
+ lines.push('', `**${label}**`, '', '| 科目 | 摘要 | 借方 | 贷方 |', '| --- | --- | --- | --- |');
777
+ for (const e of es) {
778
+ lines.push(`| ${e.account_code} | ${e.summary} | ${e.debit ? money(e.debit) : ''} | ${e.credit ? money(e.credit) : ''} |`);
779
+ }
780
+ }
781
+ return ok(lines.join('\n'));
782
+ });
783
+
654
784
  /* ================================================================
655
785
  * 启动
656
786
  * ================================================================ */