From 71db2603e15759585db8923fccce6a9c1bbfae96 Mon Sep 17 00:00:00 2001 From: lmarcouiller Date: Mon, 19 Oct 2020 13:52:12 +0200 Subject: [PATCH 1/7] FIX pb of duplicate event on command when refreshing the page after command classification as billed or closed --- htdocs/commande/card.php | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php index 3ee5b89e01a..cefe4dfccf6 100644 --- a/htdocs/commande/card.php +++ b/htdocs/commande/card.php @@ -1282,6 +1282,17 @@ if (empty($reshook)) exit(); } + //Used to not reclass as billed a command which is already billed by refreshing the page + if(strpos( $_SERVER["REQUEST_URI"],'action=classifybilled') && $object->billed){ + header("Location: $_SERVER[PHP_SELF]?id=$object->id"); + exit(); + } + //Used to not reclass as closed command which is already closed by refreshing the page + if(strpos( $_SERVER["REQUEST_URI"],'action=confirm_shipped') && Commande::STATUS_CLOSED){ + header("Location: $_SERVER[PHP_SELF]?id=$object->id"); + exit(); + } + // add lines from objectlinked if ($action == 'import_lines_from_object' && $usercancreate @@ -2490,7 +2501,7 @@ if ($action == 'create' && $usercancreate) if (($object->statut == Commande::STATUS_CLOSED || $object->statut == Commande::STATUS_CANCELED) && $usercancreate) { print '
'.$langs->trans('ReOpen').'
'; } - + // Send if (empty($user->socid)) { if ($object->statut > Commande::STATUS_DRAFT || !empty($conf->global->COMMANDE_SENDBYEMAIL_FOR_ALL_STATUS)) { @@ -2499,7 +2510,7 @@ if ($action == 'create' && $usercancreate) } else print ''.$langs->trans('SendMail').''; } } - + // Valid if ($object->statut == Commande::STATUS_DRAFT && ($object->total_ttc >= 0 || !empty($conf->global->ORDER_ENABLE_NEGATIVE)) && $numlines > 0 && $usercanvalidate) { @@ -2517,7 +2528,7 @@ if ($action == 'create' && $usercancreate) // page. print '' . $langs->trans("AddAction") . ''; }*/ - + // Create a purchase order if (!empty($conf->global->WORKFLOW_CAN_CREATE_PURCHASE_ORDER_FROM_SALE_ORDER)) { @@ -2527,11 +2538,11 @@ if ($action == 'create' && $usercancreate) } } } - + // Create intervention if ($conf->ficheinter->enabled) { $langs->load("interventions"); - + if ($object->statut > Commande::STATUS_DRAFT && $object->statut < Commande::STATUS_CLOSED && $object->getNbOfServicesLines() > 0) { if ($user->rights->ficheinter->creer) { print ''.$langs->trans('AddIntervention').''; @@ -2540,21 +2551,21 @@ if ($action == 'create' && $usercancreate) } } } - + // Create contract if ($conf->contrat->enabled && ($object->statut == Commande::STATUS_VALIDATED || $object->statut == Commande::STATUS_SHIPMENTONPROCESS || $object->statut == Commande::STATUS_CLOSED)) { $langs->load("contracts"); - + if ($user->rights->contrat->creer) { print ''.$langs->trans('AddContract').''; } } - + // Ship $numshipping = 0; if (!empty($conf->expedition->enabled)) { $numshipping = $object->nb_expedition(); - + if ($object->statut > Commande::STATUS_DRAFT && $object->statut < Commande::STATUS_CLOSED && ($object->getNbOfProductsLines() > 0 || !empty($conf->global->STOCK_SUPPORTS_SERVICES))) { if (($conf->expedition_bon->enabled && $user->rights->expedition->creer) || ($conf->livraison_bon->enabled && $user->rights->expedition->livraison->creer)) { if ($user->rights->expedition->creer) { @@ -2568,12 +2579,11 @@ if ($action == 'create' && $usercancreate) } } } - + // Set to shipped if (($object->statut == Commande::STATUS_VALIDATED || $object->statut == Commande::STATUS_SHIPMENTONPROCESS) && $usercanclose) { print '
'.$langs->trans('ClassifyShipped').'
'; } - // Create bill and Classify billed // Note: Even if module invoice is not enabled, we should be able to use button "Classified billed" if ($object->statut > Commande::STATUS_DRAFT && !$object->billed && $object->total_ttc >= 0) { @@ -2593,13 +2603,13 @@ if ($action == 'create' && $usercancreate) if ($usercancreate) { print '
'.$langs->trans("ToClone").'
'; } - + // Cancel order if ($object->statut == Commande::STATUS_VALIDATED && (!empty($usercanclose) || !empty($usercancancel))) { print '
'.$langs->trans('Cancel').'
'; } - + // Delete order if ($usercandelete) { if ($numshipping == 0) { @@ -2611,7 +2621,7 @@ if ($action == 'create' && $usercancreate) } print ''; } - + // Select mail models is same action as presend if (GETPOST('modelselected')) { $action = 'presend'; From 511943c052a689b3518a8998d92809eaf7733ed7 Mon Sep 17 00:00:00 2001 From: lmarcouiller Date: Mon, 19 Oct 2020 14:05:32 +0200 Subject: [PATCH 2/7] FIX pb of duplicate event on command when refreshing the page after command classification as billed or closed --- htdocs/commande/card.php | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php index cefe4dfccf6..655e3b2ef11 100644 --- a/htdocs/commande/card.php +++ b/htdocs/commande/card.php @@ -1282,13 +1282,13 @@ if (empty($reshook)) exit(); } - //Used to not reclass as billed a command which is already billed by refreshing the page - if(strpos( $_SERVER["REQUEST_URI"],'action=classifybilled') && $object->billed){ + //Used to not reclass as billed a command which is already billed by refreshing the page + if (strpos( $_SERVER["REQUEST_URI"],'action=classifybilled') && $object->billed){ header("Location: $_SERVER[PHP_SELF]?id=$object->id"); exit(); } - //Used to not reclass as closed command which is already closed by refreshing the page - if(strpos( $_SERVER["REQUEST_URI"],'action=confirm_shipped') && Commande::STATUS_CLOSED){ + //Used to not reclass as closed command which is already closed by refreshing the page + if (strpos( $_SERVER["REQUEST_URI"],'action=confirm_shipped') && Commande::STATUS_CLOSED){ header("Location: $_SERVER[PHP_SELF]?id=$object->id"); exit(); } @@ -2501,7 +2501,7 @@ if ($action == 'create' && $usercancreate) if (($object->statut == Commande::STATUS_CLOSED || $object->statut == Commande::STATUS_CANCELED) && $usercancreate) { print ''; } - + // Send if (empty($user->socid)) { if ($object->statut > Commande::STATUS_DRAFT || !empty($conf->global->COMMANDE_SENDBYEMAIL_FOR_ALL_STATUS)) { @@ -2510,7 +2510,7 @@ if ($action == 'create' && $usercancreate) } else print ''.$langs->trans('SendMail').''; } } - + // Valid if ($object->statut == Commande::STATUS_DRAFT && ($object->total_ttc >= 0 || !empty($conf->global->ORDER_ENABLE_NEGATIVE)) && $numlines > 0 && $usercanvalidate) { @@ -2528,7 +2528,7 @@ if ($action == 'create' && $usercancreate) // page. print '' . $langs->trans("AddAction") . ''; }*/ - + // Create a purchase order if (!empty($conf->global->WORKFLOW_CAN_CREATE_PURCHASE_ORDER_FROM_SALE_ORDER)) { @@ -2538,11 +2538,11 @@ if ($action == 'create' && $usercancreate) } } } - + // Create intervention if ($conf->ficheinter->enabled) { $langs->load("interventions"); - + if ($object->statut > Commande::STATUS_DRAFT && $object->statut < Commande::STATUS_CLOSED && $object->getNbOfServicesLines() > 0) { if ($user->rights->ficheinter->creer) { print ''.$langs->trans('AddIntervention').''; @@ -2551,21 +2551,21 @@ if ($action == 'create' && $usercancreate) } } } - + // Create contract if ($conf->contrat->enabled && ($object->statut == Commande::STATUS_VALIDATED || $object->statut == Commande::STATUS_SHIPMENTONPROCESS || $object->statut == Commande::STATUS_CLOSED)) { $langs->load("contracts"); - + if ($user->rights->contrat->creer) { print ''.$langs->trans('AddContract').''; } } - + // Ship $numshipping = 0; if (!empty($conf->expedition->enabled)) { $numshipping = $object->nb_expedition(); - + if ($object->statut > Commande::STATUS_DRAFT && $object->statut < Commande::STATUS_CLOSED && ($object->getNbOfProductsLines() > 0 || !empty($conf->global->STOCK_SUPPORTS_SERVICES))) { if (($conf->expedition_bon->enabled && $user->rights->expedition->creer) || ($conf->livraison_bon->enabled && $user->rights->expedition->livraison->creer)) { if ($user->rights->expedition->creer) { @@ -2579,7 +2579,7 @@ if ($action == 'create' && $usercancreate) } } } - + // Set to shipped if (($object->statut == Commande::STATUS_VALIDATED || $object->statut == Commande::STATUS_SHIPMENTONPROCESS) && $usercanclose) { print ''; @@ -2603,13 +2603,13 @@ if ($action == 'create' && $usercancreate) if ($usercancreate) { print ''; } - + // Cancel order if ($object->statut == Commande::STATUS_VALIDATED && (!empty($usercanclose) || !empty($usercancancel))) { print ''; } - + // Delete order if ($usercandelete) { if ($numshipping == 0) { @@ -2621,7 +2621,7 @@ if ($action == 'create' && $usercancreate) } print ''; } - + // Select mail models is same action as presend if (GETPOST('modelselected')) { $action = 'presend'; From edd391da3a9c46d61ba67a1955c0f580aee26f21 Mon Sep 17 00:00:00 2001 From: lmarcouiller Date: Mon, 19 Oct 2020 14:09:55 +0200 Subject: [PATCH 3/7] FIX pb of duplicate event on command when refreshing the page after command classification as billed or closed --- htdocs/commande/card.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php index 655e3b2ef11..c64452fb3c3 100644 --- a/htdocs/commande/card.php +++ b/htdocs/commande/card.php @@ -1283,12 +1283,14 @@ if (empty($reshook)) } //Used to not reclass as billed a command which is already billed by refreshing the page - if (strpos( $_SERVER["REQUEST_URI"],'action=classifybilled') && $object->billed){ + if (strpos( $_SERVER["REQUEST_URI"],'action=classifybilled') && $object->billed) + { header("Location: $_SERVER[PHP_SELF]?id=$object->id"); exit(); } //Used to not reclass as closed command which is already closed by refreshing the page - if (strpos( $_SERVER["REQUEST_URI"],'action=confirm_shipped') && Commande::STATUS_CLOSED){ + if (strpos( $_SERVER["REQUEST_URI"],'action=confirm_shipped') && Commande::STATUS_CLOSED) + { header("Location: $_SERVER[PHP_SELF]?id=$object->id"); exit(); } From 64d8d5334cf57af627405bb0b5656b8597bb6921 Mon Sep 17 00:00:00 2001 From: lmarcouiller Date: Mon, 19 Oct 2020 14:12:32 +0200 Subject: [PATCH 4/7] FIX pb of duplicate event on command when refreshing the page after command classification as billed or closed --- htdocs/commande/card.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php index c64452fb3c3..6a51dcd4aaa 100644 --- a/htdocs/commande/card.php +++ b/htdocs/commande/card.php @@ -1283,13 +1283,13 @@ if (empty($reshook)) } //Used to not reclass as billed a command which is already billed by refreshing the page - if (strpos( $_SERVER["REQUEST_URI"],'action=classifybilled') && $object->billed) + if (strpos($_SERVER["REQUEST_URI"],'action=classifybilled') && $object->billed) { header("Location: $_SERVER[PHP_SELF]?id=$object->id"); exit(); } //Used to not reclass as closed command which is already closed by refreshing the page - if (strpos( $_SERVER["REQUEST_URI"],'action=confirm_shipped') && Commande::STATUS_CLOSED) + if (strpos($_SERVER["REQUEST_URI"],'action=confirm_shipped') && Commande::STATUS_CLOSED) { header("Location: $_SERVER[PHP_SELF]?id=$object->id"); exit(); From 90b2d41b02b02b9e1e74bbedb356537d9d5e4299 Mon Sep 17 00:00:00 2001 From: lmarcouiller Date: Mon, 19 Oct 2020 14:19:34 +0200 Subject: [PATCH 5/7] FIX pb of duplicate event on command when refreshing the page after command classification as billed or closed --- htdocs/commande/card.php | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php index 6a51dcd4aaa..bd0d7c469a5 100644 --- a/htdocs/commande/card.php +++ b/htdocs/commande/card.php @@ -1282,14 +1282,10 @@ if (empty($reshook)) exit(); } - //Used to not reclass as billed a command which is already billed by refreshing the page - if (strpos($_SERVER["REQUEST_URI"],'action=classifybilled') && $object->billed) - { - header("Location: $_SERVER[PHP_SELF]?id=$object->id"); - exit(); - } - //Used to not reclass as closed command which is already closed by refreshing the page - if (strpos($_SERVER["REQUEST_URI"],'action=confirm_shipped') && Commande::STATUS_CLOSED) + //Used to not reclass as a billed or closed command which is already billed by refreshing the page + if (strpos($_SERVER["REQUEST_URI"], 'action=classifybilled') && $object->billed + || strpos($_SERVER["REQUEST_URI"], 'action=confirm_shipped') && Commande::STATUS_CLOSED + ) { header("Location: $_SERVER[PHP_SELF]?id=$object->id"); exit(); From 1ee8c34bf5a970a9b25f3fc16e4482bddcf2111d Mon Sep 17 00:00:00 2001 From: lmarcouiller Date: Mon, 19 Oct 2020 14:20:49 +0200 Subject: [PATCH 6/7] FIX pb of duplicate event on command when refreshing the page after command classification as billed or closed --- htdocs/commande/card.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php index bd0d7c469a5..fe40a4f9306 100644 --- a/htdocs/commande/card.php +++ b/htdocs/commande/card.php @@ -1283,8 +1283,8 @@ if (empty($reshook)) } //Used to not reclass as a billed or closed command which is already billed by refreshing the page - if (strpos($_SERVER["REQUEST_URI"], 'action=classifybilled') && $object->billed - || strpos($_SERVER["REQUEST_URI"], 'action=confirm_shipped') && Commande::STATUS_CLOSED + if (strpos($_SERVER["REQUEST_URI"], 'action=classifybilled') && $object->billed + || strpos($_SERVER["REQUEST_URI"], 'action=confirm_shipped') && Commande::STATUS_CLOSED ) { header("Location: $_SERVER[PHP_SELF]?id=$object->id"); From 42aafeb8b5fb5a2c4ffe2b18e154c5b80b0aa674 Mon Sep 17 00:00:00 2001 From: lmarcouiller Date: Fri, 23 Oct 2020 09:56:35 +0200 Subject: [PATCH 7/7] FIX pb of duplicate event on command with eldy's recommendations --- htdocs/commande/card.php | 9 --------- htdocs/commande/class/commande.class.php | 8 ++++++++ 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php index fe40a4f9306..697995ef9c1 100644 --- a/htdocs/commande/card.php +++ b/htdocs/commande/card.php @@ -1282,15 +1282,6 @@ if (empty($reshook)) exit(); } - //Used to not reclass as a billed or closed command which is already billed by refreshing the page - if (strpos($_SERVER["REQUEST_URI"], 'action=classifybilled') && $object->billed - || strpos($_SERVER["REQUEST_URI"], 'action=confirm_shipped') && Commande::STATUS_CLOSED - ) - { - header("Location: $_SERVER[PHP_SELF]?id=$object->id"); - exit(); - } - // add lines from objectlinked if ($action == 'import_lines_from_object' && $usercancreate diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index f2aab587169..13609caad25 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -745,6 +745,10 @@ class Commande extends CommonOrder if ($usercanclose) { $this->db->begin(); + if ($this->statut == self::STATUS_CLOSED) + { + return 0; + } $now = dol_now(); @@ -2882,6 +2886,10 @@ class Commande extends CommonOrder $error = 0; $this->db->begin(); + if ($this->billed) + { + return 0; + } $sql = 'UPDATE '.MAIN_DB_PREFIX.'commande SET facture = 1'; $sql .= ' WHERE rowid = '.$this->id.' AND fk_statut > '.self::STATUS_DRAFT;