dolibarr  7.0.0-beta
company.lib.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2006-2011 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
4  * Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
5  * Copyright (C) 2010-2012 Regis Houssin <regis.houssin@capnetworks.com>
6  * Copyright (C) 2013-2014 Florian Henry <florian.henry@open-concept.pro>
7  * Copyright (C) 2013-2014 Juanjo Menent <jmenent@2byte.es>
8  * Copyright (C) 2013 Christophe Battarel <contact@altairis.fr>
9  * Copyright (C) 2013 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
10  * Copyright (C) 2015 Frederic France <frederic.france@free.fr>
11  * Copyright (C) 2015 RaphaĆ«l Doursenaud <rdoursenaud@gpcsolutions.fr>
12  *
13  * This program is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 3 of the License, or
16  * (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program. If not, see <http://www.gnu.org/licenses/>.
25  * or see http://www.gnu.org/
26  */
27 
40 function societe_prepare_head(Societe $object)
41 {
42  global $db, $langs, $conf, $user;
43  $h = 0;
44  $head = array();
45 
46  $head[$h][0] = DOL_URL_ROOT.'/societe/card.php?socid='.$object->id;
47  $head[$h][1] = $langs->trans("Card");
48  $head[$h][2] = 'card';
49  $h++;
50 
51  if (empty($conf->global->MAIN_DISABLE_CONTACTS_TAB))
52  {
53  //$nbContact = count($object->liste_contact(-1,'internal')) + count($object->liste_contact(-1,'external'));
54  $nbContact = 0; // TODO
55 
56  $sql = "SELECT COUNT(p.rowid) as nb";
57  $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as p";
58  $sql .= " WHERE p.fk_soc = ".$object->id;
59  $resql = $db->query($sql);
60  if ($resql)
61  {
62  $obj = $db->fetch_object($resql);
63  if ($obj) $nbContact = $obj->nb;
64  }
65 
66  $head[$h][0] = DOL_URL_ROOT.'/societe/contact.php?socid='.$object->id;
67  $head[$h][1] = $langs->trans('ContactsAddresses');
68  if ($nbContact > 0) $head[$h][1].= ' <span class="badge">'.$nbContact.'</span>';
69  $head[$h][2] = 'contact';
70  $h++;
71  }
72 
73  if ($object->client==1 || $object->client==2 || $object->client==3)
74  {
75  $head[$h][0] = DOL_URL_ROOT.'/comm/card.php?socid='.$object->id;
76  $head[$h][1] = '';
77  if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && ($object->client==2 || $object->client==3)) $head[$h][1] .= $langs->trans("Prospect");
78  if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS) && $object->client==3) $head[$h][1] .= '/';
79  if (empty($conf->global->SOCIETE_DISABLE_CUSTOMERS) && ($object->client==1 || $object->client==3)) $head[$h][1] .= $langs->trans("Customer");
80  $head[$h][2] = 'customer';
81  $h++;
82 
83  if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES))
84  {
85  $langs->load("products");
86  // price
87  $head[$h][0] = DOL_URL_ROOT.'/societe/price.php?socid='.$object->id;
88  $head[$h][1] = $langs->trans("CustomerPrices");
89  $head[$h][2] = 'price';
90  $h++;
91  }
92  }
93  if (! empty($conf->fournisseur->enabled) && $object->fournisseur && ! empty($user->rights->fournisseur->lire))
94  {
95  $head[$h][0] = DOL_URL_ROOT.'/fourn/card.php?socid='.$object->id;
96  $head[$h][1] = $langs->trans("Supplier");
97  $head[$h][2] = 'supplier';
98  $h++;
99  }
100 
101  if (! empty($conf->global->MAIN_SUPPORT_SHARED_CONTACT_BETWEEN_THIRDPARTIES))
102  {
103  $head[$h][0] = DOL_URL_ROOT.'/societe/societecontact.php?socid='.$object->id;
104  $nbContact = count($object->liste_contact(-1,'internal')) + count($object->liste_contact(-1,'external'));
105  $head[$h][1] = $langs->trans("ContactsAddresses");
106  if ($nbContact > 0) $head[$h][1].= ' <span class="badge">'.$nbContact.'</span>';
107  $head[$h][2] = 'contact';
108  $h++;
109  }
110 
111  if (! empty($conf->projet->enabled) && (!empty($user->rights->projet->lire) ))
112  {
113  $head[$h][0] = DOL_URL_ROOT.'/societe/project.php?socid='.$object->id;
114  $head[$h][1] = $langs->trans("Projects");
115  $nbNote = 0;
116  $sql = "SELECT COUNT(n.rowid) as nb";
117  $sql.= " FROM ".MAIN_DB_PREFIX."projet as n";
118  $sql.= " WHERE fk_soc = ".$object->id;
119  $resql=$db->query($sql);
120  if ($resql)
121  {
122  $num = $db->num_rows($resql);
123  $i = 0;
124  while ($i < $num)
125  {
126  $obj = $db->fetch_object($resql);
127  $nbNote=$obj->nb;
128  $i++;
129  }
130  }
131  else {
132  dol_print_error($db);
133  }
134  if ($nbNote > 0) $head[$h][1].= ' <span class="badge">'.$nbNote.'</span>';
135  $head[$h][2] = 'project';
136  $h++;
137  }
138 
139  // Tab to link resources
140  if (! empty($conf->resource->enabled) && ! empty($conf->global->RESOURCE_ON_THIRDPARTIES))
141  {
142  $head[$h][0] = DOL_URL_ROOT.'/resource/element_resource.php?element=societe&element_id='.$object->id;
143  $head[$h][1] = $langs->trans("Resources");
144  $head[$h][2] = 'resources';
145  $h++;
146  }
147 
148  if (! empty($conf->global->ACCOUNTING_ENABLE_LETTERING))
149  {
150  // Tab to accountancy
151  if (! empty($conf->accounting->enabled) && $object->client>0)
152  {
153  $head[$h][0] = DOL_URL_ROOT.'/accountancy/bookkeeping/thirdparty_lettrage.php?socid='.$object->id;
154  $head[$h][1] = $langs->trans("TabAccountingCustomer");
155  $head[$h][2] = 'accounting';
156  $h++;
157  }
158 
159  // Tab to accountancy
160  if (! empty($conf->accounting->enabled) && $object->fournisseur>0)
161  {
162  $head[$h][0] = DOL_URL_ROOT.'/accountancy/bookkeeping/thirdparty_lettrage_supplier.php?socid='.$object->id;
163  $head[$h][1] = $langs->trans("TabAccountingSupplier");
164  $head[$h][2] = 'accounting_supplier';
165  $h++;
166  }
167  }
168 
169  // Related items
170  if (! empty($conf->commande->enabled) || ! empty($conf->propal->enabled) || ! empty($conf->facture->enabled) || ! empty($conf->fichinter->enabled) || ! empty($conf->fournisseur->enabled))
171  {
172  $head[$h][0] = DOL_URL_ROOT.'/societe/consumption.php?socid='.$object->id;
173  $head[$h][1] = $langs->trans("Referers");
174  $head[$h][2] = 'consumption';
175  $h++;
176  }
177 
178  // Bank accounrs
179  if (empty($conf->global->SOCIETE_DISABLE_BANKACCOUNT))
180  {
181  $langs->load("banks");
182 
183  $nbBankAccount=0;
184  $head[$h][0] = DOL_URL_ROOT .'/societe/rib.php?socid='.$object->id;
185  $head[$h][1] = $langs->trans("BankAccounts");
186  $sql = "SELECT COUNT(n.rowid) as nb";
187  $sql.= " FROM ".MAIN_DB_PREFIX."societe_rib as n";
188  $sql.= " WHERE fk_soc = ".$object->id;
189  $resql=$db->query($sql);
190  if ($resql)
191  {
192  $num = $db->num_rows($resql);
193  $i = 0;
194  while ($i < $num)
195  {
196  $obj = $db->fetch_object($resql);
197  $nbBankAccount=$obj->nb;
198  $i++;
199  }
200  }
201  else {
202  dol_print_error($db);
203  }
204  if ($nbBankAccount > 0) $head[$h][1].= ' <span class="badge">'.$nbBankAccount.'</span>';
205  $head[$h][2] = 'rib';
206  $h++;
207  }
208 
209  if (! empty($conf->website->enabled) && (!empty($user->rights->societe->lire) ))
210  {
211  $head[$h][0] = DOL_URL_ROOT.'/societe/website.php?id='.$object->id;
212  $head[$h][1] = $langs->trans("WebSiteAccounts");
213  $nbNote = 0;
214  $sql = "SELECT COUNT(n.rowid) as nb";
215  $sql.= " FROM ".MAIN_DB_PREFIX."website_account as n";
216  $sql.= " WHERE fk_soc = ".$object->id;
217  $resql=$db->query($sql);
218  if ($resql)
219  {
220  $num = $db->num_rows($resql);
221  $i = 0;
222  while ($i < $num)
223  {
224  $obj = $db->fetch_object($resql);
225  $nbNote=$obj->nb;
226  $i++;
227  }
228  }
229  else {
230  dol_print_error($db);
231  }
232  if ($nbNote > 0) $head[$h][1].= ' <span class="badge">'.$nbNote.'</span>';
233  $head[$h][2] = 'website';
234  $h++;
235  }
236 
237  // Show more tabs from modules
238  // Entries must be declared in modules descriptor with line
239  // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
240  // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
241  complete_head_from_modules($conf,$langs,$object,$head,$h,'thirdparty');
242 
243  if ($user->societe_id == 0)
244  {
245  // Notifications
246  if (! empty($conf->notification->enabled))
247  {
248  $nbNote = 0;
249  $sql = "SELECT COUNT(n.rowid) as nb";
250  $sql.= " FROM ".MAIN_DB_PREFIX."notify_def as n";
251  $sql.= " WHERE fk_soc = ".$object->id;
252  $resql=$db->query($sql);
253  if ($resql)
254  {
255  $num = $db->num_rows($resql);
256  $i = 0;
257  while ($i < $num)
258  {
259  $obj = $db->fetch_object($resql);
260  $nbNote=$obj->nb;
261  $i++;
262  }
263  }
264  else {
265  dol_print_error($db);
266  }
267 
268  $head[$h][0] = DOL_URL_ROOT.'/societe/notify/card.php?socid='.$object->id;
269  $head[$h][1] = $langs->trans("Notifications");
270  if ($nbNote > 0) $head[$h][1].= ' <span class="badge">'.$nbNote.'</span>';
271  $head[$h][2] = 'notify';
272  $h++;
273  }
274 
275  // Notes
276  $nbNote = 0;
277  if(!empty($object->note_private)) $nbNote++;
278  if(!empty($object->note_public)) $nbNote++;
279  $head[$h][0] = DOL_URL_ROOT.'/societe/note.php?id='.$object->id;
280  $head[$h][1] = $langs->trans("Notes");
281  if ($nbNote > 0) $head[$h][1].= ' <span class="badge">'.$nbNote.'</span>';
282  $head[$h][2] = 'note';
283  $h++;
284 
285  // Attached files
286  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
287  require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
288  $upload_dir = $conf->societe->multidir_output[$object->entity] . "/" . $object->id ;
289  $nbFiles = count(dol_dir_list($upload_dir,'files',0,'','(\.meta|_preview.*\.png)$'));
290  $nbLinks=Link::count($db, $object->element, $object->id);
291 
292  $head[$h][0] = DOL_URL_ROOT.'/societe/document.php?socid='.$object->id;
293  $head[$h][1] = $langs->trans("Documents");
294  if (($nbFiles+$nbLinks) > 0) $head[$h][1].= ' <span class="badge">'.($nbFiles+$nbLinks).'</span>';
295  $head[$h][2] = 'document';
296  $h++;
297  }
298 
299  $head[$h][0] = DOL_URL_ROOT.'/societe/agenda.php?socid='.$object->id;
300  $head[$h][1].= $langs->trans("Events");
301  if (! empty($conf->agenda->enabled) && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read) ))
302  {
303  $head[$h][1].= '/';
304  $head[$h][1].= $langs->trans("Agenda");
305  }
306  $head[$h][2] = 'agenda';
307  $h++;
308 
309  // Log
310  /*$head[$h][0] = DOL_URL_ROOT.'/societe/info.php?socid='.$object->id;
311  $head[$h][1] = $langs->trans("Info");
312  $head[$h][2] = 'info';
313  $h++;*/
314 
315  complete_head_from_modules($conf,$langs,$object,$head,$h,'thirdparty','remove');
316 
317  return $head;
318 }
319 
320 
327 function societe_prepare_head2($object)
328 {
329  global $langs, $conf, $user;
330  $h = 0;
331  $head = array();
332 
333  $head[$h][0] = DOL_URL_ROOT.'/societe/card.php?socid='.$object->id;
334  $head[$h][1] = $langs->trans("Card");
335  $head[$h][2] = 'company';
336  $h++;
337 
338  $head[$h][0] = 'commerciaux.php?socid='.$object->id;
339  $head[$h][1] = $langs->trans("SalesRepresentative");
340  $head[$h][2] = 'salesrepresentative';
341  $h++;
342 
343  return $head;
344 }
345 
346 
347 
354 {
355  global $langs, $conf, $user;
356 
357  $h = 0;
358  $head = array();
359 
360  $head[$h][0] = DOL_URL_ROOT.'/societe/admin/societe.php';
361  $head[$h][1] = $langs->trans("Miscellaneous");
362  $head[$h][2] = 'general';
363  $h++;
364 
365  // Show more tabs from modules
366  // Entries must be declared in modules descriptor with line
367  // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
368  // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
369  complete_head_from_modules($conf,$langs,null,$head,$h,'company_admin');
370 
371  $head[$h][0] = DOL_URL_ROOT.'/societe/admin/societe_extrafields.php';
372  $head[$h][1] = $langs->trans("ExtraFieldsThirdParties");
373  $head[$h][2] = 'attributes';
374  $h++;
375 
376  $head[$h][0] = DOL_URL_ROOT.'/societe/admin/contact_extrafields.php';
377  $head[$h][1] = $langs->trans("ExtraFieldsContacts");
378  $head[$h][2] = 'attributes_contacts';
379  $h++;
380 
381  complete_head_from_modules($conf,$langs,null,$head,$h,'company_admin','remove');
382 
383  return $head;
384 }
385 
386 
387 
403 function getCountry($searchkey, $withcode='', $dbtouse=0, $outputlangs='', $entconv=1, $searchlabel='')
404 {
405  global $db,$langs;
406 
407  $result='';
408 
409  // Check parameters
410  if (empty($searchkey) && empty($searchlabel))
411  {
412  if ($withcode === 'all') return array('id'=>'','code'=>'','label'=>'');
413  else return '';
414  }
415  if (! is_object($dbtouse)) $dbtouse=$db;
416  if (! is_object($outputlangs)) $outputlangs=$langs;
417 
418  $sql = "SELECT rowid, code, label FROM ".MAIN_DB_PREFIX."c_country";
419  if (is_numeric($searchkey)) $sql.= " WHERE rowid=".$searchkey;
420  elseif (! empty($searchkey)) $sql.= " WHERE code='".$db->escape($searchkey)."'";
421  else $sql.= " WHERE label='".$db->escape($searchlabel)."'";
422 
423  $resql=$dbtouse->query($sql);
424  if ($resql)
425  {
426  $obj = $dbtouse->fetch_object($resql);
427  if ($obj)
428  {
429  $label=((! empty($obj->label) && $obj->label!='-')?$obj->label:'');
430  if (is_object($outputlangs))
431  {
432  $outputlangs->load("dict");
433  if ($entconv) $label=($obj->code && ($outputlangs->trans("Country".$obj->code)!="Country".$obj->code))?$outputlangs->trans("Country".$obj->code):$label;
434  else $label=($obj->code && ($outputlangs->transnoentitiesnoconv("Country".$obj->code)!="Country".$obj->code))?$outputlangs->transnoentitiesnoconv("Country".$obj->code):$label;
435  }
436  if ($withcode == 1) $result=$label?"$obj->code - $label":"$obj->code";
437  else if ($withcode == 2) $result=$obj->code;
438  else if ($withcode == 3) $result=$obj->rowid;
439  else if ($withcode === 'all') $result=array('id'=>$obj->rowid,'code'=>$obj->code,'label'=>$label);
440  else $result=$label;
441  }
442  else
443  {
444  $result='NotDefined';
445  }
446  $dbtouse->free($resql);
447  return $result;
448  }
449  else dol_print_error($dbtouse,'');
450  return 'Error';
451 }
452 
464 function getState($id,$withcode='',$dbtouse=0)
465 {
466  global $db,$langs;
467 
468  if (! is_object($dbtouse)) $dbtouse=$db;
469 
470  $sql = "SELECT rowid, code_departement as code, nom as label FROM ".MAIN_DB_PREFIX."c_departements";
471  $sql.= " WHERE rowid=".$id;
472 
473  dol_syslog("Company.lib::getState", LOG_DEBUG);
474  $resql=$dbtouse->query($sql);
475  if ($resql)
476  {
477  $obj = $dbtouse->fetch_object($resql);
478  if ($obj)
479  {
480  $label=$obj->label;
481  if ($withcode == '1') return $label=$obj->code?"$obj->code":"$obj->code - $label";
482  else if ($withcode == '2') return $label=$obj->code;
483  else if ($withcode == 'all') return array('id'=>$obj->rowid,'code'=>$obj->code,'label'=>$label);
484  else return $label;
485  }
486  else
487  {
488  return $langs->transnoentitiesnoconv("NotDefined");
489  }
490  }
491  else dol_print_error($dbtouse,'');
492 }
493 
502 function currency_name($code_iso, $withcode='', $outputlangs=null)
503 {
504  global $langs,$db;
505 
506  if (empty($outputlangs)) $outputlangs=$langs;
507 
508  $outputlangs->load("dict");
509 
510  // If there is a translation, we can send immediatly the label
511  if ($outputlangs->trans("Currency".$code_iso)!="Currency".$code_iso)
512  {
513  return ($withcode?$code_iso.' - ':'').$outputlangs->trans("Currency".$code_iso);
514  }
515 
516  // If no translation, we read table to get label by default
517  $sql = "SELECT label FROM ".MAIN_DB_PREFIX."c_currencies";
518  $sql.= " WHERE code_iso='".$code_iso."'";
519 
520  $resql=$db->query($sql);
521  if ($resql)
522  {
523  $num = $db->num_rows($resql);
524 
525  if ($num)
526  {
527  $obj = $db->fetch_object($resql);
528  $label=($obj->label!='-'?$obj->label:'');
529  if ($withcode) return ($label==$code_iso)?"$code_iso":"$code_iso - $label";
530  else return $label;
531  }
532  else
533  {
534  return $code_iso;
535  }
536  }
537  return 'ErrorWhenReadingCurrencyLabel';
538 }
539 
546 function getFormeJuridiqueLabel($code)
547 {
548  global $db,$langs;
549 
550  if (! $code) return '';
551 
552  $sql = "SELECT libelle FROM ".MAIN_DB_PREFIX."c_forme_juridique";
553  $sql.= " WHERE code='$code'";
554 
555  dol_syslog("Company.lib::getFormeJuridiqueLabel", LOG_DEBUG);
556  $resql=$db->query($sql);
557  if ($resql)
558  {
559  $num = $db->num_rows($resql);
560 
561  if ($num)
562  {
563  $obj = $db->fetch_object($resql);
564  $label=($obj->libelle!='-' ? $obj->libelle : '');
565  return $label;
566  }
567  else
568  {
569  return $langs->trans("NotDefined");
570  }
571 
572  }
573 }
574 
582 function isInEEC($object)
583 {
584  if (empty($object->country_code)) return false;
585 
586  // List of all country codes that are in europe for european vat rules
587  // List found on http://ec.europa.eu/taxation_customs/common/faq/faq_1179_en.htm#9
588  $country_code_in_EEC=array(
589  'AT', // Austria
590  'BE', // Belgium
591  'BG', // Bulgaria
592  'CY', // Cyprus
593  'CZ', // Czech republic
594  'DE', // Germany
595  'DK', // Danemark
596  'EE', // Estonia
597  'ES', // Spain
598  'FI', // Finland
599  'FR', // France
600  'GB', // United Kingdom
601  'GR', // Greece
602  'HR', // Croatia
603  'NL', // Holland
604  'HU', // Hungary
605  'IE', // Ireland
606  'IM', // Isle of Man - Included in UK
607  'IT', // Italy
608  'LT', // Lithuania
609  'LU', // Luxembourg
610  'LV', // Latvia
611  'MC', // Monaco - Included in France
612  'MT', // Malta
613  //'NO', // Norway
614  'PL', // Poland
615  'PT', // Portugal
616  'RO', // Romania
617  'SE', // Sweden
618  'SK', // Slovakia
619  'SI', // Slovenia
620  'UK', // United Kingdom
621  //'CH', // Switzerland - No. Swizerland in not in EEC
622  );
623  //print "dd".$this->country_code;
624  return in_array($object->country_code, $country_code_in_EEC);
625 }
626 
627 
640 function show_projects($conf, $langs, $db, $object, $backtopage='', $nocreatelink=0, $morehtmlright='')
641 {
642  global $user;
643  global $bc;
644 
645  $i = -1 ;
646 
647  if (! empty($conf->projet->enabled) && $user->rights->projet->lire)
648  {
649  $langs->load("projects");
650 
651  $buttoncreate='';
652  if (! empty($conf->projet->enabled) && $user->rights->projet->creer && empty($nocreatelink))
653  {
654  //$buttoncreate='<a class="butAction" href="'.DOL_URL_ROOT.'/projet/card.php?socid='.$object->id.'&action=create&amp;backtopage='.urlencode($backtopage).'">'.$langs->trans("AddProject").'</a>';
655  $buttoncreate='<a class="addnewrecord" href="'.DOL_URL_ROOT.'/projet/card.php?socid='.$object->id.'&amp;action=create&amp;backtopage='.urlencode($backtopage).'">'.$langs->trans("AddProject");
656  if (empty($conf->dol_optimize_smallscreen)) $buttoncreate.=' '.img_picto($langs->trans("AddProject"),'filenew');
657  $buttoncreate.='</a>'."\n";
658  }
659 
660  print "\n";
661  print load_fiche_titre($langs->trans("ProjectsDedicatedToThisThirdParty"), $buttoncreate.$morehtmlright, '');
662  print '<div class="div-table-responsive">';
663  print "\n".'<table class="noborder" width=100%>';
664 
665  $sql = "SELECT p.rowid as id, p.title, p.ref, p.public, p.dateo as do, p.datee as de, p.fk_statut as status, p.fk_opp_status, p.opp_amount, p.opp_percent, p.tms as date_update, p.budget_amount";
666  $sql .= ", cls.code as opp_status_code";
667  $sql .= " FROM ".MAIN_DB_PREFIX."projet as p";
668  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_lead_status as cls on p.fk_opp_status = cls.rowid";
669  $sql .= " WHERE p.fk_soc = ".$object->id;
670  $sql .= " ORDER BY p.dateo DESC";
671 
672  $result=$db->query($sql);
673  if ($result)
674  {
675  $num = $db->num_rows($result);
676 
677  print '<tr class="liste_titre">';
678  print '<td>'.$langs->trans("Ref").'</td>';
679  print '<td>'.$langs->trans("Name").'</td>';
680  print '<td class="center">'.$langs->trans("DateStart").'</td>';
681  print '<td class="center">'.$langs->trans("DateEnd").'</td>';
682  print '<td class="right">'.$langs->trans("OpportunityAmountShort").'</td>';
683  print '<td class="center">'.$langs->trans("OpportunityStatusShort").'</td>';
684  print '<td class="right">'.$langs->trans("OpportunityProbabilityShort").'</td>';
685  print '<td class="right">'.$langs->trans("Status").'</td>';
686  print '</tr>';
687 
688  if ($num > 0)
689  {
690  require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
691 
692  $projecttmp = new Project($db);
693 
694  $i=0;
695 
696  while ($i < $num)
697  {
698  $obj = $db->fetch_object($result);
699  $projecttmp->fetch($obj->id);
700 
701  // To verify role of users
702  $userAccess = $projecttmp->restrictedProjectArea($user);
703 
704  if ($user->rights->projet->lire && $userAccess > 0)
705  {
706  print '<tr class="oddeven">';
707 
708  // Ref
709  print '<td><a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$projecttmp->id.'">'.img_object($langs->trans("ShowProject"),($obj->public?'projectpub':'project'))." ".$obj->ref.'</a></td>';
710  // Label
711  print '<td>'.$obj->title.'</td>';
712  // Date start
713  print '<td class="center">'.dol_print_date($db->jdate($obj->do),"day").'</td>';
714  // Date end
715  print '<td class="center">'.dol_print_date($db->jdate($obj->de),"day").'</td>';
716  // Opp amount
717  print '<td class="right">';
718  if ($obj->opp_status_code)
719  {
720  print price($obj->opp_amount, 1, '', 1, -1, -1, '');
721  }
722  print '</td>';
723  // Opp status
724  print '<td align="center">';
725  if ($obj->opp_status_code) print $langs->trans("OppStatusShort".$obj->opp_status_code);
726  print '</td>';
727  // Opp percent
728  print '<td align="right">';
729  if ($obj->opp_percent) print price($obj->opp_percent, 1, '', 1, 0).'%';
730  print '</td>';
731  // Status
732  print '<td align="right">'.$projecttmp->getLibStatut(5).'</td>';
733 
734  print '</tr>';
735  }
736  $i++;
737  }
738  }
739  else
740  {
741  print '<tr class="oddeven"><td colspan="5" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
742  }
743  $db->free($result);
744  }
745  else
746  {
747  dol_print_error($db);
748  }
749  print "</table>";
750  print '</div>';
751 
752  print "<br>\n";
753  }
754 
755  return $i;
756 }
757 
758 
769 function show_contacts($conf,$langs,$db,$object,$backtopage='')
770 {
771  global $user,$conf;
772  global $bc;
773 
774  $form= new Form($db);
775 
776  $sortfield = GETPOST("sortfield",'alpha');
777  $sortorder = GETPOST("sortorder",'alpha');
778  $page = GETPOST('page','int');
779  $search_status = GETPOST("search_status",'int');
780  if ($search_status=='') $search_status=1; // always display activ customer first
781  $search_name = GETPOST("search_name",'alpha');
782  $search_addressphone = GETPOST("search_addressphone",'alpha');
783 
784  if (! $sortorder) $sortorder="ASC";
785  if (! $sortfield) $sortfield="p.lastname";
786 
787  if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') ||GETPOST('button_removefilter','alpha')) // All tests are required to be compatible with all browsers
788  {
789  $search_status = '';
790  $search_name = '';
791  $search_addressphone = '';
792  $search_array_options=array();
793  }
794 
795  $i=-1;
796 
797  $contactstatic = new Contact($db);
798 
799  if (! empty($conf->clicktodial->enabled))
800  {
801  $user->fetch_clicktodial(); // lecture des infos de clicktodial
802  }
803 
804  $buttoncreate='';
805  if ($user->rights->societe->contact->creer)
806  {
807  $addcontact = (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("AddContact") : $langs->trans("AddContactAddress"));
808  $buttoncreate='<a class="addnewrecord" href="'.DOL_URL_ROOT.'/contact/card.php?socid='.$object->id.'&amp;action=create&amp;backtopage='.urlencode($backtopage).'">'.$addcontact;
809  $buttoncreate.='</a>'."\n";
810  }
811 
812  print "\n";
813 
814  $title = (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("ContactsForCompany") : $langs->trans("ContactsAddressesForCompany"));
815  print load_fiche_titre($title, $buttoncreate,'');
816 
817  print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'" name="formfilter">';
818  print '<input type="hidden" name="socid" value="'.$object->id.'">';
819  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
820  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
821  print '<input type="hidden" name="page" value="'.$page.'">';
822 
823 
824  print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
825  print "\n".'<table class="noborder" width="100%">'."\n";
826 
827  $param="socid=".$object->id;
828  if ($search_status != '') $param.='&amp;search_status='.$search_status;
829  if ($search_name != '') $param.='&amp;search_name='.urlencode($search_name);
830 
831  $sql = "SELECT p.rowid, p.lastname, p.firstname, p.fk_pays as country_id, p.civility, p.poste, p.phone as phone_pro, p.phone_mobile, p.phone_perso, p.fax, p.email, p.skype, p.statut, p.photo,";
832  $sql .= " p.civility as civility_id, p.address, p.zip, p.town";
833  $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as p";
834  $sql .= " WHERE p.fk_soc = ".$object->id;
835  if ($search_status!='' && $search_status != '-1') $sql .= " AND p.statut = ".$db->escape($search_status);
836  if ($search_name) $sql .= " AND (p.lastname LIKE '%".$db->escape($search_name)."%' OR p.firstname LIKE '%".$db->escape($search_name)."%')";
837  $sql.= " ORDER BY $sortfield $sortorder";
838 
839  dol_syslog('core/lib/company.lib.php :: show_contacts', LOG_DEBUG);
840  $result = $db->query($sql);
841  if (! $result) dol_print_error($db);
842 
843  $num = $db->num_rows($result);
844 
845  $colspan=9;
846 
847  print '<tr class="liste_titre">';
848 
849  // Photo - Name
850  print '<td class="liste_titre">';
851  print '<input type="text" class="flat minwidth75" name="search_name" value="'.dol_escape_htmltag($search_name).'">';
852  print '</td>';
853 
854  // Position
855  print '<td class="liste_titre">';
856  print '</td>';
857 
858  // Address - Phone - Email
859  print '<td class="liste_titre"></td>';
860 
861  // Status
862  print '<td class="liste_titre maxwidthonsmartphone" align="center">';
863  print $form->selectarray('search_status', array('-1'=>'','0'=>$contactstatic->LibStatut(0,1),'1'=>$contactstatic->LibStatut(1,1)),$search_status);
864  print '</td>';
865 
866  // Add to agenda
867  if (! empty($conf->agenda->enabled) && $user->rights->agenda->myactions->create)
868  {
869  $colspan++;
870  print '<td class="liste_titre"></td>';
871  }
872 
873  // Action
874  print '<td class="liste_titre" align="right">';
875  $searchpicto=$form->showFilterButtons();
876  print $searchpicto;
877  print '</td>';
878 
879  print "</tr>";
880 
881  $titlefieldaddress=$langs->trans("Address").' / '.$langs->trans("Phone").' / '.$langs->trans("Email");
882  if (! empty($conf->dol_optimize_smallscreen)) $titlefieldaddress=$langs->trans("Address");
883 
884  print '<tr class="liste_titre">';
885  print_liste_field_titre("Name",$_SERVER["PHP_SELF"],"p.lastname","",$param,'',$sortfield,$sortorder);
886  print_liste_field_titre("Poste",$_SERVER["PHP_SELF"],"p.poste","",$param,'',$sortfield,$sortorder);
887  print_liste_field_titre($titlefieldaddress,$_SERVER["PHP_SELF"],"","",$param,'',$sortfield,$sortorder);
888  print_liste_field_titre("Status",$_SERVER["PHP_SELF"],"p.statut","",$param,'align="center"',$sortfield,$sortorder);
889  // Add to agenda
890  if (! empty($conf->agenda->enabled) && ! empty($user->rights->agenda->myactions->create)) print_liste_field_titre('');
891  // Edit
893  print "</tr>\n";
894 
895  if ($num || (GETPOST('button_search') || GETPOST('button_search.x') || GETPOST('button_search_x')))
896  {
897  $i=0;
898 
899  while ($i < $num)
900  {
901  $obj = $db->fetch_object($result);
902 
903  $contactstatic->id = $obj->rowid;
904  $contactstatic->ref = $obj->ref;
905  $contactstatic->statut = $obj->statut;
906  $contactstatic->lastname = $obj->lastname;
907  $contactstatic->firstname = $obj->firstname;
908  $contactstatic->civility_id = $obj->civility_id;
909  $contactstatic->civility_code = $obj->civility_id;
910  $contactstatic->poste = $obj->poste;
911  $contactstatic->address = $obj->address;
912  $contactstatic->zip = $obj->zip;
913  $contactstatic->town = $obj->town;
914  $contactstatic->phone_pro = $obj->phone_pro;
915  $contactstatic->phone_mobile = $obj->phone_mobile;
916  $contactstatic->phone_perso = $obj->phone_perso;
917  $contactstatic->email = $obj->email;
918  $contactstatic->web = $obj->web;
919  $contactstatic->skype = $obj->skype;
920  $contactstatic->photo = $obj->photo;
921 
922  $country_code = getCountry($obj->country_id, 2);
923  $contactstatic->country_code = $country_code;
924 
925  $contactstatic->setGenderFromCivility();
926 
927  print '<tr class="oddeven">';
928 
929  // Photo - Name
930  print '<td>';
931  print $form->showphoto('contact',$contactstatic,0,0,0,'photorefnoborder valignmiddle marginrightonly','small',1,0,1);
932  print $contactstatic->getNomUrl(0,'',0,'&backtopage='.urlencode($backtopage));
933  print '</td>';
934 
935  // Job position
936  print '<td>';
937  if ($obj->poste) print $obj->poste;
938  print '</td>';
939 
940  // Address - Phone - Email
941  print '<td>';
942  print $contactstatic->getBannerAddress('contact', $object);
943  print '</td>';
944 
945  // Status
946  print '<td align="center">'.$contactstatic->getLibStatut(5).'</td>';
947 
948  // Add to agenda
949  if (! empty($conf->agenda->enabled) && $user->rights->agenda->myactions->create)
950  {
951  print '<td align="center">';
952  print '<a href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create&actioncode=&contactid='.$obj->rowid.'&socid='.$object->id.'&backtopage='.urlencode($backtopage).'">';
953  print img_object($langs->trans("Event"),"action");
954  print '</a></td>';
955  }
956 
957  // Edit
958  if ($user->rights->societe->contact->creer)
959  {
960  print '<td align="right">';
961  print '<a href="'.DOL_URL_ROOT.'/contact/card.php?action=edit&amp;id='.$obj->rowid.'&amp;backtopage='.urlencode($backtopage).'">';
962  print img_edit();
963  print '</a></td>';
964  }
965  else print '<td>&nbsp;</td>';
966 
967  print "</tr>\n";
968  $i++;
969  }
970  }
971  else
972  {
973  print '<tr class="oddeven">';
974  print '<td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("None").'</td>';
975  print "</tr>\n";
976  }
977  print "\n</table>\n";
978  print '</div>';
979 
980  print '</form>'."\n";
981 
982  return $i;
983 }
984 
995 function show_addresses($conf,$langs,$db,$object,$backtopage='')
996 {
997  global $user;
998  global $bc;
999 
1000  require_once DOL_DOCUMENT_ROOT.'/societe/class/address.class.php';
1001 
1002  $addressstatic = new Address($db);
1003  $num = $addressstatic->fetch_lines($object->id);
1004 
1005  $buttoncreate='';
1006  if ($user->rights->societe->creer)
1007  {
1008  $buttoncreate='<a class="addnewrecord" href="'.DOL_URL_ROOT.'/comm/address.php?socid='.$object->id.'&amp;action=create&amp;backtopage='.urlencode($backtopage).'">'.$langs->trans("AddAddress").' '.img_picto($langs->trans("AddAddress"),'filenew').'</a>'."\n";
1009  }
1010 
1011  print "\n";
1012  print load_fiche_titre($langs->trans("AddressesForCompany"),$buttoncreate,'');
1013 
1014  print "\n".'<table class="noborder" width="100%">'."\n";
1015 
1016  print '<tr class="liste_titre"><td>'.$langs->trans("Label").'</td>';
1017  print '<td>'.$langs->trans("CompanyName").'</td>';
1018  print '<td>'.$langs->trans("Town").'</td>';
1019  print '<td>'.$langs->trans("Country").'</td>';
1020  print '<td>'.$langs->trans("Phone").'</td>';
1021  print '<td>'.$langs->trans("Fax").'</td>';
1022  print "<td>&nbsp;</td>";
1023  print "</tr>";
1024 
1025  if ($num > 0)
1026  {
1027  foreach ($addressstatic->lines as $address)
1028  {
1029  print '<tr class="oddeven">';
1030 
1031  print '<td>';
1032  $addressstatic->id = $address->id;
1033  $addressstatic->label = $address->label;
1034  print $addressstatic->getNomUrl(1);
1035  print '</td>';
1036 
1037  print '<td>'.$address->name.'</td>';
1038 
1039  print '<td>'.$address->town.'</td>';
1040 
1041  $img=picto_from_langcode($address->country_code);
1042  print '<td>'.($img?$img.' ':'').$address->country.'</td>';
1043 
1044  // Lien click to dial
1045  print '<td>';
1046  print dol_print_phone($address->phone,$address->country_code,$address->id,$object->id,'AC_TEL');
1047  print '</td>';
1048  print '<td>';
1049  print dol_print_phone($address->fax,$address->country_code,$address->id,$object->id,'AC_FAX');
1050  print '</td>';
1051 
1052  if ($user->rights->societe->creer)
1053  {
1054  print '<td align="right">';
1055  print '<a href="'.DOL_URL_ROOT.'/comm/address.php?action=edit&amp;id='.$address->id.'&amp;socid='.$object->id.'&amp;backtopage='.urlencode($backtopage).'">';
1056  print img_edit();
1057  print '</a></td>';
1058  }
1059 
1060  print "</tr>\n";
1061  }
1062  }
1063  else
1064  {
1065  //print '<tr class="oddeven">';
1066  //print '<td>'.$langs->trans("NoAddressYetDefined").'</td>';
1067  //print "</tr>\n";
1068  }
1069  print "\n</table>\n";
1070 
1071  print "<br>\n";
1072 
1073  return $num;
1074 }
1075 
1088 function show_actions_todo($conf,$langs,$db,$filterobj,$objcon='',$noprint=0,$actioncode='')
1089 {
1090  global $bc,$user,$conf;
1091 
1092  $out = show_actions_done($conf,$langs,$db,$filterobj,$objcon,1,$actioncode, 'todo');
1093 
1094  if ($noprint) return $out;
1095  else print $out;
1096 }
1097 
1115 function show_actions_done($conf, $langs, $db, $filterobj, $objcon='', $noprint=0, $actioncode='', $donetodo='done', $filters=array(), $sortfield='a.datep,a.id', $sortorder='DESC')
1116 {
1117  global $bc,$user,$conf;
1118  global $form;
1119 
1120  global $param;
1121 
1122  // Check parameters
1123  if (! is_object($filterobj) && ! is_object($objcon)) dol_print_error('','BadParameter');
1124 
1125  $out='';
1126  $histo=array();
1127  $numaction = 0 ;
1128  $now=dol_now('tzuser');
1129 
1130  if (! empty($conf->agenda->enabled))
1131  {
1132  // Recherche histo sur actioncomm
1133  $sql = "SELECT a.id, a.label,";
1134  $sql.= " a.datep as dp,";
1135  $sql.= " a.datep2 as dp2,";
1136  $sql.= " a.note, a.percent,";
1137  $sql.= " a.fk_element, a.elementtype,";
1138  $sql.= " a.fk_user_author, a.fk_contact,";
1139  $sql.= " c.code as acode, c.libelle as alabel, c.picto as apicto,";
1140  $sql.= " u.rowid as user_id, u.login as user_login, u.photo as user_photo, u.firstname as user_firstname, u.lastname as user_lastname";
1141  if (is_object($filterobj) && get_class($filterobj) == 'Societe') $sql.= ", sp.lastname, sp.firstname";
1142  if (is_object($filterobj) && get_class($filterobj) == 'Adherent') $sql.= ", m.lastname, m.firstname";
1143  if (is_object($filterobj) && get_class($filterobj) == 'CommandeFournisseur') $sql.= ", o.ref";
1144  if (is_object($filterobj) && get_class($filterobj) == 'Product') $sql.= ", o.ref";
1145  $sql.= " FROM ".MAIN_DB_PREFIX."user as u, ".MAIN_DB_PREFIX."actioncomm as a";
1146  $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_actioncomm as c ON a.fk_action = c.id";
1147  if (is_object($filterobj) && get_class($filterobj) == 'Societe') $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople as sp ON a.fk_contact = sp.rowid";
1148  if (is_object($filterobj) && get_class($filterobj) == 'Adherent') $sql.= ", ".MAIN_DB_PREFIX."adherent as m";
1149  if (is_object($filterobj) && get_class($filterobj) == 'CommandeFournisseur') $sql.= ", ".MAIN_DB_PREFIX."commande_fournisseur as o";
1150  if (is_object($filterobj) && get_class($filterobj) == 'Product') $sql.= ", ".MAIN_DB_PREFIX."product as o";
1151  $sql.= " WHERE u.rowid = a.fk_user_action";
1152  $sql.= " AND a.entity IN (".getEntity('agenda').")";
1153  if (is_object($filterobj) && get_class($filterobj) == 'Societe' && $filterobj->id) $sql.= " AND a.fk_soc = ".$filterobj->id;
1154  if (is_object($filterobj) && get_class($filterobj) == 'Project' && $filterobj->id) $sql.= " AND a.fk_project = ".$filterobj->id;
1155  if (is_object($filterobj) && get_class($filterobj) == 'Adherent')
1156  {
1157  $sql.= " AND a.fk_element = m.rowid AND a.elementtype = 'member'";
1158  if ($filterobj->id) $sql.= " AND a.fk_element = ".$filterobj->id;
1159  }
1160  if (is_object($filterobj) && get_class($filterobj) == 'CommandeFournisseur')
1161  {
1162  $sql.= " AND a.fk_element = o.rowid AND a.elementtype = 'order_supplier'";
1163  if ($filterobj->id) $sql.= " AND a.fk_element = ".$filterobj->id;
1164  }
1165  if (is_object($filterobj) && get_class($filterobj) == 'Product')
1166  {
1167  $sql.= " AND a.fk_element = o.rowid AND a.elementtype = 'product'";
1168  if ($filterobj->id) $sql.= " AND a.fk_element = ".$filterobj->id;
1169  }
1170  if (is_object($objcon) && $objcon->id) $sql.= " AND a.fk_contact = ".$objcon->id;
1171  // Condition on actioncode
1172  if (! empty($actioncode))
1173  {
1174  if (empty($conf->global->AGENDA_USE_EVENT_TYPE))
1175  {
1176  if ($actioncode == 'AC_NON_AUTO') $sql.= " AND c.type != 'systemauto'";
1177  elseif ($actioncode == 'AC_ALL_AUTO') $sql.= " AND c.type = 'systemauto'";
1178  else
1179  {
1180  if ($actioncode == 'AC_OTH') $sql.= " AND c.type != 'systemauto'";
1181  if ($actioncode == 'AC_OTH_AUTO') $sql.= " AND c.type = 'systemauto'";
1182  }
1183  }
1184  else
1185  {
1186  if ($actioncode == 'AC_NON_AUTO') $sql.= " AND c.type != 'systemauto'";
1187  elseif ($actioncode == 'AC_ALL_AUTO') $sql.= " AND c.type = 'systemauto'";
1188  else $sql.= " AND c.code = '".$db->escape($actioncode)."'";
1189  }
1190  }
1191  if ($donetodo == 'todo') $sql.= " AND ((a.percent >= 0 AND a.percent < 100) OR (a.percent = -1 AND a.datep > '".$db->idate($now)."'))";
1192  if ($donetodo == 'done') $sql.= " AND (a.percent = 100 OR (a.percent = -1 AND a.datep <= '".$db->idate($now)."'))";
1193  if (is_array($filters) && $filters['search_agenda_label']) $sql.= natural_search('a.label', $filters['search_agenda_label']);
1194  $sql.= $db->order($sortfield, $sortorder);
1195 
1196  dol_syslog("company.lib::show_actions_done", LOG_DEBUG);
1197  $resql=$db->query($sql);
1198  if ($resql)
1199  {
1200  $i = 0 ;
1201  $num = $db->num_rows($resql);
1202 
1203  while ($i < $num)
1204  {
1205  $obj = $db->fetch_object($resql);
1206 
1207  //if ($donetodo == 'todo') $sql.= " AND ((a.percent >= 0 AND a.percent < 100) OR (a.percent = -1 AND a.datep > '".$db->idate($now)."'))";
1208  //if ($donetodo == 'done') $sql.= " AND (a.percent = 100 OR (a.percent = -1 AND a.datep <= '".$db->idate($now)."'))";
1209  $tododone='';
1210  if (($obj->percent >= 0 and $obj->percent < 100) || ($obj->percent == -1 && $obj->datep > $now)) $tododone='todo';
1211 
1212  $histo[$numaction]=array(
1213  'type'=>'action',
1214  'tododone'=>$tododone,
1215  'id'=>$obj->id,
1216  'datestart'=>$db->jdate($obj->dp),
1217  'dateend'=>$db->jdate($obj->dp2),
1218  'note'=>$obj->label,
1219  'percent'=>$obj->percent,
1220 
1221  'userid'=>$obj->user_id,
1222  'login'=>$obj->user_login,
1223  'userfirstname'=>$obj->user_firstname,
1224  'userlastname'=>$obj->user_lastname,
1225  'userphoto'=>$obj->user_photo,
1226 
1227  'contact_id'=>$obj->fk_contact,
1228  'lastname'=>$obj->lastname,
1229  'firstname'=>$obj->firstname,
1230  'fk_element'=>$obj->fk_element,
1231  'elementtype'=>$obj->elementtype,
1232  // Type of event
1233  'acode'=>$obj->acode,
1234  'alabel'=>$obj->alabel,
1235  'libelle'=>$obj->alabel, // deprecated
1236  'apicto'=>$obj->apicto
1237  );
1238 
1239  $numaction++;
1240  $i++;
1241  }
1242  }
1243  else
1244  {
1245  dol_print_error($db);
1246  }
1247  }
1248 
1249  // Add also event from emailings. TODO This should be replaced by an automatic event ? May be it's too much for very large emailing.
1250  if (! empty($conf->mailing->enabled) && ! empty($objcon->email))
1251  {
1252  $langs->load("mails");
1253 
1254  $sql = "SELECT m.rowid as id, mc.date_envoi as da, m.titre as note, '100' as percentage,";
1255  $sql.= " 'AC_EMAILING' as acode,";
1256  $sql.= " u.rowid as user_id, u.login as user_login, u.photo as user_photo, u.firstname as user_firstname, u.lastname as user_lastname"; // User that valid action
1257  $sql.= " FROM ".MAIN_DB_PREFIX."mailing as m, ".MAIN_DB_PREFIX."mailing_cibles as mc, ".MAIN_DB_PREFIX."user as u";
1258  $sql.= " WHERE mc.email = '".$db->escape($objcon->email)."'"; // Search is done on email.
1259  $sql.= " AND mc.statut = 1";
1260  $sql.= " AND u.rowid = m.fk_user_valid";
1261  $sql.= " AND mc.fk_mailing=m.rowid";
1262  $sql.= " ORDER BY mc.date_envoi DESC, m.rowid DESC";
1263 
1264  dol_syslog("company.lib::show_actions_done", LOG_DEBUG);
1265  $resql=$db->query($sql);
1266  if ($resql)
1267  {
1268  $i = 0 ;
1269  $num = $db->num_rows($resql);
1270 
1271  while ($i < $num)
1272  {
1273  $obj = $db->fetch_object($resql);
1274  $histo[$numaction]=array(
1275  'type'=>'mailing',
1276  'tododone'=>'done',
1277  'id'=>$obj->id,
1278  'datestart'=>$db->jdate($obj->da),
1279  'dateend'=>$db->jdate($obj->da),
1280  'note'=>$obj->note,
1281  'percent'=>$obj->percentage,
1282  'acode'=>$obj->acode,
1283 
1284  'userid'=>$obj->user_id,
1285  'login'=>$obj->user_login,
1286  'userfirstname'=>$obj->user_firstname,
1287  'userlastname'=>$obj->user_lastname,
1288  'userphoto'=>$obj->user_photo
1289  );
1290  $numaction++;
1291  $i++;
1292  }
1293  $db->free($resql);
1294  }
1295  else
1296  {
1297  dol_print_error($db);
1298  }
1299  }
1300 
1301 
1302  if (! empty($conf->agenda->enabled) || (! empty($conf->mailing->enabled) && ! empty($objcon->email)))
1303  {
1304  $delay_warning=$conf->global->MAIN_DELAY_ACTIONS_TODO*24*60*60;
1305 
1306  require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
1307  require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
1308  require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
1309  require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
1310  require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
1311  require_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
1312 
1313  $formactions=new FormActions($db);
1314 
1315  $actionstatic=new ActionComm($db);
1316  $userstatic=new User($db);
1317  $contactstatic = new Contact($db);
1318 
1319  // TODO mutualize/uniformize
1320  $propalstatic=new Propal($db);
1321  $orderstatic=new Commande($db);
1322  $supplierorderstatic=new CommandeFournisseur($db);
1323  $facturestatic=new Facture($db);
1324 
1325  $out.='<form name="listactionsfilter" class="listactionsfilter" action="' . $_SERVER["PHP_SELF"] . '" method="POST">';
1326  if ($objcon && get_class($objcon) == 'Contact' && $filterobj && get_class($filterobj) == 'Societe')
1327  {
1328  $out.='<input type="hidden" name="id" value="'.$objcon->id.'" />';
1329  }
1330  else
1331  {
1332  $out.='<input type="hidden" name="id" value="'.$filterobj->id.'" />';
1333  }
1334  if ($filterobj && get_class($filterobj) == 'Societe') $out.='<input type="hidden" name="socid" value="'.$filterobj->id.'" />';
1335 
1336  $out.="\n";
1337 
1338  $out.='<div class="div-table-responsive-no-min">';
1339  $out.='<table class="noborder" width="100%">';
1340 
1341  $out.='<tr class="liste_titre">';
1342  if ($donetodo)
1343  {
1344  $out.='<td class="liste_titre"></td>';
1345  }
1346  $out.='<td class="liste_titre"></td>';
1347  $out.='<td class="liste_titre"></td>';
1348  $out.='<td class="liste_titre">';
1349  $out.=$formactions->select_type_actions($actioncode, "actioncode", '', empty($conf->global->AGENDA_USE_EVENT_TYPE)?1:-1, 0, 0, 1);
1350  $out.='</td>';
1351  $out.='<td class="liste_titre maxwidth100onsmartphone"><input type="text" class="maxwidth100onsmartphone" name="search_agenda_label" value="'.$filters['search_agenda_label'].'"></td>';
1352  $out.='<td class="liste_titre"></td>';
1353  $out.='<td class="liste_titre"></td>';
1354  $out.='<td class="liste_titre"></td>';
1355  $out.='<td class="liste_titre"></td>';
1356  // Action column
1357  $out.='<td class="liste_titre" align="middle">';
1358  $searchpicto=$form->showFilterAndCheckAddButtons($massactionbutton?1:0, 'checkforselect', 1);
1359  $out.=$searchpicto;
1360  $out.='</td>';
1361  $out.='</tr>';
1362 
1363  $out.='<tr class="liste_titre">';
1364  if ($donetodo)
1365  {
1366  $tmp='';
1367  if (get_class($filterobj) == 'Societe') $tmp.='<a href="'.DOL_URL_ROOT.'/comm/action/list.php?socid='.$filterobj->id.'&amp;status=done">';
1368  $tmp.=($donetodo != 'done' ? $langs->trans("ActionsToDoShort") : '');
1369  $tmp.=($donetodo != 'done' && $donetodo != 'todo' ? ' / ' : '');
1370  $tmp.=($donetodo != 'todo' ? $langs->trans("ActionsDoneShort") : '');
1371  //$out.=$langs->trans("ActionsToDoShort").' / '.$langs->trans("ActionsDoneShort");
1372  if (get_class($filterobj) == 'Societe') $tmp.='</a>';
1373  $out.=getTitleFieldOfList($tmp);
1374  }
1375  $out.=getTitleFieldOfList($langs->trans("Ref"), 0, $_SERVER["PHP_SELF"], 'a.id', '', $param, '', $sortfield, $sortorder);
1376  $out.=getTitleFieldOfList($langs->trans("Owner"));
1377  $out.=getTitleFieldOfList($langs->trans("Type"));
1378  $out.=getTitleFieldOfList($langs->trans("Label"), 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder);
1379  $out.=getTitleFieldOfList($langs->trans("Date"), 0, $_SERVER["PHP_SELF"], 'a.datep,a.id', '', $param, 'align="center"', $sortfield, $sortorder);
1380  $out.=getTitleFieldOfList('');
1381  $out.=getTitleFieldOfList('');
1382  $out.=getTitleFieldOfList($langs->trans("Status"), 0, $_SERVER["PHP_SELF"], 'a.percent', '', $param, 'align="center"', $sortfield, $sortorder);
1383  $out.=getTitleFieldOfList('', 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'maxwidthsearch ');
1384  $out.='</tr>';
1385 
1386  foreach ($histo as $key=>$value)
1387  {
1388 
1389  $actionstatic->fetch($histo[$key]['id']); // TODO Do we need this, we already have a lot of data of line into $histo
1390 
1391  $out.='<tr class="oddeven">';
1392 
1393  // Done or todo
1394  if ($donetodo)
1395  {
1396  $out.='<td class="nowrap">';
1397  $out.='</td>';
1398  }
1399 
1400  // Ref
1401  $out.='<td class="nowrap">';
1402  $out.=$actionstatic->getNomUrl(1, -1);
1403  $out.='</td>';
1404 
1405  // Author of event
1406  $out.='<td>';
1407  //$userstatic->id=$histo[$key]['userid'];
1408  //$userstatic->login=$histo[$key]['login'];
1409  //$out.=$userstatic->getLoginUrl(1);
1410  $userstatic->fetch($histo[$key]['userid']);
1411  $out.=$userstatic->getNomUrl(-1);
1412  $out.='</td>';
1413 
1414  // Type
1415  $out.='<td>';
1416  if (! empty($conf->global->AGENDA_USE_EVENT_TYPE))
1417  {
1418  if ($histo[$key]['apicto']) $out.=img_picto('', $histo[$key]['apicto']);
1419  else {
1420  if ($histo[$key]['acode'] == 'AC_TEL') $out.=img_picto('', 'object_phoning').' ';
1421  if ($histo[$key]['acode'] == 'AC_FAX') $out.=img_picto('', 'object_phoning_fax').' ';
1422  if ($histo[$key]['acode'] == 'AC_EMAIL') $out.=img_picto('', 'object_email').' ';
1423  }
1424  $out.=$actionstatic->type;
1425  }
1426  else {
1427  $typelabel = $actionstatic->type;
1428  if ($histo[$key]['acode'] != 'AC_OTH_AUTO') $typelabel = $langs->trans("ActionAC_MANUAL");
1429  $out.=$typelabel;
1430  }
1431  $out.='</td>';
1432 
1433  // Title
1434  $out.='<td>';
1435  if (isset($histo[$key]['type']) && $histo[$key]['type']=='action')
1436  {
1437  $actionstatic->type_code=$histo[$key]['acode'];
1438  $transcode=$langs->trans("Action".$histo[$key]['acode']);
1439  $libelle=($transcode!="Action".$histo[$key]['acode']?$transcode:$histo[$key]['alabel']);
1440  //$actionstatic->libelle=$libelle;
1441  $libelle=$histo[$key]['note'];
1442  $actionstatic->id=$histo[$key]['id'];
1443  $out.=dol_trunc($libelle,120);
1444  }
1445  if (isset($histo[$key]['type']) && $histo[$key]['type']=='mailing')
1446  {
1447  $out.='<a href="'.DOL_URL_ROOT.'/comm/mailing/card.php?id='.$histo[$key]['id'].'">'.img_object($langs->trans("ShowEMailing"),"email").' ';
1448  $transcode=$langs->trans("Action".$histo[$key]['acode']);
1449  $libelle=($transcode!="Action".$histo[$key]['acode']?$transcode:'Send mass mailing');
1450  $out.=dol_trunc($libelle,120);
1451  }
1452  $out.='</td>';
1453 
1454  // Date
1455  $out.='<td class="center nowrap">';
1456  $out.=dol_print_date($histo[$key]['datestart'],'dayhour');
1457  if ($histo[$key]['dateend'] && $histo[$key]['dateend'] != $histo[$key]['datestart'])
1458  {
1459  $tmpa=dol_getdate($histo[$key]['datestart'],true);
1460  $tmpb=dol_getdate($histo[$key]['dateend'],true);
1461  if ($tmpa['mday'] == $tmpb['mday'] && $tmpa['mon'] == $tmpb['mon'] && $tmpa['year'] == $tmpb['year']) $out.='-'.dol_print_date($histo[$key]['dateend'],'hour');
1462  else $out.='-'.dol_print_date($histo[$key]['dateend'],'dayhour');
1463  }
1464  $late=0;
1465  if ($histo[$key]['percent'] == 0 && $histo[$key]['datestart'] && $histo[$key]['datestart'] < ($now - $delay_warning)) $late=1;
1466  if ($histo[$key]['percent'] == 0 && ! $histo[$key]['datestart'] && $histo[$key]['dateend'] && $histo[$key]['datestart'] < ($now - $delay_warning)) $late=1;
1467  if ($histo[$key]['percent'] > 0 && $histo[$key]['percent'] < 100 && $histo[$key]['dateend'] && $histo[$key]['dateend'] < ($now - $delay_warning)) $late=1;
1468  if ($histo[$key]['percent'] > 0 && $histo[$key]['percent'] < 100 && ! $histo[$key]['dateend'] && $histo[$key]['datestart'] && $histo[$key]['datestart'] < ($now - $delay_warning)) $late=1;
1469  if ($late) $out.=img_warning($langs->trans("Late")).' ';
1470  $out.="</td>\n";
1471 
1472  // Title of event
1473  //$out.='<td>'.dol_trunc($histo[$key]['note'], 40).'</td>';
1474 
1475  // Objet lie
1476  // TODO mutualize/uniformize
1477  $out.='<td>';
1478  //var_dump($histo[$key]['elementtype']);
1479  if (isset($histo[$key]['elementtype']))
1480  {
1481  if ($histo[$key]['elementtype'] == 'propal' && ! empty($conf->propal->enabled))
1482  {
1483  //$propalstatic->ref=$langs->trans("ProposalShort");
1484  //$propalstatic->id=$histo[$key]['fk_element'];
1485  if ($propalstatic->fetch($histo[$key]['fk_element'])>0) {
1486  $propalstatic->type=$histo[$key]['ftype'];
1487  $out.=$propalstatic->getNomUrl(1);
1488  } else {
1489  $out.= $langs->trans("ProposalDeleted");
1490  }
1491  }
1492  elseif (($histo[$key]['elementtype'] == 'order' || $histo[$key]['elementtype'] == 'commande') && ! empty($conf->commande->enabled))
1493  {
1494  //$orderstatic->ref=$langs->trans("Order");
1495  //$orderstatic->id=$histo[$key]['fk_element'];
1496  if ($orderstatic->fetch($histo[$key]['fk_element'])>0) {
1497  $orderstatic->type=$histo[$key]['ftype'];
1498  $out.=$orderstatic->getNomUrl(1);
1499  } else {
1500  $out.= $langs->trans("OrderDeleted");
1501  }
1502  }
1503  elseif (($histo[$key]['elementtype'] == 'invoice' || $histo[$key]['elementtype'] == 'facture') && ! empty($conf->facture->enabled))
1504  {
1505  //$facturestatic->ref=$langs->trans("Invoice");
1506  //$facturestatic->id=$histo[$key]['fk_element'];
1507  if ($facturestatic->fetch($histo[$key]['fk_element'])>0) {
1508  $facturestatic->type=$histo[$key]['ftype'];
1509  $out.=$facturestatic->getNomUrl(1,'compta');
1510  } else {
1511  $out.= $langs->trans("InvoiceDeleted");
1512  }
1513  }
1514  else $out.='&nbsp;';
1515  }
1516  else $out.='&nbsp;';
1517  $out.='</td>';
1518 
1519  // Contact pour cette action
1520  if (! empty($objcon->id) && isset($histo[$key]['contact_id']) && $histo[$key]['contact_id'] > 0)
1521  {
1522  $contactstatic->lastname=$histo[$key]['lastname'];
1523  $contactstatic->firstname=$histo[$key]['firstname'];
1524  $contactstatic->id=$histo[$key]['contact_id'];
1525  $out.='<td width="120">'.$contactstatic->getNomUrl(1,'',10).'</td>';
1526  }
1527  else
1528  {
1529  $out.='<td>&nbsp;</td>';
1530  }
1531 
1532  // Status
1533  $out.='<td class="nowrap" align="center">'.$actionstatic->LibStatut($histo[$key]['percent'],3,0,$histo[$key]['datestart']).'</td>';
1534 
1535  // Actions
1536  $out.='<td></td>';
1537 
1538  $out.="</tr>\n";
1539  $i++;
1540  }
1541  $out.="</table>\n";
1542  $out.="</div>\n";
1543  }
1544 
1545  $out.='</form>';
1546 
1547  if ($noprint) return $out;
1548  else print $out;
1549 }
1550 
1560 function show_subsidiaries($conf,$langs,$db,$object)
1561 {
1562  global $user;
1563  global $bc;
1564 
1565  $i=-1;
1566 
1567  $sql = "SELECT s.rowid, s.nom as name, s.address, s.zip, s.town, s.code_client, s.canvas";
1568  $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
1569  $sql.= " WHERE s.parent = ".$object->id;
1570  $sql.= " AND s.entity IN (".getEntity('societe').")";
1571  $sql.= " ORDER BY s.nom";
1572 
1573  $result = $db->query($sql);
1574  $num = $db->num_rows($result);
1575 
1576  if ($num)
1577  {
1578  $socstatic = new Societe($db);
1579 
1580  print load_fiche_titre($langs->trans("Subsidiaries"), '', '');
1581  print "\n".'<table class="noborder" width="100%">'."\n";
1582 
1583  print '<tr class="liste_titre"><td>'.$langs->trans("Company").'</td>';
1584  print '<td>'.$langs->trans("Address").'</td><td>'.$langs->trans("Zip").'</td>';
1585  print '<td>'.$langs->trans("Town").'</td><td>'.$langs->trans("CustomerCode").'</td>';
1586  print "<td>&nbsp;</td>";
1587  print "</tr>";
1588 
1589  $i=0;
1590 
1591  while ($i < $num)
1592  {
1593  $obj = $db->fetch_object($result);
1594 
1595  print '<tr class="oddeven">';
1596 
1597  print '<td>';
1598  $socstatic->id = $obj->rowid;
1599  $socstatic->name = $obj->name;
1600  $socstatic->canvas = $obj->canvas;
1601  print $socstatic->getNomUrl(1);
1602  print '</td>';
1603 
1604  print '<td>'.$obj->address.'</td>';
1605  print '<td>'.$obj->zip.'</td>';
1606  print '<td>'.$obj->town.'</td>';
1607  print '<td>'.$obj->code_client.'</td>';
1608 
1609  print '<td align="center">';
1610  print '<a href="'.DOL_URL_ROOT.'/societe/card.php?socid='.$obj->rowid.'&amp;action=edit">';
1611  print img_edit();
1612  print '</a></td>';
1613 
1614  print "</tr>\n";
1615  $i++;
1616  }
1617  print "\n</table>\n";
1618  }
1619 
1620  print "<br>\n";
1621 
1622  return $i;
1623 }
1624 
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='')
Show picto whatever it's its name (generic function)
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.
Class to manage building of HTML components.
getState($id, $withcode='', $dbtouse=0)
Return state translated from an id.
Class to manage agenda events (actions)
Class to manage contact/addresses.
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode='add')
Complete or removed entries into a head array (used to build tabs).
show_addresses($conf, $langs, $db, $object, $backtopage='')
Show html area for list of addresses.
Class to manage Dolibarr users.
Definition: user.class.php:39
show_actions_todo($conf, $langs, $db, $filterobj, $objcon='', $noprint=0, $actioncode='')
Show html area with actions to do.
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
getCountry($searchkey, $withcode='', $dbtouse=0, $outputlangs='', $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
if(empty($reshook)) $form
View.
Definition: perms.php:103
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="")
Scan a directory and return a list of files/directories.
Definition: files.lib.php:58
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
show_subsidiaries($conf, $langs, $db, $object)
Show html area for list of subsidiaries.
Class to manage generation of HTML components Only common components must be here.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
Class to manage third parties objects (customers, suppliers, prospects...)
img_warning($titlealt= 'default', $moreatt= '')
Show warning logo.
getFormeJuridiqueLabel($code)
Retourne le nom traduit de la forme juridique.
Class to manage projects.
getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $disablesortlink=0, $tooltip='')
Get title line of an array.
if($_POST["cancel"]==$langs->trans("Cancel")&&!$id) if($action== 'setdatev'&&$user->rights->tax->charges->creer) if($action== 'add'&&$_POST["cancel"]<> $langs->trans("Cancel")) if($action== 'delete') $title
Actions.
Definition: card.php:183
societe_admin_prepare_head()
Return array head with list of tabs to view object informations.
show_contacts($conf, $langs, $db, $object, $backtopage='')
Show html area for list of contacts.
Class to manage customers orders.
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id=0, $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
liste_contact($statut=-1, $source='external', $list=0, $code='')
Get array of all contacts for an object.
societe_prepare_head(Societe $object)
Return array of tabs to used on pages for third parties cards.
Definition: company.lib.php:40
dol_now($mode='gmt')
Return date for now.
Class to manage predefined suppliers products.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages...
dol_print_date($time, $format='', $tzoutput='tzserver', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
show_projects($conf, $langs, $db, $object, $backtopage='', $nocreatelink=0, $morehtmlright='')
Show html area for list of projects.
societe_prepare_head2($object)
Return array of tabs to used on page.
print
Draft customers invoices.
Definition: index.php:91
if(preg_match('/set_(.*)/', $action, $reg)) if(preg_match('/del_(.*)/', $action, $reg)) if($action== 'set') else if($action== 'specimen') else if($action== 'setmodel') else if($action== 'del') else if($action== 'setdoc' $formactions)
View.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->societe->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1013
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="")
Show title line of an array.
dol_print_phone($phone, $countrycode='', $cid=0, $socid=0, $addlink='', $separ="&nbsp;", $withpicto='', $titlealt='', $adddivfloat=0)
Format phone numbers according to country.
Class to manage invoices.
dol_getdate($timestamp, $fast=false)
Return an array with locale date info.
Class to manage addresses.
img_edit($titlealt= 'default', $float=0, $other= 'class="pictoedit"')
Show logo editer/modifier fiche.
show_actions_done($conf, $langs, $db, $filterobj, $objcon='', $noprint=0, $actioncode='', $donetodo='done', $filters=array(), $sortfield='a.datep, a.id', $sortorder='DESC')
Show html area with actions (done or not, ignore the name of function)
picto_from_langcode($codelang, $moreatt= '')
Return img flag of country for a language code or country code.
isInEEC($object)
Return if a country is inside the EEC (European Economic Community) TODO Add a field into country dic...
currency_name($code_iso, $withcode='', $outputlangs=null)
Return label of currency or code+label.
Class to manage proposals.