kts-component-invoice-operate 3.2.47 → 3.2.49

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 (200) 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/default/GoodsList/hook/useColumns/ui/ItemCodeInput/index.d.ts +0 -1
  9. package/dist/index.esm.js +5675 -7880
  10. package/dist/index.js +5675 -7880
  11. package/docs/index.md +5 -5
  12. package/docs-dist/static/arrowDown.a1cbf0d8.svg +2 -2
  13. package/docs-dist/static/arrowUp.4c482054.svg +2 -2
  14. package/docs-dist/static/fork.5431267d.svg +11 -11
  15. package/docs-dist/static/plus.44013ce3.svg +11 -11
  16. package/docs-dist/static/plus.4fd1af30.svg +11 -11
  17. package/index.html +12 -12
  18. package/package.json +60 -60
  19. package/src/Invoice/Invoice-digtal/_test/disabled/index.tsx +38 -38
  20. package/src/Invoice/Invoice-digtal/_test/easiest/index.tsx +16 -16
  21. package/src/Invoice/Invoice-digtal/_test/header/index.tsx +84 -84
  22. package/src/Invoice/Invoice-digtal/_test/importGoods/index.tsx +470 -470
  23. package/src/Invoice/Invoice-digtal/_test/importStakeholder/index.tsx +17 -17
  24. package/src/Invoice/Invoice-digtal/_test/lineCredit/index.tsx +20 -20
  25. package/src/Invoice/Invoice-digtal/_test/prefab/index.tsx +150 -150
  26. package/src/Invoice/Invoice-digtal/_test/readOnly/index.tsx +41 -41
  27. package/src/Invoice/Invoice-digtal/_test/stakeholder/index.tsx +12 -12
  28. package/src/Invoice/Invoice-digtal/_test/typeSelection/index.tsx +29 -29
  29. package/src/Invoice/Invoice-digtal/index.md +30 -30
  30. package/src/Invoice/InvoiceController/InvoiceControllerForm/index.ts +94 -94
  31. package/src/Invoice/InvoiceController/InvoiceControllerState/AutoComplete/index.ts +17 -17
  32. package/src/Invoice/InvoiceController/InvoiceControllerState/BuyerState/index.tsx +88 -88
  33. package/src/Invoice/InvoiceController/InvoiceControllerState/GoodsListState/Drag/index.ts +12 -12
  34. package/src/Invoice/InvoiceController/InvoiceControllerState/GoodsListState/EndowCode/index.tsx +93 -93
  35. package/src/Invoice/InvoiceController/InvoiceControllerState/GoodsListState/IColumnsReplenish/index.ts +10 -10
  36. package/src/Invoice/InvoiceController/InvoiceControllerState/GoodsListState/IGood/index.ts +75 -75
  37. package/src/Invoice/InvoiceController/InvoiceControllerState/GoodsListState/ImportGoods/index.ts +80 -80
  38. package/src/Invoice/InvoiceController/InvoiceControllerState/GoodsListState/LineAttributeType/index.ts +5 -5
  39. package/src/Invoice/InvoiceController/InvoiceControllerState/GoodsListState/ProductComparison/index.ts +9 -9
  40. package/src/Invoice/InvoiceController/InvoiceControllerState/GoodsListState/index.ts +107 -107
  41. package/src/Invoice/InvoiceController/InvoiceControllerState/Stakeholder/index.ts +10 -10
  42. package/src/Invoice/InvoiceController/InvoiceControllerState/index.ts +60 -60
  43. package/src/Invoice/InvoiceController/fns/addGood.ts +11 -11
  44. package/src/Invoice/InvoiceController/fns/addGoodDiscount.ts +125 -125
  45. package/src/Invoice/InvoiceController/fns/addGoodDiscountV2.ts +84 -84
  46. package/src/Invoice/InvoiceController/fns/delGood.ts +41 -41
  47. package/src/Invoice/InvoiceController/fns/getGoodsSearch.ts +26 -26
  48. package/src/Invoice/InvoiceController/fns/importGoodsDrawer.ts +67 -67
  49. package/src/Invoice/InvoiceController/fns/mergeDetails.ts +163 -161
  50. package/src/Invoice/InvoiceController/fns/mergeDiscount.ts +28 -28
  51. package/src/Invoice/InvoiceController/fns/saveEditGood.ts +24 -24
  52. package/src/Invoice/InvoiceController/fns/setEditGood.ts +16 -16
  53. package/src/Invoice/InvoiceController/fns/setGoods.ts +10 -10
  54. package/src/Invoice/InvoiceController/fns/updateInvoiceNo.ts +8 -8
  55. package/src/Invoice/InvoiceController/index.ts +77 -77
  56. package/src/Invoice/_test/buyerNameSearch/index.tsx +41 -41
  57. package/src/Invoice/_test/deduction/index.tsx +935 -935
  58. package/src/Invoice/_test/draft/index.tsx +40 -40
  59. package/src/Invoice/_test/easiest/index.tsx +5 -5
  60. package/src/Invoice/_test/endowCode/index.tsx +1099 -1099
  61. package/src/Invoice/_test/goodsMenuExpand/index.tsx +32 -32
  62. package/src/Invoice/_test/importBuyer/index.tsx +74 -74
  63. package/src/Invoice/_test/importGoods/index.tsx +515 -515
  64. package/src/Invoice/_test/invoiceType/index.tsx +59 -59
  65. package/src/Invoice/_test/isInvoiceNo/index.tsx +12 -12
  66. package/src/Invoice/_test/replaceHead/index.tsx +22 -22
  67. package/src/Invoice/_test/retrieveData/index.tsx +22 -22
  68. package/src/Invoice/_test/seller/index.tsx +28 -28
  69. package/src/Invoice/_test/setDataSource/index.tsx +73 -73
  70. package/src/Invoice/_test/unit/index.tsx +19 -19
  71. package/src/Invoice/index.less +29 -29
  72. package/src/Invoice/index.md +53 -53
  73. package/src/Invoice/index.tsx +165 -165
  74. package/src/Invoice/tools/calculate/index.ts +112 -112
  75. package/src/Invoice/tools/coolingFn/index.ts +17 -17
  76. package/src/Invoice/tools/evaluate/index.ts +7 -7
  77. package/src/Invoice/tools/idGenerator/index.ts +2 -2
  78. package/src/Invoice/tools/itemName/index.ts +55 -55
  79. package/src/Invoice/tools/lazyFn/index.ts +19 -19
  80. package/src/Invoice/tools/mounting/index.ts +13 -13
  81. package/src/Invoice/tools/strringFn/index.ts +40 -40
  82. package/src/Invoice/tools/useToGenerateId/index.ts +8 -8
  83. package/src/Invoice/ui/default/AddComparisonDrawer/index.tsx +149 -149
  84. package/src/Invoice/ui/default/Buyer/index.less +219 -219
  85. package/src/Invoice/ui/default/Buyer/index.tsx +114 -114
  86. package/src/Invoice/ui/default/Buyer/ui/BuyerNameInput/index.tsx +166 -166
  87. package/src/Invoice/ui/default/Buyer/ui/ImportBuyerButton/index.tsx +21 -21
  88. package/src/Invoice/ui/default/EndowCodeDrawer/index.less +8 -8
  89. package/src/Invoice/ui/default/EndowCodeDrawer/index.tsx +431 -431
  90. package/src/Invoice/ui/default/GoodsList/hook/useColumns/autoFillFn/index.ts +533 -533
  91. package/src/Invoice/ui/default/GoodsList/hook/useColumns/index.tsx +664 -665
  92. package/src/Invoice/ui/default/GoodsList/hook/useColumns/ui/Drag/index.less +20 -20
  93. package/src/Invoice/ui/default/GoodsList/hook/useColumns/ui/Drag/index.tsx +202 -202
  94. package/src/Invoice/ui/default/GoodsList/hook/useColumns/ui/ItemCodeInput/index.less +18 -18
  95. package/src/Invoice/ui/default/GoodsList/hook/useColumns/ui/ItemCodeInput/index.tsx +58 -56
  96. package/src/Invoice/ui/default/GoodsList/hook/useColumns/ui/ItemNameInput/index.less +17 -17
  97. package/src/Invoice/ui/default/GoodsList/hook/useColumns/ui/ItemNameInput/index.tsx +128 -128
  98. package/src/Invoice/ui/default/GoodsList/hook/useColumns/ui/RowEditButton/index.tsx +30 -30
  99. package/src/Invoice/ui/default/GoodsList/hook/useColumns/ui/RowMenu/hook/_useAddComparison/index.tsx +43 -43
  100. package/src/Invoice/ui/default/GoodsList/hook/useColumns/ui/RowMenu/hook/useAddDiscount/index.tsx +76 -76
  101. package/src/Invoice/ui/default/GoodsList/hook/useColumns/ui/RowMenu/hook/useDelItem/index.tsx +41 -41
  102. package/src/Invoice/ui/default/GoodsList/hook/useColumns/ui/RowMenu/hook/useEndowCode/index.tsx +34 -34
  103. package/src/Invoice/ui/default/GoodsList/hook/useColumns/ui/RowMenu/index.less +13 -13
  104. package/src/Invoice/ui/default/GoodsList/hook/useColumns/ui/RowMenu/index.tsx +98 -98
  105. package/src/Invoice/ui/default/GoodsList/hook/useColumns/ui/RowSaveButton/index.tsx +14 -14
  106. package/src/Invoice/ui/default/GoodsList/hook/useColumns/ui/TitleText/index.tsx +20 -20
  107. package/src/Invoice/ui/default/GoodsList/hook/useDeduction/index.tsx +24 -24
  108. package/src/Invoice/ui/default/GoodsList/hook/useOnRow/index.tsx +39 -39
  109. package/src/Invoice/ui/default/GoodsList/hook/useRowSelection/index.tsx +111 -111
  110. package/src/Invoice/ui/default/GoodsList/hook/useWindowClick/index.tsx +23 -23
  111. package/src/Invoice/ui/default/GoodsList/index.less +177 -177
  112. package/src/Invoice/ui/default/GoodsList/index.tsx +191 -191
  113. package/src/Invoice/ui/default/GoodsList/ui/AddRowButton/index.tsx +65 -65
  114. package/src/Invoice/ui/default/GoodsList/ui/BulkMenu/hooks/useAddDiscountRowButton/index.less +21 -21
  115. package/src/Invoice/ui/default/GoodsList/ui/BulkMenu/hooks/useAddDiscountRowButton/index.tsx +244 -244
  116. package/src/Invoice/ui/default/GoodsList/ui/BulkMenu/hooks/useCommodityComparisonButton/index.tsx +75 -75
  117. package/src/Invoice/ui/default/GoodsList/ui/BulkMenu/hooks/useDelRowButton/index.tsx +69 -69
  118. package/src/Invoice/ui/default/GoodsList/ui/BulkMenu/hooks/useEndowCodeButton/index.tsx +58 -58
  119. package/src/Invoice/ui/default/GoodsList/ui/BulkMenu/hooks/useMergeDetails/index.tsx +37 -37
  120. package/src/Invoice/ui/default/GoodsList/ui/BulkMenu/hooks/useMergeDiscount/index.tsx +36 -36
  121. package/src/Invoice/ui/default/GoodsList/ui/BulkMenu/index.tsx +37 -37
  122. package/src/Invoice/ui/default/GoodsList/ui/DescribeSwitch/index.tsx +36 -36
  123. package/src/Invoice/ui/default/GoodsList/ui/Search/index.less +10 -10
  124. package/src/Invoice/ui/default/GoodsList/ui/Search/index.tsx +52 -52
  125. package/src/Invoice/ui/default/GoodsList/ui/Statistics/index.less +18 -18
  126. package/src/Invoice/ui/default/GoodsList/ui/Statistics/index.tsx +109 -109
  127. package/src/Invoice/ui/default/GoodsList/ui/TableRow/index.less +13 -13
  128. package/src/Invoice/ui/default/GoodsList/ui/TableRow/index.tsx +46 -46
  129. package/src/Invoice/ui/default/GoodsList/ui/TableVirtual/index.less +38 -38
  130. package/src/Invoice/ui/default/GoodsList/ui/TableVirtual/index.tsx +108 -108
  131. package/src/Invoice/ui/default/GoodsList/ui/TableVirtual.o/index.less +44 -44
  132. package/src/Invoice/ui/default/GoodsList/ui/TableVirtual.o/index.tsx +96 -96
  133. package/src/Invoice/ui/default/GoodsList/ui/TaxIncludedSwitch/index.tsx +30 -30
  134. package/src/Invoice/ui/default/ImportBuyerDrawer/index.tsx +75 -75
  135. package/src/Invoice/ui/default/ImportGoodsDrawer/index.tsx +193 -193
  136. package/src/Invoice/ui/default/InvoiceHeader/index.less +68 -68
  137. package/src/Invoice/ui/default/InvoiceHeader/index.tsx +246 -246
  138. package/src/Invoice/ui/default/Seller/index.less +113 -113
  139. package/src/Invoice/ui/default/Seller/index.tsx +98 -98
  140. package/src/Invoice/ui/default/Sign/index.less +14 -14
  141. package/src/Invoice/ui/default/Sign/index.tsx +71 -71
  142. package/src/Invoice/ui/digtal/GoodsList/hook/useColumns/autoFillFn/index.ts +519 -519
  143. package/src/Invoice/ui/digtal/GoodsList/hook/useColumns/index.tsx +648 -648
  144. package/src/Invoice/ui/digtal/GoodsList/hook/useColumns/svg/plus.svg +11 -11
  145. package/src/Invoice/ui/digtal/GoodsList/hook/useColumns/ui/Drag/index.less +20 -20
  146. package/src/Invoice/ui/digtal/GoodsList/hook/useColumns/ui/Drag/index.tsx +186 -186
  147. package/src/Invoice/ui/digtal/GoodsList/hook/useColumns/ui/ItemNameInput/index.less +9 -9
  148. package/src/Invoice/ui/digtal/GoodsList/hook/useColumns/ui/ItemNameInput/index.tsx +50 -50
  149. package/src/Invoice/ui/digtal/GoodsList/hook/useColumns/ui/RowEditButton/index.tsx +30 -30
  150. package/src/Invoice/ui/digtal/GoodsList/hook/useColumns/ui/RowMenu/hook/_useAddComparison/index.tsx +43 -43
  151. package/src/Invoice/ui/digtal/GoodsList/hook/useColumns/ui/RowMenu/hook/useAddDiscount/index.tsx +76 -76
  152. package/src/Invoice/ui/digtal/GoodsList/hook/useColumns/ui/RowMenu/hook/useDelItem/index.tsx +41 -41
  153. package/src/Invoice/ui/digtal/GoodsList/hook/useColumns/ui/RowMenu/hook/useEndowCode/index.tsx +34 -34
  154. package/src/Invoice/ui/digtal/GoodsList/hook/useColumns/ui/RowMenu/index.less +13 -13
  155. package/src/Invoice/ui/digtal/GoodsList/hook/useColumns/ui/RowMenu/index.tsx +98 -98
  156. package/src/Invoice/ui/digtal/GoodsList/hook/useColumns/ui/RowSaveButton/index.tsx +14 -14
  157. package/src/Invoice/ui/digtal/GoodsList/hook/useColumns/ui/TitleText/index.tsx +20 -20
  158. package/src/Invoice/ui/digtal/GoodsList/hook/useOnRow/index.tsx +39 -39
  159. package/src/Invoice/ui/digtal/GoodsList/hook/useRowSelection/index.tsx +121 -121
  160. package/src/Invoice/ui/digtal/GoodsList/hook/useWindowClick/index.tsx +23 -23
  161. package/src/Invoice/ui/digtal/GoodsList/index.less +56 -56
  162. package/src/Invoice/ui/digtal/GoodsList/index.tsx +180 -180
  163. package/src/Invoice/ui/digtal/GoodsList/ui/AddRowButton/index.tsx +65 -65
  164. package/src/Invoice/ui/digtal/GoodsList/ui/BulkMenu/hooks/useAddDiscountRowButton/index.tsx +341 -341
  165. package/src/Invoice/ui/digtal/GoodsList/ui/BulkMenu/hooks/useAddDiscountRowButton/svg/add.svg +11 -11
  166. package/src/Invoice/ui/digtal/GoodsList/ui/BulkMenu/hooks/useCommodityComparisonButton/index.tsx +75 -75
  167. package/src/Invoice/ui/digtal/GoodsList/ui/BulkMenu/hooks/useDelRowButton/index.tsx +50 -50
  168. package/src/Invoice/ui/digtal/GoodsList/ui/BulkMenu/hooks/useEmptyRefill/index.tsx +35 -35
  169. package/src/Invoice/ui/digtal/GoodsList/ui/BulkMenu/hooks/useEndowCodeButton/index.tsx +82 -82
  170. package/src/Invoice/ui/digtal/GoodsList/ui/BulkMenu/hooks/useReselectInvoiceType/index.tsx +57 -57
  171. package/src/Invoice/ui/digtal/GoodsList/ui/DescribeSwitch/index.tsx +36 -36
  172. package/src/Invoice/ui/digtal/GoodsList/ui/Search/index.less +11 -11
  173. package/src/Invoice/ui/digtal/GoodsList/ui/Search/index.tsx +50 -50
  174. package/src/Invoice/ui/digtal/GoodsList/ui/Statistics/index.less +53 -53
  175. package/src/Invoice/ui/digtal/GoodsList/ui/Statistics/index.tsx +99 -99
  176. package/src/Invoice/ui/digtal/GoodsList/ui/Statistics/svg/fork.svg +11 -11
  177. package/src/Invoice/ui/digtal/GoodsList/ui/TableRow/index.less +13 -13
  178. package/src/Invoice/ui/digtal/GoodsList/ui/TableRow/index.tsx +40 -40
  179. package/src/Invoice/ui/digtal/GoodsList/ui/TableVirtual/index.less +38 -38
  180. package/src/Invoice/ui/digtal/GoodsList/ui/TableVirtual/index.tsx +108 -108
  181. package/src/Invoice/ui/digtal/GoodsList/ui/TableVirtual.o/index.less +44 -44
  182. package/src/Invoice/ui/digtal/GoodsList/ui/TableVirtual.o/index.tsx +96 -96
  183. package/src/Invoice/ui/digtal/GoodsList/ui/TaxIncludedSwitch/index.tsx +30 -30
  184. package/src/Invoice/ui/digtal/InvoiceHeader/index.less +57 -57
  185. package/src/Invoice/ui/digtal/InvoiceHeader/index.tsx +77 -77
  186. package/src/Invoice/ui/digtal/Sign/index.less +48 -48
  187. package/src/Invoice/ui/digtal/Sign/index.tsx +89 -89
  188. package/src/Invoice/ui/digtal/Stakeholder/index.less +75 -75
  189. package/src/Invoice/ui/digtal/Stakeholder/index.tsx +388 -388
  190. package/src/Invoice/ui/digtal/Stakeholder/svg/arrowDown.svg +2 -2
  191. package/src/Invoice/ui/digtal/Stakeholder/svg/arrowUp.svg +2 -2
  192. package/src/Invoice/ui/digtal/Stakeholder/svg/plus.svg +11 -11
  193. package/src/InvoiceTypeModal/_test/easiest/index.tsx +31 -31
  194. package/src/InvoiceTypeModal/index.less +7 -7
  195. package/src/InvoiceTypeModal/index.md +5 -5
  196. package/src/InvoiceTypeModal/index.tsx +153 -153
  197. package/src/index.ts +9 -9
  198. package/tsconfig.json +31 -31
  199. package/typings.d.ts +3 -3
  200. package/yarn.e.lock +14331 -14331
@@ -1,520 +1,520 @@
1
- /**
2
- * 数量 保留15位数字
3
- * 单价 保留15位数字
4
- * 金额 小数点后 2位
5
- * 税额 小数点后 2位
6
- */
7
- import { WrappedFormUtils } from 'kts-components-antd-x3/lib/form/Form';
8
- import InvoiceController, { IGood, LineAttributeType } from '../../../../../../InvoiceController';
9
- import evaluate from '../../../../../../tools/evaluate';
10
- import { message } from 'kts-components-antd-x3'
11
- import { format2, format15, countTaxAmount, countAmountExcludeTax, countPrice } from '../../../../../../tools/calculate';
12
- import moment from 'moment';
13
-
14
- export { format2, format15 } from '../../../../../../tools/calculate';
15
-
16
-
17
-
18
- /** 延迟函数 */
19
- const lazyFn = (fn: Function, delayed: number = 200) => {
20
- let timer: any;
21
- return (...par: any[]) => {
22
- clearTimeout(timer);
23
- timer = setTimeout(() => {
24
- timer = undefined;
25
- fn.apply(null, par);
26
- }, delayed);
27
- };
28
- };
29
-
30
- let promptErrV: any = {}
31
-
32
- /** 提示错误 */
33
- const promptErr = (err: any) => {
34
- if (!err) return false;
35
- if (err.errors[0].message === 'lineAmountIncludeTax need to revalidate') return true;
36
- if (err.errors[0].message === 'lineAmountExcludeTax need to revalidate') return true;
37
- if (err.errors[0].message === 'priceIncludeTax need to revalidate') return true;
38
- if (err.errors[0].message === 'priceExcludeTax need to revalidate') return true;
39
-
40
- if (new Date().getTime() - promptErrV.t > 2000 || err.errors[0].message !== promptErrV.m) {
41
- promptErrV.t = new Date().getTime();
42
- promptErrV.m = err.errors[0].message;
43
- message.error({ content: err.errors[0].message, duration: 2 });
44
- }
45
-
46
- return true;
47
- }
48
-
49
- /** 清除计算中启动字段 */
50
- export const clearCalculatingField = async (controller: InvoiceController) => controller.run(async s => s.calculatingField = '');
51
-
52
- /** 数量改变了 */
53
- export const onChangeQuantity = lazyFn(
54
- (controller: InvoiceController, form: WrappedFormUtils, record: IGood) => {
55
- form.validateFields(async (err, values) => {
56
- err = err || {};
57
-
58
- if (!values.quantity && values.quantity !== 0) {
59
- await controller.setEditGood({ quantity: undefined });
60
- await clearCalculatingField(controller);
61
- return;
62
- }
63
- if (err.quantity) {
64
- await clearCalculatingField(controller);
65
- return
66
- };
67
-
68
- const calculatingDigits = controller.state.calculatingDigits;
69
- const quantity = format15(values.quantity, calculatingDigits);
70
- await controller.setEditGood({ quantity });
71
- form.setFieldsValue({ quantity });
72
-
73
- // 是否含税
74
- if (controller.state.goodsListState.isTaxIncluded) {
75
- // 含税
76
- if (!err.priceIncludeTax && values.priceIncludeTax) {
77
- // 可以找到 单价(含税)
78
- const priceIncludeTax = format15(values.priceIncludeTax, calculatingDigits);
79
- const lineAmountIncludeTax = format2(evaluate(`${priceIncludeTax} * ${quantity}`));
80
- form.setFieldsValue({ lineAmountIncludeTax });
81
- await controller.setEditGood({ lineAmountIncludeTax });
82
- } else if (!err.lineAmountIncludeTax && values.lineAmountIncludeTax) {
83
- // 可以找到 金额(含税)
84
- const lineAmountIncludeTax = format2(values.lineAmountIncludeTax);
85
- const priceIncludeTax = format15(
86
- evaluate(`${lineAmountIncludeTax} / ${quantity}`),
87
- calculatingDigits);
88
- form.setFieldsValue({ priceIncludeTax });
89
- await controller.setEditGood({ priceIncludeTax });
90
- }
91
-
92
- // 更新不含税
93
- await updateUnitPriceExcludingTax(controller, form, record);
94
- } else {
95
- // 不含税
96
- if (!err.priceExcludeTax && values.priceExcludeTax) {
97
- const priceExcludeTax = format15(values.priceExcludeTax, calculatingDigits);
98
- const lineAmountExcludeTax = format2(evaluate(`${quantity} * ${priceExcludeTax}`));
99
- form.setFieldsValue({ lineAmountExcludeTax });
100
- await controller.setEditGood({ lineAmountExcludeTax, quantity });
101
- } else if (!err.lineAmountExcludeTax && values.lineAmountExcludeTax) {
102
- const lineAmountExcludeTax = format2(values.lineAmountExcludeTax);
103
- const priceExcludeTax = format15(evaluate(`${lineAmountExcludeTax} / ${quantity}`), calculatingDigits);
104
- form.setFieldsValue({ priceExcludeTax });
105
- await controller.setEditGood({ priceExcludeTax, quantity });
106
- }
107
-
108
- // 更新含税
109
- await updateUnitPriceTax(controller, form, record);
110
- }
111
-
112
- // 清楚 计算中启动字段
113
- await clearCalculatingField(controller);
114
- });
115
- },
116
- 1000,
117
- );
118
-
119
- /** 单价(含税) */
120
- export const onChangePriceIncludeTax = lazyFn(
121
- (controller: InvoiceController, form: WrappedFormUtils, record: IGood) => {
122
- form.validateFields(async (err, values) => {
123
- err = err || {};
124
-
125
- if (!values.priceIncludeTax && values.priceIncludeTax !== 0) {
126
- await controller.setEditGood({ priceIncludeTax: undefined, priceExcludeTax: undefined });
127
- await clearCalculatingField(controller);
128
- return;
129
- }
130
- if (err.priceIncludeTax) {
131
- await clearCalculatingField(controller);
132
- return;
133
- }
134
-
135
- const calculatingDigits = controller.state.calculatingDigits;
136
- const priceIncludeTax = format15(values.priceIncludeTax, calculatingDigits);
137
- await controller.setEditGood({ priceIncludeTax });
138
- form.setFieldsValue({ priceIncludeTax });
139
-
140
- // 是否有数量
141
- if (!err.quantity && values.quantity) {
142
- const quantity = format15(values.quantity, calculatingDigits);
143
- const lineAmountIncludeTax = format2(evaluate(`${quantity} * ${priceIncludeTax}`));
144
- form.setFieldsValue({ lineAmountIncludeTax });
145
- await controller.setEditGood({ lineAmountIncludeTax });
146
- } else if (!err.lineAmountIncludeTax && values.lineAmountIncludeTax) {
147
- const lineAmountIncludeTax = format2(values.lineAmountIncludeTax);
148
- const quantity = format15(evaluate(`${lineAmountIncludeTax} / ${priceIncludeTax}`), calculatingDigits);
149
- form.setFieldsValue({ quantity });
150
- await controller.setEditGood({ quantity });
151
- }
152
-
153
- // 更新不含税
154
- await updateUnitPriceExcludingTax(controller, form, record);
155
-
156
- // 清楚 计算中启动字段
157
- await clearCalculatingField(controller);
158
- });
159
- },
160
- 1000,
161
- );
162
-
163
- /** 单价(不含税) */
164
- export const onChangePriceExcludeTax = lazyFn(
165
- (controller: InvoiceController, form: WrappedFormUtils, record: IGood) => {
166
- form.validateFields(async (err, values) => {
167
- err = err || {};
168
-
169
- if (!values.priceExcludeTax && values.priceExcludeTax !== 0) {
170
- await controller.setEditGood({ priceIncludeTax: undefined, priceExcludeTax: undefined });
171
- await clearCalculatingField(controller);
172
- return;
173
- }
174
- if (err.priceExcludeTax) {
175
- await clearCalculatingField(controller);
176
- return;
177
- }
178
-
179
- const calculatingDigits = controller.state.calculatingDigits;
180
- const priceExcludeTax = format15(values.priceExcludeTax, calculatingDigits);
181
- await controller.setEditGood({ priceExcludeTax });
182
- form.setFieldsValue({ priceExcludeTax });
183
-
184
- // 是否有数量
185
- if (!err.quantity && values.quantity) {
186
- const quantity = format15(values.quantity, calculatingDigits);
187
- const lineAmountExcludeTax = format2(evaluate(`${quantity} * ${priceExcludeTax}`));
188
- form.setFieldsValue({ lineAmountExcludeTax });
189
- await controller.setEditGood({ lineAmountExcludeTax });
190
- } else if (!err.lineAmountExcludeTax && values.lineAmountExcludeTax) {
191
- const lineAmountExcludeTax = format2(values.lineAmountExcludeTax);
192
- const quantity = format15(
193
- evaluate(`${lineAmountExcludeTax} / ${priceExcludeTax}`),
194
- calculatingDigits
195
- );
196
- form.setFieldsValue({ quantity });
197
- await controller.setEditGood({ quantity });
198
- }
199
-
200
- // 更新含税
201
- await updateUnitPriceTax(controller, form, record);
202
-
203
- // 清楚 计算中启动字段
204
- await clearCalculatingField(controller);
205
- });
206
- },
207
- 1000,
208
- );
209
-
210
- /** 金额(含税) */
211
- export const onChangeLineAmountIncludeTax = lazyFn(
212
- (controller: InvoiceController, form: WrappedFormUtils, record: IGood) => {
213
- form.validateFields(async (err, values) => {
214
-
215
- err = err || {};
216
- if (promptErr(err.lineAmountIncludeTax) || !values.lineAmountIncludeTax) {
217
- // 更新不含税
218
- await controller.setEditGood({ lineAmountIncludeTax: undefined, lineAmountExcludeTax: undefined });
219
- await updateUnitPriceExcludingTax(controller, form, record);
220
- await clearCalculatingField(controller);
221
- return;
222
- }
223
-
224
- const calculatingDigits = controller.state.calculatingDigits;
225
- const lineAmountIncludeTax = format2(values.lineAmountIncludeTax);
226
- await controller.setEditGood({ lineAmountIncludeTax });
227
- form.setFieldsValue({ lineAmountIncludeTax });
228
-
229
- // 是否有数量
230
- if (!err.quantity && values.quantity) {
231
- const quantity = format15(values.quantity, calculatingDigits);
232
- const priceIncludeTax = format15(evaluate(`${lineAmountIncludeTax} / ${quantity}`), calculatingDigits);
233
- form.setFieldsValue({ priceIncludeTax });
234
- await controller.setEditGood({ priceIncludeTax });
235
- } else if (!err.priceIncludeTax && (values.priceIncludeTax || values.priceIncludeTax === 0)) {
236
- const priceIncludeTax = format15(values.priceIncludeTax, calculatingDigits);
237
- const quantity = format15(evaluate(`${lineAmountIncludeTax} / ${priceIncludeTax}`), calculatingDigits);
238
- form.setFieldsValue({ quantity });
239
- await controller.setEditGood({ quantity });
240
- }
241
-
242
- // 更新不含税
243
- await updateUnitPriceExcludingTax(controller, form, record);
244
-
245
- // 清楚 计算中启动字段
246
- await clearCalculatingField(controller);
247
- });
248
- },
249
- 1000,
250
- );
251
-
252
- /** 金额(不含税) */
253
- export const onChangeLineAmountExcludeTax = lazyFn(
254
- (controller: InvoiceController, form: WrappedFormUtils, record: IGood) => {
255
- form.validateFields(async (err, values) => {
256
- err = err || {};
257
- if (promptErr(err.lineAmountExcludeTax) || !values.lineAmountExcludeTax) {
258
- // 更新含税
259
- await controller.setEditGood({ lineAmountIncludeTax: undefined, lineAmountExcludeTax: undefined });
260
- await updateUnitPriceTax(controller, form, record);
261
- await clearCalculatingField(controller);
262
- return;
263
- }
264
- const calculatingDigits = controller.state.calculatingDigits;
265
- const lineAmountExcludeTax = format2(values.lineAmountExcludeTax);
266
- await controller.setEditGood({ lineAmountExcludeTax });
267
- form.setFieldsValue({ lineAmountExcludeTax });
268
-
269
- // 是否有数量
270
- if (!err.quantity && values.quantity) {
271
- const quantity = format15(values.quantity, calculatingDigits);
272
- const priceExcludeTax = format15(evaluate(`${lineAmountExcludeTax} / ${quantity}`), calculatingDigits);
273
- form.setFieldsValue({ priceExcludeTax });
274
- await controller.setEditGood({ priceExcludeTax });
275
- } else if (!err.priceExcludeTax && values.priceExcludeTax) {
276
- const priceExcludeTax = format15(values.priceExcludeTax, calculatingDigits);
277
- const quantity = format15(evaluate(`${lineAmountExcludeTax} / ${priceExcludeTax}`), calculatingDigits);
278
- form.setFieldsValue({ quantity });
279
- await controller.setEditGood({ quantity });
280
- }
281
-
282
- // 更新含税
283
- await updateUnitPriceTax(controller, form, record);
284
-
285
- // 清楚 计算中启动字段
286
- await clearCalculatingField(controller);
287
- });
288
- },
289
- 1000,
290
- );
291
-
292
- /** 税率 */
293
- export const onChangeTaxRate = lazyFn(
294
- (controller: InvoiceController, form: WrappedFormUtils, record: IGood) => {
295
-
296
- form.validateFields(async (err, values) => {
297
- err = err || {};
298
- if (promptErr(err.taxRate) || (!values.taxRate && values.taxRate !== 0)) return;
299
-
300
- let taxRate = parseFloat(values.taxRate);
301
- await controller.setEditGood({ taxRate });
302
-
303
- // 去掉赋码
304
- (() => {
305
- const cache = controller.state.goodsListState.endowCode.cache;
306
- const record = controller.state.goodsListState.editGood;
307
- if (record && cache[record.$index]) {
308
- record.favouredPolicyName = cache[record.$index].favouredPolicyName;
309
- record.favouredPolicyMark = cache[record.$index].favouredPolicyMark;
310
- record.taxFreeType = cache[record.$index].taxFreeType;
311
- cache[record.$index] = undefined;
312
- }
313
- })()
314
-
315
- // 是否含税
316
- if (controller.state.goodsListState.isTaxIncluded) {
317
- await updateUnitPriceExcludingTax(controller, form, record);
318
- } else {
319
- await updateUnitPriceTax(controller, form, record);
320
- }
321
-
322
- // 清楚 计算中启动字段
323
- await clearCalculatingField(controller);
324
- });
325
- },
326
- 1000,
327
- );
328
-
329
- /** 小规模纳税人 1% 和 3% 自动赋码免税 */
330
- export function dutyFree(controller: InvoiceController, taxRate: number, form: WrappedFormUtils<any>, record: IGood) {
331
-
332
- const cache = controller.state.goodsListState.endowCode.cache;
333
- const invoiceType = controller.state.invoiceType;
334
-
335
- // 4月1日至12月31日
336
- console.log('===> 小规模纳税人免税逻辑');
337
- console.log('===> invoiceType', invoiceType);
338
- console.log('===> en', controller.state.en);
339
- console.log('===> taxRate', taxRate);
340
- console.log('===> state', controller.state);
341
-
342
- if (moment().valueOf() > moment('2022-12-31 23:59').valueOf()) return taxRate;
343
- if (controller.state.en !== '08') return taxRate;
344
- if (invoiceType !== '10' && invoiceType !== '04') return taxRate;
345
-
346
- if (taxRate === 1 || taxRate === 3) {
347
- cache[record.$index] = { favouredPolicyName: record.favouredPolicyName, favouredPolicyMark: record.favouredPolicyMark, taxFreeType: record.taxFreeType }
348
- record.favouredPolicyName = '免税';
349
- record.taxRate = 0;
350
- record.favouredPolicyMark = 1;
351
- record.taxFreeType = 1 as any;
352
- form.setFieldsValue({ taxRate: 0 });
353
- return 0;
354
- }
355
- }
356
-
357
- /** 含税 => 更新(不含税) */
358
- export const updateUnitPriceExcludingTax = async (controller: InvoiceController, form: WrappedFormUtils, record: IGood) => {
359
- return new Promise((resolve) => {
360
- form.validateFields(async (err, values) => {
361
-
362
- err = err || {};
363
-
364
- /** 税额 */
365
- let taxAmount;
366
-
367
- /** 金额(不含税) */
368
- let lineAmountExcludeTax;
369
-
370
- /** 不含税单价 */
371
- let priceExcludeTax;
372
-
373
- /** 扣除额 */
374
- const deduction = controller.state.goodsListState.deduction;
375
-
376
- // 计算税额
377
- if (!promptErr(err.lineAmountIncludeTax) && !promptErr(err.taxRate)) {
378
- taxAmount = countTaxAmount(values.lineAmountIncludeTax, deduction, values.taxRate);
379
- }
380
- form.setFieldsValue({ taxAmount });
381
- await controller.setEditGood({ taxAmount });
382
-
383
- // 计算 金额(不含税)
384
- if ((taxAmount || taxAmount === 0) && !promptErr(err.lineAmountIncludeTax)) {
385
- lineAmountExcludeTax = countAmountExcludeTax(values.lineAmountIncludeTax, taxAmount);
386
- }
387
- form.setFieldsValue({ lineAmountExcludeTax });
388
- await controller.setEditGood({ lineAmountExcludeTax });
389
-
390
- // 单价(不含税)
391
- if (lineAmountExcludeTax && !promptErr(err.quantity)) {
392
- priceExcludeTax = countPrice(lineAmountExcludeTax, values.quantity, controller.state.calculatingDigits);
393
- }
394
- form.setFieldsValue({ priceExcludeTax });
395
- await controller.setEditGood({ priceExcludeTax });
396
- });
397
-
398
- resolve(undefined)
399
- })
400
- };
401
-
402
- /** 不含税 => 更新(含税) */
403
- export const updateUnitPriceTax = async (controller: InvoiceController, form: WrappedFormUtils, record: IGood) => {
404
- return new Promise((resolve) => {
405
- form.validateFields(async (err, values) => {
406
- err = err || {};
407
-
408
- if (
409
- !err.taxRat &&
410
- (values.taxRate || values.taxRate === 0) &&
411
- !promptErr(err.lineAmountExcludeTax) &&
412
- (values.lineAmountExcludeTax || values.lineAmountExcludeTax === 0)
413
- ) {
414
-
415
- const calculatingDigits = controller.state.calculatingDigits;
416
- // 金额(含税)= 金额(不含税)* (1+ 税率)
417
- const lineAmountExcludeTax = format2(values.lineAmountExcludeTax);
418
- const lineAmountIncludeTax = format2(evaluate(`${lineAmountExcludeTax} * (1+(${values.taxRate}/100))`));
419
- await controller.setEditGood({ lineAmountIncludeTax });
420
-
421
- // 单价(含税) = 金额(含税) / (數量)
422
- // 是否有数量
423
- if (!err.quantity && values.quantity) {
424
- const priceIncludeTax = format15(evaluate(`${lineAmountIncludeTax} / ${values.quantity}`), calculatingDigits);
425
- await controller.setEditGood({ priceIncludeTax });
426
- }
427
-
428
- // 税额 = 金额(含税)-金额(不含税)
429
- const taxAmount = evaluate(`${lineAmountIncludeTax} - ${lineAmountExcludeTax}`);
430
- form.setFieldsValue({ taxAmount });
431
- await controller.setEditGood({ taxAmount });
432
- } else {
433
- form.setFieldsValue({ taxAmount: undefined });
434
- await controller.setEditGood({ taxAmount: undefined });
435
- }
436
- // 单价(含税) = 单价(不含税) * (1+税率)
437
- // if (
438
- // !err.taxRat &&
439
- // (values.taxRate || values.taxRate === 0) &&
440
- // !promptErr(err.priceExcludeTax) &&
441
- // (values.priceExcludeTax || values.priceExcludeTax === 0)
442
- // ) {
443
- // const priceExcludeTax = format15(values.priceExcludeTax);
444
- // const priceIncludeTax = format15(evaluate(`${priceExcludeTax} * (1+(${values.taxRate}/100))`));
445
- // await controller.setEditGood({ priceIncludeTax });
446
- // }
447
-
448
- resolve(undefined)
449
- });
450
- })
451
- };
452
-
453
- /** 保存到编辑货物 */
454
- export const onSaveEditGood = lazyFn(
455
- (
456
- controller: InvoiceController,
457
- form: WrappedFormUtils,
458
- record: IGood,
459
- id: string,
460
- ) => {
461
- form.validateFields(async (err, values) => {
462
- err = err || {};
463
- if (err[id]) return;
464
-
465
- const v = {} as any;
466
- v[id] = values[id];
467
- await controller.setEditGood({ ...v });
468
- });
469
- },
470
- 1000,
471
- );
472
-
473
- /** 单调赋码 */
474
- export const endowCode = async (controller: InvoiceController, goods: IGood) => {
475
- await controller.wait();
476
- await controller.saveEditGood();
477
- await controller.pipeline(async (s) => {
478
- if (s.goodsListState.form && s.goodsListState.editGood?.$index === goods?.$index) {
479
- const err: any = s.goodsListState.form.getFieldsError();
480
- for (let key in err) {
481
- if (!err[key]) continue;
482
- message.error(err[key][0]);
483
- return;
484
- }
485
- }
486
-
487
- let g = s.goodsListState.goodsMap.get(goods.$index) as any;
488
- let i = s.goodsListState.goodsList.indexOf(g);
489
-
490
- switch (goods.lineAttribute) {
491
- case LineAttributeType.正常:
492
- s.goodsListState.endowCode.endowcodeGoodIndex = [goods.$index];
493
- break;
494
-
495
- case LineAttributeType.折扣行:
496
-
497
- s.goodsListState.endowCode.endowcodeGoodIndex = [goods.$index, s.goodsListState.goodsList[i - 1].$index];
498
- break;
499
-
500
- case LineAttributeType.被折扣行:
501
- s.goodsListState.endowCode.endowcodeGoodIndex = [goods.$index, s.goodsListState.goodsList[i + 1].$index];
502
- break;
503
- }
504
- })();
505
- }
506
-
507
- /** 修改了 项目名称 */
508
- export const onChangeItemName = async (controller: InvoiceController, form: WrappedFormUtils<any>, record: IGood) => {
509
- controller.run(async s => {
510
- const value = form.getFieldsValue().itemName;
511
-
512
- if (s.goodsListState.isMyShow) {
513
- await controller.setEditGood({ itemNameSelf: value });
514
- record.itemName && await controller.setEditGood({ itemName: record.itemName });
515
- } else {
516
- await controller.setEditGood({ itemName: value });
517
- record.itemNameSelf && await controller.setEditGood({ itemNameSelf: record.itemNameSelf });
518
- }
519
- })
1
+ /**
2
+ * 数量 保留15位数字
3
+ * 单价 保留15位数字
4
+ * 金额 小数点后 2位
5
+ * 税额 小数点后 2位
6
+ */
7
+ import { WrappedFormUtils } from 'kts-components-antd-x3/lib/form/Form';
8
+ import InvoiceController, { IGood, LineAttributeType } from '../../../../../../InvoiceController';
9
+ import evaluate from '../../../../../../tools/evaluate';
10
+ import { message } from 'kts-components-antd-x3'
11
+ import { format2, format15, countTaxAmount, countAmountExcludeTax, countPrice } from '../../../../../../tools/calculate';
12
+ import moment from 'moment';
13
+
14
+ export { format2, format15 } from '../../../../../../tools/calculate';
15
+
16
+
17
+
18
+ /** 延迟函数 */
19
+ const lazyFn = (fn: Function, delayed: number = 200) => {
20
+ let timer: any;
21
+ return (...par: any[]) => {
22
+ clearTimeout(timer);
23
+ timer = setTimeout(() => {
24
+ timer = undefined;
25
+ fn.apply(null, par);
26
+ }, delayed);
27
+ };
28
+ };
29
+
30
+ let promptErrV: any = {}
31
+
32
+ /** 提示错误 */
33
+ const promptErr = (err: any) => {
34
+ if (!err) return false;
35
+ if (err.errors[0].message === 'lineAmountIncludeTax need to revalidate') return true;
36
+ if (err.errors[0].message === 'lineAmountExcludeTax need to revalidate') return true;
37
+ if (err.errors[0].message === 'priceIncludeTax need to revalidate') return true;
38
+ if (err.errors[0].message === 'priceExcludeTax need to revalidate') return true;
39
+
40
+ if (new Date().getTime() - promptErrV.t > 2000 || err.errors[0].message !== promptErrV.m) {
41
+ promptErrV.t = new Date().getTime();
42
+ promptErrV.m = err.errors[0].message;
43
+ message.error({ content: err.errors[0].message, duration: 2 });
44
+ }
45
+
46
+ return true;
47
+ }
48
+
49
+ /** 清除计算中启动字段 */
50
+ export const clearCalculatingField = async (controller: InvoiceController) => controller.run(async s => s.calculatingField = '');
51
+
52
+ /** 数量改变了 */
53
+ export const onChangeQuantity = lazyFn(
54
+ (controller: InvoiceController, form: WrappedFormUtils, record: IGood) => {
55
+ form.validateFields(async (err, values) => {
56
+ err = err || {};
57
+
58
+ if (!values.quantity && values.quantity !== 0) {
59
+ await controller.setEditGood({ quantity: undefined });
60
+ await clearCalculatingField(controller);
61
+ return;
62
+ }
63
+ if (err.quantity) {
64
+ await clearCalculatingField(controller);
65
+ return
66
+ };
67
+
68
+ const calculatingDigits = controller.state.calculatingDigits;
69
+ const quantity = format15(values.quantity, calculatingDigits);
70
+ await controller.setEditGood({ quantity });
71
+ form.setFieldsValue({ quantity });
72
+
73
+ // 是否含税
74
+ if (controller.state.goodsListState.isTaxIncluded) {
75
+ // 含税
76
+ if (!err.priceIncludeTax && values.priceIncludeTax) {
77
+ // 可以找到 单价(含税)
78
+ const priceIncludeTax = format15(values.priceIncludeTax, calculatingDigits);
79
+ const lineAmountIncludeTax = format2(evaluate(`${priceIncludeTax} * ${quantity}`));
80
+ form.setFieldsValue({ lineAmountIncludeTax });
81
+ await controller.setEditGood({ lineAmountIncludeTax });
82
+ } else if (!err.lineAmountIncludeTax && values.lineAmountIncludeTax) {
83
+ // 可以找到 金额(含税)
84
+ const lineAmountIncludeTax = format2(values.lineAmountIncludeTax);
85
+ const priceIncludeTax = format15(
86
+ evaluate(`${lineAmountIncludeTax} / ${quantity}`),
87
+ calculatingDigits);
88
+ form.setFieldsValue({ priceIncludeTax });
89
+ await controller.setEditGood({ priceIncludeTax });
90
+ }
91
+
92
+ // 更新不含税
93
+ await updateUnitPriceExcludingTax(controller, form, record);
94
+ } else {
95
+ // 不含税
96
+ if (!err.priceExcludeTax && values.priceExcludeTax) {
97
+ const priceExcludeTax = format15(values.priceExcludeTax, calculatingDigits);
98
+ const lineAmountExcludeTax = format2(evaluate(`${quantity} * ${priceExcludeTax}`));
99
+ form.setFieldsValue({ lineAmountExcludeTax });
100
+ await controller.setEditGood({ lineAmountExcludeTax, quantity });
101
+ } else if (!err.lineAmountExcludeTax && values.lineAmountExcludeTax) {
102
+ const lineAmountExcludeTax = format2(values.lineAmountExcludeTax);
103
+ const priceExcludeTax = format15(evaluate(`${lineAmountExcludeTax} / ${quantity}`), calculatingDigits);
104
+ form.setFieldsValue({ priceExcludeTax });
105
+ await controller.setEditGood({ priceExcludeTax, quantity });
106
+ }
107
+
108
+ // 更新含税
109
+ await updateUnitPriceTax(controller, form, record);
110
+ }
111
+
112
+ // 清楚 计算中启动字段
113
+ await clearCalculatingField(controller);
114
+ });
115
+ },
116
+ 1000,
117
+ );
118
+
119
+ /** 单价(含税) */
120
+ export const onChangePriceIncludeTax = lazyFn(
121
+ (controller: InvoiceController, form: WrappedFormUtils, record: IGood) => {
122
+ form.validateFields(async (err, values) => {
123
+ err = err || {};
124
+
125
+ if (!values.priceIncludeTax && values.priceIncludeTax !== 0) {
126
+ await controller.setEditGood({ priceIncludeTax: undefined, priceExcludeTax: undefined });
127
+ await clearCalculatingField(controller);
128
+ return;
129
+ }
130
+ if (err.priceIncludeTax) {
131
+ await clearCalculatingField(controller);
132
+ return;
133
+ }
134
+
135
+ const calculatingDigits = controller.state.calculatingDigits;
136
+ const priceIncludeTax = format15(values.priceIncludeTax, calculatingDigits);
137
+ await controller.setEditGood({ priceIncludeTax });
138
+ form.setFieldsValue({ priceIncludeTax });
139
+
140
+ // 是否有数量
141
+ if (!err.quantity && values.quantity) {
142
+ const quantity = format15(values.quantity, calculatingDigits);
143
+ const lineAmountIncludeTax = format2(evaluate(`${quantity} * ${priceIncludeTax}`));
144
+ form.setFieldsValue({ lineAmountIncludeTax });
145
+ await controller.setEditGood({ lineAmountIncludeTax });
146
+ } else if (!err.lineAmountIncludeTax && values.lineAmountIncludeTax) {
147
+ const lineAmountIncludeTax = format2(values.lineAmountIncludeTax);
148
+ const quantity = format15(evaluate(`${lineAmountIncludeTax} / ${priceIncludeTax}`), calculatingDigits);
149
+ form.setFieldsValue({ quantity });
150
+ await controller.setEditGood({ quantity });
151
+ }
152
+
153
+ // 更新不含税
154
+ await updateUnitPriceExcludingTax(controller, form, record);
155
+
156
+ // 清楚 计算中启动字段
157
+ await clearCalculatingField(controller);
158
+ });
159
+ },
160
+ 1000,
161
+ );
162
+
163
+ /** 单价(不含税) */
164
+ export const onChangePriceExcludeTax = lazyFn(
165
+ (controller: InvoiceController, form: WrappedFormUtils, record: IGood) => {
166
+ form.validateFields(async (err, values) => {
167
+ err = err || {};
168
+
169
+ if (!values.priceExcludeTax && values.priceExcludeTax !== 0) {
170
+ await controller.setEditGood({ priceIncludeTax: undefined, priceExcludeTax: undefined });
171
+ await clearCalculatingField(controller);
172
+ return;
173
+ }
174
+ if (err.priceExcludeTax) {
175
+ await clearCalculatingField(controller);
176
+ return;
177
+ }
178
+
179
+ const calculatingDigits = controller.state.calculatingDigits;
180
+ const priceExcludeTax = format15(values.priceExcludeTax, calculatingDigits);
181
+ await controller.setEditGood({ priceExcludeTax });
182
+ form.setFieldsValue({ priceExcludeTax });
183
+
184
+ // 是否有数量
185
+ if (!err.quantity && values.quantity) {
186
+ const quantity = format15(values.quantity, calculatingDigits);
187
+ const lineAmountExcludeTax = format2(evaluate(`${quantity} * ${priceExcludeTax}`));
188
+ form.setFieldsValue({ lineAmountExcludeTax });
189
+ await controller.setEditGood({ lineAmountExcludeTax });
190
+ } else if (!err.lineAmountExcludeTax && values.lineAmountExcludeTax) {
191
+ const lineAmountExcludeTax = format2(values.lineAmountExcludeTax);
192
+ const quantity = format15(
193
+ evaluate(`${lineAmountExcludeTax} / ${priceExcludeTax}`),
194
+ calculatingDigits
195
+ );
196
+ form.setFieldsValue({ quantity });
197
+ await controller.setEditGood({ quantity });
198
+ }
199
+
200
+ // 更新含税
201
+ await updateUnitPriceTax(controller, form, record);
202
+
203
+ // 清楚 计算中启动字段
204
+ await clearCalculatingField(controller);
205
+ });
206
+ },
207
+ 1000,
208
+ );
209
+
210
+ /** 金额(含税) */
211
+ export const onChangeLineAmountIncludeTax = lazyFn(
212
+ (controller: InvoiceController, form: WrappedFormUtils, record: IGood) => {
213
+ form.validateFields(async (err, values) => {
214
+
215
+ err = err || {};
216
+ if (promptErr(err.lineAmountIncludeTax) || !values.lineAmountIncludeTax) {
217
+ // 更新不含税
218
+ await controller.setEditGood({ lineAmountIncludeTax: undefined, lineAmountExcludeTax: undefined });
219
+ await updateUnitPriceExcludingTax(controller, form, record);
220
+ await clearCalculatingField(controller);
221
+ return;
222
+ }
223
+
224
+ const calculatingDigits = controller.state.calculatingDigits;
225
+ const lineAmountIncludeTax = format2(values.lineAmountIncludeTax);
226
+ await controller.setEditGood({ lineAmountIncludeTax });
227
+ form.setFieldsValue({ lineAmountIncludeTax });
228
+
229
+ // 是否有数量
230
+ if (!err.quantity && values.quantity) {
231
+ const quantity = format15(values.quantity, calculatingDigits);
232
+ const priceIncludeTax = format15(evaluate(`${lineAmountIncludeTax} / ${quantity}`), calculatingDigits);
233
+ form.setFieldsValue({ priceIncludeTax });
234
+ await controller.setEditGood({ priceIncludeTax });
235
+ } else if (!err.priceIncludeTax && (values.priceIncludeTax || values.priceIncludeTax === 0)) {
236
+ const priceIncludeTax = format15(values.priceIncludeTax, calculatingDigits);
237
+ const quantity = format15(evaluate(`${lineAmountIncludeTax} / ${priceIncludeTax}`), calculatingDigits);
238
+ form.setFieldsValue({ quantity });
239
+ await controller.setEditGood({ quantity });
240
+ }
241
+
242
+ // 更新不含税
243
+ await updateUnitPriceExcludingTax(controller, form, record);
244
+
245
+ // 清楚 计算中启动字段
246
+ await clearCalculatingField(controller);
247
+ });
248
+ },
249
+ 1000,
250
+ );
251
+
252
+ /** 金额(不含税) */
253
+ export const onChangeLineAmountExcludeTax = lazyFn(
254
+ (controller: InvoiceController, form: WrappedFormUtils, record: IGood) => {
255
+ form.validateFields(async (err, values) => {
256
+ err = err || {};
257
+ if (promptErr(err.lineAmountExcludeTax) || !values.lineAmountExcludeTax) {
258
+ // 更新含税
259
+ await controller.setEditGood({ lineAmountIncludeTax: undefined, lineAmountExcludeTax: undefined });
260
+ await updateUnitPriceTax(controller, form, record);
261
+ await clearCalculatingField(controller);
262
+ return;
263
+ }
264
+ const calculatingDigits = controller.state.calculatingDigits;
265
+ const lineAmountExcludeTax = format2(values.lineAmountExcludeTax);
266
+ await controller.setEditGood({ lineAmountExcludeTax });
267
+ form.setFieldsValue({ lineAmountExcludeTax });
268
+
269
+ // 是否有数量
270
+ if (!err.quantity && values.quantity) {
271
+ const quantity = format15(values.quantity, calculatingDigits);
272
+ const priceExcludeTax = format15(evaluate(`${lineAmountExcludeTax} / ${quantity}`), calculatingDigits);
273
+ form.setFieldsValue({ priceExcludeTax });
274
+ await controller.setEditGood({ priceExcludeTax });
275
+ } else if (!err.priceExcludeTax && values.priceExcludeTax) {
276
+ const priceExcludeTax = format15(values.priceExcludeTax, calculatingDigits);
277
+ const quantity = format15(evaluate(`${lineAmountExcludeTax} / ${priceExcludeTax}`), calculatingDigits);
278
+ form.setFieldsValue({ quantity });
279
+ await controller.setEditGood({ quantity });
280
+ }
281
+
282
+ // 更新含税
283
+ await updateUnitPriceTax(controller, form, record);
284
+
285
+ // 清楚 计算中启动字段
286
+ await clearCalculatingField(controller);
287
+ });
288
+ },
289
+ 1000,
290
+ );
291
+
292
+ /** 税率 */
293
+ export const onChangeTaxRate = lazyFn(
294
+ (controller: InvoiceController, form: WrappedFormUtils, record: IGood) => {
295
+
296
+ form.validateFields(async (err, values) => {
297
+ err = err || {};
298
+ if (promptErr(err.taxRate) || (!values.taxRate && values.taxRate !== 0)) return;
299
+
300
+ let taxRate = parseFloat(values.taxRate);
301
+ await controller.setEditGood({ taxRate });
302
+
303
+ // 去掉赋码
304
+ (() => {
305
+ const cache = controller.state.goodsListState.endowCode.cache;
306
+ const record = controller.state.goodsListState.editGood;
307
+ if (record && cache[record.$index]) {
308
+ record.favouredPolicyName = cache[record.$index].favouredPolicyName;
309
+ record.favouredPolicyMark = cache[record.$index].favouredPolicyMark;
310
+ record.taxFreeType = cache[record.$index].taxFreeType;
311
+ cache[record.$index] = undefined;
312
+ }
313
+ })()
314
+
315
+ // 是否含税
316
+ if (controller.state.goodsListState.isTaxIncluded) {
317
+ await updateUnitPriceExcludingTax(controller, form, record);
318
+ } else {
319
+ await updateUnitPriceTax(controller, form, record);
320
+ }
321
+
322
+ // 清楚 计算中启动字段
323
+ await clearCalculatingField(controller);
324
+ });
325
+ },
326
+ 1000,
327
+ );
328
+
329
+ /** 小规模纳税人 1% 和 3% 自动赋码免税 */
330
+ export function dutyFree(controller: InvoiceController, taxRate: number, form: WrappedFormUtils<any>, record: IGood) {
331
+
332
+ const cache = controller.state.goodsListState.endowCode.cache;
333
+ const invoiceType = controller.state.invoiceType;
334
+
335
+ // 4月1日至12月31日
336
+ console.log('===> 小规模纳税人免税逻辑');
337
+ console.log('===> invoiceType', invoiceType);
338
+ console.log('===> en', controller.state.en);
339
+ console.log('===> taxRate', taxRate);
340
+ console.log('===> state', controller.state);
341
+
342
+ if (moment().valueOf() > moment('2022-12-31 23:59').valueOf()) return taxRate;
343
+ if (controller.state.en !== '08') return taxRate;
344
+ if (invoiceType !== '10' && invoiceType !== '04') return taxRate;
345
+
346
+ if (taxRate === 1 || taxRate === 3) {
347
+ cache[record.$index] = { favouredPolicyName: record.favouredPolicyName, favouredPolicyMark: record.favouredPolicyMark, taxFreeType: record.taxFreeType }
348
+ record.favouredPolicyName = '免税';
349
+ record.taxRate = 0;
350
+ record.favouredPolicyMark = 1;
351
+ record.taxFreeType = 1 as any;
352
+ form.setFieldsValue({ taxRate: 0 });
353
+ return 0;
354
+ }
355
+ }
356
+
357
+ /** 含税 => 更新(不含税) */
358
+ export const updateUnitPriceExcludingTax = async (controller: InvoiceController, form: WrappedFormUtils, record: IGood) => {
359
+ return new Promise((resolve) => {
360
+ form.validateFields(async (err, values) => {
361
+
362
+ err = err || {};
363
+
364
+ /** 税额 */
365
+ let taxAmount;
366
+
367
+ /** 金额(不含税) */
368
+ let lineAmountExcludeTax;
369
+
370
+ /** 不含税单价 */
371
+ let priceExcludeTax;
372
+
373
+ /** 扣除额 */
374
+ const deduction = controller.state.goodsListState.deduction;
375
+
376
+ // 计算税额
377
+ if (!promptErr(err.lineAmountIncludeTax) && !promptErr(err.taxRate)) {
378
+ taxAmount = countTaxAmount(values.lineAmountIncludeTax, deduction, values.taxRate);
379
+ }
380
+ form.setFieldsValue({ taxAmount });
381
+ await controller.setEditGood({ taxAmount });
382
+
383
+ // 计算 金额(不含税)
384
+ if ((taxAmount || taxAmount === 0) && !promptErr(err.lineAmountIncludeTax)) {
385
+ lineAmountExcludeTax = countAmountExcludeTax(values.lineAmountIncludeTax, taxAmount);
386
+ }
387
+ form.setFieldsValue({ lineAmountExcludeTax });
388
+ await controller.setEditGood({ lineAmountExcludeTax });
389
+
390
+ // 单价(不含税)
391
+ if (lineAmountExcludeTax && !promptErr(err.quantity)) {
392
+ priceExcludeTax = countPrice(lineAmountExcludeTax, values.quantity, controller.state.calculatingDigits);
393
+ }
394
+ form.setFieldsValue({ priceExcludeTax });
395
+ await controller.setEditGood({ priceExcludeTax });
396
+ });
397
+
398
+ resolve(undefined)
399
+ })
400
+ };
401
+
402
+ /** 不含税 => 更新(含税) */
403
+ export const updateUnitPriceTax = async (controller: InvoiceController, form: WrappedFormUtils, record: IGood) => {
404
+ return new Promise((resolve) => {
405
+ form.validateFields(async (err, values) => {
406
+ err = err || {};
407
+
408
+ if (
409
+ !err.taxRat &&
410
+ (values.taxRate || values.taxRate === 0) &&
411
+ !promptErr(err.lineAmountExcludeTax) &&
412
+ (values.lineAmountExcludeTax || values.lineAmountExcludeTax === 0)
413
+ ) {
414
+
415
+ const calculatingDigits = controller.state.calculatingDigits;
416
+ // 金额(含税)= 金额(不含税)* (1+ 税率)
417
+ const lineAmountExcludeTax = format2(values.lineAmountExcludeTax);
418
+ const lineAmountIncludeTax = format2(evaluate(`${lineAmountExcludeTax} * (1+(${values.taxRate}/100))`));
419
+ await controller.setEditGood({ lineAmountIncludeTax });
420
+
421
+ // 单价(含税) = 金额(含税) / (數量)
422
+ // 是否有数量
423
+ if (!err.quantity && values.quantity) {
424
+ const priceIncludeTax = format15(evaluate(`${lineAmountIncludeTax} / ${values.quantity}`), calculatingDigits);
425
+ await controller.setEditGood({ priceIncludeTax });
426
+ }
427
+
428
+ // 税额 = 金额(含税)-金额(不含税)
429
+ const taxAmount = evaluate(`${lineAmountIncludeTax} - ${lineAmountExcludeTax}`);
430
+ form.setFieldsValue({ taxAmount });
431
+ await controller.setEditGood({ taxAmount });
432
+ } else {
433
+ form.setFieldsValue({ taxAmount: undefined });
434
+ await controller.setEditGood({ taxAmount: undefined });
435
+ }
436
+ // 单价(含税) = 单价(不含税) * (1+税率)
437
+ // if (
438
+ // !err.taxRat &&
439
+ // (values.taxRate || values.taxRate === 0) &&
440
+ // !promptErr(err.priceExcludeTax) &&
441
+ // (values.priceExcludeTax || values.priceExcludeTax === 0)
442
+ // ) {
443
+ // const priceExcludeTax = format15(values.priceExcludeTax);
444
+ // const priceIncludeTax = format15(evaluate(`${priceExcludeTax} * (1+(${values.taxRate}/100))`));
445
+ // await controller.setEditGood({ priceIncludeTax });
446
+ // }
447
+
448
+ resolve(undefined)
449
+ });
450
+ })
451
+ };
452
+
453
+ /** 保存到编辑货物 */
454
+ export const onSaveEditGood = lazyFn(
455
+ (
456
+ controller: InvoiceController,
457
+ form: WrappedFormUtils,
458
+ record: IGood,
459
+ id: string,
460
+ ) => {
461
+ form.validateFields(async (err, values) => {
462
+ err = err || {};
463
+ if (err[id]) return;
464
+
465
+ const v = {} as any;
466
+ v[id] = values[id];
467
+ await controller.setEditGood({ ...v });
468
+ });
469
+ },
470
+ 1000,
471
+ );
472
+
473
+ /** 单调赋码 */
474
+ export const endowCode = async (controller: InvoiceController, goods: IGood) => {
475
+ await controller.wait();
476
+ await controller.saveEditGood();
477
+ await controller.pipeline(async (s) => {
478
+ if (s.goodsListState.form && s.goodsListState.editGood?.$index === goods?.$index) {
479
+ const err: any = s.goodsListState.form.getFieldsError();
480
+ for (let key in err) {
481
+ if (!err[key]) continue;
482
+ message.error(err[key][0]);
483
+ return;
484
+ }
485
+ }
486
+
487
+ let g = s.goodsListState.goodsMap.get(goods.$index) as any;
488
+ let i = s.goodsListState.goodsList.indexOf(g);
489
+
490
+ switch (goods.lineAttribute) {
491
+ case LineAttributeType.正常:
492
+ s.goodsListState.endowCode.endowcodeGoodIndex = [goods.$index];
493
+ break;
494
+
495
+ case LineAttributeType.折扣行:
496
+
497
+ s.goodsListState.endowCode.endowcodeGoodIndex = [goods.$index, s.goodsListState.goodsList[i - 1].$index];
498
+ break;
499
+
500
+ case LineAttributeType.被折扣行:
501
+ s.goodsListState.endowCode.endowcodeGoodIndex = [goods.$index, s.goodsListState.goodsList[i + 1].$index];
502
+ break;
503
+ }
504
+ })();
505
+ }
506
+
507
+ /** 修改了 项目名称 */
508
+ export const onChangeItemName = async (controller: InvoiceController, form: WrappedFormUtils<any>, record: IGood) => {
509
+ controller.run(async s => {
510
+ const value = form.getFieldsValue().itemName;
511
+
512
+ if (s.goodsListState.isMyShow) {
513
+ await controller.setEditGood({ itemNameSelf: value });
514
+ record.itemName && await controller.setEditGood({ itemName: record.itemName });
515
+ } else {
516
+ await controller.setEditGood({ itemName: value });
517
+ record.itemNameSelf && await controller.setEditGood({ itemNameSelf: record.itemNameSelf });
518
+ }
519
+ })
520
520
  }