movement_list.php 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639
  1. <?php
  2. /* Copyright (C) 2001-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2017 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-2022 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_list.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. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  40. if (isModEnabled('project')) {
  41. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
  42. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  43. }
  44. // Load translation files required by the page
  45. $langs->loadLangs(array('products', 'stocks', 'orders'));
  46. if (isModEnabled('productbatch')) {
  47. $langs->load("productbatch");
  48. }
  49. $action = GETPOST('action', 'aZ09');
  50. $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
  51. $confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation
  52. $cancel = GETPOST('cancel', 'alpha');
  53. $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : str_replace('_', '', basename(dirname(__FILE__)).basename(__FILE__, '.php')); // To manage different context of search
  54. $toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
  55. $backtopage = GETPOST("backtopage", "alpha");
  56. $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
  57. $mode = GETPOST('mode', 'aZ'); // The output mode ('list', 'kanban', 'hierarchy', 'calendar', ...)
  58. $id = GETPOST('id', 'int');
  59. $ref = GETPOST('ref', 'alpha');
  60. $msid = GETPOST('msid', 'int');
  61. $idproduct = GETPOST('idproduct', 'int');
  62. $product_id = GETPOST("product_id", 'int');
  63. $search_all = trim((GETPOST('search_all', 'alphanohtml') != '') ? GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
  64. $search_date_startday = GETPOST('search_date_startday', 'int');
  65. $search_date_startmonth = GETPOST('search_date_startmonth', 'int');
  66. $search_date_startyear = GETPOST('search_date_startyear', 'int');
  67. $search_date_endday = GETPOST('search_date_endday', 'int');
  68. $search_date_endmonth = GETPOST('search_date_endmonth', 'int');
  69. $search_date_endyear = GETPOST('search_date_endyear', 'int');
  70. $search_date_start = dol_mktime(0, 0, 0, GETPOST('search_date_startmonth', 'int'), GETPOST('search_date_startday', 'int'), GETPOST('search_date_startyear', 'int'), 'tzuserrel');
  71. $search_date_end = dol_mktime(23, 59, 59, GETPOST('search_date_endmonth', 'int'), GETPOST('search_date_endday', 'int'), GETPOST('search_date_endyear', 'int'), 'tzuserrel');
  72. $search_ref = GETPOST('search_ref', 'alpha');
  73. $search_movement = GETPOST("search_movement");
  74. $search_product_ref = trim(GETPOST("search_product_ref"));
  75. $search_product = trim(GETPOST("search_product"));
  76. $search_warehouse = trim(GETPOST("search_warehouse"));
  77. $search_inventorycode = trim(GETPOST("search_inventorycode"));
  78. $search_user = trim(GETPOST("search_user"));
  79. $search_batch = trim(GETPOST("search_batch"));
  80. $search_qty = trim(GETPOST("search_qty"));
  81. $search_type_mouvement = GETPOST('search_type_mouvement', 'int');
  82. $search_fk_project=GETPOST("search_fk_project", 'int');
  83. $type = GETPOST("type", "int");
  84. // Load variable for pagination
  85. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  86. $sortfield = GETPOST('sortfield', 'aZ09comma');
  87. $sortorder = GETPOST('sortorder', 'aZ09comma');
  88. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  89. if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
  90. // If $page is not defined, or '' or -1 or if we click on clear filters
  91. $page = 0;
  92. }
  93. $offset = $limit * $page;
  94. $pageprev = $page - 1;
  95. $pagenext = $page + 1;
  96. if (!$sortfield) {
  97. $sortfield = "m.datem";
  98. }
  99. if (!$sortorder) {
  100. $sortorder = "DESC";
  101. }
  102. $pdluoid = GETPOST('pdluoid', 'int');
  103. // Initialize technical objects
  104. $object = new MouvementStock($db);
  105. $extrafields = new ExtraFields($db);
  106. $diroutputmassaction = $conf->stock->dir_output.'/temp/massgeneration/'.$user->id;
  107. $hookmanager->initHooks(array($contextpage)); // Note that conf->hooks_modules contains array of activated contexes
  108. $formfile = new FormFile($db);
  109. // Fetch optionals attributes and labels
  110. $extrafields->fetch_name_optionals_label($object->table_element);
  111. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  112. $arrayfields = array(
  113. 'm.rowid'=>array('label'=>"Ref", 'checked'=>1, 'position'=>1),
  114. 'm.datem'=>array('label'=>"Date", 'checked'=>1, 'position'=>2),
  115. 'p.ref'=>array('label'=>"ProductRef", 'checked'=>1, 'css'=>'maxwidth100', 'position'=>3),
  116. 'p.label'=>array('label'=>"ProductLabel", 'checked'=>0, 'position'=>5),
  117. 'm.batch'=>array('label'=>"BatchNumberShort", 'checked'=>1, 'position'=>8, 'enabled'=>(isModEnabled('productbatch'))),
  118. 'pl.eatby'=>array('label'=>"EatByDate", 'checked'=>0, 'position'=>9, 'enabled'=>(isModEnabled('productbatch'))),
  119. 'pl.sellby'=>array('label'=>"SellByDate", 'checked'=>0, 'position'=>10, 'enabled'=>(isModEnabled('productbatch'))),
  120. 'e.ref'=>array('label'=>"Warehouse", 'checked'=>1, 'position'=>100, 'enabled'=>(!($id > 0))), // If we are on specific warehouse, we hide it
  121. 'm.fk_user_author'=>array('label'=>"Author", 'checked'=>0, 'position'=>120),
  122. 'm.inventorycode'=>array('label'=>"InventoryCodeShort", 'checked'=>1, 'position'=>130),
  123. 'm.label'=>array('label'=>"MovementLabel", 'checked'=>1, 'position'=>140),
  124. 'm.type_mouvement'=>array('label'=>"TypeMovement", 'checked'=>0, 'position'=>150),
  125. 'origin'=>array('label'=>"Origin", 'checked'=>1, 'position'=>155),
  126. 'm.fk_projet'=>array('label'=>'Project', 'checked'=>0, 'position'=>180),
  127. 'm.value'=>array('label'=>"Qty", 'checked'=>1, 'position'=>200),
  128. 'm.price'=>array('label'=>"UnitPurchaseValue", 'checked'=>0, 'position'=>210, 'enabled'=>(!getDolGlobalInt('STOCK_MOVEMENT_LIST_HIDE_UNIT_PRICE')))
  129. //'m.datec'=>array('label'=>"DateCreation", 'checked'=>0, 'position'=>500),
  130. //'m.tms'=>array('label'=>"DateModificationShort", 'checked'=>0, 'position'=>500)
  131. );
  132. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
  133. if (!empty($conf->global->PRODUCT_DISABLE_SELLBY)) {
  134. unset($arrayfields['pl.sellby']);
  135. }
  136. if (!empty($conf->global->PRODUCT_DISABLE_EATBY)) {
  137. unset($arrayfields['pl.eatby']);
  138. }
  139. $tmpwarehouse = new Entrepot($db);
  140. if ($id > 0 || !empty($ref)) {
  141. $tmpwarehouse->fetch($id, $ref);
  142. $id = $tmpwarehouse->id;
  143. }
  144. // Security check
  145. //$result=restrictedArea($user, 'stock', $id, 'entrepot&stock');
  146. $result = restrictedArea($user, 'stock');
  147. // Security check
  148. if (!$user->hasRight('stock', 'mouvement', 'lire')) {
  149. accessforbidden();
  150. }
  151. $uploaddir = $conf->stock->dir_output.'/movements';
  152. $permissiontoread = $user->rights->stock->mouvement->lire;
  153. $permissiontoadd = $user->rights->stock->mouvement->creer;
  154. $permissiontodelete = $user->rights->stock->mouvement->creer; // There is no deletion permission for stock movement as we shoul dnever delete
  155. $usercanread = $user->rights->stock->mouvement->lire;
  156. $usercancreate = $user->rights->stock->mouvement->creer;
  157. $usercandelete = $user->rights->stock->mouvement->creer;
  158. $error = 0;
  159. /*
  160. * Actions
  161. */
  162. if (GETPOST('cancel', 'alpha')) {
  163. $action = 'list';
  164. $massaction = '';
  165. }
  166. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
  167. $massaction = '';
  168. }
  169. $parameters = array();
  170. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  171. if ($reshook < 0) {
  172. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  173. }
  174. if (empty($reshook)) {
  175. // Selection of new fields
  176. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  177. // Purge search criteria
  178. 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
  179. $search_date_startday = '';
  180. $search_date_startmonth = '';
  181. $search_date_startyear = '';
  182. $search_date_endday = '';
  183. $search_date_endmonth = '';
  184. $search_date_endyear = '';
  185. $search_date_start = '';
  186. $search_date_end = '';
  187. $search_ref = '';
  188. $search_movement = "";
  189. $search_type_mouvement = "";
  190. $search_inventorycode = "";
  191. $search_product_ref = "";
  192. $search_product = "";
  193. $search_warehouse = "";
  194. $search_user = "";
  195. $search_batch = "";
  196. $search_qty = '';
  197. $search_fk_project = "";
  198. $search_all = "";
  199. $toselect = array();
  200. $search_array_options = array();
  201. }
  202. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
  203. || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
  204. $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
  205. }
  206. // Mass actions
  207. $objectclass = 'MouvementStock';
  208. $objectlabel = 'MouvementStock';
  209. if (!$error && $massaction == "builddoc" && $permissiontoread && !GETPOST('button_search')) {
  210. if (empty($diroutputmassaction)) {
  211. dol_print_error(null, 'include of actions_massactions.inc.php is done but var $diroutputmassaction was not defined');
  212. exit;
  213. }
  214. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  215. require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
  216. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  217. $objecttmp = new $objectclass($db);
  218. $listofobjectid = array();
  219. foreach ($toselect as $toselectid) {
  220. $objecttmp = new $objectclass($db); // must create new instance because instance is saved into $listofobjectref array for future use
  221. $result = $objecttmp->fetch($toselectid);
  222. if ($result > 0) {
  223. $listofobjectid[$toselectid] = $toselectid;
  224. }
  225. }
  226. $arrayofinclusion = array();
  227. foreach ($listofobjectref as $tmppdf) {
  228. $arrayofinclusion[] = '^'.preg_quote(dol_sanitizeFileName($tmppdf), '/').'\.pdf$';
  229. }
  230. foreach ($listofobjectref as $tmppdf) {
  231. $arrayofinclusion[] = '^'.preg_quote(dol_sanitizeFileName($tmppdf), '/').'_[a-zA-Z0-9-_]+\.pdf$'; // To include PDF generated from ODX files
  232. }
  233. $listoffiles = dol_dir_list($uploaddir, 'all', 1, implode('|', $arrayofinclusion), '\.meta$|\.png', 'date', SORT_DESC, 0, true);
  234. // Define output language (Here it is not used because we do only merging existing PDF)
  235. $outputlangs = $langs;
  236. $newlang = '';
  237. if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
  238. $newlang = GETPOST('lang_id', 'aZ09');
  239. }
  240. //elseif (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && is_object($objecttmp->thirdparty)) { // On massaction, we can have several values for $objecttmp->thirdparty
  241. // $newlang = $objecttmp->thirdparty->default_lang;
  242. //}
  243. if (!empty($newlang)) {
  244. $outputlangs = new Translate("", $conf);
  245. $outputlangs->setDefaultLang($newlang);
  246. }
  247. // Create output dir if not exists
  248. dol_mkdir($diroutputmassaction);
  249. // Defined name of merged file
  250. $filename = strtolower(dol_sanitizeFileName($langs->transnoentities($objectlabel)));
  251. $filename = preg_replace('/\s/', '_', $filename);
  252. // Save merged file
  253. /*
  254. if ($year) {
  255. $filename .= '_'.$year;
  256. }
  257. if ($month) {
  258. $filename .= '_'.$month;
  259. }
  260. */
  261. $now = dol_now();
  262. $file = $diroutputmassaction.'/'.$filename.'_'.dol_print_date($now, 'dayhourlog').'.pdf';
  263. // Create PDF
  264. // TODO Create the pdf including list of movement ids found into $listofobjectid
  265. // ...
  266. if (!$error) {
  267. $langs->load("exports");
  268. setEventMessages($langs->trans('FileSuccessfullyBuilt', $filename.'_'.dol_print_date($now, 'dayhourlog')), null, 'mesgs');
  269. }
  270. $massaction = '';
  271. $action = '';
  272. }
  273. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  274. }
  275. if ($action == 'update_extras') {
  276. $tmpwarehouse->oldcopy = dol_clone($tmpwarehouse);
  277. // Fill array 'array_options' with data from update form
  278. $ret = $extrafields->setOptionalsFromPost(null, $tmpwarehouse, GETPOST('attribute', 'restricthtml'));
  279. if ($ret < 0) {
  280. $error++;
  281. }
  282. if (!$error) {
  283. $result = $tmpwarehouse->insertExtraFields();
  284. if ($result < 0) {
  285. setEventMessages($tmpwarehouse->error, $tmpwarehouse->errors, 'errors');
  286. $error++;
  287. }
  288. }
  289. if ($error) {
  290. $action = 'edit_extras';
  291. }
  292. }
  293. // Correct stock
  294. if ($action == "correct_stock") {
  295. $product = new Product($db);
  296. if (!empty($product_id)) {
  297. $result = $product->fetch($product_id);
  298. }
  299. $error = 0;
  300. if (empty($product_id)) {
  301. $error++;
  302. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Product")), null, 'errors');
  303. $action = 'correction';
  304. }
  305. if (!is_numeric(GETPOST("nbpiece"))) {
  306. $error++;
  307. setEventMessages($langs->trans("ErrorFieldMustBeANumeric", $langs->transnoentitiesnoconv("NumberOfUnit")), null, 'errors');
  308. $action = 'correction';
  309. }
  310. if (!$error) {
  311. $origin_element = '';
  312. $origin_id = null;
  313. if (GETPOST('projectid', 'int')) {
  314. $origin_element = 'project';
  315. $origin_id = GETPOST('projectid', 'int');
  316. }
  317. if ($product->hasbatch()) {
  318. $batch = GETPOST('batch_number', 'alphanohtml');
  319. //$eatby=GETPOST('eatby');
  320. //$sellby=GETPOST('sellby');
  321. $eatby = dol_mktime(0, 0, 0, GETPOST('eatbymonth', 'int'), GETPOST('eatbyday', 'int'), GETPOST('eatbyyear', 'int'));
  322. $sellby = dol_mktime(0, 0, 0, GETPOST('sellbymonth', 'int'), GETPOST('sellbyday', 'int'), GETPOST('sellbyyear', 'int'));
  323. $result = $product->correct_stock_batch(
  324. $user,
  325. $id,
  326. GETPOST("nbpiece", 'int'),
  327. GETPOST("mouvement", 'int'),
  328. GETPOST("label", 'alphanohtml'),
  329. price2num(GETPOST('unitprice'), 'MT'),
  330. $eatby,
  331. $sellby,
  332. $batch,
  333. GETPOST('inventorycode', 'alphanohtml'),
  334. $origin_element,
  335. $origin_id,
  336. 0,
  337. $extrafields
  338. ); // We do not change value of stock for a correction
  339. } else {
  340. $result = $product->correct_stock(
  341. $user,
  342. $id,
  343. GETPOST("nbpiece", 'int'),
  344. GETPOST("mouvement", "int"),
  345. GETPOST("label", 'alphanohtml'),
  346. price2num(GETPOST('unitprice'), 'MT'),
  347. GETPOST('inventorycode', 'alphanohtml'),
  348. $origin_element,
  349. $origin_id,
  350. 0,
  351. $extrafields
  352. ); // We do not change value of stock for a correction
  353. }
  354. if ($result > 0) {
  355. header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
  356. exit;
  357. } else {
  358. $error++;
  359. setEventMessages($product->error, $product->errors, 'errors');
  360. $action = 'correction';
  361. }
  362. }
  363. if (!$error) {
  364. $action = '';
  365. }
  366. }
  367. // Transfer stock from a warehouse to another warehouse
  368. if ($action == "transfert_stock" && !$cancel) {
  369. $product = new Product($db);
  370. if (!empty($product_id)) {
  371. $result = $product->fetch($product_id);
  372. }
  373. if (!(GETPOST("id_entrepot_destination", 'int') > 0)) {
  374. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Warehouse")), null, 'errors');
  375. $error++;
  376. $action = 'transfert';
  377. }
  378. if (empty($product_id)) {
  379. $error++;
  380. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Product")), null, 'errors');
  381. $action = 'transfert';
  382. }
  383. if (!GETPOST("nbpiece", 'int')) {
  384. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("NumberOfUnit")), null, 'errors');
  385. $error++;
  386. $action = 'transfert';
  387. }
  388. if ($id == GETPOST("id_entrepot_destination", 'int')) {
  389. setEventMessages($langs->trans("ErrorSrcAndTargetWarehouseMustDiffers"), null, 'errors');
  390. $error++;
  391. $action = 'transfert';
  392. }
  393. if (isModEnabled('productbatch')) {
  394. $product = new Product($db);
  395. $result = $product->fetch($product_id);
  396. if ($product->hasbatch() && !GETPOST("batch_number")) {
  397. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("batch_number")), null, 'errors');
  398. $error++;
  399. $action = 'transfert';
  400. }
  401. }
  402. if (!$error) {
  403. if ($id) {
  404. $object = new Entrepot($db);
  405. $result = $object->fetch($id);
  406. $db->begin();
  407. $product->load_stock('novirtual'); // Load array product->stock_warehouse
  408. // Define value of products moved
  409. $pricesrc = 0;
  410. if (isset($product->pmp)) {
  411. $pricesrc = $product->pmp;
  412. }
  413. $pricedest = $pricesrc;
  414. if ($product->hasbatch()) {
  415. $pdluo = new Productbatch($db);
  416. if ($pdluoid > 0) {
  417. $result = $pdluo->fetch($pdluoid);
  418. if ($result) {
  419. $srcwarehouseid = $pdluo->warehouseid;
  420. $batch = $pdluo->batch;
  421. $eatby = $pdluo->eatby;
  422. $sellby = $pdluo->sellby;
  423. } else {
  424. setEventMessages($pdluo->error, $pdluo->errors, 'errors');
  425. $error++;
  426. }
  427. } else {
  428. $srcwarehouseid = $id;
  429. $batch = GETPOST('batch_number', 'alphanohtml');
  430. $eatby = $d_eatby;
  431. $sellby = $d_sellby;
  432. }
  433. if (!$error) {
  434. // Remove stock
  435. $result1 = $product->correct_stock_batch(
  436. $user,
  437. $srcwarehouseid,
  438. GETPOST("nbpiece", 'int'),
  439. 1,
  440. GETPOST("label", 'san_alpha'),
  441. $pricesrc,
  442. $eatby,
  443. $sellby,
  444. $batch,
  445. GETPOST('inventorycode'),
  446. '',
  447. null,
  448. 0,
  449. $extrafields
  450. );
  451. // Add stock
  452. $result2 = $product->correct_stock_batch(
  453. $user,
  454. GETPOST("id_entrepot_destination", 'int'),
  455. GETPOST("nbpiece", 'int'),
  456. 0,
  457. GETPOST("label", 'san_alpha'),
  458. $pricedest,
  459. $eatby,
  460. $sellby,
  461. $batch,
  462. GETPOST('inventorycode', 'alphanohtml'),
  463. '',
  464. null,
  465. 0,
  466. $extrafields
  467. );
  468. }
  469. } else {
  470. // Remove stock
  471. $result1 = $product->correct_stock(
  472. $user,
  473. $id,
  474. GETPOST("nbpiece"),
  475. 1,
  476. GETPOST("label", 'san_alpha'),
  477. $pricesrc,
  478. GETPOST('inventorycode', 'alphanohtml'),
  479. '',
  480. null,
  481. 0,
  482. $extrafields
  483. );
  484. // Add stock
  485. $result2 = $product->correct_stock(
  486. $user,
  487. GETPOST("id_entrepot_destination"),
  488. GETPOST("nbpiece"),
  489. 0,
  490. GETPOST("label", 'san_alpha'),
  491. $pricedest,
  492. GETPOST('inventorycode', 'alphanohtml'),
  493. '',
  494. null,
  495. 0,
  496. $extrafields
  497. );
  498. }
  499. if (!$error && $result1 >= 0 && $result2 >= 0) {
  500. $db->commit();
  501. if ($backtopage) {
  502. header("Location: ".$backtopage);
  503. exit;
  504. } else {
  505. header("Location: movement_list.php?id=".$object->id);
  506. exit;
  507. }
  508. } else {
  509. setEventMessages($product->error, $product->errors, 'errors');
  510. $db->rollback();
  511. $action = 'transfert';
  512. }
  513. }
  514. }
  515. }
  516. /*
  517. * View
  518. */
  519. $form = new Form($db);
  520. $formproduct = new FormProduct($db);
  521. if (isModEnabled('project')) {
  522. $formproject = new FormProjets($db);
  523. }
  524. $productlot = new Productlot($db);
  525. $productstatic = new Product($db);
  526. $warehousestatic = new Entrepot($db);
  527. $movement = new MouvementStock($db);
  528. $userstatic = new User($db);
  529. $now = dol_now();
  530. // Build and execute select
  531. // --------------------------------------------------------------------
  532. $sql = "SELECT p.rowid, p.ref as product_ref, p.label as produit, p.tosell, p.tobuy, p.tobatch, p.fk_product_type as type, p.entity,";
  533. $sql .= " e.ref as warehouse_ref, e.rowid as entrepot_id, e.lieu, e.fk_parent, e.statut,";
  534. $sql .= " m.rowid as mid, m.value as qty, m.datem, m.fk_user_author, m.label, m.inventorycode, m.fk_origin, m.origintype,";
  535. $sql .= " m.batch, m.price,";
  536. $sql .= " m.type_mouvement,";
  537. $sql .= " m.fk_projet as fk_project,";
  538. $sql .= " pl.rowid as lotid, pl.eatby, pl.sellby,";
  539. $sql .= " u.login, u.photo, u.lastname, u.firstname, u.email as user_email, u.statut as user_status";
  540. // Add fields from extrafields
  541. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  542. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  543. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
  544. }
  545. }
  546. // Add fields from hooks
  547. $parameters = array();
  548. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  549. $sql .= $hookmanager->resPrint;
  550. $sql = preg_replace('/,\s*$/', '', $sql);
  551. $sqlfields = $sql; // $sql fields to remove for count total
  552. $sql .= " FROM ".MAIN_DB_PREFIX."entrepot as e,";
  553. $sql .= " ".MAIN_DB_PREFIX."product as p,";
  554. $sql .= " ".MAIN_DB_PREFIX."stock_mouvement as m";
  555. if (!empty($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
  556. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (m.rowid = ef.fk_object)";
  557. }
  558. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON m.fk_user_author = u.rowid";
  559. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_lot as pl ON m.batch = pl.batch AND m.fk_product = pl.fk_product";
  560. // Add table from hooks
  561. $parameters = array();
  562. $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  563. $sql .= $hookmanager->resPrint;
  564. $sql .= " WHERE m.fk_product = p.rowid";
  565. if ($msid > 0) {
  566. $sql .= " AND m.rowid = ".((int) $msid);
  567. }
  568. $sql .= " AND m.fk_entrepot = e.rowid";
  569. $sql .= " AND e.entity IN (".getEntity('stock').")";
  570. if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
  571. $sql .= " AND p.fk_product_type = 0";
  572. }
  573. if ($id > 0) {
  574. $sql .= " AND e.rowid = ".((int) $id);
  575. }
  576. if (!empty($search_date_start)) {
  577. $sql .= " AND m.datem >= '" . $db->idate($search_date_start) . "'";
  578. }
  579. if (!empty($search_date_end)) {
  580. $sql .= " AND m.datem <= '" . $db->idate($search_date_end) . "'";
  581. }
  582. if ($idproduct > 0) {
  583. $sql .= " AND p.rowid = ".((int) $idproduct);
  584. }
  585. if (!empty($search_ref)) {
  586. $sql .= natural_search('m.rowid', $search_ref, 1);
  587. }
  588. if (!empty($search_movement)) {
  589. $sql .= natural_search('m.label', $search_movement);
  590. }
  591. if (!empty($search_inventorycode)) {
  592. $sql .= natural_search('m.inventorycode', $search_inventorycode);
  593. }
  594. if (!empty($search_product_ref)) {
  595. $sql .= natural_search('p.ref', $search_product_ref);
  596. }
  597. if (!empty($search_product)) {
  598. $sql .= natural_search('p.label', $search_product);
  599. }
  600. if ($search_warehouse != '' && $search_warehouse != '-1') {
  601. $sql .= natural_search('e.rowid', $search_warehouse, 2);
  602. }
  603. if (!empty($search_user)) {
  604. $sql .= natural_search(array('u.lastname', 'u.firstname', 'u.login'), $search_user);
  605. }
  606. if (!empty($search_batch)) {
  607. $sql .= natural_search('m.batch', $search_batch);
  608. }
  609. if (!empty($product_id) && $product_id != '-1') {
  610. $sql .= natural_search('p.rowid', $product_id);
  611. }
  612. if (!empty($search_fk_project) && $search_fk_project != '-1') {
  613. $sql .= natural_search('m.fk_projet', $search_fk_project);
  614. }
  615. if ($search_qty != '') {
  616. $sql .= natural_search('m.value', $search_qty, 1);
  617. }
  618. if ($search_type_mouvement != '' && $search_type_mouvement != '-1') {
  619. $sql .= natural_search('m.type_mouvement', $search_type_mouvement, 2);
  620. }
  621. // Add where from extra fields
  622. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
  623. // Add where from hooks
  624. $parameters = array();
  625. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  626. $sql .= $hookmanager->resPrint;
  627. // Count total nb of records
  628. $nbtotalofrecords = '';
  629. if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
  630. /* The fast and low memory method to get and count full list converts the sql into a sql count */
  631. $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
  632. $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
  633. $resql = $db->query($sqlforcount);
  634. if ($resql) {
  635. $objforcount = $db->fetch_object($resql);
  636. $nbtotalofrecords = $objforcount->nbtotalofrecords;
  637. } else {
  638. dol_print_error($db);
  639. }
  640. if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller than the paging size (filtering), goto and load page 0
  641. $page = 0;
  642. $offset = 0;
  643. }
  644. $db->free($resql);
  645. }
  646. // Complete request and execute it with limit
  647. $sql .= $db->order($sortfield, $sortorder);
  648. if ($limit) {
  649. $sql .= $db->plimit($limit + 1, $offset);
  650. }
  651. $resql = $db->query($sql);
  652. if (!$resql) {
  653. dol_print_error($db);
  654. exit;
  655. }
  656. $num = $db->num_rows($resql);
  657. $product = new Product($db);
  658. $object = new Entrepot($db);
  659. if ($idproduct > 0) {
  660. $product->fetch($idproduct);
  661. }
  662. if ($id > 0 || $ref) {
  663. $result = $object->fetch($id, $ref);
  664. if ($result < 0) {
  665. dol_print_error($db);
  666. }
  667. }
  668. // Output page
  669. // --------------------------------------------------------------------
  670. $i = 0;
  671. $help_url = 'EN:Module_Stocks_En|FR:Module_Stock|ES:M&oacute;dulo_Stocks';
  672. if ($msid) {
  673. $title = $langs->trans('StockMovementForId', $msid);
  674. } else {
  675. $title = $langs->trans("ListOfStockMovements");
  676. if ($id) {
  677. if (!empty($object->ref)) {
  678. $title .= ' ('.$object->ref.')';
  679. } else {
  680. $title .= ' ('.$langs->trans("ForThisWarehouse").')';
  681. }
  682. }
  683. }
  684. // Output page
  685. // --------------------------------------------------------------------
  686. llxHeader('', $title, $help_url);
  687. /*
  688. * Show tab only if we ask a particular warehouse
  689. */
  690. if ($object->id > 0) {
  691. $head = stock_prepare_head($object);
  692. print dol_get_fiche_head($head, 'movements', $langs->trans("Warehouse"), -1, 'stock');
  693. $linkback = '<a href="'.DOL_URL_ROOT.'/product/stock/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  694. $morehtmlref = '<div class="refidno">';
  695. $morehtmlref .= $langs->trans("LocationSummary").' : '.$object->lieu;
  696. // Project
  697. if (isModEnabled('project')) {
  698. $langs->load("projects");
  699. $morehtmlref .= '<br>'.img_picto('', 'project').' '.$langs->trans('Project').' ';
  700. if ($usercancreate && 1 == 2) {
  701. if ($action != 'classify') {
  702. $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> : ';
  703. }
  704. if ($action == 'classify') {
  705. $projectid = $object->fk_project;
  706. $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
  707. $morehtmlref .= '<input type="hidden" name="action" value="classin">';
  708. $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
  709. $morehtmlref .= $formproject->select_projects(($socid > 0 ? $socid : -1), $projectid, 'projectid', 0, 0, 1, 1, 0, 0, 0, '', 1, 0, 'maxwidth500');
  710. $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
  711. $morehtmlref .= '</form>';
  712. } else {
  713. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1, '', 'maxwidth300');
  714. }
  715. } else {
  716. if (!empty($object->fk_project)) {
  717. $proj = new Project($db);
  718. $proj->fetch($object->fk_project);
  719. $morehtmlref .= ' : '.$proj->getNomUrl(1);
  720. if ($proj->title) {
  721. $morehtmlref .= ' - '.$proj->title;
  722. }
  723. } else {
  724. $morehtmlref .= '';
  725. }
  726. }
  727. }
  728. $morehtmlref .= '</div>';
  729. $shownav = 1;
  730. if ($user->socid && !in_array('stock', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) {
  731. $shownav = 0;
  732. }
  733. dol_banner_tab($object, 'ref', $linkback, $shownav, 'ref', 'ref', $morehtmlref);
  734. print '<div class="fichecenter">';
  735. print '<div class="fichehalfleft">';
  736. print '<div class="underbanner clearboth"></div>';
  737. print '<table class="border centpercent tableforfield">';
  738. print '<tr>';
  739. // Description
  740. print '<td class="titlefield tdtop">'.$langs->trans("Description").'</td><td>'.dol_htmlentitiesbr($object->description).'</td></tr>';
  741. $calcproductsunique = $object->nb_different_products();
  742. $calcproducts = $object->nb_products();
  743. // Total nb of different products
  744. print '<tr><td>'.$langs->trans("NumberOfDifferentProducts").'</td><td>';
  745. print empty($calcproductsunique['nb']) ? '0' : $calcproductsunique['nb'];
  746. print "</td></tr>";
  747. // Nb of products
  748. print '<tr><td>'.$langs->trans("NumberOfProducts").'</td><td>';
  749. $valtoshow = price2num($calcproducts['nb'], 'MS');
  750. print empty($valtoshow) ? '0' : $valtoshow;
  751. print "</td></tr>";
  752. print '</table>';
  753. print '</div>';
  754. print '<div class="fichehalfright">';
  755. print '<div class="underbanner clearboth"></div>';
  756. print '<table class="border centpercent tableforfield">';
  757. // Value
  758. print '<tr><td class="titlefield">'.$langs->trans("EstimatedStockValueShort").'</td><td>';
  759. print price((empty($calcproducts['value']) ? '0' : price2num($calcproducts['value'], 'MT')), 0, $langs, 0, -1, -1, $conf->currency);
  760. print "</td></tr>";
  761. // Last movement
  762. $sql = "SELECT MAX(m.datem) as datem";
  763. $sql .= " FROM ".MAIN_DB_PREFIX."stock_mouvement as m";
  764. $sql .= " WHERE m.fk_entrepot = ".((int) $object->id);
  765. $resqlbis = $db->query($sql);
  766. if ($resqlbis) {
  767. $objbis = $db->fetch_object($resqlbis);
  768. $lastmovementdate = $db->jdate($objbis->datem);
  769. } else {
  770. dol_print_error($db);
  771. }
  772. print '<tr><td>'.$langs->trans("LastMovement").'</td><td>';
  773. if ($lastmovementdate) {
  774. print dol_print_date($lastmovementdate, 'dayhour');
  775. } else {
  776. print $langs->trans("None");
  777. }
  778. print "</td></tr>";
  779. // Other attributes
  780. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
  781. // Categories
  782. if (isModEnabled('categorie')) {
  783. print '<tr><td valign="middle">'.$langs->trans("Categories").'</td><td colspan="3">';
  784. print $form->showCategories($object->id, Categorie::TYPE_WAREHOUSE, 1);
  785. print "</td></tr>";
  786. }
  787. print "</table>";
  788. print '</div>';
  789. print '</div>';
  790. print '<div class="clearboth"></div>';
  791. print dol_get_fiche_end();
  792. }
  793. // Correct stock
  794. if ($action == "correction") {
  795. include DOL_DOCUMENT_ROOT.'/product/stock/tpl/stockcorrection.tpl.php';
  796. print '<br>';
  797. }
  798. // Transfer of units
  799. if ($action == "transfert") {
  800. include DOL_DOCUMENT_ROOT.'/product/stock/tpl/stocktransfer.tpl.php';
  801. print '<br>';
  802. }
  803. // Action bar
  804. if ((empty($action) || $action == 'list') && $id > 0) {
  805. print "<div class=\"tabsAction\">\n";
  806. $parameters = array();
  807. $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
  808. // modified by hook
  809. if (empty($reshook)) {
  810. if ($user->hasRight('stock', 'mouvement', 'creer')) {
  811. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$id.'&action=correction">'.$langs->trans("CorrectStock").'</a>';
  812. }
  813. if ($user->hasRight('stock', 'mouvement', 'creer')) {
  814. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$id.'&action=transfert">'.$langs->trans("TransferStock").'</a>';
  815. }
  816. }
  817. print '</div><br>';
  818. }
  819. $arrayofselected = is_array($toselect) ? $toselect : array();
  820. $param = '';
  821. if (!empty($mode)) {
  822. $param .= '&mode='.urlencode($mode);
  823. }
  824. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  825. $param .= '&contextpage='.urlencode($contextpage);
  826. }
  827. if ($limit > 0 && $limit != $conf->liste_limit) {
  828. $param .= '&limit='.((int) $limit);
  829. }
  830. if ($id > 0) {
  831. $param .= '&id='.urlencode($id);
  832. }
  833. if ($search_date_startday) {
  834. $param .= '&search_date_startday='.urlencode($search_date_startday);
  835. }
  836. if ($search_date_startmonth) {
  837. $param .= '&search_date_startmonth='.urlencode($search_date_startmonth);
  838. }
  839. if ($search_date_startyear) {
  840. $param .= '&search_date_startyear='.urlencode($search_date_startyear);
  841. }
  842. if ($search_date_endday) {
  843. $param .= '&search_date_endday='.urlencode($search_date_endday);
  844. }
  845. if ($search_date_endmonth) {
  846. $param .= '&search_date_endmonth='.urlencode($search_date_endmonth);
  847. }
  848. if ($search_date_endyear) {
  849. $param .= '&search_date_endyear='.urlencode($search_date_endyear);
  850. }
  851. if ($search_movement) {
  852. $param .= '&search_movement='.urlencode($search_movement);
  853. }
  854. if ($search_inventorycode) {
  855. $param .= '&search_inventorycode='.urlencode($search_inventorycode);
  856. }
  857. if ($search_type_mouvement) {
  858. $param .= '&search_type_mouvement='.urlencode($search_type_mouvement);
  859. }
  860. if ($search_product_ref) {
  861. $param .= '&search_product_ref='.urlencode($search_product_ref);
  862. }
  863. if ($search_product) {
  864. $param .= '&search_product='.urlencode($search_product);
  865. }
  866. if ($search_batch) {
  867. $param .= '&search_batch='.urlencode($search_batch);
  868. }
  869. if ($search_warehouse > 0) {
  870. $param .= '&search_warehouse='.urlencode($search_warehouse);
  871. }
  872. if ($search_user) {
  873. $param .= '&search_user='.urlencode($search_user);
  874. }
  875. if ($idproduct > 0) {
  876. $param .= '&idproduct='.urlencode($idproduct);
  877. }
  878. if ($search_fk_project != '' && $search_fk_project != '-1') {
  879. $param .= '&search_fk_project='.urlencode($search_fk_project);
  880. }
  881. // Add $param from extra fields
  882. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  883. // Add $param from hooks
  884. $parameters = array();
  885. $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  886. $param .= $hookmanager->resPrint;
  887. // List of mass actions available
  888. $arrayofmassactions = array();
  889. if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) {
  890. $arrayofmassactions['builddoc'] = img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("GeneratePDF");
  891. }
  892. // By default, we should never accept deletion of stock movement
  893. if (!empty($conf->global->STOCK_ALLOW_DELETE_OF_MOVEMENT) && $permissiontodelete) {
  894. $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
  895. }
  896. if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) {
  897. $arrayofmassactions = array();
  898. }
  899. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  900. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
  901. if ($optioncss != '') {
  902. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  903. }
  904. print '<input type="hidden" name="token" value="'.newToken().'">';
  905. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  906. print '<input type="hidden" name="action" value="list">';
  907. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  908. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  909. print '<input type="hidden" name="type" value="'.$type.'">';
  910. print '<input type="hidden" name="page" value="'.$page.'">';
  911. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  912. print '<input type="hidden" name="page_y" value="">';
  913. print '<input type="hidden" name="mode" value="'.$mode.'">';
  914. if ($id > 0) {
  915. print '<input type="hidden" name="id" value="'.$id.'">';
  916. }
  917. $newcardbutton = '';
  918. if ($id > 0) {
  919. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'movement', 0, '', '', $limit, 0, 0, 1);
  920. } else {
  921. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'movement', 0, '', '', $limit, 0, 0, 1);
  922. }
  923. // Add code for pre mass action (confirmation or email presend form)
  924. $topicmail = "SendStockMovement";
  925. $modelmail = "movementstock";
  926. $objecttmp = new MouvementStock($db);
  927. $trackid = 'mov'.$object->id;
  928. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
  929. if ($search_all) {
  930. $setupstring = '';
  931. foreach ($fieldstosearchall as $key => $val) {
  932. $fieldstosearchall[$key] = $langs->trans($val);
  933. $setupstring .= $key."=".$val.";";
  934. }
  935. print '<!-- Search done like if STOCK_QUICKSEARCH_ON_FIELDS = '.$setupstring.' -->'."\n";
  936. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>'."\n";
  937. }
  938. $moreforfilter = '';
  939. $parameters = array('arrayfields'=>&$arrayfields);
  940. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  941. if (empty($reshook)) {
  942. $moreforfilter .= $hookmanager->resPrint;
  943. } else {
  944. $moreforfilter = $hookmanager->resPrint;
  945. }
  946. if (!empty($moreforfilter)) {
  947. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  948. print $moreforfilter;
  949. print '</div>';
  950. }
  951. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  952. $selectedfields = ($mode != 'kanban' ? $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN', '')) : ''); // This also change content of $arrayfields
  953. $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
  954. print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
  955. print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  956. // Fields title search
  957. // --------------------------------------------------------------------
  958. print '<tr class="liste_titre">';
  959. // Action column
  960. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  961. print '<td class="liste_titre center maxwidthsearch">';
  962. $searchpicto = $form->showFilterButtons('left');
  963. print $searchpicto;
  964. print '</td>';
  965. }
  966. if (!empty($arrayfields['m.rowid']['checked'])) {
  967. // Ref
  968. print '<td class="liste_titre left">';
  969. print '<input class="flat maxwidth25" type="text" name="search_ref" value="'.dol_escape_htmltag($search_ref).'">';
  970. print '</td>';
  971. }
  972. if (!empty($arrayfields['m.datem']['checked'])) {
  973. // Date
  974. print '<td class="liste_titre center">';
  975. print '<div class="nowrap">';
  976. print $form->selectDate($search_date_start?$search_date_start:-1, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'), 'tzuserrel');
  977. print '</div>';
  978. print '<div class="nowrap">';
  979. print $form->selectDate($search_date_end?$search_date_end:-1, 'search_date_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'), 'tzuserrel');
  980. print '</div>';
  981. print '</td>';
  982. }
  983. if (!empty($arrayfields['p.ref']['checked'])) {
  984. // Product Ref
  985. print '<td class="liste_titre left">';
  986. print '<input class="flat maxwidth75" type="text" name="search_product_ref" value="'.dol_escape_htmltag($idproduct ? $product->ref : $search_product_ref).'">';
  987. print '</td>';
  988. }
  989. if (!empty($arrayfields['p.label']['checked'])) {
  990. // Product label
  991. print '<td class="liste_titre left">';
  992. print '<input class="flat maxwidth100" type="text" name="search_product" value="'.dol_escape_htmltag($idproduct ? $product->label : $search_product).'">';
  993. print '</td>';
  994. }
  995. // Batch
  996. if (!empty($arrayfields['m.batch']['checked'])) {
  997. print '<td class="liste_titre center"><input class="flat maxwidth75" type="text" name="search_batch" value="'.dol_escape_htmltag($search_batch).'"></td>';
  998. }
  999. if (!empty($arrayfields['pl.eatby']['checked'])) {
  1000. print '<td class="liste_titre left">';
  1001. print '</td>';
  1002. }
  1003. if (!empty($arrayfields['pl.sellby']['checked'])) {
  1004. print '<td class="liste_titre left">';
  1005. print '</td>';
  1006. }
  1007. // Warehouse
  1008. if (!empty($arrayfields['e.ref']['checked'])) {
  1009. print '<td class="liste_titre maxwidthonsmartphone left">';
  1010. //print '<input class="flat" type="text" size="8" name="search_warehouse" value="'.($search_warehouse).'">';
  1011. print $formproduct->selectWarehouses($search_warehouse, 'search_warehouse', 'warehouseopen,warehouseinternal', 1, 0, 0, '', 0, 0, null, 'maxwidth200');
  1012. print '</td>';
  1013. }
  1014. if (!empty($arrayfields['m.fk_user_author']['checked'])) {
  1015. // Author
  1016. print '<td class="liste_titre left">';
  1017. print '<input class="flat" type="text" size="6" name="search_user" value="'.dol_escape_htmltag($search_user).'">';
  1018. print '</td>';
  1019. }
  1020. if (!empty($arrayfields['m.inventorycode']['checked'])) {
  1021. // Inventory code
  1022. print '<td class="liste_titre left">';
  1023. print '<input class="flat" type="text" size="4" name="search_inventorycode" value="'.dol_escape_htmltag($search_inventorycode).'">';
  1024. print '</td>';
  1025. }
  1026. if (!empty($arrayfields['m.label']['checked'])) {
  1027. // Label of movement
  1028. print '<td class="liste_titre left">';
  1029. print '<input class="flat" type="text" size="8" name="search_movement" value="'.dol_escape_htmltag($search_movement).'">';
  1030. print '</td>';
  1031. }
  1032. if (!empty($arrayfields['origin']['checked'])) {
  1033. // Origin of movement
  1034. print '<td class="liste_titre left">';
  1035. print '&nbsp; ';
  1036. print '</td>';
  1037. }
  1038. if (!empty($arrayfields['m.fk_projet']['checked'])) {
  1039. // fk_project
  1040. print '<td class="liste_titre" align="left">';
  1041. print $object->showInputField($object->fields['fk_project'], 'fk_project', $search_fk_project, '', '', 'search_', 'maxwidth125', 1);
  1042. print '</td>';
  1043. }
  1044. if (!empty($arrayfields['m.type_mouvement']['checked'])) {
  1045. // Type of movement
  1046. print '<td class="liste_titre center">';
  1047. //print '<input class="flat" type="text" size="3" name="search_type_mouvement" value="'.dol_escape_htmltag($search_type_mouvement).'">';
  1048. print '<select id="search_type_mouvement" name="search_type_mouvement" class="maxwidth150">';
  1049. print '<option value="" '.(($search_type_mouvement == "") ? 'selected="selected"' : '').'>&nbsp;</option>';
  1050. print '<option value="0" '.(($search_type_mouvement == "0") ? 'selected="selected"' : '').'>'.$langs->trans('StockIncreaseAfterCorrectTransfer').'</option>';
  1051. print '<option value="1" '.(($search_type_mouvement == "1") ? 'selected="selected"' : '').'>'.$langs->trans('StockDecreaseAfterCorrectTransfer').'</option>';
  1052. print '<option value="2" '.(($search_type_mouvement == "2") ? 'selected="selected"' : '').'>'.$langs->trans('StockDecrease').'</option>';
  1053. print '<option value="3" '.(($search_type_mouvement == "3") ? 'selected="selected"' : '').'>'.$langs->trans('StockIncrease').'</option>';
  1054. print '</select>';
  1055. print ajax_combobox('search_type_mouvement');
  1056. // TODO: add new function $formentrepot->selectTypeOfMovement(...) like
  1057. // print $formproduct->selectWarehouses($search_warehouse, 'search_warehouse', 'warehouseopen,warehouseinternal', 1, 0, 0, '', 0, 0, null, 'maxwidth200');
  1058. print '</td>';
  1059. }
  1060. if (!empty($arrayfields['m.value']['checked'])) {
  1061. // Qty
  1062. print '<td class="liste_titre right">';
  1063. print '<input class="flat" type="text" size="4" name="search_qty" value="'.dol_escape_htmltag($search_qty).'">';
  1064. print '</td>';
  1065. }
  1066. if (!empty($arrayfields['m.price']['checked'])) {
  1067. // Price
  1068. print '<td class="liste_titre" align="left">';
  1069. print '&nbsp; ';
  1070. print '</td>';
  1071. }
  1072. // Extra fields
  1073. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  1074. // Fields from hook
  1075. $parameters = array('arrayfields'=>$arrayfields);
  1076. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  1077. print $hookmanager->resPrint;
  1078. // Date creation
  1079. if (!empty($arrayfields['m.datec']['checked'])) {
  1080. print '<td class="liste_titre">';
  1081. print '</td>';
  1082. }
  1083. // Date modification
  1084. if (!empty($arrayfields['m.tms']['checked'])) {
  1085. print '<td class="liste_titre">';
  1086. print '</td>';
  1087. }
  1088. // Action column
  1089. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  1090. print '<td class="liste_titre center maxwidthsearch">';
  1091. $searchpicto = $form->showFilterButtons();
  1092. print $searchpicto;
  1093. print '</td>';
  1094. }
  1095. print '</tr>'."\n";
  1096. $totalarray = array();
  1097. $totalarray['nbfield'] = 0;
  1098. // Fields title label
  1099. // --------------------------------------------------------------------
  1100. print '<tr class="liste_titre">';
  1101. // Action column
  1102. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  1103. print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  1104. $totalarray['nbfield']++;
  1105. }
  1106. if (!empty($arrayfields['m.rowid']['checked'])) {
  1107. print_liste_field_titre($arrayfields['m.rowid']['label'], $_SERVER["PHP_SELF"], 'm.rowid', '', $param, '', $sortfield, $sortorder);
  1108. }
  1109. if (!empty($arrayfields['m.datem']['checked'])) {
  1110. print_liste_field_titre($arrayfields['m.datem']['label'], $_SERVER["PHP_SELF"], 'm.datem', '', $param, '', $sortfield, $sortorder, 'center ');
  1111. }
  1112. if (!empty($arrayfields['p.ref']['checked'])) {
  1113. print_liste_field_titre($arrayfields['p.ref']['label'], $_SERVER["PHP_SELF"], 'p.ref', '', $param, '', $sortfield, $sortorder);
  1114. }
  1115. if (!empty($arrayfields['p.label']['checked'])) {
  1116. print_liste_field_titre($arrayfields['p.label']['label'], $_SERVER["PHP_SELF"], 'p.label', '', $param, '', $sortfield, $sortorder);
  1117. }
  1118. if (!empty($arrayfields['m.batch']['checked'])) {
  1119. print_liste_field_titre($arrayfields['m.batch']['label'], $_SERVER["PHP_SELF"], 'm.batch', '', $param, '', $sortfield, $sortorder, 'center ');
  1120. }
  1121. if (!empty($arrayfields['pl.eatby']['checked'])) {
  1122. print_liste_field_titre($arrayfields['pl.eatby']['label'], $_SERVER["PHP_SELF"], 'pl.eatby', '', $param, '', $sortfield, $sortorder, 'center ');
  1123. }
  1124. if (!empty($arrayfields['pl.sellby']['checked'])) {
  1125. print_liste_field_titre($arrayfields['pl.sellby']['label'], $_SERVER["PHP_SELF"], 'pl.sellby', '', $param, '', $sortfield, $sortorder, 'center ');
  1126. }
  1127. if (!empty($arrayfields['e.ref']['checked'])) {
  1128. // We are on a specific warehouse card, no filter on other should be possible
  1129. print_liste_field_titre($arrayfields['e.ref']['label'], $_SERVER["PHP_SELF"], "e.ref", "", $param, "", $sortfield, $sortorder);
  1130. }
  1131. if (!empty($arrayfields['m.fk_user_author']['checked'])) {
  1132. print_liste_field_titre($arrayfields['m.fk_user_author']['label'], $_SERVER["PHP_SELF"], "m.fk_user_author", "", $param, "", $sortfield, $sortorder);
  1133. }
  1134. if (!empty($arrayfields['m.inventorycode']['checked'])) {
  1135. print_liste_field_titre($arrayfields['m.inventorycode']['label'], $_SERVER["PHP_SELF"], "m.inventorycode", "", $param, "", $sortfield, $sortorder);
  1136. }
  1137. if (!empty($arrayfields['m.label']['checked'])) {
  1138. print_liste_field_titre($arrayfields['m.label']['label'], $_SERVER["PHP_SELF"], "m.label", "", $param, "", $sortfield, $sortorder);
  1139. }
  1140. if (!empty($arrayfields['origin']['checked'])) {
  1141. print_liste_field_titre($arrayfields['origin']['label'], $_SERVER["PHP_SELF"], "", "", $param, "", $sortfield, $sortorder);
  1142. }
  1143. if (!empty($arrayfields['m.fk_projet']['checked'])) {
  1144. print_liste_field_titre($arrayfields['m.fk_projet']['label'], $_SERVER["PHP_SELF"], "m.fk_projet", "", $param, '', $sortfield, $sortorder);
  1145. }
  1146. if (!empty($arrayfields['m.type_mouvement']['checked'])) {
  1147. print_liste_field_titre($arrayfields['m.type_mouvement']['label'], $_SERVER["PHP_SELF"], "m.type_mouvement", "", $param, '', $sortfield, $sortorder, 'center ');
  1148. }
  1149. if (!empty($arrayfields['m.value']['checked'])) {
  1150. print_liste_field_titre($arrayfields['m.value']['label'], $_SERVER["PHP_SELF"], "m.value", "", $param, '', $sortfield, $sortorder, 'right ');
  1151. }
  1152. if (!empty($arrayfields['m.price']['checked'])) {
  1153. print_liste_field_titre($arrayfields['m.price']['label'], $_SERVER["PHP_SELF"], "m.price", "", $param, '', $sortfield, $sortorder, 'right ');
  1154. }
  1155. // Extra fields
  1156. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  1157. // Hook fields
  1158. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder, 'totalarray'=>&$totalarray);
  1159. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  1160. print $hookmanager->resPrint;
  1161. if (!empty($arrayfields['m.datec']['checked'])) {
  1162. print_liste_field_titre($arrayfields['p.datec']['label'], $_SERVER["PHP_SELF"], "p.datec", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
  1163. }
  1164. if (!empty($arrayfields['m.tms']['checked'])) {
  1165. print_liste_field_titre($arrayfields['p.tms']['label'], $_SERVER["PHP_SELF"], "p.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
  1166. }
  1167. // Action column
  1168. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  1169. print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  1170. $totalarray['nbfield']++;
  1171. }
  1172. print '</tr>'."\n";
  1173. $arrayofuniqueproduct = array();
  1174. // Loop on record
  1175. // --------------------------------------------------------------------
  1176. $i = 0;
  1177. $savnbfield = $totalarray['nbfield'];
  1178. $totalarray = array();
  1179. $totalarray['nbfield'] = 0;
  1180. $imaxinloop = ($limit ? min($num, $limit) : $num);
  1181. while ($i < $imaxinloop) {
  1182. $obj = $db->fetch_object($resql);
  1183. if (empty($obj)) {
  1184. break; // Should not happen
  1185. }
  1186. $userstatic->id = $obj->fk_user_author;
  1187. $userstatic->login = $obj->login;
  1188. $userstatic->lastname = $obj->lastname;
  1189. $userstatic->firstname = $obj->firstname;
  1190. $userstatic->photo = $obj->photo;
  1191. $userstatic->email = $obj->user_email;
  1192. $userstatic->statut = $obj->user_status;
  1193. // Multilangs
  1194. if (getDolGlobalInt('MAIN_MULTILANGS')) { // If multilang is enabled
  1195. // TODO Use a cache
  1196. $sql = "SELECT label";
  1197. $sql .= " FROM ".MAIN_DB_PREFIX."product_lang";
  1198. $sql .= " WHERE fk_product = ".((int) $obj->rowid);
  1199. $sql .= " AND lang = '".$db->escape($langs->getDefaultLang())."'";
  1200. $sql .= " LIMIT 1";
  1201. $result = $db->query($sql);
  1202. if ($result) {
  1203. $objtp = $db->fetch_object($result);
  1204. if (!empty($objtp->label)) {
  1205. $obj->produit = $objtp->label;
  1206. }
  1207. }
  1208. }
  1209. $productstatic->id = $obj->rowid;
  1210. $productstatic->ref = $obj->product_ref;
  1211. $productstatic->label = $obj->produit;
  1212. $productstatic->type = $obj->type;
  1213. $productstatic->entity = $obj->entity;
  1214. $productstatic->status = $obj->tosell;
  1215. $productstatic->status_buy = $obj->tobuy;
  1216. $productstatic->status_batch = $obj->tobatch;
  1217. $productlot->id = $obj->lotid;
  1218. $productlot->batch = $obj->batch;
  1219. $productlot->eatby = $obj->eatby;
  1220. $productlot->sellby = $obj->sellby;
  1221. $warehousestatic->id = $obj->entrepot_id;
  1222. $warehousestatic->ref = $obj->warehouse_ref;
  1223. $warehousestatic->label = $obj->warehouse_ref;
  1224. $warehousestatic->lieu = $obj->lieu;
  1225. $warehousestatic->fk_parent = $obj->fk_parent;
  1226. $warehousestatic->statut = $obj->statut;
  1227. $movement->type = $obj->type_mouvement;
  1228. $arrayofuniqueproduct[$obj->rowid] = $obj->produit;
  1229. if (!empty($obj->fk_origin)) {
  1230. $origin = $movement->get_origin($obj->fk_origin, $obj->origintype);
  1231. } else {
  1232. $origin = '';
  1233. }
  1234. if ($mode == 'kanban') {
  1235. if ($i == 0) {
  1236. print '<tr class="trkanban"><td colspan="'.$savnbfield.'">';
  1237. print '<div class="box-flex-container kanban">';
  1238. }
  1239. // Output Kanban
  1240. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  1241. $selected = 0;
  1242. if (in_array($object->id, $arrayofselected)) {
  1243. $selected = 1;
  1244. }
  1245. }
  1246. print $object->getKanbanView('', array('selected' => in_array($warehousestatic->id, $arrayofselected)));
  1247. if ($i == ($imaxinloop - 1)) {
  1248. print '</div>';
  1249. print '</td></tr>';
  1250. }
  1251. } else {
  1252. // Show here line of result
  1253. $j = 0;
  1254. print '<tr data-rowid="'.$object->id.'" class="oddeven">';
  1255. // Action column
  1256. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  1257. print '<td class="nowrap center">';
  1258. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  1259. $selected = 0;
  1260. if (in_array($obj->mid, $arrayofselected)) {
  1261. $selected = 1;
  1262. }
  1263. print '<input id="cb'.$obj->mid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->mid.'"'.($selected ? ' checked="checked"' : '').'>';
  1264. }
  1265. print '</td>';
  1266. if (!$i) {
  1267. $totalarray['nbfield']++;
  1268. }
  1269. }
  1270. // Id movement
  1271. if (!empty($arrayfields['m.rowid']['checked'])) {
  1272. print '<td class="nowraponall">';
  1273. print img_picto($langs->trans("StockMovement"), 'movement', 'class="pictofixedwidth"');
  1274. print $obj->mid;
  1275. print '</td>'; // This is primary not movement id
  1276. }
  1277. if (!empty($arrayfields['m.datem']['checked'])) {
  1278. // Date
  1279. print '<td class="nowraponall center">'.dol_print_date($db->jdate($obj->datem), 'dayhour', 'tzuserrel').'</td>';
  1280. }
  1281. if (!empty($arrayfields['p.ref']['checked'])) {
  1282. // Product ref
  1283. print '<td class="nowraponall">';
  1284. print $productstatic->getNomUrl(1, 'stock', 16);
  1285. print "</td>\n";
  1286. }
  1287. if (!empty($arrayfields['p.label']['checked'])) {
  1288. // Product label
  1289. print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($productstatic->label).'">';
  1290. print $productstatic->label;
  1291. print "</td>\n";
  1292. }
  1293. if (!empty($arrayfields['m.batch']['checked'])) {
  1294. print '<td class="center nowraponall">';
  1295. if ($productlot->id > 0) {
  1296. print $productlot->getNomUrl(1);
  1297. } else {
  1298. 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.
  1299. }
  1300. print '</td>';
  1301. }
  1302. if (!empty($arrayfields['pl.eatby']['checked'])) {
  1303. print '<td class="center">'.dol_print_date($obj->eatby, 'day').'</td>';
  1304. }
  1305. if (!empty($arrayfields['pl.sellby']['checked'])) {
  1306. print '<td class="center">'.dol_print_date($obj->sellby, 'day').'</td>';
  1307. }
  1308. // Warehouse
  1309. if (!empty($arrayfields['e.ref']['checked'])) {
  1310. print '<td class="tdoverflowmax100">';
  1311. print $warehousestatic->getNomUrl(1);
  1312. print "</td>\n";
  1313. }
  1314. // Author
  1315. if (!empty($arrayfields['m.fk_user_author']['checked'])) {
  1316. print '<td class="tdoverflowmax100">';
  1317. print $userstatic->getNomUrl(-1);
  1318. print "</td>\n";
  1319. }
  1320. if (!empty($arrayfields['m.inventorycode']['checked'])) {
  1321. // Inventory code
  1322. print '<td><a href="'.$_SERVER["PHP_SELF"].'?search_inventorycode='.urlencode('^'.$obj->inventorycode.'$').'&search_type_mouvement='.urlencode($obj->type_mouvement).'">'.$obj->inventorycode.'</a></td>';
  1323. }
  1324. if (!empty($arrayfields['m.label']['checked'])) {
  1325. // Label of movement
  1326. print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($obj->label).'">'.$obj->label.'</td>';
  1327. }
  1328. if (!empty($arrayfields['origin']['checked'])) {
  1329. // Origin of movement
  1330. print '<td class="nowraponall">'.$origin.'</td>';
  1331. }
  1332. if (!empty($arrayfields['m.fk_projet']['checked'])) {
  1333. // fk_project
  1334. print '<td>';
  1335. if ($obj->fk_project != 0) {
  1336. print $movement->get_origin($obj->fk_project, 'project');
  1337. }
  1338. print '</td>';
  1339. }
  1340. if (!empty($arrayfields['m.type_mouvement']['checked'])) {
  1341. // Type of movement
  1342. print '<td class="center">';
  1343. print $movement->getTypeMovement();
  1344. print '</td>';
  1345. }
  1346. if (!empty($arrayfields['m.value']['checked'])) {
  1347. // Qty
  1348. print '<td class="right">';
  1349. if ($obj->qty > 0) {
  1350. print '<span class="stockmovemententry">';
  1351. print '+';
  1352. print $obj->qty;
  1353. print '</span>';
  1354. } else {
  1355. print '<span class="stockmovementexit">';
  1356. print $obj->qty;
  1357. print '</span>';
  1358. }
  1359. print '</td>';
  1360. }
  1361. if (!empty($arrayfields['m.price']['checked'])) {
  1362. // Price
  1363. print '<td class="right">';
  1364. if ($obj->price != 0) {
  1365. print price($obj->price);
  1366. }
  1367. print '</td>';
  1368. }
  1369. // Extra fields
  1370. $object = $movement;
  1371. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  1372. // Fields from hook
  1373. $parameters = array('arrayfields'=>$arrayfields, 'object'=>$object, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
  1374. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  1375. print $hookmanager->resPrint;
  1376. // Action column
  1377. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  1378. print '<td class="nowrap center">';
  1379. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  1380. $selected = 0;
  1381. if (in_array($obj->mid, $arrayofselected)) {
  1382. $selected = 1;
  1383. }
  1384. print '<input id="cb'.$obj->mid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->mid.'"'.($selected ? ' checked="checked"' : '').'>';
  1385. }
  1386. print '</td>';
  1387. if (!$i) {
  1388. $totalarray['nbfield']++;
  1389. }
  1390. }
  1391. print '</tr>'."\n";
  1392. }
  1393. $i++;
  1394. }
  1395. // If no record found
  1396. if ($num == 0) {
  1397. $colspan = 1;
  1398. foreach ($arrayfields as $key => $val) {
  1399. if (!empty($val['checked'])) {
  1400. $colspan++;
  1401. }
  1402. }
  1403. print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
  1404. }
  1405. $db->free($resql);
  1406. $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
  1407. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  1408. print $hookmanager->resPrint;
  1409. print '</table>'."\n";
  1410. print '</div>'."\n";
  1411. print '</form>'."\n";
  1412. // Add number of product when there is a filter on period
  1413. if (count($arrayofuniqueproduct) == 1 && !empty($year) && is_numeric($year)) {
  1414. print "<br>";
  1415. $productidselected = 0;
  1416. foreach ($arrayofuniqueproduct as $key => $val) {
  1417. $productidselected = $key;
  1418. $productlabelselected = $val;
  1419. }
  1420. $datebefore = dol_get_first_day($year ? $year : strftime("%Y", time()), $month ? $month : 1, true);
  1421. $dateafter = dol_get_last_day($year ? $year : strftime("%Y", time()), $month ? $month : 12, true);
  1422. $balancebefore = $movement->calculateBalanceForProductBefore($productidselected, $datebefore);
  1423. $balanceafter = $movement->calculateBalanceForProductBefore($productidselected, $dateafter);
  1424. //print '<tr class="total"><td class="liste_total">';
  1425. print $langs->trans("NbOfProductBeforePeriod", $productlabelselected, dol_print_date($datebefore, 'day', 'gmt'));
  1426. //print '</td>';
  1427. //print '<td class="liste_total right" colspan="6">';
  1428. print ': '.$balancebefore;
  1429. print "<br>\n";
  1430. //print '</td></tr>';
  1431. //print '<tr class="total"><td class="liste_total">';
  1432. print $langs->trans("NbOfProductAfterPeriod", $productlabelselected, dol_print_date($dateafter, 'day', 'gmt'));
  1433. //print '</td>';
  1434. //print '<td class="liste_total right" colspan="6">';
  1435. print ': '.$balanceafter;
  1436. print "<br>\n";
  1437. //print '</td></tr>';
  1438. }
  1439. if (in_array('builddoc', $arrayofmassactions) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
  1440. $hidegeneratedfilelistifempty = 1;
  1441. if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
  1442. $hidegeneratedfilelistifempty = 0;
  1443. }
  1444. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  1445. $formfile = new FormFile($db);
  1446. // Show list of available documents
  1447. $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
  1448. $urlsource .= str_replace('&amp;', '&', $param);
  1449. $filedir = $diroutputmassaction;
  1450. $genallowed = $permissiontoread;
  1451. $delallowed = $permissiontoadd;
  1452. print $formfile->showdocuments('massfilesarea_'.$object->module, '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
  1453. }
  1454. // End of page
  1455. llxFooter();
  1456. $db->close();