import { dutyFree, format15, updateUnitPriceExcludingTax, updateUnitPriceTax } from '../../ui/default/GoodsList/hook/useColumns/autoFillFn'; import { InvoiceControllerState, IGood } from '../'; import evaluate from '../../tools/evaluate'; import { countAmountIncludeTax } from '../../tools/calculate'; /** * 删除一个货物 */ export default async (s: InvoiceControllerState, record: any, controller:any) => { Object.keys(record).filter(e => !record[e] && record[e] !== 0).forEach(e => { delete record[e] }); // 没用 被编辑的货物 和 form 就退出 if (!s.goodsListState.editGood || !s.goodsListState.form) return; // 导入时清空之前输入的值,使用导入的单价和税率(参考税局系统) record.quantity = undefined; record.lineAmountExcludeTax = undefined; record.lineAmountIncludeTax = undefined; // 中间数据 const between: any = {...record }; between.itemCode = record.itemCode; between.shorthand = record.shorthand; between.itemName = record.itemName; between.itemNameOther = record.itemName; between.itemModelName = record.itemModelName; between.unit = record.unit; between.quantity = record.quantity; between.priceIncludeTax = record.priceIncludeTax; between.lineAmountIncludeTax = record.lineAmountIncludeTax; between.lineAmountExcludeTax = record.lineAmountExcludeTax; between.taxRate = record.taxRate; between.taxAmount = record.taxAmount; // 设置编辑货物 const editGood: IGood = s.goodsListState.editGood = { ...s.goodsListState.editGood, ...between }; if (editGood.taxRate) { editGood.taxRate = dutyFree(controller, editGood.taxRate, s.goodsListState.form, editGood) } if (`${editGood.priceIncludeTax}` === '0') { editGood.priceIncludeTax = undefined; editGood.priceExcludeTax = undefined; } else { editGood.priceExcludeTax = getPriceExcludeTax(editGood, record, s.calculatingDigits) as number; } if (editGood.quantity && editGood.priceIncludeTax) { editGood.lineAmountIncludeTax = countAmountIncludeTax(editGood.quantity, editGood.priceIncludeTax, s.calculatingDigits); } // 导入FORM里 if (s.goodsListState.isMyShow) { s.goodsListState.form.setFieldsValue({ ...editGood, itemName: editGood.itemNameSelf, itemModelName: editGood.itemModelNameSelf, }); } else { s.goodsListState.form.setFieldsValue({ ...editGood, }); } // s.goodsListState.importGoods.isVisibleDrawer = false; s.goodsListState.isTaxIncluded ? await updateUnitPriceExcludingTax(controller, s.goodsListState.form, record) : await updateUnitPriceTax(controller, s.goodsListState.form, record) } /** 货物单价,不含税 */ const getPriceExcludeTax = (s: IGood, record: any, calculatingDigits?: number) => { if ((!s.taxRate && s.taxRate !== 0) || (!record.priceIncludeTax && record.priceIncludeTax !== 0)) return; // 单价(含税)/(1+税率) = 单价(不含税) return format15(evaluate(`${record.priceIncludeTax} / (1+${s.taxRate}/100)`), calculatingDigits); };