use of com.axelor.apps.account.db.Account 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.account.db.Account 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.account.db.Account in project axelor-open-suite by axelor.
the class BatchDoubtfulCustomer method process.
@SuppressWarnings("unchecked")
@Override
protected void process() {
if (!end) {
Company company = batch.getAccountingBatch().getCompany();
AccountConfig accountConfig = company.getAccountConfig();
Account doubtfulCustomerAccount = accountConfig.getDoubtfulCustomerAccount();
String sixMonthDebtPassReason = accountConfig.getSixMonthDebtPassReason();
String threeMonthDebtPassReason = accountConfig.getThreeMonthDebtPassReason();
// FACTURES
List<Move> moveList = doubtfulCustomerService.getMove(0, doubtfulCustomerAccount, company);
log.debug("Nombre d'écritures de facture concernées (Créance de + 6 mois) au 411 : {} ", moveList.size());
this.createDoubtFulCustomerMove(moveList, doubtfulCustomerAccount, sixMonthDebtPassReason);
moveList = doubtfulCustomerService.getMove(1, doubtfulCustomerAccount, company);
log.debug("Nombre d'écritures de facture concernées (Créance de + 3 mois) au 411 : {} ", moveList.size());
this.createDoubtFulCustomerMove(moveList, doubtfulCustomerAccount, threeMonthDebtPassReason);
// FACTURES REJETES
List<MoveLine> moveLineList = (List<MoveLine>) doubtfulCustomerService.getRejectMoveLine(0, doubtfulCustomerAccount, company);
log.debug("Nombre de lignes d'écriture de rejet concernées (Créance de + 6 mois) au 411 : {} ", moveLineList.size());
this.createDoubtFulCustomerRejectMove(moveLineList, doubtfulCustomerAccount, sixMonthDebtPassReason);
moveLineList = (List<MoveLine>) doubtfulCustomerService.getRejectMoveLine(1, doubtfulCustomerAccount, company);
log.debug("Nombre de lignes d'écriture de rejet concernées (Créance de + 3 mois) au 411 : {} ", moveLineList.size());
this.createDoubtFulCustomerRejectMove(moveLineList, doubtfulCustomerAccount, threeMonthDebtPassReason);
updateCustomerAccountLog += batchAccountCustomer.updateAccountingSituationMarked(companyRepo.find(company.getId()));
}
}
use of com.axelor.apps.account.db.Account in project axelor-open-suite by axelor.
the class BatchCloseAnnualAccounts method process.
protected void process() {
if (!end) {
AccountingBatch accountingBatch = batch.getAccountingBatch();
boolean allocatePerPartner = accountingBatch.getAllocatePerPartner();
boolean closeYear = accountingBatch.getCloseYear();
boolean openYear = accountingBatch.getOpenYear();
Year year = accountingBatch.getYear();
LocalDate endOfYearDate = year.getToDate();
LocalDate reportedBalanceDate = year.getReportedBalanceDate();
String origin = accountingBatch.getCode();
String moveDescription = accountingBatch.getMoveDescription();
List<Long> accountIdList = accountingCloseAnnualService.getAllAccountOfYear(accountingBatch.getAccountSet(), year);
List<Pair<Long, Long>> accountAndPartnerPairList = accountingCloseAnnualService.assignPartner(accountIdList, year, allocatePerPartner);
Account account = null;
Partner partner = null;
for (Pair<Long, Long> accountAndPartnerPair : accountAndPartnerPairList) {
try {
account = accountRepository.find(accountAndPartnerPair.getLeft());
if (accountAndPartnerPair.getRight() != null) {
partner = partnerRepository.find(accountAndPartnerPair.getRight());
} else {
partner = null;
}
List<Move> generateMoves = accountingCloseAnnualService.generateCloseAnnualAccount(yearRepository.find(year.getId()), account, partner, endOfYearDate, reportedBalanceDate, origin, moveDescription, closeYear, openYear, allocatePerPartner);
if (generateMoves != null && !generateMoves.isEmpty()) {
updateAccount(account);
for (Move move : generateMoves) {
updateAccountMove(move, false);
}
}
} catch (AxelorException e) {
TraceBackService.trace(new AxelorException(e, e.getCategory(), I18n.get("Account") + " %s", account.getCode()), null, batch.getId());
incrementAnomaly();
break;
} catch (Exception e) {
TraceBackService.trace(new Exception(String.format(I18n.get("Account") + " %s", account.getCode()), e), null, batch.getId());
incrementAnomaly();
LOG.error("Anomaly generated for the account {}", account.getCode());
break;
} finally {
JPA.clear();
}
}
}
}
use of com.axelor.apps.account.db.Account in project axelor-open-suite by axelor.
the class FixedAssetLineMoveServiceImpl method generateDisposalMove.
@Override
@Transactional(rollbackOn = { Exception.class })
public void generateDisposalMove(FixedAssetLine fixedAssetLine) throws AxelorException {
FixedAsset fixedAsset = fixedAssetLine.getFixedAsset();
Journal journal = fixedAsset.getJournal();
Company company = fixedAsset.getCompany();
Partner partner = fixedAsset.getPartner();
LocalDate date = fixedAssetLine.getDepreciationDate();
// Creating move
Move move = moveCreateService.createMove(journal, company, company.getCurrency(), partner, date, null, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_FIXED_ASSET);
if (move != null) {
List<MoveLine> moveLines = new ArrayList<MoveLine>();
String origin = fixedAsset.getReference();
Account chargeAccount = fixedAsset.getFixedAssetCategory().getChargeAccount();
Account depreciationAccount = fixedAsset.getFixedAssetCategory().getDepreciationAccount();
Account purchaseAccount = fixedAsset.getPurchaseAccount();
BigDecimal chargeAmount = fixedAssetLine.getResidualValue();
BigDecimal cumulativeDepreciationAmount = fixedAssetLine.getCumulativeDepreciation();
// Creating accounting debit move line for charge account
MoveLine chargeAccountDebitMoveLine = new MoveLine(move, partner, chargeAccount, date, null, 1, chargeAmount, BigDecimal.ZERO, fixedAsset.getName(), origin, null, BigDecimal.ZERO, date);
moveLines.add(chargeAccountDebitMoveLine);
this.addAnalyticToMoveLine(fixedAsset.getAnalyticDistributionTemplate(), chargeAccountDebitMoveLine);
// Creating accounting debit move line for deprecation account
MoveLine deprecationAccountDebitMoveLine = new MoveLine(move, partner, depreciationAccount, date, null, 1, cumulativeDepreciationAmount, BigDecimal.ZERO, fixedAsset.getName(), origin, null, BigDecimal.ZERO, date);
moveLines.add(deprecationAccountDebitMoveLine);
this.addAnalyticToMoveLine(fixedAsset.getAnalyticDistributionTemplate(), deprecationAccountDebitMoveLine);
// Creating accounting credit move line
MoveLine creditMoveLine = new MoveLine(move, partner, purchaseAccount, date, null, 2, BigDecimal.ZERO, fixedAsset.getGrossValue(), fixedAsset.getName(), origin, null, BigDecimal.ZERO, date);
moveLines.add(creditMoveLine);
this.addAnalyticToMoveLine(fixedAsset.getAnalyticDistributionTemplate(), creditMoveLine);
move.getMoveLineList().addAll(moveLines);
}
moveRepo.save(move);
fixedAsset.setDisposalMove(move);
}
Aggregations