PDA

View Full Version : [PHP] calcolare due iva


lucas72
22-11-2006, 19:22
Ciao

Richiamo dal db e stampo i dati di una fattura in questo modo:


while ($result = mysql_fetch_array($esegui)) {
$quan = $result["quantita"];
$prezzo_uni = $result["prezzo_un"];
$iva = $result["iva"];
$imponibile = $quan*$prezzo_uni;


echo"
<tr>
<td width=\"10%\" height=\"5\" align=\"right\">$result[codice]</td>
<td width=\"30%\" height=\"5\" align=\"center\">$result[descrizione]</td>
<td width=\"10%\" height=\"5\" align=\"right\">$quan</td>
<td width=\"10%\" height=\"5\" align=\"right\">$iva</td>
<td width=\"20%\" height=\"5\" align=\"right\">".number_format($prezzo_uni, 2, ',', '.')."</td>
<td width=\"20%\" height=\"5\" align=\"right\" >".number_format($imponibile, 2, ',', '.')."</td>
</tr>";

}


echo "
</table>
<table border=\"0\" cellspacing=\"0\" cellpadding=\"5\"width=\"100%\" height=\"100\">
<tr>
<td width=\"60%\" height=\"31\"><b>Aspetto dei beni</b></td>
</center>
<td width=\"20%\" height=\"14\">
<p align=\"right\"><b>Tot. Imponibile</b></td>
<center>
<td width=\"20%\" height=\"34\"align=\"right\"><b>€</b>&nbsp;&nbsp;".number_format($tot_imp, 2, ',', '.')."</td>
</tr>
<tr>
<td width=\"60%\" height=\"24\"><input type=text name=aspetto size=50></td>
<td width=\"20%\" height=\"21\" align=\"right\"><b>IVA&nbsp;&nbsp; 4%</b></td>
<td width=\"20%\" height=\"21\"align=\"right\"><b>€</b>&nbsp;&nbsp;".number_format($iva4, 2, ',', '.')."</td>
</tr>
<tr>
<td width=\"60%\" height=\"62\" rowspan=\"2\"></td>
<td width=\"20%\" height=\"25\" align=\"right\"><b>IVA 10%</b></td>
<td width=\"20%\" height=\"25\"align=\"right\"><b>€</b>&nbsp;&nbsp;".number_format($iva10, 2, ',', '.')."</td>
</tr>
</center>
<tr>
<td width=\"20%\" height=\"35\">
<p align=\"right\"><b>TOTALE FATTURA</b></td>
<center>
<td bgcolor=\"#F3F3F3\"width=\"20%\" height=\"35\"align=\"right\"><b>€</b>&nbsp;&nbsp;".number_format($tot_fatt, 2, ',', '.')."</td>
</tr>
</table>";



Il totale imponibile posso calcolarlo così:

Tot_imp += $imponibile;

Il problema è che non ho considerato che l'iva può essere sia
al 4% sia al 10% per gli imponibili
e, in questo caso non saprei come separare
i diversi imponibili e calcolare l'iva giusta.

Potete aiutarmi

NetZiro
24-11-2006, 17:10
Edit