movement_card.php 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225
  1. <?php
  2. /* Copyright (C) 2001-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2020 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2014 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2015 Juanjo Menent <jmenent@2byte.es>
  6. * Copyright (C) 2018 Ferran Marcet <fmarcet@2byte.es>
  7. * Copyright (C) 2019 Frédéric France <frederic.france@netlogic.fr>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  21. */
  22. /**
  23. * \file htdocs/product/stock/movement_card.php
  24. * \ingroup stock
  25. * \brief Page to list stock movements
  26. */
  27. // Load Dolibarr environment
  28. require '../../main.inc.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/product/stock/class/productlot.class.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  35. require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
  36. require_once DOL_DOCUMENT_ROOT.'/core/lib/stock.lib.php';
  37. require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
  38. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  39. if (isModEnabled('project')) {
  40. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
  41. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  42. }
  43. // Load translation files required by the page
  44. $langs->loadLangs(array('products', 'stocks', 'orders'));
  45. if (isModEnabled('productbatch')) {
  46. $langs->load("productbatch");
  47. }
  48. // Security check
  49. $result = restrictedArea($user, 'stock');
  50. $id = GETPOST('id', 'int');
  51. $ref = GETPOST('ref', 'alpha');
  52. $msid = GETPOST('msid', 'int');
  53. $product_id = GETPOST("product_id", 'int');
  54. $action = GETPOST('action', 'aZ09');
  55. $cancel = GETPOST('cancel', 'alpha');
  56. $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'movementlist';
  57. $idproduct = GETPOST('idproduct', 'int');
  58. $year = GETPOST("year", 'int');
  59. $month = GETPOST("month", 'int');
  60. $search_ref = GETPOST('search_ref', 'alpha');
  61. $search_movement = GETPOST("search_movement", 'alpha');
  62. $search_product_ref = trim(GETPOST("search_product_ref", 'alpha'));
  63. $search_product = trim(GETPOST("search_product", 'alpha'));
  64. $search_warehouse = trim(GETPOST("search_warehouse", 'alpha'));
  65. $search_inventorycode = trim(GETPOST("search_inventorycode", 'alpha'));
  66. $search_user = trim(GETPOST("search_user", 'alpha'));
  67. $search_batch = trim(GETPOST("search_batch", 'alpha'));
  68. $search_qty = trim(GETPOST("search_qty", 'alpha'));
  69. $search_type_mouvement = GETPOST('search_type_mouvement', 'int');
  70. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  71. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  72. $sortfield = GETPOST('sortfield', 'aZ09comma');
  73. $sortorder = GETPOST('sortorder', 'aZ09comma');
  74. if (empty($page) || $page == -1) {
  75. $page = 0;
  76. } // If $page is not defined, or '' or -1
  77. $offset = $limit * $page;
  78. if (!$sortfield) {
  79. $sortfield = "m.datem";
  80. }
  81. if (!$sortorder) {
  82. $sortorder = "DESC";
  83. }
  84. $pdluoid = GETPOST('pdluoid', 'int');
  85. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  86. $object = new MouvementStock($db);
  87. $hookmanager->initHooks(array('movementlist'));
  88. $extrafields = new ExtraFields($db);
  89. $formfile = new FormFile($db);
  90. // fetch optionals attributes and labels
  91. $extrafields->fetch_name_optionals_label($object->table_element);
  92. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  93. $arrayfields = array(
  94. 'm.rowid'=>array('label'=>$langs->trans("Ref"), 'checked'=>1),
  95. 'm.datem'=>array('label'=>$langs->trans("Date"), 'checked'=>1),
  96. 'p.ref'=>array('label'=>$langs->trans("ProductRef"), 'checked'=>1, 'css'=>'maxwidth100'),
  97. 'p.label'=>array('label'=>$langs->trans("ProductLabel"), 'checked'=>1),
  98. 'm.batch'=>array('label'=>$langs->trans("BatchNumberShort"), 'checked'=>1, 'enabled'=>(isModEnabled('productbatch'))),
  99. 'pl.eatby'=>array('label'=>$langs->trans("EatByDate"), 'checked'=>0, 'position'=>10, 'enabled'=>(isModEnabled('productbatch'))),
  100. 'pl.sellby'=>array('label'=>$langs->trans("SellByDate"), 'checked'=>0, 'position'=>10, 'enabled'=>(isModEnabled('productbatch'))),
  101. 'e.ref'=>array('label'=>$langs->trans("Warehouse"), 'checked'=>1, 'enabled'=>(!($id > 0))), // If we are on specific warehouse, we hide it
  102. 'm.fk_user_author'=>array('label'=>$langs->trans("Author"), 'checked'=>0),
  103. 'm.inventorycode'=>array('label'=>$langs->trans("InventoryCodeShort"), 'checked'=>1),
  104. 'm.label'=>array('label'=>$langs->trans("MovementLabel"), 'checked'=>1),
  105. 'm.type_mouvement'=>array('label'=>$langs->trans("TypeMovement"), 'checked'=>1),
  106. 'origin'=>array('label'=>$langs->trans("Origin"), 'checked'=>1),
  107. 'm.value'=>array('label'=>$langs->trans("Qty"), 'checked'=>1),
  108. 'm.price'=>array('label'=>$langs->trans("UnitPurchaseValue"), 'checked'=>0),
  109. //'m.datec'=>array('label'=>$langs->trans("DateCreation"), 'checked'=>0, 'position'=>500),
  110. //'m.tms'=>array('label'=>$langs->trans("DateModificationShort"), 'checked'=>0, 'position'=>500)
  111. );
  112. $usercanread = (($user->rights->stock->mouvement->lire));
  113. $usercancreate = (($user->rights->stock->mouvement->creer));
  114. $usercandelete = (($user->rights->stock->mouvement->supprimer));
  115. /*
  116. * Actions
  117. */
  118. if (GETPOST('cancel', 'alpha')) {
  119. $action = 'list';
  120. $massaction = '';
  121. }
  122. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
  123. $massaction = '';
  124. }
  125. $parameters = array();
  126. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  127. if ($reshook < 0) {
  128. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  129. }
  130. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  131. // Do we click on purge search criteria ?
  132. 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
  133. $year = '';
  134. $month = '';
  135. $search_ref = '';
  136. $search_movement = "";
  137. $search_type_mouvement = "";
  138. $search_inventorycode = "";
  139. $search_product_ref = "";
  140. $search_product = "";
  141. $search_warehouse = "";
  142. $search_user = "";
  143. $search_batch = "";
  144. $search_qty = '';
  145. $sall = "";
  146. $toselect = array();
  147. $search_array_options = array();
  148. }
  149. // Correct stock
  150. if ($action == "correct_stock") {
  151. $product = new Product($db);
  152. if (!empty($product_id)) {
  153. $result = $product->fetch($product_id);
  154. }
  155. $error = 0;
  156. if (empty($product_id)) {
  157. $error++;
  158. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Product")), null, 'errors');
  159. $action = 'correction';
  160. }
  161. if (!is_numeric(GETPOST("nbpiece"))) {
  162. $error++;
  163. setEventMessages($langs->trans("ErrorFieldMustBeANumeric", $langs->transnoentitiesnoconv("NumberOfUnit")), null, 'errors');
  164. $action = 'correction';
  165. }
  166. if (!$error) {
  167. $origin_element = '';
  168. $origin_id = null;
  169. if (GETPOST('projectid', 'int')) {
  170. $origin_element = 'project';
  171. $origin_id = GETPOST('projectid', 'int');
  172. }
  173. if ($product->hasbatch()) {
  174. $batch = GETPOST('batch_number', 'alpha');
  175. //$eatby=GETPOST('eatby');
  176. //$sellby=GETPOST('sellby');
  177. $eatby = dol_mktime(0, 0, 0, GETPOST('eatbymonth', 'int'), GETPOST('eatbyday', 'int'), GETPOST('eatbyyear', 'int'));
  178. $sellby = dol_mktime(0, 0, 0, GETPOST('sellbymonth', 'int'), GETPOST('sellbyday', 'int'), GETPOST('sellbyyear', 'int'));
  179. $result = $product->correct_stock_batch(
  180. $user,
  181. $id,
  182. GETPOST("nbpiece", 'int'),
  183. GETPOST("mouvement", 'int'),
  184. GETPOST("label", 'san_alpha'),
  185. GETPOST('unitprice', 'alpha'),
  186. $eatby,
  187. $sellby,
  188. $batch,
  189. GETPOST('inventorycode', 'alpha'),
  190. $origin_element,
  191. $origin_id
  192. ); // We do not change value of stock for a correction
  193. } else {
  194. $result = $product->correct_stock(
  195. $user,
  196. $id,
  197. GETPOST("nbpiece", 'int'),
  198. GETPOST("mouvement", 'alpha'),
  199. GETPOST("label", 'san_alpha'),
  200. GETPOST('unitprice', 'alpha'),
  201. GETPOST('inventorycode', 'alpha'),
  202. $origin_element,
  203. $origin_id
  204. ); // We do not change value of stock for a correction
  205. }
  206. if ($result > 0) {
  207. header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
  208. exit;
  209. } else {
  210. $error++;
  211. setEventMessages($product->error, $product->errors, 'errors');
  212. $action = 'correction';
  213. }
  214. }
  215. if (!$error) {
  216. $action = '';
  217. }
  218. }
  219. // Transfer stock from a warehouse to another warehouse
  220. if ($action == "transfert_stock" && !$cancel) {
  221. $product = new Product($db);
  222. if (!empty($product_id)) {
  223. $result = $product->fetch($product_id);
  224. }
  225. if (!(GETPOST("id_entrepot_destination", 'int') > 0)) {
  226. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Warehouse")), null, 'errors');
  227. $error++;
  228. $action = 'transfert';
  229. }
  230. if (empty($product_id)) {
  231. $error++;
  232. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Product")), null, 'errors');
  233. $action = 'transfert';
  234. }
  235. if (!GETPOST("nbpiece", 'int')) {
  236. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("NumberOfUnit")), null, 'errors');
  237. $error++;
  238. $action = 'transfert';
  239. }
  240. if ($id == GETPOST("id_entrepot_destination", 'int')) {
  241. setEventMessages($langs->trans("ErrorSrcAndTargetWarehouseMustDiffers"), null, 'errors');
  242. $error++;
  243. $action = 'transfert';
  244. }
  245. if (isModEnabled('productbatch')) {
  246. $product = new Product($db);
  247. $result = $product->fetch($product_id);
  248. if ($product->hasbatch() && !GETPOST("batch_number", 'alpha')) {
  249. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("batch_number")), null, 'errors');
  250. $error++;
  251. $action = 'transfert';
  252. }
  253. }
  254. if (!$error) {
  255. if ($id) {
  256. $object = new Entrepot($db);
  257. $result = $object->fetch($id);
  258. $db->begin();
  259. $product->load_stock('novirtual'); // Load array product->stock_warehouse
  260. // Define value of products moved
  261. $pricesrc = 0;
  262. if (isset($product->pmp)) {
  263. $pricesrc = $product->pmp;
  264. }
  265. $pricedest = $pricesrc;
  266. if ($product->hasbatch()) {
  267. $pdluo = new Productbatch($db);
  268. if ($pdluoid > 0) {
  269. $result = $pdluo->fetch($pdluoid);
  270. if ($result) {
  271. $srcwarehouseid = $pdluo->warehouseid;
  272. $batch = $pdluo->batch;
  273. $eatby = $pdluo->eatby;
  274. $sellby = $pdluo->sellby;
  275. } else {
  276. setEventMessages($pdluo->error, $pdluo->errors, 'errors');
  277. $error++;
  278. }
  279. } else {
  280. $srcwarehouseid = $id;
  281. $batch = GETPOST('batch_number', 'alpha');
  282. $eatby = $d_eatby;
  283. $sellby = $d_sellby;
  284. }
  285. if (!$error) {
  286. // Remove stock
  287. $result1 = $product->correct_stock_batch(
  288. $user,
  289. $srcwarehouseid,
  290. GETPOST("nbpiece", 'int'),
  291. 1,
  292. GETPOST("label", 'san_alpha'),
  293. $pricesrc,
  294. $eatby,
  295. $sellby,
  296. $batch,
  297. GETPOST('inventorycode', 'alpha')
  298. );
  299. // Add stock
  300. $result2 = $product->correct_stock_batch(
  301. $user,
  302. GETPOST("id_entrepot_destination", 'int'),
  303. GETPOST("nbpiece", 'int'),
  304. 0,
  305. GETPOST("label", 'san_alpha'),
  306. $pricedest,
  307. $eatby,
  308. $sellby,
  309. $batch,
  310. GETPOST('inventorycode', 'alpha')
  311. );
  312. }
  313. } else {
  314. // Remove stock
  315. $result1 = $product->correct_stock(
  316. $user,
  317. $id,
  318. GETPOST("nbpiece", 'int'),
  319. 1,
  320. GETPOST("label", 'alpha'),
  321. $pricesrc,
  322. GETPOST('inventorycode', 'alpha')
  323. );
  324. // Add stock
  325. $result2 = $product->correct_stock(
  326. $user,
  327. GETPOST("id_entrepot_destination"),
  328. GETPOST("nbpiece", 'int'),
  329. 0,
  330. GETPOST("label", 'alpha'),
  331. $pricedest,
  332. GETPOST('inventorycode', 'alpha')
  333. );
  334. }
  335. if (!$error && $result1 >= 0 && $result2 >= 0) {
  336. $db->commit();
  337. if ($backtopage) {
  338. header("Location: ".$backtopage);
  339. exit;
  340. } else {
  341. header("Location: movement_list.php?id=".$object->id);
  342. exit;
  343. }
  344. } else {
  345. setEventMessages($product->error, $product->errors, 'errors');
  346. $db->rollback();
  347. $action = 'transfert';
  348. }
  349. }
  350. }
  351. }
  352. /*
  353. * Build document
  354. */
  355. // The builddoc action for object of a movement must be on the movement card
  356. // Actions to build doc
  357. $upload_dir = $conf->stock->dir_output."movement/";
  358. $permissiontoadd = $user->rights->stock->creer;
  359. include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
  360. if (empty($reshook) && $action != 'remove_file') {
  361. $objectclass = 'MouvementStock';
  362. $objectlabel = 'Movements';
  363. $permissiontoread = $user->rights->stock->lire;
  364. $permissiontodelete = $user->rights->stock->supprimer;
  365. $uploaddir = $conf->stock->dir_output."/movement/";
  366. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  367. }
  368. /*
  369. * View
  370. */
  371. $productlot = new Productlot($db);
  372. $productstatic = new Product($db);
  373. $warehousestatic = new Entrepot($db);
  374. $movement = new MouvementStock($db);
  375. $userstatic = new User($db);
  376. $form = new Form($db);
  377. $formother = new FormOther($db);
  378. $formproduct = new FormProduct($db);
  379. if (isModEnabled('project')) {
  380. $formproject = new FormProjets($db);
  381. }
  382. $sql = "SELECT p.rowid, p.ref as product_ref, p.label as produit, p.tobatch, p.fk_product_type as type, p.entity,";
  383. $sql .= " e.ref as warehouse_ref, e.rowid as entrepot_id, e.lieu,";
  384. $sql .= " m.rowid as mid, m.value as qty, m.datem, m.fk_user_author, m.label, m.inventorycode, m.fk_origin, m.origintype,";
  385. $sql .= " m.batch, m.price,";
  386. $sql .= " m.type_mouvement,";
  387. $sql .= " pl.rowid as lotid, pl.eatby, pl.sellby,";
  388. $sql .= " u.login, u.photo, u.lastname, u.firstname";
  389. // Add fields from extrafields
  390. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  391. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  392. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
  393. }
  394. }
  395. // Add fields from hooks
  396. $parameters = array();
  397. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
  398. $sql .= $hookmanager->resPrint;
  399. $sql .= " FROM ".MAIN_DB_PREFIX."entrepot as e,";
  400. $sql .= " ".MAIN_DB_PREFIX."product as p,";
  401. $sql .= " ".MAIN_DB_PREFIX."stock_mouvement as m";
  402. if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
  403. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (m.rowid = ef.fk_object)";
  404. }
  405. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON m.fk_user_author = u.rowid";
  406. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_lot as pl ON m.batch = pl.batch AND m.fk_product = pl.fk_product";
  407. $sql .= " WHERE m.fk_product = p.rowid";
  408. if ($msid > 0) {
  409. $sql .= " AND m.rowid = ".((int) $msid);
  410. }
  411. $sql .= " AND m.fk_entrepot = e.rowid";
  412. $sql .= " AND e.entity IN (".getEntity('stock').")";
  413. if (!getDolGlobalString('STOCK_SUPPORTS_SERVICES')) {
  414. $sql .= " AND p.fk_product_type = 0";
  415. }
  416. if ($id > 0) {
  417. $sql .= " AND e.rowid = ".((int) $id);
  418. }
  419. $sql .= dolSqlDateFilter('m.datem', 0, $month, $year);
  420. if ($idproduct > 0) {
  421. $sql .= " AND p.rowid = ".((int) $idproduct);
  422. }
  423. if (!empty($search_ref)) {
  424. $sql .= natural_search('m.rowid', $search_ref, 1);
  425. }
  426. if (!empty($search_movement)) {
  427. $sql .= natural_search('m.label', $search_movement);
  428. }
  429. if (!empty($search_inventorycode)) {
  430. $sql .= natural_search('m.inventorycode', $search_inventorycode);
  431. }
  432. if (!empty($search_product_ref)) {
  433. $sql .= natural_search('p.ref', $search_product_ref);
  434. }
  435. if (!empty($search_product)) {
  436. $sql .= natural_search('p.label', $search_product);
  437. }
  438. if ($search_warehouse != '' && $search_warehouse != '-1') {
  439. $sql .= natural_search('e.rowid', $search_warehouse, 2);
  440. }
  441. if (!empty($search_user)) {
  442. $sql .= natural_search(array('u.lastname', 'u.firstname', 'u.login'), $search_user);
  443. }
  444. if (!empty($search_batch)) {
  445. $sql .= natural_search('m.batch', $search_batch);
  446. }
  447. if ($search_qty != '') {
  448. $sql .= natural_search('m.value', $search_qty, 1);
  449. }
  450. if ($search_type_mouvement != '' && $search_type_mouvement != '-1') {
  451. $sql .= natural_search('m.type_mouvement', $search_type_mouvement, 2);
  452. }
  453. // Add where from extra fields
  454. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
  455. // Add where from hooks
  456. $parameters = array();
  457. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook
  458. $sql .= $hookmanager->resPrint;
  459. $sql .= $db->order($sortfield, $sortorder);
  460. $nbtotalofrecords = '';
  461. if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
  462. $result = $db->query($sql);
  463. $nbtotalofrecords = $db->num_rows($result);
  464. if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
  465. $page = 0;
  466. $offset = 0;
  467. }
  468. }
  469. //print $sql;
  470. $resql = $db->query($sql);
  471. if ($resql) {
  472. $product = new Product($db);
  473. $object = new Entrepot($db);
  474. if ($idproduct > 0) {
  475. $product->fetch($idproduct);
  476. }
  477. if ($id > 0 || $ref) {
  478. $result = $object->fetch($id, $ref);
  479. if ($result < 0) {
  480. dol_print_error($db);
  481. }
  482. }
  483. $num = $db->num_rows($resql);
  484. $arrayofselected = is_array($toselect) ? $toselect : array();
  485. $i = 0;
  486. $help_url = 'EN:Module_Stocks_En|FR:Module_Stock|ES:M&oacute;dulo_Stocks';
  487. if ($msid) {
  488. $texte = $langs->trans('StockMovementForId', $msid);
  489. } else {
  490. $texte = $langs->trans("ListOfStockMovements");
  491. if ($id) {
  492. $texte .= ' ('.$langs->trans("ForThisWarehouse").')';
  493. }
  494. }
  495. llxHeader("", $texte, $help_url);
  496. /*
  497. * Show tab only if we ask a particular warehouse
  498. */
  499. if ($object->id > 0) {
  500. $head = stock_prepare_head($object);
  501. print dol_get_fiche_head($head, 'movements', $langs->trans("Warehouse"), -1, 'stock');
  502. $linkback = '<a href="'.DOL_URL_ROOT.'/product/stock/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  503. $morehtmlref = '<div class="refidno">';
  504. $morehtmlref .= $langs->trans("LocationSummary").' : '.$object->lieu;
  505. $morehtmlref .= '</div>';
  506. $shownav = 1;
  507. if ($user->socid && !in_array('stock', explode(',', getDolGlobalString('MAIN_MODULES_FOR_EXTERNAL')))) {
  508. $shownav = 0;
  509. }
  510. dol_banner_tab($object, 'ref', $linkback, $shownav, 'ref', 'ref', $morehtmlref);
  511. print '<div class="fichecenter">';
  512. print '<div class="fichehalfleft">';
  513. print '<div class="underbanner clearboth"></div>';
  514. print '<table class="border centpercent">';
  515. print '<tr>';
  516. // Description
  517. print '<td class="titlefield tdtop">'.$langs->trans("Description").'</td><td>'.dol_htmlentitiesbr($object->description).'</td></tr>';
  518. $calcproductsunique = $object->nb_different_products();
  519. $calcproducts = $object->nb_products();
  520. // Total nb of different products
  521. print '<tr><td>'.$langs->trans("NumberOfDifferentProducts").'</td><td>';
  522. print empty($calcproductsunique['nb']) ? '0' : $calcproductsunique['nb'];
  523. print "</td></tr>";
  524. // Nb of products
  525. print '<tr><td>'.$langs->trans("NumberOfProducts").'</td><td>';
  526. $valtoshow = price2num($calcproducts['nb'], 'MS');
  527. print empty($valtoshow) ? '0' : $valtoshow;
  528. print "</td></tr>";
  529. print '</table>';
  530. print '</div>';
  531. print '<div class="fichehalfright">';
  532. print '<div class="underbanner clearboth"></div>';
  533. print '<table class="border centpercent">';
  534. // Value
  535. print '<tr><td class="titlefield">'.$langs->trans("EstimatedStockValueShort").'</td><td>';
  536. print price((empty($calcproducts['value']) ? '0' : price2num($calcproducts['value'], 'MT')), 0, $langs, 0, -1, -1, $conf->currency);
  537. print "</td></tr>";
  538. // Last movement
  539. $sql = "SELECT MAX(m.datem) as datem";
  540. $sql .= " FROM ".MAIN_DB_PREFIX."stock_mouvement as m";
  541. $sql .= " WHERE m.fk_entrepot = ".(int) $object->id;
  542. $resqlbis = $db->query($sql);
  543. if ($resqlbis) {
  544. $obj = $db->fetch_object($resqlbis);
  545. $lastmovementdate = $db->jdate($obj->datem);
  546. } else {
  547. dol_print_error($db);
  548. }
  549. print '<tr><td>'.$langs->trans("LastMovement").'</td><td>';
  550. if ($lastmovementdate) {
  551. print dol_print_date($lastmovementdate, 'dayhour');
  552. } else {
  553. print $langs->trans("None");
  554. }
  555. print "</td></tr>";
  556. print "</table>";
  557. print '</div>';
  558. print '</div>';
  559. print '<div class="clearboth"></div>';
  560. print dol_get_fiche_end();
  561. }
  562. /*
  563. * Correct stock
  564. */
  565. if ($action == "correction") {
  566. include DOL_DOCUMENT_ROOT.'/product/stock/tpl/stockcorrection.tpl.php';
  567. print '<br>';
  568. }
  569. /*
  570. * Transfer of units
  571. */
  572. if ($action == "transfert") {
  573. include DOL_DOCUMENT_ROOT.'/product/stock/tpl/stocktransfer.tpl.php';
  574. print '<br>';
  575. }
  576. /*
  577. * Action bar
  578. */
  579. if ((empty($action) || $action == 'list') && $id > 0) {
  580. print "<div class=\"tabsAction\">\n";
  581. if ($user->hasRight('stock', 'mouvement', 'creer')) {
  582. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$id.'&action=correction">'.$langs->trans("CorrectStock").'</a>';
  583. }
  584. if ($user->hasRight('stock', 'mouvement', 'creer')) {
  585. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$id.'&action=transfert">'.$langs->trans("TransferStock").'</a>';
  586. }
  587. print '</div><br>';
  588. }
  589. $param = '';
  590. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  591. $param .= '&contextpage='.urlencode($contextpage);
  592. }
  593. if ($limit > 0 && $limit != $conf->liste_limit) {
  594. $param .= '&limit='.((int) $limit);
  595. }
  596. if ($id > 0) {
  597. $param .= '&id='.urlencode($id);
  598. }
  599. if ($search_movement) {
  600. $param .= '&search_movement='.urlencode($search_movement);
  601. }
  602. if ($search_inventorycode) {
  603. $param .= '&search_inventorycode='.urlencode($search_inventorycode);
  604. }
  605. if ($search_type_mouvement) {
  606. $param .= '&search_type_mouvement='.urlencode($search_type_mouvement);
  607. }
  608. if ($search_product_ref) {
  609. $param .= '&search_product_ref='.urlencode($search_product_ref);
  610. }
  611. if ($search_product) {
  612. $param .= '&search_product='.urlencode($search_product);
  613. }
  614. if ($search_batch) {
  615. $param .= '&search_batch='.urlencode($search_batch);
  616. }
  617. if ($search_warehouse > 0) {
  618. $param .= '&search_warehouse='.urlencode($search_warehouse);
  619. }
  620. if ($search_user) {
  621. $param .= '&search_user='.urlencode($search_user);
  622. }
  623. if ($idproduct > 0) {
  624. $param .= '&idproduct='.urlencode($idproduct);
  625. }
  626. // Add $param from extra fields
  627. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  628. // List of mass actions available
  629. $arrayofmassactions = array(
  630. // 'presend'=>$langs->trans("SendByMail"),
  631. // 'builddoc'=>$langs->trans("PDFMerge"),
  632. );
  633. //if ($user->rights->stock->supprimer) $arrayofmassactions['predelete']='<span class="fa fa-trash paddingrightonly"></span>'.$langs->trans("Delete");
  634. if (in_array($massaction, array('presend', 'predelete'))) {
  635. $arrayofmassactions = array();
  636. }
  637. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  638. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  639. if ($optioncss != '') {
  640. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  641. }
  642. print '<input type="hidden" name="token" value="'.newToken().'">';
  643. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  644. print '<input type="hidden" name="action" value="list">';
  645. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  646. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  647. print '<input type="hidden" name="page" value="'.$page.'">';
  648. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  649. if ($id > 0) {
  650. print '<input type="hidden" name="id" value="'.$id.'">';
  651. }
  652. if ($id > 0) {
  653. print_barre_liste($texte, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, '', 0, '', '', $limit);
  654. } else {
  655. print_barre_liste($texte, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'generic', 0, '', '', $limit);
  656. }
  657. if ($sall) {
  658. foreach ($fieldstosearchall as $key => $val) {
  659. $fieldstosearchall[$key] = $langs->trans($val);
  660. }
  661. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'</div>';
  662. }
  663. $moreforfilter = '';
  664. $parameters = array();
  665. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
  666. if (empty($reshook)) {
  667. $moreforfilter .= $hookmanager->resPrint;
  668. } else {
  669. $moreforfilter = $hookmanager->resPrint;
  670. }
  671. if (!empty($moreforfilter)) {
  672. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  673. print $moreforfilter;
  674. print '</div>';
  675. }
  676. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  677. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  678. print '<div class="div-table-responsive">';
  679. print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  680. // Fields title search
  681. print '<tr class="liste_titre_filter">';
  682. if (!empty($arrayfields['m.rowid']['checked'])) {
  683. // Ref
  684. print '<td class="liste_titre left">';
  685. print '<input class="flat maxwidth25" type="text" name="search_ref" value="'.dol_escape_htmltag($search_ref).'">';
  686. print '</td>';
  687. }
  688. if (!empty($arrayfields['m.datem']['checked'])) {
  689. print '<td class="liste_titre nowraponall">';
  690. print '<input class="flat" type="text" size="2" maxlength="2" placeholder="'.dol_escape_htmltag($langs->trans("Month")).'" name="month" value="'.$month.'">';
  691. if (empty($conf->productbatch->enabled)) {
  692. print '&nbsp;';
  693. }
  694. //else print '<br>';
  695. $syear = $year ? $year : -1;
  696. print '<input class="flat maxwidth50" type="text" maxlength="4" placeholder="'.dol_escape_htmltag($langs->trans("Year")).'" name="year" value="'.($syear > 0 ? $syear : '').'">';
  697. //print $formother->selectyear($syear,'year',1, 20, 5);
  698. print '</td>';
  699. }
  700. if (!empty($arrayfields['p.ref']['checked'])) {
  701. // Product Ref
  702. print '<td class="liste_titre left">';
  703. print '<input class="flat maxwidth75" type="text" name="search_product_ref" value="'.dol_escape_htmltag($idproduct ? $product->ref : $search_product_ref).'">';
  704. print '</td>';
  705. }
  706. if (!empty($arrayfields['p.label']['checked'])) {
  707. // Product label
  708. print '<td class="liste_titre left">';
  709. print '<input class="flat maxwidth100" type="text" name="search_product" value="'.dol_escape_htmltag($idproduct ? $product->label : $search_product).'">';
  710. print '</td>';
  711. }
  712. // Batch
  713. if (!empty($arrayfields['m.batch']['checked'])) {
  714. print '<td class="liste_titre center"><input class="flat maxwidth75" type="text" name="search_batch" value="'.dol_escape_htmltag($search_batch).'"></td>';
  715. }
  716. if (!empty($arrayfields['pl.eatby']['checked'])) {
  717. print '<td class="liste_titre left">';
  718. print '</td>';
  719. }
  720. if (!empty($arrayfields['pl.sellby']['checked'])) {
  721. print '<td class="liste_titre left">';
  722. print '</td>';
  723. }
  724. // Warehouse
  725. if (!empty($arrayfields['e.ref']['checked'])) {
  726. print '<td class="liste_titre maxwidthonsmartphone left">';
  727. //print '<input class="flat" type="text" size="8" name="search_warehouse" value="'.($search_warehouse).'">';
  728. print $formproduct->selectWarehouses($search_warehouse, 'search_warehouse', 'warehouseopen,warehouseinternal', 1, 0, 0, '', 0, 0, null, 'maxwidth200');
  729. print '</td>';
  730. }
  731. if (!empty($arrayfields['m.fk_user_author']['checked'])) {
  732. // Author
  733. print '<td class="liste_titre left">';
  734. print '<input class="flat" type="text" size="6" name="search_user" value="'.dol_escape_htmltag($search_user).'">';
  735. print '</td>';
  736. }
  737. if (!empty($arrayfields['m.inventorycode']['checked'])) {
  738. // Inventory code
  739. print '<td class="liste_titre left">';
  740. print '<input class="flat" type="text" size="4" name="search_inventorycode" value="'.dol_escape_htmltag($search_inventorycode).'">';
  741. print '</td>';
  742. }
  743. if (!empty($arrayfields['m.label']['checked'])) {
  744. // Label of movement
  745. print '<td class="liste_titre left">';
  746. print '<input class="flat" type="text" size="8" name="search_movement" value="'.dol_escape_htmltag($search_movement).'">';
  747. print '</td>';
  748. }
  749. if (!empty($arrayfields['m.type_mouvement']['checked'])) {
  750. // Type of movement
  751. print '<td class="liste_titre center">';
  752. //print '<input class="flat" type="text" size="3" name="search_type_mouvement" value="'.dol_escape_htmltag($search_type_mouvement).'">';
  753. print '<select id="search_type_mouvement" name="search_type_mouvement" class="maxwidth150">';
  754. print '<option value="" '.(($search_type_mouvement == "") ? 'selected="selected"' : '').'></option>';
  755. print '<option value="0" '.(($search_type_mouvement == "0") ? 'selected="selected"' : '').'>'.$langs->trans('StockIncreaseAfterCorrectTransfer').'</option>';
  756. print '<option value="1" '.(($search_type_mouvement == "1") ? 'selected="selected"' : '').'>'.$langs->trans('StockDecreaseAfterCorrectTransfer').'</option>';
  757. print '<option value="2" '.(($search_type_mouvement == "2") ? 'selected="selected"' : '').'>'.$langs->trans('StockDecrease').'</option>';
  758. print '<option value="3" '.(($search_type_mouvement == "3") ? 'selected="selected"' : '').'>'.$langs->trans('StockIncrease').'</option>';
  759. print '</select>';
  760. print ajax_combobox('search_type_mouvement');
  761. // TODO: add new function $formentrepot->selectTypeOfMovement(...) like
  762. // print $formproduct->selectWarehouses($search_warehouse, 'search_warehouse', 'warehouseopen,warehouseinternal', 1, 0, 0, '', 0, 0, null, 'maxwidth200');
  763. print '</td>';
  764. }
  765. if (!empty($arrayfields['origin']['checked'])) {
  766. // Origin of movement
  767. print '<td class="liste_titre left">';
  768. print '&nbsp; ';
  769. print '</td>';
  770. }
  771. if (!empty($arrayfields['m.value']['checked'])) {
  772. // Qty
  773. print '<td class="liste_titre right">';
  774. print '<input class="flat" type="text" size="4" name="search_qty" value="'.dol_escape_htmltag($search_qty).'">';
  775. print '</td>';
  776. }
  777. if (!empty($arrayfields['m.price']['checked'])) {
  778. // Price
  779. print '<td class="liste_titre left">';
  780. print '&nbsp; ';
  781. print '</td>';
  782. }
  783. // Extra fields
  784. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  785. // Fields from hook
  786. $parameters = array('arrayfields'=>$arrayfields);
  787. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
  788. print $hookmanager->resPrint;
  789. // Date creation
  790. if (!empty($arrayfields['m.datec']['checked'])) {
  791. print '<td class="liste_titre">';
  792. print '</td>';
  793. }
  794. // Date modification
  795. if (!empty($arrayfields['m.tms']['checked'])) {
  796. print '<td class="liste_titre">';
  797. print '</td>';
  798. }
  799. // Actions
  800. print '<td class="liste_titre maxwidthsearch">';
  801. $searchpicto = $form->showFilterAndCheckAddButtons(0);
  802. print $searchpicto;
  803. print '</td>';
  804. print "</tr>\n";
  805. print '<tr class="liste_titre">';
  806. if (!empty($arrayfields['m.rowid']['checked'])) {
  807. print_liste_field_titre($arrayfields['m.rowid']['label'], $_SERVER["PHP_SELF"], 'm.rowid', '', $param, '', $sortfield, $sortorder);
  808. }
  809. if (!empty($arrayfields['m.datem']['checked'])) {
  810. print_liste_field_titre($arrayfields['m.datem']['label'], $_SERVER["PHP_SELF"], 'm.datem', '', $param, '', $sortfield, $sortorder);
  811. }
  812. if (!empty($arrayfields['p.ref']['checked'])) {
  813. print_liste_field_titre($arrayfields['p.ref']['label'], $_SERVER["PHP_SELF"], 'p.ref', '', $param, '', $sortfield, $sortorder);
  814. }
  815. if (!empty($arrayfields['p.label']['checked'])) {
  816. print_liste_field_titre($arrayfields['p.label']['label'], $_SERVER["PHP_SELF"], 'p.label', '', $param, '', $sortfield, $sortorder);
  817. }
  818. if (!empty($arrayfields['m.batch']['checked'])) {
  819. print_liste_field_titre($arrayfields['m.batch']['label'], $_SERVER["PHP_SELF"], 'm.batch', '', $param, '', $sortfield, $sortorder, 'center ');
  820. }
  821. if (!empty($arrayfields['pl.eatby']['checked'])) {
  822. print_liste_field_titre($arrayfields['pl.eatby']['label'], $_SERVER["PHP_SELF"], 'pl.eatby', '', $param, '', $sortfield, $sortorder, 'center ');
  823. }
  824. if (!empty($arrayfields['pl.sellby']['checked'])) {
  825. print_liste_field_titre($arrayfields['pl.sellby']['label'], $_SERVER["PHP_SELF"], 'pl.sellby', '', $param, '', $sortfield, $sortorder, 'center ');
  826. }
  827. if (!empty($arrayfields['e.ref']['checked'])) {
  828. // We are on a specific warehouse card, no filter on other should be possible
  829. print_liste_field_titre($arrayfields['e.ref']['label'], $_SERVER["PHP_SELF"], "e.ref", "", $param, "", $sortfield, $sortorder);
  830. }
  831. if (!empty($arrayfields['m.fk_user_author']['checked'])) {
  832. print_liste_field_titre($arrayfields['m.fk_user_author']['label'], $_SERVER["PHP_SELF"], "m.fk_user_author", "", $param, "", $sortfield, $sortorder);
  833. }
  834. if (!empty($arrayfields['m.inventorycode']['checked'])) {
  835. print_liste_field_titre($arrayfields['m.inventorycode']['label'], $_SERVER["PHP_SELF"], "m.inventorycode", "", $param, "", $sortfield, $sortorder);
  836. }
  837. if (!empty($arrayfields['m.label']['checked'])) {
  838. print_liste_field_titre($arrayfields['m.label']['label'], $_SERVER["PHP_SELF"], "m.label", "", $param, "", $sortfield, $sortorder);
  839. }
  840. if (!empty($arrayfields['m.type_mouvement']['checked'])) {
  841. print_liste_field_titre($arrayfields['m.type_mouvement']['label'], $_SERVER["PHP_SELF"], "m.type_mouvement", "", $param, '', $sortfield, $sortorder, 'center ');
  842. }
  843. if (!empty($arrayfields['origin']['checked'])) {
  844. print_liste_field_titre($arrayfields['origin']['label'], $_SERVER["PHP_SELF"], "", "", $param, "", $sortfield, $sortorder);
  845. }
  846. if (!empty($arrayfields['m.value']['checked'])) {
  847. print_liste_field_titre($arrayfields['m.value']['label'], $_SERVER["PHP_SELF"], "m.value", "", $param, '', $sortfield, $sortorder, 'right ');
  848. }
  849. if (!empty($arrayfields['m.price']['checked'])) {
  850. print_liste_field_titre($arrayfields['m.price']['label'], $_SERVER["PHP_SELF"], "m.price", "", $param, '', $sortfield, $sortorder, 'right ');
  851. }
  852. // Extra fields
  853. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  854. // Hook fields
  855. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
  856. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
  857. print $hookmanager->resPrint;
  858. if (!empty($arrayfields['m.datec']['checked'])) {
  859. print_liste_field_titre($arrayfields['p.datec']['label'], $_SERVER["PHP_SELF"], "p.datec", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
  860. }
  861. if (!empty($arrayfields['m.tms']['checked'])) {
  862. print_liste_field_titre($arrayfields['p.tms']['label'], $_SERVER["PHP_SELF"], "p.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
  863. }
  864. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
  865. print "</tr>\n";
  866. $arrayofuniqueproduct = array();
  867. while ($i < ($limit ? min($num, $limit) : $num)) {
  868. $objp = $db->fetch_object($resql);
  869. $userstatic->id = $objp->fk_user_author;
  870. $userstatic->login = $objp->login;
  871. $userstatic->lastname = $objp->lastname;
  872. $userstatic->firstname = $objp->firstname;
  873. $userstatic->photo = $objp->photo;
  874. $productstatic->id = $objp->rowid;
  875. $productstatic->ref = $objp->product_ref;
  876. $productstatic->label = $objp->produit;
  877. $productstatic->type = $objp->type;
  878. $productstatic->entity = $objp->entity;
  879. $productstatic->status_batch = $objp->tobatch;
  880. $productlot->id = $objp->lotid;
  881. $productlot->batch = $objp->batch;
  882. $productlot->eatby = $objp->eatby;
  883. $productlot->sellby = $objp->sellby;
  884. $warehousestatic->id = $objp->entrepot_id;
  885. $warehousestatic->label = $objp->warehouse_ref;
  886. $warehousestatic->lieu = $objp->lieu;
  887. $arrayofuniqueproduct[$objp->rowid] = $objp->produit;
  888. if (!empty($objp->fk_origin)) {
  889. $origin = $movement->get_origin($objp->fk_origin, $objp->origintype);
  890. } else {
  891. $origin = '';
  892. }
  893. print '<tr class="oddeven">';
  894. // Id movement
  895. if (!empty($arrayfields['m.rowid']['checked'])) {
  896. // This is primary not movement id
  897. print '<td>'.$objp->mid.'</td>';
  898. }
  899. if (!empty($arrayfields['m.datem']['checked'])) {
  900. // Date
  901. print '<td>'.dol_print_date($db->jdate($objp->datem), 'dayhour').'</td>';
  902. }
  903. if (!empty($arrayfields['p.ref']['checked'])) {
  904. // Product ref
  905. print '<td class="nowraponall">';
  906. print $productstatic->getNomUrl(1, 'stock', 16);
  907. print "</td>\n";
  908. }
  909. if (!empty($arrayfields['p.label']['checked'])) {
  910. // Product label
  911. print '<td>';
  912. /*$productstatic->id=$objp->rowid;
  913. $productstatic->ref=$objp->produit;
  914. $productstatic->type=$objp->type;
  915. print $productstatic->getNomUrl(1,'',16);*/
  916. print $productstatic->label;
  917. print "</td>\n";
  918. }
  919. if (!empty($arrayfields['m.batch']['checked'])) {
  920. print '<td class="center nowraponall">';
  921. if ($productlot->id > 0) {
  922. print $productlot->getNomUrl(1);
  923. } else {
  924. print $productlot->batch; // the id may not be defined if movement was entered when lot was not saved or if lot was removed after movement.
  925. }
  926. print '</td>';
  927. }
  928. if (!empty($arrayfields['pl.eatby']['checked'])) {
  929. print '<td class="center">'.dol_print_date($objp->eatby, 'day').'</td>';
  930. }
  931. if (!empty($arrayfields['pl.sellby']['checked'])) {
  932. print '<td class="center">'.dol_print_date($objp->sellby, 'day').'</td>';
  933. }
  934. // Warehouse
  935. if (!empty($arrayfields['e.ref']['checked'])) {
  936. print '<td>';
  937. print $warehousestatic->getNomUrl(1);
  938. print "</td>\n";
  939. }
  940. // Author
  941. if (!empty($arrayfields['m.fk_user_author']['checked'])) {
  942. print '<td class="tdoverflowmax100">';
  943. print $userstatic->getNomUrl(-1);
  944. print "</td>\n";
  945. }
  946. if (!empty($arrayfields['m.inventorycode']['checked'])) {
  947. // Inventory code
  948. print '<td><a href="'
  949. .DOL_URL_ROOT.'/product/stock/movement_card.php?id='.urlencode($objp->entrepot_id)
  950. .'&search_inventorycode='.urlencode($objp->inventorycode)
  951. .'&search_type_mouvement='.urlencode($objp->type_mouvement)
  952. .'">'
  953. .$objp->inventorycode
  954. .'</a></td>';
  955. }
  956. if (!empty($arrayfields['m.label']['checked'])) {
  957. // Label of movement
  958. print '<td class="tdoverflowmax100aaa">'.$objp->label.'</td>';
  959. }
  960. if (!empty($arrayfields['m.type_mouvement']['checked'])) {
  961. // Type of movement
  962. switch ($objp->type_mouvement) {
  963. case "0":
  964. print '<td class="center">'.$langs->trans('StockIncreaseAfterCorrectTransfer').'</td>';
  965. break;
  966. case "1":
  967. print '<td class="center">'.$langs->trans('StockDecreaseAfterCorrectTransfer').'</td>';
  968. break;
  969. case "2":
  970. print '<td class="center">'.$langs->trans('StockDecrease').'</td>';
  971. break;
  972. case "3":
  973. print '<td class="center">'.$langs->trans('StockIncrease').'</td>';
  974. break;
  975. }
  976. }
  977. if (!empty($arrayfields['origin']['checked'])) {
  978. // Origin of movement
  979. print '<td class="nowraponall">'.$origin.'</td>';
  980. }
  981. if (!empty($arrayfields['m.value']['checked'])) {
  982. // Qty
  983. print '<td class="right">';
  984. if ($objp->qt > 0) {
  985. print '+';
  986. }
  987. print $objp->qty;
  988. print '</td>';
  989. }
  990. if (!empty($arrayfields['m.price']['checked'])) {
  991. // Price
  992. print '<td class="right">';
  993. if ($objp->price != 0) {
  994. print price($objp->price);
  995. }
  996. print '</td>';
  997. }
  998. // Action column
  999. print '<td class="nowrap center">';
  1000. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  1001. $selected = 0;
  1002. if (in_array($obj->rowid, $arrayofselected)) {
  1003. $selected = 1;
  1004. }
  1005. print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
  1006. }
  1007. print '</td>';
  1008. if (!$i) {
  1009. $totalarray['nbfield']++;
  1010. }
  1011. print "</tr>\n";
  1012. $i++;
  1013. }
  1014. $db->free($resql);
  1015. print "</table>";
  1016. print '</div>';
  1017. print "</form>";
  1018. // Add number of product when there is a filter on period
  1019. if (count($arrayofuniqueproduct) == 1 && is_numeric($year)) {
  1020. print "<br>";
  1021. $productidselected = 0;
  1022. foreach ($arrayofuniqueproduct as $key => $val) {
  1023. $productidselected = $key;
  1024. $productlabelselected = $val;
  1025. }
  1026. $datebefore = dol_get_first_day($year ? $year : strftime("%Y", time()), $month ? $month : 1, true);
  1027. $dateafter = dol_get_last_day($year ? $year : strftime("%Y", time()), $month ? $month : 12, true);
  1028. $balancebefore = $movement->calculateBalanceForProductBefore($productidselected, $datebefore);
  1029. $balanceafter = $movement->calculateBalanceForProductBefore($productidselected, $dateafter);
  1030. //print '<tr class="total"><td class="liste_total">';
  1031. print $langs->trans("NbOfProductBeforePeriod", $productlabelselected, dol_print_date($datebefore, 'day', 'gmt'));
  1032. //print '</td>';
  1033. //print '<td class="liste_total right" colspan="6">';
  1034. print ': '.$balancebefore;
  1035. print "<br>\n";
  1036. //print '</td></tr>';
  1037. //print '<tr class="total"><td class="liste_total">';
  1038. print $langs->trans("NbOfProductAfterPeriod", $productlabelselected, dol_print_date($dateafter, 'day', 'gmt'));
  1039. //print '</td>';
  1040. //print '<td class="liste_total right" colspan="6">';
  1041. print ': '.$balanceafter;
  1042. print "<br>\n";
  1043. //print '</td></tr>';
  1044. }
  1045. } else {
  1046. dol_print_error($db);
  1047. }
  1048. /*
  1049. * Generated documents
  1050. */
  1051. //Area for doc and last events of warehouse are stored on the main card of warehouse
  1052. $modulepart = 'movement';
  1053. if ($action != 'create' && $action != 'edit' && $action != 'delete' && $id > 0) {
  1054. print '<br>';
  1055. print '<div class="fichecenter"><div class="fichehalfleft">';
  1056. print '<a name="builddoc"></a>'; // ancre
  1057. // Documents
  1058. $objectref = dol_sanitizeFileName($object->ref);
  1059. // Add inventorycode & type_mouvement to filename of the pdf
  1060. if (!empty($search_inventorycode)) {
  1061. $objectref .= "_".$id."_".$search_inventorycode;
  1062. }
  1063. if ($search_type_mouvement) {
  1064. $objectref .= "_".$search_type_mouvement;
  1065. }
  1066. $relativepath = $comref.'/'.$objectref.'.pdf';
  1067. $filedir = $conf->stock->dir_output.'/movement/'.$objectref;
  1068. $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id."&search_inventorycode=".$search_inventorycode."&search_type_mouvement=$search_type_mouvement";
  1069. $genallowed = $usercanread;
  1070. $delallowed = $usercancreate;
  1071. $genallowed = $user->rights->stock->lire;
  1072. $delallowed = $user->rights->stock->creer;
  1073. print $formfile->showdocuments($modulepart, $objectref, $filedir, $urlsource, $genallowed, $delallowed, '', 0, 0, 0, 28, 0, '', 0, '', $object->default_lang, '', $object);
  1074. $somethingshown = $formfile->numoffiles;
  1075. print '</div><div class="fichehalfright">';
  1076. $MAXEVENT = 10;
  1077. $morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT.'/product/agenda.php?id='.$object->id);
  1078. // List of actions on element
  1079. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
  1080. $formactions = new FormActions($db);
  1081. $somethingshown = $formactions->showactions($object, 'mouvement', 0, 1, '', $MAXEVENT, '', $morehtmlcenter); // Show all action for product
  1082. print '</div></div>';
  1083. }
  1084. // End of page
  1085. llxFooter();
  1086. $db->close();