menu 1 2 3 4 5 7 operationnels

This commit is contained in:
2026-08-03 10:02:12 +02:00
parent b2c241797b
commit f37f5b1e45
25 changed files with 2373 additions and 1120 deletions
+35 -8
View File
@@ -1,19 +1,44 @@
import os
import time
from flask import Flask, render_template
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_wtf import CSRFProtect
from sqlalchemy.exc import OperationalError
from dotenv import load_dotenv
load_dotenv()
db = SQLAlchemy()
csrf = CSRFProtect()
def create_app():
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://jfgiraud:lyon4@db/bolsa'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['SECRET_KEY'] = 'votre_cle_secrete_tres_securisee_jfgiraud04051963++fin'
# --- Configuration depuis l'environnement ---
app.config["SECRET_KEY"] = os.environ.get(
"SECRET_KEY", "change-me-in-production"
)
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
db_user = os.environ.get("MYSQL_USER", "jfgiraud")
db_pass = os.environ.get("MYSQL_PASSWORD", "")
db_host = os.environ.get("MYSQL_HOST", "db")
db_port = os.environ.get("MYSQL_PORT", "3306")
db_name = os.environ.get("MYSQL_DATABASE", "bolsa")
# DATABASE_URL prend la priorité si défini
app.config["SQLALCHEMY_DATABASE_URI"] = os.environ.get(
"DATABASE_URL",
f"mysql+pymysql://{db_user}:{db_pass}@{db_host}:{db_port}/{db_name}",
)
db.init_app(app)
csrf.init_app(app)
# Tentative de connexion et création des tables au démarrage du conteneur
# Enregistrement des modèles ORM (nécessaire avant db.create_all)
from app import models # noqa: F401
# Tentative de connexion au démarrage du conteneur (MySQL peut mettre du temps à être prêt)
with app.app_context():
max_retries = 15
delay = 2
@@ -22,8 +47,9 @@ def create_app():
db.create_all()
print("Base de données connectée et tables initialisées avec succès.")
break
except OperationalError as e:
print(f"Tentative {i+1}/{max_retries} : MySQL n'est pas encore prêt. Nouvelle tentative dans {delay}s...")
except OperationalError:
print(f"Tentative {i+1}/{max_retries} : MySQL n'est pas encore prêt. "
f"Nouvelle tentative dans {delay}s...")
time.sleep(delay)
else:
raise Exception("Impossible d'initialiser la base de données après plusieurs tentatives.")
@@ -34,5 +60,6 @@ def create_app():
return app
# Expose 'app' pour que run.py puisse l'importer directement
app = create_app()
app = create_app()
+98
View File
@@ -0,0 +1,98 @@
from datetime import datetime
from app import db
class Login(db.Model):
__tablename__ = "login"
id = db.Column(db.Integer, primary_key=True)
login = db.Column(db.String(50), nullable=False, unique=True)
nom = db.Column(db.String(100), nullable=False)
prenom = db.Column(db.String(100), nullable=False)
mail = db.Column(db.String(255), nullable=False, unique=True)
pass_ = db.Column("pass", db.String(255), nullable=False)
actif = db.Column(db.Boolean, default=True)
creer_le = db.Column(db.DateTime, default=datetime.utcnow)
modifie_le = db.Column(db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
reset_token = db.Column(db.String(255), nullable=True)
reset_token_created_at = db.Column(db.DateTime, nullable=True)
class Action(db.Model):
__tablename__ = "actions"
id = db.Column(db.Integer, primary_key=True)
isin = db.Column(db.String(50), nullable=False, unique=True)
ticker = db.Column(db.String(50))
company_name = db.Column(db.String(255))
exchange = db.Column(db.String(50), nullable=False)
pays = db.Column(db.String(50), nullable=False)
currency = db.Column(db.String(10), nullable=False)
updated_at = db.Column(db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
class Societe(db.Model):
__tablename__ = "societe"
id = db.Column(db.Integer, primary_key=True)
nom = db.Column(db.String(60), nullable=False)
forme = db.Column(db.String(10), nullable=False)
capital = db.Column(db.Integer, nullable=False)
siren = db.Column(db.String(20), nullable=False)
siret = db.Column(db.String(20), nullable=False)
rcs = db.Column(db.String(50), nullable=False)
tva = db.Column(db.String(50), nullable=False)
naf = db.Column(db.String(10), nullable=False)
tel = db.Column(db.String(30), nullable=False)
web = db.Column(db.String(100), nullable=False)
mail = db.Column(db.String(100), nullable=False)
created_at = db.Column(db.DateTime, default=datetime.utcnow)
updated_at = db.Column(db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
comptes = db.relationship("Compte", backref="societe", lazy=True)
class Compte(db.Model):
__tablename__ = "compte"
id = db.Column(db.Integer, primary_key=True)
id_societe = db.Column(db.Integer, db.ForeignKey("societe.id"), nullable=False)
date_operation = db.Column(db.Date, nullable=False)
debit = db.Column(db.Numeric(15, 2), default=0)
credit = db.Column(db.Numeric(15, 2), default=0)
libelle = db.Column(db.Text)
source = db.Column(db.Enum("manuel", "ordre"), nullable=False, default="manuel")
created_at = db.Column(db.DateTime, default=datetime.utcnow)
updated_at = db.Column(db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
class Ordre(db.Model):
__tablename__ = "ordre"
id = db.Column(db.Integer, primary_key=True)
id_societe = db.Column(db.Integer, db.ForeignKey("societe.id"), nullable=False)
isin = db.Column(db.String(50), db.ForeignKey("actions.isin"), nullable=False)
plus_value = db.Column(db.Numeric(19, 4), nullable=False, default=0)
date_plus_value = db.Column(db.Date, nullable=True)
created_at = db.Column(db.DateTime, default=datetime.utcnow)
updated_at = db.Column(db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
pieds = db.relationship("OrdrePied", backref="ordre", lazy=True, cascade="all, delete-orphan")
class OrdrePied(db.Model):
__tablename__ = "ordre_pied"
id = db.Column(db.Integer, primary_key=True)
id_entete = db.Column(db.Integer, db.ForeignKey("ordre.id", ondelete="CASCADE", onupdate="CASCADE"), nullable=False)
date_op = db.Column(db.Date, nullable=False)
quantite = db.Column(db.Integer, nullable=False)
prix_brut = db.Column(db.Numeric(19, 4))
frais_broker = db.Column(db.Numeric(19, 4))
frais_etat = db.Column(db.Numeric(19, 4))
frais_autre = db.Column(db.Numeric(19, 4))
sens = db.Column(db.Enum("achat", "vente"), nullable=False)
position = db.Column(db.Enum("long", "short"), nullable=False)
etat = db.Column(db.Enum("actif", "soldé", "annulé"), nullable=False)
created_at = db.Column(db.DateTime, default=datetime.utcnow)
updated_at = db.Column(db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
+1129 -668
View File
File diff suppressed because it is too large Load Diff
+15 -11
View File
@@ -1,5 +1,5 @@
<!doctype html>
<html lang="fr" class="dark">
<html lang="fr" class="dark h-full">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
@@ -14,15 +14,20 @@
<!-- Tailwind CSS CDN -->
<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>
<!-- Font Awesome -->
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6.5.2/css/all.min.css"
/>
</head>
<body
class="bg-gray-950 text-gray-100 min-h-screen flex flex-col justify-between"
class="bg-gray-950 text-gray-100 h-screen flex flex-col overflow-hidden"
>
<!-- Header Global -->
<header
class="bg-gray-900 border-b border-gray-800 px-6 py-4 flex items-center justify-between"
class="flex-none bg-gray-900 border-b border-gray-800 px-6 py-4 flex items-center justify-between z-10"
>
<!-- Gauche : Logo (taille augmentée d'environ 1.5x, ex: h-10 -> h-16) -->
<!-- Gauche : Logo -->
<div class="flex items-center">
<a
href="{{ url_for('main.menu') if session.get('user_id') else url_for('main.index') }}"
@@ -35,7 +40,7 @@
</a>
</div>
<!-- Centre : Titre (agrandi avec text-4xl et police plus grasse) -->
<!-- Centre : Titre -->
<div class="absolute left-1/2 transform -translate-x-1/2">
<h1 class="text-4xl font-extrabold tracking-wider text-white">Bolsa</h1>
</div>
@@ -72,13 +77,13 @@
</header>
<!-- Container dynamique -->
<main class="flex-grow w-full px-2 py-4">
<main class="flex-1 w-full px-2 py-4 overflow-hidden flex flex-col">
{% block content %}{% endblock %}
</main>
<!-- Footer Global -->
<footer
class="bg-gray-900 border-t border-gray-800 px-6 py-4 flex items-center justify-between text-xs text-gray-400"
class="flex-none bg-gray-900 border-t border-gray-800 px-6 py-4 flex items-center justify-between text-xs text-gray-400 z-10"
>
<!-- Espace vide à gauche pour équilibrer le flexbox -->
<div class="w-1/3"></div>
@@ -101,7 +106,7 @@
</div>
</footer>
<!-- Script pour récupérer l'IP externe en JS -->
<!-- Script pour récupérer l'IP publique en JS -->
{% if session.get('user_id') %}
<script>
fetch("https://api.ipify.org?format=json")
@@ -109,9 +114,8 @@
.then((data) => {
document.getElementById("external-ip").textContent = data.ip;
})
.catch((error) => {
document.getElementById("external-ip").textContent =
"IP non disponible";
.catch(() => {
document.getElementById("external-ip").textContent = "IP non disponible";
});
</script>
{% endif %}
+1
View File
@@ -107,6 +107,7 @@ content %}
action=""
class="space-y-4 flex-1 flex flex-col justify-between"
>
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
<input type="hidden" id="field-id" name="id" />
<div class="space-y-4">
+417
View File
@@ -0,0 +1,417 @@
{% extends "base.html" %} {% block title %}Gestion des Comptes - Bolsa{%
endblock %} {% block header_title %}Gestion des comptes{% endblock %} {% block
content %}
<div
class="flex flex-col items-center justify-center w-full h-full overflow-hidden px-2"
>
<!-- Système de Toasts -->
<div
id="toast-container"
class="fixed top-6 left-1/2 transform -translate-x-1/2 z-50 space-y-3 w-full max-w-md px-4 pointer-events-none"
>
{% set messages = get_flashed_messages(with_categories=true) %} {% if
messages %} {% for category, message in messages %}
<div
class="toast-message pointer-events-auto flex items-center justify-center px-4 py-3 rounded-xl shadow-2xl text-white text-sm font-medium transition-all duration-300 transform translate-y-0 opacity-100 text-center {% if category == 'success' %} bg-emerald-600 border border-emerald-500 {% elif category == 'warning' %} bg-amber-600 border border-amber-500 {% else %} bg-rose-600 border border-rose-500 {% endif %}"
>
<span>{{ message }}</span>
</div>
{% endfor %} {% endif %}
</div>
<!-- Box principale -->
<div
class="bg-gray-900 border border-gray-800 rounded-2xl shadow-2xl w-full max-w-[98%] h-full flex flex-col overflow-hidden"
>
<!-- Header fixe de la box -->
<div
class="p-4 sm:p-6 pb-3 border-b border-gray-800 flex justify-between items-center shrink-0"
>
<div>
<h2 class="text-2xl font-extrabold text-white flex items-center gap-2">
<i class="fa-solid fa-wallet text-blue-500"></i> Comptes -
<span class="text-amber-400">{{ selected_societe }}</span>
</h2>
<p class="text-gray-400 text-sm">
Suivi des écritures comptables de la société.
</p>
</div>
<div class="flex items-center gap-4">
<form
method="POST"
action="{{ url_for('main.gestion_comptes') }}"
class="m-0"
>
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
<select
name="societe_id"
id="select-societe-id"
class="bg-gray-800 border border-gray-700 text-white text-sm rounded-lg px-3 py-2 focus:outline-none focus:border-blue-500 cursor-pointer"
onchange="this.form.submit()"
>
{% for soc in societes %} {% if soc.id == selected_societe_id %}
<option value="{{ soc.id }}" data-nom="{{ soc.nom }}" selected>
{{ soc.nom }}
</option>
{% else %}
<option value="{{ soc.id }}" data-nom="{{ soc.nom }}">
{{ soc.nom }}
</option>
{% endif %} {% endfor %}
</select>
</form>
<!-- Génération automatique des écritures depuis les ordres -->
<form
method="POST"
action="{{ url_for('main.generer_ecritures_ordres') }}"
class="m-0"
onsubmit="return confirm('Générer / régénérer les écritures comptables à partir des ordres de cette société ? Les écritures générées existantes seront remplacées.');"
>
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
<input type="hidden" name="id_societe" value="{{ selected_societe_id }}" />
<button
type="submit"
class="px-4 py-2 bg-amber-600 hover:bg-amber-500 text-white text-sm font-medium rounded-lg transition duration-200 flex items-center gap-2 cursor-pointer"
title="Générer les écritures depuis les ordres"
>
<i class="fa-solid fa-wand-magic-sparkles"></i> Générer
</button>
</form>
<a
href="{{ url_for('main.menu') }}"
class="px-4 py-2 bg-gray-800 hover:bg-gray-700 text-gray-200 text-sm font-medium rounded-lg transition duration-200"
>
Retour au menu
</a>
</div>
</div>
<!-- Corps scrollable -->
<div class="p-4 sm:p-6 overflow-y-auto flex-1">
<div
class="bg-gray-950 border border-gray-800 rounded-xl p-2 overflow-x-auto"
>
<table class="w-full text-left border-collapse text-sm">
<thead>
<tr
class="bg-blue-950/60 text-gray-400 uppercase tracking-wider text-xs border-b border-gray-800"
>
<th class="py-2 px-3">Date</th>
<th class="py-2 px-3">Libellé</th>
<th class="py-2 px-3 text-right">Crédit</th>
<th class="py-2 px-3 text-right">Débit</th>
<th class="py-2 px-3 text-end">
<button
type="button"
onclick="ouvrirModalCreation()"
class="px-3.5 py-1.5 bg-emerald-600 hover:bg-emerald-500 text-white text-xs font-semibold rounded shadow transition cursor-pointer"
>
Créer
</button>
</th>
</tr>
</thead>
<tbody class="divide-y divide-gray-800 text-gray-300">
{% if ecritures %} {% for e in ecritures %}
<tr class="hover:bg-gray-900/50 transition">
<td class="py-2 px-3 whitespace-nowrap">{{ e.date_operation }}</td>
<td class="py-2 px-3 text-gray-400">
{% if e.source == 'ordre' %}{{ e.libelle | safe }}{% else %}{{ e.libelle or '-' }}{% endif %}
</td>
<td class="py-2 px-3 text-right">
{% if e.credit and e.credit > 0 %} {{ "{:,.2f}".format(e.credit)
}} {% else %} - {% endif %}
</td>
<td class="py-2 px-3 text-right">
{% if e.debit and e.debit > 0 %} {{ "{:,.2f}".format(e.debit) }}
{% else %} - {% endif %}
</td>
<td class="py-2 px-3 text-end">
{% if e.source == 'manuel' %}
<button
type="button"
onclick="ouvrirModalModification('{{ e.id }}', '{{ e.date_operation }}', '{{ e.debit }}', '{{ e.credit }}', '{{ e.libelle | e }}')"
class="px-3.5 py-1.5 bg-blue-600 hover:bg-blue-500 text-white text-xs font-semibold rounded shadow transition inline-flex items-center justify-center cursor-pointer"
title="Modifier"
>
Modifier
</button>
{% else %}
<span
class="text-[10px] text-gray-600 italic uppercase tracking-wider"
title="Écriture générée automatiquement depuis un ordre"
>Auto</span
>
{% endif %}
</td>
</tr>
{% endfor %} {% else %}
<tr>
<td colspan="5" class="text-center text-gray-500 py-8">
Aucune écriture pour cette société.
</td>
</tr>
{% endif %}
<!-- Ligne TOTAL -->
<tr
class="bg-blue-950/60 text-white uppercase tracking-wider text-xs border-t border-b border-gray-800 font-bold"
>
<td class="py-2.5 px-3">TOTAL :</td>
<td class="py-2.5 px-3"></td>
<td class="py-2.5 px-3 text-right">
{{ "{:,.2f}".format(total_credit or 0) }}
</td>
<td class="py-2.5 px-3 text-right">
{{ "{:,.2f}".format(total_debit or 0) }}
</td>
<td class="py-2.5 px-3"></td>
</tr>
<!-- Ligne DISPO (récapitulatif financier) -->
<tr class="bg-blue-950 text-white border-b border-gray-800">
<td class="py-3 px-4" colspan="5">
<div class="flex flex-wrap items-center gap-x-6 gap-y-2 text-sm font-extrabold">
<span>
SOLDE :
<span class="ml-1 {% if solde >= 0 %}text-emerald-400{% else %}text-rose-400{% endif %}">
{{ "{:,.2f}".format(solde | abs) }} €{% if solde < 0 %} (-){% endif %}
</span>
</span>
<span class="text-gray-400">|</span>
<span>
DISPO :
<span class="ml-1 {% if dispo >= 0 %}text-emerald-400{% else %}text-rose-400{% endif %}">
{{ "{:,.2f}".format(dispo | abs) }} €{% if dispo < 0 %} (-){% endif %}
</span>
</span>
<span class="text-gray-400">|</span>
<span>
ENGA. :
<span class="ml-1 {% if engagement >= 0 %}text-emerald-400{% else %}text-rose-400{% endif %}">
{{ "{:,.2f}".format(engagement | abs) }} €{% if engagement < 0 %} (-){% endif %}
</span>
</span>
<span class="text-gray-400">|</span>
<span>
Depot :
<span class="ml-1 {% if tcredit >= 0 %}text-emerald-400{% else %}text-rose-400{% endif %}">
{{ "{:,.2f}".format(tcredit | abs) }} €{% if tcredit < 0 %} (-){% endif %}
</span>
</span>
<span class="text-gray-400">|</span>
<span>
Retrait :
<span class="ml-1 {% if tdebit >= 0 %}text-emerald-400{% else %}text-rose-400{% endif %}">
{{ "{:,.2f}".format(tdebit | abs) }} €{% if tdebit < 0 %} (-){% endif %}
</span>
</span>
<span class="text-gray-400">|</span>
<span>
PV :
<span class="ml-1 {% if pv >= 0 %}text-emerald-400{% else %}text-rose-400{% endif %}">
{{ "{:,.2f}".format(pv | abs) }} €{% if pv < 0 %} (-){% endif %}
</span>
</span>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<!-- Footer -->
<div
class="px-6 py-3 border-t border-gray-800 text-xs text-gray-400 text-center shrink-0 bg-gray-900"
>
Comptes : Accès sécurisé. Veillez à fermer votre session après chaque
utilisation.
</div>
</div>
</div>
<!-- Popup unique (Création et Modification d'écriture) -->
<div
id="modal-compte-ecriture"
class="fixed inset-0 bg-black/70 backdrop-blur-sm z-50 flex items-center justify-center hidden"
>
<div
class="bg-gray-900 border border-gray-800 rounded-2xl p-6 w-full max-w-lg shadow-2xl text-white relative"
>
<button
onclick="fermerModal()"
class="absolute top-4 right-4 text-gray-400 hover:text-white cursor-pointer"
>
<i class="fa-solid fa-xmark text-xl"></i>
</button>
<h3 id="modal-title" class="text-xl font-bold mb-4 flex items-center gap-2">
<i class="fa-solid fa-plus-circle text-emerald-500"></i> Nouvelle écriture
</h3>
<form
id="form-modal-ecriture"
method="POST"
action="{{ url_for('main.creer_compte_traitement') }}"
class="space-y-4"
>
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
<input type="hidden" name="id_societe" id="input-id-societe" value="{{ selected_societe_id }}" />
<!-- Nom de la société (affichage en lecture seule) -->
<div>
<label class="text-xs text-gray-400">Société</label>
<input
type="text"
id="input-nom-societe"
readonly
class="w-full mt-1 bg-gray-950 border border-gray-800 rounded-lg px-3 py-2 text-sm text-amber-400 font-semibold focus:outline-none cursor-default"
/>
</div>
<!-- Date + Libellé -->
<div class="grid grid-cols-2 gap-3">
<div>
<label class="text-xs text-gray-400">Date d'opération</label>
<input
type="date"
name="date_operation"
id="input-date-operation"
required
class="w-full mt-1 bg-gray-800 border border-gray-700 rounded-lg px-3 py-2 text-sm text-white focus:outline-none focus:border-blue-500"
/>
</div>
<div>
<label class="text-xs text-gray-400">Libellé</label>
<input
type="text"
name="libelle"
id="input-libelle"
placeholder="Optionnel..."
class="w-full mt-1 bg-gray-800 border border-gray-700 rounded-lg px-3 py-2 text-sm text-white focus:outline-none focus:border-blue-500"
/>
</div>
</div>
<!-- Crédit + Débit -->
<div class="grid grid-cols-2 gap-3">
<div>
<label class="text-xs text-gray-400">Crédit (€)</label>
<input
type="number"
step="0.01"
name="credit"
id="input-credit"
value="0.00"
class="w-full mt-1 bg-gray-800 border border-gray-700 rounded-lg px-3 py-2 text-sm text-white focus:outline-none focus:border-blue-500"
/>
</div>
<div>
<label class="text-xs text-gray-400">Débit (€)</label>
<input
type="number"
step="0.01"
name="debit"
id="input-debit"
value="0.00"
class="w-full mt-1 bg-gray-800 border border-gray-700 rounded-lg px-3 py-2 text-sm text-white focus:outline-none focus:border-blue-500"
/>
</div>
</div>
<div class="flex justify-end gap-2 pt-2">
<button
type="button"
onclick="fermerModal()"
class="px-4 py-2 bg-gray-800 hover:bg-gray-700 text-gray-300 rounded-lg text-sm transition cursor-pointer"
>
Annuler
</button>
<button
type="submit"
id="btn-valider"
class="px-4 py-2 bg-emerald-600 hover:bg-emerald-500 text-white rounded-lg text-sm transition cursor-pointer"
>
Enregistrer
</button>
</div>
</form>
</div>
</div>
<script>
document.addEventListener("DOMContentLoaded", () => {
const toasts = document.querySelectorAll(".toast-message");
toasts.forEach((toast) => {
setTimeout(() => {
toast.style.opacity = "0";
toast.style.transform = "translateY(-10px)";
setTimeout(() => toast.remove(), 300);
}, 4000);
});
});
function getInfosSocieteActive() {
const select = document.getElementById("select-societe-id");
if (!select) return { id: "", nom: "" };
const selectedOption = select.options[select.selectedIndex];
return {
id: select.value,
nom: selectedOption ? selectedOption.getAttribute("data-nom") : "",
};
}
function ouvrirModalCreation() {
const modal = document.getElementById("modal-compte-ecriture");
const form = document.getElementById("form-modal-ecriture");
const title = document.getElementById("modal-title");
modal.classList.remove("hidden");
form.action = "{{ url_for('main.creer_compte_traitement') }}";
title.innerHTML =
'<i class="fa-solid fa-plus-circle text-emerald-500"></i> Nouvelle écriture';
const societe = getInfosSocieteActive();
document.getElementById("input-id-societe").value = societe.id;
document.getElementById("input-nom-societe").value = societe.nom;
document.getElementById("input-date-operation").value = "";
document.getElementById("input-libelle").value = "";
document.getElementById("input-credit").value = "0.00";
document.getElementById("input-debit").value = "0.00";
document.getElementById("btn-valider").textContent = "Enregistrer";
}
function ouvrirModalModification(id, dateOp, debit, credit, libelle) {
const modal = document.getElementById("modal-compte-ecriture");
const form = document.getElementById("form-modal-ecriture");
const title = document.getElementById("modal-title");
modal.classList.remove("hidden");
form.action = "/modifier_compte/" + id;
title.innerHTML =
'<i class="fa-solid fa-pen text-blue-500"></i> Modifier l\'écriture';
const societe = getInfosSocieteActive();
document.getElementById("input-id-societe").value = societe.id;
document.getElementById("input-nom-societe").value = societe.nom;
document.getElementById("input-date-operation").value = dateOp;
document.getElementById("input-libelle").value =
libelle === "None" ? "" : libelle;
document.getElementById("input-credit").value = credit;
document.getElementById("input-debit").value = debit;
document.getElementById("btn-valider").textContent = "Modifier";
}
function fermerModal() {
document.getElementById("modal-compte-ecriture").classList.add("hidden");
}
</script>
{% endblock %}
@@ -150,6 +150,7 @@ endblock %} {% block header_title %}Gestion CSV{% endblock %} {% block content
enctype="multipart/form-data"
class="w-full sm:w-3/4 flex items-center gap-2"
>
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
<input
type="file"
name="file"
+162 -139
View File
@@ -1,7 +1,7 @@
{% extends "base.html" %} {% block title %}Gestion des Ordres - Bolsa{% endblock
%} {% block header_title %}Gestion des ordres{% endblock %} {% block content %}
<div
class="flex flex-col items-center justify-center py-2 px-2 relative w-full"
class="flex flex-col items-center justify-center w-full h-full overflow-hidden px-2"
>
<!-- Système de Toasts -->
<div
@@ -18,12 +18,13 @@
{% endfor %} {% endif %}
</div>
<!-- Box principale -->
<!-- Box principale : Hauteur 100% du conteneur parent (qui occupe tout l'espace libre) -->
<div
class="bg-gray-900 border border-gray-800 p-4 sm:p-6 rounded-2xl shadow-2xl w-full max-w-[98%]"
class="bg-gray-900 border border-gray-800 rounded-2xl shadow-2xl w-full max-w-[98%] h-full flex flex-col overflow-hidden"
>
<!-- Header fixe de la box -->
<div
class="flex justify-between items-center mb-4 border-b border-gray-800 pb-3"
class="p-4 sm:p-6 pb-3 border-b border-gray-800 flex justify-between items-center shrink-0"
>
<div>
<h2 class="text-2xl font-extrabold text-white flex items-center gap-2">
@@ -43,6 +44,7 @@
action="{{ url_for('main.gestion_ordres') }}"
class="flex items-center gap-2 m-0"
>
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
<!-- Conserver la société active lors du changement d'année -->
<input
type="hidden"
@@ -71,7 +73,7 @@
<span
class="font-bold {% if total_plus_value_globale >= 0 %}text-emerald-400{% else %}text-rose-400{% endif %}"
>
{{ "{:,.2f}".format(total_plus_value_globale or 0) }} €
{{ "{:,.2f}".format(total_plus_value_globale | abs) }} €
</span>
</div>
</form>
@@ -81,6 +83,7 @@
action="{{ url_for('main.gestion_ordres') }}"
class="m-0"
>
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
<!-- Conserver l'année active lors du changement de société -->
<input
type="hidden"
@@ -93,9 +96,9 @@
onchange="this.form.submit()"
>
{% for soc in societes %} {% if soc.id == selected_societe_id %}
<option value="{{ soc.id }}" selected>{{ soc.Nom }}</option>
<option value="{{ soc.id }}" selected>{{ soc.nom }}</option>
{% else %}
<option value="{{ soc.id }}">{{ soc.Nom }}</option>
<option value="{{ soc.id }}">{{ soc.nom }}</option>
{% endif %} {% endfor %}
</select>
</form>
@@ -117,144 +120,163 @@
</div>
</div>
<!-- Tableau -->
<div
class="bg-gray-950 border border-gray-800 rounded-xl p-2 overflow-x-auto"
>
<table class="w-full text-left border-collapse text-sm">
<tbody class="divide-y divide-gray-800 text-gray-300">
{% if groupes_ordres %} {% for groupe in groupes_ordres %}
<tr class="bg-blue-950 text-white font-semibold">
<td colspan="12" class="py-2.5 px-3 text-base">
{{ groupe.isin }} --- {{ groupe.company_name }} ( {{ groupe.ticker
}} )
</td>
</tr>
<!-- Corps scrollable de la box (flex-1 et overflow-y-auto pour isoler le défilement) -->
<div class="p-4 sm:p-6 overflow-y-auto flex-1">
<!-- Tableau -->
<div
class="bg-gray-950 border border-gray-800 rounded-xl p-2 overflow-x-auto"
>
<table class="w-full text-left border-collapse text-sm">
<tbody class="divide-y divide-gray-800 text-gray-300">
{% if groupes_ordres %} {% for groupe in groupes_ordres %}
<tr class="bg-blue-950 text-white font-semibold">
<td colspan="12" class="py-2.5 px-3 text-base">
{{ groupe.isin }} --- {{ groupe.company_name }} ( {{
groupe.ticker }} )
</td>
</tr>
<tr
class="bg-blue-950/60 text-gray-400 uppercase tracking-wider text-xs border-t border-b border-gray-800"
>
<th class="py-2 px-3">Date</th>
<th class="py-2 px-3">Qté</th>
<th class="py-2 px-3">Prix Brut</th>
<th class="py-2 px-3">Frais</th>
<th class="py-2 px-3">Prix Net</th>
<th class="py-2 px-3">Eng. Brut</th>
<th class="py-2 px-3">Eng. Net</th>
<th class="py-2 px-3">Ordre</th>
<th class="py-2 px-3">Type</th>
<th class="py-2 px-3">État</th>
<th class="py-2 px-3 text-end">
<button
type="button"
onclick="ouvrirModalLigneOrdre('{{ groupe.id }}', '{{ groupe.isin }}', '{{ groupe.company_name }}', '{{ groupe.ticker }}')"
class="px-3.5 py-1.5 bg-emerald-600 hover:bg-emerald-500 text-white text-xs font-semibold rounded shadow transition cursor-pointer"
>
Créer
</button>
</th>
</tr>
<tr
class="bg-blue-950/60 text-gray-400 uppercase tracking-wider text-xs border-t border-b border-gray-800"
>
<th class="py-2 px-3">Date</th>
<th class="py-2 px-3">Qté</th>
<th class="py-2 px-3">Prix Brut</th>
<th class="py-2 px-3">Frais</th>
<th class="py-2 px-3">Prix Net</th>
<th class="py-2 px-3">Eng. Brut</th>
<th class="py-2 px-3">Eng. Net</th>
<th class="py-2 px-3">Ordre</th>
<th class="py-2 px-3">Type</th>
<th class="py-2 px-3">État</th>
<th class="py-2 px-3 text-end">
<button
type="button"
onclick="ouvrirModalLigneOrdre('{{ groupe.id }}', '{{ groupe.isin }}', '{{ groupe.company_name }}', '{{ groupe.ticker }}')"
class="px-3.5 py-1.5 bg-emerald-600 hover:bg-emerald-500 text-white text-xs font-semibold rounded shadow transition cursor-pointer"
>
Créer
</button>
</th>
</tr>
{% for p in groupe.pieds %}
<tr class="hover:bg-gray-900/50 transition">
<td class="py-2 px-3 whitespace-nowrap">{{ p.date_op }}</td>
<td class="py-2 px-3">
{{ "{:,.0f}".format(p.quantite).replace(",", " ") }}
</td>
<td class="py-2 px-3">{{ "{:,.3f}".format(p.prix_brut) }}</td>
<td class="py-2 px-3">{{ "{:,.3f}".format(p.frais) }}</td>
<td class="py-2 px-3">{{ "{:,.3f}".format(p.prix_net) }}</td>
<td class="py-2 px-3">{{ "{:,.3f}".format(p.eng_brut) }}</td>
<td class="py-2 px-3">{{ "{:,.3f}".format(p.eng_net) }}</td>
<td class="py-2 px-3">
<span
class="px-2 py-0.5 rounded text-xs font-semibold {% if p.ordre == 'achat' %}bg-blue-900 text-blue-200{% else %}bg-rose-900 text-rose-200{% endif %}"
>
{{ p.ordre | upper }}
</span>
</td>
<td class="py-2 px-3">{{ p.type_ordre }}</td>
<td class="py-2 px-3">
<span
class="px-2 py-0.5 rounded text-xs font-medium {% if p.etat == 'actif' %}bg-emerald-900 text-emerald-200 {% elif p.etat == 'soldé' %}bg-gray-800 text-gray-300 {% else %}bg-amber-900 text-amber-200{% endif %}"
>
{{ p.etat }}
</span>
</td>
<td class="py-2 px-3 text-end">
<button
type="button"
onclick="ouvrirModalModifierLigne('{{ p.id }}', '{{ groupe.isin }}', '{{ groupe.company_name }}', '{{ groupe.ticker }}', '{{ p.date_op }}', '{{ p.quantite }}', '{{ p.prix_brut }}', '{{ p.frais_brocker }}', '{{ p.frais_etat }}', '{{ p.frais_autre }}', '{{ p.ordre }}', '{{ p.type_ordre }}', '{{ p.etat }}')"
class="px-3.5 py-1.5 bg-blue-600 hover:bg-blue-500 text-white text-xs font-semibold rounded shadow transition inline-flex items-center justify-center cursor-pointer"
title="Modifier"
>
Modifier
</button>
</td>
</tr>
{% endfor %}
{% for p in groupe.pieds %}
<tr class="hover:bg-gray-900/50 transition">
<td class="py-2 px-3 whitespace-nowrap">{{ p.date_op }}</td>
<td class="py-2 px-3">
{{ "{:,.0f}".format(p.quantite).replace(",", " ") }}
</td>
<td class="py-2 px-3">
{{ "{:,.3f}".format(p.prix_brut | abs) }}
</td>
<td class="py-2 px-3">{{ "{:,.3f}".format(p.frais | abs) }}</td>
<td class="py-2 px-3">
{{ "{:,.3f}".format(p.prix_net | abs) }}
</td>
<td class="py-2 px-3">{{ "{:,.3f}".format(p.eng_brut) }}</td>
<td class="py-2 px-3">{{ "{:,.3f}".format(p.eng_net) }}</td>
<td class="py-2 px-3">
<span
class="px-2 py-0.5 rounded text-xs font-semibold {% if p.ordre == 'achat' %}bg-blue-900 text-blue-200{% else %}bg-rose-900 text-rose-200{% endif %}"
>
{{ p.ordre | upper }}
</span>
</td>
<td class="py-2 px-3">{{ p.type_ordre }}</td>
<td class="py-2 px-3">
<span
class="px-2 py-0.5 rounded text-xs font-medium {% if p.etat == 'actif' %}bg-emerald-900 text-emerald-200 {% elif p.etat == 'soldé' %}bg-gray-800 text-gray-300 {% else %}bg-amber-900 text-amber-200{% endif %}"
>
{{ p.etat }}
</span>
</td>
<td class="py-2 px-3 text-end">
<button
type="button"
onclick="ouvrirModalModifierLigne('{{ p.id }}', '{{ groupe.isin }}', '{{ groupe.company_name }}', '{{ groupe.ticker }}', '{{ p.date_op }}', '{{ p.quantite }}', '{{ p.prix_brut }}', '{{ p.frais_broker }}', '{{ p.frais_etat }}', '{{ p.frais_autre }}', '{{ p.ordre }}', '{{ p.type_ordre }}', '{{ p.etat }}')"
class="px-3.5 py-1.5 bg-blue-600 hover:bg-blue-500 text-white text-xs font-semibold rounded shadow transition inline-flex items-center justify-center cursor-pointer"
title="Modifier"
>
Modifier
</button>
</td>
</tr>
{% endfor %}
<!-- LIGNE TOTAL -->
<tr
class="bg-blue-950/60 text-white uppercase tracking-wider text-xs border-t border-b border-gray-800 font-bold"
>
<td class="py-2.5 px-3">TOTAL :</td>
<td class="py-2.5 px-3">
{{ "{:,.0f}".format(groupe.total_quantite).replace(",", " ") }}
</td>
<!-- LIGNE TOTAL -->
<tr
class="bg-blue-950/60 text-white uppercase tracking-wider text-xs border-t border-b border-gray-800 font-bold"
>
<td class="py-2.5 px-3">TOTAL :</td>
<td class="py-2.5 px-3">
{{ "{:,.0f}".format(groupe.total_quantite).replace(",", " ") }}
</td>
{% if groupe.total_quantite != 0 %} {% set total_prix_net_moyen =
(groupe.total_eng_net / groupe.total_quantite) | abs %} {% set
total_prix_brut_moyen = (groupe.total_eng_brut /
groupe.total_quantite) | abs %} {% set total_frais_moyen =
(total_prix_net_moyen - total_prix_brut_moyen) | abs %}
{% if groupe.total_quantite != 0 %} {% set total_prix_net_moyen =
(groupe.total_eng_net / groupe.total_quantite) %} {% set
total_prix_brut_moyen = (groupe.total_eng_brut /
groupe.total_quantite) %} {% set total_frais_moyen =
(total_prix_net_moyen - total_prix_brut_moyen) %}
<td class="py-2.5 px-3">
{{ "{:,.3f}".format(total_prix_brut_moyen) }}
</td>
<td class="py-2.5 px-3">
{{ "{:,.3f}".format(total_frais_moyen) }}
</td>
<td class="py-2.5 px-3">
{{ "{:,.3f}".format(total_prix_net_moyen) }}
</td>
<td class="py-2.5 px-3">
{{ "{:,.3f}".format(groupe.total_eng_brut | abs) }}
</td>
<td class="py-2.5 px-3">
{{ "{:,.3f}".format(groupe.total_eng_net | abs) }}
</td>
{% else %}
<td class="py-2.5 px-3">-</td>
<td class="py-2.5 px-3">-</td>
<td class="py-2.5 px-3">-</td>
<td class="py-2.5 px-3">
{{ "{:,.3f}".format(groupe.total_eng_brut | abs) }}
</td>
<td class="py-2.5 px-3">
<span
class="{% if groupe.total_eng_net >= 0 %}text-emerald-400{% else %}text-rose-400{% endif %}"
>
{{ "{:,.3f}".format(groupe.total_eng_net | abs) }}
</span>
</td>
<td class="py-2.5 px-3">
{{ "{:,.3f}".format(total_prix_brut_moyen | abs) }}
</td>
<td class="py-2.5 px-3">
{{ "{:,.3f}".format(total_frais_moyen | abs) }}
</td>
<td class="py-2.5 px-3">
{{ "{:,.3f}".format(total_prix_net_moyen | abs) }}
</td>
<td class="py-2.5 px-3">
{{ "{:,.3f}".format(groupe.total_eng_brut) }}
</td>
<td class="py-2.5 px-3">
<span
class="{% if groupe.total_eng_net >= 0 %}text-emerald-400{% else %}text-rose-400{% endif %}"
>
{{ "{:,.3f}".format(groupe.total_eng_net) }}
</span>
</td>
{% else %}
<td class="py-2.5 px-3">-</td>
<td class="py-2.5 px-3">-</td>
<td class="py-2.5 px-3">-</td>
<td class="py-2.5 px-3">
{{ "{:,.3f}".format(groupe.total_eng_brut) }}
</td>
<td class="py-2.5 px-3">
<span
class="{% if groupe.total_eng_net >= 0 %}text-emerald-400{% else %}text-rose-400{% endif %}"
>
{{ "{:,.3f}".format(groupe.total_eng_net) }}
</span>
</td>
{% endif %}
<td class="py-2.5 px-3" colspan="4"></td>
</tr>
<tr>
<td colspan="11" class="h-3 bg-transparent border-0"></td>
</tr>
{% endfor %} {% else %}
<tr>
<td colspan="11" class="text-center text-gray-500 py-8">
Aucun ordre trouvé pour cette société.
</td>
</tr>
{% endif %}
</tbody>
</table>
</div>
</div>
<td class="py-2.5 px-3" colspan="4"></td>
</tr>
<tr>
<td colspan="11" class="h-3 bg-transparent border-0"></td>
</tr>
{% endfor %} {% else %}
<tr>
<td colspan="11" class="text-center text-gray-500 py-8">
Aucun ordre trouvé pour cette société.
</td>
</tr>
{% endif %}
</tbody>
</table>
<!-- Footer fixe de la box -->
<div
class="px-6 py-3 border-t border-gray-800 text-xs text-gray-400 text-center shrink-0 bg-gray-900"
>
Positions en bourse : Accès sécurisé. Veillez à fermer votre session après
chaque utilisation.
</div>
</div>
</div>
@@ -285,6 +307,7 @@
action="{{ url_for('main.creer_ordre_traitement') }}"
class="space-y-4"
>
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
<!-- Transmettre dynamiquement l'année active dans le formulaire de la modale -->
<input
type="hidden"
@@ -385,7 +408,7 @@
type="number"
step="0.0001"
id="input-frais-brocker"
name="frais_brocker"
name="frais_broker"
value="0.0000"
oninput="calculerTotauxModal()"
class="w-full bg-gray-800 border border-gray-700 rounded-lg px-3 py-2 text-sm text-white focus:outline-none focus:border-blue-500"
+14 -13
View File
@@ -57,15 +57,15 @@ content %}
<div class="overflow-y-auto flex-1 space-y-1 pr-1">
{% for s in societes %}
<div
onclick="selectionnerSociete('{{ s.id }}', '{{ s.Nom | e }}', '{{ s.Forme | e }}', '{{ s.Capital }}', '{{ s.siren }}', '{{ s.siret }}', '{{ s.RCS | e }}', '{{ s.TVA | e }}', '{{ s.NAF | e }}', '{{ s.Tel | e }}', '{{ s.Web | e }}', '{{ s.Mail | e }}')"
onclick="selectionnerSociete('{{ s.id }}', '{{ s.nom | e }}', '{{ s.forme | e }}', '{{ s.capital }}', '{{ s.siren }}', '{{ s.siret }}', '{{ s.rcs | e }}', '{{ s.tva | e }}', '{{ s.naf | e }}', '{{ s.tel | e }}', '{{ s.web | e }}', '{{ s.mail | e }}')"
class="societe-item cursor-pointer px-3 py-2.5 rounded-lg {% if loop.first %}bg-blue-600 text-white{% else %}hover:bg-gray-800 text-gray-300{% endif %} font-medium text-sm transition flex justify-between items-center"
data-id="{{ s.id }}"
>
<span class="truncate pr-2 font-semibold">{{ s.Nom }}</span>
<span class="truncate pr-2 font-semibold">{{ s.nom }}</span>
<span
class="text-xs {% if loop.first %}bg-blue-800{% else %}bg-gray-800 text-gray-400{% endif %} px-2 py-0.5 rounded whitespace-nowrap"
>
{{ s.Forme or 'N/A' }}
{{ s.forme or 'N/A' }}
</span>
</div>
{% endfor %}
@@ -82,7 +82,8 @@ content %}
action=""
class="space-y-4 flex-1 flex flex-col justify-between"
>
<!-- ID technique caché -->
<!-- Jeton CSRF + ID technique caché -->
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
<input type="hidden" id="field-id" name="id" />
<div class="space-y-4">
@@ -101,7 +102,7 @@ content %}
<input
type="text"
id="field-nom"
name="Nom"
name="nom"
required
maxlength="60"
class="w-full bg-gray-900 border border-gray-800 rounded-lg px-3 py-2 text-white text-sm focus:outline-none focus:border-blue-500"
@@ -114,7 +115,7 @@ content %}
<input
type="text"
id="field-forme"
name="Forme"
name="forme"
required
maxlength="10"
class="w-full bg-gray-900 border border-gray-800 rounded-lg px-3 py-2 text-white text-sm focus:outline-none focus:border-blue-500"
@@ -127,7 +128,7 @@ content %}
<input
type="number"
id="field-capital"
name="Capital"
name="capital"
required
class="w-full bg-gray-900 border border-gray-800 rounded-lg px-3 py-2 text-white text-sm focus:outline-none focus:border-blue-500"
/>
@@ -174,7 +175,7 @@ content %}
<input
type="text"
id="field-rcs"
name="RCS"
name="rcs"
required
maxlength="50"
class="w-full bg-gray-900 border border-gray-800 rounded-lg px-3 py-2 text-white text-sm focus:outline-none focus:border-blue-500"
@@ -189,7 +190,7 @@ content %}
<input
type="text"
id="field-tva"
name="TVA"
name="tva"
required
maxlength="50"
class="w-full bg-gray-900 border border-gray-800 rounded-lg px-3 py-2 text-white text-sm focus:outline-none focus:border-blue-500"
@@ -204,7 +205,7 @@ content %}
<input
type="text"
id="field-naf"
name="NAF"
name="naf"
required
maxlength="10"
class="w-full bg-gray-900 border border-gray-800 rounded-lg px-3 py-2 text-white text-sm focus:outline-none focus:border-blue-500"
@@ -219,7 +220,7 @@ content %}
<input
type="text"
id="field-tel"
name="Tel"
name="tel"
required
maxlength="30"
class="w-full bg-gray-900 border border-gray-800 rounded-lg px-3 py-2 text-white text-sm focus:outline-none focus:border-blue-500"
@@ -234,7 +235,7 @@ content %}
<input
type="text"
id="field-web"
name="Web"
name="web"
required
maxlength="100"
class="w-full bg-gray-900 border border-gray-800 rounded-lg px-3 py-2 text-white text-sm focus:outline-none focus:border-blue-500"
@@ -249,7 +250,7 @@ content %}
<input
type="email"
id="field-mail"
name="Mail"
name="mail"
required
maxlength="100"
class="w-full bg-gray-900 border border-gray-800 rounded-lg px-3 py-2 text-white text-sm focus:outline-none focus:border-blue-500"
+2 -1
View File
@@ -83,7 +83,8 @@ content %}
action=""
class="space-y-4 flex-1 flex flex-col justify-between"
>
<!-- ID technique caché -->
<!-- Jeton CSRF + ID technique caché -->
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
<input type="hidden" id="field-id" name="id" />
<div class="space-y-4">
+1
View File
@@ -18,6 +18,7 @@ block content %}
{% endif %} {% endwith %}
<form method="POST" action="{{ url_for('main.index') }}" class="space-y-4">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
<div>
<label for="login" class="block text-sm font-medium text-gray-300 mb-1"
>Login :</label
+1 -1
View File
@@ -31,7 +31,7 @@ header_title %}Tableau de bord{% endblock %} {% block content %}
<!-- btn 3 -->
<a
href="#"
href="{{ url_for('main.gestion_comptes') }}"
class="py-6 px-6 bg-gray-950 hover:bg-blue-600/30 border-2 border-gray-800 hover:border-blue-500 rounded-xl text-white text-lg font-bold tracking-wide transition-all duration-200 flex items-center justify-center shadow-lg hover:scale-[1.01]"
>
3. Comptes