java.lang.Object
jku.se.repository.InvoiceRepository
Repository class for handling database operations related to invoices.
Provides methods to retrieve, update, insert, and delete invoice data.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
deleteInvoice
(Invoice invoice) Deletes a specific invoice from the database.getAcceptedInvoicesCurrentMonth
(String userEmail) Retrieves all accepted invoices for a user in the current month.Retrieves a list of user emails that have submitted invoices in the current month.Retrieves all invoices from the database.getAllInvoicesUser
(String userEmail) Retrieves all invoices for a given user.getDeclinedInvoicesCurrentMonth
(String userEmail) Retrieves all declined invoices for a user in the current month.static int
getInvoiceCountForUserThisMonth
(String userEmail) Counts how many invoices a user submitted in the current month.static double
getTotalReimbursementForUserThisMonth
(String userEmail) Sums the reimbursement of all invoices for a user in the current month.static double
Sums the reimbursement of all invoices in the current month.static boolean
invoiceExists
(Connection connection, String userEmail, Date date) Checks if an invoice already exists for a user on a given date.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.static void
updateInvoice
(Invoice invoice) Updates all editable fields of an invoice.static void
updateInvoiceAmount
(Invoice invoice) Updates the invoice amount in the database.static void
updateInvoiceCategory
(Invoice invoice) Updates the invoice category in the database.static void
updateInvoiceDate
(Invoice invoice) Updates the invoice date in the database.static void
updateInvoiceReimbursement
(Invoice invoice) Updates the invoice reimbursement value in the database.static void
updateInvoiceStatus
(Invoice invoice) Updates the invoice status in the database.
-
Constructor Details
-
InvoiceRepository
public InvoiceRepository()
-
-
Method Details
-
getAllInvoicesAdmin
Retrieves all invoices from the database.- Returns:
- List of all invoices.
-
getAllInvoicesUser
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
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
Updates the invoice date in the database.- Parameters:
invoice
- Invoice to update.
-
updateInvoiceAmount
Updates the invoice amount in the database.- Parameters:
invoice
- Invoice to update.
-
updateInvoiceStatus
Updates the invoice status in the database.- Parameters:
invoice
- Invoice to update.
-
updateInvoiceCategory
Updates the invoice category in the database.- Parameters:
invoice
- Invoice to update.
-
updateInvoiceReimbursement
Updates the invoice reimbursement value in the database.- Parameters:
invoice
- Invoice to update.
-
getDeclinedInvoicesCurrentMonth
Retrieves all declined invoices for a user in the current month.- Parameters:
userEmail
- Email of the user.- Returns:
- List of declined invoices.
-
getAcceptedInvoicesCurrentMonth
Retrieves all accepted invoices for a user in the current month.- Parameters:
userEmail
- Email of the user.- Returns:
- List of accepted invoices.
-
updateInvoice
Updates all editable fields of an invoice.- Parameters:
invoice
- Invoice to update.- Throws:
SQLException
- if database error occurs.
-
getActiveUsersThisMonth
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
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
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
Sums the reimbursement of all invoices in the current month.- Returns:
- Total reimbursement amount.
- Throws:
SQLException
- if database access fails.
-
deleteInvoice
Deletes a specific invoice from the database.- Parameters:
invoice
- Invoice to delete.
-