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:
+40
-12
@@ -57,8 +57,6 @@ public class TripRequirementServiceImpl extends RequirementBaseServiceImpl<TripR
|
|||||||
@Transactional
|
@Transactional
|
||||||
@PreAuthorize("hasPermission(this, 'PERM_EDIT') or hasPermission(#entity, this.getUpdateEntityPermission())")
|
@PreAuthorize("hasPermission(this, 'PERM_EDIT') or hasPermission(#entity, this.getUpdateEntityPermission())")
|
||||||
public void update(TripRequirement entity) {
|
public void update(TripRequirement entity) {
|
||||||
super.update(entity);
|
|
||||||
|
|
||||||
if (entity.getState() == RequirementState.APPROVED) {
|
if (entity.getState() == RequirementState.APPROVED) {
|
||||||
for (TripBill bill : getBills(entity)) {
|
for (TripBill bill : getBills(entity)) {
|
||||||
TripBill newBill = tripBillService.createTripBill(entity);
|
TripBill newBill = tripBillService.createTripBill(entity);
|
||||||
@@ -75,6 +73,8 @@ public class TripRequirementServiceImpl extends RequirementBaseServiceImpl<TripR
|
|||||||
tripBillService.update(bill);
|
tripBillService.update(bill);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
super.update(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -141,25 +141,53 @@ public class TripRequirementServiceImpl extends RequirementBaseServiceImpl<TripR
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void postApprove(TripRequirement entity) {
|
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);
|
TripBill bill = tripBillService.createTripBill(entity);
|
||||||
tripBillService.add(bill);
|
tripBillService.add(bill);
|
||||||
bill.setOwnedBy(entity.getOwnedBy());
|
bill.setOwnedBy(entity.getOwnedBy());
|
||||||
tripBillService.update(bill);
|
tripBillService.update(bill);
|
||||||
|
}
|
||||||
|
|
||||||
if (entity.getBillForPassengers() != null && entity.getBillForPassengers()) {
|
if (entity.getBillForPassengers() != null && entity.getBillForPassengers()) {
|
||||||
for (User u : entity.getPassengers()) {
|
for (User u : entity.getPassengers()) {
|
||||||
if (!u.equals(entity.getOwnedBy())) {
|
if (canCreateBill(entity, u, billList)) {
|
||||||
TripBill passBill = tripBillService.createPassengersBill(entity);
|
TripBill passBill = tripBillService.createPassengersBill(entity);
|
||||||
tripBillService.add(passBill);
|
tripBillService.add(passBill);
|
||||||
passBill.setOwnedBy(u);
|
passBill.setOwnedBy(u);
|
||||||
tripBillService.update(passBill);
|
tripBillService.update(passBill);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
sendMailToPassengers(entity, settingsService.getSettings().getConfReqTripPassenger());
|
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
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user