diff --git a/htdocs/contrat/card.php b/htdocs/contrat/card.php
index c40e9ab677d..eda8b600b24 100644
--- a/htdocs/contrat/card.php
+++ b/htdocs/contrat/card.php
@@ -699,6 +699,11 @@ else if ($action == 'confirm_valid' && $confirm == 'yes' && $user->rights->contr
$result = $object->validate($user);
}
+else if ($action == 'reopen' && $user->rights->contrat->creer)
+{
+ $result = $object->reopen($user);
+}
+
// Close all lines
else if ($action == 'confirm_close' && $confirm == 'yes' && $user->rights->contrat->creer)
{
@@ -1839,7 +1844,12 @@ else
if ($user->rights->contrat->creer) print '
';
else print '';
}
-
+ if ($object->statut == 1 && $nbofservices)
+ {
+ if ($user->rights->contrat->creer) print '';
+ else print '';
+ }
+
if (! empty($conf->facture->enabled) && $object->statut > 0 && $object->nbofservicesclosed < $nbofservices)
{
$langs->load("bills");
@@ -1899,6 +1909,12 @@ else
print '';
+ // List of actions on element
+ include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php';
+ $formactions = new FormActions($db);
+ $somethingshown = $formactions->showactions($object, 'contract', $socid);
+
+
print '
';
}
}
diff --git a/htdocs/contrat/class/contrat.class.php b/htdocs/contrat/class/contrat.class.php
index bb6ca1af9ff..8f56ef532ef 100644
--- a/htdocs/contrat/class/contrat.class.php
+++ b/htdocs/contrat/class/contrat.class.php
@@ -499,7 +499,71 @@ class Contrat extends CommonObject
}
+ /**
+ * Unvalidate a contract
+ *
+ * @param User $user Objet User
+ * @param int $notrigger 1=Does not execute triggers, 0=execute triggers
+ * @return int <0 if KO, >0 if OK
+ */
+ function reopen($user, $notrigger=0)
+ {
+ require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
+ global $langs, $conf;
+ $now=dol_now();
+
+ $error=0;
+ dol_syslog(get_class($this).'::reopen user='.$user->id);
+
+ $this->db->begin();
+
+ $this->fetch_thirdparty();
+
+ $sql = "UPDATE ".MAIN_DB_PREFIX."contrat SET statut = 0";
+ //$sql.= ", fk_user_valid = null, date_valid = null";
+ $sql .= " WHERE rowid = ".$this->id . " AND statut = 1";
+
+ dol_syslog(get_class($this)."::validate", LOG_DEBUG);
+ $resql = $this->db->query($sql);
+ if (! $resql)
+ {
+ dol_print_error($this->db);
+ $error++;
+ $this->error=$this->db->lasterror();
+ }
+
+ // Trigger calls
+ if (! $error && ! $notrigger)
+ {
+ // Call trigger
+ $result=$this->call_trigger('CONTRACT_REOPEN',$user);
+ if ($result < 0) {
+ $error++;
+ }
+ // End call triggers
+ }
+
+ // Set new ref and define current statut
+ if (! $error)
+ {
+ $this->statut=0;
+ $this->brouillon=1;
+ $this->date_validation=$now;
+ }
+
+ if (! $error)
+ {
+ $this->db->commit();
+ return 1;
+ }
+ else
+ {
+ $this->db->rollback();
+ return -1;
+ }
+ }
+
/**
* Load a contract from database
*