movement_card.php 43 KB

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