Search in sources :

Example 1 with FinancialAccount

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);
    }
}
Also used : FinancialAccount(org.estatio.module.financial.dom.FinancialAccount) Action(org.apache.isis.applib.annotation.Action)

Example 2 with FinancialAccount

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;
}
Also used : AgreementType(org.estatio.module.agreement.dom.type.AgreementType) FinancialAccountType(org.estatio.module.financial.dom.FinancialAccountType) Party(org.estatio.module.party.dom.Party) AgreementRoleType(org.estatio.module.agreement.dom.role.AgreementRoleType) FinancialAccount(org.estatio.module.financial.dom.FinancialAccount) Programmatic(org.apache.isis.applib.annotation.Programmatic)

Example 3 with FinancialAccount

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);
    }
}
Also used : FinancialAccountType(org.estatio.module.financial.dom.FinancialAccountType) FinancialAccount(org.estatio.module.financial.dom.FinancialAccount) Test(org.junit.Test)

Example 4 with FinancialAccount

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;
}
Also used : BankAccountsAndMandatesDto(org.estatio.canonical.bankmandate.v1.BankAccountsAndMandatesDto) BankAccountDto(org.estatio.canonical.financial.v1.BankAccountDto) DtoFactoryAbstract(org.estatio.module.base.platform.applib.DtoFactoryAbstract) FinancialAccount(org.estatio.module.financial.dom.FinancialAccount) BankMandateDto(org.estatio.canonical.bankmandate.v1.BankMandateDto) AgreementType(org.estatio.module.agreement.dom.type.AgreementType) AgreementTypeRepository(org.estatio.module.agreement.dom.type.AgreementTypeRepository) DomainService(org.apache.isis.applib.annotation.DomainService) BankAccountDto(org.estatio.canonical.financial.v1.BankAccountDto) FinancialAccountRepository(org.estatio.module.financial.dom.FinancialAccountRepository) Programmatic(org.apache.isis.applib.annotation.Programmatic) Inject(javax.inject.Inject) BankMandateAgreementRoleTypeEnum(org.estatio.module.bankmandate.dom.BankMandateAgreementRoleTypeEnum) AgreementRole(org.estatio.module.agreement.dom.AgreementRole) BankAccountsAndMandatesDto(org.estatio.canonical.bankmandate.v1.BankAccountsAndMandatesDto) BankAccount(org.estatio.module.financial.dom.BankAccount) NatureOfService(org.apache.isis.applib.annotation.NatureOfService) BankMandateAgreementTypeEnum(org.estatio.module.bankmandate.dom.BankMandateAgreementTypeEnum) Party(org.estatio.module.party.dom.Party) AgreementRoleTypeRepository(org.estatio.module.agreement.dom.role.AgreementRoleTypeRepository) Collectors(java.util.stream.Collectors) AgreementRoleType(org.estatio.module.agreement.dom.role.AgreementRoleType) List(java.util.List) BankAccountDtoFactory(org.estatio.module.financial.canonical.v1.BankAccountDtoFactory) AgreementRoleRepository(org.estatio.module.agreement.dom.AgreementRoleRepository) BankMandate(org.estatio.module.bankmandate.dom.BankMandate) FinancialAccountType(org.estatio.module.financial.dom.FinancialAccountType) AgreementType(org.estatio.module.agreement.dom.type.AgreementType) AgreementRole(org.estatio.module.agreement.dom.AgreementRole) AgreementRoleType(org.estatio.module.agreement.dom.role.AgreementRoleType) FinancialAccount(org.estatio.module.financial.dom.FinancialAccount) BankMandateDto(org.estatio.canonical.bankmandate.v1.BankMandateDto) Programmatic(org.apache.isis.applib.annotation.Programmatic)

Example 5 with FinancialAccount

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;
    }
}
Also used : FixedAssetFinancialAccount(org.estatio.module.assetfinancial.dom.FixedAssetFinancialAccount) Party(org.estatio.module.party.dom.Party) FinancialAccount(org.estatio.module.financial.dom.FinancialAccount) FixedAssetFinancialAccount(org.estatio.module.assetfinancial.dom.FixedAssetFinancialAccount) BankAccount(org.estatio.module.financial.dom.BankAccount) Property(org.estatio.module.asset.dom.Property) Programmatic(org.apache.isis.applib.annotation.Programmatic)

Aggregations

FinancialAccount (org.estatio.module.financial.dom.FinancialAccount)8 Programmatic (org.apache.isis.applib.annotation.Programmatic)5 BankAccount (org.estatio.module.financial.dom.BankAccount)4 FinancialAccountType (org.estatio.module.financial.dom.FinancialAccountType)4 Party (org.estatio.module.party.dom.Party)4 AgreementRoleType (org.estatio.module.agreement.dom.role.AgreementRoleType)2 AgreementType (org.estatio.module.agreement.dom.type.AgreementType)2 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Inject (javax.inject.Inject)1 Action (org.apache.isis.applib.annotation.Action)1 DomainService (org.apache.isis.applib.annotation.DomainService)1 NatureOfService (org.apache.isis.applib.annotation.NatureOfService)1 BankAccountsAndMandatesDto (org.estatio.canonical.bankmandate.v1.BankAccountsAndMandatesDto)1 BankMandateDto (org.estatio.canonical.bankmandate.v1.BankMandateDto)1 BankAccountDto (org.estatio.canonical.financial.v1.BankAccountDto)1 AgreementRole (org.estatio.module.agreement.dom.AgreementRole)1 AgreementRoleRepository (org.estatio.module.agreement.dom.AgreementRoleRepository)1 AgreementRoleTypeRepository (org.estatio.module.agreement.dom.role.AgreementRoleTypeRepository)1 AgreementTypeRepository (org.estatio.module.agreement.dom.type.AgreementTypeRepository)1