Search in sources :

Example 1 with PaymentMethod

use of org.estatio.module.invoice.dom.PaymentMethod 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 2 with PaymentMethod

use of org.estatio.module.invoice.dom.PaymentMethod in project estatio by estatio.

the class BudgetAssignmentService_Test method findOrCreateLeaseItemForServiceChargeBudgeted_works_when_no_item_to_copy_from_found.

@Test
public void findOrCreateLeaseItemForServiceChargeBudgeted_works_when_no_item_to_copy_from_found() throws Exception {
    // given
    BudgetAssignmentService budgetAssignmentService = new BudgetAssignmentService() {

        @Override
        LeaseItem findItemToCopyFrom(final Lease lease) {
            return null;
        }
    };
    Charge charge = new Charge();
    BudgetCalculationResult budgetCalculationResult = new BudgetCalculationResult();
    budgetCalculationResult.setInvoiceCharge(charge);
    LocalDate termStartDate = new LocalDate(2018, 1, 1);
    InvoicingFrequency invoicingFrequencyGuess = InvoicingFrequency.QUARTERLY_IN_ADVANCE;
    PaymentMethod paymentMethodGuess = PaymentMethod.DIRECT_DEBIT;
    // expect
    context.checking(new Expectations() {

        {
            oneOf(mockLease).findFirstActiveItemOfTypeAndChargeOnDate(LeaseItemType.SERVICE_CHARGE, charge, termStartDate);
            will(returnValue(null));
            oneOf(mockLease).newItem(LeaseItemType.SERVICE_CHARGE, LeaseAgreementRoleTypeEnum.LANDLORD, budgetCalculationResult.getInvoiceCharge(), invoicingFrequencyGuess, paymentMethodGuess, termStartDate);
        }
    });
    // when
    budgetAssignmentService.findOrCreateLeaseItemForServiceChargeBudgeted(mockLease, budgetCalculationResult, termStartDate);
}
Also used : Expectations(org.jmock.Expectations) Lease(org.estatio.module.lease.dom.Lease) Charge(org.estatio.module.charge.dom.Charge) PaymentMethod(org.estatio.module.invoice.dom.PaymentMethod) LocalDate(org.joda.time.LocalDate) BudgetCalculationResult(org.estatio.module.budgetassignment.dom.calculationresult.BudgetCalculationResult) InvoicingFrequency(org.estatio.module.lease.dom.InvoicingFrequency) Test(org.junit.Test)

Example 3 with PaymentMethod

use of org.estatio.module.invoice.dom.PaymentMethod in project estatio by estatio.

the class InvoiceImportLine method importData.

@Override
@Programmatic
public List<Object> importData(final Object previousRow) {
    List<Object> result = new ArrayList<>();
    Lease lease = fetchLease(getLeaseReference());
    PaymentMethod paymentMethod = fetchPaymentMethod(getPaymentMethod());
    String atPath = lease.getApplicationTenancyPath().concat("/").concat(lease.getPrimaryParty().getReference());
    ApplicationTenancy applicationTenancy = applicationTenancyRepository.findByPath(atPath);
    Invoice invoice = invoiceForLeaseRepository.newInvoice(applicationTenancy, lease.getPrimaryParty(), lease.getSecondaryParty(), paymentMethod, currencyRepository.findCurrency("EUR"), getDueDate(), lease, null);
    InvoiceItem invoiceItem = factoryService.mixin(InvoiceForLease._newItem.class, invoice).$$(fetchCharge(getItemChargeReference()), BigDecimal.ONE, getItemNetAmount(), getItemStartDate(), getItemEndDate());
    if (getItemDescription() != null) {
        invoiceItem.setDescription(getItemDescription());
    }
    result.add(invoice);
    return result;
}
Also used : Invoice(org.estatio.module.invoice.dom.Invoice) InvoiceItem(org.estatio.module.invoice.dom.InvoiceItem) Lease(org.estatio.module.lease.dom.Lease) InvoiceForLease(org.estatio.module.lease.dom.invoicing.InvoiceForLease) ArrayList(java.util.ArrayList) PaymentMethod(org.estatio.module.invoice.dom.PaymentMethod) DomainObject(org.apache.isis.applib.annotation.DomainObject) ApplicationTenancy(org.isisaddons.module.security.dom.tenancy.ApplicationTenancy) Programmatic(org.apache.isis.applib.annotation.Programmatic)

Example 4 with PaymentMethod

use of org.estatio.module.invoice.dom.PaymentMethod in project estatio by estatio.

the class InvoiceImportManager method getLines.

@Action(semantics = SemanticsOf.SAFE)
@ActionLayout(contributed = Contributed.AS_ASSOCIATION)
public List<InvoiceImportLine> getLines() {
    List<InvoiceImportLine> result = new ArrayList<>();
    for (Lease lease : leaseRepository.findByAssetAndActiveOnDate(getProperty(), clockService.now())) {
        PaymentMethod paymentMethod = null;
        Unit unit = lease.primaryOccupancy().get().getUnit();
        if (lease.getItems().size() > 0) {
            if (leaseItemRepository.findLeaseItemsByType(lease, LeaseItemType.RENT).size() > 0) {
                paymentMethod = leaseItemRepository.findLeaseItemsByType(lease, LeaseItemType.RENT).get(0).getPaymentMethod();
            } else {
                paymentMethod = lease.getItems().first().getPaymentMethod();
            }
            result.add(new InvoiceImportLine(lease.getReference(), null, paymentMethod.name(), null, null, null, null, null, unit.getReference()));
        } else {
            result.add(new InvoiceImportLine(lease.getReference(), null, null, null, null, null, null, null, unit.getReference()));
        }
    }
    return result;
}
Also used : Lease(org.estatio.module.lease.dom.Lease) ArrayList(java.util.ArrayList) PaymentMethod(org.estatio.module.invoice.dom.PaymentMethod) Unit(org.estatio.module.asset.dom.Unit) Action(org.apache.isis.applib.annotation.Action) ActionLayout(org.apache.isis.applib.annotation.ActionLayout)

Example 5 with PaymentMethod

use of org.estatio.module.invoice.dom.PaymentMethod in project estatio by estatio.

the class LeaseTermForServiceChargeImport method importData.

@Programmatic
@Override
public List<Object> importData(final Object previousRow) {
    // find or create leaseItem
    final Lease lease = fetchLease(leaseReference);
    final ApplicationTenancy leaseItemApplicationTenancy = ObjectUtils.firstNonNull(securityApplicationTenancyRepository.findByPath(leaseItemAtPath), lease.getApplicationTenancy());
    final Charge charge = fetchCharge(itemChargeReference);
    final LeaseItemType itemType = fetchLeaseItemType(itemTypeName);
    final LocalDate itemStartDateToUse = itemStartDate == null ? lease.getStartDate() : itemStartDate;
    final LeaseAgreementRoleTypeEnum invoicedByToUse = this.invoicedBy == null ? LeaseAgreementRoleTypeEnum.LANDLORD : LeaseAgreementRoleTypeEnum.valueOf(this.invoicedBy);
    final PaymentMethod paymentMethodToUse = itemPaymentMethod == null ? lease.defaultPaymentMethod() : PaymentMethod.valueOf(itemPaymentMethod);
    LeaseItem item = lease.findItem(itemType, charge, itemStartDateToUse, invoicedByToUse);
    if (item == null) {
        item = lease.newItem(itemType, invoicedByToUse, charge, InvoicingFrequency.valueOf(itemInvoicingFrequency), paymentMethodToUse, itemStartDateToUse);
        item.setSequence(itemSequence);
    }
    item.setEpochDate(itemEpochDate);
    item.setNextDueDate(itemNextDueDate);
    final LeaseItemStatus leaseItemStatus = LeaseItemStatus.valueOfElse(itemStatus, LeaseItemStatus.ACTIVE);
    item.setStatus(leaseItemStatus);
    // create term
    LeaseTermForServiceCharge term = (LeaseTermForServiceCharge) item.findTermWithSequence(sequence);
    if (term == null) {
        if (startDate == null) {
            throw new IllegalArgumentException("startDate cannot be empty");
        }
        if (sequence.equals(BigInteger.ONE)) {
            term = (LeaseTermForServiceCharge) item.newTerm(startDate, endDate);
        } else {
            final LeaseTerm previousTerm = item.findTermWithSequence(sequence.subtract(BigInteger.ONE));
            if (previousTerm == null) {
                throw new IllegalArgumentException(String.format("Previous term not found %s", lease.getReference()));
            }
            term = (LeaseTermForServiceCharge) previousTerm.createNext(startDate, endDate);
        }
        term.setSequence(sequence);
    }
    term.setStatus(LeaseTermStatus.valueOf(status));
    // set service charge term values
    term.setBudgetedValue(budgetedValue);
    term.setAuditedValue(auditedValue);
    return Lists.newArrayList(term);
}
Also used : LeaseAgreementRoleTypeEnum(org.estatio.module.lease.dom.LeaseAgreementRoleTypeEnum) Lease(org.estatio.module.lease.dom.Lease) LeaseTermForServiceCharge(org.estatio.module.lease.dom.LeaseTermForServiceCharge) Charge(org.estatio.module.charge.dom.Charge) PaymentMethod(org.estatio.module.invoice.dom.PaymentMethod) LeaseItemStatus(org.estatio.module.lease.dom.LeaseItemStatus) LeaseTermForServiceCharge(org.estatio.module.lease.dom.LeaseTermForServiceCharge) LeaseItemType(org.estatio.module.lease.dom.LeaseItemType) LocalDate(org.joda.time.LocalDate) ApplicationTenancy(org.isisaddons.module.security.dom.tenancy.ApplicationTenancy) LeaseItem(org.estatio.module.lease.dom.LeaseItem) LeaseTerm(org.estatio.module.lease.dom.LeaseTerm) Programmatic(org.apache.isis.applib.annotation.Programmatic)

Aggregations

PaymentMethod (org.estatio.module.invoice.dom.PaymentMethod)5 Lease (org.estatio.module.lease.dom.Lease)4 LocalDate (org.joda.time.LocalDate)3 ArrayList (java.util.ArrayList)2 Programmatic (org.apache.isis.applib.annotation.Programmatic)2 Charge (org.estatio.module.charge.dom.Charge)2 ApplicationTenancy (org.isisaddons.module.security.dom.tenancy.ApplicationTenancy)2 Test (org.junit.Test)2 Action (org.apache.isis.applib.annotation.Action)1 ActionLayout (org.apache.isis.applib.annotation.ActionLayout)1 DomainObject (org.apache.isis.applib.annotation.DomainObject)1 Property (org.estatio.module.asset.dom.Property)1 Unit (org.estatio.module.asset.dom.Unit)1 BudgetCalculationResult (org.estatio.module.budgetassignment.dom.calculationresult.BudgetCalculationResult)1 IncomingInvoice (org.estatio.module.capex.dom.invoice.IncomingInvoice)1 BankAccount (org.estatio.module.financial.dom.BankAccount)1 Invoice (org.estatio.module.invoice.dom.Invoice)1 InvoiceItem (org.estatio.module.invoice.dom.InvoiceItem)1 InvoiceStatus (org.estatio.module.invoice.dom.InvoiceStatus)1 InvoicingFrequency (org.estatio.module.lease.dom.InvoicingFrequency)1