Search in sources :

Example 1 with Account

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

the class AccountClearanceService method validateAccountClearance.

@Transactional(rollbackOn = { Exception.class })
public void validateAccountClearance(AccountClearance accountClearance) throws AxelorException {
    Company company = accountClearance.getCompany();
    AccountConfig accountConfig = company.getAccountConfig();
    Tax tax = accountConfig.getStandardRateTax();
    BigDecimal taxRate = taxService.getTaxRate(tax, appBaseService.getTodayDateTime().toLocalDate());
    Account taxAccount = taxAccountService.getAccount(tax, company, false, false);
    Account profitAccount = accountConfig.getProfitAccount();
    Journal journal = accountConfig.getAccountClearanceJournal();
    Set<MoveLine> moveLineList = accountClearance.getMoveLineSet();
    for (MoveLine moveLine : moveLineList) {
        Move move = this.createAccountClearanceMove(moveLine, taxRate, taxAccount, profitAccount, company, journal, accountClearance);
        moveService.getMoveValidateService().validate(move);
    }
    accountClearance.setStatusSelect(AccountClearanceRepository.STATUS_VALIDATED);
    accountClearance.setDateTime(appBaseService.getTodayDateTime());
    accountClearance.setName(sequenceService.getSequenceNumber(SequenceRepository.ACCOUNT_CLEARANCE, company));
    accountClearanceRepo.save(accountClearance);
}
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) Tax(com.axelor.apps.account.db.Tax) Journal(com.axelor.apps.account.db.Journal) BigDecimal(java.math.BigDecimal) AccountConfig(com.axelor.apps.account.db.AccountConfig) Transactional(com.google.inject.persist.Transactional)

Example 2 with Account

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

the class AccountManagementServiceAccountImpl method getProductAccount.

/**
 * Get the product tax
 *
 * @param product
 * @param company
 * @param isPurchase
 * @param fixedAsset Specify if we should get the purchase account for fixed asset or not. Used
 *     only if isPurchase param is true.
 * @param configObject Specify if we want get the tax from the product or its product family
 *     <li>1 : product
 *     <li>2 : product family
 * @return
 * @throws AxelorException
 */
@CallMethod
protected Account getProductAccount(Product product, Company company, boolean isPurchase, boolean fixedAsset, int configObject) {
    AccountManagement accountManagement = this.getAccountManagement(product, company, configObject);
    Account account = null;
    if (accountManagement != null) {
        if (isPurchase) {
            if (fixedAsset) {
                account = accountManagement.getPurchFixedAssetsAccount();
            } else {
                account = accountManagement.getPurchaseAccount();
            }
        } else {
            account = accountManagement.getSaleAccount();
        }
    }
    if (account == null && configObject == CONFIG_OBJECT_PRODUCT) {
        return getProductAccount(product, company, isPurchase, fixedAsset, CONFIG_OBJECT_PRODUCT_FAMILY);
    }
    return account;
}
Also used : Account(com.axelor.apps.account.db.Account) AccountManagement(com.axelor.apps.account.db.AccountManagement) CallMethod(com.axelor.meta.CallMethod)

Example 3 with Account

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

the class PaymentScheduleLineServiceImpl method createPaymentMove.

@Override
@Transactional(rollbackOn = { Exception.class })
public Move createPaymentMove(PaymentScheduleLine paymentScheduleLine, BankDetails companyBankDetails, PaymentMode paymentMode) throws AxelorException {
    Preconditions.checkNotNull(paymentScheduleLine);
    Preconditions.checkNotNull(companyBankDetails);
    PaymentSchedule paymentSchedule = paymentScheduleLine.getPaymentSchedule();
    Company company = paymentSchedule.getCompany();
    Partner partner = paymentSchedule.getPartner();
    Journal journal = paymentModeService.getPaymentModeJournal(paymentMode, company, companyBankDetails);
    BigDecimal amount = paymentScheduleLine.getInTaxAmount();
    String name = paymentScheduleLine.getName();
    LocalDate todayDate = appBaseService.getTodayDate(company);
    Account account = accountingSituationService.getCustomerAccount(partner, company);
    Move move = moveService.getMoveCreateService().createMove(journal, company, null, partner, paymentMode, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_PAYMENT);
    MoveLine creditMoveLine = moveService.getMoveLineService().createMoveLine(move, partner, account, amount, false, todayDate, 1, name, null);
    move.addMoveLineListItem(creditMoveLine);
    creditMoveLine = moveLineRepo.save(creditMoveLine);
    Account paymentModeAccount = paymentModeService.getPaymentModeAccount(paymentMode, company, companyBankDetails);
    MoveLine debitMoveLine = moveService.getMoveLineService().createMoveLine(move, partner, paymentModeAccount, amount, true, todayDate, 2, name, null);
    move.addMoveLineListItem(debitMoveLine);
    debitMoveLine = moveLineRepo.save(debitMoveLine);
    moveService.getMoveValidateService().validate(move);
    // Reconcile
    if (paymentSchedule.getTypeSelect() == PaymentScheduleRepository.TYPE_TERMS && paymentSchedule.getInvoiceSet() != null) {
        List<MoveLine> debitMoveLineList = paymentSchedule.getInvoiceSet().stream().sorted(Comparator.comparing(Invoice::getDueDate)).map(invoice -> moveService.getMoveLineService().getDebitCustomerMoveLine(invoice)).collect(Collectors.toList());
        if (moveToolService.isSameAccount(debitMoveLineList, account)) {
            List<MoveLine> creditMoveLineList = Lists.newArrayList(creditMoveLine);
            paymentService.useExcessPaymentOnMoveLines(debitMoveLineList, creditMoveLineList);
        }
    }
    paymentScheduleLine.setDirectDebitAmount(amount);
    paymentScheduleLine.setInTaxAmountPaid(amount);
    paymentScheduleLine.setAdvanceOrPaymentMove(move);
    paymentScheduleLine.setAdvanceMoveLine(creditMoveLine);
    paymentScheduleLine.setStatusSelect(PaymentScheduleLineRepository.STATUS_VALIDATED);
    paymentScheduleService.closePaymentScheduleIfAllPaid(paymentSchedule);
    return move;
}
Also used : Company(com.axelor.apps.base.db.Company) PaymentSchedule(com.axelor.apps.account.db.PaymentSchedule) Move(com.axelor.apps.account.db.Move) MoveService(com.axelor.apps.account.service.move.MoveService) PaymentService(com.axelor.apps.account.service.payment.PaymentService) Inject(com.google.inject.Inject) LoggerFactory(org.slf4j.LoggerFactory) PaymentModeService(com.axelor.apps.account.service.payment.PaymentModeService) Transactional(com.google.inject.persist.Transactional) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal) Lists(com.google.common.collect.Lists) AxelorException(com.axelor.exception.AxelorException) MoveLine(com.axelor.apps.account.db.MoveLine) PaymentScheduleLine(com.axelor.apps.account.db.PaymentScheduleLine) MoveToolService(com.axelor.apps.account.service.move.MoveToolService) PaymentScheduleRepository(com.axelor.apps.account.db.repo.PaymentScheduleRepository) RoundingMode(java.math.RoundingMode) Journal(com.axelor.apps.account.db.Journal) Logger(org.slf4j.Logger) MethodHandles(java.lang.invoke.MethodHandles) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) Invoice(com.axelor.apps.account.db.Invoice) Collectors(java.util.stream.Collectors) Account(com.axelor.apps.account.db.Account) SequenceService(com.axelor.apps.base.service.administration.SequenceService) List(java.util.List) PaymentScheduleLineRepository(com.axelor.apps.account.db.repo.PaymentScheduleLineRepository) LocalDate(java.time.LocalDate) PaymentMode(com.axelor.apps.account.db.PaymentMode) Preconditions(com.google.common.base.Preconditions) Comparator(java.util.Comparator) MoveLineRepository(com.axelor.apps.account.db.repo.MoveLineRepository) Partner(com.axelor.apps.base.db.Partner) MoveRepository(com.axelor.apps.account.db.repo.MoveRepository) BankDetails(com.axelor.apps.base.db.BankDetails) Account(com.axelor.apps.account.db.Account) Company(com.axelor.apps.base.db.Company) PaymentSchedule(com.axelor.apps.account.db.PaymentSchedule) 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) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) Transactional(com.google.inject.persist.Transactional)

Example 4 with Account

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

the class ReconcileGroupServiceImpl method isBalanced.

@Override
public boolean isBalanced(List<Reconcile> reconcileList) {
    List<MoveLine> debitMoveLineList = reconcileList.stream().map(Reconcile::getDebitMoveLine).distinct().collect(Collectors.toList());
    List<MoveLine> creditMoveLineList = reconcileList.stream().map(Reconcile::getCreditMoveLine).distinct().collect(Collectors.toList());
    List<Account> accountList = debitMoveLineList.stream().map(MoveLine::getAccount).distinct().collect(Collectors.toList());
    accountList.addAll(creditMoveLineList.stream().map(MoveLine::getAccount).distinct().collect(Collectors.toList()));
    for (Account account : accountList) {
        BigDecimal totalDebit = debitMoveLineList.stream().filter(moveLine -> moveLine.getAccount().equals(account)).map(MoveLine::getDebit).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        BigDecimal totalCredit = creditMoveLineList.stream().filter(moveLine -> moveLine.getAccount().equals(account)).map(MoveLine::getCredit).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        if (totalDebit.compareTo(totalCredit) != 0) {
            return false;
        }
    }
    return true;
}
Also used : Company(com.axelor.apps.base.db.Company) TraceBackRepository(com.axelor.exception.db.repo.TraceBackRepository) ReconcileRepository(com.axelor.apps.account.db.repo.ReconcileRepository) Inject(com.google.inject.Inject) ReconcileGroupRepository(com.axelor.apps.account.db.repo.ReconcileGroupRepository) Reconcile(com.axelor.apps.account.db.Reconcile) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) Collectors(java.util.stream.Collectors) Account(com.axelor.apps.account.db.Account) Transactional(com.google.inject.persist.Transactional) ArrayList(java.util.ArrayList) IExceptionMessage(com.axelor.apps.account.exception.IExceptionMessage) BigDecimal(java.math.BigDecimal) List(java.util.List) ReconcileGroup(com.axelor.apps.account.db.ReconcileGroup) AxelorException(com.axelor.exception.AxelorException) MoveLine(com.axelor.apps.account.db.MoveLine) CollectionUtils(org.apache.commons.collections.CollectionUtils) I18n(com.axelor.i18n.I18n) Optional(java.util.Optional) MoveLineRepository(com.axelor.apps.account.db.repo.MoveLineRepository) Account(com.axelor.apps.account.db.Account) MoveLine(com.axelor.apps.account.db.MoveLine) BigDecimal(java.math.BigDecimal) Reconcile(com.axelor.apps.account.db.Reconcile)

Example 5 with Account

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

the class AccountingSituationInitServiceImpl method createSupplierAccount.

protected void createSupplierAccount(AccountConfig accountConfig, AccountingSituation situation, int creationMode) throws AxelorException {
    Partner partner = situation.getPartner();
    if (partner.getIsSupplier() == Boolean.FALSE || situation.getSupplierAccount() != null)
        return;
    if (accountConfig.getSupplierAccount() == null) {
        throw new AxelorException(partner, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.ACCOUNT_CUSTOMER_2), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION), situation.getCompany().getName());
    }
    final String accountCode;
    if (creationMode == AccountConfigRepository.AUTOMATIC_ACCOUNT_CREATION_PREFIX) {
        final String prefix = accountConfig.getSupplierAccountPrefix();
        if (StringUtils.isBlank(prefix)) {
            throw new AxelorException(situation, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.ACCOUNTING_SITUATION_4), situation.getCompany().getName());
        }
        accountCode = getPrefixedAccountCode(prefix, partner);
    } else if (creationMode == AccountConfigRepository.AUTOMATIC_ACCOUNT_CREATION_SEQUENCE) {
        final Sequence sequence = accountConfig.getSupplierAccountSequence();
        if (sequence == null) {
            throw new AxelorException(situation, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.ACCOUNTING_SITUATION_5), situation.getCompany().getName());
        }
        accountCode = sequenceService.getSequenceNumber(sequence);
    } else {
        throw new AxelorException(situation, TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.ACCOUNTING_SITUATION_3), situation.getCompany().getName());
    }
    Account account = this.createAccount(partner.getFullName(), accountCode, accountConfig.getSupplierAccount(), accountConfig.getSupplierAccount().getAccountType(), true, situation.getCompany(), true);
    situation.setSupplierAccount(account);
}
Also used : AxelorException(com.axelor.exception.AxelorException) Account(com.axelor.apps.account.db.Account) Sequence(com.axelor.apps.base.db.Sequence) Partner(com.axelor.apps.base.db.Partner)

Aggregations

Account (com.axelor.apps.account.db.Account)59 MoveLine (com.axelor.apps.account.db.MoveLine)27 Company (com.axelor.apps.base.db.Company)26 BigDecimal (java.math.BigDecimal)26 Partner (com.axelor.apps.base.db.Partner)25 Move (com.axelor.apps.account.db.Move)21 AxelorException (com.axelor.exception.AxelorException)20 Journal (com.axelor.apps.account.db.Journal)18 Transactional (com.google.inject.persist.Transactional)18 AccountConfig (com.axelor.apps.account.db.AccountConfig)14 LocalDate (java.time.LocalDate)12 AnalyticMoveLine (com.axelor.apps.account.db.AnalyticMoveLine)10 ArrayList (java.util.ArrayList)10 TaxLine (com.axelor.apps.account.db.TaxLine)8 Invoice (com.axelor.apps.account.db.Invoice)7 Reconcile (com.axelor.apps.account.db.Reconcile)7 InvoiceLine (com.axelor.apps.account.db.InvoiceLine)6 BankDetails (com.axelor.apps.base.db.BankDetails)6 PaymentMode (com.axelor.apps.account.db.PaymentMode)5 Product (com.axelor.apps.base.db.Product)5