Bonsoir,
J'ai une petite appli de gestion de stock en php/mysql qui fonctionne très bien, j'aurais voulu savoir comment faire lorsque je termine la commande d'un clients via sont numéros de référence que les lignes de c'est articles soit effacer de l'affichage dans la fenêtre d'édition après avoir fais la validation, lorsque je choisi un nouveau client via sont numéros de référence il efface les lignes du client précédent ?
facuration.php ( le formulaire )
rep_facture ( pour le traitement )
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 <form id="formulaire" name="formulaire" method="post" action="rep_facture.php"> <div class="titre_h1" style="height:350px;"> <div style="width:10%;height:50px;float:left;"></div> <div style="width:35%;height:50px;float:left;font-size:20px;font-weight:bold;text-align:left;color:#a13638;"> <u>Informations du client</u><br /> </div> <div style="width:10%;height:50px;float:left;"></div> <div style="width:35%;height:50px;float:left;font-size:16px;font-weight:bold;text-align:left;"> <input type="button" id="creer_client" name="creer_client" value="Créer le client" onclick="document.getElementById('param').value='creer_client';recolter();" /> </div> <div style="width:10%;height:50px;float:left;"></div> <div style="width:10%;height:75px;float:left;"></div> <div style="width:15%;height:75px;float:left;font-size:16px;font-weight:bold;text-align:left;"> Réf. Client :<br /> <select id="ref_client" name="ref_client" onchange="document.getElementById('param').value='recup_client';recolter();"> <option value="0">Choisir client</option> <?php $requete = "SELECT Client_num FROM clients ORDER BY Client_num;"; $retours = mysqli_query($liaison, $requete); while ($retour = mysqli_fetch_array($retours)) { echo "<option value='" . $retour["Client_num"] . "'>" . $retour["Client_num"] . "</option>"; } ?> </select> </div> <div style="width:15%;height:75px;float:left;font-size:16px;font-weight:bold;text-align:left;"> Civilité :<br /> <input type="text" id="civilite" name="civilite" /> </div> <div style="width:25%;height:75px;float:left;font-size:16px;font-weight:bold;text-align:left;"> Nom du client :<br /> <input type="text" id="nom_client" name="nom_client" /> </div> <div style="width:25%;height:75px;float:left;font-size:16px;font-weight:bold;text-align:left;"> Prénom du client :<br /> <input type="text" id="prenom_client" name="prenom_client" /> </div> <div style="width:10%;height:75px;float:left;"></div> <div class="div_saut_ligne" style="height:5px;"> </div> <div style="width:10%;height:50px;float:left;"></div> <div style="width:80%;height:50px;float:left;font-size:20px;font-weight:bold;text-align:left;color:#a13638;"> <u>Ajout des produits commandés</u><br /> </div> <div style="width:10%;height:50px;float:left;"></div> <div style="width:10%;height:75px;float:left;"></div> <div style="width:15%;height:75px;float:left;font-size:16px;font-weight:bold;text-align:left;"> Réf. Produit :<br /> <select id="ref_produit" name="ref_produit" onchange="document.getElementById('param').value='recup_article';recolter();"> <option value="0">Réf. produit</option> <?php $requete = "SELECT Article_code FROM articles ORDER BY Article_code;"; $retours = mysqli_query($liaison, $requete); while ($retour = mysqli_fetch_array($retours)) { echo "<option value='" . $retour["Article_code"] . "'>" . $retour["Article_code"] . "</option>"; } ?> </select> </div> <div style="width:15%;height:75px;float:left;font-size:16px;font-weight:bold;text-align:left;"> Qté en stock :<br /> <input type="text" id="qte" name="qte" disabled style="text-align:right;" /> </div> <div style="width:25%;height:75px;float:left;font-size:16px;font-weight:bold;text-align:left;"> Désignation du produit :<br /> <input type="text" id="designation" name="designation" disabled /> </div> <div style="width:25%;height:75px;float:left;font-size:16px;font-weight:bold;text-align:left;"> Prix unitaire HT :<br /> <input type="text" id="puht" name="puht" disabled style="text-align:right;" /> </div> <div style="width:10%;height:75px;float:left;"></div> <div class="div_saut_ligne" style="height:30px;"> </div> <div style="width:10%;height:75px;float:left;"></div> <div style="width:15%;height:75px;float:left;font-size:16px;font-weight:bold;text-align:left;"> Qté commandée :<br /> <input type="text" id="qte_commande" name="qte_commande" /> </div> <div style="width:15%;height:75px;float:left;font-size:16px;font-weight:bold;text-align:left;"> Total commande :<br /> <input type="text" id="total_commande" name="total_commande" disabled /> </div> <div style="width:25%;height:75px;float:left;font-size:16px;font-weight:bold;text-align:left;"> <input type="button" id="ajouter" name="ajouter" value="Ajouter" style="margin-top:10px;" onclick="plus_com();" /><br /> <input type="text" id="param" name="param" style="visibility:hidden;" /> </div> <div style="width:25%;height:75px;float:left;font-size:16px;font-weight:bold;text-align:left;"> <input type="button" id="valider" name="valider" value="Valider" style="margin-top:10px;" onclick="document.getElementById('param').value='facturer';recolter();" /><br /> <input type="text" id="chaine_com" name="chaine_com" style="visibility:hidden;" /> <input type="text" id="total_com" name="total_com" style="visibility:hidden;" /> </div> <div style="width:10%;height:75px;float:left;"></div> </div> </form>
edition.php
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 if (isset($_POST["param"])) { switch ($_POST["param"]) { case "recup_client": $requete = "SELECT * FROM clients WHERE Client_num = " . $_POST["ref_client"] . ";"; $retours = mysqli_query($liaison2, $requete); $retour = mysqli_fetch_array($retours); $chaine = $retour["Client_civilite"] . "|" . $retour["Client_nom"] . "|" . $retour["Client_prenom"]; print($chaine); break; case "recup_article": $requete = "SELECT * FROM articles WHERE Article_code = '" . $_POST["ref_produit"] . "';"; $retours = mysqli_query($liaison2, $requete); $retour = mysqli_fetch_array($retours); $chaine = $retour["Article_designation"] . "|" . $retour["Article_PUHT"] . "|" . $retour["Article_Qte"]; print($chaine); break; case "creer_client": $requete = "SELECT COUNT(Client_num) AS nb FROM clients WHERE Client_nom='" . $_POST["nom_client"] . "' AND Client_prenom='" . $_POST["prenom_client"] . "';"; $retours = mysqli_query($liaison2, $requete); $retour = mysqli_fetch_array($retours); if ($retour["nb"] > 0) print("nok"); else { $requete = "INSERT INTO clients(Client_civilite, Client_nom, Client_prenom) VALUES ('" . $_POST["civilite"] . "', '" . $_POST["nom_client"] . "', '" . $_POST["prenom_client"] . "');"; $retours = mysqli_query($liaison2, $requete); if ($retours == 1) print(mysqli_insert_id($liaison2)); } break; case "facturer": $com_client = $_POST["ref_client"]; $com_date = date('d/m/Y'); $com_montant = $_POST["total_com"]; $texte_com = $_POST["chaine_com"]; $tab_com = explode('|', $texte_com); $requete = "INSERT INTO commandes (Com_client, Com_date, Com_montant) VALUES (" . $com_client . ", '" . $com_date . "', " . $com_montant . " );"; $retours = mysqli_query($liaison2, $requete); if ($retours == 1) { $detail_com = mysqli_insert_id($liaison2); for ($ligne = 0; $ligne < sizeof($tab_com); $ligne++) { if ($tab_com[$ligne] != "") { $ligne_com = explode(";", $tab_com[$ligne]); $requete = "INSERT INTO detail (Detail_com, Detail_ref, Detail_qte) VALUES (" . $detail_com . ", '" . $ligne_com[0] . "', " . $ligne_com[1] . " );"; $retours = mysqli_query($liaison2, $requete); $requete = "UPDATE articles SET Article_Qte = Article_Qte - " . $ligne_com[1] . " WHERE Article_code='" . $ligne_com[0] . "';"; $retours = mysqli_query($liaison2, $requete); } } print($com_client . "-" . $detail_com); } else { print("nok"); } break; } } mysqli_close($liaison2);
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 $tab_param = explode("-", $_GET['info']); $tab_param = explode("-", $_GET['info']); $num_cli = $tab_param[0]; $num_com = $tab_param[1]; $c_civ = ""; $c_nom = ""; $c_pre = ""; $c_date = ""; $c_tot = ""; $c_ref = ""; $c_des = ""; $c_qte = ""; $c_pht = 0; $c_mht = 0; $compteur = 0; $requete = "SELECT * FROM clients a, commandes b, detail c WHERE a.Client_num=" . $num_cli . " AND b.Com_num=" . $num_com . " AND c.Detail_com=" . $num_com . ";"; $retours = mysqli_query($liaison2, $requete); require("fpdf/fpdf.php"); $pdf = new FPDF('P', 'mm', 'A4'); $pdf->AddPage(); $pdf->SetFont('Arial', '', 9); while ($retour = mysqli_fetch_array($retours)) { if ($c_civ == "") { $c_civ = $retour["Client_civilite"]; $c_nom = $retour["Client_nom"]; $c_pre = $retour["Client_prenom"]; $c_date = $retour["Com_date"]; $c_tot = $retour["Com_montant"]; $pdf->Cell(35, 10, "", 0, 1, 'R'); $pdf->SetFont('Arial', 'B', 10); $pdf->Cell(120, 5, "MaSociété", 0, 0, 'L'); $pdf->Cell(60, 5, $c_civ . " " . $c_pre . " " . $c_nom, 0, 1, 'L'); $pdf->SetFont('Arial', '', 9); $pdf->Cell(120, 5, "10 Rue du champs", 0, 0, 'L'); $pdf->Cell(60, 5, "Votre Adresse", 0, 1, 'L'); $pdf->SetFont('Arial', 'B', 10); $pdf->Cell(120, 5, "1000 Bruxelles", 0, 0, 'L'); $pdf->Cell(60, 5, "Votre ville", 0, 1, 'L'); $pdf->Cell(35, 10, "", 0, 1, 'R'); $pdf->Cell(120, 5, utf8_decode("Votre commande numéro : ") . $num_com, 0, 0, 'L'); $pdf->SetFont('Arial', '', 9); $pdf->Cell(60, 5, "Date de commande :" . $c_date, 0, 1, 'L'); $pdf->Cell(35, 10, "", 0, 1, 'R'); } $requete = "SELECT * FROM articles WHERE Article_code='" . $retour["Detail_ref"] . "';"; $reponses = mysqli_query($liaison2, $requete); $reponse = mysqli_fetch_array($reponses); $c_ref = $reponse["Article_code"]; $c_des = $reponse["Article_designation"]; $c_qte = $retour["Detail_qte"]; $c_pht = number_format($reponse["Article_PUHT"], 2, ',', ' '); $c_mht = number_format($retour["Detail_qte"] * $reponse["Article_PUHT"], 2, ',', ' '); $pdf->Cell(20, 10, "", 0, 0, 'L'); $pdf->Cell(20, 10, $c_ref, 1, 0, 'L'); $pdf->Cell(70, 10, $c_des, 1, 0, 'L'); $pdf->Cell(10, 10, $c_qte, 1, 0, 'R'); $pdf->Cell(30, 10, $c_pht, 1, 0, 'R'); $pdf->SetFont('Arial', 'B', 10); $pdf->Cell(30, 10, $c_mht, 1, 1, 'R'); $pdf->SetFont('Arial', '', 9); $compteur++; } $pdf->SetFont('Arial', 'B', 11); $pdf->Cell(35, 10, "", 0, 1, 'R'); $pdf->Cell(120, 10, "Montant total HT", 0, 0, 'R'); $pdf->Cell(30, 10, "", 0, 0, 'L'); $pdf->Cell(30, 10, number_format($c_tot, 2, ',', ' '), 1, 1, 'R'); $pdf->Cell(120, 10, "TVA : 21%", 0, 0, 'R'); $pdf->Cell(30, 10, "", 0, 0, 'L'); $pdf->Cell(30, 10, number_format($c_tot / 100 * 21, 2, ',', ' '), 1, 1, 'R'); $pdf->Cell(120, 10, "Montant total TTC", 0, 0, 'R'); $pdf->Cell(30, 10, "", 0, 0, 'L'); $pdf->Cell(30, 10, number_format($c_tot + $c_tot / 100 * 21, 2, ',', ' '), 1, 1, 'R'); $pdf->Cell(35, 30, "", 0, 1, 'R'); $pdf->SetFont('Arial', 'U', 10); $restant = 120 - $compteur * 10; $pdf->Cell(35, $restant, "", 0, 1, 'R'); $pdf->Cell(60, 10, "Mentions légales et conditions :", 0, 1, 'L'); $pdf->SetFont('Arial', '', 9); $pdf->Cell(180, 10, "ici indiquer les mentions ...", 0, 1, 'L'); $nom_fichier = "factures/" . $num_cli . "-" . $num_com . ".pdf"; $pdf->Output($nom_fichier, 'F'); $pdf->Output(); mysqli_close($liaison2); }
Partager