Explorar el Código

feat(util): 信息价获取

zhangweicheng hace 4 años
padre
commit
c0c2e85fa5
Se han modificado 3 ficheros con 29 adiciones y 1 borrados
  1. 1 1
      util/package.json
  2. 27 0
      util/src/glj.ts
  3. 1 0
      util/src/index.ts

+ 1 - 1
util/package.json

@@ -22,9 +22,9 @@
     "@commitlint/config-conventional": "^11.0.0",
     "@sc/types": "^1.0.28",
     "@types/chai": "^4.2.14",
+    "@types/lodash": "^4.14.168",
     "@types/mocha": "^8.0.4",
     "@types/ms": "^0.7.31",
-    "@types/lodash": "^4.14.168",
     "@typescript-eslint/eslint-plugin": "^4.4.1",
     "@typescript-eslint/parser": "^4.4.1",
     "chai": "^4.2.0",

+ 27 - 0
util/src/glj.ts

@@ -0,0 +1,27 @@
+import { IBaseGlj, IInfoPriceItem, TaxType } from '@sc/types';
+
+export const getInfoMarketPrice = (info: IInfoPriceItem, taxType: TaxType) => {
+  // 1: 一般计税 2: 简易计税
+  const fieldArray = ['noTaxPrice']; // 一般计税 - 不含税价 || 简易计税 - 含税价
+  if (taxType === TaxType.GENERAL) {
+    fieldArray.push('taxPrice');
+  } else {
+    fieldArray.unshift('taxPrice');
+  }
+  // 一个放后面,一个放前面
+  let infoPrice = (info as any)[fieldArray[0]];
+  if (infoPrice === null || infoPrice === undefined) infoPrice = (info as any)[fieldArray[1]]; // 信息价只有一个价格(含税价/不含税价),则不分计税方式,套用仅有的价格。
+  return parseFloat(infoPrice);
+};
+
+// 返回五大项组成的索引
+export const getIndex = (obj: IBaseGlj, pops = ['code', 'name', 'specs', 'unit', 'type']): string => {
+  let index = '';
+  const arr = [];
+  for (const p of pops) {
+    const tmpK = obj[p] === undefined || obj[p] === null || obj[p] === '' ? 'null' : obj[p];
+    arr.push(tmpK);
+  }
+  index = arr.join('|-|');
+  return index;
+};

+ 1 - 0
util/src/index.ts

@@ -2,3 +2,4 @@ export * from './math';
 export * from './bill';
 export * from './rationAss';
 export * from './reg';
+export * from './glj';