diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php
index e1fa3eff3d7..a2f833704d5 100644
--- a/htdocs/comm/propal.php
+++ b/htdocs/comm/propal.php
@@ -101,15 +101,15 @@ if (! empty($object->hooks))
}
// Action clone object
-if ($_REQUEST["action"] == 'confirm_clone' && $_REQUEST['confirm'] == 'yes')
+if ($action == 'confirm_clone' && $confirm == 'yes')
{
- if (1==0 && empty($_REQUEST["clone_content"]) && empty($_REQUEST["clone_receivers"]))
+ if (1==0 && ! GETPOST('clone_content') && ! GETPOST('clone_receivers') )
{
$mesg='
'.$langs->trans("NoCloneOptionsSpecified").'
';
}
else
{
- $result=$object->createFromClone($_REQUEST["id"]);
+ $result=$object->createFromClone($id,0,GETPOST('socid'));
if ($result > 0)
{
header("Location: ".$_SERVER['PHP_SELF'].'?id='.$result);
@@ -1016,7 +1016,9 @@ if ($id > 0 || ! empty($ref))
// Create an array for form
$formquestion=array(
//'text' => $langs->trans("ConfirmClone"),
- //array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1)
+ //array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
+ //array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
+ array('type' => 'other', 'name' => 'socid', 'label' => $langs->trans("SelectThirdParty"), 'value' => $html->select_company(GETPOST('socid'),'socid','(s.client=1 OR s.client=3)'))
);
// Paiement incomplet. On demande si motif = escompte ou autre
$formconfirm=$html->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id,$langs->trans('ClonePropal'),$langs->trans('ConfirmClonePropal',$object->ref),'confirm_clone',$formquestion,'yes',1);
@@ -1570,7 +1572,7 @@ if ($id > 0 || ! empty($ref))
// Clone
if ($object->type == 0 && $user->rights->propale->creer)
{
- print ''.$langs->trans("ToClone").'';
+ print ''.$langs->trans("ToClone").'';
}
// Delete
diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php
index 3973582e880..4fa963f03f3 100644
--- a/htdocs/comm/propal/class/propal.class.php
+++ b/htdocs/comm/propal/class/propal.class.php
@@ -813,12 +813,13 @@ class Propal extends CommonObject
}
/**
- * \brief Load an object from its id and create a new one in database
- * \param fromid Id of object to clone
- * \param invertdetail Reverse sign of amounts for lines
- * \return int New id of clone
+ * Load an object from its id and create a new one in database
+ * @param fromid Id of object to clone
+ * @param invertdetail Reverse sign of amounts for lines
+ * @param socid Id of thirdparty
+ * @return int New id of clone
*/
- function createFromClone($fromid,$invertdetail=0)
+ function createFromClone($fromid,$invertdetail=0,$socid=0)
{
global $user,$langs,$conf;
@@ -839,12 +840,31 @@ class Propal extends CommonObject
// Load source object
$object->fetch($fromid);
$objFrom = $object;
+
+ $objsoc=new Societe($this->db);
+
+ // Change socid if needed
+ if (! empty($socid) && $socid != $object->socid)
+ {
+ if ($objsoc->fetch($socid)>0)
+ {
+ $object->socid = $objsoc->id;
+ $object->cond_reglement_id = $objsoc->cond_reglement_id;
+ $object->mode_reglement_id = $objsoc->mode_reglement_id;
+ $object->fk_project = '';
+ $object->fk_delivery_address = '';
+ }
+
+ // TODO Change product price if multi-prices
+ }
+ else
+ {
+ $objsoc->fetch($object->socid);
+ }
$object->id=0;
$object->statut=0;
- require_once(DOL_DOCUMENT_ROOT ."/societe/class/societe.class.php");
- $objsoc=new Societe($this->db);
$objsoc->fetch($object->socid);
if (empty($conf->global->PROPALE_ADDON) || ! is_readable(DOL_DOCUMENT_ROOT ."/includes/modules/propale/".$conf->global->PROPALE_ADDON.".php"))
diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php
index 4c6de60ce16..fd0f3faa95a 100644
--- a/htdocs/commande/class/commande.class.php
+++ b/htdocs/commande/class/commande.class.php
@@ -739,13 +739,13 @@ class Commande extends CommonObject
// Change socid if needed
if (! empty($socid) && $socid != $object->socid)
{
- $socstatic = new Societe($this->db);
+ $objsoc = new Societe($this->db);
- if ($socstatic->fetch($socid)>0)
+ if ($objsoc->fetch($socid)>0)
{
- $object->socid = $socid;
- $object->cond_reglement_id = $soc->cond_reglement_id;
- $object->mode_reglement_id = $soc->mode_reglement_id;
+ $object->socid = $objsoc->id;
+ $object->cond_reglement_id = $objsoc->cond_reglement_id;
+ $object->mode_reglement_id = $objsoc->mode_reglement_id;
$object->fk_project = '';
$object->fk_delivery_address = '';
}