diff --git a/css/ordreGF.css b/css/ordreGF.css index de29d61..3b369e6 100644 --- a/css/ordreGF.css +++ b/css/ordreGF.css @@ -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; +} diff --git a/js/ordreGF.js b/js/ordreGF.js index 51c7240..4a36918 100644 --- a/js/ordreGF.js +++ b/js/ordreGF.js @@ -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(); } } diff --git a/php/api_modifier_detail.php b/php/api_modifier_detail.php index eaad975..5206f53 100644 --- a/php/api_modifier_detail.php +++ b/php/api_modifier_detail.php @@ -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() + ]); } } diff --git a/php/ordreGF.php b/php/ordreGF.php index b5dd552..fced2fe 100644 --- a/php/ordreGF.php +++ b/php/ordreGF.php @@ -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'; ?> +

Gestion des ordres GF

-
- - + +
@@ -58,21 +55,77 @@ require_once __DIR__ . '/header.php'; 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;"' : ''; + + + // 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'] ?? ''); + $signe = ($tOp === 'long') ? ($oType === 'achat' ? 1 : -1) : ($oType === 'achat' ? -1 : 1); + $totalQ += ($q * $signe); + } + } + + + // 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;"' + : ''; ?> @@ -91,103 +144,50 @@ require_once __DIR__ . '/header.php'; Prix Brut Frais Prix Net - Engagement Brut - Engagement Net + Eng. Brut + Eng. Net Ordre Type Etat - - - + - + - + - - - - - - + + + + - 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']]); - } - } - ?> - - + Plus value : - - - + @@ -272,22 +272,22 @@ require_once __DIR__ . '/header.php';