Search in sources :

Example 26 with Move

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

the class MoveController method deleteMove.

public void deleteMove(ActionRequest request, ActionResponse response) throws AxelorException {
    try {
        Move move = request.getContext().asType(Move.class);
        MoveRepository moveRepository = Beans.get(MoveRepository.class);
        move = moveRepository.find(move.getId());
        move = moveRepository.find(move.getId());
        this.removeOneMove(move, response);
        if (!move.getStatusSelect().equals(MoveRepository.STATUS_VALIDATED)) {
            response.setView(ActionView.define("Moves").model(Move.class.getName()).add("grid", "move-grid").add("form", "move-form").param("search-filters", "move-filters").map());
            response.setCanClose(true);
        }
    } catch (Exception e) {
        TraceBackService.trace(response, e, ResponseMessageType.ERROR);
    }
}
Also used : MoveRepository(com.axelor.apps.account.db.repo.MoveRepository) Move(com.axelor.apps.account.db.Move) AxelorException(com.axelor.exception.AxelorException)

Example 27 with Move

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

the class MoveController method updateLines.

public void updateLines(ActionRequest request, ActionResponse response) {
    Move move = request.getContext().asType(Move.class);
    try {
        move = Beans.get(MoveService.class).updateMoveLinesDateExcludeFromPeriodOnlyWithoutSave(move);
        response.setValue("moveLineList", move.getMoveLineList());
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Move(com.axelor.apps.account.db.Move) AxelorException(com.axelor.exception.AxelorException)

Example 28 with Move

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

the class MoveController method checkRemoveLines.

public void checkRemoveLines(ActionRequest request, ActionResponse response) {
    try {
        Move moveView = request.getContext().asType(Move.class);
        if (moveView.getId() == null) {
            return;
        }
        Move moveBD = Beans.get(MoveRepository.class).find(moveView.getId());
        List<String> moveLineReconciledAndRemovedNameList = new ArrayList<>();
        for (MoveLine moveLineBD : moveBD.getMoveLineList()) {
            if (!moveView.getMoveLineList().contains(moveLineBD)) {
                if (moveLineBD.getReconcileGroup() != null) {
                    moveLineReconciledAndRemovedNameList.add(moveLineBD.getName());
                }
            }
        }
        if (moveLineReconciledAndRemovedNameList != null && !moveLineReconciledAndRemovedNameList.isEmpty()) {
            response.setError(String.format(I18n.get(IExceptionMessage.MOVE_LINE_RECONCILE_LINE_CANNOT_BE_REMOVED), moveLineReconciledAndRemovedNameList.toString()));
        }
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : MoveRepository(com.axelor.apps.account.db.repo.MoveRepository) Move(com.axelor.apps.account.db.Move) ArrayList(java.util.ArrayList) MoveLine(com.axelor.apps.account.db.MoveLine) AxelorException(com.axelor.exception.AxelorException)

Example 29 with Move

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

the class MoveController method autoTaxLineGenerate.

public void autoTaxLineGenerate(ActionRequest request, ActionResponse response) throws AxelorException {
    Move move = request.getContext().asType(Move.class);
    if (move.getMoveLineList() != null && !move.getMoveLineList().isEmpty() && move.getStatusSelect().equals(MoveRepository.STATUS_NEW)) {
        Beans.get(MoveService.class).getMoveLineService().autoTaxLineGenerate(move);
        response.setValue("moveLineList", move.getMoveLineList());
    }
}
Also used : Move(com.axelor.apps.account.db.Move)

Example 30 with Move

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

the class ExpenseServiceImpl method createAndSetMove.

protected Move createAndSetMove(Expense expense) throws AxelorException {
    LocalDate moveDate = expense.getMoveDate();
    if (moveDate == null) {
        moveDate = appAccountService.getTodayDate(expense.getCompany());
        expense.setMoveDate(moveDate);
    }
    Company company = expense.getCompany();
    Partner partner = expense.getUser().getPartner();
    Account account = null;
    AccountConfig accountConfig = accountConfigService.getAccountConfig(company);
    if (partner == null) {
        throw new AxelorException(expense, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(com.axelor.apps.account.exception.IExceptionMessage.USER_PARTNER), expense.getUser().getName());
    }
    Move move = moveService.getMoveCreateService().createMove(accountConfigService.getExpenseJournal(accountConfig), company, null, partner, moveDate, partner.getInPaymentMode(), MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_PURCHASE);
    List<MoveLine> moveLines = new ArrayList<>();
    Set<AnalyticAccount> analyticAccounts = new HashSet<>();
    BigDecimal exTaxTotal = null;
    int moveLineId = 1;
    int expenseLineId = 1;
    Account employeeAccount = accountingSituationService.getEmployeeAccount(partner, company);
    moveLines.add(moveLineService.createMoveLine(move, partner, employeeAccount, expense.getInTaxTotal(), false, moveDate, moveDate, moveLineId++, expense.getExpenseSeq(), expense.getFullName()));
    for (ExpenseLine expenseLine : getExpenseLineList(expense)) {
        analyticAccounts.clear();
        Product product = expenseLine.getExpenseProduct();
        account = accountManagementService.getProductAccount(product, company, partner.getFiscalPosition(), true, false);
        if (account == null) {
            throw new AxelorException(expense, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(com.axelor.apps.account.exception.IExceptionMessage.MOVE_LINE_4), expenseLineId, company.getName());
        }
        exTaxTotal = expenseLine.getUntaxedAmount();
        MoveLine moveLine = moveLineService.createMoveLine(move, partner, account, exTaxTotal, true, moveDate, moveDate, moveLineId++, expense.getExpenseSeq(), expenseLine.getComments() != null ? expenseLine.getComments().replaceAll("(\r\n|\n\r|\r|\n)", " ") : "");
        for (AnalyticMoveLine analyticDistributionLineIt : expenseLine.getAnalyticMoveLineList()) {
            AnalyticMoveLine analyticDistributionLine = Beans.get(AnalyticMoveLineRepository.class).copy(analyticDistributionLineIt, false);
            analyticDistributionLine.setExpenseLine(null);
            moveLine.addAnalyticMoveLineListItem(analyticDistributionLine);
        }
        moveLines.add(moveLine);
        expenseLineId++;
    }
    moveLineService.consolidateMoveLines(moveLines);
    account = accountConfigService.getExpenseTaxAccount(accountConfig);
    BigDecimal taxTotal = BigDecimal.ZERO;
    for (ExpenseLine expenseLine : getExpenseLineList(expense)) {
        exTaxTotal = expenseLine.getTotalTax();
        taxTotal = taxTotal.add(exTaxTotal);
    }
    if (taxTotal.signum() != 0) {
        MoveLine moveLine = moveLineService.createMoveLine(move, partner, account, taxTotal, true, moveDate, moveDate, moveLineId++, expense.getExpenseSeq(), expense.getFullName());
        moveLines.add(moveLine);
    }
    move.getMoveLineList().addAll(moveLines);
    moveService.getMoveValidateService().validate(move);
    expense.setMove(move);
    return move;
}
Also used : AnalyticAccount(com.axelor.apps.account.db.AnalyticAccount) Account(com.axelor.apps.account.db.Account) AxelorException(com.axelor.exception.AxelorException) Company(com.axelor.apps.base.db.Company) ArrayList(java.util.ArrayList) Product(com.axelor.apps.base.db.Product) AnalyticAccount(com.axelor.apps.account.db.AnalyticAccount) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) AccountConfig(com.axelor.apps.account.db.AccountConfig) AnalyticMoveLineRepository(com.axelor.apps.account.db.repo.AnalyticMoveLineRepository) Move(com.axelor.apps.account.db.Move) MoveLine(com.axelor.apps.account.db.MoveLine) AnalyticMoveLine(com.axelor.apps.account.db.AnalyticMoveLine) ExpenseLine(com.axelor.apps.hr.db.ExpenseLine) Partner(com.axelor.apps.base.db.Partner) HashSet(java.util.HashSet) AnalyticMoveLine(com.axelor.apps.account.db.AnalyticMoveLine)

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