use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.
the class ReconcileServiceImpl method reconcilePreconditions.
public void reconcilePreconditions(Reconcile reconcile) throws AxelorException {
MoveLine debitMoveLine = reconcile.getDebitMoveLine();
MoveLine creditMoveLine = reconcile.getCreditMoveLine();
if (debitMoveLine == null || creditMoveLine == null) {
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.RECONCILE_1), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION));
}
// Check if move lines companies are the same as the reconcile company
Company reconcileCompany = reconcile.getCompany();
Company debitMoveLineCompany = debitMoveLine.getMove().getCompany();
Company creditMoveLineCompany = creditMoveLine.getMove().getCompany();
if (!debitMoveLineCompany.equals(reconcileCompany) && !creditMoveLineCompany.equals(reconcileCompany)) {
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, String.format(I18n.get(IExceptionMessage.RECONCILE_7), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION), debitMoveLineCompany, creditMoveLineCompany, reconcileCompany));
}
// Check if move lines accounts are the same (debit and credit)
if (!creditMoveLine.getAccount().equals(debitMoveLine.getAccount())) {
log.debug("Compte ligne de credit : {} , Compte ligne de debit : {}", creditMoveLine.getAccount(), debitMoveLine.getAccount());
// Check if move lines accounts are compatible
if (!debitMoveLine.getAccount().getCompatibleAccountSet().contains(creditMoveLine.getAccount())) {
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.RECONCILE_2), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION));
}
}
// Check if the amount to reconcile is != zero
if (reconcile.getAmount() == null || reconcile.getAmount().compareTo(BigDecimal.ZERO) == 0) {
throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.RECONCILE_4), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION), reconcile.getReconcileSeq(), debitMoveLine.getName(), debitMoveLine.getAccount().getLabel(), creditMoveLine.getName(), creditMoveLine.getAccount().getLabel());
}
if ((reconcile.getAmount().compareTo(creditMoveLine.getCredit().subtract(creditMoveLine.getAmountPaid())) > 0 || (reconcile.getAmount().compareTo(debitMoveLine.getDebit().subtract(debitMoveLine.getAmountPaid())) > 0))) {
throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.RECONCILE_5) + " " + I18n.get(IExceptionMessage.RECONCILE_3), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION), reconcile.getReconcileSeq(), reconcile.getAmount(), debitMoveLine.getName(), debitMoveLine.getAccount().getLabel(), debitMoveLine.getDebit().subtract(debitMoveLine.getAmountPaid()), creditMoveLine.getName(), creditMoveLine.getAccount().getLabel(), creditMoveLine.getCredit().subtract(creditMoveLine.getAmountPaid()));
}
}
use of com.axelor.exception.AxelorException 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);
}
use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.
the class AccountingSituationInitServiceImpl method createCustomerAccount.
protected void createCustomerAccount(AccountConfig accountConfig, AccountingSituation situation, int creationMode) throws AxelorException {
Partner partner = situation.getPartner();
if (partner.getIsCustomer() == Boolean.FALSE || situation.getCustomerAccount() != null)
return;
if (accountConfig.getCustomerAccount() == null) {
throw new AxelorException(partner, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.ACCOUNT_CUSTOMER_1), 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.getCustomerAccountPrefix();
if (StringUtils.isBlank(prefix)) {
throw new AxelorException(situation, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.ACCOUNTING_SITUATION_1), situation.getCompany().getName());
}
accountCode = getPrefixedAccountCode(prefix, partner);
} else if (creationMode == AccountConfigRepository.AUTOMATIC_ACCOUNT_CREATION_SEQUENCE) {
final Sequence sequence = accountConfig.getCustomerAccountSequence();
if (sequence == null) {
throw new AxelorException(situation, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.ACCOUNTING_SITUATION_2), 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.getCustomerAccount(), accountConfig.getCustomerAccount().getAccountType(), true, situation.getCompany(), true);
situation.setCustomerAccount(account);
}
use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.
the class AccountingSituationInitServiceImpl method createEmployeeAccount.
protected void createEmployeeAccount(AccountConfig accountConfig, AccountingSituation situation, int creationMode) throws AxelorException {
Partner partner = situation.getPartner();
if (partner.getIsEmployee() == Boolean.FALSE || situation.getEmployeeAccount() != null)
return;
if (accountConfig.getEmployeeAccount() == null) {
throw new AxelorException(partner, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.ACCOUNT_CONFIG_40), 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.getEmployeeAccountPrefix();
if (StringUtils.isBlank(prefix)) {
throw new AxelorException(situation, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.ACCOUNTING_SITUATION_6), situation.getCompany().getName());
}
accountCode = getPrefixedAccountCode(prefix, partner);
} else if (creationMode == AccountConfigRepository.AUTOMATIC_ACCOUNT_CREATION_SEQUENCE) {
final Sequence sequence = accountConfig.getEmployeeAccountSequence();
if (sequence == null) {
throw new AxelorException(situation, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.ACCOUNTING_SITUATION_7), 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.getEmployeeAccount(), accountConfig.getEmployeeAccount().getAccountType(), true, situation.getCompany(), true);
situation.setEmployeeAccount(account);
}
use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.
the class AccountingReportServiceImpl method getSequence.
public String getSequence(AccountingReport accountingReport) throws AxelorException {
SequenceService sequenceService = Beans.get(SequenceService.class);
if (accountingReport.getReportType() == null) {
throw new AxelorException(accountingReport, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.ACCOUNTING_REPORT_NO_REPORT_TYPE));
}
int accountingReportTypeSelect = accountingReport.getReportType().getTypeSelect();
if (accountingReportTypeSelect >= 0 && accountingReportTypeSelect < 1000) {
String seq = sequenceService.getSequenceNumber(SequenceRepository.ACCOUNTING_REPORT, accountingReport.getCompany());
if (seq == null) {
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.ACCOUNTING_REPORT_1), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION), accountingReport.getCompany().getName());
}
return seq;
} else if (accountingReportTypeSelect >= 1000 && accountingReportTypeSelect < 2000) {
String seq = sequenceService.getSequenceNumber(SequenceRepository.MOVE_LINE_EXPORT, accountingReport.getCompany());
if (seq == null) {
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.ACCOUNTING_REPORT_2), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION), accountingReport.getCompany().getName());
}
return seq;
} else if (accountingReportTypeSelect >= 2000 && accountingReportTypeSelect < 3000) {
String seq = sequenceService.getSequenceNumber(SequenceRepository.ANALYTIC_REPORT, accountingReport.getCompany());
if (seq == null) {
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.ACCOUNTING_REPORT_ANALYTIC_REPORT), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION), accountingReport.getCompany().getName());
}
return seq;
} else if (accountingReportTypeSelect == 3000) {
String seq = sequenceService.getSequenceNumber(SequenceRepository.CUSTOM_ACCOUNTING_REPORT, accountingReport.getCompany());
if (seq == null) {
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.ACCOUNTING_REPORT_7), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION), accountingReport.getCompany().getName());
}
return seq;
}
throw new AxelorException(accountingReport, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.ACCOUNTING_REPORT_UNKNOWN_ACCOUNTING_REPORT_TYPE), accountingReport.getReportType().getTypeSelect());
}
Aggregations