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:
wjh 2024-04-07 20:12:58 +08:00 committed by sealday
parent 57e14cdb77
commit 39b3707deb
2 changed files with 336 additions and 271 deletions

View File

@ -22,6 +22,7 @@ export interface LeaseRule {
ucl: WeightRule; ucl: WeightRule;
product_fee: any; product_fee: any;
products: any; products: any;
comment: string;
} }
export interface Rule { export interface Rule {

View File

@ -50,18 +50,30 @@ export class SettlementService {
lease_rules?.forEach((rule) => { lease_rules?.forEach((rule) => {
if (rule) { if (rule) {
if (rule.products.length) { if (rule.products.length) {
rule.products.forEach((productRule) => { const productLength = rule.products.length;
const productCategory = productRule.product_id > RulesNumber ? 'category' : 'product'; let productCategory = 'category';
if (productLength === 1) {
productCategory = rule.products[0].product_id > RulesNumber ? 'category' : 'product';
}
settlementAbout.records.forEach((item) => { settlementAbout.records.forEach((item) => {
//计算正常租赁订单 //计算正常租赁订单
if (rule.conversion_logic_id === ConversionLogics.ActualWeight) { if (rule.conversion_logic_id === ConversionLogics.ActualWeight) {
if (item.weight_items.length) { if (item.weight_items.length) {
item.weight_items?.forEach((recordItem) => { item.weight_items?.forEach((recordItem) => {
if (recordItem) { if (recordItem) {
if ( let isCount;
if (productLength > 1) {
isCount = rule.products.find(
(productRule) =>
productRule.product_id > RulesNumber && 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( const productName = item.record_items.filter(
(value) => value.product.product_category.id === recordItem.product_category_id, (value) => value.product.product_category.id === recordItem.product_category_id,
)[0].product; )[0].product;
@ -79,8 +91,8 @@ export class SettlementService {
settlement_id: settlementsId, //合同ID settlement_id: settlementsId, //合同ID
movement: item.movement, //出入库状态 movement: item.movement, //出入库状态
date: item.date, //时间 date: item.date, //时间
name: productName.name, //名称 name: productLength > 1 ? rule.comment : productName.name, //名称
label: productName.label, //规格 label: productLength > 1 ? rule.comment : productName.label, //规格
category: item.category, //费用类别 category: item.category, //费用类别
//租赁天数 历史订单就存开始日期到结束日期 当前订单存储订单日期到结束日期 //租赁天数 历史订单就存开始日期到结束日期 当前订单存储订单日期到结束日期
days: day, days: day,
@ -96,11 +108,21 @@ export class SettlementService {
}); });
} else { } else {
const recordItem = item.record_items.find((itemValue) => { 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 &&
productRule.product_id - RulesNumber === itemValue?.product.category_id) || 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) { if (recordItem) {
const day = const day =
@ -117,8 +139,8 @@ export class SettlementService {
settlement_id: settlementsId, //合同ID settlement_id: settlementsId, //合同ID
movement: item.movement, //出入库状态 movement: item.movement, //出入库状态
date: item.date, //时间 date: item.date, //时间
name: recordItem?.product.name, //名称 name: productLength > 1 ? rule.comment : recordItem?.product.name, //名称
label: recordItem?.product.name, //规格 label: productLength > 1 ? rule.comment : recordItem?.product.name, //规格
category: item.category, //费用类别 category: item.category, //费用类别
//租赁天数 历史订单就存开始日期到结束日期 当前订单存储订单日期到结束日期 //租赁天数 历史订单就存开始日期到结束日期 当前订单存储订单日期到结束日期
days: day, days: day,
@ -132,6 +154,8 @@ export class SettlementService {
} }
} }
} else { } else {
if (productLength > 1) return;
const productRule = rule.products[0];
item.record_items?.forEach((recordItem) => { item.record_items?.forEach((recordItem) => {
if (recordItem) { if (recordItem) {
if ( if (
@ -190,7 +214,7 @@ export class SettlementService {
rulefee.count_source === countCource.outItem rulefee.count_source === countCource.outItem
) { ) {
if (item.movement === '-1') { if (item.movement === '-1') {
data = recordWeight(rule, item, settlementsId, productRule, rulefee); data = recordWeight(rule, item, settlementsId, rule.products, rulefee);
if (data) { if (data) {
data.movement = '-1'; data.movement = '-1';
} }
@ -200,13 +224,13 @@ export class SettlementService {
rulefee.count_source === countCource.enterItem rulefee.count_source === countCource.enterItem
) { ) {
if (item.movement === '1') { if (item.movement === '1') {
data = recordWeight(rule, item, settlementsId, productRule, rulefee); data = recordWeight(rule, item, settlementsId, rule.products, rulefee);
if (data) { if (data) {
data.movement = '1'; data.movement = '1';
} }
} }
} else { } else {
data = recordWeight(rule, item, settlementsId, productRule, rulefee); data = recordWeight(rule, item, settlementsId, rule.products, rulefee);
if (data) { if (data) {
data.movement = '0'; data.movement = '0';
} }
@ -217,10 +241,21 @@ export class SettlementService {
} else { } else {
item.record_items?.forEach((recordItem) => { item.record_items?.forEach((recordItem) => {
if (recordItem) { if (recordItem) {
if ( let productRule;
productRule.product_id - RulesNumber === recordItem.product.category_id || if (productLength > 1) {
recordItem.product_id === productRule.product_id 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; let productname;
switch (productCategory) { switch (productCategory) {
case 'category': case 'category':
@ -230,6 +265,10 @@ export class SettlementService {
productname = recordItem.product.label; productname = recordItem.product.label;
break; 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.count_source === countCource.artificial) {
if (rulefee.conversion_logic_id !== ConversionLogics.ActualWeight) { if (rulefee.conversion_logic_id !== ConversionLogics.ActualWeight) {
@ -246,8 +285,8 @@ export class SettlementService {
createFeesDatas.push({ createFeesDatas.push({
settlement_id: settlementsId, settlement_id: settlementsId,
date: item.date, date: item.date,
name: productname + '-' + spec, name: ruleName,
label: recordItem.product.label + '-' + spec, label: ruleLabel,
category: name, category: name,
movement: item.movement, movement: item.movement,
count: count, count: count,
@ -272,8 +311,8 @@ export class SettlementService {
createFeesDatas.push({ createFeesDatas.push({
settlement_id: settlementsId, settlement_id: settlementsId,
date: item.date, date: item.date,
name: productname + '-' + spec, name: ruleName,
label: recordItem.product.label + '-' + spec, label: ruleLabel,
category: name, category: name,
movement: '-1', movement: '-1',
count: recordCount, count: recordCount,
@ -295,8 +334,8 @@ export class SettlementService {
createFeesDatas.push({ createFeesDatas.push({
settlement_id: settlementsId, settlement_id: settlementsId,
date: item.date, date: item.date,
name: productname + '-' + spec, name: ruleName,
label: recordItem.product.label + '-' + spec, label: ruleLabel,
category: name, category: name,
movement: '1', movement: '1',
count: recordCount, count: recordCount,
@ -317,8 +356,8 @@ export class SettlementService {
createFeesDatas.push({ createFeesDatas.push({
settlement_id: settlementsId, settlement_id: settlementsId,
date: item.date, date: item.date,
name: productname + '-' + spec, name: ruleName,
label: recordItem.product.label + '-' + spec, label: ruleLabel,
category: name, category: name,
movement: '0', movement: '0',
count: recordCount, count: recordCount,
@ -338,7 +377,6 @@ export class SettlementService {
} }
} }
}); });
});
} }
} }
}); });
@ -787,17 +825,32 @@ export class SettlementService {
* @param item * @param item
* @param settlementsId * @param settlementsId
*/ */
const recordWeight = (rule, item, settlementsId, productRule, rulefee?) => { const recordWeight = (rule, item, settlementsId, products, rulefee?) => {
const productCategory = productRule.product_id > RulesNumber ? 'category' : 'product'; let productCategory = 'category';
const productLength = products.length;
if (productLength === 1) {
productCategory = products[0].product_id > RulesNumber ? 'category' : 'product';
}
const spec = rulefee.product.spec; const spec = rulefee.product.spec;
const name = rulefee.product.name; const name = rulefee.product.name;
if (item.weight_items.length) { if (item.weight_items.length) {
const itemWeight = item.weight_items.filter( const itemWeight = item.weight_items.find((weightItem) => {
(weightItem) => let isCount;
if (productLength > 1) {
isCount = products.find(
(productRule) =>
(productRule.product_id > RulesNumber && (productRule.product_id > RulesNumber &&
productRule.product_id - RulesNumber === weightItem.product_category_id) || productRule.product_id - RulesNumber === weightItem.product_category_id) ||
productRule.product_id === 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( const productsName = item.record_items?.filter(
(value) => value.product.category_id === itemWeight.product_category_id, (value) => value.product.category_id === itemWeight.product_category_id,
)[0].product; )[0].product;
@ -805,8 +858,8 @@ const recordWeight = (rule, item, settlementsId, productRule, rulefee?) => {
return { return {
settlement_id: settlementsId, settlement_id: settlementsId,
date: item.date, date: item.date,
name: productName + '-' + spec, name: productLength > 1 ? rule.comment + '-' + spec : productName + '-' + spec,
label: productsName.label + '-' + spec, label: productLength > 1 ? rule.comment + '-' + spec : productsName.label + '-' + spec,
category: rulefee ? name : rule.product.name, category: rulefee ? name : rule.product.name,
movement: item.movement, movement: item.movement,
count: itemWeight.weight, count: itemWeight.weight,
@ -816,12 +869,23 @@ const recordWeight = (rule, item, settlementsId, productRule, rulefee?) => {
is_excluded: false, is_excluded: false,
}; };
} else { } else {
const isRecordItem = item.record_items.find( const isRecordItem = item.record_items.find((itemValue) => {
(itemValue) => let isCount;
if (productLength > 1) {
isCount = products.find(
(productRule) =>
(productRule.product_id > RulesNumber && (productRule.product_id > RulesNumber &&
productRule.product_id - RulesNumber === itemValue?.product.category_id) || productRule.product_id - RulesNumber === itemValue?.product.category_id) ||
productRule.product_id === 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) { if (isRecordItem) {
let count = item.weight; let count = item.weight;
item.record_items.forEach((recordItem) => { item.record_items.forEach((recordItem) => {
@ -836,8 +900,8 @@ const recordWeight = (rule, item, settlementsId, productRule, rulefee?) => {
return { return {
settlement_id: settlementsId, settlement_id: settlementsId,
date: item.date, date: item.date,
name: productName + '-' + spec, name: productLength > 1 ? rule.comment + '-' + spec : productName + '-' + spec,
label: productName + '-' + spec, label: productLength > 1 ? rule.comment + '-' + spec : productName + '-' + spec,
category: name, category: name,
movement: item.movement, movement: item.movement,
count: count, count: count,