Search in sources :

Example 21 with Partner

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

the class InvoiceServiceImpl method getBankDetails.

@Override
public BankDetails getBankDetails(Invoice invoice) throws AxelorException {
    BankDetails bankDetails;
    if (invoice.getSchedulePaymentOk() && invoice.getPaymentSchedule() != null) {
        bankDetails = invoice.getPaymentSchedule().getBankDetails();
        if (bankDetails != null) {
            return bankDetails;
        }
    }
    bankDetails = invoice.getBankDetails();
    if (bankDetails != null) {
        return bankDetails;
    }
    Partner partner = invoice.getPartner();
    Preconditions.checkNotNull(partner);
    bankDetails = Beans.get(BankDetailsRepository.class).findDefaultByPartner(partner);
    if (bankDetails != null) {
        return bankDetails;
    }
    throw new AxelorException(invoice, 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 22 with Partner

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

the class DoubtfulCustomerService method createDoubtFulCustomerMove.

/**
 * Procédure permettant de créer les écritures de passage en client douteux pour chaque écriture
 * de facture
 *
 * @param move Une écritures de facture
 * @param doubtfulCustomerAccount Un compte client douteux
 * @param debtPassReason Un motif de passage en client douteux
 * @throws AxelorException
 */
@Transactional(rollbackOn = { Exception.class })
public void createDoubtFulCustomerMove(Move move, Account doubtfulCustomerAccount, String debtPassReason) throws AxelorException {
    log.debug("Concerned account move : {} ", move.getReference());
    Company company = move.getCompany();
    Partner partner = move.getPartner();
    Invoice invoice = move.getInvoice();
    Move newMove = moveService.getMoveCreateService().createMove(company.getAccountConfig().getAutoMiscOpeJournal(), company, invoice.getCurrency(), partner, move.getPaymentMode(), MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, move.getFunctionalOriginSelect());
    newMove.setInvoice(invoice);
    LocalDate todayDate = appBaseService.getTodayDate(company);
    MoveLine invoicePartnerMoveLine = null;
    for (MoveLine moveLine : move.getMoveLineList()) {
        if (moveLine.getAccount().getUseForPartnerBalance() && moveLine.getAmountRemaining().compareTo(BigDecimal.ZERO) > 0 && moveLine.getAccount() != doubtfulCustomerAccount && moveLine.getDebit().compareTo(BigDecimal.ZERO) > 0) {
            invoicePartnerMoveLine = moveLine;
        }
    }
    String origin = "";
    BigDecimal amountRemaining = BigDecimal.ZERO;
    MoveLine creditMoveLine = null;
    if (invoicePartnerMoveLine != null) {
        amountRemaining = invoicePartnerMoveLine.getAmountRemaining();
        // Debit move line on partner account
        creditMoveLine = moveLineService.createMoveLine(newMove, partner, invoicePartnerMoveLine.getAccount(), amountRemaining, false, todayDate, 1, move.getInvoice().getInvoiceId(), debtPassReason);
        newMove.getMoveLineList().add(creditMoveLine);
        origin = creditMoveLine.getOrigin();
    }
    // Credit move line on partner account
    MoveLine debitMoveLine = moveLineService.createMoveLine(newMove, partner, doubtfulCustomerAccount, amountRemaining, true, todayDate, 2, origin, debtPassReason);
    newMove.getMoveLineList().add(debitMoveLine);
    debitMoveLine.setPassageReason(debtPassReason);
    moveService.getMoveValidateService().validate(newMove);
    moveRepo.save(newMove);
    if (creditMoveLine != null) {
        Reconcile reconcile = reconcileService.createReconcile(invoicePartnerMoveLine, creditMoveLine, amountRemaining, false);
        if (reconcile != null) {
            reconcileService.confirmReconcile(reconcile, true);
        }
    }
    this.invoiceProcess(newMove, doubtfulCustomerAccount, debtPassReason);
}
Also used : Company(com.axelor.apps.base.db.Company) Invoice(com.axelor.apps.account.db.Invoice) Move(com.axelor.apps.account.db.Move) MoveLine(com.axelor.apps.account.db.MoveLine) Partner(com.axelor.apps.base.db.Partner) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) Reconcile(com.axelor.apps.account.db.Reconcile) Transactional(com.google.inject.persist.Transactional)

Example 23 with Partner

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

the class DebtRecoverySessionService method getDebtRecoveryMethod.

/**
 * Fonction permettant de récupérer une méthode de relance en fonction de la categorie du tiers et
 * d'une société
 *
 * @param debtRecovery Une relance
 * @return
 */
public DebtRecoveryMethod getDebtRecoveryMethod(DebtRecovery debtRecovery) {
    AccountingSituation accountingSituation = debtRecovery.getTradingName() == null ? debtRecovery.getAccountingSituation() : debtRecovery.getTradingNameAccountingSituation();
    Company company = accountingSituation.getCompany();
    Partner partner = accountingSituation.getPartner();
    List<DebtRecoveryConfigLine> debtRecoveryConfigLines = company.getAccountConfig().getDebtRecoveryConfigLineList();
    for (DebtRecoveryConfigLine debtRecoveryConfigLine : debtRecoveryConfigLines) {
        if (debtRecoveryConfigLine.getPartnerCategory().equals(partner.getPartnerCategory())) {
            log.debug("méthode de relance determinée ");
            return debtRecoveryConfigLine.getDebtRecoveryMethod();
        }
    }
    log.debug("méthode de relance non determinée ");
    return null;
}
Also used : Company(com.axelor.apps.base.db.Company) AccountingSituation(com.axelor.apps.account.db.AccountingSituation) Partner(com.axelor.apps.base.db.Partner) DebtRecoveryConfigLine(com.axelor.apps.account.db.DebtRecoveryConfigLine)

Example 24 with Partner

use of com.axelor.apps.base.db.Partner 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 échéance
 *
 * @param company Une société
 * @param paymentScheduleLine Une échéance
 * @return Un enregistrement 'destinataire'
 * @throws AxelorException
 */
private String createRecipientCFONB(PaymentScheduleLine paymentScheduleLine, boolean mensu) throws AxelorException {
    PaymentSchedule paymentSchedule = paymentScheduleLine.getPaymentSchedule();
    Partner partner = paymentSchedule.getPartner();
    BankDetails bankDetails = Beans.get(PaymentScheduleService.class).getBankDetails(paymentSchedule);
    BigDecimal amount = paymentScheduleLine.getDirectDebitAmount();
    // Référence
    String ref = paymentScheduleLine.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 : PaymentSchedule(com.axelor.apps.account.db.PaymentSchedule) BankDetails(com.axelor.apps.base.db.BankDetails) PaymentScheduleService(com.axelor.apps.account.service.PaymentScheduleService) Partner(com.axelor.apps.base.db.Partner) BigDecimal(java.math.BigDecimal)

Example 25 with Partner

use of com.axelor.apps.base.db.Partner 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();
            }
        }
    }
}
Also used : Account(com.axelor.apps.account.db.Account) AxelorException(com.axelor.exception.AxelorException) LocalDate(java.time.LocalDate) AxelorException(com.axelor.exception.AxelorException) Year(com.axelor.apps.base.db.Year) Move(com.axelor.apps.account.db.Move) AccountingBatch(com.axelor.apps.account.db.AccountingBatch) Partner(com.axelor.apps.base.db.Partner) Pair(org.apache.commons.lang3.tuple.Pair)

Aggregations

Partner (com.axelor.apps.base.db.Partner)199 AxelorException (com.axelor.exception.AxelorException)68 Company (com.axelor.apps.base.db.Company)67 Transactional (com.google.inject.persist.Transactional)54 BigDecimal (java.math.BigDecimal)43 ArrayList (java.util.ArrayList)34 MoveLine (com.axelor.apps.account.db.MoveLine)32 Move (com.axelor.apps.account.db.Move)30 PaymentMode (com.axelor.apps.account.db.PaymentMode)26 LocalDate (java.time.LocalDate)26 Account (com.axelor.apps.account.db.Account)25 Invoice (com.axelor.apps.account.db.Invoice)24 BankDetails (com.axelor.apps.base.db.BankDetails)24 List (java.util.List)22 PartnerService (com.axelor.apps.base.service.PartnerService)18 Map (java.util.Map)18 Journal (com.axelor.apps.account.db.Journal)17 Address (com.axelor.apps.base.db.Address)14 Currency (com.axelor.apps.base.db.Currency)14 AccountConfig (com.axelor.apps.account.db.AccountConfig)13