replenishorders.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. <?php
  2. /*
  3. * Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
  4. * Copyright (C) 2014 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2018-2019 Frédéric France <frederic.france@netlogic.fr>
  6. * Copyright (C) 2019 Juanjo Menent <jmenent@2byte.es>
  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/product/stock/replenishorders.php
  23. * \ingroup stock
  24. * \brief Page to list replenishment orders
  25. */
  26. // Load Dolibarr environment
  27. require '../../main.inc.php';
  28. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/product/stock/lib/replenishment.lib.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  35. // Load translation files required by the page
  36. $langs->loadLangs(array('products', 'stocks', 'orders'));
  37. $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'replenishorders'; // To manage different context of search
  38. $sall = GETPOST('search_all', 'alphanohtml');
  39. $sref = GETPOST('search_ref', 'alpha');
  40. $snom = GETPOST('search_nom', 'alpha');
  41. $suser = GETPOST('search_user', 'alpha');
  42. $sttc = GETPOST('search_ttc', 'alpha');
  43. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  44. $search_product = GETPOST('search_product', 'int');
  45. $search_dateyear = GETPOST('search_dateyear', 'int');
  46. $search_datemonth = GETPOST('search_datemonth', 'int');
  47. $search_dateday = GETPOST('search_dateday', 'int');
  48. $search_date = dol_mktime(0, 0, 0, $search_datemonth, $search_dateday, $search_dateyear);
  49. $optioncss = GETPOST('optioncss', 'alpha');
  50. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  51. $sortfield = GETPOST('sortfield', 'aZ09comma');
  52. $sortorder = GETPOST('sortorder', 'aZ09comma');
  53. if (!$sortorder) {
  54. $sortorder = 'DESC';
  55. }
  56. if (!$sortfield) {
  57. $sortfield = 'cf.date_creation';
  58. }
  59. $page = GETPOST('page', 'int') ? GETPOST('page', 'int') : 0;
  60. if ($page < 0) {
  61. $page = 0;
  62. }
  63. $offset = $limit * $page;
  64. // Security check
  65. if ($user->socid) {
  66. $socid = $user->socid;
  67. }
  68. $result = restrictedArea($user, 'produit|service');
  69. /*
  70. * Actions
  71. */
  72. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // Both test are required to be compatible with all browsers
  73. $sall = "";
  74. $sref = "";
  75. $snom = "";
  76. $suser = "";
  77. $sttc = "";
  78. $search_date = '';
  79. $search_datemonth = '';
  80. $search_dateday = '';
  81. $search_dateyear = '';
  82. $search_product = 0;
  83. }
  84. /*
  85. * View
  86. */
  87. $form = new Form($db);
  88. $helpurl = 'EN:Module_Stocks_En|FR:Module_Stock|ES:M&oacute;dulo_Stocks';
  89. $texte = $langs->trans('ReplenishmentOrders');
  90. llxHeader('', $texte, $helpurl, '');
  91. print load_fiche_titre($langs->trans('Replenishment'), '', 'stock');
  92. $head = array();
  93. $head[0][0] = DOL_URL_ROOT.'/product/stock/replenish.php';
  94. $head[0][1] = $langs->trans('MissingStocks');
  95. $head[0][2] = 'replenish';
  96. $head[1][0] = DOL_URL_ROOT.'/product/stock/replenishorders.php';
  97. $head[1][1] = $texte;
  98. $head[1][2] = 'replenishorders';
  99. print dol_get_fiche_head($head, 'replenishorders', '', -1, '');
  100. $commandestatic = new CommandeFournisseur($db);
  101. $sql = 'SELECT s.rowid as socid, s.nom as name, cf.date_creation as dc,';
  102. $sql .= ' cf.rowid, cf.ref, cf.fk_statut, cf.total_ttc, cf.fk_user_author,';
  103. $sql .= ' u.login';
  104. $sql .= ' FROM '.MAIN_DB_PREFIX.'societe as s, '.MAIN_DB_PREFIX.'commande_fournisseur as cf';
  105. $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as u ON cf.fk_user_author = u.rowid';
  106. if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
  107. $sql .= ', '.MAIN_DB_PREFIX.'societe_commerciaux as sc';
  108. }
  109. $sql .= ' WHERE cf.fk_soc = s.rowid ';
  110. $sql .= ' AND cf.entity = '.$conf->entity;
  111. if (!empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER)) {
  112. $sql .= ' AND cf.fk_statut < 3';
  113. } elseif (!empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER) || !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION) || !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE)) {
  114. $sql .= ' AND cf.fk_statut < 6'; // We want also status 5, we will keep them visible if dispatching is not yet finished (tested with function dolDispatchToDo).
  115. } else {
  116. $sql .= ' AND cf.fk_statut < 5';
  117. }
  118. if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
  119. $sql .= ' AND s.rowid = sc.fk_soc AND sc.fk_user = '.((int) $user->id);
  120. }
  121. if ($sref) {
  122. $sql .= natural_search('cf.ref', $sref);
  123. }
  124. if ($snom) {
  125. $sql .= natural_search('s.nom', $snom);
  126. }
  127. if ($suser) {
  128. natural_search(array('u.lastname', 'u.firstname', 'u.login'), $suser);
  129. }
  130. if ($sttc) {
  131. $sql .= natural_search('cf.total_ttc', $sttc, 1);
  132. }
  133. $sql .= dolSqlDateFilter('cf.date_creation', $search_dateday, $search_datemonth, $search_dateyear);
  134. if ($sall) {
  135. $sql .= natural_search(array('cf.ref', 'cf.note'), $sall);
  136. }
  137. if (!empty($socid)) {
  138. $sql .= ' AND s.rowid = '.((int) $socid);
  139. }
  140. if (GETPOST('statut', 'int')) {
  141. $sql .= ' AND fk_statut = '.GETPOST('statut', 'int');
  142. }
  143. $sql .= ' GROUP BY cf.rowid, cf.ref, cf.date_creation, cf.fk_statut';
  144. $sql .= ', cf.total_ttc, cf.fk_user_author, u.login, s.rowid, s.nom';
  145. $sql .= $db->order($sortfield, $sortorder);
  146. if (!$search_product) {
  147. $sql .= $db->plimit($limit + 1, $offset);
  148. }
  149. $resql = $db->query($sql);
  150. if ($resql) {
  151. $num = $db->num_rows($resql);
  152. $i = 0;
  153. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  154. print '<input type="hidden" name="token" value="'.newToken().'">';
  155. print '<span class="opacitymedium hideonsmartphone">'.$langs->trans("ReplenishmentOrdersDesc").'</span><br class="hideonsmartphone">';
  156. print_barre_liste('', $page, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, '', $num, 0, '');
  157. $param = '';
  158. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  159. $param .= '&contextpage='.urlencode($contextpage);
  160. }
  161. if ($limit > 0 && $limit != $conf->liste_limit) {
  162. $param .= '&limit='.((int) $limit);
  163. }
  164. if ($sref) {
  165. $param .= '&search_ref='.urlencode($sref);
  166. }
  167. if ($snom) {
  168. $param .= '&search_nom='.urlencode($snom);
  169. }
  170. if ($suser) {
  171. $param .= '&search_user='.urlencode($suser);
  172. }
  173. if ($sttc) {
  174. $param .= '&search_ttc='.urlencode($sttc);
  175. }
  176. if ($search_dateyear) {
  177. $param .= '&search_dateyear='.urlencode($search_dateyear);
  178. }
  179. if ($search_datemonth) {
  180. $param .= '&search_datemonth='.urlencode($search_datemonth);
  181. }
  182. if ($search_dateday) {
  183. $param .= '&search_dateday='.urlencode($search_dateday);
  184. }
  185. if ($optioncss != '') {
  186. $param .= '&optioncss='.urlencode($optioncss);
  187. }
  188. print '<div class="div-table-responsive-no-min">';
  189. print '<table class="noborder centpercent">';
  190. print '<tr class="liste_titre_filter">';
  191. print '<td class="liste_titre">';
  192. print '<input type="text" class="flat maxwidth100" name="search_ref" value="'.dol_escape_htmltag($sref).'">';
  193. print '</td>';
  194. print '<td class="liste_titre">';
  195. print '<input type="text" class="flat maxwidth100" name="search_nom" value="'.dol_escape_htmltag($snom).'">';
  196. print '</td>';
  197. print '<td class="liste_titre">';
  198. print '<input type="text" class="flat maxwidth100" name="search_user" value="'.dol_escape_htmltag($suser).'">';
  199. print '</td>';
  200. print '<td class="liste_titre right">';
  201. print '<input type="text" class="flat width75" name="search_ttc" value="'.dol_escape_htmltag($sttc).'">';
  202. print '</td>';
  203. print '<td class="liste_titre center">';
  204. print $form->selectDate($search_date, 'search_date', 0, 0, 1, '', 1, 0, 0, '');
  205. print '</td>';
  206. print '<td class="liste_titre right">';
  207. $searchpicto = $form->showFilterAndCheckAddButtons(0);
  208. print $searchpicto;
  209. print '</td>';
  210. print '</tr>';
  211. print '<tr class="liste_titre">';
  212. print_liste_field_titre(
  213. 'Ref',
  214. $_SERVER['PHP_SELF'],
  215. 'cf.ref',
  216. '',
  217. $param,
  218. '',
  219. $sortfield,
  220. $sortorder
  221. );
  222. print_liste_field_titre(
  223. 'Company',
  224. $_SERVER['PHP_SELF'],
  225. 's.nom',
  226. '',
  227. $param,
  228. '',
  229. $sortfield,
  230. $sortorder
  231. );
  232. print_liste_field_titre(
  233. 'Author',
  234. $_SERVER['PHP_SELF'],
  235. 'u.login',
  236. '',
  237. '',
  238. '',
  239. $sortfield,
  240. $sortorder
  241. );
  242. print_liste_field_titre(
  243. 'AmountTTC',
  244. $_SERVER['PHP_SELF'],
  245. 'cf.total_ttc',
  246. '',
  247. $param,
  248. '',
  249. $sortfield,
  250. $sortorder,
  251. 'right '
  252. );
  253. print_liste_field_titre(
  254. 'OrderCreation',
  255. $_SERVER['PHP_SELF'],
  256. 'cf.date_creation',
  257. '',
  258. $param,
  259. '',
  260. $sortfield,
  261. $sortorder,
  262. 'center '
  263. );
  264. print_liste_field_titre(
  265. 'Status',
  266. $_SERVER['PHP_SELF'],
  267. 'cf.fk_statut',
  268. '',
  269. $param,
  270. '',
  271. $sortfield,
  272. $sortorder,
  273. 'right '
  274. );
  275. print '</tr>';
  276. $userstatic = new User($db);
  277. while ($i < min($num, $search_product ? $num : $conf->liste_limit)) {
  278. $obj = $db->fetch_object($resql);
  279. $showline = dolDispatchToDo($obj->rowid) && (!$search_product || in_array($search_product, getProducts($obj->rowid)));
  280. if ($showline) {
  281. $href = DOL_URL_ROOT.'/fourn/commande/card.php?id='.$obj->rowid;
  282. print '<tr>';
  283. // Ref
  284. print '<td>';
  285. print '<a href="'.$href.'">'.img_object($langs->trans('ShowOrder'), 'order').' '.$obj->ref.'</a>';
  286. print '</td>';
  287. // Company
  288. $href = DOL_URL_ROOT.'/fourn/card.php?socid='.$obj->socid;
  289. print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($obj->name).'"><a href="'.$href.'">'.img_object($langs->trans('ShowCompany'), 'company').' '.$obj->name.'</a></td>';
  290. // Author
  291. $userstatic->id = $obj->fk_user_author;
  292. $userstatic->login = $obj->login;
  293. if ($userstatic->id) {
  294. $txt = $userstatic->getLoginUrl(1);
  295. } else {
  296. $txt = '&nbsp;';
  297. }
  298. print '<td>'.$txt.'</td>';
  299. // Amount
  300. print '<td class="right"><span class="amount">'.price($obj->total_ttc).'</span></td>';
  301. // Date
  302. if ($obj->dc) {
  303. $date = dol_print_date($db->jdate($obj->dc), 'dayhour', 'tzuserrel');
  304. } else {
  305. $date = '-';
  306. }
  307. print '<td class="center">'.$date.'</td>';
  308. // Statut
  309. print '<td class="right">'.$commandestatic->LibStatut($obj->fk_statut, 5).'</td>';
  310. print '</tr>';
  311. }
  312. $i++;
  313. }
  314. print '</table>';
  315. print '</div>';
  316. print '</form>';
  317. $db->free($resql);
  318. print dol_get_fiche_end();
  319. } else {
  320. dol_print_error($db);
  321. }
  322. // End of page
  323. llxFooter();
  324. $db->close();