Search in sources :

Example 56 with BankDetails

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

the class CfonbExportService method createRecipientCFONB.

/**
 * Fonction permettant de créer un enregistrement 'destinataire' pour un export de prélèvement
 * d'une facture
 *
 * @param company Une société
 * @param moveLine L' écriture d'export des prélèvement d'une facture
 * @return Un enregistrement 'destinataire'
 * @throws AxelorException
 */
private String createRecipientCFONB(Company company, Invoice invoice) throws AxelorException {
    Partner partner = invoice.getPartner();
    BankDetails bankDetails = partnerService.getDefaultBankDetails(partner);
    if (bankDetails == null) {
        throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.PAYMENT_SCHEDULE_2), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION), partner.getName());
    }
    BigDecimal amount = invoice.getDirectDebitAmount();
    // Référence
    String ref = invoice.getDebitNumber();
    // Nom/Raison sociale du débiteur
    String partnerName = this.getPayeurPartnerName(partner);
    String operationCode = // Code opération
    this.cfonbConfig.getDirectDebitOperationCodeExportCFONB();
    return this.createRecipientCFONB(amount, ref, partnerName, bankDetails, operationCode);
}
Also used : AxelorException(com.axelor.exception.AxelorException) BankDetails(com.axelor.apps.base.db.BankDetails) Partner(com.axelor.apps.base.db.Partner) BigDecimal(java.math.BigDecimal)

Example 57 with BankDetails

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

the class CfonbExportService method createRecipientCFONB.

/**
 * Fonction permettant de créer un enregistrement 'destinataire' pour un virement de remboursement
 *
 * @param company Une société
 * @param reimbursement Un remboursement
 * @return Un enregistrement 'destinataire'
 * @throws AxelorException
 */
private String createRecipientCFONB(Reimbursement reimbursement) throws AxelorException {
    BankDetails bankDetails = reimbursement.getBankDetails();
    if (bankDetails == null) {
        throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, "%s :\n " + I18n.get(IExceptionMessage.CFONB_EXPORT_1) + " %s", I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION), reimbursement.getRef());
    }
    BigDecimal amount = reimbursement.getAmountReimbursed();
    // Référence
    String ref = reimbursement.getRef();
    String partner = // Nom/Raison sociale du bénéficiaire
    this.getPayeurPartnerName(reimbursement.getPartner());
    // Code opération
    String operationCode = this.cfonbConfig.getTransferOperationCodeExportCFONB();
    return this.createRecipientCFONB(amount, ref, partner, bankDetails, operationCode);
}
Also used : AxelorException(com.axelor.exception.AxelorException) BankDetails(com.axelor.apps.base.db.BankDetails) BigDecimal(java.math.BigDecimal)

Example 58 with BankDetails

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

the class PaymentScheduleServiceImpl method getBankDetails.

@Override
public BankDetails getBankDetails(PaymentSchedule paymentSchedule) throws AxelorException {
    BankDetails bankDetails = paymentSchedule.getBankDetails();
    if (bankDetails != null) {
        return bankDetails;
    }
    Partner partner = paymentSchedule.getPartner();
    Preconditions.checkNotNull(partner);
    bankDetails = partnerService.getDefaultBankDetails(partner);
    if (bankDetails != null) {
        return bankDetails;
    }
    throw new AxelorException(partner, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.PARTNER_BANK_DETAILS_MISSING), partner.getName());
}
Also used : AxelorException(com.axelor.exception.AxelorException) BankDetails(com.axelor.apps.base.db.BankDetails) Partner(com.axelor.apps.base.db.Partner)

Example 59 with BankDetails

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

the class AccountingSituationInitServiceImpl method createAccountingSituation.

@Override
@Transactional(rollbackOn = { Exception.class })
public AccountingSituation createAccountingSituation(Partner partner, Company company) throws AxelorException {
    AccountingSituation accountingSituation = new AccountingSituation();
    accountingSituation.setCompany(company);
    partner.addCompanySetItem(company);
    PaymentMode inPaymentMode = partner.getInPaymentMode();
    PaymentMode outPaymentMode = partner.getOutPaymentMode();
    BankDetails defaultBankDetails = company.getDefaultBankDetails();
    if (inPaymentMode != null) {
        List<BankDetails> authorizedInBankDetails = paymentModeService.getCompatibleBankDetailsList(inPaymentMode, company);
        if (authorizedInBankDetails.contains(defaultBankDetails)) {
            accountingSituation.setCompanyInBankDetails(defaultBankDetails);
        }
    }
    if (outPaymentMode != null) {
        List<BankDetails> authorizedOutBankDetails = paymentModeService.getCompatibleBankDetailsList(outPaymentMode, company);
        if (authorizedOutBankDetails.contains(defaultBankDetails)) {
            accountingSituation.setCompanyOutBankDetails(defaultBankDetails);
        }
    }
    AccountConfig accountConfig = accountConfigService.getAccountConfig(company);
    accountingSituation.setInvoiceAutomaticMail(accountConfig.getInvoiceAutomaticMail());
    accountingSituation.setInvoiceMessageTemplate(accountConfig.getInvoiceMessageTemplate());
    partner.addAccountingSituationListItem(accountingSituation);
    return accountingSituationRepository.save(accountingSituation);
}
Also used : BankDetails(com.axelor.apps.base.db.BankDetails) AccountingSituation(com.axelor.apps.account.db.AccountingSituation) PaymentMode(com.axelor.apps.account.db.PaymentMode) AccountConfig(com.axelor.apps.account.db.AccountConfig) Transactional(com.google.inject.persist.Transactional)

Example 60 with BankDetails

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

the class BatchBankPaymentServiceImpl method createBankOrderFromMonthlyPaymentScheduleLines.

@Override
@Transactional(rollbackOn = { Exception.class })
public BankOrder createBankOrderFromMonthlyPaymentScheduleLines(Batch batch) throws AxelorException, JAXBException, IOException, DatatypeConfigurationException {
    AccountingBatch accountingBatch = batch.getAccountingBatch();
    LocalDate bankOrderDate = accountingBatch.getDueDate();
    Company senderCompany = accountingBatch.getCompany();
    BankDetails senderBankDetails = accountingBatch.getBankDetails();
    if (senderBankDetails == null) {
        senderBankDetails = accountingBatch.getCompany().getDefaultBankDetails();
    }
    PaymentMode paymentMode = accountingBatch.getPaymentMode();
    Currency currency = senderCompany.getCurrency();
    int partnerType = BankOrderRepository.PARTNER_TYPE_CUSTOMER;
    String senderReference = "";
    String senderLabel = "";
    if (bankOrderDate == null) {
        bankOrderDate = appBaseService.getTodayDate(senderCompany);
    }
    BankOrder bankOrder = bankOrderCreateService.createBankOrder(paymentMode, partnerType, bankOrderDate, senderCompany, senderBankDetails, currency, senderReference, senderLabel, BankOrderRepository.TECHNICAL_ORIGIN_AUTOMATIC);
    bankOrder = JPA.save(bankOrder);
    List<PaymentScheduleLine> paymentScheduleLineList;
    int offset = 0;
    try {
        while (!(paymentScheduleLineList = fetchPaymentScheduleLineDoneList(batch, offset)).isEmpty()) {
            bankOrder = bankOrderRepo.find(bankOrder.getId());
            for (PaymentScheduleLine paymentScheduleLine : paymentScheduleLineList) {
                PaymentSchedule paymentSchedule = paymentScheduleLine.getPaymentSchedule();
                Partner partner = paymentSchedule.getPartner();
                BankDetails bankDetails = paymentScheduleService.getBankDetails(paymentSchedule);
                BigDecimal amount = paymentScheduleLine.getInTaxAmount();
                String receiverReference = paymentScheduleLine.getName();
                String receiverLabel = paymentScheduleLine.getDebitNumber();
                BankOrderLine bankOrderLine = bankOrderLineService.createBankOrderLine(paymentMode.getBankOrderFileFormat(), null, partner, bankDetails, amount, currency, bankOrderDate, receiverReference, receiverLabel, paymentScheduleLine);
                bankOrder.addBankOrderLineListItem(bankOrderLine);
            }
            bankOrder = JPA.save(bankOrder);
            offset += paymentScheduleLineList.size();
            JPA.clear();
        }
    } catch (Exception e) {
        bankOrder = bankOrderRepo.find(bankOrder.getId());
        bankOrderRepo.remove(bankOrder);
        throw e;
    }
    bankOrder = bankOrderRepo.find(bankOrder.getId());
    bankOrder = bankOrderRepo.save(bankOrder);
    bankOrderService.confirm(bankOrder);
    batch = batchRepo.find(batch.getId());
    batch.setBankOrder(bankOrder);
    return bankOrder;
}
Also used : Company(com.axelor.apps.base.db.Company) BankOrderLine(com.axelor.apps.bankpayment.db.BankOrderLine) PaymentScheduleLine(com.axelor.apps.account.db.PaymentScheduleLine) PaymentSchedule(com.axelor.apps.account.db.PaymentSchedule) BankDetails(com.axelor.apps.base.db.BankDetails) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) AxelorException(com.axelor.exception.AxelorException) IOException(java.io.IOException) JAXBException(javax.xml.bind.JAXBException) Currency(com.axelor.apps.base.db.Currency) AccountingBatch(com.axelor.apps.account.db.AccountingBatch) BankOrder(com.axelor.apps.bankpayment.db.BankOrder) Partner(com.axelor.apps.base.db.Partner) PaymentMode(com.axelor.apps.account.db.PaymentMode) Transactional(com.google.inject.persist.Transactional)

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