Fix: Use the dolibarr function to make total rounding.
This commit is contained in:
parent
bf13666d26
commit
cc290e13ab
@ -17,6 +17,13 @@
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
include_once(DOL_DOCUMENT_ROOT.'/lib/price.lib.php');
|
||||
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
*/
|
||||
class Facturation {
|
||||
|
||||
/**
|
||||
@ -82,36 +89,29 @@ class Facturation {
|
||||
global $sql;
|
||||
$req='SELECT taux FROM '.MAIN_DB_PREFIX.'c_tva WHERE rowid = '.$this->tva();
|
||||
dol_syslog("ajoutArticle sql=".$req);
|
||||
$resql=$sql->query ();
|
||||
$resql=$sql->query($req);
|
||||
|
||||
$tab_tva = $sql->fetch_array($resql);
|
||||
$ret=array();
|
||||
foreach ( $tab_tva as $cle => $valeur )
|
||||
{
|
||||
$ret[$cle] = $valeur;
|
||||
}
|
||||
$tab_tva=$ret;
|
||||
// var_dump($tab_tva);exit;
|
||||
$obj = $sql->fetch_object($resql);
|
||||
$vat_rate=$obj->taux;
|
||||
//var_dump($vat_rate);exit;
|
||||
|
||||
// Define part of HT, VAT, TTC
|
||||
$resultarray=calcul_price_total($this->qte,$this->prix(),$this->remise_percent(),$vat_rate,0,'HT',0);
|
||||
|
||||
// TODO Mettre methode de calcul arrondi TVA de Dolibarr
|
||||
|
||||
// Calcul du total ht sans remise
|
||||
$total_ht = ( $this->qte * $this->prix() );
|
||||
$total_ht = $resultarray[0];
|
||||
$total_vat = $resultarray[1];
|
||||
$total_ttc = $resultarray[2];
|
||||
// Calcul du montant de la remise
|
||||
if ( $this->remise_percent() ) {
|
||||
|
||||
if ($this->remise_percent())
|
||||
{
|
||||
$remise_percent = $this->remise_percent();
|
||||
|
||||
} else {
|
||||
|
||||
$remise_percent = 0;
|
||||
|
||||
}
|
||||
$montant_remise = $total_ht * $remise_percent / 100;
|
||||
$this->montant_remise ($montant_remise);
|
||||
// Calcul du total ttc
|
||||
$total_ttc = ($total_ht - $montant_remise) * (($tab_tva['taux'] / 100) + 1);
|
||||
|
||||
$montant_remise_ht = ($resultarray[6] - $resultarray[0]);
|
||||
$this->montant_remise ($montant_remise_ht);
|
||||
|
||||
$req='INSERT INTO '.MAIN_DB_PREFIX.'tmp_caisse (
|
||||
fk_article,
|
||||
@ -126,9 +126,9 @@ class Facturation {
|
||||
'.$this->qte().',
|
||||
'.$this->tva().',
|
||||
'.$remise_percent.',
|
||||
'.price2num($montant_remise).',
|
||||
'.price2num($total_ht).',
|
||||
'.price2num($total_ttc).')';
|
||||
'.price2num($montant_remise_ht).',
|
||||
'.price2num($total_ht,'MT').',
|
||||
'.price2num($total_ttc,'MT').')';
|
||||
dol_syslog("ajoutArticle sql=".$req);
|
||||
$sql->query($req);
|
||||
|
||||
|
||||
@ -56,14 +56,14 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
$remise = $tab[$i]['remise'];
|
||||
$total_ht = ($tab[$i]['total_ht'] - $remise);
|
||||
|
||||
echo ('<p>'.$tab[$i]['qte'].' x '.number_format ( $tab[$i]['price'], 2, '.', '' ).$remise_percent.' = '.number_format ($total_ht, 2, '.', '').'€ HT ('.number_format ($tab[$i]['total_ttc'], 2, '.', '').'€ TTC)</p>'."\n");
|
||||
echo ('<p>'.$tab[$i]['qte'].' x '.price2num( $tab[$i]['price'], 'MT').$remise_percent.' = '.price2num($total_ht, 'MT').' '.$conf->monnaie.' HT ('.price2num($tab[$i]['total_ttc'], 'MT').' '.$conf->monnaire.' TTC)</p>'."\n");
|
||||
echo ('</div>'."\n");
|
||||
|
||||
}
|
||||
|
||||
$obj_facturation->calculTotaux();
|
||||
$total_ttc = $obj_facturation->prix_total_ttc();
|
||||
echo ('<p class="cadre_prix_total">TOTAL : '.number_format ($total_ttc, 2, '.', '').' '.$conf->monnaie.'<br /></p>'."\n");
|
||||
echo ('<p class="cadre_prix_total">'.$langs->trans("Total").' : '.price2num($total_ttc, 'MT').' '.$conf->monnaie.'<br /></p>'."\n");
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
@ -1,3 +1,6 @@
|
||||
<?php
|
||||
$langs->load("main");
|
||||
?>
|
||||
<!--Copyright (C) 2007-2008 Jeremie Ollivier <jeremie.o@laposte.net>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
@ -112,7 +115,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
</div>
|
||||
|
||||
<table class="liste_articles">
|
||||
<tr class="titres"><th>Code</th><th>Label</th><th>Qté</th><th>Remise (%)</th><th>Tot HT</th></tr>
|
||||
<tr class="titres"><th><?php print $langs->trans("Code"); ?></th><th><?php print $langs->trans("Label"); ?></th><th><?php print $langs->trans("Qty"); ?></th><th><?php print $langs->trans("Discount").' (%)'; ?></th><th><?php print $langs->trans("TotalHT"); ?></th></tr>
|
||||
|
||||
<?php
|
||||
|
||||
@ -140,7 +143,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
$remise = $tab[$i]['remise'];
|
||||
$total_ht = $tab[$i]['total_ht'] - $remise;
|
||||
|
||||
echo ('<tr><td>'.$tab[$i]['ref'].'</td><td>'.$tab[$i]['label'].'</td><td>'.$tab[$i]['qte'].'</td><td>'.$tab[$i]['remise_percent'].'</td><td class="total">'.number_format ( $total_ht,2, '.', '').' €</td></tr>'."\n");
|
||||
echo ('<tr><td>'.$tab[$i]['ref'].'</td><td>'.$tab[$i]['label'].'</td><td>'.$tab[$i]['qte'].'</td><td>'.$tab[$i]['remise_percent'].'</td><td class="total">'.price2num($total_ht,'MT').' '.$conf->monnaie.'</td></tr>'."\n");
|
||||
|
||||
}
|
||||
|
||||
@ -155,18 +158,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
<table class="totaux">
|
||||
<?php
|
||||
echo '<tr><th>Total HT</th><td>'.price2num($obj_facturation->prix_total_ht())." ".$conf->monnaie."</td></tr>\n";
|
||||
if ( $obj_facturation->montant_tva() ) {
|
||||
|
||||
echo '<tr><th>TVA</th><td>'.price2num($obj_facturation->montant_tva())." ".$conf->monnaie."</td></tr>\n";
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
echo '<tr><th></th><td>Pas de TVA</td><tr>'."\n";
|
||||
|
||||
}
|
||||
echo '<tr><th>Total TTC</th><td>'.price2num($obj_facturation->prix_total_ttc())." ".$conf->monnaie."</td></tr>\n";
|
||||
echo '<tr><th nowrap="nowrap">'.$langs->trans("TotalHT").'</th><td nowrap="nowrap">'.price2num($obj_facturation->prix_total_ht(),'MT')." ".$conf->monnaie."</td></tr>\n";
|
||||
echo '<tr><th nowrap="nowrap">'.$langs->trans("TotalVAT").'</th><td nowrap="nowrap">'.price2num($obj_facturation->montant_tva(),'MT')." ".$conf->monnaie."</td></tr>\n";
|
||||
echo '<tr><th nowrap="nowrap">'.$langs->trans("TotalTTC").'</th><td nowrap="nowrap">'.price2num($obj_facturation->prix_total_ttc(),'MT')." ".$conf->monnaie."</td></tr>\n";
|
||||
?>
|
||||
</table>
|
||||
|
||||
|
||||
@ -18,26 +18,25 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
\file htdocs/lib/price.lib.php
|
||||
\brief Librairie contenant les fonctions pour calculer un prix.
|
||||
\author Rodolphe Quiedeville.
|
||||
\version $Id$
|
||||
*/
|
||||
* \file htdocs/lib/price.lib.php
|
||||
* \brief Librairie contenant les fonctions pour calculer un prix.
|
||||
* \version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
\brief Permet de calculer les parts total HT, TVA et TTC d'une ligne de
|
||||
facture, propale, commande ou autre depuis:
|
||||
quantity, unit price, remise_percent_ligne, txtva, remise_percent_global, price_base_type, info_bits
|
||||
\param qty Quantity
|
||||
\param pu Prix unitaire (HT ou TTC selon price_base_type)
|
||||
\param remise_percent_ligne Remise ligne
|
||||
\param txtva Taux tva
|
||||
\param remise_percent_global 0
|
||||
\param price_base_type HT=on calcule sur le HT, TTC=on calcule sur le TTC
|
||||
\param info_bits Miscellanous informations on line
|
||||
\return result[0,1,2,3,4,5] (total_ht, total_tva, total_ttc, pu_ht, pu_tva, pu_ttc)
|
||||
*/
|
||||
* \brief Permet de calculer les parts total HT, TVA et TTC d'une ligne de
|
||||
* facture, propale, commande ou autre depuis:
|
||||
* quantity, unit price, remise_percent_ligne, txtva, remise_percent_global, price_base_type, info_bits
|
||||
* \param qty Quantity
|
||||
* \param pu Prix unitaire (HT ou TTC selon price_base_type)
|
||||
* \param remise_percent_ligne Remise ligne
|
||||
* \param txtva Taux tva
|
||||
* \param remise_percent_global 0
|
||||
* \param price_base_type HT=on calcule sur le HT, TTC=on calcule sur le TTC
|
||||
* \param info_bits Miscellanous informations on line
|
||||
* \return result[0,1,2,3,4,5,6,7,8] (total_ht, total_vat, total_ttc, pu_ht, pu_tva, pu_ttc, total_ht_without_discount, total_vat_without_discount, total_ttc_without_discount)
|
||||
*/
|
||||
function calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $remise_percent_global=0, $price_base_type='HT', $info_bits=0)
|
||||
{
|
||||
global $conf;
|
||||
@ -51,10 +50,17 @@ function calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $remise_pe
|
||||
$tot_sans_remise = $pu * $qty;
|
||||
$tot_avec_remise_ligne = $tot_sans_remise * ( 1 - ($remise_percent_ligne / 100));
|
||||
$tot_avec_remise = $tot_avec_remise_ligne * ( 1 - ($remise_percent_global / 100));
|
||||
|
||||
$result[6] = price2num($tot_sans_remise, 'MT');
|
||||
$result[8] = price2num($tot_sans_remise * ( 1 + ( (($info_bits & 1)?0:$txtva) / 100)), 'MT'); // Selon TVA NPR ou non
|
||||
$result8bis= price2num($tot_sans_remise * ( 1 + ( $txtva / 100)), 'MT'); // Si TVA consideree normale (non NPR)
|
||||
$result[7] = $result8bis - $result[6];
|
||||
|
||||
$result[0] = price2num($tot_avec_remise, 'MT');
|
||||
$result[2] = price2num($tot_avec_remise * ( 1 + ( (($info_bits & 1)?0:$txtva) / 100)), 'MT'); // Selon TVA NPR ou non
|
||||
$result2bis= price2num($tot_avec_remise * ( 1 + ( $txtva / 100)), 'MT'); // Si TVA consideree normale (non NPR)
|
||||
$result[1] = $result2bis - $result[0];
|
||||
|
||||
$result[3] = price2num($pu, 'MU');
|
||||
$result[5] = price2num($pu * ( 1 + ((($info_bits & 1)?0:$txtva) / 100)), 'MU'); // Selon TVA NPR ou non
|
||||
$result5bis= price2num($pu * ( 1 + ($txtva / 100)), 'MU'); // Si TVA consideree normale (non NPR)
|
||||
@ -64,15 +70,20 @@ function calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $remise_pe
|
||||
{
|
||||
// On cacule a l'envers en partant du prix TTC
|
||||
// Utilise pour les produits a prix TTC reglemente (livres, ...)
|
||||
|
||||
$tot_sans_remise = $pu * $qty;
|
||||
$tot_avec_remise_ligne = $tot_sans_remise * ( 1 - ($remise_percent_ligne / 100));
|
||||
$tot_avec_remise = $tot_avec_remise_ligne * ( 1 - ($remise_percent_global / 100));
|
||||
|
||||
$result[8] = price2num($tot_sans_remise, 'MT');
|
||||
$result[6] = price2num($tot_sans_remise / ( 1 + ((($info_bits & 1)?0:$txtva) / 100)), 'MT'); // Selon TVA NPR ou non
|
||||
$result6bis= price2num($tot_sans_remise / ( 1 + ($txtva / 100)), 'MT'); // Si TVA consideree normale (non NPR)
|
||||
$result[7] = $result[8] - $result6bis;
|
||||
|
||||
$result[2] = price2num($tot_avec_remise, 'MT');
|
||||
$result[0] = price2num($tot_avec_remise / ( 1 + ((($info_bits & 1)?0:$txtva) / 100)), 'MT'); // Selon TVA NPR ou non
|
||||
$result0bis= price2num($tot_avec_remise / ( 1 + ($txtva / 100)), 'MT'); // Si TVA consideree normale (non NPR)
|
||||
$result[1] = $result[2] - $result0bis;
|
||||
|
||||
$result[5] = price2num($pu, 'MU');
|
||||
$result[3] = price2num($pu / ( 1 + ((($info_bits & 1)?0:$txtva) / 100)), 'MU'); // Selon TVA NPR ou non
|
||||
$result3bis= price2num($pu / ( 1 + ($txtva / 100)), 'MU'); // Si TVA consideree normale (non NPR)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user