Search in sources :

Example 76 with Move

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

the class MoveLineController method computeCurrentRate.

public void computeCurrentRate(ActionRequest request, ActionResponse response) {
    try {
        Context parentContext = request.getContext().getParent();
        BigDecimal currencyRate = BigDecimal.ONE;
        if (parentContext != null && Move.class.equals(parentContext.getContextClass())) {
            Move move = parentContext.asType(Move.class);
            Currency currency = move.getCurrency();
            Currency companyCurrency = move.getCompanyCurrency();
            if (currency != null && companyCurrency != null && !currency.equals(companyCurrency)) {
                currencyRate = Beans.get(CurrencyService.class).getCurrencyConversionRate(currency, companyCurrency);
            }
        }
        response.setValue("currencyRate", currencyRate);
    } catch (AxelorException e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Context(com.axelor.rpc.Context) AxelorException(com.axelor.exception.AxelorException) Move(com.axelor.apps.account.db.Move) Currency(com.axelor.apps.base.db.Currency) BigDecimal(java.math.BigDecimal)

Example 77 with Move

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

Example 78 with Move

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

the class ImportMove method validateMove.

@Transactional(rollbackOn = Exception.class)
public Object validateMove(Object bean, Map<String, Object> values) throws AxelorException {
    assert bean instanceof Move;
    Move move = (Move) bean;
    try {
        if (move.getStatusSelect() == MoveRepository.STATUS_ACCOUNTED || move.getStatusSelect() == MoveRepository.STATUS_VALIDATED) {
            moveValidateService.validate(move);
        }
    } catch (Exception e) {
        TraceBackService.trace(e);
        move.setStatusSelect(MoveRepository.STATUS_NEW);
    }
    moveRepository.save(move);
    return move;
}
Also used : Move(com.axelor.apps.account.db.Move) AxelorException(com.axelor.exception.AxelorException) Transactional(com.google.inject.persist.Transactional)

Example 79 with Move

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

the class MoveBankPaymentRepository method copy.

@Override
public Move copy(Move entity, boolean deep) {
    Move copy = super.copy(entity, deep);
    List<MoveLine> moveLineList = copy.getMoveLineList();
    if (moveLineList != null) {
        moveLineList.forEach(moveLine -> moveLine.setBankReconciledAmount(BigDecimal.ZERO));
    }
    return copy;
}
Also used : Move(com.axelor.apps.account.db.Move) MoveLine(com.axelor.apps.account.db.MoveLine)

Example 80 with Move

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

the class AccountClearanceService method createAccountClearanceMove.

public Move createAccountClearanceMove(MoveLine moveLine, BigDecimal taxRate, Account taxAccount, Account profitAccount, Company company, Journal journal, AccountClearance accountClearance) throws AxelorException {
    Partner partner = moveLine.getPartner();
    // Move
    Move move = moveService.getMoveCreateService().createMove(journal, company, null, partner, null, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, moveLine.getMove().getFunctionalOriginSelect());
    // Debit MoveLine 411
    BigDecimal amount = moveLine.getAmountRemaining();
    MoveLine debitMoveLine = moveLineService.createMoveLine(move, partner, moveLine.getAccount(), amount, true, appBaseService.getTodayDateTime().toLocalDate(), 1, null, null);
    move.getMoveLineList().add(debitMoveLine);
    // Credit MoveLine 77. (profit account)
    BigDecimal divid = taxRate.add(BigDecimal.ONE);
    BigDecimal profitAmount = amount.divide(divid, AppBaseService.DEFAULT_NB_DECIMAL_DIGITS, RoundingMode.HALF_UP).setScale(AppBaseService.DEFAULT_NB_DECIMAL_DIGITS, RoundingMode.HALF_UP);
    MoveLine creditMoveLine1 = moveLineService.createMoveLine(move, partner, profitAccount, profitAmount, false, appBaseService.getTodayDateTime().toLocalDate(), 2, null, null);
    move.getMoveLineList().add(creditMoveLine1);
    // Credit MoveLine 445 (Tax account)
    BigDecimal taxAmount = amount.subtract(profitAmount);
    MoveLine creditMoveLine2 = moveLineService.createMoveLine(move, partner, taxAccount, taxAmount, false, appBaseService.getTodayDateTime().toLocalDate(), 3, null, null);
    move.getMoveLineList().add(creditMoveLine2);
    Reconcile reconcile = reconcileService.createReconcile(debitMoveLine, moveLine, amount, false);
    if (reconcile != null) {
        reconcileService.confirmReconcile(reconcile, true);
    }
    debitMoveLine.setAccountClearance(accountClearance);
    creditMoveLine1.setAccountClearance(accountClearance);
    creditMoveLine2.setAccountClearance(accountClearance);
    return move;
}
Also used : Move(com.axelor.apps.account.db.Move) MoveLine(com.axelor.apps.account.db.MoveLine) Partner(com.axelor.apps.base.db.Partner) BigDecimal(java.math.BigDecimal) Reconcile(com.axelor.apps.account.db.Reconcile)

Aggregations

Move (com.axelor.apps.account.db.Move)101 MoveLine (com.axelor.apps.account.db.MoveLine)51 Transactional (com.google.inject.persist.Transactional)37 Company (com.axelor.apps.base.db.Company)36 AxelorException (com.axelor.exception.AxelorException)34 BigDecimal (java.math.BigDecimal)33 Partner (com.axelor.apps.base.db.Partner)31 LocalDate (java.time.LocalDate)28 Journal (com.axelor.apps.account.db.Journal)25 Account (com.axelor.apps.account.db.Account)22 ArrayList (java.util.ArrayList)22 AccountConfig (com.axelor.apps.account.db.AccountConfig)18 Reconcile (com.axelor.apps.account.db.Reconcile)14 AnalyticMoveLine (com.axelor.apps.account.db.AnalyticMoveLine)11 Invoice (com.axelor.apps.account.db.Invoice)11 List (java.util.List)7 BankDetails (com.axelor.apps.base.db.BankDetails)6 InvoicePayment (com.axelor.apps.account.db.InvoicePayment)5 MoveRepository (com.axelor.apps.account.db.repo.MoveRepository)5 MoveService (com.axelor.apps.account.service.move.MoveService)5