PageRenderTime 47ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/comm/prospect/fiche.php

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