Search in sources :

Example 16 with ContractVersion

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

Example 17 with ContractVersion

use of com.axelor.apps.contract.db.ContractVersion in project axelor-open-suite by axelor.

the class ContractServiceImpl method waitingCurrentVersion.

@Override
@Transactional(rollbackOn = { Exception.class })
public void waitingCurrentVersion(Contract contract, LocalDate date) throws AxelorException {
    ContractVersion currentVersion = contract.getCurrentContractVersion();
    versionService.waiting(currentVersion, date);
}
Also used : ContractVersion(com.axelor.apps.contract.db.ContractVersion) Transactional(com.google.inject.persist.Transactional)

Example 18 with ContractVersion

use of com.axelor.apps.contract.db.ContractVersion in project axelor-open-suite by axelor.

the class ContractServiceImpl method increaseInvoiceDates.

@Override
@Transactional
public Contract increaseInvoiceDates(Contract contract) {
    ContractVersion version = contract.getCurrentContractVersion();
    if (version.getIsPeriodicInvoicing()) {
        contract.setInvoicePeriodStartDate(contract.getInvoicePeriodEndDate().plusDays(1));
        contract.setInvoicePeriodEndDate(durationService.computeDuration(version.getInvoicingDuration(), contract.getInvoicePeriodStartDate()).minusDays(1));
    }
    fillInvoicingDateByInvoicingMoment(contract);
    return contract;
}
Also used : ContractVersion(com.axelor.apps.contract.db.ContractVersion) Transactional(com.google.inject.persist.Transactional)

Example 19 with ContractVersion

use of com.axelor.apps.contract.db.ContractVersion in project axelor-open-suite by axelor.

the class ContractController method deleteNextVersion.

public void deleteNextVersion(ActionRequest request, ActionResponse response) {
    final Contract contract = JPA.find(Contract.class, request.getContext().asType(Contract.class).getId());
    // TODO: move this code in Service
    JPA.runInTransaction(new Runnable() {

        @Override
        public void run() {
            ContractVersion version = contract.getNextVersion();
            contract.setNextVersion(null);
            Beans.get(ContractVersionRepository.class).remove(version);
            Beans.get(ContractRepository.class).save(contract);
        }
    });
    response.setReload(true);
}
Also used : Contract(com.axelor.apps.contract.db.Contract) ContractVersion(com.axelor.apps.contract.db.ContractVersion)

Example 20 with ContractVersion

use of com.axelor.apps.contract.db.ContractVersion in project axelor-open-suite by axelor.

the class ContractVersionController method active.

public void active(ActionRequest request, ActionResponse response) {
    try {
        Long id = request.getContext().asType(ContractVersion.class).getId();
        ContractVersion contractVersion = Beans.get(ContractVersionRepository.class).find(id);
        if (contractVersion.getNextContract() == null) {
            response.setError(I18n.get(IExceptionMessage.CONTRACT_VERSION_EMPTY_NEXT_CONTRACT));
            return;
        }
        Beans.get(ContractService.class).activeNextVersion(contractVersion.getNextContract(), getTodayDate(contractVersion.getNextContract().getCompany()));
        response.setView(ActionView.define("Contract").model(Contract.class.getName()).add("form", "contract-form").add("grid", "contract-grid").param("search-filters", "contract-filters").context("_showRecord", contractVersion.getContract().getId()).map());
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : ContractService(com.axelor.apps.contract.service.ContractService) ContractVersion(com.axelor.apps.contract.db.ContractVersion) ContractVersionRepository(com.axelor.apps.contract.db.repo.ContractVersionRepository) Contract(com.axelor.apps.contract.db.Contract)

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