formulaire ok pour tout sauf btn modifier
This commit is contained in:
@@ -45,3 +45,30 @@ document.addEventListener("DOMContentLoaded", () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Dans js/ordreGF.js
|
||||||
|
window.ouvrirModalCreation = function (masterId) {
|
||||||
|
// Optionnel : stocker l'ID dans un champ caché de votre formulaire
|
||||||
|
let inputHidden = document.getElementById("Id_entete_hidden");
|
||||||
|
if (inputHidden) inputHidden.value = masterId;
|
||||||
|
|
||||||
|
document.getElementById("modalCreerOrdre").showModal();
|
||||||
|
};
|
||||||
|
|
||||||
|
document
|
||||||
|
.getElementById("formCreerDetail")
|
||||||
|
.addEventListener("submit", async (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
const formData = new FormData(e.target);
|
||||||
|
|
||||||
|
const response = await fetch("/php/api_enregistrer_detail.php", {
|
||||||
|
method: "POST",
|
||||||
|
body: formData,
|
||||||
|
});
|
||||||
|
|
||||||
|
if ((await response.json()).success) {
|
||||||
|
location.reload();
|
||||||
|
} else {
|
||||||
|
alert("Erreur lors de l'enregistrement du détail");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__ . '/db.php';
|
||||||
|
$db = (new App\Database\Database())->getConnection();
|
||||||
|
|
||||||
|
$stmt = $db->prepare("INSERT INTO ordreGF_pied
|
||||||
|
(Id_entete, Date_op, Quantite, Prix_brut, Frais_brocker, Frais_etat, Frais_autre, Ordre, Type, Etat)
|
||||||
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
|
||||||
|
|
||||||
|
$success = $stmt->execute([
|
||||||
|
$_POST['Id_entete'],
|
||||||
|
$_POST['Date_op'],
|
||||||
|
$_POST['Quantite'],
|
||||||
|
$_POST['Prix_brut'],
|
||||||
|
$_POST['Frais_brocker'],
|
||||||
|
$_POST['Frais_etat'],
|
||||||
|
$_POST['Frais_autre'],
|
||||||
|
$_POST['Ordre'],
|
||||||
|
$_POST['Type'],
|
||||||
|
$_POST['Etat']
|
||||||
|
]);
|
||||||
|
|
||||||
|
echo json_encode(['success' => $success]);
|
||||||
+119
-18
@@ -9,6 +9,11 @@ if (empty($_SESSION['user_id'])) {
|
|||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ini_set('display_errors', 1);
|
||||||
|
ini_set('display_startup_errors', 1);
|
||||||
|
error_reporting(E_ALL);
|
||||||
|
|
||||||
|
|
||||||
$pageStylesheets = ['/css/ordreGF.css'];
|
$pageStylesheets = ['/css/ordreGF.css'];
|
||||||
$bodyClass = 'ordregf-page';
|
$bodyClass = 'ordregf-page';
|
||||||
|
|
||||||
@@ -55,18 +60,14 @@ require_once __DIR__ . '/header.php';
|
|||||||
<tbody>
|
<tbody>
|
||||||
<?php foreach ($ordres as $ordre): ?>
|
<?php foreach ($ordres as $ordre): ?>
|
||||||
<tr class="ordregf-master-row ordregf-header-style">
|
<tr class="ordregf-master-row ordregf-header-style">
|
||||||
<!-- Corrigé à 11 pour couvrir toutes les colonnes -->
|
|
||||||
<td colspan="11" style="font-weight: bold; font-size: 1.1em; color: #fff;">
|
<td colspan="11" style="font-weight: bold; font-size: 1.1em; color: #fff;">
|
||||||
<?php
|
<?php
|
||||||
echo htmlspecialchars((string)$ordre['isin']) . ' --- ' .
|
echo htmlspecialchars((string)$ordre['isin']) . ' --- ' . htmlspecialchars((string)$ordre['Nom']) . ' ( ' . htmlspecialchars((string)$ordre['ticker']) . ' )';
|
||||||
htmlspecialchars((string)$ordre['Nom']) . ' ( ' .
|
|
||||||
htmlspecialchars((string)$ordre['ticker']) . ' )';
|
|
||||||
?>
|
?>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
<tr class="ordregf-detail-block">
|
<tr class="ordregf-detail-block">
|
||||||
<!-- Corrigé à 11 -->
|
|
||||||
<td colspan="11">
|
<td colspan="11">
|
||||||
<table class="ordregf-detail-table">
|
<table class="ordregf-detail-table">
|
||||||
<thead>
|
<thead>
|
||||||
@@ -76,12 +77,18 @@ require_once __DIR__ . '/header.php';
|
|||||||
<th>Prix Brut</th>
|
<th>Prix Brut</th>
|
||||||
<th>Frais</th>
|
<th>Frais</th>
|
||||||
<th>Prix Net</th>
|
<th>Prix Net</th>
|
||||||
<th>Eng. Brut</th>
|
<th>Engagement Brut</th>
|
||||||
<th>Eng. Net</th>
|
<th>Engagement Net</th>
|
||||||
<th>Ordre</th>
|
<th>Ordre</th>
|
||||||
<th>Type</th>
|
<th>Type</th>
|
||||||
<th>Etat</th>
|
<th>Etat</th>
|
||||||
<th style="text-align: right;">Actions</th>
|
<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>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@@ -95,7 +102,7 @@ require_once __DIR__ . '/header.php';
|
|||||||
$qte = (int)($detail['Quantite'] ?? 0);
|
$qte = (int)($detail['Quantite'] ?? 0);
|
||||||
$prix = (float)($detail['Prix_brut'] ?? 0);
|
$prix = (float)($detail['Prix_brut'] ?? 0);
|
||||||
$frais = (float)($detail['Frais_brocker'] ?? 0) + (float)($detail['Frais_etat'] ?? 0) + (float)($detail['Frais_autre'] ?? 0);
|
$frais = (float)($detail['Frais_brocker'] ?? 0) + (float)($detail['Frais_etat'] ?? 0) + (float)($detail['Frais_autre'] ?? 0);
|
||||||
$prixNet = $prix + ($qte != 0 ? ($frais / $qte) : 0);
|
$prixNet = $prix + $frais;
|
||||||
$date = !empty($detail['Date_op']) ? date('d/m/Y', strtotime($detail['Date_op'])) : '--/--/----';
|
$date = !empty($detail['Date_op']) ? date('d/m/Y', strtotime($detail['Date_op'])) : '--/--/----';
|
||||||
|
|
||||||
$ordre_type = strtolower($detail['Ordre'] ?? '');
|
$ordre_type = strtolower($detail['Ordre'] ?? '');
|
||||||
@@ -107,21 +114,21 @@ require_once __DIR__ . '/header.php';
|
|||||||
if ($ordre_type === 'achat') {
|
if ($ordre_type === 'achat') {
|
||||||
$totalQ += $qte;
|
$totalQ += $qte;
|
||||||
$engaBrut += $qte * $prix;
|
$engaBrut += $qte * $prix;
|
||||||
$engaNet += ($qte * $prix) + $frais;
|
$engaNet += $qte * $prixNet;
|
||||||
} elseif ($ordre_type === 'vente') {
|
} elseif ($ordre_type === 'vente') {
|
||||||
$totalQ -= $qte;
|
$totalQ -= $qte;
|
||||||
$engaBrut -= $qte * $prix;
|
$engaBrut -= $qte * $prix;
|
||||||
$engaNet -= ($qte * $prix) + $frais;
|
$engaNet -= $qte * $prixNet;
|
||||||
}
|
}
|
||||||
} elseif ($type_op === 'short') {
|
} elseif ($type_op === 'short') {
|
||||||
if ($ordre_type === 'achat') {
|
if ($ordre_type === 'achat') {
|
||||||
$totalQ -= $qte;
|
$totalQ -= $qte;
|
||||||
$engaBrut -= $qte * $prix;
|
$engaBrut -= $qte * $prix;
|
||||||
$engaNet -= ($qte * $prix) + $frais;
|
$engaNet -= $qte * $prixNet;
|
||||||
} elseif ($ordre_type === 'vente') {
|
} elseif ($ordre_type === 'vente') {
|
||||||
$totalQ += $qte;
|
$totalQ += $qte;
|
||||||
$engaBrut += $qte * $prix;
|
$engaBrut += $qte * $prix;
|
||||||
$engaNet += ($qte * $prix) + $frais;
|
$engaNet += $qte * $prixNet;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -132,8 +139,8 @@ require_once __DIR__ . '/header.php';
|
|||||||
<td class="text-right"><?= number_format($prix, 3, ',', ' ') ?></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($frais, 3, ',', ' ') ?></td>
|
||||||
<td class="text-right"><?= number_format($prixNet, 3, ',', ' ') ?></td>
|
<td class="text-right"><?= number_format($prixNet, 3, ',', ' ') ?></td>
|
||||||
<td class="text-right"><?= number_format($qte * $prix, 2, ',', ' ') ?></td>
|
<td class="text-right"><?= number_format($qte * $prix, 3, ',', ' ') ?></td>
|
||||||
<td class="text-right"><?= number_format(($qte * $prix) + $frais, 2, ',', ' ') ?></td>
|
<td class="text-right"><?= number_format($qte * $prixNet, 3, ',', ' ') ?></td>
|
||||||
<td><?= htmlspecialchars($detail['Ordre'] ?? '') ?></td>
|
<td><?= htmlspecialchars($detail['Ordre'] ?? '') ?></td>
|
||||||
<td><?= htmlspecialchars($detail['Type'] ?? '') ?></td>
|
<td><?= htmlspecialchars($detail['Type'] ?? '') ?></td>
|
||||||
<td><?= htmlspecialchars($detail['Etat'] ?? '') ?></td>
|
<td><?= htmlspecialchars($detail['Etat'] ?? '') ?></td>
|
||||||
@@ -143,14 +150,57 @@ require_once __DIR__ . '/header.php';
|
|||||||
</tr>
|
</tr>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
|
|
||||||
|
<?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;">
|
<tr style="background-color: rgba(255, 255, 255, 0.08); font-weight: bold;">
|
||||||
<td style="text-align: right;">TOTAL :</td>
|
<td style="text-align: right;">TOTAL :</td>
|
||||||
<td class="text-right"><?= number_format($totalQ, 0, ',', ' ') ?></td>
|
<td class="text-right"><?= number_format($totalQ, 0, ',', ' ') ?></td>
|
||||||
<td colspan="3"></td>
|
<td colspan="4"></td>
|
||||||
<td class="text-right"><?= number_format($engaBrut, 2, ',', ' ') ?></td>
|
<td class="text-right"><?= number_format($engaBrut, 3, ',', ' ') ?></td>
|
||||||
<td class="text-right"><?= number_format($engaNet, 2, ',', ' ') ?></td>
|
<td class="text-right"><?= number_format($engaNet, 3, ',', ' ') ?></td>
|
||||||
<td colspan="4"></td>
|
<td colspan="4"></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<?php endif; ?>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</td>
|
</td>
|
||||||
@@ -162,6 +212,7 @@ require_once __DIR__ . '/header.php';
|
|||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
<!-- ... Modals et scripts ... -->
|
||||||
<dialog id="modalCreerOrdre" class="ordregf-modal">
|
<dialog id="modalCreerOrdre" class="ordregf-modal">
|
||||||
<form id="formCreerOrdre">
|
<form id="formCreerOrdre">
|
||||||
<h2>Créer un nouvel ordre</h2>
|
<h2>Créer un nouvel ordre</h2>
|
||||||
@@ -189,6 +240,56 @@ require_once __DIR__ . '/header.php';
|
|||||||
</form>
|
</form>
|
||||||
</dialog>
|
</dialog>
|
||||||
|
|
||||||
|
<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>
|
||||||
|
|
||||||
<script src="/js/ordreGF.js" defer></script>
|
<script src="/js/ordreGF.js" defer></script>
|
||||||
|
|
||||||
<?php require_once __DIR__ . '/footer.php'; ?>
|
<?php require_once __DIR__ . '/footer.php'; ?>
|
||||||
Reference in New Issue
Block a user