From d69b20311b5c4fe0e92aa684a14258dcb2662201 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 27 Jun 2019 01:13:46 +0200 Subject: [PATCH] FIX If the replacement invoice has been deleted we can reopen --- htdocs/compta/facture/card.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index f838e401774..d81467d64e4 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -181,7 +181,8 @@ if (empty($reshook)) // Change status of invoice else if ($action == 'reopen' && $usercancreate) { $result = $object->fetch($id); - if ($object->statut == 2 || ($object->statut == 3 && $object->close_code != 'replaced') || ($object->statut == 1 && $object->paye == 1)) { // ($object->statut == 1 && $object->paye == 1) should not happened but can be found when data are corrupted + + if ($object->statut == Facture::STATUS_CLOSED || ($object->statut == Facture::STATUS_ABANDONED && ($object->close_code != 'replaced' || $object->getIdReplacingInvoice() == 0)) || ($object->statut == Facture::STATUS_VALIDATED && $object->paye == 1)) { // ($object->statut == 1 && $object->paye == 1) should not happened but can be found when data are corrupted $result = $object->set_unpaid($user); if ($result > 0) { header('Location: ' . $_SERVER["PHP_SELF"] . '?facid=' . $id); @@ -4690,11 +4691,11 @@ else if ($id > 0 || ! empty($ref)) && ($object->statut == 2 || $object->statut == 3 || ($object->statut == 1 && $object->paye == 1)) // Condition ($object->statut == 1 && $object->paye == 1) should not happened but can be found due to corrupted data && ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $usercancreate) || $usercanreopen)) // A paid invoice (partially or completely) { - if (! $objectidnext && $object->close_code != 'replaced') // Not replaced by another invoice + if ($object->close_code != 'replaced' || (! $objectidnext)) // Not replaced by another invoice or replaced but the replacement invoice has been deleted { print '
' . $langs->trans('ReOpen') . '
'; } else { - print '
' . $langs->trans('ReOpen') . '
'; + print '
' . $langs->trans('ReOpen') . '
'; } }