PageRenderTime 40ms CodeModel.GetById 10ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/core/lib/company.lib.php

https://github.com/asterix14/dolibarr
PHP | 1053 lines | 730 code | 150 blank | 173 comment | 151 complexity | 5ce443a3a78b05e0bb85f00a5333c3bd MD5 | raw file
Possible License(s): LGPL-2.0
  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 Regis Houssin <regis@dolibarr.fr>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. * or see http://www.gnu.org/
  20. */
  21. /**
  22. * \file htdocs/core/lib/company.lib.php
  23. * \brief Ensemble de fonctions de base pour le module societe
  24. * \ingroup societe
  25. */
  26. /**
  27. * Return array of tabs to used on pages for third parties cards.
  28. *
  29. * @param Object $object Object company shown
  30. * @return array Array of tabs
  31. */
  32. function societe_prepare_head($object)
  33. {
  34. global $langs, $conf, $user;
  35. $h = 0;
  36. $head = array();
  37. $head[$h][0] = DOL_URL_ROOT.'/societe/soc.php?socid='.$object->id;
  38. $head[$h][1] = $langs->trans("Card");
  39. $head[$h][2] = 'card';
  40. $h++;
  41. // TODO Remove tests on object->object. Functions must be called with a company object directly
  42. if (($object->client==2 || $object->client==3
  43. || (isset($object->object) && $object->object->client==2) || (isset($object->object) && $object->object->client==3)) && empty($conf->global->SOCIETE_DISABLE_PROSPECTS))
  44. {
  45. $head[$h][0] = DOL_URL_ROOT.'/comm/prospect/fiche.php?socid='.$object->id;
  46. $head[$h][1] = $langs->trans("Prospect");
  47. $head[$h][2] = 'prospect';
  48. $h++;
  49. }
  50. if ($object->client==1 || $object->client==3 || (is_object($object->object) && $object->object->client==1) || (is_object($object->object) && $object->object->client==3))
  51. {
  52. $head[$h][0] = DOL_URL_ROOT.'/comm/fiche.php?socid='.$object->id;
  53. $head[$h][1] = $langs->trans("Customer");
  54. $head[$h][2] = 'customer';
  55. $h++;
  56. }
  57. if (! empty($conf->fournisseur->enabled) && ($object->fournisseur || (isset($object->object) && $object->object->fournisseur)) && ! empty($user->rights->fournisseur->lire))
  58. {
  59. $head[$h][0] = DOL_URL_ROOT.'/fourn/fiche.php?socid='.$object->id;
  60. $head[$h][1] = $langs->trans("Supplier");
  61. $head[$h][2] = 'supplier';
  62. $h++;
  63. }
  64. if (! empty($conf->agenda->enabled))
  65. {
  66. $head[$h][0] = DOL_URL_ROOT.'/societe/agenda.php?socid='.$object->id;
  67. $head[$h][1] = $langs->trans("Agenda");
  68. $head[$h][2] = 'agenda';
  69. $h++;
  70. }
  71. //show categorie tab
  72. if (! empty($conf->categorie->enabled))
  73. {
  74. $type = 2;
  75. if ($object->fournisseur) $type = 1;
  76. $head[$h][0] = DOL_URL_ROOT.'/categories/categorie.php?socid='.$object->id."&type=".$type;
  77. $head[$h][1] = $langs->trans('Categories');
  78. $head[$h][2] = 'category';
  79. $h++;
  80. }
  81. // Show more tabs from modules
  82. // Entries must be declared in modules descriptor with line
  83. // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
  84. // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
  85. complete_head_from_modules($conf,$langs,$object,$head,$h,'thirdparty');
  86. // Notes
  87. if ($user->societe_id == 0)
  88. {
  89. $head[$h][0] = DOL_URL_ROOT.'/societe/socnote.php?socid='.$object->id;
  90. $head[$h][1] = $langs->trans("Note");
  91. $head[$h][2] = 'note';
  92. $h++;
  93. }
  94. // Attached files
  95. if ($user->societe_id == 0)
  96. {
  97. $head[$h][0] = DOL_URL_ROOT.'/societe/document.php?socid='.$object->id;
  98. $head[$h][1] = $langs->trans("Documents");
  99. $head[$h][2] = 'document';
  100. $h++;
  101. }
  102. // Notifications
  103. if (! empty($conf->notification->enabled) && $user->societe_id == 0)
  104. {
  105. $head[$h][0] = DOL_URL_ROOT.'/societe/notify/fiche.php?socid='.$object->id;
  106. $head[$h][1] = $langs->trans("Notifications");
  107. $head[$h][2] = 'notify';
  108. $h++;
  109. }
  110. // Log
  111. if ($user->societe_id == 0)
  112. {
  113. $head[$h][0] = DOL_URL_ROOT.'/societe/info.php?socid='.$object->id;
  114. $head[$h][1] = $langs->trans("Info");
  115. $head[$h][2] = 'info';
  116. $h++;
  117. }
  118. complete_head_from_modules($conf,$langs,$object,$head,$h,'thirdparty','remove');
  119. return $head;
  120. }
  121. /**
  122. * Return array of tabs to used on page
  123. *
  124. * @param Object $object Object for tabs
  125. * @return
  126. */
  127. function societe_prepare_head2($object)
  128. {
  129. global $langs, $conf, $user;
  130. $h = 0;
  131. $head = array();
  132. $head[$h][0] = DOL_URL_ROOT.'/societe/soc.php?socid='.$object->id;
  133. $head[$h][1] = $langs->trans("Card");
  134. $head[$h][2] = 'company';
  135. $h++;
  136. if (empty($conf->global->SOCIETE_DISABLE_BANKACCOUNT))
  137. {
  138. $head[$h][0] = DOL_URL_ROOT .'/societe/rib.php?socid='.$object->id;
  139. $head[$h][1] = $langs->trans("BankAccount")." $account->number";
  140. $head[$h][2] = 'rib';
  141. $h++;
  142. }
  143. if (empty($conf->global->SOCIETE_DISABLE_PARENTCOMPANY))
  144. {
  145. $head[$h][0] = 'lien.php?socid='.$object->id;
  146. $head[$h][1] = $langs->trans("ParentCompany");
  147. $head[$h][2] = 'links';
  148. $h++;
  149. }
  150. $head[$h][0] = 'commerciaux.php?socid='.$object->id;
  151. $head[$h][1] = $langs->trans("SalesRepresentative");
  152. $head[$h][2] = 'salesrepresentative';
  153. $h++;
  154. return $head;
  155. }
  156. /**
  157. * Return array head with list of tabs to view object informations.
  158. *
  159. * @param Object $object Thirdparty
  160. * @return array head array with tabs
  161. */
  162. function societe_admin_prepare_head($object)
  163. {
  164. global $langs, $conf, $user;
  165. $h = 0;
  166. $head = array();
  167. $head[$h][0] = DOL_URL_ROOT.'/societe/admin/societe.php';
  168. $head[$h][1] = $langs->trans("Miscellanous");
  169. $head[$h][2] = 'general';
  170. $h++;
  171. // Show more tabs from modules
  172. // Entries must be declared in modules descriptor with line
  173. // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
  174. // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
  175. complete_head_from_modules($conf,$langs,$object,$head,$h,'company_admin');
  176. $head[$h][0] = DOL_URL_ROOT.'/societe/admin/societe_extrafields.php';
  177. $head[$h][1] = $langs->trans("ExtraFields");
  178. $head[$h][2] = 'attributes';
  179. $h++;
  180. complete_head_from_modules($conf,$langs,$object,$head,$h,'company_admin','remove');
  181. return $head;
  182. }
  183. /**
  184. * Return country label, code or id from an id or a code
  185. *
  186. * @param int $id Id or code of country
  187. * @param int $withcode '0'=Return label,
  188. * '1'=Return code + label,
  189. * '2'=Return code from id,
  190. * '3'=Return id from code,
  191. * 'all'=Return array('id'=>,'code'=>,'label'=>)
  192. * @param DoliDB $dbtouse Database handler (using in global way may fail because of conflicts with some autoload features)
  193. * @param Translate $outputlangs Langs object for output translation
  194. * @param int $entconv 0=Return value without entities and not converted to output charset
  195. * @return mixed String with country code or translated country name or Array('id','code','label')
  196. */
  197. function getCountry($id,$withcode='',$dbtouse=0,$outputlangs='',$entconv=1)
  198. {
  199. global $db,$langs;
  200. if (! is_object($dbtouse)) $dbtouse=$db;
  201. if (! is_object($outputlangs)) $outputlangs=$langs;
  202. $sql = "SELECT rowid, code, libelle FROM ".MAIN_DB_PREFIX."c_pays";
  203. if (is_numeric($id)) $sql.= " WHERE rowid=".$id;
  204. else $sql.= " WHERE code='".$id."'";
  205. dol_syslog("Company.lib::getCountry sql=".$sql);
  206. $resql=$dbtouse->query($sql);
  207. if ($resql)
  208. {
  209. $obj = $dbtouse->fetch_object($resql);
  210. if ($obj)
  211. {
  212. $label=((! empty($obj->libelle) && $obj->libelle!='-')?$obj->libelle:'');
  213. if (is_object($outputlangs))
  214. {
  215. $outputlangs->load("dict");
  216. if ($entconv) $label=($obj->code && ($outputlangs->trans("Country".$obj->code)!="Country".$obj->code))?$outputlangs->trans("Country".$obj->code):$label;
  217. else $label=($obj->code && ($outputlangs->transnoentitiesnoconv("Country".$obj->code)!="Country".$obj->code))?$outputlangs->transnoentitiesnoconv("Country".$obj->code):$label;
  218. }
  219. if ($withcode == 1) return $label?"$obj->code - $label":"$obj->code";
  220. else if ($withcode == 2) return $obj->code;
  221. else if ($withcode == 3) return $obj->rowid;
  222. else if ($withcode === 'all') return array('id'=>$obj->rowid,'code'=>$obj->code,'label'=>$label);
  223. else return $label;
  224. }
  225. else
  226. {
  227. return "NotDefined";
  228. }
  229. }
  230. else dol_print_error($dbtouse,'');
  231. }
  232. /**
  233. * Return state translated from an id
  234. *
  235. * @param int $id id of state (province/departement)
  236. * @param int $withcode '0'=Return label,
  237. * '1'=Return string code + label,
  238. * '2'=Return code,
  239. * 'all'=return array('id'=>,'code'=>,'label'=>)
  240. * @param DoliDB $dbtouse Database handler (using in global way may fail because of conflicts with some autoload features)
  241. * @return string String with state code or translated state name
  242. */
  243. function getState($id,$withcode='',$dbtouse=0)
  244. {
  245. global $db,$langs;
  246. if (! is_object($dbtouse)) $dbtouse=$db;
  247. $sql = "SELECT rowid, code_departement as code, nom as label FROM ".MAIN_DB_PREFIX."c_departements";
  248. $sql.= " WHERE rowid=".$id;
  249. dol_syslog("Company.lib::getState sql=".$sql);
  250. $resql=$dbtouse->query($sql);
  251. if ($resql)
  252. {
  253. $obj = $dbtouse->fetch_object($resql);
  254. if ($obj)
  255. {
  256. $label=$obj->label;
  257. if ($withcode == '1') return $label=$obj->code?"$obj->code":"$obj->code - $label";
  258. else if ($withcode == '2') return $label=$obj->code;
  259. else if ($withcode == 'all') return array('id'=>$obj->rowid,'code'=>$obj->code,'label'=>$label);
  260. else return $label;
  261. }
  262. else
  263. {
  264. return $langs->trans("NotDefined");
  265. }
  266. }
  267. else dol_print_error($dbtouse,'');
  268. }
  269. /**
  270. * Retourne le nom traduit ou code+nom d'une devise
  271. *
  272. * @param string $code_iso Code iso de la devise
  273. * @param int $withcode '1'=affiche code + nom
  274. * @return string Nom traduit de la devise
  275. */
  276. function currency_name($code_iso,$withcode='')
  277. {
  278. global $langs,$db;
  279. // Si il existe une traduction, on peut renvoyer de suite le libelle
  280. if ($langs->trans("Currency".$code_iso)!="Currency".$code_iso)
  281. {
  282. return $langs->trans("Currency".$code_iso);
  283. }
  284. // Si pas de traduction, on consulte le libelle par defaut en table
  285. $sql = "SELECT label FROM ".MAIN_DB_PREFIX."c_currencies";
  286. $sql.= " WHERE code_iso='".$code_iso."'";
  287. $resql=$db->query($sql);
  288. if ($resql)
  289. {
  290. $num = $db->num_rows($resql);
  291. if ($num)
  292. {
  293. $obj = $db->fetch_object($resql);
  294. $label=($obj->label!='-'?$obj->label:'');
  295. if ($withcode) return ($label==$code_iso)?"$code_iso":"$code_iso - $label";
  296. else return $label;
  297. }
  298. else
  299. {
  300. return $code_iso;
  301. }
  302. }
  303. }
  304. /**
  305. * Retourne le nom traduit de la forme juridique
  306. *
  307. * @param string $code Code de la forme juridique
  308. * @return string Nom traduit du pays
  309. */
  310. function getFormeJuridiqueLabel($code)
  311. {
  312. global $db,$langs;
  313. if (! $code) return '';
  314. $sql = "SELECT libelle FROM ".MAIN_DB_PREFIX."c_forme_juridique";
  315. $sql.= " WHERE code='$code'";
  316. dol_syslog("Company.lib::getFormeJuridiqueLabel sql=".$sql);
  317. $resql=$db->query($sql);
  318. if ($resql)
  319. {
  320. $num = $db->num_rows($resql);
  321. if ($num)
  322. {
  323. $obj = $db->fetch_object($resql);
  324. $label=($obj->libelle!='-' ? $obj->libelle : '');
  325. return $label;
  326. }
  327. else
  328. {
  329. return $langs->trans("NotDefined");
  330. }
  331. }
  332. }
  333. /**
  334. * Show html area for list of projects
  335. *
  336. * @param conf Object conf
  337. * @param langs Object langs
  338. * @param db Database handler
  339. * @param object Third party object
  340. * @param backtopage Url to go once contact is created
  341. */
  342. function show_projects($conf,$langs,$db,$object,$backtopage='')
  343. {
  344. global $user;
  345. $i = -1 ;
  346. if ($conf->projet->enabled && $user->rights->projet->lire)
  347. {
  348. $langs->load("projects");
  349. $buttoncreate='';
  350. if ($conf->projet->enabled && $user->rights->projet->creer)
  351. {
  352. //$buttoncreate='<a class="butAction" href="'.DOL_URL_ROOT.'/projet/fiche.php?socid='.$object->id.'&action=create&amp;backtopage='.urlencode($backtopage).'">'.$langs->trans("AddProject").'</a>';
  353. $buttoncreate='<a class="addnewrecord" href="'.DOL_URL_ROOT.'/projet/fiche.php?socid='.$object->id.'&amp;action=create&amp;backtopage='.urlencode($backtopage).'">'.$langs->trans("AddProject").' '.img_picto($langs->trans("AddProject"),'filenew').'</a>'."\n";
  354. }
  355. print "\n";
  356. print_fiche_titre($langs->trans("ProjectsDedicatedToThisThirdParty"),$buttoncreate,'');
  357. print "\n".'<table class="noborder" width=100%>';
  358. $sql = "SELECT p.rowid,p.title,p.ref,p.public, p.dateo as do, p.datee as de";
  359. $sql .= " FROM ".MAIN_DB_PREFIX."projet as p";
  360. $sql .= " WHERE p.fk_soc = ".$object->id;
  361. $sql .= " ORDER BY p.dateo DESC";
  362. $result=$db->query($sql);
  363. if ($result)
  364. {
  365. $num = $db->num_rows($result);
  366. print '<tr class="liste_titre">';
  367. print '<td>'.$langs->trans("Ref").'</td><td>'.$langs->trans("Name").'</td><td align="center">'.$langs->trans("DateStart").'</td><td align="center">'.$langs->trans("DateEnd").'</td>';
  368. print '</tr>';
  369. if ($num > 0)
  370. {
  371. require_once(DOL_DOCUMENT_ROOT."/projet/class/project.class.php");
  372. $projectstatic = new Project($db);
  373. $i=0;
  374. $var=true;
  375. while ($i < $num)
  376. {
  377. $obj = $db->fetch_object($result);
  378. $projectstatic->fetch($obj->rowid);
  379. // To verify role of users
  380. $userAccess = $projectstatic->restrictedProjectArea($user,1);
  381. if ($user->rights->projet->lire && $userAccess > 0)
  382. {
  383. $var = !$var;
  384. print "<tr $bc[$var]>";
  385. // Ref
  386. print '<td><a href="'.DOL_URL_ROOT.'/projet/fiche.php?id='.$obj->rowid.'">'.img_object($langs->trans("ShowProject"),($obj->public?'projectpub':'project'))." ".$obj->ref.'</a></td>';
  387. // Label
  388. print '<td>'.$obj->title.'</td>';
  389. // Date start
  390. print '<td align="center">'.dol_print_date($db->jdate($obj->do),"day").'</td>';
  391. // Date end
  392. print '<td align="center">'.dol_print_date($db->jdate($obj->de),"day").'</td>';
  393. print '</tr>';
  394. }
  395. $i++;
  396. }
  397. }
  398. else
  399. {
  400. print '<tr><td colspan="3">'.$langs->trans("None").'</td></tr>';
  401. }
  402. $db->free($result);
  403. }
  404. else
  405. {
  406. dol_print_error($db);
  407. }
  408. print "</table>";
  409. print "<br>\n";
  410. }
  411. return $i;
  412. }
  413. /**
  414. * Show html area for list of contacts
  415. *
  416. * @param Conf $conf Object conf
  417. * @param Translate $langs Object langs
  418. * @param DoliDB $db Database handler
  419. * @param Object $object Third party object
  420. * @param string $backtopage Url to go once contact is created
  421. */
  422. function show_contacts($conf,$langs,$db,$object,$backtopage='')
  423. {
  424. global $user;
  425. global $bc;
  426. $i=-1;
  427. $contactstatic = new Contact($db);
  428. if ($conf->clicktodial->enabled)
  429. {
  430. $user->fetch_clicktodial(); // lecture des infos de clicktodial
  431. }
  432. $buttoncreate='';
  433. if ($user->rights->societe->contact->creer)
  434. {
  435. //$buttoncreate='<a class="butAction" href="'.DOL_URL_ROOT.'/contact/fiche.php?socid='.$object->id.'&amp;action=create&amp;backtopage='.urlencode($backtopage).'">'.$langs->trans("AddContact").'</a>'."\n";
  436. $buttoncreate='<a class="addnewrecord" href="'.DOL_URL_ROOT.'/contact/fiche.php?socid='.$object->id.'&amp;action=create&amp;backtopage='.urlencode($backtopage).'">'.$langs->trans("AddContact").' '.img_picto($langs->trans("AddContact"),'filenew').'</a>'."\n";
  437. }
  438. print "\n";
  439. print_fiche_titre($langs->trans("ContactsForCompany"),$buttoncreate,'');
  440. print "\n".'<table class="noborder" width="100%">'."\n";
  441. print '<tr class="liste_titre"><td>'.$langs->trans("Name").'</td>';
  442. print '<td>'.$langs->trans("Poste").'</td><td>'.$langs->trans("Tel").'</td>';
  443. print '<td>'.$langs->trans("Fax").'</td><td>'.$langs->trans("EMail").'</td>';
  444. print "<td>&nbsp;</td>";
  445. if ($conf->agenda->enabled && $user->rights->agenda->myactions->create)
  446. {
  447. print '<td>&nbsp;</td>';
  448. }
  449. print "</tr>";
  450. $sql = "SELECT p.rowid, p.name, p.firstname, p.poste, p.phone, p.fax, p.email, p.note ";
  451. $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as p";
  452. $sql .= " WHERE p.fk_soc = ".$object->id;
  453. $sql .= " ORDER by p.datec";
  454. $result = $db->query($sql);
  455. $num = $db->num_rows($result);
  456. if ($num)
  457. {
  458. $i=0;
  459. $var=true;
  460. while ($i < $num)
  461. {
  462. $obj = $db->fetch_object($result);
  463. $var = !$var;
  464. print "<tr ".$bc[$var].">";
  465. print '<td>';
  466. $contactstatic->id = $obj->rowid;
  467. $contactstatic->name = $obj->name;
  468. $contactstatic->firstname = $obj->firstname;
  469. print $contactstatic->getNomUrl(1);
  470. print '</td>';
  471. print '<td>'.$obj->poste.'</td>';
  472. // Lien click to dial
  473. print '<td>';
  474. print dol_print_phone($obj->phone,$obj->pays_code,$obj->rowid,$object->id,'AC_TEL');
  475. print '</td>';
  476. print '<td>';
  477. print dol_print_phone($obj->fax,$obj->pays_code,$obj->rowid,$object->id,'AC_FAX');
  478. print '</td>';
  479. print '<td>';
  480. print dol_print_email($obj->email,$obj->rowid,$object->id,'AC_EMAIL');
  481. print '</td>';
  482. if ($conf->agenda->enabled && $user->rights->agenda->myactions->create)
  483. {
  484. print '<td align="center"><a href="'.DOL_URL_ROOT.'/comm/action/fiche.php?action=create&actioncode=AC_RDV&contactid='.$obj->rowid.'&socid='.$object->id.'&backtopage='.urlencode($backtopage).'">';
  485. print img_object($langs->trans("Rendez-Vous"),"action");
  486. print '</a></td>';
  487. }
  488. if ($user->rights->societe->contact->creer)
  489. {
  490. print '<td align="right">';
  491. print '<a href="'.DOL_URL_ROOT.'/contact/fiche.php?action=edit&amp;id='.$obj->rowid.'&amp;backtopage='.urlencode($backtopage).'">';
  492. print img_edit();
  493. print '</a></td>';
  494. }
  495. print "</tr>\n";
  496. $i++;
  497. }
  498. }
  499. else
  500. {
  501. //print "<tr ".$bc[$var].">";
  502. //print '<td>'.$langs->trans("NoContactsYetDefined").'</td>';
  503. //print "</tr>\n";
  504. }
  505. print "\n</table>\n";
  506. print "<br>\n";
  507. return $i;
  508. }
  509. /**
  510. * Show html area with actions to do
  511. * @param conf Object conf
  512. * @param langs Object langs
  513. * @param db Object db
  514. * @param object Object third party
  515. * @param objcon Object contact
  516. * @param noprint Return string but does not output it
  517. */
  518. function show_actions_todo($conf,$langs,$db,$object,$objcon='',$noprint=0)
  519. {
  520. global $bc,$user;
  521. $now=dol_now();
  522. $out='';
  523. if ($conf->agenda->enabled)
  524. {
  525. require_once(DOL_DOCUMENT_ROOT."/comm/action/class/actioncomm.class.php");
  526. $actionstatic=new ActionComm($db);
  527. $userstatic=new User($db);
  528. $contactstatic = new Contact($db);
  529. $out.="\n";
  530. if (is_object($objcon) && $objcon->id) $out.=load_fiche_titre($langs->trans("TasksHistoryForThisContact"),'','');
  531. else $out.=load_fiche_titre($langs->trans("ActionsOnCompany"),'','');
  532. $out.='<table width="100%" class="noborder">';
  533. $out.='<tr class="liste_titre">';
  534. $out.='<td colspan="2"><a href="'.DOL_URL_ROOT.'/comm/action/listactions.php?socid='.$object->id.'&amp;status=todo">'.$langs->trans("ActionsToDoShort").'</a></td>';
  535. $out.='<td colspan="5" align="right">';
  536. $permok=$user->rights->agenda->myactions->create;
  537. if (($object->id || $objcon->id) && $permok)
  538. {
  539. $out.='<a href="'.DOL_URL_ROOT.'/comm/action/fiche.php?action=create&amp;socid='.$object->id.'&amp;contactid='.$objcon->id.'&amp;backtopage=1&amp;percentage=-1">';
  540. $out.=$langs->trans("AddAnAction").' ';
  541. $out.=img_picto($langs->trans("AddAnAction"),'filenew');
  542. $out.="</a>";
  543. }
  544. $out.='</td>';
  545. $out.='</tr>';
  546. $sql = "SELECT a.id, a.label,";
  547. $sql.= " a.datep as dp,";
  548. $sql.= " a.datea as da,";
  549. $sql.= " a.percent,";
  550. $sql.= " a.fk_user_author, a.fk_contact,";
  551. $sql.= " a.fk_element, a.elementtype,";
  552. $sql.= " c.code as acode, c.libelle,";
  553. $sql.= " u.login, u.rowid,";
  554. $sql.= " sp.name, sp.firstname";
  555. $sql.= " FROM ".MAIN_DB_PREFIX."c_actioncomm as c, ".MAIN_DB_PREFIX."user as u, ".MAIN_DB_PREFIX."actioncomm as a";
  556. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople as sp ON a.fk_contact = sp.rowid";
  557. $sql.= " WHERE u.rowid = a.fk_user_author";
  558. if ($object->id) $sql.= " AND a.fk_soc = ".$object->id;
  559. if (is_object($objcon) && $objcon->id) $sql.= " AND a.fk_contact = ".$objcon->id;
  560. $sql.= " AND c.id=a.fk_action";
  561. $sql.= " AND ((a.percent >= 0 AND a.percent < 100) OR (a.percent = -1 AND a.datep > '".$db->idate($now)."'))";
  562. $sql.= " ORDER BY a.datep DESC, a.id DESC";
  563. dol_syslog("company.lib::show_actions_todo sql=".$sql);
  564. $result=$db->query($sql);
  565. if ($result)
  566. {
  567. $i = 0 ;
  568. $num = $db->num_rows($result);
  569. $var=true;
  570. if ($num)
  571. {
  572. while ($i < $num)
  573. {
  574. $var = !$var;
  575. $obj = $db->fetch_object($result);
  576. $datep=$db->jdate($obj->dp);
  577. $out.="<tr ".$bc[$var].">";
  578. $out.='<td width="120" align="left" nowrap="nowrap">'.dol_print_date($datep,'dayhour')."</td>\n";
  579. // Picto warning
  580. $out.='<td width="16">';
  581. if ($obj->percent >= 0 && $datep && $datep < ($now - ($conf->global->MAIN_DELAY_ACTIONS_TODO *60*60*24)) ) $out.=' '.img_warning($langs->trans("Late"));
  582. else $out.='&nbsp;';
  583. $out.='</td>';
  584. $actionstatic->type_code=$obj->acode;
  585. $transcode=$langs->trans("Action".$obj->acode);
  586. $libelle=($transcode!="Action".$obj->acode?$transcode:$obj->libelle);
  587. //$actionstatic->libelle=$libelle;
  588. $actionstatic->libelle=$obj->label;
  589. $actionstatic->id=$obj->id;
  590. //$out.='<td width="140">'.$actionstatic->getNomUrl(1,16).'</td>';
  591. // Title of event
  592. //$out.='<td colspan="2">'.dol_trunc($obj->label,40).'</td>';
  593. $out.='<td colspan="2">'.$actionstatic->getNomUrl(1,40).'</td>';
  594. // Contact pour cette action
  595. if (! $objcon->id && $obj->fk_contact > 0)
  596. {
  597. $contactstatic->name=$obj->name;
  598. $contactstatic->firstname=$obj->firstname;
  599. $contactstatic->id=$obj->fk_contact;
  600. $out.='<td width="120">'.$contactstatic->getNomUrl(1,'',10).'</td>';
  601. }
  602. else
  603. {
  604. $out.='<td>&nbsp;</td>';
  605. }
  606. $out.='<td width="80" nowrap="nowrap">';
  607. $userstatic->id=$obj->fk_user_author;
  608. $userstatic->login=$obj->login;
  609. $out.=$userstatic->getLoginUrl(1);
  610. $out.='</td>';
  611. // Statut
  612. $out.='<td nowrap="nowrap" width="20">'.$actionstatic->LibStatut($obj->percent,3).'</td>';
  613. $out.="</tr>\n";
  614. $i++;
  615. }
  616. }
  617. else
  618. {
  619. // Aucun action a faire
  620. }
  621. $db->free($result);
  622. }
  623. else
  624. {
  625. dol_print_error($db);
  626. }
  627. $out.="</table>\n";
  628. $out.="<br>\n";
  629. }
  630. if ($noprint) return $out;
  631. else print $out;
  632. }
  633. /**
  634. * Show html area with actions done
  635. *
  636. * @param conf Object conf
  637. * @param langs Object langs
  638. * @param db Object db
  639. * @param object Object third party
  640. * @param objcon Object contact
  641. * @param noprint Return string but does not output it
  642. */
  643. function show_actions_done($conf,$langs,$db,$object,$objcon='',$noprint=0)
  644. {
  645. global $bc,$user;
  646. $out='';
  647. $histo=array();
  648. $numaction = 0 ;
  649. $now=dol_now();
  650. if ($conf->agenda->enabled)
  651. {
  652. // Recherche histo sur actioncomm
  653. $sql = "SELECT a.id, a.label,";
  654. $sql.= " a.datep as dp,";
  655. $sql.= " a.datep2 as dp2,";
  656. $sql.= " a.note, a.percent,";
  657. $sql.= " a.fk_element, a.elementtype,";
  658. $sql.= " a.fk_user_author, a.fk_contact,";
  659. $sql.= " c.code as acode, c.libelle,";
  660. $sql.= " u.login, u.rowid as user_id,";
  661. $sql.= " sp.name, sp.firstname";
  662. $sql.= " FROM ".MAIN_DB_PREFIX."c_actioncomm as c, ".MAIN_DB_PREFIX."user as u, ".MAIN_DB_PREFIX."actioncomm as a";
  663. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople as sp ON a.fk_contact = sp.rowid";
  664. $sql.= " WHERE u.rowid = a.fk_user_author";
  665. if ($object->id) $sql.= " AND a.fk_soc = ".$object->id;
  666. if (is_object($objcon) && $objcon->id) $sql.= " AND a.fk_contact = ".$objcon->id;
  667. $sql.= " AND c.id=a.fk_action";
  668. $sql.= " AND (a.percent = 100 OR (a.percent = -1 AND a.datep <= '".$db->idate($now)."'))";
  669. $sql.= " ORDER BY a.datep DESC, a.id DESC";
  670. dol_syslog("company.lib::show_actions_done sql=".$sql, LOG_DEBUG);
  671. $resql=$db->query($sql);
  672. if ($resql)
  673. {
  674. $i = 0 ;
  675. $num = $db->num_rows($resql);
  676. $var=true;
  677. while ($i < $num)
  678. {
  679. $obj = $db->fetch_object($resql);
  680. $histo[$numaction]=array('type'=>'action','id'=>$obj->id,'datestart'=>$db->jdate($obj->dp),'date'=>$db->jdate($obj->dp2),'note'=>$obj->label,'percent'=>$obj->percent,
  681. 'acode'=>$obj->acode,'libelle'=>$obj->libelle,
  682. 'userid'=>$obj->user_id,'login'=>$obj->login,
  683. 'contact_id'=>$obj->fk_contact,'name'=>$obj->name,'firstname'=>$obj->firstname,
  684. 'fk_element'=>$obj->fk_element,'elementtype'=>$obj->elementtype);
  685. $numaction++;
  686. $i++;
  687. }
  688. }
  689. else
  690. {
  691. dol_print_error($db);
  692. }
  693. }
  694. if ($conf->mailing->enabled && $objcon->email)
  695. {
  696. $langs->load("mails");
  697. // Recherche histo sur mailing
  698. $sql = "SELECT m.rowid as id, mc.date_envoi as da, m.titre as note, '100' as percentage,";
  699. $sql.= " 'AC_EMAILING' as acode,";
  700. $sql.= " u.rowid as user_id, u.login"; // User that valid action
  701. $sql.= " FROM ".MAIN_DB_PREFIX."mailing as m, ".MAIN_DB_PREFIX."mailing_cibles as mc, ".MAIN_DB_PREFIX."user as u";
  702. $sql.= " WHERE mc.email = '".$db->escape($objcon->email)."'"; // Search is done on email.
  703. $sql.= " AND mc.statut = 1";
  704. $sql.= " AND u.rowid = m.fk_user_valid";
  705. $sql.= " AND mc.fk_mailing=m.rowid";
  706. $sql.= " ORDER BY mc.date_envoi DESC, m.rowid DESC";
  707. dol_syslog("company.lib::show_actions_done sql=".$sql, LOG_DEBUG);
  708. $resql=$db->query($sql);
  709. if ($resql)
  710. {
  711. $i = 0 ;
  712. $num = $db->num_rows($resql);
  713. $var=true;
  714. while ($i < $num)
  715. {
  716. $obj = $db->fetch_object($resql);
  717. $histo[$numaction]=array('type'=>'mailing','id'=>$obj->id,'date'=>$db->jdate($obj->da),'note'=>$obj->note,'percent'=>$obj->percentage,
  718. 'acode'=>$obj->acode,'libelle'=>$obj->libelle,
  719. 'userid'=>$obj->user_id,'login'=>$obj->login,
  720. 'contact_id'=>$obj->contact_id);
  721. $numaction++;
  722. $i++;
  723. }
  724. $db->free($resql);
  725. }
  726. else
  727. {
  728. dol_print_error($db);
  729. }
  730. }
  731. if ($conf->agenda->enabled || ($conf->mailing->enabled && $objcon->email))
  732. {
  733. require_once(DOL_DOCUMENT_ROOT."/comm/action/class/actioncomm.class.php");
  734. require_once(DOL_DOCUMENT_ROOT."/comm/propal/class/propal.class.php");
  735. require_once(DOL_DOCUMENT_ROOT."/commande/class/commande.class.php");
  736. require_once(DOL_DOCUMENT_ROOT."/compta/facture/class/facture.class.php");
  737. $actionstatic=new ActionComm($db);
  738. $userstatic=new User($db);
  739. $contactstatic = new Contact($db);
  740. // TODO uniformize
  741. $propalstatic=new Propal($db);
  742. $orderstatic=new Commande($db);
  743. $facturestatic=new Facture($db);
  744. $out.="\n";
  745. $out.='<table class="noborder" width="100%">';
  746. $out.='<tr class="liste_titre">';
  747. $out.='<td colspan="2"><a href="'.DOL_URL_ROOT.'/comm/action/listactions.php?socid='.$object->id.'&amp;status=done">'.$langs->trans("ActionsDoneShort").'</a></td>';
  748. $out.='<td colspan="5" align="right">';
  749. $permok=$user->rights->agenda->myactions->create;
  750. if (($object->id || $objcon->id) && $permok)
  751. {
  752. $out.='<a href="'.DOL_URL_ROOT.'/comm/action/fiche.php?action=create&amp;socid='.$object->id.'&amp;contactid='.$objcon->id.'&amp;backtopage=1&amp;percentage=-1">';
  753. $out.=$langs->trans("AddAnAction").' ';
  754. $out.=img_picto($langs->trans("AddAnAction"),'filenew');
  755. $out.="</a>";
  756. }
  757. $out.='</td>';
  758. $out.='</tr>';
  759. foreach ($histo as $key=>$value)
  760. {
  761. $var=!$var;
  762. $out.="<tr ".$bc[$var].">";
  763. // Champ date
  764. $out.='<td width="120" nowrap="nowrap">';
  765. if ($histo[$key]['date']) $out.=dol_print_date($histo[$key]['date'],'dayhour');
  766. else if ($histo[$key]['datestart']) $out.=dol_print_date($histo[$key]['datestart'],'dayhour');
  767. $out.="</td>\n";
  768. // Picto
  769. $out.='<td width="16">&nbsp;</td>';
  770. // Action
  771. $out.='<td>';
  772. if ($histo[$key]['type']=='action')
  773. {
  774. $actionstatic->type_code=$histo[$key]['acode'];
  775. $transcode=$langs->trans("Action".$histo[$key]['acode']);
  776. $libelle=($transcode!="Action".$histo[$key]['acode']?$transcode:$histo[$key]['libelle']);
  777. //$actionstatic->libelle=$libelle;
  778. $actionstatic->libelle=$histo[$key]['note'];
  779. $actionstatic->id=$histo[$key]['id'];
  780. $out.=$actionstatic->getNomUrl(1,40);
  781. }
  782. if ($histo[$key]['type']=='mailing')
  783. {
  784. $out.='<a href="'.DOL_URL_ROOT.'/comm/mailing/fiche.php?id='.$histo[$key]['id'].'">'.img_object($langs->trans("ShowEMailing"),"email").' ';
  785. $transcode=$langs->trans("Action".$histo[$key]['acode']);
  786. $libelle=($transcode!="Action".$histo[$key]['acode']?$transcode:'Send mass mailing');
  787. $out.=dol_trunc($libelle,40);
  788. }
  789. $out.='</td>';
  790. // Title of event
  791. //$out.='<td>'.dol_trunc($histo[$key]['note'], 40).'</td>';
  792. // Objet lie
  793. // TODO uniformize
  794. $out.='<td>';
  795. if ($histo[$key]['elementtype'] == 'propal' && $conf->propal->enabled)
  796. {
  797. $propalstatic->ref=$langs->trans("ProposalShort");
  798. $propalstatic->id=$histo[$key]['fk_element'];
  799. $out.=$propalstatic->getNomUrl(1);
  800. }
  801. elseif ($histo[$key]['elementtype'] == 'commande' && $conf->commande->enabled)
  802. {
  803. $orderstatic->ref=$langs->trans("Order");
  804. $orderstatic->id=$histo[$key]['fk_element'];
  805. $out.=$orderstatic->getNomUrl(1);
  806. }
  807. elseif ($histo[$key]['elementtype'] == 'facture' && $conf->facture->enabled)
  808. {
  809. $facturestatic->ref=$langs->trans("Invoice");
  810. $facturestatic->id=$histo[$key]['fk_element'];
  811. $facturestatic->type=$histo[$key]['ftype'];
  812. $out.=$facturestatic->getNomUrl(1,'compta');
  813. }
  814. else $out.='&nbsp;';
  815. $out.='</td>';
  816. // Contact pour cette action
  817. if (! $objcon->id && $histo[$key]['contact_id'] > 0)
  818. {
  819. $contactstatic->name=$histo[$key]['name'];
  820. $contactstatic->firstname=$histo[$key]['firstname'];
  821. $contactstatic->id=$histo[$key]['contact_id'];
  822. $out.='<td width="120">'.$contactstatic->getNomUrl(1,'',10).'</td>';
  823. }
  824. else
  825. {
  826. $out.='<td>&nbsp;</td>';
  827. }
  828. // Auteur
  829. $out.='<td nowrap="nowrap" width="80">';
  830. $userstatic->id=$histo[$key]['userid'];
  831. $userstatic->login=$histo[$key]['login'];
  832. $out.=$userstatic->getLoginUrl(1);
  833. $out.='</td>';
  834. // Statut
  835. $out.='<td nowrap="nowrap" width="20">'.$actionstatic->LibStatut($histo[$key]['percent'],3).'</td>';
  836. $out.="</tr>\n";
  837. $i++;
  838. }
  839. $out.="</table>\n";
  840. $out.="<br>\n";
  841. }
  842. if ($noprint) return $out;
  843. else print $out;
  844. }
  845. /**
  846. * Show html area for list of subsidiaries
  847. * @param conf Object conf
  848. * @param langs Object langs
  849. * @param db Database handler
  850. * @param object Third party object
  851. */
  852. function show_subsidiaries($conf,$langs,$db,$object)
  853. {
  854. global $user;
  855. global $bc;
  856. $i=-1;
  857. $sql = "SELECT s.rowid, s.nom as name, s.address, s.cp as zip, s.ville as town, s.code_client, s.canvas";
  858. $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
  859. $sql.= " WHERE s.parent = ".$object->id;
  860. $sql.= " AND s.entity = ".$conf->entity;
  861. $sql.= " ORDER BY s.nom";
  862. $result = $db->query($sql);
  863. $num = $db->num_rows($result);
  864. if ($num)
  865. {
  866. $socstatic = new Societe($db);
  867. print_titre($langs->trans("Subsidiaries"));
  868. print "\n".'<table class="noborder" width="100%">'."\n";
  869. print '<tr class="liste_titre"><td>'.$langs->trans("Company").'</td>';
  870. print '<td>'.$langs->trans("Address").'</td><td>'.$langs->trans("Zip").'</td>';
  871. print '<td>'.$langs->trans("Town").'</td><td>'.$langs->trans("CustomerCode").'</td>';
  872. print "<td>&nbsp;</td>";
  873. print "</tr>";
  874. $i=0;
  875. $var=true;
  876. while ($i < $num)
  877. {
  878. $obj = $db->fetch_object($result);
  879. $var = !$var;
  880. print "<tr ".$bc[$var].">";
  881. print '<td>';
  882. $socstatic->id = $obj->rowid;
  883. $socstatic->name = $obj->name;
  884. $socstatic->canvas = $obj->canvas;
  885. print $socstatic->getNomUrl(1);
  886. print '</td>';
  887. print '<td>'.$obj->address.'</td>';
  888. print '<td>'.$obj->zip.'</td>';
  889. print '<td>'.$obj->town.'</td>';
  890. print '<td>'.$obj->code_client.'</td>';
  891. print '<td align="center">';
  892. print '<a href="'.DOL_URL_ROOT.'/societe/soc.php?socid='.$obj->rowid.'&amp;action=edit">';
  893. print img_edit();
  894. print '</a></td>';
  895. print "</tr>\n";
  896. $i++;
  897. }
  898. print "\n</table>\n";
  899. }
  900. print "<br>\n";
  901. return $i;
  902. }
  903. ?>