Search in sources :

Example 16 with AccountConfig

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

the class AccountingSituationController method setDefaultMail.

/**
 * set default value for automatic invoice printing
 *
 * @param request
 * @param response
 * @throws AxelorException
 */
public void setDefaultMail(ActionRequest request, ActionResponse response) throws AxelorException {
    AccountingSituation accountingSituation = request.getContext().asType(AccountingSituation.class);
    Company company = accountingSituation.getCompany();
    if (company != null) {
        AccountConfig accountConfig = Beans.get(AccountConfigService.class).getAccountConfig(company);
        response.setValue("invoiceAutomaticMail", accountConfig.getInvoiceAutomaticMail());
        response.setValue("invoiceMessageTemplate", accountConfig.getInvoiceMessageTemplate());
    }
}
Also used : Company(com.axelor.apps.base.db.Company) AccountingSituation(com.axelor.apps.account.db.AccountingSituation) AccountConfigService(com.axelor.apps.account.service.config.AccountConfigService) AccountConfig(com.axelor.apps.account.db.AccountConfig)

Example 17 with AccountConfig

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

the class AccountChartController method installChart.

public void installChart(ActionRequest request, ActionResponse response) throws AxelorException {
    AccountConfig accountConfig = request.getContext().asType(AccountConfig.class);
    AccountChart act = Beans.get(AccountChartRepository.class).find(accountConfig.getAccountChart().getId());
    Company company = Beans.get(CompanyRepository.class).find(accountConfig.getCompany().getId());
    accountConfig = Beans.get(AccountConfigRepository.class).find(accountConfig.getId());
    List<? extends Account> accountList = Beans.get(AccountRepository.class).all().filter("self.company.id = ?1 AND self.parentAccount != null", company.getId()).fetch();
    if (accountList.isEmpty()) {
        if (Beans.get(AccountChartService.class).installAccountChart(act, company, accountConfig))
            response.setFlash(I18n.get(IExceptionMessage.ACCOUNT_CHART_1));
        else
            response.setFlash(I18n.get(IExceptionMessage.ACCOUNT_CHART_2));
        response.setReload(true);
    } else
        response.setFlash(I18n.get(IExceptionMessage.ACCOUNT_CHART_3));
}
Also used : Company(com.axelor.apps.base.db.Company) CompanyRepository(com.axelor.apps.base.db.repo.CompanyRepository) AccountChart(com.axelor.apps.account.db.AccountChart) AccountRepository(com.axelor.apps.account.db.repo.AccountRepository) AccountChartService(com.axelor.apps.account.service.AccountChartService) AccountChartRepository(com.axelor.apps.account.db.repo.AccountChartRepository) AccountConfig(com.axelor.apps.account.db.AccountConfig)

Example 18 with AccountConfig

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

the class AccountingCutOffServiceImpl method generateCutOffMove.

public Move generateCutOffMove(StockMove stockMove, List<StockMoveLine> sortedStockMoveLine, LocalDate moveDate, LocalDate originDate, boolean isPurchase, boolean recoveredTax, boolean ati, String moveDescription, boolean includeNotStockManagedProduct, boolean isReverse) throws AxelorException {
    if (moveDate == null || stockMove.getOriginTypeSelect() == null || stockMove.getOriginId() == null) {
        return null;
    }
    Company company = stockMove.getCompany();
    AccountConfig accountConfig = accountConfigSupplychainService.getAccountConfig(company);
    Partner partner = stockMove.getPartner();
    Account partnerAccount = null;
    Currency currency = null;
    if (StockMoveRepository.ORIGIN_SALE_ORDER.equals(stockMove.getOriginTypeSelect()) && stockMove.getOriginId() != null) {
        SaleOrder saleOrder = saleOrderRepository.find(stockMove.getOriginId());
        currency = saleOrder.getCurrency();
        if (partner == null) {
            partner = saleOrder.getClientPartner();
        }
        partnerAccount = accountConfigSupplychainService.getForecastedInvCustAccount(accountConfig);
    }
    if (StockMoveRepository.ORIGIN_PURCHASE_ORDER.equals(stockMove.getOriginTypeSelect()) && stockMove.getOriginId() != null) {
        PurchaseOrder purchaseOrder = purchaseOrderRepository.find(stockMove.getOriginId());
        currency = purchaseOrder.getCurrency();
        if (partner == null) {
            partner = purchaseOrder.getSupplierPartner();
        }
        partnerAccount = accountConfigSupplychainService.getForecastedInvSuppAccount(accountConfig);
    }
    String origin = stockMove.getStockMoveSeq();
    Move move = moveCreateService.createMove(accountConfigSupplychainService.getAutoMiscOpeJournal(accountConfig), company, currency, partner, moveDate, null, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_CUT_OFF);
    counter = 0;
    this.generateMoveLines(move, stockMove.getStockMoveLineList(), origin, isPurchase, recoveredTax, ati, moveDescription, isReverse, originDate, includeNotStockManagedProduct);
    this.generatePartnerMoveLine(move, origin, partnerAccount, moveDescription, originDate);
    if (move.getMoveLineList() != null && !move.getMoveLineList().isEmpty()) {
        move.setStockMove(stockMove);
        moveValidateService.validate(move);
    } else {
        moveRepository.remove(move);
        return null;
    }
    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) StockMove(com.axelor.apps.stock.db.StockMove) Currency(com.axelor.apps.base.db.Currency) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) SaleOrder(com.axelor.apps.sale.db.SaleOrder) Partner(com.axelor.apps.base.db.Partner) AccountConfig(com.axelor.apps.account.db.AccountConfig)

Example 19 with AccountConfig

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

the class AdvancePaymentServiceSupplychainImpl method createMoveForAdvancePayment.

@Transactional(rollbackOn = { Exception.class })
public Move createMoveForAdvancePayment(AdvancePayment advancePayment) throws AxelorException {
    SaleOrder saleOrder = advancePayment.getSaleOrder();
    Company company = saleOrder.getCompany();
    PaymentMode paymentMode = advancePayment.getPaymentMode();
    Partner clientPartner = saleOrder.getClientPartner();
    LocalDate advancePaymentDate = advancePayment.getAdvancePaymentDate();
    BankDetails bankDetails = saleOrder.getCompanyBankDetails();
    String ref = saleOrder.getSaleOrderSeq();
    AccountConfig accountConfig = accountConfigService.getAccountConfig(company);
    Journal journal = paymentModeService.getPaymentModeJournal(paymentMode, company, bankDetails);
    Move move = moveService.getMoveCreateService().createMove(journal, company, advancePayment.getCurrency(), clientPartner, advancePaymentDate, paymentMode, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_PAYMENT);
    BigDecimal amountConverted = currencyService.getAmountCurrencyConvertedAtDate(advancePayment.getCurrency(), saleOrder.getCurrency(), advancePayment.getAmount(), advancePaymentDate);
    move.addMoveLineListItem(moveLineService.createMoveLine(move, clientPartner, paymentModeService.getPaymentModeAccount(paymentMode, company, bankDetails), amountConverted, true, advancePaymentDate, null, 1, ref, null));
    move.addMoveLineListItem(moveLineService.createMoveLine(move, clientPartner, accountConfigService.getAdvancePaymentAccount(accountConfig), amountConverted, false, advancePaymentDate, null, 2, ref, null));
    moveService.getMoveValidateService().validate(move);
    advancePayment.setMove(move);
    advancePaymentRepository.save(advancePayment);
    return move;
}
Also used : Company(com.axelor.apps.base.db.Company) Move(com.axelor.apps.account.db.Move) BankDetails(com.axelor.apps.base.db.BankDetails) Journal(com.axelor.apps.account.db.Journal) SaleOrder(com.axelor.apps.sale.db.SaleOrder) Partner(com.axelor.apps.base.db.Partner) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) PaymentMode(com.axelor.apps.account.db.PaymentMode) AccountConfig(com.axelor.apps.account.db.AccountConfig) Transactional(com.google.inject.persist.Transactional)

Example 20 with AccountConfig

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

the class AccountCustomerService method getBalanceDueDebtRecovery.

/**
 * **************************************** 2. Calcul du solde exigible (relançable) du tiers
 * *****************************************
 */
/**
 * solde des factures exigibles non bloquées en relance et dont « la date de facture » + « délai
 * d’acheminement(X) » <« date du jour » si la date de facture = date d'échéance de facture, sinon
 * pas de prise en compte du délai d'acheminement **
 */
/**
 * solde des échéances rejetées qui ne sont pas bloqués
 * *****************************************************
 */
public BigDecimal getBalanceDueDebtRecovery(Partner partner, Company company, TradingName tradingName) {
    log.debug("Compute balance due debt recovery (Partner : {}, Company : {}" + (tradingName != null ? ", Trading name : {})" : ")"), partner.getName(), company.getName(), tradingName != null ? tradingName.getName() : null);
    int mailTransitTime = 0;
    AccountConfig accountConfig = company.getAccountConfig();
    if (accountConfig != null) {
        mailTransitTime = accountConfig.getMailTransitTime();
    }
    // TODO: Replace native query to standard JPQL query
    Query query = JPA.em().createNativeQuery("SELECT SUM( COALESCE(m1.sum_remaining,0) - COALESCE(m2.sum_remaining,0) ) " + "FROM public.account_move_line as ml  " + "LEFT OUTER JOIN ( " + "SELECT moveline.amount_remaining AS sum_remaining, moveline.id AS moveline_id " + "FROM public.account_move_line AS moveline " + "WHERE moveline.debit > 0 AND (( moveline.date_val = moveline.due_date AND (moveline.due_date + :mailTransitTime ) < :todayDate ) " + "OR (moveline.due_date IS NOT NULL AND moveline.date_val != moveline.due_date AND moveline.due_date < :todayDate)" + "OR (moveline.due_date IS NULL AND moveline.date_val < :todayDate)) " + "GROUP BY moveline.id, moveline.amount_remaining) AS m1 ON (m1.moveline_id = ml.id) " + "LEFT OUTER JOIN ( " + "SELECT moveline.amount_remaining AS sum_remaining, moveline.id AS moveline_id " + "FROM public.account_move_line AS moveline " + "WHERE moveline.credit > 0 " + "GROUP BY moveline.id, moveline.amount_remaining) AS m2 ON (m2.moveline_id = ml.id) " + "LEFT OUTER JOIN public.account_account AS account ON (ml.account = account.id) " + "LEFT OUTER JOIN public.account_move AS move ON (ml.move = move.id) " + "LEFT JOIN public.account_invoice AS invoice ON (move.invoice = invoice.id) " + "WHERE ml.partner = :partner AND move.company = :company AND move.ignore_in_debt_recovery_ok in ('false', null) " + (tradingName != null ? "AND move.trading_name = :tradingName " : "") + "AND move.ignore_in_accounting_ok IN ('false', null) AND account.use_for_partner_balance = 'true'" + "AND (move.status_select = :statusValidated OR move.status_select = :statusDaybook) AND ml.amount_remaining > 0 " + "AND (invoice IS NULL OR invoice.debt_recovery_blocking_ok = FALSE) ").setParameter("mailTransitTime", mailTransitTime).setParameter("todayDate", Date.from(appBaseService.getTodayDate(company).atStartOfDay().atZone(ZoneOffset.UTC).toInstant()), TemporalType.DATE).setParameter("partner", partner).setParameter("company", company).setParameter("statusValidated", MoveRepository.STATUS_VALIDATED).setParameter("statusDaybook", MoveRepository.STATUS_ACCOUNTED);
    if (tradingName != null) {
        query = query.setParameter("tradingName", tradingName);
    }
    BigDecimal balance = (BigDecimal) query.getSingleResult();
    if (balance == null) {
        balance = BigDecimal.ZERO;
    }
    log.debug("Balance due debt recovery : {}", balance);
    return balance;
}
Also used : Query(javax.persistence.Query) BigDecimal(java.math.BigDecimal) AccountConfig(com.axelor.apps.account.db.AccountConfig)

Aggregations

AccountConfig (com.axelor.apps.account.db.AccountConfig)46 Company (com.axelor.apps.base.db.Company)27 Move (com.axelor.apps.account.db.Move)18 MoveLine (com.axelor.apps.account.db.MoveLine)17 BigDecimal (java.math.BigDecimal)17 Account (com.axelor.apps.account.db.Account)14 Partner (com.axelor.apps.base.db.Partner)14 Transactional (com.google.inject.persist.Transactional)14 Journal (com.axelor.apps.account.db.Journal)9 AccountConfigService (com.axelor.apps.account.service.config.AccountConfigService)9 AxelorException (com.axelor.exception.AxelorException)9 AccountingSituation (com.axelor.apps.account.db.AccountingSituation)7 Reconcile (com.axelor.apps.account.db.Reconcile)7 BankDetails (com.axelor.apps.base.db.BankDetails)6 LocalDate (java.time.LocalDate)6 ArrayList (java.util.ArrayList)6 Invoice (com.axelor.apps.account.db.Invoice)5 PaymentMode (com.axelor.apps.account.db.PaymentMode)5 List (java.util.List)4 AnalyticMoveLine (com.axelor.apps.account.db.AnalyticMoveLine)3