kts-component-invoice-operate 3.2.257 → 3.2.258

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 (289) 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/.vscode/settings.json +13 -13
  8. package/BRANCH.md +4 -4
  9. package/README.md +12 -12
  10. package/dist/Invoice/ui/digtal/Stakeholder/index.d.ts +2 -0
  11. package/dist/index.esm.js +16 -6
  12. package/dist/index.js +16 -6
  13. package/docs/index.md +5 -5
  14. package/docs-dist/404.html +33 -33
  15. package/docs-dist/index.html +33 -33
  16. package/docs-dist/static/arrowDown.22c7885c.svg +3 -0
  17. package/docs-dist/static/arrowDown.a1cbf0d8.svg +2 -2
  18. package/docs-dist/static/arrowUp.4c482054.svg +2 -2
  19. package/docs-dist/static/arrowUp.d707a3e4.svg +3 -0
  20. package/docs-dist/static/download.18f10f45.svg +1 -0
  21. package/docs-dist/static/fork.43eb4ffa.svg +12 -0
  22. package/docs-dist/static/fork.5431267d.svg +11 -11
  23. package/docs-dist/static/plus.0e60e9ea.svg +12 -0
  24. package/docs-dist/static/plus.384f41d9.svg +12 -0
  25. package/docs-dist/static/plus.44013ce3.svg +11 -11
  26. package/docs-dist/static/plus.4fd1af30.svg +11 -11
  27. package/docs-dist/static/upload.d7ea1893.svg +1 -0
  28. package/docs-dist/umi.css +18 -18
  29. package/index.html +12 -12
  30. package/package.json +62 -62
  31. package/src/Invoice/Invoice-digtal/_test/architecture/index.tsx +21 -21
  32. package/src/Invoice/Invoice-digtal/_test/disabled/index.tsx +40 -40
  33. package/src/Invoice/Invoice-digtal/_test/easiest/index.tsx +214 -214
  34. package/src/Invoice/Invoice-digtal/_test/freight/index.tsx +14592 -14580
  35. package/src/Invoice/Invoice-digtal/_test/header/index.tsx +84 -84
  36. package/src/Invoice/Invoice-digtal/_test/importGoods/index.tsx +1635 -1635
  37. package/src/Invoice/Invoice-digtal/_test/importStakeholder/index.tsx +18 -18
  38. package/src/Invoice/Invoice-digtal/_test/lineCredit/index.tsx +19 -19
  39. package/src/Invoice/Invoice-digtal/_test/pay/index.tsx +14644 -14644
  40. package/src/Invoice/Invoice-digtal/_test/prefab/index.tsx +150 -150
  41. package/src/Invoice/Invoice-digtal/_test/readOnly/index.tsx +55 -55
  42. package/src/Invoice/Invoice-digtal/_test/realEstateInfo/index.tsx +83 -83
  43. package/src/Invoice/Invoice-digtal/_test/realEstateSales/index.tsx +76 -76
  44. package/src/Invoice/Invoice-digtal/_test/stakeholder/index.tsx +12 -12
  45. package/src/Invoice/Invoice-digtal/_test/typeSelection/index.tsx +29 -29
  46. package/src/Invoice/Invoice-digtal/index.md +46 -46
  47. package/src/Invoice/InvoiceController/InvoiceControllerForm/index.ts +117 -117
  48. package/src/Invoice/InvoiceController/InvoiceControllerState/AutoComplete/index.ts +26 -26
  49. package/src/Invoice/InvoiceController/InvoiceControllerState/BuyerState/index.tsx +88 -88
  50. package/src/Invoice/InvoiceController/InvoiceControllerState/FreightListState/IColumnsReplenish/index.ts +10 -10
  51. package/src/Invoice/InvoiceController/InvoiceControllerState/FreightListState/IGood/index.ts +33 -33
  52. package/src/Invoice/InvoiceController/InvoiceControllerState/FreightListState/ImportGoods/index.ts +81 -81
  53. package/src/Invoice/InvoiceController/InvoiceControllerState/FreightListState/index.ts +39 -39
  54. package/src/Invoice/InvoiceController/InvoiceControllerState/GoodsListState/Drag/index.ts +15 -15
  55. package/src/Invoice/InvoiceController/InvoiceControllerState/GoodsListState/EndowCode/index.tsx +104 -104
  56. package/src/Invoice/InvoiceController/InvoiceControllerState/GoodsListState/IColumnsReplenish/index.ts +10 -10
  57. package/src/Invoice/InvoiceController/InvoiceControllerState/GoodsListState/IGood/index.ts +93 -93
  58. package/src/Invoice/InvoiceController/InvoiceControllerState/GoodsListState/ImportGoods/index.ts +84 -84
  59. package/src/Invoice/InvoiceController/InvoiceControllerState/GoodsListState/LineAttributeType/index.ts +7 -7
  60. package/src/Invoice/InvoiceController/InvoiceControllerState/GoodsListState/ProductComparison/index.ts +9 -9
  61. package/src/Invoice/InvoiceController/InvoiceControllerState/GoodsListState/index.ts +150 -150
  62. package/src/Invoice/InvoiceController/InvoiceControllerState/PayListState/IColumnsReplenish/index.ts +10 -10
  63. package/src/Invoice/InvoiceController/InvoiceControllerState/PayListState/IGood/index.ts +35 -35
  64. package/src/Invoice/InvoiceController/InvoiceControllerState/PayListState/ImportGoods/index.ts +81 -81
  65. package/src/Invoice/InvoiceController/InvoiceControllerState/PayListState/index.ts +39 -39
  66. package/src/Invoice/InvoiceController/InvoiceControllerState/Stakeholder/index.ts +13 -13
  67. package/src/Invoice/InvoiceController/InvoiceControllerState/index.ts +76 -76
  68. package/src/Invoice/InvoiceController/fns/addFreight.ts +11 -11
  69. package/src/Invoice/InvoiceController/fns/addGood.ts +11 -11
  70. package/src/Invoice/InvoiceController/fns/addGoodDiscount.ts +126 -126
  71. package/src/Invoice/InvoiceController/fns/addGoodDiscountV2.ts +86 -86
  72. package/src/Invoice/InvoiceController/fns/addPay.ts +11 -11
  73. package/src/Invoice/InvoiceController/fns/delFreight.ts +38 -38
  74. package/src/Invoice/InvoiceController/fns/delGood.ts +41 -41
  75. package/src/Invoice/InvoiceController/fns/delPay.ts +38 -38
  76. package/src/Invoice/InvoiceController/fns/getGoodsSearch.ts +26 -26
  77. package/src/Invoice/InvoiceController/fns/importGoodsDrawer.ts +86 -86
  78. package/src/Invoice/InvoiceController/fns/itemBlur.ts +47 -47
  79. package/src/Invoice/InvoiceController/fns/mergeDetails.ts +201 -201
  80. package/src/Invoice/InvoiceController/fns/mergeDiscount.ts +35 -35
  81. package/src/Invoice/InvoiceController/fns/saveEditFreight.ts +24 -24
  82. package/src/Invoice/InvoiceController/fns/saveEditGood.ts +24 -24
  83. package/src/Invoice/InvoiceController/fns/saveEditPay.ts +23 -23
  84. package/src/Invoice/InvoiceController/fns/setEditFreight.ts +16 -16
  85. package/src/Invoice/InvoiceController/fns/setEditGood.ts +16 -16
  86. package/src/Invoice/InvoiceController/fns/setEditPay.ts +16 -16
  87. package/src/Invoice/InvoiceController/fns/setFreight.ts +10 -10
  88. package/src/Invoice/InvoiceController/fns/setGoods.ts +10 -10
  89. package/src/Invoice/InvoiceController/fns/setPay.ts +10 -10
  90. package/src/Invoice/InvoiceController/fns/updateInvoiceNo.ts +8 -8
  91. package/src/Invoice/InvoiceController/index.ts +127 -127
  92. package/src/Invoice/_test/buyerNameSearch/index.tsx +42 -42
  93. package/src/Invoice/_test/children/index.tsx +214 -214
  94. package/src/Invoice/_test/deduction/index.tsx +956 -956
  95. package/src/Invoice/_test/draft/index.tsx +40 -40
  96. package/src/Invoice/_test/easiest/index.tsx +5 -5
  97. package/src/Invoice/_test/endowCode/index.tsx +1158 -1158
  98. package/src/Invoice/_test/goodsMenuExpand/index.tsx +32 -32
  99. package/src/Invoice/_test/importBuyer/index.tsx +75 -75
  100. package/src/Invoice/_test/importGoods/index.tsx +1375 -1375
  101. package/src/Invoice/_test/invoiceType/index.tsx +59 -59
  102. package/src/Invoice/_test/isInvoiceNo/index.tsx +12 -12
  103. package/src/Invoice/_test/replaceHead/index.tsx +22 -22
  104. package/src/Invoice/_test/retrieveData/index.tsx +22 -22
  105. package/src/Invoice/_test/seller/index.tsx +28 -28
  106. package/src/Invoice/_test/setDataSource/index.tsx +73 -73
  107. package/src/Invoice/_test/unit/index.tsx +19 -19
  108. package/src/Invoice/index.less +31 -31
  109. package/src/Invoice/index.md +56 -56
  110. package/src/Invoice/index.tsx +211 -211
  111. package/src/Invoice/tools/calculate/index.ts +144 -144
  112. package/src/Invoice/tools/coolingFn/index.ts +17 -17
  113. package/src/Invoice/tools/evaluate/index.ts +7 -7
  114. package/src/Invoice/tools/idGenerator/index.ts +2 -2
  115. package/src/Invoice/tools/itemName/index.ts +55 -55
  116. package/src/Invoice/tools/lazyFn/index.ts +19 -19
  117. package/src/Invoice/tools/mounting/index.ts +13 -13
  118. package/src/Invoice/tools/strringFn/index.ts +40 -40
  119. package/src/Invoice/tools/useToGenerateId/index.ts +12 -12
  120. package/src/Invoice/tools/utils/index.ts +1 -1
  121. package/src/Invoice/tools/utils/money/index.ts +20 -20
  122. package/src/Invoice/ui/default/AddComparisonDrawer/index.tsx +149 -149
  123. package/src/Invoice/ui/default/Buyer/index.less +219 -219
  124. package/src/Invoice/ui/default/Buyer/index.tsx +114 -114
  125. package/src/Invoice/ui/default/Buyer/ui/BuyerNameInput/index.tsx +166 -166
  126. package/src/Invoice/ui/default/Buyer/ui/ImportBuyerButton/index.tsx +21 -21
  127. package/src/Invoice/ui/default/EndowCodeDrawer/index.less +8 -8
  128. package/src/Invoice/ui/default/EndowCodeDrawer/index.tsx +620 -620
  129. package/src/Invoice/ui/default/GoodsList/hook/useColumns/autoFillFn/index.ts +690 -690
  130. package/src/Invoice/ui/default/GoodsList/hook/useColumns/index.tsx +773 -773
  131. package/src/Invoice/ui/default/GoodsList/hook/useColumns/ui/Drag/index.less +20 -20
  132. package/src/Invoice/ui/default/GoodsList/hook/useColumns/ui/Drag/index.tsx +205 -205
  133. package/src/Invoice/ui/default/GoodsList/hook/useColumns/ui/Expand/index.tsx +57 -57
  134. package/src/Invoice/ui/default/GoodsList/hook/useColumns/ui/ItemCodeInput/index.less +18 -18
  135. package/src/Invoice/ui/default/GoodsList/hook/useColumns/ui/ItemCodeInput/index.tsx +49 -49
  136. package/src/Invoice/ui/default/GoodsList/hook/useColumns/ui/ItemNameInput/index.less +17 -17
  137. package/src/Invoice/ui/default/GoodsList/hook/useColumns/ui/ItemNameInput/index.tsx +91 -91
  138. package/src/Invoice/ui/default/GoodsList/hook/useColumns/ui/RowEditButton/index.tsx +30 -30
  139. package/src/Invoice/ui/default/GoodsList/hook/useColumns/ui/RowMenu/hook/_useAddComparison/index.tsx +43 -43
  140. package/src/Invoice/ui/default/GoodsList/hook/useColumns/ui/RowMenu/hook/useAddDiscount/index.tsx +118 -118
  141. package/src/Invoice/ui/default/GoodsList/hook/useColumns/ui/RowMenu/hook/useDelItem/dist/index.js +32 -32
  142. package/src/Invoice/ui/default/GoodsList/hook/useColumns/ui/RowMenu/hook/useDelItem/index.tsx +41 -41
  143. package/src/Invoice/ui/default/GoodsList/hook/useColumns/ui/RowMenu/hook/useEndowCode/index.tsx +25 -25
  144. package/src/Invoice/ui/default/GoodsList/hook/useColumns/ui/RowMenu/index.less +13 -13
  145. package/src/Invoice/ui/default/GoodsList/hook/useColumns/ui/RowMenu/index.tsx +99 -99
  146. package/src/Invoice/ui/default/GoodsList/hook/useColumns/ui/RowSaveButton/index.tsx +14 -14
  147. package/src/Invoice/ui/default/GoodsList/hook/useColumns/ui/TitleText/index.tsx +20 -20
  148. package/src/Invoice/ui/default/GoodsList/hook/useDeduction/index.tsx +24 -24
  149. package/src/Invoice/ui/default/GoodsList/hook/useOnRow/index.tsx +52 -52
  150. package/src/Invoice/ui/default/GoodsList/hook/useRowSelection/index.tsx +120 -120
  151. package/src/Invoice/ui/default/GoodsList/hook/useWindowClick/index.tsx +23 -23
  152. package/src/Invoice/ui/default/GoodsList/index.less +185 -185
  153. package/src/Invoice/ui/default/GoodsList/index.tsx +207 -207
  154. package/src/Invoice/ui/default/GoodsList/ui/AddRowButton/index.tsx +72 -72
  155. package/src/Invoice/ui/default/GoodsList/ui/BulkMenu/hooks/useAddDiscountRowButton/index.less +21 -21
  156. package/src/Invoice/ui/default/GoodsList/ui/BulkMenu/hooks/useAddDiscountRowButton/index.tsx +244 -244
  157. package/src/Invoice/ui/default/GoodsList/ui/BulkMenu/hooks/useCommodityComparisonButton/index.tsx +75 -75
  158. package/src/Invoice/ui/default/GoodsList/ui/BulkMenu/hooks/useDelRowButton/index.tsx +69 -69
  159. package/src/Invoice/ui/default/GoodsList/ui/BulkMenu/hooks/useEndowCodeButton/index.tsx +65 -65
  160. package/src/Invoice/ui/default/GoodsList/ui/BulkMenu/hooks/useMergeDetails/index.tsx +91 -91
  161. package/src/Invoice/ui/default/GoodsList/ui/BulkMenu/hooks/useMergeDiscount/index.tsx +36 -36
  162. package/src/Invoice/ui/default/GoodsList/ui/BulkMenu/hooks/useSalesDiscount/index.tsx +109 -109
  163. package/src/Invoice/ui/default/GoodsList/ui/BulkMenu/hooks/useSalesGifts/index.tsx +94 -94
  164. package/src/Invoice/ui/default/GoodsList/ui/BulkMenu/index.tsx +37 -37
  165. package/src/Invoice/ui/default/GoodsList/ui/DescribeSwitch/index.tsx +36 -36
  166. package/src/Invoice/ui/default/GoodsList/ui/Search/index.less +10 -10
  167. package/src/Invoice/ui/default/GoodsList/ui/Search/index.tsx +52 -52
  168. package/src/Invoice/ui/default/GoodsList/ui/Statistics/index.less +18 -18
  169. package/src/Invoice/ui/default/GoodsList/ui/Statistics/index.tsx +114 -114
  170. package/src/Invoice/ui/default/GoodsList/ui/TableRow/index.less +40 -40
  171. package/src/Invoice/ui/default/GoodsList/ui/TableRow/index.tsx +71 -71
  172. package/src/Invoice/ui/default/GoodsList/ui/TableVirtual/index.less +38 -38
  173. package/src/Invoice/ui/default/GoodsList/ui/TableVirtual/index.tsx +130 -130
  174. package/src/Invoice/ui/default/GoodsList/ui/TableVirtual.o/index.less +44 -44
  175. package/src/Invoice/ui/default/GoodsList/ui/TableVirtual.o/index.tsx +96 -96
  176. package/src/Invoice/ui/default/GoodsList/ui/TaxIncludedSwitch/index.tsx +31 -31
  177. package/src/Invoice/ui/default/ImportBuyerDrawer/index.tsx +75 -75
  178. package/src/Invoice/ui/default/ImportGoodsDrawer/index.tsx +207 -207
  179. package/src/Invoice/ui/default/InvoiceHeader/index.less +68 -68
  180. package/src/Invoice/ui/default/InvoiceHeader/index.tsx +246 -246
  181. package/src/Invoice/ui/default/MeiTanModal/index.less +39 -39
  182. package/src/Invoice/ui/default/MeiTanModal/index.tsx +165 -165
  183. package/src/Invoice/ui/default/Seller/index.less +113 -113
  184. package/src/Invoice/ui/default/Seller/index.tsx +98 -98
  185. package/src/Invoice/ui/default/Sign/index.less +14 -14
  186. package/src/Invoice/ui/default/Sign/index.tsx +71 -71
  187. package/src/Invoice/ui/digtal/Architecture/index.less +22 -22
  188. package/src/Invoice/ui/digtal/Architecture/index.tsx +227 -227
  189. package/src/Invoice/ui/digtal/FreightList/hook/useColumns/dist/index.js +616 -616
  190. package/src/Invoice/ui/digtal/FreightList/hook/useColumns/index.tsx +246 -246
  191. package/src/Invoice/ui/digtal/FreightList/hook/useColumns/ui/TitleText/index.tsx +20 -20
  192. package/src/Invoice/ui/digtal/FreightList/hook/useOnRow/index.tsx +37 -37
  193. package/src/Invoice/ui/digtal/FreightList/hook/useRowSelection/index.tsx +119 -119
  194. package/src/Invoice/ui/digtal/FreightList/hook/useWindowClick/index.tsx +23 -23
  195. package/src/Invoice/ui/digtal/FreightList/index.less +72 -72
  196. package/src/Invoice/ui/digtal/FreightList/index.tsx +129 -129
  197. package/src/Invoice/ui/digtal/FreightList/ui/AddRowButton/index.tsx +74 -74
  198. package/src/Invoice/ui/digtal/FreightList/ui/BulkMenu/hooks/useDelRowButton/index.tsx +50 -50
  199. package/src/Invoice/ui/digtal/FreightList/ui/BulkMenu/hooks/useEmptyRefill/index.tsx +36 -36
  200. package/src/Invoice/ui/digtal/FreightList/ui/TableRow/index.less +28 -28
  201. package/src/Invoice/ui/digtal/FreightList/ui/TableRow/index.tsx +20 -20
  202. package/src/Invoice/ui/digtal/FreightList/ui/TableVirtual/index.less +38 -38
  203. package/src/Invoice/ui/digtal/FreightList/ui/TableVirtual/index.tsx +108 -108
  204. package/src/Invoice/ui/digtal/GoodsList/hook/useColumns/autoFillFn/index.ts +690 -690
  205. package/src/Invoice/ui/digtal/GoodsList/hook/useColumns/dist/index.js +616 -616
  206. package/src/Invoice/ui/digtal/GoodsList/hook/useColumns/index.tsx +720 -720
  207. package/src/Invoice/ui/digtal/GoodsList/hook/useColumns/svg/plus.svg +11 -11
  208. package/src/Invoice/ui/digtal/GoodsList/hook/useColumns/ui/Drag/index.less +20 -20
  209. package/src/Invoice/ui/digtal/GoodsList/hook/useColumns/ui/Drag/index.tsx +205 -205
  210. package/src/Invoice/ui/digtal/GoodsList/hook/useColumns/ui/ItemNameInput/index.less +9 -9
  211. package/src/Invoice/ui/digtal/GoodsList/hook/useColumns/ui/ItemNameInput/index.tsx +87 -87
  212. package/src/Invoice/ui/digtal/GoodsList/hook/useColumns/ui/RowEditButton/index.tsx +30 -30
  213. package/src/Invoice/ui/digtal/GoodsList/hook/useColumns/ui/RowMenu/hook/_useAddComparison/index.tsx +43 -43
  214. package/src/Invoice/ui/digtal/GoodsList/hook/useColumns/ui/RowMenu/hook/useAddDiscount/index.tsx +76 -76
  215. package/src/Invoice/ui/digtal/GoodsList/hook/useColumns/ui/RowMenu/hook/useDelItem/index.tsx +41 -41
  216. package/src/Invoice/ui/digtal/GoodsList/hook/useColumns/ui/RowMenu/hook/useEndowCode/index.tsx +34 -34
  217. package/src/Invoice/ui/digtal/GoodsList/hook/useColumns/ui/RowMenu/index.less +13 -13
  218. package/src/Invoice/ui/digtal/GoodsList/hook/useColumns/ui/RowMenu/index.tsx +98 -98
  219. package/src/Invoice/ui/digtal/GoodsList/hook/useColumns/ui/RowSaveButton/index.tsx +14 -14
  220. package/src/Invoice/ui/digtal/GoodsList/hook/useColumns/ui/TitleText/index.tsx +20 -20
  221. package/src/Invoice/ui/digtal/GoodsList/hook/useOnRow/index.tsx +51 -51
  222. package/src/Invoice/ui/digtal/GoodsList/hook/useRowSelection/index.tsx +121 -121
  223. package/src/Invoice/ui/digtal/GoodsList/hook/useWindowClick/index.tsx +23 -23
  224. package/src/Invoice/ui/digtal/GoodsList/index.less +56 -56
  225. package/src/Invoice/ui/digtal/GoodsList/index.tsx +181 -181
  226. package/src/Invoice/ui/digtal/GoodsList/ui/AddRowButton/index.tsx +87 -87
  227. package/src/Invoice/ui/digtal/GoodsList/ui/BulkMenu/hooks/useAddDiscountRowButton/index.tsx +340 -340
  228. package/src/Invoice/ui/digtal/GoodsList/ui/BulkMenu/hooks/useAddDiscountRowButton/svg/add.svg +11 -11
  229. package/src/Invoice/ui/digtal/GoodsList/ui/BulkMenu/hooks/useCommodityComparisonButton/index.tsx +75 -75
  230. package/src/Invoice/ui/digtal/GoodsList/ui/BulkMenu/hooks/useDelRowButton/index.tsx +50 -50
  231. package/src/Invoice/ui/digtal/GoodsList/ui/BulkMenu/hooks/useEmptyRefill/index.tsx +37 -37
  232. package/src/Invoice/ui/digtal/GoodsList/ui/BulkMenu/hooks/useEndowCodeButton/index.tsx +82 -82
  233. package/src/Invoice/ui/digtal/GoodsList/ui/BulkMenu/hooks/useReselectInvoiceType/index.tsx +57 -57
  234. package/src/Invoice/ui/digtal/GoodsList/ui/DescribeSwitch/index.tsx +36 -36
  235. package/src/Invoice/ui/digtal/GoodsList/ui/Search/index.less +11 -11
  236. package/src/Invoice/ui/digtal/GoodsList/ui/Search/index.tsx +60 -60
  237. package/src/Invoice/ui/digtal/GoodsList/ui/Statistics/index.less +53 -53
  238. package/src/Invoice/ui/digtal/GoodsList/ui/Statistics/index.tsx +100 -100
  239. package/src/Invoice/ui/digtal/GoodsList/ui/Statistics/svg/fork.svg +11 -11
  240. package/src/Invoice/ui/digtal/GoodsList/ui/TableRow/index.less +28 -28
  241. package/src/Invoice/ui/digtal/GoodsList/ui/TableRow/index.tsx +52 -52
  242. package/src/Invoice/ui/digtal/GoodsList/ui/TableVirtual/index.less +38 -38
  243. package/src/Invoice/ui/digtal/GoodsList/ui/TableVirtual/index.tsx +113 -113
  244. package/src/Invoice/ui/digtal/GoodsList/ui/TaxIncludedSwitch/index.tsx +34 -34
  245. package/src/Invoice/ui/digtal/InvoiceHeader/index.less +57 -57
  246. package/src/Invoice/ui/digtal/InvoiceHeader/index.tsx +77 -77
  247. package/src/Invoice/ui/digtal/PayList/hook/useColumns/dist/index.js +616 -616
  248. package/src/Invoice/ui/digtal/PayList/hook/useColumns/index.tsx +168 -168
  249. package/src/Invoice/ui/digtal/PayList/hook/useColumns/ui/TitleText/index.tsx +20 -20
  250. package/src/Invoice/ui/digtal/PayList/hook/useOnRow/index.tsx +37 -37
  251. package/src/Invoice/ui/digtal/PayList/hook/useRowSelection/index.tsx +119 -119
  252. package/src/Invoice/ui/digtal/PayList/hook/useWindowClick/index.tsx +19 -19
  253. package/src/Invoice/ui/digtal/PayList/index.less +72 -72
  254. package/src/Invoice/ui/digtal/PayList/index.tsx +132 -132
  255. package/src/Invoice/ui/digtal/PayList/ui/AddRowButton/index.tsx +74 -74
  256. package/src/Invoice/ui/digtal/PayList/ui/BulkMenu/hooks/useDelRowButton/index.tsx +50 -50
  257. package/src/Invoice/ui/digtal/PayList/ui/BulkMenu/hooks/useEmptyRefill/index.tsx +36 -36
  258. package/src/Invoice/ui/digtal/PayList/ui/TableRow/index.less +28 -28
  259. package/src/Invoice/ui/digtal/PayList/ui/TableRow/index.tsx +20 -20
  260. package/src/Invoice/ui/digtal/PayList/ui/TableVirtual/index.less +38 -38
  261. package/src/Invoice/ui/digtal/PayList/ui/TableVirtual/index.tsx +108 -108
  262. package/src/Invoice/ui/digtal/RealEstateInfo/index.less +21 -21
  263. package/src/Invoice/ui/digtal/RealEstateInfo/index.tsx +451 -451
  264. package/src/Invoice/ui/digtal/RealEstateSales/index.less +21 -21
  265. package/src/Invoice/ui/digtal/RealEstateSales/index.tsx +301 -301
  266. package/src/Invoice/ui/digtal/Sign/index.less +48 -48
  267. package/src/Invoice/ui/digtal/Sign/index.tsx +99 -99
  268. package/src/Invoice/ui/digtal/StakeFarmerholder/index.less +99 -99
  269. package/src/Invoice/ui/digtal/StakeFarmerholder/index.tsx +1102 -1102
  270. package/src/Invoice/ui/digtal/StakeFarmerholder/svg/arrowDown.svg +2 -2
  271. package/src/Invoice/ui/digtal/StakeFarmerholder/svg/arrowUp.svg +2 -2
  272. package/src/Invoice/ui/digtal/StakeFarmerholder/svg/plus.svg +11 -11
  273. package/src/Invoice/ui/digtal/Stakeholder/index.less +99 -99
  274. package/src/Invoice/ui/digtal/Stakeholder/index.tsx +458 -453
  275. package/src/Invoice/ui/digtal/Stakeholder/svg/arrowDown.svg +2 -2
  276. package/src/Invoice/ui/digtal/Stakeholder/svg/arrowUp.svg +2 -2
  277. package/src/Invoice/ui/digtal/Stakeholder/svg/plus.svg +11 -11
  278. package/src/InvoiceTypeModal/_test/easiest/index.tsx +31 -31
  279. package/src/InvoiceTypeModal/dist/index.js +92 -92
  280. package/src/InvoiceTypeModal/index.less +7 -7
  281. package/src/InvoiceTypeModal/index.md +5 -5
  282. package/src/InvoiceTypeModal/index.tsx +161 -161
  283. package/src/TaxClassificationCodeModal/_test/easiest/index.tsx +184 -184
  284. package/src/TaxClassificationCodeModal/index.less +17 -17
  285. package/src/TaxClassificationCodeModal/index.md +6 -6
  286. package/src/TaxClassificationCodeModal/index.tsx +152 -152
  287. package/src/index.ts +13 -13
  288. package/tsconfig.json +31 -31
  289. package/typings.d.ts +3 -3
@@ -1,691 +1,691 @@
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
- import { equal } from 'mathjs';
14
- import { chain, bignumber } from 'mathjs';
15
-
16
- export { format2, format15 } from '../../../../../../tools/calculate';
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
- switch (controller.state.goodsListState.calculateType) {
316
- case '1':
317
- await updateUnitPriceExcludingTax(controller, form, record);
318
- break;
319
-
320
- case '2':
321
- await updateUnitPriceTax(controller, form, record);
322
- break;
323
-
324
- case '3':
325
- default:
326
- // 是否含税
327
- if (controller.state.goodsListState.isTaxIncluded) {
328
- await updateUnitPriceExcludingTax(controller, form, record);
329
- } else {
330
- await updateUnitPriceTax(controller, form, record);
331
- }
332
- break;
333
- }
334
-
335
- // 清楚 计算中启动字段
336
- await clearCalculatingField(controller);
337
- });
338
- },
339
- 1000,
340
- );
341
-
342
- /** 小规模纳税人 1% 和 3% 自动赋码免税 */
343
- export function dutyFree(controller: InvoiceController, taxRate: number, form: WrappedFormUtils<any>, record: IGood) {
344
-
345
- const cache = controller.state.goodsListState.endowCode.cache;
346
- const invoiceType = controller.state.invoiceType;
347
-
348
- // 4月1日至12月31日
349
- console.log('===> 小规模纳税人免税逻辑');
350
- console.log('===> invoiceType', invoiceType);
351
- console.log('===> en', controller.state.en);
352
- console.log('===> taxRate', taxRate);
353
- console.log('===> state', controller.state);
354
-
355
- if (moment().valueOf() > moment('2022-12-31 23:59').valueOf()) return taxRate;
356
- if (controller.state.en !== '08') return taxRate;
357
- if (invoiceType !== '10' && invoiceType !== '04') return taxRate;
358
-
359
- if (taxRate === 1 || taxRate === 3) {
360
- cache[record.$index] = { favouredPolicyName: record.favouredPolicyName, favouredPolicyMark: record.favouredPolicyMark, taxFreeType: record.taxFreeType }
361
- record.favouredPolicyName = '免税';
362
- record.taxRate = 0;
363
- record.favouredPolicyMark = 1;
364
- record.taxFreeType = 1 as any;
365
- form.setFieldsValue({ taxRate: 0 });
366
- return 0;
367
- }
368
- }
369
-
370
- /** 含税 => 更新(不含税) */
371
- export const updateUnitPriceExcludingTax = async (controller: InvoiceController, form: WrappedFormUtils, record: IGood) => {
372
- return new Promise((resolve) => {
373
- form.validateFields(async (err, values) => {
374
-
375
- err = err || {};
376
-
377
- /** 税额 */
378
- let taxAmount;
379
-
380
- /** 金额(不含税) */
381
- let lineAmountExcludeTax;
382
-
383
- /** 不含税单价 */
384
- let priceExcludeTax;
385
-
386
- /** 扣除额 */
387
- const deduction = controller.state.goodsListState.deduction;
388
-
389
- const { editGood } = controller.state.goodsListState
390
-
391
- // 计算税额
392
- if (!promptErr(err.lineAmountIncludeTax) && !promptErr(err.taxRate)) {
393
- taxAmount = countTaxAmount(values.lineAmountIncludeTax || editGood?.lineAmountIncludeTax, deduction, values.taxRate);
394
- }
395
- form.setFieldsValue({ taxAmount });
396
- await controller.setEditGood({ taxAmount });
397
-
398
- // 计算 金额(不含税)
399
- if ((taxAmount || taxAmount === 0) && !promptErr(err.lineAmountIncludeTax)) {
400
- lineAmountExcludeTax = countAmountExcludeTax(values.lineAmountIncludeTax || editGood?.lineAmountIncludeTax, taxAmount);
401
- }
402
- form.setFieldsValue({ lineAmountExcludeTax });
403
- await controller.setEditGood({ lineAmountExcludeTax });
404
-
405
- // 单价(不含税)
406
- if (lineAmountExcludeTax && !promptErr(err.quantity)) {
407
- priceExcludeTax = countPrice(lineAmountExcludeTax, values.quantity || editGood?.quantity, controller.state.calculatingDigits);
408
- }
409
- form.setFieldsValue({ priceExcludeTax });
410
- await controller.setEditGood({ priceExcludeTax });
411
- });
412
-
413
- resolve(undefined)
414
- })
415
- };
416
-
417
- /** 不含税 => 更新(含税) */
418
- export const updateUnitPriceTax = async (controller: InvoiceController, form: WrappedFormUtils, record: IGood) => {
419
- return new Promise((resolve) => {
420
- form.validateFields(async (err, values) => {
421
- err = err || {};
422
-
423
- if (
424
- !err.taxRat &&
425
- (values.taxRate || values.taxRate === 0) &&
426
- !promptErr(err.lineAmountExcludeTax) &&
427
- (values.lineAmountExcludeTax || values.lineAmountExcludeTax === 0)
428
- ) {
429
-
430
- const calculatingDigits = controller.state.calculatingDigits;
431
- // 金额(含税)= 金额(不含税)* (1+ 税率)
432
- const lineAmountExcludeTax = format2(values.lineAmountExcludeTax);
433
- const lineAmountIncludeTax = format2(evaluate(`${lineAmountExcludeTax} * (1+(${values.taxRate}/100))`));
434
- await controller.setEditGood({ lineAmountIncludeTax });
435
-
436
- // 单价(含税) = 金额(含税) / (數量)
437
- // 是否有数量
438
- if (!err.quantity && values.quantity) {
439
- const priceIncludeTax = format15(evaluate(`${lineAmountIncludeTax} / ${values.quantity}`), calculatingDigits);
440
- await controller.setEditGood({ priceIncludeTax });
441
- }
442
-
443
- // 税额 = 金额(含税)-金额(不含税) (老逻辑)
444
- // const taxAmount = evaluate(`${lineAmountIncludeTax} - ${lineAmountExcludeTax}`);
445
-
446
- // 税额 = 金额(含税)-金额(不含税)(新逻辑)
447
- const taxAmount = format2(evaluate(`${lineAmountExcludeTax} * ${values.taxRate}/100`));
448
- form.setFieldsValue({ taxAmount });
449
- await controller.setEditGood({ taxAmount });
450
- } else {
451
- form.setFieldsValue({ taxAmount: undefined });
452
- await controller.setEditGood({ taxAmount: undefined });
453
- }
454
- // 单价(含税) = 单价(不含税) * (1+税率)
455
- // if (
456
- // !err.taxRat &&
457
- // (values.taxRate || values.taxRate === 0) &&
458
- // !promptErr(err.priceExcludeTax) &&
459
- // (values.priceExcludeTax || values.priceExcludeTax === 0)
460
- // ) {
461
- // const priceExcludeTax = format15(values.priceExcludeTax);
462
- // const priceIncludeTax = format15(evaluate(`${priceExcludeTax} * (1+(${values.taxRate}/100))`));
463
- // await controller.setEditGood({ priceIncludeTax });
464
- // }
465
-
466
- resolve(undefined)
467
- });
468
- })
469
- };
470
-
471
- /** 保存到编辑货物 */
472
- export const onSaveEditGood = lazyFn(
473
- (
474
- controller: InvoiceController,
475
- form: WrappedFormUtils,
476
- record: IGood,
477
- id: string,
478
- ) => {
479
- form.validateFields(async (err, values) => {
480
- err = err || {};
481
- if (err[id]) return;
482
-
483
- const v = {} as any;
484
- v[id] = values[id];
485
- await controller.setEditGood({ ...v });
486
- });
487
- },
488
- 1000,
489
- );
490
-
491
- /** 单调赋码 */
492
- export const endowCode = async (controller: InvoiceController, goods: IGood) => {
493
- await controller.wait();
494
- await controller.saveEditGood();
495
- await controller.pipeline(async (s) => {
496
- if (s.goodsListState.form && s.goodsListState.editGood?.$index === goods?.$index) {
497
- const err: any = s.goodsListState.form.getFieldsError();
498
- for (let key in err) {
499
- if (!err[key]) continue;
500
- message.error(err[key][0]);
501
- return;
502
- }
503
- }
504
-
505
- let g = s.goodsListState.goodsMap.get(goods.$index) as any;
506
- let i = s.goodsListState.goodsList.indexOf(g);
507
-
508
- switch (goods.lineAttribute) {
509
- case LineAttributeType.正常:
510
- s.goodsListState.endowCode.endowcodeGoodIndex = [goods.$index];
511
- break;
512
-
513
- case LineAttributeType.折扣行:
514
-
515
- s.goodsListState.endowCode.endowcodeGoodIndex = [goods.$index, s.goodsListState.goodsList[i - 1].$index];
516
- break;
517
-
518
- case LineAttributeType.被折扣行:
519
- s.goodsListState.endowCode.endowcodeGoodIndex = [goods.$index, s.goodsListState.goodsList[i + 1].$index];
520
- break;
521
- }
522
- })();
523
- }
524
-
525
- /** 修改了 项目名称 */
526
- export const onChangeItemName = async (controller: InvoiceController, form: WrappedFormUtils<any>, record: IGood) => {
527
- controller.run(async s => {
528
- const value = form.getFieldsValue().itemName;
529
-
530
- if (s.goodsListState.isMyShow) {
531
- await controller.setEditGood({ itemNameSelf: value });
532
- record.itemName && await controller.setEditGood({ itemName: record.itemName });
533
- } else {
534
- await controller.setEditGood({ itemName: value });
535
- record.itemNameSelf && await controller.setEditGood({ itemNameSelf: record.itemNameSelf });
536
- }
537
- })
538
- }
539
-
540
- /** 修改了 商品编码 */
541
- export const onChangeItemCode = async (controller: InvoiceController, form: WrappedFormUtils<any>, record: IGood) => {
542
- controller.run(async s => {
543
- const value = form.getFieldsValue().itemCode;
544
-
545
- if (s.goodsListState.isMyShow) {
546
- await controller.setEditGood({ itemCodeSelf: value });
547
- record.itemCode && await controller.setEditGood({ itemCode: record.itemCode });
548
- } else {
549
- await controller.setEditGood({ itemCode: value });
550
- record.itemCodeSelf && await controller.setEditGood({ itemCodeSelf: record.itemCodeSelf });
551
- }
552
- })
553
- }
554
-
555
- /** 修改了含税开关 重新计算 */
556
- export const onChangeSwitchTax = async (controller: InvoiceController, isTaxIncluded: boolean) => {
557
- if (!controller.state.goodsListState.isRecalculateWhenSwitchTax) {
558
- controller.pipeline(async s => { s.goodsListState = { ...s.goodsListState, isTaxIncluded } })();
559
- return
560
- }
561
- const calculatingDigits = controller.state.calculatingDigits;
562
-
563
- await controller.saveEditGood();
564
- await controller.wait();
565
-
566
- await controller.run(async s => {
567
- if (s.goodsListState.editGood) {
568
- message.error({
569
- content: '你正在编辑一个货物',
570
- key: '你正在编辑一个货物',
571
- });
572
-
573
- return;
574
- }
575
-
576
- s.goodsListState.isTaxIncluded = isTaxIncluded;
577
-
578
- try {
579
- let needRefresh = false;
580
-
581
- if (s.goodsListState?.goodsList && s.goodsListState.goodsList.length) {
582
- const newGoodsList = s.goodsListState.goodsList.map(good => {
583
- const {
584
- quantity: sourceQuantity,
585
- priceExcludeTax: sourcePriceExcludeTax,
586
- priceIncludeTax: sourcePriceIncludeTax,
587
- lineAmountExcludeTax: sourceLineAmountExcludeTax,
588
- lineAmountIncludeTax: sourceLineAmountIncludeTax,
589
- taxRate } = good;
590
- if (isTaxIncluded) {
591
- if (!sourceQuantity && sourceQuantity !== 0) return good;
592
- if (!sourcePriceIncludeTax && sourcePriceIncludeTax !== 0) return good;
593
- if (!taxRate && taxRate !== 0) return good;
594
- if (sourcePriceExcludeTax && sourceLineAmountExcludeTax && equal(countPrice(sourceLineAmountExcludeTax, sourceQuantity) || 0, sourcePriceExcludeTax)) {
595
- return good
596
- } else {
597
- needRefresh = true;
598
- }
599
- const quantity: any = format15(sourceQuantity, calculatingDigits);
600
- const priceIncludeTax: any = format15(sourcePriceIncludeTax, calculatingDigits);
601
-
602
- const lineAmountIncludeTax: any = format2(evaluate(`${priceIncludeTax} * ${quantity}`));
603
- const taxAmount: any = countTaxAmount(lineAmountIncludeTax, controller.state.goodsListState.deduction, taxRate as any);
604
- const lineAmountExcludeTax: any = countAmountExcludeTax(lineAmountIncludeTax, taxAmount);
605
- const priceExcludeTax: any = countPrice(lineAmountExcludeTax, quantity, controller.state.calculatingDigits);
606
-
607
- return {
608
- ...good,
609
- lineAmountExcludeTax,
610
- lineAmountIncludeTax,
611
- taxAmount,
612
- priceExcludeTax
613
- }
614
-
615
- } else {
616
- if (!sourceQuantity && sourceQuantity !== 0) return good;
617
- if (!sourcePriceExcludeTax && sourcePriceExcludeTax !== 0) return good;
618
- if (!taxRate && taxRate !== 0) return good;
619
- if (sourcePriceIncludeTax && sourceLineAmountIncludeTax && equal(countPrice(sourceLineAmountIncludeTax, sourceQuantity) || 0, sourcePriceIncludeTax)) {
620
- return good
621
- } else {
622
- needRefresh = true;
623
- }
624
- const quantity: any = format15(sourceQuantity, calculatingDigits);
625
- const priceExcludeTax: any = format15(sourcePriceExcludeTax, calculatingDigits);
626
-
627
- const lineAmountExcludeTax: any = format2(evaluate(`${priceExcludeTax} * ${quantity}`));
628
- const lineAmountIncludeTax: any = format2(evaluate(`${lineAmountExcludeTax} * (1+(${taxRate}/100))`));
629
- const priceIncludeTax: any = format15(evaluate(`${lineAmountIncludeTax} / ${quantity}`), calculatingDigits);
630
- const taxAmount: any = evaluate(`${lineAmountIncludeTax} - ${lineAmountExcludeTax}`);
631
-
632
- return {
633
- ...good,
634
- lineAmountExcludeTax,
635
- lineAmountIncludeTax,
636
- taxAmount,
637
- priceIncludeTax
638
- }
639
- }
640
-
641
- })
642
-
643
- if (needRefresh) {
644
- s.goodsListState.goodsList = newGoodsList;
645
- }
646
- }
647
- } catch (e) {
648
- console.error('切换税率重新计算出错', e, s.goodsListState)
649
- }
650
- })
651
- }
652
-
653
- /** 税额 */
654
- export const onChangeTaxAmount = lazyFn(
655
- (controller: InvoiceController, form: WrappedFormUtils, record: IGood) => {
656
-
657
- /** 金额(不含税) */
658
- let lineAmountExcludeTax;
659
-
660
- form.validateFields(async (err, values) => {
661
- err = err || {};
662
-
663
- const record = controller.state.goodsListState.editGood;
664
-
665
- // 校验是否有含税金额
666
- if (err.lineAmountIncludeTax && (!record?.lineAmountIncludeTax && record?.lineAmountIncludeTax !== 0)) {
667
- await clearCalculatingField(controller);
668
- return;
669
- }
670
-
671
- // 计数不含税金额
672
- // lineAmountExcludeTax = countAmountExcludeTax(record?.lineAmountIncludeTax || 0, values.taxAmount);
673
- // form.setFieldsValue({ lineAmountExcludeTax });
674
-
675
- // const priceExcludeTax: any = countPrice(lineAmountExcludeTax || '', record?.quantity || '', controller.state.calculatingDigits);
676
-
677
- // await controller.setEditGood({ lineAmountExcludeTax, taxAmount: values.taxAmount, priceExcludeTax });
678
- // form.setFieldsValue({ priceExcludeTax });
679
-
680
- // 计算含税金额
681
- const lineAmountIncludeTax = chain(bignumber(record?.lineAmountExcludeTax || 0)).add(bignumber(values.taxAmount || 0)).done().toNumber();
682
- form.setFieldsValue({ lineAmountIncludeTax });
683
-
684
- await controller.setEditGood({ taxAmount: values.taxAmount, lineAmountIncludeTax });
685
-
686
- // 清楚 计算中启动字段
687
- await clearCalculatingField(controller);
688
- })
689
- },
690
- 1000,
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
+ import { equal } from 'mathjs';
14
+ import { chain, bignumber } from 'mathjs';
15
+
16
+ export { format2, format15 } from '../../../../../../tools/calculate';
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
+ switch (controller.state.goodsListState.calculateType) {
316
+ case '1':
317
+ await updateUnitPriceExcludingTax(controller, form, record);
318
+ break;
319
+
320
+ case '2':
321
+ await updateUnitPriceTax(controller, form, record);
322
+ break;
323
+
324
+ case '3':
325
+ default:
326
+ // 是否含税
327
+ if (controller.state.goodsListState.isTaxIncluded) {
328
+ await updateUnitPriceExcludingTax(controller, form, record);
329
+ } else {
330
+ await updateUnitPriceTax(controller, form, record);
331
+ }
332
+ break;
333
+ }
334
+
335
+ // 清楚 计算中启动字段
336
+ await clearCalculatingField(controller);
337
+ });
338
+ },
339
+ 1000,
340
+ );
341
+
342
+ /** 小规模纳税人 1% 和 3% 自动赋码免税 */
343
+ export function dutyFree(controller: InvoiceController, taxRate: number, form: WrappedFormUtils<any>, record: IGood) {
344
+
345
+ const cache = controller.state.goodsListState.endowCode.cache;
346
+ const invoiceType = controller.state.invoiceType;
347
+
348
+ // 4月1日至12月31日
349
+ console.log('===> 小规模纳税人免税逻辑');
350
+ console.log('===> invoiceType', invoiceType);
351
+ console.log('===> en', controller.state.en);
352
+ console.log('===> taxRate', taxRate);
353
+ console.log('===> state', controller.state);
354
+
355
+ if (moment().valueOf() > moment('2022-12-31 23:59').valueOf()) return taxRate;
356
+ if (controller.state.en !== '08') return taxRate;
357
+ if (invoiceType !== '10' && invoiceType !== '04') return taxRate;
358
+
359
+ if (taxRate === 1 || taxRate === 3) {
360
+ cache[record.$index] = { favouredPolicyName: record.favouredPolicyName, favouredPolicyMark: record.favouredPolicyMark, taxFreeType: record.taxFreeType }
361
+ record.favouredPolicyName = '免税';
362
+ record.taxRate = 0;
363
+ record.favouredPolicyMark = 1;
364
+ record.taxFreeType = 1 as any;
365
+ form.setFieldsValue({ taxRate: 0 });
366
+ return 0;
367
+ }
368
+ }
369
+
370
+ /** 含税 => 更新(不含税) */
371
+ export const updateUnitPriceExcludingTax = async (controller: InvoiceController, form: WrappedFormUtils, record: IGood) => {
372
+ return new Promise((resolve) => {
373
+ form.validateFields(async (err, values) => {
374
+
375
+ err = err || {};
376
+
377
+ /** 税额 */
378
+ let taxAmount;
379
+
380
+ /** 金额(不含税) */
381
+ let lineAmountExcludeTax;
382
+
383
+ /** 不含税单价 */
384
+ let priceExcludeTax;
385
+
386
+ /** 扣除额 */
387
+ const deduction = controller.state.goodsListState.deduction;
388
+
389
+ const { editGood } = controller.state.goodsListState
390
+
391
+ // 计算税额
392
+ if (!promptErr(err.lineAmountIncludeTax) && !promptErr(err.taxRate)) {
393
+ taxAmount = countTaxAmount(values.lineAmountIncludeTax || editGood?.lineAmountIncludeTax, deduction, values.taxRate);
394
+ }
395
+ form.setFieldsValue({ taxAmount });
396
+ await controller.setEditGood({ taxAmount });
397
+
398
+ // 计算 金额(不含税)
399
+ if ((taxAmount || taxAmount === 0) && !promptErr(err.lineAmountIncludeTax)) {
400
+ lineAmountExcludeTax = countAmountExcludeTax(values.lineAmountIncludeTax || editGood?.lineAmountIncludeTax, taxAmount);
401
+ }
402
+ form.setFieldsValue({ lineAmountExcludeTax });
403
+ await controller.setEditGood({ lineAmountExcludeTax });
404
+
405
+ // 单价(不含税)
406
+ if (lineAmountExcludeTax && !promptErr(err.quantity)) {
407
+ priceExcludeTax = countPrice(lineAmountExcludeTax, values.quantity || editGood?.quantity, controller.state.calculatingDigits);
408
+ }
409
+ form.setFieldsValue({ priceExcludeTax });
410
+ await controller.setEditGood({ priceExcludeTax });
411
+ });
412
+
413
+ resolve(undefined)
414
+ })
415
+ };
416
+
417
+ /** 不含税 => 更新(含税) */
418
+ export const updateUnitPriceTax = async (controller: InvoiceController, form: WrappedFormUtils, record: IGood) => {
419
+ return new Promise((resolve) => {
420
+ form.validateFields(async (err, values) => {
421
+ err = err || {};
422
+
423
+ if (
424
+ !err.taxRat &&
425
+ (values.taxRate || values.taxRate === 0) &&
426
+ !promptErr(err.lineAmountExcludeTax) &&
427
+ (values.lineAmountExcludeTax || values.lineAmountExcludeTax === 0)
428
+ ) {
429
+
430
+ const calculatingDigits = controller.state.calculatingDigits;
431
+ // 金额(含税)= 金额(不含税)* (1+ 税率)
432
+ const lineAmountExcludeTax = format2(values.lineAmountExcludeTax);
433
+ const lineAmountIncludeTax = format2(evaluate(`${lineAmountExcludeTax} * (1+(${values.taxRate}/100))`));
434
+ await controller.setEditGood({ lineAmountIncludeTax });
435
+
436
+ // 单价(含税) = 金额(含税) / (數量)
437
+ // 是否有数量
438
+ if (!err.quantity && values.quantity) {
439
+ const priceIncludeTax = format15(evaluate(`${lineAmountIncludeTax} / ${values.quantity}`), calculatingDigits);
440
+ await controller.setEditGood({ priceIncludeTax });
441
+ }
442
+
443
+ // 税额 = 金额(含税)-金额(不含税) (老逻辑)
444
+ // const taxAmount = evaluate(`${lineAmountIncludeTax} - ${lineAmountExcludeTax}`);
445
+
446
+ // 税额 = 金额(含税)-金额(不含税)(新逻辑)
447
+ const taxAmount = format2(evaluate(`${lineAmountExcludeTax} * ${values.taxRate}/100`));
448
+ form.setFieldsValue({ taxAmount });
449
+ await controller.setEditGood({ taxAmount });
450
+ } else {
451
+ form.setFieldsValue({ taxAmount: undefined });
452
+ await controller.setEditGood({ taxAmount: undefined });
453
+ }
454
+ // 单价(含税) = 单价(不含税) * (1+税率)
455
+ // if (
456
+ // !err.taxRat &&
457
+ // (values.taxRate || values.taxRate === 0) &&
458
+ // !promptErr(err.priceExcludeTax) &&
459
+ // (values.priceExcludeTax || values.priceExcludeTax === 0)
460
+ // ) {
461
+ // const priceExcludeTax = format15(values.priceExcludeTax);
462
+ // const priceIncludeTax = format15(evaluate(`${priceExcludeTax} * (1+(${values.taxRate}/100))`));
463
+ // await controller.setEditGood({ priceIncludeTax });
464
+ // }
465
+
466
+ resolve(undefined)
467
+ });
468
+ })
469
+ };
470
+
471
+ /** 保存到编辑货物 */
472
+ export const onSaveEditGood = lazyFn(
473
+ (
474
+ controller: InvoiceController,
475
+ form: WrappedFormUtils,
476
+ record: IGood,
477
+ id: string,
478
+ ) => {
479
+ form.validateFields(async (err, values) => {
480
+ err = err || {};
481
+ if (err[id]) return;
482
+
483
+ const v = {} as any;
484
+ v[id] = values[id];
485
+ await controller.setEditGood({ ...v });
486
+ });
487
+ },
488
+ 1000,
489
+ );
490
+
491
+ /** 单调赋码 */
492
+ export const endowCode = async (controller: InvoiceController, goods: IGood) => {
493
+ await controller.wait();
494
+ await controller.saveEditGood();
495
+ await controller.pipeline(async (s) => {
496
+ if (s.goodsListState.form && s.goodsListState.editGood?.$index === goods?.$index) {
497
+ const err: any = s.goodsListState.form.getFieldsError();
498
+ for (let key in err) {
499
+ if (!err[key]) continue;
500
+ message.error(err[key][0]);
501
+ return;
502
+ }
503
+ }
504
+
505
+ let g = s.goodsListState.goodsMap.get(goods.$index) as any;
506
+ let i = s.goodsListState.goodsList.indexOf(g);
507
+
508
+ switch (goods.lineAttribute) {
509
+ case LineAttributeType.正常:
510
+ s.goodsListState.endowCode.endowcodeGoodIndex = [goods.$index];
511
+ break;
512
+
513
+ case LineAttributeType.折扣行:
514
+
515
+ s.goodsListState.endowCode.endowcodeGoodIndex = [goods.$index, s.goodsListState.goodsList[i - 1].$index];
516
+ break;
517
+
518
+ case LineAttributeType.被折扣行:
519
+ s.goodsListState.endowCode.endowcodeGoodIndex = [goods.$index, s.goodsListState.goodsList[i + 1].$index];
520
+ break;
521
+ }
522
+ })();
523
+ }
524
+
525
+ /** 修改了 项目名称 */
526
+ export const onChangeItemName = async (controller: InvoiceController, form: WrappedFormUtils<any>, record: IGood) => {
527
+ controller.run(async s => {
528
+ const value = form.getFieldsValue().itemName;
529
+
530
+ if (s.goodsListState.isMyShow) {
531
+ await controller.setEditGood({ itemNameSelf: value });
532
+ record.itemName && await controller.setEditGood({ itemName: record.itemName });
533
+ } else {
534
+ await controller.setEditGood({ itemName: value });
535
+ record.itemNameSelf && await controller.setEditGood({ itemNameSelf: record.itemNameSelf });
536
+ }
537
+ })
538
+ }
539
+
540
+ /** 修改了 商品编码 */
541
+ export const onChangeItemCode = async (controller: InvoiceController, form: WrappedFormUtils<any>, record: IGood) => {
542
+ controller.run(async s => {
543
+ const value = form.getFieldsValue().itemCode;
544
+
545
+ if (s.goodsListState.isMyShow) {
546
+ await controller.setEditGood({ itemCodeSelf: value });
547
+ record.itemCode && await controller.setEditGood({ itemCode: record.itemCode });
548
+ } else {
549
+ await controller.setEditGood({ itemCode: value });
550
+ record.itemCodeSelf && await controller.setEditGood({ itemCodeSelf: record.itemCodeSelf });
551
+ }
552
+ })
553
+ }
554
+
555
+ /** 修改了含税开关 重新计算 */
556
+ export const onChangeSwitchTax = async (controller: InvoiceController, isTaxIncluded: boolean) => {
557
+ if (!controller.state.goodsListState.isRecalculateWhenSwitchTax) {
558
+ controller.pipeline(async s => { s.goodsListState = { ...s.goodsListState, isTaxIncluded } })();
559
+ return
560
+ }
561
+ const calculatingDigits = controller.state.calculatingDigits;
562
+
563
+ await controller.saveEditGood();
564
+ await controller.wait();
565
+
566
+ await controller.run(async s => {
567
+ if (s.goodsListState.editGood) {
568
+ message.error({
569
+ content: '你正在编辑一个货物',
570
+ key: '你正在编辑一个货物',
571
+ });
572
+
573
+ return;
574
+ }
575
+
576
+ s.goodsListState.isTaxIncluded = isTaxIncluded;
577
+
578
+ try {
579
+ let needRefresh = false;
580
+
581
+ if (s.goodsListState?.goodsList && s.goodsListState.goodsList.length) {
582
+ const newGoodsList = s.goodsListState.goodsList.map(good => {
583
+ const {
584
+ quantity: sourceQuantity,
585
+ priceExcludeTax: sourcePriceExcludeTax,
586
+ priceIncludeTax: sourcePriceIncludeTax,
587
+ lineAmountExcludeTax: sourceLineAmountExcludeTax,
588
+ lineAmountIncludeTax: sourceLineAmountIncludeTax,
589
+ taxRate } = good;
590
+ if (isTaxIncluded) {
591
+ if (!sourceQuantity && sourceQuantity !== 0) return good;
592
+ if (!sourcePriceIncludeTax && sourcePriceIncludeTax !== 0) return good;
593
+ if (!taxRate && taxRate !== 0) return good;
594
+ if (sourcePriceExcludeTax && sourceLineAmountExcludeTax && equal(countPrice(sourceLineAmountExcludeTax, sourceQuantity) || 0, sourcePriceExcludeTax)) {
595
+ return good
596
+ } else {
597
+ needRefresh = true;
598
+ }
599
+ const quantity: any = format15(sourceQuantity, calculatingDigits);
600
+ const priceIncludeTax: any = format15(sourcePriceIncludeTax, calculatingDigits);
601
+
602
+ const lineAmountIncludeTax: any = format2(evaluate(`${priceIncludeTax} * ${quantity}`));
603
+ const taxAmount: any = countTaxAmount(lineAmountIncludeTax, controller.state.goodsListState.deduction, taxRate as any);
604
+ const lineAmountExcludeTax: any = countAmountExcludeTax(lineAmountIncludeTax, taxAmount);
605
+ const priceExcludeTax: any = countPrice(lineAmountExcludeTax, quantity, controller.state.calculatingDigits);
606
+
607
+ return {
608
+ ...good,
609
+ lineAmountExcludeTax,
610
+ lineAmountIncludeTax,
611
+ taxAmount,
612
+ priceExcludeTax
613
+ }
614
+
615
+ } else {
616
+ if (!sourceQuantity && sourceQuantity !== 0) return good;
617
+ if (!sourcePriceExcludeTax && sourcePriceExcludeTax !== 0) return good;
618
+ if (!taxRate && taxRate !== 0) return good;
619
+ if (sourcePriceIncludeTax && sourceLineAmountIncludeTax && equal(countPrice(sourceLineAmountIncludeTax, sourceQuantity) || 0, sourcePriceIncludeTax)) {
620
+ return good
621
+ } else {
622
+ needRefresh = true;
623
+ }
624
+ const quantity: any = format15(sourceQuantity, calculatingDigits);
625
+ const priceExcludeTax: any = format15(sourcePriceExcludeTax, calculatingDigits);
626
+
627
+ const lineAmountExcludeTax: any = format2(evaluate(`${priceExcludeTax} * ${quantity}`));
628
+ const lineAmountIncludeTax: any = format2(evaluate(`${lineAmountExcludeTax} * (1+(${taxRate}/100))`));
629
+ const priceIncludeTax: any = format15(evaluate(`${lineAmountIncludeTax} / ${quantity}`), calculatingDigits);
630
+ const taxAmount: any = evaluate(`${lineAmountIncludeTax} - ${lineAmountExcludeTax}`);
631
+
632
+ return {
633
+ ...good,
634
+ lineAmountExcludeTax,
635
+ lineAmountIncludeTax,
636
+ taxAmount,
637
+ priceIncludeTax
638
+ }
639
+ }
640
+
641
+ })
642
+
643
+ if (needRefresh) {
644
+ s.goodsListState.goodsList = newGoodsList;
645
+ }
646
+ }
647
+ } catch (e) {
648
+ console.error('切换税率重新计算出错', e, s.goodsListState)
649
+ }
650
+ })
651
+ }
652
+
653
+ /** 税额 */
654
+ export const onChangeTaxAmount = lazyFn(
655
+ (controller: InvoiceController, form: WrappedFormUtils, record: IGood) => {
656
+
657
+ /** 金额(不含税) */
658
+ let lineAmountExcludeTax;
659
+
660
+ form.validateFields(async (err, values) => {
661
+ err = err || {};
662
+
663
+ const record = controller.state.goodsListState.editGood;
664
+
665
+ // 校验是否有含税金额
666
+ if (err.lineAmountIncludeTax && (!record?.lineAmountIncludeTax && record?.lineAmountIncludeTax !== 0)) {
667
+ await clearCalculatingField(controller);
668
+ return;
669
+ }
670
+
671
+ // 计数不含税金额
672
+ // lineAmountExcludeTax = countAmountExcludeTax(record?.lineAmountIncludeTax || 0, values.taxAmount);
673
+ // form.setFieldsValue({ lineAmountExcludeTax });
674
+
675
+ // const priceExcludeTax: any = countPrice(lineAmountExcludeTax || '', record?.quantity || '', controller.state.calculatingDigits);
676
+
677
+ // await controller.setEditGood({ lineAmountExcludeTax, taxAmount: values.taxAmount, priceExcludeTax });
678
+ // form.setFieldsValue({ priceExcludeTax });
679
+
680
+ // 计算含税金额
681
+ const lineAmountIncludeTax = chain(bignumber(record?.lineAmountExcludeTax || 0)).add(bignumber(values.taxAmount || 0)).done().toNumber();
682
+ form.setFieldsValue({ lineAmountIncludeTax });
683
+
684
+ await controller.setEditGood({ taxAmount: values.taxAmount, lineAmountIncludeTax });
685
+
686
+ // 清楚 计算中启动字段
687
+ await clearCalculatingField(controller);
688
+ })
689
+ },
690
+ 1000,
691
691
  )