diff --git a/htdocs/fourn/fournisseur.facture.class.php b/htdocs/fourn/fournisseur.facture.class.php index 61edf8cb145..2bde9caef81 100644 --- a/htdocs/fourn/fournisseur.facture.class.php +++ b/htdocs/fourn/fournisseur.facture.class.php @@ -99,9 +99,6 @@ class FactureFournisseur if (! $remise) $remise = 0 ; $totalht = ($amount - $remise); -// NE ME SEMBLE PLUS JUSTIFIE ICI -// $tva = tva($totalht); -// $total = $totalht + $tva; $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'facture_fourn (facnumber, libelle, fk_soc, datec, datef, note, fk_user_author, date_lim_reglement) '; $sql .= " VALUES ('".addslashes($number)."','".addslashes($this->libelle)."',"; diff --git a/htdocs/html.form.class.php b/htdocs/html.form.class.php index cc16320c431..af05cf60627 100644 --- a/htdocs/html.form.class.php +++ b/htdocs/html.form.class.php @@ -1484,9 +1484,9 @@ class Form /** - * \brief Selection du taux de tva + * \brief Selection du taux de tva appliqué par vendeur * \param name Nom champ html - * \param defaulttx Taux tva présélectionné (deprecated) + * \param defaulttx Forçage du taux tva présélectionné. Mettre '' pour appliquer règle par défaut. * \param societe_vendeuse Objet société vendeuse * \param societe_acheteuse Objet société acheteuse * \param taux_produit Taux par defaut du produit vendu @@ -1498,13 +1498,12 @@ class Form */ function select_tva($name='tauxtva', $defaulttx='', $societe_vendeuse='', $societe_acheteuse='', $taux_produit='') { - global $langs,$conf; + global $langs,$conf,$mysoc; - // \todo Si pays vendeur non défini - if (1 == 2) + //print $societe_vendeuse."-".$societe_acheteuse; + if (! $societe_vendeuse->pays_code) { - // \todo si pays vendeur = soi-même - if (1 == 1) + if ($societe_vendeuse->id == $mysoc->id) { print ''.$langs->trans("ErrorYourCountryIsNotDefined").''; } @@ -1515,38 +1514,37 @@ class Form return; } - // \todo Ecraser defaulttx par valeur en fonction de la règle de gestion TVA - //$defaulttx=get_default_tva($societe_vendeuse,$societe_acheteuse,$taux_produit); - - // \todo Initialiser code_pays avec code_pays société vendeuse - $code_pays=$conf->global->MAIN_INFO_SOCIETE_PAYS; + // Recherche liste des codes TVA du pays vendeur $sql = "SELECT t.taux,t.recuperableonly"; $sql .= " FROM ".MAIN_DB_PREFIX."c_tva AS t"; - $sql .= " WHERE t.fk_pays = '".$code_pays."'"; + $sql .= " WHERE t.fk_pays = '".$societe_vendeuse->pays_code."'"; $sql .= " AND t.active = 1"; $sql .= " ORDER BY t.taux ASC, t.recuperableonly ASC"; - if ($this->db->query($sql)) + $resql=$this->db->query($sql); + if ($resql) { - $num = $this->db->num_rows(); + $num = $this->db->num_rows($resql); for ($i = 0; $i < $num; $i++) { - $obj = $this->db->fetch_object(); + $obj = $this->db->fetch_object($resql); $txtva[ $i ] = $obj->taux; $libtva[ $i ] = $obj->taux.'%'.($obj->recuperableonly ? ' *':''); } } + // Définition du taux à présélectionner + if ($defaulttx == '') $defaulttx=get_default_tva($societe_vendeuse,$societe_acheteuse,$taux_produit); // Si taux par defaut n'a pu etre trouvé, on prend dernier. // Comme ils sont triés par ordre croissant, dernier = plus élevé = taux courant if ($defaulttx == '') $defaulttx = $txtva[sizeof($txtva)-1]; - $taille = sizeof($txtva); + $nbdetaux = sizeof($txtva); print ''; diff --git a/htdocs/soc.php b/htdocs/soc.php index 1889284cc61..fd3b9ff7a34 100644 --- a/htdocs/soc.php +++ b/htdocs/soc.php @@ -106,15 +106,17 @@ if ($_POST["action"] == 'add' || $_POST["action"] == 'update') $soc->codeclient_modifiable = $_POST["codeclient_modifiable"]; $soc->codefournisseur_modifiable = $_POST["codefournisseur_modifiable"]; $soc->capital = $_POST["capital"]; + + $soc->tva_assuj = $_POST["assujtva_value"]; $soc->tva_intra_code = $_POST["tva_intra_code"]; $soc->tva_intra_num = $_POST["tva_intra_num"]; $soc->tva_intra = $_POST["tva_intra_code"] . $_POST["tva_intra_num"]; + $soc->forme_juridique_code = $_POST["forme_juridique_code"]; $soc->effectif_id = $_POST["effectif_id"]; $soc->typent_id = $_POST["typent_id"]; $soc->client = $_POST["client"]; $soc->fournisseur = $_POST["fournisseur"]; - $soc->tva_assuj = $_POST["assujtva_value"]; if ($_POST["action"] == 'add') { @@ -214,9 +216,10 @@ if ($_GET["action"] == 'create' || $_POST["action"] == 'create') $soc->ape=$_POST["ape"]; $soc->typent_id=$_POST["typent_id"]; $soc->effectif_id=$_POST["effectif_id"]; + + $soc->tva_assuj = $_POST["assujtva_value"]; $soc->tva_intra_code=$_POST["tva_intra_code"]; $soc->tva_intra_num=$_POST["tva_intra_num"]; - $soc->tva_assuj = $_POST["assujtva_value"]; } // On positionne pays_id, pays_code et libelle du pays choisi @@ -366,17 +369,15 @@ if ($_GET["action"] == 'create' || $_POST["action"] == 'create') print ''; print ''; - print ' '.$langs->trans("VATIntraCheckableOnEUSite"); + print ' '.$langs->trans("VATIntraCheckableOnEUSite"); print ''; - // assuj TVA - if($conf->facture->enabled) - { - $html = new Form($db); - print ''.$langs->trans('VATIsUsed').''; - $html->select_assujetti_tva("1",'assujtva_value'); - print ''."\n"; - } - + + + // Assujeti TVA + $html = new Form($db); + print ''.$langs->trans('VATIsUsed').''; + $html->select_assujetti_tva("1",'assujtva_value'); // Assujeti par défaut + print ''."\n"; print ''; @@ -426,9 +427,10 @@ elseif ($_GET["action"] == 'edit' || $_POST["action"] == 'edit') $soc->ape=$_POST["ape"]; $soc->typent_id=$_POST["typent_id"]; $soc->effectif_id=$_POST["effectif_id"]; + + $soc->tva_assuj = $_POST["assujtva_value"]; $soc->tva_intra_code=$_POST["tva_intra_code"]; $soc->tva_intra_num=$_POST["tva_intra_num"]; - $soc->tva_assuj = $_POST["assujtva_value"]; // On positionne pays_id, pays_code et libelle du pays choisi if ($soc->pays_id) diff --git a/htdocs/societe.class.php b/htdocs/societe.class.php index f6f490ef89b..cdbbdcc81de 100644 --- a/htdocs/societe.class.php +++ b/htdocs/societe.class.php @@ -1,9 +1,9 @@ - * Copyright (C) 2004-2005 Laurent Destailleur + * Copyright (C) 2004-2006 Laurent Destailleur * Copyright (C) 2004 Eric Seigne * Copyright (C) 2003 Brian Fraval - * Copyright (C) 2006 Andre Cianfarani + * Copyright (C) 2006 Andre Cianfarani * * 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 @@ -36,50 +36,53 @@ \brief Classe permettant la gestion des societes */ -class Societe { - var $db; - - var $id; - var $nom; - var $adresse; - var $cp; - var $ville; - var $departement_id; - var $pays_id; - var $pays_code; - var $tel; - var $fax; - var $url; - var $siren; - var $siret; - var $ape; - - var $prefix_comm; - - var $tva_intra; - var $capital; - var $typent_id; - var $effectif_id; - var $forme_juridique_code; - var $forme_juridique; - - var $remise_client; - - var $client; - var $prospect; - var $fournisseur; - - var $code_client; - var $code_fournisseur; - var $code_compta; - var $code_compta_fournisseur; - - var $note; - - var $stcomm_id; - var $statut_commercial; - - var $price_level; +class Societe +{ + var $db; + + var $id; + var $nom; + var $adresse; + var $cp; + var $ville; + var $departement_id; + var $pays_id; + var $pays_code; + var $tel; + var $fax; + var $url; + var $siren; + var $siret; + var $ape; + + var $prefix_comm; + + var $tva_assuj; + var $tva_intra; + + var $capital; + var $typent_id; + var $effectif_id; + var $forme_juridique_code; + var $forme_juridique; + + var $remise_client; + + var $client; + var $prospect; + var $fournisseur; + + var $code_client; + var $code_fournisseur; + var $code_compta; + var $code_compta_fournisseur; + + var $note; + + var $stcomm_id; + var $statut_commercial; + + var $price_level; /** @@ -278,11 +281,13 @@ class Societe { $this->siret=trim($this->siret); $this->ape=trim($this->ape); $this->prefix_comm=trim($this->prefix_comm); + + $this->tva_assuj=trim($this->tva_assuj); $this->tva_intra=trim($this->tva_intra); + $this->capital=trim($this->capital); $this->effectif_id=trim($this->effectif_id); $this->forme_juridique_code=trim($this->forme_juridique_code); - $this->tva_assuj=trim($this->tva_assuj); $result = $this->verify(); // Verifie que nom obligatoire et code client ok et unique @@ -300,10 +305,10 @@ class Societe { $this->fax = ereg_replace(" ","",$this->fax); $this->fax = ereg_replace("\.","",$this->fax); - $sql = "UPDATE ".MAIN_DB_PREFIX."societe "; - $sql .= " SET nom = '" . addslashes($this->nom) ."'"; // Champ obligatoire - $sql .= ", datea = now()"; - $sql .= ",address = '" . addslashes($this->adresse) ."'"; + $sql = "UPDATE ".MAIN_DB_PREFIX."societe"; + $sql.= " SET nom = '" . addslashes($this->nom) ."'"; // Champ obligatoire + $sql.= ",datea = now()"; + $sql.= ",address = '" . addslashes($this->adresse) ."'"; if ($this->cp) { $sql .= ",cp = '" . $this->cp ."'"; } @@ -322,9 +327,11 @@ class Societe { $sql .= ",siret = '". addslashes($this->siret) ."'"; $sql .= ",ape = '". addslashes($this->ape) ."'"; + $sql .= ",tva_assuj = ".($this->tva_assuj>=0?"'".$this->tva_assuj."'":"null"); $sql .= ",tva_intra = '" . addslashes($this->tva_intra) ."'"; + $sql .= ",capital = '" . addslashes($this->capital) ."'"; - + $sql .= ",prefix_comm = ".($this->prefix_comm?"'".addslashes($this->prefix_comm)."'":"null"); $sql .= ",fk_effectif = ".($this->effectif_id?"'".$this->effectif_id."'":"null"); @@ -335,7 +342,6 @@ class Societe { $sql .= ",client = " . $this->client; $sql .= ",fournisseur = " . $this->fournisseur; - $sql .= ",tva_assuj = ".($this->tva_assuj>=0?"'".$this->tva_assuj."'":"null"); if ($this->creation_bit || $this->codeclient_modifiable) { @@ -510,6 +516,7 @@ class Societe { $this->code_compta = $obj->code_compta; $this->code_compta_fournisseur = $obj->code_compta_fournisseur; + $this->tva_assuj = $obj->tva_assuj; $this->tva_intra = $obj->tva_intra; $this->tva_intra_code = substr($obj->tva_intra,0,2); $this->tva_intra_num = substr($obj->tva_intra,2); @@ -528,7 +535,6 @@ class Societe { $this->remise_client = $obj->remise_client; $this->mode_reglement = $obj->mode_reglement; $this->cond_reglement = $obj->cond_reglement; - $this->tva_assuj = $obj->tva_assuj; $this->client = $obj->client; $this->fournisseur = $obj->fournisseur; @@ -1486,6 +1492,18 @@ function set_price_level($price_level, $user) } } + /* + * \brief Renvoi si pays appartient à CEE + * \param boolean true = pays dans CEE, false, pays hors CEE + */ + function isInEEC() + { + // \todo liste pays à compléter + $country_code_in_EEC=array('BE','FR','LU'); + //print "dd".$this->pays_code; + return in_array($this->pays_code,$country_code_in_EEC); + } + } ?>