diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php
index 28f98c739c3..dc4077dea5c 100644
--- a/htdocs/comm/propal.php
+++ b/htdocs/comm/propal.php
@@ -99,23 +99,25 @@ $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action);
// Action clone object
if ($action == 'confirm_clone' && $confirm == 'yes')
{
- if (1==0 && ! GETPOST('clone_content') && ! GETPOST('clone_receivers') )
+ if (1==0 && ! GETPOST('clone_content') && ! GETPOST('clone_receivers'))
{
$mesg='
'.$langs->trans("NoCloneOptionsSpecified").'
';
}
else
{
- $result=$object->createFromClone($id,0,GETPOST('socid'),$hookmanager);
- if ($result > 0)
+ if ($object->fetch($id) > 0)
{
- header("Location: ".$_SERVER['PHP_SELF'].'?id='.$result);
- exit;
- }
- else
- {
- $mesg=$object->error;
- $action='';
- //$_GET['id']=$_REQUEST['id'];
+ $result=$object->createFromClone($socid, $hookmanager);
+ if ($result > 0)
+ {
+ header("Location: ".$_SERVER['PHP_SELF'].'?id='.$result);
+ exit;
+ }
+ else
+ {
+ $mesg=$object->error;
+ $action='';
+ }
}
}
}
diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php
index 82057f92f64..cc2065e0a0c 100644
--- a/htdocs/comm/propal/class/propal.class.php
+++ b/htdocs/comm/propal/class/propal.class.php
@@ -836,53 +836,45 @@ class Propal extends CommonObject
/**
* Load an object from its id and create a new one in database
*
- * @param int $fromid Id of object to clone
- * @param int $invertdetail Reverse sign of amounts for lines
* @param int $socid Id of thirdparty
* @param HookManager $hookmanager Hook manager instance
* @return int New id of clone
*/
- function createFromClone($fromid,$invertdetail=0,$socid=0,$hookmanager=false)
+ function createFromClone($socid=0,$hookmanager=false)
{
global $user,$langs,$conf;
$error=0;
-
$now=dol_now();
- $object=new Propal($this->db);
-
$this->db->begin();
// Load source object
- $object->fetch($fromid);
- $objFrom = $object;
+ $objFrom = dol_clone($this);
$objsoc=new Societe($this->db);
// Change socid if needed
- if (! empty($socid) && $socid != $object->socid)
+ if (! empty($socid) && $socid != $this->socid)
{
- if ($objsoc->fetch($socid)>0)
+ if ($objsoc->fetch($socid) > 0)
{
- $object->socid = $objsoc->id;
- $object->cond_reglement_id = (! empty($objsoc->cond_reglement_id) ? $objsoc->cond_reglement_id : 0);
- $object->mode_reglement_id = (! empty($objsoc->mode_reglement_id) ? $objsoc->mode_reglement_id : 0);
- $object->fk_project = '';
- $object->fk_delivery_address = '';
+ $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 = '';
+ $this->fk_delivery_address = '';
}
// TODO Change product price if multi-prices
}
else
{
- $objsoc->fetch($object->socid);
+ $objsoc->fetch($this->socid);
}
- $object->id=0;
- $object->statut=0;
-
- $objsoc->fetch($object->socid);
+ $this->id=0;
+ $this->statut=0;
if (empty($conf->global->PROPALE_ADDON) || ! is_readable(DOL_DOCUMENT_ROOT ."/core/modules/propale/".$conf->global->PROPALE_ADDON.".php"))
{
@@ -891,28 +883,22 @@ class Propal extends CommonObject
}
// Clear fields
- $object->user_author = $user->id;
- $object->user_valid = '';
- $object->date = '';
- $object->datep = $now;
- $object->fin_validite = $object->datep + ($this->duree_validite * 24 * 3600);
- $object->ref_client = '';
+ $this->user_author = $user->id;
+ $this->user_valid = '';
+ $this->date = '';
+ $this->datep = $now;
+ $this->fin_validite = $this->datep + ($this->duree_validite * 24 * 3600);
+ $this->ref_client = '';
// Set ref
require_once(DOL_DOCUMENT_ROOT ."/core/modules/propale/".$conf->global->PROPALE_ADDON.".php");
$obj = $conf->global->PROPALE_ADDON;
$modPropale = new $obj;
- $object->ref = $modPropale->getNextValue($objsoc,$object);
+ $this->ref = $modPropale->getNextValue($objsoc,$this);
// Create clone
- $result=$object->create($user);
-
- // Other options
- if ($result < 0)
- {
- $this->error=$object->error;
- $error++;
- }
+ $result=$this->create($user);
+ if ($result < 0) $error++;
if (! $error)
{
@@ -921,14 +907,14 @@ class Propal extends CommonObject
{
$parameters=array('objFrom'=>$objFrom);
$action='';
- $reshook=$hookmanager->executeHooks('createfrom',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
+ $reshook=$hookmanager->executeHooks('createfrom',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) $error++;
}
// Appel des triggers
include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
$interface=new Interfaces($this->db);
- $result=$interface->run_triggers('PROPAL_CLONE',$object,$user,$langs,$conf);
+ $result=$interface->run_triggers('PROPAL_CLONE',$this,$user,$langs,$conf);
if ($result < 0) { $error++; $this->errors=$interface->errors; }
// Fin appel triggers
}
@@ -937,7 +923,7 @@ class Propal extends CommonObject
if (! $error)
{
$this->db->commit();
- return $object->id;
+ return $this->id;
}
else
{
diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php
index 2e663f1fe4d..dcc92d7d0ea 100644
--- a/htdocs/commande/class/commande.class.php
+++ b/htdocs/commande/class/commande.class.php
@@ -769,62 +769,51 @@ class Commande extends CommonObject
/**
* Load an object from its id and create a new one in database
*
- * @param int $fromid Id of object to clone
- * @param int $invertdetail Reverse sign of amounts for lines
* @param int $socid Id of thirdparty
* @param HookManager $hookmanager Hook manager instance
* @return int New id of clone
*/
- function createFromClone($fromid,$invertdetail=0,$socid=0,$hookmanager=false)
+ function createFromClone($socid=0,$hookmanager=false)
{
global $conf,$user,$langs;
$error=0;
- $object=new Commande($this->db);
-
$this->db->begin();
// Load source object
- $object->fetch($fromid);
- $objFrom = $object;
+ $objFrom = dol_clone($this);
// Change socid if needed
- if (! empty($socid) && $socid != $object->socid)
+ if (! empty($socid) && $socid != $this->socid)
{
$objsoc = new Societe($this->db);
if ($objsoc->fetch($socid)>0)
{
- $object->socid = $objsoc->id;
- $object->cond_reglement_id = (! empty($objsoc->cond_reglement_id) ? $objsoc->cond_reglement_id : 0);
- $object->mode_reglement_id = (! empty($objsoc->mode_reglement_id) ? $objsoc->mode_reglement_id : 0);
- $object->fk_project = '';
- $object->fk_delivery_address = '';
+ $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 = '';
+ $this->fk_delivery_address = '';
}
// TODO Change product price if multi-prices
}
- $object->id=0;
- $object->statut=0;
+ $this->id=0;
+ $this->statut=0;
// Clear fields
- $object->user_author_id = $user->id;
- $object->user_valid = '';
- $object->date_creation = '';
- $object->date_validation = '';
- $object->ref_client = '';
+ $this->user_author_id = $user->id;
+ $this->user_valid = '';
+ $this->date_creation = '';
+ $this->date_validation = '';
+ $this->ref_client = '';
// Create clone
- $result=$object->create($user);
-
- // Other options
- if ($result < 0)
- {
- $this->error=$object->error;
- $error++;
- }
+ $result=$this->create($user);
+ if ($result < 0) $error++;
if (! $error)
{
@@ -833,14 +822,14 @@ class Commande extends CommonObject
{
$parameters=array('objFrom'=>$objFrom);
$action='';
- $reshook=$hookmanager->executeHooks('createfrom',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
+ $reshook=$hookmanager->executeHooks('createfrom',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) $error++;
}
// Appel des triggers
include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
$interface=new Interfaces($this->db);
- $result=$interface->run_triggers('ORDER_CLONE',$object,$user,$langs,$conf);
+ $result=$interface->run_triggers('ORDER_CLONE',$this,$user,$langs,$conf);
if ($result < 0) { $error++; $this->errors=$interface->errors; }
// Fin appel triggers
}
@@ -849,7 +838,7 @@ class Commande extends CommonObject
if (! $error)
{
$this->db->commit();
- return $object->id;
+ return $this->id;
}
else
{
diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php
index ffe5b39e31a..9a7cc4a397e 100644
--- a/htdocs/commande/fiche.php
+++ b/htdocs/commande/fiche.php
@@ -79,23 +79,26 @@ $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action);
// Action clone object
if ($action == 'confirm_clone' && $confirm == 'yes')
{
- if ( 1==0 && ! GETPOST('clone_content') && ! GETPOST('clone_receivers') )
+ if (1==0 && ! GETPOST('clone_content') && ! GETPOST('clone_receivers'))
{
$mesg=''.$langs->trans("NoCloneOptionsSpecified").'
';
}
else
{
- $result=$object->createFromClone($id, 0, GETPOST('socid'), $hookmanager);
- if ($result > 0)
- {
- header("Location: ".$_SERVER['PHP_SELF'].'?id='.$result);
- exit;
- }
- else
- {
- $mesg=''.$object->error.'
';
- $action='';
- }
+ if ($object->fetch($id) > 0)
+ {
+ $result=$object->createFromClone($socid, $hookmanager);
+ if ($result > 0)
+ {
+ header("Location: ".$_SERVER['PHP_SELF'].'?id='.$result);
+ exit;
+ }
+ else
+ {
+ $mesg=''.$object->error.'
';
+ $action='';
+ }
+ }
}
}
diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php
index 82e2c659f15..0f34e84e434 100644
--- a/htdocs/compta/facture.php
+++ b/htdocs/compta/facture.php
@@ -98,17 +98,20 @@ if ($action == 'confirm_clone' && $confirm == 'yes')
}
else
{
- $result=$object->createFromClone($id,0,$hookmanager);
- if ($result > 0)
- {
- header("Location: ".$_SERVER['PHP_SELF'].'?facid='.$result);
- exit;
- }
- else
- {
- $mesg=$object->error;
- $action='';
- }
+ if ($object->fetch($id) > 0)
+ {
+ $result=$object->createFromClone($socid, $hookmanager);
+ if ($result > 0)
+ {
+ header("Location: ".$_SERVER['PHP_SELF'].'?facid='.$result);
+ exit;
+ }
+ else
+ {
+ $mesg=$object->error;
+ $action='';
+ }
+ }
}
}
diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php
index 6b8715bd1a1..cbe54bf29fd 100644
--- a/htdocs/compta/facture/class/facture.class.php
+++ b/htdocs/compta/facture/class/facture.class.php
@@ -490,60 +490,65 @@ class Facture extends CommonObject
/**
* Load an object from its id and create a new one in database
*
- * @param int $fromid Id of object to clone
- * @param int $invertdetail Reverse sign of amounts for lines
+ * @param int $socid Id of thirdparty
* @param HookManager $hookmanager Hook manager instance
* @return int New id of clone
*/
- function createFromClone($fromid,$invertdetail=0,$hookmanager=false)
+ function createFromClone($socid=0,$hookmanager=false)
{
global $conf,$user,$langs;
$error=0;
-
- // Load source object
- $objFrom=new Facture($this->db);
- $objFrom->fetch($fromid);
-
- // Load new object
- $object=new Facture($this->db);
- $object->fetch($fromid);
-
+
$this->db->begin();
- $object->id=0;
- $object->statut=0;
+ // Load source object
+ $objFrom = dol_clone($this);
+
+ // Change socid if needed
+ if (! empty($socid) && $socid != $this->socid)
+ {
+ $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 = '';
+ $this->fk_delivery_address = '';
+ }
+
+ // TODO Change product price if multi-prices
+ }
+
+ $this->id=0;
+ $this->statut=0;
// Clear fields
- $object->user_author = $user->id;
- $object->user_valid = '';
- $object->fk_facture_source = 0;
- $object->date_creation = '';
- $object->date_validation = '';
- $object->ref_client = '';
- $object->close_code = '';
- $object->close_note = '';
- $object->products = $object->lines; // Tant que products encore utilise
+ $this->user_author = $user->id;
+ $this->user_valid = '';
+ $this->fk_facture_source = 0;
+ $this->date_creation = '';
+ $this->date_validation = '';
+ $this->ref_client = '';
+ $this->close_code = '';
+ $this->close_note = '';
+ $this->products = $this->lines; // Tant que products encore utilise
// Loop on each line of new invoice
- foreach($object->lines as $i => $line)
+ foreach($this->lines as $i => $line)
{
- if (($object->lines[$i]->info_bits & 0x02) == 0x02) // We do not clone line of discounts
+ if (($this->lines[$i]->info_bits & 0x02) == 0x02) // We do not clone line of discounts
{
- unset($object->lines[$i]);
- unset($object->products[$i]); // Tant que products encore utilise
+ unset($this->lines[$i]);
+ unset($this->products[$i]); // Tant que products encore utilise
}
}
// Create clone
- $result=$object->create($user);
-
- // Other options
- if ($result < 0)
- {
- $this->error=$object->error;
- $error++;
- }
+ $result=$this->create($user);
+ if ($result < 0) $error++;
if (! $error)
{
@@ -552,14 +557,14 @@ class Facture extends CommonObject
{
$parameters=array('objFrom'=>$objFrom);
$action='';
- $reshook=$hookmanager->executeHooks('createfrom',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
+ $reshook=$hookmanager->executeHooks('createfrom',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) $error++;
}
// Appel des triggers
include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
$interface=new Interfaces($this->db);
- $result=$interface->run_triggers('BILL_CLONE',$object,$user,$langs,$conf);
+ $result=$interface->run_triggers('BILL_CLONE',$this,$user,$langs,$conf);
if ($result < 0) { $error++; $this->errors=$interface->errors; }
// Fin appel triggers
}
@@ -568,7 +573,7 @@ class Facture extends CommonObject
if (! $error)
{
$this->db->commit();
- return $object->id;
+ return $this->id;
}
else
{