Search in sources :

Example 1 with Contract

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

the class ContractVersionController method newDraft.

public void newDraft(ActionRequest request, ActionResponse response) {
    Long contractId = Long.valueOf(request.getContext().get("_xContractId").toString());
    Contract contract = Beans.get(ContractRepository.class).find(contractId);
    ContractVersion newVersion = Beans.get(ContractVersionService.class).newDraft(contract);
    response.setValues(Mapper.toMap(newVersion));
}
Also used : ContractVersionService(com.axelor.apps.contract.service.ContractVersionService) ContractRepository(com.axelor.apps.contract.db.repo.ContractRepository) Contract(com.axelor.apps.contract.db.Contract) ContractVersion(com.axelor.apps.contract.db.ContractVersion)

Example 2 with Contract

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

the class ContractController method saveNextVersion.

public void saveNextVersion(ActionRequest request, ActionResponse response) {
    final ContractVersion version = JPA.find(ContractVersion.class, request.getContext().asType(ContractVersion.class).getId());
    if (version.getNextContract() != null) {
        return;
    }
    Object xContractId = request.getContext().get("_xContractId");
    Long contractId;
    if (xContractId != null) {
        contractId = Long.valueOf(xContractId.toString());
    } else if (version.getContract() != null) {
        contractId = version.getContract().getId();
    } else {
        contractId = null;
    }
    if (contractId == null) {
        return;
    }
    JPA.runInTransaction(new Runnable() {

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

Example 3 with Contract

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

the class ContractController method renew.

public void renew(ActionRequest request, ActionResponse response) {
    Contract contract = Beans.get(ContractRepository.class).find(request.getContext().asType(Contract.class).getId());
    try {
        Beans.get(ContractService.class).renewContract(contract, getTodayDate(contract.getCompany()));
        response.setReload(true);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : ContractRepository(com.axelor.apps.contract.db.repo.ContractRepository) ContractService(com.axelor.apps.contract.service.ContractService) Contract(com.axelor.apps.contract.db.Contract)

Example 4 with Contract

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

the class ContractController 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);
        Contract contract = request.getContext().getParent().asType(Contract.class);
        Product product = contractLine.getProduct();
        contractLine = contractLineService.fillAndCompute(contractLine, contract, product);
        response.setValues(contractLine);
    } catch (Exception e) {
        response.setValues(contractLineService.reset(contractLine));
    }
}
Also used : ContractLine(com.axelor.apps.contract.db.ContractLine) ContractLineService(com.axelor.apps.contract.service.ContractLineService) Product(com.axelor.apps.base.db.Product) Contract(com.axelor.apps.contract.db.Contract)

Example 5 with Contract

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

the class ContractController method close.

public void close(ActionRequest request, ActionResponse response) {
    Contract contract = Beans.get(ContractRepository.class).find(request.getContext().asType(Contract.class).getId());
    ContractService service = Beans.get(ContractService.class);
    try {
        service.checkCanTerminateContract(contract);
        service.close(contract, contract.getTerminatedDate());
        response.setReload(true);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : ContractRepository(com.axelor.apps.contract.db.repo.ContractRepository) ContractService(com.axelor.apps.contract.service.ContractService) Contract(com.axelor.apps.contract.db.Contract)

Aggregations

Contract (com.axelor.apps.contract.db.Contract)21 ContractRepository (com.axelor.apps.contract.db.repo.ContractRepository)10 ContractVersion (com.axelor.apps.contract.db.ContractVersion)9 ContractService (com.axelor.apps.contract.service.ContractService)7 ContractLine (com.axelor.apps.contract.db.ContractLine)6 AxelorException (com.axelor.exception.AxelorException)5 InvoiceGeneratorContract (com.axelor.apps.contract.generator.InvoiceGeneratorContract)4 Invoice (com.axelor.apps.account.db.Invoice)3 ConsumptionLine (com.axelor.apps.contract.db.ConsumptionLine)3 ContractTemplate (com.axelor.apps.contract.db.ContractTemplate)3 ContractVersionRepository (com.axelor.apps.contract.db.repo.ContractVersionRepository)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