Search in sources :

Example 36 with Move

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

the class MoveServiceImpl method createMove.

/**
 * Créer une écriture comptable propre à la facture.
 *
 * @param invoice
 * @param consolidate
 * @return
 * @throws AxelorException
 */
@Transactional(rollbackOn = { Exception.class })
@Override
public Move createMove(Invoice invoice) throws AxelorException {
    Move move = null;
    if (invoice != null && invoice.getInvoiceLineList() != null) {
        Journal journal = invoice.getJournal();
        Company company = invoice.getCompany();
        Partner partner = invoice.getPartner();
        Account account = invoice.getPartnerAccount();
        log.debug("Création d'une écriture comptable spécifique à la facture {} (Société : {}, Journal : {})", new Object[] { invoice.getInvoiceId(), company.getName(), journal.getCode() });
        int functionalOrigin = Beans.get(InvoiceService.class).getPurchaseTypeOrSaleType(invoice);
        if (functionalOrigin == PriceListRepository.TYPE_PURCHASE) {
            functionalOrigin = MoveRepository.FUNCTIONAL_ORIGIN_PURCHASE;
        } else if (functionalOrigin == PriceListRepository.TYPE_SALE) {
            functionalOrigin = MoveRepository.FUNCTIONAL_ORIGIN_SALE;
        } else {
            functionalOrigin = 0;
        }
        move = moveCreateService.createMove(journal, company, invoice.getCurrency(), partner, invoice.getInvoiceDate(), invoice.getPaymentMode(), MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, functionalOrigin);
        if (move != null) {
            move.setInvoice(invoice);
            move.setTradingName(invoice.getTradingName());
            boolean isPurchase = InvoiceToolService.isPurchase(invoice);
            boolean isDebitCustomer = moveToolService.isDebitCustomer(invoice, false);
            move.getMoveLineList().addAll(moveLineService.createMoveLines(invoice, move, company, partner, account, journal.getIsInvoiceMoveConsolidated(), isPurchase, isDebitCustomer));
            moveRepository.save(move);
            invoice.setMove(move);
            invoice.setCompanyInTaxTotalRemaining(moveToolService.getInTaxTotalRemaining(invoice));
            moveValidateService.validate(move);
        }
    }
    return move;
}
Also used : Account(com.axelor.apps.account.db.Account) Company(com.axelor.apps.base.db.Company) Move(com.axelor.apps.account.db.Move) InvoiceService(com.axelor.apps.account.service.invoice.InvoiceService) Journal(com.axelor.apps.account.db.Journal) Partner(com.axelor.apps.base.db.Partner) Transactional(com.google.inject.persist.Transactional)

Example 37 with Move

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

the class MoveTemplateService method generateMove.

@Transactional(rollbackOn = { Exception.class })
public List<Long> generateMove(MoveTemplate moveTemplate, List<HashMap<String, Object>> dataList) throws AxelorException {
    List<Long> moveList = new ArrayList<>();
    BigDecimal hundred = new BigDecimal(100);
    for (HashMap<String, Object> data : dataList) {
        LocalDate moveDate = LocalDate.parse(data.get("date").toString(), DateTimeFormatter.ISO_DATE);
        boolean isDebit = false;
        Partner debitPartner = null;
        Partner creditPartner = null;
        BigDecimal moveBalance = new BigDecimal(data.get("moveBalance").toString());
        Partner partner = null;
        if (data.get("debitPartner") != null) {
            debitPartner = partnerRepo.find(Long.parseLong(((HashMap<String, Object>) data.get("debitPartner")).get("id").toString()));
            partner = debitPartner;
        }
        if (data.get("creditPartner") != null) {
            creditPartner = partnerRepo.find(Long.parseLong(((HashMap<String, Object>) data.get("creditPartner")).get("id").toString()));
            partner = creditPartner;
        }
        if (moveTemplate.getJournal().getCompany() != null) {
            Move move = moveService.getMoveCreateService().createMove(moveTemplate.getJournal(), moveTemplate.getJournal().getCompany(), null, partner, moveDate, null, MoveRepository.TECHNICAL_ORIGIN_TEMPLATE, 0);
            int counter = 1;
            for (MoveTemplateLine moveTemplateLine : moveTemplate.getMoveTemplateLineList()) {
                partner = null;
                if (moveTemplateLine.getDebitCreditSelect().equals(MoveTemplateLineRepository.DEBIT)) {
                    isDebit = true;
                    if (moveTemplateLine.getHasPartnerToDebit()) {
                        partner = debitPartner;
                    }
                } else if (moveTemplateLine.getDebitCreditSelect().equals(MoveTemplateLineRepository.CREDIT)) {
                    isDebit = false;
                    if (moveTemplateLine.getHasPartnerToCredit()) {
                        partner = creditPartner;
                    }
                }
                BigDecimal amount = moveBalance.multiply(moveTemplateLine.getPercentage()).divide(hundred, RoundingMode.HALF_UP);
                MoveLine moveLine = moveLineService.createMoveLine(move, partner, moveTemplateLine.getAccount(), amount, isDebit, 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 : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Tax(com.axelor.apps.account.db.Tax) LocalDate(java.time.LocalDate) 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) Partner(com.axelor.apps.base.db.Partner) Transactional(com.google.inject.persist.Transactional)

Example 38 with Move

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

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

the class MoveValidateService method validateMultiple.

public void validateMultiple(Query<Move> moveListQuery) throws AxelorException {
    Move move;
    while (!((move = moveListQuery.fetchOne()) == null)) {
        validate(move);
        JPA.clear();
    }
}
Also used : Move(com.axelor.apps.account.db.Move)

Example 40 with Move

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

the class MoveAdjustementService method createAdjustmentDebitMove.

/**
 * Creating move of passage in gap regulation (on debit)
 *
 * @param debitMoveLine
 * @return
 * @throws AxelorException
 */
@Transactional(rollbackOn = { Exception.class })
public void createAdjustmentDebitMove(MoveLine debitMoveLine) throws AxelorException {
    Partner partner = debitMoveLine.getPartner();
    Account account = debitMoveLine.getAccount();
    Move debitMove = debitMoveLine.getMove();
    Company company = debitMove.getCompany();
    AccountConfig accountConfig = accountConfigService.getAccountConfig(company);
    BigDecimal debitAmountRemaining = debitMoveLine.getAmountRemaining();
    Journal miscOperationJournal = accountConfigService.getAutoMiscOpeJournal(accountConfig);
    Move adjustmentMove = moveCreateService.createMove(miscOperationJournal, company, null, partner, null, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, debitMove.getFunctionalOriginSelect());
    // Création de la ligne au crédit
    MoveLine creditAdjustmentMoveLine = moveLineService.createMoveLine(adjustmentMove, partner, account, debitAmountRemaining, false, appAccountService.getTodayDate(company), 1, null, null);
    // Création de la ligne au debit
    MoveLine debitAdjustmentMoveLine = moveLineService.createMoveLine(adjustmentMove, partner, accountConfigService.getCashPositionVariationAccount(accountConfig), debitAmountRemaining, true, appAccountService.getTodayDate(company), 2, null, null);
    adjustmentMove.addMoveLineListItem(creditAdjustmentMoveLine);
    adjustmentMove.addMoveLineListItem(debitAdjustmentMoveLine);
    moveValidateService.validate(adjustmentMove);
    moveRepository.save(adjustmentMove);
}
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) Journal(com.axelor.apps.account.db.Journal) Partner(com.axelor.apps.base.db.Partner) BigDecimal(java.math.BigDecimal) AccountConfig(com.axelor.apps.account.db.AccountConfig) 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