New: Gestion gnrique des contacts sur les contrats.
This commit is contained in:
parent
91afe690c5
commit
8670345354
@ -95,11 +95,10 @@ function select_societes_for_newconcat($contrat, $selected = '', $htmlname = 'ne
|
||||
function select_nature_contact($contrat, $defValue, $htmlname = 'nature')
|
||||
{
|
||||
$lesNatures = $contrat->liste_nature_contact();
|
||||
print '<input name="'.$htmlname.'" type="text" size="12" value="'.$defValue.'"> ';
|
||||
print '<select size="0" name="choix" onChange="form.'.$htmlname.'.value=this.value;" >';
|
||||
for ($i = 0; $i < count($lesNatures); $i ++)
|
||||
print '<select size="0" name="nature">';
|
||||
foreach($lesNatures as $key=>$value)
|
||||
{
|
||||
print '<option>'.$lesNatures[$i].'</option>';
|
||||
print '<option value="'.$key.'">'.$value.'</option>';
|
||||
}
|
||||
print "</select>\n";
|
||||
}
|
||||
@ -122,7 +121,7 @@ if ($_POST["action"] == 'addcontact' && $user->rights->contrat->creer)
|
||||
$result = $contrat->fetch($_GET["id"]);
|
||||
if ($_POST["id"] > 0)
|
||||
{
|
||||
$result = $contrat->add_contact($_POST["contactid"], $_POST["newnature"]);
|
||||
$result = $contrat->add_contact($_POST["contactid"], $_POST["nature"]);
|
||||
}
|
||||
|
||||
if ($result >= 0)
|
||||
@ -165,10 +164,10 @@ if ($_GET["action"] == 'swapstatut' && $user->rights->contrat->creer)
|
||||
if ($contrat->fetch($_GET["id"]))
|
||||
{
|
||||
$contact = $contrat->detail_contact($_GET["ligne"]);
|
||||
$nature = $contact->nature;
|
||||
$id_type_contact = $contact->fk_c_type_contact;
|
||||
$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)
|
||||
{
|
||||
$db->commit();
|
||||
@ -249,11 +248,55 @@ if ($id > 0)
|
||||
|
||||
print "</table>";
|
||||
|
||||
|
||||
print '</div>';
|
||||
|
||||
|
||||
/*
|
||||
* Lignes de contacts
|
||||
*/
|
||||
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"> </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"> </td></tr>';
|
||||
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td>'.$langs->trans("Societe").'</td>';
|
||||
print '<td>'.$langs->trans("Contacts").'</td>';
|
||||
@ -286,18 +329,30 @@ if ($id > 0)
|
||||
{
|
||||
print '<tr '.$bc[$var].' valign="top">';
|
||||
|
||||
print '<td>';
|
||||
print '<a href="'.DOL_URL_ROOT.'/contact/fiche.php?id='.$objp->fk_socpeople.'">';
|
||||
print $person->fullname.'</a>';
|
||||
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 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
|
||||
print '<td align="center">'.$objp->nature.'</td>';
|
||||
print '<td align="center">'.$objp->libelle.'</td>';
|
||||
|
||||
// Statut
|
||||
print '<td align="center">';
|
||||
// Activation descativation du contact
|
||||
// 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);
|
||||
@ -329,7 +384,7 @@ if ($id > 0)
|
||||
|
||||
}
|
||||
// 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
|
||||
{
|
||||
|
||||
@ -340,15 +395,28 @@ if ($id > 0)
|
||||
print "<tr $bc[$var]>";
|
||||
|
||||
print '<td>';
|
||||
print '<a href="'.DOL_URL_ROOT.'/contact/fiche.php?id='.$objp->fk_socpeople.'">';
|
||||
print $person->fullname.'</a>';
|
||||
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 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
|
||||
print '<td align="center">';
|
||||
|
||||
select_nature_contact($contrat, $objp->nature, 'nature');
|
||||
print "</td>";
|
||||
|
||||
// Statut
|
||||
print '<td align="center">'.img_statut($objp->statut).'</td>';
|
||||
|
||||
@ -363,48 +431,8 @@ if ($id > 0)
|
||||
$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"> </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 '</div>';
|
||||
|
||||
} else
|
||||
{
|
||||
|
||||
@ -925,21 +925,22 @@ class Contrat
|
||||
$datecreate = mktime();
|
||||
|
||||
// Insertion dans la base
|
||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."contrat_contact";
|
||||
$sql.= " (fk_contrat, fk_socpeople, datecreate, statut, nature) ";
|
||||
$sql.= " VALUES ($this->id, $fk_socpeople , " ;
|
||||
$sql.= $this->db->pdate(time());
|
||||
$sql.= ", 5, '". $lNature . "' ";
|
||||
$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.= ");";
|
||||
|
||||
// Retour
|
||||
if ( $this->db->query($sql) )
|
||||
{
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
dolibarr_print_error($this->db);
|
||||
// dolibarr_print_error($this->db);
|
||||
$this->error=$this->db->error()." - $sql";
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@ -947,20 +948,17 @@ class Contrat
|
||||
/**
|
||||
*
|
||||
* \brief Misea jour du contact associé au contrat
|
||||
* \param rowid La reference du lien contant contact.
|
||||
* \param statut Le nouveau statut
|
||||
* \param nature description du contact
|
||||
* \param rowid La reference du lien contant contact.
|
||||
* \param statut Le nouveau statut
|
||||
* \param nature Description du contact
|
||||
* \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
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."contrat_contact set ";
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."element_contact set ";
|
||||
$sql.= " statut = $statut ,";
|
||||
$sql.= " nature = '" . $lNature ."'";
|
||||
$sql.= " fk_c_type_contact = '".$type_contact_id ."'";
|
||||
$sql.= " where rowid = $rowid ;";
|
||||
// Retour
|
||||
if ( $this->db->query($sql) )
|
||||
@ -977,21 +975,20 @@ class Contrat
|
||||
/**
|
||||
* \brief Supprime une ligne de contact de contrat
|
||||
* \param idligne La reference du contact
|
||||
* \return statur 0 OK, -1 erreur
|
||||
* \return statur >0 si ok, <0 si ko
|
||||
*/
|
||||
function delete_contact($idligne)
|
||||
{
|
||||
|
||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."contrat_contact WHERE rowid =".$idligne;
|
||||
|
||||
if ($this->db->query($sql) ) {
|
||||
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
function delete_contact($idligne)
|
||||
{
|
||||
|
||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."element_contact WHERE rowid =".$idligne;
|
||||
if ($this->db->query($sql))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1003,10 +1000,14 @@ class Contrat
|
||||
{
|
||||
$tab=array();
|
||||
|
||||
$sql = "SELECT cd.rowid";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."contrat_contact cd , ".MAIN_DB_PREFIX."socpeople sp";
|
||||
$sql.= " WHERE fk_contrat =".$this->id;
|
||||
$sql.= " and cd.fk_socpeople = sp.idp";
|
||||
$sql = "SELECT ec.rowid, tc.code";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."element_contact ec, ".MAIN_DB_PREFIX."socpeople sp,";
|
||||
$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'";
|
||||
$sql.= " AND tc.active=1";
|
||||
$sql.= " AND ec.fk_socpeople = sp.idp";
|
||||
if ($statut >= 0) $sql.= " AND statut = '$statut'";
|
||||
$sql.=" order by sp.name asc ;";
|
||||
|
||||
@ -1026,48 +1027,53 @@ class Contrat
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->error();
|
||||
// dolibarr_print_error($this->db);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Le détail d'un contact
|
||||
* \param rowid L'identifiant du contant de contrat
|
||||
* \return object L'objet de construit par DoliDb.fetch_object
|
||||
* \param rowid L'identifiant du contact
|
||||
* \return object L'objet construit par DoliDb.fetch_object
|
||||
*/
|
||||
function detail_contact($rowid)
|
||||
{
|
||||
|
||||
$sql = "SELECT datecreate, statut, nature, fk_socpeople";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."contrat_contact";
|
||||
$sql.= " WHERE rowid =".$rowid.";";
|
||||
$sql = "SELECT ec.datecreate, ec.statut, ec.fk_socpeople, ec.fk_c_type_contact,";
|
||||
$sql.= " tc.code, tc.libelle, s.fk_soc";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."element_contact as ec, ".MAIN_DB_PREFIX."c_type_contact as tc, ";
|
||||
$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);
|
||||
if ($resql)
|
||||
{
|
||||
$obj = $this->db->fetch_object($result);
|
||||
|
||||
$obj = $this->db->fetch_object($result);
|
||||
return $obj;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->error();
|
||||
dolibarr_print_error($this->db);
|
||||
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
|
||||
*/
|
||||
function liste_nature_contact()
|
||||
{
|
||||
$tab = array();
|
||||
|
||||
$sql = "SELECT distinct nature";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."contrat_contact";
|
||||
$sql.= " order by nature;";
|
||||
$sql = "SELECT distinct tc.rowid, tc.code, tc.libelle";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."c_type_contact as tc";
|
||||
$sql.= " WHERE element='contrat'";
|
||||
$sql.= " ORDER by tc.code";
|
||||
|
||||
$resql=$this->db->query($sql);
|
||||
if ($resql)
|
||||
@ -1077,7 +1083,7 @@ class Contrat
|
||||
while ($i < $num)
|
||||
{
|
||||
$obj = $this->db->fetch_object($result);
|
||||
$tab[$i]=$obj->nature;
|
||||
$tab[$obj->rowid]=$obj->libelle;
|
||||
$i++;
|
||||
}
|
||||
return $tab;
|
||||
@ -1085,6 +1091,7 @@ class Contrat
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->error();
|
||||
// dolibarr_print_error($this->db);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user