company.lib.php 55 KB

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