movement_list.php 55 KB

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