import BaseService from "../baseService";
|
import { FinanceBankAccount } from "../../entity/finance/base/financeBankAccount";
|
import { FinanceFlow } from "../../entity/finance/base/financeFlow";
|
import { Not } from "typeorm";
|
|
/**
|
* 财务管理
|
*/
|
export default class BankAccountService extends BaseService {
|
//#region 添加保存前事件
|
/**
|
* 添加保存后事件
|
*/
|
public async onAddSaveAfter(t: FinanceBankAccount, isAdd: boolean) {
|
let userInfo = await this.userInfo; // 当前登录人信息
|
this.info.result = true;
|
// 只有在添加时才增加流水
|
if (isAdd) {
|
// 获得最后一条流水
|
let lastFlow = await this.dbRead.findOne(FinanceFlow, {
|
where: {
|
bankAccount_Id: t.bankAccount_Id
|
},
|
order: {
|
bankAccount_Id: "DESC"
|
}
|
});
|
// 获得最终金额
|
let balanceRMB = 0;
|
if (lastFlow) {
|
balanceRMB = lastFlow.balanceRMB;
|
}
|
// 获得流水编号
|
let flowCode = await this.ctx.service.common.getCodeRegular(1698);
|
// 增加流水
|
let newFlow = new FinanceFlow();
|
newFlow.flowCode = flowCode;
|
newFlow.bankAccountCode = t.bankAccountCode;
|
newFlow.bankAccountName = t.bankAccountName;
|
newFlow.bankAccount_Id = t.bankAccount_Id;
|
newFlow.outcomeRMB = 0;
|
newFlow.incomeRMB = t.originalRMB;
|
newFlow.balanceRMB = balanceRMB + t.originalRMB;
|
|
newFlow.mainID = t.bankAccount_Id;
|
newFlow.detailID = t.bankAccount_Id;
|
newFlow.billCode = t.bankAccount;
|
newFlow.flowName = "账户初始化";
|
newFlow.sourceType = "账户初始化";
|
|
newFlow.deptName = userInfo.deptName;
|
newFlow.dept_Id = userInfo.dept_Id;
|
newFlow.userTrueName = userInfo.userTrueName;
|
newFlow.user_Id = userInfo.user_Id;
|
await this.setAccountInfo(newFlow);
|
await this.dbWrite.save(newFlow);
|
}
|
return this.info;
|
}
|
//#endregion
|
//#region 添加保存前事件
|
/**
|
* 添加保存前事件
|
*/
|
public async onAddSaveBefore(t: FinanceBankAccount) {
|
let userInfo = await this.userInfo;
|
this.info.result = true;
|
|
//判断条码是否重复
|
let where = {
|
consignorName: t.consignorName,
|
userProduct_Id: userInfo.userProduct_Id,
|
consignor_Id: Not(0)
|
};
|
let count = await this.dbRead.count(FinanceBankAccount, where);
|
if (count) {
|
this.info.msg = "当前货主名字,【" + t.consignorName + "】已存在不允许重复添加,无法添加!";
|
this.info.result = false;
|
}
|
return this.info;
|
}
|
//#endregion
|
}
|