|
|
|
@ -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,25 +141,53 @@ 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())) {
|
|
|
|
|
TripBill passBill = tripBillService.createPassengersBill(entity);
|
|
|
|
|
tripBillService.add(passBill);
|
|
|
|
|
passBill.setOwnedBy(u);
|
|
|
|
|
tripBillService.update(passBill);
|
|
|
|
|
}
|
|
|
|
|
if (entity.getBillForPassengers() != null && entity.getBillForPassengers()) {
|
|
|
|
|
for (User u : entity.getPassengers()) {
|
|
|
|
|
if (canCreateBill(entity, u, billList)) {
|
|
|
|
|
TripBill passBill = tripBillService.createPassengersBill(entity);
|
|
|
|
|
tripBillService.add(passBill);
|
|
|
|
|
passBill.setOwnedBy(u);
|
|
|
|
|
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
|
|
|
|
|