Skip to content

Commit

Permalink
Fix de plusieurs bugs dans les reboursements
Browse files Browse the repository at this point in the history
Les vérifications, saisies des remboursements étaient impacté.
J'ai reussi à factoriser du code serveur de remboursement et de ventes.

Voir :

- <#354>
- <#351>

Liée à :
- <#352>
  • Loading branch information
darnuria committed Nov 19, 2018
1 parent 9debabf commit bfdb31d
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 47 deletions.
31 changes: 31 additions & 0 deletions core/requetes.php
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,37 @@ function data_graphs_from_bilan(array $bilan, string $key): array {
return ['data' => $data, 'colors' => $colors];
}

/// Fonction servant à obtenir le détail d'une vente ou
/// d'un remboursement identifié par son Id vente.
function vendu_by_id_vente(PDO $bdd, int $id_vente): array {
$req = $bdd->prepare('SELECT
vendus.id,
vendus.id_vente,
vendus.timestamp,
vendus.quantite,
vendus.prix,
vendus.remboursement,
vendus.id_createur,
vendus.id_last_hero,
vendus.last_hero_timestamp,
type_dechets.nom type,
CASE WHEN vendus.id_objet > 0 THEN grille_objets.nom ELSE "autre" END objet,
pesees_vendus.masse
FROM vendus
INNER JOIN type_dechets
ON type_dechets.id = vendus.id_type_dechet
left JOIN grille_objets
ON grille_objets.id = vendus.id_objet
LEFT JOIN pesees_vendus
ON pesees_vendus.id = vendus.id_vente
WHERE vendus.id_vente = :id_vente');
$req->bindParam(':id_vente', $id_vente, PDO::PARAM_INT);
$req->execute();
$vendus = $req->fetchAll(PDO::FETCH_ASSOC);
$req->closeCursor();
return $vendus;
}

function vendus_case_lot_unit(): string {
return "case when vendus.lot > 0
then vendus.prix
Expand Down
26 changes: 7 additions & 19 deletions ifaces/modification_verification_remboursement.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,15 @@
require_once '../core/requetes.php';
require_once '../core/session.php';

if (is_valid_session() === 'oressource' && is_allowed_verifications()) {
if (is_valid_session() && is_allowed_verifications()) {
require_once '../moteur/dbconfig.php';
require_once 'tete.php';

$users = map_by(utilisateurs($bdd), 'id');

$id = $_GET['nvente'];
$req = $bdd->prepare('SELECT
vendus.id,
vendus.timestamp,
type_dechets.nom type,
grille_objets.nom objet,
vendus.remboursement,
vendus.quantite,
FROM vendus, type_dechets, grille_objets
WHERE vendus.id_vente = :id_vente
AND grille_objets.id = vendus.id_objet
AND type_dechets.id = vendus.id_type_dechet');
$req->execute(['id_vente' => $id]);
$rembs = $req->fetchAll(PDO::FETCH_ASSOC);
$req->closeCursor();
$rembs = vendu_by_id_vente($bdd, $id);

require_once 'tete.php';
?>
<div class="container">
<h1>Modifier le remboursement n° <?= $_GET['nvente']; ?></h1>
Expand Down Expand Up @@ -76,7 +64,7 @@
<td><?= $r['objet']; ?></td>
<td><?= $r['quantite']; ?></td>
<td><?= $r['remboursement']; ?></td>
<td><?= $users[$v['id_createur']]['mail'] ?></td>
<td><?= $users[$r['id_createur']]['mail'] ?></td>
<td><form action="modification_verification_objet_remboursement.php" method="post">
<input type="hidden" name="id" value="<?= $r['id']; ?>">
<input type="hidden" name="nvente" value="<?= $id ?>">
Expand All @@ -87,8 +75,8 @@
<input type="hidden" name="npoint" value="<?= $_POST['npoint']; ?>">
<button class="btn btn-warning btn-sm">Modifier</button>
</form>
<td><?= $v['last_hero_timestamp'] !== $v['timestamp'] ? $users[$v['id_last_hero']]['mail'] : '' ?></td>
<td><?= $v['last_hero_timestamp'] !== $v['timestamp'] ? $v['last_hero_timestamp'] : '' ?></td>
<td><?= $r['last_hero_timestamp'] !== $r['timestamp'] ? $users[$r['id_last_hero']]['mail'] : '' ?></td>
<td><?= $r['last_hero_timestamp'] !== $r['timestamp'] ? $r['last_hero_timestamp'] : '' ?></td>
</tr>
<?php } ?>
</tbody>
Expand Down
25 changes: 2 additions & 23 deletions ifaces/modification_verification_vente.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,34 +26,13 @@
require_once '../moteur/dbconfig.php';
$users = map_by(utilisateurs($bdd), 'id');

$req = $bdd->prepare('SELECT
vendus.id,
vendus.id_vente,
vendus.timestamp,
vendus.quantite,
vendus.prix,
vendus.id_createur,
vendus.id_last_hero,
vendus.last_hero_timestamp,
type_dechets.nom type,
CASE WHEN vendus.id_objet > 0 THEN grille_objets.nom ELSE "autre" END objet,
pesees_vendus.masse
FROM vendus
INNER JOIN type_dechets
ON type_dechets.id = vendus.id_type_dechet
INNER JOIN grille_objets
ON (grille_objets.id = vendus.id_objet OR vendus.id_objet = 0)
LEFT JOIN pesees_vendus
ON pesees_vendus.id = vendus.id_vente
WHERE vendus.id_vente = :id_vente');
$req->bindParam(':id_vente', $_GET['nvente'], PDO::PARAM_INT);
$req->execute();
$vendus = $req->fetchAll(PDO::FETCH_ASSOC);
$vendus = vendu_by_id_vente($bdd, $_GET['nvente']);

$reponse = $bdd->prepare('SELECT commentaire FROM ventes WHERE id = :id_vente');
$reponse->execute(['id_vente' => $_GET['nvente']]);
$commentaire = $reponse->fetch()['commentaire'];
$reponse->closeCursor();

require_once 'tete.php';
?>
<div class="container">
Expand Down
12 changes: 8 additions & 4 deletions ifaces/verif_vente.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,17 @@
$remboursements = $v['remb'];
$quantite = $v['quantite'];
$masse = $v['masse'];
$rembo = $ventes > 0 && $remboursements > 0;
$rembo = ($remboursements > 0.00);
?>
<tr>
<td><?= $v['id']; ?></td>
<td>
<span <?= $rembo
? '(class="badge" style="background-color:red"'
: '' ?>><?= $v['id'] ?></span>
</td>
<td><?= $v['timestamp']; ?></td>
<td><?= !$rembo ? $ventes : '' ?></td>
<td><?= $rembo ? $remboursements : '' ?></td>
<td><?= $ventes ?></td>
<td><?= $remboursements ?></td>
<td><?= $quantite ?></td>
<td>
<span class="badge" style="background-color:<?= $v['couleur']; ?>"><?= $v['moyen']; ?></span>
Expand Down
5 changes: 4 additions & 1 deletion moteur/remboursement_post.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@

session_start();

// TODO: Réecrire la gestion des remboursements pour avoir quelque chose de plus proche de ventes.
// Pourquoi pas sinon fair une table dédiée.

if (is_valid_session() && is_allowed_vente_id($_POST['id_point_vente'])) {
require_once '../moteur/dbconfig.php';

Expand Down Expand Up @@ -70,7 +73,7 @@
$tquantite = 'tquantite' . $i;
$tprix = 'tprix' . $i;

if (!isset($_POST[$tid_type_objet])) {
if (!$_POST[$tid_type_objet]) {
header("Location:../ifaces/ventes.php?err=Les remboursement de sans type d'objet ou dechet ne sont pas valides&numero=" . $_POST['id_point_vente']);
die();
}
Expand Down

0 comments on commit bfdb31d

Please sign in to comment.