index.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  1. <?php
  2. /* Copyright (C) 2003-2004 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@inodbox.com>
  5. * Copyright (C) 2019 Nicolas ZABOURI <info@inovea-conseil.com>
  6. * Copyright (C) 2019 Frédéric France <frederic.france@netlogic.fr>
  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/commande/index.php
  23. * \ingroup commande
  24. * \brief Home page of sales order module
  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.'/core/class/notify.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/societe/class/client.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/lib/order.lib.php';
  33. // Load translation files required by the page
  34. $langs->loadLangs(array('orders', 'bills'));
  35. if (!$user->hasRight('commande', 'lire')) {
  36. accessforbidden();
  37. }
  38. $hookmanager = new HookManager($db);
  39. // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
  40. $hookmanager->initHooks(array('ordersindex'));
  41. // Security check
  42. $socid = GETPOST('socid', 'int');
  43. if ($user->socid > 0) {
  44. $action = '';
  45. $socid = $user->socid;
  46. }
  47. $max = getDolGlobalInt('MAIN_SIZE_SHORTLIST_LIMIT');
  48. // Maximum elements of the tables
  49. $maxDraftCount = !getDolGlobalString('MAIN_MAXLIST_OVERLOAD') ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD;
  50. $maxLatestEditCount = 5;
  51. $maxOpenCount = !getDolGlobalString('MAIN_MAXLIST_OVERLOAD') ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD;
  52. /*
  53. * View
  54. */
  55. $commandestatic = new Commande($db);
  56. $companystatic = new Societe($db);
  57. $form = new Form($db);
  58. $formfile = new FormFile($db);
  59. $help_url = "EN:Module_Customers_Orders|FR:Module_Commandes_Clients|ES:Módulo_Pedidos_de_clientes";
  60. llxHeader("", $langs->trans("Orders"), $help_url);
  61. print load_fiche_titre($langs->trans("OrdersArea"), '', 'order');
  62. print '<div class="fichecenter"><div class="fichethirdleft">';
  63. $tmp = getCustomerOrderPieChart($socid);
  64. if ($tmp) {
  65. print $tmp;
  66. print '<br>';
  67. }
  68. /*
  69. * Draft orders
  70. */
  71. if (isModEnabled('commande')) {
  72. $sql = "SELECT c.rowid, c.ref, s.nom as name, s.rowid as socid";
  73. $sql .= ", s.client";
  74. $sql .= ", s.code_client";
  75. $sql .= ", s.canvas";
  76. $sql .= " FROM ".MAIN_DB_PREFIX."commande as c";
  77. $sql .= ", ".MAIN_DB_PREFIX."societe as s";
  78. if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
  79. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  80. }
  81. $sql .= " WHERE c.fk_soc = s.rowid";
  82. $sql .= " AND c.entity IN (".getEntity('commande').")";
  83. $sql .= " AND c.fk_statut = 0";
  84. if ($socid) {
  85. $sql .= " AND c.fk_soc = ".((int) $socid);
  86. }
  87. if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
  88. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  89. }
  90. $resql = $db->query($sql);
  91. if ($resql) {
  92. print '<div class="div-table-responsive-no-min">';
  93. print '<table class="noborder centpercent">';
  94. print '<tr class="liste_titre">';
  95. print '<th colspan="2">'.$langs->trans("DraftOrders").'</th></tr>';
  96. $langs->load("orders");
  97. $num = $db->num_rows($resql);
  98. if ($num) {
  99. $i = 0;
  100. while ($i < $num) {
  101. $obj = $db->fetch_object($resql);
  102. $commandestatic->id = $obj->rowid;
  103. $commandestatic->ref = $obj->ref;
  104. $companystatic->id = $obj->socid;
  105. $companystatic->name = $obj->name;
  106. $companystatic->client = $obj->client;
  107. $companystatic->code_client = $obj->code_client;
  108. $companystatic->canvas = $obj->canvas;
  109. print '<tr class="oddeven">';
  110. print '<td class="nowrap">';
  111. print $commandestatic->getNomUrl(1);
  112. print "</td>";
  113. print '<td class="nowrap">';
  114. print $companystatic->getNomUrl(1, 'company', 16);
  115. print '</td></tr>';
  116. $i++;
  117. }
  118. } else {
  119. print '<tr class="oddeven"><td colspan="3">'.$langs->trans("NoOrder").'</td></tr>';
  120. }
  121. print "</table></div><br>";
  122. }
  123. }
  124. print '</div><div class="fichetwothirdright">';
  125. $max = 5;
  126. /*
  127. * Lattest modified orders
  128. */
  129. $sql = "SELECT c.rowid, c.entity, c.ref, c.fk_statut, c.facture, c.date_cloture as datec, c.tms as datem,";
  130. $sql .= " s.nom as name, s.rowid as socid";
  131. $sql .= ", s.client";
  132. $sql .= ", s.code_client";
  133. $sql .= ", s.canvas";
  134. $sql .= " FROM ".MAIN_DB_PREFIX."commande as c,";
  135. $sql .= " ".MAIN_DB_PREFIX."societe as s";
  136. if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
  137. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  138. }
  139. $sql .= " WHERE c.fk_soc = s.rowid";
  140. $sql .= " AND c.entity IN (".getEntity('commande').")";
  141. //$sql.= " AND c.fk_statut > 2";
  142. if ($socid) {
  143. $sql .= " AND c.fk_soc = ".((int) $socid);
  144. }
  145. if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
  146. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  147. }
  148. $sql .= " ORDER BY c.tms DESC";
  149. $sql .= $db->plimit($max, 0);
  150. $resql = $db->query($sql);
  151. if ($resql) {
  152. print '<div class="div-table-responsive-no-min">';
  153. print '<table class="noborder centpercent">';
  154. print '<tr class="liste_titre">';
  155. print '<th colspan="4">'.$langs->trans("LastModifiedOrders", $max).'</th></tr>';
  156. $num = $db->num_rows($resql);
  157. if ($num) {
  158. $i = 0;
  159. while ($i < $num) {
  160. $obj = $db->fetch_object($resql);
  161. print '<tr class="oddeven">';
  162. print '<td width="20%" class="nowrap">';
  163. $commandestatic->id = $obj->rowid;
  164. $commandestatic->ref = $obj->ref;
  165. $companystatic->id = $obj->socid;
  166. $companystatic->name = $obj->name;
  167. $companystatic->client = $obj->client;
  168. $companystatic->code_client = $obj->code_client;
  169. $companystatic->canvas = $obj->canvas;
  170. print '<table class="nobordernopadding"><tr class="nocellnopadd">';
  171. print '<td width="96" class="nobordernopadding nowrap">';
  172. print $commandestatic->getNomUrl(1);
  173. print '</td>';
  174. print '<td width="16" class="nobordernopadding nowrap">';
  175. print '&nbsp;';
  176. print '</td>';
  177. print '<td width="16" class="nobordernopadding hideonsmartphone right">';
  178. $filename = dol_sanitizeFileName($obj->ref);
  179. $filedir = $conf->commande->multidir_output[$obj->entity].'/'.dol_sanitizeFileName($obj->ref);
  180. $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
  181. print $formfile->getDocumentsLink($commandestatic->element, $filename, $filedir);
  182. print '</td></tr></table>';
  183. print '</td>';
  184. print '<td class="nowrap">';
  185. print $companystatic->getNomUrl(1, 'company', 16);
  186. print '</td>';
  187. print '<td>'.dol_print_date($db->jdate($obj->datem), 'day').'</td>';
  188. print '<td class="right">'.$commandestatic->LibStatut($obj->fk_statut, $obj->facture, 3).'</td>';
  189. print '</tr>';
  190. $i++;
  191. }
  192. }
  193. print "</table></div><br>";
  194. } else {
  195. dol_print_error($db);
  196. }
  197. $max = 10;
  198. /*
  199. * Orders to process
  200. */
  201. if (isModEnabled('commande')) {
  202. $sql = "SELECT c.rowid, c.entity, c.ref, c.fk_statut, c.facture, c.date_commande as date, s.nom as name, s.rowid as socid";
  203. $sql .= ", s.client";
  204. $sql .= ", s.code_client";
  205. $sql .= ", s.canvas";
  206. $sql .= " FROM ".MAIN_DB_PREFIX."commande as c";
  207. $sql .= ", ".MAIN_DB_PREFIX."societe as s";
  208. if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
  209. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  210. }
  211. $sql .= " WHERE c.fk_soc = s.rowid";
  212. $sql .= " AND c.entity IN (".getEntity('commande').")";
  213. $sql .= " AND c.fk_statut = ".Commande::STATUS_VALIDATED;
  214. if ($socid) {
  215. $sql .= " AND c.fk_soc = ".((int) $socid);
  216. }
  217. if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
  218. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  219. }
  220. $sql .= " ORDER BY c.rowid DESC";
  221. $resql = $db->query($sql);
  222. if ($resql) {
  223. $num = $db->num_rows($resql);
  224. print '<div class="div-table-responsive-no-min">';
  225. print '<table class="noborder centpercent">';
  226. print '<tr class="liste_titre">';
  227. print '<th colspan="4">'.$langs->trans("OrdersToProcess").' <a href="'.DOL_URL_ROOT.'/commande/list.php?search_status='.Commande::STATUS_VALIDATED.'"><span class="badge">'.$num.'</span></a></th></tr>';
  228. if ($num) {
  229. $i = 0;
  230. while ($i < $num && $i < $max) {
  231. $obj = $db->fetch_object($resql);
  232. print '<tr class="oddeven">';
  233. print '<td class="nowrap" width="20%">';
  234. $commandestatic->id = $obj->rowid;
  235. $commandestatic->ref = $obj->ref;
  236. $companystatic->id = $obj->socid;
  237. $companystatic->name = $obj->name;
  238. $companystatic->client = $obj->client;
  239. $companystatic->code_client = $obj->code_client;
  240. $companystatic->canvas = $obj->canvas;
  241. print '<table class="nobordernopadding"><tr class="nocellnopadd">';
  242. print '<td width="96" class="nobordernopadding nowrap">';
  243. print $commandestatic->getNomUrl(1);
  244. print '</td>';
  245. print '<td width="16" class="nobordernopadding nowrap">';
  246. print '&nbsp;';
  247. print '</td>';
  248. print '<td width="16" class="nobordernopadding hideonsmartphone right">';
  249. $filename = dol_sanitizeFileName($obj->ref);
  250. $filedir = $conf->commande->multidir_output[$obj->entity].'/'.dol_sanitizeFileName($obj->ref);
  251. $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
  252. print $formfile->getDocumentsLink($commandestatic->element, $filename, $filedir);
  253. print '</td></tr></table>';
  254. print '</td>';
  255. print '<td class="nowrap">';
  256. print $companystatic->getNomUrl(1, 'company', 24);
  257. print '</td>';
  258. print '<td class="right">'.dol_print_date($db->jdate($obj->date), 'day').'</td>'."\n";
  259. print '<td class="right">'.$commandestatic->LibStatut($obj->fk_statut, $obj->facture, 3).'</td>';
  260. print '</tr>';
  261. $i++;
  262. }
  263. if ($i < $num) {
  264. print '<tr><td><span class="opacitymedium">'.$langs->trans("More").'...</span></td><td></td><td></td><td></td></tr>';
  265. }
  266. }
  267. print "</table></div><br>";
  268. } else {
  269. dol_print_error($db);
  270. }
  271. }
  272. /*
  273. * Orders that are in process
  274. */
  275. if (isModEnabled('commande')) {
  276. $sql = "SELECT c.rowid, c.entity, c.ref, c.fk_statut, c.facture, c.date_commande as date, s.nom as name, s.rowid as socid";
  277. $sql .= ", s.client";
  278. $sql .= ", s.code_client";
  279. $sql .= ", s.canvas";
  280. $sql .= " FROM ".MAIN_DB_PREFIX."commande as c";
  281. $sql .= ", ".MAIN_DB_PREFIX."societe as s";
  282. if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
  283. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  284. }
  285. $sql .= " WHERE c.fk_soc = s.rowid";
  286. $sql .= " AND c.entity IN (".getEntity('commande').")";
  287. $sql .= " AND c.fk_statut = ".((int) Commande::STATUS_ACCEPTED);
  288. if ($socid) {
  289. $sql .= " AND c.fk_soc = ".((int) $socid);
  290. }
  291. if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
  292. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  293. }
  294. $sql .= " ORDER BY c.rowid DESC";
  295. $resql = $db->query($sql);
  296. if ($resql) {
  297. $num = $db->num_rows($resql);
  298. print '<div class="div-table-responsive-no-min">';
  299. print '<table class="noborder centpercent">';
  300. print '<tr class="liste_titre">';
  301. print '<th colspan="4">'.$langs->trans("OnProcessOrders").' <a href="'.DOL_URL_ROOT.'/commande/list.php?search_status='.Commande::STATUS_ACCEPTED.'"><span class="badge">'.$num.'</span></a></th></tr>';
  302. if ($num) {
  303. $i = 0;
  304. while ($i < $num && $i < $max) {
  305. $obj = $db->fetch_object($resql);
  306. print '<tr class="oddeven">';
  307. print '<td width="20%" class="nowrap">';
  308. $commandestatic->id = $obj->rowid;
  309. $commandestatic->ref = $obj->ref;
  310. $companystatic->id = $obj->socid;
  311. $companystatic->name = $obj->name;
  312. $companystatic->client = $obj->client;
  313. $companystatic->code_client = $obj->code_client;
  314. $companystatic->canvas = $obj->canvas;
  315. print '<table class="nobordernopadding"><tr class="nocellnopadd">';
  316. print '<td width="96" class="nobordernopadding nowrap">';
  317. print $commandestatic->getNomUrl(1);
  318. print '</td>';
  319. print '<td width="16" class="nobordernopadding nowrap">';
  320. print '&nbsp;';
  321. print '</td>';
  322. print '<td width="16" class="nobordernopadding hideonsmartphone right">';
  323. $filename = dol_sanitizeFileName($obj->ref);
  324. $filedir = $conf->commande->multidir_output[$obj->entity].'/'.dol_sanitizeFileName($obj->ref);
  325. $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
  326. print $formfile->getDocumentsLink($commandestatic->element, $filename, $filedir);
  327. print '</td></tr></table>';
  328. print '</td>';
  329. print '<td>';
  330. print $companystatic->getNomUrl(1, 'company');
  331. print '</td>';
  332. print '<td class="right">'.dol_print_date($db->jdate($obj->date), 'day').'</td>'."\n";
  333. print '<td class="right">'.$commandestatic->LibStatut($obj->fk_statut, $obj->facture, 3).'</td>';
  334. print '</tr>';
  335. $i++;
  336. }
  337. if ($i < $num) {
  338. print '<tr><td><span class="opacitymedium">'.$langs->trans("More").'...</span></td><td></td><td></td><td></td></tr>';
  339. }
  340. }
  341. print "</table></div><br>";
  342. } else {
  343. dol_print_error($db);
  344. }
  345. }
  346. print '</div></div>';
  347. $parameters = array('user' => $user);
  348. $reshook = $hookmanager->executeHooks('dashboardOrders', $parameters, $object); // Note that $action and $object may have been modified by hook
  349. // End of page
  350. llxFooter();
  351. $db->close();