company.lib.php 50 KB

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