package pt.utl.ist.scripts.runOnce.candidacy; import net.sourceforge.fenixedu.domain.accounting.PaymentCode; import net.sourceforge.fenixedu.domain.accounting.PaymentCodeType; import net.sourceforge.fenixedu.domain.accounting.paymentCodes.IndividualCandidacyPaymentCode; import net.sourceforge.fenixedu.util.Money; import org.joda.time.LocalDate; import pt.utl.ist.scripts.commons.AtomicScript; public class UpdatePaymentCodesValue extends AtomicScript { /** * update SECOND_CYCLE_INDIVIDUAL_CANDIDACY_PROCESS payment codes with max value 100 to 3500, so that the students can pay * their candidacies for several degrees */ private static final Money PAYMENT_VALUE = Money.valueOf(3500); @Override protected void run() throws Exception { int count = 0; LocalDate startDate = new LocalDate(2013, 07, 9); for (PaymentCode paymentCode : rootDomainObject.getPaymentCodesSet()) { if (paymentCode instanceof IndividualCandidacyPaymentCode) { if (paymentCode.getType().equals(PaymentCodeType.SECOND_CYCLE_INDIVIDUAL_CANDIDACY_PROCESS)) { if (paymentCode.getMaxAmount().getAmount().longValue() == 100) { if (paymentCode.getStartDate().toDateMidnight().toLocalDate().equals(startDate)) { paymentCode.setMaxAmount(PAYMENT_VALUE); count++; } } } } } System.out.println(count + " payment codes updated to the new value"); } public static final void main(String[] args) { processWriteTransaction(new UpdatePaymentCodesValue()); } }