use of com.axelor.apps.contract.db.ContractLine in project axelor-open-suite by axelor.
the class ContractServiceImpl method invoicingContract.
@Override
@Transactional(rollbackOn = { Exception.class })
public Invoice invoicingContract(Contract contract) throws AxelorException {
Invoice invoice = generateInvoice(contract);
InvoiceRepository invoiceRepository = Beans.get(InvoiceRepository.class);
invoiceRepository.save(invoice);
// Compute all additional lines
List<ContractLine> additionalLines = contract.getAdditionalBenefitContractLineList().stream().filter(contractLine -> !contractLine.getIsInvoiced()).peek(contractLine -> contractLine.setIsInvoiced(true)).collect(Collectors.toList());
for (ContractLine line : additionalLines) {
InvoiceLine invLine = generate(invoice, line);
invLine.setContractLine(line);
contractLineRepo.save(line);
}
// Compute all classic contract lines
for (ContractVersion version : getVersions(contract)) {
BigDecimal ratio = BigDecimal.ONE;
if (contract.getCurrentContractVersion().getIsTimeProratedInvoice()) {
if (isFullProrated(contract) && !DateTool.isProrata(contract.getInvoicePeriodStartDate(), contract.getInvoicePeriodEndDate(), version.getActivationDate(), version.getEndDate())) {
continue;
}
LocalDate start = version.getActivationDate().isBefore(contract.getInvoicePeriodStartDate()) ? contract.getInvoicePeriodStartDate() : version.getActivationDate();
LocalDate end = version.getEndDate() == null || (version.getEndDate() != null && contract.getInvoicePeriodEndDate().isBefore(version.getEndDate())) ? contract.getInvoicePeriodEndDate() : version.getEndDate();
ratio = durationService.computeRatio(start, end, contract.getCurrentContractVersion().getInvoicingDuration());
}
List<ContractLine> lines = version.getContractLineList().stream().filter(contractLine -> !contractLine.getIsConsumptionLine()).collect(Collectors.toList());
for (ContractLine line : lines) {
ContractLine tmp = contractLineRepo.copy(line, false);
tmp.setAnalyticMoveLineList(line.getAnalyticMoveLineList());
tmp.setQty(tmp.getQty().multiply(ratio).setScale(appBaseService.getNbDecimalDigitForQty(), RoundingMode.HALF_UP));
tmp = this.contractLineService.computeTotal(tmp);
InvoiceLine invLine = generate(invoice, tmp);
invLine.setContractLine(line);
}
}
// Compute all consumption lines
Multimap<ContractLine, ConsumptionLine> consLines = mergeConsumptionLines(contract);
for (Entry<ContractLine, Collection<ConsumptionLine>> entries : consLines.asMap().entrySet()) {
ContractLine line = entries.getKey();
InvoiceLine invoiceLine = generate(invoice, line);
invoiceLine.setContractLine(line);
entries.getValue().stream().peek(cons -> cons.setInvoiceLine(invoiceLine)).forEach(cons -> cons.setIsInvoiced(true));
line.setQty(BigDecimal.ZERO);
contractLineService.computeTotal(line);
}
// Compute invoice
if (invoice.getInvoiceLineList() != null && !invoice.getInvoiceLineList().isEmpty()) {
Beans.get(InvoiceServiceImpl.class).compute(invoice);
}
// Increase invoice period date
increaseInvoiceDates(contract);
return invoiceRepository.save(invoice);
}
use of com.axelor.apps.contract.db.ContractLine in project axelor-open-suite by axelor.
the class ContractServiceImpl method copyFromTemplate.
@Transactional(rollbackOn = { Exception.class })
public Contract copyFromTemplate(Contract contract, ContractTemplate template) throws AxelorException {
if (template.getAdditionalBenefitContractLineList() != null && !template.getAdditionalBenefitContractLineList().isEmpty()) {
for (ContractLine line : template.getAdditionalBenefitContractLineList()) {
ContractLine newLine = contractLineRepo.copy(line, false);
contractLineService.compute(newLine, contract, newLine.getProduct());
contractLineService.computeTotal(newLine);
contractLineRepo.save(newLine);
contract.addAdditionalBenefitContractLineListItem(newLine);
}
}
contract.setCompany(template.getCompany());
contract.setCurrency(template.getCurrency());
contract.setIsAdditionaBenefitManagement(template.getIsAdditionaBenefitManagement());
contract.setIsConsumptionManagement(template.getIsConsumptionManagement());
contract.setIsInvoicingManagement(template.getIsInvoicingManagement());
contract.setName(template.getName());
contract.setNote(template.getNote());
ContractVersion version = new ContractVersion();
if (template.getContractLineList() != null && !template.getContractLineList().isEmpty()) {
for (ContractLine line : template.getContractLineList()) {
ContractLine newLine = contractLineRepo.copy(line, false);
contractLineService.compute(newLine, contract, newLine.getProduct());
contractLineService.computeTotal(newLine);
contractLineRepo.save(newLine);
version.addContractLineListItem(newLine);
}
}
version.setIsConsumptionBeforeEndDate(template.getIsConsumptionBeforeEndDate());
version.setIsPeriodicInvoicing(template.getIsPeriodicInvoicing());
version.setIsProratedFirstInvoice(template.getIsProratedFirstInvoice());
version.setIsProratedInvoice(template.getIsProratedInvoice());
version.setIsProratedLastInvoice(template.getIsProratedLastInvoice());
version.setIsTacitRenewal(template.getIsTacitRenewal());
version.setIsTimeProratedInvoice(template.getIsTimeProratedInvoice());
version.setIsVersionProratedInvoice(template.getIsVersionProratedInvoice());
version.setIsWithEngagement(template.getIsWithEngagement());
version.setIsWithPriorNotice(template.getIsWithPriorNotice());
version.setIsAutoEnableVersionOnRenew(template.getIsAutoEnableVersionOnRenew());
version.setAutomaticInvoicing(template.getAutomaticInvoicing());
version.setEngagementDuration(template.getEngagementDuration());
version.setEngagementStartFromVersion(template.getEngagementStartFromVersion());
version.setInvoicingDuration(template.getInvoicingDuration());
version.setInvoicingMomentSelect(template.getInvoicingMomentSelect());
version.setPaymentCondition(template.getPaymentCondition());
version.setPaymentMode(template.getPaymentMode());
version.setPriorNoticeDuration(template.getPriorNoticeDuration());
version.setRenewalDuration(template.getRenewalDuration());
version.setDescription(template.getDescription());
contract.setCurrentContractVersion(version);
return contract;
}
use of com.axelor.apps.contract.db.ContractLine in project axelor-open-suite by axelor.
the class ContractLineController method computeTotal.
public void computeTotal(ActionRequest request, ActionResponse response) {
ContractLine contractLine = request.getContext().asType(ContractLine.class);
ContractLineService contractLineService = Beans.get(ContractLineService.class);
try {
contractLine = contractLineService.computeTotal(contractLine);
response.setValues(contractLine);
} catch (Exception e) {
response.setValues(contractLineService.reset(contractLine));
}
}
use of com.axelor.apps.contract.db.ContractLine in project axelor-open-suite by axelor.
the class ContractTemplateController method changeProduct.
public void changeProduct(ActionRequest request, ActionResponse response) {
ContractLineService contractLineService = Beans.get(ContractLineService.class);
ContractLine contractLine = new ContractLine();
try {
contractLine = request.getContext().asType(ContractLine.class);
Product product = contractLine.getProduct();
contractLine = contractLineService.fill(contractLine, product);
response.setValues(contractLine);
} catch (Exception e) {
response.setValues(contractLineService.reset(contractLine));
}
}
use of com.axelor.apps.contract.db.ContractLine in project axelor-open-suite by axelor.
the class ContractVersionRepository method copy.
public ContractVersion copy(Contract contract) {
ContractVersion newVersion = new ContractVersion();
ContractVersion currentVersion = contract.getCurrentContractVersion();
newVersion.setStatusSelect(ContractVersionRepository.DRAFT_VERSION);
newVersion.setNextContract(contract);
newVersion.setPaymentMode(currentVersion.getPaymentMode());
newVersion.setPaymentCondition(currentVersion.getPaymentCondition());
newVersion.setInvoicingDuration(currentVersion.getInvoicingDuration());
newVersion.setInvoicingMomentSelect(currentVersion.getInvoicingMomentSelect());
newVersion.setIsPeriodicInvoicing(currentVersion.getIsPeriodicInvoicing());
newVersion.setAutomaticInvoicing(currentVersion.getAutomaticInvoicing());
newVersion.setIsProratedInvoice(currentVersion.getIsProratedInvoice());
newVersion.setIsProratedFirstInvoice(currentVersion.getIsProratedFirstInvoice());
newVersion.setIsProratedLastInvoice(currentVersion.getIsProratedLastInvoice());
newVersion.setDescription(currentVersion.getDescription());
newVersion.setIsTacitRenewal(currentVersion.getIsTacitRenewal());
newVersion.setRenewalDuration(currentVersion.getRenewalDuration());
newVersion.setIsAutoEnableVersionOnRenew(currentVersion.getIsAutoEnableVersionOnRenew());
newVersion.setIsWithEngagement(currentVersion.getIsWithEngagement());
newVersion.setEngagementDuration(currentVersion.getEngagementDuration());
newVersion.setIsWithPriorNotice(currentVersion.getIsWithPriorNotice());
newVersion.setPriorNoticeDuration(currentVersion.getPriorNoticeDuration());
newVersion.setEngagementStartFromVersion(currentVersion.getEngagementStartFromVersion());
newVersion.setDoNotRenew(currentVersion.getDoNotRenew());
ContractLineRepository repository = Beans.get(ContractLineRepository.class);
List<ContractLine> lines = ModelTool.copy(repository, currentVersion.getContractLineList(), false);
newVersion.setContractLineList(lines);
newVersion.setIsTimeProratedInvoice(currentVersion.getIsTimeProratedInvoice());
newVersion.setIsVersionProratedInvoice(currentVersion.getIsVersionProratedInvoice());
newVersion.setIsConsumptionBeforeEndDate(currentVersion.getIsConsumptionBeforeEndDate());
newVersion.setIsConsumptionManagement(currentVersion.getIsConsumptionManagement());
return newVersion;
}
Aggregations