kts-component-invoice-operate 3.1.2 → 3.1.4

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