dolibarr  16.0.5
societecontact.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2005 Patrick Rouillon <patrick@rouillon.net>
3  * Copyright (C) 2005-2011 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
5  * Copyright (C) 2011-2015 Philippe Grand <philippe.grand@atoo-net.com>
6  * Copyright (C) 2014 Charles-Fr Benke <charles.fr@benke.fr>
7  * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <https://www.gnu.org/licenses/>.
21  */
22 
29 require '../main.inc.php';
30 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
34 
35 $langs->loadLangs(array("orders", "companies"));
36 
37 $id = GETPOST('id', 'int') ?GETPOST('id', 'int') : GETPOST('socid', 'int');
38 $ref = GETPOST('ref', 'alpha');
39 $action = GETPOST('action', 'aZ09');
40 $massaction = GETPOST('massaction', 'alpha');
41 
42 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
43 $sortfield = GETPOST('sortfield', 'aZ09comma');
44 $sortorder = GETPOST('sortorder', 'aZ09comma');
45 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
46 if (!$sortorder) {
47  $sortorder = "ASC";
48 }
49 if (!$sortfield) {
50  $sortfield = "s.nom";
51 }
52 if (empty($page) || $page == -1 || !empty($search_btn) || !empty($search_remove_btn) || (empty($toselect) && $massaction === '0')) {
53  $page = 0;
54 }
55 $offset = $limit * $page;
56 $pageprev = $page - 1;
57 $pagenext = $page + 1;
58 
59 // Security check
60 if ($user->socid) {
61  $socid = $user->socid;
62 }
63 $result = restrictedArea($user, 'societe', $id, '');
64 
65 $object = new Societe($db);
66 
67 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
68 $hookmanager->initHooks(array('contactthirdparty', 'globalcard'));
69 
70 
71 /*
72  * Actions
73  */
74 
75 if ($action == 'addcontact' && $user->rights->societe->creer) {
76  $result = $object->fetch($id);
77 
78  if ($result > 0 && $id > 0) {
79  $contactid = (GETPOST('userid', 'int') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int'));
80  $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
81  $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
82  }
83 
84  if ($result >= 0) {
85  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
86  exit;
87  } else {
88  if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
89  $langs->load("errors");
90  $mesg = '<div class="error">'.$langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType").'</div>';
91  } else {
92  $mesg = '<div class="error">'.$object->error.'</div>';
93  }
94  }
95 } elseif ($action == 'swapstatut' && $user->rights->societe->creer) {
96  // bascule du statut d'un contact
97  if ($object->fetch($id)) {
98  $result = $object->swapContactStatus(GETPOST('ligne', 'int'));
99  } else {
100  dol_print_error($db);
101  }
102 } elseif ($action == 'deletecontact' && $user->rights->societe->creer) {
103  // Efface un contact
104  $object->fetch($id);
105  $result = $object->delete_contact(GETPOST("lineid", 'int'));
106 
107  if ($result >= 0) {
108  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
109  exit;
110  } else {
111  dol_print_error($db);
112  }
113 }
114 
115 
116 /*
117  * View
118  */
119 
120 $help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
121 llxHeader('', $langs->trans("ThirdParty"), $help_url);
122 
123 
124 $form = new Form($db);
125 $formcompany = new FormCompany($db);
126 $formother = new FormOther($db);
127 $contactstatic = new Contact($db);
128 $userstatic = new User($db);
129 
130 
131 /* *************************************************************************** */
132 /* */
133 /* Mode vue et edition */
134 /* */
135 /* *************************************************************************** */
136 
137 if ($id > 0 || !empty($ref)) {
138  if ($object->fetch($id, $ref) > 0) {
139  $soc = new Societe($db);
140  $soc->fetch($object->socid);
141 
142  $head = societe_prepare_head($object);
143  print dol_get_fiche_head($head, 'contact', $langs->trans("ThirdParty"), -1, 'company');
144 
145  print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
146  print '<input type="hidden" name="token" value="'.newToken().'">';
147 
148  $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
149 
150  dol_banner_tab($object, 'socid', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom');
151 
152  print '<div class="fichecenter">';
153 
154  print '<div class="underbanner clearboth"></div>';
155  print '<table class="border centpercent">';
156 
157  // Prospect/Customer
158  /*print '<tr><td class="titlefield">'.$langs->trans('ProspectCustomer').'</td><td>';
159  print $object->getLibCustProspStatut();
160  print '</td></tr>';
161 
162  // Supplier
163  print '<tr><td>'.$langs->trans('Supplier').'</td><td>';
164  print yn($object->fournisseur);
165  print '</td></tr>';*/
166 
167  if (!empty($conf->global->SOCIETE_USEPREFIX)) { // Old not used prefix field
168  print '<tr><td>'.$langs->trans('Prefix').'</td><td colspan="3">'.$object->prefix_comm.'</td></tr>';
169  }
170 
171  if ($object->client) {
172  print '<tr><td class="titlefield">';
173  print $langs->trans('CustomerCode').'</td><td colspan="3">';
174  print $object->code_client;
175  $tmpcheck = $object->check_codeclient();
176  if ($tmpcheck != 0 && $tmpcheck != -5) {
177  print ' <span class="error">('.$langs->trans("WrongCustomerCode").')</span>';
178  }
179  print '</td></tr>';
180  }
181 
182  if ($object->fournisseur) {
183  print '<tr><td class="titlefield">';
184  print $langs->trans('SupplierCode').'</td><td colspan="3">';
185  print $object->code_fournisseur;
186  $tmpcheck = $object->check_codefournisseur();
187  if ($tmpcheck != 0 && $tmpcheck != -5) {
188  print ' <span class="error">('.$langs->trans("WrongSupplierCode").')</span>';
189  }
190  print '</td></tr>';
191  }
192  print '</table>';
193 
194  print '</div>';
195 
196  print '</form>';
197  print '<br>';
198 
199  // Contacts lines (modules that overwrite templates must declare this into descriptor)
200  $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
201  foreach ($dirtpls as $reldir) {
202  $res = @include dol_buildpath($reldir.'/contacts.tpl.php');
203  if ($res) {
204  break;
205  }
206  }
207 
208  // additionnal list with adherents of company
209  if (!empty($conf->adherent->enabled) && $user->rights->adherent->lire) {
210  require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
211  require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
212 
213  $membertypestatic = new AdherentType($db);
214  $memberstatic = new Adherent($db);
215 
216  $langs->load("members");
217  $sql = "SELECT d.rowid, d.login, d.lastname, d.firstname, d.societe as company, d.fk_soc,";
218  $sql .= " d.datefin,";
219  $sql .= " d.email, d.fk_adherent_type as type_id, d.morphy, d.statut,";
220  $sql .= " t.libelle as type, t.subscription";
221  $sql .= " FROM ".MAIN_DB_PREFIX."adherent as d";
222  $sql .= ", ".MAIN_DB_PREFIX."adherent_type as t";
223  $sql .= " WHERE d.fk_soc = ".((int) $id);
224  $sql .= " AND d.fk_adherent_type = t.rowid";
225 
226  dol_syslog("get list sql=".$sql);
227  $resql = $db->query($sql);
228  if ($resql) {
229  $num = $db->num_rows($resql);
230 
231  if ($num > 0) {
232  $param = '';
233 
234  $titre = $langs->trans("MembersListOfTiers");
235  print '<br>';
236 
237  print_barre_liste($titre, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, 0, '');
238 
239  print "<table class=\"noborder\" width=\"100%\">";
240  print '<tr class="liste_titre">';
241  print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "d.rowid", $param, "", "", $sortfield, $sortorder);
242  print_liste_field_titre("NameSlashCompany", $_SERVER["PHP_SELF"], "d.lastname", $param, "", "", $sortfield, $sortorder);
243  print_liste_field_titre("Login", $_SERVER["PHP_SELF"], "d.login", $param, "", "", $sortfield, $sortorder);
244  print_liste_field_titre("Type", $_SERVER["PHP_SELF"], "t.libelle", $param, "", "", $sortfield, $sortorder);
245  print_liste_field_titre("Person", $_SERVER["PHP_SELF"], "d.morphy", $param, "", "", $sortfield, $sortorder);
246  print_liste_field_titre("EMail", $_SERVER["PHP_SELF"], "d.email", $param, "", "", $sortfield, $sortorder);
247  print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "d.statut,d.datefin", $param, "", "", $sortfield, $sortorder);
248  print_liste_field_titre("EndSubscription", $_SERVER["PHP_SELF"], "d.datefin", $param, "", '', $sortfield, $sortorder, 'center ');
249  print "</tr>\n";
250 
251  $i = 0;
252  while ($i < $num && $i < $conf->liste_limit) {
253  $objp = $db->fetch_object($resql);
254 
255  $datefin = $db->jdate($objp->datefin);
256  $memberstatic->id = $objp->rowid;
257  $memberstatic->ref = $objp->rowid;
258  $memberstatic->lastname = $objp->lastname;
259  $memberstatic->firstname = $objp->firstname;
260  $memberstatic->statut = $objp->statut;
261  $memberstatic->datefin = $db->jdate($objp->datefin);
262 
263  $companyname = $objp->company;
264 
265  print '<tr class="oddeven">';
266 
267  // Ref
268  print "<td>";
269  print $memberstatic->getNomUrl(1);
270  print "</td>\n";
271 
272  // Lastname
273  print "<td><a href=\"card.php?rowid=$objp->rowid\">";
274  print ((!empty($objp->lastname) || !empty($objp->firstname)) ? dol_trunc($memberstatic->getFullName($langs)) : '');
275  print (((!empty($objp->lastname) || !empty($objp->firstname)) && !empty($companyname)) ? ' / ' : '');
276  print (!empty($companyname) ? dol_trunc($companyname, 32) : '');
277  print "</a></td>\n";
278 
279  // Login
280  print "<td>".$objp->login."</td>\n";
281 
282  // Type
283  $membertypestatic->id = $objp->type_id;
284  $membertypestatic->libelle = $objp->type;
285  $membertypestatic->label = $objp->type;
286 
287  print '<td class="nowrap">';
288  print $membertypestatic->getNomUrl(1, 32);
289  print '</td>';
290 
291  // Moral/Physique
292  print "<td>".$memberstatic->getmorphylib($objp->morphy)."</td>\n";
293 
294  // EMail
295  print "<td>".dol_print_email($objp->email, 0, 0, 1)."</td>\n";
296 
297  // Statut
298  print '<td class="nowrap">';
299  print $memberstatic->LibStatut($objp->statut, $objp->subscription, $datefin, 2);
300  print "</td>";
301 
302  // End of subscription date
303  if ($datefin) {
304  print '<td class="center nowrap">';
305  print dol_print_date($datefin, 'day');
306  if ($memberstatic->hasDelay()) {
307  print " ".img_warning($langs->trans("SubscriptionLate"));
308  }
309  print '</td>';
310  } else {
311  print '<td class="left nowrap">';
312  if (!empty($objp->subscription)) {
313  print $langs->trans("SubscriptionNotReceived");
314  if ($objp->statut > 0) {
315  print " ".img_warning();
316  }
317  } else {
318  print '&nbsp;';
319  }
320  print '</td>';
321  }
322 
323  print "</tr>\n";
324  $i++;
325  }
326  print "</table>\n";
327  }
328  }
329  }
330  } else {
331  // Contrat non trouve
332  print "ErrorRecordNotFound";
333  }
334 }
335 
336 // End of page
337 llxFooter();
338 $db->close();
Societe
Class to manage third parties objects (customers, suppliers, prospects...)
Definition: societe.class.php:48
AdherentType
Class to manage members type.
Definition: adherent_type.class.php:35
dol_trunc
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
Definition: functions.lib.php:3805
restrictedArea
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
Definition: security.lib.php:234
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
dol_buildpath
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
Definition: functions.lib.php:1062
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
FormOther
Classe permettant la generation de composants html autre Only common components are here.
Definition: html.formother.class.php:39
dol_banner_tab
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
Definition: functions.lib.php:2046
$help_url
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
Definition: agenda.php:116
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2514
FormCompany
Class to build HTML component for third parties management Only common components are here.
Definition: html.formcompany.class.php:40
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1603
Contact
Class to manage contact/addresses.
Definition: contact.class.php:40
print_barre_liste
print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
Definition: functions.lib.php:5257
Adherent
Class to manage members of a foundation.
Definition: adherent.class.php:46
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
societe_prepare_head
societe_prepare_head(Societe $object)
Return array of tabs to used on pages for third parties cards.
Definition: company.lib.php:42
User
Class to manage Dolibarr users.
Definition: user.class.php:44
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:386
print_liste_field_titre
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
Definition: functions.lib.php:5026
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->supplier_invoice->lire)) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59