public void doWithdrawsAndAccruals(Order order) { if (order.getSubscriber().getId() != 0) { if (order.getCash().compareTo(BigDecimal.ZERO) == 0) { SubscriberAccountOperation subscriberOutAccountOperation = new SubscriberAccountOperation(); subscriberOutAccountOperation.setSubscriber(order.getSubscriber()); subscriberOutAccountOperation.setOrder(order); subscriberOutAccountOperation.setDate(new Date()); subscriberOutAccountOperation.setType(OUTCOME_TYPE); subscriberOutAccountOperation.setCause(TRIP_CAUSE); subscriberOutAccountOperation.setAmount(order.getBonus()); subscriberAccountOperationService.create(subscriberOutAccountOperation); order.getSubscriber().setBonus(order.getSubscriber().getBonus().subtract(order.getBonus())); } else if (order.getCash().compareTo(BigDecimal.ZERO) > 0 && order.getBonus().compareTo(BigDecimal.ZERO) > 0) { BigDecimal subscriberIncome = order .getCash() .multiply(SUBSCRIBER_PERCENT) .divide(TOTAL_PERCENTAGE) .setScale(0, BigDecimal.ROUND_HALF_UP); SubscriberAccountOperation subscriberInAccountOperation = new SubscriberAccountOperation(); subscriberInAccountOperation.setSubscriber(order.getSubscriber()); subscriberInAccountOperation.setOrder(order); subscriberInAccountOperation.setDate(new Date()); subscriberInAccountOperation.setType(INCOME_TYPE); subscriberInAccountOperation.setCause(TRIP_CAUSE); subscriberInAccountOperation.setAmount(subscriberIncome); subscriberAccountOperationService.create(subscriberInAccountOperation); order.getSubscriber().setBonus(order.getSubscriber().getBonus().add(subscriberIncome)); SubscriberAccountOperation subscriberOutAccountOperation = new SubscriberAccountOperation(); subscriberOutAccountOperation.setSubscriber(order.getSubscriber()); subscriberOutAccountOperation.setOrder(order); subscriberOutAccountOperation.setDate(new Date()); subscriberOutAccountOperation.setType(OUTCOME_TYPE); subscriberOutAccountOperation.setCause(TRIP_CAUSE); subscriberOutAccountOperation.setAmount(order.getBonus()); subscriberAccountOperationService.create(subscriberOutAccountOperation); order.getSubscriber().setBonus(order.getSubscriber().getBonus().subtract(order.getBonus())); } else { BigDecimal subscriberIncome = order .getTotal() .multiply(SUBSCRIBER_PERCENT) .divide(TOTAL_PERCENTAGE) .setScale(0, BigDecimal.ROUND_HALF_UP); SubscriberAccountOperation subscriberInAccountOperation = new SubscriberAccountOperation(); subscriberInAccountOperation.setSubscriber(order.getSubscriber()); subscriberInAccountOperation.setOrder(order); subscriberInAccountOperation.setDate(new Date()); subscriberInAccountOperation.setType(INCOME_TYPE); subscriberInAccountOperation.setCause(TRIP_CAUSE); subscriberInAccountOperation.setAmount(subscriberIncome); subscriberAccountOperationService.create(subscriberInAccountOperation); order.getSubscriber().setBonus(order.getSubscriber().getBonus().add(subscriberIncome)); } } BigDecimal driverIncome = order .getTotal() .multiply(new BigDecimal(order.getDriver().getWithdrawRate())) .divide(TOTAL_PERCENTAGE) .setScale(0, BigDecimal.ROUND_HALF_UP); DriverAccountOperation driverInAccountOperation = new DriverAccountOperation(); driverInAccountOperation.setDriver(order.getDriver()); driverInAccountOperation.setOrder(order); driverInAccountOperation.setDate(new Date()); driverInAccountOperation.setType(INCOME_TYPE); driverInAccountOperation.setCause(TRIP_CAUSE); driverInAccountOperation.setAmount(driverIncome); driverInAccountOperation.setPaybacked(false); driverAccountOperationService.create(driverInAccountOperation); }
public Order update(Order entity) { if (entity.getStatus().equals(ORDER_STATUS_ACTIVE)) { if (entity.getSubscriber().getId() != 0) { orderDao.find(entity.getId()).getSubscriber().setInTrip(false); entity.getSubscriber().setInTrip(true); } orderDao.find(entity.getId()).getDriver().setInTrip(false); entity.getDriver().setInTrip(true); } entity.setDeparturePoint(entity.getDeparturePoint().trim()); entity.setDestinationPoint(entity.getDestinationPoint().trim()); if (entity.getNotes() != null) { entity.setNotes(entity.getNotes().trim()); } else { entity.setNotes(null); } entity.setCash(entity.getTotal().subtract(entity.getBonus())); entity.setOperator(operatorService.getCurrentOperator()); return orderDao.update(entity); }