kts-component-invoice-operate 3.1.12 → 3.1.13

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 (115) hide show
  1. package/.dumi/theme/builtins/API.tsx +66 -66
  2. package/.editorconfig +16 -16
  3. package/.fatherrc.ts +4 -4
  4. package/.prettierignore +7 -7
  5. package/.prettierrc +11 -11
  6. package/.umirc.ts +8 -8
  7. package/README.md +5 -5
  8. package/dist/Invoice/ui/GoodsList/hook/useColumns/autoFillFn/index.d.ts +2 -0
  9. package/dist/index.esm.js +2754 -3920
  10. package/dist/index.js +2754 -3920
  11. package/docs/index.md +5 -5
  12. package/index.html +12 -12
  13. package/package.json +59 -59
  14. package/src/Invoice/InvoiceController/InvoiceControllerForm/index.ts +94 -94
  15. package/src/Invoice/InvoiceController/InvoiceControllerState/BuyerState/index.tsx +88 -88
  16. package/src/Invoice/InvoiceController/InvoiceControllerState/GoodsListState/EndowCode/index.tsx +93 -93
  17. package/src/Invoice/InvoiceController/InvoiceControllerState/GoodsListState/IColumnsReplenish/index.ts +10 -10
  18. package/src/Invoice/InvoiceController/InvoiceControllerState/GoodsListState/IGood/index.ts +72 -72
  19. package/src/Invoice/InvoiceController/InvoiceControllerState/GoodsListState/ImportGoods/index.ts +80 -80
  20. package/src/Invoice/InvoiceController/InvoiceControllerState/GoodsListState/LineAttributeType/index.ts +5 -5
  21. package/src/Invoice/InvoiceController/InvoiceControllerState/GoodsListState/ProductComparison/index.ts +9 -9
  22. package/src/Invoice/InvoiceController/InvoiceControllerState/GoodsListState/index.ts +88 -88
  23. package/src/Invoice/InvoiceController/InvoiceControllerState/index.ts +48 -48
  24. package/src/Invoice/InvoiceController/fns/addGood.ts +11 -11
  25. package/src/Invoice/InvoiceController/fns/addGoodDiscount.ts +125 -125
  26. package/src/Invoice/InvoiceController/fns/delGood.ts +43 -43
  27. package/src/Invoice/InvoiceController/fns/getGoodsSearch.ts +23 -23
  28. package/src/Invoice/InvoiceController/fns/saveEditGood.ts +23 -23
  29. package/src/Invoice/InvoiceController/fns/setEditGood.ts +16 -16
  30. package/src/Invoice/InvoiceController/fns/setGoods.ts +10 -10
  31. package/src/Invoice/InvoiceController/fns/updateInvoiceNo.ts +8 -8
  32. package/src/Invoice/InvoiceController/index.ts +61 -61
  33. package/src/Invoice/_test/buyerNameSearch/index.tsx +41 -41
  34. package/src/Invoice/_test/deduction/index.tsx +935 -935
  35. package/src/Invoice/_test/draft/index.tsx +40 -40
  36. package/src/Invoice/_test/easiest/index.tsx +5 -5
  37. package/src/Invoice/_test/endowCode/index.tsx +1095 -1095
  38. package/src/Invoice/_test/goodsMenuExpand/index.tsx +32 -32
  39. package/src/Invoice/_test/importBuyer/index.tsx +74 -74
  40. package/src/Invoice/_test/importGoods/index.tsx +515 -515
  41. package/src/Invoice/_test/invoiceType/index.tsx +59 -59
  42. package/src/Invoice/_test/isInvoiceNo/index.tsx +12 -12
  43. package/src/Invoice/_test/replaceHead/index.tsx +22 -22
  44. package/src/Invoice/_test/retrieveData/index.tsx +22 -22
  45. package/src/Invoice/_test/seller/index.tsx +28 -28
  46. package/src/Invoice/_test/setDataSource/index.tsx +22 -22
  47. package/src/Invoice/_test/unit/index.tsx +19 -19
  48. package/src/Invoice/index.less +12 -12
  49. package/src/Invoice/index.md +53 -53
  50. package/src/Invoice/index.tsx +104 -104
  51. package/src/Invoice/tools/calculate/index.ts +97 -97
  52. package/src/Invoice/tools/coolingFn/index.ts +17 -17
  53. package/src/Invoice/tools/evaluate/index.ts +7 -7
  54. package/src/Invoice/tools/idGenerator/index.ts +2 -2
  55. package/src/Invoice/tools/itemName/index.ts +46 -46
  56. package/src/Invoice/tools/lazyFn/index.ts +19 -19
  57. package/src/Invoice/tools/strringFn/index.ts +40 -40
  58. package/src/Invoice/ui/AddComparisonDrawer/index.tsx +149 -149
  59. package/src/Invoice/ui/Buyer/index.less +219 -219
  60. package/src/Invoice/ui/Buyer/index.tsx +114 -114
  61. package/src/Invoice/ui/Buyer/ui/BuyerNameInput/index.tsx +166 -166
  62. package/src/Invoice/ui/Buyer/ui/ImportBuyerButton/index.tsx +21 -21
  63. package/src/Invoice/ui/EndowCodeDrawer/index.less +8 -8
  64. package/src/Invoice/ui/EndowCodeDrawer/index.tsx +445 -445
  65. package/src/Invoice/ui/GoodsList/hook/useColumns/autoFillFn/index.ts +513 -496
  66. package/src/Invoice/ui/GoodsList/hook/useColumns/index.tsx +618 -606
  67. package/src/Invoice/ui/GoodsList/hook/useColumns/ui/ItemNameInput/index.less +9 -9
  68. package/src/Invoice/ui/GoodsList/hook/useColumns/ui/ItemNameInput/index.tsx +34 -34
  69. package/src/Invoice/ui/GoodsList/hook/useColumns/ui/RowEditButton/index.tsx +30 -30
  70. package/src/Invoice/ui/GoodsList/hook/useColumns/ui/RowMenu/hook/_useAddComparison/index.tsx +43 -43
  71. package/src/Invoice/ui/GoodsList/hook/useColumns/ui/RowMenu/hook/useAddDiscount/index.tsx +76 -76
  72. package/src/Invoice/ui/GoodsList/hook/useColumns/ui/RowMenu/hook/useDelItem/index.tsx +35 -35
  73. package/src/Invoice/ui/GoodsList/hook/useColumns/ui/RowMenu/hook/useEndowCode/index.tsx +34 -34
  74. package/src/Invoice/ui/GoodsList/hook/useColumns/ui/RowMenu/index.less +13 -13
  75. package/src/Invoice/ui/GoodsList/hook/useColumns/ui/RowMenu/index.tsx +98 -98
  76. package/src/Invoice/ui/GoodsList/hook/useColumns/ui/RowSaveButton/index.tsx +14 -14
  77. package/src/Invoice/ui/GoodsList/hook/useColumns/ui/TitleText/index.tsx +20 -20
  78. package/src/Invoice/ui/GoodsList/hook/useDeduction/index.tsx +24 -24
  79. package/src/Invoice/ui/GoodsList/hook/useOnRow/index.tsx +39 -39
  80. package/src/Invoice/ui/GoodsList/hook/useRowSelection/index.tsx +111 -111
  81. package/src/Invoice/ui/GoodsList/hook/useToGenerateId/index.ts +8 -8
  82. package/src/Invoice/ui/GoodsList/hook/useWindowClick/index.tsx +23 -23
  83. package/src/Invoice/ui/GoodsList/index.less +177 -177
  84. package/src/Invoice/ui/GoodsList/index.tsx +177 -177
  85. package/src/Invoice/ui/GoodsList/ui/AddRowButton/index.tsx +61 -61
  86. package/src/Invoice/ui/GoodsList/ui/BulkMenu/hooks/useAddDiscountRowButton/index.less +21 -21
  87. package/src/Invoice/ui/GoodsList/ui/BulkMenu/hooks/useAddDiscountRowButton/index.tsx +244 -244
  88. package/src/Invoice/ui/GoodsList/ui/BulkMenu/hooks/useCommodityComparisonButton/index.tsx +75 -75
  89. package/src/Invoice/ui/GoodsList/ui/BulkMenu/hooks/useDelRowButton/index.tsx +66 -66
  90. package/src/Invoice/ui/GoodsList/ui/BulkMenu/hooks/useEndowCodeButton/index.tsx +58 -58
  91. package/src/Invoice/ui/GoodsList/ui/BulkMenu/index.tsx +37 -37
  92. package/src/Invoice/ui/GoodsList/ui/DescribeSwitch/index.tsx +36 -36
  93. package/src/Invoice/ui/GoodsList/ui/Search/index.less +10 -10
  94. package/src/Invoice/ui/GoodsList/ui/Search/index.tsx +50 -50
  95. package/src/Invoice/ui/GoodsList/ui/Statistics/index.less +18 -18
  96. package/src/Invoice/ui/GoodsList/ui/Statistics/index.tsx +109 -109
  97. package/src/Invoice/ui/GoodsList/ui/TableRow/index.tsx +29 -29
  98. package/src/Invoice/ui/GoodsList/ui/TableVirtual/index.less +38 -38
  99. package/src/Invoice/ui/GoodsList/ui/TableVirtual/index.tsx +105 -105
  100. package/src/Invoice/ui/GoodsList/ui/TableVirtual.o/index.less +44 -44
  101. package/src/Invoice/ui/GoodsList/ui/TableVirtual.o/index.tsx +96 -96
  102. package/src/Invoice/ui/GoodsList/ui/TaxIncludedSwitch/index.tsx +30 -30
  103. package/src/Invoice/ui/ImportBuyerDrawer/index.tsx +75 -75
  104. package/src/Invoice/ui/ImportGoodsDrawer/index.tsx +174 -174
  105. package/src/Invoice/ui/InvoiceHeader/index.less +68 -68
  106. package/src/Invoice/ui/InvoiceHeader/index.tsx +246 -246
  107. package/src/Invoice/ui/Seller/index.less +113 -113
  108. package/src/Invoice/ui/Seller/index.tsx +98 -98
  109. package/src/Invoice/ui/Sign/index.less +14 -14
  110. package/src/Invoice/ui/Sign/index.tsx +71 -71
  111. package/src/index.ts +6 -6
  112. package/tsconfig.json +31 -31
  113. package/typings.d.ts +3 -3
  114. package/yarn.e.lock +14331 -14331
  115. package/yarn.o.lock +14800 -14800
@@ -1,104 +1,104 @@
1
- import './index.less';
2
- import React from 'react';
3
- import InvoiceController from './InvoiceController';
4
- import InvoiceHeader from './ui/InvoiceHeader';
5
- import GoodsList from './ui/GoodsList';
6
- import useToGenerateId from './ui/GoodsList/hook/useToGenerateId';
7
- import Seller from './ui/Seller';
8
- import Sign from './ui/Sign';
9
- import Buyer from './ui/Buyer';
10
- import ImportBuyerDrawer from './ui/ImportBuyerDrawer';
11
- import ImportGoodsDrawer from './ui/ImportGoodsDrawer';
12
- import EndowCodeDrawer from './ui/EndowCodeDrawer';
13
- import AddComparisonDrawer from './ui/AddComparisonDrawer';
14
- import idGenerator from './tools/idGenerator';
15
-
16
- /** 发票组件的上下文 */
17
- export const InvoiceContext = React.createContext<InvoiceController>(
18
- undefined as any,
19
- );
20
-
21
- export interface IInvoiceProps {
22
- /** 发票数据控制器 */
23
- controller?: InvoiceController;
24
-
25
- /** 发票头UI */
26
- invoiceHeader?: React.ReactNode;
27
-
28
- /** 货物列表UI */
29
- goodsList?: React.ReactNode;
30
-
31
- /** 购买方UI */
32
- buyer?: React.ReactNode;
33
-
34
- /** 销售方UI */
35
- seller?: React.ReactNode;
36
-
37
- /** 落款UI */
38
- sign?: React.ReactNode;
39
-
40
- /** 底部扩展UI */
41
- footExpand?: React.ReactNode;
42
- }
43
-
44
- export default class Invoice extends React.PureComponent<IInvoiceProps> {
45
- /** 控制器 */
46
- static readonly InvoiceController = InvoiceController;
47
-
48
- /** 发票头 */
49
- static readonly InvoiceHeader = InvoiceHeader;
50
-
51
- /** 货物列表 */
52
- static readonly GoodsList = GoodsList;
53
-
54
- /** 销售方 */
55
- static readonly Seller = Seller;
56
-
57
- /** 落款 */
58
- static readonly Sign = Sign;
59
-
60
- /** 购买方 */
61
- static readonly Buyer = Buyer;
62
-
63
- /** 货物索引生成器 */
64
- static idGenerator = idGenerator;
65
-
66
- /** 获取控制器钩子 */
67
- static useInvoiceController = () => { return React.useContext(InvoiceContext) };
68
-
69
- render() {
70
- return <Main {...this.props}></Main>;
71
- }
72
- }
73
-
74
- const Main = (props: IInvoiceProps) => {
75
-
76
- const controller = React.useMemo(() => props.controller || new InvoiceController(), [props.controller]);
77
-
78
- const [key, setKey] = React.useState(0);
79
-
80
- useToGenerateId(controller);
81
-
82
- React.useEffect(() => { setKey(key + 1) }, [controller]);
83
-
84
- return (
85
- <InvoiceContext.Provider key={key} value={controller}>
86
-
87
- <div className="kts-invoice-operate" ref={controller.pipeline<HTMLDivElement | null>(async (s, e) => { s.rootElement = e })} >
88
- {props.invoiceHeader || <InvoiceHeader /> /** 发票头 */}
89
- {props.buyer || <Buyer /> /** 购买方 */}
90
- {props.goodsList || <GoodsList /> /** 货物列表 */}
91
- {props.seller || <Seller /> /** 销售方 */}
92
- {props.sign || <Sign /> /** 落款 */}
93
- {props.footExpand}
94
- </div>
95
-
96
- <ImportBuyerDrawer />{/* 导入购买方的抽屉 */}
97
- <ImportGoodsDrawer />{/* 导入货品的抽屉 */}
98
- <EndowCodeDrawer />{/* 给货品赋码的抽屉 */}
99
- <AddComparisonDrawer />{/* 添加商品对照的抽屉 */}
100
- </InvoiceContext.Provider>
101
- );
102
- };
103
-
104
-
1
+ import './index.less';
2
+ import React from 'react';
3
+ import InvoiceController from './InvoiceController';
4
+ import InvoiceHeader from './ui/InvoiceHeader';
5
+ import GoodsList from './ui/GoodsList';
6
+ import useToGenerateId from './ui/GoodsList/hook/useToGenerateId';
7
+ import Seller from './ui/Seller';
8
+ import Sign from './ui/Sign';
9
+ import Buyer from './ui/Buyer';
10
+ import ImportBuyerDrawer from './ui/ImportBuyerDrawer';
11
+ import ImportGoodsDrawer from './ui/ImportGoodsDrawer';
12
+ import EndowCodeDrawer from './ui/EndowCodeDrawer';
13
+ import AddComparisonDrawer from './ui/AddComparisonDrawer';
14
+ import idGenerator from './tools/idGenerator';
15
+
16
+ /** 发票组件的上下文 */
17
+ export const InvoiceContext = React.createContext<InvoiceController>(
18
+ undefined as any,
19
+ );
20
+
21
+ export interface IInvoiceProps {
22
+ /** 发票数据控制器 */
23
+ controller?: InvoiceController;
24
+
25
+ /** 发票头UI */
26
+ invoiceHeader?: React.ReactNode;
27
+
28
+ /** 货物列表UI */
29
+ goodsList?: React.ReactNode;
30
+
31
+ /** 购买方UI */
32
+ buyer?: React.ReactNode;
33
+
34
+ /** 销售方UI */
35
+ seller?: React.ReactNode;
36
+
37
+ /** 落款UI */
38
+ sign?: React.ReactNode;
39
+
40
+ /** 底部扩展UI */
41
+ footExpand?: React.ReactNode;
42
+ }
43
+
44
+ export default class Invoice extends React.PureComponent<IInvoiceProps> {
45
+ /** 控制器 */
46
+ static readonly InvoiceController = InvoiceController;
47
+
48
+ /** 发票头 */
49
+ static readonly InvoiceHeader = InvoiceHeader;
50
+
51
+ /** 货物列表 */
52
+ static readonly GoodsList = GoodsList;
53
+
54
+ /** 销售方 */
55
+ static readonly Seller = Seller;
56
+
57
+ /** 落款 */
58
+ static readonly Sign = Sign;
59
+
60
+ /** 购买方 */
61
+ static readonly Buyer = Buyer;
62
+
63
+ /** 货物索引生成器 */
64
+ static idGenerator = idGenerator;
65
+
66
+ /** 获取控制器钩子 */
67
+ static useInvoiceController = () => { return React.useContext(InvoiceContext) };
68
+
69
+ render() {
70
+ return <Main {...this.props}></Main>;
71
+ }
72
+ }
73
+
74
+ const Main = (props: IInvoiceProps) => {
75
+
76
+ const controller = React.useMemo(() => props.controller || new InvoiceController(), [props.controller]);
77
+
78
+ const [key, setKey] = React.useState(0);
79
+
80
+ useToGenerateId(controller);
81
+
82
+ React.useEffect(() => { setKey(key + 1) }, [controller]);
83
+
84
+ return (
85
+ <InvoiceContext.Provider key={key} value={controller}>
86
+
87
+ <div className="kts-invoice-operate" ref={controller.pipeline<HTMLDivElement | null>(async (s, e) => { s.rootElement = e })} >
88
+ {props.invoiceHeader || <InvoiceHeader /> /** 发票头 */}
89
+ {props.buyer || <Buyer /> /** 购买方 */}
90
+ {props.goodsList || <GoodsList /> /** 货物列表 */}
91
+ {props.seller || <Seller /> /** 销售方 */}
92
+ {props.sign || <Sign /> /** 落款 */}
93
+ {props.footExpand}
94
+ </div>
95
+
96
+ <ImportBuyerDrawer />{/* 导入购买方的抽屉 */}
97
+ <ImportGoodsDrawer />{/* 导入货品的抽屉 */}
98
+ <EndowCodeDrawer />{/* 给货品赋码的抽屉 */}
99
+ <AddComparisonDrawer />{/* 添加商品对照的抽屉 */}
100
+ </InvoiceContext.Provider>
101
+ );
102
+ };
103
+
104
+
@@ -1,97 +1,97 @@
1
-
2
- import { chain, bignumber } from 'mathjs';
3
-
4
-
5
- /** 格式化 保留2位小数 */
6
- export const format2 = (value: number | string) => {
7
- if (value === Infinity) return '';
8
- if (`${value}` === 'NaN') return '';
9
- if (typeof value === 'string') value = parseFloat(value);
10
- return parseFloat(value.toFixed(2));
11
- };
12
-
13
-
14
- /** 格式化 保留15位数字 */
15
- export const format15 = (value: number | string, defaultFractionDigits: number = 8) => {
16
- if (value === Infinity) return '';
17
- if (`${value}` === 'NaN') return '';
18
- if (typeof value === 'string') value = parseFloat(value);
19
-
20
- const fractionDigits = 15 - `${value || 0}`.indexOf('.');
21
- return parseFloat(value.toFixed(fractionDigits > defaultFractionDigits ? defaultFractionDigits : fractionDigits));
22
- };
23
-
24
-
25
- /**
26
- * 金额(含税) = 数量 * 单价(含税)
27
- * @param quantity 数量
28
- * @param priceIncludeTax 单价(含税)
29
- * @returns 金额(含税)
30
- */
31
- export function countAmountIncludeTax(quantity?: number | string, priceIncludeTax?: number | string, calculatingDigits?: number): number | undefined {
32
- if (!quantity && quantity !== 0) return undefined;
33
- if (!priceIncludeTax && priceIncludeTax !== 0) return undefined;
34
-
35
- quantity = format15(quantity, calculatingDigits);
36
- priceIncludeTax = format15(priceIncludeTax, calculatingDigits);
37
-
38
- return parseFloat(chain(bignumber(priceIncludeTax)).multiply(bignumber(quantity)).done().toNumber().toFixed(2));
39
- // return parseFloat(evaluate(`${priceIncludeTax} * ${quantity}`).toFixed(2));
40
- }
41
-
42
- /**
43
- * 不含税金额 = 含税金额-税额
44
- * @param amountIncludeTax 含税金额
45
- * @param taxAmount 税额
46
- * @returns 不含税金额
47
- */
48
- export function countAmountExcludeTax(amountIncludeTax: string | number, taxAmount: number): number | undefined {
49
- if (!amountIncludeTax && amountIncludeTax !== 0) return undefined;
50
- if (!taxAmount && taxAmount !== 0) return undefined;
51
-
52
- return chain(bignumber(amountIncludeTax)).subtract(bignumber(taxAmount)).done().toNumber();
53
- }
54
-
55
- /**
56
- * 税额 = (含税金额-扣除额)/(1+税率)*税率
57
- * @param amountIncludeTax 含税金额
58
- * @param deduction 扣除额
59
- * @param taxRate 税率
60
- * @returns 税额
61
- */
62
- export function countTaxAmount(amountIncludeTax: string | number, deduction: number, taxRate: number): number | undefined {
63
-
64
- if (!amountIncludeTax && amountIncludeTax !== 0) return undefined;
65
- if (!deduction && deduction !== 0) return undefined;
66
- if (!taxRate && taxRate !== 0) return undefined;
67
-
68
- const taxRateBu = chain(bignumber(taxRate)).divide(bignumber(100)).done();
69
-
70
- return parseFloat(chain(bignumber(amountIncludeTax))
71
- .subtract(bignumber(deduction))
72
- .divide(chain(bignumber(1)).add(taxRateBu).done())
73
- .multiply(taxRateBu)
74
- .done()
75
- .toNumber()
76
- .toFixed(2))
77
- }
78
-
79
- /**
80
- * 单价 = 金额/数量
81
- * @param amount 金额
82
- * @param quantity 数量
83
- * @returns 单价
84
- */
85
- export function countPrice(amount: string | number, quantity: string | number, calculatingDigits?: number): number | undefined | '' {
86
- if (!amount && amount !== 0) return undefined;
87
- if (!quantity && quantity !== 0) return undefined;
88
-
89
- return format15(chain(bignumber(amount)).divide(bignumber(quantity))
90
- .done()
91
- .toNumber(), calculatingDigits)
92
- }
93
-
94
-
95
-
96
-
97
-
1
+
2
+ import { chain, bignumber } from 'mathjs';
3
+
4
+
5
+ /** 格式化 保留2位小数 */
6
+ export const format2 = (value: number | string) => {
7
+ if (value === Infinity) return '';
8
+ if (`${value}` === 'NaN') return '';
9
+ if (typeof value === 'string') value = parseFloat(value);
10
+ return parseFloat(value.toFixed(2));
11
+ };
12
+
13
+
14
+ /** 格式化 保留15位数字 */
15
+ export const format15 = (value: number | string, defaultFractionDigits: number = 8) => {
16
+ if (value === Infinity) return '';
17
+ if (`${value}` === 'NaN') return '';
18
+ if (typeof value === 'string') value = parseFloat(value);
19
+
20
+ const fractionDigits = 15 - `${value || 0}`.indexOf('.');
21
+ return parseFloat(value.toFixed(fractionDigits > defaultFractionDigits ? defaultFractionDigits : fractionDigits));
22
+ };
23
+
24
+
25
+ /**
26
+ * 金额(含税) = 数量 * 单价(含税)
27
+ * @param quantity 数量
28
+ * @param priceIncludeTax 单价(含税)
29
+ * @returns 金额(含税)
30
+ */
31
+ export function countAmountIncludeTax(quantity?: number | string, priceIncludeTax?: number | string, calculatingDigits?: number): number | undefined {
32
+ if (!quantity && quantity !== 0) return undefined;
33
+ if (!priceIncludeTax && priceIncludeTax !== 0) return undefined;
34
+
35
+ quantity = format15(quantity, calculatingDigits);
36
+ priceIncludeTax = format15(priceIncludeTax, calculatingDigits);
37
+
38
+ return parseFloat(chain(bignumber(priceIncludeTax)).multiply(bignumber(quantity)).done().toNumber().toFixed(2));
39
+ // return parseFloat(evaluate(`${priceIncludeTax} * ${quantity}`).toFixed(2));
40
+ }
41
+
42
+ /**
43
+ * 不含税金额 = 含税金额-税额
44
+ * @param amountIncludeTax 含税金额
45
+ * @param taxAmount 税额
46
+ * @returns 不含税金额
47
+ */
48
+ export function countAmountExcludeTax(amountIncludeTax: string | number, taxAmount: number): number | undefined {
49
+ if (!amountIncludeTax && amountIncludeTax !== 0) return undefined;
50
+ if (!taxAmount && taxAmount !== 0) return undefined;
51
+
52
+ return chain(bignumber(amountIncludeTax)).subtract(bignumber(taxAmount)).done().toNumber();
53
+ }
54
+
55
+ /**
56
+ * 税额 = (含税金额-扣除额)/(1+税率)*税率
57
+ * @param amountIncludeTax 含税金额
58
+ * @param deduction 扣除额
59
+ * @param taxRate 税率
60
+ * @returns 税额
61
+ */
62
+ export function countTaxAmount(amountIncludeTax: string | number, deduction: number, taxRate: number): number | undefined {
63
+
64
+ if (!amountIncludeTax && amountIncludeTax !== 0) return undefined;
65
+ if (!deduction && deduction !== 0) return undefined;
66
+ if (!taxRate && taxRate !== 0) return undefined;
67
+
68
+ const taxRateBu = chain(bignumber(taxRate)).divide(bignumber(100)).done();
69
+
70
+ return parseFloat(chain(bignumber(amountIncludeTax))
71
+ .subtract(bignumber(deduction))
72
+ .divide(chain(bignumber(1)).add(taxRateBu).done())
73
+ .multiply(taxRateBu)
74
+ .done()
75
+ .toNumber()
76
+ .toFixed(2))
77
+ }
78
+
79
+ /**
80
+ * 单价 = 金额/数量
81
+ * @param amount 金额
82
+ * @param quantity 数量
83
+ * @returns 单价
84
+ */
85
+ export function countPrice(amount: string | number, quantity: string | number, calculatingDigits?: number): number | undefined | '' {
86
+ if (!amount && amount !== 0) return undefined;
87
+ if (!quantity && quantity !== 0) return undefined;
88
+
89
+ return format15(chain(bignumber(amount)).divide(bignumber(quantity))
90
+ .done()
91
+ .toNumber(), calculatingDigits)
92
+ }
93
+
94
+
95
+
96
+
97
+
@@ -1,18 +1,18 @@
1
-
2
-
3
- const keys: { [key: string]: any } = {}
4
-
5
- /**
6
- * 有冷却时间的函数
7
- * @param fn 方法
8
- * @param key 方法key
9
- * @param delayed 冷却时间
10
- */
11
- export default (key: string = 'default', delayed: number = 200, fn: Function) => {
12
- if (keys[key]) {
13
- return;
14
- } else {
15
- fn();
16
- keys[key] = setTimeout(() => { delete keys[key] }, delayed);
17
- }
1
+
2
+
3
+ const keys: { [key: string]: any } = {}
4
+
5
+ /**
6
+ * 有冷却时间的函数
7
+ * @param fn 方法
8
+ * @param key 方法key
9
+ * @param delayed 冷却时间
10
+ */
11
+ export default (key: string = 'default', delayed: number = 200, fn: Function) => {
12
+ if (keys[key]) {
13
+ return;
14
+ } else {
15
+ fn();
16
+ keys[key] = setTimeout(() => { delete keys[key] }, delayed);
17
+ }
18
18
  }
@@ -1,7 +1,7 @@
1
- import { create, all } from 'mathjs';
2
-
3
- const math = create(all, { number: 'BigNumber', precision: 20 }) as any;
4
-
5
- export default (expr: any, fractionDigits = 20) => {
6
- return parseFloat(math.evaluate(expr).toFixed(fractionDigits));
7
- };
1
+ import { create, all } from 'mathjs';
2
+
3
+ const math = create(all, { number: 'BigNumber', precision: 20 }) as any;
4
+
5
+ export default (expr: any, fractionDigits = 20) => {
6
+ return parseFloat(math.evaluate(expr).toFixed(fractionDigits));
7
+ };
@@ -1,3 +1,3 @@
1
-
2
- import { v4 as uuidv4 } from 'uuid';
1
+
2
+ import { v4 as uuidv4 } from 'uuid';
3
3
  export default () => uuidv4();
@@ -1,47 +1,47 @@
1
-
2
- export interface ISN {
3
-
4
- /** 简称 */
5
- shorthand?: string;
6
-
7
- /** 全称 */
8
- full: string
9
- }
10
-
11
- /** 拆分全称加简称 */
12
- export const getSN = (value?: string): ISN | undefined => {
13
- if (!value) return undefined;
14
- const arr = value.match(/\*[^*]+\*/);
15
- if (arr && arr[0]) {
16
- return { shorthand: arr[0].split('*')[1], full: value.replace(arr[0], '') };
17
- } else {
18
- return { shorthand: undefined, full: value };
19
- }
20
- };
21
-
22
- /** 组合全称加简称 */
23
- export const getItemName = (value: ISN) => {
24
- if (value.shorthand) {
25
- return `*${value.shorthand}*${value.full}`;
26
- } else {
27
- return value.full;
28
- }
29
- }
30
-
31
- /** 设置全称 */
32
- export const setFull = (name?:string, full?:string) => {
33
- const sn = getSN(name);
34
- if(!sn) return full;
35
- sn.full = full || '';
36
- return getItemName(sn);
37
- }
38
-
39
- /** 设置简称 */
40
- export const setShorthand = (name?:string, shorthand?:string) => {
41
- if(!name) return undefined
42
-
43
- const sn = getSN(name);
44
- if(!sn) return undefined;
45
- sn.shorthand = shorthand || '';
46
- return getItemName(sn);
1
+
2
+ export interface ISN {
3
+
4
+ /** 简称 */
5
+ shorthand?: string;
6
+
7
+ /** 全称 */
8
+ full: string
9
+ }
10
+
11
+ /** 拆分全称加简称 */
12
+ export const getSN = (value?: string): ISN | undefined => {
13
+ if (!value) return undefined;
14
+ const arr = value.match(/\*[^*]+\*/);
15
+ if (arr && arr[0]) {
16
+ return { shorthand: arr[0].split('*')[1], full: value.replace(arr[0], '') };
17
+ } else {
18
+ return { shorthand: undefined, full: value };
19
+ }
20
+ };
21
+
22
+ /** 组合全称加简称 */
23
+ export const getItemName = (value: ISN) => {
24
+ if (value.shorthand) {
25
+ return `*${value.shorthand}*${value.full}`;
26
+ } else {
27
+ return value.full;
28
+ }
29
+ }
30
+
31
+ /** 设置全称 */
32
+ export const setFull = (name?:string, full?:string) => {
33
+ const sn = getSN(name);
34
+ if(!sn) return full;
35
+ sn.full = full || '';
36
+ return getItemName(sn);
37
+ }
38
+
39
+ /** 设置简称 */
40
+ export const setShorthand = (name?:string, shorthand?:string) => {
41
+ if(!name) return undefined
42
+
43
+ const sn = getSN(name);
44
+ if(!sn) return undefined;
45
+ sn.shorthand = shorthand || '';
46
+ return getItemName(sn);
47
47
  }
@@ -1,20 +1,20 @@
1
- /** 延迟函数 */
2
- export default (fn: Function, delayed: number = 200) => {
3
- // let timer: any = 0;
4
- // return (...par: any[]) => {
5
- // if (timer === 0) {
6
- // timer = setTimeout(() => {
7
- // fn.apply(null, par);
8
- // timer = 0;
9
- // }, delayed);
10
- // }
11
- // }
12
- let timer: any;
13
- return (...par: any[]) => {
14
- if (timer) return;
15
- timer = setTimeout(() => {
16
- timer = undefined;
17
- fn.apply(null, par);
18
- }, delayed);
19
- }
1
+ /** 延迟函数 */
2
+ export default (fn: Function, delayed: number = 200) => {
3
+ // let timer: any = 0;
4
+ // return (...par: any[]) => {
5
+ // if (timer === 0) {
6
+ // timer = setTimeout(() => {
7
+ // fn.apply(null, par);
8
+ // timer = 0;
9
+ // }, delayed);
10
+ // }
11
+ // }
12
+ let timer: any;
13
+ return (...par: any[]) => {
14
+ if (timer) return;
15
+ timer = setTimeout(() => {
16
+ timer = undefined;
17
+ fn.apply(null, par);
18
+ }, delayed);
19
+ }
20
20
  }