Merge pull request #31904 from IC-Mathieu/FIx_go_back_status

FIX go back status #24944
This commit is contained in:
Laurent Destailleur 2025-02-12 04:39:42 +01:00 committed by GitHub
commit 86c4c0ccc6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 26 additions and 1 deletions

View File

@ -333,6 +333,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->oldcopy = dol_clone($object, 2);
@ -916,6 +925,9 @@ if (!empty($id) && $action != 'edit') {
if ($object->status == $object::STATUS_VALIDATED && round($remaintopay) == 0 && $object->paid == 0 && $user->hasRight('don', 'creer')) {
print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?rowid='.$object->id.'&action=set_paid&token='.newToken().'">'.$langs->trans("ClassifyPaid")."</a></div>";
}
if ($object->status == $object::STATUS_PAID && $object->paid == 1 && $user->hasRight('don', 'creer')) {
print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?rowid='.$object->id.'&action=set_validate&token='.newToken().'">'.$langs->trans("ReOpen")."</a></div>";
}
// Delete
if ($user->hasRight('don', 'supprimer')) {

View File

@ -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');
}