java.lang.Object
jku.se.Invoice
Represents an invoice submitted by a user, including metadata, validation logic, and OCR support.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
approve()
Marks the invoice as approved.double
Calculates the actual refund based on category rules and invoice amount.void
Updates the invoice with new values and sets it back to processing status.void
declined()
Marks the invoice as declined.double
Returns the category of the invoice as a string.Returns the formatted creation date (dd.MM.yyyy).getDate()
double
Returns the status of the invoice as a string.boolean
isDateOnWeekday
(LocalDate date) Checks if the given date is a weekday.boolean
Checks if the invoice can be edited (same month and year as current).boolean
isInCurrentMonth
(LocalDate date, LocalDate now) Checks whether the invoice date is in the current month and year.boolean
isValidAmount
(double amount) Validates that the invoice amount is within acceptable limits (0–1000).void
setAmount
(double amount) void
setAnomalyDetected
(boolean anomalyDetected) Indicates whether an anomaly (mismatch) has been detected.void
setCategory
(Category category) void
void
setFileUrl
(String fileUrl) void
setOcrData
(String date, String amount, String category) Sets the OCR result data for this invoice.void
setReimbursement
(double reimbursement) void
toString()
Returns a string representation of the invoice for UI display.validateDate
(LocalDate date) Validates the invoice date (must be a weekday).static void
validateFile
(File file) Validates the uploaded file (existence, format, size).
-
Field Details
-
ocrDate
-
ocrAmount
-
ocrCategory
-
-
Constructor Details
-
Invoice
public Invoice(String userEmail, LocalDate date, double amount, Category category, Status status, String fileUrl, LocalDateTime createdAt, double reimbursement) Constructs a new Invoice.- Parameters:
userEmail
- The email address of the user who submitted the invoice.date
- The date of the invoice.amount
- The amount of the invoice.category
- The invoice category (RESTAURANT or SUPERMARKET).status
- The invoice processing status.fileUrl
- URL to the uploaded invoice image.createdAt
- Timestamp when the invoice was submitted.reimbursement
- The refund amount to be granted.
-
-
Method Details
-
validateDate
Validates the invoice date (must be a weekday).- Parameters:
date
- The date to validate.- Returns:
- The same date if valid.
- Throws:
IllegalArgumentException
- if the date falls on a weekend.
-
validateFile
Validates the uploaded file (existence, format, size).- Parameters:
file
- The file to check.- Throws:
IllegalArgumentException
- if validation fails.
-
getUserEmail
-
getAmount
public double getAmount() -
setAmount
public void setAmount(double amount) -
getCategory
-
setCategory
-
setFileUrl
-
setDate
-
getDate
-
getFileUrl
-
getCreatedAt
-
getReimbursement
public double getReimbursement() -
setReimbursement
public void setReimbursement(double reimbursement) -
setStatus
-
getStatus
-
getCreatedAtString
Returns the formatted creation date (dd.MM.yyyy).- Returns:
- Formatted string.
-
calculateRefund
public double calculateRefund()Calculates the actual refund based on category rules and invoice amount.- Returns:
- Refund amount.
-
getStatusString
Returns the status of the invoice as a string. (used in tables) -
getCategoryString
Returns the category of the invoice as a string. (used in tables) -
approve
public void approve()Marks the invoice as approved. -
declined
public void declined()Marks the invoice as declined. -
correct
Updates the invoice with new values and sets it back to processing status.- Parameters:
newAmount
- New invoice amount.newCategory
- New category.newDate
- New invoice date.
-
isEditable
public boolean isEditable()Checks if the invoice can be edited (same month and year as current).- Returns:
- true if editable, otherwise false.
-
isDateOnWeekday
Checks if the given date is a weekday. -
isInCurrentMonth
Checks whether the invoice date is in the current month and year. -
isValidAmount
public boolean isValidAmount(double amount) Validates that the invoice amount is within acceptable limits (0–1000). -
setOcrData
Sets the OCR result data for this invoice. -
setAnomalyDetected
public void setAnomalyDetected(boolean anomalyDetected) Indicates whether an anomaly (mismatch) has been detected. -
toString
Returns a string representation of the invoice for UI display.
-