use of org.estatio.module.charge.dom.ChargeGroup in project estatio by estatio.
the class ChargeImport method importData.
@Override
@Programmatic
public List<Object> importData(Object previousRow) {
ChargeGroup chargeGroup = null;
if (getChargeGroupReference() != null) {
chargeGroup = findOrCreateChargeGroup(chargeGroupReference, chargeGroupName);
}
final ApplicationTenancy applicationTenancy = securityApplicationTenancyRepository.findByPath(atPath);
final Applicability applicability = this.applicability != null ? Applicability.valueOf(this.applicability) : Applicability.IN_AND_OUT;
Tax tax = null;
if (getTaxReference() != null) {
tax = taxRepository.findOrCreate(taxReference, taxReference, applicationTenancy);
}
if (getReference() == null) {
setReference(getName());
}
final Charge charge = chargeRepository.upsert(getReference(), getName(), getDescription(), applicationTenancy, applicability, tax, chargeGroup);
if (getParent() != null) {
Charge parentCharge = chargeRepository.findByReference(getParent());
if (parentCharge != null) {
charge.setParent(parentCharge);
}
}
if (externalReference != null) {
charge.setExternalReference(externalReference);
}
if (sortOrder != null) {
charge.setSortOrder(sortOrder);
}
return Lists.newArrayList(charge);
}
use of org.estatio.module.charge.dom.ChargeGroup in project estatio by estatio.
the class ChargeImport method findOrCreateChargeGroup.
private ChargeGroup findOrCreateChargeGroup(final String reference, final String name) {
ChargeGroup chargeGroup = chargeGroupRepository.findChargeGroup(reference);
if (chargeGroup == null) {
chargeGroup = chargeGroupRepository.createChargeGroup(reference, name);
}
chargeGroup.setName(name);
return chargeGroup;
}
use of org.estatio.module.charge.dom.ChargeGroup in project estatio by estatio.
the class InvoiceForLeaseDtoFactory_Test method newItem.
private static InvoiceItemForTesting newItem(final Invoice invoice, final String netAmt, final String grossAmt, final String vatAmt) {
final InvoiceItemForTesting invoiceItem = new InvoiceItemForTesting(invoice);
invoiceItem.setInvoice(invoice);
final ChargeGroup chargeGroup = new ChargeGroup();
final Charge charge = new Charge();
charge.setGroup(chargeGroup);
invoiceItem.setCharge(charge);
final Tax tax = new Tax();
invoiceItem.setTax(tax);
invoiceItem.setNetAmount(new BigDecimal(netAmt));
invoiceItem.setGrossAmount(new BigDecimal(grossAmt));
invoiceItem.setVatAmount(new BigDecimal(vatAmt));
return invoiceItem;
}
use of org.estatio.module.charge.dom.ChargeGroup 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;
}
use of org.estatio.module.charge.dom.ChargeGroup in project estatio by estatio.
the class LeaseItemForDepositBuilder method execute.
@Override
protected void execute(final ExecutionContext ec) {
defaultParam("charge", ec, Charge_enum.ItDeposit.findUsing(serviceRegistry));
final ChargeGroup group = getCharge().getGroup();
final ChargeGroup_enum expectedGroup = ChargeGroup_enum.Deposit;
if (group != expectedGroup.findUsing(serviceRegistry)) {
throw new IllegalArgumentException("Charge's group must be " + expectedGroup.getRef());
}
LeaseItem leaseItem = new LeaseItemBuilder().setLease(lease).setCharge(charge).setLeaseItemType(LEASE_ITEM_TYPE).setInvoicingFrequency(INVOICING_FREQUENCY).setSequence(sequence).setInvoicedBy(invoicedBy).setPaymentMethod(paymentMethod).setStatus(status).build(this, ec).getObject();
if (sourceItem != null) {
if (leaseItem.getSourceItems().isEmpty()) {
leaseItem.newSourceItem(sourceItem);
}
}
for (LeaseTermForDepositBuilder.TermSpec termSpec : termSpecs) {
final LeaseTermForDeposit term = new LeaseTermForDepositBuilder().setLeaseItem(leaseItem).setStartDate(termSpec.startDate).setEndDate(termSpec.endDate).setFraction(termSpec.fraction).build(this, ec).getObject();
terms.add(term);
}
object = leaseItem;
}
Aggregations