Module Lunchify

Class InvoiceRepository

java.lang.Object
jku.se.repository.InvoiceRepository

public class InvoiceRepository extends Object
Repository class for handling database operations related to invoices. Provides methods to retrieve, update, insert, and delete invoice data.
  • Constructor Details

    • InvoiceRepository

      public InvoiceRepository()
  • Method Details

    • getAllInvoicesAdmin

      public static List<Invoice> getAllInvoicesAdmin()
      Retrieves all invoices from the database.
      Returns:
      List of all invoices.
    • getAllInvoicesUser

      public static List<Invoice> getAllInvoicesUser(String userEmail)
      Retrieves all invoices for a given user.
      Parameters:
      userEmail - Email address of the user.
      Returns:
      List of invoices associated with the user.
    • saveInvoiceInfo

      public static void saveInvoiceInfo(Connection connection, String userEmail, Date date, double amount, Category category, Status status, String fileUrl, LocalDateTime createdAt, double reimbursement, File imageFile)
      Saves a new invoice record in the database and uploads associated file.
      Parameters:
      connection - Database connection.
      userEmail - User email.
      date - Invoice date.
      amount - Invoice amount.
      category - Invoice category.
      status - Invoice status.
      fileUrl - File URL.
      createdAt - Timestamp of creation.
      reimbursement - Reimbursement amount.
      imageFile - File object to upload.
    • invoiceExists

      public static boolean invoiceExists(Connection connection, String userEmail, Date date)
      Checks if an invoice already exists for a user on a given date.
      Parameters:
      connection - Database connection.
      userEmail - Email of the user.
      date - Date to check.
      Returns:
      true if invoice exists, false otherwise.
    • updateInvoiceDate

      public static void updateInvoiceDate(Invoice invoice)
      Updates the invoice date in the database.
      Parameters:
      invoice - Invoice to update.
    • updateInvoiceAmount

      public static void updateInvoiceAmount(Invoice invoice)
      Updates the invoice amount in the database.
      Parameters:
      invoice - Invoice to update.
    • updateInvoiceStatus

      public static void updateInvoiceStatus(Invoice invoice)
      Updates the invoice status in the database.
      Parameters:
      invoice - Invoice to update.
    • updateInvoiceCategory

      public static void updateInvoiceCategory(Invoice invoice)
      Updates the invoice category in the database.
      Parameters:
      invoice - Invoice to update.
    • updateInvoiceReimbursement

      public static void updateInvoiceReimbursement(Invoice invoice)
      Updates the invoice reimbursement value in the database.
      Parameters:
      invoice - Invoice to update.
    • getDeclinedInvoicesCurrentMonth

      public static List<Invoice> getDeclinedInvoicesCurrentMonth(String userEmail)
      Retrieves all declined invoices for a user in the current month.
      Parameters:
      userEmail - Email of the user.
      Returns:
      List of declined invoices.
    • getAcceptedInvoicesCurrentMonth

      public static List<Invoice> getAcceptedInvoicesCurrentMonth(String userEmail)
      Retrieves all accepted invoices for a user in the current month.
      Parameters:
      userEmail - Email of the user.
      Returns:
      List of accepted invoices.
    • updateInvoice

      public static void updateInvoice(Invoice invoice) throws SQLException
      Updates all editable fields of an invoice.
      Parameters:
      invoice - Invoice to update.
      Throws:
      SQLException - if database error occurs.
    • getActiveUsersThisMonth

      public static List<String> getActiveUsersThisMonth() throws SQLException
      Retrieves a list of user emails that have submitted invoices in the current month.
      Returns:
      List of user emails.
      Throws:
      SQLException - if database access fails.
    • getInvoiceCountForUserThisMonth

      public static int getInvoiceCountForUserThisMonth(String userEmail) throws SQLException
      Counts how many invoices a user submitted in the current month.
      Parameters:
      userEmail - User email.
      Returns:
      Number of invoices.
      Throws:
      SQLException - if database access fails.
    • getTotalReimbursementForUserThisMonth

      public static double getTotalReimbursementForUserThisMonth(String userEmail) throws SQLException
      Sums the reimbursement of all invoices for a user in the current month.
      Parameters:
      userEmail - User email.
      Returns:
      Total reimbursement amount.
      Throws:
      SQLException - if database access fails.
    • getTotalReimbursementThisMonth

      public static double getTotalReimbursementThisMonth() throws SQLException
      Sums the reimbursement of all invoices in the current month.
      Returns:
      Total reimbursement amount.
      Throws:
      SQLException - if database access fails.
    • deleteInvoice

      public static void deleteInvoice(Invoice invoice)
      Deletes a specific invoice from the database.
      Parameters:
      invoice - Invoice to delete.