diff --git a/htdocs/don/card.php b/htdocs/don/card.php index 8571c73f09458..8db831b035ccf 100644 --- a/htdocs/don/card.php +++ b/htdocs/don/card.php @@ -333,6 +333,15 @@ $object->setProject($projectid); } + if ($action == 'set_validate' && $permissiontoadd) { + $object->fetch($id); + if ($object->reopen($user) >= 0) { + $action = ''; + } else { + setEventMessages($object->error, $object->errors, 'errors'); + } + } + if ($action == 'update_extras' && $permissiontoadd) { $object->oldcopy = dol_clone($object, 2); @@ -916,6 +925,9 @@ if ($object->status == $object::STATUS_VALIDATED && round($remaintopay) == 0 && $object->paid == 0 && $user->hasRight('don', 'creer')) { print '
'.$langs->trans("ClassifyPaid")."
"; } + if ($object->status == $object::STATUS_PAID && $object->paid == 1 && $user->hasRight('don', 'creer')) { + print '
'.$langs->trans("ReOpen")."
"; + } // Delete if ($user->hasRight('don', 'supprimer')) { diff --git a/htdocs/don/class/don.class.php b/htdocs/don/class/don.class.php index c1f3065035e34..4ed4daa902211 100644 --- a/htdocs/don/class/don.class.php +++ b/htdocs/don/class/don.class.php @@ -859,9 +859,22 @@ public function set_cancel($id) public function reopen($user, $notrigger = 0) { // Protection - if ($this->status != self::STATUS_CANCELED) { + if ($this->status != self::STATUS_CANCELED && $this->status != self::STATUS_PAID) { return 0; } + if ($this->statut == self::STATUS_PAID) { + $sql = "UPDATE " . MAIN_DB_PREFIX . "don SET paid = 0 WHERE rowid = " . ((int) $this->id); + + $resql = $this->db->query($sql); + if ($resql) { + if ($this->db->affected_rows($resql)) { + $this->paid = 0; + } else { + dol_print_error($this->db); + return -1; + } + } + } return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'DON_REOPEN'); }