Search in sources :

Example 1 with BankDetails

use of com.axelor.apps.base.db.BankDetails 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;
}
Also used : Company(com.axelor.apps.base.db.Company) PaymentSchedule(com.axelor.apps.account.db.PaymentSchedule) Move(com.axelor.apps.account.db.Move) MoveService(com.axelor.apps.account.service.move.MoveService) PaymentService(com.axelor.apps.account.service.payment.PaymentService) Inject(com.google.inject.Inject) LoggerFactory(org.slf4j.LoggerFactory) PaymentModeService(com.axelor.apps.account.service.payment.PaymentModeService) Transactional(com.google.inject.persist.Transactional) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal) Lists(com.google.common.collect.Lists) AxelorException(com.axelor.exception.AxelorException) MoveLine(com.axelor.apps.account.db.MoveLine) PaymentScheduleLine(com.axelor.apps.account.db.PaymentScheduleLine) MoveToolService(com.axelor.apps.account.service.move.MoveToolService) PaymentScheduleRepository(com.axelor.apps.account.db.repo.PaymentScheduleRepository) RoundingMode(java.math.RoundingMode) Journal(com.axelor.apps.account.db.Journal) Logger(org.slf4j.Logger) MethodHandles(java.lang.invoke.MethodHandles) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) Invoice(com.axelor.apps.account.db.Invoice) Collectors(java.util.stream.Collectors) Account(com.axelor.apps.account.db.Account) SequenceService(com.axelor.apps.base.service.administration.SequenceService) List(java.util.List) PaymentScheduleLineRepository(com.axelor.apps.account.db.repo.PaymentScheduleLineRepository) LocalDate(java.time.LocalDate) PaymentMode(com.axelor.apps.account.db.PaymentMode) Preconditions(com.google.common.base.Preconditions) Comparator(java.util.Comparator) MoveLineRepository(com.axelor.apps.account.db.repo.MoveLineRepository) Partner(com.axelor.apps.base.db.Partner) MoveRepository(com.axelor.apps.account.db.repo.MoveRepository) BankDetails(com.axelor.apps.base.db.BankDetails) Account(com.axelor.apps.account.db.Account) Company(com.axelor.apps.base.db.Company) PaymentSchedule(com.axelor.apps.account.db.PaymentSchedule) Move(com.axelor.apps.account.db.Move) MoveLine(com.axelor.apps.account.db.MoveLine) Journal(com.axelor.apps.account.db.Journal) Partner(com.axelor.apps.base.db.Partner) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) Transactional(com.google.inject.persist.Transactional)

Example 2 with BankDetails

use of com.axelor.apps.base.db.BankDetails in project axelor-open-suite by axelor.

the class ReimbursementExportService method createReimbursement.

/**
 * Méthode permettant de créer un remboursement
 *
 * @param partner Un tiers
 * @param company Une société
 * @return Le remboursmeent créé
 * @throws AxelorException
 */
public Reimbursement createReimbursement(Partner partner, Company company) throws AxelorException {
    Reimbursement reimbursement = new Reimbursement();
    reimbursement.setPartner(partner);
    reimbursement.setCompany(company);
    BankDetails bankDetails = partnerService.getDefaultBankDetails(partner);
    reimbursement.setBankDetails(bankDetails);
    reimbursement.setRef(sequenceService.getSequenceNumber(SequenceRepository.REIMBOURSEMENT, company));
    return reimbursement;
}
Also used : BankDetails(com.axelor.apps.base.db.BankDetails) Reimbursement(com.axelor.apps.account.db.Reimbursement)

Example 3 with BankDetails

use of com.axelor.apps.base.db.BankDetails in project axelor-open-suite by axelor.

the class BankDetailsServiceAccountImpl method getDefaultCompanyBankDetailsFromFactorPartner.

private BankDetails getDefaultCompanyBankDetailsFromFactorPartner(Company company) throws AxelorException {
    AccountConfig accountConfig = Beans.get(AccountConfigService.class).getAccountConfig(company);
    if (accountConfig.getFactorPartner() == null) {
        return null;
    }
    List<BankDetails> bankDetailsList = accountConfig.getFactorPartner().getBankDetailsList();
    return bankDetailsList.stream().filter(bankDetails -> bankDetails.getIsDefault()).findFirst().orElse(null);
}
Also used : BankDetails(com.axelor.apps.base.db.BankDetails) AccountConfigService(com.axelor.apps.account.service.config.AccountConfigService) AccountConfig(com.axelor.apps.account.db.AccountConfig)

Example 4 with BankDetails

use of com.axelor.apps.base.db.BankDetails in project axelor-open-suite by axelor.

the class BankDetailsServiceAccountImpl method getDefaultCompanyBankDetailsFromPartner.

/**
 * Looks for the bank details in accounting situation.
 *
 * @param company
 * @param paymentMode
 * @param partner
 * @return The bank details corresponding to the partner and the company with the right payment
 *     mode null if the partner is null or the accounting situation empty
 */
protected BankDetails getDefaultCompanyBankDetailsFromPartner(Company company, PaymentMode paymentMode, Partner partner) {
    if (partner == null) {
        return null;
    }
    AccountingSituation accountingSituation = Beans.get(AccountingSituationService.class).getAccountingSituation(partner, company);
    if (accountingSituation == null) {
        return null;
    }
    BankDetails candidateBankDetails = null;
    if (paymentMode.getInOutSelect() == PaymentModeRepository.IN) {
        candidateBankDetails = accountingSituation.getCompanyInBankDetails();
    } else if (paymentMode.getInOutSelect() == PaymentModeRepository.OUT) {
        candidateBankDetails = accountingSituation.getCompanyOutBankDetails();
    }
    return candidateBankDetails;
}
Also used : BankDetails(com.axelor.apps.base.db.BankDetails) AccountingSituation(com.axelor.apps.account.db.AccountingSituation)

Example 5 with BankDetails

use of com.axelor.apps.base.db.BankDetails in project axelor-open-suite by axelor.

the class SaleOrderController method fillCompanyBankDetails.

/**
 * Called on partner, company or payment change. Fill the bank details with a default value.
 *
 * @param request
 * @param response
 * @throws AxelorException
 */
public void fillCompanyBankDetails(ActionRequest request, ActionResponse response) throws AxelorException {
    SaleOrder saleOrder = request.getContext().asType(SaleOrder.class);
    PaymentMode paymentMode = (PaymentMode) request.getContext().get("paymentMode");
    Company company = saleOrder.getCompany();
    Partner partner = saleOrder.getClientPartner();
    if (company == null) {
        return;
    }
    if (partner != null) {
        partner = Beans.get(PartnerRepository.class).find(partner.getId());
    }
    BankDetails defaultBankDetails = Beans.get(BankDetailsService.class).getDefaultCompanyBankDetails(company, paymentMode, partner, null);
    response.setValue("companyBankDetails", defaultBankDetails);
}
Also used : BankDetailsService(com.axelor.apps.base.service.BankDetailsService) Company(com.axelor.apps.base.db.Company) BankDetails(com.axelor.apps.base.db.BankDetails) SaleOrder(com.axelor.apps.sale.db.SaleOrder) Partner(com.axelor.apps.base.db.Partner) PaymentMode(com.axelor.apps.account.db.PaymentMode)

Aggregations

BankDetails (com.axelor.apps.base.db.BankDetails)63 Partner (com.axelor.apps.base.db.Partner)26 AxelorException (com.axelor.exception.AxelorException)26 PaymentMode (com.axelor.apps.account.db.PaymentMode)22 Company (com.axelor.apps.base.db.Company)22 BigDecimal (java.math.BigDecimal)14 LocalDate (java.time.LocalDate)13 Transactional (com.google.inject.persist.Transactional)12 ArrayList (java.util.ArrayList)11 Invoice (com.axelor.apps.account.db.Invoice)10 Journal (com.axelor.apps.account.db.Journal)9 BankDetailsService (com.axelor.apps.base.service.BankDetailsService)8 PaymentModeService (com.axelor.apps.account.service.payment.PaymentModeService)7 BankOrderLine (com.axelor.apps.bankpayment.db.BankOrderLine)7 Currency (com.axelor.apps.base.db.Currency)7 Account (com.axelor.apps.account.db.Account)6 AccountConfig (com.axelor.apps.account.db.AccountConfig)6 InvoicePayment (com.axelor.apps.account.db.InvoicePayment)6 Move (com.axelor.apps.account.db.Move)6 MoveLine (com.axelor.apps.account.db.MoveLine)6