Search in sources :

Example 1 with PaymentScheduleLine

use of com.axelor.apps.account.db.PaymentScheduleLine 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;
}
Also used : Company(com.axelor.apps.base.db.Company) PaymentSchedule(com.axelor.apps.account.db.PaymentSchedule) Move(com.axelor.apps.account.db.Move) MoveService(com.axelor.apps.account.service.move.MoveService) PaymentService(com.axelor.apps.account.service.payment.PaymentService) Inject(com.google.inject.Inject) LoggerFactory(org.slf4j.LoggerFactory) PaymentModeService(com.axelor.apps.account.service.payment.PaymentModeService) Transactional(com.google.inject.persist.Transactional) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal) Lists(com.google.common.collect.Lists) AxelorException(com.axelor.exception.AxelorException) MoveLine(com.axelor.apps.account.db.MoveLine) PaymentScheduleLine(com.axelor.apps.account.db.PaymentScheduleLine) MoveToolService(com.axelor.apps.account.service.move.MoveToolService) PaymentScheduleRepository(com.axelor.apps.account.db.repo.PaymentScheduleRepository) RoundingMode(java.math.RoundingMode) Journal(com.axelor.apps.account.db.Journal) Logger(org.slf4j.Logger) MethodHandles(java.lang.invoke.MethodHandles) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) Invoice(com.axelor.apps.account.db.Invoice) Collectors(java.util.stream.Collectors) Account(com.axelor.apps.account.db.Account) SequenceService(com.axelor.apps.base.service.administration.SequenceService) List(java.util.List) PaymentScheduleLineRepository(com.axelor.apps.account.db.repo.PaymentScheduleLineRepository) LocalDate(java.time.LocalDate) PaymentMode(com.axelor.apps.account.db.PaymentMode) Preconditions(com.google.common.base.Preconditions) Comparator(java.util.Comparator) MoveLineRepository(com.axelor.apps.account.db.repo.MoveLineRepository) Partner(com.axelor.apps.base.db.Partner) MoveRepository(com.axelor.apps.account.db.repo.MoveRepository) BankDetails(com.axelor.apps.base.db.BankDetails) Account(com.axelor.apps.account.db.Account) Company(com.axelor.apps.base.db.Company) PaymentSchedule(com.axelor.apps.account.db.PaymentSchedule) Move(com.axelor.apps.account.db.Move) MoveLine(com.axelor.apps.account.db.MoveLine) Journal(com.axelor.apps.account.db.Journal) Partner(com.axelor.apps.base.db.Partner) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) Transactional(com.google.inject.persist.Transactional)

Example 2 with PaymentScheduleLine

use of com.axelor.apps.account.db.PaymentScheduleLine 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;
}
Also used : Invoice(com.axelor.apps.account.db.Invoice) PaymentSchedule(com.axelor.apps.account.db.PaymentSchedule) PaymentScheduleLine(com.axelor.apps.account.db.PaymentScheduleLine)

Example 3 with PaymentScheduleLine

use of com.axelor.apps.account.db.PaymentScheduleLine in project axelor-open-suite by axelor.

the class PaymentScheduleServiceImpl method cancelPaymentSchedule.

/**
 * Methode qui annule un échéancier
 *
 * @param paymentSchedule
 */
@Override
public void cancelPaymentSchedule(PaymentSchedule paymentSchedule) {
    // L'échéancier est passé à annulé
    paymentSchedule.setStatusSelect(PaymentScheduleRepository.STATUS_CANCELED);
    for (PaymentScheduleLine paymentScheduleLine : paymentSchedule.getPaymentScheduleLineList()) {
        // Si l'échéance n'est pas complètement payée
        if (paymentScheduleLine.getInTaxAmountPaid().compareTo(paymentScheduleLine.getInTaxAmount()) != 0) {
            // L'échéance est passée à cloturé
            paymentScheduleLine.setStatusSelect(PaymentScheduleLineRepository.STATUS_CLOSED);
        }
    }
    for (Invoice invoice : paymentSchedule.getInvoiceSet()) {
        // L'échéancier n'est plus selectionné sur la facture
        invoice.setPaymentSchedule(null);
        // L'échéancier est assigné dans un nouveau champs afin de garder un lien invisble pour
        // l'utilisateur, mais utilisé pour le passage en irrécouvrable
        invoice.setCanceledPaymentSchedule(paymentSchedule);
        invoice.setSchedulePaymentOk(false);
    }
}
Also used : Invoice(com.axelor.apps.account.db.Invoice) PaymentScheduleLine(com.axelor.apps.account.db.PaymentScheduleLine)

Example 4 with PaymentScheduleLine

use of com.axelor.apps.account.db.PaymentScheduleLine in project axelor-open-suite by axelor.

the class PaymentScheduleServiceImpl method updatePaymentSchedule.

/**
 * Mise à jour d'un échéancier avec un nouveau montant d'échéance.
 *
 * @param paymentSchedule L'échéancier cible.
 * @param inTaxTotal Nouveau montant d'une échéance.
 */
@Override
@Transactional
public void updatePaymentSchedule(PaymentSchedule paymentSchedule, BigDecimal inTaxTotal) {
    log.debug("Mise à jour de l'échéancier {} : {}", new Object[] { paymentSchedule.getPaymentScheduleSeq(), inTaxTotal });
    for (PaymentScheduleLine paymentScheduleLine : paymentSchedule.getPaymentScheduleLineList()) {
        if (paymentScheduleLine.getStatusSelect() == PaymentScheduleLineRepository.STATUS_IN_PROGRESS && !paymentScheduleLine.getRejectedOk()) {
            log.debug("Mise à jour de la ligne {} ", paymentScheduleLine.getName());
            paymentScheduleLine.setInTaxAmount(inTaxTotal);
        }
    }
    paymentScheduleRepo.save(paymentSchedule);
}
Also used : PaymentScheduleLine(com.axelor.apps.account.db.PaymentScheduleLine) Transactional(com.google.inject.persist.Transactional)

Example 5 with PaymentScheduleLine

use of com.axelor.apps.account.db.PaymentScheduleLine in project axelor-open-suite by axelor.

the class IrrecoverableService method passInIrrecoverable.

/**
 * Procédure permettant de passer un échéancier de lissage de paiement en irrécouvrable La
 * procédure passera aussi les lignes d'écriture de rejet d'échéance en irrécouvrable, ainsi que
 * les factures pas complètement payée selectionnées sur l'échéancier
 *
 * @param paymentSchedule Un échéancier de paiement
 * @throws AxelorException
 */
@Transactional(rollbackOn = { Exception.class })
public void passInIrrecoverable(PaymentSchedule paymentSchedule) throws AxelorException {
    Company company = paymentSchedule.getCompany();
    paymentSchedule.setIrrecoverableStatusSelect(PaymentScheduleRepository.IRRECOVERABLE_STATUS_TO_PASS_IN_IRRECOUVRABLE);
    ManagementObject managementObject = this.createManagementObject("IRR", accountConfigService.getIrrecoverableReasonPassage(accountConfigService.getAccountConfig(company)));
    paymentSchedule.setManagementObject(managementObject);
    List<MoveLine> paymentScheduleLineRejectMoveLineList = new ArrayList<MoveLine>();
    for (PaymentScheduleLine paymentScheduleLine : paymentSchedule.getPaymentScheduleLineList()) {
        if (paymentScheduleLine.getRejectMoveLine() != null && paymentScheduleLine.getRejectMoveLine().getAmountRemaining().compareTo(BigDecimal.ZERO) > 0) {
            paymentScheduleLineRejectMoveLineList.add(paymentScheduleLine.getRejectMoveLine());
        }
    }
    for (MoveLine moveLine : paymentScheduleLineRejectMoveLineList) {
        this.passInIrrecoverable(moveLine, managementObject, true);
    }
    for (Invoice invoice : paymentSchedule.getInvoiceSet()) {
        if (invoice.getCompanyInTaxTotalRemaining().compareTo(BigDecimal.ZERO) > 0) {
            this.passInIrrecoverable(invoice, managementObject);
        }
    }
    paymentScheduleService.cancelPaymentSchedule(paymentSchedule);
    paymentScheduleRepo.save(paymentSchedule);
}
Also used : Company(com.axelor.apps.base.db.Company) Invoice(com.axelor.apps.account.db.Invoice) ManagementObject(com.axelor.apps.account.db.ManagementObject) PaymentScheduleLine(com.axelor.apps.account.db.PaymentScheduleLine) MoveLine(com.axelor.apps.account.db.MoveLine) ArrayList(java.util.ArrayList) Transactional(com.google.inject.persist.Transactional)

Aggregations

PaymentScheduleLine (com.axelor.apps.account.db.PaymentScheduleLine)29 Transactional (com.google.inject.persist.Transactional)12 Invoice (com.axelor.apps.account.db.Invoice)11 AxelorException (com.axelor.exception.AxelorException)10 ArrayList (java.util.ArrayList)8 PaymentSchedule (com.axelor.apps.account.db.PaymentSchedule)7 BigDecimal (java.math.BigDecimal)6 LocalDate (java.time.LocalDate)5 MoveLine (com.axelor.apps.account.db.MoveLine)4 BankDetails (com.axelor.apps.base.db.BankDetails)4 Company (com.axelor.apps.base.db.Company)4 Partner (com.axelor.apps.base.db.Partner)4 Move (com.axelor.apps.account.db.Move)3 PaymentMode (com.axelor.apps.account.db.PaymentMode)3 AccountingBatch (com.axelor.apps.account.db.AccountingBatch)2 PaymentModeService (com.axelor.apps.account.service.payment.PaymentModeService)2 BankOrder (com.axelor.apps.bankpayment.db.BankOrder)2 EntityTransaction (javax.persistence.EntityTransaction)2 Account (com.axelor.apps.account.db.Account)1 AccountManagement (com.axelor.apps.account.db.AccountManagement)1