-
Notifications
You must be signed in to change notification settings - Fork 0
Pirasanth #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Pirasanth #24
Changes from all commits
6553e50
49d6f3a
dc83fc4
45956c0
53e8644
8451d85
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| backend/venv/ | ||
| Backend/venv/ | ||
| Backend/__pycache__/ |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,291 @@ | ||||||||||
| CREATE TABLE branch ( | ||||||||||
| branch_id char(5) PRIMARY KEY, | ||||||||||
| branch_name varchar(30) , | ||||||||||
| location varchar(30), | ||||||||||
| branch_phone_number char(10) , | ||||||||||
| status Boolean | ||||||||||
| ); | ||||||||||
|
|
||||||||||
| CREATE TYPE etype AS ENUM('Agent','Branch Manager','Admin'); | ||||||||||
| CREATE TABLE employee( | ||||||||||
| employee_id char(5) PRIMARY KEY, | ||||||||||
| name varchar(50), | ||||||||||
| nic varchar(12), | ||||||||||
| phone_number char(10), | ||||||||||
| address varchar(255), | ||||||||||
| date_started date, | ||||||||||
| last_login_time timestamp, | ||||||||||
| type etype, | ||||||||||
| status boolean, | ||||||||||
| branch_id char(5) REFERENCES Branch(branch_id) | ||||||||||
| ); | ||||||||||
|
|
||||||||||
| CREATE TABLE token( | ||||||||||
| token_id varchar(128) PRIMARY KEY, | ||||||||||
| token_value varchar(255), | ||||||||||
| created_time timestamp, | ||||||||||
| last_used timestamp, | ||||||||||
| employee_id char(5) REFERENCES Employee(employee_id) | ||||||||||
| ); | ||||||||||
|
|
||||||||||
| CREATE TABLE authentication( | ||||||||||
| username varchar(30) PRIMARY KEY, | ||||||||||
| password varchar(255), | ||||||||||
| type etype, | ||||||||||
| employee_id char(5) REFERENCES Employee(employee_id) | ||||||||||
| ); | ||||||||||
|
|
||||||||||
| CREATE TABLE customer( | ||||||||||
| customer_id char(5) PRIMARY KEY, | ||||||||||
| name varchar(50), | ||||||||||
| nic varchar(12), | ||||||||||
| phone_number char(10), | ||||||||||
| address varchar(255), | ||||||||||
| date_of_birth date, | ||||||||||
| email varchar(255), | ||||||||||
| status boolean, | ||||||||||
| employee_id char(5) REFERENCES Employee(employee_id) | ||||||||||
| ); | ||||||||||
|
|
||||||||||
| CREATE TYPE stype AS ENUM('Children','Teen','Adult','Senior','Joint'); | ||||||||||
| CREATE TABLE savingsaccount_plans( | ||||||||||
| s_plan_id char(5) PRIMARY KEY, | ||||||||||
| plan_name stype, | ||||||||||
| interest_rate numeric(5,2), | ||||||||||
| min_balance numeric(12,2) | ||||||||||
| ); | ||||||||||
|
|
||||||||||
| CREATE TABLE savingsaccount( | ||||||||||
| saving_account_id char(5) PRIMARY KEY, | ||||||||||
| open_date timestamp, | ||||||||||
| balance numeric(12,2), | ||||||||||
| employee_id char(5) REFERENCES Employee(employee_id), | ||||||||||
| s_plan_id char(5) REFERENCES SavingsAccount_Plans(s_plan_id), | ||||||||||
| status boolean, | ||||||||||
| branch_id char(5) REFERENCES Branch(branch_id) | ||||||||||
| ); | ||||||||||
|
|
||||||||||
| CREATE TABLE fixeddeposit_plans( | ||||||||||
| f_plan_id char(5) PRIMARY KEY , | ||||||||||
| months varchar(10), | ||||||||||
| interest_rate numeric(5,2) | ||||||||||
| ); | ||||||||||
|
|
||||||||||
| CREATE TABLE fixeddeposit( | ||||||||||
| fixed_deposit_id char(5) PRIMARY KEY , | ||||||||||
| saving_account_id char(5) REFERENCES SavingsAccount(saving_account_id), | ||||||||||
| f_plan_id char(5) REFERENCES FixedDeposit_Plans(f_plan_id), | ||||||||||
| start_date timestamp, | ||||||||||
| end_date timestamp, | ||||||||||
| principal_amount numeric(12,2), | ||||||||||
| interest_payment_type boolean, | ||||||||||
| last_payout_date timestamp, | ||||||||||
| status boolean | ||||||||||
| ); | ||||||||||
|
|
||||||||||
| CREATE TABLE accountholder( | ||||||||||
| holder_id char(5) PRIMARY KEY, | ||||||||||
| customer_id char(5)REFERENCES Customer(customer_id), | ||||||||||
| saving_account_id char(5) REFERENCES SavingsAccount(saving_account_id) | ||||||||||
| ); | ||||||||||
|
|
||||||||||
| CREATE TYPE transtype AS ENUM('Interest','Withdrawal','Deposit'); | ||||||||||
| CREATE TABLE transactions( | ||||||||||
| transaction_id int AUTO_INCREMENT PRIMARY KEY, | ||||||||||
| ref_number VARCHAR(20) UNIQUE, | ||||||||||
| holder_id char(5) REFERENCES AccountHolder(holder_id), | ||||||||||
| type transtype, | ||||||||||
| amount numeric(12,2), | ||||||||||
| timestamp timestamp, | ||||||||||
| description varchar(255)); | ||||||||||
|
|
||||||||||
| -- Employee | ||||||||||
| CREATE INDEX idx_employee_branch_id ON Employee(branch_id); | ||||||||||
|
|
||||||||||
| -- Customer | ||||||||||
| CREATE INDEX idx_customer_employee_id ON Customer(employee_id); | ||||||||||
|
|
||||||||||
| -- Token | ||||||||||
| CREATE INDEX idx_token_employee_id ON Token(employee_id); | ||||||||||
|
|
||||||||||
| -- AccountHolder | ||||||||||
| CREATE INDEX idx_holder_customer_id ON AccountHolder(customer_id); | ||||||||||
|
|
||||||||||
| -- Transactions | ||||||||||
| CREATE INDEX idx_transaction_holder_id ON Transactions(holder_id); | ||||||||||
|
|
||||||||||
| -- Update Transactions | ||||||||||
| CREATE PROCEDURE make_transaction( | ||||||||||
| IN p_customer_id char(5), | ||||||||||
| IN p_saving_account_id char(5), | ||||||||||
| IN p_type transtype, | ||||||||||
| IN p_amount numeric(12,2), | ||||||||||
| IN p_description varchar(255), | ||||||||||
| OUT new_balance numeric(12,2) | ||||||||||
| ) | ||||||||||
| LANGUAGE plpgsql | ||||||||||
| AS $$ | ||||||||||
| DECLARE current_balance numeric(12,2); | ||||||||||
| DECLARE current_holder_id char(5); | ||||||||||
| BEGIN | ||||||||||
| -- Get current balance | ||||||||||
| SELECT balance INTO current_balance | ||||||||||
| FROM savingsaccount | ||||||||||
| WHERE saving_account_id = p_saving_account_id; | ||||||||||
|
|
||||||||||
| -- Get current holder ID | ||||||||||
| SELECT holder_id INTO current_holder_id | ||||||||||
| FROM accountholder | ||||||||||
| JOIN savingsaccount | ||||||||||
| USING (saving_account_id) | ||||||||||
| WHERE accountholder.customer_id = p_customer_id AND savingsaccount.saving_account_id = p_saving_account_id; | ||||||||||
|
|
||||||||||
| IF p_type = 'Deposit' THEN | ||||||||||
| new_balance := current_balance + p_amount; | ||||||||||
| ELSIF p_type = 'Withdrawal' THEN | ||||||||||
| IF current_balance > p_amount THEN | ||||||||||
| new_balance := current_balance - p_amount; | ||||||||||
| ELSE | ||||||||||
| RAISE EXCEPTION 'Insufficient balance'; | ||||||||||
| END IF; | ||||||||||
| END IF; | ||||||||||
|
|
||||||||||
| -- Update balance | ||||||||||
| UPDATE savingsaccount | ||||||||||
| SET balance = new_balance | ||||||||||
| WHERE saving_account_id = p_saving_account_id; | ||||||||||
|
|
||||||||||
| -- Insert transaction | ||||||||||
| INSERT INTO transactions(holder_id, amount, type, description) | ||||||||||
| VALUES (current_holder_id, p_amount, p_type, p_description); | ||||||||||
|
Comment on lines
+159
to
+160
|
||||||||||
| INSERT INTO transactions(holder_id, amount, type, description) | |
| VALUES (current_holder_id, p_amount, p_type, p_description); | |
| INSERT INTO transactions(holder_id, amount, type, description, timestamp) | |
| VALUES (current_holder_id, p_amount, p_type, p_description, CURRENT_TIMESTAMP); |
Copilot
AI
Oct 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The trigger function references 'ref_no' but the transactions table defines the column as 'ref_number' (line 95). This will cause a runtime error when the trigger executes.
| NEW.ref_no := prefix || '-' || TO_CHAR(NEW.timestamp, 'YYYYMMDD') || '-' || LPAD(NEXTVAL('txn_ref_no')::TEXT, 5, '0'); | |
| NEW.ref_number := prefix || '-' || TO_CHAR(NEW.timestamp, 'YYYYMMDD') || '-' || LPAD(NEXTVAL('txn_ref_no')::TEXT, 5, '0'); |
Copilot
AI
Oct 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable 'new_balance' is used as an OUT parameter but is not declared in the procedure. This will cause a compilation error.
Copilot
AI
Oct 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable 'new_balance' is used as an OUT parameter but is not declared in the procedure. This will cause a compilation error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The withdrawal validation allows withdrawal when balance equals amount, but doesn't account for minimum balance requirements defined in savingsaccount_plans. This could allow accounts to fall below their required min_balance.