movement_list.php 54 KB

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