PageRenderTime 48ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/comm/prospect.old/fiche.php

https://bitbucket.org/speedealing/speedealing
PHP | 412 lines | 284 code | 64 blank | 64 comment | 64 complexity | e5c92e11b98500867bc384e7db237a4f MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  1. <?php
  2. /* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
  5. * Copyright (C) 2010-2011 Herve Prot <herve.prot@symeos.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/comm/prospect/fiche.php
  22. * \ingroup prospect
  23. * \brief Page de la fiche prospect
  24. */
  25. require_once '../../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT . '/societe/lib/societe.lib.php';
  27. require_once DOL_DOCUMENT_ROOT . '/comm/prospect/class/prospect.class.php';
  28. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formcompany.class.php';
  29. require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php';
  30. //require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
  31. if (!empty($conf->adherent->enabled))
  32. require_once DOL_DOCUMENT_ROOT . '/adherent/class/adherent.class.php';
  33. if (!empty($conf->propal->enabled))
  34. require_once DOL_DOCUMENT_ROOT . '/comm/propal/class/propal.class.php';
  35. $langs->load('companies');
  36. $langs->load('lead@lead');
  37. $langs->load('projects');
  38. $langs->load('propal');
  39. $langs->load('commercial');
  40. // Security check
  41. $socid = GETPOST('socid', 'alpha');
  42. if ($user->societe_id)
  43. $socid = $user->societe_id;
  44. $result = restrictedArea($user, 'societe', $socid, '&societe');
  45. $object = new Prospect($db);
  46. /*
  47. * Actions
  48. */
  49. if ($_GET["action"] == 'cstc') {
  50. $sql = "UPDATE " . MAIN_DB_PREFIX . "societe SET fk_stcomm = " . $_GET["stcomm"];
  51. $sql .= " WHERE rowid = " . $_GET["socid"];
  52. $db->query($sql);
  53. $actioncomm = new ActionComm($db);
  54. $actioncomm->addAutoTask('AC_PROSPECT', $_GET["stcomm"] . " Statut de prospection : " . $obj->libelle, $_GET["socid"], '', '');
  55. if ($objp->fk_stcomm == 0 && $_GET["stcomm"] > 0) {
  56. $actioncomm = new ActionComm($db);
  57. $actioncomm->addAutoTask('AC_SUSP', "Statut de prospection : " . $obj->libelle, $_GET["socid"], '', '');
  58. }
  59. if (!empty($_GET["backtopage"])) {
  60. header("Location: " . $_GET["backtopage"]);
  61. }
  62. }
  63. // set prospect level
  64. if ($_POST["action"] == 'setprospectlevel' && $user->rights->societe->creer) {
  65. $object->fetch($_GET["socid"]);
  66. $object->fk_prospectlevel = $_POST['prospect_level_id'];
  67. $sql = "UPDATE " . MAIN_DB_PREFIX . "societe SET fk_prospectlevel='" . $_POST['prospect_level_id'];
  68. $sql.= "' WHERE rowid='" . $_GET["socid"] . "'";
  69. $result = $db->query($sql);
  70. if (!$result)
  71. dol_print_error($result);
  72. }
  73. /* * *******************************************************************************
  74. *
  75. * Mode fiche
  76. *
  77. * ******************************************************************************* */
  78. llxHeader();
  79. $now = dol_now();
  80. $form = new Form($db);
  81. $formcompany = new FormCompany($db);
  82. if ($socid > 0) {
  83. $actionstatic = new ActionComm($db);
  84. $result = $object->fetch($socid);
  85. if ($result < 0) {
  86. dol_print_error($db);
  87. exit;
  88. }
  89. /*
  90. * Affichage onglets
  91. */
  92. $head = societe_prepare_head($object);
  93. dol_fiche_head($head, 'prospect', $langs->trans("ThirdParty"), 0, 'company');
  94. print '<table width="100%" class="notopnoleftnoright">';
  95. print '<tr><td valign="top" width="50%" class="notopnoleft">';
  96. print '<table class="border" width="100%">';
  97. print '<tr><td width="25%">' . $langs->trans("ThirdPartyName") . '</td><td colspan="3">';
  98. $object->next_prev_filter = "te.client in (2,3)";
  99. print $form->showrefnav($object, 'socid', '', ($user->societe_id ? 0 : 1), 'rowid', 'nom', '', '');
  100. print '</td></tr>';
  101. // Address
  102. print '<tr><td valign="top">' . $langs->trans("Address") . '</td><td colspan="3">';
  103. dol_print_address($object->address, 'gmap', 'thirdparty', $object->id);
  104. print "</td></tr>";
  105. // Zip / Town
  106. print '<tr><td nowrap="nowrap">' . $langs->trans('Zip') . ' / ' . $langs->trans("Town") . '</td><td colspan="3">' . $object->zip . (($object->zip && $object->town) ? ' / ' : '') . $societe->town . '</td>';
  107. print '</tr>';
  108. // Country
  109. print '<tr><td>' . $langs->trans("Country") . '</td><td colspan="3">';
  110. $img = picto_from_langcode($object->country_code);
  111. if ($object->isInEEC())
  112. print $form->textwithpicto(($img ? $img . ' ' : '') . $object->country, $langs->trans("CountryIsInEEC"), 1, 0);
  113. else
  114. print ($img ? $img . ' ' : '') . $object->country;
  115. print '</td></tr>';
  116. // Phone
  117. print '<tr><td>' . $langs->trans("Phone") . '</td><td style="min-width: 25%;">' . dol_print_phone($object->tel, $object->country_code, 0, $object->id, 'AC_TEL') . '</td>';
  118. print '<td>' . $langs->trans("Fax") . '</td><td style="min-width: 25%;">' . dol_print_phone($object->fax, $object->country_code) . '</td></tr>';
  119. // EMail
  120. print '<td>' . $langs->trans('EMail') . '</td><td colspan="3">' . dol_print_email($object->email, 0, $object->id, 'AC_EMAIL') . '</td></tr>';
  121. // Web
  122. print '<tr><td>' . $langs->trans("Web") . "</td><td colspan=\"3\"><a href=\"http://$object->url\">$object->url</a></td></tr>";
  123. // Level of prospect
  124. print '<tr><td nowrap>';
  125. print '<table width="100%" class="nobordernopadding"><tr><td nowrap>';
  126. print $langs->trans('ProspectLevelShort');
  127. print '<td>';
  128. if (($_GET['action'] != 'editlevel') && $user->rights->societe->creer)
  129. print '<td align="right"><a href="' . $_SERVER["PHP_SELF"] . '?action=editlevel&amp;socid=' . $object->id . '">' . img_edit($langs->trans('SetLevel'), 1) . '</a></td>';
  130. print '</tr></table>';
  131. print '</td><td colspan="3">';
  132. if ($_GET['action'] == 'editlevel') {
  133. $formcompany->form_prospect_level($_SERVER['PHP_SELF'] . '?socid=' . $object->id, $object->fk_prospectlevel, 'prospect_level_id', 1);
  134. } else {
  135. print $object->getLibLevel();
  136. //$formcompany->form_prospect_level($_SERVER['PHP_SELF'].'?socid='.$objsoc->id,$objsoc->mode_reglement,'none');
  137. }
  138. print "</td>";
  139. print '</tr>';
  140. // Multiprice level
  141. if (!empty($conf->global->PRODUIT_MULTIPRICES)) {
  142. print '<tr><td nowrap>';
  143. print '<table width="100%" class="nobordernopadding"><tr><td nowrap>';
  144. print $langs->trans("PriceLevel");
  145. print '<td><td align="right">';
  146. if ($user->rights->societe->creer) {
  147. print '<a href="' . DOL_URL_ROOT . '/comm/multiprix.php?id=' . $object->id . '">' . img_edit($langs->trans("Modify")) . '</a>';
  148. }
  149. print '</td></tr></table>';
  150. print '</td><td colspan="3">' . $object->price_level . "</td>";
  151. print '</tr>';
  152. }
  153. // Status
  154. print '<tr><td>' . $langs->trans("StatusProsp") . '</td><td colspan="2">' . $object->getLibProspStatut(4) . '</td>';
  155. print '<td>';
  156. if ($object->stcomm_id != -1)
  157. print '<a href="fiche.php?socid=' . $object->id . '&amp;stcomm=-1&amp;action=cstc">' . img_action(0, -1) . '</a>';
  158. if ($object->stcomm_id != 0)
  159. print '<a href="fiche.php?socid=' . $object->id . '&amp;stcomm=0&amp;action=cstc">' . img_action(0, 0) . '</a>';
  160. if ($object->stcomm_id != 1)
  161. print '<a href="fiche.php?socid=' . $object->id . '&amp;stcomm=1&amp;action=cstc">' . img_action(0, 1) . '</a>';
  162. if ($object->stcomm_id != 2)
  163. print '<a href="fiche.php?socid=' . $object->id . '&amp;stcomm=2&amp;action=cstc">' . img_action(0, 2) . '</a>';
  164. if ($object->stcomm_id != 3)
  165. print '<a href="fiche.php?socid=' . $object->id . '&amp;stcomm=3&amp;action=cstc">' . img_action(0, 3) . '</a>';
  166. print '</td></tr>';
  167. // Sales representative
  168. include DOL_DOCUMENT_ROOT . '/societe/tpl/linesalesrepresentative.tpl.php';
  169. // Module Adherent
  170. if (!empty($conf->adherent->enabled)) {
  171. $langs->load("members");
  172. $langs->load("users");
  173. print '<tr><td width="25%" valign="top">' . $langs->trans("LinkedToSpeedealingMember") . '</td>';
  174. print '<td colspan="3">';
  175. $adh = new Adherent($db);
  176. $result = $adh->fetch('', '', $object->id);
  177. if ($result > 0) {
  178. $adh->ref = $adh->getFullName($langs);
  179. print $adh->getNomUrl(1);
  180. } else {
  181. print $langs->trans("UserNotLinkedToMember");
  182. }
  183. print '</td>';
  184. print "</tr>\n";
  185. }
  186. // Commercial
  187. print '<tr ' . $bc[$var] . '><td>';
  188. print '<table width="100%" class="nobordernopadding"><tr><td id="label">';
  189. print $langs->trans('SalesRepresentatives');
  190. print '<td><td id="value" align="right">';
  191. if ($user->rights->societe->creer)
  192. print '<a href="' . DOL_URL_ROOT . '/societe/commerciaux.php?socid=' . $societe->id . '">' . img_edit() . '</a>';
  193. else
  194. print '&nbsp;';
  195. print '</td></tr></table>';
  196. print '</td>';
  197. print '<td colspan="3">';
  198. $listsalesrepresentatives = $societe->getSalesRepresentatives($user);
  199. $nbofsalesrepresentative = sizeof($listsalesrepresentatives);
  200. if ($nbofsalesrepresentative > 3) { // We print only number
  201. print '<a href="' . DOL_URL_ROOT . '/societe/commerciaux.php?socid=' . $societe->id . '">';
  202. print $nbofsalesrepresentative;
  203. print '</a>';
  204. } else if ($nbofsalesrepresentative > 0) {
  205. $userstatic = new User($db);
  206. $i = 0;
  207. foreach ($listsalesrepresentatives as $val) {
  208. $userstatic->id = $val['id'];
  209. $userstatic->nom = $val['name'];
  210. $userstatic->prenom = $val['firstname'];
  211. print $userstatic->getNomUrl(1);
  212. $i++;
  213. if ($i < $nbofsalesrepresentative)
  214. print ', ';
  215. }
  216. }
  217. else
  218. print $langs->trans("NoSalesRepresentativeAffected");
  219. print '</td></tr>';
  220. $var = !$var;
  221. // Affichage des notes
  222. print '<tr ' . $bc[$var] . '><td valign="top">';
  223. print '<table width="100%" class="nobordernopadding"><tr><td id="label">';
  224. print $langs->trans("Note");
  225. print '</td><td align="right">';
  226. if ($user->rights->societe->creer)
  227. print '<a href="' . DOL_URL_ROOT . '/societe/socnote.php?socid=' . $societe->id . '&action=edit&backtopage=' . DOL_URL_ROOT . '/comm/prospect/fiche.php?socid=' . $societe->id . '">' . img_edit() . '</a>';
  228. else
  229. print '&nbsp;';
  230. print '</td></tr></table>';
  231. print '</td>';
  232. print '<td colspan="3" id="value">';
  233. print nl2br($societe->note);
  234. print "</td></tr>";
  235. $var = !$var;
  236. print '</table>';
  237. print "</td>\n";
  238. print '<td valign="top" width="50%" class="notopnoleftnoright">';
  239. // Nbre max d'elements des petites listes
  240. $MAXLIST = 5;
  241. $tableaushown = 0;
  242. // Lien recap
  243. print '<table class="noborder" width="100%">';
  244. print '<tr class="liste_titre">';
  245. print '<td colspan="4"><table width="100%" class="nobordernopadding"><tr><td>' . $langs->trans("Summary") . '</td>';
  246. print '<td align="right"><a href="' . DOL_URL_ROOT . '/comm/prospect/recap-prospect.php?socid=' . $object->id . '">' . $langs->trans("ShowProspectPreview") . '</a></td></tr></table></td>';
  247. print '</tr>';
  248. print '</table>';
  249. print '<br>';
  250. /*
  251. * Last proposals
  252. */
  253. if (!empty($conf->propal->enabled) && $user->rights->propale->lire) {
  254. $propal_static = new Propal($db);
  255. $sql = "SELECT s.nom, s.rowid as socid, p.rowid as propalid, p.fk_statut, p.total_ht, p.ref, p.remise, ";
  256. $sql.= " p.datep as dp, p.fin_validite as datelimite,";
  257. $sql.= " c.label as statut, c.id as statutid";
  258. $sql.= " FROM " . MAIN_DB_PREFIX . "societe as s";
  259. $sql.= ", " . MAIN_DB_PREFIX . "propal as p";
  260. $sql.= ", " . MAIN_DB_PREFIX . "c_propalst as c";
  261. $sql.= " WHERE p.fk_soc = s.rowid";
  262. $sql.= " AND p.fk_statut = c.id";
  263. $sql.= " AND p.entity = " . $conf->entity;
  264. $sql.= " AND s.rowid = " . $object->id;
  265. $sql.= " ORDER BY p.datep DESC";
  266. $resql = $db->query($sql);
  267. if ($resql) {
  268. $var = true;
  269. $i = 0;
  270. $num = $db->num_rows($resql);
  271. if ($num > 0) {
  272. print '<table class="noborder" width="100%">';
  273. print '<tr class="liste_titre">';
  274. print '<td colspan="4"><table width="100%" class="nobordernopadding"><tr><td>' . $langs->trans("LastPropals", ($num <= $MAXLIST ? "" : $MAXLIST)) . '</td><td align="right"><a href="' . DOL_URL_ROOT . '/comm/propal.php?socid=' . $object->id . '">' . $langs->trans("AllPropals") . ' (' . $num . ')</a></td>';
  275. print '<td width="20px" align="right"><a href="' . DOL_URL_ROOT . '/comm/propal/stats/index.php?socid=' . $object->id . '">' . img_picto($langs->trans("Statistics"), 'stats') . '</a></td>';
  276. print '</tr></table></td>';
  277. print '</tr>';
  278. }
  279. while ($i < $num && $i < $MAXLIST) {
  280. $objp = $db->fetch_object($resql);
  281. $var = !$var;
  282. print "<tr $bc[$var]>";
  283. print "<td><a href=\"../propal.php?id=$objp->propalid\">";
  284. print img_object($langs->trans("ShowPropal"), "propal");
  285. print " " . $objp->ref . "</a>\n";
  286. if ($db->jdate($objp->dp) < ($now - $conf->propal->cloture->warning_delay) && $objp->fk_statut == 1) {
  287. print " " . img_warning();
  288. }
  289. print "</td><td align=\"right\">" . dol_print_date($db->jdate($objp->dp), "day") . "</td>\n";
  290. print "<td align=\"right\">" . price($objp->total_ht) . "</td>\n";
  291. print "<td align=\"right\">" . $propal_static->LibStatut($objp->fk_statut, 5) . "</td></tr>\n";
  292. $i++;
  293. }
  294. $db->free();
  295. if ($num > 0)
  296. print "</table>";
  297. }
  298. else {
  299. dol_print_error($db);
  300. }
  301. }
  302. print "</td></tr>";
  303. print "</table>\n";
  304. dol_fiche_end();
  305. /*
  306. * Barre d'action
  307. */
  308. print '<div class="tabsAction">';
  309. if (!empty($conf->propal->enabled) && $user->rights->propale->creer) {
  310. print '<a class="butAction" href="' . DOL_URL_ROOT . '/comm/addpropal.php?socid=' . $object->id . '&amp;action=create">' . $langs->trans("AddProp") . '</a>';
  311. }
  312. // Add action
  313. if (!empty($conf->agenda->enabled) && !empty($conf->global->MAIN_REPEATTASKONEACHTAB)) {
  314. if ($user->rights->agenda->myactions->create) {
  315. print '<a class="butAction" href="' . DOL_URL_ROOT . '/comm/action/fiche.php?action=create&socid=' . $object->id . '">' . $langs->trans("AddAction") . '</a>';
  316. } else {
  317. print '<a class="butAction" title="' . dol_escape_js($langs->trans("NotAllowed")) . '" href="#">' . $langs->trans("AddAction") . '</a>';
  318. }
  319. }
  320. print '</div>';
  321. print '<br>';
  322. if (!empty($conf->global->MAIN_REPEATCONTACTONEACHTAB)) {
  323. print '<br>';
  324. // List of contacts
  325. show_contacts($conf, $langs, $db, $object, $_SERVER["PHP_SELF"] . '?socid=' . $object->id);
  326. }
  327. if (!empty($conf->global->MAIN_REPEATTASKONEACHTAB)) {
  328. print load_fiche_titre($langs->trans("ActionsOnCompany"), '', '');
  329. // List of todo actions
  330. show_actions_todo($conf, $langs, $db, $object);
  331. // List of done actions
  332. show_actions_done($conf, $langs, $db, $object);
  333. }
  334. if ($conf->lead->enabled) {
  335. print '<table width="100%" class="notopnoleftnoright">';
  336. print '<tr><td valign="top" width="50%" class="notopnoleft">';
  337. // Leads list
  338. $result = show_leads($conf, $langs, $db, $societe);
  339. print "</td>\n";
  340. print '<td valign="top" width="50%" class="notopnoleft">';
  341. print "</td>\n";
  342. print "</tr>\n";
  343. print "</table>\n";
  344. }
  345. }
  346. llxFooter();
  347. $db->close();
  348. ?>