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

This commit is contained in:
Laurent Destailleur 2005-09-17 02:06:06 +00:00
parent 91afe690c5
commit 8670345354
2 changed files with 142 additions and 107 deletions

View File

@ -95,11 +95,10 @@ function select_societes_for_newconcat($contrat, $selected = '', $htmlname = 'ne
function select_nature_contact($contrat, $defValue, $htmlname = 'nature') function select_nature_contact($contrat, $defValue, $htmlname = 'nature')
{ {
$lesNatures = $contrat->liste_nature_contact(); $lesNatures = $contrat->liste_nature_contact();
print '<input name="'.$htmlname.'" type="text" size="12" value="'.$defValue.'"> '; print '<select size="0" name="nature">';
print '<select size="0" name="choix" onChange="form.'.$htmlname.'.value=this.value;" >'; foreach($lesNatures as $key=>$value)
for ($i = 0; $i < count($lesNatures); $i ++)
{ {
print '<option>'.$lesNatures[$i].'</option>'; print '<option value="'.$key.'">'.$value.'</option>';
} }
print "</select>\n"; print "</select>\n";
} }
@ -122,7 +121,7 @@ if ($_POST["action"] == 'addcontact' && $user->rights->contrat->creer)
$result = $contrat->fetch($_GET["id"]); $result = $contrat->fetch($_GET["id"]);
if ($_POST["id"] > 0) if ($_POST["id"] > 0)
{ {
$result = $contrat->add_contact($_POST["contactid"], $_POST["newnature"]); $result = $contrat->add_contact($_POST["contactid"], $_POST["nature"]);
} }
if ($result >= 0) if ($result >= 0)
@ -165,10 +164,10 @@ if ($_GET["action"] == 'swapstatut' && $user->rights->contrat->creer)
if ($contrat->fetch($_GET["id"])) if ($contrat->fetch($_GET["id"]))
{ {
$contact = $contrat->detail_contact($_GET["ligne"]); $contact = $contrat->detail_contact($_GET["ligne"]);
$nature = $contact->nature; $id_type_contact = $contact->fk_c_type_contact;
$statut = ($contact->statut == 4) ? 5 : 4; $statut = ($contact->statut == 4) ? 5 : 4;
$result = $contrat->update_contact($_GET["ligne"], $statut, $nature); $result = $contrat->update_contact($_GET["ligne"], $statut, $id_type_contact);
if ($result >= 0) if ($result >= 0)
{ {
$db->commit(); $db->commit();
@ -249,11 +248,55 @@ if ($id > 0)
print "</table>"; print "</table>";
print '</div>';
/* /*
* Lignes de contacts * Lignes de contacts
*/ */
echo '<br><table class="noborder" width="100%">'; echo '<br><table class="noborder" width="100%">';
/*
* Ajouter une ligne de contact
* Non affiché en mode modification de ligne
*/
if ($_GET["action"] != 'editline' && $user->rights->contrat->creer)
{
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Societe").'</td>';
print '<td>'.$langs->trans("Contacts").'</td>';
print '<td align="center">'.$langs->trans("ContactType").'</td>';
print '<td colspan="2">&nbsp;</td>';
print "</tr>\n";
$var = false;
print '<form action="contact.php?id='.$id.'" method="post">';
print '<input type="hidden" name="action" value="addcontact">';
print '<input type="hidden" name="id" value="'.$id.'">';
print "<tr $bc[$var]>";
print '<td colspan="1">';
$selectedCompany = isset($_GET["newcompany"])?$_GET["newcompany"]:$contrat->societe->id;
$selectedCompany = select_societes_for_newconcat($contrat, $selectedCompany, $htmlname = 'newcompany');
print '</td>';
print '<td colspan="1">';
$html->select_contacts($selectedCompany, $selected = '', $htmlname = 'contactid');
print '</td>';
print '<td align="center">';
select_nature_contact($contrat, '', 'nature');
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">&nbsp;</td></tr>';
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Societe").'</td>'; print '<td>'.$langs->trans("Societe").'</td>';
print '<td>'.$langs->trans("Contacts").'</td>'; print '<td>'.$langs->trans("Contacts").'</td>';
@ -286,18 +329,30 @@ if ($id > 0)
{ {
print '<tr '.$bc[$var].' valign="top">'; print '<tr '.$bc[$var].' valign="top">';
print '<td>'; print '<td align="left">';
print '<a href="'.DOL_URL_ROOT.'/contact/fiche.php?id='.$objp->fk_socpeople.'">'; if ($objp->fk_soc)
print $person->fullname.'</a>'; {
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 '<td align="left">'.$societe->get_nom($person->socid).'</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 // Description
print '<td align="center">'.$objp->nature.'</td>'; print '<td align="center">'.$objp->libelle.'</td>';
// Statut // Statut
print '<td align="center">'; print '<td align="center">';
// Activation descativation du contact // Activation desativation du contact
if ($contrat->statut >= 0) if ($contrat->statut >= 0)
print '<a href="'.DOL_URL_ROOT.'/contrat/contact.php?id='.$contrat->id.'&amp;action=swapstatut&amp;ligne='.$tab[$i].'">'; print '<a href="'.DOL_URL_ROOT.'/contrat/contact.php?id='.$contrat->id.'&amp;action=swapstatut&amp;ligne='.$tab[$i].'">';
print img_statut($objp->statut); print img_statut($objp->statut);
@ -329,7 +384,7 @@ if ($id > 0)
} }
// mode edition de une ligne ligne (editline) // mode edition de une ligne ligne (editline)
// on ne change pas le contact. Seulement la nature // on ne change pas le contact. Seulement le type
else else
{ {
@ -340,15 +395,28 @@ if ($id > 0)
print "<tr $bc[$var]>"; print "<tr $bc[$var]>";
print '<td>'; print '<td>';
print '<a href="'.DOL_URL_ROOT.'/contact/fiche.php?id='.$objp->fk_socpeople.'">'; if ($objp->fk_soc)
print $person->fullname.'</a>'; {
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 '<td align="left">'.$societe->get_nom($person->socid).'</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 // Description
print '<td align="center">'; print '<td align="center">';
select_nature_contact($contrat, $objp->nature, 'nature'); select_nature_contact($contrat, $objp->nature, 'nature');
print "</td>"; print "</td>";
// Statut // Statut
print '<td align="center">'.img_statut($objp->statut).'</td>'; print '<td align="center">'.img_statut($objp->statut).'</td>';
@ -363,48 +431,8 @@ if ($id > 0)
$db->free($result); $db->free($result);
} }
/*
* Ajouter une ligne de contact
* uniquement sur les contrats en creation.
* En pas en mode modification de ligne
*/
if ($_GET["action"] != 'editline' && $user->rights->contrat->creer && $contrat->statut == 0)
{
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Societe").'</td>';
print '<td>'.$langs->trans("Contacts").'</td>';
print '<td align="center">'.$langs->trans("ContactType").'</td>';
print '<td colspan="2">&nbsp;</td>';
print "</tr>\n";
$var = false;
print '<form action="contact.php?id='.$id.'" method="post">';
print '<input type="hidden" name="action" value="addcontact">';
print '<input type="hidden" name="id" value="'.$id.'">';
print "<tr $bc[$var]>";
print '<td colspan="1">';
$selectedCompany = $_GET["newcompany"]; // vide pour la premiere recherche
$selectedCompany = select_societes_for_newconcat($contrat, $selectedCompany, $htmlname = 'newcompany');
print '</td>';
print '<td colspan="1">';
$html->select_contacts($selectedCompany, $selected = '', $htmlname = 'contactid');
print '</td>';
print '<td align="center">';
select_nature_contact($contrat, "", 'newnature');
print '</td>';
print '<td align="right" colspan="3" ><input type="submit" class="button" value="'.$langs->trans("Add").'"></td>';
print '</tr>';
print "</form>";
}
print "</table>"; print "</table>";
print '</div>';
} else } else
{ {

View File

@ -925,21 +925,22 @@ class Contrat
$datecreate = mktime(); $datecreate = mktime();
// Insertion dans la base // Insertion dans la base
$sql = "INSERT INTO ".MAIN_DB_PREFIX."contrat_contact"; $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_contact";
$sql.= " (fk_contrat, fk_socpeople, datecreate, statut, nature) "; $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->pdate(time()); $sql.= $this->db->idate(time());
$sql.= ", 5, '". $lNature . "' "; $sql.= ", 4, '". $lNature . "' ";
$sql.= ");"; $sql.= ");";
// Retour // Retour
if ( $this->db->query($sql) ) if ( $this->db->query($sql) )
{ {
return 0; return 1;
} }
else else
{ {
dolibarr_print_error($this->db); // dolibarr_print_error($this->db);
$this->error=$this->db->error()." - $sql";
return -1; return -1;
} }
} }
@ -947,20 +948,17 @@ class Contrat
/** /**
* *
* \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.
* \param statut Le nouveau statut * \param statut Le nouveau statut
* \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, $nature) function update_contact($rowid, $statut, $type_contact_id)
{ {
$lNature = addslashes(trim($nature));
// Insertion dans la base // Insertion dans la base
$sql = "UPDATE ".MAIN_DB_PREFIX."contrat_contact set "; $sql = "UPDATE ".MAIN_DB_PREFIX."element_contact set ";
$sql.= " statut = $statut ,"; $sql.= " statut = $statut ,";
$sql.= " nature = '" . $lNature ."'"; $sql.= " fk_c_type_contact = '".$type_contact_id ."'";
$sql.= " where rowid = $rowid ;"; $sql.= " where rowid = $rowid ;";
// Retour // Retour
if ( $this->db->query($sql) ) if ( $this->db->query($sql) )
@ -977,21 +975,20 @@ class Contrat
/** /**
* \brief Supprime une ligne de contact de contrat * \brief Supprime une ligne de contact de contrat
* \param idligne La reference du contact * \param idligne La reference du contact
* \return statur 0 OK, -1 erreur * \return statur >0 si ok, <0 si ko
*/ */
function delete_contact($idligne) function delete_contact($idligne)
{ {
$sql = "DELETE FROM ".MAIN_DB_PREFIX."contrat_contact WHERE rowid =".$idligne; $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_contact WHERE rowid =".$idligne;
if ($this->db->query($sql))
if ($this->db->query($sql) ) { {
return 1;
return 0; }
} else
else {
{ return -1;
return 1; }
}
} }
/** /**
@ -1003,10 +1000,14 @@ class Contrat
{ {
$tab=array(); $tab=array();
$sql = "SELECT cd.rowid"; $sql = "SELECT ec.rowid, tc.code";
$sql.= " FROM ".MAIN_DB_PREFIX."contrat_contact cd , ".MAIN_DB_PREFIX."socpeople sp"; $sql.= " FROM ".MAIN_DB_PREFIX."element_contact ec, ".MAIN_DB_PREFIX."socpeople sp,";
$sql.= " WHERE fk_contrat =".$this->id; $sql.= " ".MAIN_DB_PREFIX."c_type_contact tc";
$sql.= " and cd.fk_socpeople = sp.idp"; $sql.= " WHERE element_id =".$this->id;
$sql.= " AND ec.fk_c_type_contact=tc.rowid";
$sql.= " AND tc.element='contrat'";
$sql.= " AND tc.active=1";
$sql.= " AND ec.fk_socpeople = sp.idp";
if ($statut >= 0) $sql.= " AND statut = '$statut'"; if ($statut >= 0) $sql.= " AND statut = '$statut'";
$sql.=" order by sp.name asc ;"; $sql.=" order by sp.name asc ;";
@ -1026,48 +1027,53 @@ class Contrat
else else
{ {
$this->error=$this->db->error(); $this->error=$this->db->error();
// dolibarr_print_error($this->db);
return -1; return -1;
} }
} }
/** /**
* \brief Le détail d'un contact * \brief Le détail d'un contact
* \param rowid L'identifiant du contant de contrat * \param rowid L'identifiant du contact
* \return object L'objet de construit par DoliDb.fetch_object * \return object L'objet construit par DoliDb.fetch_object
*/ */
function detail_contact($rowid) function detail_contact($rowid)
{ {
$sql = "SELECT ec.datecreate, ec.statut, ec.fk_socpeople, ec.fk_c_type_contact,";
$sql = "SELECT datecreate, statut, nature, fk_socpeople"; $sql.= " tc.code, tc.libelle, s.fk_soc";
$sql.= " FROM ".MAIN_DB_PREFIX."contrat_contact"; $sql.= " FROM ".MAIN_DB_PREFIX."element_contact as ec, ".MAIN_DB_PREFIX."c_type_contact as tc, ";
$sql.= " WHERE rowid =".$rowid.";"; $sql.= " ".MAIN_DB_PREFIX."socpeople as s";
$sql.= " WHERE ec.rowid =".$rowid;
$sql.= " AND ec.fk_socpeople=s.idp";
$sql.= " AND ec.fk_c_type_contact=tc.rowid";
$sql.= " AND tc.element = 'contrat'";
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)
{ {
$obj = $this->db->fetch_object($result); $obj = $this->db->fetch_object($result);
return $obj; return $obj;
} }
else else
{ {
$this->error=$this->db->error(); $this->error=$this->db->error();
dolibarr_print_error($this->db);
return null; return null;
} }
} }
/** /**
* \brief La liste des valeurs possibles de nature de contats * \brief La liste des valeurs possibles de type de contats
*
* \return array La liste des natures * \return array La liste des natures
*/ */
function liste_nature_contact() function liste_nature_contact()
{ {
$tab = array(); $tab = array();
$sql = "SELECT distinct nature"; $sql = "SELECT distinct tc.rowid, tc.code, tc.libelle";
$sql.= " FROM ".MAIN_DB_PREFIX."contrat_contact"; $sql.= " FROM ".MAIN_DB_PREFIX."c_type_contact as tc";
$sql.= " order by nature;"; $sql.= " WHERE element='contrat'";
$sql.= " ORDER by tc.code";
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)
@ -1077,7 +1083,7 @@ class Contrat
while ($i < $num) while ($i < $num)
{ {
$obj = $this->db->fetch_object($result); $obj = $this->db->fetch_object($result);
$tab[$i]=$obj->nature; $tab[$obj->rowid]=$obj->libelle;
$i++; $i++;
} }
return $tab; return $tab;
@ -1085,6 +1091,7 @@ class Contrat
else else
{ {
$this->error=$this->db->error(); $this->error=$this->db->error();
// dolibarr_print_error($this->db);
return null; return null;
} }
} }