use of com.axelor.apps.account.db.PaymentSchedule in project axelor-open-suite by axelor.
the class PaymentScheduleLineBankPaymentServiceImpl method representPaymentScheduleLine.
@Transactional
protected PaymentScheduleLine representPaymentScheduleLine(PaymentScheduleLine paymentScheduleLine) {
PaymentSchedule paymentSchedule = paymentScheduleLine.getPaymentSchedule();
BigDecimal inTaxAmount = paymentScheduleLine.getInTaxAmount();
int scheduleLineSeq = paymentScheduleService.getNextScheduleLineSeq(paymentSchedule);
LocalDate scheduleDate = paymentScheduleLine.getScheduleDate();
PaymentScheduleLine representedPaymentScheduleLine = createPaymentScheduleLine(paymentSchedule, inTaxAmount, scheduleLineSeq, scheduleDate);
representedPaymentScheduleLine.setFromReject(true);
representedPaymentScheduleLine.setStatusSelect(PaymentScheduleLineRepository.STATUS_IN_PROGRESS);
return representedPaymentScheduleLine;
}
use of com.axelor.apps.account.db.PaymentSchedule in project axelor-open-suite by axelor.
the class PaymentScheduleServiceImpl method createPaymentSchedule.
/**
* Création d'un échéancier sans ces lignes.
*
* @param partner Le tiers.
* @param invoices Collection de factures.
* @param company La société.
* @param startDate Date de première échéance.
* @param nbrTerm Nombre d'échéances.
* @return L'échéancier créé.
* @throws AxelorException
*/
@Override
public PaymentSchedule createPaymentSchedule(Partner partner, Company company, Set<Invoice> invoices, LocalDate startDate, int nbrTerm) throws AxelorException {
Invoice invoice = null;
PaymentSchedule paymentSchedule = this.createPaymentSchedule(partner, invoice, company, appAccountService.getTodayDate(company), startDate, nbrTerm, partnerService.getDefaultBankDetails(partner), partner.getInPaymentMode());
paymentSchedule.getInvoiceSet().addAll(invoices);
return paymentSchedule;
}
use of com.axelor.apps.account.db.PaymentSchedule 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.PaymentSchedule 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.PaymentSchedule 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