Skip to content
This repository has been archived by the owner on Jun 4, 2022. It is now read-only.

Commit

Permalink
finish portals
Browse files Browse the repository at this point in the history
  • Loading branch information
L23de committed May 4, 2022
1 parent 6481e27 commit 17eddb6
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 17 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,25 @@ The following schemas were generated using the aid of [Mockaroo](https://www.moc
- Renter Info - `https://api.mockaroo.com/api/bce9b270`
- Venmo - `https://api.mockaroo.com/api/5d5a4450`

### Test Data


> Note: Not all mock data has been updated. Some of the data values were manually converted to use PL/SQL Procedures/Functions once they were implemented
## Functions

- Resident Portal (Requires sign-in with a valid resident ID (Person with a lease))
- My Info - Displays personal information about the resident
- Make Payment - View upcoming payments and pay for them
- My Lease Details - View details about their lease and their personal information

- Management Portal

### Assumptions

-


## Dev Notes

- When a user logins to the system, the system should automatically create a view for that user that only represents the info that they can see. All queries will be used on that
78 changes: 74 additions & 4 deletions numa/src/main/java/numa/Portals/ManagementPortal.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import java.sql.Types;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

import numa.Reader;
import numa.Exceptions.*;
Expand All @@ -29,9 +32,9 @@ public ManagementPortal(Connection conn, Reader input) throws IOException, ExitE
System.out.println("-----------------\n");

// Get management login
// if (!getManagerLogin()) {
// return;
// }
if (!getManagerLogin()) {
return;
}

System.out.println("[1] Properties");
System.out.println("[2] People");
Expand Down Expand Up @@ -211,11 +214,78 @@ private void people() throws IOException, ExitException, MenuException, SQLExcep
switch (choice) {
case 1: Person.searchName(conn, input, true); break;
case 2: Person.searchId(conn, input); break;

}
}

private void lease() throws IOException, ExitException, SQLException, MenuException, TooManyTriesException {
System.out.println("[1] New Lease Registration");
System.out.println("[2] Modify Existing Lease Term");
System.out.println();

int choice = -1;
while (choice == -1) {
choice = input.getMenuInt("Option [1-2]: ");
if (choice == 1 || choice == 2) break;
}

switch (choice) {
case 1: leaseReg(); break;
case 2: modifyTerm(); break;
}
}

private void modifyTerm() throws IOException, ExitException, MenuException, TooManyTriesException, SQLException {
System.out.println("Modify Term Length:");
System.out.println();
boolean valid = false;

while (!valid) {
try (
PreparedStatement getLeaseBasics = conn.prepareStatement("select street_name, apt, city, state, zipcode, start_date, ADD_MONTHS(start_date, term_length) as end_date, term_length from lease join property on lease.prop_id = property.id where lease.id = ?");
PreparedStatement modifyLength = conn.prepareStatement("UPDATE lease SET term_length = ? WHERE id = ?");
) {
int lid = input.getMenuInt("Lease ID: ");
getLeaseBasics.setInt(1, lid);
ResultSet leaseDetails = getLeaseBasics.executeQuery();

if (leaseDetails.next()) {
valid = true;
String street = leaseDetails.getString("street_name");
String apt = leaseDetails.getString("apt");
String city = leaseDetails.getString("city");
String state = leaseDetails.getString("state");
String zip = leaseDetails.getString("zipcode");
Timestamp start = leaseDetails.getTimestamp("start_date");
Timestamp end = leaseDetails.getTimestamp("end_date");
int length = leaseDetails.getInt("term_length");

SimpleDateFormat dateFmt = new SimpleDateFormat("MM/dd/yyyy");
int monthDiffNow = getMonths(start, new Date());

System.out.format("Modify Lease %d:\n", lid);
System.out.format("%s %s %s %s %s\n(%d Month Lease: %s - %s)", street, apt, city, state, zip, length, dateFmt.format(start), dateFmt.format(end));
System.out.println();

int change = input.getMenuInt("# of months to change to: ");
while (change <= monthDiffNow) {
System.out.println("Invalid input, # of months must be greater than " + monthDiffNow);
}

modifyLength.setInt(1, change);
modifyLength.setInt(2, lid);
modifyLength.execute();

conn.commit();

System.out.println("Successfully modified lease");
} else {
System.out.println("Invalid lease ID. Please try again");
}
}
}
}

private void leaseReg() throws IOException, ExitException, SQLException, MenuException, TooManyTriesException {
System.out.println("New Lease Registration:");
System.out.println();
String first = input.getPrompt("First Name: ");
Expand Down
17 changes: 17 additions & 0 deletions numa/src/main/java/numa/Portals/Portal.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package numa.Portals;

import java.io.IOException;
import java.sql.SQLException;
import java.util.Date;
import java.util.Calendar;
import java.util.GregorianCalendar;

import numa.Reader;
import numa.Exceptions.*;
Expand Down Expand Up @@ -30,4 +34,17 @@ public void sessionReset(Reader input) throws IOException, ExitException, MenuEx
while (true)
input.getMenuLine("Enter 'm' to return to the main menu or 'q' to quit the program: ");
}

public int getMonths(Date start, Date end) throws SQLException {
Calendar startTime = new GregorianCalendar();
Calendar endTime = new GregorianCalendar();

startTime.setTime(start);
endTime.setTime(end);

int yearDiff = endTime.get(Calendar.YEAR) - startTime.get(Calendar.YEAR);
int monthDiff = endTime.get(Calendar.MONTH) - startTime.get(Calendar.MONTH);

return yearDiff * 12 + monthDiff;
}
}
13 changes: 0 additions & 13 deletions numa/src/main/java/numa/Portals/ResidentPortal.java
Original file line number Diff line number Diff line change
Expand Up @@ -435,19 +435,6 @@ public void viewAptDetails() throws SQLException {
}
}

public int getMonths(Date start, Date end) throws SQLException {
Calendar startTime = new GregorianCalendar();
Calendar endTime = new GregorianCalendar();

startTime.setTime(start);
endTime.setTime(end);

int yearDiff = endTime.get(Calendar.YEAR) - startTime.get(Calendar.YEAR);
int monthDiff = endTime.get(Calendar.MONTH) - startTime.get(Calendar.MONTH);

return yearDiff * 12 + monthDiff;
}

public void changeDefaultPayment(ArrayList<Integer> payIds) throws SQLException, IOException, MenuException, ExitException, TooManyTriesException {
while (true) {

Expand Down

0 comments on commit 17eddb6

Please sign in to comment.