bonjour,
j'ai une facture pdf à faire en php
j'ai un problème avec les calculs.
il y a le montant de chaque ligne qui ne s'affiche pas ainsi que le montant ht.
la tva et le montant ttc s'affiche mais ce n'est pas les bons.
aider moi svp
merci d'avance
voici le code entier de ma facture :

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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
<?php
require('fpdf/fpdf.php');
$datejour= date('d m Y'); // affichera 18 09 2003 20:21
 
//Connection à votre database si externe
//include("conectmysql.php");
 
//creation de la connexion
$connection = mysql_connect('localhost','root','');
if (!$connection ) die ("Connection Impossible");
 
// ouverture de la base
$mabasededonnees="BdRayban";
mysql_select_db($mabasededonnees) or die ("Connection Impossible");
 
 
// requete sql sur table client
$result1 = mysql_query("Select NoCli, CiviliteCli, NomCli, PrenomCli, AdresseCli, CodePostalCli, VilleCli From Client Order by NomCli");
 
//preparation MEP CLient
while($row1= mysql_fetch_array($result1))
{
    $NoCli = $row1["NoCli"];
	$CiviliteCli = $row1["CiviliteCli"];
    $NomCli = substr($row1["NomCli"],0,20);
	$PrenomCli = $row1["PrenomCli"];	
	$AdresseCli = $row1["AdresseCli"];
    $CodePostalCli = $row1["CodePostalCli"];	
	$VilleCli = $row1["VilleCli"];
 
	$destinataire = "";
	//$destinataire = $destinataire.$NoCli."\n";
	$destinataire = $destinataire.$CiviliteCli." ";
	$destinataire = $destinataire.$NomCli." ";
	$destinataire = $destinataire.$PrenomCli."\n";
	$destinataire = $destinataire.$AdresseCli."\n";
	$destinataire = $destinataire.$CodePostalCli." ";
	$destinataire = $destinataire.$VilleCli."\n";
}
 
//requete corps facture
$result=mysql_query("Select Produit.NoProd, DesignProd, Qte, PuProd, (Qte*PuProd) As Mtt, Total From Produit, Contenir, Commande Where Produit.NoProd = Contenir.NoProd And Contenir.NoCommande = Commande.NoCommande Order by Produit.NoProd");
if($result)
{
	$number_of_products = mysql_num_rows($result);
}
else
{
	$result = 0;
}
 
//Initialize the n columns and the total
	$column_NoProd = "";
	$column_DesignProd = "";
	$column_Qte = "";
	$column_PuProd = "";
	$column_Mtt = "";
	$Total = 0;
	$tva = 0;
	$mtt_ttc = 0;
 
// Pour chaque ligne on ajoute le champ correspondant à la colonne
while($row = mysql_fetch_array($result))
{
    $NoProd = $row["NoProd"];
    $DesignProd = substr($row["DesignProd"],0,20);
	$real_Qte = $row["Qte"];
    $real_PuProd = $row["PuProd"];   
    $real_Mtt = $row["Mtt"];
 
// Presentation anglo saxonne des nombres 
// number_format Convert to a number with (.) for thousands, and (,) for decimals.
 
    $Qte_to_show = number_format($row["Qte"],',','.','.');
    $PuProd_to_show = number_format($row["PuProd"],',','.','.');
    $Mtt_to_show = number_format($row["Mtt"],',','.','.');
 
    $column_NoProd = $column_NoProd.$NoProd."\n";
    $column_DesignProd = $column_DesignProd.$DesignProd."\n";
    $column_Qte = $column_Qte.$Qte_to_show."\n";
    $column_PuProd = $column_PuProd.$PuProd_to_show."\n";
    $column_Mtt = $column_Mtt.$Mtt_to_show."\n";
 
//Ajoute tous les montants (mtt_ht)
	//$mtt_ht = $Total;
	$Total = $Total + $real_Mtt; 
}
mysql_close();
 
$Total = number_format($Total,',','.','.');
 
// Calcul TVA
$tva = $Total*0.196;
$tva= number_format($tva,',','.','.');
 
//calcul mtt_ttc
$mtt_ttc = $Total+$tva;
$mtt_ttc= number_format($mtt_ttc,',','.','.');
 
//Création d'un nouveau fichier PDF
$pdf=new FPDF();
$pdf->AddPage();
 
//Ajoute un rectangle, une ligne, un logo et du commentaire
$pdf -> Rect (15,5,180,90);
//$pdf -> Line(15,90,90,90);
$pdf -> Image('terre.jpg',15,5,10,0,'JPG','http://www.dnocs.gov.br');
 
//MEP raison sociale
$raisonsoc = "Societe Rayban \n";
$raisonsoc .= "21, rue Jeanne D'Arc \n";
$raisonsoc .= "76000 Rouen \n";
$raisonsoc .= "R.C.S. Rouen B 000 000 007 \n";
$raisonsoc .= "Capital : 20 000 Euros";
 
$pdf -> SetFont('Arial','B',10);
$pdf -> SetXY(30,15);
$pdf -> Multicell(60,5,$raisonsoc,1);
 
//MEP Destinataire
$pdf -> SetFont('Arial','B',10);
$pdf -> SetXY(130,40);
$pdf -> Multicell(60,5,'Destinataire :');
$pdf -> SetFont('Arial','B',10);
$pdf -> SetXY(130,45);
$pdf -> Multicell(45,5,$destinataire,1);
 
//MEP date du jour
$pdf -> SetFont('Arial','B',12);
$pdf -> SetXY(130,70);
$pdf -> Cell(30,10,'Emise le :');
$pdf -> SetFont('Arial','B',12);
$pdf -> SetXY(153,70);
$pdf -> Cell(30,10,$datejour);
 
//titre document facture, devis
$pdf->SetFont('Arial','B',16);
$pdf->SetXY(130,15);
$pdf->Cell(30,10, 'FACTURE',1);
 
//positionnement des noms de champs
$Y_Fields_Name_position = 100;
//Table position, under Fields Name
$Y_Table_Position = 106;
 
//mep en-tete colonne
//remplissage des cellules en gris
$pdf->SetFillColor(232,232,232);
//Bold Font for Field Name
$pdf->SetFont('Arial','B',12);
$pdf->SetY($Y_Fields_Name_position);
$pdf->SetX(15);
$pdf->Cell(20,6,'N° Prod',1,0,'L',1);
$pdf->SetX(35);
$pdf->Cell(70,6,'Désignation',1,0,'L',1);
$pdf->SetX(105);
$pdf->Cell(30,6,'Quantité',1,0,'L',1);
$pdf->SetX(135);
$pdf->Cell(30,6,'P.U.',1,0,'L',1);
$pdf->SetX(165);
$pdf->Cell(30,6,'Montant',1,0,'L',1);
 
//saut de ligne
$pdf->Ln(); 
 
//MEP colonne
$pdf->SetFont('Arial','',12);
$pdf->SetY($Y_Table_Position);
$pdf->SetX(15);
$pdf->MultiCell(20,6,$column_NoProd,1);
$pdf->SetY($Y_Table_Position);
$pdf->SetX(35);
$pdf->MultiCell(70,6,$column_DesignProd,1);
$pdf->SetY($Y_Table_Position);
$pdf->SetX(105);
$pdf->MultiCell(30,6,$column_Qte,1,'R');
$pdf->SetY($Y_Table_Position);
$pdf->SetX(135);
$pdf->MultiCell(30,6,$column_PuProd,1,'R');
$pdf->SetY($Y_Table_Position);
$pdf->SetX(165);
$pdf->MultiCell(30,6,$column_Total,1,'R');
$pdf->ln();
$pdf->ln();
 
//calcul tva et totaux
$pdf->SetX(135);
$pdf->Cell(30,6,'Montant H.T. :',1,'L');
$pdf->SetX(165);
$pdf->MultiCell(30,6,$mtt_ht,1,'R');
$pdf->SetX(135);
$pdf->Cell(30,6,'T.V.A. 19,6%',1,'L');
$pdf->SetX(165);
$pdf->MultiCell(30,6,$tva,1,'R');
$pdf->SetX(135);
$pdf->Cell(30,6,'Montant T.T.C. :',1,'L');
$pdf->SetX(165);
$pdf->MultiCell(30,6,$mtt_ttc,1,'R');
 
//Création de ligne de séparation pour chaque enregistrement
$i = 0;
$pdf->SetY($Y_Table_Position);
while ($i < $number_of_products)
{
    $pdf->SetX(15);
    $pdf->MultiCell(180,6,'',1);
    $i = $i +1;
}
$pdf->Output();
?>