use of com.axelor.apps.account.db.AccountingBatch in project axelor-open-suite by axelor.
the class AccountingBatchController method actionCreditTransfer.
public void actionCreditTransfer(ActionRequest request, ActionResponse response) {
AccountingBatch accountingBatch = request.getContext().asType(AccountingBatch.class);
accountingBatch = Beans.get(AccountingBatchRepository.class).find(accountingBatch.getId());
Batch batch = Beans.get(AccountingBatchService.class).creditTransfer(accountingBatch);
response.setFlash(batch.getComments());
response.setReload(true);
}
use of com.axelor.apps.account.db.AccountingBatch in project axelor-open-suite by axelor.
the class BatchAccountCustomer method process.
@Override
public void process() {
AccountingBatch accountingBatch = batch.getAccountingBatch();
Company company = accountingBatch.getCompany();
boolean updateCustAccountOk = accountingBatch.getUpdateCustAccountOk();
boolean updateDueCustAccountOk = accountingBatch.getUpdateDueCustAccountOk();
boolean updateDueDebtRecoveryCustAccountOk = accountingBatch.getUpdateDueDebtRecoveryCustAccountOk();
List<AccountingSituation> accountingSituationList = accountingSituationRepo.all().filter("self.company = ?1", company).fetch();
int i = 0;
JPA.clear();
for (AccountingSituation accountingSituation : accountingSituationList) {
try {
accountingSituation = accountCustomerService.updateAccountingSituationCustomerAccount(accountingSituationRepo.find(accountingSituation.getId()), updateCustAccountOk, updateDueCustAccountOk, updateDueDebtRecoveryCustAccountOk);
if (accountingSituation != null) {
this.updateAccountingSituation(accountingSituation);
i++;
}
} catch (Exception e) {
TraceBackService.trace(new Exception(String.format(I18n.get(IExceptionMessage.BATCH_ACCOUNT_1), accountingSituationRepo.find(accountingSituation.getId()).getName()), e), ExceptionOriginRepository.CUSTOMER_ACCOUNT, batch.getId());
incrementAnomaly();
log.error("Bug(Anomalie) généré(e) pour la situation compable {}", accountingSituationRepo.find(accountingSituation.getId()).getName());
} finally {
if (i % 1 == 0) {
JPA.clear();
}
}
}
}
use of com.axelor.apps.account.db.AccountingBatch in project axelor-open-suite by axelor.
the class BatchBankPaymentServiceImpl method createBankOrderFromMonthlyPaymentScheduleLines.
@Override
@Transactional(rollbackOn = { Exception.class })
public BankOrder createBankOrderFromMonthlyPaymentScheduleLines(Batch batch) throws AxelorException, JAXBException, IOException, DatatypeConfigurationException {
AccountingBatch accountingBatch = batch.getAccountingBatch();
LocalDate bankOrderDate = accountingBatch.getDueDate();
Company senderCompany = accountingBatch.getCompany();
BankDetails senderBankDetails = accountingBatch.getBankDetails();
if (senderBankDetails == null) {
senderBankDetails = accountingBatch.getCompany().getDefaultBankDetails();
}
PaymentMode paymentMode = accountingBatch.getPaymentMode();
Currency currency = senderCompany.getCurrency();
int partnerType = BankOrderRepository.PARTNER_TYPE_CUSTOMER;
String senderReference = "";
String senderLabel = "";
if (bankOrderDate == null) {
bankOrderDate = appBaseService.getTodayDate(senderCompany);
}
BankOrder bankOrder = bankOrderCreateService.createBankOrder(paymentMode, partnerType, bankOrderDate, senderCompany, senderBankDetails, currency, senderReference, senderLabel, BankOrderRepository.TECHNICAL_ORIGIN_AUTOMATIC);
bankOrder = JPA.save(bankOrder);
List<PaymentScheduleLine> paymentScheduleLineList;
int offset = 0;
try {
while (!(paymentScheduleLineList = fetchPaymentScheduleLineDoneList(batch, offset)).isEmpty()) {
bankOrder = bankOrderRepo.find(bankOrder.getId());
for (PaymentScheduleLine paymentScheduleLine : paymentScheduleLineList) {
PaymentSchedule paymentSchedule = paymentScheduleLine.getPaymentSchedule();
Partner partner = paymentSchedule.getPartner();
BankDetails bankDetails = paymentScheduleService.getBankDetails(paymentSchedule);
BigDecimal amount = paymentScheduleLine.getInTaxAmount();
String receiverReference = paymentScheduleLine.getName();
String receiverLabel = paymentScheduleLine.getDebitNumber();
BankOrderLine bankOrderLine = bankOrderLineService.createBankOrderLine(paymentMode.getBankOrderFileFormat(), null, partner, bankDetails, amount, currency, bankOrderDate, receiverReference, receiverLabel, paymentScheduleLine);
bankOrder.addBankOrderLineListItem(bankOrderLine);
}
bankOrder = JPA.save(bankOrder);
offset += paymentScheduleLineList.size();
JPA.clear();
}
} catch (Exception e) {
bankOrder = bankOrderRepo.find(bankOrder.getId());
bankOrderRepo.remove(bankOrder);
throw e;
}
bankOrder = bankOrderRepo.find(bankOrder.getId());
bankOrder = bankOrderRepo.save(bankOrder);
bankOrderService.confirm(bankOrder);
batch = batchRepo.find(batch.getId());
batch.setBankOrder(bankOrder);
return bankOrder;
}
use of com.axelor.apps.account.db.AccountingBatch in project axelor-open-suite by axelor.
the class BatchCreditTransferPartnerReimbursementBankPayment method process.
@Override
protected void process() {
super.process();
AccountingBatch accountingBatch = batch.getAccountingBatch();
if (!accountingBatch.getPaymentMode().getGenerateBankOrder()) {
return;
}
// Fetch all reimbursements that are validated for the specified company.
Query<Reimbursement> query = reimbursementRepo.all().filter("self.statusSelect = :statusSelect AND self.company = :company");
query.bind("statusSelect", ReimbursementRepository.STATUS_VALIDATED);
query.bind("company", accountingBatch.getCompany());
List<Reimbursement> reimbursementList = query.fetch();
if (reimbursementList.isEmpty()) {
return;
}
accountingBatch = Beans.get(AccountingBatchRepository.class).find(accountingBatch.getId());
try {
createBankOrder(accountingBatch, reimbursementList);
} catch (Exception ex) {
TraceBackService.trace(ex);
logger.error(ex.getLocalizedMessage());
}
}
use of com.axelor.apps.account.db.AccountingBatch in project axelor-open-suite by axelor.
the class BatchCreditTransferInvoice method processInvoices.
/**
* Process invoices of the specified document type.
*
* @param operationTypeSelect
* @return
*/
protected List<InvoicePayment> processInvoices(int operationTypeSelect) {
List<InvoicePayment> doneList = new ArrayList<>();
// Can't pass an empty collection to the query
List<Long> anomalyList = Lists.newArrayList(0L);
AccountingBatch accountingBatch = batch.getAccountingBatch();
boolean manageMultiBanks = appAccountService.getAppBase().getManageMultiBanks();
StringBuilder filter = new StringBuilder();
filter.append("self.operationTypeSelect = :operationTypeSelect " + "AND self.statusSelect = :statusSelect " + "AND self.amountRemaining > 0 " + "AND self.hasPendingPayments = FALSE " + "AND self.company = :company " + "AND self.dueDate <= :dueDate " + "AND self.paymentMode = :paymentMode " + "AND self.id NOT IN (:anomalyList)" + "AND self.pfpValidateStatusSelect != :pfpValidateStatusSelect");
if (manageMultiBanks) {
filter.append(" AND self.companyBankDetails IN (:bankDetailsSet)");
}
if (accountingBatch.getCurrency() != null) {
filter.append(" AND self.currency = :currency");
}
Query<Invoice> query = invoiceRepo.all().filter(filter.toString()).bind("operationTypeSelect", operationTypeSelect).bind("statusSelect", InvoiceRepository.STATUS_VENTILATED).bind("company", accountingBatch.getCompany()).bind("dueDate", accountingBatch.getDueDate()).bind("paymentMode", accountingBatch.getPaymentMode()).bind("anomalyList", anomalyList).bind("pfpValidateStatusSelect", InvoiceRepository.PFP_STATUS_LITIGATION);
if (manageMultiBanks) {
Set<BankDetails> bankDetailsSet = Sets.newHashSet(accountingBatch.getBankDetails());
if (accountingBatch.getIncludeOtherBankAccounts()) {
bankDetailsSet.addAll(accountingBatch.getCompany().getBankDetailsList());
}
query.bind("bankDetailsSet", bankDetailsSet);
}
if (accountingBatch.getCurrency() != null) {
query.bind("currency", accountingBatch.getCurrency());
}
BankDetailsRepository bankDetailsRepo = Beans.get(BankDetailsRepository.class);
BankDetails companyBankDetails = accountingBatch.getBankDetails();
for (List<Invoice> invoiceList; !(invoiceList = query.fetch(FETCH_LIMIT)).isEmpty(); JPA.clear()) {
if (!JPA.em().contains(companyBankDetails)) {
companyBankDetails = bankDetailsRepo.find(companyBankDetails.getId());
}
for (Invoice invoice : invoiceList) {
try {
doneList.add(invoicePaymentCreateService.createInvoicePayment(invoice, companyBankDetails));
incrementDone();
} catch (Exception ex) {
incrementAnomaly();
anomalyList.add(invoice.getId());
query.bind("anomalyList", anomalyList);
TraceBackService.trace(ex, ExceptionOriginRepository.CREDIT_TRANSFER, batch.getId());
ex.printStackTrace();
log.error(String.format("Credit transfer batch for invoices: anomaly for invoice %s", invoice.getInvoiceId()));
break;
}
}
}
return doneList;
}
Aggregations