Class InvoicesService

java.lang.Object
de.bytestore.hostinger.ecommerce.service.InvoicesService

@Component @Service public class InvoicesService extends Object
  • Constructor Details

    • InvoicesService

      public InvoicesService()
  • Method Details

    • onApplicationStarted

      @EventListener public void onApplicationStarted(org.springframework.boot.context.event.ApplicationStartedEvent event)
    • load

      public void load()
    • getInvoicesByMonth

      public List<Invoice> getInvoicesByMonth()
    • generatePDF

      public void generatePDF(Invoice invoiceIO)
      Generates a PDF for the provided invoice and saves it to a specified location.
      Parameters:
      invoiceIO - the Invoice object for which the PDF will be generated
    • generatePDFStream

      public ByteArrayInputStream generatePDFStream(Invoice invoiceIO)
      Generates a PDF stream for the given invoice. The method takes an Invoice object, generates the corresponding PDF content, and returns it as a ByteArrayOutputStream. If the input invoice is null or does not contain a valid ID, the method will return null. If any exception occurs during the PDF generation process, a RuntimeException will be thrown.
      Parameters:
      invoiceIO - the Invoice object for which the PDF is to be generated; must not be null and must have a valid ID.
      Returns:
      a ByteArrayOutputStream containing the generated PDF content, or null if the input is invalid.
    • generateContent

      public String generateContent(Invoice invoiceIO)
      Generates the content for an invoice by retrieving associated products, calculating totals, and populating a template with the required data.
      Parameters:
      invoiceIO - the invoice object containing details such as the receiver and other metadata
      Returns:
      a string representing the generated content, which is primarily HTML, or an error message in case of issues
    • getProductsCount

      public Integer getProductsCount(Invoice invoice)
      Calculates and returns the total count of products associated with a given invoice.
      Parameters:
      invoice - the Invoice object for which the product count is to be retrieved
      Returns:
      the total count of products for the specified invoice
    • getProductsPrice

      public double getProductsPrice(Invoice invoice)
      Calculates the total price of all products associated with the specified invoice.
      Parameters:
      invoice - the invoice object containing the details of the invoice whose products' total price needs to be calculated
      Returns:
      the total price of all products for the specified invoice
    • exitsInDb

      public boolean exitsInDb(Invoice entity)
      Checks if a given Invoice entity exists in the database.
      Parameters:
      entity - the Invoice entity to check for existence in the database
      Returns:
      true if the Invoice entity exists in the database, false otherwise
    • getProductsFor

      public List<InvoiceProduct> getProductsFor(Invoice entity)
      Retrieves a list of InvoiceProduct entities associated with the given Invoice entity.
      Parameters:
      entity - the Invoice entity for which associated InvoiceProduct entities are to be retrieved
      Returns:
      a list of InvoiceProduct entities associated with the specified Invoice
    • getInvoicePath

      public String getInvoicePath(Invoice invoiceIO)
      Generates the file path for the invoice PDF based on the given invoice object.
      Parameters:
      invoiceIO - the Invoice object from which the file path is derived
      Returns:
      the file path as a String for the invoice PDF
    • webhooks

      public void webhooks()
    • executeCreateWebhook

      public void executeCreateWebhook(io.jmix.core.event.EntitySavingEvent<Invoice> eventIO)
    • executeUpdateWebhook

      public void executeUpdateWebhook(io.jmix.core.event.EntityChangedEvent<Invoice> eventIO)