1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
| <?php
try{
$bdd=new PDO('mysql:host=localhost;dbname=pcg;charset=utf8', 'root','');
$bdd->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);// afficher les erreurs php
}catch(Exception $e){
die('Erreur :' . $e->getMessage());
}
if(// Vérifie si les champs existent et ne sont pas vides
isset($_POST['nom'],
$_POST['irrecouvrable'],
$_POST['creancesTTC'],
$_POST['provisionsTaux'],
$_POST['provisionsanterieures']
)
AND !empty($_POST['nom'])
AND !empty($_POST['irrecouvrable'])
AND !empty($_POST['creancesTTC'])
AND !empty($_POST['provisionsTaux'])
AND !empty($_POST['provisionsanterieures'])
){
if(!isset($errors)){
// insertion dans la BDD
$clientsdouteux =$bdd->prepare("INSERT INTO clientsdouteux(nom, irrecouvrable, creancesTTC, provisionsTaux, provisionsanterieures) VALUES(?,?,?,?,?)");
$clientsdouteux->execute(array($_POST['nom'], $_POST['irrecouvrable'], $_POST['creancesTTC'], $_POST['provisionsTaux'], $_POST['provisionsanterieures']));
if($clientsdouteux->rowCount()>0){
$successMsg = 'Le client douteux a bien été ajouté !';
}else{
$errorMsg[]='Suite à un problème dans la base de données, le client douteux n\'a pas pu être ajouté !';
}
$clientsdouteux->closeCursor();
}
if(!preg_match('#^[a-zA-Z\-\'ÀÁÂÃÄÅàáâãäåÒÓÔÕÖØòóôõöøÈÉÊËèéêëÇçÌÍÎÏìíîïÙÚÛÜùúûüÿÑñ]{50}$#',$_POST['nom'])){
$errors[] = 'Champ invalide<br>';
}
if(!preg_match('#^[0-9]{1,10}([.,][0-9]{1,2})?$#', $_POST['creancesTTC'])){
$errors[] = "Champ invalide";
}
if(!preg_match('#^[0-9]{1,10}([.,][0-9]{1,2})?$#', $_POST['provisionsTaux'])){
$errors[] = "Champ invalide";
}
if(!preg_match('#^[0-9]{1,10}([.,][0-9]{1,2})?$#', $_POST['provisionsanterieures'])){
$errors[] = "Champ invalide";
}
}
$response = $bdd->query('SELECT * FROM clientsdouteux');
$clientsdouteux = $response->fetchAll();
?>
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="../css/bootstrap.css">
<link rel="stylesheet" href="../css/style.css">
<link rel="stylesheet" href="../css/carousel.css">
<title>Comptabilité</title>
<script src="../js/jquery.js"></script>
<script src="../js/bootstrap.min.js"></script>
<body>
<div id="clientsdouteux">
<div class="container">
<div class="row">
<div class="col-sm-12">
<h1 style="font-size:25px;text-align:center;color:black;">Tableau d'ajustement des provisions des clients douteux</h1>
<form name="clientsdouteux" method="POST" action="clientsdouteux.php">
<input name="nom" id="nom" type="text" placeholder="Nom du client">
<input name="irrecouvrable" id="irrecouvrable" type="text" placeholder="Irrécouvrable? oui ou non"><br>
<input name="creancesTTC" id="creancesTTC" type="number" step=0.01 placeholder="Créances TTC">
<input name="provisionsTaux" id="provisionsTaux" type="number" step=0.01 placeholder="Provisions Taux"><br>
<input name="provisionsanterieures" id="provisionsanterieures" type="number" step=0.01 placeholder="Provisions antérieures">
<input type="submit" value="Envoyer">
</form><br>
<?php
if (!empty($clientsdouteux)){
$response = $bdd->query('SELECT * FROM clientsdouteux');
$clientsdouteux = $response->fetchAll();
?>
<table>
<tr>
<th rowspan="2">Clients</th>
<th rowspan="2">Irrécouvrable? Oui ou Non</th>
<th rowspan="2">Créances TTC</th>
<th colspan="2">Créeanes irrécouvrables</th>
<th colspan="2">Créances douteuses</th>
<th colspan="2">Provisions</th>
<th rowspan="2">Provisions antérieures</th>
<th colspan="2">Ajustements</th>
</tr>
<tr>
<th>Hors Taxes</th> <th>TVA</th>
<th>TTC</th> <th>Hors Taxes</th>
<th>Taux</th> <th>Montant</th>
<th>Dotation</th> <th>Reprises</th>
</tr>
<?php
foreach($clientsdouteux as $data){
echo '<tr><td>'.htmlspecialchars($data['nom']).'</td><td>'.htmlspecialchars($data['irrecouvrable']).'</td><td>'.htmlspecialchars($data['creancesTTC']).'</td><td>'.htmlspecialchars($data['provisionsTaux']).'</td><td>'.htmlspecialchars($data['provisionsanterieures']).'</td></tr>';
}
?>
</table>
<?php
}
?>
</div>
</div>
</div>
</div>
<?php
// Si l'array errors existe, on affiche toutes les erreurs qu'il contient avec un foreach
if(isset($errors)){
foreach($errors as $errorMsg){
echo '<p style="color:red;">'.$errorMsg.'</p>';
}
}
// Si successMsg existe, alors on l'affiche
if(isset($successMsg)){
echo '<p style="color:#00FF00;">'.$successMsg.'</p>';
}
?>
<script type="application/javascript" src="../js/jquery-3.3.1.min.js"></script>
<script src="../js/script.js"></script>
</body>
</html> |