import sys
if "/service_app_banks" not in list(sys.path):
sys.path.append("/service_app_banks")
from api_services.email.service import send_email
from api_library.date_time_actions.date_functions import client_arrow
from databases import AccountRecords
def send_mail_to_users_that_have_received_email_from_banks():
print("Service is booting up")
print("Sending mail to users that have received email from banks")
# account_records = AccountRecords.query.filter(
# AccountRecords.bank_date >= datetime(
# today.year, today.month, today.day - int(day_offset), 23, 59, 59) # AccountRecords.bank_date >= datetime(2024, 9, 5, 23, 59, 59)
# ).order_by(
# AccountRecords.bank_date.desc(), AccountRecords.bank_reference_code.desc()
# ).all()
# if not account_records:
account_records = (
AccountRecords.query.filter()
.order_by(
AccountRecords.bank_date.desc(), AccountRecords.bank_reference_code.desc()
)
.limit(3)
.all()
)
today, first_record, second_record, balance_error = (
client_arrow.now(),
account_records[0],
account_records[1],
False,
)
second_balance = first_record.bank_balance - first_record.currency_value
if second_balance != second_record.bank_balance:
balance_error = True
send_to = "karatay@mehmetkaratay.com.tr"
styles = """
"""
table_data = ""
table_headers = """
"""
table_row_add = (
lambda date, comment, currency: f"""
Ulaştığı Tarih
Banka Transaksiyonu Ek Bilgi
Aktarım Değeri
"""
)
if not account_records:
return
for account_record in account_records:
table_data += table_row_add(
account_record.bank_date,
account_record.process_comment,
account_record.currency_value,
)
html_template = f"""
{date}
{comment}
{"%.2f" % currency}
Banka Kayıtları : {str(today)}
Son Bakiye : {"%.2f" % account_records[0].bank_balance}
{"Status : İkinci Bakiye Hatalı" if balance_error else "Status :OK"}
Teşekkür ederiz,
Evyos Yönetim
Saygılarımızla