index.php 15 KB

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