Search in sources :

Example 11 with Reimbursement

use of com.axelor.apps.account.db.Reimbursement in project axelor-open-suite by axelor.

the class BatchCreditTransferPartnerReimbursement method createReimbursement.

/**
 * Create a reimbursement for the specified partner and from the specified company.
 *
 * @param partner
 * @param company
 * @return
 * @throws AxelorException
 */
@Transactional(rollbackOn = { Exception.class })
protected Reimbursement createReimbursement(Partner partner, Company company) throws AxelorException {
    List<MoveLine> moveLineList = moveLineRepo.all().filter("self.account.reconcileOk = true AND (self.move.statusSelect = ?1 OR self.move.statusSelect = ?2) " + "AND self.amountRemaining > 0 AND self.credit > 0 " + "AND self.move.partner = ?3 AND self.move.company = ?4 " + "AND self.reimbursementStatusSelect = ?5", MoveRepository.STATUS_VALIDATED, MoveRepository.STATUS_ACCOUNTED, partner, company, MoveLineRepository.REIMBURSEMENT_STATUS_NULL).fetch();
    Reimbursement reimbursement = partnerReimbursementExportService.runCreateReimbursement(moveLineList, company, partner);
    return reimbursement;
}
Also used : MoveLine(com.axelor.apps.account.db.MoveLine) Reimbursement(com.axelor.apps.account.db.Reimbursement) Transactional(com.google.inject.persist.Transactional)

Example 12 with Reimbursement

use of com.axelor.apps.account.db.Reimbursement in project axelor-open-suite by axelor.

the class BatchCreditTransferPartnerReimbursement method process.

@Override
protected void process() {
    AccountingBatch accountingBatch = batch.getAccountingBatch();
    // Fetch all partners that have a credit balance for the specified company.
    TypedQuery<Partner> partnerQuery = JPA.em().createQuery("SELECT self FROM Partner self JOIN self.accountingSituationList accountingSituation " + "WHERE accountingSituation.company = :company AND accountingSituation.balanceCustAccount < 0", Partner.class);
    partnerQuery.setParameter("company", accountingBatch.getCompany());
    List<Partner> partnerList = partnerQuery.getResultList();
    for (Partner partner : partnerList) {
        try {
            partner = partnerRepo.find(partner.getId());
            Reimbursement reimbursement = createReimbursement(partner, accountingBatch.getCompany());
            if (reimbursement != null) {
                incrementDone();
            }
        } catch (Exception ex) {
            incrementAnomaly();
            TraceBackService.trace(ex, ExceptionOriginRepository.CREDIT_TRANSFER, batch.getId());
            ex.printStackTrace();
            log.error(String.format("Credit transfer batch for partner credit balance reimbursement: anomaly for partner %s", partner.getName()));
        }
        JPA.clear();
    }
}
Also used : AccountingBatch(com.axelor.apps.account.db.AccountingBatch) Reimbursement(com.axelor.apps.account.db.Reimbursement) Partner(com.axelor.apps.base.db.Partner) AxelorException(com.axelor.exception.AxelorException)

Example 13 with Reimbursement

use of com.axelor.apps.account.db.Reimbursement in project axelor-open-suite by axelor.

the class BatchReimbursementExport method runCreateReimbursementExport.

public void runCreateReimbursementExport(Company company) {
    List<Reimbursement> reimbursementList = reimbursementRepo.all().filter("self.statusSelect != ?1 AND self.statusSelect != ?2 AND self.company = ?3 " + "AND self.partner.id NOT IN (" + Beans.get(BlockingService.class).listOfBlockedPartner(company, BlockingRepository.REIMBURSEMENT_BLOCKING) + " )", ReimbursementRepository.STATUS_REIMBURSED, ReimbursementRepository.STATUS_CANCELED, company).fetch();
    int i = 0;
    for (Reimbursement reimbursement : reimbursementList) {
        log.debug("Remboursement n° {}", reimbursement.getRef());
        updateReimbursement(reimbursementRepo.find(reimbursement.getId()));
    }
    List<Partner> partnerList = Lists.transform(reimbursementList, Reimbursement::getPartner);
    for (Partner partner : partnerList) {
        try {
            partner = partnerRepository.find(partner.getId());
            log.debug("Tiers n° {}", partner.getName());
            List<MoveLine> moveLineList = moveLineRepo.all().filter("self.account.useForPartnerBalance = 'true' " + "AND (self.move.statusSelect = ?1 OR self.move.statusSelect = ?2) AND self.amountRemaining > 0 AND self.credit > 0 AND self.partner = ?3 AND self.company = ?4 AND " + "self.reimbursementStatusSelect = ?5 ", MoveRepository.STATUS_VALIDATED, MoveRepository.STATUS_ACCOUNTED, partnerRepository.find(partner.getId()), companyRepo.find(company.getId()), MoveLineRepository.REIMBURSEMENT_STATUS_NULL).fetch();
            log.debug("Liste des trop perçus : {}", moveLineList);
            if (moveLineList != null && !moveLineList.isEmpty()) {
                Reimbursement reimbursement = reimbursementExportService.runCreateReimbursement(moveLineList, companyRepo.find(company.getId()), partnerRepository.find(partner.getId()));
                if (reimbursement != null) {
                    updateReimbursement(reimbursementRepo.find(reimbursement.getId()));
                    this.totalAmount = this.totalAmount.add(reimbursementRepo.find(reimbursement.getId()).getAmountToReimburse());
                    i++;
                }
            }
        } catch (AxelorException e) {
            TraceBackService.trace(new AxelorException(e, e.getCategory(), I18n.get("Partner") + "%s", partnerRepository.find(partner.getId()).getName()), ExceptionOriginRepository.REIMBURSEMENT, batch.getId());
            incrementAnomaly();
        } catch (Exception e) {
            TraceBackService.trace(new Exception(String.format(I18n.get("Partner") + "%s", partnerRepository.find(partner.getId()).getName()), e), ExceptionOriginRepository.REIMBURSEMENT, batch.getId());
            incrementAnomaly();
            log.error("Bug(Anomalie) généré(e) pour le tiers {}", partnerRepository.find(partner.getId()).getName());
        } finally {
            if (i % 10 == 0) {
                JPA.clear();
            }
        }
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) BlockingService(com.axelor.apps.base.service.BlockingService) MoveLine(com.axelor.apps.account.db.MoveLine) Reimbursement(com.axelor.apps.account.db.Reimbursement) Partner(com.axelor.apps.base.db.Partner) AxelorException(com.axelor.exception.AxelorException)

Example 14 with Reimbursement

use of com.axelor.apps.account.db.Reimbursement in project axelor-open-suite by axelor.

the class BatchReimbursementImport method process.

@Override
protected void process() {
    if (!end) {
        Company company = batch.getAccountingBatch().getCompany();
        company = companyRepo.find(company.getId());
        AccountConfig accountConfig = company.getAccountConfig();
        Map<List<String[]>, String> data = null;
        try {
            String dataImportDir = AppService.getFileUploadDir();
            String reimbursementImportFolderPathCFONB = accountConfig.getReimbursementImportFolderPathCFONB() == null ? null : dataImportDir + accountConfig.getReimbursementImportFolderPathCFONB();
            rejectImportService.createFilePath(reimbursementImportFolderPathCFONB);
            data = rejectImportService.getCFONBFileByLot(reimbursementImportFolderPathCFONB, accountConfig.getTempReimbImportFolderPathCFONB() == null ? null : dataImportDir + accountConfig.getTempReimbImportFolderPathCFONB(), company, 0);
        } catch (AxelorException e) {
            TraceBackService.trace(new AxelorException(e, e.getCategory(), I18n.get(IExceptionMessage.BATCH_REIMBURSEMENT_6), batch.getId()), ExceptionOriginRepository.REIMBURSEMENT, batch.getId());
            incrementAnomaly();
            stop();
        } catch (Exception e) {
            TraceBackService.trace(new Exception(String.format(I18n.get(IExceptionMessage.BATCH_REIMBURSEMENT_6), batch.getId()), e), ExceptionOriginRepository.REIMBURSEMENT, batch.getId());
            incrementAnomaly();
            log.error("Bug(Anomalie) généré(e) pour le batch d'import des remboursements {}", batch.getId());
            stop();
        }
        int seq = 1;
        int i = 0;
        for (Entry<List<String[]>, String> entry : data.entrySet()) {
            LocalDate rejectDate = rejectImportService.createRejectDate(entry.getValue());
            Move move = this.createMove(company, rejectDate);
            for (String[] reject : entry.getKey()) {
                try {
                    Reimbursement reimbursement = reimbursementImportService.createReimbursementRejectMoveLine(reject, companyRepo.find(company.getId()), seq, moveRepo.find(move.getId()), rejectDate);
                    if (reimbursement != null) {
                        log.debug("Remboursement n° {} traité", reimbursement.getRef());
                        seq++;
                        i++;
                        updateReimbursement(reimbursement);
                    }
                } catch (AxelorException e) {
                    TraceBackService.trace(new AxelorException(e, e.getCategory(), I18n.get(IExceptionMessage.BATCH_REIMBURSEMENT_7), reject[1]), ExceptionOriginRepository.REIMBURSEMENT, batch.getId());
                    incrementAnomaly();
                } catch (Exception e) {
                    TraceBackService.trace(new Exception(String.format(I18n.get(IExceptionMessage.BATCH_REIMBURSEMENT_7), reject[1]), e), ExceptionOriginRepository.REIMBURSEMENT, batch.getId());
                    incrementAnomaly();
                    log.error("Bug(Anomalie) généré(e) pour le rejet de remboursement {}", reject[1]);
                } finally {
                    if (i % 10 == 0) {
                        JPA.clear();
                    }
                }
            }
            this.validateMove(move, rejectDate, seq);
        }
        updateCustomerAccountLog += batchAccountCustomer.updateAccountingSituationMarked(company);
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) Company(com.axelor.apps.base.db.Company) LocalDate(java.time.LocalDate) AxelorException(com.axelor.exception.AxelorException) AccountConfig(com.axelor.apps.account.db.AccountConfig) Move(com.axelor.apps.account.db.Move) List(java.util.List) Reimbursement(com.axelor.apps.account.db.Reimbursement)

Aggregations

Reimbursement (com.axelor.apps.account.db.Reimbursement)14 AxelorException (com.axelor.exception.AxelorException)6 Transactional (com.google.inject.persist.Transactional)5 MoveLine (com.axelor.apps.account.db.MoveLine)4 BigDecimal (java.math.BigDecimal)4 Partner (com.axelor.apps.base.db.Partner)3 AccountConfig (com.axelor.apps.account.db.AccountConfig)2 AccountingBatch (com.axelor.apps.account.db.AccountingBatch)2 BatchCreditTransferPartnerReimbursement (com.axelor.apps.account.service.batch.BatchCreditTransferPartnerReimbursement)2 LocalDate (java.time.LocalDate)2 ArrayList (java.util.ArrayList)2 InterbankCodeLine (com.axelor.apps.account.db.InterbankCodeLine)1 Move (com.axelor.apps.account.db.Move)1 MoveLineRepository (com.axelor.apps.account.db.repo.MoveLineRepository)1 ReimbursementExportService (com.axelor.apps.account.service.ReimbursementExportService)1 ReimbursementService (com.axelor.apps.account.service.ReimbursementService)1 BankOrder (com.axelor.apps.bankpayment.db.BankOrder)1 BankOrderLine (com.axelor.apps.bankpayment.db.BankOrderLine)1 BankDetails (com.axelor.apps.base.db.BankDetails)1 Company (com.axelor.apps.base.db.Company)1