|
|
@ -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,15 +141,30 @@ 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);
|
|
|
@ -160,6 +175,19 @@ public class TripRequirementServiceImpl extends RequirementBaseServiceImpl<TripR
|
|
|
|
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
|
|
|
|