use of com.axelor.apps.account.db.Account in project axelor-open-suite by axelor.
the class AccountClearanceService method validateAccountClearance.
@Transactional(rollbackOn = { Exception.class })
public void validateAccountClearance(AccountClearance accountClearance) throws AxelorException {
Company company = accountClearance.getCompany();
AccountConfig accountConfig = company.getAccountConfig();
Tax tax = accountConfig.getStandardRateTax();
BigDecimal taxRate = taxService.getTaxRate(tax, appBaseService.getTodayDateTime().toLocalDate());
Account taxAccount = taxAccountService.getAccount(tax, company, false, false);
Account profitAccount = accountConfig.getProfitAccount();
Journal journal = accountConfig.getAccountClearanceJournal();
Set<MoveLine> moveLineList = accountClearance.getMoveLineSet();
for (MoveLine moveLine : moveLineList) {
Move move = this.createAccountClearanceMove(moveLine, taxRate, taxAccount, profitAccount, company, journal, accountClearance);
moveService.getMoveValidateService().validate(move);
}
accountClearance.setStatusSelect(AccountClearanceRepository.STATUS_VALIDATED);
accountClearance.setDateTime(appBaseService.getTodayDateTime());
accountClearance.setName(sequenceService.getSequenceNumber(SequenceRepository.ACCOUNT_CLEARANCE, company));
accountClearanceRepo.save(accountClearance);
}
use of com.axelor.apps.account.db.Account in project axelor-open-suite by axelor.
the class AccountManagementServiceAccountImpl method getProductAccount.
/**
* Get the product tax
*
* @param product
* @param company
* @param isPurchase
* @param fixedAsset Specify if we should get the purchase account for fixed asset or not. Used
* only if isPurchase param is true.
* @param configObject Specify if we want get the tax from the product or its product family
* <li>1 : product
* <li>2 : product family
* @return
* @throws AxelorException
*/
@CallMethod
protected Account getProductAccount(Product product, Company company, boolean isPurchase, boolean fixedAsset, int configObject) {
AccountManagement accountManagement = this.getAccountManagement(product, company, configObject);
Account account = null;
if (accountManagement != null) {
if (isPurchase) {
if (fixedAsset) {
account = accountManagement.getPurchFixedAssetsAccount();
} else {
account = accountManagement.getPurchaseAccount();
}
} else {
account = accountManagement.getSaleAccount();
}
}
if (account == null && configObject == CONFIG_OBJECT_PRODUCT) {
return getProductAccount(product, company, isPurchase, fixedAsset, CONFIG_OBJECT_PRODUCT_FAMILY);
}
return account;
}
use of com.axelor.apps.account.db.Account in project axelor-open-suite by axelor.
the class PaymentScheduleLineServiceImpl method createPaymentMove.
@Override
@Transactional(rollbackOn = { Exception.class })
public Move createPaymentMove(PaymentScheduleLine paymentScheduleLine, BankDetails companyBankDetails, PaymentMode paymentMode) throws AxelorException {
Preconditions.checkNotNull(paymentScheduleLine);
Preconditions.checkNotNull(companyBankDetails);
PaymentSchedule paymentSchedule = paymentScheduleLine.getPaymentSchedule();
Company company = paymentSchedule.getCompany();
Partner partner = paymentSchedule.getPartner();
Journal journal = paymentModeService.getPaymentModeJournal(paymentMode, company, companyBankDetails);
BigDecimal amount = paymentScheduleLine.getInTaxAmount();
String name = paymentScheduleLine.getName();
LocalDate todayDate = appBaseService.getTodayDate(company);
Account account = accountingSituationService.getCustomerAccount(partner, company);
Move move = moveService.getMoveCreateService().createMove(journal, company, null, partner, paymentMode, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_PAYMENT);
MoveLine creditMoveLine = moveService.getMoveLineService().createMoveLine(move, partner, account, amount, false, todayDate, 1, name, null);
move.addMoveLineListItem(creditMoveLine);
creditMoveLine = moveLineRepo.save(creditMoveLine);
Account paymentModeAccount = paymentModeService.getPaymentModeAccount(paymentMode, company, companyBankDetails);
MoveLine debitMoveLine = moveService.getMoveLineService().createMoveLine(move, partner, paymentModeAccount, amount, true, todayDate, 2, name, null);
move.addMoveLineListItem(debitMoveLine);
debitMoveLine = moveLineRepo.save(debitMoveLine);
moveService.getMoveValidateService().validate(move);
// Reconcile
if (paymentSchedule.getTypeSelect() == PaymentScheduleRepository.TYPE_TERMS && paymentSchedule.getInvoiceSet() != null) {
List<MoveLine> debitMoveLineList = paymentSchedule.getInvoiceSet().stream().sorted(Comparator.comparing(Invoice::getDueDate)).map(invoice -> moveService.getMoveLineService().getDebitCustomerMoveLine(invoice)).collect(Collectors.toList());
if (moveToolService.isSameAccount(debitMoveLineList, account)) {
List<MoveLine> creditMoveLineList = Lists.newArrayList(creditMoveLine);
paymentService.useExcessPaymentOnMoveLines(debitMoveLineList, creditMoveLineList);
}
}
paymentScheduleLine.setDirectDebitAmount(amount);
paymentScheduleLine.setInTaxAmountPaid(amount);
paymentScheduleLine.setAdvanceOrPaymentMove(move);
paymentScheduleLine.setAdvanceMoveLine(creditMoveLine);
paymentScheduleLine.setStatusSelect(PaymentScheduleLineRepository.STATUS_VALIDATED);
paymentScheduleService.closePaymentScheduleIfAllPaid(paymentSchedule);
return move;
}
use of com.axelor.apps.account.db.Account in project axelor-open-suite by axelor.
the class ReconcileGroupServiceImpl method isBalanced.
@Override
public boolean isBalanced(List<Reconcile> reconcileList) {
List<MoveLine> debitMoveLineList = reconcileList.stream().map(Reconcile::getDebitMoveLine).distinct().collect(Collectors.toList());
List<MoveLine> creditMoveLineList = reconcileList.stream().map(Reconcile::getCreditMoveLine).distinct().collect(Collectors.toList());
List<Account> accountList = debitMoveLineList.stream().map(MoveLine::getAccount).distinct().collect(Collectors.toList());
accountList.addAll(creditMoveLineList.stream().map(MoveLine::getAccount).distinct().collect(Collectors.toList()));
for (Account account : accountList) {
BigDecimal totalDebit = debitMoveLineList.stream().filter(moveLine -> moveLine.getAccount().equals(account)).map(MoveLine::getDebit).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
BigDecimal totalCredit = creditMoveLineList.stream().filter(moveLine -> moveLine.getAccount().equals(account)).map(MoveLine::getCredit).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
if (totalDebit.compareTo(totalCredit) != 0) {
return false;
}
}
return true;
}
use of com.axelor.apps.account.db.Account 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);
}
Aggregations