WIP: tout fonctionne + corrections de bug
This commit is contained in:
@@ -227,3 +227,19 @@ body {
|
||||
width: 100%;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.ordregf-btn-petit {
|
||||
width: 90px;
|
||||
height: 30px;
|
||||
padding: 0 10px;
|
||||
font-size: 0.8em;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
box-sizing: border-box;
|
||||
transition: background 0.2s ease;
|
||||
}
|
||||
|
||||
+12
-1
@@ -97,7 +97,18 @@ document.addEventListener("DOMContentLoaded", () => {
|
||||
detail.Frais_etat || 0;
|
||||
document.getElementById("edit_frais_autre").value =
|
||||
detail.Frais_autre || 0;
|
||||
document.getElementById("edit_ordre").value = detail.Ordre;
|
||||
document.getElementById("edit_type").value = (
|
||||
detail.Type || ""
|
||||
).toLowerCase();
|
||||
|
||||
document.getElementById("edit_etat").value = (
|
||||
detail.Etat || ""
|
||||
).toLowerCase();
|
||||
|
||||
document.getElementById("edit_ordre").value = (
|
||||
detail.Ordre || ""
|
||||
).toLowerCase();
|
||||
|
||||
modal.showModal();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,10 +16,13 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
Frais_brocker = :f_b,
|
||||
Frais_etat = :f_e,
|
||||
Frais_autre = :f_a,
|
||||
Ordre = :ordre
|
||||
Ordre = :ordre,
|
||||
Type = :type,
|
||||
Etat = :etat
|
||||
WHERE Id = :id";
|
||||
|
||||
$stmt = $db->prepare($sql);
|
||||
|
||||
$stmt->execute([
|
||||
':date' => $_POST['Date_op'],
|
||||
':qte' => $_POST['Quantite'],
|
||||
@@ -28,11 +31,16 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
':f_e' => $_POST['Frais_etat'],
|
||||
':f_a' => $_POST['Frais_autre'],
|
||||
':ordre' => $_POST['Ordre'],
|
||||
':type' => $_POST['Type'],
|
||||
':etat' => $_POST['Etat'],
|
||||
':id' => $_POST['id']
|
||||
]);
|
||||
|
||||
echo json_encode(['success' => true]);
|
||||
} catch (Exception $e) {
|
||||
echo json_encode(['success' => false, 'message' => $e->getMessage()]);
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'message' => $e->getMessage()
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
+111
-96
@@ -9,9 +9,12 @@ if (empty($_SESSION['user_id'])) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/*A supprimer quand la page fonctionnera correctement*/
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
/**************************************************** */
|
||||
|
||||
|
||||
|
||||
$pageStylesheets = ['/css/ordreGF.css'];
|
||||
$bodyClass = 'ordregf-page';
|
||||
@@ -19,11 +22,9 @@ $bodyClass = 'ordregf-page';
|
||||
$database = new App\Database\Database();
|
||||
$connection = $database->getConnection();
|
||||
|
||||
// --- Fonctions ---
|
||||
function fetchOrdreGF(PDO $connection): array
|
||||
{
|
||||
$query = 'SELECT * FROM `ordreGF` ORDER BY `ID` DESC';
|
||||
$stmt = $connection->query($query);
|
||||
$stmt = $connection->query('SELECT * FROM `ordreGF` ORDER BY `ID` DESC');
|
||||
return $stmt->fetchAll(PDO::FETCH_ASSOC) ?: [];
|
||||
}
|
||||
|
||||
@@ -38,18 +39,14 @@ $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;">
|
||||
<button type="button" class="ordregf-btn-creer" onclick="document.getElementById('modalCreerOrdre').showModal();">
|
||||
Créer un ordre
|
||||
</button>
|
||||
<button type="button" class="ordregf-btn-menu" onclick="window.location.href='/php/menu.php';">
|
||||
Retour au menu
|
||||
</button>
|
||||
<button type="button" class="ordregf-btn-creer" onclick="document.getElementById('modalCreerOrdre').showModal();">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>
|
||||
|
||||
@@ -58,21 +55,77 @@ require_once __DIR__ . '/header.php';
|
||||
<tbody>
|
||||
<?php foreach ($ordres as $ordre): ?>
|
||||
<?php
|
||||
// Pré-calcul pour les boutons
|
||||
$details = fetchOrdreGFPied($connection, (string)$ordre['ID']);
|
||||
$totalQ = 0;
|
||||
|
||||
// Détection d'un ordre annulé
|
||||
$isCanceled = false;
|
||||
|
||||
foreach ($details as $d) {
|
||||
if (strtolower($d['Etat'] ?? '') === 'annulé') {
|
||||
$isCanceled = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 1. Calcul du total des quantités actives
|
||||
foreach ($details as $d) {
|
||||
if (strtolower($d['Etat'] ?? '') === 'actif') {
|
||||
$q = (int)($d['Quantite'] ?? 0);
|
||||
$oType = strtolower($d['Ordre'] ?? '');
|
||||
$tOp = strtolower($d['Type'] ?? '');
|
||||
if (strtolower($d['Etat'] ?? '') === 'actif') {
|
||||
$totalQ += ($tOp === 'long' ? ($oType === 'achat' ? $q : -$q) : ($oType === 'achat' ? -$q : $q));
|
||||
$signe = ($tOp === 'long') ? ($oType === 'achat' ? 1 : -1) : ($oType === 'achat' ? -1 : 1);
|
||||
$totalQ += ($q * $signe);
|
||||
}
|
||||
}
|
||||
$isSold = ($totalQ === 0 && count($details) > 0);
|
||||
// Désactiver si vendu OU si une plus-value existe déjà
|
||||
$isDisabled = $isSold || (isset($ordre['PlusValue']) && (float)$ordre['PlusValue'] !== 0.0);
|
||||
$disabledAttr = $isDisabled ? 'disabled style="opacity:0.5; cursor:not-allowed;"' : '';
|
||||
|
||||
|
||||
// 2. Calcul Plus-Value et Mise à jour statut
|
||||
$plusvalue = 0.0000;
|
||||
|
||||
if ($isCanceled) {
|
||||
$plusvalue = 0;
|
||||
|
||||
if ((float)$ordre['PlusValue'] != 0) {
|
||||
$connection->prepare(
|
||||
"UPDATE ordreGF SET PlusValue = 0 WHERE ID = ?"
|
||||
)->execute([$ordre['ID']]);
|
||||
|
||||
$ordre['PlusValue'] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$isSold = (!$isCanceled && $totalQ === 0 && count($details) > 0);
|
||||
|
||||
if ($isSold) {
|
||||
foreach ($details as $detail) {
|
||||
$qte = (int)$detail['Quantite'];
|
||||
$fraisDetail = (float)$detail['Frais_brocker'] + (float)$detail['Frais_etat'] + (float)$detail['Frais_autre'];
|
||||
$oType = strtolower($detail['Ordre']);
|
||||
$prixNet = ($oType === 'vente') ? (float)$detail['Prix_brut'] - $fraisDetail : (float)$detail['Prix_brut'] + $fraisDetail;
|
||||
$tOp = strtolower($detail['Type']);
|
||||
$signePV = ($oType === 'vente') ? 1 : -1;
|
||||
$plusvalue += ($qte * $prixNet * $signePV);
|
||||
}
|
||||
$plusvalue = round($plusvalue, 4);
|
||||
|
||||
// Mise à jour si la PlusValue n'est pas encore enregistrée en base (différente de 0)
|
||||
if (abs((float)$ordre['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']]);
|
||||
// On met à jour la valeur locale
|
||||
$ordre['PlusValue'] = $plusvalue;
|
||||
}
|
||||
}
|
||||
|
||||
// Désactivation si ordre soldé ou annulé
|
||||
$isDisabled = $isCanceled || abs((float)$ordre['PlusValue']) > 0.0001;
|
||||
|
||||
$disabledAttr = $isDisabled
|
||||
? 'disabled style="opacity:0.5; cursor:not-allowed;"'
|
||||
: '';
|
||||
?>
|
||||
|
||||
<tr class="ordregf-master-row ordregf-header-style">
|
||||
@@ -91,103 +144,50 @@ require_once __DIR__ . '/header.php';
|
||||
<th>Prix Brut</th>
|
||||
<th>Frais</th>
|
||||
<th>Prix Net</th>
|
||||
<th>Engagement Brut</th>
|
||||
<th>Engagement Net</th>
|
||||
<th>Eng. Brut</th>
|
||||
<th>Eng. Net</th>
|
||||
<th>Ordre</th>
|
||||
<th>Type</th>
|
||||
<th>Etat</th>
|
||||
<th style="text-align: right;">
|
||||
<button type="button" class="ordregf-btn-petit ordregf-btn-creer-petit"
|
||||
<?= $disabledAttr ?>
|
||||
onclick="document.getElementById('Id_entete_detail').value='<?= $ordre['ID'] ?>'; document.getElementById('modalCreerDetail').showModal();">
|
||||
Créer
|
||||
</button>
|
||||
</th>
|
||||
<th style="text-align: right;"><button type="button" class="ordregf-btn-creer-petit ordregf-btn-petit" <?= $disabledAttr ?> onclick="document.getElementById('Id_entete_detail').value='<?= $ordre['ID'] ?>'; document.getElementById('modalCreerDetail').showModal();">Créer</button></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
$engaBrut = 0;
|
||||
$engaNet = 0;
|
||||
|
||||
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);
|
||||
$prixNet = $prix + $frais;
|
||||
$ordreType = strtolower($detail['Ordre'] ?? '');
|
||||
$prixNet = ($ordreType === 'vente') ? $prix - $frais : $prix + $frais;
|
||||
$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') {
|
||||
$engaBrut += $qte * $prix;
|
||||
$engaNet += $qte * $prixNet;
|
||||
} else {
|
||||
$engaBrut -= $qte * $prix;
|
||||
$engaNet -= $qte * $prixNet;
|
||||
}
|
||||
} elseif ($type_op === 'short') {
|
||||
if ($ordre_type === 'achat') {
|
||||
$engaBrut -= $qte * $prix;
|
||||
$engaNet -= $qte * $prixNet;
|
||||
} else {
|
||||
$engaBrut += $qte * $prix;
|
||||
$engaNet += $qte * $prixNet;
|
||||
}
|
||||
}
|
||||
if (strtolower($detail['Etat'] ?? '') === 'actif') {
|
||||
$mult = (strtolower($detail['Type'] ?? '') === 'long' ? 1 : -1) * (strtolower($detail['Ordre'] ?? '') === 'achat' ? 1 : -1);
|
||||
$engaBrut += ($qte * $prix) * $mult;
|
||||
$engaNet += ($qte * $prixNet) * $mult;
|
||||
}
|
||||
?>
|
||||
<tr class="ordregf-detail-row">
|
||||
<tr>
|
||||
<td><?= htmlspecialchars($date) ?></td>
|
||||
<td class="text-right"><?= number_format($qte, 0, ',', ' ') ?></td>
|
||||
<td class="text-right"><?= $qte ?></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>
|
||||
<td class="text-right"><?= number_format($qte * $prix, 3, ',', ' ') ?></td>
|
||||
<td class="text-right"><?= number_format($qte * $prixNet, 3, ',', ' ') ?></td>
|
||||
<td><?= htmlspecialchars($detail['Ordre'] ?? '') ?></td>
|
||||
<td><?= htmlspecialchars($detail['Type'] ?? '') ?></td>
|
||||
<td><?= htmlspecialchars($detail['Etat'] ?? '') ?></td>
|
||||
<td style="text-align: right;">
|
||||
<button type="button" class="ordregf-btn-petit ordregf-btn-modifier-petit"
|
||||
<?= $disabledAttr ?>
|
||||
data-detail='<?= htmlspecialchars(json_encode($detail), ENT_QUOTES, 'UTF-8') ?>'>
|
||||
Modifier
|
||||
</button>
|
||||
</td>
|
||||
<td style="text-align: center"><?= htmlspecialchars($detail['Ordre'] ?? '') ?></td>
|
||||
<td style="text-align: center"><?= htmlspecialchars($detail['Type'] ?? '') ?></td>
|
||||
<td style="text-align: center"><?= htmlspecialchars($detail['Etat'] ?? '') ?></td>
|
||||
<td style="text-align: center"><button type=" button" class="ordregf-btn-petit ordregf-btn-modifier-petit" <?= $disabledAttr ?> data-detail='<?= htmlspecialchars(json_encode($detail), ENT_QUOTES, 'UTF-8') ?>'>Modifier</button></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
|
||||
<?php
|
||||
$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']);
|
||||
$signe = ($tOp === 'long') ? (($oType === 'vente') ? 1 : -1) : (($oType === 'achat') ? 1 : -1);
|
||||
$plusvalue += ($eNet * $signe);
|
||||
}
|
||||
$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): ?>
|
||||
<?php if ($isDisabled): ?>
|
||||
<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 style="color: <?= (float)$ordre['PlusValue'] < 0 ? 'red' : 'green' ?>;"><?= number_format((float)$ordre['PlusValue'], 3, ',', ' ') ?></td>
|
||||
<td colspan="4"></td>
|
||||
</tr>
|
||||
<?php else: ?>
|
||||
@@ -272,22 +272,22 @@ require_once __DIR__ . '/header.php';
|
||||
<div class="form-group">
|
||||
<label>Ordre (Achat/Vente) :</label>
|
||||
<select name="Ordre">
|
||||
<option value="Achat">Achat</option>
|
||||
<option value="Vente">Vente</option>
|
||||
<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>
|
||||
<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>
|
||||
<option value="actif">actif</option>
|
||||
<option value="annulé">annulé</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="modal-actions" style="margin-top: 20px;">
|
||||
@@ -323,8 +323,23 @@ require_once __DIR__ . '/header.php';
|
||||
<div class="form-group">
|
||||
<label>Ordre :</label>
|
||||
<select name="Ordre" id="edit_ordre">
|
||||
<option value="Achat">Achat</option>
|
||||
<option value="Vente">Vente</option>
|
||||
<option value="achat">achat</option>
|
||||
<option value="vente">vente</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Type :</label>
|
||||
<select name="Type" id="edit_type">
|
||||
<option value="long">long</option>
|
||||
<option value="short">short</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>Etat :</label>
|
||||
<select name="Etat" id="edit_etat">
|
||||
<option value="actif">actif</option>
|
||||
<option value="annulé">annulé</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="modal-actions" style="margin-top: 20px;">
|
||||
|
||||
Reference in New Issue
Block a user