Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import pandas as pd | |
| st.title("📘 Grand Livre Comptable Test") | |
| df = pd.read_csv("src/tcrg-rgat.csv") | |
| # Renommer les colonnes utiles | |
| df = df.rename(columns={ | |
| "General-Ledger-Account-Code-Code-du-compte-du-grand-livre-général": "Compte_GL", | |
| "Subleger-Account-Identifier-Compte_du_GL_auxiliaire": "Compte_auxiliaire", | |
| "Journal-Voucher-Item-Amount-Montant-de-l'item-de-la-pièce-de-journal": "Montant", | |
| "Credit/Debit-Code-Code-Crédit/Débit": "Type", | |
| "Accounting-Effective-Date-Date-d'entrée-en-vigueur-comptable": "Date", | |
| "Journal-Voucher-Item-Identifier-Identificateur-de-l'item-de-la-pièce-de-journal": "N°_pièce" | |
| }) | |
| df = df[df["Compte_GL"].notna()] | |
| df["Débit"] = df.apply(lambda row: row["Montant"] if row["Type"] == "D" else 0, axis=1) | |
| df["Crédit"] = df.apply(lambda row: row["Montant"] if row["Type"] == "C" else 0, axis=1) | |
| df["Date"] = pd.to_datetime(df["Date"]) | |
| df = df.sort_values("Date") | |
| st.subheader("🧾 Écritures comptables") | |
| st.dataframe(df[["Date", "Compte_GL", "Débit", "Crédit", "Montant", "Type", "N°_pièce"]]) | |
| st.subheader("📊 Résumé du Grand Livre") | |
| resume = df.groupby("Compte_GL").agg({ | |
| "Débit": "sum", | |
| "Crédit": "sum", | |
| "Montant": "count" | |
| }).rename(columns={"Montant": "Nombre_lignes"}).reset_index() | |
| st.dataframe(resume) | |
| # Export bouton | |
| def convert_to_excel(df1, df2): | |
| from io import BytesIO | |
| output = BytesIO() | |
| with pd.ExcelWriter(output, engine='xlsxwriter') as writer: | |
| df1.to_excel(writer, index=False, sheet_name='Ecritures') | |
| df2.to_excel(writer, index=False, sheet_name='Résumé_GL') | |
| return output.getvalue() | |
| excel_bytes = convert_to_excel(df, resume) | |
| st.download_button( | |
| label="📥 Télécharger le fichier Excel", | |
| data=excel_bytes, | |
| file_name="grand_livre.xlsx", | |
| mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" | |
| ) | |
| # import altair as alt | |
| # import numpy as np | |
| # import pandas as pd | |
| # import streamlit as st | |
| # """ | |
| # # Welcome to Streamlit! | |
| # Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:. | |
| # If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community | |
| # forums](https://discuss.streamlit.io). | |
| # In the meantime, below is an example of what you can do with just a few lines of code: | |
| # """ | |
| # num_points = st.slider("Number of points in spiral", 1, 10000, 1100) | |
| # num_turns = st.slider("Number of turns in spiral", 1, 300, 31) | |
| # indices = np.linspace(0, 1, num_points) | |
| # theta = 2 * np.pi * num_turns * indices | |
| # radius = indices | |
| # x = radius * np.cos(theta) | |
| # y = radius * np.sin(theta) | |
| # df = pd.DataFrame({ | |
| # "x": x, | |
| # "y": y, | |
| # "idx": indices, | |
| # "rand": np.random.randn(num_points), | |
| # }) | |
| # st.altair_chart(alt.Chart(df, height=700, width=700) | |
| # .mark_point(filled=True) | |
| # .encode( | |
| # x=alt.X("x", axis=None), | |
| # y=alt.Y("y", axis=None), | |
| # color=alt.Color("idx", legend=None, scale=alt.Scale()), | |
| # size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])), | |
| # )) |