diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index f8f246924e3..4feeb3d60b6 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -1,22 +1,23 @@ - * Copyright (C) 2004-2013 Laurent Destailleur - * Copyright (C) 2004 Sebastien Di Cintio - * Copyright (C) 2004 Benoit Mortier - * Copyright (C) 2005 Marc Barilley / Ocebo - * Copyright (C) 2005-2014 Regis Houssin - * Copyright (C) 2006 Andre Cianfarani - * Copyright (C) 2007 Franky Van Liedekerke - * Copyright (C) 2010-2020 Juanjo Menent - * Copyright (C) 2012-2014 Christophe Battarel - * Copyright (C) 2012-2015 Marcos García - * Copyright (C) 2012 Cédric Salvador - * Copyright (C) 2012-2014 Raphaël Doursenaud - * Copyright (C) 2013 Cedric Gross - * Copyright (C) 2013 Florian Henry - * Copyright (C) 2016 Ferran Marcet - * Copyright (C) 2018 Alexandre Spangaro - * Copyright (C) 2018 Nicolas ZABOURI +/* Copyright (C) 2002-2007 Rodolphe Quiedeville + * Copyright (C) 2004-2013 Laurent Destailleur + * Copyright (C) 2004 Sebastien Di Cintio + * Copyright (C) 2004 Benoit Mortier + * Copyright (C) 2005 Marc Barilley / Ocebo + * Copyright (C) 2005-2014 Regis Houssin + * Copyright (C) 2006 Andre Cianfarani + * Copyright (C) 2007 Franky Van Liedekerke + * Copyright (C) 2010-2020 Juanjo Menent + * Copyright (C) 2012-2014 Christophe Battarel + * Copyright (C) 2012-2015 Marcos García + * Copyright (C) 2012 Cédric Salvador + * Copyright (C) 2012-2014 Raphaël Doursenaud + * Copyright (C) 2013 Cedric Gross + * Copyright (C) 2013 Florian Henry + * Copyright (C) 2016 Ferran Marcet + * Copyright (C) 2018 Alexandre Spangaro + * Copyright (C) 2018 Nicolas ZABOURI + * Copyright (C) 2022 Sylvain Legrand * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -1159,6 +1160,9 @@ class Facture extends CommonInvoice $object->fetch($fromid); + // Load source object + $objFrom = clone $object; + // Change socid if needed if (!empty($this->socid) && $this->socid != $object->socid) { $objsoc = new Societe($this->db); @@ -1239,13 +1243,13 @@ class Facture extends CommonInvoice $this->errors = $object->errors; } else { // copy internal contacts - if ($object->copy_linked_contact($this, 'internal') < 0) { + if ($object->copy_linked_contact($objFrom, 'internal') < 0) { $error++; $this->error = $object->error; $this->errors = $object->errors; - } elseif ($this->socid == $object->socid) { + } elseif ($object->socid == $objFrom->socid) { // copy external contacts if same company - if ($object->copy_linked_contact($this, 'external') < 0) { + if ($object->copy_linked_contact($objFrom, 'external') < 0) { $error++; $this->error = $object->error; $this->errors = $object->errors; @@ -1256,7 +1260,7 @@ class Facture extends CommonInvoice if (!$error) { // Hook of thirdparty module if (is_object($hookmanager)) { - $parameters = array('objFrom'=>$this); + $parameters = array('objFrom'=>$objFrom); $action = ''; $reshook = $hookmanager->executeHooks('createFrom', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks if ($reshook < 0) {