aviza wip
This commit is contained in:
parent
9575b584c5
commit
2c32600817
16
app_main.py
16
app_main.py
@ -6,6 +6,8 @@ from aviza.paynl_single import extract_and_process_zip_paynl_single
|
||||
from aviza.gls_single import extract_and_process_zip_gls_single
|
||||
from csv2gpc import convert_csv_to_gpc, mapping_sparkasse, mapping_pko, mapping_wise
|
||||
from allegro import convert_csv_to_gpc_allegro, mapping_allegro
|
||||
from aviza.przelewy24_report_single import extract_and_process_zip_przelewy_report_single
|
||||
from aviza.paynl_auto import convert_csv_to_gpc_paynl_auto, mapping_paynl_avizo
|
||||
import tempfile
|
||||
import datetime
|
||||
|
||||
@ -112,6 +114,20 @@ def index():
|
||||
as_attachment=True,
|
||||
mimetype="application/zip"
|
||||
)
|
||||
elif option == "przelewy24_single":
|
||||
|
||||
result_data = extract_and_process_zip_przelewy_report_single(tmp_file_path, f"{option}_aviza_{day_of_year}.csv")
|
||||
return send_file(
|
||||
result_data,
|
||||
download_name=f"przelewy24_single_{day_of_year}.zip",
|
||||
as_attachment=True,
|
||||
mimetype="application/zip"
|
||||
)
|
||||
elif option == "paynl_auto":
|
||||
|
||||
result_data = convert_csv_to_gpc_paynl_auto(tmp_file_path, bank_statement_file_path, f"{option}_vypis_{day_of_year}.gpc",
|
||||
account_number=3498710000999125,
|
||||
currency="EUR", mapping=mapping_paynl_avizo)
|
||||
|
||||
|
||||
|
||||
|
@ -21,7 +21,7 @@ def load_bank_transactions(csv_file):
|
||||
|
||||
return df
|
||||
|
||||
def search_bank_transaction(df, search_string):
|
||||
def search_bank_transaction(search_string):
|
||||
"""
|
||||
Searches for a given string in the 'Zpráva pro příjemce' column of the loaded DataFrame.
|
||||
|
||||
@ -29,14 +29,16 @@ def search_bank_transaction(df, search_string):
|
||||
:param search_string: String to search for in the 'Zpráva pro příjemce' column.
|
||||
:return: The first matching row as a dictionary or None if not found.
|
||||
"""
|
||||
matching_row = df[df['Zpráva pro příjemce'].str.contains(search_string, na=False, case=False)]
|
||||
global transactions_df
|
||||
matching_row = transactions_df[transactions_df['Zpráva pro příjemce'].str.contains(search_string, na=False, case=False)]
|
||||
|
||||
return matching_row.iloc[0].to_dict() if not matching_row.empty else None
|
||||
|
||||
|
||||
def convert_csv_to_gpc(csv_file_path, gpc_file_path, account_number, currency, mapping):
|
||||
def convert_csv_to_gpc_paynl_auto(csv_file_path, bank_statement_file_path, gpc_file_path, account_number, currency, mapping):
|
||||
gpc_lines = []
|
||||
global transactions_df
|
||||
transactions_df = load_bank_transactions(bank_statement_file_path)
|
||||
|
||||
|
||||
if mapping['forced_encoding'] is not None:
|
||||
@ -57,6 +59,9 @@ def convert_csv_to_gpc(csv_file_path, gpc_file_path, account_number, currency, m
|
||||
next(reader)
|
||||
|
||||
total_payout = 0.0
|
||||
total_payout_debet = 0.0
|
||||
total_payout_credit = 0.0
|
||||
total_payout_abs = 0.0
|
||||
first = True
|
||||
clearing_id = ""
|
||||
for row in reader:
|
||||
@ -110,13 +115,16 @@ def convert_csv_to_gpc(csv_file_path, gpc_file_path, account_number, currency, m
|
||||
constant_symbol=0,
|
||||
bank_code=0,
|
||||
specific_symbol=0,
|
||||
client_name=source_name,
|
||||
client_name="CG ABCD-EFGH-IJKL" if transaction_code == TransactionCode.DEBET else "CG refundace",
|
||||
currency=currency_code,
|
||||
date=created_on
|
||||
)
|
||||
|
||||
gpc_lines.append(gpc_data.to_string())
|
||||
total_payout += source_amount_cents
|
||||
total_payout_abs += abs(source_amount_cents)
|
||||
total_payout_debet += abs(source_amount_cents) if transaction_code == TransactionCode.DEBET else 0
|
||||
total_payout_credit += abs(source_amount_cents) if transaction_code == TransactionCode.CREDIT else 0
|
||||
# break
|
||||
|
||||
# add fees
|
||||
@ -137,13 +145,13 @@ def convert_csv_to_gpc(csv_file_path, gpc_file_path, account_number, currency, m
|
||||
#
|
||||
# gpc_lines.append(gpc_data.to_string())
|
||||
|
||||
corresponding_transaction = search_bank_transaction(transactions_df, clearing_id)
|
||||
corresponding_transaction = search_bank_transaction(clearing_id)
|
||||
|
||||
# vyuctovani row
|
||||
payout_data = Data(
|
||||
account=account_number,
|
||||
payer_account=2801379531,
|
||||
no=0,
|
||||
no=666111222,
|
||||
balance=total_payout,
|
||||
code=TransactionCode.DEBET,
|
||||
variable=666111222,
|
||||
@ -156,6 +164,9 @@ def convert_csv_to_gpc(csv_file_path, gpc_file_path, account_number, currency, m
|
||||
date=parse_date(corresponding_transaction['Datum'])
|
||||
)
|
||||
|
||||
total_payout_credit += abs(total_payout)
|
||||
total_payout_abs += abs(total_payout)
|
||||
|
||||
gpc_lines.append(payout_data.to_string())
|
||||
|
||||
# Create and add the header
|
||||
@ -167,22 +178,26 @@ def convert_csv_to_gpc(csv_file_path, gpc_file_path, account_number, currency, m
|
||||
old_sign='+',
|
||||
new_balance=0,
|
||||
new_sign='+',
|
||||
turnover_debet=total_payout,
|
||||
turnover_debet=total_payout_debet,
|
||||
turnover_debet_sign='+',
|
||||
turnover_credit=total_payout,
|
||||
turnover_credit=total_payout_credit,
|
||||
turnover_credit_sign='+',
|
||||
transaction_list_no=3,
|
||||
date=datetime.now()
|
||||
)
|
||||
gpc_lines.insert(0, header.to_string())
|
||||
|
||||
with open(gpc_file_path, mode='w', encoding='utf-8') as gpc_file:
|
||||
gpc_file.writelines(gpc_lines)
|
||||
# with open(gpc_file_path, mode='w', encoding='utf-8') as gpc_file:
|
||||
# gpc_file.writelines(gpc_lines)
|
||||
#
|
||||
# print(f"GPC file successfully created: {gpc_file_path}")
|
||||
|
||||
print(f"GPC file successfully created: {gpc_file_path}")
|
||||
file_content = "".join(gpc_lines)
|
||||
print(f"GPC file content successfully created for: {gpc_file_path}")
|
||||
return file_content.encode("utf-8")
|
||||
|
||||
# Example mappings
|
||||
mapping_paynl = {
|
||||
mapping_paynl_avizo = {
|
||||
'transaction_id': 'PAYMENT_SESSION_ID',
|
||||
'reference': 'EXTRA_1',
|
||||
'direction': None,
|
||||
@ -202,8 +217,7 @@ mapping_paynl = {
|
||||
}
|
||||
|
||||
|
||||
transactions_df = load_bank_transactions("bank_statement.csv")
|
||||
# Example usage:
|
||||
convert_csv_to_gpc("Specification clearing 2024-05-10.csv", "avizo_paynl_test.gpc", account_number=3498710000999117, currency="EUR", mapping=mapping_paynl)
|
||||
# convert_csv_to_gpc("../Specification clearing 2024-05-10.csv", "avizo_paynl_test.gpc", account_number=3498710000999117, currency="EUR", mapping=mapping_paynl_avizo)
|
||||
# convert_csv_to_gpc("pko_input.csv", "pko_output.gpc", account_number=95102013900000630206821286, currency="PLN", mapping=mapping_pko)
|
||||
# convert_csv_to_gpc("sparkasse_input.csv", "sparkasse_output.gpc", account_number=95850503000221267034, currency="EUR", mapping=mapping_sparkasse)
|
@ -104,15 +104,15 @@ def extract_and_process_zip_paynl_single(zip_file_path, bank_statement_file_path
|
||||
|
||||
def transform_csv(input_file):
|
||||
global transactions_df
|
||||
df = pd.read_csv(input_file, delimiter=";", dtype=str)
|
||||
df.iloc[:, 12] = pd.to_numeric(df.iloc[:, 12].str.replace(',', '.'), errors='coerce').fillna(0)
|
||||
df['Zůstatek na účtu'] = df.iloc[:, 12].cumsum().astype(float).round(2)
|
||||
df = pd.read_csv(input_file, delimiter=";", dtype=str, skiprows=3)
|
||||
df.iloc[:, 11] = pd.to_numeric(df.iloc[:, 11], errors='coerce').fillna(0)
|
||||
df["Commission_cumsum"] = df["Commission"].astype(float).cumsum().round(2)
|
||||
transformed_data = []
|
||||
total_rows = len(df)
|
||||
clearing_id = df['CLEARING_ID'].iloc[0] if 'CLEARING_ID' in df.columns else None
|
||||
|
||||
for index, row in df.iterrows():
|
||||
amount = row.iloc[12]
|
||||
for index, row in df.iloc[:-1].iterrows():
|
||||
amount = row.iloc[11]
|
||||
typ_operace = "t" if amount >= 0 else "c"
|
||||
|
||||
transformed_row = [
|
||||
@ -125,7 +125,7 @@ def transform_csv(input_file):
|
||||
sys.stdout.write(f"\rProcessing: {progress:.2f}%")
|
||||
sys.stdout.flush()
|
||||
|
||||
total_sum = round(df.iloc[:, 12].sum(), 2)
|
||||
total_sum = round(df.iloc[:, 11].sum(), 2)
|
||||
corresponding_transaction = search_bank_transaction(clearing_id)
|
||||
final_row = ["w", datetime.strptime(corresponding_transaction['Datum'], "%d.%m.%Y").strftime("%Y-%m-%d"), corresponding_transaction['Zpráva pro příjemce'].split(',')[-1].strip(), -total_sum, 0, "TRUE", "", "Vyrovnání zůstatku", corresponding_transaction['Číslo účtu'] + "/2010", "", "", "", "", "", "NEWLINE BREAK", "", "EUR"]
|
||||
transformed_data.append(final_row)
|
||||
|
71
aviza/przelewy24_report_single.py
Normal file
71
aviza/przelewy24_report_single.py
Normal file
@ -0,0 +1,71 @@
|
||||
import pandas as pd
|
||||
import csv
|
||||
import sys
|
||||
import os
|
||||
import io
|
||||
import zipfile
|
||||
import shutil
|
||||
from aviza.helpers import write_output_csv_to_zip
|
||||
from utils import parse_date, extract_order_number
|
||||
|
||||
|
||||
|
||||
def extract_and_process_zip_przelewy_report_single(zip_file_path, output_file):
|
||||
all_transformed_data = []
|
||||
|
||||
# Create a temporary folder for extraction
|
||||
base_dir = os.path.dirname(zip_file_path)
|
||||
extract_folder = os.path.join(base_dir, "extracted_temp")
|
||||
os.makedirs(extract_folder, exist_ok=True)
|
||||
|
||||
# Extract the provided outer zip file
|
||||
with zipfile.ZipFile(zip_file_path, 'r') as zip_ref:
|
||||
zip_ref.extractall(extract_folder)
|
||||
|
||||
# Check if a top-level "Transactions" folder exists
|
||||
if os.path.exists(extract_folder):
|
||||
# Look for a CSV file inside the Transactions folder
|
||||
csv_filename = next(
|
||||
(f for f in os.listdir(extract_folder)
|
||||
if f.endswith(".csv")),
|
||||
None
|
||||
)
|
||||
if csv_filename:
|
||||
csv_path = os.path.join(extract_folder, csv_filename)
|
||||
transformed_data = transform_csv(csv_path)
|
||||
all_transformed_data.append(transformed_data)
|
||||
|
||||
# Clean up the outer extraction folder
|
||||
shutil.rmtree(extract_folder)
|
||||
print(f"Processed and cleaned up: {zip_file_path}")
|
||||
|
||||
# Return a ZIP archive (in memory) containing all the output CSV files.
|
||||
return write_output_csv_to_zip(output_file, all_transformed_data)
|
||||
|
||||
def transform_csv(input_file):
|
||||
df = pd.read_csv(input_file, delimiter=",", dtype=str, skiprows=3)
|
||||
df.iloc[:, 11] = pd.to_numeric(df.iloc[:, 11], errors='coerce').fillna(0)
|
||||
df["Commission_cumsum"] = df["Commission"].astype(float).cumsum().round(2)
|
||||
df["Amount_cumsum"] = df["Amount"].astype(float).cumsum().round(2)
|
||||
transformed_data = []
|
||||
total_rows = len(df)
|
||||
|
||||
for index, row in df.iloc[:-1].iterrows():
|
||||
amount = row.iloc[11]
|
||||
typ_operace = "t" if amount >= 0 else "c"
|
||||
orders_id = extract_order_number(row['Title'])
|
||||
transformed_row = [
|
||||
typ_operace, parse_date(row.iloc[12]).strftime("%Y-%m-%d"), row['Transaction text id'], amount, row['Balance after operation'], "TRUE", orders_id,
|
||||
f"Dobirka za FA s VS {orders_id}", "", "", "", "", row['Client email'], row['Client email'], "", row["Commission"], "PLN"
|
||||
]
|
||||
transformed_data.append(transformed_row)
|
||||
|
||||
progress = (index + 1) / total_rows * 100
|
||||
sys.stdout.write(f"\rProcessing: {progress:.2f}%")
|
||||
sys.stdout.flush()
|
||||
|
||||
last_row = df.iloc[-1]
|
||||
final_row = ["w", parse_date(last_row.iloc[12]).strftime("%Y-%m-%d"), last_row['Transaction text id'], last_row['Amount without commission'], 0, "TRUE", "", "Vyrovnání zůstatku", "95102013900000630206821286", "", "", "", "", "", "NEWLINE BREAK", "", "PLN"]
|
||||
transformed_data.append(final_row)
|
||||
|
||||
return transformed_data
|
@ -62,6 +62,12 @@
|
||||
<p class="text-gray-600 text-sm italic">Pouzijte .zip se vsemi zip soubory z exportu (z disku zazipovat slozku <i>Aviza GLS</i>)</p>
|
||||
<p class="text-gray-600 text-sm">.csv aviza pro HUF dobirky</p>
|
||||
</div>
|
||||
<div class="tile bg-white shadow-md rounded-lg p-4 cursor-pointer hover:bg-blue-50"
|
||||
data-option="przelewy24_single" data-section="aviza">
|
||||
<h2 class="text-xl font-semibold mb-2">Przelewy24 .csv</h2>
|
||||
<p class="text-gray-600 text-sm italic">Pouzijte .zip se vsemi .csv soubory z reportu</p>
|
||||
<p class="text-gray-600 text-sm">.csv aviza pro Przelewy24</p>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
@ -70,6 +76,25 @@
|
||||
<div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-6">
|
||||
|
||||
|
||||
<div class="tile bg-white shadow-md rounded-lg p-4 cursor-pointer hover:bg-blue-50 opacity-25 pointer-events-none"
|
||||
data-option="paynl_auto" data-section="aviza">
|
||||
<h2 class="text-xl font-semibold mb-2">Paynl .gpc</h2>
|
||||
<p class="text-gray-600 text-sm italic">Pouzijte .zip se vsemi zip soubory z exportu</p>
|
||||
<p class="text-gray-600 text-sm">.gpc aviza pro EUR ucet</p>
|
||||
</div>
|
||||
<div class="tile bg-white shadow-md rounded-lg p-4 cursor-pointer hover:bg-blue-50 opacity-25 pointer-events-none"
|
||||
data-option="przelewy24_auto" data-section="aviza">
|
||||
<h2 class="text-xl font-semibold mb-2">Przelewy24 .gpc</h2>
|
||||
<p class="text-gray-600 text-sm italic">Pouzijte .zip se vsemi .csv soubory z reportu</p>
|
||||
<p class="text-gray-600 text-sm">.gpc aviza pro Przelewy24</p>
|
||||
</div>
|
||||
<div class="tile bg-white shadow-md rounded-lg p-4 cursor-pointer hover:bg-blue-50 opacity-25 pointer-events-none"
|
||||
data-option="gls_auto_huf" data-section="aviza">
|
||||
<h2 class="text-xl font-semibold mb-2">GLS HU .gpc</h2>
|
||||
<p class="text-gray-600 text-sm italic">Pouzijte .zip se vsemi zip soubory z exportu (z disku zazipovat slozku <i>Aviza GLS</i>)</p>
|
||||
<p class="text-gray-600 text-sm">.gpc aviza pro HUF dobirky</p>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user