menu actions operationnel
This commit is contained in:
+159
@@ -0,0 +1,159 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
require_once __DIR__ . '/session.php';
|
||||
require_once __DIR__ . '/db.php';
|
||||
|
||||
// Redirection si l'utilisateur n'est pas authentifié.
|
||||
if (empty($_SESSION['user_id'])) {
|
||||
header('Location: ../index.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
$pageStylesheets = ['/css/actions.css'];
|
||||
$bodyClass = 'actions-page';
|
||||
|
||||
$database = new App\Database\Database();
|
||||
$actionsManager = new App\Database\ActionsManager($database);
|
||||
|
||||
// Traitement du formulaire d'ajout d'une nouvelle action.
|
||||
$creationMessage = null;
|
||||
$creationError = null;
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action_create'])) {
|
||||
$newAction = [
|
||||
'isin' => trim($_POST['isin'] ?? ''),
|
||||
'ticker' => trim($_POST['ticker'] ?? ''),
|
||||
'yahoo_code' => trim($_POST['yahoo_code'] ?? ''),
|
||||
'company_name' => trim($_POST['company_name'] ?? ''),
|
||||
];
|
||||
|
||||
if ($newAction['isin'] === '' || $newAction['ticker'] === '' || $newAction['company_name'] === '') {
|
||||
$creationError = 'Veuillez remplir tous les champs obligatoires.';
|
||||
} else {
|
||||
if ($actionsManager->createAction($newAction)) {
|
||||
$creationMessage = 'Nouvelle action ajoutée avec succès.';
|
||||
} else {
|
||||
$creationError = 'Impossible d’ajouter l’action, veuillez réessayer.';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Traitement du formulaire de mise à jour d'une action.
|
||||
$updateMessage = null;
|
||||
$updateError = null;
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action_update'], $_POST['action_isin'])) {
|
||||
$actionIsin = trim($_POST['action_isin']);
|
||||
$updateData = [
|
||||
'ticker' => trim($_POST['ticker'] ?? ''),
|
||||
'yahoo_code' => trim($_POST['yahoo_code'] ?? ''),
|
||||
'company_name' => trim($_POST['company_name'] ?? ''),
|
||||
];
|
||||
|
||||
if ($actionIsin === '' || $updateData['ticker'] === '' || $updateData['company_name'] === '') {
|
||||
$updateError = 'Tous les champs requis doivent être remplis pour mettre à jour cette action.';
|
||||
} else {
|
||||
if ($actionsManager->updateAction($actionIsin, $updateData)) {
|
||||
$updateMessage = 'Action mise à jour avec succès.';
|
||||
} else {
|
||||
$updateError = 'Impossible de mettre à jour l’action. Vérifiez les données et réessayez.';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$actions = $actionsManager->listActions();
|
||||
|
||||
require_once __DIR__ . '/header.php';
|
||||
?>
|
||||
|
||||
<section class="actions-shell">
|
||||
<div class="actions-container">
|
||||
<div class="actions-header">
|
||||
<h1 class="actions-title">Actions financières</h1>
|
||||
<a href="/php/menu.php" class="action-button">Retour au menu</a>
|
||||
</div>
|
||||
|
||||
<?php if ($creationMessage): ?>
|
||||
<div class="actions-card action-notice action-success"><?= htmlspecialchars($creationMessage, ENT_QUOTES, 'UTF-8') ?></div>
|
||||
<?php endif; ?>
|
||||
<?php if ($creationError): ?>
|
||||
<div class="actions-card action-notice action-error"><?= htmlspecialchars($creationError, ENT_QUOTES, 'UTF-8') ?></div>
|
||||
<?php endif; ?>
|
||||
<?php if ($updateMessage): ?>
|
||||
<div class="actions-card action-notice action-success"><?= htmlspecialchars($updateMessage, ENT_QUOTES, 'UTF-8') ?></div>
|
||||
<?php endif; ?>
|
||||
<?php if ($updateError): ?>
|
||||
<div class="actions-card action-notice action-error"><?= htmlspecialchars($updateError, ENT_QUOTES, 'UTF-8') ?></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<section class="actions-panel" id="formulaire-creation">
|
||||
<form id="action-form" method="post" action="" autocomplete="off">
|
||||
<input type="hidden" name="action_isin" value="">
|
||||
<div class="action-form-row">
|
||||
<label class="field-isin">
|
||||
ISIN
|
||||
<input id="action-isin" type="text" name="isin" placeholder="Ex. FR0000123456" required>
|
||||
</label>
|
||||
<label class="field-ticker">
|
||||
Symbole
|
||||
<input id="action-ticker" type="text" name="ticker" placeholder="EXA" required>
|
||||
</label>
|
||||
<label class="field-yahoo">
|
||||
Code Yahoo
|
||||
<input id="action-yahoo_code" type="text" name="yahoo_code" placeholder="EXA.PA" required>
|
||||
</label>
|
||||
<label class="field-company">
|
||||
Société
|
||||
<input id="action-company_name" type="text" name="company_name" placeholder="Société Alpha" required>
|
||||
</label>
|
||||
</div>
|
||||
<div id="action-form-feedback" class="form-error" aria-live="polite" style="display:none;"></div>
|
||||
<div class="actions-panel-footer">
|
||||
<button type="submit" name="action_create" class="btn-action btn-primary create-button">Créer une action</button>
|
||||
<button type="submit" name="action_update" class="btn-action btn-primary update-button" hidden>Modifier l'action</button>
|
||||
<button type="button" class="btn-action btn-cancel cancel-edit-button" hidden>Annuler</button>
|
||||
</div>
|
||||
</form>
|
||||
</section>
|
||||
|
||||
<section class="actions-card table-container">
|
||||
<div class="actions-table-wrapper">
|
||||
<table class="actions-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ISIN</th>
|
||||
<th>Symbole</th>
|
||||
<th>Code Yahoo</th>
|
||||
<th>Société</th>
|
||||
<th>Mise à jour</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($actions as $action): ?>
|
||||
<tr class="action-row"
|
||||
data-isin="<?= htmlspecialchars((string) $action['isin'], ENT_QUOTES, 'UTF-8') ?>"
|
||||
data-ticker="<?= htmlspecialchars((string) $action['ticker'], ENT_QUOTES, 'UTF-8') ?>"
|
||||
data-yahoo_code="<?= htmlspecialchars((string) $action['yahoo_code'], ENT_QUOTES, 'UTF-8') ?>"
|
||||
data-company_name="<?= htmlspecialchars((string) $action['company_name'], ENT_QUOTES, 'UTF-8') ?>"
|
||||
>
|
||||
<td><?= htmlspecialchars((string) $action['isin'], ENT_QUOTES, 'UTF-8') ?></td>
|
||||
<td><?= htmlspecialchars((string) $action['ticker'], ENT_QUOTES, 'UTF-8') ?></td>
|
||||
<td><?= htmlspecialchars((string) $action['yahoo_code'], ENT_QUOTES, 'UTF-8') ?></td>
|
||||
<td><?= htmlspecialchars((string) $action['company_name'], ENT_QUOTES, 'UTF-8') ?></td>
|
||||
<td><?= htmlspecialchars((string) $action['updated_at'], ENT_QUOTES, 'UTF-8') ?></td>
|
||||
<td>
|
||||
<button type="button" class="btn-action btn-edit edit-action-button">Modifier</button>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<script src="/js/actions.js" defer></script>
|
||||
|
||||
<?php require_once __DIR__ . '/footer.php'; ?>
|
||||
+100
@@ -364,3 +364,103 @@ class LoginManager
|
||||
return $statement->execute();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Class ActionsManager
|
||||
*
|
||||
* Opérations CRUD sur la table `actions`.
|
||||
*/
|
||||
class ActionsManager
|
||||
{
|
||||
private PDO $connection;
|
||||
|
||||
public function __construct(Database $database)
|
||||
{
|
||||
$this->connection = $database->getConnection();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retourne toutes les actions.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function listActions(): array
|
||||
{
|
||||
$statement = $this->connection->query(
|
||||
'SELECT isin, ticker, yahoo_code, company_name, updated_at
|
||||
FROM actions
|
||||
ORDER BY updated_at DESC'
|
||||
);
|
||||
|
||||
return $statement->fetchAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retourne une action par son ISIN.
|
||||
*
|
||||
* @param string $isin
|
||||
* @return array|null
|
||||
*/
|
||||
public function getActionByIsin(string $isin): ?array
|
||||
{
|
||||
$statement = $this->connection->prepare(
|
||||
'SELECT isin, ticker, yahoo_code, company_name, updated_at
|
||||
FROM actions
|
||||
WHERE isin = :isin'
|
||||
);
|
||||
|
||||
$statement->bindValue(':isin', $isin, PDO::PARAM_STR);
|
||||
$statement->execute();
|
||||
|
||||
$result = $statement->fetch();
|
||||
|
||||
return $result === false ? null : $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Crée une nouvelle action.
|
||||
*
|
||||
* @param array $data
|
||||
* @return bool
|
||||
*/
|
||||
public function createAction(array $data): bool
|
||||
{
|
||||
$statement = $this->connection->prepare(
|
||||
'INSERT INTO actions (isin, ticker, yahoo_code, company_name, updated_at)
|
||||
VALUES (:isin, :ticker, :yahoo_code, :company_name, NOW())'
|
||||
);
|
||||
|
||||
$statement->bindValue(':isin', $data['isin'], PDO::PARAM_STR);
|
||||
$statement->bindValue(':ticker', $data['ticker'], PDO::PARAM_STR);
|
||||
$statement->bindValue(':yahoo_code', $data['yahoo_code'], PDO::PARAM_STR);
|
||||
$statement->bindValue(':company_name', $data['company_name'], PDO::PARAM_STR);
|
||||
|
||||
return $statement->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Met à jour une action.
|
||||
*
|
||||
* @param string $isin
|
||||
* @param array $data
|
||||
* @return bool
|
||||
*/
|
||||
public function updateAction(string $isin, array $data): bool
|
||||
{
|
||||
$statement = $this->connection->prepare(
|
||||
'UPDATE actions
|
||||
SET ticker = :ticker,
|
||||
yahoo_code = :yahoo_code,
|
||||
company_name = :company_name,
|
||||
updated_at = NOW()
|
||||
WHERE isin = :isin'
|
||||
);
|
||||
|
||||
$statement->bindValue(':ticker', $data['ticker'], PDO::PARAM_STR);
|
||||
$statement->bindValue(':yahoo_code', $data['yahoo_code'], PDO::PARAM_STR);
|
||||
$statement->bindValue(':company_name', $data['company_name'], PDO::PARAM_STR);
|
||||
$statement->bindValue(':isin', $isin, PDO::PARAM_STR);
|
||||
|
||||
return $statement->execute();
|
||||
}
|
||||
}
|
||||
|
||||
+6
-6
@@ -31,7 +31,7 @@ require_once __DIR__ . '/header.php';
|
||||
<button type="button" class="menu-button" data-target="/php/order_gf.php">
|
||||
<div class="menu-button__content">
|
||||
<span class="menu-button__title">Ordre GF</span>
|
||||
<span class="menu-button__text">Envoyer un ordre GF</span>
|
||||
<span class="menu-button__text">Voir et modifier les ordres GF</span>
|
||||
</div>
|
||||
<span class="menu-button__icon">⇄</span>
|
||||
</button>
|
||||
@@ -39,7 +39,7 @@ require_once __DIR__ . '/header.php';
|
||||
<button type="button" class="menu-button" data-target="/php/order_jfg.php">
|
||||
<div class="menu-button__content">
|
||||
<span class="menu-button__title">Ordre JFG</span>
|
||||
<span class="menu-button__text">Envoyer un ordre JFG</span>
|
||||
<span class="menu-button__text">Voir et modifier les ordres JFG</span>
|
||||
</div>
|
||||
<span class="menu-button__icon">↻</span>
|
||||
</button>
|
||||
@@ -47,7 +47,7 @@ require_once __DIR__ . '/header.php';
|
||||
<button type="button" class="menu-button" data-target="/php/account_gf.php">
|
||||
<div class="menu-button__content">
|
||||
<span class="menu-button__title">Compte GF</span>
|
||||
<span class="menu-button__text">Consulter le compte GF</span>
|
||||
<span class="menu-button__text">Voir et modifier le compte GF</span>
|
||||
</div>
|
||||
<span class="menu-button__icon">💼</span>
|
||||
</button>
|
||||
@@ -55,7 +55,7 @@ require_once __DIR__ . '/header.php';
|
||||
<button type="button" class="menu-button" data-target="/php/account_jfg.php">
|
||||
<div class="menu-button__content">
|
||||
<span class="menu-button__title">Compte JFG</span>
|
||||
<span class="menu-button__text">Consulter le compte JFG</span>
|
||||
<span class="menu-button__text">Voir et modifier le compte JFG</span>
|
||||
</div>
|
||||
<span class="menu-button__icon">📊</span>
|
||||
</button>
|
||||
@@ -63,7 +63,7 @@ require_once __DIR__ . '/header.php';
|
||||
<button type="button" class="menu-button" data-target="/php/actions.php">
|
||||
<div class="menu-button__content">
|
||||
<span class="menu-button__title">Actions</span>
|
||||
<span class="menu-button__text">Voir les actions et transactions</span>
|
||||
<span class="menu-button__text">Créer, voir et modifier les actions</span>
|
||||
</div>
|
||||
<span class="menu-button__icon">⚡</span>
|
||||
</button>
|
||||
@@ -71,7 +71,7 @@ require_once __DIR__ . '/header.php';
|
||||
<button type="button" class="menu-button" data-target="/php/csv.php">
|
||||
<div class="menu-button__content">
|
||||
<span class="menu-button__title">CSV</span>
|
||||
<span class="menu-button__text">Importer / exporter les données</span>
|
||||
<span class="menu-button__text">Importer / exporter les actions</span>
|
||||
</div>
|
||||
<span class="menu-button__icon">📁</span>
|
||||
</button>
|
||||
|
||||
Reference in New Issue
Block a user