kts-component-invoice-operate 3.2.121 → 3.2.123

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kts-component-invoice-operate",
3
- "version": "3.2.121",
3
+ "version": "3.2.123",
4
4
  "scripts": {
5
5
  "dev": "dumi dev",
6
6
  "start": "dumi dev",
@@ -11,6 +11,18 @@ export default () => {
11
11
  // 初始化控制器
12
12
  const controller = React.useMemo(() => new MyInvoiceController(), []);
13
13
 
14
+ React.useEffect(() => {
15
+ controller.run(async s => {
16
+ // 设置数量单价计算小数位
17
+ s.calculatingDigits = 13;
18
+
19
+ // 设置数量金额计算小数位
20
+ s.priceIntegerDigit = 14;
21
+
22
+ s.goodsListState.isRecalculateWhenSwitchTax = true;
23
+ })
24
+ }, [controller])
25
+
14
26
  return (
15
27
  <>
16
28
  <Button style={{ marginBottom: 10 }} onClick={async () => { console.log('===> 当前组件状态', await controller.validateFields()); }} >获取数据</Button>
@@ -18,6 +18,9 @@ export default class GoodsListState {
18
18
  /** 是否可以切换(含税/不含税)状态 */
19
19
  isSwitchTax?: boolean;
20
20
 
21
+ /** 切换含税时是否重新计算 */
22
+ isRecalculateWhenSwitchTax = false;
23
+
21
24
  /** 是否能添加折扣行 */
22
25
  isAddDiscount?: boolean;
23
26
 
@@ -110,4 +113,5 @@ export default class GoodsListState {
110
113
 
111
114
  /** 商品拖拽数据 */
112
115
  drag = new Drag();
116
+
113
117
  }
@@ -6,7 +6,7 @@ import { Input, NumberPicker } from '@formily/antd-components';
6
6
  import { format15 } from '../GoodsList/hook/useColumns/autoFillFn';
7
7
  import { LineAttributeType } from '../../../InvoiceController';
8
8
  import IGood from '../../../InvoiceController/InvoiceControllerState/GoodsListState/IGood';
9
- import { countTaxAmount } from '../../../tools/calculate';
9
+ import { countTaxAmount, countAmountExcludeTax, countPrice } from '../../../tools/calculate';
10
10
  import { bytesLnegth, cutStr } from '../../../tools/strringFn';
11
11
  import {
12
12
  SchemaForm,
@@ -428,16 +428,15 @@ const DrawerBody = (props: { defaultValue: IGood }) => {
428
428
  good.favouredPolicyMark = values.favouredPolicyMark;
429
429
  good.favouredPolicyName = values.favouredPolicyName;
430
430
 
431
- const taxRate = chain(bignumber(values.taxRate)).dotDivide(bignumber(100)).add(bignumber(1)).done();
432
-
433
- // 是否含税
434
- const lineAmountExcludeTax = chain(bignumber(good.lineAmountIncludeTax)).dotDivide(taxRate).done();
435
- const priceExcludeTax = good.priceIncludeTax ? chain(bignumber(good.priceIncludeTax)).dotDivide(taxRate).done() : undefined
436
-
437
- good.lineAmountExcludeTax = lineAmountExcludeTax.toNumber().toFixed(2);
438
- good.priceExcludeTax = (priceExcludeTax ? format15(priceExcludeTax.toNumber(), s.calculatingDigits) : undefined) || undefined;
439
-
431
+ // 无论是否含税,都保持价税合计不变
440
432
  good.taxAmount = countTaxAmount(good.lineAmountIncludeTax || 0, s.goodsListState.deduction, values.taxRate);
433
+ if (good.taxAmount || good.taxAmount === 0 ) {
434
+ good.lineAmountExcludeTax = countAmountExcludeTax(good.lineAmountIncludeTax || 0, good.taxAmount);
435
+ }
436
+ if (good.lineAmountExcludeTax && good.quantity) {
437
+ good.priceExcludeTax = countPrice(good.lineAmountExcludeTax, good.quantity, controller.state.calculatingDigits) as any;
438
+ }
439
+
441
440
  });
442
441
 
443
442
  s.goodsListState.goodsList = s.goodsListState.goodsList.slice();
@@ -10,6 +10,7 @@ import evaluate from '../../../../../../tools/evaluate';
10
10
  import { message } from 'kts-components-antd-x3'
11
11
  import { format2, format15, countTaxAmount, countAmountExcludeTax, countPrice } from '../../../../../../tools/calculate';
12
12
  import moment from 'moment';
13
+ import { equal } from 'mathjs';
13
14
 
14
15
  export { format2, format15 } from '../../../../../../tools/calculate';
15
16
 
@@ -531,3 +532,101 @@ export const onChangeItemCode = async (controller: InvoiceController, form: Wrap
531
532
  }
532
533
  })
533
534
  }
535
+
536
+ /** 修改了含税开关 重新计算 */
537
+ export const onChangeSwitchTax = async (controller: InvoiceController, isTaxIncluded: boolean) => {
538
+ if (!controller.state.goodsListState.isRecalculateWhenSwitchTax) {
539
+ controller.pipeline(async s => { s.goodsListState = { ...s.goodsListState, isTaxIncluded } })();
540
+ return
541
+ }
542
+ const calculatingDigits = controller.state.calculatingDigits;
543
+
544
+ await controller.saveEditGood();
545
+ await controller.wait();
546
+
547
+ await controller.run(async s => {
548
+ if (s.goodsListState.editGood) {
549
+ message.error({
550
+ content: '你正在编辑一个货物',
551
+ key: '你正在编辑一个货物',
552
+ });
553
+
554
+ return ;
555
+ }
556
+
557
+ s.goodsListState.isTaxIncluded = isTaxIncluded;
558
+
559
+ try {
560
+ let needRefresh = false;
561
+
562
+ if (s.goodsListState?.goodsList && s.goodsListState.goodsList.length) {
563
+ const newGoodsList = s.goodsListState.goodsList.map(good => {
564
+ const {
565
+ quantity: sourceQuantity,
566
+ priceExcludeTax: sourcePriceExcludeTax,
567
+ priceIncludeTax: sourcePriceIncludeTax,
568
+ lineAmountExcludeTax: sourceLineAmountExcludeTax,
569
+ lineAmountIncludeTax: sourceLineAmountIncludeTax,
570
+ taxRate } = good;
571
+ if (isTaxIncluded) {
572
+ if (!sourceQuantity && sourceQuantity !== 0) return good;
573
+ if (!sourcePriceIncludeTax && sourcePriceIncludeTax !== 0) return good;
574
+ if (!taxRate && taxRate !== 0) return good;
575
+ if (sourcePriceExcludeTax && sourceLineAmountExcludeTax && equal(countPrice(sourceLineAmountExcludeTax, sourceQuantity) || 0, sourcePriceExcludeTax)) {
576
+ return good
577
+ } else {
578
+ needRefresh = true;
579
+ }
580
+ const quantity: any = format15(sourceQuantity, calculatingDigits);
581
+ const priceIncludeTax: any = format15(sourcePriceIncludeTax, calculatingDigits);
582
+
583
+ const lineAmountIncludeTax: any = format2(evaluate(`${priceIncludeTax} * ${quantity}`));
584
+ const taxAmount: any = countTaxAmount(lineAmountIncludeTax, controller.state.goodsListState.deduction, taxRate as any);
585
+ const lineAmountExcludeTax: any = countAmountExcludeTax(lineAmountIncludeTax, taxAmount);
586
+ const priceExcludeTax: any = countPrice(lineAmountExcludeTax, quantity, controller.state.calculatingDigits);
587
+
588
+ return {
589
+ ...good,
590
+ lineAmountExcludeTax,
591
+ lineAmountIncludeTax,
592
+ taxAmount,
593
+ priceExcludeTax
594
+ }
595
+
596
+ } else {
597
+ if (!sourceQuantity && sourceQuantity !== 0) return good;
598
+ if (!sourcePriceExcludeTax && sourcePriceExcludeTax !== 0) return good;
599
+ if (!taxRate && taxRate !== 0) return good;
600
+ if (sourcePriceIncludeTax && sourceLineAmountIncludeTax && equal(countPrice(sourceLineAmountIncludeTax, sourceQuantity) || 0, sourcePriceIncludeTax)) {
601
+ return good
602
+ } else {
603
+ needRefresh = true;
604
+ }
605
+ const quantity: any = format15(sourceQuantity, calculatingDigits);
606
+ const priceExcludeTax: any = format15(sourcePriceExcludeTax, calculatingDigits);
607
+
608
+ const lineAmountExcludeTax: any = format2(evaluate(`${priceExcludeTax} * ${quantity}`));
609
+ const lineAmountIncludeTax: any = format2(evaluate(`${lineAmountExcludeTax} * (1+(${taxRate}/100))`));
610
+ const priceIncludeTax: any = format15(evaluate(`${lineAmountIncludeTax} / ${quantity}`), calculatingDigits);
611
+ const taxAmount: any = evaluate(`${lineAmountIncludeTax} - ${lineAmountExcludeTax}`);
612
+
613
+ return {
614
+ ...good,
615
+ lineAmountExcludeTax,
616
+ lineAmountIncludeTax,
617
+ taxAmount,
618
+ priceIncludeTax
619
+ }
620
+ }
621
+
622
+ })
623
+
624
+ if (needRefresh) {
625
+ s.goodsListState.goodsList = newGoodsList;
626
+ }
627
+ }
628
+ } catch(e) {
629
+ console.error('切换税率重新计算出错', e, s.goodsListState)
630
+ }
631
+ })
632
+ }
@@ -2,6 +2,7 @@
2
2
  import React from 'react';
3
3
  import { Switch } from 'kts-xui';
4
4
  import Invoice from '../../../../..';
5
+ import { onChangeSwitchTax } from '../../hook/useColumns/autoFillFn';
5
6
 
6
7
  export default () => {
7
8
 
@@ -14,7 +15,7 @@ export default () => {
14
15
  const isSwitchTax = controller.useMemo(e => e.goodsListState.isSwitchTax, []);
15
16
 
16
17
  const onChange = React.useCallback(e => {
17
- controller.pipeline(async s => { s.goodsListState = { ...s.goodsListState, isTaxIncluded: e } })();
18
+ onChangeSwitchTax(controller, e)
18
19
  }, [])
19
20
 
20
21
  return (
@@ -10,6 +10,7 @@ import evaluate from '../../../../../../tools/evaluate';
10
10
  import { message } from 'kts-components-antd-x3'
11
11
  import { format2, format15, countTaxAmount, countAmountExcludeTax, countPrice } from '../../../../../../tools/calculate';
12
12
  import moment from 'moment';
13
+ import { equal } from 'mathjs';
13
14
 
14
15
  export { format2, format15 } from '../../../../../../tools/calculate';
15
16
 
@@ -94,11 +95,13 @@ export const onChangeQuantity = lazyFn(
94
95
  } else {
95
96
  // 不含税
96
97
  if (!err.priceExcludeTax && values.priceExcludeTax) {
98
+ // 可以找到 单价(不含税)
97
99
  const priceExcludeTax = format15(values.priceExcludeTax, calculatingDigits);
98
100
  const lineAmountExcludeTax = format2(evaluate(`${quantity} * ${priceExcludeTax}`));
99
101
  form.setFieldsValue({ lineAmountExcludeTax });
100
102
  await controller.setEditGood({ lineAmountExcludeTax, quantity });
101
103
  } else if (!err.lineAmountExcludeTax && values.lineAmountExcludeTax) {
104
+ // 可以找到 金额(不含税)
102
105
  const lineAmountExcludeTax = format2(values.lineAmountExcludeTax);
103
106
  const priceExcludeTax = format15(evaluate(`${lineAmountExcludeTax} / ${quantity}`), calculatingDigits);
104
107
  form.setFieldsValue({ priceExcludeTax });
@@ -358,6 +361,7 @@ export function dutyFree(controller: InvoiceController, taxRate: number, form: W
358
361
  export const updateUnitPriceExcludingTax = async (controller: InvoiceController, form: WrappedFormUtils, record: IGood) => {
359
362
  return new Promise((resolve) => {
360
363
  form.validateFields(async (err, values) => {
364
+ console.log('含税 => 更新(不含税')
361
365
 
362
366
  err = err || {};
363
367
 
@@ -403,6 +407,8 @@ export const updateUnitPriceExcludingTax = async (controller: InvoiceController,
403
407
  export const updateUnitPriceTax = async (controller: InvoiceController, form: WrappedFormUtils, record: IGood) => {
404
408
  return new Promise((resolve) => {
405
409
  form.validateFields(async (err, values) => {
410
+ console.log('不含税 => 更新(含税)')
411
+
406
412
  err = err || {};
407
413
 
408
414
  if (
@@ -517,4 +523,102 @@ export const onChangeItemName = async (controller: InvoiceController, form: Wrap
517
523
  record.itemNameSelf && await controller.setEditGood({ itemNameSelf: record.itemNameSelf });
518
524
  }
519
525
  })
520
- }
526
+ }
527
+
528
+ /** 修改了含税开关 重新计算 */
529
+ export const onChangeSwitchTax = async (controller: InvoiceController, isTaxIncluded: boolean) => {
530
+ if (!controller.state.goodsListState.isRecalculateWhenSwitchTax) {
531
+ controller.pipeline(async s => { s.goodsListState = { ...s.goodsListState, isTaxIncluded } })();
532
+ return
533
+ }
534
+ const calculatingDigits = controller.state.calculatingDigits;
535
+
536
+ await controller.saveEditGood();
537
+ await controller.wait();
538
+
539
+ await controller.run(async s => {
540
+ if (s.goodsListState.editGood) {
541
+ message.error({
542
+ content: '你正在编辑一个货物',
543
+ key: '你正在编辑一个货物',
544
+ });
545
+
546
+ return ;
547
+ }
548
+
549
+ s.goodsListState.isTaxIncluded = isTaxIncluded;
550
+
551
+ try {
552
+ let needRefresh = false;
553
+
554
+ if (s.goodsListState?.goodsList && s.goodsListState.goodsList.length) {
555
+ const newGoodsList = s.goodsListState.goodsList.map(good => {
556
+ const {
557
+ quantity: sourceQuantity,
558
+ priceExcludeTax: sourcePriceExcludeTax,
559
+ priceIncludeTax: sourcePriceIncludeTax,
560
+ lineAmountExcludeTax: sourceLineAmountExcludeTax,
561
+ lineAmountIncludeTax: sourceLineAmountIncludeTax,
562
+ taxRate } = good;
563
+ if (isTaxIncluded) {
564
+ if (!sourceQuantity && sourceQuantity !== 0) return good;
565
+ if (!sourcePriceIncludeTax && sourcePriceIncludeTax !== 0) return good;
566
+ if (!taxRate && taxRate !== 0) return good;
567
+ if (sourcePriceExcludeTax && sourceLineAmountExcludeTax && equal(countPrice(sourceLineAmountExcludeTax, sourceQuantity) || 0, sourcePriceExcludeTax)) {
568
+ return good
569
+ } else {
570
+ needRefresh = true;
571
+ }
572
+ const quantity: any = format15(sourceQuantity, calculatingDigits);
573
+ const priceIncludeTax: any = format15(sourcePriceIncludeTax, calculatingDigits);
574
+
575
+ const lineAmountIncludeTax: any = format2(evaluate(`${priceIncludeTax} * ${quantity}`));
576
+ const taxAmount: any = countTaxAmount(lineAmountIncludeTax, controller.state.goodsListState.deduction, taxRate as any);
577
+ const lineAmountExcludeTax: any = countAmountExcludeTax(lineAmountIncludeTax, taxAmount);
578
+ const priceExcludeTax: any = countPrice(lineAmountExcludeTax, quantity, controller.state.calculatingDigits);
579
+
580
+ return {
581
+ ...good,
582
+ lineAmountExcludeTax,
583
+ lineAmountIncludeTax,
584
+ taxAmount,
585
+ priceExcludeTax
586
+ }
587
+
588
+ } else {
589
+ if (!sourceQuantity && sourceQuantity !== 0) return good;
590
+ if (!sourcePriceExcludeTax && sourcePriceExcludeTax !== 0) return good;
591
+ if (!taxRate && taxRate !== 0) return good;
592
+ if (sourcePriceIncludeTax && sourceLineAmountIncludeTax && equal(countPrice(sourceLineAmountIncludeTax, sourceQuantity) || 0, sourcePriceIncludeTax)) {
593
+ return good
594
+ } else {
595
+ needRefresh = true;
596
+ }
597
+ const quantity: any = format15(sourceQuantity, calculatingDigits);
598
+ const priceExcludeTax: any = format15(sourcePriceExcludeTax, calculatingDigits);
599
+
600
+ const lineAmountExcludeTax: any = format2(evaluate(`${priceExcludeTax} * ${quantity}`));
601
+ const lineAmountIncludeTax: any = format2(evaluate(`${lineAmountExcludeTax} * (1+(${taxRate}/100))`));
602
+ const priceIncludeTax: any = format15(evaluate(`${lineAmountIncludeTax} / ${quantity}`), calculatingDigits);
603
+ const taxAmount: any = evaluate(`${lineAmountIncludeTax} - ${lineAmountExcludeTax}`);
604
+
605
+ return {
606
+ ...good,
607
+ lineAmountExcludeTax,
608
+ lineAmountIncludeTax,
609
+ taxAmount,
610
+ priceIncludeTax
611
+ }
612
+ }
613
+
614
+ })
615
+
616
+ if (needRefresh) {
617
+ s.goodsListState.goodsList = newGoodsList;
618
+ }
619
+ }
620
+ } catch(e) {
621
+ console.error('切换税率重新计算出错', e, s.goodsListState)
622
+ }
623
+ })
624
+ }
@@ -64,8 +64,6 @@ export default function ItemNameInput(props: {
64
64
  }
65
65
  }, [autoComplete.onItemNameSearch])
66
66
 
67
- console.log('===> options', options);
68
-
69
67
  return (
70
68
  <div className='kts-invoice-operate-goods-list-itemName-input'>
71
69
  {props.shorthand && <span style={{ alignSelf: 'center', fontSize: 12 }} >*{props.shorthand}*</span>}
@@ -2,6 +2,7 @@
2
2
  import React from 'react';
3
3
  import { Switch } from 'kts-xui';
4
4
  import Invoice from '../../../../..';
5
+ import { onChangeSwitchTax } from '../../hook/useColumns/autoFillFn';
5
6
 
6
7
  export default () => {
7
8
 
@@ -13,8 +14,8 @@ export default () => {
13
14
  /** 是否可以切换(含税/不含税)状态 */
14
15
  const isSwitchTax = controller.useMemo(e => e.goodsListState.isSwitchTax, []);
15
16
 
16
- const onChange = React.useCallback(e => {
17
- controller.pipeline(async s => { s.goodsListState = { ...s.goodsListState, isTaxIncluded: e } })();
17
+ const onChange = React.useCallback(async e => {
18
+ onChangeSwitchTax(controller, e);
18
19
  }, [])
19
20
 
20
21
  return (
@@ -56,7 +56,7 @@ export default decorator<IBuyerProps, IBuyerProps & FormComponentProps>(Form.cre
56
56
  })(
57
57
  isEnables('remarks')
58
58
  ? <Input.TextArea placeholder='请输入' style={{ height: '100%' }} />
59
- : <MyDiv style={{whiteSpace: 'pre'}} />
59
+ : <MyDiv style={{whiteSpace: 'pre-wrap'}} />
60
60
  )}
61
61
  </div>
62
62
  </div>