Search in sources :

Example 21 with Move

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

the class BatchCloseAnnualAccounts method process.

protected void process() {
    if (!end) {
        AccountingBatch accountingBatch = batch.getAccountingBatch();
        boolean allocatePerPartner = accountingBatch.getAllocatePerPartner();
        boolean closeYear = accountingBatch.getCloseYear();
        boolean openYear = accountingBatch.getOpenYear();
        Year year = accountingBatch.getYear();
        LocalDate endOfYearDate = year.getToDate();
        LocalDate reportedBalanceDate = year.getReportedBalanceDate();
        String origin = accountingBatch.getCode();
        String moveDescription = accountingBatch.getMoveDescription();
        List<Long> accountIdList = accountingCloseAnnualService.getAllAccountOfYear(accountingBatch.getAccountSet(), year);
        List<Pair<Long, Long>> accountAndPartnerPairList = accountingCloseAnnualService.assignPartner(accountIdList, year, allocatePerPartner);
        Account account = null;
        Partner partner = null;
        for (Pair<Long, Long> accountAndPartnerPair : accountAndPartnerPairList) {
            try {
                account = accountRepository.find(accountAndPartnerPair.getLeft());
                if (accountAndPartnerPair.getRight() != null) {
                    partner = partnerRepository.find(accountAndPartnerPair.getRight());
                } else {
                    partner = null;
                }
                List<Move> generateMoves = accountingCloseAnnualService.generateCloseAnnualAccount(yearRepository.find(year.getId()), account, partner, endOfYearDate, reportedBalanceDate, origin, moveDescription, closeYear, openYear, allocatePerPartner);
                if (generateMoves != null && !generateMoves.isEmpty()) {
                    updateAccount(account);
                    for (Move move : generateMoves) {
                        updateAccountMove(move, false);
                    }
                }
            } catch (AxelorException e) {
                TraceBackService.trace(new AxelorException(e, e.getCategory(), I18n.get("Account") + " %s", account.getCode()), null, batch.getId());
                incrementAnomaly();
                break;
            } catch (Exception e) {
                TraceBackService.trace(new Exception(String.format(I18n.get("Account") + " %s", account.getCode()), e), null, batch.getId());
                incrementAnomaly();
                LOG.error("Anomaly generated for the account {}", account.getCode());
                break;
            } finally {
                JPA.clear();
            }
        }
    }
}
Also used : Account(com.axelor.apps.account.db.Account) AxelorException(com.axelor.exception.AxelorException) LocalDate(java.time.LocalDate) AxelorException(com.axelor.exception.AxelorException) Year(com.axelor.apps.base.db.Year) Move(com.axelor.apps.account.db.Move) AccountingBatch(com.axelor.apps.account.db.AccountingBatch) Partner(com.axelor.apps.base.db.Partner) Pair(org.apache.commons.lang3.tuple.Pair)

Example 22 with Move

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

the class FixedAssetLineMoveServiceImpl method generateDisposalMove.

@Override
@Transactional(rollbackOn = { Exception.class })
public void generateDisposalMove(FixedAssetLine fixedAssetLine) throws AxelorException {
    FixedAsset fixedAsset = fixedAssetLine.getFixedAsset();
    Journal journal = fixedAsset.getJournal();
    Company company = fixedAsset.getCompany();
    Partner partner = fixedAsset.getPartner();
    LocalDate date = fixedAssetLine.getDepreciationDate();
    // Creating move
    Move move = moveCreateService.createMove(journal, company, company.getCurrency(), partner, date, null, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_FIXED_ASSET);
    if (move != null) {
        List<MoveLine> moveLines = new ArrayList<MoveLine>();
        String origin = fixedAsset.getReference();
        Account chargeAccount = fixedAsset.getFixedAssetCategory().getChargeAccount();
        Account depreciationAccount = fixedAsset.getFixedAssetCategory().getDepreciationAccount();
        Account purchaseAccount = fixedAsset.getPurchaseAccount();
        BigDecimal chargeAmount = fixedAssetLine.getResidualValue();
        BigDecimal cumulativeDepreciationAmount = fixedAssetLine.getCumulativeDepreciation();
        // Creating accounting debit move line for charge account
        MoveLine chargeAccountDebitMoveLine = new MoveLine(move, partner, chargeAccount, date, null, 1, chargeAmount, BigDecimal.ZERO, fixedAsset.getName(), origin, null, BigDecimal.ZERO, date);
        moveLines.add(chargeAccountDebitMoveLine);
        this.addAnalyticToMoveLine(fixedAsset.getAnalyticDistributionTemplate(), chargeAccountDebitMoveLine);
        // Creating accounting debit move line for deprecation account
        MoveLine deprecationAccountDebitMoveLine = new MoveLine(move, partner, depreciationAccount, date, null, 1, cumulativeDepreciationAmount, BigDecimal.ZERO, fixedAsset.getName(), origin, null, BigDecimal.ZERO, date);
        moveLines.add(deprecationAccountDebitMoveLine);
        this.addAnalyticToMoveLine(fixedAsset.getAnalyticDistributionTemplate(), deprecationAccountDebitMoveLine);
        // Creating accounting credit move line
        MoveLine creditMoveLine = new MoveLine(move, partner, purchaseAccount, date, null, 2, BigDecimal.ZERO, fixedAsset.getGrossValue(), fixedAsset.getName(), origin, null, BigDecimal.ZERO, date);
        moveLines.add(creditMoveLine);
        this.addAnalyticToMoveLine(fixedAsset.getAnalyticDistributionTemplate(), creditMoveLine);
        move.getMoveLineList().addAll(moveLines);
    }
    moveRepo.save(move);
    fixedAsset.setDisposalMove(move);
}
Also used : Account(com.axelor.apps.account.db.Account) Company(com.axelor.apps.base.db.Company) Move(com.axelor.apps.account.db.Move) MoveLine(com.axelor.apps.account.db.MoveLine) ArrayList(java.util.ArrayList) Journal(com.axelor.apps.account.db.Journal) FixedAsset(com.axelor.apps.account.db.FixedAsset) Partner(com.axelor.apps.base.db.Partner) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) Transactional(com.google.inject.persist.Transactional)

Example 23 with Move

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

the class SubrogationReleaseController method displayMoveLines.

public void displayMoveLines(ActionRequest request, ActionResponse response) {
    try {
        SubrogationRelease subrogationRelease = request.getContext().asType(SubrogationRelease.class);
        List<Long> moveLineIdList = new ArrayList<Long>();
        for (Move move : subrogationRelease.getMoveList()) {
            for (MoveLine moveLine : move.getMoveLineList()) {
                moveLineIdList.add(moveLine.getId());
            }
        }
        response.setView(ActionView.define("MoveLines").model(MoveLine.class.getName()).add("grid", "move-line-grid").add("form", "move-line-form").param("search-filters", "move-line-filters").domain("self.id in (" + Joiner.on(",").join(moveLineIdList) + ")").map());
    } catch (Exception e) {
        response.setError(e.getMessage());
        TraceBackService.trace(e);
    }
}
Also used : Move(com.axelor.apps.account.db.Move) SubrogationRelease(com.axelor.apps.account.db.SubrogationRelease) ArrayList(java.util.ArrayList) MoveLine(com.axelor.apps.account.db.MoveLine)

Example 24 with Move

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

the class InvoicePaymentController method cancelInvoicePayment.

public void cancelInvoicePayment(ActionRequest request, ActionResponse response) {
    InvoicePayment invoicePayment = request.getContext().asType(InvoicePayment.class);
    invoicePayment = Beans.get(InvoicePaymentRepository.class).find(invoicePayment.getId());
    try {
        Move move = invoicePayment.getMove();
        Beans.get(InvoicePaymentCancelService.class).cancel(invoicePayment);
        if (ObjectUtils.notEmpty(move)) {
            Beans.get(MoveCustAccountService.class).updateCustomerAccount(move);
        }
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
    response.setReload(true);
}
Also used : InvoicePayment(com.axelor.apps.account.db.InvoicePayment) Move(com.axelor.apps.account.db.Move) InvoicePaymentCancelService(com.axelor.apps.account.service.payment.invoice.payment.InvoicePaymentCancelService) MoveCustAccountService(com.axelor.apps.account.service.move.MoveCustAccountService) AxelorException(com.axelor.exception.AxelorException)

Example 25 with Move

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

the class ImportMove method importFECMove.

@Transactional(rollbackOn = { AxelorException.class, Exception.class })
public Object importFECMove(Object bean, Map<String, Object> values) throws AxelorException {
    assert bean instanceof MoveLine;
    MoveLine moveLine = (MoveLine) bean;
    try {
        moveLine.setCounter(1);
        if (values.get("EcritureNum") == null) {
            return null;
        }
        String moveReference = values.get("EcritureNum").toString();
        MoveLine mvLine = moveLineRepo.all().filter("self.name LIKE '" + moveReference + "-%'").order("-counter").fetchOne();
        if (mvLine != null) {
            int counter = mvLine.getCounter() + 1;
            moveLine.setCounter(counter);
        }
        if (values.get("EcritureDate") != null) {
            LocalDate moveLineDate = LocalDate.parse(values.get("EcritureDate").toString(), DateTimeFormatter.BASIC_ISO_DATE);
            moveLine.setDate(moveLineDate);
        }
        Move move = moveRepository.all().filter("self.reference = ?", moveReference).fetchOne();
        if (move == null) {
            move = new Move();
            move.setReference(moveReference);
            if (values.get("ValidDate") != null) {
                move.setStatusSelect(MoveRepository.STATUS_VALIDATED);
                move.setValidationDate(LocalDate.parse(values.get("ValidDate").toString(), DateTimeFormatter.BASIC_ISO_DATE));
            } else {
                move.setStatusSelect(MoveRepository.STATUS_ACCOUNTED);
            }
            move.setCompany(getCompany(values));
            move.setCompanyCurrency(move.getCompany().getCurrency());
            move.setDate(LocalDate.parse(values.get("EcritureDate").toString(), DateTimeFormatter.BASIC_ISO_DATE));
            move.setPeriod(Beans.get(PeriodService.class).getPeriod(move.getDate(), move.getCompany(), YearRepository.TYPE_FISCAL));
            if (values.get("Idevise") != null) {
                move.setCurrency(Beans.get(CurrencyRepository.class).findByCode(values.get("Idevise").toString()));
                move.setCurrencyCode(values.get("Idevise").toString());
            }
            if (values.get("JournalCode") != null) {
                Journal journal = Beans.get(JournalRepository.class).all().filter("self.code = ?1 AND self.company.id = ?2", values.get("JournalCode").toString(), move.getCompany().getId()).fetchOne();
                move.setJournal(journal);
            }
            if (values.get("CompAuxNum") != null) {
                Partner partner = Beans.get(PartnerRepository.class).all().filter("self.partnerSeq = ?", values.get("CompAuxNum").toString()).fetchOne();
                move.setPartner(partner);
            }
            moveRepository.save(move);
        }
        if (values.get("CompteNum") != null) {
            Account account = Beans.get(AccountRepository.class).all().filter("self.code = ?1 AND self.company.id = ?2", values.get("CompteNum").toString(), move.getCompany().getId()).fetchOne();
            moveLine.setAccount(account);
        }
        moveLine.setMove(move);
    } catch (Exception e) {
        TraceBackService.trace(e);
        throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, e.getMessage());
    }
    return moveLine;
}
Also used : Account(com.axelor.apps.account.db.Account) AxelorException(com.axelor.exception.AxelorException) AccountRepository(com.axelor.apps.account.db.repo.AccountRepository) Journal(com.axelor.apps.account.db.Journal) LocalDate(java.time.LocalDate) AxelorException(com.axelor.exception.AxelorException) PartnerRepository(com.axelor.apps.base.db.repo.PartnerRepository) JournalRepository(com.axelor.apps.account.db.repo.JournalRepository) Move(com.axelor.apps.account.db.Move) MoveLine(com.axelor.apps.account.db.MoveLine) Partner(com.axelor.apps.base.db.Partner) Transactional(com.google.inject.persist.Transactional)

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