company.lib.php 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452
  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. /**
  28. * \file htdocs/core/lib/company.lib.php
  29. * \brief Ensemble de fonctions de base pour le module societe
  30. * \ingroup societe
  31. */
  32. /**
  33. * Return array of tabs to used on pages for third parties cards.
  34. *
  35. * @param Societe $object Object company shown
  36. * @return array Array of tabs
  37. */
  38. function societe_prepare_head(Societe $object)
  39. {
  40. global $db, $langs, $conf, $user;
  41. $h = 0;
  42. $head = array();
  43. $head[$h][0] = DOL_URL_ROOT.'/societe/soc.php?socid='.$object->id;
  44. $head[$h][1] = $langs->trans("Card");
  45. $head[$h][2] = 'card';
  46. $h++;
  47. if ($object->client==1 || $object->client==2 || $object->client==3)
  48. {
  49. $head[$h][0] = DOL_URL_ROOT.'/comm/card.php?socid='.$object->id;
  50. $head[$h][1] = '';
  51. if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && ($object->client==2 || $object->client==3)) $head[$h][1] .= $langs->trans("Prospect");
  52. if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS) && $object->client==3) $head[$h][1] .= '/';
  53. if (empty($conf->global->SOCIETE_DISABLE_CUSTOMERS) && ($object->client==1 || $object->client==3)) $head[$h][1] .= $langs->trans("Customer");
  54. $head[$h][2] = 'customer';
  55. $h++;
  56. if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES))
  57. {
  58. $langs->load("products");
  59. // price
  60. $head[$h][0] = DOL_URL_ROOT.'/societe/price.php?socid='.$object->id;
  61. $head[$h][1] = $langs->trans("CustomerPrices");
  62. $head[$h][2] = 'price';
  63. $h++;
  64. }
  65. }
  66. if (! empty($conf->fournisseur->enabled) && $object->fournisseur && ! empty($user->rights->fournisseur->lire))
  67. {
  68. $head[$h][0] = DOL_URL_ROOT.'/fourn/card.php?socid='.$object->id;
  69. $head[$h][1] = $langs->trans("Supplier");
  70. $head[$h][2] = 'supplier';
  71. $h++;
  72. }
  73. if (! empty($conf->global->MAIN_SUPPORT_SHARED_CONTACT_BETWEEN_THIRDPARTIES))
  74. {
  75. $head[$h][0] = DOL_URL_ROOT.'/societe/societecontact.php?socid='.$object->id;
  76. $nbContact = count($object->liste_contact(-1,'internal')) + count($object->liste_contact(-1,'external'));
  77. $head[$h][1] = $langs->trans("ContactsAddresses");
  78. if ($nbContact > 0) $head[$h][1].= ' <span class="badge">'.$nbContact.'</span>';
  79. $head[$h][2] = 'contact';
  80. $h++;
  81. }
  82. if (! empty($conf->projet->enabled) && (!empty($user->rights->projet->lire) ))
  83. {
  84. $head[$h][0] = DOL_URL_ROOT.'/societe/project.php?socid='.$object->id;
  85. $head[$h][1] = $langs->trans("Projects");
  86. $nbNote = 0;
  87. $sql = "SELECT COUNT(n.rowid) as nb";
  88. $sql.= " FROM ".MAIN_DB_PREFIX."projet as n";
  89. $sql.= " WHERE fk_soc = ".$object->id;
  90. $resql=$db->query($sql);
  91. if ($resql)
  92. {
  93. $num = $db->num_rows($resql);
  94. $i = 0;
  95. while ($i < $num)
  96. {
  97. $obj = $db->fetch_object($resql);
  98. $nbNote=$obj->nb;
  99. $i++;
  100. }
  101. }
  102. else {
  103. dol_print_error($db);
  104. }
  105. if ($nbNote > 0) $head[$h][1].= ' <span class="badge">'.$nbNote.'</span>';
  106. $head[$h][2] = 'project';
  107. $h++;
  108. }
  109. //show categorie tab
  110. /*if (! empty($conf->categorie->enabled) && ! empty($user->rights->categorie->lire))
  111. {
  112. require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
  113. $type = Categorie::TYPE_CUSTOMER;
  114. if ($object->fournisseur) $type = Categorie::TYPE_SUPPLIER;
  115. $head[$h][0] = DOL_URL_ROOT.'/categories/categorie.php?socid='.$object->id."&type=".$type;
  116. $head[$h][1] = $langs->trans('Categories');
  117. $head[$h][2] = 'category';
  118. $h++;
  119. }*/
  120. // Tab to link resources
  121. if (! empty($conf->resource->enabled) && ! empty($conf->global->RESOURCE_ON_THIRDPARTIES))
  122. {
  123. $head[$h][0] = DOL_URL_ROOT.'/resource/element_resource.php?element=societe&element_id='.$object->id;
  124. $head[$h][1] = $langs->trans("Resources");
  125. $head[$h][2] = 'resources';
  126. $h++;
  127. }
  128. // Show more tabs from modules
  129. // Entries must be declared in modules descriptor with line
  130. // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
  131. // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
  132. complete_head_from_modules($conf,$langs,$object,$head,$h,'thirdparty');
  133. if ($user->societe_id == 0)
  134. {
  135. if (! empty($conf->commande->enabled) || ! empty($conf->propal->enabled) || ! empty($conf->facture->enabled) || ! empty($conf->fichinter->enabled) || ! empty($conf->fournisseur->enabled))
  136. {
  137. $head[$h][0] = DOL_URL_ROOT.'/societe/consumption.php?socid='.$object->id;
  138. $head[$h][1] = $langs->trans("Referers");
  139. $head[$h][2] = 'consumption';
  140. $h++;
  141. }
  142. // Notifications
  143. if (! empty($conf->notification->enabled))
  144. {
  145. $nbNote = 0;
  146. $sql = "SELECT COUNT(n.rowid) as nb";
  147. $sql.= " FROM ".MAIN_DB_PREFIX."notify_def as n";
  148. $sql.= " WHERE fk_soc = ".$object->id;
  149. $resql=$db->query($sql);
  150. if ($resql)
  151. {
  152. $num = $db->num_rows($resql);
  153. $i = 0;
  154. while ($i < $num)
  155. {
  156. $obj = $db->fetch_object($resql);
  157. $nbNote=$obj->nb;
  158. $i++;
  159. }
  160. }
  161. else {
  162. dol_print_error($db);
  163. }
  164. $head[$h][0] = DOL_URL_ROOT.'/societe/notify/card.php?socid='.$object->id;
  165. $head[$h][1] = $langs->trans("Notifications");
  166. if ($nbNote > 0) $head[$h][1].= ' <span class="badge">'.$nbNote.'</span>';
  167. $head[$h][2] = 'notify';
  168. $h++;
  169. }
  170. // Notes
  171. $nbNote = 0;
  172. if(!empty($object->note_private)) $nbNote++;
  173. if(!empty($object->note_public)) $nbNote++;
  174. $head[$h][0] = DOL_URL_ROOT.'/societe/note.php?id='.$object->id;
  175. $head[$h][1] = $langs->trans("Notes");
  176. if ($nbNote > 0) $head[$h][1].= ' <span class="badge">'.$nbNote.'</span>';
  177. $head[$h][2] = 'note';
  178. $h++;
  179. // Attached files
  180. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  181. require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
  182. $upload_dir = $conf->societe->dir_output . "/" . $object->id;
  183. $nbFiles = count(dol_dir_list($upload_dir,'files',0,'','(\.meta|_preview\.png)$'));
  184. $nbLinks=Link::count($db, $object->element, $object->id);
  185. $head[$h][0] = DOL_URL_ROOT.'/societe/document.php?socid='.$object->id;
  186. $head[$h][1] = $langs->trans("Documents");
  187. if (($nbFiles+$nbLinks) > 0) $head[$h][1].= ' <span class="badge">'.($nbFiles+$nbLinks).'</span>';
  188. $head[$h][2] = 'document';
  189. $h++;
  190. }
  191. $head[$h][0] = DOL_URL_ROOT.'/societe/agenda.php?socid='.$object->id;
  192. if (! empty($conf->agenda->enabled) && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read) ))
  193. {
  194. $head[$h][1] = $langs->trans("Events");
  195. $head[$h][1].= '/';
  196. }
  197. $head[$h][1].= $langs->trans("Agenda");
  198. $head[$h][2] = 'agenda';
  199. $h++;
  200. // Log
  201. /*$head[$h][0] = DOL_URL_ROOT.'/societe/info.php?socid='.$object->id;
  202. $head[$h][1] = $langs->trans("Info");
  203. $head[$h][2] = 'info';
  204. $h++;*/
  205. complete_head_from_modules($conf,$langs,$object,$head,$h,'thirdparty','remove');
  206. return $head;
  207. }
  208. /**
  209. * Return array of tabs to used on page
  210. *
  211. * @param Object $object Object for tabs
  212. * @return array Array of tabs
  213. */
  214. function societe_prepare_head2($object)
  215. {
  216. global $langs, $conf, $user;
  217. $h = 0;
  218. $head = array();
  219. $head[$h][0] = DOL_URL_ROOT.'/societe/soc.php?socid='.$object->id;
  220. $head[$h][1] = $langs->trans("Card");
  221. $head[$h][2] = 'company';
  222. $h++;
  223. if (empty($conf->global->SOCIETE_DISABLE_BANKACCOUNT))
  224. {
  225. $head[$h][0] = DOL_URL_ROOT .'/societe/rib.php?socid='.$object->id;
  226. $head[$h][1] = $langs->trans("BankAccount");
  227. $head[$h][2] = 'rib';
  228. $h++;
  229. }
  230. $head[$h][0] = 'commerciaux.php?socid='.$object->id;
  231. $head[$h][1] = $langs->trans("SalesRepresentative");
  232. $head[$h][2] = 'salesrepresentative';
  233. $h++;
  234. return $head;
  235. }
  236. /**
  237. * Return array head with list of tabs to view object informations.
  238. *
  239. * @return array head array with tabs
  240. */
  241. function societe_admin_prepare_head()
  242. {
  243. global $langs, $conf, $user;
  244. $h = 0;
  245. $head = array();
  246. $head[$h][0] = DOL_URL_ROOT.'/societe/admin/societe.php';
  247. $head[$h][1] = $langs->trans("Miscellaneous");
  248. $head[$h][2] = 'general';
  249. $h++;
  250. // Show more tabs from modules
  251. // Entries must be declared in modules descriptor with line
  252. // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
  253. // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
  254. complete_head_from_modules($conf,$langs,null,$head,$h,'company_admin');
  255. $head[$h][0] = DOL_URL_ROOT.'/societe/admin/societe_extrafields.php';
  256. $head[$h][1] = $langs->trans("ExtraFieldsThirdParties");
  257. $head[$h][2] = 'attributes';
  258. $h++;
  259. $head[$h][0] = DOL_URL_ROOT.'/societe/admin/contact_extrafields.php';
  260. $head[$h][1] = $langs->trans("ExtraFieldsContacts");
  261. $head[$h][2] = 'attributes_contacts';
  262. $h++;
  263. complete_head_from_modules($conf,$langs,null,$head,$h,'company_admin','remove');
  264. return $head;
  265. }
  266. /**
  267. * Return country label, code or id from an id, code or label
  268. *
  269. * @param int $searchkey Id or code of country to search
  270. * @param int $withcode '0'=Return label,
  271. * '1'=Return code + label,
  272. * '2'=Return code from id,
  273. * '3'=Return id from code,
  274. * 'all'=Return array('id'=>,'code'=>,'label'=>)
  275. * @param DoliDB $dbtouse Database handler (using in global way may fail because of conflicts with some autoload features)
  276. * @param Translate $outputlangs Langs object for output translation
  277. * @param int $entconv 0=Return value without entities and not converted to output charset, 1=Ready for html output
  278. * @param int $searchlabel Label of country to search (warning: searching on label is not reliable)
  279. * @return mixed String with country code or translated country name or Array('id','code','label')
  280. */
  281. function getCountry($searchkey,$withcode='',$dbtouse=0,$outputlangs='',$entconv=1,$searchlabel='')
  282. {
  283. global $db,$langs;
  284. // Check parameters
  285. if (empty($searchkey) && empty($searchlabel))
  286. {
  287. if ($withcode === 'all') return array('id'=>'','code'=>'','label'=>'');
  288. else return '';
  289. }
  290. if (! is_object($dbtouse)) $dbtouse=$db;
  291. if (! is_object($outputlangs)) $outputlangs=$langs;
  292. $sql = "SELECT rowid, code, label FROM ".MAIN_DB_PREFIX."c_country";
  293. if (is_numeric($searchkey)) $sql.= " WHERE rowid=".$searchkey;
  294. elseif (! empty($searchkey)) $sql.= " WHERE code='".$db->escape($searchkey)."'";
  295. else $sql.= " WHERE label='".$db->escape($searchlabel)."'";
  296. dol_syslog("Company.lib::getCountry", LOG_DEBUG);
  297. $resql=$dbtouse->query($sql);
  298. if ($resql)
  299. {
  300. $obj = $dbtouse->fetch_object($resql);
  301. if ($obj)
  302. {
  303. $label=((! empty($obj->label) && $obj->label!='-')?$obj->label:'');
  304. if (is_object($outputlangs))
  305. {
  306. $outputlangs->load("dict");
  307. if ($entconv) $label=($obj->code && ($outputlangs->trans("Country".$obj->code)!="Country".$obj->code))?$outputlangs->trans("Country".$obj->code):$label;
  308. else $label=($obj->code && ($outputlangs->transnoentitiesnoconv("Country".$obj->code)!="Country".$obj->code))?$outputlangs->transnoentitiesnoconv("Country".$obj->code):$label;
  309. }
  310. if ($withcode == 1) return $label?"$obj->code - $label":"$obj->code";
  311. else if ($withcode == 2) return $obj->code;
  312. else if ($withcode == 3) return $obj->rowid;
  313. else if ($withcode === 'all') return array('id'=>$obj->rowid,'code'=>$obj->code,'label'=>$label);
  314. else return $label;
  315. }
  316. else
  317. {
  318. return 'NotDefined';
  319. }
  320. $dbtouse->free($resql);
  321. }
  322. else dol_print_error($dbtouse,'');
  323. return 'Error';
  324. }
  325. /**
  326. * Return state translated from an id. Return value is always utf8 encoded and without entities.
  327. *
  328. * @param int $id id of state (province/departement)
  329. * @param int $withcode '0'=Return label,
  330. * '1'=Return string code + label,
  331. * '2'=Return code,
  332. * 'all'=return array('id'=>,'code'=>,'label'=>)
  333. * @param DoliDB $dbtouse Database handler (using in global way may fail because of conflicts with some autoload features)
  334. * @return string String with state code or state name (Return value is always utf8 encoded and without entities)
  335. */
  336. function getState($id,$withcode='',$dbtouse=0)
  337. {
  338. global $db,$langs;
  339. if (! is_object($dbtouse)) $dbtouse=$db;
  340. $sql = "SELECT rowid, code_departement as code, nom as label FROM ".MAIN_DB_PREFIX."c_departements";
  341. $sql.= " WHERE rowid=".$id;
  342. dol_syslog("Company.lib::getState", LOG_DEBUG);
  343. $resql=$dbtouse->query($sql);
  344. if ($resql)
  345. {
  346. $obj = $dbtouse->fetch_object($resql);
  347. if ($obj)
  348. {
  349. $label=$obj->label;
  350. if ($withcode == '1') return $label=$obj->code?"$obj->code":"$obj->code - $label";
  351. else if ($withcode == '2') return $label=$obj->code;
  352. else if ($withcode == 'all') return array('id'=>$obj->rowid,'code'=>$obj->code,'label'=>$label);
  353. else return $label;
  354. }
  355. else
  356. {
  357. return $langs->transnoentitiesnoconv("NotDefined");
  358. }
  359. }
  360. else dol_print_error($dbtouse,'');
  361. }
  362. /**
  363. * Retourne le nom traduit ou code+nom d'une devise
  364. *
  365. * @param string $code_iso Code iso de la devise
  366. * @param int $withcode '1'=affiche code + nom
  367. * @return string Nom traduit de la devise
  368. */
  369. function currency_name($code_iso,$withcode='')
  370. {
  371. global $langs,$db;
  372. // Si il existe une traduction, on peut renvoyer de suite le libelle
  373. if ($langs->trans("Currency".$code_iso)!="Currency".$code_iso)
  374. {
  375. return $langs->trans("Currency".$code_iso);
  376. }
  377. // Si pas de traduction, on consulte le libelle par defaut en table
  378. $sql = "SELECT label FROM ".MAIN_DB_PREFIX."c_currencies";
  379. $sql.= " WHERE code_iso='".$code_iso."'";
  380. $resql=$db->query($sql);
  381. if ($resql)
  382. {
  383. $num = $db->num_rows($resql);
  384. if ($num)
  385. {
  386. $obj = $db->fetch_object($resql);
  387. $label=($obj->label!='-'?$obj->label:'');
  388. if ($withcode) return ($label==$code_iso)?"$code_iso":"$code_iso - $label";
  389. else return $label;
  390. }
  391. else
  392. {
  393. return $code_iso;
  394. }
  395. }
  396. }
  397. /**
  398. * Retourne le nom traduit de la forme juridique
  399. *
  400. * @param string $code Code de la forme juridique
  401. * @return string Nom traduit du pays
  402. */
  403. function getFormeJuridiqueLabel($code)
  404. {
  405. global $db,$langs;
  406. if (! $code) return '';
  407. $sql = "SELECT libelle FROM ".MAIN_DB_PREFIX."c_forme_juridique";
  408. $sql.= " WHERE code='$code'";
  409. dol_syslog("Company.lib::getFormeJuridiqueLabel", LOG_DEBUG);
  410. $resql=$db->query($sql);
  411. if ($resql)
  412. {
  413. $num = $db->num_rows($resql);
  414. if ($num)
  415. {
  416. $obj = $db->fetch_object($resql);
  417. $label=($obj->libelle!='-' ? $obj->libelle : '');
  418. return $label;
  419. }
  420. else
  421. {
  422. return $langs->trans("NotDefined");
  423. }
  424. }
  425. }
  426. /**
  427. * Show html area for list of projects
  428. *
  429. * @param Conf $conf Object conf
  430. * @param Translate $langs Object langs
  431. * @param DoliDB $db Database handler
  432. * @param Object $object Third party object
  433. * @param string $backtopage Url to go once contact is created
  434. * @param int $nocreatelink 1=Hide create project link
  435. * @return void
  436. */
  437. function show_projects($conf, $langs, $db, $object, $backtopage='', $nocreatelink=0)
  438. {
  439. global $user;
  440. global $bc;
  441. $i = -1 ;
  442. if (! empty($conf->projet->enabled) && $user->rights->projet->lire)
  443. {
  444. $langs->load("projects");
  445. $buttoncreate='';
  446. if (! empty($conf->projet->enabled) && $user->rights->projet->creer && empty($nocreatelink))
  447. {
  448. //$buttoncreate='<a class="butAction" href="'.DOL_URL_ROOT.'/projet/card.php?socid='.$object->id.'&action=create&amp;backtopage='.urlencode($backtopage).'">'.$langs->trans("AddProject").'</a>';
  449. $buttoncreate='<a class="addnewrecord" href="'.DOL_URL_ROOT.'/projet/card.php?socid='.$object->id.'&amp;action=create&amp;backtopage='.urlencode($backtopage).'">'.$langs->trans("AddProject");
  450. if (empty($conf->dol_optimize_smallscreen)) $buttoncreate.=' '.img_picto($langs->trans("AddProject"),'filenew');
  451. $buttoncreate.='</a>'."\n";
  452. }
  453. print "\n";
  454. print load_fiche_titre($langs->trans("ProjectsDedicatedToThisThirdParty"),$buttoncreate,'');
  455. print "\n".'<table class="noborder" width=100%>';
  456. $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";
  457. $sql .= " FROM ".MAIN_DB_PREFIX."projet as p";
  458. $sql .= " WHERE p.fk_soc = ".$object->id;
  459. $sql .= " ORDER BY p.dateo DESC";
  460. $result=$db->query($sql);
  461. if ($result)
  462. {
  463. $num = $db->num_rows($result);
  464. print '<tr class="liste_titre">';
  465. 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>';
  466. print '<td align="right">'.$langs->trans("Status").'</td>';
  467. print '</tr>';
  468. if ($num > 0)
  469. {
  470. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  471. $projecttmp = new Project($db);
  472. $i=0;
  473. $var=true;
  474. while ($i < $num)
  475. {
  476. $obj = $db->fetch_object($result);
  477. $projecttmp->fetch($obj->id);
  478. // To verify role of users
  479. $userAccess = $projecttmp->restrictedProjectArea($user);
  480. if ($user->rights->projet->lire && $userAccess > 0)
  481. {
  482. $var = !$var;
  483. print "<tr ".$bc[$var].">";
  484. // Ref
  485. 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>';
  486. // Label
  487. print '<td>'.$obj->title.'</td>';
  488. // Date start
  489. print '<td align="center">'.dol_print_date($db->jdate($obj->do),"day").'</td>';
  490. // Date end
  491. print '<td align="center">'.dol_print_date($db->jdate($obj->de),"day").'</td>';
  492. // Status
  493. print '<td align="right">'.$projecttmp->getLibStatut(5).'</td>';
  494. print '</tr>';
  495. }
  496. $i++;
  497. }
  498. }
  499. else
  500. {
  501. $var = false;
  502. print '<tr '.$bc[$var].'><td colspan="5" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
  503. }
  504. $db->free($result);
  505. }
  506. else
  507. {
  508. dol_print_error($db);
  509. }
  510. print "</table>";
  511. print "<br>\n";
  512. }
  513. return $i;
  514. }
  515. /**
  516. * Show html area for list of contacts
  517. *
  518. * @param Conf $conf Object conf
  519. * @param Translate $langs Object langs
  520. * @param DoliDB $db Database handler
  521. * @param Societe $object Third party object
  522. * @param string $backtopage Url to go once contact is created
  523. * @return void
  524. */
  525. function show_contacts($conf,$langs,$db,$object,$backtopage='')
  526. {
  527. global $user,$conf;
  528. global $bc;
  529. $form= new Form($db);
  530. $sortfield = GETPOST("sortfield",'alpha');
  531. $sortorder = GETPOST("sortorder",'alpha');
  532. $search_status = GETPOST("search_status",'int');
  533. if ($search_status=='') $search_status=1; // always display activ customer first
  534. $search_name = GETPOST("search_name",'alpha');
  535. $search_addressphone = GETPOST("search_addressphone",'alpha');
  536. if (! $sortorder) $sortorder="ASC";
  537. if (! $sortfield) $sortfield="p.lastname";
  538. $i=-1;
  539. $contactstatic = new Contact($db);
  540. if (! empty($conf->clicktodial->enabled))
  541. {
  542. $user->fetch_clicktodial(); // lecture des infos de clicktodial
  543. }
  544. $buttoncreate='';
  545. if ($user->rights->societe->contact->creer)
  546. {
  547. $addcontact = (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("AddContact") : $langs->trans("AddContactAddress"));
  548. $buttoncreate='<a class="addnewrecord" href="'.DOL_URL_ROOT.'/contact/card.php?socid='.$object->id.'&amp;action=create&amp;backtopage='.urlencode($backtopage).'">'.$addcontact;
  549. if (empty($conf->dol_optimize_smallscreen)) $buttoncreate.=' '.img_picto($addcontact,'filenew');
  550. $buttoncreate.='</a>'."\n";
  551. }
  552. print "\n";
  553. $title = (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("ContactsForCompany") : $langs->trans("ContactsAddressesForCompany"));
  554. print load_fiche_titre($title,$buttoncreate,'');
  555. print '<form method="GET" action="'.$_SERVER["PHP_SELF"].'" name="formfilter">';
  556. print '<input type="hidden" name="socid" value="'.$object->id.'">';
  557. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  558. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  559. print "\n".'<table class="noborder" width="100%">'."\n";
  560. $param="socid=".$object->id;
  561. if ($search_status != '') $param.='&amp;search_status='.$search_status;
  562. if ($search_name != '') $param.='&amp;search_name='.urlencode($search_name);
  563. $colspan=9;
  564. print '<tr class="liste_titre">';
  565. print_liste_field_titre($langs->trans("Name"),$_SERVER["PHP_SELF"],"p.lastname","",$param,'',$sortfield,$sortorder);
  566. print_liste_field_titre($langs->trans("Poste"),$_SERVER["PHP_SELF"],"p.poste","",$param,'',$sortfield,$sortorder);
  567. print_liste_field_titre($langs->trans("Address").' / '.$langs->trans("Phone").' / '.$langs->trans("Email"),$_SERVER["PHP_SELF"],"","",$param,'',$sortfield,$sortorder);
  568. print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"p.statut","",$param,'',$sortfield,$sortorder);
  569. // Add to agenda
  570. if (! empty($conf->agenda->enabled) && ! empty($user->rights->agenda->myactions->create))
  571. {
  572. $colspan++;
  573. print_liste_field_titre('');
  574. }
  575. // Edit
  576. print_liste_field_titre('');
  577. print "</tr>\n";
  578. $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 ";
  579. $sql .= ", p.civility as civility_id, p.address, p.zip, p.town";
  580. $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as p";
  581. $sql .= " WHERE p.fk_soc = ".$object->id;
  582. if ($search_status!='' && $search_status != '-1') $sql .= " AND p.statut = ".$db->escape($search_status);
  583. if ($search_name) $sql .= " AND (p.lastname LIKE '%".$db->escape($search_name)."%' OR p.firstname LIKE '%".$db->escape($search_name)."%')";
  584. $sql.= " ORDER BY $sortfield $sortorder";
  585. dol_syslog('core/lib/company.lib.php :: show_contacts', LOG_DEBUG);
  586. $result = $db->query($sql);
  587. if (! $result) dol_print_error($db);
  588. $num = $db->num_rows($result);
  589. $var=true;
  590. if ($num || (GETPOST('button_search') || GETPOST('button_search.x') || GETPOST('button_search_x')))
  591. {
  592. print '<tr class="liste_titre">';
  593. // Name - Position
  594. print '<td class="liste_titre">';
  595. print '<input type="text" class="flat" name="search_name" size="20" value="'.$search_name.'">';
  596. print '</td>';
  597. // Address / Phone
  598. print '<td>';
  599. //print '<input type="text" class="flat" name="search_addressphone" size="20" value="'.$search_addressphone.'">';
  600. print '</td>';
  601. // Email
  602. print '<td>&nbsp;</td>';
  603. // Status
  604. print '<td class="liste_titre maxwidthonsmartphone">';
  605. print $form->selectarray('search_status', array('-1'=>'','0'=>$contactstatic->LibStatut(0,1),'1'=>$contactstatic->LibStatut(1,1)),$search_status);
  606. print '</td>';
  607. // Add to agenda
  608. if (! empty($conf->agenda->enabled) && $user->rights->agenda->myactions->create)
  609. {
  610. $colspan++;
  611. print '<td>&nbsp;</td>';
  612. }
  613. // Edit
  614. print '<td class="liste_titre" align="right">';
  615. print '<input type="image" class="liste_titre" name="button_search" src="'.img_picto($langs->trans("Search"),'search.png','','',1).'" value="'.dol_escape_htmltag($langs->trans("Search")).'" title="'.dol_escape_htmltag($langs->trans("Search")).'">';
  616. print '</td>';
  617. print "</tr>";
  618. $i=0;
  619. while ($i < $num)
  620. {
  621. $obj = $db->fetch_object($result);
  622. $var = !$var;
  623. $contactstatic->id = $obj->rowid;
  624. $contactstatic->ref = $obj->ref;
  625. $contactstatic->statut = $obj->statut;
  626. $contactstatic->lastname = $obj->lastname;
  627. $contactstatic->firstname = $obj->firstname;
  628. $contactstatic->civility_id = $obj->civility_id;
  629. $contactstatic->poste = $obj->poste;
  630. $contactstatic->address = $obj->address;
  631. $contactstatic->zip = $obj->zip;
  632. $contactstatic->town = $obj->town;
  633. $contactstatic->phone_pro = $obj->phone_pro;
  634. $contactstatic->phone_mobile = $obj->phone_mobile;
  635. $contactstatic->phone_perso = $obj->phone_perso;
  636. $contactstatic->email = $obj->email;
  637. $contactstatic->web = $obj->web;
  638. $contactstatic->skype = $obj->skype;
  639. $country_code = getCountry($obj->country_id, 2);
  640. $contactstatic->country_code = $country_code;
  641. print "<tr ".$bc[$var].">";
  642. print '<td>';
  643. print $contactstatic->getNomUrl(1,'',0,'&backtopage='.urlencode($backtopage));
  644. print '</td><td>';
  645. if ($obj->poste) print $obj->poste;
  646. print '</td>';
  647. // Address and phone
  648. print '<td>';
  649. print $contactstatic->getBannerAddress('contact', $object);
  650. print '</td>';
  651. // Status
  652. print '<td>'.$contactstatic->getLibStatut(5).'</td>';
  653. // Add to agenda
  654. if (! empty($conf->agenda->enabled) && $user->rights->agenda->myactions->create)
  655. {
  656. print '<td align="center">';
  657. print '<a href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create&actioncode=&contactid='.$obj->rowid.'&socid='.$object->id.'&backtopage='.urlencode($backtopage).'">';
  658. print img_object($langs->trans("Event"),"action");
  659. print '</a></td>';
  660. }
  661. // Edit
  662. if ($user->rights->societe->contact->creer)
  663. {
  664. print '<td align="right">';
  665. print '<a href="'.DOL_URL_ROOT.'/contact/card.php?action=edit&amp;id='.$obj->rowid.'&amp;backtopage='.urlencode($backtopage).'">';
  666. print img_edit();
  667. print '</a></td>';
  668. }
  669. else print '<td>&nbsp;</td>';
  670. print "</tr>\n";
  671. $i++;
  672. }
  673. }
  674. else
  675. {
  676. print "<tr ".$bc[! $var].">";
  677. print '<td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("None").'</td>';
  678. print "</tr>\n";
  679. }
  680. print "\n</table>\n";
  681. print '</form>'."\n";
  682. return $i;
  683. }
  684. /**
  685. * Show html area for list of addresses
  686. *
  687. * @param Conf $conf Object conf
  688. * @param Translate $langs Object langs
  689. * @param DoliDB $db Database handler
  690. * @param Societe $object Third party object
  691. * @param string $backtopage Url to go once address is created
  692. * @return void
  693. */
  694. function show_addresses($conf,$langs,$db,$object,$backtopage='')
  695. {
  696. global $user;
  697. global $bc;
  698. require_once DOL_DOCUMENT_ROOT.'/societe/class/address.class.php';
  699. $addressstatic = new Address($db);
  700. $num = $addressstatic->fetch_lines($object->id);
  701. $buttoncreate='';
  702. if ($user->rights->societe->creer)
  703. {
  704. $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";
  705. }
  706. print "\n";
  707. print load_fiche_titre($langs->trans("AddressesForCompany"),$buttoncreate,'');
  708. print "\n".'<table class="noborder" width="100%">'."\n";
  709. print '<tr class="liste_titre"><td>'.$langs->trans("Label").'</td>';
  710. print '<td>'.$langs->trans("CompanyName").'</td>';
  711. print '<td>'.$langs->trans("Town").'</td>';
  712. print '<td>'.$langs->trans("Country").'</td>';
  713. print '<td>'.$langs->trans("Phone").'</td>';
  714. print '<td>'.$langs->trans("Fax").'</td>';
  715. print "<td>&nbsp;</td>";
  716. print "</tr>";
  717. if ($num > 0)
  718. {
  719. $var=true;
  720. foreach ($addressstatic->lines as $address)
  721. {
  722. $var = !$var;
  723. print "<tr ".$bc[$var].">";
  724. print '<td>';
  725. $addressstatic->id = $address->id;
  726. $addressstatic->label = $address->label;
  727. print $addressstatic->getNomUrl(1);
  728. print '</td>';
  729. print '<td>'.$address->name.'</td>';
  730. print '<td>'.$address->town.'</td>';
  731. $img=picto_from_langcode($address->country_code);
  732. print '<td>'.($img?$img.' ':'').$address->country.'</td>';
  733. // Lien click to dial
  734. print '<td>';
  735. print dol_print_phone($address->phone,$address->country_code,$address->id,$object->id,'AC_TEL');
  736. print '</td>';
  737. print '<td>';
  738. print dol_print_phone($address->fax,$address->country_code,$address->id,$object->id,'AC_FAX');
  739. print '</td>';
  740. if ($user->rights->societe->creer)
  741. {
  742. print '<td align="right">';
  743. print '<a href="'.DOL_URL_ROOT.'/comm/address.php?action=edit&amp;id='.$address->id.'&amp;socid='.$object->id.'&amp;backtopage='.urlencode($backtopage).'">';
  744. print img_edit();
  745. print '</a></td>';
  746. }
  747. print "</tr>\n";
  748. }
  749. }
  750. else
  751. {
  752. //print "<tr ".$bc[$var].">";
  753. //print '<td>'.$langs->trans("NoAddressYetDefined").'</td>';
  754. //print "</tr>\n";
  755. }
  756. print "\n</table>\n";
  757. print "<br>\n";
  758. return $num;
  759. }
  760. /**
  761. * Show html area with actions to do
  762. *
  763. * @param Conf $conf Object conf
  764. * @param Translate $langs Object langs
  765. * @param DoliDB $db Object db
  766. * @param Adherent|Societe $object Object third party or member
  767. * @param Contact $objcon Object contact
  768. * @param int $noprint Return string but does not output it
  769. * @return mixed Return html part or void if noprint is 1
  770. */
  771. function show_actions_todo($conf,$langs,$db,$object,$objcon='',$noprint=0)
  772. {
  773. global $bc,$user,$conf;
  774. // Check parameters
  775. if (! is_object($object)) dol_print_error('','BadParameter');
  776. $now=dol_now('tzuser');
  777. $out='';
  778. if (! empty($conf->agenda->enabled))
  779. {
  780. require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
  781. $actionstatic=new ActionComm($db);
  782. $userstatic=new User($db);
  783. $contactstatic = new Contact($db);
  784. $out.="\n";
  785. $out.='<table width="100%" class="noborder">';
  786. $out.='<tr class="liste_titre">';
  787. if($conf->global->AGENDA_USE_EVENT_TYPE) $out.='<td colspan="3">';
  788. else $out.='<td colspan="2">';
  789. if (get_class($object) == 'Societe') $out.='<a href="'.DOL_URL_ROOT.'/comm/action/listactions.php?socid='.$object->id.'&amp;status=todo">';
  790. $out.=$langs->trans("ActionsToDoShort");
  791. if (get_class($object) == 'Societe') $out.='</a>';
  792. $out.='</td>';
  793. if($conf->global->AGENDA_USE_EVENT_TYPE) {
  794. $out.='<td>';
  795. $out.=$langs->trans("Type");
  796. $out.='</td>';
  797. $out.='<td colspan="4" align="right">';
  798. } else {
  799. $out.='<td colspan="5" align="right">';
  800. }
  801. $out.='</td>';
  802. $out.='</tr>';
  803. $sql = "SELECT a.id, a.label,";
  804. $sql.= " a.datep as dp,";
  805. $sql.= " a.datep2 as dp2,";
  806. $sql.= " a.percent,";
  807. $sql.= " a.fk_user_author, a.fk_contact,";
  808. $sql.= " a.fk_element, a.elementtype,";
  809. $sql.= " c.code as acode, c.libelle,";
  810. $sql.= " u.login, u.rowid";
  811. if (get_class($object) == 'Societe') $sql.= ", sp.lastname, sp.firstname";
  812. if (get_class($object) == 'Adherent') $sql.= ", m.lastname, m.firstname";
  813. $sql.= " FROM ".MAIN_DB_PREFIX."user as u, ".MAIN_DB_PREFIX."actioncomm as a";
  814. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_actioncomm as c ON a.fk_action = c.id";
  815. if (get_class($object) == 'Societe') $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople as sp ON a.fk_contact = sp.rowid";
  816. if (get_class($object) == 'Adherent') $sql.= ", ".MAIN_DB_PREFIX."adherent as m";
  817. $sql.= " WHERE u.rowid = a.fk_user_author";
  818. $sql.= " AND a.entity IN (".getEntity('agenda', 1).")";
  819. if (get_class($object) == 'Adherent')
  820. {
  821. $sql.= " AND a.fk_element = m.rowid AND a.elementtype = 'member'";
  822. if (! empty($object->id)) $sql.= " AND a.fk_element = ".$object->id;
  823. }
  824. if (get_class($object) == 'Societe' && $object->id) $sql.= " AND a.fk_soc = ".$object->id;
  825. if (! empty($objcon->id)) $sql.= " AND a.fk_contact = ".$objcon->id;
  826. $sql.= " AND ((a.percent >= 0 AND a.percent < 100) OR (a.percent = -1 AND a.datep > '".$db->idate($now)."'))";
  827. $sql.= " ORDER BY a.datep DESC, a.id DESC";
  828. dol_syslog("company.lib::show_actions_todo", LOG_DEBUG);
  829. $result=$db->query($sql);
  830. if ($result)
  831. {
  832. $i = 0 ;
  833. $num = $db->num_rows($result);
  834. $var=true;
  835. if ($num)
  836. {
  837. while ($i < $num)
  838. {
  839. $var = !$var;
  840. $obj = $db->fetch_object($result);
  841. $actionstatic->fetch($obj->id);
  842. $datep=$db->jdate($obj->dp);
  843. $datep2=$db->jdate($obj->dp2);
  844. $out.="<tr ".$bc[$var].">";
  845. // Date
  846. $out.='<td width="120" align="left" class="nowrap">';
  847. $out.=dol_print_date($datep,'dayhour');
  848. if ($datep2 && $datep2 != $datep)
  849. {
  850. $tmpa=dol_getdate($datep,true);
  851. $tmpb=dol_getdate($datep2,true);
  852. if ($tmpa['mday'] == $tmpb['mday'] && $tmpa['mon'] == $tmpb['mon'] && $tmpa['year'] == $tmpb['year']) $out.='-'.dol_print_date($datep2,'hour');
  853. else $out.='-'.dol_print_date($datep2,'dayhour');
  854. }
  855. $out.="</td>\n";
  856. // Picto warning
  857. $out.='<td width="16">';
  858. if ($obj->percent >= 0 && $datep && $datep < ($now - ($conf->global->MAIN_DELAY_ACTIONS_TODO *60*60*24)) ) $out.=' '.img_warning($langs->trans("Late"));
  859. else $out.='&nbsp;';
  860. $out.='</td>';
  861. $actionstatic->type_code=$obj->acode;
  862. $transcode=$langs->trans("Action".$obj->acode);
  863. $libelle=($transcode!="Action".$obj->acode?$transcode:$obj->libelle);
  864. //$actionstatic->libelle=$libelle;
  865. $actionstatic->libelle=$obj->label;
  866. $actionstatic->id=$obj->id;
  867. //$out.='<td width="140">'.$actionstatic->getNomUrl(1,16).'</td>';
  868. // Title of event
  869. //$out.='<td colspan="2">'.dol_trunc($obj->label,40).'</td>';
  870. $out.='<td>'.$actionstatic->getNomUrl(1,120).'</td>';
  871. if($conf->global->AGENDA_USE_EVENT_TYPE) {
  872. $out.= '<td>';
  873. $out.=$actionstatic->type;
  874. $out.='</td>';
  875. }
  876. // Contact pour cette action
  877. if (empty($objcon->id) && $obj->fk_contact > 0)
  878. {
  879. $contactstatic->lastname=$obj->lastname;
  880. $contactstatic->firstname=$obj->firstname;
  881. $contactstatic->id=$obj->fk_contact;
  882. $out.='<td width="120">'.$contactstatic->getNomUrl(1,'',10).'</td>';
  883. }
  884. else
  885. {
  886. $out.='<td>&nbsp;</td>';
  887. }
  888. $out.='<td width="80" class="nowrap">';
  889. //$userstatic->id=$obj->fk_user_author;
  890. //$userstatic->login=$obj->login;
  891. //$out.=$userstatic->getLoginUrl(1);
  892. $userstatic->fetch($obj->fk_user_author);
  893. $out.=$userstatic->getNomUrl(1);
  894. $out.='</td>';
  895. // Statut
  896. $out.='<td class="nowrap" width="20">'.$actionstatic->LibStatut($obj->percent,3).'</td>';
  897. $out.="</tr>\n";
  898. $i++;
  899. }
  900. }
  901. else
  902. {
  903. // Aucun action a faire
  904. }
  905. $db->free($result);
  906. }
  907. else
  908. {
  909. dol_print_error($db);
  910. }
  911. $out.="</table>\n";
  912. $out.="<br>\n";
  913. }
  914. if ($noprint) return $out;
  915. else print $out;
  916. }
  917. /**
  918. * Show html area with actions done
  919. *
  920. * @param Conf $conf Object conf
  921. * @param Translate $langs Object langs
  922. * @param DoliDB $db Object db
  923. * @param Adherent|Societe $object Object third party or member
  924. * @param Contact $objcon Object contact
  925. * @param int $noprint Return string but does not output it
  926. * @return mixed Return html part or void if noprint is 1
  927. * TODO change function to be able to list event linked to an object.
  928. */
  929. function show_actions_done($conf,$langs,$db,$object,$objcon='',$noprint=0)
  930. {
  931. global $bc,$user,$conf;
  932. // Check parameters
  933. if (! is_object($object)) dol_print_error('','BadParameter');
  934. $out='';
  935. $histo=array();
  936. $numaction = 0 ;
  937. $now=dol_now('tzuser');
  938. if (! empty($conf->agenda->enabled))
  939. {
  940. // Recherche histo sur actioncomm
  941. $sql = "SELECT a.id, a.label,";
  942. $sql.= " a.datep as dp,";
  943. $sql.= " a.datep2 as dp2,";
  944. $sql.= " a.note, a.percent,";
  945. $sql.= " a.fk_element, a.elementtype,";
  946. $sql.= " a.fk_user_author, a.fk_contact,";
  947. $sql.= " c.code as acode, c.libelle,";
  948. $sql.= " u.login, u.rowid as user_id";
  949. if (get_class($object) == 'Societe') $sql.= ", sp.lastname, sp.firstname";
  950. if (get_class($object) == 'Adherent') $sql.= ", m.lastname, m.firstname";
  951. $sql.= " FROM ".MAIN_DB_PREFIX."user as u, ".MAIN_DB_PREFIX."actioncomm as a";
  952. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_actioncomm as c ON a.fk_action = c.id";
  953. if (get_class($object) == 'Societe') $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople as sp ON a.fk_contact = sp.rowid";
  954. if (get_class($object) == 'Adherent') $sql.= ", ".MAIN_DB_PREFIX."adherent as m";
  955. $sql.= " WHERE u.rowid = a.fk_user_author";
  956. $sql.= " AND a.entity IN (".getEntity('agenda', 1).")";
  957. if (get_class($object) == 'Societe' && $object->id) $sql.= " AND a.fk_soc = ".$object->id;
  958. if (get_class($object) == 'Adherent') $sql.= " AND a.fk_element = m.rowid AND a.elementtype = 'member'";
  959. if (get_class($object) == 'Adherent' && $object->id) $sql.= " AND a.fk_element = ".$object->id;
  960. if (is_object($objcon) && $objcon->id) $sql.= " AND a.fk_contact = ".$objcon->id;
  961. $sql.= " AND (a.percent = 100 OR (a.percent = -1 AND a.datep <= '".$db->idate($now)."'))";
  962. $sql.= " ORDER BY a.datep DESC, a.id DESC";
  963. dol_syslog("company.lib::show_actions_done", LOG_DEBUG);
  964. $resql=$db->query($sql);
  965. if ($resql)
  966. {
  967. $i = 0 ;
  968. $num = $db->num_rows($resql);
  969. $var=true;
  970. while ($i < $num)
  971. {
  972. $obj = $db->fetch_object($resql);
  973. $histo[$numaction]=array(
  974. 'type'=>'action',
  975. 'id'=>$obj->id,
  976. 'datestart'=>$db->jdate($obj->dp),
  977. 'dateend'=>$db->jdate($obj->dp2),
  978. 'note'=>$obj->label,
  979. 'percent'=>$obj->percent,
  980. 'acode'=>$obj->acode,
  981. 'libelle'=>$obj->libelle,
  982. 'userid'=>$obj->user_id,
  983. 'login'=>$obj->login,
  984. 'contact_id'=>$obj->fk_contact,
  985. 'lastname'=>$obj->lastname,
  986. 'firstname'=>$obj->firstname,
  987. 'fk_element'=>$obj->fk_element,
  988. 'elementtype'=>$obj->elementtype
  989. );
  990. $numaction++;
  991. $i++;
  992. }
  993. }
  994. else
  995. {
  996. dol_print_error($db);
  997. }
  998. }
  999. if (! empty($conf->mailing->enabled) && ! empty($objcon->email))
  1000. {
  1001. $langs->load("mails");
  1002. // Recherche histo sur mailing
  1003. $sql = "SELECT m.rowid as id, mc.date_envoi as da, m.titre as note, '100' as percentage,";
  1004. $sql.= " 'AC_EMAILING' as acode,";
  1005. $sql.= " u.rowid as user_id, u.login"; // User that valid action
  1006. $sql.= " FROM ".MAIN_DB_PREFIX."mailing as m, ".MAIN_DB_PREFIX."mailing_cibles as mc, ".MAIN_DB_PREFIX."user as u";
  1007. $sql.= " WHERE mc.email = '".$db->escape($objcon->email)."'"; // Search is done on email.
  1008. $sql.= " AND mc.statut = 1";
  1009. $sql.= " AND u.rowid = m.fk_user_valid";
  1010. $sql.= " AND mc.fk_mailing=m.rowid";
  1011. $sql.= " ORDER BY mc.date_envoi DESC, m.rowid DESC";
  1012. dol_syslog("company.lib::show_actions_done", LOG_DEBUG);
  1013. $resql=$db->query($sql);
  1014. if ($resql)
  1015. {
  1016. $i = 0 ;
  1017. $num = $db->num_rows($resql);
  1018. $var=true;
  1019. while ($i < $num)
  1020. {
  1021. $obj = $db->fetch_object($resql);
  1022. $histo[$numaction]=array(
  1023. 'type'=>'mailing',
  1024. 'id'=>$obj->id,
  1025. 'datestart'=>$db->jdate($obj->da),
  1026. 'dateend'=>$db->jdate($obj->da),
  1027. 'note'=>$obj->note,
  1028. 'percent'=>$obj->percentage,
  1029. 'acode'=>$obj->acode,
  1030. 'userid'=>$obj->user_id,
  1031. 'login'=>$obj->login
  1032. );
  1033. $numaction++;
  1034. $i++;
  1035. }
  1036. $db->free($resql);
  1037. }
  1038. else
  1039. {
  1040. dol_print_error($db);
  1041. }
  1042. }
  1043. if (! empty($conf->agenda->enabled) || (! empty($conf->mailing->enabled) && ! empty($objcon->email)))
  1044. {
  1045. require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
  1046. require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
  1047. require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
  1048. require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  1049. $actionstatic=new ActionComm($db);
  1050. $userstatic=new User($db);
  1051. $contactstatic = new Contact($db);
  1052. // TODO uniformize
  1053. $propalstatic=new Propal($db);
  1054. $orderstatic=new Commande($db);
  1055. $facturestatic=new Facture($db);
  1056. $out.="\n";
  1057. $out.='<table class="noborder" width="100%">';
  1058. $out.='<tr class="liste_titre">';
  1059. if($conf->global->AGENDA_USE_EVENT_TYPE) $out.='<td colspan="3">';
  1060. else $out.='<td colspan="2">';
  1061. if (get_class($object) == 'Societe') $out.='<a href="'.DOL_URL_ROOT.'/comm/action/listactions.php?socid='.$object->id.'&amp;status=done">';
  1062. $out.=$langs->trans("ActionsDoneShort");
  1063. if (get_class($object) == 'Societe') $out.='</a>';
  1064. $out.='</td>';
  1065. if($conf->global->AGENDA_USE_EVENT_TYPE) {
  1066. $out.='<td>';
  1067. $out.=$langs->trans("Type");
  1068. $out.='</td>';
  1069. $out.='<td colspan="4" align="right">';
  1070. } else {
  1071. $out.='<td colspan="5" align="right">';
  1072. }
  1073. $out.='</td>';
  1074. $out.='</tr>';
  1075. foreach ($histo as $key=>$value)
  1076. {
  1077. $var=!$var;
  1078. $out.="<tr ".$bc[$var].">";
  1079. $actionstatic->fetch($histo[$key]['id']);
  1080. // Champ date
  1081. $out.='<td width="120" class="nowrap">';
  1082. $out.=dol_print_date($histo[$key]['datestart'],'dayhour');
  1083. if ($histo[$key]['dateend'] && $histo[$key]['dateend'] != $histo[$key]['datestart'])
  1084. {
  1085. $tmpa=dol_getdate($histo[$key]['datestart'],true);
  1086. $tmpb=dol_getdate($histo[$key]['dateend'],true);
  1087. if ($tmpa['mday'] == $tmpb['mday'] && $tmpa['mon'] == $tmpb['mon'] && $tmpa['year'] == $tmpb['year']) $out.='-'.dol_print_date($histo[$key]['dateend'],'hour');
  1088. else $out.='-'.dol_print_date($histo[$key]['dateend'],'dayhour');
  1089. }
  1090. $out.="</td>\n";
  1091. // Picto
  1092. $out.='<td width="16">&nbsp;</td>';
  1093. // Action
  1094. $out.='<td>';
  1095. if (isset($histo[$key]['type']) && $histo[$key]['type']=='action')
  1096. {
  1097. $actionstatic->type_code=$histo[$key]['acode'];
  1098. $transcode=$langs->trans("Action".$histo[$key]['acode']);
  1099. $libelle=($transcode!="Action".$histo[$key]['acode']?$transcode:$histo[$key]['libelle']);
  1100. //$actionstatic->libelle=$libelle;
  1101. $actionstatic->libelle=$histo[$key]['note'];
  1102. $actionstatic->id=$histo[$key]['id'];
  1103. $out.=$actionstatic->getNomUrl(1,120);
  1104. }
  1105. if (isset($histo[$key]['type']) && $histo[$key]['type']=='mailing')
  1106. {
  1107. $out.='<a href="'.DOL_URL_ROOT.'/comm/mailing/card.php?id='.$histo[$key]['id'].'">'.img_object($langs->trans("ShowEMailing"),"email").' ';
  1108. $transcode=$langs->trans("Action".$histo[$key]['acode']);
  1109. $libelle=($transcode!="Action".$histo[$key]['acode']?$transcode:'Send mass mailing');
  1110. $out.=dol_trunc($libelle,120);
  1111. }
  1112. $out.='</td>';
  1113. if($conf->global->AGENDA_USE_EVENT_TYPE) {
  1114. $out.='<td>';
  1115. $out.=$actionstatic->type;
  1116. $out.='</td>';
  1117. }
  1118. // Title of event
  1119. //$out.='<td>'.dol_trunc($histo[$key]['note'], 40).'</td>';
  1120. // Objet lie
  1121. // TODO uniformize
  1122. $out.='<td>';
  1123. //var_dump($histo[$key]['elementtype']);
  1124. if (isset($histo[$key]['elementtype']))
  1125. {
  1126. if ($histo[$key]['elementtype'] == 'propal' && ! empty($conf->propal->enabled))
  1127. {
  1128. //$propalstatic->ref=$langs->trans("ProposalShort");
  1129. //$propalstatic->id=$histo[$key]['fk_element'];
  1130. if ($propalstatic->fetch($histo[$key]['fk_element'])>0) {
  1131. $propalstatic->type=$histo[$key]['ftype'];
  1132. $out.=$propalstatic->getNomUrl(1);
  1133. } else {
  1134. $out.= $langs->trans("ProposalDeleted");
  1135. }
  1136. }
  1137. elseif (($histo[$key]['elementtype'] == 'order' || $histo[$key]['elementtype'] == 'commande') && ! empty($conf->commande->enabled))
  1138. {
  1139. //$orderstatic->ref=$langs->trans("Order");
  1140. //$orderstatic->id=$histo[$key]['fk_element'];
  1141. if ($orderstatic->fetch($histo[$key]['fk_element'])>0) {
  1142. $orderstatic->type=$histo[$key]['ftype'];
  1143. $out.=$orderstatic->getNomUrl(1);
  1144. } else {
  1145. $out.= $langs->trans("OrderDeleted");
  1146. }
  1147. }
  1148. elseif (($histo[$key]['elementtype'] == 'invoice' || $histo[$key]['elementtype'] == 'facture') && ! empty($conf->facture->enabled))
  1149. {
  1150. //$facturestatic->ref=$langs->trans("Invoice");
  1151. //$facturestatic->id=$histo[$key]['fk_element'];
  1152. if ($facturestatic->fetch($histo[$key]['fk_element'])>0) {
  1153. $facturestatic->type=$histo[$key]['ftype'];
  1154. $out.=$facturestatic->getNomUrl(1,'compta');
  1155. } else {
  1156. $out.= $langs->trans("InvoiceDeleted");
  1157. }
  1158. }
  1159. else $out.='&nbsp;';
  1160. }
  1161. else $out.='&nbsp;';
  1162. $out.='</td>';
  1163. // Contact pour cette action
  1164. if (! empty($objcon->id) && isset($histo[$key]['contact_id']) && $histo[$key]['contact_id'] > 0)
  1165. {
  1166. $contactstatic->lastname=$histo[$key]['lastname'];
  1167. $contactstatic->firstname=$histo[$key]['firstname'];
  1168. $contactstatic->id=$histo[$key]['contact_id'];
  1169. $out.='<td width="120">'.$contactstatic->getNomUrl(1,'',10).'</td>';
  1170. }
  1171. else
  1172. {
  1173. $out.='<td>&nbsp;</td>';
  1174. }
  1175. // Auteur
  1176. $out.='<td class="nowrap" width="80">';
  1177. //$userstatic->id=$histo[$key]['userid'];
  1178. //$userstatic->login=$histo[$key]['login'];
  1179. //$out.=$userstatic->getLoginUrl(1);
  1180. $userstatic->fetch($histo[$key]['userid']);
  1181. $out.=$userstatic->getNomUrl(1);
  1182. $out.='</td>';
  1183. // Statut
  1184. $out.='<td class="nowrap" width="20">'.$actionstatic->LibStatut($histo[$key]['percent'],3).'</td>';
  1185. $out.="</tr>\n";
  1186. $i++;
  1187. }
  1188. $out.="</table>\n";
  1189. //$out.="<br>\n";
  1190. }
  1191. if ($noprint) return $out;
  1192. else print $out;
  1193. }
  1194. /**
  1195. * Show html area for list of subsidiaries
  1196. *
  1197. * @param Conf $conf Object conf
  1198. * @param Translate $langs Object langs
  1199. * @param DoliDB $db Database handler
  1200. * @param Societe $object Third party object
  1201. * @return void
  1202. */
  1203. function show_subsidiaries($conf,$langs,$db,$object)
  1204. {
  1205. global $user;
  1206. global $bc;
  1207. $i=-1;
  1208. $sql = "SELECT s.rowid, s.nom as name, s.address, s.zip, s.town, s.code_client, s.canvas";
  1209. $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
  1210. $sql.= " WHERE s.parent = ".$object->id;
  1211. $sql.= " AND s.entity IN (".getEntity('societe', 1).")";
  1212. $sql.= " ORDER BY s.nom";
  1213. $result = $db->query($sql);
  1214. $num = $db->num_rows($result);
  1215. if ($num)
  1216. {
  1217. $socstatic = new Societe($db);
  1218. print load_fiche_titre($langs->trans("Subsidiaries"));
  1219. print "\n".'<table class="noborder" width="100%">'."\n";
  1220. print '<tr class="liste_titre"><td>'.$langs->trans("Company").'</td>';
  1221. print '<td>'.$langs->trans("Address").'</td><td>'.$langs->trans("Zip").'</td>';
  1222. print '<td>'.$langs->trans("Town").'</td><td>'.$langs->trans("CustomerCode").'</td>';
  1223. print "<td>&nbsp;</td>";
  1224. print "</tr>";
  1225. $i=0;
  1226. $var=true;
  1227. while ($i < $num)
  1228. {
  1229. $obj = $db->fetch_object($result);
  1230. $var = !$var;
  1231. print "<tr ".$bc[$var].">";
  1232. print '<td>';
  1233. $socstatic->id = $obj->rowid;
  1234. $socstatic->name = $obj->name;
  1235. $socstatic->canvas = $obj->canvas;
  1236. print $socstatic->getNomUrl(1);
  1237. print '</td>';
  1238. print '<td>'.$obj->address.'</td>';
  1239. print '<td>'.$obj->zip.'</td>';
  1240. print '<td>'.$obj->town.'</td>';
  1241. print '<td>'.$obj->code_client.'</td>';
  1242. print '<td align="center">';
  1243. print '<a href="'.DOL_URL_ROOT.'/societe/soc.php?socid='.$obj->rowid.'&amp;action=edit">';
  1244. print img_edit();
  1245. print '</a></td>';
  1246. print "</tr>\n";
  1247. $i++;
  1248. }
  1249. print "\n</table>\n";
  1250. }
  1251. print "<br>\n";
  1252. return $i;
  1253. }