Package backend.logic
Klasse ReimbursementService
java.lang.Object
frontend.controller.ReimbursementHistoryController
backend.logic.ReimbursementService
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.
-
Feldübersicht
Felder -
Konstruktorübersicht
KonstruktorenKonstruktorBeschreibungdefault Constructor initially loads limits from DB, so that they are always upToDateReimbursementService
(User user) Constructor with User initially loads limits from DB, so that they are always upToDate -
Methodenübersicht
Modifizierer und TypMethodeBeschreibungboolean
addReimbursement
(Invoice invoice, float amount) Adds a new reimbursement entry for a given invoice.boolean
approveReimbursement
(Reimbursement toApproveReimb, User reimbUser, boolean selfmade) Sets a Reimbursement to State ApprovedconvertMonthToNumber
(String month) Converts a Month to a numberboolean
deleteReimbursement
(Reimbursement toDeleteReimb, User reimbUser, boolean selfmade) Deletes Reimbursement on DatabasegetAllReimbursements
(int userId) returns a List of All Reimbursements of a certain usergetAllReimbursements
(int month, int year) gets all Reimbursements for a certain month and yeargetAllReimbursements
(String condition) returns a List of All ReimbursementsgetCurrentReimbursements
(int userId) returns a List of Reimbursements of Current MonthgetFilteredReimbursements
(String selectedMonth, String selectedYear, String selectedCategory, String selectedStatus, int userId) returns a List of Reimbursements, used for filteringBuilds the info-Text for Reimbursement Servicefloat
getLimit
(InvoiceCategory category) Returns the reimbursement limit based on invoice category.float
getter Method for reimbursementAmountstatic Reimbursement
getReimbursementByInvoiceId
(int invoiceId) looks up a Reimbursement by an invoiceIDgetReimbursements
(String condition, int userId) Returns a List of Reimbursements having a certain conditiongetter Method for Userfloat
getTotalReimbursement
(List<Reimbursement> reimb) Calculates the sum of approved Amount of Reimbursementsfloat
getTotalReimbursement
(List<Reimbursement> reimb, ReimbursementState state) Calculates the sum Amount of Reimbursements with a certain stateboolean
isAmountValid
(String text) Checks whether the given string is a valid float representing an amount.boolean
isValidFloat
(String text) Validates whether a given string can be interpreted as a float.boolean
modifyLimits
(InvoiceCategory category, float newLimit) Updates the reimbursement limit for a given category.boolean
rejectReimbursement
(Reimbursement toRejectReimb, User reimbUser, boolean selfmade) Sets a Reimbursement to State Rejectedstatic void
setConnectionProvider
(ConnectionProvider provider) secures DatabaseConnectionvoid
setReimbursementAmount
(float amount) Sets the reimbursement amount manually.void
setSelectedUser
(User selectedUser) Sets the selected user (for admin actions).boolean
updateReimbursementIfChanged
(Reimbursement oldReimb, Reimbursement newReimb, User reimbUser, boolean selfmade) Checks, if a Reimbursment changed, and if yes, Updates its in DatabaseVon Klasse geerbte Methoden frontend.controller.ReimbursementHistoryController
getFilterInput, handlePayrollData, initializeForSelectedUser, loadReimbursementsForUser, setReimbursementService, setUserService, showAlert
-
Felddetails
-
connectionProvider
-
-
Konstruktordetails
-
ReimbursementService
public ReimbursementService()default Constructor initially loads limits from DB, so that they are always upToDate -
ReimbursementService
Constructor with User initially loads limits from DB, so that they are always upToDate
-
-
Methodendetails
-
setConnectionProvider
secures DatabaseConnection -
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
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
Sets the selected user (for admin actions).- Parameter:
selectedUser
- the user to select
-
addReimbursement
Adds a new reimbursement entry for a given invoice.- Parameter:
invoice
- the invoice to reimburseamount
- approved reimbursement amount- Gibt zurück:
- true if successful, false otherwise
- Löst aus:
InfrastructureException
- if noConnectionProvider
is set
-
isValidFloat
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
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
Updates the reimbursement limit for a given category.- Parameter:
category
- the invoice categorynewLimit
- the new limit- Gibt zurück:
- true if updated successfully, false otherwise
-
getReimbursements
Returns a List of Reimbursements having a certain condition- Parameter:
condition
- used in the Where-Statement in SELECTuserId
- could be used as int in WHERE- Gibt zurück:
- List of Reimbursements
-
getCurrentReimbursements
returns a List of Reimbursements of Current Month- Parameter:
userId
- the ID of a User- Gibt zurück:
- List of Reimbursements
-
getAllReimbursements
returns a List of All Reimbursements of a certain user- Parameter:
userId
- the ID of a User- Gibt zurück:
- List of Reimbursements
-
getAllReimbursements
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, StringselectedYear
- the selected Year, StringselectedCategory
- the selected Category, StringselectedStatus
- the selected Status, StringuserId
- the current User, int- Gibt zurück:
- List of Reimbursements
-
getTotalReimbursement
Calculates the sum of approved Amount of Reimbursements- Parameter:
reimb
- a List of Reimbursements- Gibt zurück:
- float sum of all Approved Amounts
-
getTotalReimbursement
Calculates the sum Amount of Reimbursements with a certain state- Parameter:
reimb
- a List of Reimbursementsstate
- a ReimbursementState, could be "Rejected" or "Pending"- Gibt zurück:
- float sum of all Amounts with a certain state
-
convertMonthToNumber
Converts a Month to a number- Parameter:
month
- String Month- Gibt zurück:
- String "1" for "jänner", "2" for "februar" ...
-
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 ReimbursementnewReimb
- the new ReimbursementreimbUser
- User, whose Reimbursement it isselfmade
- 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
Deletes Reimbursement on Database- Parameter:
toDeleteReimb
- the Reimbursement to deletereimbUser
- the User whose Reimbursement is to deleteselfmade
- 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
Sets a Reimbursement to State Approved- Parameter:
toApproveReimb
- the Reimbursement that should be set to approvedreimbUser
- the User whose Reimbursement that should be set to approvedselfmade
- 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
Sets a Reimbursement to State Rejected- Parameter:
toRejectReimb
- the Reimbursement that should be set to rejectedreimbUser
- the User whose Reimbursement that should be set to rejectedselfmade
- 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
looks up a Reimbursement by an invoiceID- Parameter:
invoiceId
- int invoiceID- Gibt zurück:
- Reimbursment which invoiceID fits
-
getAllReimbursements
gets all Reimbursements for a certain month and year- Parameter:
month
- int Monthyear
- int year- Gibt zurück:
- a List of Reimbursements
-