use of com.axelor.apps.account.db.PaymentSchedule in project axelor-open-suite by axelor.
the class PaymentScheduleLineServiceImpl method createPaymentMove.
@Override
@Transactional(rollbackOn = { Exception.class })
public Move createPaymentMove(PaymentScheduleLine paymentScheduleLine, BankDetails companyBankDetails, PaymentMode paymentMode) throws AxelorException {
Preconditions.checkNotNull(paymentScheduleLine);
Preconditions.checkNotNull(companyBankDetails);
PaymentSchedule paymentSchedule = paymentScheduleLine.getPaymentSchedule();
Company company = paymentSchedule.getCompany();
Partner partner = paymentSchedule.getPartner();
Journal journal = paymentModeService.getPaymentModeJournal(paymentMode, company, companyBankDetails);
BigDecimal amount = paymentScheduleLine.getInTaxAmount();
String name = paymentScheduleLine.getName();
LocalDate todayDate = appBaseService.getTodayDate(company);
Account account = accountingSituationService.getCustomerAccount(partner, company);
Move move = moveService.getMoveCreateService().createMove(journal, company, null, partner, paymentMode, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_PAYMENT);
MoveLine creditMoveLine = moveService.getMoveLineService().createMoveLine(move, partner, account, amount, false, todayDate, 1, name, null);
move.addMoveLineListItem(creditMoveLine);
creditMoveLine = moveLineRepo.save(creditMoveLine);
Account paymentModeAccount = paymentModeService.getPaymentModeAccount(paymentMode, company, companyBankDetails);
MoveLine debitMoveLine = moveService.getMoveLineService().createMoveLine(move, partner, paymentModeAccount, amount, true, todayDate, 2, name, null);
move.addMoveLineListItem(debitMoveLine);
debitMoveLine = moveLineRepo.save(debitMoveLine);
moveService.getMoveValidateService().validate(move);
// Reconcile
if (paymentSchedule.getTypeSelect() == PaymentScheduleRepository.TYPE_TERMS && paymentSchedule.getInvoiceSet() != null) {
List<MoveLine> debitMoveLineList = paymentSchedule.getInvoiceSet().stream().sorted(Comparator.comparing(Invoice::getDueDate)).map(invoice -> moveService.getMoveLineService().getDebitCustomerMoveLine(invoice)).collect(Collectors.toList());
if (moveToolService.isSameAccount(debitMoveLineList, account)) {
List<MoveLine> creditMoveLineList = Lists.newArrayList(creditMoveLine);
paymentService.useExcessPaymentOnMoveLines(debitMoveLineList, creditMoveLineList);
}
}
paymentScheduleLine.setDirectDebitAmount(amount);
paymentScheduleLine.setInTaxAmountPaid(amount);
paymentScheduleLine.setAdvanceOrPaymentMove(move);
paymentScheduleLine.setAdvanceMoveLine(creditMoveLine);
paymentScheduleLine.setStatusSelect(PaymentScheduleLineRepository.STATUS_VALIDATED);
paymentScheduleService.closePaymentScheduleIfAllPaid(paymentSchedule);
return move;
}
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 invoice Facture globale permettant de définir la facture pour une échéance. L'échéancier
* est automatiquement associé à la facture si celle-ci existe.
* @param company La société.
* @param date Date de création.
* @param startDate Date de première échéance.
* @param nbrTerm Nombre d'échéances.
* @param bankDetails RIB.
* @param paymentMode Mode de paiement.
* @return L'échéancier créé.
* @throws AxelorException
*/
@Override
public PaymentSchedule createPaymentSchedule(Partner partner, Invoice invoice, Company company, LocalDate date, LocalDate startDate, int nbrTerm, BankDetails bankDetails, PaymentMode paymentMode) throws AxelorException {
PaymentSchedule paymentSchedule = new PaymentSchedule();
paymentSchedule.setCompany(company);
paymentSchedule.setPaymentScheduleSeq(this.getPaymentScheduleSequence(company));
paymentSchedule.setCreationDate(date);
paymentSchedule.setStartDate(startDate);
paymentSchedule.setNbrTerm(nbrTerm);
paymentSchedule.setBankDetails(bankDetails);
paymentSchedule.setPaymentMode(paymentMode);
paymentSchedule.setPartner(partner);
if (paymentSchedule.getInvoiceSet() == null) {
paymentSchedule.setInvoiceSet(new HashSet<Invoice>());
} else {
paymentSchedule.getInvoiceSet().clear();
}
if (invoice != null) {
paymentSchedule.addInvoiceSetItem(invoice);
invoice.setPaymentSchedule(paymentSchedule);
}
return paymentSchedule;
}
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 avec ces lignes.
*
* @param company La société.
* @param date Date de création.
* @param firstTermDate Date de première échéance.
* @param initialInTaxAmount Montant d'une échéance.
* @param nbrTerm Nombre d'échéances.
* @param bankDetails RIB.
* @param paymentMode Mode de paiement.
* @return L'échéancier créé.
* @throws AxelorException
*/
@Override
public PaymentSchedule createPaymentSchedule(Partner partner, Company company, LocalDate date, LocalDate firstTermDate, BigDecimal initialInTaxAmount, int nbrTerm, BankDetails bankDetails, PaymentMode paymentMode) throws AxelorException {
Invoice invoice = null;
PaymentSchedule paymentSchedule = this.createPaymentSchedule(partner, invoice, company, date, firstTermDate, nbrTerm, bankDetails, paymentMode);
paymentSchedule.setPaymentScheduleLineList(new ArrayList<PaymentScheduleLine>());
for (int term = 1; term < nbrTerm + 1; term++) {
paymentSchedule.getPaymentScheduleLineList().add(paymentScheduleLineService.createPaymentScheduleLine(paymentSchedule, initialInTaxAmount, term, firstTermDate.plusMonths(term - 1)));
}
return paymentSchedule;
}
use of com.axelor.apps.account.db.PaymentSchedule in project axelor-open-suite by axelor.
the class CfonbExportService method createRecipientCFONB.
/**
* Fonction permettant de créer un enregistrement 'destinataire' pour un export de prélèvement
* d'une échéance
*
* @param company Une société
* @param paymentScheduleLine Une échéance
* @return Un enregistrement 'destinataire'
* @throws AxelorException
*/
private String createRecipientCFONB(PaymentScheduleLine paymentScheduleLine, boolean mensu) throws AxelorException {
PaymentSchedule paymentSchedule = paymentScheduleLine.getPaymentSchedule();
Partner partner = paymentSchedule.getPartner();
BankDetails bankDetails = Beans.get(PaymentScheduleService.class).getBankDetails(paymentSchedule);
BigDecimal amount = paymentScheduleLine.getDirectDebitAmount();
// Référence
String ref = paymentScheduleLine.getDebitNumber();
// Nom/Raison sociale du débiteur
String partnerName = this.getPayeurPartnerName(partner);
String operationCode = // Code opération
this.cfonbConfig.getDirectDebitOperationCodeExportCFONB();
return this.createRecipientCFONB(amount, ref, partnerName, bankDetails, operationCode);
}
use of com.axelor.apps.account.db.PaymentSchedule in project axelor-open-suite by axelor.
the class PaymentScheduleController method validate.
// Validation button
public void validate(ActionRequest request, ActionResponse response) {
PaymentSchedule paymentSchedule = request.getContext().asType(PaymentSchedule.class);
paymentSchedule = Beans.get(PaymentScheduleRepository.class).find(paymentSchedule.getId());
try {
Beans.get(PaymentScheduleService.class).validatePaymentSchedule(paymentSchedule);
response.setReload(true);
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
Aggregations