@Atomic
private void makeGratuityPostingRule(CreateGratuityPhdBean bean, PhdProgram phdProgram) {
if (bean.getPeriods().size() == 0) {
throw new RuntimeException("error.empty.periods");
}
PhdGratuityPR postingRule =
new PhdGratuityPR(bean.getStartDate(), bean.getEndDate(), phdProgram.getServiceAgreementTemplate(), new Money(
bean.getGratuity()), bean.getFineRate());
for (CreateGratuityPhdPRPeriodBean periodBean : bean.getPeriods()) {
PhdGratuityPaymentPeriod period =
new PhdGratuityPaymentPeriod(periodBean.getPeriodStartDate(), periodBean.getPeriodEndDate(),
periodBean.getLimitePaymentDay());
postingRule.addPhdGratuityPaymentPeriods(period);
period.setRootDomainObject(Bennu.getInstance());
}
for (CreateGratuityPhdPRQuickBean quirkBean : bean.getExceptions()) {
PhdGratuityPriceQuirk quirk = new PhdGratuityPriceQuirk(quirkBean.getYear(), new Money(quirkBean.getGratuity()));
postingRule.addPhdGratuityPriceQuirks(quirk);
quirk.setRootDomainObject(Bennu.getInstance());
}
postingRule.setRootDomainObject(Bennu.getInstance());
}