From 1b9cdd021a850ea591acc3f1914b4cf31046bded Mon Sep 17 00:00:00 2001 From: Christophe Battarel Date: Wed, 27 Mar 2019 10:00:29 +0100 Subject: [PATCH 1/4] test constant for keeping customer ref on clone of order like in propal --- htdocs/commande/class/commande.class.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 07b7a907150..b76a40f7672 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -1116,7 +1116,7 @@ class Commande extends CommonOrder $this->date_commande = dol_now(); $this->date_creation = ''; $this->date_validation = ''; - $this->ref_client = ''; + if (empty($conf->global->MAIN_KEEP_REF_CUSTOMER_ON_CLONING)) $this->ref_client = ''; // Create clone $this->context['createfromclone'] = 'createfromclone'; @@ -1367,7 +1367,7 @@ class Commande extends CommonOrder // Check parameters if ($type < 0) return -1; - + if ($date_start && $date_end && $date_start > $date_end) { $langs->load("errors"); $this->error=$langs->trans('ErrorStartDateGreaterEnd'); @@ -2947,7 +2947,7 @@ class Commande extends CommonOrder if (empty($txlocaltax2)) $txlocaltax2=0; if (empty($remise_percent)) $remise_percent=0; if (empty($special_code) || $special_code == 3) $special_code=0; - + if ($date_start && $date_end && $date_start > $date_end) { $langs->load("errors"); $this->error=$langs->trans('ErrorStartDateGreaterEnd'); @@ -2962,7 +2962,7 @@ class Commande extends CommonOrder $txtva=price2num($txtva); $txlocaltax1=price2num($txlocaltax1); $txlocaltax2=price2num($txlocaltax2); - + $this->db->begin(); // Calcul du total TTC et de la TVA pour la ligne a partir de From 9efb1b95254a9f11b08f309e7c39daa58268d521 Mon Sep 17 00:00:00 2001 From: Christophe Battarel Date: Wed, 27 Mar 2019 10:09:45 +0100 Subject: [PATCH 2/4] copy internal and external contacts when cloning like in propal --- htdocs/commande/class/commande.class.php | 119 +++++++++++++---------- 1 file changed, 69 insertions(+), 50 deletions(-) diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index b76a40f7672..69cdae6a181 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -1085,69 +1085,88 @@ class Commande extends CommonOrder foreach($this->lines as $line) $line->fetch_optionals(); - // Load source object - $objFrom = clone $this; + // Load source object + $objFrom = clone $this; - // Change socid if needed - if (! empty($socid) && $socid != $this->socid) + // Change socid if needed + if (! empty($socid) && $socid != $this->socid) + { + $objsoc = new Societe($this->db); + + if ($objsoc->fetch($socid)>0) { - $objsoc = new Societe($this->db); - - if ($objsoc->fetch($socid)>0) - { - $this->socid = $objsoc->id; - $this->cond_reglement_id = (! empty($objsoc->cond_reglement_id) ? $objsoc->cond_reglement_id : 0); - $this->mode_reglement_id = (! empty($objsoc->mode_reglement_id) ? $objsoc->mode_reglement_id : 0); - $this->fk_project = 0; - $this->fk_delivery_address = 0; - } - - // TODO Change product price if multi-prices + $this->socid = $objsoc->id; + $this->cond_reglement_id = (! empty($objsoc->cond_reglement_id) ? $objsoc->cond_reglement_id : 0); + $this->mode_reglement_id = (! empty($objsoc->mode_reglement_id) ? $objsoc->mode_reglement_id : 0); + $this->fk_project = 0; + $this->fk_delivery_address = 0; } - $this->id=0; - $this->ref = ''; - $this->statut=self::STATUS_DRAFT; + // TODO Change product price if multi-prices + } - // Clear fields - $this->user_author_id = $user->id; - $this->user_valid = ''; - $this->date = dol_now(); - $this->date_commande = dol_now(); - $this->date_creation = ''; - $this->date_validation = ''; - if (empty($conf->global->MAIN_KEEP_REF_CUSTOMER_ON_CLONING)) $this->ref_client = ''; + $this->id=0; + $this->ref = ''; + $this->statut=self::STATUS_DRAFT; - // Create clone - $this->context['createfromclone'] = 'createfromclone'; - $result=$this->create($user); - if ($result < 0) $error++; + // Clear fields + $this->user_author_id = $user->id; + $this->user_valid = ''; + $this->date = dol_now(); + $this->date_commande = dol_now(); + $this->date_creation = ''; + $this->date_validation = ''; + if (empty($conf->global->MAIN_KEEP_REF_CUSTOMER_ON_CLONING)) $this->ref_client = ''; - if (! $error) + // Create clone + $this->context['createfromclone'] = 'createfromclone'; + $result=$this->create($user); + if ($result < 0) $error++; + + if (! $error) + { + // copy internal contacts + if ($this->copy_linked_contact($objFrom, 'internal') < 0) { - // Hook of thirdparty module - if (is_object($hookmanager)) - { - $parameters=array('objFrom'=>$objFrom); - $action=''; - $reshook=$hookmanager->executeHooks('createFrom', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks - if ($reshook < 0) $error++; - } + $error++; } + } - unset($this->context['createfromclone']); + if (! $error) + { + // copy external contacts if same company + if ($this->socid == $object->socid) + { + if ($this->copy_linked_contact($objFrom, 'external') < 0) + $error++; + } + } - // End - if (! $error) + if (! $error) + { + // Hook of thirdparty module + if (is_object($hookmanager)) { - $this->db->commit(); - return $this->id; - } - else - { - $this->db->rollback(); - return -1; + $parameters=array('objFrom'=>$objFrom); + $action=''; + $reshook=$hookmanager->executeHooks('createFrom', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks + if ($reshook < 0) $error++; } + } + + unset($this->context['createfromclone']); + + // End + if (! $error) + { + $this->db->commit(); + return $this->id; + } + else + { + $this->db->rollback(); + return -1; + } } From f1548bd253fc40b2b5913b31612c7536c76445f1 Mon Sep 17 00:00:00 2001 From: Christophe Battarel Date: Wed, 27 Mar 2019 10:27:08 +0100 Subject: [PATCH 3/4] fix objfrom --- htdocs/commande/class/commande.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 69cdae6a181..81d13b749ba 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -1135,7 +1135,7 @@ class Commande extends CommonOrder if (! $error) { // copy external contacts if same company - if ($this->socid == $object->socid) + if ($this->socid == $objFrom->socid) { if ($this->copy_linked_contact($objFrom, 'external') < 0) $error++; From c9b321ded48092375d11621fa1e17e88aebf0331 Mon Sep 17 00:00:00 2001 From: Christophe Battarel Date: Wed, 27 Mar 2019 10:32:40 +0100 Subject: [PATCH 4/4] add global conf to createfromclone --- htdocs/commande/class/commande.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 81d13b749ba..b6e4010600c 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -1075,7 +1075,7 @@ class Commande extends CommonOrder */ public function createFromClone($socid = 0) { - global $user,$hookmanager; + global $conf, $user,$hookmanager; $error=0;