index.php 9.2 KB

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