use of com.axelor.apps.contract.db.ContractVersion in project axelor-open-suite by axelor.
the class ContractServiceImpl method terminateContract.
@Override
@Transactional(rollbackOn = { Exception.class })
public void terminateContract(Contract contract, Boolean isManual, LocalDate date) throws AxelorException {
ContractVersion currentVersion = contract.getCurrentContractVersion();
if (currentVersion.getIsTacitRenewal() && !currentVersion.getDoNotRenew()) {
renewContract(contract, date);
return;
}
contract.setTerminatedManually(isManual);
contract.setTerminatedDate(date);
if (isManual) {
contract.setTerminationDemandDate(appBaseService.getTodayDate(contract.getCompany()));
contract.setTerminatedByUser(AuthUtils.getUser());
}
contract.setEndDate(date);
close(contract, date);
save(contract);
}
use of com.axelor.apps.contract.db.ContractVersion in project axelor-open-suite by axelor.
the class ContractServiceImpl method activeNextVersion.
@Override
@Transactional(rollbackOn = { Exception.class })
public void activeNextVersion(Contract contract, LocalDate date) throws AxelorException {
ContractVersion currentVersion = contract.getCurrentContractVersion();
// Terminate currentVersion
versionService.terminate(currentVersion, date.minusDays(1));
// Archive current version
archiveVersion(contract, date);
if (contract.getCurrentContractVersion().getDoNotRenew()) {
contract.getCurrentContractVersion().setIsTacitRenewal(false);
}
// Ongoing current version
ongoingCurrentVersion(contract, date);
save(contract);
}
use of com.axelor.apps.contract.db.ContractVersion in project axelor-open-suite by axelor.
the class ContractServiceImpl method mergeConsumptionLines.
@Override
public Multimap<ContractLine, ConsumptionLine> mergeConsumptionLines(Contract contract) {
Multimap<ContractLine, ConsumptionLine> mergedLines = HashMultimap.create();
Stream<ConsumptionLine> lineStream = contract.getConsumptionLineList().stream().filter(c -> !c.getIsInvoiced());
if (contract.getCurrentContractVersion().getIsConsumptionBeforeEndDate()) {
lineStream = lineStream.filter(line -> line.getLineDate().isBefore(contract.getInvoicePeriodEndDate()));
}
lineStream.forEach(line -> {
ContractVersion version = contract.getCurrentContractVersion();
if (isFullProrated(contract)) {
version = versionService.getContractVersion(contract, line.getLineDate());
}
if (version == null) {
line.setIsError(true);
} else {
ContractLine matchLine = contractLineRepo.findOneBy(version, line.getProduct(), line.getReference(), true);
if (matchLine == null) {
line.setIsError(true);
} else {
matchLine.setQty(matchLine.getQty().add(line.getQty()));
contractLineService.computeTotal(matchLine);
line.setIsError(false);
line.setContractLine(matchLine);
mergedLines.put(matchLine, line);
}
}
});
return mergedLines;
}
use of com.axelor.apps.contract.db.ContractVersion in project axelor-open-suite by axelor.
the class ContractRepository method copy.
@Override
public Contract copy(Contract entity, boolean deep) {
Contract contract = super.copy(entity, deep);
ContractVersion version = Beans.get(ContractVersionRepository.class).copy(entity);
contract.setCurrentContractVersion(version);
return contract;
}
use of com.axelor.apps.contract.db.ContractVersion in project axelor-open-suite by axelor.
the class InvoiceGeneratorContract method createInvoiceHeader.
@Override
protected Invoice createInvoiceHeader() throws AxelorException {
Invoice invoice = super.createInvoiceHeader();
ContractVersion version = contract.getCurrentContractVersion();
if (contract.getIsInvoicingManagement() && version.getIsPeriodicInvoicing()) {
invoice.setOperationSubTypeSelect(InvoiceRepository.OPERATION_SUB_TYPE_CONTRACT_PERIODIC_INVOICE);
invoice.setSubscriptionFromDate(contract.getInvoicePeriodStartDate());
invoice.setSubscriptionToDate(contract.getInvoicePeriodEndDate());
} else if (contract.getEndDate() == null || contract.getEndDate().isAfter(appBaseService.getTodayDate(company))) {
invoice.setOperationSubTypeSelect(InvoiceRepository.OPERATION_SUB_TYPE_CONTRACT_INVOICE);
} else {
invoice.setOperationSubTypeSelect(InvoiceRepository.OPERATION_SUB_TYPE_CONTRACT_CLOSING_INVOICE);
}
invoice.setContract(contract);
if (contract.getInvoicingDate() != null) {
invoice.setInvoiceDate(contract.getInvoicingDate());
} else {
invoice.setInvoiceDate(appBaseService.getTodayDate(company));
}
return invoice;
}
Aggregations