index.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. <?php
  2. /* Copyright (C) 2003-2005 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) 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/expedition/index.php
  23. * \ingroup expedition
  24. * \brief Home page of shipping area.
  25. */
  26. // Load Dolibarr environment
  27. require '../main.inc.php';
  28. require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
  30. $hookmanager = new HookManager($db);
  31. $socid = GETPOST('socid', 'int');
  32. // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
  33. $hookmanager->initHooks(array('sendingindex'));
  34. // Load translation files required by the page
  35. $langs->loadLangs(array('orders', 'sendings'));
  36. /*
  37. * View
  38. */
  39. $orderstatic = new Commande($db);
  40. $companystatic = new Societe($db);
  41. $shipment = new Expedition($db);
  42. $helpurl = 'EN:Module_Shipments|FR:Module_Exp&eacute;ditions|ES:M&oacute;dulo_Expediciones';
  43. llxHeader('', $langs->trans("Shipment"), $helpurl);
  44. print load_fiche_titre($langs->trans("SendingsArea"), '', 'dolly');
  45. print '<div class="fichecenter"><div class="fichethirdleft">';
  46. /*
  47. * Shipments to validate
  48. */
  49. $clause = " WHERE ";
  50. $sql = "SELECT e.rowid, e.ref, e.ref_customer,";
  51. $sql .= " s.nom as name, s.rowid as socid,";
  52. $sql .= " c.ref as commande_ref, c.rowid as commande_id";
  53. $sql .= " FROM ".MAIN_DB_PREFIX."expedition as e";
  54. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON e.rowid = el.fk_target AND el.targettype = 'shipping'";
  55. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."commande as c ON el.fk_source = c.rowid";
  56. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = e.fk_soc";
  57. if (empty($user->rights->societe->client->voir) && !$socid) {
  58. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON e.fk_soc = sc.fk_soc";
  59. $sql .= $clause." sc.fk_user = ".((int) $user->id);
  60. $clause = " AND ";
  61. }
  62. $sql .= $clause." e.fk_statut = ".Expedition::STATUS_DRAFT;
  63. $sql .= " AND e.entity IN (".getEntity('expedition').")";
  64. if ($socid) {
  65. $sql .= " AND c.fk_soc = ".((int) $socid);
  66. }
  67. $resql = $db->query($sql);
  68. if ($resql) {
  69. $num = $db->num_rows($resql);
  70. print '<div class="div-table-responsive-no-min">';
  71. print '<table class="noborder centpercent">';
  72. print '<tr class="liste_titre">';
  73. print '<th colspan="3">';
  74. print $langs->trans("SendingsToValidate").' ';
  75. print '<a href="'.DOL_URL_ROOT.'/expedition/list.php?search_status='.Expedition::STATUS_DRAFT.'">';
  76. print '<span class="badge">'.$num.'</span>';
  77. print '</a>';
  78. print '</th>';
  79. print '</tr>';
  80. if ($num) {
  81. $i = 0;
  82. while ($i < $num) {
  83. $obj = $db->fetch_object($resql);
  84. $shipment->id = $obj->rowid;
  85. $shipment->ref = $obj->ref;
  86. $shipment->ref_customer = $obj->ref_customer;
  87. print '<tr class="oddeven"><td class="nowrap">';
  88. print $shipment->getNomUrl(1);
  89. print "</td>";
  90. print '<td>';
  91. print '<a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$obj->socid.'">'.$obj->name.'</a>';
  92. print '</td>';
  93. print '<td>';
  94. if ($obj->commande_id) {
  95. print '<a href="'.DOL_URL_ROOT.'/commande/card.php?id='.$obj->commande_id.'">'.$obj->commande_ref.'</a>';
  96. }
  97. print '</td></tr>';
  98. $i++;
  99. }
  100. } else {
  101. print '<tr><td>'.$langs->trans("None").'</td><td></td><td></td></tr>';
  102. }
  103. print "</table></div><br>";
  104. }
  105. //print '</td><td valign="top" width="70%">';
  106. print '</div><div class="fichetwothirdright">';
  107. $max = 5;
  108. /*
  109. * Latest shipments
  110. */
  111. $sql = "SELECT e.rowid, e.ref, e.ref_customer,";
  112. $sql .= " s.nom as name, s.rowid as socid,";
  113. $sql .= " c.ref as commande_ref, c.rowid as commande_id";
  114. $sql .= " FROM ".MAIN_DB_PREFIX."expedition as e";
  115. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON e.rowid = el.fk_target AND el.targettype = 'shipping' AND el.sourcetype IN ('commande')";
  116. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."commande as c ON el.fk_source = c.rowid AND el.sourcetype IN ('commande') AND el.targettype = 'shipping'";
  117. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = e.fk_soc";
  118. if (empty($user->rights->societe->client->voir) && !$socid) {
  119. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON e.fk_soc = sc.fk_soc";
  120. }
  121. $sql .= " WHERE e.entity IN (".getEntity('expedition').")";
  122. if (empty($user->rights->societe->client->voir) && !$socid) {
  123. $sql .= " AND sc.fk_user = ".((int) $user->id);
  124. }
  125. $sql .= " AND e.fk_statut = ".Expedition::STATUS_VALIDATED;
  126. if ($socid) {
  127. $sql .= " AND c.fk_soc = ".((int) $socid);
  128. }
  129. $sql .= " ORDER BY e.date_delivery DESC";
  130. $sql .= $db->plimit($max, 0);
  131. $resql = $db->query($sql);
  132. if ($resql) {
  133. $num = $db->num_rows($resql);
  134. print '<div class="div-table-responsive-no-min">';
  135. print '<table class="noborder centpercent">';
  136. print '<tr class="liste_titre">';
  137. print '<th colspan="4">';
  138. print $langs->trans("LastSendings").' ';
  139. print '<a href="'.DOL_URL_ROOT.'/expedition/list.php?search_status='.Expedition::STATUS_VALIDATED.'">';
  140. print '<span class="badge">'.$num.'</span>';
  141. print '</a>';
  142. print '</th>';
  143. print '</tr>';
  144. if ($num) {
  145. $i = 0;
  146. while ($i < $num) {
  147. $obj = $db->fetch_object($resql);
  148. $shipment->id = $obj->rowid;
  149. $shipment->ref = $obj->ref;
  150. $shipment->ref_customer = $obj->ref_customer;
  151. print '<tr class="oddeven"><td>';
  152. print $shipment->getNomUrl(1);
  153. print '</td>';
  154. print '<td><a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"), "company").' '.$obj->name.'</a></td>';
  155. print '<td>';
  156. if ($obj->commande_id > 0) {
  157. $orderstatic->id = $obj->commande_id;
  158. $orderstatic->ref = $obj->commande_ref;
  159. print $orderstatic->getNomUrl(1);
  160. }
  161. print '</td>';
  162. print '<td class="">';
  163. print '</td>';
  164. print '</tr>';
  165. $i++;
  166. }
  167. } else {
  168. print '<tr><td>'.$langs->trans("None").'</td><td></td><td></td><td></td></tr>';
  169. }
  170. print "</table></div><br>";
  171. $db->free($resql);
  172. } else {
  173. dol_print_error($db);
  174. }
  175. /*
  176. * Open orders
  177. */
  178. $sql = "SELECT c.rowid, c.ref, c.ref_client as ref_customer, c.fk_statut as status, c.facture as billed, s.nom as name, s.rowid as socid";
  179. $sql .= " FROM ".MAIN_DB_PREFIX."commande as c,";
  180. $sql .= " ".MAIN_DB_PREFIX."societe as s";
  181. if (empty($user->rights->societe->client->voir) && !$socid) {
  182. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  183. }
  184. $sql .= " WHERE c.fk_soc = s.rowid";
  185. $sql .= " AND c.entity IN (".getEntity('order').")";
  186. $sql .= " AND c.fk_statut IN (".Commande::STATUS_VALIDATED.", ".Commande::STATUS_ACCEPTED.")";
  187. if ($socid > 0) {
  188. $sql .= " AND c.fk_soc = ".((int) $socid);
  189. }
  190. if (empty($user->rights->societe->client->voir) && !$socid) {
  191. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  192. }
  193. $sql .= " ORDER BY c.rowid ASC";
  194. $resql = $db->query($sql);
  195. if ($resql) {
  196. $langs->load("orders");
  197. $num = $db->num_rows($resql);
  198. print '<div class="div-table-responsive-no-min">';
  199. print '<table class="noborder centpercent">';
  200. print '<tr class="liste_titre">';
  201. print '<th colspan="3">'.$langs->trans("OrdersToProcess").' ';
  202. print '<a href="'.DOL_URL_ROOT.'/commande/list.php?search_status='.Commande::STATUS_VALIDATED.','.Commande::STATUS_ACCEPTED.'">';
  203. print '<span class="badge">'.$num.'</span>';
  204. print '</a>';
  205. print '</th>';
  206. print '</tr>';
  207. if ($num) {
  208. $i = 0;
  209. while ($i < $num && $i < 10) {
  210. $obj = $db->fetch_object($resql);
  211. $orderstatic->id = $obj->rowid;
  212. $orderstatic->ref = $obj->ref;
  213. $orderstatic->ref_customer = $obj->ref_customer;
  214. $orderstatic->statut = $obj->status;
  215. $orderstatic->billed = $obj->billed;
  216. $companystatic->name = $obj->name;
  217. $companystatic->id = $obj->socid;
  218. print '<tr class="oddeven"><td>';
  219. print $orderstatic->getNomUrl(1);
  220. print '</td>';
  221. print '<td>';
  222. print $companystatic->getNomUrl(1, 'customer', 32);
  223. print '</td>';
  224. print '<td class="right">';
  225. print $orderstatic->getLibStatut(3);
  226. print '</td>';
  227. print '</tr>';
  228. $i++;
  229. }
  230. if ($i < $num) {
  231. print '<tr class="opacitymedium">';
  232. print '<td>'.$langs->trans("More").'...</td>';
  233. print '<td></td>';
  234. print '<td></td>';
  235. print '</tr>';
  236. }
  237. } else {
  238. print '<tr><td>'.$langs->trans("None").'</td><td></td><td></td></tr>';
  239. }
  240. print "</table></div><br>";
  241. } else {
  242. dol_print_error($db);
  243. }
  244. print '</div></div>';
  245. $parameters = array('user' => $user);
  246. $reshook = $hookmanager->executeHooks('dashboardWarehouseSendings', $parameters, $object); // Note that $action and $object may have been modified by hook
  247. // End of page
  248. llxFooter();
  249. $db->close();