use of com.axelor.apps.account.db.PaymentScheduleLine in project axelor-open-suite by axelor.
the class PaymentScheduleServiceImpl method validatePaymentSchedule.
/**
* Permet de valider un échéancier.
*
* @param paymentSchedule
* @throws AxelorException
*/
@Override
@Transactional(rollbackOn = { Exception.class })
public void validatePaymentSchedule(PaymentSchedule paymentSchedule) throws AxelorException {
log.debug("Validation de l'échéancier {}", paymentSchedule.getPaymentScheduleSeq());
if (paymentSchedule.getPaymentScheduleLineList() == null || paymentSchedule.getPaymentScheduleLineList().isEmpty()) {
throw new AxelorException(paymentSchedule, TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.PAYMENT_SCHEDULE_6), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION), paymentSchedule.getPaymentScheduleSeq());
}
checkTotalLineAmount(paymentSchedule);
for (PaymentScheduleLine paymentScheduleLine : paymentSchedule.getPaymentScheduleLineList()) {
paymentScheduleLine.setStatusSelect(PaymentScheduleLineRepository.STATUS_IN_PROGRESS);
}
this.updateInvoices(paymentSchedule);
paymentSchedule.setStatusSelect(PaymentScheduleRepository.STATUS_CONFIRMED);
}
use of com.axelor.apps.account.db.PaymentScheduleLine in project axelor-open-suite by axelor.
the class BatchBankPaymentServiceImpl method createBankOrder.
@Override
@Transactional(rollbackOn = { Exception.class })
public BankOrder createBankOrder(Batch batch) throws AxelorException, JAXBException, IOException, DatatypeConfigurationException {
PaymentScheduleLine paymentScheduleLine = getPaymentScheduleLineDoneListQuery(batch).fetchOne();
if (paymentScheduleLine == null) {
throw new AxelorException(batch, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.BATCH_DIRECT_DEBIT_NO_PROCESSED_PAYMENT_SCHEDULE_LINES));
}
PaymentSchedule paymentSchedule = paymentScheduleLine.getPaymentSchedule();
switch(paymentSchedule.getTypeSelect()) {
case PaymentScheduleRepository.TYPE_TERMS:
return createBankOrderFromPaymentScheduleLines(batch);
case PaymentScheduleRepository.TYPE_MONTHLY:
return createBankOrderFromMonthlyPaymentScheduleLines(batch);
default:
throw new AxelorException(paymentSchedule, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.BATCH_DIRECT_DEBIT_UNKNOWN_DATA_TYPE));
}
}
use of com.axelor.apps.account.db.PaymentScheduleLine 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.PaymentScheduleLine in project axelor-open-suite by axelor.
the class BatchDirectDebitPaymentSchedule method processQuery.
private void processQuery(QueryBuilder<PaymentScheduleLine> queryBuilder) {
Query<PaymentScheduleLine> query = queryBuilder.build();
List<PaymentScheduleLine> paymentScheduleLineList;
PaymentScheduleService paymentScheduleService = Beans.get(PaymentScheduleService.class);
PaymentScheduleLineService paymentScheduleLineService = Beans.get(PaymentScheduleLineService.class);
BankDetailsRepository bankDetailsRepo = Beans.get(BankDetailsRepository.class);
BankDetails companyBankDetails = getCompanyBankDetails(batch.getAccountingBatch());
while (!(paymentScheduleLineList = query.fetch(FETCH_LIMIT)).isEmpty()) {
findBatch();
companyBankDetails = bankDetailsRepo.find(companyBankDetails.getId());
PaymentMode directDebitPaymentMode = batch.getAccountingBatch().getPaymentMode();
for (PaymentScheduleLine paymentScheduleLine : paymentScheduleLineList) {
try {
if (generateBankOrderFlag) {
PaymentSchedule paymentSchedule = paymentScheduleLine.getPaymentSchedule();
BankDetails bankDetails = paymentScheduleService.getBankDetails(paymentSchedule);
Preconditions.checkArgument(bankDetails.getActive(), bankDetails.getPartner() != null ? bankDetails.getPartner().getFullName() + " - " + I18n.get("Bank details are inactive.") : I18n.get("Bank details are inactive."));
if (directDebitPaymentMode.getOrderTypeSelect() == PaymentModeRepository.ORDER_TYPE_SEPA_DIRECT_DEBIT) {
Partner partner = paymentSchedule.getPartner();
Preconditions.checkNotNull(partner, I18n.get("Partner is missing."));
Preconditions.checkNotNull(partner.getActiveUmr(), I18n.get("Partner active UMR is missing."));
}
}
paymentScheduleLineService.createPaymentMove(paymentScheduleLine, companyBankDetails, directDebitPaymentMode);
incrementDone(paymentScheduleLine);
} catch (Exception e) {
TraceBackService.trace(e, ExceptionOriginRepository.DIRECT_DEBIT, batch.getId());
incrementAnomaly(paymentScheduleLine);
break;
}
}
JPA.clear();
}
}
Aggregations