2004-10-20 00:47:16 +02:00
|
|
|
|
<?php
|
2004-07-21 13:11:21 +02:00
|
|
|
|
/* Copyright (C) 2002-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
2003-09-17 18:00:48 +02:00
|
|
|
|
*
|
|
|
|
|
|
* 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$
|
|
|
|
|
|
*
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2004-08-14 14:47:39 +02:00
|
|
|
|
/*! \file htdocs/lib/price.lib.php
|
2004-07-21 13:11:21 +02:00
|
|
|
|
\brief librairie contenant les fonctions pour calculer un prix.
|
|
|
|
|
|
\author Rodolphe Quiedeville.
|
2004-07-28 00:50:27 +02:00
|
|
|
|
\version $Revision$
|
2004-07-21 13:11:21 +02:00
|
|
|
|
|
|
|
|
|
|
Ensemble des fonctions permettant de calculer un prix.
|
2004-07-15 13:38:43 +02:00
|
|
|
|
*/
|
|
|
|
|
|
|
2004-08-14 14:47:39 +02:00
|
|
|
|
|
2004-07-15 13:38:43 +02:00
|
|
|
|
/*!
|
2004-07-21 13:11:21 +02:00
|
|
|
|
\brief permet de calculer un prix.
|
|
|
|
|
|
\param products
|
|
|
|
|
|
\param remise_percent
|
|
|
|
|
|
\return result
|
2004-07-15 13:38:43 +02:00
|
|
|
|
*/
|
2004-06-19 12:09:05 +02:00
|
|
|
|
|
2004-07-15 20:43:48 +02:00
|
|
|
|
function calcul_price($products, $remise_percent)
|
2003-09-17 18:00:48 +02:00
|
|
|
|
{
|
2005-10-08 17:54:06 +02:00
|
|
|
|
$total_ht = 0;
|
|
|
|
|
|
$amount_ht = 0;
|
|
|
|
|
|
$total_tva = 0;
|
|
|
|
|
|
$total_ttc = 0;
|
|
|
|
|
|
$total_remise = 0;
|
|
|
|
|
|
$result[5] = array();
|
|
|
|
|
|
|
|
|
|
|
|
if ( sizeof( $products ) )
|
2003-09-17 18:00:48 +02:00
|
|
|
|
{
|
2005-10-08 17:54:06 +02:00
|
|
|
|
foreach ($products as $product)
|
|
|
|
|
|
{
|
|
|
|
|
|
$prod_price = $product[0];
|
|
|
|
|
|
$prod_qty = $product[1];
|
|
|
|
|
|
$prod_txtva = $product[2];
|
|
|
|
|
|
|
|
|
|
|
|
// montant total HT de la ligne
|
|
|
|
|
|
$line_price_ht = $prod_qty * $prod_price;
|
|
|
|
|
|
|
|
|
|
|
|
// incr<63>mentation montant HT hors remise de l'ensemble
|
|
|
|
|
|
$amount_ht += $line_price_ht;
|
|
|
|
|
|
|
|
|
|
|
|
// si une remise est consentie sur l'ensemble
|
|
|
|
|
|
if ($remise_percent > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
// calcul de la remise sur la ligne
|
|
|
|
|
|
$line_remise = ($line_price_ht * $remise_percent / 100);
|
|
|
|
|
|
// soustraction de cette remise au montant HT de la ligne
|
|
|
|
|
|
$line_price_ht -= $line_remise;
|
|
|
|
|
|
// incr<63>mentation du montant total de remise sur l'ensemble
|
|
|
|
|
|
$total_remise += $line_remise;
|
|
|
|
|
|
}
|
|
|
|
|
|
// incr<63>mentation du montant HT remis<69> de l'ensemble
|
|
|
|
|
|
$total_ht += $line_price_ht;
|
|
|
|
|
|
|
|
|
|
|
|
// calcul de la TVA sur la ligne
|
|
|
|
|
|
$line_tva = ($line_price_ht * (abs($prod_txtva) / 100));
|
|
|
|
|
|
|
|
|
|
|
|
// incr<63>mentation du montant TTC de la valeur HT, on traite la TVA ensuite
|
|
|
|
|
|
$total_ttc += $line_price_ht;
|
|
|
|
|
|
// traitement de la tva non per<65>ue r<>cup<75>rable
|
|
|
|
|
|
if ( $prod_txtva >= 0 )
|
|
|
|
|
|
{
|
|
|
|
|
|
// ce n'est pas une TVA non per<65>ue r<>cup<75>rable,
|
|
|
|
|
|
// donc on incr<63>mente le total TTC de l'ensemble, de la valeur de TVA de la ligne
|
|
|
|
|
|
$total_ttc += $line_tva;
|
|
|
|
|
|
}
|
|
|
|
|
|
// dans tous les cas, on incr<63>mente le total de TVA
|
|
|
|
|
|
$total_tva += $line_tva;
|
|
|
|
|
|
// on incr<63>mente le tableau de diff<66>rentiation des taux de TVA
|
|
|
|
|
|
// s'il faut rassembler les tva facturables ou non, du m<>me taux
|
|
|
|
|
|
// dans un m<>me ligne du tableau, remplacer la ligne suivante par :
|
|
|
|
|
|
// $result[5][abs($prod_txtva)] += $line_tva;
|
|
|
|
|
|
$result[5][$prod_txtva] += $line_tva;
|
|
|
|
|
|
|
|
|
|
|
|
$i++;
|
|
|
|
|
|
}
|
2003-09-17 18:00:48 +02:00
|
|
|
|
}
|
2005-10-08 17:54:06 +02:00
|
|
|
|
/*
|
|
|
|
|
|
* arrondis
|
|
|
|
|
|
*/
|
|
|
|
|
|
$total_ht = round($total_ht, 2);
|
|
|
|
|
|
$total_tva = round($total_tva, 2);
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
*
|
|
|
|
|
|
*/
|
|
|
|
|
|
$result[0] = $total_ht;
|
|
|
|
|
|
$result[1] = $total_tva;
|
|
|
|
|
|
$result[2] = $total_ttc;
|
|
|
|
|
|
$result[3] = $total_remise;
|
|
|
|
|
|
$result[4] = $amount_ht;
|
|
|
|
|
|
|
|
|
|
|
|
return $result;
|
2003-09-17 18:00:48 +02:00
|
|
|
|
}
|
2005-10-08 17:54:06 +02:00
|
|
|
|
|