mo_movements.php 41 KB

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