-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_entries.py
executable file
·217 lines (179 loc) · 7.58 KB
/
create_entries.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
import datetime
import string
import time
import random
from src import db
from src.models.card_model import Card
from src.models.system_user_model import SystemUser
from src.utils.genarators import Auto
from src.models.account_type_model import AccountType
from src.models.banking_service_model import BankServices
from src.models.branch_model import Branch
from src.models.currency_model import Currency
from src.models.customer_model import Customer
from src.models.system_date_model import SysDate
from src.models.till_model import Till
from src.models.transaction_charge_fee_model import TransactionChargeFee
def create_system_date():
date_obj = db.session.query(SysDate).all()
if not date_obj:
sys_date = SysDate(date=time.strftime('%Y-%m-%d'))
db.session.add(sys_date)
db.session.commit()
else:
print("System Date Already Set To: {}".format(date_obj[0].date))
def create_system_user():
user = SystemUser(
full_name="System User",
job_title="System User",
department="System User",
branch_code="Default",
email="[email protected]",
password="systemuser",
access_level=0,
lock=1,
)
db.session.add(user)
db.session.commit()
return user.uid
system_user_id = create_system_user()
def create_system_card(accountNo):
card_no = random.choices(string.digits, k=15)
print("card number generated: {}".format(''.join(card_no)))
card = Card(
card_number=str(''.join(card_no)),
account_number=accountNo,
card_type="Default"
)
db.session.add(card)
db.session.commit()
return card.id
def create_system_accounts():
account_types = ["rtgs", "charges", "suspense", "servfee", "acccreate", "interest"]
contact_number_counter = 772000000
existing_account_types = {at.account_type for at in Customer.query.all()}
for account_type in account_types:
account_number = Auto().account_number_generator()
card_id = create_system_card(account_number)
if account_type not in existing_account_types:
print(f"Creating account of type {account_type}.")
contact_number = str(contact_number_counter).zfill(10)
record = Customer(
first_name='sys_user',
last_name='sys_user',
dob=time.strftime('%Y-%m-%d'),
address='Head Office',
country='Zimbabwe',
email='[email protected]',
gender='system',
contact_number=contact_number,
working_bal=0,
acc_number=account_number,
account_type=account_type,
inputter_id=system_user_id,
card_id=card_id,
)
db.session.add(record)
db.session.commit()
contact_number_counter += 1
def create_system_tellers():
record_till = db.session.query(Till).all()
if len(record_till) <= 6:
for _ in range(0, 6):
print("Teller account created")
new_teller = Till(
branch_code='',
o_balance=0,
c_balance=0,
till_account=Auto().system_account_number_generator(),
currency="USD",
remark='',
date='',
user_id=system_user_id)
db.session.add(new_teller)
db.session.commit()
def create_system_currencies():
currencies = [{"currency_code": "USD", "description": "United States Dollar"},
{"currency_code": "ZAR", "description": "South African Rand"},
{"currency_code": "GBP", "description": "Great Britain Pound"}]
for currency in currencies:
code = currency.get("currency_code")
description = currency.get("description")
if code not in [c.currency_code for c in db.session.query(Currency).all()]:
new_currency = Currency(currency_code=code, description=description,
create_date=str(datetime.datetime.now()))
db.session.add(new_currency)
else:
continue
print("System currencies created")
db.session.commit()
def create_system_branches():
branches = [{"code": "01", "description": "Head Office"},
{"code": "02", "description": "Treasury"},
{"code": "03", "description": "Reconciliation"}]
for branch in branches:
branch_code = branch.get("code")
description = branch.get("description")
if branch_code not in [b.code for b in db.session.query(Branch).all()]:
new_branch = Branch(code=branch_code, description=description)
db.session.add(new_branch)
db.session.commit()
else:
continue
def create_transaction_charge_type():
charge_types = [{"tran_type": "CR", "tran_charge": 0},
{"tran_type": "DR", "tran_charge": 1.50},
{"tran_type": "TR", "tran_charge": 1.0},
{"tran_type": "RTGS", "tran_charge": 5.0},
{"tran_type": "SF", "tran_charge": 3.0}]
for charge in charge_types:
trans_type = charge.get("tran_type")
trans_charge = charge.get("tran_charge")
if trans_type not in [chg.tran_type for chg in db.session.query(TransactionChargeFee).all()]:
new_charge = TransactionChargeFee(tran_type=trans_type, tran_charge=trans_charge)
db.session.add(new_charge)
db.session.commit()
print("Charge Type created")
else:
continue
def create_account_type():
account_types = [{"acc_type": "Savings", "minbalance": 0},
{"acc_type": "Current", "minbalance": 5},
{"acc_type": "Corporate", "minbalance": 100}]
for account_type in account_types:
type_name = account_type.get("acc_type")
min_balance = account_type.get("minbalance")
if type_name not in [t.acc_type for t in db.session.query(AccountType).filter_by(acc_type=type_name).all()]:
new_type = AccountType(acc_type=type_name, minbalance=min_balance)
print("Account types created")
db.session.add(new_type)
db.session.commit()
else:
continue
def create_banking_services():
service_dictionary = [{"service_name": "Pay", "service_description": "for payments"},
{"service_name": "Transfer", "service_description": "Transfer funds to local banks"},
{"service_name": "CashSend", "service_description": "E-wallet services"},
{"service_name": "Bill Payments", "service_description": "Bill Payments"}]
for service in service_dictionary:
service_n = service.get("service_name")
service_d = service.get("service_description")
existing_services = db.session.query(BankServices).filter_by(service_name=service_n).all()
if service_n not in [s.service_name for s in existing_services]:
service_record: BankServices = BankServices(service_name=service_n, service_description=service_d)
print("Banking service: {} create".format(service_n))
db.session.add(service_record)
else:
continue
db.session.commit()
def create_application_defaults():
create_system_date()
create_system_accounts()
create_system_currencies()
create_system_tellers()
create_system_branches()
create_transaction_charge_type()
create_banking_services()
create_account_type()
if __name__ == '__main__':
create_application_defaults()