kts-component-invoice-operate 3.1.12 → 3.1.13

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