This repository has been archived by the owner on Jun 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
79 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +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; | ||
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; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
-- Check if a person is a resident or not, used for login | ||
|
||
SELECT COUNT(*) FROM renter_info where person_id = ?; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
-- Used by NUMA to get more details about a certain apartment | ||
|
||
SELECT * | ||
FROM apartment | ||
WHERE prop_id = ?; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
-- Used by NUMA to see all properties | ||
|
||
SELECT * | ||
FROM property; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
-- Used to get aggregate data about the leases | ||
-- Group by prop_id (Avg term length and count of each property) | ||
-- Group by term_length (Total # of tenants with the same term length) | ||
-- Group by prop_id, term_length (Total # of tenants w/ same term length in the same property) | ||
-- Group by nothing (Average term and total tenants) | ||
|
||
SELECT prop_id, avg(term_length), count(person_id) | ||
FROM lease join person_on_lease on lease.id = person_on_lease.lease_id | ||
GROUP BY cube(prop_id, term_length); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
-- Select leases that are still active | ||
-- End date of the lease is past today's date | ||
-- Payment has already been made for the month or first payment is due | ||
|
||
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 | ||
(TO_CHAR(date_paid, 'YYYYMM') = TO_CHAR(CURRENT_TIMESTAMP, 'YYYYMM') or TO_CHAR(date_paid, 'YYYYMM') is null); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
-- Used to register a new person into the NUMA system | ||
-- For the purpose of a new leasee or a new visitor of one of NUMA's properties | ||
|
||
INSERT into person(first_name, last_name, age, phone_number, email, credit_score) | ||
VALUES(?, ?, ?, ?, ?, ?); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
-- Used to update a renter's preferred payment method | ||
|
||
UPDATE renter_info | ||
SET preferred_payment = ? | ||
WHERE person_id = ?; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
-- Used by NUMA to end prematurely or extend a person's lease | ||
|
||
UPDATE lease | ||
SET term_length = ? | ||
WHERE id = ?; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
-- Used by NUMA to register a new visit to a property | ||
|
||
INSERT into visited(person_id, date_visited, prop_id, apt) | ||
VALUES(?, ?, ?, ?); |