Search in sources :

Example 21 with AccountingBatch

use of com.axelor.apps.account.db.AccountingBatch 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)

Aggregations

AccountingBatch (com.axelor.apps.account.db.AccountingBatch)21 Batch (com.axelor.apps.base.db.Batch)11 AxelorException (com.axelor.exception.AxelorException)9 AccountingBatchRepository (com.axelor.apps.account.db.repo.AccountingBatchRepository)5 AccountingBatchService (com.axelor.apps.account.service.batch.AccountingBatchService)5 BankDetails (com.axelor.apps.base.db.BankDetails)5 LocalDate (java.time.LocalDate)4 Partner (com.axelor.apps.base.db.Partner)3 ArrayList (java.util.ArrayList)3 InvoicePayment (com.axelor.apps.account.db.InvoicePayment)2 PaymentScheduleLine (com.axelor.apps.account.db.PaymentScheduleLine)2 Reimbursement (com.axelor.apps.account.db.Reimbursement)2 BankOrder (com.axelor.apps.bankpayment.db.BankOrder)2 Company (com.axelor.apps.base.db.Company)2 IOException (java.io.IOException)2 JAXBException (javax.xml.bind.JAXBException)2 DatatypeConfigurationException (javax.xml.datatype.DatatypeConfigurationException)2 Pair (org.apache.commons.lang3.tuple.Pair)2 Account (com.axelor.apps.account.db.Account)1 AccountManagement (com.axelor.apps.account.db.AccountManagement)1