Search in sources :

Example 16 with Contract

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

the class ContractController method invoicing.

public void invoicing(ActionRequest request, ActionResponse response) {
    Contract contract = Beans.get(ContractRepository.class).find(request.getContext().asType(Contract.class).getId());
    try {
        Invoice invoice = Beans.get(ContractService.class).invoicingContract(contract);
        response.setReload(true);
        response.setView(ActionView.define(I18n.get("Invoice")).model(Invoice.class.getName()).add("form", "invoice-form").add("grid", "invoice-grid").param("search-filters", "customer-invoices-filters").param("forceTitle", "true").context("_showRecord", invoice.getId().toString()).map());
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Invoice(com.axelor.apps.account.db.Invoice) ContractRepository(com.axelor.apps.contract.db.repo.ContractRepository) ContractService(com.axelor.apps.contract.service.ContractService) Contract(com.axelor.apps.contract.db.Contract)

Example 17 with Contract

use of com.axelor.apps.contract.db.Contract 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 18 with Contract

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

the class ContractController method waiting.

public void waiting(ActionRequest request, ActionResponse response) {
    Contract contract = Beans.get(ContractRepository.class).find(request.getContext().asType(Contract.class).getId());
    try {
        Beans.get(ContractService.class).waitingCurrentVersion(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 19 with Contract

use of com.axelor.apps.contract.db.Contract 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)

Example 20 with Contract

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

the class ContractVersionController method save.

public void save(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;
    }
    // TODO: move in service
    JPA.runInTransaction(() -> {
        Contract contract = JPA.find(Contract.class, contractId);
        contract.setNextVersion(version);
        Beans.get(ContractRepository.class).save(contract);
    });
    response.setReload(true);
}
Also used : ContractRepository(com.axelor.apps.contract.db.repo.ContractRepository) ContractVersion(com.axelor.apps.contract.db.ContractVersion) 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