Module Lunchify
Package jku.se

Class Invoice

java.lang.Object
jku.se.Invoice

public class Invoice extends Object
Represents an invoice submitted by a user, including metadata, validation logic, and OCR support.
  • Field Details

    • ocrDate

      public String ocrDate
    • ocrAmount

      public String ocrAmount
    • ocrCategory

      public String 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

      public LocalDate validateDate(LocalDate date)
      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

      public static void validateFile(File file)
      Validates the uploaded file (existence, format, size).
      Parameters:
      file - The file to check.
      Throws:
      IllegalArgumentException - if validation fails.
    • getUserEmail

      public String getUserEmail()
    • getAmount

      public double getAmount()
    • setAmount

      public void setAmount(double amount)
    • getCategory

      public Category getCategory()
    • setCategory

      public void setCategory(Category category)
    • setFileUrl

      public void setFileUrl(String fileUrl)
    • setDate

      public void setDate(LocalDate date)
    • getDate

      public LocalDate getDate()
    • getFileUrl

      public String getFileUrl()
    • getCreatedAt

      public LocalDateTime getCreatedAt()
    • getReimbursement

      public double getReimbursement()
    • setReimbursement

      public void setReimbursement(double reimbursement)
    • setStatus

      public void setStatus(Status status)
    • getStatus

      public Status getStatus()
    • getCreatedAtString

      public String 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

      public String getStatusString()
      Returns the status of the invoice as a string. (used in tables)
    • getCategoryString

      public String 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

      public void correct(double newAmount, Category newCategory, LocalDate newDate)
      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

      public boolean isDateOnWeekday(LocalDate date)
      Checks if the given date is a weekday.
    • isInCurrentMonth

      public boolean isInCurrentMonth(LocalDate date, LocalDate now)
      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

      public void setOcrData(String date, String amount, String category)
      Sets the OCR result data for this invoice.
    • setAnomalyDetected

      public void setAnomalyDetected(boolean anomalyDetected)
      Indicates whether an anomaly (mismatch) has been detected.
    • toString

      public String toString()
      Returns a string representation of the invoice for UI display.
      Overrides:
      toString in class Object