index.php 13 KB

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