@@ -57,6 +57,7 @@ class GoldTransaction(db.Model):
5757 service_charge = db .Column (db .Float , nullable = False )
5858 tax = db .Column (db .Float , nullable = False )
5959 total = db .Column (db .Float , nullable = False )
60+ currency = db .Column (db .String (3 ), nullable = False )
6061 timestamp = db .Column (db .DateTime , default = datetime .utcnow )
6162
6263
@@ -68,6 +69,7 @@ class SilverTransaction(db.Model):
6869 service_charge = db .Column (db .Float , nullable = False )
6970 tax = db .Column (db .Float , nullable = False )
7071 total = db .Column (db .Float , nullable = False )
72+ currency = db .Column (db .String (3 ), nullable = False )
7173 timestamp = db .Column (db .DateTime , default = datetime .utcnow )
7274
7375
@@ -89,7 +91,6 @@ class Settings(db.Model):
8991 currency = db .Column (db .String (10 ), nullable = False )
9092 theme = db .Column (db .String (10 ), nullable = False )
9193
92-
9394class AuditLog (db .Model ):
9495 id = db .Column (db .Integer , primary_key = True )
9596 user_id = db .Column (db .Integer , db .ForeignKey ('user.id' ), nullable = False )
@@ -106,6 +107,15 @@ def __repr__(self):
106107with app .app_context ():
107108 db .create_all ()
108109
110+
111+ # first commit in database for settings
112+ with app .app_context ():
113+ db .create_all ()
114+ settings = Settings (currency = 'INR' , theme = 'light' )
115+ db .session .add (settings )
116+ db .session .commit ()
117+
118+
109119@app .route ('/health' )
110120def health ():
111121 health_info = {
@@ -133,9 +143,22 @@ def home() -> str:
133143def inject_theme ():
134144 return dict (current_theme = app .config .get ('THEME' , 'light' ))
135145
146+
136147# Gold calculator route
137148@app .route ('/gold-calculator' , methods = ['GET' , 'POST' ])
138149def gold_calculator ():
150+
151+ currency_to_symbol_dict = {
152+ "INR" : "₹ " ,
153+ "USD" : "$ " ,
154+ "EUR" : "€ " ,
155+ "GBP" : "£ " ,
156+ "JPY" : "¥ " ,
157+ "AUD" : "A$ " ,
158+ }
159+
160+ current_currency = Settings .query .first ().currency
161+ currency_symbol = currency_to_symbol_dict .get (current_currency , '$' )
139162 if request .method == 'POST' :
140163 try :
141164 weight = float (request .form ['weight' ])
@@ -160,17 +183,25 @@ def gold_calculator():
160183 purity = purity ,
161184 service_charge = gold_service_charge ,
162185 tax = gold_tax ,
163- total = bill_details ['Final Price' ]
186+ total = bill_details ['Final Price' ],
187+ currency = current_currency ,
164188 )
165189 db .session .add (transaction )
166190 db .session .commit ()
167191
192+ # if user is logged in, log the transaction
193+ if current_user .is_authenticated :
194+ log_action (user_id = current_user .id , username = current_user .username ,
195+ action = 'Gold Calculator' , details = f"Calculated gold price for weight { weight } grams" )
196+
168197 return render_template ('gold_bill.html' ,
169198 bill = bill_details ,
170199 weight = weight ,
171200 price_per_gram = gold_price_per_gram ,
172201 purity = purity ,
173- config = app .config )
202+ config = app .config ,
203+ current_currency = current_currency ,
204+ currency_symbol = currency_symbol )
174205 except ValueError as e :
175206 logging .error (f"ValueError in gold calculator: { str (e )} " )
176207 flash (f"Input error: { str (e )} " , 'error' )
@@ -185,7 +216,10 @@ def gold_calculator():
185216 price_per_gram = gold_price_per_gram ,
186217 service_charge = gold_service_charge ,
187218 tax = gold_tax ,
188- config = app .config )
219+ config = app .config ,
220+ current_currency = current_currency ,
221+ currency_symbol = currency_symbol )
222+
189223
190224# Silver calculator route
191225@app .route ('/silver-calculator' , methods = ['GET' , 'POST' ])
@@ -224,7 +258,7 @@ def silver_calculator():
224258 )
225259 db .session .add (transaction )
226260 db .session .commit ()
227-
261+
228262 return render_template ('silver_bill.html' ,
229263 bill = bill_details ,
230264 weight = weight ,
@@ -257,20 +291,24 @@ def history():
257291 if selected_type == 'gold' :
258292 transactions = GoldTransaction .query .all ()
259293 transactions = [{'id' : t .id , 'type' : 'Gold' , 'weight' : t .weight , 'price_per_gram' : t .price_per_gram ,
260- "purity" : t .purity , 'service_charge' : t .service_charge , 'tax' : t .tax , 'total' : t .total , 'timestamp' : t .timestamp } for t in transactions ]
294+ "purity" : t .purity , 'service_charge' : t .service_charge , 'tax' : t .tax , 'total' : t .total , 'currency' : t .currency ,
295+ 'timestamp' : t .timestamp } for t in transactions ]
261296 elif selected_type == 'silver' :
262297 transactions = SilverTransaction .query .all ()
263298 transactions = [{'id' : t .id , 'type' : 'Silver' , 'weight' : t .weight , 'price_per_gram' : t .price_per_gram ,
264- 'purity' : t .purity , 'service_charge' : t .service_charge , 'tax' : t .tax , 'total' : t .total , 'timestamp' : t .timestamp } for t in transactions ]
299+ 'purity' : t .purity , 'service_charge' : t .service_charge , 'tax' : t .tax , 'total' : t .total , 'currency' : t .currency ,
300+ 'timestamp' : t .timestamp } for t in transactions ]
265301 else :
266302 gold_transactions = GoldTransaction .query .all ()
267303 silver_transactions = SilverTransaction .query .all ()
268304
269305 transactions = [{'id' : t .id , 'type' : 'Gold' , 'weight' : t .weight , 'price_per_gram' : t .price_per_gram ,
270- 'purity' : t .purity , 'service_charge' : t .service_charge , 'tax' : t .tax , 'total' : t .total , 'timestamp' : t .timestamp } for t in gold_transactions ]
306+ 'purity' : t .purity , 'service_charge' : t .service_charge , 'tax' : t .tax , 'total' : t .total , 'currency' : t .currency ,
307+ 'timestamp' : t .timestamp } for t in gold_transactions ]
271308
272309 transactions += [{'id' : t .id , 'type' : 'Silver' , 'weight' : t .weight , 'price_per_gram' : t .price_per_gram ,
273- 'purity' : t .purity , 'service_charge' : t .service_charge , 'tax' : t .tax , 'total' : t .total , 'timestamp' : t .timestamp } for t in silver_transactions ]
310+ 'purity' : t .purity , 'service_charge' : t .service_charge , 'tax' : t .tax , 'total' : t .total , 'currency' : t .currency ,
311+ 'timestamp' : t .timestamp } for t in silver_transactions ]
274312
275313 return render_template ('history.html' , transactions = transactions , selected_type = selected_type )
276314
@@ -290,18 +328,22 @@ def download_csv():
290328 if selected_type == 'gold' :
291329 transactions = GoldTransaction .query .all ()
292330 for t in transactions :
293- writer .writerow ([t .id , 'Gold' , t .weight , t .price_per_gram , t .purity , t .service_charge , t .tax , t .total , t .timestamp ])
331+ writer .writerow ([t .id , 'Gold' , t .weight , t .price_per_gram , t .purity , t .service_charge , t .tax , t .total , t .currency ,
332+ t .timestamp ])
294333 elif selected_type == 'silver' :
295334 transactions = SilverTransaction .query .all ()
296335 for t in transactions :
297- writer .writerow ([t .id , 'Silver' , t .weight , t .price_per_gram , t .purity , t .service_charge , t .tax , t .total , t .timestamp ])
336+ writer .writerow ([t .id , 'Silver' , t .weight , t .price_per_gram , t .purity , t .service_charge , t .tax , t .total , t .currency ,
337+ t .timestamp ])
298338 else :
299339 gold_transactions = GoldTransaction .query .all ()
300340 for t in gold_transactions :
301- writer .writerow ([t .id , 'Gold' , t .weight , t .price_per_gram , t .purity , t .service_charge , t .tax , t .total , t .timestamp ])
341+ writer .writerow ([t .id , 'Gold' , t .weight , t .price_per_gram , t .purity , t .service_charge , t .tax , t .total , t .currency ,
342+ t .timestamp ])
302343 silver_transactions = SilverTransaction .query .all ()
303344 for t in silver_transactions :
304- writer .writerow ([t .id , 'Silver' , t .weight , t .price_per_gram , t .purity , t .service_charge , t .tax , t .total , t .timestamp ])
345+ writer .writerow ([t .id , 'Silver' , t .weight , t .price_per_gram , t .purity , t .service_charge , t .tax , t .total , t .currency ,
346+ t .timestamp ])
305347
306348 output = si .getvalue ().encode ('utf-8' )
307349 return send_file (
@@ -381,16 +423,18 @@ def dashboard():
381423 else :
382424 system_health = "Good"
383425
426+ audit_logs = AuditLog .query .filter_by (user_id = current_user .id ).all ()
384427 return render_template ('admin_dashboard.html' ,
385428 total_users = total_users ,
386429 active_sessions = active_sessions ,
387430 system_health = system_health ,
388431 cpu_core = cpu_core ,
389- cpu_util = cpu_utilization )
390- elif current_user .user_level == 'manager' :
391- return render_template ('manager_dashboard.html' )
392- else :
393- return render_template ('customer_dashboard.html' )
432+ cpu_util = cpu_utilization ,
433+ audit_logs = audit_logs )
434+ elif current_user .user_level == 'customer' :
435+ audit_logs = AuditLog .query .filter_by (user_id = current_user .id ).all ()
436+ return render_template ('customer_dashboard.html' , audit_logs = audit_logs )
437+
394438
395439@app .route ("/logout" )
396440def logout ():
0 commit comments