From 5bffbe196ec3426ef7db8abafa3445e024f310b1 Mon Sep 17 00:00:00 2001 From: Rodolphe Quiedeville Date: Wed, 17 Sep 2003 16:00:48 +0000 Subject: [PATCH] Nouveau fichier --- htdocs/lib/price.lib.php | 87 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 htdocs/lib/price.lib.php diff --git a/htdocs/lib/price.lib.php b/htdocs/lib/price.lib.php new file mode 100644 index 00000000000..fd43df456a0 --- /dev/null +++ b/htdocs/lib/price.lib.php @@ -0,0 +1,87 @@ + + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * $Id$ + * $Source$ + * + */ + +Function calcul_price($products, $remise_percent) +{ + $total_ht = 0; + $amount_ht = 0; + $tva = array(); + $total_tva = 0; + $total_remise = 0; + + $num = sizeof($products); + $i = 0; + + while ($i < $num) + { + $prod_price = $products[$i][0]; + $prod_qty = $products[$i][1]; + $prod_txtva = $products[$i][2]; + + $lprice = $prod_qty * $prod_price; + + $amount_ht = $amount_ht + $lprice; + + if ($remise_percent > 0) + { + $lremise = ($lprice * $remise_percent / 100); + $lprice = $lprice - $lremise; + $total_remise = $total_remise + $lremise; + } + + $total_ht = $total_ht + $lprice; + + $ligne_tva = ($lprice * ($prod_txtva / 100)); + + $tva[$prod_txtva] = $tva[$prod_txtva] + $ligne_tva; + $i++; + } + + /* + * Sommes et arrondis + */ + $j=0; + $result[4] = array(); + foreach ($tva as $key => $value) + { + $tva[$key] = round($tva[$key], 2); + $total_tva = $total_tva + $tva[$key]; + $result[5][$j] = $tva[$key]; + $j++; + } + + $total_ht = round($total_ht, 2); + $total_tva = round($total_tva, 2); + + $total_ttc = $total_ht + $total_tva; + + /* + * + */ + $result[0] = $total_ht; + $result[1] = $total_tva; + $result[2] = $total_ttc; + $result[3] = $total_remise; + $result[4] = $amount_ht; + + return $result; +}