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;
}
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);
}
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;
}
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);
}
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);
}
}
Aggregations