on going
This commit is contained in:
parent
b535bc0cb9
commit
405c92640c
@ -82,7 +82,7 @@ class Contact extends CommonObject
|
||||
|
||||
public $civility_id; // In fact we store civility_code
|
||||
public $civility_code;
|
||||
public $civility;
|
||||
public $civility;
|
||||
public $address;
|
||||
public $zip;
|
||||
public $town;
|
||||
@ -139,6 +139,8 @@ class Contact extends CommonObject
|
||||
|
||||
public $oldcopy; // To contains a clone of this when we need to save old properties of object
|
||||
|
||||
public $roles=array();
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
@ -1449,4 +1451,50 @@ class Contact extends CommonObject
|
||||
|
||||
return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch Role for a contact
|
||||
*
|
||||
* @return float|int
|
||||
* @throws Exception
|
||||
*/
|
||||
public function fetchRole()
|
||||
{
|
||||
|
||||
global $langs;
|
||||
$error= 0;
|
||||
$num=0;
|
||||
|
||||
$sql ="SELECT tc.rowid, tc.element, tc.source, tc.code, tc.libelle";
|
||||
$sql.=" FROM ".MAIN_DB_PREFIX."societe_contacts as sc ";
|
||||
$sql.=" INNER JOIN ".MAIN_DB_PREFIX."c_type_contact as tc";
|
||||
$sql.=" ON tc.rowid = sc.fk_c_type_contact";
|
||||
$sql.=" AND sc.fk_socpeople = ". $this->id;
|
||||
$sql.=" AND tc.source = 'external' AND tc.active=1";
|
||||
$sql.=" AND sc.entity IN (".getEntity('societe').')';
|
||||
|
||||
dol_syslog(get_class($this)."::".__METHOD__, LOG_DEBUG);
|
||||
|
||||
$this->roles=array();
|
||||
$resql=$this->db->query($sql);
|
||||
if ($resql) {
|
||||
$num = $this->db->num_rows($resql);
|
||||
if ($num > 0) {
|
||||
while ($obj = $this->db->fetch_object($resql)) {
|
||||
$transkey="TypeContact_".$obj->element."_".$obj->source."_".$obj->code;
|
||||
$this->roles[$this->id]=array('id'=>$obj->rowid,'element'=>$obj->element,'source'=>$obj->source,'code'=>$obj->code,'label'=>($langs->trans($transkey)!=$transkey ? $langs->trans($transkey) : $obj->libelle));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$error++;
|
||||
$this->errors[]=$this->db->lasterror();
|
||||
}
|
||||
|
||||
if (empty($error)) {
|
||||
return $num;
|
||||
} else {
|
||||
return $error * -1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1210,6 +1210,75 @@ abstract class CommonObject
|
||||
}
|
||||
}
|
||||
|
||||
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
|
||||
/**
|
||||
* Return array with list of possible values for type of contacts
|
||||
*
|
||||
* @param string $source 'internal', 'external' or 'all'
|
||||
* @param int $option 0=Return array id->label, 1=Return array code->label
|
||||
* @param int $activeonly 0=all status of contact, 1=only the active
|
||||
* @param string $code Type of contact (Example: 'CUSTOMER', 'SERVICE')
|
||||
* @param string $element Filter Element Type
|
||||
* @return array Array list of type of contacts (id->label if option=0, code->label if option=1)
|
||||
*/
|
||||
public function listeTypeContacts($source = 'internal', $option = 0, $activeonly = 0, $code = '', $element = '')
|
||||
{
|
||||
// phpcs:enable
|
||||
global $langs;
|
||||
|
||||
if (empty($order)) $order='position';
|
||||
if ($order == 'position') $order.=',code';
|
||||
|
||||
$tab = array();
|
||||
$sql = "SELECT DISTINCT tc.rowid, tc.code, tc.libelle, tc.position, tc.element";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."c_type_contact as tc";
|
||||
|
||||
$sqlWhere=array();
|
||||
if (!empty($element))
|
||||
$sqlWhere[]=" tc.element='".$this->db->escape($element)."'";
|
||||
|
||||
if ($activeonly == 1)
|
||||
$sqlWhere[]=" tc.active=1"; // only the active types
|
||||
|
||||
if (! empty($source) && $source != 'all')
|
||||
$sqlWhere[]=" tc.source='".$this->db->escape($source)."'";
|
||||
|
||||
if (! empty($code))
|
||||
$sqlWhere[]=" tc.code='".$this->db->escape($code)."'";
|
||||
|
||||
if (count($sqlWhere)>0) {
|
||||
$sql .= " WHERE ". implode(' AND ', $sqlWhere);
|
||||
}
|
||||
|
||||
$sql.= $this->db->order('tc.element, tc.position', 'ASC');
|
||||
|
||||
dol_syslog(get_class($this)."::".__METHOD__, LOG_DEBUG);
|
||||
$resql=$this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$num=$this->db->num_rows($resql);
|
||||
$i=0;
|
||||
while ($i < $num)
|
||||
{
|
||||
$obj = $this->db->fetch_object($resql);
|
||||
|
||||
$libelle_element = $langs->trans('ContactDefault_'.ucfirst($obj->element));
|
||||
$transkey="TypeContact_".$this->element."_".$source."_".$obj->code;
|
||||
$libelle_type=($langs->trans($transkey)!=$transkey ? $langs->trans($transkey) : $obj->libelle);
|
||||
if (empty($option)) $tab[$obj->rowid]=$libelle_element.' - '.$libelle_type;
|
||||
else $tab[$obj->code]=$libelle_element.' - '.$libelle_type;
|
||||
$i++;
|
||||
}
|
||||
return $tab;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->lasterror();
|
||||
//dol_print_error($this->db);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return id of contacts for a source and a contact code.
|
||||
* Example: contact client de facturation ('external', 'BILLING')
|
||||
|
||||
@ -869,6 +869,7 @@ function show_contacts($conf, $langs, $db, $object, $backtopage = '')
|
||||
if ($search_status=='') $search_status=1; // always display active customer first
|
||||
$search_name = GETPOST("search_name", 'alpha');
|
||||
$search_addressphone = GETPOST("search_addressphone", 'alpha');
|
||||
$search_role = GETPOST("search_role", 'array');
|
||||
|
||||
if (! $sortorder) $sortorder="ASC";
|
||||
if (! $sortfield) $sortfield="t.lastname";
|
||||
@ -887,7 +888,8 @@ function show_contacts($conf, $langs, $db, $object, $backtopage = '')
|
||||
'name' =>array('type'=>'varchar(128)', 'label'=>'Name', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'showoncombobox'=>1, 'index'=>1, 'position'=>10, 'searchall'=>1),
|
||||
'poste' =>array('type'=>'varchar(128)', 'label'=>'PostOfFunction', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'showoncombobox'=>1, 'index'=>1, 'position'=>20),
|
||||
'address' =>array('type'=>'varchar(128)', 'label'=>'Address', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'showoncombobox'=>1, 'index'=>1, 'position'=>30),
|
||||
'statut' =>array('type'=>'integer', 'label'=>'Status', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'default'=>0, 'index'=>1, 'position'=>40, 'arrayofkeyval'=>array(0=>$contactstatic->LibStatut(0, 1), 1=>$contactstatic->LibStatut(1, 1))),
|
||||
'role' =>array('type'=>'checkbox', 'label'=>'Role', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'showoncombobox'=>1, 'index'=>1, 'position'=>40),
|
||||
'statut' =>array('type'=>'integer', 'label'=>'Status', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'default'=>0, 'index'=>1, 'position'=>50, 'arrayofkeyval'=>array(0=>$contactstatic->LibStatut(0, 1), 1=>$contactstatic->LibStatut(1, 1))),
|
||||
);
|
||||
|
||||
// Definition of fields for list
|
||||
@ -896,8 +898,8 @@ function show_contacts($conf, $langs, $db, $object, $backtopage = '')
|
||||
't.name'=>array('label'=>"Name", 'checked'=>1, 'position'=>10),
|
||||
't.poste'=>array('label'=>"PostOrFunction", 'checked'=>1, 'position'=>20),
|
||||
't.address'=>array('label'=>(empty($conf->dol_optimize_smallscreen) ? $langs->trans("Address").' / '.$langs->trans("Phone").' / '.$langs->trans("Email") : $langs->trans("Address")), 'checked'=>1, 'position'=>30),
|
||||
't.address'=>array('label'=>(empty($conf->dol_optimize_smallscreen) ? $langs->trans("Address").' / '.$langs->trans("Phone").' / '.$langs->trans("Email") : $langs->trans("Address")), 'checked'=>1, 'position'=>30),
|
||||
't.statut'=>array('label'=>"Status", 'checked'=>1, 'position'=>40, 'class'=>'center'),
|
||||
'sc.role'=>array('label'=>"Role", 'checked'=>1, 'position'=>40),
|
||||
't.statut'=>array('label'=>"Status", 'checked'=>1, 'position'=>50, 'class'=>'center'),
|
||||
);
|
||||
// Extra fields
|
||||
if (is_array($extrafields->attributes[$contactstatic->table_element]['label']) && count($extrafields->attributes[$contactstatic->table_element]['label']))
|
||||
@ -927,6 +929,7 @@ function show_contacts($conf, $langs, $db, $object, $backtopage = '')
|
||||
{
|
||||
$search_status = '';
|
||||
$search_name = '';
|
||||
$search_role = '';
|
||||
$search_addressphone = '';
|
||||
$search_array_options=array();
|
||||
|
||||
@ -968,6 +971,7 @@ function show_contacts($conf, $langs, $db, $object, $backtopage = '')
|
||||
|
||||
$param="socid=".urlencode($object->id);
|
||||
if ($search_status != '') $param.='&search_status='.urlencode($search_status);
|
||||
if (count($search_role)>0) $param.=implode('&search_role[]=', $search_role);
|
||||
if ($search_name != '') $param.='&search_name='.urlencode($search_name);
|
||||
if ($optioncss != '') $param.='&optioncss='.urlencode($optioncss);
|
||||
// Add $param from extra fields
|
||||
@ -978,9 +982,15 @@ function show_contacts($conf, $langs, $db, $object, $backtopage = '')
|
||||
$sql .= " t.civility as civility_id, t.address, t.zip, t.town";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."socpeople as t";
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople_extrafields as ef on (t.rowid = ef.fk_object)";
|
||||
if (count($search_role)>0) {
|
||||
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_contacts as sc on (sc.fk_socpeople = t.rowid)";
|
||||
}
|
||||
$sql .= " WHERE t.fk_soc = ".$object->id;
|
||||
if ($search_status!='' && $search_status != '-1') $sql .= " AND t.statut = ".$db->escape($search_status);
|
||||
if ($search_name) $sql .= natural_search(array('t.lastname', 't.firstname'), $search_name);
|
||||
if (count($search_role)>0) {
|
||||
$sql .= ' AND sc.fk_c_type_contact IN ('.implode(',',$search_role).')';
|
||||
}
|
||||
// Add where from extra fields
|
||||
$extrafieldsobjectkey=$contactstatic->table_element;
|
||||
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
|
||||
@ -993,6 +1003,7 @@ function show_contacts($conf, $langs, $db, $object, $backtopage = '')
|
||||
|
||||
$num = $db->num_rows($result);
|
||||
|
||||
|
||||
// Fields title search
|
||||
// --------------------------------------------------------------------
|
||||
print '<tr class="liste_titre">';
|
||||
@ -1002,11 +1013,16 @@ function show_contacts($conf, $langs, $db, $object, $backtopage = '')
|
||||
if (in_array($val['type'], array('date','datetime','timestamp'))) $align.=($align?' ':'').'center';
|
||||
if (in_array($val['type'], array('timestamp'))) $align.=($align?' ':'').'nowrap';
|
||||
if ($key == 'status' || $key == 'statut') $align.=($align?' ':'').'center';
|
||||
if (! empty($arrayfields['t.'.$key]['checked']))
|
||||
if (! empty($arrayfields['t.'.$key]['checked']) || ! empty($arrayfields['sc.'.$key]['checked']))
|
||||
{
|
||||
|
||||
print '<td class="liste_titre'.($align?' '.$align:'').'">';
|
||||
if (in_array($key, array('lastname','name'))) print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag($search[$key]).'">';
|
||||
elseif (in_array($key, array('statut'))) print $form->selectarray('search_status', array('-1'=>'','0'=>$contactstatic->LibStatut(0, 1),'1'=>$contactstatic->LibStatut(1, 1)), $search_status);
|
||||
elseif (in_array($key, array('role'))) {
|
||||
$contactType=$contactstatic->listeTypeContacts('external', '', 1);
|
||||
print $form->multiselectarray('search_role', $contactType, $search_role);
|
||||
}
|
||||
print '</td>';
|
||||
}
|
||||
}
|
||||
@ -1035,7 +1051,10 @@ function show_contacts($conf, $langs, $db, $object, $backtopage = '')
|
||||
if (in_array($val['type'], array('date','datetime','timestamp'))) $align.=($align?' ':'').'center';
|
||||
if (in_array($val['type'], array('timestamp'))) $align.=($align?' ':'').'nowrap';
|
||||
if ($key == 'status' || $key == 'statut') $align.=($align?' ':'').'center';
|
||||
if (! empty($arrayfields['t.'.$key]['checked'])) print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($align?'class="'.$align.'"':''), $sortfield, $sortorder, $align.' ')."\n";
|
||||
if ($key == 'role') $align.=($align?' ':'').'center';
|
||||
if (! empty($arrayfields['t.'.$key]['checked']) || ! empty($arrayfields['sc.'.$key]['checked'])) {
|
||||
print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($align?'class="'.$align.'"':''), $sortfield, $sortorder, $align.' ')."\n";
|
||||
}
|
||||
}
|
||||
// Extra fields
|
||||
$extrafieldsobjectkey=$contactstatic->table_element;
|
||||
@ -1082,6 +1101,11 @@ function show_contacts($conf, $langs, $db, $object, $backtopage = '')
|
||||
$contactstatic->setGenderFromCivility();
|
||||
$contactstatic->fetch_optionals();
|
||||
|
||||
$resultRole=$contactstatic->fetchRole();
|
||||
if ($resultRole<0) {
|
||||
setEventMessages(null, $contactstatic->errors,'errors');
|
||||
}
|
||||
|
||||
if (is_array($contactstatic->array_options))
|
||||
{
|
||||
foreach($contactstatic->array_options as $key => $val)
|
||||
@ -1125,6 +1149,16 @@ function show_contacts($conf, $langs, $db, $object, $backtopage = '')
|
||||
print '</td>';
|
||||
}
|
||||
|
||||
// Role
|
||||
if (! empty($arrayfields['sc.role']['checked']))
|
||||
{
|
||||
print '<td>';
|
||||
foreach($contactstatic->roles as $key=>$val) {
|
||||
print '<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(' ', $val['label']).'</ul></div>';
|
||||
}
|
||||
print '</td>';
|
||||
}
|
||||
|
||||
// Status
|
||||
if (! empty($arrayfields['t.statut']['checked']))
|
||||
{
|
||||
|
||||
@ -89,18 +89,19 @@ ALTER TABLE llx_projet ADD COLUMN usage_organize_event integer DEFAULT 0;
|
||||
|
||||
UPDATE llx_projet set usage_opportunity = 1 WHERE fk_opp_status > 0;
|
||||
|
||||
create table llx_societe_contact
|
||||
create table llx_societe_contacts
|
||||
(
|
||||
rowid integer AUTO_INCREMENT PRIMARY KEY,
|
||||
datec datetime NULL, -- date de creation de l'enregistrement
|
||||
statut smallint DEFAULT 5, -- 5 inactif, 4 actif
|
||||
|
||||
element_id int NOT NULL, -- la reference de l'element.
|
||||
fk_c_type_contact int NOT NULL, -- nature du contact.
|
||||
fk_socpeople integer NOT NULL
|
||||
entity integer DEFAULT 1 NOT NULL,
|
||||
date_creation datetime NOT NULL,
|
||||
fk_soc integer NOT NULL,
|
||||
fk_c_type_contact int NOT NULL,
|
||||
fk_socpeople integer NOT NULL,
|
||||
tms TIMESTAMP,
|
||||
import_key VARCHAR(14)
|
||||
)ENGINE=innodb;
|
||||
|
||||
ALTER TABLE llx_societe_contact ADD UNIQUE INDEX idx_societe_contact_idx1 (element_id, fk_c_type_contact, fk_socpeople);
|
||||
|
||||
ALTER TABLE llx_societe_contact ADD CONSTRAINT fk_societe_contact_fk_c_type_contact FOREIGN KEY (fk_c_type_contact) REFERENCES llx_c_type_contact(rowid);
|
||||
ALTER TABLE llx_societe_contact ADD CONSTRAINT fk_societe_contact_fk_socpeople FOREIGN KEY (fk_socpeople) REFERENCES llx_socpeople(rowid);
|
||||
ALTER TABLE llx_societe_contacts ADD UNIQUE INDEX idx_societe_contacts_idx1 (entity, fk_soc, fk_c_type_contact, fk_socpeople);
|
||||
ALTER TABLE llx_societe_contacts ADD CONSTRAINT fk_societe_contacts_fk_c_type_contact FOREIGN KEY (fk_c_type_contact) REFERENCES llx_c_type_contact(rowid);
|
||||
ALTER TABLE llx_societe_contacts ADD CONSTRAINT fk_societe_contacts_fk_soc FOREIGN KEY (fk_soc) REFERENCES llx_societe(rowid);
|
||||
ALTER TABLE llx_societe_contacts ADD CONSTRAINT fk_societe_contacts_fk_socpeople FOREIGN KEY (fk_socpeople) REFERENCES llx_socpeople(rowid);
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
--
|
||||
-- ========================================================================
|
||||
|
||||
ALTER TABLE llx_societe_contact ADD UNIQUE INDEX idx_societe_contact_idx1 (element_id, fk_c_type_contact, fk_socpeople);
|
||||
|
||||
ALTER TABLE llx_societe_contact ADD CONSTRAINT fk_societe_contact_fk_c_type_contact FOREIGN KEY (fk_c_type_contact) REFERENCES llx_c_type_contact(rowid);
|
||||
ALTER TABLE llx_societe_contact ADD CONSTRAINT fk_societe_contact_fk_socpeople FOREIGN KEY (fk_socpeople) REFERENCES llx_socpeople(rowid);
|
||||
ALTER TABLE llx_societe_contacts ADD UNIQUE INDEX idx_societe_contacts_idx1 (entity, fk_soc, fk_c_type_contact, fk_socpeople);
|
||||
ALTER TABLE llx_societe_contacts ADD CONSTRAINT fk_societe_contacts_fk_c_type_contact FOREIGN KEY (fk_c_type_contact) REFERENCES llx_c_type_contact(rowid);
|
||||
ALTER TABLE llx_societe_contacts ADD CONSTRAINT fk_societe_contacts_fk_soc FOREIGN KEY (fk_soc) REFERENCES llx_societe(rowid);
|
||||
ALTER TABLE llx_societe_contacts ADD CONSTRAINT fk_societe_contacts_fk_socpeople FOREIGN KEY (fk_socpeople) REFERENCES llx_socpeople(rowid);
|
||||
@ -17,13 +17,14 @@
|
||||
-- ========================================================================
|
||||
|
||||
|
||||
create table llx_societe_contact
|
||||
create table llx_societe_contacts
|
||||
(
|
||||
rowid integer AUTO_INCREMENT PRIMARY KEY,
|
||||
datec datetime NULL, -- date de creation de l'enregistrement
|
||||
statut smallint DEFAULT 5, -- 5 inactif, 4 actif
|
||||
|
||||
element_id int NOT NULL, -- la reference de l'element.
|
||||
fk_c_type_contact int NOT NULL, -- nature du contact.
|
||||
fk_socpeople integer NOT NULL
|
||||
rowid integer AUTO_INCREMENT PRIMARY KEY,
|
||||
entity integer DEFAULT 1 NOT NULL,
|
||||
date_creation datetime NOT NULL,
|
||||
fk_soc integer NOT NULL,
|
||||
fk_c_type_contact int NOT NULL,
|
||||
fk_socpeople integer NOT NULL,
|
||||
tms TIMESTAMP,
|
||||
import_key VARCHAR(14)
|
||||
)ENGINE=innodb;
|
||||
@ -989,4 +989,16 @@ ToApprove=To approve
|
||||
GlobalOpenedElemView=Global view
|
||||
NoArticlesFoundForTheKeyword=No article found for the keyword '<strong>%s</strong>'
|
||||
NoArticlesFoundForTheCategory=No article found for the category
|
||||
ToAcceptRefuse=To accept | refuse
|
||||
ToAcceptRefuse=To accept | refuse
|
||||
ContactDefault_agenda=Event
|
||||
ContactDefault_commande=Order
|
||||
ContactDefault_contrat=Contract
|
||||
ContactDefault_facture=Invoice
|
||||
ContactDefault_fichinter=Intervention
|
||||
ContactDefault_invoice_supplier=Supplier Invoice
|
||||
ContactDefault_order_supplier=Supplier Order
|
||||
ContactDefault_project=Project
|
||||
ContactDefault_project_task=Task
|
||||
ContactDefault_propal=Proposal
|
||||
ContactDefault_supplier_proposal=Supplier Proposal
|
||||
ContactDefault_ticketsup=Ticket
|
||||
|
||||
Loading…
Reference in New Issue
Block a user