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

Commit

Permalink
add queries for each transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
L23de committed Apr 20, 2022
1 parent 0db19b8 commit f7a89a5
Show file tree
Hide file tree
Showing 17 changed files with 400 additions and 128 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CREATE OR REPLACE PROCEDURE add_pet_lease (
CREATE OR REPLACE PROCEDURE add_pet (
animal pet.animal%type,
pet_name pet.pet_name%type,
lease_id lease.id%type
Expand Down
23 changes: 23 additions & 0 deletions db/procedures/make_payment.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
CREATE OR REPLACE PROCEDURE make_payment (
amen_id IN amenity_payment.amenity_id%type,
lease_id IN lease_payment.lease_id%type,
pay_method IN payment_method.id%type,
pay_amt IN amenity_payment.pay_amt%type,
payer IN person.id%type,
memo IN amenity_payment.memo%type,
ret OUT NUMBER
)
IS
BEGIN
IF amen_id <> -1 THEN
INSERT INTO amenity_payment(date_paid, pay_method_id, pay_amt, payer, memo)
VALUES(DEFAULT, pay_method, pay_amt, payer, memo);
ret := 0;
ELSIF lease_id <> -1 THEN
INSERT INTO lease_payment(date_paid, pay_method_id, pay_amt, payer, memo)
VALUES(DEFAULT, pay_method, pay_amt, payer, memo);
ret := 0;
ELSE
ret := 1;
END IF;
END;
32 changes: 32 additions & 0 deletions db/procedures/sign_lease.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
CREATE OR REPLACE PROCEDURE sign_lease (
personId IN payment_method.person_id%type,
propId IN lease.prop_id%type,
apt IN lease.apt%type,
termLength IN lease.term_length%type,
amt OUT number,
valid OUT number,
success OUT number
) IS
rent_amount lease.rent_amount%type;
lease_id lease.id%type;
BEGIN
-- Ensures that the lease does not exist the same time as another
SELECT COUNT(*) into amt from lease where prop_id = propId and apt=apt and CURRENT_TIMESTAMP <= ADD_MONTHS(start_date, term_length);
-- Ensures that the apartment is a valid apartment
SELECT COUNT(*) into valid from apartment where prop_id = propId and apt = apt;

IF amt <> 0 THEN
success := -1;
return;
ELSIF valid <> 0 THEN
success := -2;
return;
END IF;

SELECT RENT into rent_amount from apartment where prop_id = propId and apt = apt;
INSERT INTO lease(prop_id, apt, start_date, term_length, rent_amount) VALUES(propId, apt, CURRENT_TIMESTAMP, termLength, rent_amount);
SELECT MAX(id) into lease_id from lease;
INSERT INTO person_on_lease VALUES(lease_id, personId);
success := 0;
END;

1 change: 1 addition & 0 deletions db/queries/check_resident.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT COUNT(*) FROM renter_info where person_id = ?;
19 changes: 19 additions & 0 deletions db/queries/view_amenity_to_pay.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
-- The prop_id and apt fields should come from the Java program, first ensuring that it is a valid apartment (Lease is still alive), view_lease_to_pay should be run before this.

-- Selecting prop amenities to pay for
SELECT amenity.id, amenity, cost
FROM
(amenity left outer join amenity_payment on amenity.id = amenity_payment.amenity_id)
join prop_amenity on amenity.prop_amenity_id = prop_amenity.id
WHERE
prop_id = ? and
(TO_CHAR(date_paid, 'YYYYMM') = TO_CHAR(CURRENT_TIMESTAMP, 'YYYYMM') or TO_CHAR(date_paid, 'YYYYMM') is null);

-- Selecting apt amenities to pay for
SELECT amenity.id, amenity, cost
FROM
(amenity left outer join amenity_payment on amenity.id = amenity_payment.amenity_id)
join apt_amenity on amenity.apt_amenity_id = apt_amenity.id
WHERE
prop_id = ? and apt = ?
(TO_CHAR(date_paid, 'YYYYMM') = TO_CHAR(CURRENT_TIMESTAMP, 'YYYYMM') or TO_CHAR(date_paid, 'YYYYMM') is null);
39 changes: 39 additions & 0 deletions db/queries/view_lease_info.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
-- By Lease ID
select
prop_id,
street_name,
apt,
city,
state,
zipcode,
square_footage,
bed_count,
bath_count,
start_date,
term_length,
rent
from (lease join apartment on lease.prop_id = apartment.prop_id and lease.apt = apartment.apt) join property on lease.prop_id = property.id;


-- Get Prop Amenities
select amenity, cost
from prop_amenity
where prop_id = ?;


-- Get Apt Amenities
select amenity, cost
from apt_amenity
where prop_id = ? and apt = ?;


-- Get Roommates
select first_name, last_name
from person_on_lease join person on person_on_lease.person_id = person.id
where lease_id = ? and person_id <> ?;


-- Get Pets
select animal, pet_name
from pet_on_lease join pet on pet_on_lease.pet_id = pet.id
where lease_id = ?;
8 changes: 8 additions & 0 deletions db/queries/view_lease_to_pay.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- Select leases that are still active
SELECT id, prop_id, apt, start_date, term_length, rent_amount
FROM lease left outer join lease_payment on lease.id = lease_payment.lease_id
WHERE id in (SELECT lease_id from person_on_lease where person_id = 8) and
TO_CHAR(ADD_MONTHS(start_date, term_length), 'YYYYMM') >= TO_CHAR(CURRENT_TIMESTAMP, 'YYYYMM') and
(TO_CHAR(date_paid, 'YYYYMM') = TO_CHAR(CURRENT_TIMESTAMP, 'YYYYMM') or TO_CHAR(date_paid, 'YYYYMM') is null);
-- End date of the lease is past today's date
-- Payment has already been made for the month or first payment is due
14 changes: 14 additions & 0 deletions db/queries/view_payment_methods.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-- Venmo Given Person ID
select payment_method.id, handle
from payment_method join venmo on venmo_id = venmo.id
where person_id = ?;

-- ACH Given Person ID
select payment_method.id, bank_name, acct_num, routing_num
from payment_method join ach on ach_id = ach.id
where person_id = ?;

-- Card Given Person ID
select payment_method.id, first_name, last_name, card_num, exp_date, cvv, pin
from payment_method join pay_card on card_id = pay_card.id
where person_id = ?;
58 changes: 58 additions & 0 deletions db/queries/view_person_info.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
-- Given Person ID
select
person.id as id,
first_name || ' ' || last_name as name,
ssn,
age,
phone_number,
email,
credit_score,
apt,
lease_id
from
(((person
left outer join renter_info on renter_info.person_id = person.id)
natural left outer join person_on_lease)
left outer join lease on lease_id = lease.id)
natural left outer join apartment
where person.id = ?;


-- Given First/Last Name
select
person.id as id,
first_name || ' ' || last_name as name,
ssn,
age,
phone_number,
email,
credit_score,
apt,
lease_id
from
(((person
left outer join renter_info on renter_info.person_id = person.id)
natural left outer join person_on_lease)
left outer join lease on lease_id = lease.id)
natural left outer join apartment
where first_name = ? or last_name = ?;


-- Given First Name ONLY
select
person.id as id,
first_name || ' ' || last_name as name,
ssn,
age,
phone_number,
email,
credit_score,
apt,
lease_id
from
(((person
left outer join renter_info on renter_info.person_id = person.id)
natural left outer join person_on_lease)
left outer join lease on lease_id = lease.id)
natural left outer join apartment
where first_name = ?;
15 changes: 2 additions & 13 deletions db/setup.sql
Original file line number Diff line number Diff line change
Expand Up @@ -154,20 +154,9 @@ CREATE TABLE visited (
FOREIGN KEY(prop_id, apt) REFERENCES apartment(prop_id, apt) ON DELETE CASCADE
);

CREATE TABLE prev_addr (
person_id NUMBER,
street_name VARCHAR2(255),
city VARCHAR2(255) NOT NULL,
state CHAR(2) NOT NULL
CHECK (state like '__'),
zipcode CHAR(5),
PRIMARY KEY(person_id, street_name, zipcode),
FOREIGN KEY(person_id) REFERENCES person(id) ON DELETE CASCADE
);

CREATE TABLE renter_info (
person_id NUMBER,
ssn CHAR(11)
ssn CHAR(11) UNIQUE
CHECK (REGEXP_LIKE(ssn, '\d{3}-\d{2}-\d{4}')),
preferred_payment NUMBER NOT NULL,
PRIMARY KEY(person_id),
Expand All @@ -182,7 +171,7 @@ CREATE TABLE lease (
id NUMBER GENERATED ALWAYS AS IDENTITY,
prop_id NUMBER NOT NULL,
apt VARCHAR2(5) NOT NULL,
start_date DATE NOT NULL,
start_date DATE DEFAULT CURRENT_TIMESTAMP,
term_length NUMBER NOT NULL,
rent_amount NUMBER NOT NULL,
PRIMARY KEY(id),
Expand Down
13 changes: 6 additions & 7 deletions numa/src/main/java/numa/NUMA.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,12 @@ public static void main (String[] args) throws IOException {
System.out.println("Enter 'm' to return here and 'q' to quit the program at any time\n");
System.out.println("[1] Resident Portal");
System.out.println("[2] Management Portal");
System.out.println("[3] Shareholder Disclosures\n");
// System.out.println("[3] Shareholder Disclosures\n");

Boolean portalEntered = false;
while (!portalEntered) {
System.out.print("Portal #: ");
try {
String portalChoice = input.getMenuLine();
String portalChoice = input.getMenuLine("Portal #: ");

switch(portalChoice) {
case "1":
Expand All @@ -64,10 +63,10 @@ public static void main (String[] args) throws IOException {
new ManagementPortal(conn, input);
portalEntered = true;
break;
case "3":
new ShareholderPortal(conn, input);
portalEntered = true;
break;
// case "3":
// new ShareholderPortal(conn, input);
// portalEntered = true;
// break;
default:
System.out.println("Invalid input, please only enter numbers 1 - 3\n");
}
Expand Down
Loading

0 comments on commit f7a89a5

Please sign in to comment.