Update app.py
Browse files
app.py
CHANGED
@@ -214,21 +214,27 @@ def generate_t_account(account_name):
|
|
214 |
cursor.execute("SELECT account_id FROM chart_of_accounts WHERE account_name = ?", (account_name,))
|
215 |
account_id = cursor.fetchone()
|
216 |
if not account_id:
|
|
|
217 |
return "Account not found."
|
218 |
|
219 |
account_id = account_id[0]
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
|
|
|
|
|
|
|
|
|
|
227 |
|
228 |
t_account = f"T-Account for {account_name}\n{'='*50}\n{'Debit':<20} | {'Credit':<20} | Description\n{'-'*50}\n"
|
229 |
debit_total = 0
|
230 |
credit_total = 0
|
231 |
-
for amount, desc, entry_type in entries:
|
232 |
if entry_type == "Debit":
|
233 |
t_account += f"${amount:<19} | {'':<20} | {desc}\n"
|
234 |
debit_total += amount
|
|
|
214 |
cursor.execute("SELECT account_id FROM chart_of_accounts WHERE account_name = ?", (account_name,))
|
215 |
account_id = cursor.fetchone()
|
216 |
if not account_id:
|
217 |
+
logging.error(f"Account {account_name} not found.")
|
218 |
return "Account not found."
|
219 |
|
220 |
account_id = account_id[0]
|
221 |
+
try:
|
222 |
+
cursor.execute("""
|
223 |
+
SELECT date, amount, description, 'Debit' as type FROM journal_entries WHERE debit_account_id = ?
|
224 |
+
UNION
|
225 |
+
SELECT date, amount, description, 'Credit' as type FROM journal_entries WHERE credit_account_id = ?
|
226 |
+
ORDER BY date
|
227 |
+
""", (account_id, account_id))
|
228 |
+
entries = cursor.fetchall()
|
229 |
+
logging.info(f"Retrieved {len(entries)} entries for T-account: {account_name}")
|
230 |
+
except sqlite3.Error as e:
|
231 |
+
logging.error(f"SQL error in generate_t_account: {e}")
|
232 |
+
return "Error retrieving T-account data."
|
233 |
|
234 |
t_account = f"T-Account for {account_name}\n{'='*50}\n{'Debit':<20} | {'Credit':<20} | Description\n{'-'*50}\n"
|
235 |
debit_total = 0
|
236 |
credit_total = 0
|
237 |
+
for date, amount, desc, entry_type in entries:
|
238 |
if entry_type == "Debit":
|
239 |
t_account += f"${amount:<19} | {'':<20} | {desc}\n"
|
240 |
debit_total += amount
|