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,88 +1,88 @@
1
- import IGood from './IGood';
2
- import ImportGoods from './ImportGoods';
3
- import EndowCode from './EndowCode';
4
- import ProductComparison from './ProductComparison';
5
- import { WrappedFormUtils } from 'kts-components-antd-x3/lib/form/Form';
6
- import InvoiceController from '../..';
7
- import IColumnsReplenish from './IColumnsReplenish';
8
-
9
- export default class GoodsListState {
10
-
11
- /** 扣除额 */
12
- deduction = 0;
13
-
14
- /** 产品最大数 */
15
- goodMax?: number;
16
-
17
- /** 是否可以切换(含税/不含税)状态 */
18
- isSwitchTax?: boolean;
19
-
20
- /** 是否能添加折扣行 */
21
- isAddDiscount?: boolean;
22
-
23
- /** 是否含税 */
24
- isTaxIncluded = true;
25
-
26
- /** 是否显示我方 */
27
- isMyShow = false;
28
-
29
- /** 正在编辑的货物 */
30
- editGood?: IGood;
31
-
32
- /** 被编辑行的form对象 */
33
- form?: WrappedFormUtils;
34
-
35
- /** 商品表格补充配置 */
36
- columnsReplenish: { [key: string]: IColumnsReplenish } = {};
37
-
38
- /** 单位列表 */
39
- unitList: string[] = [];
40
-
41
- /** 默认税率 */
42
- defaultRate = 3;
43
-
44
- /** 税率列表 */
45
- taxRateList: number[] = [0, 3, 5, 6, 9, 13];
46
-
47
- /** 搜索条件 */
48
- searchValue = '';
49
-
50
- /** 货物列表 */
51
- goodsList: IGood[] = [];
52
-
53
- /** 货物字典 */
54
- goodsMap = new Map<string, IGood>();
55
-
56
- /** 货物菜单扩展 */
57
- goodsMenuExpand: ((index: string, controller: InvoiceController) => React.ReactNode)[] = [];
58
-
59
- /** 金额含税(受控,输入后不再自动计算) */
60
- amountIncludeTax?: number;
61
-
62
- /** 金额不含税(受控,输入后不再自动计算) */
63
- amountExcludeTax?: number;
64
-
65
- /** 税额(受控,输入后不再自动计算) */
66
- amountTax?: number;
67
-
68
- /** 列表选中的货物索引列表 */
69
- selectedGoodIndex: string[] = [];
70
-
71
- /** 准备添加折扣的货物索引列表 */
72
- discountGoodIndex: string[] = [];
73
-
74
- /** 货物赋码的相关数据 */
75
- endowCode = new EndowCode();
76
-
77
- /** 导入商品的相关数据 */
78
- importGoods = new ImportGoods();
79
-
80
- /** 商品对照 相关 */
81
- productComparison = new ProductComparison();
82
-
83
- /** 是否显购买示导入抽屉 */
84
- isVisibleDrawer = false;
85
-
86
- /** 正在 添加商品对照 的货物 */
87
- addComparisonIndex?: string;
88
- }
1
+ import IGood from './IGood';
2
+ import ImportGoods from './ImportGoods';
3
+ import EndowCode from './EndowCode';
4
+ import ProductComparison from './ProductComparison';
5
+ import { WrappedFormUtils } from 'kts-components-antd-x3/lib/form/Form';
6
+ import InvoiceController from '../..';
7
+ import IColumnsReplenish from './IColumnsReplenish';
8
+
9
+ export default class GoodsListState {
10
+
11
+ /** 扣除额 */
12
+ deduction = 0;
13
+
14
+ /** 产品最大数 */
15
+ goodMax?: number;
16
+
17
+ /** 是否可以切换(含税/不含税)状态 */
18
+ isSwitchTax?: boolean;
19
+
20
+ /** 是否能添加折扣行 */
21
+ isAddDiscount?: boolean;
22
+
23
+ /** 是否含税 */
24
+ isTaxIncluded = true;
25
+
26
+ /** 是否显示我方 */
27
+ isMyShow = false;
28
+
29
+ /** 正在编辑的货物 */
30
+ editGood?: IGood;
31
+
32
+ /** 被编辑行的form对象 */
33
+ form?: WrappedFormUtils;
34
+
35
+ /** 商品表格补充配置 */
36
+ columnsReplenish: { [key: string]: IColumnsReplenish } = {};
37
+
38
+ /** 单位列表 */
39
+ unitList: string[] = [];
40
+
41
+ /** 默认税率 */
42
+ defaultRate = 3;
43
+
44
+ /** 税率列表 */
45
+ taxRateList: number[] = [0, 3, 5, 6, 9, 13];
46
+
47
+ /** 搜索条件 */
48
+ searchValue = '';
49
+
50
+ /** 货物列表 */
51
+ goodsList: IGood[] = [];
52
+
53
+ /** 货物字典 */
54
+ goodsMap = new Map<string, IGood>();
55
+
56
+ /** 货物菜单扩展 */
57
+ goodsMenuExpand: ((index: string, controller: InvoiceController) => React.ReactNode)[] = [];
58
+
59
+ /** 金额含税(受控,输入后不再自动计算) */
60
+ amountIncludeTax?: number;
61
+
62
+ /** 金额不含税(受控,输入后不再自动计算) */
63
+ amountExcludeTax?: number;
64
+
65
+ /** 税额(受控,输入后不再自动计算) */
66
+ amountTax?: number;
67
+
68
+ /** 列表选中的货物索引列表 */
69
+ selectedGoodIndex: string[] = [];
70
+
71
+ /** 准备添加折扣的货物索引列表 */
72
+ discountGoodIndex: string[] = [];
73
+
74
+ /** 货物赋码的相关数据 */
75
+ endowCode = new EndowCode();
76
+
77
+ /** 导入商品的相关数据 */
78
+ importGoods = new ImportGoods();
79
+
80
+ /** 商品对照 相关 */
81
+ productComparison = new ProductComparison();
82
+
83
+ /** 是否显购买示导入抽屉 */
84
+ isVisibleDrawer = false;
85
+
86
+ /** 正在 添加商品对照 的货物 */
87
+ addComparisonIndex?: string;
88
+ }
@@ -1,48 +1,48 @@
1
- import GoodsListState from './GoodsListState';
2
- import BuyerState from './BuyerState';
3
-
4
- export default class InvoiceControllerState {
5
-
6
- /**
7
- * 组件模式
8
- * prefab 预制
9
- * readOnly 只读
10
- * */
11
- model: 'default' | 'prefab' | 'readOnly' = 'default';
12
-
13
- /**
14
- * 企业类型
15
- * 01 一般纳税人
16
- * 05 转登记纳税人
17
- * 04 代开企业
18
- * 08 小规模纳税人
19
- * */
20
- en: '01' | '05' | '04' | '08' = '01';
21
-
22
- /**
23
- * 发票类型
24
- * 08 - 增值税电子专用发票
25
- * 10 - 增值税电子普通发票
26
- * 01 - 增值税纸质专用发票
27
- * 04 - 增值税纸质普通发票
28
- */
29
- invoiceType: '08' | '10' | '01' | '04' = '08';
30
-
31
- /** 购买方 */
32
- buyerState = new BuyerState();
33
-
34
- /** 货物信息 */
35
- goodsListState = new GoodsListState();
36
-
37
- /** 计算中启动字段 */
38
- calculating?: string;
39
-
40
- /** 数量,单价计算时保留的小数位,不传默认8位 */
41
- calculatingDigits?: number;
42
-
43
- /** 金额整数位限制,不传默认9位 */
44
- priceIntegerDigit?: number;
45
-
46
- /** 组件根结构 */
47
- rootElement?: HTMLDivElement | null = null;
48
- }
1
+ import GoodsListState from './GoodsListState';
2
+ import BuyerState from './BuyerState';
3
+
4
+ export default class InvoiceControllerState {
5
+
6
+ /**
7
+ * 组件模式
8
+ * prefab 预制
9
+ * readOnly 只读
10
+ * */
11
+ model: 'default' | 'prefab' | 'readOnly' = 'default';
12
+
13
+ /**
14
+ * 企业类型
15
+ * 01 一般纳税人
16
+ * 05 转登记纳税人
17
+ * 04 代开企业
18
+ * 08 小规模纳税人
19
+ * */
20
+ en: '01' | '05' | '04' | '08' = '01';
21
+
22
+ /**
23
+ * 发票类型
24
+ * 08 - 增值税电子专用发票
25
+ * 10 - 增值税电子普通发票
26
+ * 01 - 增值税纸质专用发票
27
+ * 04 - 增值税纸质普通发票
28
+ */
29
+ invoiceType: '08' | '10' | '01' | '04' = '08';
30
+
31
+ /** 购买方 */
32
+ buyerState = new BuyerState();
33
+
34
+ /** 货物信息 */
35
+ goodsListState = new GoodsListState();
36
+
37
+ /** 计算中启动字段 */
38
+ calculating?: string;
39
+
40
+ /** 数量,单价计算时保留的小数位,不传默认8位 */
41
+ calculatingDigits?: number;
42
+
43
+ /** 金额整数位限制,不传默认9位 */
44
+ priceIntegerDigit?: number;
45
+
46
+ /** 组件根结构 */
47
+ rootElement?: HTMLDivElement | null = null;
48
+ }
@@ -1,11 +1,11 @@
1
- import { InvoiceControllerState } from '../';
2
- import idGenerator from '../../tools/idGenerator';
3
-
4
- /**
5
- * 添加的编辑货物
6
- */
7
- export default async (state: InvoiceControllerState, options?: any) => {
8
- options.$index = idGenerator();
9
- state.goodsListState.goodsList = [...state.goodsListState.goodsList, options];
10
- return options;
11
- };
1
+ import { InvoiceControllerState } from '../';
2
+ import idGenerator from '../../tools/idGenerator';
3
+
4
+ /**
5
+ * 添加的编辑货物
6
+ */
7
+ export default async (state: InvoiceControllerState, options?: any) => {
8
+ options.$index = idGenerator();
9
+ state.goodsListState.goodsList = [...state.goodsListState.goodsList, options];
10
+ return options;
11
+ };
@@ -1,125 +1,125 @@
1
- /**
2
- *
3
- * 折扣率 含税金额 不含税金额
4
- *
5
- * 含税折扣额 = -1 * (含税金额 * 折扣率)
6
- * 不含税扣额 = 含税折扣额 / (1+税率)
7
- * 折扣税额 = 含税折扣额 - 不含税扣额
8
- */
9
-
10
- import { v4 as uuidv4 } from 'uuid';
11
- import { chain, bignumber } from 'mathjs';
12
- import { InvoiceControllerState } from '../';
13
- import LineAttributeType from '../InvoiceControllerState/GoodsListState/LineAttributeType';
14
- import idGenerator from '../../tools/idGenerator';
15
- import { format2 } from '../../../Invoice/tools/calculate';
16
-
17
- export interface IOptions {
18
- /** 需要添加的 索引列表 */
19
- indexList: string[];
20
-
21
- /** 折扣 */
22
- discount: number;
23
-
24
- /** 折扣 金额 */
25
- discolineAmountunt: number;
26
- }
27
-
28
- /**
29
- * 设置当前的编辑货物
30
- */
31
- export default async (state: InvoiceControllerState, options?: IOptions) => {
32
- if (!options) return;
33
-
34
- const { indexList = [] } = options;
35
- const discount = chain(bignumber(options.discount || 0)).dotDivide(bignumber(100)).done();
36
- const goodsMap = state.goodsListState.goodsMap;
37
- const goodsList = state.goodsListState.goodsList;
38
- const discountGroup = uuidv4();
39
- let amountSum = bignumber(0);
40
-
41
- for (let t = 0; t < indexList.length; t++) {
42
- const $index = indexList[t];
43
- const good = goodsMap.get($index);
44
-
45
- if (!good || good.lineAttribute !== LineAttributeType.正常) continue;
46
-
47
- const i = goodsList.indexOf(good);
48
-
49
- let lineAmountIncludeTax = 0;
50
- let lineAmountExcludeTax = 0;
51
-
52
- const taxRate = chain(bignumber(good.taxRate)).dotDivide(bignumber(100)).done();
53
- if (state.goodsListState.isTaxIncluded) {
54
- /** 金额(含税) -1 * ${good.lineAmountIncludeTax} * ${discount}*/
55
- lineAmountIncludeTax = (() => {
56
- if (t === indexList.length - 1) {
57
- return chain(bignumber(options.discolineAmountunt)).add(amountSum).multiply(-1).done().toNumber();
58
- } else {
59
- return chain(bignumber(-1))
60
- .multiply(bignumber(good.lineAmountIncludeTax))
61
- .multiply(discount)
62
- .done()
63
- .toNumber()
64
- .toFixed(2);
65
- }
66
- })()
67
- amountSum = amountSum.add(bignumber(lineAmountIncludeTax));
68
-
69
- /** 金额(不含税) ${lineAmountIncludeTax} / (1+${good.taxRate}/100)*/
70
- lineAmountExcludeTax = 1 * chain(bignumber(lineAmountIncludeTax))
71
- .dotDivide(chain(bignumber(1)).add(taxRate).done())
72
- .done()
73
- .toNumber()
74
- .toFixed(2)
75
- } else {
76
-
77
- /** 金额(不含税) -1 * ${good.lineAmountIncludeTax} * ${discount}*/
78
- lineAmountExcludeTax = (() => {
79
- if (t === indexList.length - 1) {
80
- return chain(bignumber(options.discolineAmountunt)).add(amountSum).multiply(-1).done().toNumber();
81
- } else {
82
- return chain(bignumber(-1))
83
- .multiply(bignumber(good.lineAmountExcludeTax))
84
- .multiply(discount)
85
- .done()
86
- .toNumber()
87
- .toFixed(2);
88
- }
89
- })()
90
- amountSum = amountSum.add(bignumber(lineAmountExcludeTax));
91
-
92
- /** 金额(含税) lineAmountExcludeTax * (1+${good.taxRate}/100)*/
93
- lineAmountIncludeTax = format2(chain(bignumber(lineAmountExcludeTax))
94
- .multiply(chain(bignumber(1)).add(taxRate).done())
95
- .done().toNumber()) as number
96
- }
97
-
98
- /** 税额 */
99
- const taxAmount = chain(bignumber(lineAmountIncludeTax))
100
- .subtract(bignumber(lineAmountExcludeTax))
101
- .done()
102
- .toNumber();
103
-
104
-
105
- good.discountGroup = discountGroup;
106
- good.lineAttribute = LineAttributeType.被折扣行;
107
- goodsList.splice(i + 1, 0, {
108
- $index: idGenerator(),
109
- lineAttribute: LineAttributeType.折扣行,
110
- taxClassificationCode: good.taxClassificationCode,
111
- taxRate: good.taxRate,
112
- itemName: good.itemName,
113
- itemNameSelf: good.itemNameSelf,
114
- favouredPolicyMark: good.favouredPolicyMark,
115
- favouredPolicyName: good.favouredPolicyName,
116
- taxFreeType: good.taxFreeType,
117
- discountGroup,
118
- lineAmountIncludeTax,
119
- lineAmountExcludeTax,
120
- taxAmount,
121
- });
122
- }
123
-
124
- state.goodsListState.goodsList = goodsList.slice();
125
- };
1
+ /**
2
+ *
3
+ * 折扣率 含税金额 不含税金额
4
+ *
5
+ * 含税折扣额 = -1 * (含税金额 * 折扣率)
6
+ * 不含税扣额 = 含税折扣额 / (1+税率)
7
+ * 折扣税额 = 含税折扣额 - 不含税扣额
8
+ */
9
+
10
+ import { v4 as uuidv4 } from 'uuid';
11
+ import { chain, bignumber } from 'mathjs';
12
+ import { InvoiceControllerState } from '../';
13
+ import LineAttributeType from '../InvoiceControllerState/GoodsListState/LineAttributeType';
14
+ import idGenerator from '../../tools/idGenerator';
15
+ import { format2 } from '../../../Invoice/tools/calculate';
16
+
17
+ export interface IOptions {
18
+ /** 需要添加的 索引列表 */
19
+ indexList: string[];
20
+
21
+ /** 折扣 */
22
+ discount: number;
23
+
24
+ /** 折扣 金额 */
25
+ discolineAmountunt: number;
26
+ }
27
+
28
+ /**
29
+ * 设置当前的编辑货物
30
+ */
31
+ export default async (state: InvoiceControllerState, options?: IOptions) => {
32
+ if (!options) return;
33
+
34
+ const { indexList = [] } = options;
35
+ const discount = chain(bignumber(options.discount || 0)).dotDivide(bignumber(100)).done();
36
+ const goodsMap = state.goodsListState.goodsMap;
37
+ const goodsList = state.goodsListState.goodsList;
38
+ const discountGroup = uuidv4();
39
+ let amountSum = bignumber(0);
40
+
41
+ for (let t = 0; t < indexList.length; t++) {
42
+ const $index = indexList[t];
43
+ const good = goodsMap.get($index);
44
+
45
+ if (!good || good.lineAttribute !== LineAttributeType.正常) continue;
46
+
47
+ const i = goodsList.indexOf(good);
48
+
49
+ let lineAmountIncludeTax = 0;
50
+ let lineAmountExcludeTax = 0;
51
+
52
+ const taxRate = chain(bignumber(good.taxRate)).dotDivide(bignumber(100)).done();
53
+ if (state.goodsListState.isTaxIncluded) {
54
+ /** 金额(含税) -1 * ${good.lineAmountIncludeTax} * ${discount}*/
55
+ lineAmountIncludeTax = (() => {
56
+ if (t === indexList.length - 1) {
57
+ return chain(bignumber(options.discolineAmountunt)).add(amountSum).multiply(-1).done().toNumber();
58
+ } else {
59
+ return chain(bignumber(-1))
60
+ .multiply(bignumber(good.lineAmountIncludeTax))
61
+ .multiply(discount)
62
+ .done()
63
+ .toNumber()
64
+ .toFixed(2);
65
+ }
66
+ })()
67
+ amountSum = amountSum.add(bignumber(lineAmountIncludeTax));
68
+
69
+ /** 金额(不含税) ${lineAmountIncludeTax} / (1+${good.taxRate}/100)*/
70
+ lineAmountExcludeTax = 1 * chain(bignumber(lineAmountIncludeTax))
71
+ .dotDivide(chain(bignumber(1)).add(taxRate).done())
72
+ .done()
73
+ .toNumber()
74
+ .toFixed(2)
75
+ } else {
76
+
77
+ /** 金额(不含税) -1 * ${good.lineAmountIncludeTax} * ${discount}*/
78
+ lineAmountExcludeTax = (() => {
79
+ if (t === indexList.length - 1) {
80
+ return chain(bignumber(options.discolineAmountunt)).add(amountSum).multiply(-1).done().toNumber();
81
+ } else {
82
+ return chain(bignumber(-1))
83
+ .multiply(bignumber(good.lineAmountExcludeTax))
84
+ .multiply(discount)
85
+ .done()
86
+ .toNumber()
87
+ .toFixed(2);
88
+ }
89
+ })()
90
+ amountSum = amountSum.add(bignumber(lineAmountExcludeTax));
91
+
92
+ /** 金额(含税) lineAmountExcludeTax * (1+${good.taxRate}/100)*/
93
+ lineAmountIncludeTax = format2(chain(bignumber(lineAmountExcludeTax))
94
+ .multiply(chain(bignumber(1)).add(taxRate).done())
95
+ .done().toNumber()) as number
96
+ }
97
+
98
+ /** 税额 */
99
+ const taxAmount = chain(bignumber(lineAmountIncludeTax))
100
+ .subtract(bignumber(lineAmountExcludeTax))
101
+ .done()
102
+ .toNumber();
103
+
104
+
105
+ good.discountGroup = discountGroup;
106
+ good.lineAttribute = LineAttributeType.被折扣行;
107
+ goodsList.splice(i + 1, 0, {
108
+ $index: idGenerator(),
109
+ lineAttribute: LineAttributeType.折扣行,
110
+ taxClassificationCode: good.taxClassificationCode,
111
+ taxRate: good.taxRate,
112
+ itemName: good.itemName,
113
+ itemNameSelf: good.itemNameSelf,
114
+ favouredPolicyMark: good.favouredPolicyMark,
115
+ favouredPolicyName: good.favouredPolicyName,
116
+ taxFreeType: good.taxFreeType,
117
+ discountGroup,
118
+ lineAmountIncludeTax,
119
+ lineAmountExcludeTax,
120
+ taxAmount,
121
+ });
122
+ }
123
+
124
+ state.goodsListState.goodsList = goodsList.slice();
125
+ };
@@ -1,43 +1,43 @@
1
- import { InvoiceControllerState, IGood } from '../';
2
- import LineAttributeType from '../../InvoiceController/InvoiceControllerState/GoodsListState/LineAttributeType';
3
-
4
- /**
5
- * 设置当前的编辑货物
6
- */
7
- export default async (state: InvoiceControllerState, $index?: string) => {
8
- if (!$index) return;
9
-
10
- const goods = state.goodsListState.goodsList.filter( (e) => e.$index === $index)[0];
11
- if (!goods) return;
12
- if (
13
- state.goodsListState.editGood &&
14
- state.goodsListState.editGood.$index === $index
15
- ) {
16
- state.goodsListState.editGood = undefined;
17
- }
18
-
19
- if (goods.lineAttribute === LineAttributeType.正常) {
20
- state.goodsListState.selectedGoodIndex =
21
- state.goodsListState.selectedGoodIndex.filter((e) => e !== $index);
22
- state.goodsListState.goodsList = state.goodsListState.goodsList.filter(
23
- (e) => e.$index !== $index,
24
- );
25
- }
26
-
27
- if (goods.lineAttribute === LineAttributeType.折扣行) {
28
- state.goodsListState.goodsList = state.goodsListState.goodsList.filter(
29
- (e) => {
30
- if (e.discountGroup !== goods.discountGroup) return true;
31
- if (e.lineAttribute === LineAttributeType.折扣行) {
32
- state.goodsListState.selectedGoodIndex =
33
- state.goodsListState.selectedGoodIndex.filter((e) => e !== $index);
34
- return false;
35
- }
36
- if (e.lineAttribute === LineAttributeType.被折扣行) {
37
- e.lineAttribute = LineAttributeType.正常;
38
- return true;
39
- }
40
- },
41
- );
42
- }
43
- };
1
+ import { InvoiceControllerState, IGood } from '../';
2
+ import LineAttributeType from '../../InvoiceController/InvoiceControllerState/GoodsListState/LineAttributeType';
3
+
4
+ /**
5
+ * 设置当前的编辑货物
6
+ */
7
+ export default async (state: InvoiceControllerState, $index?: string) => {
8
+ if (!$index) return;
9
+
10
+ const goods = state.goodsListState.goodsList.filter( (e) => e.$index === $index)[0];
11
+ if (!goods) return;
12
+ if (
13
+ state.goodsListState.editGood &&
14
+ state.goodsListState.editGood.$index === $index
15
+ ) {
16
+ state.goodsListState.editGood = undefined;
17
+ }
18
+
19
+ if (goods.lineAttribute === LineAttributeType.正常) {
20
+ state.goodsListState.selectedGoodIndex =
21
+ state.goodsListState.selectedGoodIndex.filter((e) => e !== $index);
22
+ state.goodsListState.goodsList = state.goodsListState.goodsList.filter(
23
+ (e) => e.$index !== $index,
24
+ );
25
+ }
26
+
27
+ if (goods.lineAttribute === LineAttributeType.折扣行) {
28
+ state.goodsListState.goodsList = state.goodsListState.goodsList.filter(
29
+ (e) => {
30
+ if (e.discountGroup !== goods.discountGroup) return true;
31
+ if (e.lineAttribute === LineAttributeType.折扣行) {
32
+ state.goodsListState.selectedGoodIndex =
33
+ state.goodsListState.selectedGoodIndex.filter((e) => e !== $index);
34
+ return false;
35
+ }
36
+ if (e.lineAttribute === LineAttributeType.被折扣行) {
37
+ e.lineAttribute = LineAttributeType.正常;
38
+ return true;
39
+ }
40
+ },
41
+ );
42
+ }
43
+ };