2026-07-05 13:52:19 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
require_once __DIR__ . '/session.php';
|
|
|
|
|
require_once __DIR__ . '/db.php';
|
|
|
|
|
|
|
|
|
|
if (empty($_SESSION['user_id'])) {
|
|
|
|
|
header('Location: ../index.php');
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-05 18:21:13 +00:00
|
|
|
ini_set('display_errors', 1);
|
|
|
|
|
ini_set('display_startup_errors', 1);
|
|
|
|
|
error_reporting(E_ALL);
|
|
|
|
|
|
|
|
|
|
|
2026-07-05 13:52:19 +00:00
|
|
|
$pageStylesheets = ['/css/ordreGF.css'];
|
|
|
|
|
$bodyClass = 'ordregf-page';
|
|
|
|
|
|
|
|
|
|
$database = new App\Database\Database();
|
|
|
|
|
$connection = $database->getConnection();
|
|
|
|
|
|
|
|
|
|
// --- Fonctions ---
|
|
|
|
|
function fetchOrdreGF(PDO $connection): array
|
|
|
|
|
{
|
2026-07-05 14:19:13 +00:00
|
|
|
$query = 'SELECT * FROM `ordreGF` ORDER BY `ID` DESC';
|
|
|
|
|
$stmt = $connection->query($query);
|
|
|
|
|
return $stmt->fetchAll(PDO::FETCH_ASSOC) ?: [];
|
2026-07-05 13:52:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function fetchOrdreGFPied(PDO $connection, string $masterId): array
|
|
|
|
|
{
|
|
|
|
|
$stmt = $connection->prepare('SELECT * FROM `ordreGF_pied` WHERE `Id_entete` = :masterId ORDER BY `Id` ASC');
|
|
|
|
|
$stmt->execute([':masterId' => $masterId]);
|
|
|
|
|
return $stmt->fetchAll(PDO::FETCH_ASSOC) ?: [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$ordres = fetchOrdreGF($connection);
|
|
|
|
|
|
|
|
|
|
require_once __DIR__ . '/header.php';
|
|
|
|
|
?>
|
|
|
|
|
|
|
|
|
|
<section class="ordregf-shell">
|
|
|
|
|
<div class="ordregf-card">
|
|
|
|
|
<header class="ordregf-card-header" style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 28px;">
|
|
|
|
|
<h1 class="ordregf-title">Gestion des ordres GF</h1>
|
|
|
|
|
|
|
|
|
|
<div style="display: flex; gap: 10px;">
|
2026-07-05 14:19:13 +00:00
|
|
|
<button type="button" class="ordregf-btn-creer" onclick="document.getElementById('modalCreerOrdre').showModal();">
|
2026-07-05 13:52:19 +00:00
|
|
|
Créer un ordre
|
|
|
|
|
</button>
|
|
|
|
|
<button type="button" class="ordregf-btn-menu" onclick="window.location.href='/php/menu.php';">
|
|
|
|
|
Retour au menu
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
</header>
|
|
|
|
|
|
|
|
|
|
<div class="ordregf-table-wrapper">
|
|
|
|
|
<table class="ordregf-table">
|
|
|
|
|
<tbody>
|
|
|
|
|
<?php foreach ($ordres as $ordre): ?>
|
|
|
|
|
<tr class="ordregf-master-row ordregf-header-style">
|
2026-07-05 14:19:13 +00:00
|
|
|
<td colspan="11" style="font-weight: bold; font-size: 1.1em; color: #fff;">
|
2026-07-05 13:52:19 +00:00
|
|
|
<?php
|
2026-07-05 18:21:13 +00:00
|
|
|
echo htmlspecialchars((string)$ordre['isin']) . ' --- ' . htmlspecialchars((string)$ordre['Nom']) . ' ( ' . htmlspecialchars((string)$ordre['ticker']) . ' )';
|
2026-07-05 13:52:19 +00:00
|
|
|
?>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
|
|
|
|
|
<tr class="ordregf-detail-block">
|
2026-07-05 14:19:13 +00:00
|
|
|
<td colspan="11">
|
2026-07-05 13:52:19 +00:00
|
|
|
<table class="ordregf-detail-table">
|
|
|
|
|
<thead>
|
|
|
|
|
<tr>
|
|
|
|
|
<th>Date</th>
|
|
|
|
|
<th>Qté</th>
|
|
|
|
|
<th>Prix Brut</th>
|
|
|
|
|
<th>Frais</th>
|
|
|
|
|
<th>Prix Net</th>
|
2026-07-05 18:21:13 +00:00
|
|
|
<th>Engagement Brut</th>
|
|
|
|
|
<th>Engagement Net</th>
|
2026-07-05 13:52:19 +00:00
|
|
|
<th>Ordre</th>
|
|
|
|
|
<th>Type</th>
|
|
|
|
|
<th>Etat</th>
|
2026-07-05 18:21:13 +00:00
|
|
|
<th style="text-align: right;">
|
|
|
|
|
<button type="button"
|
|
|
|
|
class="ordregf-btn-petit ordregf-btn-creer-petit"
|
|
|
|
|
onclick="document.getElementById('Id_entete_detail').value='<?= $ordre['ID'] ?>'; document.getElementById('modalCreerDetail').showModal();">
|
|
|
|
|
Créer
|
|
|
|
|
</button>
|
|
|
|
|
</th>
|
2026-07-05 13:52:19 +00:00
|
|
|
</tr>
|
|
|
|
|
</thead>
|
|
|
|
|
<tbody>
|
|
|
|
|
<?php
|
|
|
|
|
$totalQ = 0;
|
|
|
|
|
$engaBrut = 0;
|
|
|
|
|
$engaNet = 0;
|
|
|
|
|
$details = fetchOrdreGFPied($connection, (string)$ordre['ID']);
|
|
|
|
|
|
|
|
|
|
foreach ($details as $detail):
|
|
|
|
|
$qte = (int)($detail['Quantite'] ?? 0);
|
|
|
|
|
$prix = (float)($detail['Prix_brut'] ?? 0);
|
|
|
|
|
$frais = (float)($detail['Frais_brocker'] ?? 0) + (float)($detail['Frais_etat'] ?? 0) + (float)($detail['Frais_autre'] ?? 0);
|
2026-07-05 18:21:13 +00:00
|
|
|
$prixNet = $prix + $frais;
|
2026-07-05 13:52:19 +00:00
|
|
|
$date = !empty($detail['Date_op']) ? date('d/m/Y', strtotime($detail['Date_op'])) : '--/--/----';
|
|
|
|
|
|
|
|
|
|
$ordre_type = strtolower($detail['Ordre'] ?? '');
|
|
|
|
|
$type_op = strtolower($detail['Type'] ?? '');
|
|
|
|
|
$etat = strtolower($detail['Etat'] ?? '');
|
|
|
|
|
|
|
|
|
|
if ($etat === 'actif') {
|
|
|
|
|
if ($type_op === 'long') {
|
|
|
|
|
if ($ordre_type === 'achat') {
|
|
|
|
|
$totalQ += $qte;
|
|
|
|
|
$engaBrut += $qte * $prix;
|
2026-07-05 18:21:13 +00:00
|
|
|
$engaNet += $qte * $prixNet;
|
2026-07-05 13:52:19 +00:00
|
|
|
} elseif ($ordre_type === 'vente') {
|
|
|
|
|
$totalQ -= $qte;
|
|
|
|
|
$engaBrut -= $qte * $prix;
|
2026-07-05 18:21:13 +00:00
|
|
|
$engaNet -= $qte * $prixNet;
|
2026-07-05 13:52:19 +00:00
|
|
|
}
|
|
|
|
|
} elseif ($type_op === 'short') {
|
|
|
|
|
if ($ordre_type === 'achat') {
|
|
|
|
|
$totalQ -= $qte;
|
|
|
|
|
$engaBrut -= $qte * $prix;
|
2026-07-05 18:21:13 +00:00
|
|
|
$engaNet -= $qte * $prixNet;
|
2026-07-05 13:52:19 +00:00
|
|
|
} elseif ($ordre_type === 'vente') {
|
|
|
|
|
$totalQ += $qte;
|
|
|
|
|
$engaBrut += $qte * $prix;
|
2026-07-05 18:21:13 +00:00
|
|
|
$engaNet += $qte * $prixNet;
|
2026-07-05 13:52:19 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
?>
|
|
|
|
|
<tr class="ordregf-detail-row">
|
|
|
|
|
<td><?= htmlspecialchars($date) ?></td>
|
|
|
|
|
<td class="text-right"><?= number_format($qte, 0, ',', ' ') ?></td>
|
|
|
|
|
<td class="text-right"><?= number_format($prix, 3, ',', ' ') ?></td>
|
|
|
|
|
<td class="text-right"><?= number_format($frais, 3, ',', ' ') ?></td>
|
|
|
|
|
<td class="text-right"><?= number_format($prixNet, 3, ',', ' ') ?></td>
|
2026-07-05 18:21:13 +00:00
|
|
|
<td class="text-right"><?= number_format($qte * $prix, 3, ',', ' ') ?></td>
|
|
|
|
|
<td class="text-right"><?= number_format($qte * $prixNet, 3, ',', ' ') ?></td>
|
2026-07-05 13:52:19 +00:00
|
|
|
<td><?= htmlspecialchars($detail['Ordre'] ?? '') ?></td>
|
|
|
|
|
<td><?= htmlspecialchars($detail['Type'] ?? '') ?></td>
|
|
|
|
|
<td><?= htmlspecialchars($detail['Etat'] ?? '') ?></td>
|
|
|
|
|
<td style="text-align: right;">
|
2026-07-05 14:19:13 +00:00
|
|
|
<button type="button" class="ordregf-btn-petit ordregf-btn-modifier-petit" data-detail='<?= json_encode($detail) ?>'>Modifier</button>
|
2026-07-05 13:52:19 +00:00
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<?php endforeach; ?>
|
|
|
|
|
|
2026-07-05 18:21:13 +00:00
|
|
|
<?php
|
|
|
|
|
// Calcul Plus-value
|
|
|
|
|
$isSold = ($totalQ === 0 && count($details) > 0);
|
|
|
|
|
$plusvalue = 0.0000;
|
|
|
|
|
if ($isSold) {
|
|
|
|
|
foreach ($details as $detail) {
|
|
|
|
|
$qte = (int)$detail['Quantite'];
|
|
|
|
|
$prixNet = (float)$detail['Prix_brut'] + (float)$detail['Frais_brocker'] + (float)$detail['Frais_etat'] + (float)$detail['Frais_autre'];
|
|
|
|
|
$eNet = round($qte * $prixNet, 4);
|
|
|
|
|
$oType = strtolower($detail['Ordre']);
|
|
|
|
|
$tOp = strtolower($detail['Type']);
|
|
|
|
|
|
|
|
|
|
// Logique plus claire
|
|
|
|
|
$signe = 0;
|
|
|
|
|
if ($tOp === 'long') {
|
|
|
|
|
$signe = ($oType === 'vente') ? 1 : -1;
|
|
|
|
|
} else { // short
|
|
|
|
|
$signe = ($oType === 'achat') ? 1 : -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$plusvalue += ($eNet * $signe);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// On arrondit le résultat final avant comparaison et insertion
|
|
|
|
|
$plusvalue = round($plusvalue, 4);
|
|
|
|
|
|
|
|
|
|
if (abs((float)$ordre['PlusValue'] - $plusvalue) > 0.0001) {
|
|
|
|
|
$connection->prepare("UPDATE ordreGF SET PlusValue = ? WHERE ID = ?")->execute([$plusvalue, $ordre['ID']]);
|
|
|
|
|
$connection->prepare("UPDATE ordreGF_pied SET Etat = 'soldé' WHERE Id_entete = ? AND Etat != 'soldé'")->execute([$ordre['ID']]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
?>
|
|
|
|
|
|
|
|
|
|
<?php if ($isSold): ?>
|
|
|
|
|
<tr style="background-color: rgba(255, 255, 255, 0.08); font-weight: bold;">
|
|
|
|
|
<td colspan="6" style="text-align: right;">Plus value :</td>
|
|
|
|
|
<td class="text-right" style="color: <?= $plusvalue < 0 ? 'red' : 'green' ?>;">
|
|
|
|
|
<?= number_format((float)($ordre['PlusValue'] ?: $plusvalue), 3, ',', ' ') ?>
|
|
|
|
|
</td>
|
|
|
|
|
<td colspan="4"></td>
|
|
|
|
|
</tr>
|
|
|
|
|
<?php else: ?>
|
|
|
|
|
<tr style="background-color: rgba(255, 255, 255, 0.08); font-weight: bold;">
|
|
|
|
|
<td style="text-align: right;">TOTAL :</td>
|
|
|
|
|
<td class="text-right"><?= number_format($totalQ, 0, ',', ' ') ?></td>
|
|
|
|
|
<td colspan="4"></td>
|
|
|
|
|
<td class="text-right"><?= number_format($engaBrut, 3, ',', ' ') ?></td>
|
|
|
|
|
<td class="text-right"><?= number_format($engaNet, 3, ',', ' ') ?></td>
|
|
|
|
|
<td colspan="4"></td>
|
|
|
|
|
</tr>
|
|
|
|
|
<?php endif; ?>
|
2026-07-05 13:52:19 +00:00
|
|
|
</tbody>
|
|
|
|
|
</table>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<?php endforeach; ?>
|
|
|
|
|
</tbody>
|
|
|
|
|
</table>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</section>
|
|
|
|
|
|
2026-07-05 18:21:13 +00:00
|
|
|
<!-- ... Modals et scripts ... -->
|
2026-07-05 14:19:13 +00:00
|
|
|
<dialog id="modalCreerOrdre" class="ordregf-modal">
|
|
|
|
|
<form id="formCreerOrdre">
|
|
|
|
|
<h2>Créer un nouvel ordre</h2>
|
|
|
|
|
<div class="form-group">
|
|
|
|
|
<label>ISIN :</label><br>
|
|
|
|
|
<input type="text" id="isinRecherche" required>
|
|
|
|
|
<button type="button" id="btnRechercher">Rechercher</button>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="form-group">
|
|
|
|
|
<label>Nom :</label><br>
|
|
|
|
|
<input type="text" name="Nom" id="Nom" readonly>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="form-group">
|
|
|
|
|
<label>Ticker :</label><br>
|
|
|
|
|
<input type="text" name="ticker" id="ticker" readonly>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="form-group">
|
|
|
|
|
<label>Code Yahoo :</label><br>
|
|
|
|
|
<input type="text" name="code_yahoo" id="code_yahoo" readonly>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="modal-actions" style="margin-top: 20px;">
|
|
|
|
|
<button type="button" id="btnAnnuler">Annuler</button>
|
|
|
|
|
<button type="submit" id="btnValider" disabled>Valider</button>
|
|
|
|
|
</div>
|
|
|
|
|
</form>
|
|
|
|
|
</dialog>
|
|
|
|
|
|
2026-07-05 18:21:13 +00:00
|
|
|
<dialog id="modalCreerDetail" class="ordregf-modal">
|
|
|
|
|
<form id="formCreerDetail">
|
|
|
|
|
<input type="hidden" name="Id_entete" id="Id_entete_detail">
|
|
|
|
|
<h2>Ajouter un mouvement</h2>
|
|
|
|
|
<div class="form-group">
|
|
|
|
|
<label>Date :</label><br>
|
|
|
|
|
<input type="date" name="Date_op" required>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="form-group">
|
|
|
|
|
<label>Quantité :</label><br>
|
|
|
|
|
<input type="number" name="Quantite" required>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="form-group">
|
|
|
|
|
<label>Prix Brut :</label><br>
|
|
|
|
|
<input type="number" step="0.001" name="Prix_brut" required>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="form-group">
|
|
|
|
|
<label>Frais (Broker / Etat / Autre) :</label><br>
|
|
|
|
|
<input type="number" step="0.01" name="Frais_brocker" placeholder="Broker">
|
|
|
|
|
<input type="number" step="0.01" name="Frais_etat" placeholder="Etat">
|
|
|
|
|
<input type="number" step="0.01" name="Frais_autre" placeholder="Autre">
|
|
|
|
|
</div>
|
|
|
|
|
<div class="form-group">
|
|
|
|
|
<label>Ordre (Achat/Vente) :</label>
|
|
|
|
|
<select name="Ordre">
|
|
|
|
|
<option value="Achat">Achat</option>
|
|
|
|
|
<option value="Vente">Vente</option>
|
|
|
|
|
</select>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="form-group">
|
|
|
|
|
<label>Type (Long/Short) :</label>
|
|
|
|
|
<select name="Type">
|
|
|
|
|
<option value="Long">Long</option>
|
|
|
|
|
<option value="Short">Short</option>
|
|
|
|
|
</select>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="form-group">
|
|
|
|
|
<label>Etat :</label>
|
|
|
|
|
<select name="Etat">
|
|
|
|
|
<option value="Actif">Actif</option>
|
|
|
|
|
<option value="Cloture">Cloture</option>
|
|
|
|
|
</select>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="modal-actions" style="margin-top: 20px;">
|
|
|
|
|
<button type="button" onclick="document.getElementById('modalCreerDetail').close()">Annuler</button>
|
|
|
|
|
<button type="submit">Valider</button>
|
|
|
|
|
</div>
|
|
|
|
|
</form>
|
|
|
|
|
</dialog>
|
|
|
|
|
|
2026-07-05 14:19:13 +00:00
|
|
|
<script src="/js/ordreGF.js" defer></script>
|
|
|
|
|
|
2026-07-05 13:52:19 +00:00
|
|
|
<?php require_once __DIR__ . '/footer.php'; ?>
|