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 pt.utl.ist.scripts.commons.AtomicScript; public class CancelPaymentCodesWithValueZero extends AtomicScript { /** * cancel phd payment codes with value zero that are not in use */ @Override protected void run() throws Exception { int count = 0; for (PaymentCode paymentCode : rootDomainObject.getPaymentCodesSet()) { if (paymentCode instanceof IndividualCandidacyPaymentCode) { if (paymentCode.getType().equals(PaymentCodeType.PHD_PROGRAM_CANDIDACY_PROCESS) && !paymentCode.hasPerson()) { if (paymentCode.getMinAmount().equals(paymentCode.getMaxAmount()) && paymentCode.getMinAmount().isZero()) { paymentCode.cancel(); count++; } } } } System.out.println(count + " canceled payment codes"); } public static final void main(String[] args) { processWriteTransaction(new CancelPaymentCodesWithValueZero()); } }