fix: 合同结算单打印预览单价计算、费用赔偿计算相关,出入库内容字段报错
Reviewed-on: daoyoucloud/tachycode#663 Co-authored-by: wjh <wwwjh0710@163.com> Co-committed-by: wjh <wwwjh0710@163.com>
This commit is contained in:
parent
a329ab5727
commit
d9e851d1ca
@ -44,6 +44,7 @@ export const RecordDetails: CustomFunctionComponent = () => {
|
||||
// 根据关联产品名称来合并赔偿
|
||||
if (reqRecordItemFeeItems.data) {
|
||||
feeItems = reqRecordItemFeeItems.data.data?.reduce((prev, current) => {
|
||||
if (current.record_item.product) {
|
||||
const key = current.record_item.product.name;
|
||||
if (!(key in prev)) {
|
||||
prev[key] = {};
|
||||
@ -59,6 +60,7 @@ export const RecordDetails: CustomFunctionComponent = () => {
|
||||
};
|
||||
}
|
||||
prev[key][current.product.label].count += current.count;
|
||||
}
|
||||
return prev;
|
||||
}, {});
|
||||
}
|
||||
@ -66,6 +68,7 @@ export const RecordDetails: CustomFunctionComponent = () => {
|
||||
|
||||
if (reqRecordItems.data && feeItems) {
|
||||
reqRecordItems.data.data?.forEach((item) => {
|
||||
if (!item.product) return;
|
||||
const key = item.product.name;
|
||||
const count = item.product.category.convertible ? item.count * item.product.ratio : item.count;
|
||||
const unit = item.product.category.convertible
|
||||
|
@ -41,11 +41,17 @@ export class SettlementService {
|
||||
const lease_rules = ruleItem?.rule.lease_items;
|
||||
// fee_rules 费用明细
|
||||
const fee_rules = ruleItem?.rule.fee_item;
|
||||
//合并产品
|
||||
const countRule = [];
|
||||
// 处理原始数据,适合后续租金数据成
|
||||
if (settlementAbout.records === null) {
|
||||
settlementAbout.records = [];
|
||||
}
|
||||
|
||||
lease_rules.forEach((rule) => {
|
||||
if (rule?.products.length > 1) {
|
||||
countRule.push(...rule.products.map((value) => value));
|
||||
}
|
||||
});
|
||||
// 正常租赁数据
|
||||
lease_rules?.forEach((rule) => {
|
||||
if (rule) {
|
||||
@ -63,15 +69,17 @@ export class SettlementService {
|
||||
if (recordItem) {
|
||||
let isCount;
|
||||
if (productLength > 1) {
|
||||
isCount = rule.products.find(
|
||||
(productRule) =>
|
||||
isCount = rule.products.find((productRule) => {
|
||||
return (
|
||||
productRule.product_id > RulesNumber &&
|
||||
productRule.product_id - RulesNumber === recordItem.product_category_id,
|
||||
productRule.product_id - RulesNumber === recordItem.product_category_id
|
||||
);
|
||||
});
|
||||
} else {
|
||||
isCount =
|
||||
rule.products[0].product_id > RulesNumber &&
|
||||
rule.products[0].product_id - RulesNumber === recordItem.product_category_id;
|
||||
rule.products[0].product_id - RulesNumber === recordItem.product_category_id &&
|
||||
!countRule.find((productRule) => productRule.product_id === rule.products[0].product_id);
|
||||
}
|
||||
if (isCount) {
|
||||
const productName = item.record_items.filter(
|
||||
@ -99,7 +107,7 @@ export class SettlementService {
|
||||
is_excluded: false,
|
||||
count: recordItem.weight * Number(movement),
|
||||
unit_price: rule.unit_price * 1000,
|
||||
amount: recordItem.weight * (rule.unit_price * 1000) * day,
|
||||
amount: recordItem.weight * (rule.unit_price * 1000) * day * Number(movement),
|
||||
unit_name: '吨',
|
||||
productCategory,
|
||||
});
|
||||
@ -118,9 +126,10 @@ export class SettlementService {
|
||||
);
|
||||
} else {
|
||||
isCount =
|
||||
(rule.products[0].product_id > RulesNumber &&
|
||||
((rule.products[0].product_id > RulesNumber &&
|
||||
rule.products[0].product_id - RulesNumber === itemValue?.product.category_id) ||
|
||||
rule.products[0].product_id === itemValue?.product.id;
|
||||
rule.products[0].product_id === itemValue?.product.id) &&
|
||||
!countRule.find((productRule) => productRule.product_id === rule.products[0].product_id);
|
||||
}
|
||||
return isCount;
|
||||
});
|
||||
@ -147,7 +156,7 @@ export class SettlementService {
|
||||
is_excluded: false,
|
||||
count: item.weight * Number(movement),
|
||||
unit_price: rule.unit_price * 1000,
|
||||
amount: item.weight * (rule.unit_price * 1000) * day,
|
||||
amount: item.weight * (rule.unit_price * 1000) * day * Number(movement),
|
||||
unit_name: '吨',
|
||||
productCategory,
|
||||
});
|
||||
@ -207,6 +216,7 @@ export class SettlementService {
|
||||
if (rulefee.fee_product_id) {
|
||||
const spec = rulefee.product.spec;
|
||||
const name = rulefee.product.name;
|
||||
rule.products.forEach((productRule) => {
|
||||
if (rulefee.conversion_logic_id === ConversionLogics.ActualWeight) {
|
||||
let data;
|
||||
if (
|
||||
@ -214,7 +224,7 @@ export class SettlementService {
|
||||
rulefee.count_source === countCource.outItem
|
||||
) {
|
||||
if (item.movement === '-1') {
|
||||
data = recordWeight(rule, item, settlementsId, rule.products, rulefee);
|
||||
data = recordWeight(rule, item, settlementsId, productRule, rulefee);
|
||||
if (data) {
|
||||
data.movement = '-1';
|
||||
}
|
||||
@ -224,13 +234,13 @@ export class SettlementService {
|
||||
rulefee.count_source === countCource.enterItem
|
||||
) {
|
||||
if (item.movement === '1') {
|
||||
data = recordWeight(rule, item, settlementsId, rule.products, rulefee);
|
||||
data = recordWeight(rule, item, settlementsId, productRule, rulefee);
|
||||
if (data) {
|
||||
data.movement = '1';
|
||||
}
|
||||
}
|
||||
} else {
|
||||
data = recordWeight(rule, item, settlementsId, rule.products, rulefee);
|
||||
data = recordWeight(rule, item, settlementsId, productRule, rulefee);
|
||||
if (data) {
|
||||
data.movement = '0';
|
||||
}
|
||||
@ -241,21 +251,10 @@ export class SettlementService {
|
||||
} else {
|
||||
item.record_items?.forEach((recordItem) => {
|
||||
if (recordItem) {
|
||||
let productRule;
|
||||
if (productLength > 1) {
|
||||
productRule = rule.products.find(
|
||||
(item) =>
|
||||
item.product_id - RulesNumber === recordItem.product.category_id ||
|
||||
recordItem.product_id === item.product_id,
|
||||
);
|
||||
} else {
|
||||
productRule =
|
||||
rule.products[0].product_id - RulesNumber === recordItem.product.category_id ||
|
||||
recordItem.product_id === rule.products[0].product_id
|
||||
? rule.products[0]
|
||||
: null;
|
||||
}
|
||||
if (productRule) {
|
||||
if (
|
||||
productRule.product_id - RulesNumber === recordItem.product.category_id ||
|
||||
recordItem.product_id === productRule.product_id
|
||||
) {
|
||||
let productname;
|
||||
switch (productCategory) {
|
||||
case 'category':
|
||||
@ -265,12 +264,6 @@ export class SettlementService {
|
||||
productname = recordItem.product.label;
|
||||
break;
|
||||
}
|
||||
const ruleName =
|
||||
productLength > 1 ? rule.comment ?? '' + '-' + spec : productname + '-' + spec;
|
||||
const ruleLabel =
|
||||
productLength > 1
|
||||
? rule.comment ?? '' + '-' + spec
|
||||
: recordItem.product.label + '-' + spec;
|
||||
//人工录入
|
||||
if (rulefee.count_source === countCource.artificial) {
|
||||
if (rulefee.conversion_logic_id !== ConversionLogics.ActualWeight) {
|
||||
@ -287,8 +280,8 @@ export class SettlementService {
|
||||
createFeesDatas.push({
|
||||
settlement_id: settlementsId,
|
||||
date: item.date,
|
||||
name: ruleName,
|
||||
label: ruleLabel,
|
||||
name: productname + '-' + spec,
|
||||
label: recordItem.product.label + '-' + spec,
|
||||
category: name,
|
||||
movement: item.movement,
|
||||
count: count,
|
||||
@ -313,8 +306,8 @@ export class SettlementService {
|
||||
createFeesDatas.push({
|
||||
settlement_id: settlementsId,
|
||||
date: item.date,
|
||||
name: ruleName,
|
||||
label: ruleLabel,
|
||||
name: productname + '-' + spec,
|
||||
label: recordItem.product.label + '-' + spec,
|
||||
category: name,
|
||||
movement: '-1',
|
||||
count: recordCount,
|
||||
@ -336,8 +329,8 @@ export class SettlementService {
|
||||
createFeesDatas.push({
|
||||
settlement_id: settlementsId,
|
||||
date: item.date,
|
||||
name: ruleName,
|
||||
label: ruleLabel,
|
||||
name: productname + '-' + spec,
|
||||
label: recordItem.product.label + '-' + spec,
|
||||
category: name,
|
||||
movement: '1',
|
||||
count: recordCount,
|
||||
@ -358,8 +351,8 @@ export class SettlementService {
|
||||
createFeesDatas.push({
|
||||
settlement_id: settlementsId,
|
||||
date: item.date,
|
||||
name: ruleName,
|
||||
label: ruleLabel,
|
||||
name: productname + '-' + spec,
|
||||
label: recordItem.product.label + '-' + spec,
|
||||
category: name,
|
||||
movement: '0',
|
||||
count: recordCount,
|
||||
@ -374,6 +367,7 @@ export class SettlementService {
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -827,32 +821,17 @@ export class SettlementService {
|
||||
* @param item
|
||||
* @param settlementsId
|
||||
*/
|
||||
const recordWeight = (rule, item, settlementsId, products, rulefee?) => {
|
||||
let productCategory = 'category';
|
||||
const productLength = products.length;
|
||||
if (productLength === 1) {
|
||||
productCategory = products[0].product_id > RulesNumber ? 'category' : 'product';
|
||||
}
|
||||
const recordWeight = (rule, item, settlementsId, productRule, rulefee?) => {
|
||||
const productCategory = productRule.product_id > RulesNumber ? 'category' : 'product';
|
||||
const spec = rulefee.product.spec;
|
||||
const name = rulefee.product.name;
|
||||
if (item.weight_items.length) {
|
||||
const itemWeight = item.weight_items.find((weightItem) => {
|
||||
let isCount;
|
||||
if (productLength > 1) {
|
||||
isCount = products.find(
|
||||
(productRule) =>
|
||||
const itemWeight = item.weight_items.filter(
|
||||
(weightItem) =>
|
||||
(productRule.product_id > RulesNumber &&
|
||||
productRule.product_id - RulesNumber === weightItem.product_category_id) ||
|
||||
productRule.product_id === weightItem.product_category_id,
|
||||
);
|
||||
} else {
|
||||
isCount =
|
||||
(products[0].product_id > RulesNumber &&
|
||||
products[0].product_id - RulesNumber === weightItem.product_category_id) ||
|
||||
products[0].product_id === weightItem.product_category_id;
|
||||
}
|
||||
return isCount;
|
||||
});
|
||||
)[0];
|
||||
const productsName = item.record_items?.filter(
|
||||
(value) => value.product.category_id === itemWeight.product_category_id,
|
||||
)[0].product;
|
||||
@ -860,8 +839,8 @@ const recordWeight = (rule, item, settlementsId, products, rulefee?) => {
|
||||
return {
|
||||
settlement_id: settlementsId,
|
||||
date: item.date,
|
||||
name: productLength > 1 ? rule.comment ?? '' + '-' + spec : productName + '-' + spec,
|
||||
label: productLength > 1 ? rule.comment ?? '' + '-' + spec : productsName.label + '-' + spec,
|
||||
name: productName + '-' + spec,
|
||||
label: productsName.label + '-' + spec,
|
||||
category: rulefee ? name : rule.product.name,
|
||||
movement: item.movement,
|
||||
count: itemWeight.weight,
|
||||
@ -871,39 +850,28 @@ const recordWeight = (rule, item, settlementsId, products, rulefee?) => {
|
||||
is_excluded: false,
|
||||
};
|
||||
} else {
|
||||
const isRecordItem = item.record_items.find((itemValue) => {
|
||||
let isCount;
|
||||
if (productLength > 1) {
|
||||
isCount = products.find(
|
||||
(productRule) =>
|
||||
const isRecordItem = item.record_items.find(
|
||||
(itemValue) =>
|
||||
(productRule.product_id > RulesNumber &&
|
||||
productRule.product_id - RulesNumber === itemValue?.product.category_id) ||
|
||||
productRule.product_id === itemValue?.product.category_id,
|
||||
);
|
||||
} else {
|
||||
isCount =
|
||||
(products[0].product_id > RulesNumber &&
|
||||
products[0].product_id - RulesNumber === itemValue?.product.category_id) ||
|
||||
products[0].product_id === itemValue?.product.category_id;
|
||||
}
|
||||
return isCount;
|
||||
});
|
||||
if (isRecordItem) {
|
||||
let count = item.weight;
|
||||
item.record_items.forEach((recordItem) => {
|
||||
if (recordItem.record_item_fee_items.length) {
|
||||
const recordItemFee = recordItem.record_item_fee_items.find(
|
||||
const recordItemFee = recordItem.record_item_fee_items.filter(
|
||||
(value) => value.product_id === rulefee.fee_product_id,
|
||||
);
|
||||
count = recordItemFee?.is_excluded ? count - recordItemFee?.count : count;
|
||||
)[0];
|
||||
count = recordItemFee?.is_excluded ? count - recordItemFee.count : count;
|
||||
}
|
||||
});
|
||||
const productName = isRecordItem.product.name;
|
||||
return {
|
||||
settlement_id: settlementsId,
|
||||
date: item.date,
|
||||
name: productLength > 1 ? rule.comment ?? '' + '-' + spec : productName + '-' + spec,
|
||||
label: productLength > 1 ? rule.comment ?? '' + '-' + spec : productName + '-' + spec,
|
||||
name: productName + '-' + spec,
|
||||
label: productName + '-' + spec,
|
||||
category: name,
|
||||
movement: item.movement,
|
||||
count: count,
|
||||
@ -923,10 +891,10 @@ const recordWeight = (rule, item, settlementsId, products, rulefee?) => {
|
||||
* @param itemCount 需要计算的订单数量
|
||||
* @returns count,unit 返回了最后的计算数量和单位
|
||||
*/
|
||||
const ruleCount = (rules: FeeRule | LeaseRule, item: Record, recordItem: RecordItems, valueCount?, rulefee?) => {
|
||||
const ruleCount = (lease_rules: FeeRule | LeaseRule, item: Record, recordItem: RecordItems, valueCount?, rulefee?) => {
|
||||
let count, unit;
|
||||
const itemCount = valueCount ? valueCount : recordItem.count;
|
||||
const conversion_logic_id = rulefee ? rulefee.conversion_logic_id : rules.conversion_logic_id;
|
||||
const conversion_logic_id = rulefee ? rulefee.conversion_logic_id : lease_rules.conversion_logic_id;
|
||||
if (conversion_logic_id === ConversionLogics.Product) {
|
||||
// 换算:2
|
||||
// 查产品分类,看产品分类是否需要换算
|
||||
@ -943,7 +911,8 @@ const ruleCount = (rules: FeeRule | LeaseRule, item: Record, recordItem: RecordI
|
||||
count = itemCount * recordItem.product.weight;
|
||||
unit = recordItem.product.product_category.unit;
|
||||
} else {
|
||||
const rule = rules?.ucl?.weight_items.filter(
|
||||
const rules = rulefee ? rulefee?.weight_items : lease_rules?.ucl?.weight_items;
|
||||
const rule = rules.filter(
|
||||
(value) =>
|
||||
value.product_id === recordItem.product_id || value.product_id - RulesNumber === recordItem.product.category_id,
|
||||
)[0];
|
||||
|
@ -1,5 +1,7 @@
|
||||
-- 租金
|
||||
SELECT
|
||||
-- distinct说明:sql根据订单中产品去合同规则中找规则,如果合同存在单个产品多条规则,会连接查询出多条规则,所以需要distinct
|
||||
-- 直接disinct掉,不会有任何影响,因为查询数据只关注点单产品数量,根换算逻辑,正好多条规则换算逻辑是一样的
|
||||
SELECT DISTINCT
|
||||
r.category,
|
||||
ri.comment AS item_comment,
|
||||
ri.count,
|
||||
|
@ -43,7 +43,19 @@ SELECT
|
||||
SELECT
|
||||
COALESCE(
|
||||
JSONB_AGG(
|
||||
JSONB_SET(TO_JSONB(cpfi), '{product}', TO_JSONB(product))
|
||||
JSONB_SET(TO_JSONB(cpfi), '{product}', TO_JSONB(product)) || JSONB_SET(
|
||||
TO_JSONB(cpfi),
|
||||
'{weight_items}',
|
||||
(
|
||||
SELECT
|
||||
COALESCE(JSONB_AGG(wrs), '[]'::jsonb)
|
||||
FROM
|
||||
weight_rules wrs
|
||||
WHERE
|
||||
wrs.logic_id = cpfi.conversion_logic_id
|
||||
AND cpfi.conversion_logic_id > 4
|
||||
)
|
||||
)
|
||||
),
|
||||
'[]'::jsonb
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user