diff --git a/htdocs/comm/remise.php b/htdocs/comm/remise.php index 4fb87d6908d..5ba500ad826 100644 --- a/htdocs/comm/remise.php +++ b/htdocs/comm/remise.php @@ -44,10 +44,17 @@ if ($_POST["action"] == 'setremise') { $soc = New Societe($db); $soc->fetch($_GET["id"]); - $soc->set_remise_client($_POST["remise"],$user); - - Header("Location: remise.php?id=".$_GET["id"]); - exit; + $result=$soc->set_remise_client($_POST["remise"],$_POST["note"],$user); + + if ($result > 0) + { + Header("Location: remise.php?id=".$_GET["id"]); + exit; + } + else + { + $errmesg=$soc->error; + } } @@ -99,12 +106,19 @@ if ($_socid > 0) print ''; print ''; + // Remise print '"; + // Nouvelle valeur print ''; - print ''; + + // Motif/Note + print ''; + + print ''; print "
'; print $langs->trans("CustomerRelativeDiscount").''.$objsoc->remise_client."%
'; print $langs->trans("NewValue").'%
'; + print $langs->trans("Note").'
"; print ""; @@ -120,7 +134,7 @@ if ($_socid > 0) /* * Liste de l'historique des avoirs */ - $sql = "SELECT rc.rowid,rc.remise_client,".$db->pdate("rc.datec")." as dc,"; + $sql = "SELECT rc.rowid,rc.remise_client,rc.note,".$db->pdate("rc.datec")." as dc,"; $sql.= " u.rowid as user_id, u.code"; $sql.= " FROM ".MAIN_DB_PREFIX."societe_remise as rc, ".MAIN_DB_PREFIX."user as u"; $sql.= " WHERE rc.fk_soc =". $objsoc->id; @@ -133,8 +147,9 @@ if ($_socid > 0) print ''; $tag = !$tag; print ''; - print ''; - print ''; + print ''; + print ''; + print ''; print ''; print ''; $i = 0 ; @@ -146,7 +161,8 @@ if ($_socid > 0) $tag = !$tag; print ''; print ''; - print ''; + print ''; + print ''; print ''; print ''; $i++; diff --git a/htdocs/societe.class.php b/htdocs/societe.class.php index a3828549cac..83a1152062e 100644 --- a/htdocs/societe.class.php +++ b/htdocs/societe.class.php @@ -864,32 +864,63 @@ class Societe } } - /** - * \brief Définit la société comme un client - * \param remise montant de la remise - * \param user utilisateur qui place la remise - */ - function set_remise_client($remise, $user) - { - if ($this->id) - { - $sql = "UPDATE ".MAIN_DB_PREFIX."societe "; - $sql .= " SET remise_client = '".$remise."'"; - $sql .= " WHERE idp = " . $this->id .";"; + /** + * \brief Définit la société comme un client + * \param remise Valeur en % de la remise + * \param note Note/Motif de modification de la remise + * \param user Utilisateur qui définie la remise + * \return int <0 si ko, >0 si ok + */ + function set_remise_client($remise, $note, $user) + { + global $langs; + + // Nettoyage parametres + $note=trim($note); + if (! $note) + { + $this->error=$langs->trans("ErrorFieldRequired",$langs->trans("Note")); + return -2; + } - $this->db->query($sql); + dolibarr_syslog("Societe::set_remise_client $remise, $note, $user"); - $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_remise "; - $sql .= " ( datec, fk_soc, remise_client, fk_user_author )"; - $sql .= " VALUES (now(),".$this->id.",'".$remise."',".$user->id.")"; + if ($this->id) + { + $this->db->begin(); + + // Positionne remise courante + $sql = "UPDATE ".MAIN_DB_PREFIX."societe "; + $sql.= " SET remise_client = '".$remise."'"; + $sql.= " WHERE idp = " . $this->id .";"; + $resql=$this->db->query($sql); + if (! $resql) + { + $this->db->rollback(); + $this->error=$this->db->error(); + return -1; + } + + // Ecrit trace dans historique des remises + $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_remise "; + $sql.= " (datec, fk_soc, remise_client, note, fk_user_author)"; + $sql.= " VALUES (now(), ".$this->id.", '".$remise."',"; + $sql.= " '".addslashes($note)."',"; + $sql.= " ".$user->id; + $sql.= ")"; - if (! $this->db->query($sql) ) - { - dolibarr_print_error($this->db); - } - - } - } + $resql=$this->db->query($sql); + if (! $resql) + { + $this->db->rollback(); + $this->error=$this->db->error(); + return -1; + } + + $this->db->commit(); + return 1; + } + } /** * \brief Ajoute un avoir pour la société
'.$langs->trans("Date").''.$langs->trans("CreditNote").''.$langs->trans("Date").''.$langs->trans("CustomerRelativeDiscountShort").''.$langs->trans("Note").''.$langs->trans("User").'
'.dolibarr_print_date($obj->dc,"%d %B %Y %H:%M").''.$obj->remise_client.' %'.$obj->remise_client.' %'.$obj->note.''.img_object($langs->trans("ShowUser"),'user').' '.$obj->code.'