dsh-workbench-salary 0.2.4 → 0.4.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.
package/lib/db/db.js CHANGED
@@ -12,7 +12,9 @@ const DDL = [
12
12
  `CREATE TABLE IF NOT EXISTS salary_record (
13
13
  id TEXT PRIMARY KEY,
14
14
  pay_date TEXT NOT NULL,
15
+ income_period TEXT,
15
16
  cycle TEXT NOT NULL DEFAULT 'monthly',
17
+ employment_type TEXT,
16
18
  ${MONEY_FIELDS.map((f) => f.column + " REAL NOT NULL DEFAULT 0").join(",\n ")},
17
19
  note TEXT NOT NULL DEFAULT '',
18
20
  created_at INTEGER NOT NULL,
@@ -26,11 +28,18 @@ const DDL = [
26
28
 
27
29
  export function ensureSchema(db) {
28
30
  for (const sql of DDL) db.exec(sql);
31
+ if (!db.prepare("PRAGMA table_info(salary_record)").all().some((col) => col.name === "income_period")) {
32
+ db.exec("ALTER TABLE salary_record ADD COLUMN income_period TEXT");
33
+ }
34
+ if (!db.prepare("PRAGMA table_info(salary_record)").all().some((col) => col.name === "employment_type")) {
35
+ db.exec("ALTER TABLE salary_record ADD COLUMN employment_type TEXT");
36
+ }
37
+ db.exec("CREATE INDEX IF NOT EXISTS idx_salary_income_period ON salary_record(income_period)");
29
38
  }
30
39
 
31
40
  export function salaryRow(r) {
32
41
  if (!r) return null;
33
- const out = { id: r.id, payDate: r.pay_date, cycle: r.cycle };
42
+ const out = { id: r.id, payDate: r.pay_date, incomePeriod: r.income_period ?? null, cycle: r.cycle, employmentType: r.employment_type ?? null };
34
43
  for (const field of MONEY_FIELDS) out[field.key] = Number(r[field.column]) || 0;
35
44
  out.note = r.note || "";
36
45
  out.createdAt = r.created_at;
@@ -39,4 +48,4 @@ export function salaryRow(r) {
39
48
  return out;
40
49
  }
41
50
 
42
- export const COLUMNS = ["id", "pay_date", "cycle", ...MONEY_COLUMNS, "note", "created_at", "updated_at", "rev"];
51
+ export const COLUMNS = ["id", "pay_date", "income_period", "cycle", "employment_type", ...MONEY_COLUMNS, "note", "created_at", "updated_at", "rev"];
@@ -1,5 +1,6 @@
1
1
  /** 工资 action:读、写都允许 agent(用户口述后可直接落库);数据页查询仅 UI。 */
2
- import { MONEY_FIELDS } from "./model.js";
2
+ import { EMPLOYMENT_VALUES, MONEY_FIELDS } from "./model.js";
3
+ import { COLUMNS } from "../db/db.js";
3
4
 
4
5
  const obj = (properties, required = []) => ({ type: "object", properties, required, additionalProperties: false });
5
6
  const str = (description) => ({ type: "string", description });
@@ -56,19 +57,23 @@ export function registerSalaryActions(api, salary) {
56
57
  });
57
58
  action("salary.stats", {
58
59
  description: "只读:年度工资统计(按月聚合的实发/应发/个税/社保、月均、环比、最近月构成)",
59
- input: obj({ year: num("年份 2000–2100,默认今年") }),
60
- execute: (args) => salary.stats({ year: args.year }),
60
+ input: obj({
61
+ year: num("年份 2000–2100,默认今年"),
62
+ basis: { type: "string", enum: ["arrival", "income"], description: "arrival 按到账月(默认);income 按所属月,未归属不计入" },
63
+ }),
64
+ execute: (args) => salary.stats({ year: args.year, basis: args.basis }),
61
65
  });
62
66
  action("salary.recordList", {
63
- description: "只读:按日期倒序列出工资记录,可按年、日期区间、日结/月结筛选",
67
+ description: "只读:按日期倒序列出工资记录,可按年、日期区间、结算方式、用工类型筛选",
64
68
  input: obj({
65
69
  year: num("只取该年(按发薪日期)"),
66
70
  from: str("开始日期 YYYY-MM-DD(含)"),
67
71
  to: str("结束日期 YYYY-MM-DD(含)"),
68
- cycle: { type: "string", enum: ["monthly", "daily"], description: "月结 / 日结" },
72
+ cycle: { type: "string", enum: ["monthly", "daily"], description: "结算方式:月结 / 日结" },
73
+ employmentType: { type: "string", enum: EMPLOYMENT_VALUES, description: "用工类型:临时/兼职/外快/实习/试用/正式(temp/parttime/side/intern/probation/regular)" },
69
74
  limit: num("1–500,默认 200"),
70
75
  }),
71
- execute: (args) => salary.list({ year: args.year, from: args.from, to: args.to, cycle: args.cycle, limit: args.limit }),
76
+ execute: (args) => salary.list({ year: args.year, from: args.from, to: args.to, cycle: args.cycle, employmentType: args.employmentType, limit: args.limit }),
72
77
  });
73
78
  action("salary.recordGet", {
74
79
  description: "只读:单笔工资详情(全部收入项与扣款项)",
@@ -79,22 +84,26 @@ export function registerSalaryActions(api, salary) {
79
84
  description: "新增一笔工资(会写库,agent 可直接调用):按发薪日期记录日结/月结工资,金额缺省 0,应发与实发默认由明细推导",
80
85
  input: obj({
81
86
  payDate: str("发薪日期 YYYY-MM-DD,必填;月结通常取当月 15 号"),
82
- cycle: { type: "string", enum: ["monthly", "daily"], description: "月结 monthly(默认)/ 日结 daily" },
87
+ incomePeriod: str("工资所属期 YYYY-MM 或 YYYY-MM-DD;空串表示未归属;不传则月结取上月、日结取到账日"),
88
+ cycle: { type: "string", enum: ["monthly", "daily"], description: "结算方式:月结 monthly(默认)/ 日结 daily" },
89
+ employmentType: { type: "string", enum: EMPLOYMENT_VALUES, description: "用工类型:临时/兼职/外快/实习/试用/正式(temp/parttime/side/intern/probation/regular);可选,不传为未设置" },
83
90
  ...MONEY_SCHEMA,
84
91
  note: str("备注,可选"),
85
92
  }, ["payDate"]),
86
- execute: (args) => salary.create({ payDate: args.payDate, cycle: args.cycle, note: args.note, ...amountsFrom(args) }),
93
+ execute: (args) => salary.create({ payDate: args.payDate, incomePeriod: args.incomePeriod, cycle: args.cycle, employmentType: args.employmentType, note: args.note, ...amountsFrom(args) }),
87
94
  });
88
95
  action("salary.recordUpdate", {
89
96
  description: "修改一笔工资(会写库;只覆盖传入字段,金额改动后重算应发与实发)",
90
97
  input: obj({
91
98
  id: str("工资记录 id,必填"),
92
99
  payDate: str("发薪日期 YYYY-MM-DD"),
93
- cycle: { type: "string", enum: ["monthly", "daily"], description: "月结 / 日结" },
100
+ incomePeriod: str("工资所属期 YYYY-MM 或 YYYY-MM-DD;空串清除,不传保留原值"),
101
+ cycle: { type: "string", enum: ["monthly", "daily"], description: "结算方式:月结 / 日结" },
102
+ employmentType: { type: "string", enum: EMPLOYMENT_VALUES, description: "用工类型:临时/兼职/外快/实习/试用/正式(temp/parttime/side/intern/probation/regular);传空串清除" },
94
103
  ...MONEY_SCHEMA,
95
104
  note: str("备注"),
96
105
  }, ["id"]),
97
- execute: (args) => salary.update({ id: args.id, payDate: args.payDate, cycle: args.cycle, note: args.note, ...amountsFrom(args) }),
106
+ execute: (args) => salary.update({ id: args.id, payDate: args.payDate, incomePeriod: args.incomePeriod, cycle: args.cycle, employmentType: args.employmentType, note: args.note, ...amountsFrom(args) }),
98
107
  });
99
108
  action("salary.recordDelete", {
100
109
  description: "软删除一笔工资(会写库;记录不再出现在列表与统计中)",
@@ -107,7 +116,7 @@ export function registerSalaryActions(api, salary) {
107
116
  execute: () => ({
108
117
  tables: [{
109
118
  name: "salary_record",
110
- columns: ["id", "pay_date", "cycle", ...MONEY_FIELDS.map((f) => f.column), "note", "created_at", "updated_at", "rev"],
119
+ columns: COLUMNS,
111
120
  }],
112
121
  }),
113
122
  });
@@ -125,7 +134,7 @@ export function registerSalaryActions(api, salary) {
125
134
  input: obj({}),
126
135
  execute: () => ({
127
136
  shellVersion: api.shellVersion || "",
128
- domains: [{ id: "wb-addon-salary", version: (api.addon && api.addon.version) || "0.1.0" }],
137
+ domains: [{ id: "wb-addon-salary", version: (api.addon && api.addon.version) || "0.4.0" }],
129
138
  actions: defs.filter((d) => d.name !== "salary.actionSchema").map((d) => ({ ...d, domain: "wb-addon-salary", examples: [] })),
130
139
  }),
131
140
  });
@@ -35,6 +35,31 @@ export const TAX_KEYS = ["incomeTax", "postTaxDeduction"];
35
35
  export const CYCLE_VALUES = ["monthly", "daily"];
36
36
  export const CYCLE_LABELS = { monthly: "月结", daily: "日结" };
37
37
 
38
+ /**
39
+ * 用工类型:与结算方式(月结/日结)相互独立。
40
+ * 只用于分类与统计切片,不参与金额推导;旧记录可为空(未设置)。
41
+ */
42
+ export const EMPLOYMENT_TYPES = [
43
+ { value: "temp", label: "临时" },
44
+ { value: "parttime", label: "兼职" },
45
+ { value: "side", label: "外快" },
46
+ { value: "intern", label: "实习" },
47
+ { value: "probation", label: "试用" },
48
+ { value: "regular", label: "正式" },
49
+ ];
50
+ export const EMPLOYMENT_VALUES = EMPLOYMENT_TYPES.map((t) => t.value);
51
+ export const EMPLOYMENT_LABELS = Object.fromEntries(EMPLOYMENT_TYPES.map((t) => [t.value, t.label]));
52
+
53
+ /** 空串/null 表示未设置;其它值必须在枚举内。 */
54
+ export function normalizeEmploymentType(value) {
55
+ if (value === undefined || value === null || value === "") return null;
56
+ const v = String(value).trim().toLowerCase();
57
+ if (!EMPLOYMENT_VALUES.includes(v)) {
58
+ throw new Error("用工类型只支持:" + EMPLOYMENT_TYPES.map((t) => t.label + "(" + t.value + ")").join("、"));
59
+ }
60
+ return v;
61
+ }
62
+
38
63
  export function round2(value) {
39
64
  const n = Number(value);
40
65
  if (!Number.isFinite(n)) return 0;
@@ -7,6 +7,7 @@ import {
7
7
  hasValue,
8
8
  netFromGross,
9
9
  normalizeCycle,
10
+ normalizeEmploymentType,
10
11
  requireDate,
11
12
  round2,
12
13
  sumKeys,
@@ -17,6 +18,21 @@ import {
17
18
  const PAD = (n) => String(n).padStart(2, "0");
18
19
  const MONTH_OF = (date) => Number(String(date).slice(5, 7));
19
20
 
21
+ function incomePeriod(value, payDate, cycle) {
22
+ if (value === null || value === "") return null;
23
+ if (value !== undefined) {
24
+ if (typeof value === "string" && /^\d{4}-\d{2}$/.test(value)) {
25
+ requireDate(`${value}-01`, "工资所属期");
26
+ return value;
27
+ }
28
+ return requireDate(value, "工资所属期");
29
+ }
30
+ if (cycle === "daily") return payDate;
31
+ const year = Number(payDate.slice(0, 4));
32
+ const month = MONTH_OF(payDate);
33
+ return month === 1 ? (year === 2000 ? null : `${year - 1}-12`) : `${year}-${PAD(month - 1)}`;
34
+ }
35
+
20
36
  function yearNumber(value) {
21
37
  const year = Number(value) || new Date(now()).getFullYear();
22
38
  if (!Number.isInteger(year) || year < 2000 || year > 2100) throw new Error("年份必须在 2000–2100 之间");
@@ -49,7 +65,7 @@ export function createSalary({ db, host, log }) {
49
65
  const latest = one("SELECT * FROM salary_record WHERE deleted_at IS NULL ORDER BY pay_date DESC, created_at DESC LIMIT 1");
50
66
  const y = one("SELECT COUNT(*) n, COALESCE(SUM(net_pay),0) net FROM salary_record WHERE deleted_at IS NULL AND substr(pay_date,1,4)=?", String(year));
51
67
  return {
52
- version: "0.1.0",
68
+ version: "0.4.0",
53
69
  records: total,
54
70
  latestDate: latest ? latest.pay_date : "",
55
71
  latestNetPay: latest ? round2(latest.net_pay) : 0,
@@ -78,6 +94,10 @@ export function createSalary({ db, host, log }) {
78
94
  where.push("cycle=?");
79
95
  params.push(normalizeCycle(input.cycle));
80
96
  }
97
+ if (hasValue(input.employmentType)) {
98
+ where.push("employment_type=?");
99
+ params.push(normalizeEmploymentType(input.employmentType));
100
+ }
81
101
  const clause = where.join(" AND ");
82
102
  const limit = Math.min(Math.max(Number(input.limit) || 200, 1), 500);
83
103
  const rows = all(`SELECT * FROM salary_record WHERE ${clause} ORDER BY pay_date DESC, created_at DESC LIMIT ?`, ...params, limit);
@@ -92,18 +112,22 @@ export function createSalary({ db, host, log }) {
92
112
  function create(input = {}) {
93
113
  const payDate = requireDate(input.payDate, "发薪日期");
94
114
  const cycle = normalizeCycle(input.cycle);
115
+ const employmentType = normalizeEmploymentType(input.employmentType);
116
+ const period = incomePeriod(input.incomePeriod, payDate, cycle);
95
117
  const money = moneyInput(input);
96
118
  const gross = hasValue(input.grossPay) ? money.grossPay : derivedTotals(money).gross;
97
119
  const net = hasValue(input.netPay) ? money.netPay : round2(Math.max(gross - sumKeys(money, SOCIAL_KEYS) - money.incomeTax - money.postTaxDeduction, 0));
98
120
  const id = newId("sal");
99
121
  const columns = MONEY_FIELDS.map((f) => f.column);
100
122
  const values = MONEY_FIELDS.map((f) => (f.key === "grossPay" ? gross : f.key === "netPay" ? net : money[f.key]));
101
- const placeholders = Array.from({ length: columns.length + 6 }, () => "?").join(", ");
123
+ const placeholders = Array.from({ length: columns.length + 8 }, () => "?").join(", ");
102
124
  run(
103
- `INSERT INTO salary_record (id, pay_date, cycle, ${columns.join(", ")}, note, created_at, updated_at) VALUES (${placeholders})`,
125
+ `INSERT INTO salary_record (id, pay_date, income_period, cycle, employment_type, ${columns.join(", ")}, note, created_at, updated_at) VALUES (${placeholders})`,
104
126
  id,
105
127
  payDate,
128
+ period,
106
129
  cycle,
130
+ employmentType,
107
131
  ...values,
108
132
  String(input.note === undefined ? "" : input.note).trim(),
109
133
  now(),
@@ -117,7 +141,9 @@ export function createSalary({ db, host, log }) {
117
141
  const row = record(input.id);
118
142
  const patch = {};
119
143
  if (input.payDate !== undefined) patch.payDate = requireDate(input.payDate, "发薪日期");
144
+ if (input.incomePeriod !== undefined) patch.incomePeriod = incomePeriod(input.incomePeriod);
120
145
  if (input.cycle !== undefined) patch.cycle = normalizeCycle(input.cycle);
146
+ if (input.employmentType !== undefined) patch.employmentType = normalizeEmploymentType(input.employmentType);
121
147
  if (input.note !== undefined) patch.note = String(input.note || "").trim();
122
148
  let moneyChanged = false;
123
149
  for (const field of MONEY_FIELDS) {
@@ -131,9 +157,11 @@ export function createSalary({ db, host, log }) {
131
157
  if (!hasValue(input.netPay) && (moneyChanged || hasValue(input.grossPay))) merged.netPay = netFromGross(merged);
132
158
  const assignments = MONEY_FIELDS.map((f) => f.column + "=?");
133
159
  run(
134
- `UPDATE salary_record SET pay_date=?, cycle=?, ${assignments.join(", ")}, note=?, updated_at=?, rev=rev+1 WHERE id=? AND deleted_at IS NULL`,
160
+ `UPDATE salary_record SET pay_date=?, income_period=?, cycle=?, employment_type=?, ${assignments.join(", ")}, note=?, updated_at=?, rev=rev+1 WHERE id=? AND deleted_at IS NULL`,
135
161
  merged.payDate,
162
+ merged.incomePeriod,
136
163
  merged.cycle,
164
+ merged.employmentType ?? null,
137
165
  ...MONEY_FIELDS.map((f) => merged[f.key]),
138
166
  merged.note,
139
167
  now(),
@@ -157,7 +185,12 @@ export function createSalary({ db, host, log }) {
157
185
 
158
186
  function stats(input = {}) {
159
187
  const year = yearNumber(input.year);
160
- const rows = all("SELECT * FROM salary_record WHERE deleted_at IS NULL AND substr(pay_date,1,4)=? ORDER BY pay_date, created_at", String(year)).map(salaryRow);
188
+ const basis = input.basis ?? "arrival";
189
+ if (basis !== "arrival" && basis !== "income") throw new Error("统计口径须为 arrival 或 income");
190
+ const dateColumn = basis === "income" ? "income_period" : "pay_date";
191
+ const groupDate = (row) => basis === "income" ? row.incomePeriod : row.payDate;
192
+ const rows = all(`SELECT * FROM salary_record WHERE deleted_at IS NULL AND ${dateColumn}>=? AND ${dateColumn}<? ORDER BY ${dateColumn}, pay_date, created_at, id`, `${year}-01`, `${year + 1}-01`).map(salaryRow);
193
+ const unassignedRecords = basis === "income" ? one("SELECT COUNT(*) n FROM salary_record WHERE deleted_at IS NULL AND income_period IS NULL").n : null;
161
194
  const monthly = Array.from({ length: 12 }, (_, i) => ({
162
195
  month: i + 1,
163
196
  period: `${year}-${PAD(i + 1)}`,
@@ -176,7 +209,7 @@ export function createSalary({ db, host, log }) {
176
209
  housingFund: 0,
177
210
  }));
178
211
  for (const row of rows) {
179
- const bucket = monthly[MONTH_OF(row.payDate) - 1];
212
+ const bucket = monthly[MONTH_OF(groupDate(row)) - 1];
180
213
  bucket.records += 1;
181
214
  bucket.basePay = round2(bucket.basePay + row.basePay);
182
215
  bucket.performancePay = round2(bucket.performancePay + row.performancePay);
@@ -208,9 +241,71 @@ export function createSalary({ db, host, log }) {
208
241
  const mom = latestMonth && previousMonth
209
242
  ? { amount: diff, percent: previousMonth.netPay ? round2((diff / previousMonth.netPay) * 100) : null }
210
243
  : null;
211
- const latestRows = latestMonth ? rows.filter((r) => MONTH_OF(r.payDate) === latestMonth.month) : [];
244
+ const latestRows = latestMonth ? rows.filter((r) => MONTH_OF(groupDate(r)) === latestMonth.month) : [];
245
+ // 年度/季度跨期聚合:口径与 monthly 完全一致(arrival 用 pay_date、income 用 income_period),
246
+ // 只对真实存在的年份/季度出点,空年空季不补 0,避免把「还没到的季度」画成 0。
247
+ const datedRows = all(
248
+ `SELECT * FROM salary_record WHERE deleted_at IS NULL AND ${dateColumn} IS NOT NULL ORDER BY ${dateColumn}, id`,
249
+ ).map(salaryRow);
250
+ const quarterOf = (date) => `${String(date).slice(0, 4)}-Q${Math.floor((Number(String(date).slice(5, 7)) - 1) / 3) + 1}`;
251
+ const aggregate = (bucketOf) => {
252
+ const map = new Map();
253
+ for (const row of datedRows) {
254
+ const bucket = bucketOf(basis === "income" ? row.incomePeriod : row.payDate);
255
+ if (!bucket) continue;
256
+ const acc = map.get(bucket) || { bucket, count: 0, netTotal: 0, grossTotal: 0, netMax: 0, grossMax: 0 };
257
+ acc.count += 1;
258
+ acc.netTotal = round2(acc.netTotal + row.netPay);
259
+ acc.grossTotal = round2(acc.grossTotal + row.grossPay);
260
+ acc.netMax = round2(Math.max(acc.netMax, row.netPay));
261
+ acc.grossMax = round2(Math.max(acc.grossMax, row.grossPay));
262
+ map.set(bucket, acc);
263
+ }
264
+ return [...map.values()]
265
+ .sort((a, b) => (a.bucket < b.bucket ? -1 : a.bucket > b.bucket ? 1 : 0))
266
+ .map((item) => ({ ...item, netAvg: round2(item.netTotal / item.count), grossAvg: round2(item.grossTotal / item.count) }));
267
+ };
268
+ const yearly = aggregate((date) => String(date).slice(0, 4));
269
+ // 季度折线默认展示最近 8 个有记录的季度,数据不足时就是实际有几个画几个。
270
+ const quarterly = aggregate(quarterOf).slice(-8);
271
+ // 同比:上一年同期 12 个月的实发/应发,用于「今年 vs 去年」对照线。
272
+ const priorYear = year - 1;
273
+ const priorRows = all(
274
+ `SELECT * FROM salary_record WHERE deleted_at IS NULL AND ${dateColumn}>=? AND ${dateColumn}<? ORDER BY ${dateColumn}, id`,
275
+ `${priorYear}-01`,
276
+ `${priorYear + 1}-01`,
277
+ ).map(salaryRow);
278
+ const priorMonthly = Array.from({ length: 12 }, (_, i) => ({ month: i + 1, records: 0, netPay: 0, grossPay: 0 }));
279
+ for (const row of priorRows) {
280
+ const bucket = priorMonthly[MONTH_OF(groupDate(row)) - 1];
281
+ bucket.records += 1;
282
+ bucket.netPay = round2(bucket.netPay + row.netPay);
283
+ bucket.grossPay = round2(bucket.grossPay + row.grossPay);
284
+ }
285
+ // 单笔实发分布:按当前年份、当前口径的记录分档,档位边界写死便于核对。
286
+ const DIST_BUCKETS = [
287
+ { key: "lt5k", label: "5k 以下", upper: 5000 },
288
+ { key: "5to8k", label: "5k–8k", upper: 8000 },
289
+ { key: "8to12k", label: "8k–12k", upper: 12000 },
290
+ { key: "12to20k", label: "12k–20k", upper: 20000 },
291
+ { key: "gte20k", label: "20k 以上", upper: null },
292
+ ];
293
+ const distribution = DIST_BUCKETS.map((b, i) => ({ key: b.key, label: b.label, lower: i === 0 ? 0 : DIST_BUCKETS[i - 1].upper, upper: b.upper, count: 0 }));
294
+ for (const row of rows) {
295
+ const value = Math.max(0, row.netPay);
296
+ const hit = distribution.find((d) => d.upper === null || value < d.upper);
297
+ if (hit) hit.count += 1;
298
+ }
299
+ const peakMonth = monthsWithData.length
300
+ ? monthsWithData.reduce((best, b) => (b.netPay > best.netPay ? b : best), monthsWithData[0])
301
+ : null;
302
+ const lowestMonth = monthsWithData.length
303
+ ? monthsWithData.reduce((worst, b) => (b.netPay < worst.netPay ? b : worst), monthsWithData[0])
304
+ : null;
212
305
  return {
213
306
  year,
307
+ basis,
308
+ unassignedRecords,
214
309
  records: rows.length,
215
310
  months: monthsWithData.length,
216
311
  netTotal,
@@ -225,6 +320,13 @@ export function createSalary({ db, host, log }) {
225
320
  latestMonth: latestMonth ? { ...latestMonth, breakdown: breakdown(latestRows) } : null,
226
321
  previousMonth,
227
322
  mom,
323
+ yearly,
324
+ quarterly,
325
+ priorYear,
326
+ priorMonthly,
327
+ distribution,
328
+ peakMonth: peakMonth ? { month: peakMonth.month, period: peakMonth.period, netPay: peakMonth.netPay } : null,
329
+ lowestMonth: lowestMonth ? { month: lowestMonth.month, period: lowestMonth.period, netPay: lowestMonth.netPay } : null,
228
330
  };
229
331
  }
230
332
 
package/lib/index.js CHANGED
@@ -27,13 +27,13 @@ export function apply(ctx) {
27
27
  ctx.effect(() => host.registerDomain({
28
28
  id: "wb-addon-salary",
29
29
  title: "工资",
30
- description: "按日期记录日结/月结工资:收入项、税前扣款、社保公积金、个税与实发",
31
- version: "0.2.4",
30
+ description: "按日期记录日结/月结工资:用工类型、收入项、税前扣款、社保公积金、个税与实发",
31
+ version: "0.4.0",
32
32
  tables: ["salary_record"],
33
33
  sync: { tables: [] },
34
34
  views: VIEWS,
35
35
  capability: {
36
- summary: "记录每一笔工资的日期、类型与全部金额明细,按年/按月统计实发、应发、个税与社保;不做报销与支出流水。",
36
+ summary: "记录每一笔工资的日期、用工类型(实习/试用/正式等)、结算方式与全部金额明细,按年/按月统计实发、应发、个税与社保;不做报销与支出流水。",
37
37
  records: [{
38
38
  kind: "record",
39
39
  title: "工资记录",
@@ -45,6 +45,7 @@ export function apply(ctx) {
45
45
  }],
46
46
  fields: [
47
47
  { name: "payDate", type: "string", description: "发薪日期 YYYY-MM-DD;月结通常取当月 15 号" },
48
+ { name: "incomePeriod", type: "string", description: "工资所属期:YYYY-MM 或 YYYY-MM-DD,可独立修改" },
48
49
  { name: "cycle", type: "string", description: "monthly 月结(默认)/ daily 日结" },
49
50
  { name: "netPay", type: "number", description: "实发工资" },
50
51
  { name: "grossPay", type: "number", description: "应发税前工资" },
@@ -55,7 +56,7 @@ export function apply(ctx) {
55
56
  ],
56
57
  notFor: ["不做工资条 OCR", "不做多公司并行核算", "不存姓名等身份信息"],
57
58
  notes: [
58
- "同名日期允许多笔(日结可能一天多笔),统计按发薪日期所属月份聚合。",
59
+ "同日允许多笔;统计可按到账月或所属月聚合,未归属的旧记录仅纳入到账口径。",
59
60
  "金额在本机 SQLite 保存,随宿主备份;不参与云同步。",
60
61
  "agent 可新增、修改、软删除工资记录;删除后不再出现在列表与统计。",
61
62
  ],
@@ -70,7 +71,7 @@ export function apply(ctx) {
70
71
  let imported = 0;
71
72
  let failed = 0;
72
73
  for (const item of records) {
73
- try { engine.create(item); imported += 1; } catch { failed += 1; }
74
+ try { engine.create({ ...item, incomePeriod: item.incomePeriod ?? null }); imported += 1; } catch { failed += 1; }
74
75
  }
75
76
  return { imported, failed };
76
77
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-workbench-salary",
3
- "version": "0.2.4",
3
+ "version": "0.4.0",
4
4
  "description": "个人工作台工资插件:按发薪日期记录工资构成、扣款与实发",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -16,7 +16,7 @@
16
16
  "addon": {
17
17
  "id": "wb-addon-salary",
18
18
  "title": "工资",
19
- "version": "0.2.4",
19
+ "version": "0.4.0",
20
20
  "minShell": "0.8.0",
21
21
  "tables": [
22
22
  "salary_record"
@@ -43,7 +43,7 @@
43
43
  }
44
44
  },
45
45
  "dependencies": {
46
- "dsh-workbench-host": "^0.8.0"
46
+ "dsh-workbench-host": "^0.8.1"
47
47
  },
48
48
  "dsh": {
49
49
  "bundle": {