From ac65921498f0d55021272b1b020375c9241eea32 Mon Sep 17 00:00:00 2001 From: pb Date: Sat, 21 Jun 2025 20:39:14 +0200 Subject: [PATCH] ajout sankey compta fonctionnel --- budget.svg | 70 +- compta.svg | 1891 +++++++++++++++++ libs/__pycache__/lib_csv.cpython-311.pyc | Bin 219 -> 218 bytes libs/__pycache__/lib_mariadb.cpython-311.pyc | Bin 433 -> 432 bytes .../lib_matplotlib.cpython-311.pyc | Bin 264 -> 263 bytes libs/lib_matplotlib.py | 2 - main.py | 79 +- requirements.txt | 1 + 8 files changed, 1986 insertions(+), 57 deletions(-) create mode 100644 compta.svg diff --git a/budget.svg b/budget.svg index ae57408..a9053f2 100644 --- a/budget.svg +++ b/budget.svg @@ -6,7 +6,7 @@ - 2025-06-15T14:55:20.889417 + 2025-06-21T20:31:55.648539 image/svg+xml @@ -35,7 +35,7 @@ L 307.150694 140.046626 L 307.150694 111.6 L 288.409091 111.6 z -" clip-path="url(#pd093175b84)" style="fill: #1f77b4"/> +" clip-path="url(#p3a0fb5d9d6)" style="fill: #1f77b4"/> +" clip-path="url(#p3a0fb5d9d6)" style="fill: #ff7f0e"/> +" clip-path="url(#p3a0fb5d9d6)" style="fill: #2ca02c"/> +" clip-path="url(#p3a0fb5d9d6)" style="fill: #d62728"/> +" clip-path="url(#p3a0fb5d9d6)" style="fill: #9467bd"/> +" clip-path="url(#p3a0fb5d9d6)" style="fill: #8c564b"/> +" clip-path="url(#p3a0fb5d9d6)" style="fill: #e377c2"/> +" clip-path="url(#p3a0fb5d9d6)" style="fill: #7f7f7f"/> +" clip-path="url(#p3a0fb5d9d6)" style="fill: #bcbd22"/> +" clip-path="url(#p3a0fb5d9d6)" style="fill: #17becf"/> +" clip-path="url(#p3a0fb5d9d6)" style="fill: #1f77b4"/> +" clip-path="url(#p3a0fb5d9d6)" style="fill: #ff7f0e"/> +" clip-path="url(#p3a0fb5d9d6)" style="fill: #2ca02c"/> +" clip-path="url(#p3a0fb5d9d6)" style="fill: #d62728"/> +" clip-path="url(#p3a0fb5d9d6)" style="fill: #9467bd"/> +" clip-path="url(#p3a0fb5d9d6)" style="fill: #8c564b"/> +" clip-path="url(#p3a0fb5d9d6)" style="fill: #e377c2"/> +" clip-path="url(#p3a0fb5d9d6)" style="fill: #17becf; fill-opacity: 0.6"/> +" clip-path="url(#p3a0fb5d9d6)" style="fill: #17becf; fill-opacity: 0.6"/> +" clip-path="url(#p3a0fb5d9d6)" style="fill: #17becf; fill-opacity: 0.6"/> +" clip-path="url(#p3a0fb5d9d6)" style="fill: #17becf; fill-opacity: 0.6"/> +" clip-path="url(#p3a0fb5d9d6)" style="fill: #17becf; fill-opacity: 0.6"/> +" clip-path="url(#p3a0fb5d9d6)" style="fill: #17becf; fill-opacity: 0.6"/> +" clip-path="url(#p3a0fb5d9d6)" style="fill: #17becf; fill-opacity: 0.6"/> +" clip-path="url(#p3a0fb5d9d6)" style="fill: #17becf; fill-opacity: 0.6"/> +" clip-path="url(#p3a0fb5d9d6)" style="fill: #17becf; fill-opacity: 0.6"/> +" clip-path="url(#p3a0fb5d9d6)" style="fill: #1f77b4; fill-opacity: 0.6"/> +" clip-path="url(#p3a0fb5d9d6)" style="fill: #ff7f0e; fill-opacity: 0.6"/> +" clip-path="url(#p3a0fb5d9d6)" style="fill: #2ca02c; fill-opacity: 0.6"/> +" clip-path="url(#p3a0fb5d9d6)" style="fill: #d62728; fill-opacity: 0.6"/> +" clip-path="url(#p3a0fb5d9d6)" style="fill: #9467bd; fill-opacity: 0.6"/> +" clip-path="url(#p3a0fb5d9d6)" style="fill: #8c564b; fill-opacity: 0.6"/> +" clip-path="url(#p3a0fb5d9d6)" style="fill: #e377c2; fill-opacity: 0.6"/> @@ -1404,7 +1404,7 @@ z - + diff --git a/compta.svg b/compta.svg new file mode 100644 index 0000000..4a140ba --- /dev/null +++ b/compta.svg @@ -0,0 +1,1891 @@ + + + + + + + + 2025-06-21T20:31:55.979272 + image/svg+xml + + + Matplotlib v3.10.3, https://matplotlib.org/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/__pycache__/lib_csv.cpython-311.pyc b/libs/__pycache__/lib_csv.cpython-311.pyc index e95389659405b7c5f5dc1c9796b6a9d52612124f..027e3cfa234b77c562ea316418016a0efaf8652b 100644 GIT binary patch delta 27 hcmcc3c#DyHIWI340}xDi4w}dv%V<6^Q)XgYC;(!~2WbJ7SB diff --git a/libs/__pycache__/lib_mariadb.cpython-311.pyc b/libs/__pycache__/lib_mariadb.cpython-311.pyc index 3fd8ab21049457ab7818a9bd3c6d998ab6aa3ba4..1cb7a75fd0492b6a09c00dbf6a2027bcaa4c0961 100644 GIT binary patch delta 28 icmdnUyn&f}IWI340}xDi4w}eaz-T?OMrPwo2}S^8QU^W& delta 30 kcmdnMypfrEIWI340}!lx?LCpZfYD}RjSOS)#u*Zf0DSNWY5)KL diff --git a/libs/__pycache__/lib_matplotlib.cpython-311.pyc b/libs/__pycache__/lib_matplotlib.cpython-311.pyc index 86cac13f602765894b41b30dce2bce62a786d8ab..222607426586ce185c6c380bf06c70fb27fb6df3 100644 GIT binary patch delta 52 zcmeBRYG>kJ&dbZi00h&WgC=s9%i8H@=5Sw delta 53 zcmZo?>R{qt&dbZi00fWqd?s?2%h~H^ 0 : + NC.append((a.label, tmp_tot, {'label_pos':'right'})) + flows.append(('Total', a.label, tmp_tot)) + else : + tmp_tot = tot_cred-tot_deb + if tmp_tot > 0 : + tot += tmp_tot + NR.append((a.label, tmp_tot, {'label_pos':'left'})) + flows.append((a.label, 'Total', tmp_tot)) + + NC.insert(0, ('reserves aujourd\'hui', tmp_res, {'label_pos':'right'})) + nodes = [ + NR, + [('Total', tot, {'label_pos':'top'})], + NC + ] + + plt.figure(figsize=(25, 10), dpi=144) + s = Sankey( + flows=flows, + nodes=nodes, + node_opts=dict(label_format='{label}:{value}') + ) + s.draw() + path = os.path.join(save_dir, 'compta.svg') + plt.savefig(path) + plt.close() def get_income_and_expense_accounts(cursor): print("get_income_and_expense_accounts") cursor.execute( - "SELECT account_number, label FROM llx_accounting_account WHERE reconcilable = 'PCG-BSC'" + "SELECT account_number, label FROM llx_accounting_account WHERE fk_pcg_version = 'PCG-BSC' AND active = 1;" ) accounts = [] for account_number, label in cursor: - tmp = str(account_number)[0] - if tmp == '6' or tmp == '7': + tmp = account_number[0] + if (tmp == '6' or tmp == '7') and int(account_number) > 10: accounts.append(Account(label, account_number, int(tmp))) [print(f'account {a.number} / {a.label}') for a in accounts] @@ -87,10 +124,11 @@ def get_bank_reserves(cursor, date:str): print('get_bank_reserves') total = 0 cursor.execute( - "SELECT piece_num, numero_compte, label_compte, doc_date, code_journal, debit, credit FROM llx_accounting_bookkeeping WHERE (numero_compte = ? OR numero_compte = ?) AND doc_date = ? AND code_journal = ?", + "SELECT piece_num, numero_compte, label_compte, doc_date, code_journal, debit, credit FROM llx_accounting_bookkeeping WHERE (numero_compte = ? OR numero_compte = ?) AND doc_date = ? AND code_journal = ?;", (5121, 5311, date, 'AN',) ) - for debit, label_compte in cursor: + for piece_num, numero_compte, label_compte, doc_date, code_journal, debit, credit in cursor: + #print(piece_num, numero_compte, label_compte, doc_date, code_journal, debit, credit, sep=" | ") print(f'ajout de : {debit} provenant du compte {label_compte} au total') total += debit print(f'total = {total}') @@ -100,11 +138,11 @@ def get_bank_reserves(cursor, date:str): def connect_mariadb(db_infos:DBInfos): try: conn = mariadb.connect( - user="db_user", - password="db_user_passwd", - host="192.0.2.1", - port=3306, - database="employees" + user=db_infos.user, + password=db_infos.password, + host=db_infos.host, + port=db_infos.port, + database=db_infos.name ) except mariadb.Error as e: @@ -146,19 +184,19 @@ def get_sum_of_operations(cursor, date:str, account:Account): "SELECT piece_num, numero_compte, label_compte, doc_date, code_journal, debit, credit FROM llx_accounting_bookkeeping WHERE numero_compte = ? AND doc_date >= ?", (account.number, date) ) - for debit, credit in cursor : + for piece_num, numero_compte, label_compte, doc_date, code_journal, debit, credit in cursor : tot_cred += credit tot_deb += debit print(f'pour le compte {account.number} : credit = {tot_cred} / debit = {tot_deb} à partir du {date}') - return tot_deb, tot_cred + return int(tot_deb), int(tot_cred) def get_db_infos(path_wp:str): with open(path_wp, "r") as file: content = file.read() db_infos = DBInfos() - db_infos.name = extract_value(content, 'DB_NAME') + db_infos.name = "doli_bsc" db_infos.user = extract_value(content, 'DB_USER') db_infos.password = extract_value(content, 'DB_PASSWORD') db_infos.host = extract_value(content, 'DB_HOST') @@ -209,6 +247,7 @@ def create_budget_sankey( s.draw() path = os.path.join(save, 'budget.svg') plt.savefig(path) + plt.close() if __name__ == "__main__": diff --git a/requirements.txt b/requirements.txt index d985a01..fd62dec 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,6 +3,7 @@ contourpy==1.3.2 cycler==0.12.1 fonttools==4.58.2 kiwisolver==1.4.8 +mariadb==1.1.12 matplotlib==3.10.3 mysql-connector-python==9.3.0 numpy==2.3.0