movement_card.php 43 KB

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