Search in sources :

Example 26 with AccountConfig

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

the class ReimbursementImportService method testCompanyField.

/**
 * Procédure permettant de tester la présence des champs et des séquences nécessaire aux rejets de
 * remboursement.
 *
 * @param company Une société
 * @throws AxelorException
 */
public void testCompanyField(Company company) throws AxelorException {
    log.debug("Test de la société {}", company.getName());
    AccountConfig accountConfig = accountConfigService.getAccountConfig(company);
    accountConfigService.getReimbursementAccount(accountConfig);
    accountConfigService.getRejectJournal(accountConfig);
    accountConfigService.getReimbursementImportFolderPathCFONB(accountConfig);
    accountConfigService.getTempReimbImportFolderPathCFONB(accountConfig);
}
Also used : AccountConfig(com.axelor.apps.account.db.AccountConfig)

Example 27 with AccountConfig

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

the class ReimbursementImportService method runReimbursementImport.

@Transactional(rollbackOn = { Exception.class })
public void runReimbursementImport(Company company) throws AxelorException, IOException {
    String dataUploadDir = AppService.getFileUploadDir();
    this.testCompanyField(company);
    AccountConfig accountConfig = company.getAccountConfig();
    this.createReimbursementRejectMove(rejectImportService.getCFONBFile(dataUploadDir + accountConfig.getReimbursementImportFolderPathCFONB(), dataUploadDir + accountConfig.getTempReimbImportFolderPathCFONB(), company, 0), company);
}
Also used : AccountConfig(com.axelor.apps.account.db.AccountConfig) Transactional(com.google.inject.persist.Transactional)

Example 28 with AccountConfig

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

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

use of com.axelor.apps.account.db.AccountConfig 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 facture
 *
 * @param invoice Une facture
 * @param prorataRate Le taux de restant à payer sur la facture
 * @param isInvoiceReject La facture est-elle rejetée?
 * @return
 * @throws AxelorException
 */
public Move createIrrecoverableMove(Invoice invoice, BigDecimal prorataRate, boolean isInvoiceReject, String irrecoverableName) throws AxelorException {
    Company company = invoice.getCompany();
    Partner payerPartner = invoice.getPartner();
    AccountConfig accountConfig = company.getAccountConfig();
    // Move
    Move move = moveService.getMoveCreateService().createMove(accountConfig.getIrrecoverableJournal(), company, null, payerPartner, null, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_SALE);
    int seq = 1;
    BigDecimal amount = BigDecimal.ZERO;
    MoveLine debitMoveLine = null;
    BigDecimal creditAmount = null;
    BigDecimal debitAmount = null;
    if (isInvoiceReject) {
        creditAmount = invoice.getRejectMoveLine().getAmountRemaining();
        debitAmount = creditAmount;
    } else {
        creditAmount = invoice.getCompanyInTaxTotalRemaining();
        debitAmount = creditAmount;
    }
    // Debits MoveLines Tva
    for (InvoiceLineTax invoiceLineTax : invoice.getInvoiceLineTaxList()) {
        amount = (invoiceLineTax.getTaxTotal().multiply(prorataRate)).setScale(2, RoundingMode.HALF_UP);
        // do not generate move line with amount equal to zero
        if (amount.signum() == 0) {
            continue;
        }
        debitMoveLine = moveLineService.createMoveLine(move, payerPartner, taxAccountService.getAccount(invoiceLineTax.getTaxLine().getTax(), company, false, false), amount, true, appAccountService.getTodayDate(company), seq, irrecoverableName, invoice.getInvoiceId());
        move.getMoveLineList().add(debitMoveLine);
        seq++;
        debitAmount = debitAmount.subtract(amount);
    }
    // Debit MoveLine 654 (irrecoverable account)
    debitMoveLine = moveLineService.createMoveLine(move, payerPartner, accountConfig.getIrrecoverableAccount(), debitAmount, true, appAccountService.getTodayDate(company), seq, irrecoverableName, invoice.getInvoiceId());
    move.getMoveLineList().add(debitMoveLine);
    seq++;
    // Getting customer MoveLine from Facture
    MoveLine customerMoveLine = moveService.getMoveToolService().getCustomerMoveLineByQuery(invoice);
    if (customerMoveLine == null) {
        throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.IRRECOVERABLE_3), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION), invoice.getInvoiceId());
    }
    customerMoveLine.setIrrecoverableStatusSelect(MoveLineRepository.IRRECOVERABLE_STATUS_PASSED_IN_IRRECOUVRABLE);
    // Credit MoveLine Customer account (411, 416, ...)
    MoveLine creditMoveLine = moveLineService.createMoveLine(move, payerPartner, customerMoveLine.getAccount(), creditAmount, false, appAccountService.getTodayDate(company), seq, irrecoverableName, invoice.getInvoiceId());
    move.getMoveLineList().add(creditMoveLine);
    Reconcile reconcile = reconcileService.createReconcile(customerMoveLine, creditMoveLine, creditAmount, false);
    if (reconcile != null) {
        reconcileService.confirmReconcile(reconcile, true);
    }
    return move;
}
Also used : AxelorException(com.axelor.exception.AxelorException) Company(com.axelor.apps.base.db.Company) Move(com.axelor.apps.account.db.Move) MoveLine(com.axelor.apps.account.db.MoveLine) Partner(com.axelor.apps.base.db.Partner) InvoiceLineTax(com.axelor.apps.account.db.InvoiceLineTax) BigDecimal(java.math.BigDecimal) AccountConfig(com.axelor.apps.account.db.AccountConfig) Reconcile(com.axelor.apps.account.db.Reconcile)

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