feat: link deposits to bill payment
This commit is contained in:
@@ -106,9 +106,18 @@ export class OccupanciesService {
|
||||
|
||||
if (dto.collectDeposit) {
|
||||
const existingDeposit = await this.depositRepo.findOne({
|
||||
where: { studentId: dto.studentId, status: 'paid' },
|
||||
where: { studentId: dto.studentId },
|
||||
});
|
||||
if (!existingDeposit) {
|
||||
if (existingDeposit) {
|
||||
existingDeposit.amount = Number(
|
||||
(Number(existingDeposit.amount || 0) + Number(dto.depositAmount ?? 500)).toFixed(2),
|
||||
);
|
||||
existingDeposit.status = 'paid';
|
||||
existingDeposit.paidDate = dto.checkInDate;
|
||||
existingDeposit.recordedBy = userId ?? null;
|
||||
existingDeposit.notes = '入住登记自动收取';
|
||||
await this.depositRepo.save(existingDeposit);
|
||||
} else {
|
||||
await this.depositRepo.save(
|
||||
this.depositRepo.create({
|
||||
studentId: dto.studentId,
|
||||
@@ -529,9 +538,18 @@ export class OccupanciesService {
|
||||
// 9. 自动收取押金(仅对新入住且非历史记录的学生)
|
||||
if (options?.autoDeposit && !row.checkOutDate?.trim()) {
|
||||
const existingDeposit = await this.depositRepo.findOne({
|
||||
where: { studentId: student.id, status: 'paid' },
|
||||
where: { studentId: student.id },
|
||||
});
|
||||
if (!existingDeposit) {
|
||||
if (existingDeposit) {
|
||||
existingDeposit.amount = Number(
|
||||
(Number(existingDeposit.amount || 0) + Number(options.depositAmount || 500)).toFixed(2),
|
||||
);
|
||||
existingDeposit.status = 'paid';
|
||||
existingDeposit.paidDate = checkInDate;
|
||||
existingDeposit.notes = '入住导入自动收取';
|
||||
await this.depositRepo.save(existingDeposit);
|
||||
depositsCreated++;
|
||||
} else {
|
||||
await this.depositRepo.save(
|
||||
this.depositRepo.create({
|
||||
studentId: student.id,
|
||||
|
||||
Reference in New Issue
Block a user