From 424304d58e1acbe096fad794605906482c3a2ef7 Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期二, 19 八月 2025 16:42:51 +0800
Subject: [PATCH] 1.销售台账联调 2.开票登记开发联调

---
 src/utils/summarizeTable.js |   57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 57 insertions(+), 0 deletions(-)

diff --git a/src/utils/summarizeTable.js b/src/utils/summarizeTable.js
new file mode 100644
index 0000000..1ad480d
--- /dev/null
+++ b/src/utils/summarizeTable.js
@@ -0,0 +1,57 @@
+/**
+ * 閫氱敤鐨勮〃鏍煎悎璁℃柟娉�
+ * @param {Object} param - 鍖呭惈琛ㄦ牸鍒楅厤缃拰鏁版嵁婧愮殑瀵硅薄
+ * @param {Array<string>} summaryProps - 闇�瑕佹眹鎬荤殑瀛楁鍚嶆暟缁�
+ * @param {Object} specialFormat - 鐗规畩鏍煎紡鍖栬鍒欙細瀛楁鍚� -> 鏍煎紡鍖栭�夐」锛堝鏄惁鍘绘帀灏忔暟锛�
+ * @returns {Array} 鍚堣琛屾暟鎹�
+ */
+const summarizeTable = (param, summaryProps, specialFormat = {}) => {
+  const { columns, data } = param;
+  const sums = [];
+  columns.forEach((column, index) => {
+    if (index === 0) {
+      sums[index] = "鍚堣";
+      return;
+    }
+    const prop = column.property;
+    if (summaryProps.includes(prop)) {
+      const values = data.map((item) => Number(item[prop]));
+      // 鍙鏈夋晥鏁板瓧杩涜姹傚拰
+      if (!values.every(isNaN)) {
+        const sum = values.reduce(
+          (acc, val) => (!isNaN(val) ? acc + val : acc),
+          0
+        );
+        if (specialFormat[prop] && specialFormat[prop].noDecimal) {
+          // 濡傛灉鎸囧畾浜嗕笉闇�瑕佷繚鐣欏皬鏁帮紝鍒欑洿鎺ヨ浆鎹负鏁存暟
+          sums[index] = Math.round(sum).toString();
+        } else {
+          // 榛樿淇濈暀涓や綅灏忔暟
+          sums[index] = parseFloat(sum).toFixed(
+            specialFormat[prop]?.decimalPlaces ?? 2
+          );
+        }
+      } else {
+        sums[index] = "";
+      }
+    } else {
+      sums[index] = "";
+    }
+  });
+  return sums;
+};
+// 涓嶅惈绋庢�讳环璁$畻
+const calculateTaxExclusiveTotalPrice = (taxInclusiveTotalPrice, taxRate) => {
+  const taxRateDecimal = taxRate / 100;
+  return (taxInclusiveTotalPrice / (1 + taxRateDecimal)).toFixed(2);
+};
+// 鍚◣鎬讳环璁$畻
+const calculateTaxIncludeTotalPrice = (taxInclusiveUnitPrice, quantity) => {
+  return (taxInclusiveUnitPrice * quantity).toFixed(2);
+};
+// 瀵煎嚭鍑芥暟渚涘叾浠栨枃浠朵娇鐢�
+export {
+  summarizeTable,
+  calculateTaxExclusiveTotalPrice,
+  calculateTaxIncludeTotalPrice,
+};

--
Gitblit v1.9.3