use of org.estatio.module.charge.dom.Charge 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.charge.dom.Charge in project estatio by estatio.
the class BudgetAssignmentService_Test method findOrCreateLeaseItemForServiceChargeBudgeted_works_when_item_to_copy_from_found.
@Test
public void findOrCreateLeaseItemForServiceChargeBudgeted_works_when_item_to_copy_from_found() throws Exception {
// given
LeaseItem leaseItemToCopyFrom = new LeaseItem();
leaseItemToCopyFrom.setInvoicingFrequency(InvoicingFrequency.QUARTERLY_IN_ADVANCE);
leaseItemToCopyFrom.setPaymentMethod(PaymentMethod.CHEQUE);
BudgetAssignmentService budgetAssignmentService = new BudgetAssignmentService() {
@Override
LeaseItem findItemToCopyFrom(final Lease lease) {
return leaseItemToCopyFrom;
}
};
Charge charge = new Charge();
BudgetCalculationResult budgetCalculationResult = new BudgetCalculationResult();
budgetCalculationResult.setInvoiceCharge(charge);
LocalDate termStartDate = new LocalDate(2018, 1, 1);
// 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(), leaseItemToCopyFrom.getInvoicingFrequency(), leaseItemToCopyFrom.getPaymentMethod(), termStartDate);
}
});
// when
budgetAssignmentService.findOrCreateLeaseItemForServiceChargeBudgeted(mockLease, budgetCalculationResult, termStartDate);
}
use of org.estatio.module.charge.dom.Charge in project estatio by estatio.
the class BudgetOverrideRepository_IntegTest method findByLeaseAndInvoiceCharge.
@Test
public void findByLeaseAndInvoiceCharge() {
// given
Lease leaseTopModel = Lease_enum.OxfTopModel001Gb.findUsing(serviceRegistry);
Charge invoiceCharge = Charge_enum.GbServiceCharge.findUsing(serviceRegistry);
BigDecimal overrideValue = new BigDecimal("1234.56");
String reason = "Some reason";
// when
BudgetOverrideForFixed budgetOverrideForFixed = wrap(budgetOverrideRepository).newBudgetOverrideForFixed(overrideValue, leaseTopModel, null, null, invoiceCharge, null, null, reason);
// then
assertThat(budgetOverrideRepository.findByLeaseAndInvoiceCharge(leaseTopModel, invoiceCharge).size()).isEqualTo(1);
assertThat(budgetOverrideRepository.findByLeaseAndInvoiceCharge(leaseTopModel, invoiceCharge).get(0)).isEqualTo(budgetOverrideForFixed);
}
use of org.estatio.module.charge.dom.Charge in project estatio by estatio.
the class Project_CreateMissingItems method chargesLinkedNotOnItems.
private List<Charge> chargesLinkedNotOnItems() {
List<Charge> result = new ArrayList<>();
Project_OrderItemsNotOnProjectItem orderItemsMixin = new Project_OrderItemsNotOnProjectItem(project);
serviceRegistry2.injectServicesInto(orderItemsMixin);
for (Charge chargeCandidate : orderItemsMixin.orderItemsNotOnProjectItem().stream().filter(x -> x.getCharge() != null).map(x -> x.getCharge()).collect(Collectors.toList())) {
if (!result.contains(chargeCandidate)) {
result.add(chargeCandidate);
}
}
Project_InvoiceItemsNotOnProjectItem invoiceItemsMixin = new Project_InvoiceItemsNotOnProjectItem(project);
serviceRegistry2.injectServicesInto(invoiceItemsMixin);
for (Charge chargeCandidate : invoiceItemsMixin.invoiceItemsNotOnProjectItem().stream().filter(x -> x.getCharge() != null).map(x -> x.getCharge()).collect(Collectors.toList())) {
if (!result.contains(chargeCandidate)) {
result.add(chargeCandidate);
}
}
return result;
}
use of org.estatio.module.charge.dom.Charge in project estatio by estatio.
the class InvoiceItemForLeaseDtoFactory method newDto.
@Programmatic
public InvoiceItemDto newDto(final InvoiceItem item) {
InvoiceItemDto dto = new InvoiceItemDto();
if (item instanceof InvoiceItemForLease) {
InvoiceItemForLease invoiceItemForLease = (InvoiceItemForLease) item;
final Lease lease = invoiceItemForLease.getLease();
if (lease != null) {
dto.setAgreementReference(lease.getReference());
}
final FixedAsset fixedAsset = invoiceItemForLease.getFixedAsset();
if (fixedAsset != null) {
dto.setFixedAssetReference(fixedAsset.getReference());
dto.setFixedAssetExternalReference(fixedAsset.getExternalReference());
}
}
final Charge charge = item.getCharge();
dto.setChargeReference(charge.getReference());
dto.setChargeDescription(charge.getDescription());
dto.setChargeExternalReference(charge.getExternalReference());
dto.setChargeName(charge.getName());
final ChargeGroup group = charge.getGroup();
dto.setChargeGroupReference(group.getReference());
dto.setChargeGroupName(group.getName());
final Tax tax = item.getTax();
final TaxRate rate = item.getTaxRate();
dto.setTaxReference(tax.getReference());
dto.setTaxName(tax.getName());
dto.setTaxDescription(tax.getDescription());
dto.setTaxExternalReference(rate == null || rate.getExternalReference() == null ? tax.getExternalReference() : rate.getExternalReference());
dto.setNetAmount(item.getNetAmount());
dto.setGrossAmount(item.getGrossAmount());
dto.setVatAmount(item.getVatAmount());
dto.setDescription(item.getDescription());
dto.setStartDate(asXMLGregorianCalendar(item.getStartDate()));
dto.setEndDate(asXMLGregorianCalendar(item.getEndDate()));
dto.setEffectiveStartDate(asXMLGregorianCalendar(firstNonNull(item.getEffectiveStartDate(), item.getStartDate())));
dto.setEffectiveEndDate(asXMLGregorianCalendar(firstNonNull(item.getEffectiveEndDate(), item.getEndDate())));
if (item instanceof InvoiceItemForLease) {
final InvoiceItemForLease invoiceItemForLease = (InvoiceItemForLease) item;
final InvoiceForLease invoice = (InvoiceForLease) invoiceItemForLease.getInvoice();
final Lease leaseIfAny = invoice.getLease();
if (leaseIfAny != null) {
final SortedSet<Occupancy> occupancies = leaseIfAny.getOccupancies();
if (!occupancies.isEmpty()) {
// final Optional<Occupancy> occupancyIfAny =
// occupancies.stream().filter(x -> x.getInterval().overlaps(item.getEffectiveInterval())).findFirst();
final Optional<Occupancy> occupancyIfAny = Optional.ofNullable(occupancies.first());
if (occupancyIfAny.isPresent()) {
final Occupancy occupancy = occupancyIfAny.orElse(occupancies.last());
final Brand brand = occupancy.getBrand();
dto.setOccupancyBrand(brand == null ? null : brand.getName());
if (dto.getFixedAssetReference() == null) {
// the unit was not retrieved through the invoice item, so get it from the occupancy then.
dto.setFixedAssetReference(occupancy.getUnit().getReference());
dto.setFixedAssetExternalReference(occupancy.getUnit().getExternalReference());
}
} else {
// throw new IllegalArgumentException("Invoice has an effective date range outside the scope of the occupanies");
throw new IllegalArgumentException("No Occupancy Found");
}
}
}
}
return dto;
}
Aggregations