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;
}
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();
}
}
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();
}
}
}
}
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);
}
}
Aggregations