新增合同管理相关功能

This commit is contained in:
2026-09-11 18:22:22 +08:00
parent 840673bda5
commit 184c604bee
17 changed files with 2944 additions and 0 deletions
@@ -0,0 +1,62 @@
/**
* 合同组件工具:金额汇总计算(产品清单 → 各部分金额 / 总金额 / 总成本 / 总利润)
*
* 金额归属:
* - 硬件部分 = Σ 产品类别为「硬件(货物)」的小计
* - 软件部分 = Σ 产品类别为「软件(许可)」的小计
* - 其他部分 = Σ 服务 / 开发 / 其他类小计
* - 合同总金额 = 硬件 + 软件 + 其他
* - 产品总成本 = Σ (数量 × 成本单价)
* - 合同总利润 = 合同总金额 - 产品总成本
*/
const round2 = (n) => Math.round((Number(n) || 0) * 100) / 100;
export function buildSummary(products) {
const rows = Array.isArray(products) ? products : [];
let hardware = 0;
let software = 0;
let other = 0;
let totalCost = 0;
rows.forEach((row) => {
const qty = Number(row?.quantity) || 0;
const price = Number(row?.price) || 0;
const costPrice = Number(row?.cost_price) || 0;
const amount = round2(qty * price);
totalCost += round2(qty * costPrice);
const cat = String(row?.category || "");
if (cat === "1") hardware += amount;
else if (cat === "2") software += amount;
else other += amount;
});
hardware = round2(hardware);
software = round2(software);
other = round2(other);
const totalAmount = round2(hardware + software + other);
return {
hardware_amount: hardware,
software_amount: software,
other_amount: other,
total_amount: totalAmount,
total_cost: round2(totalCost),
total_profit: round2(totalAmount - round2(totalCost)),
};
}
/** 生成合同编号建议值:HT-YYYYMMDD-4位随机 */
export function genContractNo() {
const d = new Date();
const y = d.getFullYear();
const m = String(d.getMonth() + 1).padStart(2, "0");
const day = String(d.getDate()).padStart(2, "0");
const rand = String(Math.floor(Math.random() * 10000)).padStart(4, "0");
return `HT-${y}${m}${day}-${rand}`;
}
/** 甲乙丙丁角色 key,按 party_count 取前 n 个 */
export const PARTY_ROLES = [
{ key: "party_a", label: "甲方" },
{ key: "party_b", label: "乙方" },
{ key: "party_c", label: "丙方" },
{ key: "party_d", label: "丁方" },
];