use of com.axelor.apps.base.db.Sequence 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.apps.base.db.Sequence 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.apps.base.db.Sequence 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.apps.base.db.Sequence in project axelor-open-suite by axelor.
the class SequenceService method getSequenceNumber.
/**
* Method returning a sequence number from a given generic sequence and a date
*
* @param sequence
* @param refDate
* @return
*/
@Transactional
public String getSequenceNumber(Sequence sequence, LocalDate refDate) {
Sequence seq = JPA.em().createQuery("SELECT self FROM Sequence self WHERE id = :id", Sequence.class).setParameter("id", sequence.getId()).setLockMode(LockModeType.PESSIMISTIC_WRITE).setFlushMode(FlushModeType.COMMIT).getSingleResult();
SequenceVersion sequenceVersion = getVersion(seq, refDate);
String nextSeq = computeNextSeq(sequenceVersion, seq, refDate);
sequenceVersion.setNextNum(sequenceVersion.getNextNum() + seq.getToBeAdded());
if (sequenceVersion.getId() == null) {
sequenceVersionRepository.save(sequenceVersion);
}
return nextSeq;
}
use of com.axelor.apps.base.db.Sequence in project axelor-open-suite by axelor.
the class SequenceBaseRepository method copy.
@Override
public Sequence copy(Sequence sequence, boolean deep) {
Sequence copy = super.copy(sequence, deep);
copy.clearSequenceVersionList();
return copy;
}
Aggregations