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);
}
}
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();
}
}
}
}
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);
}
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);
}
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;
}
Aggregations