Opraveno duplikování vyúčtování SC, když se na požadavku provede úprava a znovu se schválí.
closes #255
This commit is contained in:
+32
-4
@@ -57,8 +57,6 @@ public class TripRequirementServiceImpl extends RequirementBaseServiceImpl<TripR
|
||||
@Transactional
|
||||
@PreAuthorize("hasPermission(this, 'PERM_EDIT') or hasPermission(#entity, this.getUpdateEntityPermission())")
|
||||
public void update(TripRequirement entity) {
|
||||
super.update(entity);
|
||||
|
||||
if (entity.getState() == RequirementState.APPROVED) {
|
||||
for (TripBill bill : getBills(entity)) {
|
||||
TripBill newBill = tripBillService.createTripBill(entity);
|
||||
@@ -75,6 +73,8 @@ public class TripRequirementServiceImpl extends RequirementBaseServiceImpl<TripR
|
||||
tripBillService.update(bill);
|
||||
}
|
||||
}
|
||||
|
||||
super.update(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -141,15 +141,30 @@ public class TripRequirementServiceImpl extends RequirementBaseServiceImpl<TripR
|
||||
|
||||
@Override
|
||||
protected void postApprove(TripRequirement entity) {
|
||||
if (entity.getState() == RequirementState.APPROVED) {
|
||||
if (entity.getState() != RequirementState.APPROVED) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<TripBill> billList = getBills(entity);
|
||||
boolean hasOwned = false;
|
||||
|
||||
for (TripBill tb : billList) {
|
||||
if (tb.getOwnedBy().equals(entity.getOwnedBy())) {
|
||||
hasOwned = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasOwned) {
|
||||
TripBill bill = tripBillService.createTripBill(entity);
|
||||
tripBillService.add(bill);
|
||||
bill.setOwnedBy(entity.getOwnedBy());
|
||||
tripBillService.update(bill);
|
||||
}
|
||||
|
||||
if (entity.getBillForPassengers() != null && entity.getBillForPassengers()) {
|
||||
for (User u : entity.getPassengers()) {
|
||||
if (!u.equals(entity.getOwnedBy())) {
|
||||
if (canCreateBill(entity, u, billList)) {
|
||||
TripBill passBill = tripBillService.createPassengersBill(entity);
|
||||
tripBillService.add(passBill);
|
||||
passBill.setOwnedBy(u);
|
||||
@@ -160,6 +175,19 @@ public class TripRequirementServiceImpl extends RequirementBaseServiceImpl<TripR
|
||||
sendMailToPassengers(entity, settingsService.getSettings().getConfReqTripPassenger());
|
||||
}
|
||||
}
|
||||
|
||||
private boolean canCreateBill(TripRequirement req, User owner, List<TripBill> bills) {
|
||||
if (owner.equals(req.getOwnedBy())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (TripBill tb : bills) {
|
||||
if (tb.getOwnedBy().equals(owner)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user