Search in sources :

Example 16 with AccountingSituation

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

the class BatchAccountCustomer method updateAccountingSituationMarked.

public String updateAccountingSituationMarked(Company company) {
    int anomaly = 0;
    List<AccountingSituation> accountingSituationList = null;
    if (company != null) {
        accountingSituationList = accountingSituationRepo.all().filter("self.company = ?1 and self.custAccountMustBeUpdateOk = 'true'", company).fetch();
    } else {
        accountingSituationList = accountingSituationRepo.all().filter("self.custAccountMustBeUpdateOk = 'true'").fetch();
    }
    int i = 0;
    JPA.clear();
    for (AccountingSituation accountingSituation : accountingSituationList) {
        try {
            accountingSituation = accountCustomerService.updateAccountingSituationCustomerAccount(accountingSituationRepo.find(accountingSituation.getId()), true, true, false);
            if (accountingSituation != null) {
                i++;
            }
        } catch (Exception e) {
            TraceBackService.trace(new Exception(String.format(I18n.get(IExceptionMessage.BATCH_ACCOUNT_1), accountingSituationRepo.find(accountingSituation.getId()).getName()), e), ExceptionOriginRepository.CUSTOMER_ACCOUNT, batch.getId());
            anomaly++;
            log.error("Bug(Anomalie) généré(e) pour le compte client {}", accountingSituationRepo.find(accountingSituation.getId()));
        } finally {
            if (i % 5 == 0) {
                JPA.clear();
            }
        }
    }
    if (anomaly != 0) {
        return String.format(I18n.get(IExceptionMessage.BATCH_ACCOUNT_4), anomaly);
    } else {
        return String.format(I18n.get(IExceptionMessage.BATCH_ACCOUNT_5), i);
    }
}
Also used : AccountingSituation(com.axelor.apps.account.db.AccountingSituation)

Example 17 with AccountingSituation

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

the class BatchAccountCustomer method process.

@Override
public void process() {
    AccountingBatch accountingBatch = batch.getAccountingBatch();
    Company company = accountingBatch.getCompany();
    boolean updateCustAccountOk = accountingBatch.getUpdateCustAccountOk();
    boolean updateDueCustAccountOk = accountingBatch.getUpdateDueCustAccountOk();
    boolean updateDueDebtRecoveryCustAccountOk = accountingBatch.getUpdateDueDebtRecoveryCustAccountOk();
    List<AccountingSituation> accountingSituationList = accountingSituationRepo.all().filter("self.company = ?1", company).fetch();
    int i = 0;
    JPA.clear();
    for (AccountingSituation accountingSituation : accountingSituationList) {
        try {
            accountingSituation = accountCustomerService.updateAccountingSituationCustomerAccount(accountingSituationRepo.find(accountingSituation.getId()), updateCustAccountOk, updateDueCustAccountOk, updateDueDebtRecoveryCustAccountOk);
            if (accountingSituation != null) {
                this.updateAccountingSituation(accountingSituation);
                i++;
            }
        } catch (Exception e) {
            TraceBackService.trace(new Exception(String.format(I18n.get(IExceptionMessage.BATCH_ACCOUNT_1), accountingSituationRepo.find(accountingSituation.getId()).getName()), e), ExceptionOriginRepository.CUSTOMER_ACCOUNT, batch.getId());
            incrementAnomaly();
            log.error("Bug(Anomalie) généré(e) pour la situation compable {}", accountingSituationRepo.find(accountingSituation.getId()).getName());
        } finally {
            if (i % 1 == 0) {
                JPA.clear();
            }
        }
    }
}
Also used : Company(com.axelor.apps.base.db.Company) AccountingSituation(com.axelor.apps.account.db.AccountingSituation) AccountingBatch(com.axelor.apps.account.db.AccountingBatch)

Example 18 with AccountingSituation

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

the class YearServiceAccountImpl method closeYearProcess.

/**
 * Procédure permettant de cloturer un exercice comptable
 *
 * @param year Un exercice comptable
 * @throws AxelorException
 */
public void closeYearProcess(Year year) throws AxelorException {
    year = yearRepository.find(year.getId());
    for (Period period : year.getPeriodList()) {
        if (period.getStatusSelect() == PeriodRepository.STATUS_ADJUSTING) {
            adjustHistoryService.setEndDate(period);
        }
        period.setStatusSelect(PeriodRepository.STATUS_CLOSED);
        period.setClosureDateTime(LocalDateTime.now());
    }
    Company company = year.getCompany();
    if (company == null) {
        throw new AxelorException(year, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.YEAR_1), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION), year.getName());
    }
    Query q;
    if (year.getStatusSelect() == YearRepository.STATUS_ADJUSTING) {
        AdjustHistory adjustHistory = adjustHistoryService.setEndDate(year);
        q = JPA.em().createQuery("select DISTINCT(self.partner) FROM MoveLine as self WHERE self.move.ignoreInAccountingOk = false AND self.move.period.year = ?1 " + "AND self.move.statusSelect = ?2 AND self.move.adjustingMove = true AND self.date >= ?3 AND self.date <= ?4 AND self.move.company = ?5");
        q.setParameter(1, year);
        q.setParameter(2, MoveRepository.STATUS_VALIDATED);
        q.setParameter(3, adjustHistory.getStartDate().toLocalDate());
        q.setParameter(4, adjustHistory.getEndDate().toLocalDate());
    } else {
        q = JPA.em().createQuery("select DISTINCT(self.partner) FROM MoveLine as self WHERE self.move.ignoreInAccountingOk = false AND self.move.period.year = ?1 " + "AND self.move.statusSelect = ?2 AND self.date >= ?3 AND self.date <= ?4 AND self.move.company = ?5");
        q.setParameter(1, year);
        q.setParameter(2, MoveRepository.STATUS_VALIDATED);
        q.setParameter(3, year.getFromDate());
        q.setParameter(4, year.getToDate());
    }
    q.setParameter(5, year.getCompany());
    @SuppressWarnings("unchecked") List<Partner> partnerList = q.getResultList();
    List<? extends Partner> partnerListAll = partnerRepository.all().fetch();
    log.debug("Nombre total de tiers : {}", partnerListAll.size());
    log.debug("Nombre de tiers récupéré : {}", partnerList.size());
    for (Partner partner : partnerList) {
        partner = partnerRepository.find(partner.getId());
        year = yearRepository.find(year.getId());
        log.debug("Tiers en cours de traitement : {}", partner.getName());
        for (AccountingSituation accountingSituation : partner.getAccountingSituationList()) {
            if (accountingSituation.getCompany().equals(year.getCompany())) {
                log.debug("On ajoute une ligne à la Situation comptable trouvée");
                BigDecimal reportedBalanceAmount = this.computeReportedBalance(year.getFromDate(), year.getToDate(), partner, year);
                this.createReportedBalanceLine(accountingSituation, reportedBalanceAmount, year);
                break;
            }
        }
        JPA.clear();
    }
    year = yearRepository.find(year.getId());
    closeYear(year);
}
Also used : AxelorException(com.axelor.exception.AxelorException) Company(com.axelor.apps.base.db.Company) Query(javax.persistence.Query) AccountingSituation(com.axelor.apps.account.db.AccountingSituation) Period(com.axelor.apps.base.db.Period) Partner(com.axelor.apps.base.db.Partner) BigDecimal(java.math.BigDecimal) AdjustHistory(com.axelor.apps.base.db.AdjustHistory)

Example 19 with AccountingSituation

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

the class AccountingSituationInitServiceImpl method createAccountingSituation.

@Override
@Transactional(rollbackOn = { Exception.class })
public AccountingSituation createAccountingSituation(Partner partner, Company company) throws AxelorException {
    AccountingSituation accountingSituation = new AccountingSituation();
    accountingSituation.setCompany(company);
    partner.addCompanySetItem(company);
    PaymentMode inPaymentMode = partner.getInPaymentMode();
    PaymentMode outPaymentMode = partner.getOutPaymentMode();
    BankDetails defaultBankDetails = company.getDefaultBankDetails();
    if (inPaymentMode != null) {
        List<BankDetails> authorizedInBankDetails = paymentModeService.getCompatibleBankDetailsList(inPaymentMode, company);
        if (authorizedInBankDetails.contains(defaultBankDetails)) {
            accountingSituation.setCompanyInBankDetails(defaultBankDetails);
        }
    }
    if (outPaymentMode != null) {
        List<BankDetails> authorizedOutBankDetails = paymentModeService.getCompatibleBankDetailsList(outPaymentMode, company);
        if (authorizedOutBankDetails.contains(defaultBankDetails)) {
            accountingSituation.setCompanyOutBankDetails(defaultBankDetails);
        }
    }
    AccountConfig accountConfig = accountConfigService.getAccountConfig(company);
    accountingSituation.setInvoiceAutomaticMail(accountConfig.getInvoiceAutomaticMail());
    accountingSituation.setInvoiceMessageTemplate(accountConfig.getInvoiceMessageTemplate());
    partner.addAccountingSituationListItem(accountingSituation);
    return accountingSituationRepository.save(accountingSituation);
}
Also used : BankDetails(com.axelor.apps.base.db.BankDetails) AccountingSituation(com.axelor.apps.account.db.AccountingSituation) PaymentMode(com.axelor.apps.account.db.PaymentMode) AccountConfig(com.axelor.apps.account.db.AccountConfig) Transactional(com.google.inject.persist.Transactional)

Example 20 with AccountingSituation

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

the class AccountingSituationServiceImpl method getCustomerAccount.

@Override
public Account getCustomerAccount(Partner partner, Company company) throws AxelorException {
    Account account = null;
    AccountingSituation accountingSituation = getAccountingSituation(partner, company);
    if (accountingSituation != null) {
        account = accountingSituation.getCustomerAccount();
    }
    if (account == null) {
        AccountConfig accountConfig = accountConfigService.getAccountConfig(company);
        account = accountConfigService.getCustomerAccount(accountConfig);
    }
    return account;
}
Also used : Account(com.axelor.apps.account.db.Account) AccountingSituation(com.axelor.apps.account.db.AccountingSituation) AccountConfig(com.axelor.apps.account.db.AccountConfig)

Aggregations

AccountingSituation (com.axelor.apps.account.db.AccountingSituation)26 Partner (com.axelor.apps.base.db.Partner)9 Company (com.axelor.apps.base.db.Company)8 AccountConfig (com.axelor.apps.account.db.AccountConfig)6 AxelorException (com.axelor.exception.AxelorException)6 AccountingSituationService (com.axelor.apps.account.service.AccountingSituationService)5 Transactional (com.google.inject.persist.Transactional)5 BankDetails (com.axelor.apps.base.db.BankDetails)4 BigDecimal (java.math.BigDecimal)4 Account (com.axelor.apps.account.db.Account)3 DebtRecovery (com.axelor.apps.account.db.DebtRecovery)3 Invoice (com.axelor.apps.account.db.Invoice)3 PaymentMode (com.axelor.apps.account.db.PaymentMode)3 AccountingSituationRepository (com.axelor.apps.account.db.repo.AccountingSituationRepository)3 InvoiceLine (com.axelor.apps.account.db.InvoiceLine)2 MoveLine (com.axelor.apps.account.db.MoveLine)2 InvoiceRepository (com.axelor.apps.account.db.repo.InvoiceRepository)2 AccountConfigService (com.axelor.apps.account.service.config.AccountConfigService)2 PaymentModeService (com.axelor.apps.account.service.payment.PaymentModeService)2 Address (com.axelor.apps.base.db.Address)2