index.php 9.2 KB

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