From 415ef98ca64fb6c6acfa726b0df3df56a073a830 Mon Sep 17 00:00:00 2001
From: lyx <2027667395@qq.com>
Date: Mon, 18 Mar 2024 19:53:09 +0800
Subject: [PATCH] =?UTF-8?q?fix:=20=E6=8A=A5=E4=BB=B7=E6=80=BB=E9=87=91?=
=?UTF-8?q?=E9=A2=9D=E7=BB=93=E7=AE=97=E7=BB=84=E4=BB=B6=E7=BC=96=E8=BE=91?=
=?UTF-8?q?=E6=8A=A5=E9=94=99=E4=BF=AE=E5=A4=8D=EF=BC=88=E5=BE=85=E9=87=8D?=
=?UTF-8?q?=E6=9E=84=EF=BC=89=E8=B4=AD=E9=94=80=E5=8D=95pdf=E6=89=93?=
=?UTF-8?q?=E5=8D=B0=E5=90=8D=E7=A7=B0=E6=9B=B4=E6=AD=A3=EF=BC=8Cpdf?=
=?UTF-8?q?=E6=8A=A5=E4=BB=B7=E9=87=91=E9=A2=9D=E4=BF=AE=E5=A4=8D=EF=BC=8C?=
=?UTF-8?q?=E8=B4=AD=E9=94=80=E5=88=97=E8=A1=A8=E6=80=BB=E9=87=91=E9=A2=9D?=
=?UTF-8?q?=E4=BF=AE=E5=A4=8D?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../RecordItemValuationQuantity.tsx | 2 +-
.../custom-components/RecordSummary.tsx | 2 +-
.../custom-components/RecordTotalPrice.tsx | 43 +++++++++----------
.../pdf-documents/records-documentV2.tsx | 6 +--
.../src/server/services/record-pdf-service.ts | 13 +++++-
.../src/server/services/record-service.ts | 12 +++---
6 files changed, 43 insertions(+), 35 deletions(-)
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) => {