From 71db2603e15759585db8923fccce6a9c1bbfae96 Mon Sep 17 00:00:00 2001 From: lmarcouiller Date: Mon, 19 Oct 2020 13:52:12 +0200 Subject: [PATCH 1/9] 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/9] 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/9] 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/9] 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/9] 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/9] 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 57064a79762970820886c5f039a29c8b00a2f4fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Fri, 23 Oct 2020 08:07:00 +0200 Subject: [PATCH 7/9] fix phpcs --- htdocs/expensereport/class/expensereport.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/expensereport/class/expensereport.class.php b/htdocs/expensereport/class/expensereport.class.php index 817e211e957..d91893223b0 100644 --- a/htdocs/expensereport/class/expensereport.class.php +++ b/htdocs/expensereport/class/expensereport.class.php @@ -2192,7 +2192,7 @@ class ExpenseReport extends CommonObject $modele = $conf->global->EXPENSEREPORT_ADDON_PDF; } } - + if (!empty($modele)) { $modelpath = "core/modules/expensereport/doc/"; From 0f1996759f2a90f53ccdd760059262e457120141 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Fri, 23 Oct 2020 08:12:19 +0200 Subject: [PATCH 8/9] fix phpcs --- .../class/rejetprelevement.class.php | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/htdocs/compta/prelevement/class/rejetprelevement.class.php b/htdocs/compta/prelevement/class/rejetprelevement.class.php index fce3096c41f..f1a396f131f 100644 --- a/htdocs/compta/prelevement/class/rejetprelevement.class.php +++ b/htdocs/compta/prelevement/class/rejetprelevement.class.php @@ -47,6 +47,7 @@ class RejetPrelevement * * @param DoliDb $db Database handler * @param User $user Objet user + * @param string $type type */ public function __construct($db, $user, $type) { @@ -137,13 +138,11 @@ class RejetPrelevement } $num = count($facs); - for ($i = 0; $i < $num; $i++) - { - if($this->type == 'bank-transfer'){ + for ($i = 0; $i < $num; $i++) { + if ($this->type == 'bank-transfer') { $fac = new FactureFournisseur($this->db); $pai = new PaiementFourn($this->db); - } - else{ + } else { $fac = new Facture($this->db); $pai = new Paiement($this->db); } @@ -165,21 +164,19 @@ class RejetPrelevement $pai->paiementid = 3; // type of payment: withdrawal $pai->num_payment = $fac->ref; - if ($pai->create($this->user) < 0) // we call with no_commit - { + if ($pai->create($this->user) < 0) { + // we call with no_commit $error++; dol_syslog("RejetPrelevement::Create Error creation payment invoice ".$facs[$i][0]); } else { $result = $pai->addPaymentToBank($user, 'payment', '(InvoiceRefused)', $bankaccount, '', ''); - if ($result < 0) - { + if ($result < 0) { dol_syslog("RejetPrelevement::Create AddPaymentToBan Error"); $error++; } // Payment validation - if ($pai->validate($user) < 0) - { + if ($pai->validate($user) < 0) { $error++; dol_syslog("RejetPrelevement::Create Error payment validation"); } @@ -265,8 +262,7 @@ class RejetPrelevement $mailfile = new CMailFile($subject, $sendto, $from, $message, $arr_file, $arr_mime, $arr_name, '', '', 0, $msgishtml, $this->user->email, '', $trackid); $result = $mailfile->sendfile(); - if ($result) - { + if ($result) { dol_syslog("RejetPrelevement::_send_email email envoye"); } else { dol_syslog("RejetPrelevement::_send_email Erreur envoi email"); @@ -293,8 +289,11 @@ class RejetPrelevement $sql = "SELECT f.rowid as facid, pl.amount"; $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_facture as pf"; //$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture as f ON (pf.fk_facture = f.rowid)"; - if ($this->type == 'bank-transfer') $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture_fourn as f ON (pf.fk_facture_fourn = f.rowid)"; - else $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture as f ON (pf.fk_facture = f.rowid)"; + if ($this->type == 'bank-transfer') { + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture_fourn as f ON (pf.fk_facture_fourn = f.rowid)"; + } else { + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture as f ON (pf.fk_facture = f.rowid)"; + } $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."prelevement_lignes as pl ON (pf.fk_prelevement_lignes = pl.rowid)"; $sql .= " WHERE pf.fk_prelevement_lignes = ".$this->id; @@ -311,8 +310,9 @@ class RejetPrelevement while ($i < $num) { $row = $this->db->fetch_row($resql); - if (!$amounts) $arr[$i] = $row[0]; - else { + if (!$amounts) { + $arr[$i] = $row[0]; + } else { $arr[$i] = array( $row[0], $row[1] @@ -349,9 +349,9 @@ class RejetPrelevement { $obj = $this->db->fetch_object($resql); - $this->id = $rowid; - $this->date_rejet = $this->db->jdate($obj->dr); - $this->motif = $this->motifs[$obj->motif]; + $this->id = $rowid; + $this->date_rejet = $this->db->jdate($obj->dr); + $this->motif = $this->motifs[$obj->motif]; $this->invoicing = $this->facturer[$obj->afacturer]; $this->db->free($resql); From 42aafeb8b5fb5a2c4ffe2b18e154c5b80b0aa674 Mon Sep 17 00:00:00 2001 From: lmarcouiller Date: Fri, 23 Oct 2020 09:56:35 +0200 Subject: [PATCH 9/9] 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;