Search in sources :

Example 21 with Party

use of org.estatio.module.party.dom.Party in project estatio by estatio.

the class OrderRepository_Test method upsert_when_already_exists.

@Test
public void upsert_when_already_exists() throws Exception {
    // given
    OrderRepository orderRepository = new OrderRepository() {

        @Override
        public Order findByOrderNumber(final String orderNumber) {
            return order;
        }
    };
    String number = "some number";
    String sellerOrderReference = "ref";
    LocalDate entryDate = new LocalDate(2017, 1, 1);
    LocalDate orderDate = new LocalDate(2017, 1, 2);
    Party seller = new Organisation();
    Party buyer = new Organisation();
    Property property = new Property();
    String atPath = "atPath";
    OrderApprovalState approvalState = OrderApprovalState.APPROVED;
    assertThat(order.getOrderNumber()).isNull();
    // when
    orderRepository.upsert(property, number, sellerOrderReference, entryDate, orderDate, seller, buyer, atPath, approvalState);
    // then
    assertThat(order.getOrderNumber()).isNull();
    assertThat(order.getSellerOrderReference()).isEqualTo(sellerOrderReference);
    assertThat(order.getEntryDate()).isEqualTo(entryDate);
    assertThat(order.getOrderDate()).isEqualTo(orderDate);
    assertThat(order.getSeller()).isEqualTo(seller);
    assertThat(order.getBuyer()).isEqualTo(buyer);
    assertThat(order.getProperty()).isEqualTo(property);
    assertThat(order.getAtPath()).isEqualTo(atPath);
    // is ignored.
    assertThat(order.getApprovalState()).isNull();
}
Also used : Party(org.estatio.module.party.dom.Party) Organisation(org.estatio.module.party.dom.Organisation) LocalDate(org.joda.time.LocalDate) Property(org.estatio.module.asset.dom.Property) OrderApprovalState(org.estatio.module.capex.dom.order.approval.OrderApprovalState) Test(org.junit.Test)

Example 22 with Party

use of org.estatio.module.party.dom.Party 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);
}
Also used : Party(org.estatio.module.party.dom.Party) IncomingInvoice(org.estatio.module.capex.dom.invoice.IncomingInvoice) PaymentMethod(org.estatio.module.invoice.dom.PaymentMethod) BankAccount(org.estatio.module.financial.dom.BankAccount) LocalDate(org.joda.time.LocalDate) InvoiceStatus(org.estatio.module.invoice.dom.InvoiceStatus) Property(org.estatio.module.asset.dom.Property) Test(org.junit.Test)

Example 23 with Party

use of org.estatio.module.party.dom.Party in project estatio by estatio.

the class BankAccountRepository_Test method findBankAccountsByOwner_filters_deprecated.

@Test
public void findBankAccountsByOwner_filters_deprecated() throws Exception {
    // given
    BankAccountRepository repo = new BankAccountRepository();
    repo.financialAccountRepository = mockFARepo;
    Party party = new Organisation();
    BankAccount account1 = new BankAccount();
    BankAccount account2 = new BankAccount();
    // expect
    context.checking(new Expectations() {

        {
            oneOf(mockFARepo).findAccountsByTypeOwner(FinancialAccountType.BANK_ACCOUNT, party);
            will(returnValue(Arrays.asList(account1, account2)));
        }
    });
    // when
    List<BankAccount> result = repo.findBankAccountsByOwner(party);
    Assertions.assertThat(result.size()).isEqualTo(2);
    Assertions.assertThat(result).contains(account1);
    Assertions.assertThat(result).contains(account2);
    // and given
    account2.setDeprecated(true);
    // expect
    context.checking(new Expectations() {

        {
            oneOf(mockFARepo).findAccountsByTypeOwner(FinancialAccountType.BANK_ACCOUNT, party);
            will(returnValue(Arrays.asList(account1, account2)));
        }
    });
    // when
    result = repo.findBankAccountsByOwner(party);
    Assertions.assertThat(result.size()).isEqualTo(1);
    Assertions.assertThat(result).contains(account1);
    Assertions.assertThat(result).doesNotContain(account2);
}
Also used : Expectations(org.jmock.Expectations) Party(org.estatio.module.party.dom.Party) Organisation(org.estatio.module.party.dom.Organisation) Test(org.junit.Test)

Example 24 with Party

use of org.estatio.module.party.dom.Party 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 25 with Party

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

Aggregations

Party (org.estatio.module.party.dom.Party)51 Programmatic (org.apache.isis.applib.annotation.Programmatic)22 Test (org.junit.Test)15 Property (org.estatio.module.asset.dom.Property)13 BankAccount (org.estatio.module.financial.dom.BankAccount)13 Organisation (org.estatio.module.party.dom.Organisation)13 IncomingInvoice (org.estatio.module.capex.dom.invoice.IncomingInvoice)10 Expectations (org.jmock.Expectations)10 AgreementRole (org.estatio.module.agreement.dom.AgreementRole)8 ArrayList (java.util.ArrayList)7 AgreementRoleType (org.estatio.module.agreement.dom.role.AgreementRoleType)7 Lease (org.estatio.module.lease.dom.Lease)6 CommunicationChannel (org.incode.module.communications.dom.impl.commchannel.CommunicationChannel)6 List (java.util.List)5 Inject (javax.inject.Inject)4 Action (org.apache.isis.applib.annotation.Action)4 Country (org.incode.module.country.dom.impl.Country)4 LocalDate (org.joda.time.LocalDate)4 Optional (java.util.Optional)3 SortedSet (java.util.SortedSet)3