Package my.edu.tarc.dco.bookrentalpos
Class TransactionManager
public class TransactionManager extends Manager<Transaction>
Used to load all transactions from the database
- Version:
- 1.0
- Author:
- Looz
-
Field Summary
Fields Modifier and Type Field Description HashMap<Integer,Integer>DEPOSIT_RATESContains the rates for the deposit to pay for customer HashMap keys: rentalWeeks HashMap values: rates in % If more than 4 weeks, max % appliesintMAXIMUM_RENT_PER_MEMBERintMEMBER_POINTS_NEEDED_TO_CLAIM_DISCOUNTThis variable is storing the members points needed to apply discountintPENALTY_RATESDeposit deduction for each day the customer is late in returning the book -
Constructor Summary
Constructors Constructor Description TransactionManager(DBManager db, BookManager bm, MemberManager mm) -
Method Summary
Modifier and Type Method Description booleanadd(Transaction trans)this function accepts transaction object where there is no id and date`RentTransactiongetBookLastRentTransaction(Book bk)This function returns transaction of the last renting record of a specific bookTransactiongetBookLastReservedTransaction(Book bk)This function returns Transaction of the last reserve record of a specific bookTransactiongetById(int id)get Transaction by IDTransactiongetByName(String name)Not implemented
Reason: Transaction do not use the name fieldTransaction[]getCache()Get a cache of the transaction list
Note: for the count of data you should get it from TransactionManager.getTransactionCount()ArrayList<Book>getMemberActiveReservations(Member mem)This function return an array list of books currently reserved by this memberArrayList<Transaction>getTransactionByDate(Date startDate, Date endDate)This function returns an array list of transactions between specified date rangeArrayList<Transaction>getTransactionByStaff(Staff staff, Date startDate, Date endDate)This function returns an array list of transactions for specific staff IDintgetTransactionCount()ArrayList<Transaction>getTransactionsByMember(Member memID)This function returns an array list of transactions for specific member idArrayList<Transaction>getTransactionsByMember(Member mem, Date startDate, Date endDate)This function have the same behavior as getTransactionsByMemberID(int) except it accepts startDate and endDate filtervoidreload()Reload all the data from databasebooleanremove(Transaction trans)Remove transaction of specific trans from databasebooleanupdate(Transaction ref)Update transaction table in databasevoidupdateBookReservationStatus()This function is suppose to update the reservation status of all the books
Criteria as stated below:
- If the book is not reserved, dont touch it
- If the book is reserved, check if the book is being rented at the moment
- If the book is rented, dont touch it
- If the book is not rented, or in other words it was returned, check if (return date - current date) > 7 days
- If > 7 days, set reserved status as false
- If !(> 7 days), dont touch it
-
Field Details
-
DEPOSIT_RATES
Contains the rates for the deposit to pay for customer HashMap keys: rentalWeeks HashMap values: rates in % If more than 4 weeks, max % applies -
MEMBER_POINTS_NEEDED_TO_CLAIM_DISCOUNT
public final int MEMBER_POINTS_NEEDED_TO_CLAIM_DISCOUNTThis variable is storing the members points needed to apply discount- See Also:
- Constant Field Values
-
PENALTY_RATES
public final int PENALTY_RATESDeposit deduction for each day the customer is late in returning the book- See Also:
- Constant Field Values
-
MAXIMUM_RENT_PER_MEMBER
public final int MAXIMUM_RENT_PER_MEMBER- See Also:
- Constant Field Values
-
-
Constructor Details
-
Method Details
-
reload
public void reload()Reload all the data from database- Specified by:
reloadin classManager<Transaction>
-
add
this function accepts transaction object where there is no id and date`- Specified by:
addin classManager<Transaction>- Parameters:
trans- accept Transaction object- Returns:
- Return true if the transaction was added into database successfully
-
getById
get Transaction by ID- Specified by:
getByIdin classManager<Transaction>- Parameters:
id- Transaction ID- Returns:
- Transaction reference object if found, null if nothing was found
-
getCache
Get a cache of the transaction list
Note: for the count of data you should get it from TransactionManager.getTransactionCount()- Specified by:
getCachein classManager<Transaction>- Returns:
- an copy of Transaction list array
- See Also:
getTransactionCount()
-
update
Update transaction table in database- Specified by:
updatein classManager<Transaction>- Parameters:
ref- Transaction reference object preferably from Transaction.getById- Returns:
- true if update was successful, false if otherwise
- See Also:
getById(int)
-
remove
Remove transaction of specific trans from database- Specified by:
removein classManager<Transaction>- Parameters:
trans- transaction trans- Returns:
- true if it was removed successfully, false if otherwise
-
updateBookReservationStatus
public void updateBookReservationStatus()This function is suppose to update the reservation status of all the books
Criteria as stated below:
- If the book is not reserved, dont touch it
- If the book is reserved, check if the book is being rented at the moment
- If the book is rented, dont touch it
- If the book is not rented, or in other words it was returned, check if (return date - current date) > 7 days
- If > 7 days, set reserved status as false
- If !(> 7 days), dont touch it -
getBookLastRentTransaction
This function returns transaction of the last renting record of a specific book- Parameters:
bk- book object to be checked- Returns:
- Transaction reference object to the last renting record, return null if book is null or the book is not currently rented
-
getBookLastReservedTransaction
This function returns Transaction of the last reserve record of a specific book- Parameters:
bk- book object to be checked- Returns:
- Transaction reference object to the last reserve record, return null if book is null or the book is not reserved
-
getMemberActiveReservations
This function return an array list of books currently reserved by this member- Parameters:
mem- member object- Returns:
- an arraylist of book reference from BookManager
-
getTransactionsByMember
This function returns an array list of transactions for specific member id- Parameters:
memID- member id- Returns:
- an array list of reference to transactions
-
getTransactionsByMember
This function have the same behavior as getTransactionsByMemberID(int) except it accepts startDate and endDate filter- Parameters:
mem- member objectstartDate- date filter to filter out record before this dateendDate- date filter to filter out record after this date- Returns:
- an array list of reference to transactions
- See Also:
getTransactionsByMember(Member)
-
getTransactionByStaff
This function returns an array list of transactions for specific staff ID- Parameters:
staff- staff ObjectstartDate- add filter to the records by specifying start dateendDate- add filter to the records by specifying end date- Returns:
- an array list of transactions
-
getTransactionByDate
This function returns an array list of transactions between specified date range- Parameters:
startDate- add filter to the records by specifying start dateendDate- add filter to the records by specifying end date- Returns:
- an arraylist of transaction
-
getTransactionCount
public int getTransactionCount()- Returns:
- transaction count loaded from database
-
getByName
Not implemented
Reason: Transaction do not use the name field- Specified by:
getByNamein classManager<Transaction>- Parameters:
name- Not implemented- Returns:
- null
-