fix: 修改结算单产品计算逻辑 (#619)
Reviewed-on: daoyoucloud/tachycode#619 Co-authored-by: wjh <wwwjh0710@163.com> Co-committed-by: wjh <wwwjh0710@163.com>
This commit is contained in:
parent
57e14cdb77
commit
39b3707deb
@ -22,6 +22,7 @@ export interface LeaseRule {
|
||||
ucl: WeightRule;
|
||||
product_fee: any;
|
||||
products: any;
|
||||
comment: string;
|
||||
}
|
||||
|
||||
export interface Rule {
|
||||
|
@ -50,18 +50,30 @@ export class SettlementService {
|
||||
lease_rules?.forEach((rule) => {
|
||||
if (rule) {
|
||||
if (rule.products.length) {
|
||||
rule.products.forEach((productRule) => {
|
||||
const productCategory = productRule.product_id > RulesNumber ? 'category' : 'product';
|
||||
const productLength = rule.products.length;
|
||||
let productCategory = 'category';
|
||||
if (productLength === 1) {
|
||||
productCategory = rule.products[0].product_id > RulesNumber ? 'category' : 'product';
|
||||
}
|
||||
settlementAbout.records.forEach((item) => {
|
||||
//计算正常租赁订单
|
||||
if (rule.conversion_logic_id === ConversionLogics.ActualWeight) {
|
||||
if (item.weight_items.length) {
|
||||
item.weight_items?.forEach((recordItem) => {
|
||||
if (recordItem) {
|
||||
if (
|
||||
let isCount;
|
||||
if (productLength > 1) {
|
||||
isCount = rule.products.find(
|
||||
(productRule) =>
|
||||
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;
|
||||
}
|
||||
if (isCount) {
|
||||
const productName = item.record_items.filter(
|
||||
(value) => value.product.product_category.id === recordItem.product_category_id,
|
||||
)[0].product;
|
||||
@ -79,8 +91,8 @@ export class SettlementService {
|
||||
settlement_id: settlementsId, //合同ID
|
||||
movement: item.movement, //出入库状态
|
||||
date: item.date, //时间
|
||||
name: productName.name, //名称
|
||||
label: productName.label, //规格
|
||||
name: productLength > 1 ? rule.comment : productName.name, //名称
|
||||
label: productLength > 1 ? rule.comment : productName.label, //规格
|
||||
category: item.category, //费用类别
|
||||
//租赁天数 历史订单就存开始日期到结束日期 当前订单存储订单日期到结束日期
|
||||
days: day,
|
||||
@ -96,11 +108,21 @@ export class SettlementService {
|
||||
});
|
||||
} else {
|
||||
const recordItem = item.record_items.find((itemValue) => {
|
||||
return (
|
||||
let isCount;
|
||||
if (productLength > 1) {
|
||||
isCount = rule.products.find(
|
||||
(productRule) =>
|
||||
(productRule.product_id > RulesNumber &&
|
||||
productRule.product_id - RulesNumber === itemValue?.product.category_id) ||
|
||||
productRule.product_id === itemValue?.product.id
|
||||
productRule.product_id === itemValue?.product.id,
|
||||
);
|
||||
} else {
|
||||
isCount =
|
||||
(rule.products[0].product_id > RulesNumber &&
|
||||
rule.products[0].product_id - RulesNumber === itemValue?.product.category_id) ||
|
||||
rule.products[0].product_id === itemValue?.product.id;
|
||||
}
|
||||
return isCount;
|
||||
});
|
||||
if (recordItem) {
|
||||
const day =
|
||||
@ -117,8 +139,8 @@ export class SettlementService {
|
||||
settlement_id: settlementsId, //合同ID
|
||||
movement: item.movement, //出入库状态
|
||||
date: item.date, //时间
|
||||
name: recordItem?.product.name, //名称
|
||||
label: recordItem?.product.name, //规格
|
||||
name: productLength > 1 ? rule.comment : recordItem?.product.name, //名称
|
||||
label: productLength > 1 ? rule.comment : recordItem?.product.name, //规格
|
||||
category: item.category, //费用类别
|
||||
//租赁天数 历史订单就存开始日期到结束日期 当前订单存储订单日期到结束日期
|
||||
days: day,
|
||||
@ -132,6 +154,8 @@ export class SettlementService {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (productLength > 1) return;
|
||||
const productRule = rule.products[0];
|
||||
item.record_items?.forEach((recordItem) => {
|
||||
if (recordItem) {
|
||||
if (
|
||||
@ -190,7 +214,7 @@ export class SettlementService {
|
||||
rulefee.count_source === countCource.outItem
|
||||
) {
|
||||
if (item.movement === '-1') {
|
||||
data = recordWeight(rule, item, settlementsId, productRule, rulefee);
|
||||
data = recordWeight(rule, item, settlementsId, rule.products, rulefee);
|
||||
if (data) {
|
||||
data.movement = '-1';
|
||||
}
|
||||
@ -200,13 +224,13 @@ export class SettlementService {
|
||||
rulefee.count_source === countCource.enterItem
|
||||
) {
|
||||
if (item.movement === '1') {
|
||||
data = recordWeight(rule, item, settlementsId, productRule, rulefee);
|
||||
data = recordWeight(rule, item, settlementsId, rule.products, rulefee);
|
||||
if (data) {
|
||||
data.movement = '1';
|
||||
}
|
||||
}
|
||||
} else {
|
||||
data = recordWeight(rule, item, settlementsId, productRule, rulefee);
|
||||
data = recordWeight(rule, item, settlementsId, rule.products, rulefee);
|
||||
if (data) {
|
||||
data.movement = '0';
|
||||
}
|
||||
@ -217,10 +241,21 @@ export class SettlementService {
|
||||
} else {
|
||||
item.record_items?.forEach((recordItem) => {
|
||||
if (recordItem) {
|
||||
if (
|
||||
productRule.product_id - RulesNumber === recordItem.product.category_id ||
|
||||
recordItem.product_id === productRule.product_id
|
||||
) {
|
||||
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) {
|
||||
let productname;
|
||||
switch (productCategory) {
|
||||
case 'category':
|
||||
@ -230,6 +265,10 @@ 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) {
|
||||
@ -246,8 +285,8 @@ export class SettlementService {
|
||||
createFeesDatas.push({
|
||||
settlement_id: settlementsId,
|
||||
date: item.date,
|
||||
name: productname + '-' + spec,
|
||||
label: recordItem.product.label + '-' + spec,
|
||||
name: ruleName,
|
||||
label: ruleLabel,
|
||||
category: name,
|
||||
movement: item.movement,
|
||||
count: count,
|
||||
@ -272,8 +311,8 @@ export class SettlementService {
|
||||
createFeesDatas.push({
|
||||
settlement_id: settlementsId,
|
||||
date: item.date,
|
||||
name: productname + '-' + spec,
|
||||
label: recordItem.product.label + '-' + spec,
|
||||
name: ruleName,
|
||||
label: ruleLabel,
|
||||
category: name,
|
||||
movement: '-1',
|
||||
count: recordCount,
|
||||
@ -295,8 +334,8 @@ export class SettlementService {
|
||||
createFeesDatas.push({
|
||||
settlement_id: settlementsId,
|
||||
date: item.date,
|
||||
name: productname + '-' + spec,
|
||||
label: recordItem.product.label + '-' + spec,
|
||||
name: ruleName,
|
||||
label: ruleLabel,
|
||||
category: name,
|
||||
movement: '1',
|
||||
count: recordCount,
|
||||
@ -317,8 +356,8 @@ export class SettlementService {
|
||||
createFeesDatas.push({
|
||||
settlement_id: settlementsId,
|
||||
date: item.date,
|
||||
name: productname + '-' + spec,
|
||||
label: recordItem.product.label + '-' + spec,
|
||||
name: ruleName,
|
||||
label: ruleLabel,
|
||||
category: name,
|
||||
movement: '0',
|
||||
count: recordCount,
|
||||
@ -338,7 +377,6 @@ export class SettlementService {
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -787,17 +825,32 @@ export class SettlementService {
|
||||
* @param item
|
||||
* @param settlementsId
|
||||
*/
|
||||
const recordWeight = (rule, item, settlementsId, productRule, rulefee?) => {
|
||||
const productCategory = productRule.product_id > RulesNumber ? 'category' : 'product';
|
||||
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 spec = rulefee.product.spec;
|
||||
const name = rulefee.product.name;
|
||||
if (item.weight_items.length) {
|
||||
const itemWeight = item.weight_items.filter(
|
||||
(weightItem) =>
|
||||
const itemWeight = item.weight_items.find((weightItem) => {
|
||||
let isCount;
|
||||
if (productLength > 1) {
|
||||
isCount = products.find(
|
||||
(productRule) =>
|
||||
(productRule.product_id > RulesNumber &&
|
||||
productRule.product_id - RulesNumber === weightItem.product_category_id) ||
|
||||
productRule.product_id === weightItem.product_category_id,
|
||||
)[0];
|
||||
);
|
||||
} 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;
|
||||
});
|
||||
const productsName = item.record_items?.filter(
|
||||
(value) => value.product.category_id === itemWeight.product_category_id,
|
||||
)[0].product;
|
||||
@ -805,8 +858,8 @@ const recordWeight = (rule, item, settlementsId, productRule, rulefee?) => {
|
||||
return {
|
||||
settlement_id: settlementsId,
|
||||
date: item.date,
|
||||
name: productName + '-' + spec,
|
||||
label: productsName.label + '-' + spec,
|
||||
name: productLength > 1 ? rule.comment + '-' + spec : productName + '-' + spec,
|
||||
label: productLength > 1 ? rule.comment + '-' + spec : productsName.label + '-' + spec,
|
||||
category: rulefee ? name : rule.product.name,
|
||||
movement: item.movement,
|
||||
count: itemWeight.weight,
|
||||
@ -816,12 +869,23 @@ const recordWeight = (rule, item, settlementsId, productRule, rulefee?) => {
|
||||
is_excluded: false,
|
||||
};
|
||||
} else {
|
||||
const isRecordItem = item.record_items.find(
|
||||
(itemValue) =>
|
||||
const isRecordItem = item.record_items.find((itemValue) => {
|
||||
let isCount;
|
||||
if (productLength > 1) {
|
||||
isCount = products.find(
|
||||
(productRule) =>
|
||||
(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) => {
|
||||
@ -836,8 +900,8 @@ const recordWeight = (rule, item, settlementsId, productRule, rulefee?) => {
|
||||
return {
|
||||
settlement_id: settlementsId,
|
||||
date: item.date,
|
||||
name: productName + '-' + spec,
|
||||
label: productName + '-' + spec,
|
||||
name: productLength > 1 ? rule.comment + '-' + spec : productName + '-' + spec,
|
||||
label: productLength > 1 ? rule.comment + '-' + spec : productName + '-' + spec,
|
||||
category: name,
|
||||
movement: item.movement,
|
||||
count: count,
|
||||
|
Loading…
Reference in New Issue
Block a user