From fe268d5f15eab871300f4f7b5215f31ee82e7e26 Mon Sep 17 00:00:00 2001
From: lyx <2027667395@qq.com>
Date: Thu, 14 Mar 2024 16:32:52 +0800
Subject: [PATCH] =?UTF-8?q?fix:=20=E8=AE=A2=E5=8D=95pdf=E6=8A=A5=E4=BB=B7?=
=?UTF-8?q?=E5=AE=9E=E9=99=85=E9=87=8D=E9=87=8F/=E5=B0=8F=E7=BB=93?=
=?UTF-8?q?=E6=8A=A5=E4=BB=B7=E5=AE=9E=E9=99=85=E9=87=8D=E9=87=8F/?=
=?UTF-8?q?=E8=BF=90=E8=BE=93=E5=8D=95=E4=B8=8A=E8=BE=B9=E8=B7=9D?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../custom-components/RecordSummary.tsx | 29 +++++++--
.../src/client/hooks/usePdfPath.tsx | 12 +++-
.../@hera/plugin-rental/src/client/index.tsx | 14 ++++-
.../src/server/actions/waybills-controller.ts | 12 +++-
.../pdf-documents/waybills-document.tsx | 8 +--
.../src/server/services/record-pdf-service.ts | 15 ++++-
.../src/server/sqls/pdf_record.sql | 61 +++++--------------
7 files changed, 85 insertions(+), 66 deletions(-)
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 91d365525..eec1f8540 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
@@ -11,7 +11,9 @@ import _ from 'lodash';
import { formatCurrency, formatQuantity } from '../../utils/currencyUtils';
import { useCachedRequest, useLeaseItems } from '../hooks';
import { RecordItems } from '../../interfaces/records';
+const cache = [];
export const RecordSummary = observer((props): any => {
+ cache.length = 0;
const form = useForm();
const contractPlanId = form.values.contract_plan?.id;
const inContractPlanId = form.values.in_contract_plan?.id;
@@ -66,7 +68,8 @@ export const RecordSummary = observer((props): any => {
total: 0,
unit: '吨',
};
-
+ // 订单分组实际重量
+ const recordData = form.values;
// 基础小结
const summaryProduct = {};
// 合同小结/入库合同小结
@@ -114,13 +117,13 @@ export const RecordSummary = observer((props): any => {
unit_price: rule.unit_price,
};
});
- const { ruleCalc } = summary(element, priceRules, reqWeightRules);
+ const { ruleCalc } = summary(element, priceRules, reqWeightRules, recordData);
priceWeight.total += ruleCalc.weight / 1000;
allPrice.total += ruleCalc.price;
calcProductCount(quoteSummary, ruleCalc, productCategory);
if (form.values.category === RecordCategory.purchase2lease && inLeaseItems) {
const in_contract = inLeaseItems.data;
- const { ruleCalc } = summary(element, in_contract, null);
+ const { ruleCalc } = summary(element, in_contract, null, recordData);
contractWeight.total += ruleCalc.weight / 1000;
calcProductCount(contractSummary, ruleCalc, productCategory);
}
@@ -177,7 +180,7 @@ RecordSummary[KEY_CUSTOM_COMPONENT_LABEL] = '记录单 - 小结';
/** 计算小结
* @param event RecordItem 订单项,record_item
*/
-const summary = (event: RecordItems, rules: any[], ruleWeight: any) => {
+const summary = (event: RecordItems, rules: any[], ruleWeight: any, recordData = null) => {
// 1. 没有规则直接默认产品表换算逻辑
const calc = {
name: '',
@@ -223,8 +226,22 @@ const summary = (event: RecordItems, rules: any[], ruleWeight: any) => {
ruleCalc.count = (event.count * event.product.weight) / 1000;
ruleCalc.unit = '吨';
} else if (plain.conversion_logic_id === ConversionLogics.ActualWeight) {
- ruleCalc.count = 0;
- ruleCalc.unit = '吨';
+ const cacheData = cache.find(
+ (c) => c.id === plain.conversion_logic_id && c.category_id === event.product.category_id,
+ );
+ if (!cacheData) {
+ const weight =
+ recordData.group_weight_items?.find((g) =>
+ g.product_categories?.find((pc) => pc.id === event.product?.category_id),
+ )?.weight || recordData.weight;
+ cache.push({
+ id: plain.conversion_logic_id,
+ category_id: event.product?.category_id,
+ weight: weight,
+ });
+ ruleCalc.count = weight;
+ ruleCalc.unit = '吨';
+ }
} else {
const weightRule = ruleWeight.data?.data?.find(
(item) =>
diff --git a/packages/plugins/@hera/plugin-rental/src/client/hooks/usePdfPath.tsx b/packages/plugins/@hera/plugin-rental/src/client/hooks/usePdfPath.tsx
index 8e1d349a4..2e54ce1c2 100644
--- a/packages/plugins/@hera/plugin-rental/src/client/hooks/usePdfPath.tsx
+++ b/packages/plugins/@hera/plugin-rental/src/client/hooks/usePdfPath.tsx
@@ -38,10 +38,20 @@ export const useRecordPdfPath = () => {
return `/records:pdf?recordId=${record.id}&isDouble=${isDouble}&settingType=${settingType}&margingTop=${margingTop}`;
};
+export const WaybillsProvider = (props) => {
+ const [margingTop, setMargingTop] = useState(0);
+ return (
+
+ {props.children}
+
+ );
+};
+
export const useWaybillPdfPath = () => {
const record = useRecord();
const recordId = record.__collectionName === 'records' ? record.waybill?.id : record.id;
- return `/waybills:pdf?recordId=${recordId}`;
+ const { margingTop } = useContext(PdfMargingTopContext);
+ return `/waybills:pdf?recordId=${recordId}&margingTop=${margingTop}`;
};
export const useSettlementPdfPath = () => {
diff --git a/packages/plugins/@hera/plugin-rental/src/client/index.tsx b/packages/plugins/@hera/plugin-rental/src/client/index.tsx
index 398535839..e674d7581 100644
--- a/packages/plugins/@hera/plugin-rental/src/client/index.tsx
+++ b/packages/plugins/@hera/plugin-rental/src/client/index.tsx
@@ -19,7 +19,13 @@ import {
PrintCounterProvider,
usePDFViewerCountablePrintActionProps,
} from './schema-initializer/PDFViewerPrintActionInitializer';
-import { PdfIsDoubleProvider, useRecordPdfPath, useSettlementPdfPath, useWaybillPdfPath } from './hooks/usePdfPath';
+import {
+ PdfIsDoubleProvider,
+ useRecordPdfPath,
+ useSettlementPdfPath,
+ useWaybillPdfPath,
+ WaybillsProvider,
+} from './hooks/usePdfPath';
import { ColumnSwitchAction, ColumnSwitchActionInitializer } from './schema-initializer/ColumnSwitchActionInitializer';
import {
SettlementExcelExportActionInitializer,
@@ -92,7 +98,7 @@ export class PluginRentalClient extends Plugin {
type: 'item',
title: tval('record'),
component: 'PDFViewerBlockInitializer',
- decorator: 'PdfIsDoubleProvider',
+ 'x-settings': 'PdfIsDoubleProvider',
usePdfPath: '{{ useRecordPdfPath }}',
target: 'record',
});
@@ -101,6 +107,7 @@ export class PluginRentalClient extends Plugin {
type: 'item',
title: tval('waybill'),
component: 'PDFViewerBlockInitializer',
+ 'x-settings': 'WaybillsProvider',
usePdfPath: '{{ useWaybillPdfPath }}',
target: 'waybill',
});
@@ -110,7 +117,7 @@ export class PluginRentalClient extends Plugin {
title: tval('settlement'),
component: 'PDFViewerBlockInitializer',
usePdfPath: '{{ useSettlementPdfPath }}',
- decorator: 'SettlementStyleProvider',
+ 'x-settings': 'SettlementStyleProvider',
target: 'settlement',
});
}
@@ -131,6 +138,7 @@ export class PluginRentalClient extends Plugin {
RecordDetails,
DetailChecks,
PdfIsDoubleProvider,
+ WaybillsProvider,
AddToChecklistActionInitializer,
PrintCounterProvider,
PrintCounterAction,
diff --git a/packages/plugins/@hera/plugin-rental/src/server/actions/waybills-controller.ts b/packages/plugins/@hera/plugin-rental/src/server/actions/waybills-controller.ts
index 8dd863329..1aec97d33 100644
--- a/packages/plugins/@hera/plugin-rental/src/server/actions/waybills-controller.ts
+++ b/packages/plugins/@hera/plugin-rental/src/server/actions/waybills-controller.ts
@@ -13,7 +13,7 @@ export class WaybillsController {
@Action('pdf')
async printPreview(ctx: Context) {
const {
- params: { recordId },
+ params: { recordId, margingTop },
} = ctx.action;
if (recordId === 'undefined' || recordId === undefined) {
ctx.body = await renderWaybill(null);
@@ -25,6 +25,14 @@ export class WaybillsController {
},
type: QueryTypes.SELECT,
});
- ctx.body = await renderWaybill(waybills[0] as Waybill);
+ const settings = {};
+ if (Number(margingTop)) {
+ settings['margingTop'] = Number(margingTop);
+ } else {
+ // 查询当前用户信息
+ const currentUser = await ctx.db.getRepository('users').findOne({ filter: { id: ctx.state.currentUser.id } });
+ settings['margingTop'] = Number(currentUser?.pdf_top_margin) || 0;
+ }
+ ctx.body = await renderWaybill(waybills[0] as Waybill, settings);
}
}
diff --git a/packages/plugins/@hera/plugin-rental/src/server/pdf-documents/waybills-document.tsx b/packages/plugins/@hera/plugin-rental/src/server/pdf-documents/waybills-document.tsx
index 0959b71bd..8a0aa9fe3 100644
--- a/packages/plugins/@hera/plugin-rental/src/server/pdf-documents/waybills-document.tsx
+++ b/packages/plugins/@hera/plugin-rental/src/server/pdf-documents/waybills-document.tsx
@@ -181,7 +181,7 @@ const styles = StyleSheet.create({
* @param
* @returns
*/
-const PreviewDocument = ({ waybill }: { waybill: Waybill }) => {
+const PreviewDocument = ({ waybill, settings }: { waybill: Waybill; settings: any }) => {
// 运输单信息
if (!waybill) {
return (
@@ -222,7 +222,7 @@ const PreviewDocument = ({ waybill }: { waybill: Waybill }) => {
});
return (
-
+
货运运输协议
@@ -452,6 +452,6 @@ const PreviewDocument = ({ waybill }: { waybill: Waybill }) => {
);
};
-export const renderWaybill = async (waybill: Waybill) => {
- return await renderToStream();
+export const renderWaybill = async (waybill: Waybill, settings = null) => {
+ return await renderToStream();
};
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 ddb890086..48d31e569 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
@@ -45,8 +45,14 @@ export class RecordPdfService {
data['count'] = item.count * item.weight;
data['unit'] = 'KG';
} else if (item.conversion_logic_id === ConversionLogics.ActualWeight) {
- if (item.convertible) (data['count'] = item.count * item.ratio), (data['unit'] = item.conversion_unit);
- else (data['count'] = item.count), (data['unit'] = item.unit);
+ const weight = recordData.record_group_weight_items?.find((w) => w.category.id === item.product_category_id);
+ if (weight) {
+ data['count'] = weight.weight;
+ data['unit'] = '吨';
+ } else {
+ data['count'] = recordData.weight;
+ data['unit'] = '吨';
+ }
} else {
data['unit'] = 'KG';
if (item.wr.conversion_logic_id === ConversionLogics.Keep) {
@@ -58,7 +64,10 @@ export class RecordPdfService {
data['all_price'] = data['count'] * data['unit_price'];
return data;
});
- make_price = price_rule;
+ const setData = Array.from(new Set(price_rule.map((item) => item.name))).map((name) =>
+ price_rule.find((item) => item.name === name),
+ );
+ make_price = setData;
}
// 计算租金数据
diff --git a/packages/plugins/@hera/plugin-rental/src/server/sqls/pdf_record.sql b/packages/plugins/@hera/plugin-rental/src/server/sqls/pdf_record.sql
index 5403534a1..301ca47e1 100644
--- a/packages/plugins/@hera/plugin-rental/src/server/sqls/pdf_record.sql
+++ b/packages/plugins/@hera/plugin-rental/src/server/sqls/pdf_record.sql
@@ -89,52 +89,6 @@ SELECT
)
)
) AS contract,
- (
- -- 订单自己的租金规则
- SELECT
- JSONB_AGG(
- JSONB_SET(
- TO_JSONB(lr2),
- '{ucl}',
- (
- SELECT
- TO_JSONB(
- JSONB_SET(
- TO_JSONB(ucl),
- '{other_rules}',
- (
- SELECT
- COALESCE(JSONB_AGG(wr), '[]'::jsonb)
- FROM
- weight_rules wr
- WHERE
- ucl.id = wr.logic_id
- )
- )
- )
- FROM
- unit_conversion_logics ucl
- WHERE
- lr2.conversion_logic_id = ucl.id
- )
- ) || JSONB_SET(
- TO_JSONB(lr2),
- '{product}',
- (
- SELECT
- TO_JSONB(vp)
- FROM
- view_products vp
- WHERE
- lr2.product_id = vp.id
- )
- )
- )
- FROM
- lease_rules lr2
- WHERE
- r.id = lr2.record_id
- ) AS record_lease_rules,
-- ==========================================车号==========================================
(
SELECT
@@ -157,7 +111,20 @@ SELECT
JOIN product p ON p.id = rfi.product_id
WHERE
rfi.record_id = r.id
- ) AS record_fee_items
+ ) AS record_fee_items,
+ -- 查询分组实际重量
+ (
+ SELECT
+ JSONB_AGG(
+ JSONB_SET(TO_JSONB(rgwi), '{category}', TO_JSONB(pc))
+ )
+ FROM
+ record_group_weight_items rgwi
+ JOIN record_group_weight_items_products rgwip ON rgwip.item_id = rgwi.id
+ JOIN product_category pc ON rgwip.product_category_id = pc.id
+ WHERE
+ rgwi.record_id = r.id
+ ) AS record_group_weight_items
FROM
records r
-- 合同数据(租赁有合同)