Package backend.logic

Klasse ReimbursementService


public class ReimbursementService extends ReimbursementHistoryController
The ReimbursementService class provides core business logic for managing reimbursement operations within the Lunchify application.

This includes:

  • Inserting and updating reimbursement records
  • Modifying category limits
  • Filtering and retrieving reimbursement histories
  • Approving or rejecting reimbursements
  • Integration with notification and user services

It interacts with the database using JDBC and assumes a PostgreSQL backend. A static ConnectionProvider must be set before operations are performed.

Note: This class also extends ReimbursementHistoryController to inherit common filtering logic and UI-relevant behaviors.

  • Felddetails

  • Konstruktordetails

    • ReimbursementService

      public ReimbursementService()
      default Constructor
      initially loads limits from DB, so that they are always upToDate
    • ReimbursementService

      public ReimbursementService(User user)
      Constructor with User
      initially loads limits from DB, so that they are always upToDate
  • Methodendetails

    • setConnectionProvider

      public static void setConnectionProvider(ConnectionProvider provider)
      secures DatabaseConnection
    • getSelectedUser

      public User getSelectedUser()
      getter Method for User
      Gibt zurück:
      User which is selected in the process
    • getReimbursementAmount

      public float getReimbursementAmount()
      getter Method for reimbursementAmount
      Gibt zurück:
      float for this reimbursement
    • getLimit

      public float getLimit(InvoiceCategory category)
      Returns the reimbursement limit based on invoice category.
      Parameter:
      category - the invoice category
      Gibt zurück:
      the applicable limit
    • setReimbursementAmount

      public void setReimbursementAmount(float amount)
      Sets the reimbursement amount manually.
      Parameter:
      amount - reimbursement amount
    • setSelectedUser

      public void setSelectedUser(User selectedUser)
      Sets the selected user (for admin actions).
      Parameter:
      selectedUser - the user to select
    • addReimbursement

      public boolean addReimbursement(Invoice invoice, float amount)
      Adds a new reimbursement entry for a given invoice.
      Parameter:
      invoice - the invoice to reimburse
      amount - approved reimbursement amount
      Gibt zurück:
      true if successful, false otherwise
      Löst aus:
      InfrastructureException - if no ConnectionProvider is set
    • isValidFloat

      public boolean isValidFloat(String text)
      Validates whether a given string can be interpreted as a float.
      Parameter:
      text - the input string
      Gibt zurück:
      true if valid float, false otherwise
    • isAmountValid

      public boolean isAmountValid(String text)
      Checks whether the given string is a valid float representing an amount.
      Parameter:
      text - the input amount string
      Gibt zurück:
      true if valid, false otherwise
    • modifyLimits

      public boolean modifyLimits(InvoiceCategory category, float newLimit)
      Updates the reimbursement limit for a given category.
      Parameter:
      category - the invoice category
      newLimit - the new limit
      Gibt zurück:
      true if updated successfully, false otherwise
    • getReimbursements

      public List<Reimbursement> getReimbursements(String condition, int userId)
      Returns a List of Reimbursements having a certain condition
      Parameter:
      condition - used in the Where-Statement in SELECT
      userId - could be used as int in WHERE
      Gibt zurück:
      List of Reimbursements
    • getCurrentReimbursements

      public List<Reimbursement> getCurrentReimbursements(int userId)
      returns a List of Reimbursements of Current Month
      Parameter:
      userId - the ID of a User
      Gibt zurück:
      List of Reimbursements
    • getAllReimbursements

      public List<Reimbursement> getAllReimbursements(int userId)
      returns a List of All Reimbursements of a certain user
      Parameter:
      userId - the ID of a User
      Gibt zurück:
      List of Reimbursements
    • getAllReimbursements

      public List<Reimbursement> getAllReimbursements(String condition)
      returns a List of All Reimbursements
      Gibt zurück:
      List of Reimbursements
    • getFilteredReimbursements

      public List<Reimbursement> getFilteredReimbursements(String selectedMonth, String selectedYear, String selectedCategory, String selectedStatus, int userId)
      returns a List of Reimbursements, used for filtering
      Parameter:
      selectedMonth - the selected Month, String
      selectedYear - the selected Year, String
      selectedCategory - the selected Category, String
      selectedStatus - the selected Status, String
      userId - the current User, int
      Gibt zurück:
      List of Reimbursements
    • getTotalReimbursement

      public float getTotalReimbursement(List<Reimbursement> reimb)
      Calculates the sum of approved Amount of Reimbursements
      Parameter:
      reimb - a List of Reimbursements
      Gibt zurück:
      float sum of all Approved Amounts
    • getTotalReimbursement

      public float getTotalReimbursement(List<Reimbursement> reimb, ReimbursementState state)
      Calculates the sum Amount of Reimbursements with a certain state
      Parameter:
      reimb - a List of Reimbursements
      state - a ReimbursementState, could be "Rejected" or "Pending"
      Gibt zurück:
      float sum of all Amounts with a certain state
    • convertMonthToNumber

      public String convertMonthToNumber(String month)
      Converts a Month to a number
      Parameter:
      month - String Month
      Gibt zurück:
      String "1" for "jänner", "2" for "februar" ...
    • getInfoText

      public String getInfoText()
      Builds the info-Text for Reimbursement Service
      Gibt zurück:
      String for "just one per day." or "maximum per day".
    • updateReimbursementIfChanged

      public boolean updateReimbursementIfChanged(Reimbursement oldReimb, Reimbursement newReimb, User reimbUser, boolean selfmade)
      Checks, if a Reimbursment changed, and if yes, Updates its in Database
      Parameter:
      oldReimb - the old Reimbursement
      newReimb - the new Reimbursement
      reimbUser - User, whose Reimbursement it is
      selfmade - true if User changed by himself, false if not (eg. Admin changed for him/her)
      Gibt zurück:
      boolean - true if updated, false if not updated
    • deleteReimbursement

      public boolean deleteReimbursement(Reimbursement toDeleteReimb, User reimbUser, boolean selfmade)
      Deletes Reimbursement on Database
      Parameter:
      toDeleteReimb - the Reimbursement to delete
      reimbUser - the User whose Reimbursement is to delete
      selfmade - true if User changed by himself, false if not (eg. Admin changed for him/her)
      Gibt zurück:
      boolean - true if deleted, false if not deleted
    • approveReimbursement

      public boolean approveReimbursement(Reimbursement toApproveReimb, User reimbUser, boolean selfmade)
      Sets a Reimbursement to State Approved
      Parameter:
      toApproveReimb - the Reimbursement that should be set to approved
      reimbUser - the User whose Reimbursement that should be set to approved
      selfmade - true if User changed by himself, false if not (eg. Admin changed for him/her)
      Gibt zurück:
      boolean - true if approved, false if not approved
    • rejectReimbursement

      public boolean rejectReimbursement(Reimbursement toRejectReimb, User reimbUser, boolean selfmade)
      Sets a Reimbursement to State Rejected
      Parameter:
      toRejectReimb - the Reimbursement that should be set to rejected
      reimbUser - the User whose Reimbursement that should be set to rejected
      selfmade - true if User changed by himself, false if not (eg. Admin changed for him/her)
      Gibt zurück:
      boolean - true if rejected, false if not rejected
    • getReimbursementByInvoiceId

      public static Reimbursement getReimbursementByInvoiceId(int invoiceId)
      looks up a Reimbursement by an invoiceID
      Parameter:
      invoiceId - int invoiceID
      Gibt zurück:
      Reimbursment which invoiceID fits
    • getAllReimbursements

      public List<Reimbursement> getAllReimbursements(int month, int year)
      gets all Reimbursements for a certain month and year
      Parameter:
      month - int Month
      year - int year
      Gibt zurück:
      a List of Reimbursements