index.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  1. <?php
  2. /* Copyright (C) 2003-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2017 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2019 Nicolas ZABOURI <info@inovea-conseil.com>
  6. * Copyright (C) 2020 Tobias Sekan <tobias.sekan@startmail.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. */
  21. /**
  22. * \file htdocs/comm/propal/index.php
  23. * \ingroup propal
  24. * \brief Home page of proposal area
  25. */
  26. // Load Dolibarr environment
  27. require '../../main.inc.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/propal.lib.php';
  31. // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
  32. $hookmanager = new HookManager($db);
  33. $hookmanager->initHooks(array('proposalindex'));
  34. // Load translation files required by the page
  35. $langs->loadLangs(array('propal', 'companies'));
  36. $now = dol_now();
  37. $max = 5;
  38. // Security check
  39. $socid = GETPOST('socid', 'int');
  40. if (isset($user->socid) && $user->socid > 0) {
  41. $action = '';
  42. $socid = $user->socid;
  43. }
  44. restrictedArea($user, 'propal');
  45. /*
  46. * View
  47. */
  48. $propalstatic = new Propal($db);
  49. $companystatic = new Societe($db);
  50. $form = new Form($db);
  51. $formfile = new FormFile($db);
  52. $help_url = "EN:Module_Commercial_Proposals|FR:Module_Propositions_commerciales|ES:Módulo_Presupuestos";
  53. llxHeader("", $langs->trans("ProspectionArea"), $help_url);
  54. print load_fiche_titre($langs->trans("ProspectionArea"), '', 'propal');
  55. print '<div class="fichecenter">';
  56. print '<div class="fichethirdleft">';
  57. $tmp = getCustomerProposalPieChart($socid);
  58. if ($tmp) {
  59. print $tmp;
  60. print '<br>';
  61. }
  62. /*
  63. * Draft proposals
  64. */
  65. if (isModEnabled("propal")) {
  66. $sql = "SELECT p.rowid, p.ref, p.ref_client, p.total_ht, p.total_tva, p.total_ttc";
  67. $sql .= ", s.rowid as socid, s.nom as name, s.client, s.canvas, s.code_client, s.code_fournisseur, s.email, s.entity, s.code_compta";
  68. $sql .= " FROM ".MAIN_DB_PREFIX."propal as p";
  69. $sql .= ", ".MAIN_DB_PREFIX."societe as s";
  70. if (empty($user->rights->societe->client->voir) && !$socid) {
  71. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  72. }
  73. $sql .= " WHERE p.entity IN (".getEntity($propalstatic->element).")";
  74. $sql .= " AND p.fk_soc = s.rowid";
  75. $sql .= " AND p.fk_statut =".Propal::STATUS_DRAFT;
  76. if (empty($user->rights->societe->client->voir) && !$socid) {
  77. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  78. }
  79. if ($socid) {
  80. $sql .= " AND p.fk_soc = ".((int) $socid);
  81. }
  82. $resql = $db->query($sql);
  83. if ($resql) {
  84. $num = $db->num_rows($resql);
  85. $nbofloop = min($num, (empty($conf->global->MAIN_MAXLIST_OVERLOAD) ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD));
  86. startSimpleTable("DraftPropals", "comm/propal/list.php", "search_status=".Propal::STATUS_DRAFT, 2, $num);
  87. $total = 0;
  88. if ($num) {
  89. $i = 0;
  90. while ($i < $nbofloop) {
  91. $obj = $db->fetch_object($resql);
  92. $propalstatic->id = $obj->rowid;
  93. $propalstatic->ref = $obj->ref;
  94. $propalstatic->ref_client = $obj->ref_client;
  95. $propalstatic->total_ht = $obj->total_ht;
  96. $propalstatic->total_tva = $obj->total_tva;
  97. $propalstatic->total_ttc = $obj->total_ttc;
  98. $companystatic->id = $obj->socid;
  99. $companystatic->name = $obj->name;
  100. $companystatic->client = $obj->client;
  101. $companystatic->code_client = $obj->code_client;
  102. $companystatic->code_fournisseur = $obj->code_fournisseur;
  103. $companystatic->canvas = $obj->canvas;
  104. $companystatic->entity = $obj->entity;
  105. $companystatic->email = $obj->email;
  106. $companystatic->code_compta = $obj->code_compta;
  107. print '<tr class="oddeven">';
  108. print '<td class="nowrap">'.$propalstatic->getNomUrl(1).'</td>';
  109. print '<td class="nowrap">'.$companystatic->getNomUrl(1, 'customer', 16).'</td>';
  110. print '<td class="nowrap right">'.price(!empty($conf->global->MAIN_DASHBOARD_USE_TOTAL_HT) ? $obj->total_ht : $obj->total_ttc).'</td>';
  111. print '</tr>';
  112. $i++;
  113. $total += (!empty($conf->global->MAIN_DASHBOARD_USE_TOTAL_HT) ? $obj->total_ht : $obj->total_ttc);
  114. }
  115. }
  116. addSummaryTableLine(3, $num, $nbofloop, $total, "NoProposal");
  117. finishSimpleTable(true);
  118. $db->free($resql);
  119. } else {
  120. dol_print_error($db);
  121. }
  122. }
  123. print '</div>';
  124. print '<div class="fichetwothirdright">';
  125. /*
  126. * Last modified proposals
  127. */
  128. $sql = "SELECT c.rowid, c.entity, c.ref, c.fk_statut, date_cloture as datec";
  129. $sql .= ", s.nom as socname, s.rowid as socid, s.canvas, s.client, s.email, s.code_compta";
  130. $sql .= " FROM ".MAIN_DB_PREFIX."propal as c";
  131. $sql .= ", ".MAIN_DB_PREFIX."societe as s";
  132. if (empty($user->rights->societe->client->voir) && !$socid) {
  133. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  134. }
  135. $sql .= " WHERE c.entity IN (".getEntity($propalstatic->element).")";
  136. $sql .= " AND c.fk_soc = s.rowid";
  137. //$sql.= " AND c.fk_statut > 2";
  138. if ($socid) {
  139. $sql .= " AND c.fk_soc = ".((int) $socid);
  140. }
  141. if (empty($user->rights->societe->client->voir) && !$socid) {
  142. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  143. }
  144. $sql .= " ORDER BY c.tms DESC";
  145. $sql .= $db->plimit($max, 0);
  146. $resql = $db->query($sql);
  147. if ($resql) {
  148. $num = $db->num_rows($resql);
  149. startSimpleTable($langs->trans("LastModifiedProposals", $max), "", "", 3);
  150. if ($num) {
  151. $i = 0;
  152. while ($i < $num) {
  153. $obj = $db->fetch_object($resql);
  154. $propalstatic->id = $obj->rowid;
  155. $propalstatic->ref = $obj->ref;
  156. $companystatic->id = $obj->socid;
  157. $companystatic->name = $obj->socname;
  158. $companystatic->client = $obj->client;
  159. $companystatic->canvas = $obj->canvas;
  160. $companystatic->email = $obj->email;
  161. $companystatic->code_compta = $obj->code_compta;
  162. $filename = dol_sanitizeFileName($obj->ref);
  163. $filedir = $conf->propal->multidir_output[$obj->entity].'/'.dol_sanitizeFileName($obj->ref);
  164. $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
  165. print '<tr class="oddeven">';
  166. print '<td width="20%" class="nowrap">';
  167. print '<table class="nobordernopadding">';
  168. print '<tr class="nocellnopadd">';
  169. print '<td width="96" class="nobordernopadding nowrap">'.$propalstatic->getNomUrl(1).'</td>';
  170. print '<td width="16" class="nobordernopadding nowrap"></td>';
  171. print '<td width="16" class="nobordernopadding right">'.$formfile->getDocumentsLink($propalstatic->element, $filename, $filedir).'</td>';
  172. print '</tr>';
  173. print '</table>';
  174. print '</td>';
  175. print '<td>'.$companystatic->getNomUrl(1, 'customer').'</td>';
  176. print '<td>'.dol_print_date($db->jdate($obj->datec), 'day').'</td>';
  177. print '<td class="right">'.$propalstatic->LibStatut($obj->fk_statut, 3).'</td>';
  178. print '</tr>';
  179. $i++;
  180. }
  181. }
  182. finishSimpleTable(true);
  183. $db->free($resql);
  184. } else {
  185. dol_print_error($db);
  186. }
  187. /*
  188. * Open (validated) proposals
  189. */
  190. if (isModEnabled("propal") && $user->rights->propal->lire) {
  191. $sql = "SELECT s.nom as socname, s.rowid as socid, s.canvas, s.client, s.email, s.code_compta";
  192. $sql .= ", p.rowid as propalid, p.entity, p.total_ttc, p.total_ht, p.ref, p.fk_statut, p.datep as dp, p.fin_validite as dfv";
  193. $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
  194. $sql .= ", ".MAIN_DB_PREFIX."propal as p";
  195. if (empty($user->rights->societe->client->voir) && !$socid) {
  196. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  197. }
  198. $sql .= " WHERE p.fk_soc = s.rowid";
  199. $sql .= " AND p.entity IN (".getEntity($propalstatic->element).")";
  200. $sql .= " AND p.fk_statut = ".Propal::STATUS_VALIDATED;
  201. if (empty($user->rights->societe->client->voir) && !$socid) {
  202. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  203. }
  204. if ($socid) {
  205. $sql .= " AND s.rowid = ".((int) $socid);
  206. }
  207. $sql .= " ORDER BY p.rowid DESC";
  208. $resql = $db->query($sql);
  209. if ($resql) {
  210. $total = 0;
  211. $num = $db->num_rows($resql);
  212. $nbofloop = min($num, (empty($conf->global->MAIN_MAXLIST_OVERLOAD) ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD));
  213. startSimpleTable("ProposalsOpened", "comm/propal/list.php", "search_status=".Propal::STATUS_VALIDATED, 4, $num);
  214. if ($num > 0) {
  215. $i = 0;
  216. while ($i < $nbofloop) {
  217. $obj = $db->fetch_object($resql);
  218. $propalstatic->id = $obj->propalid;
  219. $propalstatic->ref = $obj->ref;
  220. $companystatic->id = $obj->socid;
  221. $companystatic->name = $obj->socname;
  222. $companystatic->client = $obj->client;
  223. $companystatic->canvas = $obj->canvas;
  224. $companystatic->email = $obj->email;
  225. $companystatic->code_compta = $obj->code_compta;
  226. $filename = dol_sanitizeFileName($obj->ref);
  227. $filedir = $conf->propal->multidir_output[$obj->entity].'/'.dol_sanitizeFileName($obj->ref);
  228. $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->propalid;
  229. $warning = ($db->jdate($obj->dfv) < ($now - $conf->propal->cloture->warning_delay)) ? img_warning($langs->trans("Late")) : '';
  230. print '<tr class="oddeven">';
  231. // Ref
  232. print '<td class="nowrap" width="140">';
  233. print '<table class="nobordernopadding">';
  234. print '<tr class="nocellnopadd">';
  235. print '<td class="nobordernopadding nowrap">'.$propalstatic->getNomUrl(1).'</td>';
  236. print '<td width="18" class="nobordernopadding nowrap">'.$warning.'</td>';
  237. print '<td width="16" align="center" class="nobordernopadding">'.$formfile->getDocumentsLink($propalstatic->element, $filename, $filedir).'</td>';
  238. print '</tr>';
  239. print '</table>';
  240. print '</td>';
  241. print '<td class="left">'.$companystatic->getNomUrl(1, 'customer', 44).'</td>';
  242. print '<td class="right">'.dol_print_date($db->jdate($obj->dp), 'day').'</td>';
  243. print '<td class="right">'.price(!empty($conf->global->MAIN_DASHBOARD_USE_TOTAL_HT) ? $obj->total_ht : $obj->total_ttc).'</td>';
  244. print '<td align="center" width="14">'.$propalstatic->LibStatut($obj->fk_statut, 3).'</td>';
  245. print '</tr>';
  246. $i++;
  247. $total += (!empty($conf->global->MAIN_DASHBOARD_USE_TOTAL_HT) ? $obj->total_ht : $obj->total_ttc);
  248. }
  249. }
  250. addSummaryTableLine(5, $num, $nbofloop, $total, "None", true);
  251. finishSimpleTable(true);
  252. $db->free($resql);
  253. } else {
  254. dol_print_error($db);
  255. }
  256. }
  257. /*
  258. * Proposals to process
  259. */
  260. /*
  261. if (isModEnabled('propal'))
  262. {
  263. $sql = "SELECT c.rowid, c.ref, c.fk_statut, s.nom as name, s.rowid as socid";
  264. $sql.=" FROM ".MAIN_DB_PREFIX."propal as c";
  265. $sql.= ", ".MAIN_DB_PREFIX."societe as s";
  266. if (empty($user->rights->societe->client->voir) && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  267. $sql.= " WHERE c.fk_soc = s.rowid";
  268. $sql.= " AND c.entity = ".$conf->entity;
  269. $sql.= " AND c.fk_statut = 1";
  270. if ($socid) $sql.= " AND c.fk_soc = ".((int) $socid);
  271. if (empty($user->rights->societe->client->voir) && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .((int) $user->id);
  272. $sql.= " ORDER BY c.rowid DESC";
  273. $resql=$db->query($sql);
  274. if ($resql)
  275. {
  276. $num = $db->num_rows($resql);
  277. print '<div class="div-table-responsive-no-min">';
  278. print '<table class="noborder centpercent">';
  279. print '<tr class="liste_titre">';
  280. print '<td colspan="3">'.$langs->trans("ProposalsToProcess").' <a href="'.DOL_URL_ROOT.'/commande/list.php?search_status=1"><span class="badge">'.$num.'</span></a></td></tr>';
  281. if ($num)
  282. {
  283. $i = 0;
  284. while ($i < $num)
  285. {
  286. $obj = $db->fetch_object($resql);
  287. print '<tr class="oddeven">';
  288. print '<td class="nowrap">';
  289. $propalstatic->id=$obj->rowid;
  290. $propalstatic->ref=$obj->ref;
  291. print '<table class="nobordernopadding"><tr class="nocellnopadd">';
  292. print '<td width="96" class="nobordernopadding nowrap">';
  293. print $propalstatic->getNomUrl(1);
  294. print '</td>';
  295. print '<td width="16" class="nobordernopadding nowrap">';
  296. print '&nbsp;';
  297. print '</td>';
  298. print '<td width="16" class="nobordernopadding right">';
  299. $filename=dol_sanitizeFileName($obj->ref);
  300. $filedir=$conf->commande->dir_output . '/' . dol_sanitizeFileName($obj->ref);
  301. $urlsource=$_SERVER['PHP_SELF'].'?id='.$obj->rowid;
  302. print $formfile->getDocumentsLink($propalstatic->element, $filename, $filedir);
  303. print '</td></tr></table>';
  304. print '</td>';
  305. print '<td><a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"),"company").' '.dol_trunc($obj->name,24).'</a></td>';
  306. print '<td class="right">'.$propalstatic->LibStatut($obj->fk_statut,$obj->facture,5).'</td>';
  307. print '</tr>';
  308. $i++;
  309. }
  310. }
  311. print "</table>";
  312. print "</div><br>";
  313. }
  314. else dol_print_error($db);
  315. }
  316. */
  317. /*
  318. * Proposal that are in a shipping process
  319. */
  320. /*
  321. if (isModEnabled('propal'))
  322. {
  323. $sql = "SELECT c.rowid, c.ref, c.fk_statut, c.facture, s.nom as name, s.rowid as socid";
  324. $sql.= " FROM ".MAIN_DB_PREFIX."commande as c";
  325. $sql.= ", ".MAIN_DB_PREFIX."societe as s";
  326. if (empty($user->rights->societe->client->voir) && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  327. $sql.= " WHERE c.fk_soc = s.rowid";
  328. $sql.= " AND c.entity = ".$conf->entity;
  329. $sql.= " AND c.fk_statut = 2 ";
  330. if ($socid) $sql.= " AND c.fk_soc = ".((int) $socid);
  331. if (empty($user->rights->societe->client->voir) && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .((int) $user->id);
  332. $sql.= " ORDER BY c.rowid DESC";
  333. $resql=$db->query($sql);
  334. if ($resql)
  335. {
  336. $num = $db->num_rows($resql);
  337. print '<div class="div-table-responsive-no-min">';
  338. print '<table class="noborder centpercent">';
  339. print '<tr class="liste_titre">';
  340. print '<td colspan="3">'.$langs->trans("OnProcessOrders").' <a href="'.DOL_URL_ROOT.'/commande/list.php?search_status=2"><span class="badge">'.$num.'</span></a></td></tr>';
  341. if ($num)
  342. {
  343. $i = 0;
  344. while ($i < $num)
  345. {
  346. $obj = $db->fetch_object($resql);
  347. print '<tr class="oddeven">';
  348. print '<td width="20%" class="nowrap">';
  349. $propalstatic->id=$obj->rowid;
  350. $propalstatic->ref=$obj->ref;
  351. print '<table class="nobordernopadding"><tr class="nocellnopadd">';
  352. print '<td width="96" class="nobordernopadding nowrap">';
  353. print $propalstatic->getNomUrl(1);
  354. print '</td>';
  355. print '<td width="16" class="nobordernopadding nowrap">';
  356. print '&nbsp;';
  357. print '</td>';
  358. print '<td width="16" class="nobordernopadding right">';
  359. $filename=dol_sanitizeFileName($obj->ref);
  360. $filedir=$conf->commande->dir_output . '/' . dol_sanitizeFileName($obj->ref);
  361. $urlsource=$_SERVER['PHP_SELF'].'?id='.$obj->rowid;
  362. print $formfile->getDocumentsLink($propalstatic->element, $filename, $filedir);
  363. print '</td></tr></table>';
  364. print '</td>';
  365. print '<td><a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"),"company").' '.$obj->name.'</a></td>';
  366. print '<td class="right">'.$propalstatic->LibStatut($obj->fk_statut,$obj->facture,5).'</td>';
  367. print '</tr>';
  368. $i++;
  369. }
  370. }
  371. print "</table>";
  372. print "</div><br>";
  373. }
  374. else dol_print_error($db);
  375. }
  376. */
  377. print '</div>';
  378. print '</div>';
  379. $parameters = array('user' => $user);
  380. $reshook = $hookmanager->executeHooks('dashboardPropals', $parameters, $object); // Note that $action and $object may have been modified by hook
  381. // End of page
  382. llxFooter();
  383. $db->close();