diff --git a/htdocs/don/card.php b/htdocs/don/card.php index 1038cdb68d2..b730a7ff227 100644 --- a/htdocs/don/card.php +++ b/htdocs/don/card.php @@ -337,6 +337,15 @@ if (empty($reshook)) { $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->fetch($id); @@ -932,6 +941,9 @@ if (!empty($id) && $action != 'edit') { 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 9ba0ac8de98..a1988a2a2b3 100644 --- a/htdocs/don/class/don.class.php +++ b/htdocs/don/class/don.class.php @@ -859,9 +859,22 @@ class Don extends CommonObject 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'); }