kts-component-invoice-operate 3.2.98 → 3.2.99

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