mo_movements.php 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024
  1. <?php
  2. /* Copyright (C) 2019 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2022 Ferran Marcet <fmarcet@2byte.es>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file mo_movements.php
  20. * \ingroup mrp
  21. * \brief Page to show stock movements of a MO
  22. */
  23. // Load Dolibarr environment
  24. require '../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.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. dol_include_once('/mrp/class/mo.class.php');
  34. dol_include_once('/mrp/lib/mrp_mo.lib.php');
  35. // Load translation files required by the page
  36. $langs->loadLangs(array("mrp", "stocks", "other"));
  37. // Get parameters
  38. $id = GETPOST('id', 'int');
  39. $ref = GETPOST('ref', 'alpha');
  40. $action = GETPOST('action', 'aZ09');
  41. $confirm = GETPOST('confirm', 'alpha');
  42. $cancel = GETPOST('cancel', 'aZ09');
  43. $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'mostockmovement'; // To manage different context of search
  44. $backtopage = GETPOST('backtopage', 'alpha');
  45. $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
  46. $massaction = GETPOST('massaction', 'aZ09');
  47. $lineid = GETPOST('lineid', 'int');
  48. $msid = GETPOST('msid', 'int');
  49. $year = GETPOST("year", 'int');
  50. $month = GETPOST("month", 'int');
  51. $search_ref = GETPOST('search_ref', 'alpha');
  52. $search_movement = GETPOST("search_movement", 'alpha');
  53. $search_product_ref = trim(GETPOST("search_product_ref", 'alpha'));
  54. $search_product = trim(GETPOST("search_product", 'alpha'));
  55. $search_warehouse = trim(GETPOST("search_warehouse", 'alpha'));
  56. $search_inventorycode = trim(GETPOST("search_inventorycode", 'alpha'));
  57. $search_user = trim(GETPOST("search_user", 'alpha'));
  58. $search_batch = trim(GETPOST("search_batch", 'alpha'));
  59. $search_qty = trim(GETPOST("search_qty", 'alpha'));
  60. $search_type_mouvement = GETPOST('search_type_mouvement', 'int');
  61. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  62. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  63. $sortfield = GETPOST('sortfield', 'aZ09comma');
  64. $sortorder = GETPOST('sortorder', 'aZ09comma');
  65. if (empty($page) || $page == -1) {
  66. $page = 0;
  67. } // If $page is not defined, or '' or -1
  68. $offset = $limit * $page;
  69. if (!$sortfield) {
  70. $sortfield = "m.datem";
  71. }
  72. if (!$sortorder) {
  73. $sortorder = "DESC";
  74. }
  75. // Initialize technical objects
  76. $object = new Mo($db);
  77. $extrafields = new ExtraFields($db);
  78. $diroutputmassaction = $conf->mrp->dir_output.'/temp/massgeneration/'.$user->id;
  79. $hookmanager->initHooks(array('mocard', 'globalcard')); // Note that conf->hooks_modules contains array
  80. // Fetch optionals attributes and labels
  81. $extrafields->fetch_name_optionals_label($object->table_element);
  82. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  83. // Initialize array of search criterias
  84. $search_all = trim(GETPOST("search_all", 'alpha'));
  85. $search = array();
  86. foreach ($object->fields as $key => $val) {
  87. if (GETPOST('search_'.$key, 'alpha')) {
  88. $search[$key] = GETPOST('search_'.$key, 'alpha');
  89. }
  90. }
  91. if (empty($action) && empty($id) && empty($ref)) {
  92. $action = 'view';
  93. }
  94. // Load object
  95. include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
  96. // Security check - Protection if external user
  97. //if ($user->socid > 0) accessforbidden();
  98. //if ($user->socid > 0) $socid = $user->socid;
  99. $isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
  100. $result = restrictedArea($user, 'mrp', $object->id, 'mrp_mo', '', 'fk_soc', 'rowid', $isdraft);
  101. $objectlist = new MouvementStock($db);
  102. // Definition of fields for list
  103. $arrayfields = array(
  104. 'm.rowid'=>array('label'=>"Ref", 'checked'=>1, 'position'=>1),
  105. 'm.datem'=>array('label'=>"Date", 'checked'=>1, 'position'=>2),
  106. 'p.ref'=>array('label'=>"ProductRef", 'checked'=>1, 'css'=>'maxwidth100', 'position'=>3),
  107. 'p.label'=>array('label'=>"ProductLabel", 'checked'=>0, 'position'=>5),
  108. 'm.batch'=>array('label'=>"BatchNumberShort", 'checked'=>1, 'position'=>8, 'enabled'=>(isModEnabled('productbatch'))),
  109. 'pl.eatby'=>array('label'=>"EatByDate", 'checked'=>0, 'position'=>9, 'enabled'=>(isModEnabled('productbatch'))),
  110. 'pl.sellby'=>array('label'=>"SellByDate", 'checked'=>0, 'position'=>10, 'enabled'=>(isModEnabled('productbatch'))),
  111. 'e.ref'=>array('label'=>"Warehouse", 'checked'=>1, 'position'=>100, 'enabled'=>(!($id > 0))), // If we are on specific warehouse, we hide it
  112. 'm.fk_user_author'=>array('label'=>"Author", 'checked'=>0, 'position'=>120),
  113. 'm.inventorycode'=>array('label'=>"InventoryCodeShort", 'checked'=>1, 'position'=>130),
  114. 'm.label'=>array('label'=>"MovementLabel", 'checked'=>1, 'position'=>140),
  115. 'm.type_mouvement'=>array('label'=>"TypeMovement", 'checked'=>0, 'position'=>150),
  116. 'origin'=>array('label'=>"Origin", 'checked'=>1, 'position'=>155),
  117. 'm.fk_projet'=>array('label'=>'Project', 'checked'=>0, 'position'=>180),
  118. 'm.value'=>array('label'=>"Qty", 'checked'=>1, 'position'=>200),
  119. 'm.price'=>array('label'=>"UnitPurchaseValue", 'checked'=>0, 'position'=>210)
  120. //'m.datec'=>array('label'=>"DateCreation", 'checked'=>0, 'position'=>500),
  121. //'m.tms'=>array('label'=>"DateModificationShort", 'checked'=>0, 'position'=>500)
  122. );
  123. if (getDolGlobalString('PRODUCT_DISABLE_SELLBY')) {
  124. unset($arrayfields['pl.sellby']);
  125. }
  126. if (getDolGlobalString('PRODUCT_DISABLE_EATBY')) {
  127. unset($arrayfields['pl.eatby']);
  128. }
  129. $objectlist->fields = dol_sort_array($objectlist->fields, 'position');
  130. $arrayfields = dol_sort_array($arrayfields, 'position');
  131. // Permissions
  132. $permissionnote = $user->rights->mrp->write; // Used by the include of actions_setnotes.inc.php
  133. $permissiondellink = $user->rights->mrp->write; // Used by the include of actions_dellink.inc.php
  134. $permissiontoadd = $user->rights->mrp->write; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
  135. $permissiontodelete = $user->rights->mrp->delete || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT);
  136. $upload_dir = $conf->mrp->multidir_output[isset($object->entity) ? $object->entity : 1];
  137. $permissiontoproduce = $permissiontoadd;
  138. $permissiontoupdatecost = $user->hasRight('bom', 'write'); // User who can define cost must have knowledge of pricing
  139. if ($permissiontoupdatecost) {
  140. $arrayfields['m.price']['enabled'] = 1;
  141. }
  142. $arrayofselected = array();
  143. /*
  144. * Actions
  145. */
  146. if (GETPOST('cancel', 'alpha')) {
  147. $action = 'list';
  148. $massaction = '';
  149. }
  150. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
  151. $massaction = '';
  152. }
  153. $parameters = array();
  154. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  155. if ($reshook < 0) {
  156. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  157. }
  158. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  159. // Do we click on purge search criteria ?
  160. 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
  161. $year = '';
  162. $month = '';
  163. $search_ref = '';
  164. $search_movement = "";
  165. $search_type_mouvement = "";
  166. $search_inventorycode = "";
  167. $search_product_ref = "";
  168. $search_product = "";
  169. $search_warehouse = "";
  170. $search_user = "";
  171. $search_batch = "";
  172. $search_qty = '';
  173. $sall = "";
  174. $toselect = array();
  175. $search_array_options = array();
  176. }
  177. if (empty($reshook)) {
  178. $error = 0;
  179. $backurlforlist = dol_buildpath('/mrp/mo_list.php', 1);
  180. if (empty($backtopage) || ($cancel && empty($id))) {
  181. //var_dump($backurlforlist);exit;
  182. if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
  183. $backtopage = $backurlforlist;
  184. } else {
  185. $backtopage = DOL_URL_ROOT.'/mrp/mo_production.php?id='.($id > 0 ? $id : '__ID__');
  186. }
  187. }
  188. $triggermodname = 'MO_MODIFY'; // Name of trigger action code to execute when we modify record
  189. // Actions cancel, add, update, delete or clone
  190. include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php';
  191. // Actions when linking object each other
  192. include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php';
  193. // Actions when printing a doc from card
  194. include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
  195. // Actions to send emails
  196. $triggersendname = 'MO_SENTBYMAIL';
  197. $autocopy = 'MAIN_MAIL_AUTOCOPY_MO_TO';
  198. $trackid = 'mo'.$object->id;
  199. include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
  200. // Action to move up and down lines of object
  201. //include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php'; // Must be include, not include_once
  202. if ($action == 'set_thirdparty' && $permissiontoadd) {
  203. $object->setValueFrom('fk_soc', GETPOST('fk_soc', 'int'), '', '', 'date', '', $user, $triggermodname);
  204. }
  205. if ($action == 'classin' && $permissiontoadd) {
  206. $object->setProject(GETPOST('projectid', 'int'));
  207. }
  208. if ($action == 'confirm_reopen') {
  209. $result = $object->setStatut($object::STATUS_INPROGRESS, 0, '', 'MRP_REOPEN');
  210. }
  211. }
  212. /*
  213. * View
  214. */
  215. $form = new Form($db);
  216. $formproject = new FormProjets($db);
  217. $formproduct = new FormProduct($db);
  218. $productstatic = new Product($db);
  219. $productlot = new Productlot($db);
  220. $warehousestatic = new Entrepot($db);
  221. $userstatic = new User($db);
  222. $help_url = 'EN:Module_Manufacturing_Orders|FR:Module_Ordres_de_Fabrication|DE:Modul_Fertigungsauftrag';
  223. llxHeader('', $langs->trans('Mo'), $help_url);
  224. // Part to show record
  225. if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
  226. $res = $object->fetch_thirdparty();
  227. $res = $object->fetch_optionals();
  228. $head = moPrepareHead($object);
  229. print dol_get_fiche_head($head, 'stockmovement', $langs->trans("ManufacturingOrder"), -1, $object->picto);
  230. $formconfirm = '';
  231. // Confirmation to delete
  232. if ($action == 'delete') {
  233. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteMo'), $langs->trans('ConfirmDeleteMo'), 'confirm_delete', '', 0, 1);
  234. }
  235. // Confirmation to delete line
  236. if ($action == 'deleteline') {
  237. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid, $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_deleteline', '', 0, 1);
  238. }
  239. // Clone confirmation
  240. if ($action == 'clone') {
  241. // Create an array for form
  242. $formquestion = array();
  243. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneMo', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);
  244. }
  245. // Confirmation of action xxxx
  246. if ($action == 'xxx') {
  247. $formquestion = array();
  248. /*
  249. $forcecombo=0;
  250. if ($conf->browser->name == 'ie') $forcecombo = 1; // There is a bug in IE10 that make combo inside popup crazy
  251. $formquestion = array(
  252. // 'text' => $langs->trans("ConfirmClone"),
  253. // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
  254. // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
  255. // array('type' => 'other', 'name' => 'idwarehouse', 'label' => $langs->trans("SelectWarehouseForStockDecrease"), 'value' => $formproduct->selectWarehouses(GETPOST('idwarehouse')?GETPOST('idwarehouse'):'ifone', 'idwarehouse', '', 1, 0, 0, '', 0, $forcecombo))
  256. );
  257. */
  258. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('XXX'), $text, 'confirm_xxx', $formquestion, 0, 1, 220);
  259. }
  260. // Call Hook formConfirm
  261. $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid);
  262. $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  263. if (empty($reshook)) {
  264. $formconfirm .= $hookmanager->resPrint;
  265. } elseif ($reshook > 0) {
  266. $formconfirm = $hookmanager->resPrint;
  267. }
  268. // Print form confirm
  269. print $formconfirm;
  270. // Object card
  271. // ------------------------------------------------------------
  272. $linkback = '<a href="'.dol_buildpath('/mrp/mo_list.php', 1).'?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  273. $morehtmlref = '<div class="refidno">';
  274. /*
  275. // Ref bis
  276. $morehtmlref.=$form->editfieldkey("RefBis", 'ref_client', $object->ref_client, $object, $user->rights->mrp->creer, 'string', '', 0, 1);
  277. $morehtmlref.=$form->editfieldval("RefBis", 'ref_client', $object->ref_client, $object, $user->rights->mrp->creer, 'string', '', null, null, '', 1);*/
  278. // Thirdparty
  279. if (is_object($object->thirdparty)) {
  280. $morehtmlref .= $object->thirdparty->getNomUrl(1, 'customer');
  281. if (!getDolGlobalString('MAIN_DISABLE_OTHER_LINK') && $object->thirdparty->id > 0) {
  282. $morehtmlref .= ' (<a href="'.DOL_URL_ROOT.'/commande/list.php?socid='.$object->thirdparty->id.'&search_societe='.urlencode($object->thirdparty->name).'">'.$langs->trans("OtherOrders").'</a>)';
  283. }
  284. }
  285. // Project
  286. if (isModEnabled('project')) {
  287. $langs->load("projects");
  288. if (is_object($object->thirdparty)) {
  289. $morehtmlref .= '<br>';
  290. }
  291. if ($permissiontoadd) {
  292. $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
  293. if ($action != 'classify') {
  294. $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
  295. }
  296. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
  297. } else {
  298. if (!empty($object->fk_project)) {
  299. $proj = new Project($db);
  300. $proj->fetch($object->fk_project);
  301. $morehtmlref .= $proj->getNomUrl(1);
  302. if ($proj->title) {
  303. $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
  304. }
  305. }
  306. }
  307. }
  308. $morehtmlref .= '</div>';
  309. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  310. print '<div class="fichecenter">';
  311. print '<div class="fichehalfleft">';
  312. print '<div class="underbanner clearboth"></div>';
  313. print '<table class="border centpercent tableforfield">'."\n";
  314. // Common attributes
  315. $keyforbreak = 'fk_warehouse';
  316. unset($object->fields['fk_project']);
  317. unset($object->fields['fk_soc']);
  318. include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_view.tpl.php';
  319. // Other attributes
  320. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
  321. print '</table>';
  322. print '</div>';
  323. print '</div>';
  324. print '<div class="clearboth"></div>';
  325. print dol_get_fiche_end();
  326. /*
  327. print '<div class="tabsAction">';
  328. $parameters = array();
  329. // Note that $action and $object may be modified by hook
  330. $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action);
  331. if (empty($reshook)) {
  332. // Cancel - Reopen
  333. if ($permissiontoadd)
  334. {
  335. if ($object->status == $object::STATUS_VALIDATED || $object->status == $object::STATUS_INPROGRESS)
  336. {
  337. print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=confirm_close&confirm=yes">'.$langs->trans("Cancel").'</a>'."\n";
  338. }
  339. if ($object->status == $object::STATUS_CANCELED)
  340. {
  341. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=confirm_reopen&confirm=yes">'.$langs->trans("Re-Open").'</a>'."\n";
  342. }
  343. if ($object->status == $object::STATUS_PRODUCED) {
  344. if ($permissiontoproduce) {
  345. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=confirm_reopen">'.$langs->trans('ReOpen').'</a>';
  346. } else {
  347. print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotEnoughPermissions").'">'.$langs->trans('ReOpen').'</a>';
  348. }
  349. }
  350. }
  351. }
  352. print '</div>';
  353. */
  354. $sql = "SELECT p.rowid, p.ref as product_ref, p.label as produit, p.tobatch, p.fk_product_type as type, p.entity,";
  355. $sql .= " e.ref as warehouse_ref, e.rowid as entrepot_id, e.lieu,";
  356. $sql .= " m.rowid as mid, m.value as qty, m.datem, m.fk_user_author, m.label, m.inventorycode, m.fk_origin, m.origintype,";
  357. $sql .= " m.batch, m.price,";
  358. $sql .= " m.type_mouvement,";
  359. $sql .= " pl.rowid as lotid, pl.eatby, pl.sellby,";
  360. $sql .= " u.login, u.photo, u.lastname, u.firstname";
  361. // Add fields from extrafields
  362. if (!empty($extrafields->attributes[$objectlist->table_element]['label'])) {
  363. foreach ($extrafields->attributes[$objectlist->table_element]['label'] as $key => $val) {
  364. $sql .= ($extrafields->attributes[$objectlist->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
  365. }
  366. }
  367. // Add fields from hooks
  368. $parameters = array();
  369. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $objectlist may have been modified by hook
  370. $sql .= $hookmanager->resPrint;
  371. $sql .= " FROM ".MAIN_DB_PREFIX."entrepot as e,";
  372. $sql .= " ".MAIN_DB_PREFIX."product as p,";
  373. $sql .= " ".MAIN_DB_PREFIX."stock_mouvement as m";
  374. if (!empty($extrafields->attributes[$objectlist->table_element]) && is_array($extrafields->attributes[$objectlist->table_element]['label']) && count($extrafields->attributes[$objectlist->table_element]['label'])) {
  375. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$objectlist->table_element."_extrafields as ef on (m.rowid = ef.fk_object)";
  376. }
  377. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON m.fk_user_author = u.rowid";
  378. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_lot as pl ON m.batch = pl.batch AND m.fk_product = pl.fk_product";
  379. $sql .= " WHERE m.fk_product = p.rowid";
  380. $sql .= " AND m.origintype = 'mo' AND m.fk_origin = ".(int) $object->id;
  381. if ($msid > 0) {
  382. $sql .= " AND m.rowid = ".((int) $msid);
  383. }
  384. $sql .= " AND m.fk_entrepot = e.rowid";
  385. $sql .= " AND e.entity IN (".getEntity('stock').")";
  386. if (!getDolGlobalString('STOCK_SUPPORTS_SERVICES')) {
  387. $sql .= " AND p.fk_product_type = 0";
  388. }
  389. $sql .= dolSqlDateFilter('m.datem', 0, $month, $year);
  390. if (!empty($search_ref)) {
  391. $sql .= natural_search('m.rowid', $search_ref, 1);
  392. }
  393. if (!empty($search_movement)) {
  394. $sql .= natural_search('m.label', $search_movement);
  395. }
  396. if (!empty($search_inventorycode)) {
  397. $sql .= natural_search('m.inventorycode', $search_inventorycode);
  398. }
  399. if (!empty($search_product_ref)) {
  400. $sql .= natural_search('p.ref', $search_product_ref);
  401. }
  402. if (!empty($search_product)) {
  403. $sql .= natural_search('p.label', $search_product);
  404. }
  405. if ($search_warehouse != '' && $search_warehouse != '-1') {
  406. $sql .= natural_search('e.rowid', $search_warehouse, 2);
  407. }
  408. if (!empty($search_user)) {
  409. $sql .= natural_search(array('u.lastname', 'u.firstname', 'u.login'), $search_user);
  410. }
  411. if (!empty($search_batch)) {
  412. $sql .= natural_search('m.batch', $search_batch);
  413. }
  414. if ($search_qty != '') {
  415. $sql .= natural_search('m.value', $search_qty, 1);
  416. }
  417. if ($search_type_mouvement != '' && $search_type_mouvement != '-1') {
  418. $sql .= natural_search('m.type_mouvement', $search_type_mouvement, 2);
  419. }
  420. // Add where from extra fields
  421. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
  422. // Add where from hooks
  423. $parameters = array();
  424. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $objectlist may have been modified by hook
  425. $sql .= $hookmanager->resPrint;
  426. $sql .= $db->order($sortfield, $sortorder);
  427. $nbtotalofrecords = '';
  428. if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
  429. $result = $db->query($sql);
  430. $nbtotalofrecords = $db->num_rows($result);
  431. if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
  432. $page = 0;
  433. $offset = 0;
  434. }
  435. }
  436. $sql .= $db->plimit($limit + 1, $offset);
  437. $resql = $db->query($sql);
  438. if (!$resql) {
  439. dol_print_error($db);
  440. }
  441. $num = $db->num_rows($resql);
  442. $param = '';
  443. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  444. $param .= '&contextpage='.urlencode($contextpage);
  445. }
  446. if ($limit > 0 && $limit != $conf->liste_limit) {
  447. $param .= '&limit='.((int) $limit);
  448. }
  449. if ($id > 0) {
  450. $param .= '&id='.urlencode($id);
  451. }
  452. if ($search_movement) {
  453. $param .= '&search_movement='.urlencode($search_movement);
  454. }
  455. if ($search_inventorycode) {
  456. $param .= '&search_inventorycode='.urlencode($search_inventorycode);
  457. }
  458. if ($search_type_mouvement) {
  459. $param .= '&search_type_mouvement='.urlencode($search_type_mouvement);
  460. }
  461. if ($search_product_ref) {
  462. $param .= '&search_product_ref='.urlencode($search_product_ref);
  463. }
  464. if ($search_product) {
  465. $param .= '&search_product='.urlencode($search_product);
  466. }
  467. if ($search_batch) {
  468. $param .= '&search_batch='.urlencode($search_batch);
  469. }
  470. if ($search_warehouse > 0) {
  471. $param .= '&search_warehouse='.urlencode($search_warehouse);
  472. }
  473. if ($search_user) {
  474. $param .= '&search_user='.urlencode($search_user);
  475. }
  476. // Add $param from extra fields
  477. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  478. // List of mass actions available
  479. $arrayofmassactions = array(
  480. // 'presend'=>$langs->trans("SendByMail"),
  481. // 'builddoc'=>$langs->trans("PDFMerge"),
  482. );
  483. //if ($user->rights->stock->supprimer) $arrayofmassactions['predelete']='<span class="fa fa-trash paddingrightonly"></span>'.$langs->trans("Delete");
  484. if (in_array($massaction, array('presend', 'predelete'))) {
  485. $arrayofmassactions = array();
  486. }
  487. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  488. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  489. if ($optioncss != '') {
  490. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  491. }
  492. print '<input type="hidden" name="token" value="'.newToken().'">';
  493. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  494. print '<input type="hidden" name="action" value="list">';
  495. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  496. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  497. print '<input type="hidden" name="page" value="'.$page.'">';
  498. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  499. if ($id > 0) {
  500. print '<input type="hidden" name="id" value="'.$id.'">';
  501. }
  502. if ($id > 0) {
  503. print_barre_liste('', $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, '', 0, '', '', $limit);
  504. } else {
  505. print_barre_liste('', $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'generic', 0, '', '', $limit);
  506. }
  507. $moreforfilter = '';
  508. $parameters = array();
  509. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
  510. if (empty($reshook)) {
  511. $moreforfilter .= $hookmanager->resPrint;
  512. } else {
  513. $moreforfilter = $hookmanager->resPrint;
  514. }
  515. if (!empty($moreforfilter)) {
  516. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  517. print $moreforfilter;
  518. print '</div>';
  519. }
  520. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  521. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  522. print '<div class="div-table-responsive">';
  523. print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  524. // Fields title search
  525. print '<tr class="liste_titre_filter">';
  526. if (!empty($arrayfields['m.rowid']['checked'])) {
  527. // Ref
  528. print '<td class="liste_titre left">';
  529. print '<input class="flat maxwidth25" type="text" name="search_ref" value="'.dol_escape_htmltag($search_ref).'">';
  530. print '</td>';
  531. }
  532. if (!empty($arrayfields['m.datem']['checked'])) {
  533. print '<td class="liste_titre nowraponall">';
  534. print '<input class="flat" type="text" size="2" maxlength="2" placeholder="'.dol_escape_htmltag($langs->trans("Month")).'" name="month" value="'.$month.'">';
  535. if (!isModEnabled('productbatch')) {
  536. print '&nbsp;';
  537. }
  538. //else print '<br>';
  539. $syear = $year ? $year : -1;
  540. print '<input class="flat maxwidth50" type="text" maxlength="4" placeholder="'.dol_escape_htmltag($langs->trans("Year")).'" name="year" value="'.($syear > 0 ? $syear : '').'">';
  541. //print $formother->selectyear($syear,'year',1, 20, 5);
  542. print '</td>';
  543. }
  544. if (!empty($arrayfields['p.ref']['checked'])) {
  545. // Product Ref
  546. print '<td class="liste_titre left">';
  547. print '<input class="flat maxwidth75" type="text" name="search_product_ref" value="'.dol_escape_htmltag($search_product_ref).'">';
  548. print '</td>';
  549. }
  550. if (!empty($arrayfields['p.label']['checked'])) {
  551. // Product label
  552. print '<td class="liste_titre left">';
  553. print '<input class="flat maxwidth100" type="text" name="search_product" value="'.dol_escape_htmltag($search_product).'">';
  554. print '</td>';
  555. }
  556. // Batch
  557. if (!empty($arrayfields['m.batch']['checked'])) {
  558. print '<td class="liste_titre center"><input class="flat maxwidth75" type="text" name="search_batch" value="'.dol_escape_htmltag($search_batch).'"></td>';
  559. }
  560. if (!empty($arrayfields['pl.eatby']['checked'])) {
  561. print '<td class="liste_titre left">';
  562. print '</td>';
  563. }
  564. if (!empty($arrayfields['pl.sellby']['checked'])) {
  565. print '<td class="liste_titre left">';
  566. print '</td>';
  567. }
  568. // Warehouse
  569. if (!empty($arrayfields['e.ref']['checked'])) {
  570. print '<td class="liste_titre maxwidthonsmartphone left">';
  571. //print '<input class="flat" type="text" size="8" name="search_warehouse" value="'.($search_warehouse).'">';
  572. print $formproduct->selectWarehouses($search_warehouse, 'search_warehouse', 'warehouseopen,warehouseinternal', 1, 0, 0, '', 0, 0, null, 'maxwidth200');
  573. print '</td>';
  574. }
  575. if (!empty($arrayfields['m.fk_user_author']['checked'])) {
  576. // Author
  577. print '<td class="liste_titre left">';
  578. print '<input class="flat" type="text" size="6" name="search_user" value="'.dol_escape_htmltag($search_user).'">';
  579. print '</td>';
  580. }
  581. if (!empty($arrayfields['m.inventorycode']['checked'])) {
  582. // Inventory code
  583. print '<td class="liste_titre left">';
  584. print '<input class="flat" type="text" size="4" name="search_inventorycode" value="'.dol_escape_htmltag($search_inventorycode).'">';
  585. print '</td>';
  586. }
  587. if (!empty($arrayfields['m.label']['checked'])) {
  588. // Label of movement
  589. print '<td class="liste_titre left">';
  590. print '<input class="flat" type="text" size="8" name="search_movement" value="'.dol_escape_htmltag($search_movement).'">';
  591. print '</td>';
  592. }
  593. if (!empty($arrayfields['m.type_mouvement']['checked'])) {
  594. // Type of movement
  595. print '<td class="liste_titre center">';
  596. //print '<input class="flat" type="text" size="3" name="search_type_mouvement" value="'.dol_escape_htmltag($search_type_mouvement).'">';
  597. print '<select id="search_type_mouvement" name="search_type_mouvement" class="maxwidth150">';
  598. print '<option value="" '.(($search_type_mouvement == "") ? 'selected="selected"' : '').'>&nbsp;</option>';
  599. print '<option value="0" '.(($search_type_mouvement == "0") ? 'selected="selected"' : '').'>'.$langs->trans('StockIncreaseAfterCorrectTransfer').'</option>';
  600. print '<option value="1" '.(($search_type_mouvement == "1") ? 'selected="selected"' : '').'>'.$langs->trans('StockDecreaseAfterCorrectTransfer').'</option>';
  601. print '<option value="2" '.(($search_type_mouvement == "2") ? 'selected="selected"' : '').'>'.$langs->trans('StockDecrease').'</option>';
  602. print '<option value="3" '.(($search_type_mouvement == "3") ? 'selected="selected"' : '').'>'.$langs->trans('StockIncrease').'</option>';
  603. print '</select>';
  604. print ajax_combobox('search_type_mouvement');
  605. // TODO: add new function $formentrepot->selectTypeOfMovement(...) like
  606. // print $formproduct->selectWarehouses($search_warehouse, 'search_warehouse', 'warehouseopen,warehouseinternal', 1, 0, 0, '', 0, 0, null, 'maxwidth200');
  607. print '</td>';
  608. }
  609. if (!empty($arrayfields['origin']['checked'])) {
  610. // Origin of movement
  611. print '<td class="liste_titre left">';
  612. print '&nbsp; ';
  613. print '</td>';
  614. }
  615. if (!empty($arrayfields['m.fk_projet']['checked'])) {
  616. // fk_project
  617. print '<td class="liste_titre" align="left">';
  618. print '&nbsp; ';
  619. print '</td>';
  620. }
  621. if (!empty($arrayfields['m.value']['checked'])) {
  622. // Qty
  623. print '<td class="liste_titre right">';
  624. print '<input class="flat" type="text" size="4" name="search_qty" value="'.dol_escape_htmltag($search_qty).'">';
  625. print '</td>';
  626. }
  627. if (!empty($arrayfields['m.price']['checked'])) {
  628. // Price
  629. print '<td class="liste_titre left">';
  630. print '&nbsp; ';
  631. print '</td>';
  632. }
  633. // Extra fields
  634. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  635. // Fields from hook
  636. $parameters = array('arrayfields'=>$arrayfields);
  637. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
  638. print $hookmanager->resPrint;
  639. // Date creation
  640. if (!empty($arrayfields['m.datec']['checked'])) {
  641. print '<td class="liste_titre">';
  642. print '</td>';
  643. }
  644. // Date modification
  645. if (!empty($arrayfields['m.tms']['checked'])) {
  646. print '<td class="liste_titre">';
  647. print '</td>';
  648. }
  649. // Actions
  650. print '<td class="liste_titre maxwidthsearch">';
  651. $searchpicto = $form->showFilterAndCheckAddButtons(0);
  652. print $searchpicto;
  653. print '</td>';
  654. print "</tr>\n";
  655. $totalarray = array();
  656. $totalarray['nbfield'] = 0;
  657. print '<tr class="liste_titre">';
  658. if (!empty($arrayfields['m.rowid']['checked'])) {
  659. print_liste_field_titre($arrayfields['m.rowid']['label'], $_SERVER["PHP_SELF"], 'm.rowid', '', $param, '', $sortfield, $sortorder);
  660. $totalarray['nbfield']++;
  661. }
  662. if (!empty($arrayfields['m.datem']['checked'])) {
  663. print_liste_field_titre($arrayfields['m.datem']['label'], $_SERVER["PHP_SELF"], 'm.datem', '', $param, '', $sortfield, $sortorder);
  664. $totalarray['nbfield']++;
  665. }
  666. if (!empty($arrayfields['p.ref']['checked'])) {
  667. print_liste_field_titre($arrayfields['p.ref']['label'], $_SERVER["PHP_SELF"], 'p.ref', '', $param, '', $sortfield, $sortorder);
  668. $totalarray['nbfield']++;
  669. }
  670. if (!empty($arrayfields['p.label']['checked'])) {
  671. print_liste_field_titre($arrayfields['p.label']['label'], $_SERVER["PHP_SELF"], 'p.label', '', $param, '', $sortfield, $sortorder);
  672. $totalarray['nbfield']++;
  673. }
  674. if (!empty($arrayfields['m.batch']['checked'])) {
  675. print_liste_field_titre($arrayfields['m.batch']['label'], $_SERVER["PHP_SELF"], 'm.batch', '', $param, '', $sortfield, $sortorder, 'center ');
  676. $totalarray['nbfield']++;
  677. }
  678. if (!empty($arrayfields['pl.eatby']['checked'])) {
  679. print_liste_field_titre($arrayfields['pl.eatby']['label'], $_SERVER["PHP_SELF"], 'pl.eatby', '', $param, '', $sortfield, $sortorder, 'center ');
  680. $totalarray['nbfield']++;
  681. }
  682. if (!empty($arrayfields['pl.sellby']['checked'])) {
  683. print_liste_field_titre($arrayfields['pl.sellby']['label'], $_SERVER["PHP_SELF"], 'pl.sellby', '', $param, '', $sortfield, $sortorder, 'center ');
  684. $totalarray['nbfield']++;
  685. }
  686. if (!empty($arrayfields['e.ref']['checked'])) {
  687. // We are on a specific warehouse card, no filter on other should be possible
  688. print_liste_field_titre($arrayfields['e.ref']['label'], $_SERVER["PHP_SELF"], "e.ref", "", $param, "", $sortfield, $sortorder);
  689. $totalarray['nbfield']++;
  690. }
  691. if (!empty($arrayfields['m.fk_user_author']['checked'])) {
  692. print_liste_field_titre($arrayfields['m.fk_user_author']['label'], $_SERVER["PHP_SELF"], "m.fk_user_author", "", $param, "", $sortfield, $sortorder);
  693. $totalarray['nbfield']++;
  694. }
  695. if (!empty($arrayfields['m.inventorycode']['checked'])) {
  696. print_liste_field_titre($arrayfields['m.inventorycode']['label'], $_SERVER["PHP_SELF"], "m.inventorycode", "", $param, "", $sortfield, $sortorder);
  697. $totalarray['nbfield']++;
  698. }
  699. if (!empty($arrayfields['m.label']['checked'])) {
  700. print_liste_field_titre($arrayfields['m.label']['label'], $_SERVER["PHP_SELF"], "m.label", "", $param, "", $sortfield, $sortorder);
  701. $totalarray['nbfield']++;
  702. }
  703. if (!empty($arrayfields['m.type_mouvement']['checked'])) {
  704. print_liste_field_titre($arrayfields['m.type_mouvement']['label'], $_SERVER["PHP_SELF"], "m.type_mouvement", "", $param, '', $sortfield, $sortorder, 'center ');
  705. $totalarray['nbfield']++;
  706. }
  707. if (!empty($arrayfields['origin']['checked'])) {
  708. print_liste_field_titre($arrayfields['origin']['label'], $_SERVER["PHP_SELF"], "", "", $param, "", $sortfield, $sortorder);
  709. $totalarray['nbfield']++;
  710. }
  711. if (!empty($arrayfields['m.fk_projet']['checked'])) {
  712. print_liste_field_titre($arrayfields['m.fk_projet']['label'], $_SERVER["PHP_SELF"], "m.fk_projet", "", $param, '', $sortfield, $sortorder);
  713. $totalarray['nbfield']++;
  714. }
  715. if (!empty($arrayfields['m.value']['checked'])) {
  716. print_liste_field_titre($arrayfields['m.value']['label'], $_SERVER["PHP_SELF"], "m.value", "", $param, '', $sortfield, $sortorder, 'right ');
  717. $totalarray['nbfield']++;
  718. }
  719. if (!empty($arrayfields['m.price']['checked'])) {
  720. print_liste_field_titre($arrayfields['m.price']['label'], $_SERVER["PHP_SELF"], "m.price", "", $param, '', $sortfield, $sortorder, 'right ');
  721. $totalarray['nbfield']++;
  722. }
  723. // Extra fields
  724. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  725. // Hook fields
  726. $parameters = array('arrayfields' => $arrayfields, 'param' => $param, 'sortfield' => $sortfield, 'sortorder' => $sortorder);
  727. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
  728. print $hookmanager->resPrint;
  729. if (!empty($arrayfields['m.datec']['checked'])) {
  730. print_liste_field_titre($arrayfields['p.datec']['label'], $_SERVER["PHP_SELF"], "p.datec", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
  731. $totalarray['nbfield']++;
  732. }
  733. if (!empty($arrayfields['m.tms']['checked'])) {
  734. print_liste_field_titre($arrayfields['p.tms']['label'], $_SERVER["PHP_SELF"], "p.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
  735. $totalarray['nbfield']++;
  736. }
  737. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
  738. $totalarray['nbfield']++;
  739. print "</tr>\n";
  740. $i = 0;
  741. $savnbfield = $totalarray['nbfield'];
  742. $totalarray = array();
  743. $totalarray['nbfield'] = 0;
  744. $imaxinloop = ($limit ? min($num, $limit) : $num);
  745. while ($i < $imaxinloop) {
  746. $objp = $db->fetch_object($resql);
  747. // Multilangs
  748. if (getDolGlobalInt('MAIN_MULTILANGS')) { // If multilang is enabled
  749. // TODO Use a cache here
  750. $sql = "SELECT label";
  751. $sql .= " FROM ".MAIN_DB_PREFIX."product_lang";
  752. $sql .= " WHERE fk_product = ".((int) $objp->rowid);
  753. $sql .= " AND lang = '".$db->escape($langs->getDefaultLang())."'";
  754. $sql .= " LIMIT 1";
  755. $result = $db->query($sql);
  756. if ($result) {
  757. $objtp = $db->fetch_object($result);
  758. if (!empty($objtp->label)) {
  759. $objp->produit = $objtp->label;
  760. }
  761. }
  762. }
  763. $userstatic->id = $objp->fk_user_author;
  764. $userstatic->login = $objp->login;
  765. $userstatic->lastname = $objp->lastname;
  766. $userstatic->firstname = $objp->firstname;
  767. $userstatic->photo = $objp->photo;
  768. $productstatic->id = $objp->rowid;
  769. $productstatic->ref = $objp->product_ref;
  770. $productstatic->label = $objp->produit;
  771. $productstatic->type = $objp->type;
  772. $productstatic->entity = $objp->entity;
  773. $productstatic->status_batch = $objp->tobatch;
  774. $productlot->id = $objp->lotid;
  775. $productlot->batch = $objp->batch;
  776. $productlot->eatby = $objp->eatby;
  777. $productlot->sellby = $objp->sellby;
  778. $warehousestatic->id = $objp->entrepot_id;
  779. $warehousestatic->libelle = $objp->warehouse_ref; // deprecated
  780. $warehousestatic->label = $objp->warehouse_ref;
  781. $warehousestatic->lieu = $objp->lieu;
  782. if (!empty($objp->fk_origin)) {
  783. $origin = $objectlist->get_origin($objp->fk_origin, $objp->origintype);
  784. } else {
  785. $origin = '';
  786. }
  787. print '<tr class="oddeven">';
  788. // Id movement
  789. if (!empty($arrayfields['m.rowid']['checked'])) {
  790. // This is primary not movement id
  791. print '<td>'.dol_escape_htmltag($objp->mid).'</td>';
  792. }
  793. if (!empty($arrayfields['m.datem']['checked'])) {
  794. // Date
  795. print '<td>'.dol_print_date($db->jdate($objp->datem), 'dayhour').'</td>';
  796. }
  797. if (!empty($arrayfields['p.ref']['checked'])) {
  798. // Product ref
  799. print '<td class="nowraponall">';
  800. print $productstatic->getNomUrl(1, 'stock', 16);
  801. print "</td>\n";
  802. }
  803. if (!empty($arrayfields['p.label']['checked'])) {
  804. // Product label
  805. print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($productstatic->label).'">';
  806. print $productstatic->label;
  807. print "</td>\n";
  808. }
  809. if (!empty($arrayfields['m.batch']['checked'])) {
  810. print '<td class="center nowraponall">';
  811. if ($productlot->id > 0) {
  812. print $productlot->getNomUrl(1);
  813. } else {
  814. print dol_escape_htmltag($productlot->batch); // the id may not be defined if movement was entered when lot was not saved or if lot was removed after movement.
  815. }
  816. print '</td>';
  817. }
  818. if (!empty($arrayfields['pl.eatby']['checked'])) {
  819. print '<td class="center">'.dol_print_date($objp->eatby, 'day').'</td>';
  820. }
  821. if (!empty($arrayfields['pl.sellby']['checked'])) {
  822. print '<td class="center">'.dol_print_date($objp->sellby, 'day').'</td>';
  823. }
  824. // Warehouse
  825. if (!empty($arrayfields['e.ref']['checked'])) {
  826. print '<td>';
  827. print $warehousestatic->getNomUrl(1);
  828. print "</td>\n";
  829. }
  830. // Author
  831. if (!empty($arrayfields['m.fk_user_author']['checked'])) {
  832. print '<td class="tdoverflowmax100">';
  833. print $userstatic->getNomUrl(-1);
  834. print "</td>\n";
  835. }
  836. // Inventory code
  837. if (!empty($arrayfields['m.inventorycode']['checked'])) {
  838. print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($objp->inventorycode).'">';
  839. //print '<a href="' . DOL_URL_ROOT . '/product/stock/movement_card.php' . '?id=' . $objp->entrepot_id . '&amp;search_inventorycode=' . $objp->inventorycode . '&amp;search_type_mouvement=' . $objp->type_mouvement . '">';
  840. print dol_escape_htmltag($objp->inventorycode);
  841. //print '</a>';
  842. print '</td>';
  843. }
  844. // Label of movement
  845. if (!empty($arrayfields['m.label']['checked'])) {
  846. print '<td class="tdoverflowmax300" title="'.dol_escape_htmltag($objp->label).'">'.dol_escape_htmltag($objp->label).'</td>';
  847. }
  848. // Type of movement
  849. if (!empty($arrayfields['m.type_mouvement']['checked'])) {
  850. switch ($objp->type_mouvement) {
  851. case "0":
  852. print '<td class="center">'.$langs->trans('StockIncreaseAfterCorrectTransfer').'</td>';
  853. break;
  854. case "1":
  855. print '<td class="center">'.$langs->trans('StockDecreaseAfterCorrectTransfer').'</td>';
  856. break;
  857. case "2":
  858. print '<td class="center">'.$langs->trans('StockDecrease').'</td>';
  859. break;
  860. case "3":
  861. print '<td class="center">'.$langs->trans('StockIncrease').'</td>';
  862. break;
  863. }
  864. }
  865. if (!empty($arrayfields['origin']['checked'])) {
  866. // Origin of movement
  867. print '<td class="nowraponall">'.$origin.'</td>';
  868. }
  869. if (!empty($arrayfields['m.fk_projet']['checked'])) {
  870. // fk_project
  871. print '<td>';
  872. if ($objp->fk_project != 0) {
  873. print $movement->get_origin($objp->fk_project, 'project');
  874. }
  875. print '</td>';
  876. }
  877. if (!empty($arrayfields['m.value']['checked'])) {
  878. // Qty
  879. print '<td class="right">';
  880. if ($objp->qty >0) {
  881. print '<span class="stockmovemententry">+'.$objp->qty.'</span>';
  882. } else {
  883. print '<span class="stockmovementexit">'.$objp->qty.'<span>';
  884. }
  885. print '</td>';
  886. }
  887. if (!empty($arrayfields['m.price']['checked'])) {
  888. // Price
  889. print '<td class="right">';
  890. if ($objp->price != 0) {
  891. print '<span class="opacitymedium">'.price($objp->price).'</span>';
  892. }
  893. print '</td>';
  894. }
  895. // Action column
  896. print '<td class="nowrap center">';
  897. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  898. $selected = 0;
  899. if (in_array($objp->rowid, $arrayofselected)) {
  900. $selected = 1;
  901. }
  902. print '<input id="cb'.$objp->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$objp->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
  903. }
  904. print '</td>';
  905. if (!$i) {
  906. $totalarray['nbfield']++;
  907. }
  908. print "</tr>\n";
  909. $i++;
  910. }
  911. if (empty($num)) {
  912. print '<tr><td colspan="'.$savnbfield.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
  913. }
  914. $db->free($resql);
  915. print "</table>";
  916. print '</div>';
  917. print "</form>";
  918. }
  919. // End of page
  920. llxFooter();
  921. $db->close();