formulaire ok sauf calcul totaux et btn modifier
This commit is contained in:
+29
-29
@@ -13,7 +13,6 @@ ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
|
||||
$pageStylesheets = ['/css/ordreGF.css'];
|
||||
$bodyClass = 'ordregf-page';
|
||||
|
||||
@@ -59,11 +58,27 @@ require_once __DIR__ . '/header.php';
|
||||
<table class="ordregf-table">
|
||||
<tbody>
|
||||
<?php foreach ($ordres as $ordre): ?>
|
||||
<?php
|
||||
// Pré-calcul pour les boutons
|
||||
$details = fetchOrdreGFPied($connection, (string)$ordre['ID']);
|
||||
$totalQ = 0;
|
||||
foreach ($details as $d) {
|
||||
$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));
|
||||
}
|
||||
}
|
||||
$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;"' : '';
|
||||
?>
|
||||
|
||||
<tr class="ordregf-master-row ordregf-header-style">
|
||||
<td colspan="11" style="font-weight: bold; font-size: 1.1em; color: #fff;">
|
||||
<?php
|
||||
echo htmlspecialchars((string)$ordre['isin']) . ' --- ' . htmlspecialchars((string)$ordre['Nom']) . ' ( ' . htmlspecialchars((string)$ordre['ticker']) . ' )';
|
||||
?>
|
||||
<?php echo htmlspecialchars((string)$ordre['isin']) . ' --- ' . htmlspecialchars((string)$ordre['Nom']) . ' ( ' . htmlspecialchars((string)$ordre['ticker']) . ' )'; ?>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@@ -83,8 +98,8 @@ require_once __DIR__ . '/header.php';
|
||||
<th>Type</th>
|
||||
<th>Etat</th>
|
||||
<th style="text-align: right;">
|
||||
<button type="button"
|
||||
class="ordregf-btn-petit ordregf-btn-creer-petit"
|
||||
<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>
|
||||
@@ -93,10 +108,8 @@ require_once __DIR__ . '/header.php';
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
$totalQ = 0;
|
||||
$engaBrut = 0;
|
||||
$engaNet = 0;
|
||||
$details = fetchOrdreGFPied($connection, (string)$ordre['ID']);
|
||||
|
||||
foreach ($details as $detail):
|
||||
$qte = (int)($detail['Quantite'] ?? 0);
|
||||
@@ -112,21 +125,17 @@ require_once __DIR__ . '/header.php';
|
||||
if ($etat === 'actif') {
|
||||
if ($type_op === 'long') {
|
||||
if ($ordre_type === 'achat') {
|
||||
$totalQ += $qte;
|
||||
$engaBrut += $qte * $prix;
|
||||
$engaNet += $qte * $prixNet;
|
||||
} elseif ($ordre_type === 'vente') {
|
||||
$totalQ -= $qte;
|
||||
} else {
|
||||
$engaBrut -= $qte * $prix;
|
||||
$engaNet -= $qte * $prixNet;
|
||||
}
|
||||
} elseif ($type_op === 'short') {
|
||||
if ($ordre_type === 'achat') {
|
||||
$totalQ -= $qte;
|
||||
$engaBrut -= $qte * $prix;
|
||||
$engaNet -= $qte * $prixNet;
|
||||
} elseif ($ordre_type === 'vente') {
|
||||
$totalQ += $qte;
|
||||
} else {
|
||||
$engaBrut += $qte * $prix;
|
||||
$engaNet += $qte * $prixNet;
|
||||
}
|
||||
@@ -145,14 +154,16 @@ require_once __DIR__ . '/header.php';
|
||||
<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" data-detail='<?= json_encode($detail) ?>'>Modifier</button>
|
||||
<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
|
||||
// Calcul Plus-value
|
||||
$isSold = ($totalQ === 0 && count($details) > 0);
|
||||
$plusvalue = 0.0000;
|
||||
if ($isSold) {
|
||||
foreach ($details as $detail) {
|
||||
@@ -161,21 +172,10 @@ require_once __DIR__ . '/header.php';
|
||||
$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;
|
||||
}
|
||||
|
||||
$signe = ($tOp === 'long') ? (($oType === 'vente') ? 1 : -1) : (($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']]);
|
||||
|
||||
Reference in New Issue
Block a user