kts-component-invoice-operate 1.2.13 → 1.2.16

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": "1.2.13",
3
+ "version": "1.2.16",
4
4
  "scripts": {
5
5
  "start": "dumi dev",
6
6
  "docs:build": "dumi build",
@@ -64,6 +64,9 @@ export default class EndowCode {
64
64
  { label: '不征增值税(不征税))', value: 2 },
65
65
  { label: '普通零税率(0%)', value: 3 },
66
66
  ];
67
+
68
+ /** 小规模纳税人 自动赋码缓存 */
69
+ cache: { [key: string]: any } = {};
67
70
  }
68
71
 
69
72
  /** 草稿发票 税率 是否可以编辑 校验函数 */
@@ -5,7 +5,16 @@ export default class InvoiceControllerState {
5
5
 
6
6
  /** 组件模式 */
7
7
  model: 'default' | 'prefab' = 'default'
8
-
8
+
9
+ /**
10
+ * 企业类型
11
+ * 01 一般纳税人
12
+ * 05 转登记纳税人
13
+ * 04 代开企业
14
+ * 08 小规模纳税人
15
+ * */
16
+ en: '01' | '05' | '04' | '08' = '01';
17
+
9
18
  /** 购买方 */
10
19
  buyerState = new BuyerState();
11
20
 
@@ -34,6 +34,10 @@ export default () => {
34
34
  })();
35
35
  }, [controller]);
36
36
 
37
+ const onClick6 = React.useCallback(async () => {
38
+ console.log('===> 当前组件状态', await controller.validateFields());
39
+ }, []);
40
+
37
41
  return (
38
42
  <div>
39
43
  <Button onClick={onClick1} style={{ marginBottom: 20 }}>
@@ -45,6 +49,7 @@ export default () => {
45
49
  <Button onClick={onClick2} style={{ marginBottom: 20 }}>
46
50
  模拟生成数据
47
51
  </Button>
52
+ <Button onClick={onClick6} style={{ marginBottom: 10 }}>获取数据</Button>
48
53
  <Switch checkedChildren="预制" unCheckedChildren="默认" onChange={e => { e ? setController(controller2) : setController(controller1) }} ></Switch>
49
54
  <Button onClick={controller.pipeline(async s => { s.goodsListState.endowCode.getReadOnlyTaxRate = s.goodsListState.endowCode.readOnlyTaxRateMap.DRAFT })} >税率(草稿)</Button>
50
55
  <Button onClick={controller.pipeline(async s => { s.goodsListState.endowCode.getReadOnlyTaxRate = () => true })} >税率(预制)</Button>
@@ -242,7 +242,7 @@ const DrawerBody = (props: { defaultValue: IGood }) => {
242
242
  setList([])
243
243
  }
244
244
  }, [visible])
245
-
245
+
246
246
  return (
247
247
  <>
248
248
  <InputAntd readOnly value={props.value} addonAfter={<Button size="small" type="link" onClick={() => { setVisible(true) }} >点击选择</Button>} />
@@ -290,7 +290,7 @@ const DrawerBody = (props: { defaultValue: IGood }) => {
290
290
  if (!good) return;
291
291
 
292
292
  // const name = getItemName(good.itemName, values.shorthand);
293
-
293
+
294
294
  good.itemName = getItemName(good.itemName, values.shorthand); // `*${values.shorthand}*${name}`;
295
295
  good.taxClassificationCode = values.taxClassificationCode;
296
296
  good.taxRate = values.taxRate;
@@ -9,6 +9,7 @@ import InvoiceController, { IGood, LineAttributeType } from '../../../../../Invo
9
9
  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
+ import moment from 'moment';
12
13
 
13
14
  export { format2, format15 } from '../../../../../tools/calculate';
14
15
 
@@ -252,14 +253,15 @@ export const onChangeLineAmountExcludeTax = lazyFn(
252
253
  /** 税率 */
253
254
  export const onChangeTaxRate = lazyFn(
254
255
  (controller: InvoiceController, form: WrappedFormUtils, record: IGood) => {
255
- // 是否含税
256
+
256
257
  form.validateFields(async (err, values) => {
257
258
  err = err || {};
258
259
  if (promptErr(err.taxRate) || (!values.taxRate && values.taxRate !== 0)) return;
259
260
 
260
- const taxRate = parseFloat(values.taxRate);
261
+ let taxRate = parseFloat(values.taxRate);
262
+ taxRate = dutyFree(controller, taxRate, form, record); // 小规模纳税人
261
263
  await controller.setEditGood({ taxRate });
262
-
264
+ // 是否含税
263
265
  if (controller.state.goodsListState.isTaxIncluded) {
264
266
  updateUnitPriceExcludingTax(controller, form, record);
265
267
  } else {
@@ -270,12 +272,44 @@ export const onChangeTaxRate = lazyFn(
270
272
  1000,
271
273
  );
272
274
 
275
+ /** 小规模纳税人 1% 和 3% 自动赋码免税 */
276
+ function dutyFree(controller: InvoiceController, taxRate: number, form: WrappedFormUtils<any>, record: IGood) {
277
+
278
+ const cache = controller.state.goodsListState.endowCode.cache;
279
+
280
+ // 4月1日至12月31日
281
+ if (moment().valueOf() > moment('2022-12-31 23:59').valueOf()) return taxRate;
282
+ if (controller.state.en !== '08') return taxRate;
283
+
284
+ // 选择的 1或者3
285
+ if (taxRate === 1 || taxRate === 3) {
286
+ // 是否处理过
287
+ if (cache[record.$index]) {
288
+ return taxRate;
289
+ } else {
290
+ cache[record.$index] = { favouredPolicyName: record.favouredPolicyName, favouredPolicyMark: record.favouredPolicyMark, }
291
+ record.favouredPolicyName = '免税';
292
+ record.favouredPolicyMark = 1;
293
+ record.taxRate = 0;
294
+ form.setFieldsValue({ taxRate: 0 });
295
+ return 0;
296
+ }
297
+ } else {
298
+ if (cache[record.$index] && cache[record.$index] !== true) {
299
+ record.favouredPolicyName = cache[record.$index].favouredPolicyName;
300
+ record.favouredPolicyName = cache[record.$index].favouredPolicyName;
301
+ cache[record.$index] = true;
302
+ }
303
+ return taxRate;
304
+ }
305
+ }
306
+
273
307
  /** 含税 => 更新(不含税) */
274
308
  export const updateUnitPriceExcludingTax = (controller: InvoiceController, form: WrappedFormUtils, record: IGood) => {
275
309
  form.validateFields(async (err, values) => {
276
310
 
277
311
  err = err || {};
278
-
312
+
279
313
  /** 税额 */
280
314
  let taxAmount;
281
315
 
@@ -62,6 +62,11 @@ const Main = decorator<IGoodsListProps, FormComponentProps & IGoodsListProps>(Fo
62
62
  useDeduction(controller, props.deduction);
63
63
  useWindowClick(controller);
64
64
 
65
+ /** 清空自动赋码缓存 */
66
+ React.useEffect(() => {
67
+ controller.run(async s => { s.goodsListState.endowCode.cache = {} });
68
+ }, [controller])
69
+
65
70
  /** 注册 from 对象 */
66
71
  React.useEffect(() => {
67
72
  controller.pipeline<WrappedFormUtils>(async (s, form) => {
@@ -11,7 +11,7 @@
11
11
  }
12
12
 
13
13
  .invoice-header-title {
14
- top: 20;
14
+ top: 20px;
15
15
  left: 0;
16
16
  position: absolute;
17
17
  color: #e28b89;
@@ -20,7 +20,7 @@
20
20
  text-align: center;
21
21
  width: 100%;
22
22
  pointer-events: none;
23
- z-index: 10;
23
+ z-index: 1;
24
24
  }
25
25
 
26
26
  .invoice-header-no {