diff --git a/htdocs/contrat/contrat.class.php b/htdocs/contrat/contrat.class.php index c3d9edf84e1..dbcefe51603 100644 --- a/htdocs/contrat/contrat.class.php +++ b/htdocs/contrat/contrat.class.php @@ -661,8 +661,7 @@ class Contrat extends CommonObject */ function addline($desc, $pu, $qty, $txtva, $fk_product=0, $remise_percent=0, $date_start, $date_end, $price_base_type='HT') { - global $langs; - global $conf; + global $langs, $conf; // Nettoyage parametres if (! $txtva) $txtva=0; @@ -674,7 +673,7 @@ class Contrat extends CommonObject dolibarr_syslog("Contrat::addline $desc, $pu, $qty, $txtva, $fk_product, $remise_percent, $date_start, $date_end, $price_base_type, $info_bits"); - if ($this->statut == 0) + if ($this->statut == 0 || ($this->statut == 1 && $conf->global->CONTRAT_EDITWHENVALIDATED)) { if ($fk_product > 0) { @@ -743,6 +742,7 @@ class Contrat extends CommonObject } else { + dolibarr_syslog("Contrat::addline ErrorTryToAddLineOnValidatedContract", LOG_ERR); return -2; } } @@ -826,20 +826,24 @@ class Contrat extends CommonObject } /** - * \brief Supprime une ligne de detail - * \param idligne Id de la ligne detail à supprimer - * \return int >0 si ok, <0 si ko + * \brief Delete a contract line + * \param idline Id of line to delete + * \return int >0 if OK, <0 if KO */ - function delete_line($idligne) + function delete_line($idline) { - if ($this->statut == 0) + global $conf; + + if ($contrat->statut == 0 || + ($contrat->statut == 1 && $conf->global->CONTRAT_EDITWHENVALIDATED) ) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."contratdet WHERE rowid =".$idligne; - + $sql = "DELETE FROM ".MAIN_DB_PREFIX."contratdet"; + $sql.= " WHERE rowid =".$idline; + + dolibarr_syslog("Contrat::delete_line sql=".$sql); if ($this->db->query($sql) ) { $this->update_price(); - return 1; } else diff --git a/htdocs/contrat/fiche.php b/htdocs/contrat/fiche.php index e2862b8ed0b..37977f4ab1f 100644 --- a/htdocs/contrat/fiche.php +++ b/htdocs/contrat/fiche.php @@ -334,11 +334,15 @@ if ($_GET["action"] == 'deleteline' && $user->rights->contrat->creer) $contrat->fetch($_GET["id"]); $result = $contrat->delete_line($_GET["lineid"]); - if ($result == 0) + if ($result >= 0) { Header("Location: fiche.php?id=".$contrat->id); exit; } + else + { + $mesg=$contrat->error; + } } if ($_POST["action"] == 'confirm_valid' && $_POST["confirm"] == 'yes' && $user->rights->contrat->creer) @@ -357,7 +361,7 @@ if ($_POST["action"] == 'confirm_close' && $_POST["confirm"] == 'yes' && $user-> if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"] == 'yes') { - if ($user->rights->contrat->supprimer ) + if ($user->rights->contrat->supprimer) { $contrat = new Contrat($db); $contrat->id = $_GET["id"]; @@ -783,7 +787,8 @@ else else { print ' '; } - if ($contrat->statut == 0 && $user->rights->contrat->creer) + if ( ($contrat->statut == 0 || ($contrat->statut == 1 && $conf->global->CONTRAT_EDITWHENVALIDATED)) + && $user->rights->contrat->creer) { print ' '; print ''; @@ -1067,7 +1072,8 @@ else /* * Ajouter une ligne produit/service */ - if ($user->rights->contrat->creer && ($contrat->statut == 0 || $conf->global->CONTRAT_EDITWHENVALIDATED)) + if ($user->rights->contrat->creer && + ($contrat->statut == 0 || ($contrat->statut == 1 && $conf->global->CONTRAT_EDITWHENVALIDATED)) ) { print '
'; print ''; // Array with (n*2)+1 lines