Class ProductListService

java.lang.Object
sk.iway.iwcm.components.basket.rest.ProductListService

public class ProductListService extends Object
Provides product-category administration and invoice calculation helpers for the basket module.
  • Method Details

    • getAllItems

      public static DatatablePageImpl<DocDetails> getAllItems(GetAllItemsDocOptions options)
      Loads products from the selected category tree and prepares prices in the requested currency.
      Parameters:
      options - repositories, request data, paging, and selected group information
      Returns:
      prepared product page for the administration DataTable
    • getGroupTreeIds

      public static List<Integer> getGroupTreeIds(int rootGroupId, DocDetailsRepository repo)
      Resolves product group identifiers for a selected subtree or all configured product groups.
      Parameters:
      rootGroupId - root group identifier, or a value below one to use all product groups
      repo - document repository used to detect configured product groups
      Returns:
      identifiers of groups included in the product listing
    • addProductGroup

      public static ProductListService.AddingStatus addProductGroup(Identity currentUser, String customData, EditorFacade editorFacade)
      Creates a product category and its default category page for an authorized user.
      Parameters:
      currentUser - user requesting category creation
      customData - JSON containing the parent group identifier and new group name
      editorFacade - editor facade used to create the category page
      Returns:
      status describing whether the category was created, already existed, or failed validation
    • getListOfProductsGroups

      public static List<LabelValueInteger> getListOfProductsGroups(DocDetailsRepository docDetailsRepository)
      Returns product groups from explicit configuration or automatic include detection.
      Parameters:
      docDetailsRepository - repository used to detect pages containing product-list applications
      Returns:
      configured product groups sorted as a tree
    • getListOfProductGroupsViaInclude

      public static List<LabelValueInteger> getListOfProductGroupsViaInclude(DocDetailsRepository docDetailsRepository)
      Finds product groups from pages containing a basket product-list application. Detected groups are expanded to their complete subtrees and sorted for selection.
      Parameters:
      docDetailsRepository - repository used to search page content
      Returns:
      detected product groups sorted as a tree
    • getListOfProductGroupsViaIds

      public static List<LabelValueInteger> getListOfProductGroupsViaIds(String idsString)
      Parses configured product group identifiers and validates them against the group cache. An identifier followed by * includes the complete subtree of that group.
      Parameters:
      idsString - comma- or plus-separated group identifiers
      Returns:
      valid configured product groups sorted as a tree
    • updateInvoiceStats

      public static void updateInvoiceStats(Long invoiceId, boolean updateStatus)
    • updateInvoiceStats

      public static void updateInvoiceStats(Long invoiceId, Long browserId, boolean updateStatus)
      Recalculates invoice item count, totals, balance, and optionally payment status.
      Parameters:
      invoiceId - invoice whose totals are updated
      browserId - browser identifier used to select items, or null to use the invoice identifier
      updateStatus - whether to derive the invoice status from invoice and payment totals
    • getPriceToPay

      public static BigDecimal getPriceToPay(Long invoiceId, BasketInvoiceItemsRepository biir)
      Calculates the VAT-inclusive total price of all items in an invoice.
      Parameters:
      invoiceId - invoice identifier
      biir - invoice item repository
      Returns:
      total price, zero for an empty invoice, or -1 for an invalid identifier
    • getPayedPrice

      public static BigDecimal getPayedPrice(Long invoiceId, BasketInvoicePaymentsRepository bipr)
      Calculates the total amount of confirmed payments for an invoice.
      Parameters:
      invoiceId - invoice identifier
      bipr - invoice payment repository
      Returns:
      confirmed payment total, zero when no payments exist, or -1 for a null identifier
    • getPriceInfo

      public static Map<String,String> getPriceInfo(Long invoiceId, BasketInvoiceItemsRepository biir, BasketInvoicePaymentsRepository bipr)
      Returns invoice totals and the status derived from its confirmed payments.
      Parameters:
      invoiceId - invoice identifier
      biir - invoice item repository
      bipr - invoice payment repository
      Returns:
      string values for price to pay, paid price, and derived status
    • getInvoiceStatusByValues

      public static final Integer getInvoiceStatusByValues(BigDecimal priceToPayVat, BigDecimal totalPayedPrice)
      Derives an invoice status by comparing its total price with received payments.
      Parameters:
      priceToPayVat - VAT-inclusive invoice total
      totalPayedPrice - total confirmed payments
      Returns:
      paid, partially paid, or new invoice status identifier
    • addItemToInvoice

      public static void addItemToInvoice(Long invoiceId, List<Integer> itemIdsToAdd, BasketInvoiceItemsRepository biir, int userId, jakarta.servlet.http.HttpServletRequest request)
      Adds or increments selected products in an existing invoice.
      Parameters:
      invoiceId - target invoice identifier
      itemIdsToAdd - product document identifiers to add
      biir - invoice item repository
      userId - identifier of the user modifying the invoice
      request - current request used to resolve product prices