New: Gestion gnrique des contacts sur les contrats.
This commit is contained in:
parent
3e7a5f2fa5
commit
3f3c66ef72
@ -1,5 +1,6 @@
|
||||
<?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
|
||||
* 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
|
||||
$sql = "SELECT s.idp, s.nom FROM";
|
||||
$sql .= " ".MAIN_DB_PREFIX."societe as s";
|
||||
if ($filter)
|
||||
$sql .= " WHERE $filter";
|
||||
if ($filter) $sql .= " WHERE $filter";
|
||||
$sql .= " ORDER BY nom ASC";
|
||||
|
||||
$resql = $contrat->db->query($sql);
|
||||
@ -72,11 +72,11 @@ function select_societes_for_newconcat($contrat, $selected = '', $htmlname = 'ne
|
||||
$firstCompany = $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;
|
||||
} else
|
||||
{
|
||||
print '<option value="'.$obj->idp.'">'.$obj->nom.'</option>';
|
||||
print '<option value="'.$obj->idp.'">'.dolibarr_trunc($obj->nom,24).'</option>';
|
||||
}
|
||||
$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();
|
||||
print '<select size="0" name="nature">';
|
||||
foreach($lesNatures as $key=>$value)
|
||||
$lesTypes = $contrat->liste_type_contact($source);
|
||||
print '<select size="0" name="'.$htmlname.'">';
|
||||
foreach($lesTypes as $key=>$value)
|
||||
{
|
||||
print '<option value="'.$key.'">'.$value.'</option>';
|
||||
}
|
||||
print "</select>\n";
|
||||
}
|
||||
|
||||
|
||||
// Sécurité accés client
|
||||
if ($user->societe_id > 0)
|
||||
{
|
||||
@ -119,11 +120,12 @@ if ($_POST["action"] == 'addcontact' && $user->rights->contrat->creer)
|
||||
$result = 0;
|
||||
$contrat = new Contrat($db);
|
||||
$result = $contrat->fetch($_GET["id"]);
|
||||
if ($_POST["id"] > 0)
|
||||
{
|
||||
$result = $contrat->add_contact($_POST["contactid"], $_POST["nature"]);
|
||||
}
|
||||
|
||||
if ($result > 0 && $_POST["id"] > 0)
|
||||
{
|
||||
$result = $contrat->add_contact($_POST["contactid"], $_POST["type"], $_POST["source"]);
|
||||
}
|
||||
|
||||
if ($result >= 0)
|
||||
{
|
||||
Header("Location: contact.php?id=".$contrat->id);
|
||||
@ -133,17 +135,17 @@ if ($_POST["action"] == 'addcontact' && $user->rights->contrat->creer)
|
||||
$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)
|
||||
{
|
||||
$contrat = new Contrat($db);
|
||||
if ($contrat->fetch($_GET["id"]))
|
||||
{
|
||||
$contact = $contrat->detail_contact($_POST["elrowid"]);
|
||||
$nature = $_POST["nature"];
|
||||
$type = $_POST["type"];
|
||||
$statut = $contact->statut;
|
||||
|
||||
$result = $contrat->update_contact($_POST["elrowid"], $statut, $nature);
|
||||
$result = $contrat->update_contact($_POST["elrowid"], $statut, $type);
|
||||
if ($result >= 0)
|
||||
{
|
||||
$db->commit();
|
||||
@ -157,6 +159,7 @@ if ($_POST["action"] == 'updateligne' && $user->rights->contrat->creer)
|
||||
dolibarr_print_error($db);
|
||||
}
|
||||
}
|
||||
|
||||
// bascule du statut d'un contact
|
||||
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)
|
||||
{
|
||||
$contrat = new Contrat($db);
|
||||
@ -264,6 +268,7 @@ if ($id > 0)
|
||||
if ($_GET["action"] != 'editline' && $user->rights->contrat->creer)
|
||||
{
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td>'.$langs->trans("Source").'</td>';
|
||||
print '<td>'.$langs->trans("Societe").'</td>';
|
||||
print '<td>'.$langs->trans("Contacts").'</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 '<input type="hidden" name="action" value="addcontact">';
|
||||
print '<input type="hidden" name="source" value="internal">';
|
||||
print '<input type="hidden" name="id" value="'.$id.'">';
|
||||
|
||||
// Ligne ajout pour contact interne
|
||||
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">';
|
||||
$selectedCompany = isset($_GET["newcompany"])?$_GET["newcompany"]:$contrat->societe->id;
|
||||
$selectedCompany = select_societes_for_newconcat($contrat, $selectedCompany, $htmlname = 'newcompany');
|
||||
@ -286,155 +326,115 @@ if ($id > 0)
|
||||
$html->select_contacts($selectedCompany, $selected = '', $htmlname = 'contactid');
|
||||
print '</td>';
|
||||
print '<td align="center">';
|
||||
select_nature_contact($contrat, '', 'nature');
|
||||
select_type_contact($contrat, '', 'type','external');
|
||||
print '</td>';
|
||||
print '<td align="right" colspan="3" ><input type="submit" class="button" value="'.$langs->trans("Add").'"></td>';
|
||||
print '</tr>';
|
||||
|
||||
|
||||
print "</form>";
|
||||
|
||||
}
|
||||
|
||||
print '<tr><td colspan="6"> </td></tr>';
|
||||
|
||||
// Liste des contacts liés
|
||||
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 align="center">'.$langs->trans("ContactType").'</td>';
|
||||
print '<td align="center">'.$langs->trans("Status").'</td>';
|
||||
print '<td colspan="2"> </td>';
|
||||
print "</tr>\n";
|
||||
|
||||
$tab = $contrat->liste_contact();
|
||||
$societe = new Societe($db);
|
||||
$var = true;
|
||||
|
||||
$num = ($tab == null) ? 0 : count($tab);
|
||||
if ($tab != null && $num > 0)
|
||||
foreach(array('internal','external') as $source)
|
||||
{
|
||||
$tab = $contrat->liste_contact(-1,$source);
|
||||
$num=sizeof($tab);
|
||||
|
||||
$i = 0;
|
||||
$total = 0;
|
||||
|
||||
$var = true;
|
||||
$person = new Contact($db);
|
||||
$societe = new Societe($db);
|
||||
|
||||
while ($i < $num)
|
||||
{
|
||||
$objp = $contrat->detail_contact($tab[$i]);
|
||||
$var = !$var;
|
||||
|
||||
// detail du contact
|
||||
$person->fetch($objp->fk_socpeople);
|
||||
$var = !$var; // flip flop lines
|
||||
print '<tr '.$bc[$var].' valign="top">';
|
||||
|
||||
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 '<td align="left">';
|
||||
if ($objp->fk_soc)
|
||||
{
|
||||
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 ' ';
|
||||
}
|
||||
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.'&action=swapstatut&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.'&action=editline&rowid='.$tab[$i].'">';
|
||||
print img_edit();
|
||||
print '</a>';
|
||||
} else
|
||||
{
|
||||
print ' ';
|
||||
}
|
||||
if ($contrat->statut == 0 && $user->rights->contrat->creer)
|
||||
{
|
||||
print ' ';
|
||||
print '<a href="contact.php?id='.$id.'&action=deleteline&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 '<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 '</a>';
|
||||
}
|
||||
if ($tab[$i]['socid'] < 0)
|
||||
{
|
||||
print $conf->global->MAIN_INFO_SOCIETE_NOM;
|
||||
}
|
||||
if (! $tab[$i]['socid'])
|
||||
{
|
||||
print ' ';
|
||||
}
|
||||
print '</td>';
|
||||
|
||||
print "<form name='detailcontact' action=\"contact.php?id=$id\" method=\"post\">";
|
||||
print '<input type="hidden" name="action" value="updateligne">';
|
||||
print '<input type="hidden" name="elrowid" value="'.$_GET["rowid"].'">';
|
||||
// Ligne carac
|
||||
print "<tr $bc[$var]>";
|
||||
// Contact
|
||||
print '<td>';
|
||||
if ($tab[$i]['source']=='internal')
|
||||
{
|
||||
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>';
|
||||
if ($objp->fk_soc)
|
||||
{
|
||||
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 ' ';
|
||||
}
|
||||
print '</td>';
|
||||
// Description
|
||||
print '<td align="center">'.$tab[$i]['libelle'].'</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>';
|
||||
// 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.'&action=swapstatut&ligne='.$tab[$i]['rowid'].'">';
|
||||
print img_statut($tab[$i]['status']);
|
||||
if ($contrat->statut >= 0)
|
||||
print '</a>';
|
||||
print '</td>';
|
||||
|
||||
// Description
|
||||
print '<td align="center">';
|
||||
select_nature_contact($contrat, $objp->nature, 'nature');
|
||||
print "</td>";
|
||||
|
||||
// Statut
|
||||
print '<td align="center">'.img_statut($objp->statut).'</td>';
|
||||
|
||||
// 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";
|
||||
// Icon update et delete (statut contrat 0=brouillon,1=validé,2=fermé)
|
||||
print '<td align="center" nowrap>';
|
||||
if ($contrat->statut == 0 && $user->rights->contrat->creer)
|
||||
{
|
||||
print ' ';
|
||||
print '<a href="contact.php?id='.$contrat->id.'&action=deleteline&lineid='.$tab[$i]['rowid'].'">';
|
||||
print img_delete();
|
||||
print '</a>';
|
||||
}
|
||||
print '</td>';
|
||||
|
||||
print "</tr>\n";
|
||||
|
||||
$i ++;
|
||||
}
|
||||
$db->free($result);
|
||||
}
|
||||
|
||||
print "</table>";
|
||||
|
||||
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
// Contrat non trouvé
|
||||
print "Contrat inexistant ou accés refusé";
|
||||
|
||||
@ -420,25 +420,47 @@ class Contrat
|
||||
$this->db->begin();
|
||||
|
||||
// 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.= ",".($this->commercial_signature_id>=0?$this->commercial_signature_id:"null");
|
||||
$sql.= ",".($this->commercial_suivi_id>=0?$this->commercial_suivi_id:"null");
|
||||
$sql.= ",".$this->db->idate($this->date_contrat) .")";
|
||||
$sql.= ",".$this->db->idate($this->date_contrat);
|
||||
// $sql.= ",".($this->commercial_signature_id>=0?$this->commercial_signature_id:"null");
|
||||
// $sql.= ",".($this->commercial_suivi_id>=0?$this->commercial_suivi_id:"null");
|
||||
$sql.= ")";
|
||||
$resql=$this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$error=0;
|
||||
|
||||
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."contrat");
|
||||
|
||||
// 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();
|
||||
// Insère contacts commerciaux ('SALESREPSIGN','contrat')
|
||||
$result=$this->add_contact($this->commercial_signature_id,'SALESREPSIGN','internal');
|
||||
if ($result < 0) $error++;
|
||||
|
||||
// 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
|
||||
{
|
||||
@ -905,31 +927,30 @@ class Contrat
|
||||
/* gestion des contacts d'un contrat */
|
||||
|
||||
/**
|
||||
*
|
||||
* \brief Ajoute un contact associé au contrat
|
||||
* \param fk_socpeople Id du contact a ajouter.
|
||||
* \param nature description du contact
|
||||
* \return int <0 si erreur, >0 si ok
|
||||
* \param fk_socpeople Id du contact a ajouter.
|
||||
* \param type_contact Type de contact
|
||||
* \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) return -1;
|
||||
|
||||
// \todo si type_contact = texte, aller chercher code dans table llx_c_type_contact
|
||||
if ($type_contact == 'SALESREPSIGN') $type_contact=11;
|
||||
if ($type_contact == 'SALESREPFOLL') $type_contact=12;
|
||||
|
||||
if ($fk_socpeople <= 0
|
||||
|| $this->societe->contact_get_email($fk_socpeople) == "" )
|
||||
{
|
||||
// le contact n'existe pas ou est invalide
|
||||
return -1;
|
||||
}
|
||||
|
||||
$lNature = addslashes(trim($nature));
|
||||
$datecreate = mktime();
|
||||
$datecreate = time();
|
||||
|
||||
// Insertion dans la base
|
||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."element_contact";
|
||||
$sql.= " (element_id, fk_socpeople, datecreate, statut, fk_c_type_contact) ";
|
||||
$sql.= " VALUES (".$this->id.", ".$fk_socpeople." , " ;
|
||||
$sql.= $this->db->idate(time());
|
||||
$sql.= ", 4, '". $lNature . "' ";
|
||||
$sql.= $this->db->idate($datecreate);
|
||||
$sql.= ", 4, '". $type_contact . "' ";
|
||||
$sql.= ");";
|
||||
|
||||
// Retour
|
||||
@ -943,9 +964,9 @@ class Contrat
|
||||
$this->error=$this->db->error()." - $sql";
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* \brief Misea jour du contact associé au contrat
|
||||
* \param rowid La reference du lien contant contact.
|
||||
@ -953,8 +974,8 @@ class Contrat
|
||||
* \param nature Description du contact
|
||||
* \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
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."element_contact set ";
|
||||
$sql.= " statut = $statut ,";
|
||||
@ -993,23 +1014,36 @@ class Contrat
|
||||
|
||||
/**
|
||||
* \brief Récupère les lignes de contact du contrat
|
||||
* \param statut Statut des lignes detail à récupérer
|
||||
* \return array Tableau des rowid des contacts
|
||||
* \param statut Statut des lignes detail à récupérer
|
||||
* \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();
|
||||
|
||||
$sql = "SELECT ec.rowid, tc.code";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."element_contact ec, ".MAIN_DB_PREFIX."socpeople sp,";
|
||||
$sql = "SELECT ec.rowid, ec.statut, ec.fk_socpeople as id,";
|
||||
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.= " WHERE element_id =".$this->id;
|
||||
$sql.= " AND ec.fk_c_type_contact=tc.rowid";
|
||||
$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 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'";
|
||||
$sql.=" order by sp.name asc ;";
|
||||
$sql.=" ORDER BY t.name ASC";
|
||||
|
||||
$resql=$this->db->query($sql);
|
||||
if ($resql)
|
||||
@ -1019,7 +1053,10 @@ class Contrat
|
||||
while ($i < $num)
|
||||
{
|
||||
$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++;
|
||||
}
|
||||
return $tab;
|
||||
@ -1027,7 +1064,7 @@ class Contrat
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->error();
|
||||
// dolibarr_print_error($this->db);
|
||||
dolibarr_print_error($this->db);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@ -1063,16 +1100,18 @@ class Contrat
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief La liste des valeurs possibles de type de contats
|
||||
* \return array La liste des natures
|
||||
* \brief La liste des valeurs possibles de type de contacts
|
||||
* \param source internal ou externam
|
||||
* \return array La liste des natures
|
||||
*/
|
||||
function liste_nature_contact()
|
||||
function liste_type_contact($source)
|
||||
{
|
||||
$tab = array();
|
||||
|
||||
$sql = "SELECT distinct tc.rowid, tc.code, tc.libelle";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."c_type_contact as tc";
|
||||
$sql.= " WHERE element='contrat'";
|
||||
$sql.= " AND source='".$source."'";
|
||||
$sql.= " ORDER by tc.code";
|
||||
|
||||
$resql=$this->db->query($sql);
|
||||
|
||||
@ -353,52 +353,95 @@ class Form
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief Retourne la liste déroulante des contacts d'une société donnée
|
||||
* \param socid Id de la société
|
||||
* \param selected Id contact pré-sélectionné
|
||||
* \param htmlname Nom champ formulaire
|
||||
*/
|
||||
function select_contacts($socid,$selected='',$htmlname='contactid')
|
||||
{
|
||||
// On recherche les societes
|
||||
$sql = "SELECT s.idp, s.name, s.firstname FROM ";
|
||||
$sql .= MAIN_DB_PREFIX ."socpeople as s";
|
||||
$sql .= " WHERE fk_soc=".$socid;
|
||||
$sql .= " ORDER BY s.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->idp)
|
||||
{
|
||||
print '<option value="'.$obj->idp.'" selected="true">'.$obj->name.' '.$obj->firstname.'</option>';
|
||||
}
|
||||
else
|
||||
{
|
||||
print '<option value="'.$obj->idp.'">'.$obj->name.' '.$obj->firstname.'</option>';
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
print '</select>';
|
||||
}
|
||||
else
|
||||
{
|
||||
dolibarr_print_error($this->db);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* \brief Retourne la liste déroulante des contacts d'une société donnée
|
||||
* \param socid Id de la société
|
||||
* \param selected Id contact pré-sélectionn
|
||||
* \param htmlname Nom champ formulaire
|
||||
*/
|
||||
function select_contacts($socid,$selected='',$htmlname='contactid')
|
||||
{
|
||||
// On recherche les societes
|
||||
$sql = "SELECT s.idp, s.name, s.firstname FROM ";
|
||||
$sql .= MAIN_DB_PREFIX ."socpeople as s";
|
||||
$sql .= " WHERE fk_soc=".$socid;
|
||||
$sql .= " ORDER BY s.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->idp)
|
||||
{
|
||||
print '<option value="'.$obj->idp.'" selected="true">'.$obj->name.' '.$obj->firstname.'</option>';
|
||||
}
|
||||
else
|
||||
{
|
||||
print '<option value="'.$obj->idp.'">'.$obj->name.' '.$obj->firstname.'</option>';
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
print '</select>';
|
||||
}
|
||||
else
|
||||
{
|
||||
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
|
||||
* \param socid Id société
|
||||
* \param selected Id projet présélectionné
|
||||
|
||||
@ -280,6 +280,10 @@ DateFromTo=From %s to %s
|
||||
DateFrom=From %s
|
||||
DateUntil=Until %s
|
||||
Check=Check
|
||||
Internal=Internal
|
||||
External=External
|
||||
Internals=Internal
|
||||
Externals=External
|
||||
# Countries
|
||||
CountryFR=France
|
||||
CountryBE=Belgium
|
||||
|
||||
@ -280,6 +280,10 @@ DateFromTo=Du %s au %s
|
||||
DateFrom=A partir du %s
|
||||
DateUntil=Jusqu'au %s
|
||||
Check=Vérifier
|
||||
Internal=Interne
|
||||
External=Externe
|
||||
Internals=Internes
|
||||
Externals=Externes
|
||||
# Countries
|
||||
CountryFR=France
|
||||
CountryBE=Belgique
|
||||
|
||||
@ -1789,52 +1789,57 @@ create table llx_societe_perms
|
||||
)type=innodb;
|
||||
|
||||
|
||||
drop table if exists llx_element_contact;
|
||||
drop table if exists llx_c_type_contact;
|
||||
|
||||
create table llx_c_type_contact
|
||||
(
|
||||
rowid integer PRIMARY KEY,
|
||||
code varchar(16) NOT NULL,
|
||||
element varchar(30) NOT NULL,
|
||||
source varchar(8) DEFAULT 'external' NOT NULL,
|
||||
code varchar(16) NOT NULL,
|
||||
libelle varchar(64) NOT NULL,
|
||||
active tinyint DEFAULT 1 NOT NULL
|
||||
)type=innodb;
|
||||
|
||||
|
||||
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
|
||||
(
|
||||
rowid integer AUTO_INCREMENT PRIMARY KEY,
|
||||
datecreate datetime NULL,
|
||||
statut smallint DEFAULT 5,
|
||||
datecreate datetime NULL, -- date de creation de l'enregistrement
|
||||
statut smallint DEFAULT 5, -- 5 inactif, 4 actif
|
||||
|
||||
fk_c_type_contact int NOT NULL,
|
||||
element_id int NOT NULL,
|
||||
|
||||
fk_socpeople integer NOT NULL
|
||||
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
|
||||
)type=innodb;
|
||||
|
||||
|
||||
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
|
||||
ADD CONSTRAINT idx_element_contact_fk_c_type_contact
|
||||
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, code, element, libelle, active ) values (11, 'SALESREPSIGN', 'contrat', '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, code, element, libelle, active ) values (13, 'CUSTOMER', 'contrat', '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, code, element, libelle, active ) values (21, 'SALESREPSIGN', 'propal', '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, code, element, libelle, active ) values (23, 'CUSTOMER', 'propal', 'Contact client pour la propale', 1);
|
||||
|
||||
insert into llx_c_type_contact(rowid, code, element, libelle, active ) values (80, 'PROJECTLEADER', 'projet', 'Chef de Projet', 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, element, source, code, libelle, active ) values (11, 'contrat', 'internal', 'SALESREPSIGN', 'Commercial signataire 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, element, source, code, libelle, active ) values (13, 'contrat', 'external', 'CUSTOMER', 'Contact client pour le contrat', 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, element, source, code, libelle, active ) values (21, 'propal', 'internal', 'SALESREPSIGN', 'Commercial signataire 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, 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);
|
||||
|
||||
|
||||
alter table llx_commande add ref_client varchar(30);
|
||||
alter table llx_facture add ref_client varchar(30);
|
||||
|
||||
@ -31,5 +31,5 @@
|
||||
|
||||
|
||||
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);
|
||||
|
||||
|
||||
@ -33,8 +33,9 @@
|
||||
create table llx_c_type_contact
|
||||
(
|
||||
rowid integer PRIMARY KEY,
|
||||
code varchar(16) NOT NULL,
|
||||
element varchar(30) NOT NULL,
|
||||
source varchar(8) DEFAULT 'external' NOT NULL,
|
||||
code varchar(16) NOT NULL,
|
||||
libelle varchar(64) NOT NULL,
|
||||
active tinyint DEFAULT 1 NOT NULL
|
||||
)type=innodb;
|
||||
|
||||
@ -22,15 +22,8 @@
|
||||
|
||||
|
||||
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
|
||||
ADD CONSTRAINT idx_element_contact_fk_c_type_contact
|
||||
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);
|
||||
|
||||
|
||||
@ -29,10 +29,8 @@ create table llx_element_contact
|
||||
datecreate datetime NULL, -- date de creation de l'enregistrement
|
||||
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.
|
||||
-- pour connaitre la table associée a ce contact regarder fk_element_contact->element
|
||||
|
||||
fk_socpeople integer NOT NULL
|
||||
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
|
||||
)type=innodb;
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user