New: Gestion générique des contacts sur les contrats.

This commit is contained in:
Laurent Destailleur 2005-09-17 16:58:58 +00:00
parent 3e7a5f2fa5
commit 3f3c66ef72
10 changed files with 342 additions and 255 deletions

View File

@ -1,5 +1,6 @@
<?php <?php
/* Copyright (C) 2005 Patrick Rouillon <patrick@rouillon.net> /* Copyright (C) 2005 Patrick Rouillon <patrick@rouillon.net>
* Copyright (C) 2005 Destailleur Laurent <eldy@users.sourceforge.net>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -52,8 +53,7 @@ function select_societes_for_newconcat($contrat, $selected = '', $htmlname = 'ne
// On recherche les societes // On recherche les societes
$sql = "SELECT s.idp, s.nom FROM"; $sql = "SELECT s.idp, s.nom FROM";
$sql .= " ".MAIN_DB_PREFIX."societe as s"; $sql .= " ".MAIN_DB_PREFIX."societe as s";
if ($filter) if ($filter) $sql .= " WHERE $filter";
$sql .= " WHERE $filter";
$sql .= " ORDER BY nom ASC"; $sql .= " ORDER BY nom ASC";
$resql = $contrat->db->query($sql); $resql = $contrat->db->query($sql);
@ -72,11 +72,11 @@ function select_societes_for_newconcat($contrat, $selected = '', $htmlname = 'ne
$firstCompany = $obj->idp; $firstCompany = $obj->idp;
if ($selected > 0 && $selected == $obj->idp) if ($selected > 0 && $selected == $obj->idp)
{ {
print '<option value="'.$obj->idp.'" selected="true">'.$obj->nom.'</option>'; print '<option value="'.$obj->idp.'" selected="true">'.dolibarr_trunc($obj->nom,24).'</option>';
$firstCompany = $obj->idp; $firstCompany = $obj->idp;
} else } else
{ {
print '<option value="'.$obj->idp.'">'.$obj->nom.'</option>'; print '<option value="'.$obj->idp.'">'.dolibarr_trunc($obj->nom,24).'</option>';
} }
$i ++; $i ++;
} }
@ -92,17 +92,18 @@ function select_societes_for_newconcat($contrat, $selected = '', $htmlname = 'ne
/** /**
* *
*/ */
function select_nature_contact($contrat, $defValue, $htmlname = 'nature') function select_type_contact($contrat, $defValue, $htmlname = 'type', $source)
{ {
$lesNatures = $contrat->liste_nature_contact(); $lesTypes = $contrat->liste_type_contact($source);
print '<select size="0" name="nature">'; print '<select size="0" name="'.$htmlname.'">';
foreach($lesNatures as $key=>$value) foreach($lesTypes as $key=>$value)
{ {
print '<option value="'.$key.'">'.$value.'</option>'; print '<option value="'.$key.'">'.$value.'</option>';
} }
print "</select>\n"; print "</select>\n";
} }
// Sécurité accés client // Sécurité accés client
if ($user->societe_id > 0) if ($user->societe_id > 0)
{ {
@ -119,10 +120,11 @@ if ($_POST["action"] == 'addcontact' && $user->rights->contrat->creer)
$result = 0; $result = 0;
$contrat = new Contrat($db); $contrat = new Contrat($db);
$result = $contrat->fetch($_GET["id"]); $result = $contrat->fetch($_GET["id"]);
if ($_POST["id"] > 0)
{ if ($result > 0 && $_POST["id"] > 0)
$result = $contrat->add_contact($_POST["contactid"], $_POST["nature"]); {
} $result = $contrat->add_contact($_POST["contactid"], $_POST["type"], $_POST["source"]);
}
if ($result >= 0) if ($result >= 0)
{ {
@ -133,17 +135,17 @@ if ($_POST["action"] == 'addcontact' && $user->rights->contrat->creer)
$mesg = '<div class="error">'.$contrat->error.'</div>'; $mesg = '<div class="error">'.$contrat->error.'</div>';
} }
} }
// modification d'un contact. On enregistre la nature // modification d'un contact. On enregistre le type
if ($_POST["action"] == 'updateligne' && $user->rights->contrat->creer) if ($_POST["action"] == 'updateligne' && $user->rights->contrat->creer)
{ {
$contrat = new Contrat($db); $contrat = new Contrat($db);
if ($contrat->fetch($_GET["id"])) if ($contrat->fetch($_GET["id"]))
{ {
$contact = $contrat->detail_contact($_POST["elrowid"]); $contact = $contrat->detail_contact($_POST["elrowid"]);
$nature = $_POST["nature"]; $type = $_POST["type"];
$statut = $contact->statut; $statut = $contact->statut;
$result = $contrat->update_contact($_POST["elrowid"], $statut, $nature); $result = $contrat->update_contact($_POST["elrowid"], $statut, $type);
if ($result >= 0) if ($result >= 0)
{ {
$db->commit(); $db->commit();
@ -157,6 +159,7 @@ if ($_POST["action"] == 'updateligne' && $user->rights->contrat->creer)
dolibarr_print_error($db); dolibarr_print_error($db);
} }
} }
// bascule du statut d'un contact // bascule du statut d'un contact
if ($_GET["action"] == 'swapstatut' && $user->rights->contrat->creer) if ($_GET["action"] == 'swapstatut' && $user->rights->contrat->creer)
{ {
@ -182,6 +185,7 @@ if ($_GET["action"] == 'swapstatut' && $user->rights->contrat->creer)
} }
} }
// Efface un contact
if ($_GET["action"] == 'deleteline' && $user->rights->contrat->creer) if ($_GET["action"] == 'deleteline' && $user->rights->contrat->creer)
{ {
$contrat = new Contrat($db); $contrat = new Contrat($db);
@ -264,6 +268,7 @@ if ($id > 0)
if ($_GET["action"] != 'editline' && $user->rights->contrat->creer) if ($_GET["action"] != 'editline' && $user->rights->contrat->creer)
{ {
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Source").'</td>';
print '<td>'.$langs->trans("Societe").'</td>'; print '<td>'.$langs->trans("Societe").'</td>';
print '<td>'.$langs->trans("Contacts").'</td>'; print '<td>'.$langs->trans("Contacts").'</td>';
print '<td align="center">'.$langs->trans("ContactType").'</td>'; print '<td align="center">'.$langs->trans("ContactType").'</td>';
@ -274,9 +279,44 @@ if ($id > 0)
print '<form action="contact.php?id='.$id.'" method="post">'; print '<form action="contact.php?id='.$id.'" method="post">';
print '<input type="hidden" name="action" value="addcontact">'; print '<input type="hidden" name="action" value="addcontact">';
print '<input type="hidden" name="source" value="internal">';
print '<input type="hidden" name="id" value="'.$id.'">'; print '<input type="hidden" name="id" value="'.$id.'">';
// Ligne ajout pour contact interne
print "<tr $bc[$var]>"; print "<tr $bc[$var]>";
print '<td>';
print $langs->trans("Internal");
print '</td>';
print '<td colspan="1">';
print $conf->global->MAIN_INFO_SOCIETE_NOM;
print '</td>';
print '<td colspan="1">';
$html->select_users($user->id,'contactid');
print '</td>';
print '<td align="center">';
select_type_contact($contrat, '', 'type','internal');
print '</td>';
print '<td align="right" colspan="3" ><input type="submit" class="button" value="'.$langs->trans("Add").'"></td>';
print '</tr>';
print '</form>';
print '<form action="contact.php?id='.$id.'" method="post">';
print '<input type="hidden" name="action" value="addcontact">';
print '<input type="hidden" name="source" value="external">';
print '<input type="hidden" name="id" value="'.$id.'">';
// Ligne ajout pour contact externe
$var=!$var;
print "<tr $bc[$var]>";
print '<td>';
print $langs->trans("External");
print '</td>';
print '<td colspan="1">'; print '<td colspan="1">';
$selectedCompany = isset($_GET["newcompany"])?$_GET["newcompany"]:$contrat->societe->id; $selectedCompany = isset($_GET["newcompany"])?$_GET["newcompany"]:$contrat->societe->id;
$selectedCompany = select_societes_for_newconcat($contrat, $selectedCompany, $htmlname = 'newcompany'); $selectedCompany = select_societes_for_newconcat($contrat, $selectedCompany, $htmlname = 'newcompany');
@ -286,7 +326,7 @@ if ($id > 0)
$html->select_contacts($selectedCompany, $selected = '', $htmlname = 'contactid'); $html->select_contacts($selectedCompany, $selected = '', $htmlname = 'contactid');
print '</td>'; print '</td>';
print '<td align="center">'; print '<td align="center">';
select_nature_contact($contrat, '', 'nature'); select_type_contact($contrat, '', 'type','external');
print '</td>'; print '</td>';
print '<td align="right" colspan="3" ><input type="submit" class="button" value="'.$langs->trans("Add").'"></td>'; print '<td align="right" colspan="3" ><input type="submit" class="button" value="'.$langs->trans("Add").'"></td>';
print '</tr>'; print '</tr>';
@ -297,144 +337,104 @@ if ($id > 0)
print '<tr><td colspan="6">&nbsp;</td></tr>'; print '<tr><td colspan="6">&nbsp;</td></tr>';
// Liste des contacts liés
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Societe").'</td>'; print '<td>'.$langs->trans("Source").'</td>';
print '<td>'.$langs->trans("Company").'</td>';
print '<td>'.$langs->trans("Contacts").'</td>'; print '<td>'.$langs->trans("Contacts").'</td>';
print '<td align="center">'.$langs->trans("ContactType").'</td>'; print '<td align="center">'.$langs->trans("ContactType").'</td>';
print '<td align="center">'.$langs->trans("Status").'</td>'; print '<td align="center">'.$langs->trans("Status").'</td>';
print '<td colspan="2">&nbsp;</td>'; print '<td colspan="2">&nbsp;</td>';
print "</tr>\n"; print "</tr>\n";
$tab = $contrat->liste_contact(); $societe = new Societe($db);
$var = true;
$num = ($tab == null) ? 0 : count($tab); foreach(array('internal','external') as $source)
if ($tab != null && $num > 0)
{ {
$tab = $contrat->liste_contact(-1,$source);
$num=sizeof($tab);
$i = 0; $i = 0;
$total = 0;
$var = true;
$person = new Contact($db);
$societe = new Societe($db);
while ($i < $num) while ($i < $num)
{ {
$objp = $contrat->detail_contact($tab[$i]); $var = !$var;
// detail du contact print '<tr '.$bc[$var].' valign="top">';
$person->fetch($objp->fk_socpeople);
$var = !$var; // flip flop lines
if ($_GET["action"] != 'editline' || $_GET["rowid"] != $tab[$i]) // Source
print '<td align="left">';
if ($tab[$i]['source']=='internal') print $langs->trans("Internal");
if ($tab[$i]['source']=='external') print $langs->trans("External");
print '</td>';
// Societe
print '<td align="left">';
if ($tab[$i]['socid'] > 0)
{ {
print '<tr '.$bc[$var].' valign="top">'; print '<a href="'.DOL_URL_ROOT.'/soc.php?idp='.$tab[$i]['socid'].'">';
print img_object($langs->trans("ShowCompany"),"company").' '.$societe->get_nom($tab[$i]['socid']);
print '<td align="left">'; print '</a>';
if ($objp->fk_soc) }
{ if ($tab[$i]['socid'] < 0)
print '<a href="'.DOL_URL_ROOT.'/soc.php?idp='.$objp->fk_soc.'">';
print img_object($langs->trans("ShowCompany"),"company").' '.$societe->get_nom($person->socid);
print '</a>';
}
else
{
print '&nbsp;';
}
print '</td>';
print '<td>';
print '<a href="'.DOL_URL_ROOT.'/contact/fiche.php?id='.$objp->fk_socpeople.'">';
print img_object($langs->trans("ShowContact"),"contact").' '.$person->fullname.'</a>';
print '</td>';
// Description
print '<td align="center">'.$objp->libelle.'</td>';
// Statut
print '<td align="center">';
// Activation desativation du contact
if ($contrat->statut >= 0)
print '<a href="'.DOL_URL_ROOT.'/contrat/contact.php?id='.$contrat->id.'&amp;action=swapstatut&amp;ligne='.$tab[$i].'">';
print img_statut($objp->statut);
if ($contrat->statut > 0)
print '</a>';
print '</td>';
// Icon update et delete (statut contrat 0=brouillon,1=validé,2=fermé)
print '<td align="center" nowrap>';
if ($contrat->statut != 2 && $user->rights->contrat->creer)
{
print '<a href="contact.php?id='.$id.'&amp;action=editline&amp;rowid='.$tab[$i].'">';
print img_edit();
print '</a>';
} else
{
print '&nbsp;';
}
if ($contrat->statut == 0 && $user->rights->contrat->creer)
{
print '&nbsp;';
print '<a href="contact.php?id='.$id.'&amp;action=deleteline&amp;lineid='.$tab[$i].'">';
print img_delete();
print '</a>';
}
print '</td>';
print "</tr>\n";
}
// mode edition de une ligne ligne (editline)
// on ne change pas le contact. Seulement le type
else
{ {
print $conf->global->MAIN_INFO_SOCIETE_NOM;
}
if (! $tab[$i]['socid'])
{
print '&nbsp;';
}
print '</td>';
print "<form name='detailcontact' action=\"contact.php?id=$id\" method=\"post\">"; // Contact
print '<input type="hidden" name="action" value="updateligne">'; print '<td>';
print '<input type="hidden" name="elrowid" value="'.$_GET["rowid"].'">'; if ($tab[$i]['source']=='internal')
// Ligne carac {
print "<tr $bc[$var]>"; print '<a href="'.DOL_URL_ROOT.'/user/fiche.php?id='.$tab[$i]['id'].'">';
print img_object($langs->trans("ShowUser"),"user").' '.$tab[$i]['nom'].'</a>';
}
if ($tab[$i]['source']=='external')
{
print '<a href="'.DOL_URL_ROOT.'/contact/fiche.php?id='.$tab[$i]['id'].'">';
print img_object($langs->trans("ShowContact"),"contact").' '.$tab[$i]['nom'].'</a>';
}
print '</td>';
print '<td>'; // Description
if ($objp->fk_soc) print '<td align="center">'.$tab[$i]['libelle'].'</td>';
{
print '<a href="'.DOL_URL_ROOT.'/soc.php?idp='.$objp->fk_soc.'">';
print img_object($langs->trans("ShowCompany"),"company").' '.$societe->get_nom($person->socid);
print '</a>';
}
else
{
print '&nbsp;';
}
print '</td>';
print '<td>'; // Statut
print '<a href="'.DOL_URL_ROOT.'/contact/fiche.php?id='.$objp->fk_socpeople.'">'; print '<td align="center">';
print img_object($langs->trans("ShowContact"),"contact").' '.$person->fullname.'</a>'; // Activation desativation du contact
print '</td>'; if ($contrat->statut >= 0)
print '<a href="'.DOL_URL_ROOT.'/contrat/contact.php?id='.$contrat->id.'&amp;action=swapstatut&amp;ligne='.$tab[$i]['rowid'].'">';
print img_statut($tab[$i]['status']);
if ($contrat->statut >= 0)
print '</a>';
print '</td>';
// Description // Icon update et delete (statut contrat 0=brouillon,1=validé,2=fermé)
print '<td align="center">'; print '<td align="center" nowrap>';
select_nature_contact($contrat, $objp->nature, 'nature'); if ($contrat->statut == 0 && $user->rights->contrat->creer)
print "</td>"; {
print '&nbsp;';
// Statut print '<a href="contact.php?id='.$contrat->id.'&amp;action=deleteline&amp;lineid='.$tab[$i]['rowid'].'">';
print '<td align="center">'.img_statut($objp->statut).'</td>'; print img_delete();
print '</a>';
// Icon update et delete (statut contrat 0=brouillon,1=validé,2=fermé)
print '<td align="center" colspan="1"><input type="submit" class="button" value="'.$langs->trans("Save").'"></td>';
print '</tr>'."\n";
print "</form>\n";
} }
print '</td>';
print "</tr>\n";
$i ++; $i ++;
} }
$db->free($result); $db->free($result);
} }
print "</table>"; print "</table>";
} else }
else
{ {
// Contrat non trouvé // Contrat non trouvé
print "Contrat inexistant ou accés refusé"; print "Contrat inexistant ou accés refusé";

View File

@ -420,25 +420,47 @@ class Contrat
$this->db->begin(); $this->db->begin();
// Insère contrat // Insère contrat
$sql = "INSERT INTO ".MAIN_DB_PREFIX."contrat (datec, fk_soc, fk_user_author, fk_commercial_signature, fk_commercial_suivi, date_contrat)"; $sql = "INSERT INTO ".MAIN_DB_PREFIX."contrat (datec, fk_soc, fk_user_author, date_contrat";
// $sql.= ", fk_commercial_signature, fk_commercial_suivi";
$sql.= ")";
$sql.= " VALUES (now(),".$this->soc_id.",".$user->id; $sql.= " VALUES (now(),".$this->soc_id.",".$user->id;
$sql.= ",".($this->commercial_signature_id>=0?$this->commercial_signature_id:"null"); $sql.= ",".$this->db->idate($this->date_contrat);
$sql.= ",".($this->commercial_suivi_id>=0?$this->commercial_suivi_id:"null"); // $sql.= ",".($this->commercial_signature_id>=0?$this->commercial_signature_id:"null");
$sql.= ",".$this->db->idate($this->date_contrat) .")"; // $sql.= ",".($this->commercial_suivi_id>=0?$this->commercial_suivi_id:"null");
$sql.= ")";
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)
{ {
$error=0;
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."contrat"); $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."contrat");
// Appel des triggers // Insère contacts commerciaux ('SALESREPSIGN','contrat')
include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php"); $result=$this->add_contact($this->commercial_signature_id,'SALESREPSIGN','internal');
$interface=new Interfaces($this->db); if ($result < 0) $error++;
$interface->run_triggers('CONTRACT_CREATE',$this,$user,$lang,$conf);
// Fin appel triggers
$this->db->commit(); // Insère contacts commerciaux ('SALESREPFOLL','contrat')
$result=$this->add_contact($this->commercial_suivi_id,'SALESREPFOLL','internal');
if ($result < 0) $error++;
return $this->id; if (! $error)
{
// Appel des triggers
include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php");
$interface=new Interfaces($this->db);
$interface->run_triggers('CONTRACT_CREATE',$this,$user,$lang,$conf);
// Fin appel triggers
$this->db->commit();
return $this->id;
}
else
{
$this->db->rollback();
return -1;
}
} }
else else
{ {
@ -905,31 +927,30 @@ class Contrat
/* gestion des contacts d'un contrat */ /* gestion des contacts d'un contrat */
/** /**
*
* \brief Ajoute un contact associé au contrat * \brief Ajoute un contact associé au contrat
* \param fk_socpeople Id du contact a ajouter. * \param fk_socpeople Id du contact a ajouter.
* \param nature description du contact * \param type_contact Type de contact
* \return int <0 si erreur, >0 si ok * \param source extern=Contact externe (llx_socpeople), intern=Contact interne (llx_user)
* \return int <0 si erreur, >0 si ok
*/ */
function add_contact($fk_socpeople, $nature) function add_contact($fk_socpeople, $type_contact, $source='extern')
{ {
dolibarr_syslog("Contrat::add_contact $fk_socpeople, $type_contact, $source");
if ($fk_socpeople <= 0 if ($fk_socpeople <= 0) return -1;
|| $this->societe->contact_get_email($fk_socpeople) == "" )
{
// le contact n'existe pas ou est invalide
return -1;
}
$lNature = addslashes(trim($nature)); // \todo si type_contact = texte, aller chercher code dans table llx_c_type_contact
$datecreate = mktime(); if ($type_contact == 'SALESREPSIGN') $type_contact=11;
if ($type_contact == 'SALESREPFOLL') $type_contact=12;
$datecreate = time();
// Insertion dans la base // Insertion dans la base
$sql = "INSERT INTO ".MAIN_DB_PREFIX."element_contact"; $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_contact";
$sql.= " (element_id, fk_socpeople, datecreate, statut, fk_c_type_contact) "; $sql.= " (element_id, fk_socpeople, datecreate, statut, fk_c_type_contact) ";
$sql.= " VALUES (".$this->id.", ".$fk_socpeople." , " ; $sql.= " VALUES (".$this->id.", ".$fk_socpeople." , " ;
$sql.= $this->db->idate(time()); $sql.= $this->db->idate($datecreate);
$sql.= ", 4, '". $lNature . "' "; $sql.= ", 4, '". $type_contact . "' ";
$sql.= ");"; $sql.= ");";
// Retour // Retour
@ -943,9 +964,9 @@ class Contrat
$this->error=$this->db->error()." - $sql"; $this->error=$this->db->error()." - $sql";
return -1; return -1;
} }
} }
/** /**
* *
* \brief Misea jour du contact associé au contrat * \brief Misea jour du contact associé au contrat
* \param rowid La reference du lien contant contact. * \param rowid La reference du lien contant contact.
@ -953,8 +974,8 @@ class Contrat
* \param nature Description du contact * \param nature Description du contact
* \return int <0 si erreur, >0 si ok * \return int <0 si erreur, >0 si ok
*/ */
function update_contact($rowid, $statut, $type_contact_id) function update_contact($rowid, $statut, $type_contact_id)
{ {
// Insertion dans la base // Insertion dans la base
$sql = "UPDATE ".MAIN_DB_PREFIX."element_contact set "; $sql = "UPDATE ".MAIN_DB_PREFIX."element_contact set ";
$sql.= " statut = $statut ,"; $sql.= " statut = $statut ,";
@ -993,23 +1014,36 @@ class Contrat
/** /**
* \brief Récupère les lignes de contact du contrat * \brief Récupère les lignes de contact du contrat
* \param statut Statut des lignes detail à récupérer * \param statut Statut des lignes detail à récupérer
* \return array Tableau des rowid des contacts * \param source Source du contact external (llx_socpeople) ou internal (llx_user)
* \return array Tableau des rowid des contacts
*/ */
function liste_contact($statut=-1) function liste_contact($statut=-1,$source='external')
{ {
global $langs;
$tab=array(); $tab=array();
$sql = "SELECT ec.rowid, tc.code"; $sql = "SELECT ec.rowid, ec.statut, ec.fk_socpeople as id,";
$sql.= " FROM ".MAIN_DB_PREFIX."element_contact ec, ".MAIN_DB_PREFIX."socpeople sp,"; if ($source == 'internal') $sql.=" '-1' as socid,";
if ($source == 'external') $sql.=" t.fk_soc as socid,";
if ($source == 'internal') $sql.=" t.name as nom,";
if ($source == 'external') $sql.=" t.name as nom,";
$sql.= "tc.code, tc.source, tc.libelle";
$sql.= " FROM ".MAIN_DB_PREFIX."element_contact ec,";
if ($source == 'internal') $sql.=" ".MAIN_DB_PREFIX."user t,";
if ($source == 'external') $sql.=" ".MAIN_DB_PREFIX."socpeople t,";
$sql.= " ".MAIN_DB_PREFIX."c_type_contact tc"; $sql.= " ".MAIN_DB_PREFIX."c_type_contact tc";
$sql.= " WHERE element_id =".$this->id; $sql.= " WHERE element_id =".$this->id;
$sql.= " AND ec.fk_c_type_contact=tc.rowid"; $sql.= " AND ec.fk_c_type_contact=tc.rowid";
$sql.= " AND tc.element='contrat'"; $sql.= " AND tc.element='contrat'";
if ($source == 'internal') $sql.= " AND tc.source = 'internal'";
if ($source == 'external') $sql.= " AND tc.source = 'external'";
$sql.= " AND tc.active=1"; $sql.= " AND tc.active=1";
$sql.= " AND ec.fk_socpeople = sp.idp"; if ($source == 'internal') $sql.= " AND ec.fk_socpeople = t.rowid";
if ($source == 'external') $sql.= " AND ec.fk_socpeople = t.idp";
if ($statut >= 0) $sql.= " AND statut = '$statut'"; if ($statut >= 0) $sql.= " AND statut = '$statut'";
$sql.=" order by sp.name asc ;"; $sql.=" ORDER BY t.name ASC";
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)
@ -1019,7 +1053,10 @@ class Contrat
while ($i < $num) while ($i < $num)
{ {
$obj = $this->db->fetch_object($resql); $obj = $this->db->fetch_object($resql);
$tab[$i]=$obj->rowid;
$libelle_type=($langs->trans("TypeContact".$obj->code)!=$langs->trans("TypeContact".$obj->code) ? $langs->trans("TypeContact".$obj->code) : $obj->libelle);
$tab[$i]=array('source'=>$obj->source,'socid'=>$obj->socid,'id'=>$obj->id,'nom'=>$obj->nom,
'rowid'=>$obj->rowid,'code'=>$obj->code,'libelle'=>$libelle_type,'status'=>$obj->statut);
$i++; $i++;
} }
return $tab; return $tab;
@ -1027,7 +1064,7 @@ class Contrat
else else
{ {
$this->error=$this->db->error(); $this->error=$this->db->error();
// dolibarr_print_error($this->db); dolibarr_print_error($this->db);
return -1; return -1;
} }
} }
@ -1063,16 +1100,18 @@ class Contrat
} }
/** /**
* \brief La liste des valeurs possibles de type de contats * \brief La liste des valeurs possibles de type de contacts
* \return array La liste des natures * \param source internal ou externam
* \return array La liste des natures
*/ */
function liste_nature_contact() function liste_type_contact($source)
{ {
$tab = array(); $tab = array();
$sql = "SELECT distinct tc.rowid, tc.code, tc.libelle"; $sql = "SELECT distinct tc.rowid, tc.code, tc.libelle";
$sql.= " FROM ".MAIN_DB_PREFIX."c_type_contact as tc"; $sql.= " FROM ".MAIN_DB_PREFIX."c_type_contact as tc";
$sql.= " WHERE element='contrat'"; $sql.= " WHERE element='contrat'";
$sql.= " AND source='".$source."'";
$sql.= " ORDER by tc.code"; $sql.= " ORDER by tc.code";
$resql=$this->db->query($sql); $resql=$this->db->query($sql);

View File

@ -353,52 +353,95 @@ class Form
} }
/** /**
* \brief Retourne la liste déroulante des contacts d'une société donnée * \brief Retourne la liste déroulante des contacts d'une société donnée
* \param socid Id de la société * \param socid Id de la société
* \param selected Id contact pré-sélectionné * \param selected Id contact pré-sélectionn
* \param htmlname Nom champ formulaire * \param htmlname Nom champ formulaire
*/ */
function select_contacts($socid,$selected='',$htmlname='contactid') function select_contacts($socid,$selected='',$htmlname='contactid')
{ {
// On recherche les societes // On recherche les societes
$sql = "SELECT s.idp, s.name, s.firstname FROM "; $sql = "SELECT s.idp, s.name, s.firstname FROM ";
$sql .= MAIN_DB_PREFIX ."socpeople as s"; $sql .= MAIN_DB_PREFIX ."socpeople as s";
$sql .= " WHERE fk_soc=".$socid; $sql .= " WHERE fk_soc=".$socid;
$sql .= " ORDER BY s.name ASC"; $sql .= " ORDER BY s.name ASC";
if ($this->db->query($sql)) if ($this->db->query($sql))
{ {
print '<select class="flat" name="'.$htmlname.'">'; print '<select class="flat" name="'.$htmlname.'">';
$num = $this->db->num_rows(); $num = $this->db->num_rows();
$i = 0; $i = 0;
if ($num) if ($num)
{ {
while ($i < $num) while ($i < $num)
{ {
$obj = $this->db->fetch_object(); $obj = $this->db->fetch_object();
if ($selected && $selected == $obj->idp) if ($selected && $selected == $obj->idp)
{ {
print '<option value="'.$obj->idp.'" selected="true">'.$obj->name.' '.$obj->firstname.'</option>'; print '<option value="'.$obj->idp.'" selected="true">'.$obj->name.' '.$obj->firstname.'</option>';
} }
else else
{ {
print '<option value="'.$obj->idp.'">'.$obj->name.' '.$obj->firstname.'</option>'; print '<option value="'.$obj->idp.'">'.$obj->name.' '.$obj->firstname.'</option>';
} }
$i++; $i++;
} }
} }
print '</select>'; print '</select>';
} }
else else
{ {
dolibarr_print_error($this->db); dolibarr_print_error($this->db);
} }
} }
/** /**
* \brief Retourne la liste déroulante des utilisateurs
* \param selected Id contact pré-sélectionn
* \param htmlname Nom champ formulaire
*/
function select_users($selected='',$htmlname='userid')
{
// On recherche les societes
$sql = "SELECT u.rowid, u.name, u.firstname FROM ";
$sql .= MAIN_DB_PREFIX ."user as u";
$sql .= " ORDER BY u.name ASC";
if ($this->db->query($sql))
{
print '<select class="flat" name="'.$htmlname.'">';
$num = $this->db->num_rows();
$i = 0;
if ($num)
{
while ($i < $num)
{
$obj = $this->db->fetch_object();
if ($selected && $selected == $obj->rowid)
{
print '<option value="'.$obj->rowid.'" selected="true">'.$obj->name.' '.$obj->firstname.'</option>';
}
else
{
print '<option value="'.$obj->rowid.'">'.$obj->name.' '.$obj->firstname.'</option>';
}
$i++;
}
}
print '</select>';
}
else
{
dolibarr_print_error($this->db);
}
}
/**
* \brief Affiche la liste déroulante des projets d'une société donnée * \brief Affiche la liste déroulante des projets d'une société donnée
* \param socid Id société * \param socid Id société
* \param selected Id projet présélectionné * \param selected Id projet présélectionné

View File

@ -280,6 +280,10 @@ DateFromTo=From %s to %s
DateFrom=From %s DateFrom=From %s
DateUntil=Until %s DateUntil=Until %s
Check=Check Check=Check
Internal=Internal
External=External
Internals=Internal
Externals=External
# Countries # Countries
CountryFR=France CountryFR=France
CountryBE=Belgium CountryBE=Belgium

View File

@ -280,6 +280,10 @@ DateFromTo=Du %s au %s
DateFrom=A partir du %s DateFrom=A partir du %s
DateUntil=Jusqu'au %s DateUntil=Jusqu'au %s
Check=Vérifier Check=Vérifier
Internal=Interne
External=Externe
Internals=Internes
Externals=Externes
# Countries # Countries
CountryFR=France CountryFR=France
CountryBE=Belgique CountryBE=Belgique

View File

@ -1789,52 +1789,57 @@ create table llx_societe_perms
)type=innodb; )type=innodb;
drop table if exists llx_element_contact;
drop table if exists llx_c_type_contact;
create table llx_c_type_contact create table llx_c_type_contact
( (
rowid integer PRIMARY KEY, rowid integer PRIMARY KEY,
code varchar(16) NOT NULL,
element varchar(30) NOT NULL, element varchar(30) NOT NULL,
source varchar(8) DEFAULT 'external' NOT NULL,
code varchar(16) NOT NULL,
libelle varchar(64) NOT NULL, libelle varchar(64) NOT NULL,
active tinyint DEFAULT 1 NOT NULL active tinyint DEFAULT 1 NOT NULL
)type=innodb; )type=innodb;
ALTER TABLE llx_c_type_contact ALTER TABLE llx_c_type_contact
ADD UNIQUE INDEX idx_c_type_contact_uk (element, code); ADD UNIQUE INDEX idx_c_type_contact_uk (element, source, code);
create table llx_element_contact create table llx_element_contact
( (
rowid integer AUTO_INCREMENT PRIMARY KEY, rowid integer AUTO_INCREMENT PRIMARY KEY,
datecreate datetime NULL, datecreate datetime NULL, -- date de creation de l'enregistrement
statut smallint DEFAULT 5, statut smallint DEFAULT 5, -- 5 inactif, 4 actif
fk_c_type_contact int NOT NULL, element_id int NOT NULL, -- la reference de l'element.
element_id int NOT NULL, fk_c_type_contact int NOT NULL, -- nature du contact.
fk_socpeople integer NOT NULL
fk_socpeople integer NOT NULL
)type=innodb; )type=innodb;
ALTER TABLE llx_element_contact ALTER TABLE llx_element_contact
ADD INDEX idx_element_contact_idx1 (element_id, fk_socpeople); ADD UNIQUE INDEX idx_element_contact_idx1 (element_id, fk_c_type_contact, fk_socpeople);
ALTER TABLE llx_element_contact ALTER TABLE llx_element_contact
ADD CONSTRAINT idx_element_contact_fk_c_type_contact ADD CONSTRAINT idx_element_contact_fk_c_type_contact
FOREIGN KEY (fk_c_type_contact) REFERENCES llx_c_type_contact(rowid); FOREIGN KEY (fk_c_type_contact) REFERENCES llx_c_type_contact(rowid);
insert into llx_c_type_contact(rowid, code, element, libelle, active ) values (10, 'BILLING', 'contrat', 'Contact facturation du contrat', 1); insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (10, 'contrat', 'external', 'BILLING', 'Contact facturation du contrat', 1);
insert into llx_c_type_contact(rowid, code, element, libelle, active ) values (11, 'SALESREPSIGN', 'contrat', 'Commercial signataire du contrat', 1); insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (11, 'contrat', 'internal', 'SALESREPSIGN', 'Commercial signataire du contrat', 1);
insert into llx_c_type_contact(rowid, code, element, libelle, active ) values (12, 'SALESREPFOLL', 'contrat', 'Commercial suivi du contrat', 1); insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (12, 'contrat', 'internal', 'SALESREPFOLL', 'Commercial suivi du contrat', 1);
insert into llx_c_type_contact(rowid, code, element, libelle, active ) values (13, 'CUSTOMER', 'contrat', 'Contact client pour le contrat', 1); insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (13, 'contrat', 'external', 'CUSTOMER', 'Contact client pour le contrat', 1);
insert into llx_c_type_contact(rowid, code, element, libelle, active ) values (20, 'BILLING', 'propal', 'Contact facturation de la propale', 1); insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (20, 'propal', 'external', 'BILLING', 'Contact facturation de la propale', 1);
insert into llx_c_type_contact(rowid, code, element, libelle, active ) values (21, 'SALESREPSIGN', 'propal', 'Commercial signataire de la propale', 1); insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (21, 'propal', 'internal', 'SALESREPSIGN', 'Commercial signataire de la propale', 1);
insert into llx_c_type_contact(rowid, code, element, libelle, active ) values (22, 'SALESREPFOLL', 'propal', 'Commercial suivi de la propale', 1); insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (22, 'propal', 'internal', 'SALESREPFOLL', 'Commercial suivi de la propale', 1);
insert into llx_c_type_contact(rowid, code, element, libelle, active ) values (23, 'CUSTOMER', 'propal', 'Contact client pour la propale', 1); insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (23, 'propal', 'external', 'CUSTOMER', 'Contact client pour la propale', 1);
insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (80, 'projet', 'internal', 'PROJECTLEADER', 'Chef de Projet', 1);
insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (81, 'projet', 'external', 'PROJECTLEADER', 'Chef de Projet', 1);
insert into llx_c_type_contact(rowid, code, element, libelle, active ) values (80, 'PROJECTLEADER', 'projet', 'Chef de Projet', 1);
alter table llx_commande add ref_client varchar(30); alter table llx_commande add ref_client varchar(30);
alter table llx_facture add ref_client varchar(30); alter table llx_facture add ref_client varchar(30);

View File

@ -31,5 +31,5 @@
ALTER TABLE llx_c_type_contact ALTER TABLE llx_c_type_contact
ADD UNIQUE INDEX idx_c_type_contact_uk (element, code); ADD UNIQUE INDEX idx_c_type_contact_uk (element, source, code);

View File

@ -33,8 +33,9 @@
create table llx_c_type_contact create table llx_c_type_contact
( (
rowid integer PRIMARY KEY, rowid integer PRIMARY KEY,
code varchar(16) NOT NULL,
element varchar(30) NOT NULL, element varchar(30) NOT NULL,
source varchar(8) DEFAULT 'external' NOT NULL,
code varchar(16) NOT NULL,
libelle varchar(64) NOT NULL, libelle varchar(64) NOT NULL,
active tinyint DEFAULT 1 NOT NULL active tinyint DEFAULT 1 NOT NULL
)type=innodb; )type=innodb;

View File

@ -22,15 +22,8 @@
ALTER TABLE llx_element_contact ALTER TABLE llx_element_contact
ADD INDEX idx_element_contact_idx1 (element_id, fk_socpeople); ADD UNIQUE INDEX idx_element_contact_idx1 (element_id, fk_c_type_contact, fk_socpeople);
ALTER TABLE llx_element_contact ALTER TABLE llx_element_contact
ADD CONSTRAINT idx_element_contact_fk_c_type_contact ADD CONSTRAINT idx_element_contact_fk_c_type_contact
FOREIGN KEY (fk_c_type_contact) REFERENCES llx_c_type_contact(rowid); FOREIGN KEY (fk_c_type_contact) REFERENCES llx_c_type_contact(rowid);
-- Au cas ou ce serait necessaire.
-- Abuser des foreign key et parfois plus genant que utile.
-- ALTER TABLE llx_element_contact
-- ADD CONSTRAINT idx_element_contact_fk_socpeople
-- FOREIGN KEY (fk_socpeople) REFERENCES llx_socpeople(idp);

View File

@ -29,10 +29,8 @@ create table llx_element_contact
datecreate datetime NULL, -- date de creation de l'enregistrement datecreate datetime NULL, -- date de creation de l'enregistrement
statut smallint DEFAULT 5, -- 5 inactif, 4 actif statut smallint DEFAULT 5, -- 5 inactif, 4 actif
fk_c_type_contact int NOT NULL, -- nature du contact. element_id int NOT NULL, -- la reference de l'element.
element_id int NOT NULL, -- la reference de l'element. fk_c_type_contact int NOT NULL, -- nature du contact.
-- pour connaitre la table associée a ce contact regarder fk_element_contact->element fk_socpeople integer NOT NULL
fk_socpeople integer NOT NULL
)type=innodb; )type=innodb;