diff --git a/packages/plugins/@hera/plugin-rental/src/client/custom-components/RecordItemValuationQuantity.tsx b/packages/plugins/@hera/plugin-rental/src/client/custom-components/RecordItemValuationQuantity.tsx index 92f045768..1a381fef3 100644 --- a/packages/plugins/@hera/plugin-rental/src/client/custom-components/RecordItemValuationQuantity.tsx +++ b/packages/plugins/@hera/plugin-rental/src/client/custom-components/RecordItemValuationQuantity.tsx @@ -59,7 +59,7 @@ export const RecordItemValuationQuantity = observer((props) => { (rule) => rule.product?.category_id === item.product?.category_id || rule.product?.id === item.product?.id, ); if (rule) { - rule.conversion_logic_id = rule.conversion_logic.id; + rule.conversion_logic_id = rule.conversion_logic?.id; const count = subtotal(rule, item, productCategory, reqWeightRules); count && result.push({ label: '报价', value: count }); } diff --git a/packages/plugins/@hera/plugin-rental/src/client/custom-components/RecordSummary.tsx b/packages/plugins/@hera/plugin-rental/src/client/custom-components/RecordSummary.tsx index 77edd3989..e252cc4f4 100644 --- a/packages/plugins/@hera/plugin-rental/src/client/custom-components/RecordSummary.tsx +++ b/packages/plugins/@hera/plugin-rental/src/client/custom-components/RecordSummary.tsx @@ -206,7 +206,7 @@ const summary = (event: RecordItems, rules: any[], ruleWeight: any, recordData = // 处理报价跟合同不同数据结构问题 [].flat() [item.products] .flat() - .find((product) => product?.id - 99999 === event.product.category_id || product.id === event.product.id), + .find((product) => product?.id - 99999 === event.product.category_id || product?.id === event.product.id), ); if (!plain) return { ruleCalc }; ruleCalc.name = category.name; diff --git a/packages/plugins/@hera/plugin-rental/src/client/custom-components/RecordTotalPrice.tsx b/packages/plugins/@hera/plugin-rental/src/client/custom-components/RecordTotalPrice.tsx index 2b691ed03..c6317bade 100644 --- a/packages/plugins/@hera/plugin-rental/src/client/custom-components/RecordTotalPrice.tsx +++ b/packages/plugins/@hera/plugin-rental/src/client/custom-components/RecordTotalPrice.tsx @@ -34,6 +34,7 @@ export const RecordTotalPrice: CustomFunctionComponent = () => { const [recordWeight, setRecordWeight] = useState(0); // 总金额计算方法 const computeTotalPrice = () => { + if (!leaseData) return; const about_product = form.values.items.filter( (item) => item.product?.id === leaseData.product?.id || item.product?.category_id === leaseData.product?.id - 99999, @@ -93,34 +94,32 @@ export const RecordTotalPrice: CustomFunctionComponent = () => { setAllPrice(allPrice); }; useFormEffects(() => { - onFieldInit('items.*', () => { + const updateProducts = () => { setProducts(_.cloneDeep(form.values.items)); - }); - onFieldValueChange('items.*', () => { - setProducts(_.cloneDeep(form.values.items)); - }); - onFieldInit('price_items.*', () => { + }; + const updateLeaseData = () => { if (form.values.price_items) { setLeaseData(_.cloneDeep(form.values.price_items[lease_index])); } - }); - onFieldValueChange('price_items.*', () => { - if (form.values.price_items) { - setLeaseData(_.cloneDeep(form.values.price_items[lease_index])); - } - }); - onFieldInit('group_weight_items.*', () => { + }; + const updateGroupWeight = () => { setGroupWeight(_.cloneDeep(form.values.group_weight_items)); - }); - onFieldValueChange('group_weight_items.*', () => { - setGroupWeight(_.cloneDeep(form.values.group_weight_items)); - }); - onFieldInit('weight', () => { + }; + const updateRecordWeight = () => { setRecordWeight(_.cloneDeep(form.values.weight)); - }); - onFieldValueChange('weight', () => { - setRecordWeight(_.cloneDeep(form.values.weight)); - }); + }; + + onFieldInit('items.*', updateProducts); + onFieldValueChange('items.*', updateProducts); + + onFieldInit('price_items.*', updateLeaseData); + onFieldValueChange('price_items.*', updateLeaseData); + + onFieldInit('group_weight_items.*', updateGroupWeight); + onFieldValueChange('group_weight_items.*', updateGroupWeight); + + onFieldInit('weight', updateRecordWeight); + onFieldValueChange('weight', updateRecordWeight); }); useEffect(() => { if (!reqProduct.loading && !reqWeightRules.loading) { diff --git a/packages/plugins/@hera/plugin-rental/src/server/pdf-documents/records-documentV2.tsx b/packages/plugins/@hera/plugin-rental/src/server/pdf-documents/records-documentV2.tsx index 581e0d4c0..9140165ab 100644 --- a/packages/plugins/@hera/plugin-rental/src/server/pdf-documents/records-documentV2.tsx +++ b/packages/plugins/@hera/plugin-rental/src/server/pdf-documents/records-documentV2.tsx @@ -224,9 +224,9 @@ const PreviewDocument = ({ name = detail.contract?.project?.associated_company?.name ?? detail.systemTitle; } else { if (outOfStorage === '入库') { - name = detail.out_stock?.associated_company?.name ?? detail.systemTitle; + name = detail.in_stock?.name ?? detail.systemTitle; } else { - name = detail.in_stock?.associated_company?.name ?? detail.systemTitle; + name = detail.out_stock?.name ?? detail.systemTitle; } } return name; @@ -427,7 +427,7 @@ const PreviewDocument = ({ {item?.right_unit_price && formatQuantity(item.right_unit_price, 2) + '元/' + item.right_unit} - {formatQuantity(item.right_count)} + {item.right_count && formatQuantity(item.right_count)} {item.right_unit} diff --git a/packages/plugins/@hera/plugin-rental/src/server/services/record-pdf-service.ts b/packages/plugins/@hera/plugin-rental/src/server/services/record-pdf-service.ts index 48d31e569..f92108137 100644 --- a/packages/plugins/@hera/plugin-rental/src/server/services/record-pdf-service.ts +++ b/packages/plugins/@hera/plugin-rental/src/server/services/record-pdf-service.ts @@ -64,8 +64,17 @@ export class RecordPdfService { data['all_price'] = data['count'] * data['unit_price']; return data; }); - const setData = Array.from(new Set(price_rule.map((item) => item.name))).map((name) => - price_rule.find((item) => item.name === name), + + const setData = Object.values( + price_rule.reduce((acc, item) => { + if (!acc[item.name]) { + acc[item.name] = { ...item }; + } else { + acc[item.name].count += item.count; + acc[item.name].all_price += item.all_price; + } + return acc; + }, {}), ); make_price = setData; } diff --git a/packages/plugins/@hera/plugin-rental/src/server/services/record-service.ts b/packages/plugins/@hera/plugin-rental/src/server/services/record-service.ts index 9a0c06ccf..7957444a6 100644 --- a/packages/plugins/@hera/plugin-rental/src/server/services/record-service.ts +++ b/packages/plugins/@hera/plugin-rental/src/server/services/record-service.ts @@ -99,7 +99,7 @@ export class RecordService { const weight_items = values.group_weight_items; let allPrice = 0; for (const item of rule) { - const data = await this.amountCalculation(item, products, weight_items); + const data = await this.amountCalculation(item, products, weight_items, values.weight); allPrice += data; } const recordId = record.id; @@ -260,7 +260,7 @@ export class RecordService { * @param weight_items 全部分组实际重量 * @returns 单个规则产生的总金额 */ - private async amountCalculation(rule, products, weight_items) { + private async amountCalculation(rule, products, weight_items, recprdWeight) { const calc_products = products.filter( (product) => product.product.category_id === rule.product.id - 99999 || product.product.id === rule.product.id, ); @@ -299,11 +299,11 @@ export class RecordService { return allPrice / 1000; } else if (rule.conversion_logic.id === ConversionLogics.ActualWeight) { // 根据产品找分组实际重量 - const weightDate = weight_items.find((item) => - item.products?.find((product) => product?.id === rule.product.id - 99999), - ); + const weightDate = + weight_items.find((item) => item.products?.find((product) => product?.id === rule.product.id - 99999)) + ?.weight || recprdWeight; if (weightDate) { - const allPrice = weightDate.weight * rule.unit_price; + const allPrice = weightDate * rule.unit_price; return allPrice; } else { const allPrice = calc_products.reduce((accumulator, currentValue) => {