massstockmove.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752
  1. <?php
  2. /* Copyright (C) 2013-2022 Laurent Destaileur <ely@users.sourceforge.net>
  3. * Copyright (C) 2014 Regis Houssin <regis.houssin@inodbox.com>
  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 htdocs/product/stock/massstockmove.php
  20. * \ingroup stock
  21. * \brief This page allows to select several products, then incoming warehouse and
  22. * outgoing warehouse and create all stock movements for this.
  23. */
  24. // Load Dolibarr environment
  25. require '../../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/modules/import/import_csv.modules.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/lib/import.lib.php';
  35. $confirm = GETPOST('confirm', 'alpha');
  36. $filetoimport = GETPOST('filetoimport');
  37. // Load translation files required by the page
  38. $langs->loadLangs(array('products', 'stocks', 'orders', 'productbatch'));
  39. //init Hook
  40. $hookmanager->initHooks(array('massstockmove'));
  41. // Security check
  42. if ($user->socid) {
  43. $socid = $user->socid;
  44. }
  45. $result = restrictedArea($user, 'produit|service');
  46. //checks if a product has been ordered
  47. $action = GETPOST('action', 'aZ09');
  48. $id_product = GETPOST('productid', 'int');
  49. $id_sw = GETPOST('id_sw', 'int');
  50. $id_tw = GETPOST('id_tw', 'int');
  51. $batch = GETPOST('batch');
  52. $qty = GETPOST('qty');
  53. $idline = GETPOST('idline');
  54. $sortfield = GETPOST('sortfield', 'aZ09comma');
  55. $sortorder = GETPOST('sortorder', 'aZ09comma');
  56. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  57. if (empty($page) || $page == -1) {
  58. $page = 0;
  59. } // If $page is not defined, or '' or -1
  60. if (!$sortfield) {
  61. $sortfield = 'p.ref';
  62. }
  63. if (!$sortorder) {
  64. $sortorder = 'ASC';
  65. }
  66. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  67. $offset = $limit * $page;
  68. if (GETPOST('init')) {
  69. unset($_SESSION['massstockmove']);
  70. }
  71. $listofdata = array();
  72. if (!empty($_SESSION['massstockmove'])) {
  73. $listofdata = json_decode($_SESSION['massstockmove'], true);
  74. }
  75. /*
  76. * Actions
  77. */
  78. if ($action == 'addline' && !empty($user->rights->stock->mouvement->creer)) {
  79. if (!($id_sw > 0)) {
  80. //$error++;
  81. //setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WarehouseSource")), null, 'errors');
  82. if ($id_sw < 0) {
  83. $id_sw = 0;
  84. }
  85. }
  86. if (!($id_tw > 0)) {
  87. $error++;
  88. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WarehouseTarget")), null, 'errors');
  89. }
  90. if ($id_sw > 0 && $id_tw == $id_sw) {
  91. $error++;
  92. $langs->load("errors");
  93. setEventMessages($langs->trans("ErrorWarehouseMustDiffers"), null, 'errors');
  94. }
  95. if (!($id_product > 0)) {
  96. $error++;
  97. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Product")), null, 'errors');
  98. }
  99. if (!$qty) {
  100. $error++;
  101. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Qty")), null, 'errors');
  102. }
  103. // Check a batch number is provided if product need it
  104. if (!$error) {
  105. $producttmp = new Product($db);
  106. $producttmp->fetch($id_product);
  107. if ($producttmp->hasbatch()) {
  108. if (empty($batch)) {
  109. $error++;
  110. $langs->load("errors");
  111. setEventMessages($langs->trans("ErrorTryToMakeMoveOnProductRequiringBatchData", $producttmp->ref), null, 'errors');
  112. }
  113. }
  114. }
  115. // TODO Check qty is ok for stock move. Note qty may not be enough yet, but we make a check now to report a warning.
  116. // What is more important is to have qty when doing action 'createmovements'
  117. if (!$error) {
  118. // Warning, don't forget lines already added into the $_SESSION['massstockmove']
  119. if ($producttmp->hasbatch()) {
  120. } else {
  121. }
  122. }
  123. //var_dump($_SESSION['massstockmove']);exit;
  124. if (!$error) {
  125. if (count(array_keys($listofdata)) > 0) {
  126. $id = max(array_keys($listofdata)) + 1;
  127. } else {
  128. $id = 1;
  129. }
  130. $listofdata[$id] = array('id'=>$id, 'id_product'=>$id_product, 'qty'=>$qty, 'id_sw'=>$id_sw, 'id_tw'=>$id_tw, 'batch'=>$batch);
  131. $_SESSION['massstockmove'] = json_encode($listofdata);
  132. //unset($id_sw);
  133. //unset($id_tw);
  134. unset($id_product);
  135. unset($batch);
  136. unset($qty);
  137. }
  138. }
  139. if ($action == 'delline' && $idline != '' && !empty($user->rights->stock->mouvement->creer)) {
  140. if (!empty($listofdata[$idline])) {
  141. unset($listofdata[$idline]);
  142. }
  143. if (count($listofdata) > 0) {
  144. $_SESSION['massstockmove'] = json_encode($listofdata);
  145. } else {
  146. unset($_SESSION['massstockmove']);
  147. }
  148. }
  149. if ($action == 'createmovements' && !empty($user->rights->stock->mouvement->creer)) {
  150. $error = 0;
  151. if (!GETPOST("label")) {
  152. $error++;
  153. setEventMessages($langs->trans("ErrorFieldRequired"), $langs->transnoentitiesnoconv("MovementLabel"), null, 'errors');
  154. }
  155. $db->begin();
  156. if (!$error) {
  157. $product = new Product($db);
  158. foreach ($listofdata as $key => $val) { // Loop on each movement to do
  159. $id = $val['id'];
  160. $id_product = $val['id_product'];
  161. $id_sw = $val['id_sw'];
  162. $id_tw = $val['id_tw'];
  163. $qty = price2num($val['qty']);
  164. $batch = $val['batch'];
  165. $dlc = -1; // They are loaded later from serial
  166. $dluo = -1; // They are loaded later from serial
  167. if (!$error && $id_sw <> $id_tw && is_numeric($qty) && $id_product) {
  168. $result = $product->fetch($id_product);
  169. $product->load_stock('novirtual'); // Load array product->stock_warehouse
  170. // Define value of products moved
  171. $pricesrc = 0;
  172. if (!empty($product->pmp)) {
  173. $pricesrc = $product->pmp;
  174. }
  175. $pricedest = $pricesrc;
  176. //print 'price src='.$pricesrc.', price dest='.$pricedest;exit;
  177. if (empty($conf->productbatch->enabled) || !$product->hasbatch()) { // If product does not need lot/serial
  178. // Remove stock if source warehouse defined
  179. if ($id_sw > 0) {
  180. $result1 = $product->correct_stock(
  181. $user,
  182. $id_sw,
  183. $qty,
  184. 1,
  185. GETPOST("label"),
  186. $pricesrc,
  187. GETPOST("codemove")
  188. );
  189. if ($result1 < 0) {
  190. $error++;
  191. setEventMessages($product->error, $product->errors, 'errors');
  192. }
  193. }
  194. // Add stock
  195. $result2 = $product->correct_stock(
  196. $user,
  197. $id_tw,
  198. $qty,
  199. 0,
  200. GETPOST("label"),
  201. $pricedest,
  202. GETPOST("codemove")
  203. );
  204. if ($result2 < 0) {
  205. $error++;
  206. setEventMessages($product->error, $product->errors, 'errors');
  207. }
  208. } else {
  209. $arraybatchinfo = $product->loadBatchInfo($batch);
  210. if (count($arraybatchinfo) > 0) {
  211. $firstrecord = array_shift($arraybatchinfo);
  212. $dlc = $firstrecord['eatby'];
  213. $dluo = $firstrecord['sellby'];
  214. //var_dump($batch);
  215. //var_dump($arraybatchinfo);
  216. //var_dump($firstrecord);
  217. //var_dump($dlc);
  218. //var_dump($dluo); exit;
  219. } else {
  220. $dlc = '';
  221. $dluo = '';
  222. }
  223. // Remove stock
  224. if ($id_sw > 0) {
  225. $result1 = $product->correct_stock_batch(
  226. $user,
  227. $id_sw,
  228. $qty,
  229. 1,
  230. GETPOST("label"),
  231. $pricesrc,
  232. $dlc,
  233. $dluo,
  234. $batch,
  235. GETPOST("codemove")
  236. );
  237. if ($result1 < 0) {
  238. $error++;
  239. setEventMessages($product->error, $product->errors, 'errors');
  240. }
  241. }
  242. // Add stock
  243. $result2 = $product->correct_stock_batch(
  244. $user,
  245. $id_tw,
  246. $qty,
  247. 0,
  248. GETPOST("label"),
  249. $pricedest,
  250. $dlc,
  251. $dluo,
  252. $batch,
  253. GETPOST("codemove")
  254. );
  255. if ($result2 < 0) {
  256. $error++;
  257. setEventMessages($product->error, $product->errors, 'errors');
  258. }
  259. }
  260. } else {
  261. // dol_print_error('',"Bad value saved into sessions");
  262. $error++;
  263. }
  264. }
  265. }
  266. //var_dump($_SESSION['massstockmove']);exit;
  267. if (!$error) {
  268. unset($_SESSION['massstockmove']);
  269. $db->commit();
  270. setEventMessages($langs->trans("StockMovementRecorded"), null, 'mesgs');
  271. header("Location: ".DOL_URL_ROOT.'/product/stock/index.php'); // Redirect to avoid pb when using back
  272. exit;
  273. } else {
  274. $db->rollback();
  275. setEventMessages($langs->trans("Error"), null, 'errors');
  276. }
  277. }
  278. if ($action == 'importCSV' && !empty($user->rights->stock->mouvement->creer)) {
  279. dol_mkdir($conf->stock->dir_temp);
  280. $nowyearmonth = dol_print_date(dol_now(), '%Y%m%d%H%M%S');
  281. $fullpath = $conf->stock->dir_temp."/".$user->id.'-csvfiletotimport.csv';
  282. if (dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $fullpath, 1) > 0) {
  283. dol_syslog("File ".$fullpath." was added for import");
  284. } else {
  285. $error++;
  286. $langs->load("errors");
  287. setEventMessages($langs->trans("ErrorFailedToSaveFile"), null, 'errors');
  288. }
  289. if (!$error) {
  290. $importcsv = new ImportCsv($db, 'massstocklist');
  291. //print $importcsv->separator;
  292. $nblinesrecord = $importcsv->import_get_nb_of_lines($fullpath)-1;
  293. $importcsv->import_open_file($fullpath);
  294. $labelsrecord = $importcsv->import_read_record();
  295. if ($nblinesrecord < 1) {
  296. setEventMessages($langs->trans("BadNumberOfLinesMustHaveAtLeastOneLinePlusTitle"), null, 'errors');
  297. } else {
  298. $i=0;
  299. $data = array();
  300. $productstatic = new Product($db);
  301. $warehousestatics = new Entrepot($db);
  302. $warehousestatict = new Entrepot($db);
  303. while (($i < $nblinesrecord) && !$error) {
  304. $data[] = $importcsv->import_read_record();
  305. if (count($data[$i]) == 1) {
  306. // Only 1 empty line
  307. unset($data[$i]);
  308. $i++;
  309. continue;
  310. }
  311. //var_dump($data);
  312. $tmp_id_sw = $data[$i][0]['val'];
  313. $tmp_id_tw = $data[$i][1]['val'];
  314. $tmp_id_product = $data[$i][2]['val'];
  315. $tmp_qty = $data[$i][3]['val'];
  316. $tmp_batch = $data[$i][4]['val'];
  317. if (!is_numeric($tmp_id_product)) {
  318. $result = fetchref($productstatic, $tmp_id_product);
  319. $tmp_id_product = $result;
  320. $data[$i][2]['val'] = $result;
  321. }
  322. if (!($tmp_id_product > 0)) {
  323. $error++;
  324. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Product")), null, 'errors');
  325. }
  326. if (!is_numeric($tmp_id_sw)) {
  327. $result = fetchref($warehousestatics, $tmp_id_sw);
  328. $tmp_id_sw = $result;
  329. $data[$i][0]['val'] = $result;
  330. }
  331. if (!($tmp_id_sw > 0)) {
  332. $error++;
  333. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WarehouseSource")), null, 'errors');
  334. }
  335. if (!is_numeric($tmp_id_tw)) {
  336. $result = fetchref($warehousestatict, $tmp_id_tw);
  337. $tmp_id_tw = $result;
  338. $data[$i][1]['val'] = $result;
  339. }
  340. if (!($tmp_id_tw > 0)) {
  341. $error++;
  342. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WarehouseTarget")), null, 'errors');
  343. }
  344. if ($tmp_id_sw > 0 && $tmp_id_tw == $tmp_id_sw) {
  345. $error++;
  346. $langs->load("errors");
  347. setEventMessages($langs->trans("ErrorWarehouseMustDiffers"), null, 'errors');
  348. }
  349. if (!$tmp_qty) {
  350. $error++;
  351. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Qty")), null, 'errors');
  352. }
  353. // Check a batch number is provided if product need it
  354. if (!$error) {
  355. $producttmp = new Product($db);
  356. $producttmp->fetch($tmp_id_product);
  357. if ($producttmp->hasbatch()) {
  358. if (empty($tmp_batch)) {
  359. $error++;
  360. $langs->load("errors");
  361. setEventMessages($langs->trans("ErrorTryToMakeMoveOnProductRequiringBatchData", $producttmp->ref), null, 'errors');
  362. }
  363. }
  364. }
  365. $i++;
  366. }
  367. if (!$error) {
  368. foreach ($data as $key => $value) {
  369. if (count(array_keys($listofdata)) > 0) {
  370. $id = max(array_keys($listofdata)) + 1;
  371. } else {
  372. $id = 1;
  373. }
  374. $tmp_id_sw = $data[$key][0]['val'];
  375. $tmp_id_tw = $data[$key][1]['val'];
  376. $tmp_id_product = $data[$key][2]['val'];
  377. $tmp_qty = $data[$key][3]['val'];
  378. $tmp_batch = $data[$key][4]['val'];
  379. $listofdata[$key] = array('id'=>$key, 'id_sw'=>$tmp_id_sw, 'id_tw'=>$tmp_id_tw, 'id_product'=>$tmp_id_product, 'qty'=>$tmp_qty, 'batch'=>$tmp_batch);
  380. }
  381. }
  382. }
  383. }
  384. $_SESSION['massstockmove'] = json_encode($listofdata);
  385. }
  386. if ($action == 'confirm_deletefile' && $confirm == 'yes') {
  387. $langs->load("other");
  388. $param = '&datatoimport='.urlencode($datatoimport).'&format='.urlencode($format);
  389. if ($excludefirstline) {
  390. $param .= '&excludefirstline='.urlencode($excludefirstline);
  391. }
  392. if ($endatlinenb) {
  393. $param .= '&endatlinenb='.urlencode($endatlinenb);
  394. }
  395. $file = $conf->stock->dir_temp.'/'.GETPOST('urlfile'); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
  396. $ret = dol_delete_file($file);
  397. if ($ret) {
  398. setEventMessages($langs->trans("FileWasRemoved", GETPOST('urlfile')), null, 'mesgs');
  399. } else {
  400. setEventMessages($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), null, 'errors');
  401. }
  402. Header('Location: '.$_SERVER["PHP_SELF"]);
  403. exit;
  404. }
  405. /*
  406. * View
  407. */
  408. $now = dol_now();
  409. $error = 0;
  410. $form = new Form($db);
  411. $formproduct = new FormProduct($db);
  412. $productstatic = new Product($db);
  413. $warehousestatics = new Entrepot($db);
  414. $warehousestatict = new Entrepot($db);
  415. $help_url = 'EN:Module_Stocks_En|FR:Module_Stock|ES:Módulo_Stocks|DE:Modul_Bestände';
  416. $title = $langs->trans('MassMovement');
  417. llxHeader('', $title, $help_url);
  418. print load_fiche_titre($langs->trans("MassStockTransferShort"), '', 'stock');
  419. $titletoadd = $langs->trans("Select");
  420. $buttonrecord = $langs->trans("RecordMovements");
  421. $titletoaddnoent = $langs->transnoentitiesnoconv("Select");
  422. $buttonrecordnoent = $langs->transnoentitiesnoconv("RecordMovements");
  423. print '<span class="opacitymedium">'.$langs->trans("SelectProductInAndOutWareHouse", $titletoaddnoent, $buttonrecordnoent).'</span><br>';
  424. print '<br>';
  425. // Form to upload a file
  426. print '<form name="userfile" action="'.$_SERVER["PHP_SELF"].'" enctype="multipart/form-data" METHOD="POST">';
  427. print '<input type="hidden" name="token" value="'.newToken().'">';
  428. print '<input type="hidden" name="action" value="importCSV">';
  429. print '<span class="opacitymedium">';
  430. print $langs->trans("or").' ';
  431. $importcsv = new ImportCsv($db, 'massstocklist');
  432. print $form->textwithpicto($langs->trans('SelectAStockMovementFileToImport'), $langs->transnoentitiesnoconv("InfoTemplateImport", $importcsv->separator));
  433. print '</span>';
  434. $maxfilesizearray = getMaxFileSizeArray();
  435. $maxmin = $maxfilesizearray['maxmin'];
  436. if ($maxmin > 0) {
  437. print '<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).'">'; // MAX_FILE_SIZE must precede the field type=file
  438. }
  439. print '<input type="file" name="userfile" size="20" maxlength="80"> &nbsp; &nbsp; ';
  440. $out = (empty($conf->global->MAIN_UPLOAD_DOC) ? ' disabled' : '');
  441. print '<input type="submit" class="button small" value="'.$langs->trans("ImportFromCSV").'"'.$out.' name="sendit">';
  442. $out = '';
  443. if (!empty($conf->global->MAIN_UPLOAD_DOC)) {
  444. $max = $conf->global->MAIN_UPLOAD_DOC; // In Kb
  445. $maxphp = @ini_get('upload_max_filesize'); // In unknown
  446. if (preg_match('/k$/i', $maxphp)) {
  447. $maxphp = preg_replace('/k$/i', '', $maxphp);
  448. $maxphp = $maxphp * 1;
  449. }
  450. if (preg_match('/m$/i', $maxphp)) {
  451. $maxphp = preg_replace('/m$/i', '', $maxphp);
  452. $maxphp = $maxphp * 1024;
  453. }
  454. if (preg_match('/g$/i', $maxphp)) {
  455. $maxphp = preg_replace('/g$/i', '', $maxphp);
  456. $maxphp = $maxphp * 1024 * 1024;
  457. }
  458. if (preg_match('/t$/i', $maxphp)) {
  459. $maxphp = preg_replace('/t$/i', '', $maxphp);
  460. $maxphp = $maxphp * 1024 * 1024 * 1024;
  461. }
  462. $maxphp2 = @ini_get('post_max_size'); // In unknown
  463. if (preg_match('/k$/i', $maxphp2)) {
  464. $maxphp2 = preg_replace('/k$/i', '', $maxphp2);
  465. $maxphp2 = $maxphp2 * 1;
  466. }
  467. if (preg_match('/m$/i', $maxphp2)) {
  468. $maxphp2 = preg_replace('/m$/i', '', $maxphp2);
  469. $maxphp2 = $maxphp2 * 1024;
  470. }
  471. if (preg_match('/g$/i', $maxphp2)) {
  472. $maxphp2 = preg_replace('/g$/i', '', $maxphp2);
  473. $maxphp2 = $maxphp2 * 1024 * 1024;
  474. }
  475. if (preg_match('/t$/i', $maxphp2)) {
  476. $maxphp2 = preg_replace('/t$/i', '', $maxphp2);
  477. $maxphp2 = $maxphp2 * 1024 * 1024 * 1024;
  478. }
  479. // Now $max and $maxphp and $maxphp2 are in Kb
  480. $maxmin = $max;
  481. $maxphptoshow = $maxphptoshowparam = '';
  482. if ($maxphp > 0) {
  483. $maxmin = min($max, $maxphp);
  484. $maxphptoshow = $maxphp;
  485. $maxphptoshowparam = 'upload_max_filesize';
  486. }
  487. if ($maxphp2 > 0) {
  488. $maxmin = min($max, $maxphp2);
  489. if ($maxphp2 < $maxphp) {
  490. $maxphptoshow = $maxphp2;
  491. $maxphptoshowparam = 'post_max_size';
  492. }
  493. }
  494. $langs->load('other');
  495. $out .= ' ';
  496. $out .= info_admin($langs->trans("ThisLimitIsDefinedInSetup", $max, $maxphptoshow), 1);
  497. } else {
  498. $out .= ' ('.$langs->trans("UploadDisabled").')';
  499. }
  500. print $out;
  501. print '</form>';
  502. print '<br><br>';
  503. // Form to add a line
  504. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" name="formulaire">';
  505. print '<input type="hidden" name="token" value="'.newToken().'">';
  506. print '<input type="hidden" name="action" value="addline">';
  507. print '<div class="div-table-responsive-no-min">';
  508. print '<table class="liste centpercent">';
  509. $param = '';
  510. print '<tr class="liste_titre">';
  511. print getTitleFieldOfList($langs->trans('WarehouseSource'), 0, $_SERVER["PHP_SELF"], '', $param, '', '', $sortfield, $sortorder, 'tagtd maxwidthonsmartphone ');
  512. print getTitleFieldOfList($langs->trans('WarehouseTarget'), 0, $_SERVER["PHP_SELF"], '', $param, '', '', $sortfield, $sortorder, 'tagtd maxwidthonsmartphone ');
  513. print getTitleFieldOfList($langs->trans('Product'), 0, $_SERVER["PHP_SELF"], '', $param, '', '', $sortfield, $sortorder, 'tagtd maxwidthonsmartphone ');
  514. if (isModEnabled('productbatch')) {
  515. print getTitleFieldOfList($langs->trans('Batch'), 0, $_SERVER["PHP_SELF"], '', $param, '', '', $sortfield, $sortorder, 'tagtd maxwidthonsmartphone ');
  516. }
  517. print getTitleFieldOfList($langs->trans('Qty'), 0, $_SERVER["PHP_SELF"], '', $param, '', '', $sortfield, $sortorder, 'right tagtd maxwidthonsmartphone ');
  518. print getTitleFieldOfList('', 0);
  519. print '</tr>';
  520. print '<tr class="oddeven">';
  521. // From warehouse
  522. print '<td class="nowraponall">';
  523. print img_picto($langs->trans("WarehouseSource"), 'stock', 'class="paddingright"').$formproduct->selectWarehouses($id_sw, 'id_sw', 'warehouseopen,warehouseinternal', 1, 0, 0, '', 0, 0, array(), 'minwidth200imp maxwidth200');
  524. print '</td>';
  525. // To warehouse
  526. print '<td class="nowraponall">';
  527. print img_picto($langs->trans("WarehouseTarget"), 'stock', 'class="paddingright"').$formproduct->selectWarehouses($id_tw, 'id_tw', 'warehouseopen,warehouseinternal', 1, 0, 0, '', 0, 0, array(), 'minwidth200imp maxwidth200');
  528. print '</td>';
  529. // Product
  530. print '<td class="nowraponall">';
  531. $filtertype = 0;
  532. if (!empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
  533. $filtertype = '';
  534. }
  535. if ($conf->global->PRODUIT_LIMIT_SIZE <= 0) {
  536. $limit = '';
  537. } else {
  538. $limit = $conf->global->PRODUIT_LIMIT_SIZE;
  539. }
  540. print img_picto($langs->trans("Product"), 'product', 'class="paddingright"');
  541. print $form->select_produits($id_product, 'productid', $filtertype, $limit, 0, -1, 2, '', 1, array(), 0, '1', 0, 'minwidth200imp maxwidth300', 1, '', null, 1);
  542. print '</td>';
  543. // Batch number
  544. if (isModEnabled('productbatch')) {
  545. print '<td class="nowraponall">';
  546. print img_picto($langs->trans("LotSerial"), 'lot', 'class="paddingright"');
  547. print '<input type="text" name="batch" class="flat maxwidth75" value="'.dol_escape_htmltag($batch).'">';
  548. print '</td>';
  549. }
  550. // Qty
  551. print '<td class="right"><input type="text" class="flat maxwidth50 right" name="qty" value="'.price2num((float) $qty, 'MS').'"></td>';
  552. // Button to add line
  553. print '<td class="right"><input type="submit" class="button" name="addline" value="'.dol_escape_htmltag($titletoadd).'"></td>';
  554. print '</tr>';
  555. foreach ($listofdata as $key => $val) {
  556. $productstatic->fetch($val['id_product']);
  557. $warehousestatics->id = 0;
  558. $warehousestatict->id = 0;
  559. if ($val['id_sw'] > 0) {
  560. $warehousestatics->fetch($val['id_sw']);
  561. }
  562. if ($val['id_tw'] > 0) {
  563. $warehousestatict->fetch($val['id_tw']);
  564. }
  565. if ($productstatic->id <= 0) {
  566. $error++;
  567. setEventMessages($langs->trans("ObjectNotFound", $langs->transnoentitiesnoconv("Product")), null, 'errors');
  568. }
  569. if ($warehousestatics->id < 0) { // We accept 0 for source warehouse id
  570. $error++;
  571. setEventMessages($langs->trans("ObjectNotFound", $langs->transnoentitiesnoconv("WarehouseSource")), null, 'errors');
  572. }
  573. if ($warehousestatict->id <= 0) {
  574. $error++;
  575. setEventMessages($langs->trans("ObjectNotFound", $langs->transnoentitiesnoconv("WarehouseTarget")), null, 'errors');
  576. }
  577. if (!$error) {
  578. print '<tr class="oddeven">';
  579. print '<td>';
  580. if ($warehousestatics->id > 0) {
  581. print $warehousestatics->getNomUrl(1);
  582. } else {
  583. print '<span class="opacitymedium">';
  584. print $langs->trans("None");
  585. print '</span>';
  586. }
  587. print '</td>';
  588. print '<td>';
  589. print $warehousestatict->getNomUrl(1);
  590. print '</td>';
  591. print '<td>';
  592. print $productstatic->getNomUrl(1).' - '.dol_escape_htmltag($productstatic->label);
  593. print '</td>';
  594. if (isModEnabled('productbatch')) {
  595. print '<td>';
  596. print dol_escape_htmltag($val['batch']);
  597. print '</td>';
  598. }
  599. print '<td class="right">'.price2num((float) $val['qty'], 'MS').'</td>';
  600. print '<td class="right"><a href="'.$_SERVER["PHP_SELF"].'?action=delline&token='.newToken().'&idline='.$val['id'].'">'.img_delete($langs->trans("Remove")).'</a></td>';
  601. print '</tr>';
  602. }
  603. }
  604. print '</table>';
  605. print '</div>';
  606. print '</form>';
  607. print '<br>';
  608. // Form to validate all movements
  609. if (count($listofdata)) {
  610. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" name="formulaire2" class="formconsumeproduce">';
  611. print '<input type="hidden" name="token" value="'.newToken().'">';
  612. print '<input type="hidden" name="action" value="createmovements">';
  613. // Button to record mass movement
  614. $codemove = (GETPOSTISSET("codemove") ? GETPOST("codemove", 'alpha') : dol_print_date(dol_now(), '%Y%m%d%H%M%S'));
  615. $labelmovement = GETPOST("label") ? GETPOST('label') : $langs->trans("MassStockTransferShort").' '.dol_print_date($now, '%Y-%m-%d %H:%M');
  616. print '<div class="center">';
  617. print '<span class="fieldrequired">'.$langs->trans("InventoryCode").':</span> ';
  618. print '<input type="text" name="codemove" class="maxwidth300" value="'.dol_escape_htmltag($codemove).'"> &nbsp; ';
  619. print '<span class="clearbothonsmartphone"></span>';
  620. print $langs->trans("MovementLabel").': ';
  621. print '<input type="text" name="label" class="minwidth300" value="'.dol_escape_htmltag($labelmovement).'"><br>';
  622. print '<br>';
  623. print '<div class="center"><input type="submit" class="button" name="valid" value="'.dol_escape_htmltag($buttonrecord).'"></div>';
  624. print '<br>';
  625. print '</div>';
  626. print '</form>';
  627. }
  628. if ($action == 'delete') {
  629. print $form->formconfirm($_SERVER["PHP_SELF"].'?urlfile='.urlencode(GETPOST('urlfile')).'&step=3'.$param, $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', 0, 1);
  630. }
  631. // End of page
  632. llxFooter();
  633. $db->close();
  634. /**
  635. * Verify if $haystack startswith $needle
  636. *
  637. * @param string $haystack string to test
  638. * @param string $needle string to find
  639. * @return bool false if Ko true else
  640. */
  641. function startsWith($haystack, $needle)
  642. {
  643. $length = strlen($needle);
  644. return substr($haystack, 0, $length) === $needle;
  645. }
  646. /**
  647. * Fetch object with ref
  648. *
  649. * @param Object $static_object static object to fetch
  650. * @param string $tmp_ref ref of the object to fetch
  651. * @return int <0 if Ko or Id of object
  652. */
  653. function fetchref($static_object, $tmp_ref)
  654. {
  655. if (startsWith($tmp_ref, 'ref:')) {
  656. $tmp_ref = str_replace('ref:', '', $tmp_ref);
  657. }
  658. $static_object->fetch('', $tmp_ref);
  659. return $static_object->id;
  660. }