use of com.axelor.apps.account.db.Account in project axelor-open-suite by axelor.
the class AccountAccountRepository method save.
@Override
public Account save(Account account) {
try {
if (account.getId() == null) {
return super.save(account);
}
if (account.getReconcileOk()) {
Set<Account> accountList = account.getCompatibleAccountSet();
if (accountList != null) {
for (Account acc : accountList) {
acc.setReconcileOk(true);
acc.addCompatibleAccountSetItem(account);
JPA.save(acc);
}
}
} else {
if (account.getCompatibleAccountSet() != null) {
for (Account acc : account.getCompatibleAccountSet()) {
acc.removeCompatibleAccountSetItem(account);
if (acc.getCompatibleAccountSet().size() == 0) {
acc.setReconcileOk(false);
}
JPA.save(acc);
}
account.getCompatibleAccountSet().clear();
}
}
return super.save(account);
} catch (Exception e) {
TraceBackService.traceExceptionFromSaveMethod(e);
throw new PersistenceException(e.getMessage(), e);
}
}
use of com.axelor.apps.account.db.Account in project axelor-open-suite by axelor.
the class SubrogationReleaseServiceImpl method enterReleaseInTheAccounts.
@Override
@Transactional(rollbackOn = { Exception.class })
public void enterReleaseInTheAccounts(SubrogationRelease subrogationRelease) throws AxelorException {
MoveService moveService = Beans.get(MoveService.class);
MoveRepository moveRepository = Beans.get(MoveRepository.class);
AccountConfigService accountConfigService = Beans.get(AccountConfigService.class);
AppBaseService appBaseService = Beans.get(AppBaseService.class);
Company company = subrogationRelease.getCompany();
AccountConfig accountConfig = accountConfigService.getAccountConfig(company);
Journal journal = accountConfigService.getAutoMiscOpeJournal(accountConfig);
Account factorCreditAccount = accountConfigService.getFactorCreditAccount(accountConfig);
Account factorDebitAccount = accountConfigService.getFactorDebitAccount(accountConfig);
if (subrogationRelease.getAccountingDate() == null) {
subrogationRelease.setAccountingDate(appBaseService.getTodayDate(company));
}
this.checkIfAnOtherSubrogationAlreadyExist(subrogationRelease);
for (Invoice invoice : subrogationRelease.getInvoiceSet()) {
boolean isRefund = false;
if (invoice.getOperationTypeSelect() == InvoiceRepository.OPERATION_TYPE_CLIENT_REFUND) {
isRefund = true;
}
LocalDate date = subrogationRelease.getAccountingDate();
Move move = moveService.getMoveCreateService().createMove(journal, company, company.getCurrency(), invoice.getPartner(), date, null, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_PAYMENT);
MoveLine creditMoveLine, debitMoveLine;
debitMoveLine = moveService.getMoveLineService().createMoveLine(move, invoice.getPartner(), factorDebitAccount, invoice.getCompanyInTaxTotalRemaining(), !isRefund, date, null, 1, subrogationRelease.getSequenceNumber(), invoice.getInvoiceId());
creditMoveLine = moveService.getMoveLineService().createMoveLine(move, invoice.getPartner(), factorCreditAccount, invoice.getCompanyInTaxTotalRemaining(), isRefund, date, null, 2, subrogationRelease.getSequenceNumber(), invoice.getInvoiceId());
move.addMoveLineListItem(debitMoveLine);
move.addMoveLineListItem(creditMoveLine);
move = moveRepository.save(move);
moveService.getMoveValidateService().validate(move);
invoice.setSubrogationRelease(subrogationRelease);
invoice.setSubrogationReleaseMove(move);
subrogationRelease.addMoveListItem(move);
}
subrogationRelease.setStatusSelect(SubrogationReleaseRepository.STATUS_ACCOUNTED);
}
use of com.axelor.apps.account.db.Account in project axelor-open-suite by axelor.
the class IrrecoverableService method createIrrecoverableMove.
/**
* Fonction permettant de créer l'écriture de passage en irrécouvrable d'une échéance
*
* @param moveLine Une écriture d'échéance
* @return
* @throws AxelorException
*/
public Move createIrrecoverableMove(MoveLine moveLine, String irrecoverableName) throws AxelorException {
Company company = moveLine.getMove().getCompany();
Partner payerPartner = moveLine.getPartner();
BigDecimal amount = moveLine.getAmountRemaining();
AccountConfig accountConfig = company.getAccountConfig();
// Move
Move move = moveService.getMoveCreateService().createMove(accountConfig.getIrrecoverableJournal(), company, null, payerPartner, null, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, moveLine.getMove().getFunctionalOriginSelect());
int seq = 1;
// Credit MoveLine Customer account (411, 416, ...)
MoveLine creditMoveLine = moveLineService.createMoveLine(move, payerPartner, moveLine.getAccount(), amount, false, appAccountService.getTodayDate(company), seq, irrecoverableName, moveLine.getDescription());
move.getMoveLineList().add(creditMoveLine);
Reconcile reconcile = reconcileService.createReconcile(moveLine, creditMoveLine, amount, false);
if (reconcile != null) {
reconcileService.confirmReconcile(reconcile, true);
}
Tax tax = accountConfig.getIrrecoverableStandardRateTax();
BigDecimal taxRate = taxService.getTaxRate(tax, appAccountService.getTodayDate(company));
// Debit MoveLine 654. (irrecoverable account)
BigDecimal divid = taxRate.add(BigDecimal.ONE);
BigDecimal irrecoverableAmount = amount.divide(divid, 6, RoundingMode.HALF_UP).setScale(AppBaseService.DEFAULT_NB_DECIMAL_DIGITS, RoundingMode.HALF_UP);
MoveLine creditMoveLine1 = moveLineService.createMoveLine(move, payerPartner, accountConfig.getIrrecoverableAccount(), irrecoverableAmount, true, appAccountService.getTodayDate(company), 2, irrecoverableName, moveLine.getDescription());
move.getMoveLineList().add(creditMoveLine1);
// Debit MoveLine 445 (Tax account)
Account taxAccount = taxAccountService.getAccount(tax, company, false, false);
BigDecimal taxAmount = amount.subtract(irrecoverableAmount);
MoveLine creditMoveLine2 = moveLineService.createMoveLine(move, payerPartner, taxAccount, taxAmount, true, appAccountService.getTodayDate(company), 3, irrecoverableName, moveLine.getDescription());
move.getMoveLineList().add(creditMoveLine2);
return move;
}
use of com.axelor.apps.account.db.Account in project axelor-open-suite by axelor.
the class NotificationServiceImpl method createPaymentMove.
@Transactional(rollbackOn = { Exception.class })
protected Move createPaymentMove(NotificationItem notificationItem) throws AxelorException {
Notification notification = notificationItem.getNotification();
Invoice invoice = notificationItem.getInvoice();
Company company = invoice.getCompany();
AccountConfig accountConfig = accountConfigService.getAccountConfig(company);
Journal journal = getJournal(accountConfig);
SubrogationRelease subrogationRelease = getSubrogationRelease(notificationItem);
String origin = computeOrigin(subrogationRelease, invoice);
BigDecimal amountPaid = notificationItem.getAmountPaid();
if (amountPaid.compareTo(BigDecimal.ZERO) == 0) {
return null;
}
Move paymentMove = moveService.getMoveCreateService().createMove(journal, company, company.getCurrency(), invoice.getPartner(), notification.getPaymentDate(), null, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_PAYMENT);
MoveLine creditMoveLine, debitMoveLine;
Account account = getAccount(accountConfig, notificationItem);
debitMoveLine = moveService.getMoveLineService().createMoveLine(paymentMove, invoice.getPartner(), account, amountPaid, true, notification.getPaymentDate(), null, 1, origin, invoice.getInvoiceId());
creditMoveLine = moveService.getMoveLineService().createMoveLine(paymentMove, invoice.getPartner(), invoice.getPartnerAccount(), amountPaid, false, notification.getPaymentDate(), null, 2, origin, invoice.getInvoiceId());
paymentMove.addMoveLineListItem(debitMoveLine);
paymentMove.addMoveLineListItem(creditMoveLine);
paymentMove = moveRepository.save(paymentMove);
moveService.getMoveValidateService().validate(paymentMove);
MoveLine invoiceMoveLine = findInvoiceAccountMoveLine(invoice);
MoveLine subrogationReleaseMoveLine = findSubrogationReleaseAccountMoveLine(invoice);
if (invoiceMoveLine.getAmountRemaining().compareTo(BigDecimal.ZERO) == 1) {
reconcileService.reconcile(invoiceMoveLine, creditMoveLine, true, true);
if (subrogationReleaseMoveLine != null && notificationItem.getTypeSelect() == NotificationRepository.TYPE_PAYMENT_TO_THE_FACTORE) {
reconcileService.reconcile(debitMoveLine, subrogationReleaseMoveLine, true, false);
}
}
notificationItem.setMove(paymentMove);
if (subrogationRelease != null) {
subrogationReleaseService.clear(subrogationRelease);
}
return paymentMove;
}
use of com.axelor.apps.account.db.Account in project axelor-open-suite by axelor.
the class AccountingSituationInitServiceImpl method createAccount.
protected Account createAccount(String fullName, String accountCode, Account parentAccount, AccountType accountType, boolean reconcileOk, Company company, boolean useForPartnerBalance) {
Account account = new Account();
account.setName(fullName);
account.setCode(accountCode);
account.setParentAccount(parentAccount);
account.setAccountType(accountType);
account.setReconcileOk(reconcileOk);
account.setCompany(company);
account.setUseForPartnerBalance(useForPartnerBalance);
account.setCompatibleAccountSet(new HashSet<>());
return account;
}
Aggregations