fix: 订单pdf报价实际重量/小结报价实际重量/运输单上边距

This commit is contained in:
lyx 2024-03-14 16:32:52 +08:00
parent a41b3451be
commit fe268d5f15
7 changed files with 85 additions and 66 deletions

View File

@ -11,7 +11,9 @@ import _ from 'lodash';
import { formatCurrency, formatQuantity } from '../../utils/currencyUtils'; import { formatCurrency, formatQuantity } from '../../utils/currencyUtils';
import { useCachedRequest, useLeaseItems } from '../hooks'; import { useCachedRequest, useLeaseItems } from '../hooks';
import { RecordItems } from '../../interfaces/records'; import { RecordItems } from '../../interfaces/records';
const cache = [];
export const RecordSummary = observer((props): any => { export const RecordSummary = observer((props): any => {
cache.length = 0;
const form = useForm(); const form = useForm();
const contractPlanId = form.values.contract_plan?.id; const contractPlanId = form.values.contract_plan?.id;
const inContractPlanId = form.values.in_contract_plan?.id; const inContractPlanId = form.values.in_contract_plan?.id;
@ -66,7 +68,8 @@ export const RecordSummary = observer((props): any => {
total: 0, total: 0,
unit: '吨', unit: '吨',
}; };
// 订单分组实际重量
const recordData = form.values;
// 基础小结 // 基础小结
const summaryProduct = {}; const summaryProduct = {};
// 合同小结/入库合同小结 // 合同小结/入库合同小结
@ -114,13 +117,13 @@ export const RecordSummary = observer((props): any => {
unit_price: rule.unit_price, unit_price: rule.unit_price,
}; };
}); });
const { ruleCalc } = summary(element, priceRules, reqWeightRules); const { ruleCalc } = summary(element, priceRules, reqWeightRules, recordData);
priceWeight.total += ruleCalc.weight / 1000; priceWeight.total += ruleCalc.weight / 1000;
allPrice.total += ruleCalc.price; allPrice.total += ruleCalc.price;
calcProductCount(quoteSummary, ruleCalc, productCategory); calcProductCount(quoteSummary, ruleCalc, productCategory);
if (form.values.category === RecordCategory.purchase2lease && inLeaseItems) { if (form.values.category === RecordCategory.purchase2lease && inLeaseItems) {
const in_contract = inLeaseItems.data; 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; contractWeight.total += ruleCalc.weight / 1000;
calcProductCount(contractSummary, ruleCalc, productCategory); calcProductCount(contractSummary, ruleCalc, productCategory);
} }
@ -177,7 +180,7 @@ RecordSummary[KEY_CUSTOM_COMPONENT_LABEL] = '记录单 - 小结';
/** /**
* @param event RecordItem record_item * @param event RecordItem record_item
*/ */
const summary = (event: RecordItems, rules: any[], ruleWeight: any) => { const summary = (event: RecordItems, rules: any[], ruleWeight: any, recordData = null) => {
// 1. 没有规则直接默认产品表换算逻辑 // 1. 没有规则直接默认产品表换算逻辑
const calc = { const calc = {
name: '', name: '',
@ -223,8 +226,22 @@ const summary = (event: RecordItems, rules: any[], ruleWeight: any) => {
ruleCalc.count = (event.count * event.product.weight) / 1000; ruleCalc.count = (event.count * event.product.weight) / 1000;
ruleCalc.unit = '吨'; ruleCalc.unit = '吨';
} else if (plain.conversion_logic_id === ConversionLogics.ActualWeight) { } else if (plain.conversion_logic_id === ConversionLogics.ActualWeight) {
ruleCalc.count = 0; const cacheData = cache.find(
ruleCalc.unit = '吨'; (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 { } else {
const weightRule = ruleWeight.data?.data?.find( const weightRule = ruleWeight.data?.data?.find(
(item) => (item) =>

View File

@ -38,10 +38,20 @@ export const useRecordPdfPath = () => {
return `/records:pdf?recordId=${record.id}&isDouble=${isDouble}&settingType=${settingType}&margingTop=${margingTop}`; return `/records:pdf?recordId=${record.id}&isDouble=${isDouble}&settingType=${settingType}&margingTop=${margingTop}`;
}; };
export const WaybillsProvider = (props) => {
const [margingTop, setMargingTop] = useState(0);
return (
<PdfMargingTopContext.Provider value={{ margingTop, setMargingTop }}>
{props.children}
</PdfMargingTopContext.Provider>
);
};
export const useWaybillPdfPath = () => { export const useWaybillPdfPath = () => {
const record = useRecord(); const record = useRecord();
const recordId = record.__collectionName === 'records' ? record.waybill?.id : record.id; 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 = () => { export const useSettlementPdfPath = () => {

View File

@ -19,7 +19,13 @@ import {
PrintCounterProvider, PrintCounterProvider,
usePDFViewerCountablePrintActionProps, usePDFViewerCountablePrintActionProps,
} from './schema-initializer/PDFViewerPrintActionInitializer'; } 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 { ColumnSwitchAction, ColumnSwitchActionInitializer } from './schema-initializer/ColumnSwitchActionInitializer';
import { import {
SettlementExcelExportActionInitializer, SettlementExcelExportActionInitializer,
@ -92,7 +98,7 @@ export class PluginRentalClient extends Plugin {
type: 'item', type: 'item',
title: tval('record'), title: tval('record'),
component: 'PDFViewerBlockInitializer', component: 'PDFViewerBlockInitializer',
decorator: 'PdfIsDoubleProvider', 'x-settings': 'PdfIsDoubleProvider',
usePdfPath: '{{ useRecordPdfPath }}', usePdfPath: '{{ useRecordPdfPath }}',
target: 'record', target: 'record',
}); });
@ -101,6 +107,7 @@ export class PluginRentalClient extends Plugin {
type: 'item', type: 'item',
title: tval('waybill'), title: tval('waybill'),
component: 'PDFViewerBlockInitializer', component: 'PDFViewerBlockInitializer',
'x-settings': 'WaybillsProvider',
usePdfPath: '{{ useWaybillPdfPath }}', usePdfPath: '{{ useWaybillPdfPath }}',
target: 'waybill', target: 'waybill',
}); });
@ -110,7 +117,7 @@ export class PluginRentalClient extends Plugin {
title: tval('settlement'), title: tval('settlement'),
component: 'PDFViewerBlockInitializer', component: 'PDFViewerBlockInitializer',
usePdfPath: '{{ useSettlementPdfPath }}', usePdfPath: '{{ useSettlementPdfPath }}',
decorator: 'SettlementStyleProvider', 'x-settings': 'SettlementStyleProvider',
target: 'settlement', target: 'settlement',
}); });
} }
@ -131,6 +138,7 @@ export class PluginRentalClient extends Plugin {
RecordDetails, RecordDetails,
DetailChecks, DetailChecks,
PdfIsDoubleProvider, PdfIsDoubleProvider,
WaybillsProvider,
AddToChecklistActionInitializer, AddToChecklistActionInitializer,
PrintCounterProvider, PrintCounterProvider,
PrintCounterAction, PrintCounterAction,

View File

@ -13,7 +13,7 @@ export class WaybillsController {
@Action('pdf') @Action('pdf')
async printPreview(ctx: Context) { async printPreview(ctx: Context) {
const { const {
params: { recordId }, params: { recordId, margingTop },
} = ctx.action; } = ctx.action;
if (recordId === 'undefined' || recordId === undefined) { if (recordId === 'undefined' || recordId === undefined) {
ctx.body = await renderWaybill(null); ctx.body = await renderWaybill(null);
@ -25,6 +25,14 @@ export class WaybillsController {
}, },
type: QueryTypes.SELECT, 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);
} }
} }

View File

@ -181,7 +181,7 @@ const styles = StyleSheet.create({
* @param * @param
* @returns * @returns
*/ */
const PreviewDocument = ({ waybill }: { waybill: Waybill }) => { const PreviewDocument = ({ waybill, settings }: { waybill: Waybill; settings: any }) => {
// 运输单信息 // 运输单信息
if (!waybill) { if (!waybill) {
return ( return (
@ -222,7 +222,7 @@ const PreviewDocument = ({ waybill }: { waybill: Waybill }) => {
}); });
return ( return (
<Document> <Document>
<Page size="A4" style={styles.page}> <Page size="A4" style={{ ...styles.page, marginTop: settings.margingTop }}>
<Text style={styles.title}></Text> <Text style={styles.title}></Text>
<Text style={styles.titleBtm}></Text> <Text style={styles.titleBtm}></Text>
<View style={styles.content}> <View style={styles.content}>
@ -452,6 +452,6 @@ const PreviewDocument = ({ waybill }: { waybill: Waybill }) => {
</Document> </Document>
); );
}; };
export const renderWaybill = async (waybill: Waybill) => { export const renderWaybill = async (waybill: Waybill, settings = null) => {
return await renderToStream(<PreviewDocument waybill={waybill} />); return await renderToStream(<PreviewDocument waybill={waybill} settings={settings} />);
}; };

View File

@ -45,8 +45,14 @@ export class RecordPdfService {
data['count'] = item.count * item.weight; data['count'] = item.count * item.weight;
data['unit'] = 'KG'; data['unit'] = 'KG';
} else if (item.conversion_logic_id === ConversionLogics.ActualWeight) { } else if (item.conversion_logic_id === ConversionLogics.ActualWeight) {
if (item.convertible) (data['count'] = item.count * item.ratio), (data['unit'] = item.conversion_unit); const weight = recordData.record_group_weight_items?.find((w) => w.category.id === item.product_category_id);
else (data['count'] = item.count), (data['unit'] = item.unit); if (weight) {
data['count'] = weight.weight;
data['unit'] = '吨';
} else {
data['count'] = recordData.weight;
data['unit'] = '吨';
}
} else { } else {
data['unit'] = 'KG'; data['unit'] = 'KG';
if (item.wr.conversion_logic_id === ConversionLogics.Keep) { if (item.wr.conversion_logic_id === ConversionLogics.Keep) {
@ -58,7 +64,10 @@ export class RecordPdfService {
data['all_price'] = data['count'] * data['unit_price']; data['all_price'] = data['count'] * data['unit_price'];
return data; 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;
} }
// 计算租金数据 // 计算租金数据

View File

@ -89,52 +89,6 @@ SELECT
) )
) )
) AS contract, ) 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 SELECT
@ -157,7 +111,20 @@ SELECT
JOIN product p ON p.id = rfi.product_id JOIN product p ON p.id = rfi.product_id
WHERE WHERE
rfi.record_id = r.id 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 FROM
records r records r
-- 合同数据(租赁有合同) -- 合同数据(租赁有合同)