VAT management must be internationnal

This commit is contained in:
Laurent Destailleur 2008-10-26 15:17:52 +00:00
parent 3e0608154f
commit 7a4325be73
6 changed files with 87 additions and 165 deletions

View File

@ -16,54 +16,49 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
require ('classes/Facturation.class.php');
require ('classes/Facturation.class.php');
// Si nouvelle vente, réinitialisation des données (destruction de l'objet et vidage de la table contenant la liste des articles)
if ( $_GET['id'] == 'NOUV' ) {
// Si nouvelle vente, réinitialisation des données (destruction de l'objet et vidage de la table contenant la liste des articles)
if ( $_GET['id'] == 'NOUV' ) {
unset ($_SESSION['serObjFacturation']);
unset ($_SESSION['serObjFacturation']);
$sql->query ('DELETE FROM '.MAIN_DB_PREFIX.'tmp_caisse');
$sql->query ('DELETE FROM '.MAIN_DB_PREFIX.'tmp_caisse');
}
}
// Récupération, s'il existe, de l'objet contenant les infos de la vente en cours ...
if ( isset ($_SESSION['serObjFacturation']) ) {
// Récupération, s'il existe, de l'objet contenant les infos de la vente en cours ...
if ( isset ($_SESSION['serObjFacturation']) ) {
$obj_facturation = unserialize ($_SESSION['serObjFacturation']);
unset ($_SESSION['serObjFacturation']);
$obj_facturation = unserialize ($_SESSION['serObjFacturation']);
unset ($_SESSION['serObjFacturation']);
// ... sinon, c'est une nouvelle vente
} else {
} else {
$obj_facturation = new Facturation;
$obj_facturation = new Facturation;
}
}
?>
<div class="liste_articles">
<?php include ('liste_articles.php'); ?>
</div>
<div class="liste_articles"><?php include ('liste_articles.php'); ?></div>
<div class="principal">
<div class="principal"><?php
if ( $_GET['menu'] ) {
<?php
if ( $_GET['menu'] ) {
include ($_GET['menu'].'.php');
include ($_GET['menu'].'.php');
} else {
} else {
include ('facturation.php');
include ('facturation.php');
}
?>
</div>
}
?></div>
<?php
$_SESSION['serObjFacturation'] = serialize ($obj_facturation);
$_SESSION['serObjFacturation'] = serialize ($obj_facturation);
?>

View File

@ -49,8 +49,6 @@
*
* @var int $prix_total_ht => Prix total hors taxes
* @var int $montant_tva => Montant total de la TVA, tous taux confondus
* @var int $montant_tva_19_6 => Montant de la TVA à 19.6%
* @var int $montant_tva_5_5 => Montant de la TVA à 5.5%
* @var int $prix_total_ttc => Prix total TTC
*/
protected $num_facture;
@ -61,8 +59,6 @@
protected $prix_total_ht;
protected $montant_tva;
protected $montant_tva_19_6;
protected $montant_tva_5_5;
protected $prix_total_ttc;
@ -85,9 +81,11 @@
$tab_tva = $sql->fetchFirst ( $sql->query ('SELECT taux FROM '.MAIN_DB_PREFIX.'c_tva WHERE rowid = '.$this->tva().';') );
// TODO Mettre methode de calcul arrondi TVA de Dolibarr
// Calcul du total ht sans remise
$total_ht = ( $this->qte * $this->prix() );
// Calcul du montant de la remise
if ( $this->remise_percent() ) {
@ -98,13 +96,12 @@
$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);
$sql->query('
INSERT INTO '.MAIN_DB_PREFIX.'tmp_caisse (
fk_article,
@ -123,9 +120,6 @@
'.price2num($total_ht).',
'.price2num($total_ttc).')');
// On modifie les totaux
$this->calculTotaux();
$this->raz();
}
@ -143,7 +137,7 @@
}
/**
* Calcul du total HT, total TTC et montants TVA par types
* Calcul du total HT, total TTC et montants TVA
*/
public function calculTotaux () {
global $conf_db_host, $conf_db_user, $conf_db_pass, $conf_db_base;
@ -151,13 +145,13 @@
$sql = new Sql ($conf_db_host, $conf_db_user, $conf_db_pass, $conf_db_base);
// Incrémentation des compteurs
$res = $sql->query ('SELECT remise, total_ht, taux FROM '.MAIN_DB_PREFIX.'tmp_caisse as c
$res = $sql->query ('SELECT remise, total_ht, total_ttc, taux FROM '.MAIN_DB_PREFIX.'tmp_caisse as c
LEFT JOIN '.MAIN_DB_PREFIX.'c_tva as t ON c.fk_tva = t.rowid
ORDER BY id');
$total_tva_19_6 = 0;
$total_tva_5_5 = 0;
$total_tva_0 = 0;
$total_ht=0;
$total_ttc=0;
if ( $sql->numRows($res) ) {
$tab = $sql->fetchAll($res);
@ -166,35 +160,15 @@
// Total HT
$remise = $tab[$i]['remise'];
$total = ($tab[$i]['total_ht'] - $remise);
// Calcul des totaux HT par taux de tva
if ( $tab[$i]['taux'] == '19.6' ) {
$total_tva_19_6 += $total;
} elseif ( $tab[$i]['taux'] == '5.5' ) {
$total_tva_5_5 += $total;
} else {
$total_tva_0 += $total;
}
$total_ht += ($tab[$i]['total_ht']);
$total_ttc += ($tab[$i]['total_ttc']);
}
$this->prix_total_ht = $total_tva_0 + $total_tva_19_6 + $total_tva_5_5;
$total_ttc_19_6 = round ( ($total_tva_19_6 * 1.196), 2 );
$total_ttc_5_5 = round ( ($total_tva_5_5 * 1.055), 2 );
$this->prix_total_ttc = $total_ttc_19_6 + $total_ttc_5_5 + $total_tva_0;
$this->montant_tva_19_6 = ($total_ttc_19_6 - $total_tva_19_6);
$this->montant_tva_5_5 = ($total_ttc_5_5 - $total_tva_5_5);
$this->montant_tva = ($this->montant_tva_19_6 + $this->montant_tva_5_5);
$this->prix_total_ttc = $total_ttc;
$this->prix_total_ht = $total_ht;
$this->montant_tva = $total_ttc - $total_ht;
//print $this->prix_total_ttc.'eeee'; exit;
}
}
@ -228,8 +202,6 @@
$this->prix_total_ht ('RESET');
$this->montant_tva ('RESET');
$this->montant_tva_19_6 ('RESET');
$this->montant_tva_5_5 ('RESET');
$this->prix_total_ttc ('RESET');
}
@ -505,42 +477,6 @@
}
public function montant_tva_19_6 ( $aMontantTva=null ) {
if ( !$aMontantTva ) {
return $this->montant_tva_19_6;
} else if ( $aMontantTva == 'RESET' ) {
$this->montant_tva_19_6 = NULL;
} else {
$this->montant_tva_19_6 = $aMontantTva;
}
}
public function montant_tva_5_5 ( $aMontantTva=null ) {
if ( !$aMontantTva ) {
return $this->montant_tva_5_5;
} else if ( $aMontantTva == 'RESET' ) {
$this->montant_tva_5_5 = NULL;
} else {
$this->montant_tva_5_5 = $aMontantTva;
}
}
public function prix_total_ttc ( $aTotalTtc=null ) {
if ( !$aTotalTtc ) {

View File

@ -16,11 +16,11 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
// Récupération de la liste des articles
if ( $_GET['filtre'] ) {
// Récupération de la liste des articles
if ( $_GET['filtre'] ) {
// Avec filtre
$tab_designations = $sql->fetchAll ( $sql->query (
// Avec filtre
$tab_designations = $sql->fetchAll ( $sql->query (
'SELECT '.MAIN_DB_PREFIX.'product.rowid, ref, label, tva_tx
FROM '.MAIN_DB_PREFIX.'product
LEFT JOIN '.MAIN_DB_PREFIX.'product_stock ON '.MAIN_DB_PREFIX.'product.rowid = '.MAIN_DB_PREFIX.'product_stock.fk_product
@ -32,10 +32,10 @@
ORDER BY label
;'));
} else {
} else {
// Sans filtre
$tab_designations = $sql->fetchAll ( $sql->query ('
// Sans filtre
$tab_designations = $sql->fetchAll ( $sql->query ('
SELECT '.MAIN_DB_PREFIX.'product.rowid, ref, label, tva_tx
FROM '.MAIN_DB_PREFIX.'product
LEFT JOIN '.MAIN_DB_PREFIX.'product_stock ON '.MAIN_DB_PREFIX.'product.rowid = '.MAIN_DB_PREFIX.'product_stock.fk_product
@ -45,50 +45,50 @@
ORDER BY label
;'));
}
}
$nbr_enreg = count ($tab_designations);
$nbr_enreg = count ($tab_designations);
if ( $nbr_enreg > 1 ) {
if ( $nbr_enreg > 1 ) {
if ( $nbr_enreg > $conf_taille_listes ) {
if ( $nbr_enreg > $conf_taille_listes ) {
$top_liste_produits = '----- '.$conf_taille_listes.' produits affichés sur un total de '.$nbr_enreg.' -----';
} else {
$top_liste_produits = '----- '.$nbr_enreg.' produits affichés sur un total de '.$nbr_enreg.' -----';
}
} else if ( $nbr_enreg == 1 ) {
$top_liste_produits = '----- 1 article trouvé -----';
$top_liste_produits = '----- '.$conf_taille_listes.' produits affichés sur un total de '.$nbr_enreg.' -----';
} else {
$top_liste_produits = '----- Aucun article trouvé -----';
$top_liste_produits = '----- '.$nbr_enreg.' produits affichés sur un total de '.$nbr_enreg.' -----';
}
} else if ( $nbr_enreg == 1 ) {
// Récupération des taux de tva
global $mysoc;
$request="SELECT t.rowid, t.taux
$top_liste_produits = '----- 1 article trouvé -----';
} else {
$top_liste_produits = '----- Aucun article trouvé -----';
}
// Récupération des taux de tva
global $mysoc;
$request="SELECT t.rowid, t.taux
FROM ".MAIN_DB_PREFIX."c_tva as t, llx_c_pays as p
WHERE t.fk_pays = p.rowid AND t.active = 1 AND p.code = '".$mysoc->pays_code."'";
//print $request;
$tab_tva = $sql->fetchAll ($sql->query ($request));
//print $request;
$tab_tva = $sql->fetchAll ($sql->query ($request));
// Réinitialisation du mode de paiement, en cas de retour aux achats après validation
$obj_facturation->mode_reglement ('RESET');
$obj_facturation->montant_encaisse ('RESET');
$obj_facturation->montant_rendu ('RESET');
$obj_facturation->paiement_le ('RESET');
// Réinitialisation du mode de paiement, en cas de retour aux achats après validation
$obj_facturation->mode_reglement ('RESET');
$obj_facturation->montant_encaisse ('RESET');
$obj_facturation->montant_rendu ('RESET');
$obj_facturation->paiement_le ('RESET');
// Affichage des templates
require ('templates/facturation1.tpl.php');
// Affichage des templates
require ('templates/facturation1.tpl.php');
?>

View File

@ -53,6 +53,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
}
$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");

View File

@ -146,23 +146,18 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
<table class="totaux">
<?php
echo '<tr><th>Total HT</th><td>'.number_format ($obj_facturation->prix_total_ht(),2, '.', '')." &#8364;</td></tr>\n";
if ( $obj_facturation->montant_tva_19_6() ) {
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 19.6%</th><td>'.number_format ($obj_facturation->montant_tva_19_6(),2, '.', '')." &#8364;</td></tr>\n";
echo '<tr><th>TVA</th><td>'.price2num($obj_facturation->montant_tva())." ".$conf->monnaie."</td></tr>\n";
}
if ( $obj_facturation->montant_tva_5_5() ) {
echo '<tr><th>TVA 5.5%</th><td>'.number_format ($obj_facturation->montant_tva_5_5(),2, '.', '')." &#8364;</td></tr>\n";
}
if ( !$obj_facturation->montant_tva_19_6() && !$obj_facturation->montant_tva_5_5() ) {
else {
echo '<tr><th></th><td>Pas de TVA</td><tr>'."\n";
}
echo '<tr><th>Total TTC</th><td>'.number_format ($obj_facturation->prix_total_ttc(), 2, '.', '')." &#8364;</td></tr>\n";
echo '<tr><th>Total TTC</th><td>'.price2num($obj_facturation->prix_total_ttc())." ".$conf->monnaie."</td></tr>\n";
?>
</table>

View File

@ -19,27 +19,22 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
<table class="table_resume">
<tr><td class="resume_label">Facture </td><td><?php echo $obj_facturation->num_facture(); ?></td></tr>
<tr><td class="resume_label">Prix HT :</td><td><?php echo number_format ($obj_facturation->prix_total_ht(), 2, '.', ''); ?> &#8364;</td></tr>
<tr><td class="resume_label">Prix HT :</td><td><?php echo price2num($obj_facturation->prix_total_ht()).' '.$conf->monnaie; ?></td></tr>
<?php
// Affichage de la tva par taux
if ( $obj_facturation->montant_tva_19_6() ) {
if ( $obj_facturation->montant_tva() ) {
echo ('<tr><td class="resume_label">Montant TVA 19.6% :</td><td>'.number_format ($obj_facturation->montant_tva_19_6(), 2, '.', '').' &#8364;</td></tr>');
echo ('<tr><td class="resume_label">Montant TVA 19.6% :</td><td>'.price2num($obj_facturation->montant_tva()).' '.$conf->monnaie.'</td></tr>');
}
if ( $obj_facturation->montant_tva_5_5() ) {
echo ('<tr><td class="resume_label">Montant TVA 5.5% :</td><td>'.number_format ($obj_facturation->montant_tva_5_5(), 2, '.', '').' &#8364;</td></tr>');
}
if ( !$obj_facturation->montant_tva_19_6() && !$obj_facturation->montant_tva_5_5() ) {
else
{
echo ('<tr><td class="resume_label">Montant TVA :</td><td>Pas de TVA pour cette vente</td></tr>');
}
?>
<tr><td class="resume_label">A payer :</td><td><?php echo number_format ($obj_facturation->prix_total_ttc(), 2, '.', ''); ?> &#8364;</td></tr>
<tr><td class="resume_label">A payer :</td><td><?php echo price2num($obj_facturation->prix_total_ttc()).' '.$conf->monnaie; ?></td></tr>
<tr><td class="resume_label">Mode de réglement :</td><td><?php echo $obj_facturation->mode_reglement(); ?></td></tr>
<?php
@ -51,14 +46,14 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
} else {
echo ('<tr><td class="resume_label">Encaissé :</td><td>'.number_format ($obj_facturation->montant_encaisse(), 2, '.', '').' &#8364;</td></tr>');
echo ('<tr><td class="resume_label">Encaissé :</td><td>'.price2num($obj_facturation->montant_encaisse()).' '.$conf->monnaie.'</td></tr>');
}
// Affichage du montant rendu (réglement en espèces)
if ( $obj_facturation->montant_rendu() ) {
echo ('<tr><td class="resume_label">Rendu :</td><td>'.number_format ($obj_facturation->montant_rendu(), 2, '.', '').' &#8364;</td></tr>');
echo ('<tr><td class="resume_label">Rendu :</td><td>'.price2num($obj_facturation->montant_rendu()).' '.$conf->monnaie.'</td></tr>');
}