kts-component-invoice-operate 3.2.265 → 3.2.267
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/dist/DifferenceInputModal/index.d.ts +8 -2
- package/dist/Invoice/InvoiceController/InvoiceControllerState/DifferenceInputState/index.d.ts +2 -0
- package/dist/Invoice/InvoiceController/InvoiceControllerState/GoodsListState/index.d.ts +2 -0
- package/dist/Invoice/InvoiceController/hooks/index.d.ts +3 -0
- package/dist/Invoice/tools/calculate/index.d.ts +1 -1
- package/dist/index.esm.js +695 -288
- package/dist/index.js +695 -288
- package/package.json +1 -1
- package/src/DifferenceInputModal/index.tsx +87 -17
- package/src/Invoice/Invoice-digtal/index.md +9 -9
- package/src/Invoice/InvoiceController/InvoiceControllerForm/index.ts +2 -1
- package/src/Invoice/InvoiceController/InvoiceControllerState/DifferenceInputState/index.ts +3 -0
- package/src/Invoice/InvoiceController/InvoiceControllerState/GoodsListState/index.ts +3 -0
- package/src/Invoice/InvoiceController/fns/saveEditGood.ts +1 -0
- package/src/Invoice/InvoiceController/hooks/index.ts +76 -0
- package/src/Invoice/index.tsx +3 -0
- package/src/Invoice/tools/calculate/index.ts +2 -3
- package/src/Invoice/ui/default/EndowCodeDrawer/index.tsx +4 -2
- package/src/Invoice/ui/default/GoodsList/hook/useColumns/autoFillFn/index.ts +2 -1
- package/src/Invoice/ui/default/GoodsList/hook/useColumns/index.tsx +19 -6
- package/src/Invoice/ui/default/GoodsList/hook/useColumns/ui/ItemNameInput/index.tsx +5 -4
- package/src/Invoice/ui/default/GoodsList/hook/useWindowClick/index.tsx +4 -1
- package/src/Invoice/ui/default/GoodsList/index.tsx +1 -1
- package/src/Invoice/ui/default/GoodsList/ui/AddRowButton/index.tsx +1 -1
- package/src/Invoice/ui/digtal/DifferenceInput/index.tsx +33 -3
- package/src/Invoice/ui/digtal/GoodsList/hook/useColumns/autoFillFn/index.ts +2 -2
- package/src/Invoice/ui/digtal/GoodsList/hook/useColumns/index.tsx +34 -21
- package/src/Invoice/ui/digtal/GoodsList/hook/useWindowClick/index.tsx +4 -1
- package/src/Invoice/ui/digtal/GoodsList/ui/AddRowButton/index.tsx +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { Modal, Form, Input, InputNumber, Select, Radio, Table, DatePicker, Space, Row, Col, Card } from 'kts-components-antd-x4';
|
|
3
3
|
import type { ColumnsType } from 'kts-components-antd-x4/es/table';
|
|
4
|
+
import type { FormInstance } from 'kts-components-antd-x4/es/form';
|
|
4
5
|
import { Button } from 'kts-xui';
|
|
5
6
|
import { v4 as uuidv4 } from 'uuid';
|
|
6
7
|
import moment from 'moment';
|
|
@@ -48,8 +49,8 @@ export interface IData {
|
|
|
48
49
|
/** 申报项目代码 */
|
|
49
50
|
projectCode?: string;
|
|
50
51
|
|
|
51
|
-
/**
|
|
52
|
-
|
|
52
|
+
/** 含税销售额 */
|
|
53
|
+
amountIncludeTax?: number;
|
|
53
54
|
|
|
54
55
|
/** 本次扣除金额总计 */
|
|
55
56
|
deductTotal: number;
|
|
@@ -129,6 +130,38 @@ enum VoucherType {
|
|
|
129
130
|
OTHER_DEDUCTION_VOUCHER = '09',
|
|
130
131
|
}
|
|
131
132
|
|
|
133
|
+
/** 最多只允许输入两位小数的校验器 */
|
|
134
|
+
export const maxTwoDecimalsValidator = (_rule: any, value: any) => {
|
|
135
|
+
if (value === undefined || value === null || value === '') {
|
|
136
|
+
return Promise.resolve();
|
|
137
|
+
}
|
|
138
|
+
const decimalPart = String(value).split('.')[1];
|
|
139
|
+
if (decimalPart && decimalPart.length > 2) {
|
|
140
|
+
return Promise.reject(new Error('最多只能输入2位小数'));
|
|
141
|
+
}
|
|
142
|
+
return Promise.resolve();
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
/** 凭证明细表单实例(用于跨字段校验:本次扣除金额 <= 凭证合计金额) */
|
|
146
|
+
let formInstance: FormInstance | undefined;
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* 本次扣除金额不能大于凭证合计金额的校验器
|
|
150
|
+
*/
|
|
151
|
+
export const deductAmtNotExceedVoucherTotalValidator = (_rule: any, value: any) => {
|
|
152
|
+
if (value === undefined || value === null || value === '') {
|
|
153
|
+
return Promise.resolve();
|
|
154
|
+
}
|
|
155
|
+
const voucherTotalAmt = formInstance?.getFieldValue('voucherTotalAmt');
|
|
156
|
+
if (voucherTotalAmt === undefined || voucherTotalAmt === null || voucherTotalAmt === '') {
|
|
157
|
+
return Promise.resolve();
|
|
158
|
+
}
|
|
159
|
+
if (Number(value) > Number(voucherTotalAmt)) {
|
|
160
|
+
return Promise.reject(new Error('本次扣除金额不能大于凭证合计金额'));
|
|
161
|
+
}
|
|
162
|
+
return Promise.resolve();
|
|
163
|
+
};
|
|
164
|
+
|
|
132
165
|
/** 凭证类型候选项 */
|
|
133
166
|
const voucherTypeOptions = [
|
|
134
167
|
{ value: VoucherType.SPECIAL_INVOICE, label: '专用发票' },
|
|
@@ -237,9 +270,28 @@ const projectOptions = [
|
|
|
237
270
|
export function DifferenceInputModal(props: IDifferenceInputModalProps) {
|
|
238
271
|
const { open = true, onCancel, onOk } = props;
|
|
239
272
|
const [form] = Form.useForm();
|
|
273
|
+
const [topForm] = Form.useForm();
|
|
274
|
+
|
|
275
|
+
/** 记录表单实例,供跨字段校验使用 */
|
|
276
|
+
React.useEffect(() => {
|
|
277
|
+
formInstance = form;
|
|
278
|
+
return () => {
|
|
279
|
+
formInstance = undefined;
|
|
280
|
+
};
|
|
281
|
+
}, [form]);
|
|
282
|
+
|
|
240
283
|
const [dataSource, setDataSource] = React.useState<IDifferenceRow[]>([]);
|
|
241
284
|
const voucherType: VoucherType = Form.useWatch('voucherType', form) || form.getFieldValue('voucherType');
|
|
242
|
-
const
|
|
285
|
+
const projectCode = Form.useWatch('projectCode', topForm) || topForm.getFieldValue('projectCode');
|
|
286
|
+
|
|
287
|
+
/** 凭证合计金额(用于联动校验本次扣除金额) */
|
|
288
|
+
const voucherTotalAmt = Form.useWatch('voucherTotalAmt', form);
|
|
289
|
+
|
|
290
|
+
/** 凭证合计金额变化时,重新校验本次扣除金额 */
|
|
291
|
+
React.useEffect(() => {
|
|
292
|
+
if (!form.isFieldTouched('currentDeductAmt')) return;
|
|
293
|
+
form.validateFields(['currentDeductAmt']).catch(() => { /* 错误信息由表单展示 */ });
|
|
294
|
+
}, [form, voucherTotalAmt]);
|
|
243
295
|
|
|
244
296
|
/** 扣除额 (明细汇总) */
|
|
245
297
|
const deductTotal = React.useMemo(() => {
|
|
@@ -251,19 +303,28 @@ export function DifferenceInputModal(props: IDifferenceInputModalProps) {
|
|
|
251
303
|
return dataSource.reduce((acc, curr) => acc + (curr.voucherTotalAmt || 0), 0);
|
|
252
304
|
}, [dataSource]);
|
|
253
305
|
|
|
254
|
-
const total = props.total || { voucherTotal
|
|
306
|
+
const total = props.total || { voucherTotal, deductTotal };
|
|
255
307
|
|
|
256
308
|
const onFinish = React.useCallback((values: any) => {
|
|
257
309
|
setDataSource([...dataSource, { ...values, $index: uuidv4(), dataSrc: DataSrcEnum.MANUAL }]);
|
|
258
310
|
form.resetFields();
|
|
259
311
|
}, [dataSource, form]);
|
|
260
312
|
|
|
313
|
+
const onOkClick = React.useCallback(async () => {
|
|
314
|
+
const values = await topForm.validateFields();
|
|
315
|
+
onOk?.({ ...values, deductTotal, rows: dataSource });
|
|
316
|
+
}, [dataSource, onOk]);
|
|
317
|
+
|
|
261
318
|
React.useEffect(() => {
|
|
262
319
|
console.log('DifferenceInputModal props.value ===>', props.value)
|
|
263
320
|
if (open) {
|
|
264
321
|
form.resetFields();
|
|
322
|
+
topForm.resetFields()
|
|
323
|
+
topForm.setFieldsValue({
|
|
324
|
+
amountIncludeTax: props.value?.amountIncludeTax,
|
|
325
|
+
projectCode: props.value?.projectCode,
|
|
326
|
+
});
|
|
265
327
|
setDataSource(props.value?.rows || []);
|
|
266
|
-
setProjectCode(props.value?.projectCode || '');
|
|
267
328
|
}
|
|
268
329
|
}, [open, props.value]);
|
|
269
330
|
|
|
@@ -277,7 +338,7 @@ export function DifferenceInputModal(props: IDifferenceInputModalProps) {
|
|
|
277
338
|
footer={
|
|
278
339
|
<Space align="end" className="kts-difference-modal-footer">
|
|
279
340
|
<Button onClick={onCancel}>取消</Button>
|
|
280
|
-
<Button type="primary" onClick={
|
|
341
|
+
<Button type="primary" onClick={onOkClick}>
|
|
281
342
|
确定
|
|
282
343
|
</Button>
|
|
283
344
|
</Space>
|
|
@@ -286,11 +347,16 @@ export function DifferenceInputModal(props: IDifferenceInputModalProps) {
|
|
|
286
347
|
<div className="kts-difference-modal">
|
|
287
348
|
{/* 顶部:含税销售额、扣除额、申报项目名称 */}
|
|
288
349
|
<div className="kts-difference-modal-top">
|
|
289
|
-
<Form layout='horizontal' className="kts-difference-modal-top-form" labelCol={{ flex: '100px' }}>
|
|
350
|
+
<Form form={topForm} layout='horizontal' className="kts-difference-modal-top-form" labelCol={{ flex: '100px' }}>
|
|
290
351
|
<Row>
|
|
291
352
|
<Col span={12} >
|
|
292
|
-
<Form.Item label="含税销售额" className="kts-difference-modal-item"
|
|
293
|
-
|
|
353
|
+
<Form.Item name='amountIncludeTax' label="含税销售额" className="kts-difference-modal-item"
|
|
354
|
+
rules={[
|
|
355
|
+
{ required: true, message: '请输入含税销售额' },
|
|
356
|
+
{ validator: maxTwoDecimalsValidator }
|
|
357
|
+
]}
|
|
358
|
+
>
|
|
359
|
+
<InputNumber style={{ width: '100%' }} placeholder="请输入含税销售额" />
|
|
294
360
|
</Form.Item>
|
|
295
361
|
</Col>
|
|
296
362
|
|
|
@@ -301,11 +367,8 @@ export function DifferenceInputModal(props: IDifferenceInputModalProps) {
|
|
|
301
367
|
</Col>
|
|
302
368
|
|
|
303
369
|
<Col span={24} >
|
|
304
|
-
<Form.Item label="申报项目名称" className="kts-difference-modal-item">
|
|
305
|
-
<Select options={projectOptions} placeholder="请选择申报项目名称"
|
|
306
|
-
onChange={(value) => { setProjectCode(value) }}
|
|
307
|
-
value={projectCode}
|
|
308
|
-
/>
|
|
370
|
+
<Form.Item name='projectCode' label="申报项目名称" className="kts-difference-modal-item" rules={[{ required: true, message: '请选择申报项目名称' }]}>
|
|
371
|
+
<Select options={projectOptions} placeholder="请选择申报项目名称" />
|
|
309
372
|
</Form.Item>
|
|
310
373
|
</Col>
|
|
311
374
|
|
|
@@ -376,7 +439,10 @@ export function DifferenceInputModal(props: IDifferenceInputModalProps) {
|
|
|
376
439
|
|
|
377
440
|
<Col span={24 / 3} >
|
|
378
441
|
<Form.Item name='voucherTotalAmt' label="凭证合计金额" className="kts-difference-modal-cell"
|
|
379
|
-
rules={
|
|
442
|
+
rules={[
|
|
443
|
+
...(voucherTypeRules[voucherType]?.['voucherTotalAmt'] || []),
|
|
444
|
+
{ validator: maxTwoDecimalsValidator },
|
|
445
|
+
]}
|
|
380
446
|
>
|
|
381
447
|
<InputNumber style={{ width: '100%' }} placeholder="请输入凭证合计金额" />
|
|
382
448
|
</Form.Item>
|
|
@@ -384,7 +450,11 @@ export function DifferenceInputModal(props: IDifferenceInputModalProps) {
|
|
|
384
450
|
|
|
385
451
|
<Col span={24 / 3} >
|
|
386
452
|
<Form.Item name='currentDeductAmt' label="本次扣除金额" className="kts-difference-modal-cell"
|
|
387
|
-
rules={
|
|
453
|
+
rules={[
|
|
454
|
+
...(voucherTypeRules[voucherType]?.['currentDeductAmt'] || []),
|
|
455
|
+
{ validator: maxTwoDecimalsValidator },
|
|
456
|
+
{ validator: deductAmtNotExceedVoucherTotalValidator },
|
|
457
|
+
]}
|
|
388
458
|
>
|
|
389
459
|
<InputNumber style={{ width: '100%' }} placeholder="请输入本次扣除金额" />
|
|
390
460
|
</Form.Item>
|
|
@@ -400,7 +470,7 @@ export function DifferenceInputModal(props: IDifferenceInputModalProps) {
|
|
|
400
470
|
|
|
401
471
|
<Col span={24} >
|
|
402
472
|
<div style={{ display: 'flex', justifyContent: 'center', gap: 10 }} >
|
|
403
|
-
<Button type='primary' size='small' onClick={() => form.resetFields()}
|
|
473
|
+
<Button type='primary' size='small' onClick={() => form.resetFields()}>清除</Button>
|
|
404
474
|
<Button type='primary' size='small' onClick={() => form.submit()}>添加并继续</Button>
|
|
405
475
|
</div>
|
|
406
476
|
</Col>
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
# 数电
|
|
2
2
|
|
|
3
3
|
## 简单用法
|
|
4
|
-
<code src="./_test/pay/index.tsx"></code>
|
|
4
|
+
<!-- <code src="./_test/pay/index.tsx"></code> -->
|
|
5
5
|
<!-- <code src="./_test/easiest/index.tsx"></code> -->
|
|
6
6
|
|
|
7
|
-
## 旅客运输发票
|
|
8
|
-
<code src="./_test/passenger/index.tsx"></code>
|
|
7
|
+
<!-- ## 旅客运输发票
|
|
8
|
+
<code src="./_test/passenger/index.tsx"></code> -->
|
|
9
9
|
|
|
10
10
|
<!-- ## 不动产经营租赁服务
|
|
11
11
|
<code src="./_test/realEstateInfo/index.tsx"></code> -->
|
|
12
12
|
|
|
13
|
-
## 不动产销售
|
|
14
|
-
<code src="./_test/realEstateSales/index.tsx"></code>
|
|
13
|
+
<!-- ## 不动产销售
|
|
14
|
+
<code src="./_test/realEstateSales/index.tsx"></code> -->
|
|
15
15
|
|
|
16
16
|
<!-- ## 建筑服务
|
|
17
17
|
<code src="./_test/architecture/index.tsx"></code> -->
|
|
@@ -36,8 +36,8 @@
|
|
|
36
36
|
|
|
37
37
|
|
|
38
38
|
|
|
39
|
-
## 导入项目
|
|
40
|
-
<code src="./_test/importGoods/index.tsx"></code>
|
|
39
|
+
<!-- ## 导入项目
|
|
40
|
+
<code src="./_test/importGoods/index.tsx"></code> -->
|
|
41
41
|
|
|
42
42
|
<!-- ## 预制模式
|
|
43
43
|
<code src="./_test/prefab/index.tsx"></code>
|
|
@@ -46,8 +46,8 @@
|
|
|
46
46
|
<code src="./_test/lineCredit/index.tsx"></code> -->
|
|
47
47
|
|
|
48
48
|
|
|
49
|
-
## 货物运输服务
|
|
50
|
-
<code src="./_test/freight/index.tsx"></code>
|
|
49
|
+
<!-- ## 货物运输服务 -->
|
|
50
|
+
<!-- <code src="./_test/freight/index.tsx"></code> -->
|
|
51
51
|
|
|
52
52
|
## 差额开票
|
|
53
53
|
<code src="./_test/differenceInput/index.tsx"></code>
|
|
@@ -49,7 +49,8 @@ export default class InvoiceControllerForm extends GreyReactBox<InvoiceControlle
|
|
|
49
49
|
_values.set('goodsList', this.state.goodsListState.goodsList.slice().map(e => {
|
|
50
50
|
return {
|
|
51
51
|
...e,
|
|
52
|
-
deductAmount: this.state?.differenceInputState?.data?.deductTotal || 0
|
|
52
|
+
deductAmount: this.state?.differenceInputState?.data?.deductTotal || 0,
|
|
53
|
+
amountIncludeTax: this.state?.differenceInputState?.data?.amountIncludeTax || 0
|
|
53
54
|
}
|
|
54
55
|
}));
|
|
55
56
|
|
|
@@ -137,6 +137,9 @@ export default class GoodsListState {
|
|
|
137
137
|
/** 煤炭种类赋值商品索引 */
|
|
138
138
|
meiTanGoodIndex?: string[] = [];
|
|
139
139
|
|
|
140
|
+
/** 是否可以点击组件外保存行 */
|
|
141
|
+
isSaveRowOutside = true;
|
|
142
|
+
|
|
140
143
|
/** 煤炭时校验函数 */
|
|
141
144
|
verifyMeiTanFn: (record: any) => Promise<boolean> = async record => {
|
|
142
145
|
const { taxClassificationCode } = record;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import InvoiceController from "../";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { chain, bignumber } from 'mathjs';
|
|
4
|
+
import { countAmountExcludeTax, countTaxAmount, countPrice } from "../../tools/calculate";
|
|
5
|
+
|
|
6
|
+
/** 切换是否启用差额开票重新计算税额 */
|
|
7
|
+
export const useRecalculateTax = (invoiceController: InvoiceController) => {
|
|
8
|
+
const differenceInputEnabled = invoiceController.useMemo(s => s.differenceInputState.enabled, [])
|
|
9
|
+
React.useEffect(() => {
|
|
10
|
+
console.log('切换是否启用差额开票重新计算税额 - 重新计算税额===>')
|
|
11
|
+
if (invoiceController.state.goodsListState.editGood) {
|
|
12
|
+
const editGood = invoiceController.state.goodsListState.editGood;
|
|
13
|
+
const form = invoiceController.state.goodsListState.form;
|
|
14
|
+
const isTaxIncluded = invoiceController.state.goodsListState.isTaxIncluded
|
|
15
|
+
if (isTaxIncluded) {
|
|
16
|
+
// 含税
|
|
17
|
+
const lineAmountIncludeTax = form?.getFieldValue('lineAmountIncludeTax') || 0; //含税金额
|
|
18
|
+
const deduction = invoiceController.state.goodsListState.deduction || 0
|
|
19
|
+
const taxRate = form?.getFieldValue('taxRate') || 0; //税率
|
|
20
|
+
const taxAmount = countTaxAmount(lineAmountIncludeTax, deduction, taxRate) || 0; //税额
|
|
21
|
+
const lineAmountExcludeTax = countAmountExcludeTax(lineAmountIncludeTax, taxAmount) || 0; // 不含税金额
|
|
22
|
+
const quantity = form?.getFieldValue('quantity') || 0;
|
|
23
|
+
const priceExcludeTax = quantity > 0 ? countPrice(lineAmountExcludeTax, quantity) : undefined; // 不含税单价
|
|
24
|
+
|
|
25
|
+
form?.setFieldsValue({ taxAmount, lineAmountExcludeTax });
|
|
26
|
+
invoiceController.run(async s => {
|
|
27
|
+
s.goodsListState.editGood = {
|
|
28
|
+
...editGood,
|
|
29
|
+
taxAmount,
|
|
30
|
+
lineAmountExcludeTax,
|
|
31
|
+
priceExcludeTax: priceExcludeTax || undefined,
|
|
32
|
+
};
|
|
33
|
+
})
|
|
34
|
+
} else {
|
|
35
|
+
// 不含税
|
|
36
|
+
const lineAmountIncludeTax = editGood.lineAmountIncludeTax || 0;
|
|
37
|
+
const deduction = invoiceController.state.goodsListState.deduction || 0
|
|
38
|
+
const taxRate = form?.getFieldValue('taxRate') || 0; //税率
|
|
39
|
+
const taxAmount = countTaxAmount(lineAmountIncludeTax, deduction, taxRate) || 0; //税额
|
|
40
|
+
const lineAmountExcludeTax = countAmountExcludeTax(lineAmountIncludeTax, taxAmount) || 0; // 不含税金额
|
|
41
|
+
const quantity = form?.getFieldValue('quantity') || 0;
|
|
42
|
+
const priceExcludeTax = quantity > 0 ? countPrice(lineAmountExcludeTax, quantity) : undefined; // 不含税单价
|
|
43
|
+
|
|
44
|
+
form?.setFieldsValue({ taxAmount, lineAmountExcludeTax });
|
|
45
|
+
invoiceController.run(async s => {
|
|
46
|
+
s.goodsListState.editGood = {
|
|
47
|
+
...editGood,
|
|
48
|
+
taxAmount,
|
|
49
|
+
lineAmountExcludeTax,
|
|
50
|
+
priceExcludeTax: priceExcludeTax || undefined,
|
|
51
|
+
};
|
|
52
|
+
})
|
|
53
|
+
}
|
|
54
|
+
} else {
|
|
55
|
+
invoiceController.run(async s => {
|
|
56
|
+
const good = s.goodsListState.goodsList[0];
|
|
57
|
+
if (!good) return;
|
|
58
|
+
const lineAmountIncludeTax = good.lineAmountIncludeTax || 0;
|
|
59
|
+
const deduction = invoiceController.state.goodsListState.deduction || 0
|
|
60
|
+
const taxRate = good.taxRate || 0;
|
|
61
|
+
const taxAmount = countTaxAmount(lineAmountIncludeTax, deduction, taxRate) || 0; //税额
|
|
62
|
+
const lineAmountExcludeTax = countAmountExcludeTax(lineAmountIncludeTax, taxAmount) || 0; // 不含税金额
|
|
63
|
+
const quantity = good.quantity || 0;
|
|
64
|
+
const priceExcludeTax = quantity > 0 ? countPrice(lineAmountExcludeTax, quantity) : undefined; // 不含税单价
|
|
65
|
+
|
|
66
|
+
s.goodsListState.goodsList[0] = {
|
|
67
|
+
...good,
|
|
68
|
+
taxAmount,
|
|
69
|
+
lineAmountExcludeTax,
|
|
70
|
+
priceExcludeTax: priceExcludeTax || undefined,
|
|
71
|
+
};
|
|
72
|
+
s.goodsListState.goodsList = [...s.goodsListState.goodsList]
|
|
73
|
+
})
|
|
74
|
+
}
|
|
75
|
+
}, [differenceInputEnabled]);
|
|
76
|
+
}
|
package/src/Invoice/index.tsx
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import './index.less';
|
|
3
3
|
import React from 'react';
|
|
4
4
|
import InvoiceController from './InvoiceController';
|
|
5
|
+
import { useRecalculateTax } from './InvoiceController/hooks';
|
|
5
6
|
import useToGenerateId from './tools/useToGenerateId';
|
|
6
7
|
import idGenerator from './tools/idGenerator';
|
|
7
8
|
import * as calculator from './tools/calculate';
|
|
@@ -155,6 +156,7 @@ const Main = (props: IInvoiceProps) => {
|
|
|
155
156
|
const [key, setKey] = React.useState(0);
|
|
156
157
|
|
|
157
158
|
useToGenerateId(controller);
|
|
159
|
+
useRecalculateTax(controller);
|
|
158
160
|
// useClearGoodsList(controller);
|
|
159
161
|
|
|
160
162
|
React.useEffect(() => { setKey(key + 1) }, [controller]);
|
|
@@ -189,6 +191,7 @@ const Digtal = (props: IInvoiceProps) => {
|
|
|
189
191
|
const [key, setKey] = React.useState(0);
|
|
190
192
|
|
|
191
193
|
useToGenerateId(controller);
|
|
194
|
+
useRecalculateTax(controller);
|
|
192
195
|
// useClearGoodsList(controller);
|
|
193
196
|
|
|
194
197
|
React.useEffect(() => { setKey(key + 1) }, [controller]);
|
|
@@ -40,7 +40,7 @@ export function countAmountIncludeTax(quantity?: number | string, priceIncludeTa
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
/**
|
|
43
|
-
* 不含税金额 =
|
|
43
|
+
* 不含税金额 = 含税金额 - 税额
|
|
44
44
|
* @param amountIncludeTax 含税金额
|
|
45
45
|
* @param taxAmount 税额
|
|
46
46
|
* @returns 不含税金额
|
|
@@ -62,13 +62,12 @@ export function countAmountExcludeTax(amountIncludeTax: string | number, taxAmou
|
|
|
62
62
|
export function countTaxAmount(amountIncludeTax: string | number, deduction: number, taxRate: number): number | undefined {
|
|
63
63
|
|
|
64
64
|
if (!amountIncludeTax && amountIncludeTax !== 0) return undefined;
|
|
65
|
-
if (!deduction && deduction !== 0) return undefined;
|
|
66
65
|
if (!taxRate && taxRate !== 0) return undefined;
|
|
67
66
|
|
|
68
67
|
const taxRateBu = chain(bignumber(taxRate)).divide(bignumber(100)).done();
|
|
69
68
|
|
|
70
69
|
return parseFloat(chain(bignumber(amountIncludeTax))
|
|
71
|
-
.subtract(bignumber(deduction))
|
|
70
|
+
.subtract(bignumber(deduction || 0))
|
|
72
71
|
.divide(chain(bignumber(1)).add(taxRateBu).done())
|
|
73
72
|
.multiply(taxRateBu)
|
|
74
73
|
.done()
|
|
@@ -472,9 +472,11 @@ const DrawerBody = (props: { defaultValue: IGood }) => {
|
|
|
472
472
|
|
|
473
473
|
// 确定
|
|
474
474
|
const onSubmit = React.useCallback(values => {
|
|
475
|
+
console.log('天开组件', '点击了赋码确定按钮 ===>', values)
|
|
475
476
|
controller.pipeline(async s => {
|
|
476
477
|
|
|
477
|
-
const endowCodeGood = s.goodsListState.endowCode.endowcodeGoodIndex.map(e => s.goodsListState.goodsMap.get(e));
|
|
478
|
+
// const endowCodeGood = s.goodsListState.endowCode.endowcodeGoodIndex.map(e => s.goodsListState.goodsMap.get(e));
|
|
479
|
+
const endowCodeGood = s.goodsListState.endowCode.endowcodeGoodIndex.map(e => s.goodsListState.goodsList.find(item => item.$index === e));
|
|
478
480
|
|
|
479
481
|
// 赋码
|
|
480
482
|
endowCodeGood.forEach(good => {
|
|
@@ -489,7 +491,7 @@ const DrawerBody = (props: { defaultValue: IGood }) => {
|
|
|
489
491
|
good.mtzlDm = undefined; //设置成空
|
|
490
492
|
|
|
491
493
|
// 无论是否含税,都保持价税合计不变
|
|
492
|
-
good.taxAmount = countTaxAmount(good.lineAmountIncludeTax || 0, s.goodsListState.deduction, values.taxRate);
|
|
494
|
+
good.taxAmount = countTaxAmount(good.lineAmountIncludeTax || 0, s.goodsListState.deduction || 0, values.taxRate);
|
|
493
495
|
if (good.taxAmount || good.taxAmount === 0) {
|
|
494
496
|
good.lineAmountExcludeTax = countAmountExcludeTax(good.lineAmountIncludeTax || 0, good.taxAmount);
|
|
495
497
|
}
|
|
@@ -293,6 +293,7 @@ export const onChangeLineAmountExcludeTax = lazyFn(
|
|
|
293
293
|
export const onChangeTaxRate = lazyFn(
|
|
294
294
|
(controller: InvoiceController, form: WrappedFormUtils, record: IGood) => {
|
|
295
295
|
|
|
296
|
+
console.log('计算税率===>')
|
|
296
297
|
form.validateFields(async (err, values) => {
|
|
297
298
|
err = err || {};
|
|
298
299
|
if (promptErr(err.taxRate) || (!values.taxRate && values.taxRate !== 0)) return;
|
|
@@ -384,7 +385,7 @@ export const updateUnitPriceExcludingTax = async (controller: InvoiceController,
|
|
|
384
385
|
let priceExcludeTax;
|
|
385
386
|
|
|
386
387
|
/** 扣除额 */
|
|
387
|
-
const deduction = controller.state.goodsListState.deduction;
|
|
388
|
+
const deduction = controller.state.goodsListState.deduction || 0;
|
|
388
389
|
|
|
389
390
|
const { editGood } = controller.state.goodsListState
|
|
390
391
|
|
|
@@ -81,6 +81,9 @@ export default (form: WrappedFormUtils) => {
|
|
|
81
81
|
/** 扣除额 */
|
|
82
82
|
const deduction = controller.useMemo((e) => e.goodsListState.deduction, []);
|
|
83
83
|
|
|
84
|
+
/** 差额开票是否启用 */
|
|
85
|
+
const differenceInputStateEnabled = controller.useMemo((e) => e.differenceInputState.enabled, []);
|
|
86
|
+
|
|
84
87
|
/** 计算中启动字段 */
|
|
85
88
|
const changeField = controller.useMemo((e) => e.calculatingField, []);
|
|
86
89
|
|
|
@@ -352,6 +355,7 @@ export default (form: WrappedFormUtils) => {
|
|
|
352
355
|
<MyInput
|
|
353
356
|
style={{ textAlign: 'right' }}
|
|
354
357
|
maxLength={25}
|
|
358
|
+
disabled={differenceInputStateEnabled}
|
|
355
359
|
loading={isCipher(changeField, 'priceIncludeTax')}
|
|
356
360
|
onChange={() => {
|
|
357
361
|
setChangeField('priceIncludeTax');
|
|
@@ -396,6 +400,7 @@ export default (form: WrappedFormUtils) => {
|
|
|
396
400
|
<MyInput
|
|
397
401
|
style={{ textAlign: 'right' }}
|
|
398
402
|
maxLength={25}
|
|
403
|
+
disabled={differenceInputStateEnabled}
|
|
399
404
|
loading={isCipher(changeField, 'priceExcludeTax')}
|
|
400
405
|
onChange={() => {
|
|
401
406
|
setChangeField('priceExcludeTax');
|
|
@@ -446,16 +451,20 @@ export default (form: WrappedFormUtils) => {
|
|
|
446
451
|
<MyInput
|
|
447
452
|
style={{ textAlign: 'right' }}
|
|
448
453
|
loading={isCipher(changeField, 'lineAmountIncludeTax')}
|
|
454
|
+
readOnly={differenceInputStateEnabled}
|
|
449
455
|
onChange={() => {
|
|
450
456
|
setChangeField('lineAmountIncludeTax');
|
|
451
457
|
onChangeLineAmountIncludeTax(controller, form, record);
|
|
452
458
|
}}
|
|
459
|
+
onClick={differenceInputStateEnabled ? (() => {
|
|
460
|
+
controller.run(async (s) => { s.differenceInputState.open = true });
|
|
461
|
+
}) : undefined}
|
|
453
462
|
/>,
|
|
454
463
|
)}
|
|
455
464
|
</Form.Item>
|
|
456
465
|
);
|
|
457
466
|
} else {
|
|
458
|
-
return <span style={{ padding: '0 10px' }}>{formatSearch(parseFloat(value).toFixed(2), searchValue)}</span>;
|
|
467
|
+
return <span style={{ padding: '0 10px' }}>{formatSearch((isNaN(parseFloat(value)) ? 0 : parseFloat(value)).toFixed(2), searchValue)}</span>;
|
|
459
468
|
}
|
|
460
469
|
},
|
|
461
470
|
},
|
|
@@ -466,7 +475,7 @@ export default (form: WrappedFormUtils) => {
|
|
|
466
475
|
align: 'right',
|
|
467
476
|
width: 119,
|
|
468
477
|
render: (value: string, record: IGood) => {
|
|
469
|
-
if (editGood?.$index === record.$index && model !== 'prefab') {
|
|
478
|
+
if (editGood?.$index === record.$index && model !== 'prefab' && !differenceInputStateEnabled) {
|
|
470
479
|
return (
|
|
471
480
|
<Form.Item>
|
|
472
481
|
{getFieldDecorator('lineAmountExcludeTax', {
|
|
@@ -487,7 +496,11 @@ export default (form: WrappedFormUtils) => {
|
|
|
487
496
|
})(
|
|
488
497
|
<MyInput
|
|
489
498
|
style={{ textAlign: 'right' }}
|
|
499
|
+
readOnly={differenceInputStateEnabled}
|
|
490
500
|
loading={isCipher(changeField, 'lineAmountExcludeTax')}
|
|
501
|
+
onClick={differenceInputStateEnabled ? (() => {
|
|
502
|
+
controller.run(async (s) => { s.differenceInputState.open = true });
|
|
503
|
+
}) : undefined}
|
|
491
504
|
onChange={() => {
|
|
492
505
|
setChangeField('lineAmountExcludeTax');
|
|
493
506
|
onChangeLineAmountExcludeTax(controller, form, record);
|
|
@@ -497,8 +510,7 @@ export default (form: WrappedFormUtils) => {
|
|
|
497
510
|
</Form.Item>
|
|
498
511
|
);
|
|
499
512
|
} else {
|
|
500
|
-
|
|
501
|
-
return <span style={{ padding: '0 10px' }}>{value === '' ? '' : formatSearch(parseFloat(value).toFixed(2), searchValue)}</span>;
|
|
513
|
+
return <span style={{ padding: '0 10px' }}>{value === '' ? '' : formatSearch((isNaN(parseFloat(value)) ? 0 : parseFloat(value)).toFixed(2), searchValue)}</span>;
|
|
502
514
|
}
|
|
503
515
|
},
|
|
504
516
|
},
|
|
@@ -571,10 +583,11 @@ export default (form: WrappedFormUtils) => {
|
|
|
571
583
|
//不含税金额
|
|
572
584
|
// const lineAmountExcludeTax = lineAmountIncludeTax-value;
|
|
573
585
|
const lineAmountExcludeTax = editGood?.lineAmountExcludeTax || 0;
|
|
586
|
+
const deduction = controller.state.goodsListState.deduction || 0;
|
|
574
587
|
const taxRate = editGood?.taxRate;
|
|
575
588
|
if (lineAmountExcludeTax && (taxRate || taxRate === 0) && lineAmountIncludeTax) {
|
|
576
589
|
// const total = bignumber(lineAmountExcludeTax * taxRate / 100);
|
|
577
|
-
const total =chain(bignumber(lineAmountExcludeTax)).multiply(bignumber(taxRate || 0)).divide(bignumber(100));
|
|
590
|
+
const total = chain(bignumber(lineAmountExcludeTax)).subtract(bignumber(deduction)).multiply(bignumber(taxRate || 0)).divide(bignumber(100));
|
|
578
591
|
// if (Number(Math.abs(Number(total) - Number(value)).toFixed(4)) <= 0.01) {
|
|
579
592
|
if (Math.abs(total.subtract(bignumber(value || 0)).done().toNumber()) <= 0.06) {
|
|
580
593
|
callback();
|
|
@@ -672,7 +685,7 @@ export default (form: WrappedFormUtils) => {
|
|
|
672
685
|
ellipsis: true,
|
|
673
686
|
};
|
|
674
687
|
}) as any[];
|
|
675
|
-
}, [isTaxIncluded, editGood, goodsList, controller, changeField, deduction, isMyShow, searchValue, model, columnsReplenish, columnshide, isStart]);
|
|
688
|
+
}, [isTaxIncluded, editGood, goodsList, controller, changeField, deduction, isMyShow, searchValue, model, columnsReplenish, columnshide, isStart, differenceInputStateEnabled]);
|
|
676
689
|
|
|
677
690
|
return controller.setColumnsConfig ? controller.setColumnsConfig(columns) : columns;
|
|
678
691
|
};
|
|
@@ -10,10 +10,10 @@ export default function ItemNameInput(props: { onChange?: (e: ChangeEvent<HTMLIn
|
|
|
10
10
|
|
|
11
11
|
const controller = Invoice.useInvoiceController();
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
const rootElement = controller.useMemo(s => s.rootElement, []);
|
|
14
14
|
|
|
15
15
|
const autoComplete = controller.useMemo(s => s.autoComplete, [])
|
|
16
|
-
const enabled = controller.useMemo((s) => s.differenceInputState.enabled, []);
|
|
16
|
+
// const enabled = controller.useMemo((s) => s.differenceInputState.enabled, []);
|
|
17
17
|
const [options, setOptions] = React.useState<IGood[]>([]);
|
|
18
18
|
|
|
19
19
|
const [selectLine, setSelectLine] = React.useState<any>(null);
|
|
@@ -41,14 +41,15 @@ export default function ItemNameInput(props: { onChange?: (e: ChangeEvent<HTMLIn
|
|
|
41
41
|
setSelectLine(null);
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
console.log('onBlur ===>', controller.state.differenceInputState.enabled)
|
|
44
45
|
// 失去焦点时,打开差额开票弹窗
|
|
45
|
-
if (enabled) {
|
|
46
|
+
if (controller.state.differenceInputState.enabled) {
|
|
46
47
|
controller.run(async (s) => { s.differenceInputState.open = true });
|
|
47
48
|
}
|
|
48
49
|
} catch (error) {
|
|
49
50
|
throw error;
|
|
50
51
|
}
|
|
51
|
-
}, [autoComplete.onItemNameBlur, selectLine, props.editGood
|
|
52
|
+
}, [autoComplete.onItemNameBlur, selectLine, props.editGood])
|
|
52
53
|
|
|
53
54
|
const onSearch = React.useCallback(async (searchText: string) => {
|
|
54
55
|
try {
|
|
@@ -13,7 +13,10 @@ export default function useWindowClick(controller: InvoiceController) {
|
|
|
13
13
|
|
|
14
14
|
/** 点击组件外部 保存正在编辑的货物 */
|
|
15
15
|
React.useEffect(() => {
|
|
16
|
-
const click = () => {
|
|
16
|
+
const click = () => {
|
|
17
|
+
if (!controller.state.goodsListState?.isSaveRowOutside) return;
|
|
18
|
+
setTimeout(controller.saveEditGood)
|
|
19
|
+
};
|
|
17
20
|
|
|
18
21
|
window.addEventListener('click', click);
|
|
19
22
|
return () => {
|
|
@@ -77,7 +77,7 @@ const Main = decorator<IGoodsListProps, FormComponentProps & IGoodsListProps>(Fo
|
|
|
77
77
|
/** 表格行事件 */
|
|
78
78
|
const onRow = useOnRow();
|
|
79
79
|
|
|
80
|
-
useDeduction(controller, props.deduction);
|
|
80
|
+
// useDeduction(controller, props.deduction);
|
|
81
81
|
useWindowClick(controller);
|
|
82
82
|
|
|
83
83
|
/** 批量赋码 */
|
|
@@ -42,7 +42,7 @@ export default (props: any) => {
|
|
|
42
42
|
if (isAddRow === false) return <></>;
|
|
43
43
|
if (model === 'prefab') return <></>;
|
|
44
44
|
if (model === 'readOnly') return <></>;
|
|
45
|
-
if (isDifferenceInput && goodsNum >= 1) return <></>;
|
|
45
|
+
// if (isDifferenceInput && goodsNum >= 1) return <></>;
|
|
46
46
|
|
|
47
47
|
return (
|
|
48
48
|
<Button onClick={onClick} disabled={disabled}>
|