mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-02-20 13:46:52 +01:00
Merge pull request #1381 from altairis-fr/clonepropal
clone of propal improvements
This commit is contained in:
commit
bdbbb580f8
|
|
@ -8,7 +8,7 @@
|
|||
* Copyright (C) 2008 Raphael Bertrand <raphael.bertrand@resultic.fr>
|
||||
* Copyright (C) 2010-2013 Juanjo Menent <jmenent@2byte.es>
|
||||
* Copyright (C) 2010-2011 Philippe Grand <philippe.grand@atoo-net.com>
|
||||
* Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
|
||||
* Copyright (C) 2012-214 Christophe Battarel <christophe.battarel@altairis.fr>
|
||||
* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
|
|
@ -939,6 +939,9 @@ class Propal extends CommonObject
|
|||
$this->fk_delivery_address = '';
|
||||
}
|
||||
|
||||
// reset ref_client
|
||||
$this->ref_client = '';
|
||||
|
||||
// TODO Change product price if multi-prices
|
||||
}
|
||||
else
|
||||
|
|
@ -961,7 +964,7 @@ class Propal extends CommonObject
|
|||
$this->date = $now;
|
||||
$this->datep = $now; // deprecated
|
||||
$this->fin_validite = $this->date + ($this->duree_validite * 24 * 3600);
|
||||
$this->ref_client = '';
|
||||
if (empty($conf->global->MAIN_KEEP_REF_CUSTOMER_ON_CLONING)) $this->ref_client = '';
|
||||
|
||||
// Set ref
|
||||
require_once DOL_DOCUMENT_ROOT ."/core/modules/propale/".$conf->global->PROPALE_ADDON.'.php';
|
||||
|
|
@ -972,6 +975,19 @@ class Propal extends CommonObject
|
|||
// Create clone
|
||||
$result=$this->create($user);
|
||||
if ($result < 0) $error++;
|
||||
else
|
||||
{
|
||||
// copy internal contacts
|
||||
if ($this->copy_linked_contact($objFrom, 'internal') < 0)
|
||||
$error++;
|
||||
|
||||
// copy external contacts if same company
|
||||
elseif ($objFrom->socid == $this->socid)
|
||||
{
|
||||
if ($this->copy_linked_contact($objFrom, 'external') < 0)
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -238,6 +238,30 @@ abstract class CommonObject
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy contact from one element to current
|
||||
*
|
||||
* @param int $rowid source element
|
||||
* @param int $rowid contact source (internal / external)
|
||||
* @return int >0 if OK, <0 if KO
|
||||
*/
|
||||
function copy_linked_contact($objFrom, $source='internal')
|
||||
{
|
||||
global $user,$langs,$conf;
|
||||
|
||||
$contacts = $objFrom->liste_contact(-1, $source);
|
||||
foreach($contacts as $contact)
|
||||
{
|
||||
if ($this->add_contact($contact['id'], $contact['fk_c_type_contact'], $contact['source']) < 0)
|
||||
{
|
||||
$this->error=$this->db->lasterror();
|
||||
dol_syslog(get_class($this)."::copy_contact error=".$this->error, LOG_ERR);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a link to contact line
|
||||
*
|
||||
|
|
@ -355,7 +379,7 @@ abstract class CommonObject
|
|||
|
||||
$tab=array();
|
||||
|
||||
$sql = "SELECT ec.rowid, ec.statut, ec.fk_socpeople as id"; // This field contains id of llx_socpeople or id of llx_user
|
||||
$sql = "SELECT ec.rowid, ec.statut, ec.fk_socpeople as id, ec.fk_c_type_contact"; // This field contains id of llx_socpeople or id of llx_user
|
||||
if ($source == 'internal') $sql.=", '-1' as socid";
|
||||
if ($source == 'external' || $source == 'thirdparty') $sql.=", t.fk_soc as socid";
|
||||
$sql.= ", t.civilite as civility, t.lastname as lastname, t.firstname, t.email";
|
||||
|
|
@ -390,7 +414,7 @@ abstract class CommonObject
|
|||
$tab[$i]=array('source'=>$obj->source,'socid'=>$obj->socid,'id'=>$obj->id,
|
||||
'nom'=>$obj->lastname, // For backward compatibility
|
||||
'civility'=>$obj->civility, 'lastname'=>$obj->lastname, 'firstname'=>$obj->firstname, 'email'=>$obj->email,
|
||||
'rowid'=>$obj->rowid,'code'=>$obj->code,'libelle'=>$libelle_type,'status'=>$obj->statut);
|
||||
'rowid'=>$obj->rowid,'code'=>$obj->code,'libelle'=>$libelle_type,'status'=>$obj->statut, 'fk_c_type_contact' => $obj->fk_c_type_contact);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user