Search in sources :

Example 6 with ContractVersion

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);
}
Also used : ContractVersion(com.axelor.apps.contract.db.ContractVersion) Transactional(com.google.inject.persist.Transactional)

Example 7 with ContractVersion

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);
}
Also used : ContractVersion(com.axelor.apps.contract.db.ContractVersion) Transactional(com.google.inject.persist.Transactional)

Example 8 with ContractVersion

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;
}
Also used : ConsumptionLine(com.axelor.apps.contract.db.ConsumptionLine) InvoiceLineService(com.axelor.apps.account.service.invoice.InvoiceLineService) ConsumptionLine(com.axelor.apps.contract.db.ConsumptionLine) Inject(com.google.inject.Inject) LoggerFactory(org.slf4j.LoggerFactory) ContractLine(com.axelor.apps.contract.db.ContractLine) InvoiceGeneratorContract(com.axelor.apps.contract.generator.InvoiceGeneratorContract) ContractVersion(com.axelor.apps.contract.db.ContractVersion) Transactional(com.google.inject.persist.Transactional) BigDecimal(java.math.BigDecimal) HashMultimap(com.google.common.collect.HashMultimap) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) TaxLine(com.axelor.apps.account.db.TaxLine) FiscalPositionAccountService(com.axelor.apps.account.service.FiscalPositionAccountService) RoundingMode(java.math.RoundingMode) AnalyticMoveLineRepository(com.axelor.apps.account.db.repo.AnalyticMoveLineRepository) MethodHandles(java.lang.invoke.MethodHandles) Collection(java.util.Collection) InvoiceService(com.axelor.apps.account.service.invoice.InvoiceService) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) Collectors(java.util.stream.Collectors) List(java.util.List) Stream(java.util.stream.Stream) InvoiceLineGenerator(com.axelor.apps.account.service.invoice.generator.InvoiceLineGenerator) DurationService(com.axelor.apps.base.service.DurationService) LocalDate(java.time.LocalDate) Entry(java.util.Map.Entry) ContractVersionRepository(com.axelor.apps.contract.db.repo.ContractVersionRepository) FiscalPosition(com.axelor.apps.account.db.FiscalPosition) PriceListRepository(com.axelor.apps.base.db.repo.PriceListRepository) ContractRepository(com.axelor.apps.contract.db.repo.ContractRepository) Multimap(com.google.common.collect.Multimap) ArrayList(java.util.ArrayList) IExceptionMessage(com.axelor.apps.contract.exception.IExceptionMessage) AxelorException(com.axelor.exception.AxelorException) ConsumptionLineRepository(com.axelor.apps.contract.db.repo.ConsumptionLineRepository) I18n(com.axelor.i18n.I18n) ContractTemplate(com.axelor.apps.contract.db.ContractTemplate) DateTool(com.axelor.apps.tool.date.DateTool) PriceListLineRepository(com.axelor.apps.base.db.repo.PriceListLineRepository) InvoiceServiceImpl(com.axelor.apps.account.service.invoice.InvoiceServiceImpl) AccountManagementService(com.axelor.apps.base.service.tax.AccountManagementService) Logger(org.slf4j.Logger) TraceBackRepository(com.axelor.exception.db.repo.TraceBackRepository) InvoiceLineRepository(com.axelor.apps.account.db.repo.InvoiceLineRepository) ContractLineRepository(com.axelor.apps.contract.db.repo.ContractLineRepository) Invoice(com.axelor.apps.account.db.Invoice) Account(com.axelor.apps.account.db.Account) Contract(com.axelor.apps.contract.db.Contract) InvoiceGenerator(com.axelor.apps.account.service.invoice.generator.InvoiceGenerator) InvoiceRepository(com.axelor.apps.account.db.repo.InvoiceRepository) Beans(com.axelor.inject.Beans) Collections(java.util.Collections) AuthUtils(com.axelor.auth.AuthUtils) AnalyticMoveLine(com.axelor.apps.account.db.AnalyticMoveLine) ContractLine(com.axelor.apps.contract.db.ContractLine) ContractVersion(com.axelor.apps.contract.db.ContractVersion)

Example 9 with ContractVersion

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;
}
Also used : Contract(com.axelor.apps.contract.db.Contract) ContractVersion(com.axelor.apps.contract.db.ContractVersion)

Example 10 with ContractVersion

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;
}
Also used : Invoice(com.axelor.apps.account.db.Invoice) ContractVersion(com.axelor.apps.contract.db.ContractVersion)

Aggregations

ContractVersion (com.axelor.apps.contract.db.ContractVersion)23 Transactional (com.google.inject.persist.Transactional)12 Contract (com.axelor.apps.contract.db.Contract)9 ContractLine (com.axelor.apps.contract.db.ContractLine)5 ContractVersionRepository (com.axelor.apps.contract.db.repo.ContractVersionRepository)5 Invoice (com.axelor.apps.account.db.Invoice)4 ContractRepository (com.axelor.apps.contract.db.repo.ContractRepository)4 AxelorException (com.axelor.exception.AxelorException)3 Account (com.axelor.apps.account.db.Account)2 AnalyticMoveLine (com.axelor.apps.account.db.AnalyticMoveLine)2 FiscalPosition (com.axelor.apps.account.db.FiscalPosition)2 InvoiceLine (com.axelor.apps.account.db.InvoiceLine)2 TaxLine (com.axelor.apps.account.db.TaxLine)2 AnalyticMoveLineRepository (com.axelor.apps.account.db.repo.AnalyticMoveLineRepository)2 InvoiceLineRepository (com.axelor.apps.account.db.repo.InvoiceLineRepository)2 InvoiceRepository (com.axelor.apps.account.db.repo.InvoiceRepository)2 FiscalPositionAccountService (com.axelor.apps.account.service.FiscalPositionAccountService)2 InvoiceLineService (com.axelor.apps.account.service.invoice.InvoiceLineService)2 InvoiceService (com.axelor.apps.account.service.invoice.InvoiceService)2 InvoiceServiceImpl (com.axelor.apps.account.service.invoice.InvoiceServiceImpl)2