use of org.estatio.module.financial.dom.BankAccount in project estatio by estatio.
the class IncomingInvoiceRepository_IntegTest method upsert_works.
@Test
public void upsert_works() throws Exception {
// given
IncomingInvoice existingInvoice = createIncomingInvoice();
IncomingInvoice invoice = incomingInvoiceRepository.findByInvoiceNumberAndSellerAndInvoiceDate(invoiceNumber, seller, invoiceDate);
assertThat(invoice.getInvoiceNumber()).isEqualTo(invoiceNumber);
assertThat(invoice.getAtPath()).isEqualTo(atPath);
assertThat(invoice.getBuyer()).isEqualTo(buyer);
assertThat(invoice.getDueDate()).isEqualTo(dueDate);
assertThat(invoice.getPaymentMethod()).isEqualTo(paymentMethod);
assertThat(invoice.getStatus()).isEqualTo(invoiceStatus);
assertThat(invoice.getDateReceived()).isNull();
assertThat(invoice.getBankAccount()).isNull();
// when
String updatedAtPath = "/NLD";
Party updatedBuyer = Organisation_enum.HelloWorldNl.findUsing(serviceRegistry);
LocalDate updatedDueDate = dueDate.minusWeeks(1);
PaymentMethod updatedPaymentMethod = PaymentMethod.DIRECT_DEBIT;
InvoiceStatus updatedStatus = InvoiceStatus.INVOICED;
LocalDate updatedDateReceived = new LocalDate(2017, 1, 2);
BankAccount updatedBankAccount = bankAccountRepository.allBankAccounts().get(0);
Property property = existingInvoice.getProperty();
IncomingInvoice updatedInvoice = incomingInvoiceRepository.upsert(IncomingInvoiceType.CAPEX, invoiceNumber, property, updatedAtPath, updatedBuyer, seller, invoiceDate, updatedDueDate, updatedPaymentMethod, updatedStatus, updatedDateReceived, updatedBankAccount, null);
// then
assertThat(updatedInvoice.getInvoiceNumber()).isEqualTo(invoiceNumber);
assertThat(updatedInvoice.getSeller()).isEqualTo(seller);
assertThat(updatedInvoice.getInvoiceDate()).isEqualTo(invoiceDate);
assertThat(updatedInvoice.getAtPath()).isEqualTo(updatedAtPath);
assertThat(updatedInvoice.getBuyer()).isEqualTo(updatedBuyer);
assertThat(updatedInvoice.getDueDate()).isEqualTo(updatedDueDate);
assertThat(updatedInvoice.getPaymentMethod()).isEqualTo(updatedPaymentMethod);
assertThat(updatedInvoice.getStatus()).isEqualTo(updatedStatus);
assertThat(updatedInvoice.getDateReceived()).isEqualTo(updatedDateReceived);
assertThat(updatedInvoice.getBankAccount()).isEqualTo(updatedBankAccount);
}
use of org.estatio.module.financial.dom.BankAccount in project estatio by estatio.
the class IncomingInvoiceApprovalState_IntegTest method refund_by_supplier_skips_bank_account_verification_and_creates_check_task_for_treasury.
@Test
public void refund_by_supplier_skips_bank_account_verification_and_creates_check_task_for_treasury() {
// given
PartyRoleType typeForTreasurer = partyRoleTypeRepository.findByKey(PartyRoleTypeEnum.TREASURER.getKey());
// workaround: clear MeService#me cache
queryResultsCache.resetForNextTransaction();
sudoService.sudo(Person_enum.JonathanPropertyManagerGb.getRef().toLowerCase(), (Runnable) () -> wrap(incomingInvoice).changePaymentMethod(PaymentMethod.REFUND_BY_SUPPLIER));
sudoService.sudo(Person_enum.JonathanPropertyManagerGb.getRef().toLowerCase(), (Runnable) () -> wrap(mixin(IncomingInvoice_complete.class, incomingInvoice)).act("PROPERTY_MANAGER", null, null));
// workaround: clear MeService#me cache
queryResultsCache.resetForNextTransaction();
sudoService.sudo(Person_enum.PeterPanProjectManagerGb.getRef().toLowerCase(), (Runnable) () -> wrap(mixin(IncomingInvoice_approve.class, incomingInvoice)).act("COUNTRY_DIRECTOR", null, null, false));
List<Task> tasksForTreasury = taskRepository.findIncompleteByRole(typeForTreasurer);
assertThat(tasksForTreasury).isEmpty();
BankAccount bankAccount = incomingInvoice.getBankAccount();
assertThat(bankAccount).isNotNull();
BankAccountVerificationState state = stateTransitionService.currentStateOf(bankAccount, BankAccountVerificationStateTransition.class);
assertThat(state).isEqualTo(BankAccountVerificationState.NOT_VERIFIED);
// when
// workaround: clear MeService#me cache
queryResultsCache.resetForNextTransaction();
sudoService.sudo(Person_enum.OscarCountryDirectorGb.getRef().toLowerCase(), (Runnable) () -> wrap(mixin(IncomingInvoice_approveAsCountryDirector.class, incomingInvoice)).act(null, false));
// then
assertThat(incomingInvoice.getApprovalState()).isEqualTo(IncomingInvoiceApprovalState.PAYABLE);
List<IncomingInvoiceApprovalStateTransition> transitions = incomingInvoiceStateTransitionRepository.findByDomainObject(incomingInvoice);
assertThat(transitions.size()).isEqualTo(7);
assertThat(transitions.get(0).getTransitionType()).isEqualTo(IncomingInvoiceApprovalStateTransitionType.CHECK_PAYMENT);
tasksForTreasury = taskRepository.findIncompleteByRole(typeForTreasurer);
assertThat(tasksForTreasury.size()).isEqualTo(1);
assertThat(tasksForTreasury.get(0).getDescription()).isEqualTo("Check Payment");
// and still
state = stateTransitionService.currentStateOf(bankAccount, BankAccountVerificationStateTransition.class);
assertThat(state).isEqualTo(BankAccountVerificationState.NOT_VERIFIED);
// and when
// workaround: clear MeService#me cache
queryResultsCache.resetForNextTransaction();
sudoService.sudo(Person_enum.EmmaTreasurerGb.getRef().toLowerCase(), (Runnable) () -> wrap(mixin(IncomingInvoice_checkPayment.class, incomingInvoice)).act(null, false));
// then
assertThat(incomingInvoice.getApprovalState()).isEqualTo(IncomingInvoiceApprovalState.PAID);
}
use of org.estatio.module.financial.dom.BankAccount in project estatio by estatio.
the class EnforceTaskAssignmentPolicySubscriber_applyPolicy_Test method setUp.
@Before
public void setUp() throws Exception {
subscriber = new EnforceTaskAssignmentPolicySubscriber();
subscriber.stateTransitionService = mockStateTransitionService;
subscriber.personRepository = mockPersonRepository;
subscriber.metaModelService3 = mockMetaModelService3;
domainObject = new BankAccount();
stateTransitionClass = BankAccountVerificationStateTransition.class;
pendingTransition = new BankAccountVerificationStateTransition();
personTaskAssignedTo = new Person();
personTaskAssignedTo.setReference("JBLOGGS");
roleTaskAssignedTo = new PartyRoleType();
roleTaskAssignedTo.setKey("Treasurer");
pendingTask = new Task(roleTaskAssignedTo, personTaskAssignedTo, "some description", LocalDateTime.now(), // objectType of transition class
"bankAccount.BankAccountVerificationStateTransition");
pendingTransition.setTask(pendingTask);
personForMe = new Person();
personForMe.getRoles().add(new PartyRole(personForMe, roleTaskAssignedTo));
assertThat(pendingTransition.getTask()).isNotNull();
assertThat(personForMe.getRoles()).isNotEmpty();
assertThat(Lists.newArrayList(personForMe.getRoles()).stream().map(PartyRole::getRoleType)).contains(roleTaskAssignedTo);
}
use of org.estatio.module.financial.dom.BankAccount in project estatio by estatio.
the class PartyBankAccountsAndMandatesDtoFactory method newDto.
@Programmatic
public BankAccountsAndMandatesDto newDto(final Party party) {
final BankAccountsAndMandatesDto dto = new BankAccountsAndMandatesDto();
final List<FinancialAccount> financialAccountList = financialAccountRepository.findAccountsByTypeOwner(FinancialAccountType.BANK_ACCOUNT, party);
final List<BankAccountDto> bankAccountDtos = financialAccountList.stream().map(x -> bankAccountDtoFactory.newDto((BankAccount) x)).collect(Collectors.toList());
dto.setBankAccounts(bankAccountDtos);
final AgreementType bankMandateAt = agreementTypeRepository.find(BankMandateAgreementTypeEnum.MANDATE);
final AgreementRoleType debtorOfMandate = agreementRoleTypeRepository.findByAgreementTypeAndTitle(bankMandateAt, BankMandateAgreementRoleTypeEnum.DEBTOR.getTitle());
final List<AgreementRole> agreementRoles = agreementRoleRepository.findByPartyAndType(party, debtorOfMandate);
final List<BankMandateDto> mandateDtos = agreementRoles.stream().map(x -> x.getAgreement()).map(x -> bankMandateDtoFactory.newDto((BankMandate) x)).collect(Collectors.toList());
dto.setBankMandates(mandateDtos);
return dto;
}
use of org.estatio.module.financial.dom.BankAccount in project estatio by estatio.
the class BankAccountImport method importData.
@Programmatic
@Override
public List<Object> importData(final Object previousRow) {
if (IBANValidator.valid(iban)) {
final Party owner = partyRepository.findPartyByReference(ownerReference);
BankAccount bankAccount = (BankAccount) financialAccountRepository.findByOwnerAndReference(owner, iban);
if (owner == null)
return Lists.newArrayList();
if (bankAccount == null) {
bankAccount = bankAccountRepository.newBankAccount(owner, iban, bic);
} else {
bankAccount.setIban(iban);
bankAccount.verifyIban();
bankAccount.setBic(BankAccount.trimBic(bic));
}
if (propertyReference != null) {
final Property property = propertyRepository.findPropertyByReference(propertyReference);
if (property == null) {
throw new IllegalArgumentException(String.format("Property with reference [%s] not found", propertyReference));
}
fixedAssetFinancialAccountRepository.findOrCreate(property, bankAccount);
}
}
return Lists.newArrayList();
}
Aggregations