index.php 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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@capnetworks.com>
  5. * Copyright (C) 2018 Quentin Vial-Gouteyron <quentin.vial-gouteyron@atm-consulting.fr>
  6. * Copyright (C) 2019 Nicolas ZABOURI <info@inovea-conseil.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/reception/index.php
  23. * \ingroup reception
  24. * \brief Home page of reception area.
  25. */
  26. // Load Dolibarr environment
  27. require '../main.inc.php';
  28. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/reception/class/reception.class.php';
  30. $hookmanager = new HookManager($db);
  31. // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
  32. $hookmanager->initHooks(array('receptionindex'));
  33. $langs->loadLangs(array("orders", "receptions"));
  34. $reception = new Reception($db);
  35. // Security check
  36. $socid = '';
  37. if ($user->socid) {
  38. $socid = $user->socid;
  39. }
  40. $result = restrictedArea($user, 'reception', 0, '');
  41. /*
  42. * View
  43. */
  44. $orderstatic = new CommandeFournisseur($db);
  45. $companystatic = new Societe($db);
  46. $helpurl = 'EN:Module_Receptions|FR:Module_Receptions|ES:M&oacute;dulo_Receptiones';
  47. llxHeader('', $langs->trans("Reception"), $helpurl);
  48. print load_fiche_titre($langs->trans("ReceptionsArea"), '', 'dollyrevert');
  49. print '<div class="fichecenter"><div class="fichethirdleft">';
  50. if (getDolGlobalString('MAIN_SEARCH_FORM_ON_HOME_AREAS')) { // This may be useless due to the global search combo
  51. print '<form method="post" action="list.php">';
  52. print '<input type="hidden" name="token" value="'.newToken().'">';
  53. print '<div class="div-table-responsive-no-min">';
  54. print '<table class="noborder nohover centpercent">';
  55. print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("Search").'</td></tr>';
  56. print '<tr class="oddeven"><td>';
  57. print $langs->trans("Reception").':</td><td><input type="text" class="flat" name="sall" size="18"></td><td><input type="submit" value="'.$langs->trans("Search").'" class="button"></td></tr>';
  58. print "</table></div></form><br>\n";
  59. }
  60. /*
  61. * Draft receptions
  62. */
  63. $clause = " WHERE ";
  64. $sql = "SELECT e.rowid, e.ref, e.ref_supplier,";
  65. $sql .= " s.nom as name, s.rowid as socid,";
  66. $sql .= " c.ref as commande_fournisseur_ref, c.rowid as commande_fournisseur_id";
  67. $sql .= " FROM ".MAIN_DB_PREFIX."reception as e";
  68. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON e.rowid = el.fk_target AND el.targettype = 'reception'";
  69. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."commande_fournisseur as c ON el.fk_source = c.rowid";
  70. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = e.fk_soc";
  71. if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
  72. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON e.fk_soc = sc.fk_soc";
  73. $sql .= $clause." sc.fk_user = ".((int) $user->id);
  74. $clause = " AND ";
  75. }
  76. $sql .= $clause." e.fk_statut = 0";
  77. $sql .= " AND e.entity IN (".getEntity('reception').")";
  78. if ($socid) {
  79. $sql .= " AND c.fk_soc = ".((int) $socid);
  80. }
  81. $resql = $db->query($sql);
  82. if ($resql) {
  83. print '<div class="div-table-responsive-no-min">';
  84. print '<table class="noborder centpercent">';
  85. print '<tr class="liste_titre">';
  86. print '<th colspan="3">'.$langs->trans("ReceptionsToValidate").'</th></tr>';
  87. $num = $db->num_rows($resql);
  88. if ($num) {
  89. $i = 0;
  90. while ($i < $num) {
  91. $obj = $db->fetch_object($resql);
  92. $reception->id = $obj->rowid;
  93. $reception->ref = $obj->ref;
  94. $reception->ref_supplier = $obj->ref_supplier;
  95. print '<tr class="oddeven"><td class="nowrap">';
  96. print $reception->getNomUrl(1);
  97. print "</td>";
  98. print '<td>';
  99. print '<a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$obj->socid.'">'.$obj->name.'</a>';
  100. print '</td>';
  101. print '<td>';
  102. if ($obj->commande_fournisseur_id) {
  103. print '<a href="'.DOL_URL_ROOT.'/commande_fournisseur/card.php?id='.$obj->commande_fournisseur_id.'">'.$obj->commande_fournisseur_ref.'</a>';
  104. }
  105. print '</td></tr>';
  106. $i++;
  107. }
  108. } else {
  109. print '<tr><td><span class="opacitymedium">'.$langs->trans("None").'</span></td><td></td><td></td></tr>';
  110. }
  111. print "</table></div><br>";
  112. }
  113. print '</div><div class="fichetwothirdright">';
  114. $max = 5;
  115. /*
  116. * Latest receptions
  117. */
  118. $sql = "SELECT e.rowid, e.ref, e.ref_supplier,";
  119. $sql .= " s.nom as name, s.rowid as socid,";
  120. $sql .= " c.ref as commande_fournisseur_ref, c.rowid as commande_fournisseur_id";
  121. $sql .= " FROM ".MAIN_DB_PREFIX."reception as e";
  122. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON e.rowid = el.fk_target AND el.targettype = 'reception' AND el.sourcetype IN ('order_supplier')";
  123. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."commande_fournisseur as c ON el.fk_source = c.rowid AND el.sourcetype IN ('order_supplier') AND el.targettype = 'reception'";
  124. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = e.fk_soc";
  125. if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
  126. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON e.fk_soc = sc.fk_soc";
  127. }
  128. $sql .= " WHERE e.entity IN (".getEntity('reception').")";
  129. if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
  130. $sql .= " AND sc.fk_user = ".((int) $user->id);
  131. }
  132. $sql .= " AND e.fk_statut = 1";
  133. if ($socid) {
  134. $sql .= " AND c.fk_soc = ".((int) $socid);
  135. }
  136. $sql .= " ORDER BY e.date_delivery DESC";
  137. $sql .= $db->plimit($max, 0);
  138. $resql = $db->query($sql);
  139. if ($resql) {
  140. $num = $db->num_rows($resql);
  141. if ($num) {
  142. $i = 0;
  143. print '<div class="div-table-responsive-no-min">';
  144. print '<table class="noborder centpercent">';
  145. print '<tr class="liste_titre">';
  146. print '<th colspan="3">'.$langs->trans("LastReceptions", $num).'</th></tr>';
  147. while ($i < $num) {
  148. $obj = $db->fetch_object($resql);
  149. $reception->id = $obj->rowid;
  150. $reception->ref = $obj->ref;
  151. $reception->ref_supplier = $obj->ref_supplier;
  152. print '<tr class="oddeven"><td>';
  153. print $reception->getNomUrl(1);
  154. print '</td>';
  155. print '<td><a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"), "company").' '.$obj->name.'</a></td>';
  156. print '<td>';
  157. if ($obj->commande_fournisseur_id > 0) {
  158. $orderstatic->id = $obj->commande_fournisseur_id;
  159. $orderstatic->ref = $obj->commande_fournisseur_ref;
  160. print $orderstatic->getNomUrl(1);
  161. } else {
  162. print '&nbsp;';
  163. }
  164. print '</td></tr>';
  165. $i++;
  166. }
  167. print "</table></div><br>";
  168. }
  169. $db->free($resql);
  170. } else {
  171. dol_print_error($db);
  172. }
  173. /*
  174. * Open pruchase orders to process
  175. */
  176. $sql = "SELECT c.rowid, c.ref, c.ref_supplier as ref_supplier, c.fk_statut as status, c.billed as billed, s.nom as name, s.rowid as socid";
  177. $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as c,";
  178. $sql .= " ".MAIN_DB_PREFIX."societe as s";
  179. if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
  180. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  181. }
  182. $sql .= " WHERE c.fk_soc = s.rowid";
  183. $sql .= " AND c.entity IN (".getEntity('supplier_order').")";
  184. $sql .= " AND c.fk_statut IN (".CommandeFournisseur::STATUS_ORDERSENT.", ".CommandeFournisseur::STATUS_RECEIVED_PARTIALLY.")";
  185. if ($socid > 0) {
  186. $sql .= " AND c.fk_soc = ".((int) $socid);
  187. }
  188. if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
  189. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  190. }
  191. $sql .= " ORDER BY c.rowid ASC";
  192. $resql = $db->query($sql);
  193. if ($resql) {
  194. $num = $db->num_rows($resql);
  195. if ($num) {
  196. $langs->load("orders");
  197. $i = 0;
  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("SuppliersOrdersToProcess").' <span class="badge">'.$num.'</span></th></tr>';
  202. while ($i < $num) {
  203. $obj = $db->fetch_object($resql);
  204. $orderstatic->id = $obj->rowid;
  205. $orderstatic->ref = $obj->ref;
  206. $orderstatic->ref_supplier = $obj->ref_supplier;
  207. $orderstatic->statut = $obj->status;
  208. $orderstatic->facturee = $obj->billed;
  209. $companystatic->name = $obj->name;
  210. $companystatic->id = $obj->socid;
  211. print '<tr class="oddeven">';
  212. print '<td class="nowrap">';
  213. print $orderstatic->getNomUrl(1);
  214. print '</td>';
  215. print '<td>';
  216. print $companystatic->getNomUrl(1, 'customer', 32);
  217. print '</td>';
  218. print '<td class="right">';
  219. print $orderstatic->getLibStatut(3);
  220. print '</td>';
  221. print '</tr>';
  222. $i++;
  223. }
  224. print "</table></div><br>";
  225. }
  226. }
  227. print '</div></div>';
  228. $parameters = array('user' => $user);
  229. $reshook = $hookmanager->executeHooks('dashboardWarehouseReceptions', $parameters, $object); // Note that $action and $object may have been modified by hook
  230. llxFooter();
  231. $db->close();