Search in sources :

Example 1 with Partner

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

the class AccountCustomerService method updateAccountingSituationCustomerAccount.

@Transactional(rollbackOn = { Exception.class })
public AccountingSituation updateAccountingSituationCustomerAccount(AccountingSituation accountingSituation, boolean updateCustAccount, boolean updateDueCustAccount, boolean updateDueDebtRecoveryCustAccount) throws AxelorException {
    Partner partner = accountingSituation.getPartner();
    Company company = accountingSituation.getCompany();
    log.debug("Update customer account (Partner : {}, Company : {}, Update balance : {}, balance due : {}, balance due debt recovery : {})", partner.getName(), company.getName(), updateCustAccount, updateDueCustAccount, updateDueDebtRecoveryCustAccount);
    if (updateCustAccount) {
        accountingSituation.setBalanceCustAccount(this.getBalance(partner, company));
    }
    if (updateDueCustAccount) {
        accountingSituation.setBalanceDueCustAccount(this.getBalanceDue(partner, company, null));
    }
    if (updateDueDebtRecoveryCustAccount) {
        accountingSituation.setBalanceDueDebtRecoveryCustAccount(this.getBalanceDueDebtRecovery(partner, company, null));
    }
    accountingSituation.setCustAccountMustBeUpdateOk(false);
    accSituationRepo.save(accountingSituation);
    return accountingSituation;
}
Also used : Company(com.axelor.apps.base.db.Company) Partner(com.axelor.apps.base.db.Partner) Transactional(com.google.inject.persist.Transactional)

Example 2 with Partner

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

the class MoveLineExportServiceImpl method exportMoveLineTypeSelect1000.

/**
 * Méthode réalisant l'export des FEC (Fichiers des écritures Comptables)
 *
 * @throws AxelorException
 * @throws IOException
 */
@Transactional(rollbackOn = { Exception.class })
public MetaFile exportMoveLineTypeSelect1000(AccountingReport accountingReport, boolean administration, boolean replay) throws AxelorException, IOException {
    log.info("In Export type 1000 service : ");
    List<String[]> allMoveLineData = new ArrayList<>();
    Company company = accountingReport.getCompany();
    LocalDate interfaceDate = accountingReport.getDate();
    String moveLineQueryStr = String.format("(self.move.statusSelect = %s", MoveRepository.STATUS_VALIDATED);
    if (!administration) {
        moveLineQueryStr += String.format(" OR self.move.statusSelect = %s", MoveRepository.STATUS_ACCOUNTED);
    }
    moveLineQueryStr += ")";
    moveLineQueryStr += String.format(" AND self.move.company = %s", company.getId());
    if (accountingReport.getYear() != null) {
        moveLineQueryStr += String.format(" AND self.move.period.year = %s", accountingReport.getYear().getId());
    }
    if (accountingReport.getPeriod() != null) {
        moveLineQueryStr += String.format(" AND self.move.period = %s", accountingReport.getPeriod().getId());
    } else {
        if (accountingReport.getDateFrom() != null) {
            moveLineQueryStr += String.format(" AND self.date >= '%s'", accountingReport.getDateFrom().toString());
        }
        if (accountingReport.getDateTo() != null) {
            moveLineQueryStr += String.format(" AND self.date <= '%s'", accountingReport.getDateTo().toString());
        }
    }
    if (accountingReport.getDate() != null) {
        moveLineQueryStr += String.format(" AND self.date <= '%s'", accountingReport.getDate().toString());
    }
    moveLineQueryStr += " AND self.move.ignoreInAccountingOk = false";
    if (!administration) {
        moveLineQueryStr += " AND self.move.journal.notExportOk = false";
        if (replay) {
            moveLineQueryStr += String.format(" AND self.move.accountingOk = true AND self.move.accountingReport.id = %s", accountingReport.getId());
        } else {
            moveLineQueryStr += " AND self.move.accountingOk = false";
        }
    }
    List<MoveLine> moveLineList = moveLineRepo.all().filter(moveLineQueryStr).order("move.validationDate").order("date").order("name").fetch();
    if (!moveLineList.isEmpty()) {
        List<Move> moveList = new ArrayList<>();
        for (MoveLine moveLine : moveLineList) {
            String[] items = new String[18];
            Move move = moveLine.getMove();
            if (!moveList.contains(move)) {
                moveList.add(move);
            }
            Journal journal = move.getJournal();
            items[0] = journal.getCode();
            items[1] = journal.getName();
            items[2] = moveLine.getMove().getReference();
            items[3] = moveLine.getDate().format(DateTimeFormatter.ofPattern(DATE_FORMAT_YYYYMMDD));
            items[4] = moveLine.getAccount().getCode();
            items[5] = moveLine.getAccount().getName();
            items[6] = "";
            items[7] = "";
            Partner partner = moveLine.getPartner();
            if (partner != null) {
                items[6] = partner.getPartnerSeq();
                items[7] = partner.getName();
            }
            items[8] = moveLine.getOrigin();
            if (moveLine.getOriginDate() != null) {
                items[9] = moveLine.getOriginDate().format(DateTimeFormatter.ofPattern(DATE_FORMAT_YYYYMMDD));
            }
            items[10] = moveLine.getDescription();
            items[11] = moveLine.getDebit().toString().replace('.', ',');
            items[12] = moveLine.getCredit().toString().replace('.', ',');
            ReconcileGroup reconcileGroup = moveLine.getReconcileGroup();
            if (reconcileGroup != null && reconcileGroup.getStatusSelect() == ReconcileGroupRepository.STATUS_FINAL) {
                items[13] = reconcileGroup.getCode();
                items[14] = reconcileGroup.getDateOfLettering().format(DateTimeFormatter.ofPattern(DATE_FORMAT_YYYYMMDD)).toString();
            } else {
                items[13] = "";
                items[14] = "";
            }
            if (move.getValidationDate() != null) {
                items[15] = move.getValidationDate().format(DateTimeFormatter.ofPattern(DATE_FORMAT_YYYYMMDD));
            }
            items[16] = moveLine.getCurrencyAmount().toString().replace('.', ',');
            if (moveLine.getCurrencyAmount().compareTo(BigDecimal.ZERO) > 0 && moveLine.getCredit().compareTo(BigDecimal.ZERO) > 0) {
                items[16] = "-" + items[16];
            }
            if (move.getCurrency() != null) {
                items[17] = move.getCurrency().getCode();
            }
            allMoveLineData.add(items);
        }
        if (!administration) {
            String exportNumber = this.getSaleExportNumber(company);
            this.updateMoveList(moveList, accountingReport, interfaceDate, exportNumber);
        }
    }
    accountingReport = accountingReportRepo.find(accountingReport.getId());
    String fileName = this.setFileName(accountingReport);
    accountingReportRepo.save(accountingReport);
    return writeMoveLineToCsvFile(company, fileName, this.createHeaderForJournalEntry(), allMoveLineData, accountingReport);
}
Also used : Company(com.axelor.apps.base.db.Company) ReconcileGroup(com.axelor.apps.account.db.ReconcileGroup) ArrayList(java.util.ArrayList) Journal(com.axelor.apps.account.db.Journal) LocalDate(java.time.LocalDate) Move(com.axelor.apps.account.db.Move) MoveLine(com.axelor.apps.account.db.MoveLine) AnalyticMoveLine(com.axelor.apps.account.db.AnalyticMoveLine) Partner(com.axelor.apps.base.db.Partner) Transactional(com.google.inject.persist.Transactional)

Example 3 with Partner

use of com.axelor.apps.base.db.Partner 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 4 with Partner

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

the class IrrecoverableService method createIrrecoverableReport.

/**
 * Procédure permettant de passer en irrécouvrables les factures et échéances rejetées récupéré
 * sur l'objet Irrécouvrable
 *
 * @param irrecoverable Un objet Irrécouvrable
 */
@Transactional
public void createIrrecoverableReport(Irrecoverable irrecoverable) {
    Set<Invoice> invoiceSet = irrecoverable.getInvoiceSet();
    Set<PaymentScheduleLine> paymentScheduleLineSet = irrecoverable.getPaymentScheduleLineSet();
    irrecoverable.setMoveSet(new HashSet<Move>());
    List<Partner> payerPartnerList = this.getPayerPartnerList(invoiceSet);
    EntityTransaction transaction = JPA.em().getTransaction();
    int i = 0;
    if (payerPartnerList != null && payerPartnerList.size() != 0) {
        for (Partner payerPartner : payerPartnerList) {
            if (!transaction.isActive()) {
                transaction.begin();
            }
            i++;
            try {
                log.debug("Tiers : {}", payerPartner.getName());
                this.createIrrecoverableCustomerLine(irrecoverable, payerPartner, this.getInvoiceList(payerPartner, invoiceSet), this.getPaymentScheduleLineList(payerPartner, paymentScheduleLineSet));
                irrecoverableRepo.save(irrecoverable);
                transaction.commit();
                if (i % 50 == 0) {
                    JPA.flush();
                    JPA.clear();
                }
            } catch (Exception e) {
                TraceBackService.trace(e);
                log.error("Bug(Anomalie) généré(e) pour le tiers : {}", payerPartner.getName());
            } finally {
                if (!transaction.isActive()) {
                    transaction.begin();
                }
            }
        }
    }
}
Also used : EntityTransaction(javax.persistence.EntityTransaction) Invoice(com.axelor.apps.account.db.Invoice) PaymentScheduleLine(com.axelor.apps.account.db.PaymentScheduleLine) Move(com.axelor.apps.account.db.Move) Partner(com.axelor.apps.base.db.Partner) AxelorException(com.axelor.exception.AxelorException) Transactional(com.google.inject.persist.Transactional)

Example 5 with Partner

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

the class ReimbursementExportService method createReimbursementMove.

/**
 * Methode permettant de créer l'écriture de remboursement
 *
 * @param reimbursement Un objet d'export des prélèvements
 * @throws AxelorException
 */
public void createReimbursementMove(Reimbursement reimbursement, Company company) throws AxelorException {
    reimbursement = reimbursementRepo.find(reimbursement.getId());
    Partner partner = null;
    Move newMove = null;
    boolean first = true;
    AccountConfig accountConfig = company.getAccountConfig();
    if (reimbursement.getMoveLineSet() != null && !reimbursement.getMoveLineSet().isEmpty()) {
        int seq = 1;
        for (MoveLine moveLine : reimbursement.getMoveLineSet()) {
            BigDecimal amountRemaining = moveLine.getAmountRemaining();
            if (amountRemaining.compareTo(BigDecimal.ZERO) > 0) {
                partner = moveLine.getPartner();
                // On passe les lignes d'écriture (trop perçu) à l'état 'remboursé'
                moveLine.setReimbursementStatusSelect(MoveLineRepository.REIMBURSEMENT_STATUS_REIMBURSED);
                if (first) {
                    newMove = moveService.getMoveCreateService().createMove(accountConfig.getReimbursementJournal(), company, null, partner, null, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_PAYMENT);
                    first = false;
                }
                // Création d'une ligne au débit
                MoveLine newDebitMoveLine = moveLineService.createMoveLine(newMove, partner, moveLine.getAccount(), amountRemaining, true, appAccountService.getTodayDate(company), seq, reimbursement.getRef(), reimbursement.getDescription());
                newMove.getMoveLineList().add(newDebitMoveLine);
                if (reimbursement.getDescription() != null && !reimbursement.getDescription().isEmpty()) {
                    newDebitMoveLine.setDescription(reimbursement.getDescription());
                }
                seq++;
                // Création de la réconciliation
                Reconcile reconcile = reconcileService.createReconcile(newDebitMoveLine, moveLine, amountRemaining, false);
                if (reconcile != null) {
                    reconcileService.confirmReconcile(reconcile, true);
                }
            }
        }
        // Création de la ligne au crédit
        MoveLine newCreditMoveLine = moveLineService.createMoveLine(newMove, partner, accountConfig.getReimbursementAccount(), reimbursement.getAmountReimbursed(), false, appAccountService.getTodayDate(company), seq, reimbursement.getRef(), reimbursement.getDescription());
        newMove.getMoveLineList().add(newCreditMoveLine);
        if (reimbursement.getDescription() != null && !reimbursement.getDescription().isEmpty()) {
            newCreditMoveLine.setDescription(reimbursement.getDescription());
        }
        moveService.getMoveValidateService().validate(newMove);
        moveRepo.save(newMove);
    }
}
Also used : Move(com.axelor.apps.account.db.Move) MoveLine(com.axelor.apps.account.db.MoveLine) Partner(com.axelor.apps.base.db.Partner) BigDecimal(java.math.BigDecimal) AccountConfig(com.axelor.apps.account.db.AccountConfig) Reconcile(com.axelor.apps.account.db.Reconcile)

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