mo_movements.php 40 KB

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