kts-component-invoice-operate 3.2.104 → 3.2.106

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.
@@ -6,54 +6,87 @@ import { IGood, InvoiceControllerState, LineAttributeType } from '..';
6
6
  import { format15 } from '../../tools/calculate';
7
7
 
8
8
  export default async function mergeDetails(state: InvoiceControllerState, selectedGoodIndex?: string[]) {
9
- debugger;
9
+
10
10
  if (state.goodsListState.editGood || !selectedGoodIndex || selectedGoodIndex.length < 2) return;
11
11
 
12
- // const goodsList = state.goodsListState.selectedGoodIndex.map(e => state.goodsListState.goodsMap.get(e)).filter(e => !!e) as IGood[];
13
- // const goodsList = state.goodsListState.goodsList.filter(e => state.goodsListState.selectedGoodIndex.indexOf(e.$index) >= 0)
14
12
  const goodsList = state.goodsListState.goodsList.filter(e => selectedGoodIndex.indexOf(e.$index) >= 0);
15
13
  if (goodsList.length < 2) return;
16
14
 
17
- try {
18
- // 创建合并后的商品对象
19
- let sum: IGood = { $index: idGenerator(), lineAttribute: LineAttributeType.正常 }
20
-
21
- // 存在税率不一样的明细,不能合并
22
- await checkTaxTate(goodsList);
23
-
24
- // 填充行明细信息
25
- sum = await fillingInformationGood(goodsList, sum);
26
-
27
- // 合并数量
28
- sum.quantity = await mergeQuantity(goodsList);
29
-
30
- // 合并金额(不含税)
31
- sum.lineAmountExcludeTax = await mergeLineAmountExcludeTax(goodsList);
32
-
33
- // 合并金额(含税)
34
- sum.lineAmountIncludeTax = await mergeLineAmountIncludeTax(goodsList);
35
-
36
- // 计算单价(不含税)
37
- sum.priceExcludeTax = await calculatePriceExcludeTax(sum, state.calculatingDigits);
38
-
39
- // 计算单价(含税)
40
- sum.priceIncludeTax = await calculatePriceIncludeTax(sum, state.calculatingDigits);
41
-
42
- // 计算税额
43
- sum.taxAmount = chain(bignumber(sum.lineAmountIncludeTax)).subtract(bignumber(sum.lineAmountExcludeTax)).done().toNumber()
44
-
45
- // 校验数据 是否数量和金额是否同号
46
- await checkSameNumber(sum);
15
+ grouping(goodsList).forEach(merge);
16
+
17
+ /** 分组 */
18
+ function grouping(goodsList: IGood[]): IGood[][] {
19
+ const grouped: any = {};
20
+ goodsList.forEach(good => {
21
+ const key = (() => {
22
+ switch (good.lineAttribute) {
23
+ case LineAttributeType.折让行:
24
+ return LineAttributeType.折让行
25
+ case LineAttributeType.赠品行:
26
+ return LineAttributeType.赠品行
27
+ default:
28
+ return LineAttributeType.正常
29
+ }
30
+ })()
31
+
32
+ if (!grouped[key]) {
33
+ grouped[key] = [];
34
+ }
35
+
36
+ grouped[key].push({ ...good, lineAttribute: key });
37
+ })
38
+ return Object.values(grouped);
39
+ }
47
40
 
48
- const p = state.goodsListState.goodsList.indexOf(goodsList[0]);
49
- state.goodsListState.goodsList = state.goodsListState.goodsList.filter(e => selectedGoodIndex.indexOf(e.$index) < 0);
50
- state.goodsListState.goodsList.splice(p, 0, sum);
51
- state.goodsListState.goodsList = state.goodsListState.goodsList.filter(e => e.lineAmountExcludeTax !== 0);
52
- state.goodsListState.goodsMap = new Map();
53
- state.goodsListState.goodsList.forEach(e => { state.goodsListState.goodsMap.set(e.$index, e) });
54
- state.goodsListState.selectedGoodIndex = [];
55
- } catch (error: any) {
56
- showError(error)
41
+ /** 合并 */
42
+ async function merge(goodsList: IGood[]) {
43
+ if (goodsList.length < 2) return;
44
+
45
+ const selectedGoodIndex = goodsList.map(e => e.$index);
46
+ try {
47
+ // 创建合并后的商品对象
48
+ let sum: IGood = {
49
+ $index: idGenerator(),
50
+ lineAttribute: goodsList[0].lineAttribute,
51
+ }
52
+
53
+ // 存在税率不一样的明细,不能合并
54
+ await checkTaxTate(goodsList);
55
+
56
+ // 填充行明细信息
57
+ sum = await fillingInformationGood(goodsList, sum);
58
+
59
+ // 合并数量
60
+ sum.quantity = await mergeQuantity(goodsList);
61
+
62
+ // 合并金额(不含税)
63
+ sum.lineAmountExcludeTax = await mergeLineAmountExcludeTax(goodsList);
64
+
65
+ // 合并金额(含税)
66
+ sum.lineAmountIncludeTax = await mergeLineAmountIncludeTax(goodsList);
67
+
68
+ // 计算单价(不含税)
69
+ sum.priceExcludeTax = await calculatePriceExcludeTax(sum, state.calculatingDigits);
70
+
71
+ // 计算单价(含税)
72
+ sum.priceIncludeTax = await calculatePriceIncludeTax(sum, state.calculatingDigits);
73
+
74
+ // 计算税额
75
+ sum.taxAmount = chain(bignumber(sum.lineAmountIncludeTax)).subtract(bignumber(sum.lineAmountExcludeTax)).done().toNumber()
76
+
77
+ // 校验数据 是否数量和金额是否同号
78
+ await checkSameNumber(sum);
79
+
80
+ const p = state.goodsListState.goodsList.indexOf(goodsList[0]);
81
+ state.goodsListState.goodsList = state.goodsListState.goodsList.filter(e => selectedGoodIndex.indexOf(e.$index) < 0);
82
+ state.goodsListState.goodsList.splice(p, 0, sum);
83
+ state.goodsListState.goodsList = state.goodsListState.goodsList.filter(e => e.lineAmountExcludeTax !== 0);
84
+ state.goodsListState.goodsMap = new Map();
85
+ state.goodsListState.goodsList.forEach(e => { state.goodsListState.goodsMap.set(e.$index, e) });
86
+ state.goodsListState.selectedGoodIndex = [];
87
+ } catch (error: any) {
88
+ showError(error)
89
+ }
57
90
  }
58
91
  }
59
92
 
@@ -104,7 +137,7 @@ async function fillingInformationGood(goodsList: IGood[], sum: IGood) {
104
137
 
105
138
  const goods = goodsList[findMaxIndex(goodsList.map(e => e.lineAmountIncludeTax || 0))]
106
139
 
107
- return { ...goods, lineAttribute: LineAttributeType.正常 };
140
+ return { ...goods, lineAttribute: sum.lineAttribute };
108
141
  }
109
142
 
110
143
  /** 存在税率不一样的明细,不能合并 */
@@ -140,129 +140,129 @@ for (let i = 0; i <= 10000; i++) {
140
140
 
141
141
  const lines: any[] = [
142
142
  {
143
- "serialNumber": "1714491422279110656",
144
- "lineNumber": 1,
145
- "taxCode": "3070401000000000000",
146
- "taxName": "信息技术服务",
147
- "specification": null,
148
- "itemName": "技术服务费",
149
- "itemCode": "",
150
- "unit": "套",
151
- "quantity": 1.0000000000001,
152
- "taxRate": 0.06,
153
- "priceExcludeTax": 5,
154
- "priceIncludeTax": 5.3,
155
- "amountTax": 0.3,
156
- "lineAmountExcludeTax": 5,
157
- "lineAmountIncludeTax": 5.3,
158
- "lineAttribute": LineAttributeType.被折扣行,
159
- "discountGroup": "1714491422291693568",
160
- "favouredPolicyMark": false,
161
- "favouredPolicyName": null,
162
- "zeroTaxRateFlag": null,
163
- "referenceLines": null,
164
- "version": 0,
165
- taxAmount:1
143
+ "serialNumber": "1714491422279110656",
144
+ "lineNumber": 1,
145
+ "taxCode": "3070401000000000000",
146
+ "taxName": "信息技术服务",
147
+ "specification": null,
148
+ "itemName": "技术服务费",
149
+ "itemCode": "z",
150
+ "unit": "套",
151
+ "quantity": 1.0000000000001,
152
+ "taxRate": 0.06,
153
+ "priceExcludeTax": 2,
154
+ "priceIncludeTax": 2.12,
155
+ "amountTax": 0.3,
156
+ "lineAmountExcludeTax": 5,
157
+ "lineAmountIncludeTax": 5.3,
158
+ "lineAttribute": LineAttributeType.被折扣行,
159
+ "discountGroup": "1714491422291693568",
160
+ "favouredPolicyMark": false,
161
+ "favouredPolicyName": null,
162
+ "zeroTaxRateFlag": null,
163
+ "referenceLines": null,
164
+ "version": 0,
165
+ "taxAmount": 1
166
166
  },
167
167
  {
168
- "serialNumber": "1714491422279110656",
169
- "lineNumber": 2,
170
- "taxCode": "3070401000000000000",
171
- "taxName": "信息技术服务",
172
- "specification": "",
173
- "itemName": "技术服务费",
174
- "itemCode": "",
175
- "unit": "",
176
- "quantity": null,
177
- "taxRate": 0.06,
178
- "priceExcludeTax": null,
179
- "priceIncludeTax": null,
180
- "amountTax": -0.06,
181
- "lineAmountExcludeTax": 5,
182
- "lineAmountIncludeTax": 5.3,
183
- "lineAttribute": LineAttributeType.折扣行,
184
- "discountGroup": "1714491422291693568",
185
- "favouredPolicyMark": false,
186
- "favouredPolicyName": null,
187
- "zeroTaxRateFlag": null,
188
- "referenceLines": null,
189
- "version": 0,
190
- taxAmount:1
168
+ "serialNumber": "1714491422279110656",
169
+ "lineNumber": 2,
170
+ "taxCode": "3070401000000000000",
171
+ "taxName": "信息技术服务",
172
+ "specification": "",
173
+ "itemName": "技术服务费",
174
+ "itemCode": "z",
175
+ "unit": "",
176
+ "quantity": null,
177
+ "taxRate": 0.06,
178
+ "priceExcludeTax": null,
179
+ "priceIncludeTax": null,
180
+ "amountTax": -0.06,
181
+ "lineAmountExcludeTax": 5,
182
+ "lineAmountIncludeTax": 5.3,
183
+ "lineAttribute": LineAttributeType.折扣行,
184
+ "discountGroup": "1714491422291693568",
185
+ "favouredPolicyMark": false,
186
+ "favouredPolicyName": null,
187
+ "zeroTaxRateFlag": null,
188
+ "referenceLines": null,
189
+ "version": 0,
190
+ "taxAmount": 1
191
191
  },
192
192
  {
193
- "serialNumber": "1714491422279110656",
194
- "lineNumber": 3,
195
- "taxCode": "3070401000000000000",
196
- "taxName": "信息技术服务",
197
- "specification": null,
198
- "itemName": "技术服务费",
199
- "itemCode": null,
200
- "unit": "套",
201
- "quantity": 1,
202
- "taxRate": 0.06,
203
- "priceExcludeTax": 2,
204
- "priceIncludeTax": 2.12,
205
- "amountTax": 0.12,
206
- "lineAmountExcludeTax": 5,
207
- "lineAmountIncludeTax": 5.3,
208
- "lineAttribute": LineAttributeType.正常,
209
- "discountGroup": null,
210
- "favouredPolicyMark": false,
211
- "favouredPolicyName": null,
212
- "zeroTaxRateFlag": null,
213
- "referenceLines": null,
214
- "version": 0,
215
- taxAmount:1
193
+ "serialNumber": "1714491422279110656",
194
+ "lineNumber": 3,
195
+ "taxCode": "3070401000000000000",
196
+ "taxName": "信息技术服务",
197
+ "specification": null,
198
+ "itemName": "技术服务费",
199
+ "itemCode": "z",
200
+ "unit": "套",
201
+ "quantity": 1,
202
+ "taxRate": 0.06,
203
+ "priceExcludeTax": 2,
204
+ "priceIncludeTax": 2.12,
205
+ "amountTax": 0.12,
206
+ "lineAmountExcludeTax": 5,
207
+ "lineAmountIncludeTax": 5.3,
208
+ "lineAttribute": LineAttributeType.正常,
209
+ "discountGroup": null,
210
+ "favouredPolicyMark": false,
211
+ "favouredPolicyName": null,
212
+ "zeroTaxRateFlag": null,
213
+ "referenceLines": null,
214
+ "version": 0,
215
+ "taxAmount": 1
216
216
  },
217
217
  {
218
- "serialNumber": "1714491422279110656",
219
- "lineNumber": 3,
220
- "taxCode": "3070401000000000000",
221
- "taxName": "信息技术服务",
222
- "specification": null,
223
- "itemName": "技术服务费",
224
- "itemCode": null,
225
- "unit": "套",
226
- "quantity": 1,
227
- "taxRate": 0.06,
228
- "priceExcludeTax": 2,
229
- "priceIncludeTax": 2.12,
230
- "amountTax": 0.12,
231
- "lineAmountExcludeTax": 5,
232
- "lineAmountIncludeTax": 5.3,
233
- "lineAttribute": LineAttributeType.折让行,
234
- "discountGroup": null,
235
- "favouredPolicyMark": false,
236
- "favouredPolicyName": null,
237
- "zeroTaxRateFlag": null,
238
- "referenceLines": null,
239
- "version": 0,
240
- taxAmount:1
218
+ "serialNumber": "1714491422279110656",
219
+ "lineNumber": 3,
220
+ "taxCode": "3070401000000000000",
221
+ "taxName": "信息技术服务",
222
+ "specification": null,
223
+ "itemName": "技术服务费",
224
+ "itemCode": "z",
225
+ "unit": "套",
226
+ "quantity": 1,
227
+ "taxRate": 0.06,
228
+ "priceExcludeTax": 2,
229
+ "priceIncludeTax": 2.12,
230
+ "amountTax": 0.12,
231
+ "lineAmountExcludeTax": 5,
232
+ "lineAmountIncludeTax": 5.3,
233
+ "lineAttribute": LineAttributeType.折让行,
234
+ "discountGroup": null,
235
+ "favouredPolicyMark": false,
236
+ "favouredPolicyName": null,
237
+ "zeroTaxRateFlag": null,
238
+ "referenceLines": null,
239
+ "version": 0,
240
+ "taxAmount": 1
241
241
  },
242
242
  {
243
- "serialNumber": "1714491422279110656",
244
- "lineNumber": 3,
245
- "taxCode": "3070401000000000000",
246
- "taxName": "信息技术服务",
247
- "specification": null,
248
- "itemName": "技术服务费",
249
- "itemCode": null,
250
- "unit": "套",
251
- "quantity": 1,
252
- "taxRate": 0.06,
253
- "priceExcludeTax": 2,
254
- "priceIncludeTax": 2.12,
255
- "amountTax": 0.12,
256
- "lineAmountExcludeTax": 5,
257
- "lineAmountIncludeTax": 5.3,
258
- "lineAttribute": LineAttributeType.折让行,
259
- "discountGroup": null,
260
- "favouredPolicyMark": false,
261
- "favouredPolicyName": null,
262
- "zeroTaxRateFlag": null,
263
- "referenceLines": null,
264
- "version": 0,
265
- taxAmount:1
243
+ "serialNumber": "1714491422279110656",
244
+ "lineNumber": 3,
245
+ "taxCode": "3070401000000000000",
246
+ "taxName": "信息技术服务",
247
+ "specification": null,
248
+ "itemName": "技术服务费",
249
+ "itemCode": "z",
250
+ "unit": "套",
251
+ "quantity": 1,
252
+ "taxRate": 0.06,
253
+ "priceExcludeTax": 2,
254
+ "priceIncludeTax": 2.12,
255
+ "amountTax": 0.12,
256
+ "lineAmountExcludeTax": 5,
257
+ "lineAmountIncludeTax": 5.3,
258
+ "lineAttribute": LineAttributeType.折让行,
259
+ "discountGroup": null,
260
+ "favouredPolicyMark": false,
261
+ "favouredPolicyName": null,
262
+ "zeroTaxRateFlag": null,
263
+ "referenceLines": null,
264
+ "version": 0,
265
+ "taxAmount": 1
266
266
  },
267
267
  {
268
268
  "serialNumber": "1714491422279110656",
@@ -271,7 +271,7 @@ const lines: any[] = [
271
271
  "taxName": "信息技术服务",
272
272
  "specification": null,
273
273
  "itemName": "技术服务费",
274
- "itemCode": null,
274
+ "itemCode": "z",
275
275
  "unit": "套",
276
276
  "quantity": 1,
277
277
  "taxRate": 0.06,
@@ -288,8 +288,8 @@ const lines: any[] = [
288
288
  "referenceLines": null,
289
289
  "version": 0,
290
290
  "shorthand": "布料",
291
- taxAmount:1
292
- }
291
+ "taxAmount": 1
292
+ }
293
293
  ]
294
294
 
295
295
  const moke = [
@@ -28,38 +28,74 @@ class MyInvoiceController extends InvoiceController {
28
28
  this.state.autoComplete.onItemNameBlur = async (value: any) => {
29
29
  console.log(value, 'onBuyerNameBlur - Blur');
30
30
 
31
- return [
32
- {
33
- "taxCategoryCode": "1030206030000000000",
34
- "productName": "醋及醋代用品",
35
- "shorthand": "调味品",
36
- "id": null,
37
- "specification": null,
38
- "createTime": null,
39
- "status": 1,
40
- "versionCode": "48.0",
41
- "version": "32.0",
42
- "startTime": "20190401",
43
- "endTime": null,
44
- "cargo": null,
45
- "desc": null,
46
- "taxRate": "13%",
47
- "keyword": "食醋、米醋、酒醋、啤酒醋、麦芽醋、酒精醋、水果醋、醋精",
48
- "summarizedItem": "N",
49
- "countCode": null,
50
- "customsItem": null,
51
- "updateTime": null,
52
- "hzx": null,
53
- "children": null,
54
- "vatspecialManagement": "",
55
- "pid": "1030206000000000000",
56
- "vatpolicyBasis": null,
57
- "vatspecialManagementCode": "",
58
- "gstpolicyBasisCode": null,
59
- "gstspecialManagement": null,
60
- "gstpolicyBasis": null
61
- }
62
- ]
31
+ return new Promise((resolve, reject)=> {
32
+ resolve([
33
+ {
34
+ "taxCategoryCode": "1030206030000000000",
35
+ "productName": "醋及醋代用品",
36
+ "shorthand": "调味品",
37
+ "id": null,
38
+ "specification": null,
39
+ "createTime": null,
40
+ "status": 1,
41
+ "versionCode": "48.0",
42
+ "version": "32.0",
43
+ "startTime": "20190401",
44
+ "endTime": null,
45
+ "cargo": null,
46
+ "desc": null,
47
+ "taxRate": "13%",
48
+ "keyword": "食醋、米醋、酒醋、啤酒醋、麦芽醋、酒精醋、水果醋、醋精",
49
+ "summarizedItem": "N",
50
+ "countCode": null,
51
+ "customsItem": null,
52
+ "updateTime": null,
53
+ "hzx": null,
54
+ "children": null,
55
+ "vatspecialManagement": "",
56
+ "pid": "1030206000000000000",
57
+ "vatpolicyBasis": null,
58
+ "vatspecialManagementCode": "",
59
+ "gstpolicyBasisCode": null,
60
+ "gstspecialManagement": null,
61
+ "gstpolicyBasis": null
62
+ }
63
+ ]);
64
+
65
+ });
66
+ //
67
+ // return [
68
+ // {
69
+ // "taxCategoryCode": "1030206030000000000",
70
+ // "productName": "醋及醋代用品",
71
+ // "shorthand": "调味品",
72
+ // "id": null,
73
+ // "specification": null,
74
+ // "createTime": null,
75
+ // "status": 1,
76
+ // "versionCode": "48.0",
77
+ // "version": "32.0",
78
+ // "startTime": "20190401",
79
+ // "endTime": null,
80
+ // "cargo": null,
81
+ // "desc": null,
82
+ // "taxRate": "13%",
83
+ // "keyword": "食醋、米醋、酒醋、啤酒醋、麦芽醋、酒精醋、水果醋、醋精",
84
+ // "summarizedItem": "N",
85
+ // "countCode": null,
86
+ // "customsItem": null,
87
+ // "updateTime": null,
88
+ // "hzx": null,
89
+ // "children": null,
90
+ // "vatspecialManagement": "",
91
+ // "pid": "1030206000000000000",
92
+ // "vatpolicyBasis": null,
93
+ // "vatspecialManagementCode": "",
94
+ // "gstpolicyBasisCode": null,
95
+ // "gstspecialManagement": null,
96
+ // "gstpolicyBasis": null
97
+ // }
98
+ // ]
63
99
  };
64
100
 
65
101
  this.state.autoComplete.onItemNameSearch = async (value: any) => {