index.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. <?php
  2. /* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2020 Open-Dsi <support@open-dsi.fr>
  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 <https://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/comm/prospect/index.php
  22. * \ingroup commercial
  23. * \brief Home page of propest area
  24. */
  25. // Load Dolibarr environment
  26. require '../../main.inc.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php';
  28. // Load translation files required by the page
  29. $langs->load("propal");
  30. if ($user->socid > 0) {
  31. $socid = $user->socid;
  32. }
  33. // Security check
  34. $socid = GETPOST('socid', 'int');
  35. if ($user->socid) {
  36. $action = '';
  37. $socid = $user->socid;
  38. }
  39. $result = restrictedArea($user, 'propal', $socid, '');
  40. /*
  41. * View
  42. */
  43. $companystatic = new Societe($db);
  44. llxHeader();
  45. print load_fiche_titre($langs->trans("ProspectionArea"));
  46. //print '<table border="0" width="100%" class="notopnoleftnoright">';
  47. //print '<tr><td valign="top" width="30%" class="notopnoleft">';
  48. print '<div class="fichecenter"><div class="fichethirdleft">';
  49. if (isModEnabled("propal")) {
  50. $var = false;
  51. print '<form method="post" action="'.DOL_URL_ROOT.'/comm/propal/card.php">';
  52. print '<input type="hidden" name="token" value="'.newToken().'">';
  53. print '<table class="noborder nohover centpercent">';
  54. print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("SearchAProposal").'</td></tr>';
  55. print '<tr class="oddeven"><td>';
  56. print $langs->trans("Ref").':</td><td><input type="text" class="flat" name="sf_ref" size="18"></td><td rowspan="2"><input type="submit" value="'.$langs->trans("Search").'" class="button"></td></tr>';
  57. print '<tr class="oddeven"><td class="nowrap">'.$langs->trans("Other").':</td><td><input type="text" class="flat" name="sall" size="18"></td>';
  58. print '</tr>';
  59. print "</table></form><br>\n";
  60. }
  61. /*
  62. * Prospects par statut
  63. *
  64. */
  65. $sql = "SELECT count(*) as cc, st.libelle as stcomm, st.picto, st.id";
  66. $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
  67. $sql .= ", ".MAIN_DB_PREFIX."c_stcomm as st ";
  68. if (empty($user->rights->societe->client->voir) && !$socid) {
  69. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  70. }
  71. $sql .= " WHERE s.fk_stcomm = st.id";
  72. $sql .= " AND s.client IN (2, 3)";
  73. $sql .= " AND s.entity IN (".getEntity($companystatic->element).")";
  74. if (empty($user->rights->societe->client->voir) && !$socid) {
  75. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  76. }
  77. $sql .= " GROUP BY st.id";
  78. $sql .= " ORDER BY st.id";
  79. $resql = $db->query($sql);
  80. if ($resql) {
  81. $num = $db->num_rows($resql);
  82. $i = 0;
  83. if ($num > 0) {
  84. print '<table class="noborder centpercent">';
  85. print '<tr class="liste_titre">';
  86. print '<td colspan="2">'.$langs->trans("ProspectsByStatus").'</td></tr>';
  87. while ($i < $num) {
  88. $obj = $db->fetch_object($resql);
  89. print '<tr class="oddeven"><td>';
  90. print '<a href="prospects.php?page=0&amp;stcomm='.$obj->id.'">';
  91. print img_action($langs->trans("Show"), $obj->id, $obj->picto).' ';
  92. print $langs->trans("StatusProspect".$obj->id);
  93. print '</a></td><td class="right">'.$obj->cc.'</td></tr>';
  94. $i++;
  95. }
  96. print "</table><br>";
  97. }
  98. }
  99. /*
  100. * Liste des propal brouillons
  101. */
  102. if (isModEnabled("propal") && $user->rights->propal->lire) {
  103. $sql = "SELECT p.rowid, p.ref, p.price, s.nom as sname";
  104. $sql .= " FROM ".MAIN_DB_PREFIX."propal as p";
  105. $sql .= ", ".MAIN_DB_PREFIX."societe as s";
  106. if (empty($user->rights->societe->client->voir) && !$socid) {
  107. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  108. }
  109. $sql .= " WHERE p.fk_statut = 0";
  110. $sql .= " AND p.fk_soc = s.rowid";
  111. $sql .= " AND p.entity IN (".getEntity('propal').")";
  112. if (empty($user->rights->societe->client->voir) && !$socid) {
  113. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  114. }
  115. $resql = $db->query($sql);
  116. if ($resql) {
  117. $total = 0;
  118. $num = $db->num_rows($resql);
  119. $i = 0;
  120. if ($num > 0) {
  121. print '<table class="noborder"" width="100%">';
  122. print '<tr class="liste_titre">';
  123. print '<td colspan="2">'.$langs->trans("ProposalsDraft").'</td></tr>';
  124. while ($i < $num) {
  125. $obj = $db->fetch_object($resql);
  126. print '<tr class="oddeven"><td>';
  127. print '<a href="'.DOL_URL_ROOT.'/comm/propal/card.php?id='.$obj->rowid.'">'.img_object($langs->trans("ShowPropal"), "propal").' '.$obj->ref.'</a>';
  128. print '</td><td class="right">';
  129. print price($obj->price);
  130. print "</td></tr>";
  131. $i++;
  132. $total += $obj->price;
  133. }
  134. if ($total > 0) {
  135. print '<tr class="liste_total"><td>'.$langs->trans("Total")."</td><td align=\"right\">".price($total)."</td></tr>";
  136. }
  137. print "</table><br>";
  138. }
  139. $db->free($resql);
  140. }
  141. }
  142. print '</div><div class="fichetwothirdright">';
  143. /*
  144. * Actions commerciales a faire
  145. */
  146. if (isModEnabled('agenda')) {
  147. show_array_actions_to_do(10);
  148. }
  149. /*
  150. * Dernieres propales ouvertes
  151. */
  152. if (isModEnabled("propal") && $user->rights->propal->lire) {
  153. $sql = "SELECT s.nom as name, s.rowid as socid, s.client, s.canvas,";
  154. $sql .= " p.rowid as propalid, p.total_ttc, p.ref, p.datep as dp, c.label as statut, c.id as statutid";
  155. $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
  156. $sql .= ", ".MAIN_DB_PREFIX."propal as p";
  157. $sql .= ", ".MAIN_DB_PREFIX."c_propalst as c";
  158. if (empty($user->rights->societe->client->voir) && !$socid) {
  159. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  160. }
  161. $sql .= " WHERE p.fk_soc = s.rowid";
  162. $sql .= " AND p.fk_statut = c.id";
  163. $sql .= " AND p.fk_statut = 1";
  164. $sql .= " AND p.entity IN (".getEntity('propal').")";
  165. if (empty($user->rights->societe->client->voir) && !$socid) {
  166. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  167. }
  168. if ($socid) {
  169. $sql .= " AND s.rowid = ".((int) $socid);
  170. }
  171. $sql .= " ORDER BY p.rowid DESC";
  172. $sql .= $db->plimit(5, 0);
  173. $resql = $db->query($sql);
  174. if ($resql) {
  175. $total = 0;
  176. $num = $db->num_rows($resql);
  177. $i = 0;
  178. if ($num > 0) {
  179. print '<table class="noborder centpercent">';
  180. print '<tr class="liste_titre"><td colspan="4">'.$langs->trans("ProposalsOpened").'</td></tr>';
  181. while ($i < $num) {
  182. $obj = $db->fetch_object($resql);
  183. print '<tr class="oddeven"><td>';
  184. print '<a href="../propal.php?id='.$obj->propalid.'">';
  185. print img_object($langs->trans("ShowPropal"), "propal").' '.$obj->ref.'</a></td>';
  186. print "<td>";
  187. $companystatic->id = $obj->socid;
  188. $companystatic->name = $obj->name;
  189. $companystatic->client = $obj->client;
  190. $companystatic->canvas = $obj->canvas;
  191. print $companystatic->getNomUrl(1, '', 44);
  192. print "</td>\n";
  193. print "<td align=\"right\">";
  194. print dol_print_date($db->jdate($obj->dp), 'day')."</td>\n";
  195. print "<td align=\"right\">".price($obj->total_ttc)."</td></tr>\n";
  196. $i++;
  197. $total += $obj->price;
  198. }
  199. if ($total > 0) {
  200. print '<tr class="liste_total"><td colspan="3" class="right">'.$langs->trans("Total")."</td><td class=\"right\">".price($total)."</td></tr>";
  201. }
  202. print "</table><br>";
  203. }
  204. } else {
  205. dol_print_error($db);
  206. }
  207. }
  208. /*
  209. * Societes a contacter
  210. *
  211. */
  212. $sql = "SELECT s.nom as name, s.rowid as socid, s.client, s.canvas";
  213. $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
  214. if (empty($user->rights->societe->client->voir) && !$socid) {
  215. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  216. }
  217. $sql .= " WHERE s.fk_stcomm = 1";
  218. $sql .= " AND s.entity IN (".getEntity($companystatic->element).")";
  219. if (empty($user->rights->societe->client->voir) && !$socid) {
  220. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  221. }
  222. $sql .= " ORDER BY s.tms ASC";
  223. $sql .= $db->plimit(15, 0);
  224. $resql = $db->query($sql);
  225. if ($resql) {
  226. $num = $db->num_rows($resql);
  227. $i = 0;
  228. if ($num > 0) {
  229. print '<table class="noborder centpercent">';
  230. print '<tr class="liste_titre"><td>'.$langs->trans("ProspectToContact").'</td></tr>';
  231. while ($i < $num) {
  232. $obj = $db->fetch_object($resql);
  233. print '<tr class="oddeven"><td width="12%">';
  234. $companystatic->id = $obj->socid;
  235. $companystatic->name = $obj->name;
  236. $companystatic->client = $obj->client;
  237. $companystatic->canvas = $obj->canvas;
  238. print $companystatic->getNomUrl(1, 'prospect', 44);
  239. print '</td></tr>';
  240. $i++;
  241. }
  242. print "</table><br>";
  243. }
  244. }
  245. print '</div></div>';
  246. // End of page
  247. llxFooter();
  248. $db->close();