Search in sources :

Example 46 with Account

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

the class AccountAccountRepository method save.

@Override
public Account save(Account account) {
    try {
        if (account.getId() == null) {
            return super.save(account);
        }
        if (account.getReconcileOk()) {
            Set<Account> accountList = account.getCompatibleAccountSet();
            if (accountList != null) {
                for (Account acc : accountList) {
                    acc.setReconcileOk(true);
                    acc.addCompatibleAccountSetItem(account);
                    JPA.save(acc);
                }
            }
        } else {
            if (account.getCompatibleAccountSet() != null) {
                for (Account acc : account.getCompatibleAccountSet()) {
                    acc.removeCompatibleAccountSetItem(account);
                    if (acc.getCompatibleAccountSet().size() == 0) {
                        acc.setReconcileOk(false);
                    }
                    JPA.save(acc);
                }
                account.getCompatibleAccountSet().clear();
            }
        }
        return super.save(account);
    } catch (Exception e) {
        TraceBackService.traceExceptionFromSaveMethod(e);
        throw new PersistenceException(e.getMessage(), e);
    }
}
Also used : Account(com.axelor.apps.account.db.Account) PersistenceException(javax.persistence.PersistenceException) PersistenceException(javax.persistence.PersistenceException)

Example 47 with Account

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

the class SubrogationReleaseServiceImpl method enterReleaseInTheAccounts.

@Override
@Transactional(rollbackOn = { Exception.class })
public void enterReleaseInTheAccounts(SubrogationRelease subrogationRelease) throws AxelorException {
    MoveService moveService = Beans.get(MoveService.class);
    MoveRepository moveRepository = Beans.get(MoveRepository.class);
    AccountConfigService accountConfigService = Beans.get(AccountConfigService.class);
    AppBaseService appBaseService = Beans.get(AppBaseService.class);
    Company company = subrogationRelease.getCompany();
    AccountConfig accountConfig = accountConfigService.getAccountConfig(company);
    Journal journal = accountConfigService.getAutoMiscOpeJournal(accountConfig);
    Account factorCreditAccount = accountConfigService.getFactorCreditAccount(accountConfig);
    Account factorDebitAccount = accountConfigService.getFactorDebitAccount(accountConfig);
    if (subrogationRelease.getAccountingDate() == null) {
        subrogationRelease.setAccountingDate(appBaseService.getTodayDate(company));
    }
    this.checkIfAnOtherSubrogationAlreadyExist(subrogationRelease);
    for (Invoice invoice : subrogationRelease.getInvoiceSet()) {
        boolean isRefund = false;
        if (invoice.getOperationTypeSelect() == InvoiceRepository.OPERATION_TYPE_CLIENT_REFUND) {
            isRefund = true;
        }
        LocalDate date = subrogationRelease.getAccountingDate();
        Move move = moveService.getMoveCreateService().createMove(journal, company, company.getCurrency(), invoice.getPartner(), date, null, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_PAYMENT);
        MoveLine creditMoveLine, debitMoveLine;
        debitMoveLine = moveService.getMoveLineService().createMoveLine(move, invoice.getPartner(), factorDebitAccount, invoice.getCompanyInTaxTotalRemaining(), !isRefund, date, null, 1, subrogationRelease.getSequenceNumber(), invoice.getInvoiceId());
        creditMoveLine = moveService.getMoveLineService().createMoveLine(move, invoice.getPartner(), factorCreditAccount, invoice.getCompanyInTaxTotalRemaining(), isRefund, date, null, 2, subrogationRelease.getSequenceNumber(), invoice.getInvoiceId());
        move.addMoveLineListItem(debitMoveLine);
        move.addMoveLineListItem(creditMoveLine);
        move = moveRepository.save(move);
        moveService.getMoveValidateService().validate(move);
        invoice.setSubrogationRelease(subrogationRelease);
        invoice.setSubrogationReleaseMove(move);
        subrogationRelease.addMoveListItem(move);
    }
    subrogationRelease.setStatusSelect(SubrogationReleaseRepository.STATUS_ACCOUNTED);
}
Also used : MoveRepository(com.axelor.apps.account.db.repo.MoveRepository) Account(com.axelor.apps.account.db.Account) Company(com.axelor.apps.base.db.Company) Invoice(com.axelor.apps.account.db.Invoice) MoveService(com.axelor.apps.account.service.move.MoveService) Journal(com.axelor.apps.account.db.Journal) LocalDate(java.time.LocalDate) AccountConfig(com.axelor.apps.account.db.AccountConfig) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) Move(com.axelor.apps.account.db.Move) AccountConfigService(com.axelor.apps.account.service.config.AccountConfigService) MoveLine(com.axelor.apps.account.db.MoveLine) Transactional(com.google.inject.persist.Transactional)

Example 48 with Account

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

the class IrrecoverableService method createIrrecoverableMove.

/**
 * Fonction permettant de créer l'écriture de passage en irrécouvrable d'une échéance
 *
 * @param moveLine Une écriture d'échéance
 * @return
 * @throws AxelorException
 */
public Move createIrrecoverableMove(MoveLine moveLine, String irrecoverableName) throws AxelorException {
    Company company = moveLine.getMove().getCompany();
    Partner payerPartner = moveLine.getPartner();
    BigDecimal amount = moveLine.getAmountRemaining();
    AccountConfig accountConfig = company.getAccountConfig();
    // Move
    Move move = moveService.getMoveCreateService().createMove(accountConfig.getIrrecoverableJournal(), company, null, payerPartner, null, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, moveLine.getMove().getFunctionalOriginSelect());
    int seq = 1;
    // Credit MoveLine Customer account (411, 416, ...)
    MoveLine creditMoveLine = moveLineService.createMoveLine(move, payerPartner, moveLine.getAccount(), amount, false, appAccountService.getTodayDate(company), seq, irrecoverableName, moveLine.getDescription());
    move.getMoveLineList().add(creditMoveLine);
    Reconcile reconcile = reconcileService.createReconcile(moveLine, creditMoveLine, amount, false);
    if (reconcile != null) {
        reconcileService.confirmReconcile(reconcile, true);
    }
    Tax tax = accountConfig.getIrrecoverableStandardRateTax();
    BigDecimal taxRate = taxService.getTaxRate(tax, appAccountService.getTodayDate(company));
    // Debit MoveLine 654. (irrecoverable account)
    BigDecimal divid = taxRate.add(BigDecimal.ONE);
    BigDecimal irrecoverableAmount = amount.divide(divid, 6, RoundingMode.HALF_UP).setScale(AppBaseService.DEFAULT_NB_DECIMAL_DIGITS, RoundingMode.HALF_UP);
    MoveLine creditMoveLine1 = moveLineService.createMoveLine(move, payerPartner, accountConfig.getIrrecoverableAccount(), irrecoverableAmount, true, appAccountService.getTodayDate(company), 2, irrecoverableName, moveLine.getDescription());
    move.getMoveLineList().add(creditMoveLine1);
    // Debit MoveLine 445 (Tax account)
    Account taxAccount = taxAccountService.getAccount(tax, company, false, false);
    BigDecimal taxAmount = amount.subtract(irrecoverableAmount);
    MoveLine creditMoveLine2 = moveLineService.createMoveLine(move, payerPartner, taxAccount, taxAmount, true, appAccountService.getTodayDate(company), 3, irrecoverableName, moveLine.getDescription());
    move.getMoveLineList().add(creditMoveLine2);
    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) MoveLine(com.axelor.apps.account.db.MoveLine) InvoiceLineTax(com.axelor.apps.account.db.InvoiceLineTax) Tax(com.axelor.apps.account.db.Tax) Partner(com.axelor.apps.base.db.Partner) BigDecimal(java.math.BigDecimal) AccountConfig(com.axelor.apps.account.db.AccountConfig) Reconcile(com.axelor.apps.account.db.Reconcile)

Example 49 with Account

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

the class NotificationServiceImpl method createPaymentMove.

@Transactional(rollbackOn = { Exception.class })
protected Move createPaymentMove(NotificationItem notificationItem) throws AxelorException {
    Notification notification = notificationItem.getNotification();
    Invoice invoice = notificationItem.getInvoice();
    Company company = invoice.getCompany();
    AccountConfig accountConfig = accountConfigService.getAccountConfig(company);
    Journal journal = getJournal(accountConfig);
    SubrogationRelease subrogationRelease = getSubrogationRelease(notificationItem);
    String origin = computeOrigin(subrogationRelease, invoice);
    BigDecimal amountPaid = notificationItem.getAmountPaid();
    if (amountPaid.compareTo(BigDecimal.ZERO) == 0) {
        return null;
    }
    Move paymentMove = moveService.getMoveCreateService().createMove(journal, company, company.getCurrency(), invoice.getPartner(), notification.getPaymentDate(), null, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_PAYMENT);
    MoveLine creditMoveLine, debitMoveLine;
    Account account = getAccount(accountConfig, notificationItem);
    debitMoveLine = moveService.getMoveLineService().createMoveLine(paymentMove, invoice.getPartner(), account, amountPaid, true, notification.getPaymentDate(), null, 1, origin, invoice.getInvoiceId());
    creditMoveLine = moveService.getMoveLineService().createMoveLine(paymentMove, invoice.getPartner(), invoice.getPartnerAccount(), amountPaid, false, notification.getPaymentDate(), null, 2, origin, invoice.getInvoiceId());
    paymentMove.addMoveLineListItem(debitMoveLine);
    paymentMove.addMoveLineListItem(creditMoveLine);
    paymentMove = moveRepository.save(paymentMove);
    moveService.getMoveValidateService().validate(paymentMove);
    MoveLine invoiceMoveLine = findInvoiceAccountMoveLine(invoice);
    MoveLine subrogationReleaseMoveLine = findSubrogationReleaseAccountMoveLine(invoice);
    if (invoiceMoveLine.getAmountRemaining().compareTo(BigDecimal.ZERO) == 1) {
        reconcileService.reconcile(invoiceMoveLine, creditMoveLine, true, true);
        if (subrogationReleaseMoveLine != null && notificationItem.getTypeSelect() == NotificationRepository.TYPE_PAYMENT_TO_THE_FACTORE) {
            reconcileService.reconcile(debitMoveLine, subrogationReleaseMoveLine, true, false);
        }
    }
    notificationItem.setMove(paymentMove);
    if (subrogationRelease != null) {
        subrogationReleaseService.clear(subrogationRelease);
    }
    return paymentMove;
}
Also used : Account(com.axelor.apps.account.db.Account) Company(com.axelor.apps.base.db.Company) Invoice(com.axelor.apps.account.db.Invoice) Move(com.axelor.apps.account.db.Move) SubrogationRelease(com.axelor.apps.account.db.SubrogationRelease) MoveLine(com.axelor.apps.account.db.MoveLine) Journal(com.axelor.apps.account.db.Journal) Notification(com.axelor.apps.account.db.Notification) BigDecimal(java.math.BigDecimal) AccountConfig(com.axelor.apps.account.db.AccountConfig) Transactional(com.google.inject.persist.Transactional)

Example 50 with Account

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

the class AccountingSituationInitServiceImpl method createAccount.

protected Account createAccount(String fullName, String accountCode, Account parentAccount, AccountType accountType, boolean reconcileOk, Company company, boolean useForPartnerBalance) {
    Account account = new Account();
    account.setName(fullName);
    account.setCode(accountCode);
    account.setParentAccount(parentAccount);
    account.setAccountType(accountType);
    account.setReconcileOk(reconcileOk);
    account.setCompany(company);
    account.setUseForPartnerBalance(useForPartnerBalance);
    account.setCompatibleAccountSet(new HashSet<>());
    return account;
}
Also used : Account(com.axelor.apps.account.db.Account)

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