making loan tables

This commit is contained in:
CHIEFSOFT\ameye
2025-02-22 06:51:09 -05:00
parent bcba8fc166
commit ef99e8d3da
2 changed files with 30 additions and 8 deletions
+9 -5
View File
@@ -83,7 +83,8 @@ CREATE TABLE loan_apply (
amount INT DEFAULT 0,
added timestamp without time zone DEFAULT now(),
status INT DEFAULT 1,
verified timestamp
verified timestamp,
due_date timestamp
);
ALTER TABLE ONLY loan_apply
ADD CONSTRAINT loan_apply_id_key UNIQUE (id);
@@ -93,20 +94,23 @@ ALTER TABLE ONLY loan_apply
CREATE TABLE loans (
id SERIAL,
uid uuid DEFAULT uuid_generate_v4(),
application_uid VARCHAR(150) NOT NULL,
bvn VARCHAR(12) NOT NULL,
loan VARCHAR(25) REFERENCES loan_offers (loan),
approved_amount INT DEFAULT 0,
initial_deduction INT DEFAULT 0,
days_duration INT DEFAULT 0,
added timestamp without time zone DEFAULT now(),
due_date timestamp
);
due_date timestamp,
payment INT DEFAULT 0,
added timestamp without time zone DEFAULT now()
);
ALTER TABLE ONLY loans
ADD CONSTRAINT loans_id_key UNIQUE (id);
--- ALTER TABLE loan_apply ADD verified timestamp;
--- ALTER TABLE loan_apply ADD status INT DEFAULT 1;
-- ALTER TABLE loan_apply ADD due_date timestamp;
{"cid": "425611f2-c692-4404-b93d-76ca7a5ce00", "description": "100,000 Naira for 30 Days" , "active" : 1 },
{"cid": "425611f2-c692-4404-b93d-76ca7a5ce01", "description": "300,000 Naira for 60 Days" , "active" : 1 },
+21 -3
View File
@@ -343,6 +343,9 @@ def salary_verifloan2():
bvn = data["bvn"]
pin = data["pin"]
loan_application_id = data["loan_application_id"]
loan_read = load_offer(loan,bvn)
SELECT_ACC = "SELECT id, uid,pin,bvn FROM demo_bank_accounts WHERE bvn='" + bvn + "' AND pin = '" + pin + "' "
print(SELECT_ACC)
with connection:
@@ -353,7 +356,7 @@ def salary_verifloan2():
account_found = count = len( account )
print("10000-a")
if account_found == 1 :
UPDATE_APPLICATION = "UPDATE loan_apply SET verified = now(),status=5 WHERE uid::text = '" + loan_application_id + "' AND status = 1"
UPDATE_APPLICATION = "UPDATE loan_apply SET verified = now(), due_date = now(() + '30 days' status=5 WHERE uid::text = '" + loan_application_id + "' AND status = 1"
print(UPDATE_APPLICATION)
with connection.cursor(cursor_factory=psycopg2.extras.DictCursor) as cursor:
cursor.execute(UPDATE_APPLICATION)
@@ -395,14 +398,15 @@ def products():
return product_data
def load_offer(loan,bvn):
OFFER_QUERY = "SELECT uid AS cid,loan,amount,description,days_duration,active FROM loan_offers WHERE loan='" + loan +"'"
OFFER_QUERY = "SELECT uid AS cid,loan,amount,description,days_duration,active FROM loan_offers WHERE loan='" + loan +"' LIMIT 1"
with connection:
with connection.cursor(cursor_factory=psycopg2.extras.DictCursor) as cursor:
cursor.execute(OFFER_QUERY)
select_demoS = cursor.fetchall()
loan_data = json.dumps( [dict(ix) for ix in select_demoS] )
return json.loads( loan_data )
loan_result = json.loads( loan_data[0] )
return json.loads( loan_data[0] )
def offers():
OFFER_QUERY = "SELECT uid AS cid,loan,amount,description,days_duration,active FROM loan_offers ORDER BY amount ASC"
@@ -503,5 +507,19 @@ def office_loan_data(loanLevel):
demo_data = json.dumps( [dict(ix) for ix in select_demoS] )
return json.loads( demo_data)
@app.route('/office/offers')
def offer_offers():
OFFER_QUERY = "SELECT uid AS cid,loan,amount,description,days_duration,active,score,lorder FROM loan_offers "
with connection:
with connection.cursor(cursor_factory=psycopg2.extras.DictCursor) as cursor:
cursor.execute(OFFER_QUERY)
select_demoS = cursor.fetchall()
loan_data = json.dumps( [dict(ix) for ix in select_demoS] )
loan_result = json.loads( loan_data)
return loan_result
if __name__ == '__main__':
app.run(host='0.0.0.0', port=8000)