Search in sources :

Example 1 with Invoice

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

the class NotificationServiceImpl method populateNotificationItemList.

@Override
public void populateNotificationItemList(Notification notification) {
    notification.clearNotificationItemList();
    Comparator<Invoice> byInvoiceDate = (i1, i2) -> i1.getInvoiceDate().compareTo(i2.getInvoiceDate());
    Comparator<Invoice> byDueDate = (i1, i2) -> i1.getDueDate().compareTo(i2.getDueDate());
    Comparator<Invoice> byInvoiceId = (i1, i2) -> i1.getInvoiceId().compareTo(i2.getInvoiceId());
    List<Invoice> invoiceList = new ArrayList<Invoice>();
    if (notification.getSubrogationRelease() != null) {
        invoiceList = notification.getSubrogationRelease().getInvoiceSet().stream().sorted(byInvoiceDate.thenComparing(byDueDate).thenComparing(byInvoiceId)).collect(Collectors.toList());
    }
    for (Invoice invoice : invoiceList) {
        if (invoice.getAmountRemaining().signum() > 0) {
            notification.addNotificationItemListItem(createNotificationItem(invoice));
        }
    }
}
Also used : Company(com.axelor.apps.base.db.Company) AccountConfig(com.axelor.apps.account.db.AccountConfig) Move(com.axelor.apps.account.db.Move) MoveService(com.axelor.apps.account.service.move.MoveService) Inject(com.google.inject.Inject) NotificationItem(com.axelor.apps.account.db.NotificationItem) TypedQuery(javax.persistence.TypedQuery) SubrogationRelease(com.axelor.apps.account.db.SubrogationRelease) NotificationRepository(com.axelor.apps.account.db.repo.NotificationRepository) Transactional(com.google.inject.persist.Transactional) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal) AxelorException(com.axelor.exception.AxelorException) MoveLine(com.axelor.apps.account.db.MoveLine) I18n(com.axelor.i18n.I18n) NoSuchElementException(java.util.NoSuchElementException) Journal(com.axelor.apps.account.db.Journal) JPA(com.axelor.db.JPA) Invoice(com.axelor.apps.account.db.Invoice) Collectors(java.util.stream.Collectors) Account(com.axelor.apps.account.db.Account) List(java.util.List) AccountConfigService(com.axelor.apps.account.service.config.AccountConfigService) Notification(com.axelor.apps.account.db.Notification) Comparator(java.util.Comparator) SubrogationReleaseRepository(com.axelor.apps.account.db.repo.SubrogationReleaseRepository) MoveRepository(com.axelor.apps.account.db.repo.MoveRepository) Invoice(com.axelor.apps.account.db.Invoice) ArrayList(java.util.ArrayList)

Example 2 with Invoice

use of com.axelor.apps.account.db.Invoice 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 3 with Invoice

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

Example 4 with Invoice

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

the class PaymentScheduleServiceImpl method getPaymentSchedulerMoveLineToPay.

/**
 * This method is used to get the movelines to be paid based on a paymentSchedule It loops on the
 * invoice M2M content and gets the movelines which are to pay
 *
 * @param paymentSchedule
 * @return
 */
@Override
public List<MoveLine> getPaymentSchedulerMoveLineToPay(PaymentSchedule paymentSchedule) {
    log.debug("In getPaymentSchedulerMoveLineToPay ....");
    List<MoveLine> moveLines = new ArrayList<MoveLine>();
    for (Invoice invoice : paymentSchedule.getInvoiceSet()) {
        if (invoice.getCompanyInTaxTotalRemaining().compareTo(BigDecimal.ZERO) > 0 && invoice.getMove() != null && invoice.getMove().getMoveLineList() != null) {
            for (MoveLine moveLine : invoice.getMove().getMoveLineList()) {
                if (moveLine.getAccount().getUseForPartnerBalance() && moveLine.getAmountRemaining().compareTo(BigDecimal.ZERO) > 0 && moveLine.getDebit().compareTo(BigDecimal.ZERO) > 0) {
                    moveLines.add(moveLine);
                }
            }
        }
    }
    log.debug("End getPaymentSchedulerMoveLineToPay.");
    return moveLines;
}
Also used : Invoice(com.axelor.apps.account.db.Invoice) MoveLine(com.axelor.apps.account.db.MoveLine) ArrayList(java.util.ArrayList)

Example 5 with Invoice

use of com.axelor.apps.account.db.Invoice 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)

Aggregations

Invoice (com.axelor.apps.account.db.Invoice)195 AxelorException (com.axelor.exception.AxelorException)69 ArrayList (java.util.ArrayList)48 Transactional (com.google.inject.persist.Transactional)46 BigDecimal (java.math.BigDecimal)32 Company (com.axelor.apps.base.db.Company)31 InvoiceLine (com.axelor.apps.account.db.InvoiceLine)29 Partner (com.axelor.apps.base.db.Partner)27 InvoiceRepository (com.axelor.apps.account.db.repo.InvoiceRepository)22 InvoiceService (com.axelor.apps.account.service.invoice.InvoiceService)22 PaymentMode (com.axelor.apps.account.db.PaymentMode)21 Map (java.util.Map)21 List (java.util.List)20 StockMove (com.axelor.apps.stock.db.StockMove)19 RefundInvoice (com.axelor.apps.account.service.invoice.generator.invoice.RefundInvoice)18 MoveLine (com.axelor.apps.account.db.MoveLine)17 LocalDate (java.time.LocalDate)17 InvoiceGenerator (com.axelor.apps.account.service.invoice.generator.InvoiceGenerator)16 Context (com.axelor.rpc.Context)15 InvoicePayment (com.axelor.apps.account.db.InvoicePayment)14