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);
}
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);
}
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;
}
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;
}
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);
}
Aggregations