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;
|
ucl: WeightRule;
|
||||||
product_fee: any;
|
product_fee: any;
|
||||||
products: any;
|
products: any;
|
||||||
|
comment: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Rule {
|
export interface Rule {
|
||||||
|
@ -50,294 +50,332 @@ 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';
|
||||||
settlementAbout.records.forEach((item) => {
|
if (productLength === 1) {
|
||||||
//计算正常租赁订单
|
productCategory = rule.products[0].product_id > RulesNumber ? 'category' : 'product';
|
||||||
if (rule.conversion_logic_id === ConversionLogics.ActualWeight) {
|
}
|
||||||
if (item.weight_items.length) {
|
settlementAbout.records.forEach((item) => {
|
||||||
item.weight_items?.forEach((recordItem) => {
|
//计算正常租赁订单
|
||||||
if (recordItem) {
|
if (rule.conversion_logic_id === ConversionLogics.ActualWeight) {
|
||||||
if (
|
if (item.weight_items.length) {
|
||||||
productRule.product_id > RulesNumber &&
|
item.weight_items?.forEach((recordItem) => {
|
||||||
productRule.product_id - RulesNumber === recordItem.product_category_id
|
if (recordItem) {
|
||||||
) {
|
let isCount;
|
||||||
const productName = item.record_items.filter(
|
if (productLength > 1) {
|
||||||
(value) => value.product.product_category.id === recordItem.product_category_id,
|
isCount = rule.products.find(
|
||||||
)[0].product;
|
(productRule) =>
|
||||||
const day =
|
productRule.product_id > RulesNumber &&
|
||||||
dayjsDays(item.date) < dayjsDays(settlementAbout.start_date)
|
productRule.product_id - RulesNumber === recordItem.product_category_id,
|
||||||
? getCalcDays(settlementAbout.start_date, settlementAbout.end_date)
|
);
|
||||||
: afterDays(
|
} else {
|
||||||
settlementAbout.contracts.calc_type,
|
isCount =
|
||||||
item.movement,
|
rule.products[0].product_id > RulesNumber &&
|
||||||
item.date,
|
rule.products[0].product_id - RulesNumber === recordItem.product_category_id;
|
||||||
settlementAbout.end_date,
|
|
||||||
);
|
|
||||||
const movement = item.movement === '-1' ? '1' : '-1';
|
|
||||||
createLeasDatas.push({
|
|
||||||
settlement_id: settlementsId, //合同ID
|
|
||||||
movement: item.movement, //出入库状态
|
|
||||||
date: item.date, //时间
|
|
||||||
name: productName.name, //名称
|
|
||||||
label: productName.label, //规格
|
|
||||||
category: item.category, //费用类别
|
|
||||||
//租赁天数 历史订单就存开始日期到结束日期 当前订单存储订单日期到结束日期
|
|
||||||
days: day,
|
|
||||||
is_excluded: false,
|
|
||||||
count: recordItem.weight * Number(movement),
|
|
||||||
unit_price: rule.unit_price * 1000,
|
|
||||||
amount: recordItem.weight * (rule.unit_price * 1000) * day,
|
|
||||||
unit_name: '吨',
|
|
||||||
productCategory,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
if (isCount) {
|
||||||
} else {
|
const productName = item.record_items.filter(
|
||||||
const recordItem = item.record_items.find((itemValue) => {
|
(value) => value.product.product_category.id === recordItem.product_category_id,
|
||||||
return (
|
)[0].product;
|
||||||
(productRule.product_id > RulesNumber &&
|
const day =
|
||||||
productRule.product_id - RulesNumber === itemValue?.product.category_id) ||
|
dayjsDays(item.date) < dayjsDays(settlementAbout.start_date)
|
||||||
productRule.product_id === itemValue?.product.id
|
? getCalcDays(settlementAbout.start_date, settlementAbout.end_date)
|
||||||
);
|
: afterDays(
|
||||||
});
|
settlementAbout.contracts.calc_type,
|
||||||
if (recordItem) {
|
item.movement,
|
||||||
const day =
|
item.date,
|
||||||
dayjsDays(item.date) < dayjsDays(settlementAbout.start_date)
|
settlementAbout.end_date,
|
||||||
? getCalcDays(settlementAbout.start_date, settlementAbout.end_date)
|
);
|
||||||
: afterDays(
|
const movement = item.movement === '-1' ? '1' : '-1';
|
||||||
settlementAbout.contracts.calc_type,
|
createLeasDatas.push({
|
||||||
item.movement,
|
|
||||||
item.date,
|
|
||||||
settlementAbout.end_date,
|
|
||||||
);
|
|
||||||
const movement = item.movement === '-1' ? '1' : '-1';
|
|
||||||
createLeasDatas.push({
|
|
||||||
settlement_id: settlementsId, //合同ID
|
|
||||||
movement: item.movement, //出入库状态
|
|
||||||
date: item.date, //时间
|
|
||||||
name: recordItem?.product.name, //名称
|
|
||||||
label: recordItem?.product.name, //规格
|
|
||||||
category: item.category, //费用类别
|
|
||||||
//租赁天数 历史订单就存开始日期到结束日期 当前订单存储订单日期到结束日期
|
|
||||||
days: day,
|
|
||||||
is_excluded: false,
|
|
||||||
count: item.weight * Number(movement),
|
|
||||||
unit_price: rule.unit_price * 1000,
|
|
||||||
amount: item.weight * (rule.unit_price * 1000) * day,
|
|
||||||
unit_name: '吨',
|
|
||||||
productCategory,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
item.record_items?.forEach((recordItem) => {
|
|
||||||
if (recordItem) {
|
|
||||||
if (
|
|
||||||
(productRule.product_id > RulesNumber &&
|
|
||||||
productRule.product_id - RulesNumber === recordItem.product.category_id) ||
|
|
||||||
productRule.product_id === recordItem.product.id
|
|
||||||
) {
|
|
||||||
const data = {
|
|
||||||
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 : productName.name, //名称
|
||||||
label: recordItem.product.label, //规格
|
label: productLength > 1 ? rule.comment : productName.label, //规格
|
||||||
category: item.category, //费用类别
|
category: item.category, //费用类别
|
||||||
//租赁天数 历史订单就存开始日期到结束日期 当前订单存储订单日期到结束日期
|
//租赁天数 历史订单就存开始日期到结束日期 当前订单存储订单日期到结束日期
|
||||||
days:
|
days: day,
|
||||||
dayjsDays(item.date) < dayjsDays(settlementAbout.start_date)
|
|
||||||
? getCalcDays(settlementAbout.start_date, settlementAbout.end_date)
|
|
||||||
: afterDays(
|
|
||||||
settlementAbout.contracts.calc_type,
|
|
||||||
item.movement,
|
|
||||||
item.date,
|
|
||||||
settlementAbout.end_date,
|
|
||||||
),
|
|
||||||
is_excluded: false,
|
is_excluded: false,
|
||||||
|
count: recordItem.weight * Number(movement),
|
||||||
|
unit_price: rule.unit_price * 1000,
|
||||||
|
amount: recordItem.weight * (rule.unit_price * 1000) * day,
|
||||||
|
unit_name: '吨',
|
||||||
productCategory,
|
productCategory,
|
||||||
};
|
});
|
||||||
// 要根据规则计算数量,单价,金额,确定单位
|
|
||||||
const price = rule.unit_price || 0;
|
|
||||||
const movement = item.movement === '-1' ? '1' : '-1';
|
|
||||||
const { count, unit } = ruleCount(rule, item, recordItem);
|
|
||||||
data['unit_name'] = unit;
|
|
||||||
data['count'] = count * Number(movement);
|
|
||||||
data['unit_price'] = price;
|
|
||||||
data['amount'] = data['count'] * price * (data.days || 0);
|
|
||||||
createLeasDatas.push(data);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
const recordItem = item.record_items.find((itemValue) => {
|
||||||
|
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,
|
||||||
|
);
|
||||||
|
} 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 =
|
||||||
|
dayjsDays(item.date) < dayjsDays(settlementAbout.start_date)
|
||||||
|
? getCalcDays(settlementAbout.start_date, settlementAbout.end_date)
|
||||||
|
: afterDays(
|
||||||
|
settlementAbout.contracts.calc_type,
|
||||||
|
item.movement,
|
||||||
|
item.date,
|
||||||
|
settlementAbout.end_date,
|
||||||
|
);
|
||||||
|
const movement = item.movement === '-1' ? '1' : '-1';
|
||||||
|
createLeasDatas.push({
|
||||||
|
settlement_id: settlementsId, //合同ID
|
||||||
|
movement: item.movement, //出入库状态
|
||||||
|
date: item.date, //时间
|
||||||
|
name: productLength > 1 ? rule.comment : recordItem?.product.name, //名称
|
||||||
|
label: productLength > 1 ? rule.comment : recordItem?.product.name, //规格
|
||||||
|
category: item.category, //费用类别
|
||||||
|
//租赁天数 历史订单就存开始日期到结束日期 当前订单存储订单日期到结束日期
|
||||||
|
days: day,
|
||||||
|
is_excluded: false,
|
||||||
|
count: item.weight * Number(movement),
|
||||||
|
unit_price: rule.unit_price * 1000,
|
||||||
|
amount: item.weight * (rule.unit_price * 1000) * day,
|
||||||
|
unit_name: '吨',
|
||||||
|
productCategory,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if (productLength > 1) return;
|
||||||
|
const productRule = rule.products[0];
|
||||||
|
item.record_items?.forEach((recordItem) => {
|
||||||
|
if (recordItem) {
|
||||||
|
if (
|
||||||
|
(productRule.product_id > RulesNumber &&
|
||||||
|
productRule.product_id - RulesNumber === recordItem.product.category_id) ||
|
||||||
|
productRule.product_id === recordItem.product.id
|
||||||
|
) {
|
||||||
|
const data = {
|
||||||
|
settlement_id: settlementsId, //合同ID
|
||||||
|
movement: item.movement, //出入库状态
|
||||||
|
date: item.date, //时间
|
||||||
|
name: recordItem.product.name, //名称
|
||||||
|
label: recordItem.product.label, //规格
|
||||||
|
category: item.category, //费用类别
|
||||||
|
//租赁天数 历史订单就存开始日期到结束日期 当前订单存储订单日期到结束日期
|
||||||
|
days:
|
||||||
|
dayjsDays(item.date) < dayjsDays(settlementAbout.start_date)
|
||||||
|
? getCalcDays(settlementAbout.start_date, settlementAbout.end_date)
|
||||||
|
: afterDays(
|
||||||
|
settlementAbout.contracts.calc_type,
|
||||||
|
item.movement,
|
||||||
|
item.date,
|
||||||
|
settlementAbout.end_date,
|
||||||
|
),
|
||||||
|
is_excluded: false,
|
||||||
|
productCategory,
|
||||||
|
};
|
||||||
|
// 要根据规则计算数量,单价,金额,确定单位
|
||||||
|
const price = rule.unit_price || 0;
|
||||||
|
const movement = item.movement === '-1' ? '1' : '-1';
|
||||||
|
const { count, unit } = ruleCount(rule, item, recordItem);
|
||||||
|
data['unit_name'] = unit;
|
||||||
|
data['count'] = count * Number(movement);
|
||||||
|
data['unit_price'] = price;
|
||||||
|
data['amount'] = data['count'] * price * (data.days || 0);
|
||||||
|
createLeasDatas.push(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
//计算有关联产品费用订单
|
//计算有关联产品费用订单
|
||||||
if (rule.product_fee.length) {
|
if (rule.product_fee.length) {
|
||||||
if (
|
if (
|
||||||
dayjs(item.date).isBetween(ruleItem.start_date, ruleItem.end_date, 'day', '[]') &&
|
dayjs(item.date).isBetween(ruleItem.start_date, ruleItem.end_date, 'day', '[]') &&
|
||||||
dayjs(item.date).isSameOrAfter(settlementAbout.start_date)
|
dayjs(item.date).isSameOrAfter(settlementAbout.start_date)
|
||||||
) {
|
) {
|
||||||
rule.product_fee.forEach((rulefee) => {
|
rule.product_fee.forEach((rulefee) => {
|
||||||
if (rulefee.fee_product_id) {
|
if (rulefee.fee_product_id) {
|
||||||
const spec = rulefee.product.spec;
|
const spec = rulefee.product.spec;
|
||||||
const name = rulefee.product.name;
|
const name = rulefee.product.name;
|
||||||
if (rulefee.conversion_logic_id === ConversionLogics.ActualWeight) {
|
if (rulefee.conversion_logic_id === ConversionLogics.ActualWeight) {
|
||||||
let data;
|
let data;
|
||||||
if (
|
if (
|
||||||
rulefee.count_source === countCource.outProduct ||
|
rulefee.count_source === countCource.outProduct ||
|
||||||
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) {
|
|
||||||
data.movement = '-1';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (
|
|
||||||
rulefee.count_source === countCource.enterProduct ||
|
|
||||||
rulefee.count_source === countCource.enterItem
|
|
||||||
) {
|
|
||||||
if (item.movement === '1') {
|
|
||||||
data = recordWeight(rule, item, settlementsId, productRule, rulefee);
|
|
||||||
if (data) {
|
|
||||||
data.movement = '1';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
data = recordWeight(rule, item, settlementsId, productRule, rulefee);
|
|
||||||
if (data) {
|
if (data) {
|
||||||
data.movement = '0';
|
data.movement = '-1';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (data) {
|
} else if (
|
||||||
createFeesDatas.push({ ...data, productCategory });
|
rulefee.count_source === countCource.enterProduct ||
|
||||||
|
rulefee.count_source === countCource.enterItem
|
||||||
|
) {
|
||||||
|
if (item.movement === '1') {
|
||||||
|
data = recordWeight(rule, item, settlementsId, rule.products, rulefee);
|
||||||
|
if (data) {
|
||||||
|
data.movement = '1';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
item.record_items?.forEach((recordItem) => {
|
data = recordWeight(rule, item, settlementsId, rule.products, rulefee);
|
||||||
if (recordItem) {
|
if (data) {
|
||||||
if (
|
data.movement = '0';
|
||||||
productRule.product_id - RulesNumber === recordItem.product.category_id ||
|
}
|
||||||
recordItem.product_id === productRule.product_id
|
}
|
||||||
) {
|
if (data) {
|
||||||
let productname;
|
createFeesDatas.push({ ...data, productCategory });
|
||||||
switch (productCategory) {
|
}
|
||||||
case 'category':
|
} else {
|
||||||
productname = recordItem.product.name;
|
item.record_items?.forEach((recordItem) => {
|
||||||
break;
|
if (recordItem) {
|
||||||
case 'product':
|
let productRule;
|
||||||
productname = recordItem.product.label;
|
if (productLength > 1) {
|
||||||
break;
|
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':
|
||||||
|
productname = recordItem.product.name;
|
||||||
|
break;
|
||||||
|
case 'product':
|
||||||
|
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) {
|
||||||
|
if (recordItem.record_item_fee_items.length) {
|
||||||
|
recordItem.record_item_fee_items.forEach((value) => {
|
||||||
|
if (value.product_id === rulefee.fee_product_id) {
|
||||||
|
const { count, unit } = ruleCount(
|
||||||
|
rule,
|
||||||
|
item,
|
||||||
|
recordItem,
|
||||||
|
value.count,
|
||||||
|
rulefee,
|
||||||
|
);
|
||||||
|
createFeesDatas.push({
|
||||||
|
settlement_id: settlementsId,
|
||||||
|
date: item.date,
|
||||||
|
name: ruleName,
|
||||||
|
label: ruleLabel,
|
||||||
|
category: name,
|
||||||
|
movement: item.movement,
|
||||||
|
count: count,
|
||||||
|
unit_price: rulefee.unit_price,
|
||||||
|
amount: rulefee.unit_price * count,
|
||||||
|
unit_name: unit,
|
||||||
|
is_excluded: value.is_excluded,
|
||||||
|
productCategory,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//人工录入
|
} //出库
|
||||||
if (rulefee.count_source === countCource.artificial) {
|
else if (
|
||||||
if (rulefee.conversion_logic_id !== ConversionLogics.ActualWeight) {
|
rulefee.count_source === countCource.outProduct ||
|
||||||
if (recordItem.record_item_fee_items.length) {
|
rulefee.count_source === countCource.outItem
|
||||||
recordItem.record_item_fee_items.forEach((value) => {
|
) {
|
||||||
if (value.product_id === rulefee.fee_product_id) {
|
if (item.movement === '-1') {
|
||||||
const { count, unit } = ruleCount(
|
|
||||||
rule,
|
|
||||||
item,
|
|
||||||
recordItem,
|
|
||||||
value.count,
|
|
||||||
rulefee,
|
|
||||||
);
|
|
||||||
createFeesDatas.push({
|
|
||||||
settlement_id: settlementsId,
|
|
||||||
date: item.date,
|
|
||||||
name: productname + '-' + spec,
|
|
||||||
label: recordItem.product.label + '-' + spec,
|
|
||||||
category: name,
|
|
||||||
movement: item.movement,
|
|
||||||
count: count,
|
|
||||||
unit_price: rulefee.unit_price,
|
|
||||||
amount: rulefee.unit_price * count,
|
|
||||||
unit_name: unit,
|
|
||||||
is_excluded: value.is_excluded,
|
|
||||||
productCategory,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} //出库
|
|
||||||
else if (
|
|
||||||
rulefee.count_source === countCource.outProduct ||
|
|
||||||
rulefee.count_source === countCource.outItem
|
|
||||||
) {
|
|
||||||
if (item.movement === '-1') {
|
|
||||||
const { count, unit } = ruleCount(rule, item, recordItem, '', rulefee);
|
|
||||||
const recordCount = recordItemsFee(rule, item, recordItem, count, rulefee);
|
|
||||||
createFeesDatas.push({
|
|
||||||
settlement_id: settlementsId,
|
|
||||||
date: item.date,
|
|
||||||
name: productname + '-' + spec,
|
|
||||||
label: recordItem.product.label + '-' + spec,
|
|
||||||
category: name,
|
|
||||||
movement: '-1',
|
|
||||||
count: recordCount,
|
|
||||||
unit_price: rulefee.unit_price,
|
|
||||||
amount: count * rulefee.unit_price,
|
|
||||||
unit_name: unit,
|
|
||||||
is_excluded: false,
|
|
||||||
productCategory,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} //入库
|
|
||||||
else if (
|
|
||||||
rulefee.count_source === countCource.enterProduct ||
|
|
||||||
rulefee.count_source === countCource.enterItem
|
|
||||||
) {
|
|
||||||
if (item.movement === '1') {
|
|
||||||
const { count, unit } = ruleCount(rule, item, recordItem, '', rulefee);
|
|
||||||
const recordCount = recordItemsFee(rule, item, recordItem, count, rulefee);
|
|
||||||
createFeesDatas.push({
|
|
||||||
settlement_id: settlementsId,
|
|
||||||
date: item.date,
|
|
||||||
name: productname + '-' + spec,
|
|
||||||
label: recordItem.product.label + '-' + spec,
|
|
||||||
category: name,
|
|
||||||
movement: '1',
|
|
||||||
count: recordCount,
|
|
||||||
unit_price: rulefee.unit_price,
|
|
||||||
amount: count * rulefee.unit_price,
|
|
||||||
unit_name: unit,
|
|
||||||
is_excluded: false,
|
|
||||||
productCategory,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} //出入库
|
|
||||||
else if (
|
|
||||||
rulefee.count_source === countCource.product ||
|
|
||||||
rulefee.count_source === countCource.item
|
|
||||||
) {
|
|
||||||
const { count, unit } = ruleCount(rule, item, recordItem, '', rulefee);
|
const { count, unit } = ruleCount(rule, item, recordItem, '', rulefee);
|
||||||
const recordCount = recordItemsFee(rule, item, recordItem, count, rulefee);
|
const recordCount = recordItemsFee(rule, item, recordItem, count, rulefee);
|
||||||
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: '-1',
|
||||||
count: recordCount,
|
count: recordCount,
|
||||||
unit_price: rule.unit_price,
|
unit_price: rulefee.unit_price,
|
||||||
amount: count * rule.unit_price,
|
amount: count * rulefee.unit_price,
|
||||||
unit_name: unit,
|
unit_name: unit,
|
||||||
is_excluded: false,
|
is_excluded: false,
|
||||||
productCategory,
|
productCategory,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
} //入库
|
||||||
|
else if (
|
||||||
|
rulefee.count_source === countCource.enterProduct ||
|
||||||
|
rulefee.count_source === countCource.enterItem
|
||||||
|
) {
|
||||||
|
if (item.movement === '1') {
|
||||||
|
const { count, unit } = ruleCount(rule, item, recordItem, '', rulefee);
|
||||||
|
const recordCount = recordItemsFee(rule, item, recordItem, count, rulefee);
|
||||||
|
createFeesDatas.push({
|
||||||
|
settlement_id: settlementsId,
|
||||||
|
date: item.date,
|
||||||
|
name: ruleName,
|
||||||
|
label: ruleLabel,
|
||||||
|
category: name,
|
||||||
|
movement: '1',
|
||||||
|
count: recordCount,
|
||||||
|
unit_price: rulefee.unit_price,
|
||||||
|
amount: count * rulefee.unit_price,
|
||||||
|
unit_name: unit,
|
||||||
|
is_excluded: false,
|
||||||
|
productCategory,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} //出入库
|
||||||
|
else if (
|
||||||
|
rulefee.count_source === countCource.product ||
|
||||||
|
rulefee.count_source === countCource.item
|
||||||
|
) {
|
||||||
|
const { count, unit } = ruleCount(rule, item, recordItem, '', rulefee);
|
||||||
|
const recordCount = recordItemsFee(rule, item, recordItem, count, rulefee);
|
||||||
|
createFeesDatas.push({
|
||||||
|
settlement_id: settlementsId,
|
||||||
|
date: item.date,
|
||||||
|
name: ruleName,
|
||||||
|
label: ruleLabel,
|
||||||
|
category: name,
|
||||||
|
movement: '0',
|
||||||
|
count: recordCount,
|
||||||
|
unit_price: rule.unit_price,
|
||||||
|
amount: count * rule.unit_price,
|
||||||
|
unit_name: unit,
|
||||||
|
is_excluded: false,
|
||||||
|
productCategory,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -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;
|
||||||
(productRule.product_id > RulesNumber &&
|
if (productLength > 1) {
|
||||||
productRule.product_id - RulesNumber === weightItem.product_category_id) ||
|
isCount = products.find(
|
||||||
productRule.product_id === weightItem.product_category_id,
|
(productRule) =>
|
||||||
)[0];
|
(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;
|
||||||
|
});
|
||||||
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;
|
||||||
(productRule.product_id > RulesNumber &&
|
if (productLength > 1) {
|
||||||
productRule.product_id - RulesNumber === itemValue?.product.category_id) ||
|
isCount = products.find(
|
||||||
productRule.product_id === itemValue?.product.category_id,
|
(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) {
|
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,
|
||||||
|
Loading…
Reference in New Issue
Block a user