Search in sources :

Example 1 with MoveTemplate

use of com.axelor.apps.account.db.MoveTemplate in project axelor-open-suite by axelor.

the class ImportMoveTemplate method importMove.

public Object importMove(Object bean, Map<String, Object> values) throws IOException {
    assert bean instanceof MoveTemplate;
    MoveTemplate moveTemplate = (MoveTemplate) bean;
    try {
        if (moveTemplate.getJournal() != null) {
            moveTemplate.setCompany(moveTemplate.getJournal().getCompany());
            String dateShift = values.get("endOfValidityDateShift").toString();
            if (StringUtils.notBlank(dateShift)) {
                moveTemplate.setEndOfValidityDate(Beans.get(AppBaseService.class).getTodayDate(moveTemplate.getCompany()).plusMonths(Integer.parseInt(dateShift)));
            }
        }
    } catch (Exception e) {
        TraceBackService.trace(e);
    }
    return moveTemplate;
}
Also used : AppBaseService(com.axelor.apps.base.service.app.AppBaseService) MoveTemplate(com.axelor.apps.account.db.MoveTemplate) AxelorException(com.axelor.exception.AxelorException) IOException(java.io.IOException)

Example 2 with MoveTemplate

use of com.axelor.apps.account.db.MoveTemplate in project axelor-open-suite by axelor.

the class MoveTemplateController method checkValidity.

public void checkValidity(ActionRequest request, ActionResponse response) {
    MoveTemplate moveTemplate = request.getContext().asType(MoveTemplate.class);
    moveTemplate = Beans.get(MoveTemplateRepository.class).find(moveTemplate.getId());
    boolean valid = Beans.get(MoveTemplateService.class).checkValidity(moveTemplate);
    if (valid) {
        response.setReload(true);
    } else {
        response.setFlash(I18n.get(IExceptionMessage.MOVE_TEMPLATE_1));
    }
}
Also used : MoveTemplateService(com.axelor.apps.account.service.move.MoveTemplateService) MoveTemplate(com.axelor.apps.account.db.MoveTemplate)

Example 3 with MoveTemplate

use of com.axelor.apps.account.db.MoveTemplate in project axelor-open-suite by axelor.

the class MoveTemplateService method generateMove.

@Transactional(rollbackOn = { Exception.class })
public List<Long> generateMove(LocalDate moveDate, List<HashMap<String, Object>> moveTemplateList) throws AxelorException {
    List<Long> moveList = new ArrayList<>();
    for (HashMap<String, Object> moveTemplateMap : moveTemplateList) {
        MoveTemplate moveTemplate = moveTemplateRepo.find(Long.valueOf((Integer) moveTemplateMap.get("id")));
        if (moveTemplate.getJournal().getCompany() != null) {
            Move move = moveService.getMoveCreateService().createMove(moveTemplate.getJournal(), moveTemplate.getJournal().getCompany(), null, null, moveDate, null, MoveRepository.TECHNICAL_ORIGIN_TEMPLATE, 0);
            int counter = 1;
            for (MoveTemplateLine moveTemplateLine : moveTemplate.getMoveTemplateLineList()) {
                BigDecimal amount = moveTemplateLine.getDebit().add(moveTemplateLine.getCredit());
                MoveLine moveLine = moveLineService.createMoveLine(move, moveTemplateLine.getPartner(), moveTemplateLine.getAccount(), amount, moveTemplateLine.getDebit().compareTo(BigDecimal.ZERO) > 0, moveDate, moveDate, counter, moveTemplate.getFullName(), moveTemplateLine.getName());
                move.getMoveLineList().add(moveLine);
                Tax tax = moveTemplateLine.getTax();
                if (tax != null) {
                    TaxLine taxLine = taxService.getTaxLine(tax, moveDate);
                    if (taxLine != null) {
                        moveLine.setTaxLine(taxLine);
                        moveLine.setTaxRate(taxLine.getValue());
                        moveLine.setTaxCode(tax.getCode());
                    }
                }
                moveLine.setAnalyticDistributionTemplate(moveTemplateLine.getAnalyticDistributionTemplate());
                moveLineService.generateAnalyticMoveLines(moveLine);
                counter++;
            }
            if (moveTemplate.getAutomaticallyValidate()) {
                moveValidateService.validate(move);
            }
            moveRepo.save(move);
            moveList.add(move.getId());
        }
    }
    return moveList;
}
Also used : ArrayList(java.util.ArrayList) Tax(com.axelor.apps.account.db.Tax) MoveTemplate(com.axelor.apps.account.db.MoveTemplate) BigDecimal(java.math.BigDecimal) TaxLine(com.axelor.apps.account.db.TaxLine) Move(com.axelor.apps.account.db.Move) MoveTemplateLine(com.axelor.apps.account.db.MoveTemplateLine) MoveLine(com.axelor.apps.account.db.MoveLine) Transactional(com.google.inject.persist.Transactional)

Example 4 with MoveTemplate

use of com.axelor.apps.account.db.MoveTemplate in project axelor-open-suite by axelor.

the class MoveTemplateController method computeTotals.

public void computeTotals(ActionRequest request, ActionResponse response) {
    try {
        MoveTemplate moveTemplate = request.getContext().asType(MoveTemplate.class);
        Map<String, Object> values = Beans.get(MoveTemplateService.class).computeTotals(moveTemplate);
        response.setValues(values);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : MoveTemplateService(com.axelor.apps.account.service.move.MoveTemplateService) MoveTemplate(com.axelor.apps.account.db.MoveTemplate)

Example 5 with MoveTemplate

use of com.axelor.apps.account.db.MoveTemplate in project axelor-open-suite by axelor.

the class MoveTemplateController method generateMove.

@SuppressWarnings("unchecked")
public void generateMove(ActionRequest request, ActionResponse response) {
    try {
        Context context = request.getContext();
        HashMap<String, Object> moveTemplateTypeMap = (HashMap<String, Object>) context.get("moveTemplateType");
        MoveTemplateType moveTemplateType = Beans.get(MoveTemplateTypeRepository.class).find(Long.parseLong(moveTemplateTypeMap.get("id").toString()));
        HashMap<String, Object> moveTemplateMap = (HashMap<String, Object>) context.get("moveTemplate");
        MoveTemplate moveTemplate = null;
        if (moveTemplateType.getTypeSelect() == MoveTemplateTypeRepository.TYPE_PERCENTAGE) {
            moveTemplate = Beans.get(MoveTemplateRepository.class).find(Long.parseLong(moveTemplateMap.get("id").toString()));
        }
        List<HashMap<String, Object>> dataList = (List<HashMap<String, Object>>) context.get("dataInputList");
        List<HashMap<String, Object>> moveTemplateList = (List<HashMap<String, Object>>) context.get("moveTemplateSet");
        LocalDate moveDate = null;
        if (moveTemplateType.getTypeSelect() == MoveTemplateTypeRepository.TYPE_AMOUNT) {
            moveDate = LocalDate.parse((String) context.get("moveDate"), DateTimeFormatter.ofPattern("yyyy-MM-dd"));
        }
        LOG.debug("MoveTemplate : {}", moveTemplate);
        LOG.debug("Data inputlist : {}", dataList);
        LOG.debug("Data inputlist : {}", moveTemplateList);
        if ((dataList != null && !dataList.isEmpty()) || (moveTemplateList != null && !moveTemplateList.isEmpty())) {
            List<Long> moveList = Beans.get(MoveTemplateService.class).generateMove(moveTemplateType, moveTemplate, dataList, moveDate, moveTemplateList);
            if (moveList != null && !moveList.isEmpty()) {
                response.setView(ActionView.define(I18n.get(IExceptionMessage.MOVE_TEMPLATE_3)).model(Move.class.getName()).add("grid", "move-grid").add("form", "move-form").param("search-filters", "move-filters").domain("self.id in (" + Joiner.on(",").join(moveList) + ")").map());
            }
        } else {
            response.setFlash(I18n.get(IExceptionMessage.MOVE_TEMPLATE_4));
        }
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Context(com.axelor.rpc.Context) HashMap(java.util.HashMap) MoveTemplateType(com.axelor.apps.account.db.MoveTemplateType) MoveTemplate(com.axelor.apps.account.db.MoveTemplate) LocalDate(java.time.LocalDate) MoveTemplateService(com.axelor.apps.account.service.move.MoveTemplateService) Move(com.axelor.apps.account.db.Move) MoveTemplateTypeRepository(com.axelor.apps.account.db.repo.MoveTemplateTypeRepository) List(java.util.List)

Aggregations

MoveTemplate (com.axelor.apps.account.db.MoveTemplate)6 MoveTemplateService (com.axelor.apps.account.service.move.MoveTemplateService)3 Move (com.axelor.apps.account.db.Move)2 Transactional (com.google.inject.persist.Transactional)2 MoveLine (com.axelor.apps.account.db.MoveLine)1 MoveTemplateLine (com.axelor.apps.account.db.MoveTemplateLine)1 MoveTemplateType (com.axelor.apps.account.db.MoveTemplateType)1 Tax (com.axelor.apps.account.db.Tax)1 TaxLine (com.axelor.apps.account.db.TaxLine)1 MoveTemplateTypeRepository (com.axelor.apps.account.db.repo.MoveTemplateTypeRepository)1 AppBaseService (com.axelor.apps.base.service.app.AppBaseService)1 AxelorException (com.axelor.exception.AxelorException)1 Context (com.axelor.rpc.Context)1 IOException (java.io.IOException)1 BigDecimal (java.math.BigDecimal)1 LocalDate (java.time.LocalDate)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1