use of org.estatio.module.financial.dom.FinancialAccount in project estatio by estatio.
the class Guarantee method remove.
@Action(semantics = SemanticsOf.NON_IDEMPOTENT_ARE_YOU_SURE)
public void remove(final String reason) {
remove(this);
final FinancialAccount financialAccount = getFinancialAccount();
this.setFinancialAccount(null);
if (financialAccount != null) {
financialAccount.remove(reason);
}
}
use of org.estatio.module.financial.dom.FinancialAccount in project estatio by estatio.
the class GuaranteeRepository method newGuarantee.
@Programmatic
public Guarantee newGuarantee(final Lease lease, @Parameter(regexPattern = ReferenceType.Meta.REGEX, regexPatternReplacement = ReferenceType.Meta.REGEX_DESCRIPTION) final String reference, final String name, final GuaranteeType guaranteeType, final LocalDate startDate, final LocalDate endDate, final String description, final BigDecimal contractualAmount, final BigDecimal startAmount) {
AgreementRoleType artGuarantee = agreementRoleTypeRepository.find(GuaranteeAgreementRoleTypeEnum.GUARANTEE);
Party leasePrimaryParty = lease.getPrimaryParty();
AgreementRoleType artGuarantor = agreementRoleTypeRepository.find(GuaranteeAgreementRoleTypeEnum.GUARANTOR);
Party leaseSecondaryParty = lease.getSecondaryParty();
Guarantee guarantee = newTransientInstance(Guarantee.class);
final AgreementType at = agreementTypeRepository.find(GuaranteeAgreementTypeEnum.GUARANTEE);
guarantee.setType(at);
guarantee.setReference(reference);
guarantee.setDescription(description);
guarantee.setName(name);
guarantee.setStartDate(startDate);
guarantee.setEndDate(endDate);
guarantee.setGuaranteeType(guaranteeType);
guarantee.setLease(lease);
guarantee.setContractualAmount(contractualAmount);
guarantee.newRole(artGuarantee, leasePrimaryParty, null, null);
guarantee.newRole(artGuarantor, leaseSecondaryParty, null, null);
FinancialAccountType financialAccountType = guaranteeType.getFinancialAccountType();
if (financialAccountType != null) {
FinancialAccount financialAccount = financialAccountRepository.newFinancialAccount(financialAccountType, reference, name, leaseSecondaryParty);
guarantee.setFinancialAccount(financialAccount);
if (ObjectUtils.compare(startAmount, BigDecimal.ZERO) > 0) {
financialAccountTransactionRepository.newTransaction(guarantee.getFinancialAccount(), startDate, null, startAmount);
}
}
persistIfNotAlready(guarantee);
return guarantee;
}
use of org.estatio.module.financial.dom.FinancialAccount in project estatio by estatio.
the class FinancialAccountRepository_create_IntegTest method when_bankAccount.
@Test
public void when_bankAccount() throws Exception {
final FinancialAccountType[] financialAccountTypes = FinancialAccountType.values();
for (final FinancialAccountType financialAccountType : financialAccountTypes) {
final String someRef = fakeDataService.strings().fixed(4);
final String someName = fakeDataService.strings().upper(20);
// given
final List<FinancialAccount> before = financialAccountRepository.allAccounts();
// when
final FinancialAccount financialAccount = financialAccountRepository.newFinancialAccount(financialAccountType, someRef, someName, party);
// then
assertThat(financialAccount.getType()).isEqualTo(financialAccountType);
assertThat(financialAccount.getReference()).isEqualTo(someRef);
assertThat(financialAccount.getName()).isEqualTo(someName);
final List<FinancialAccount> after = financialAccountRepository.allAccounts();
assertThat(after).contains(financialAccount);
assertThat(after.size()).isEqualTo(before.size() + 1);
}
}
use of org.estatio.module.financial.dom.FinancialAccount 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.FinancialAccount in project estatio by estatio.
the class DebtorBankAccountService method uniqueDebtorAccountToPay.
@Programmatic
public BankAccount uniqueDebtorAccountToPay(final IncomingInvoice invoice) {
final Party buyer = invoice.getBuyer();
List<BankAccount> bankAccountsForBuyer = bankAccountRepository.findBankAccountsByOwner(buyer);
final Property propertyIfAny = invoice.getProperty();
if (propertyIfAny != null) {
List<FixedAssetFinancialAccount> fafrList = fixedAssetFinancialAccountRepository.findByFixedAsset(propertyIfAny);
List<FinancialAccount> bankAccountsForProperty = fafrList.stream().map(FixedAssetFinancialAccount::getFinancialAccount).filter(BankAccount.class::isInstance).map(BankAccount.class::cast).collect(Collectors.toList());
bankAccountsForBuyer.retainAll(bankAccountsForProperty);
}
// original implementation ... see if we already have a unique bank account
int numBankAccounts = bankAccountsForBuyer.size();
switch(numBankAccounts) {
case 0:
return null;
case 1:
return bankAccountsForBuyer.get(0);
default:
}
// see if removing non-preferred helps
bankAccountsForBuyer.removeIf(x -> (x.getPreferred() == null || !x.getPreferred()));
numBankAccounts = bankAccountsForBuyer.size();
switch(numBankAccounts) {
case 0:
return null;
case 1:
return bankAccountsForBuyer.get(0);
default:
// give up, still non-duplicate
return null;
}
}
Aggregations