product.php 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350
  1. <?php
  2. /* Copyright (C) 2001-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2020 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
  5. * Copyright (C) 2005 Simon TOSSER <simon@kornog-computing.com>
  6. * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
  7. * Copyright (C) 2013 Cédric Salvador <csalvador.gpcsolutions.fr>
  8. * Copyright (C) 2013-2018 Juanjo Menent <jmenent@2byte.es>
  9. * Copyright (C) 2014-2015 Cédric Gross <c.gross@kreiz-it.fr>
  10. * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
  11. * Copyright (C) 2018-2019 Frédéric France <frederic.france@netlogic.fr>
  12. * Copyright (C) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation; either version 3 of the License, or
  17. * (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  26. */
  27. /**
  28. * \file htdocs/product/stock/product.php
  29. * \ingroup product stock
  30. * \brief Page to list detailed stock of a product
  31. */
  32. require '../../main.inc.php';
  33. require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php';
  34. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  35. require_once DOL_DOCUMENT_ROOT.'/product/stock/class/productlot.class.php';
  36. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
  37. require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
  38. require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
  39. require_once DOL_DOCUMENT_ROOT.'/product/stock/class/productstockentrepot.class.php';
  40. if (!empty($conf->productbatch->enabled)) {
  41. require_once DOL_DOCUMENT_ROOT.'/product/class/productbatch.class.php';
  42. }
  43. if (!empty($conf->project->enabled)) {
  44. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
  45. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  46. }
  47. if (!empty($conf->variants->enabled)) {
  48. require_once DOL_DOCUMENT_ROOT.'/variants/class/ProductAttribute.class.php';
  49. require_once DOL_DOCUMENT_ROOT.'/variants/class/ProductAttributeValue.class.php';
  50. require_once DOL_DOCUMENT_ROOT.'/variants/class/ProductCombination.class.php';
  51. require_once DOL_DOCUMENT_ROOT.'/variants/class/ProductCombination2ValuePair.class.php';
  52. }
  53. // Load translation files required by the page
  54. $langs->loadlangs(array('products', 'suppliers', 'orders', 'bills', 'stocks', 'sendings', 'margins'));
  55. if (!empty($conf->productbatch->enabled)) {
  56. $langs->load("productbatch");
  57. }
  58. $backtopage = GETPOST('backtopage', 'alpha');
  59. $action = GETPOST('action', 'aZ09');
  60. $cancel = GETPOST('cancel', 'alpha');
  61. $id = GETPOST('id', 'int');
  62. $ref = GETPOST('ref', 'alpha');
  63. $stocklimit = GETPOST('seuil_stock_alerte');
  64. $desiredstock = GETPOST('desiredstock');
  65. $cancel = GETPOST('cancel', 'alpha');
  66. $fieldid = isset($_GET["ref"]) ? 'ref' : 'rowid';
  67. $d_eatby = dol_mktime(0, 0, 0, GETPOST('eatbymonth', 'int'), GETPOST('eatbyday', 'int'), GETPOST('eatbyyear', 'int'));
  68. $d_sellby = dol_mktime(0, 0, 0, GETPOST('sellbymonth', 'int'), GETPOST('sellbyday', 'int'), GETPOST('sellbyyear', 'int'));
  69. $pdluoid = GETPOST('pdluoid', 'int');
  70. $batchnumber = GETPOST('batch_number', 'san_alpha');
  71. if (!empty($batchnumber)) {
  72. $batchnumber = trim($batchnumber);
  73. }
  74. $cost_price = GETPOST('cost_price', 'alpha');
  75. // Security check
  76. if ($user->socid) {
  77. $socid = $user->socid;
  78. }
  79. $object = new Product($db);
  80. $extrafields = new ExtraFields($db);
  81. // fetch optionals attributes and labels
  82. $extrafields->fetch_name_optionals_label($object->table_element);
  83. if ($id > 0 || !empty($ref)) {
  84. $result = $object->fetch($id, $ref);
  85. }
  86. if (empty($id) && !empty($object->id)) {
  87. $id = $object->id;
  88. }
  89. $modulepart = 'product';
  90. // Get object canvas (By default, this is not defined, so standard usage of dolibarr)
  91. $canvas = !empty($object->canvas) ? $object->canvas : GETPOST("canvas");
  92. $objcanvas = null;
  93. if (!empty($canvas)) {
  94. require_once DOL_DOCUMENT_ROOT.'/core/class/canvas.class.php';
  95. $objcanvas = new Canvas($db, $action);
  96. $objcanvas->getCanvas('stockproduct', 'card', $canvas);
  97. }
  98. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  99. $hookmanager->initHooks(array('stockproductcard', 'globalcard'));
  100. $error = 0;
  101. $usercanread = (($object->type == Product::TYPE_PRODUCT && $user->rights->produit->lire) || ($object->type == Product::TYPE_SERVICE && $user->rights->service->lire));
  102. $usercancreate = (($object->type == Product::TYPE_PRODUCT && $user->rights->produit->creer) || ($object->type == Product::TYPE_SERVICE && $user->rights->service->creer));
  103. if ($object->id > 0) {
  104. if ($object->type == $object::TYPE_PRODUCT) {
  105. restrictedArea($user, 'produit', $object->id, 'product&product', '', '');
  106. }
  107. if ($object->type == $object::TYPE_SERVICE) {
  108. restrictedArea($user, 'service', $object->id, 'product&product', '', '');
  109. }
  110. } else {
  111. restrictedArea($user, 'produit|service', $id, 'product&product', '', '', $fieldid);
  112. }
  113. /*
  114. * Actions
  115. */
  116. if ($cancel) {
  117. $action = '';
  118. }
  119. $parameters = array('id'=>$id, 'ref'=>$ref, 'objcanvas'=>$objcanvas);
  120. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  121. if ($reshook < 0) {
  122. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  123. }
  124. if ($action == 'setcost_price') {
  125. if ($id) {
  126. $result = $object->fetch($id);
  127. $object->cost_price = price2num($cost_price);
  128. $result = $object->update($object->id, $user);
  129. if ($result > 0) {
  130. setEventMessages($langs->trans("RecordSaved"), null, 'mesgs');
  131. $action = '';
  132. } else {
  133. $error++;
  134. setEventMessages($object->error, $object->errors, 'errors');
  135. }
  136. }
  137. }
  138. if ($action == 'addlimitstockwarehouse' && !empty($user->rights->produit->creer)) {
  139. $seuil_stock_alerte = GETPOST('seuil_stock_alerte');
  140. $desiredstock = GETPOST('desiredstock');
  141. $maj_ok = true;
  142. if ($seuil_stock_alerte == '') {
  143. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("StockLimit")), null, 'errors');
  144. $maj_ok = false;
  145. }
  146. if ($desiredstock == '') {
  147. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DesiredStock")), null, 'errors');
  148. $maj_ok = false;
  149. }
  150. if ($maj_ok) {
  151. $pse = new ProductStockEntrepot($db);
  152. if ($pse->fetch(0, $id, GETPOST('fk_entrepot', 'int')) > 0) {
  153. // Update
  154. $pse->seuil_stock_alerte = $seuil_stock_alerte;
  155. $pse->desiredstock = $desiredstock;
  156. if ($pse->update($user) > 0) {
  157. setEventMessages($langs->trans('ProductStockWarehouseUpdated'), null, 'mesgs');
  158. }
  159. } else {
  160. // Create
  161. $pse->fk_entrepot = GETPOST('fk_entrepot', 'int');
  162. $pse->fk_product = $id;
  163. $pse->seuil_stock_alerte = GETPOST('seuil_stock_alerte');
  164. $pse->desiredstock = GETPOST('desiredstock');
  165. if ($pse->create($user) > 0) {
  166. setEventMessages($langs->trans('ProductStockWarehouseCreated'), null, 'mesgs');
  167. }
  168. }
  169. }
  170. header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
  171. exit;
  172. }
  173. if ($action == 'delete_productstockwarehouse' && !empty($user->rights->produit->creer)) {
  174. $pse = new ProductStockEntrepot($db);
  175. $pse->fetch(GETPOST('fk_productstockwarehouse', 'int'));
  176. if ($pse->delete($user) > 0) {
  177. setEventMessages($langs->trans('ProductStockWarehouseDeleted'), null, 'mesgs');
  178. }
  179. $action = '';
  180. }
  181. // Set stock limit
  182. if ($action == 'setseuil_stock_alerte' && !empty($user->rights->produit->creer)) {
  183. $object = new Product($db);
  184. $result = $object->fetch($id);
  185. $object->seuil_stock_alerte = $stocklimit;
  186. $result = $object->update($object->id, $user, 0, 'update');
  187. if ($result < 0) {
  188. setEventMessages($object->error, $object->errors, 'errors');
  189. }
  190. //else
  191. // setEventMessages($lans->trans("SavedRecordSuccessfully"), null, 'mesgs');
  192. $action = '';
  193. }
  194. // Set desired stock
  195. if ($action == 'setdesiredstock' && !empty($user->rights->produit->creer)) {
  196. $object = new Product($db);
  197. $result = $object->fetch($id);
  198. $object->desiredstock = $desiredstock;
  199. $result = $object->update($object->id, $user, 0, 'update');
  200. if ($result < 0) {
  201. setEventMessages($object->error, $object->errors, 'errors');
  202. }
  203. $action = '';
  204. }
  205. // Correct stock
  206. if ($action == "correct_stock" && !$cancel) {
  207. if (!(GETPOST("id_entrepot", 'int') > 0)) {
  208. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Warehouse")), null, 'errors');
  209. $error++;
  210. $action = 'correction';
  211. }
  212. if (!GETPOST("nbpiece")) {
  213. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("NumberOfUnit")), null, 'errors');
  214. $error++;
  215. $action = 'correction';
  216. }
  217. if (!empty($conf->productbatch->enabled)) {
  218. $object = new Product($db);
  219. $result = $object->fetch($id);
  220. if ($object->hasbatch() && !$batchnumber) {
  221. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("batch_number")), null, 'errors');
  222. $error++;
  223. $action = 'correction';
  224. }
  225. }
  226. if (!$error) {
  227. $priceunit = price2num(GETPOST("unitprice"));
  228. $nbpiece = price2num(GETPOST("nbpiece", 'alphanohtml'));
  229. if (is_numeric($nbpiece) && $nbpiece != 0 && $id) {
  230. $origin_element = '';
  231. $origin_id = null;
  232. if (GETPOST('projectid', 'int')) {
  233. $origin_element = 'project';
  234. $origin_id = GETPOST('projectid', 'int');
  235. }
  236. if (empty($object)) {
  237. $object = new Product($db);
  238. $result = $object->fetch($id);
  239. }
  240. $disablestockchangeforsubproduct = 0;
  241. if (GETPOST('disablesubproductstockchange')) {
  242. $disablestockchangeforsubproduct = 1;
  243. }
  244. if ($object->hasbatch()) {
  245. $result = $object->correct_stock_batch(
  246. $user,
  247. GETPOST("id_entrepot", 'int'),
  248. $nbpiece,
  249. GETPOST("mouvement", 'int'),
  250. GETPOST("label", 'alphanohtml'), // label movement
  251. $priceunit,
  252. $d_eatby,
  253. $d_sellby,
  254. $batchnumber,
  255. GETPOST('inventorycode', 'alphanohtml'),
  256. $origin_element,
  257. $origin_id,
  258. $disablestockchangeforsubproduct
  259. ); // We do not change value of stock for a correction
  260. } else {
  261. $result = $object->correct_stock(
  262. $user,
  263. GETPOST("id_entrepot", 'int'),
  264. $nbpiece,
  265. GETPOST("mouvement", 'int'),
  266. GETPOST("label", 'alphanohtml'),
  267. $priceunit,
  268. GETPOST('inventorycode', 'alphanohtml'),
  269. $origin_element,
  270. $origin_id,
  271. $disablestockchangeforsubproduct
  272. ); // We do not change value of stock for a correction
  273. }
  274. if ($result > 0) {
  275. if ($backtopage) {
  276. header("Location: ".$backtopage);
  277. exit;
  278. } else {
  279. header("Location: ".$_SERVER["PHP_SELF"]."?id=".$object->id);
  280. exit;
  281. }
  282. } else {
  283. setEventMessages($object->error, $object->errors, 'errors');
  284. $action = 'correction';
  285. }
  286. }
  287. }
  288. }
  289. // Transfer stock from a warehouse to another warehouse
  290. if ($action == "transfert_stock" && !$cancel) {
  291. if (!(GETPOST("id_entrepot", 'int') > 0) || !(GETPOST("id_entrepot_destination", 'int') > 0)) {
  292. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Warehouse")), null, 'errors');
  293. $error++;
  294. $action = 'transfert';
  295. }
  296. if (!GETPOST("nbpiece", 'int')) {
  297. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("NumberOfUnit")), null, 'errors');
  298. $error++;
  299. $action = 'transfert';
  300. }
  301. if (GETPOST("id_entrepot", 'int') == GETPOST("id_entrepot_destination", 'int')) {
  302. setEventMessages($langs->trans("ErrorSrcAndTargetWarehouseMustDiffers"), null, 'errors');
  303. $error++;
  304. $action = 'transfert';
  305. }
  306. if (!empty($conf->productbatch->enabled)) {
  307. $object = new Product($db);
  308. $result = $object->fetch($id);
  309. if ($object->hasbatch() && !$batchnumber) {
  310. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("batch_number")), null, 'errors');
  311. $error++;
  312. $action = 'transfert';
  313. }
  314. }
  315. if (!$error) {
  316. if ($id) {
  317. $object = new Product($db);
  318. $result = $object->fetch($id);
  319. $db->begin();
  320. $object->load_stock('novirtual'); // Load array product->stock_warehouse
  321. // Define value of products moved
  322. $pricesrc = 0;
  323. if (isset($object->pmp)) {
  324. $pricesrc = $object->pmp;
  325. }
  326. $pricedest = $pricesrc;
  327. $nbpiece = price2num(GETPOST("nbpiece", 'alphanohtml'));
  328. if ($object->hasbatch()) {
  329. $pdluo = new Productbatch($db);
  330. if ($pdluoid > 0) {
  331. $result = $pdluo->fetch($pdluoid);
  332. if ($result) {
  333. $srcwarehouseid = $pdluo->warehouseid;
  334. $batch = $pdluo->batch;
  335. $eatby = $pdluo->eatby;
  336. $sellby = $pdluo->sellby;
  337. } else {
  338. setEventMessages($pdluo->error, $pdluo->errors, 'errors');
  339. $error++;
  340. }
  341. } else {
  342. $srcwarehouseid = GETPOST('id_entrepot', 'int');
  343. $batch = $batchnumber;
  344. $eatby = $d_eatby;
  345. $sellby = $d_sellby;
  346. }
  347. $nbpiece = price2num(GETPOST("nbpiece", 'alphanohtml'));
  348. if (!$error) {
  349. // Remove stock
  350. $result1 = $object->correct_stock_batch(
  351. $user,
  352. $srcwarehouseid,
  353. $nbpiece,
  354. 1,
  355. GETPOST("label", 'alphanohtml'),
  356. $pricesrc,
  357. $eatby,
  358. $sellby,
  359. $batch,
  360. GETPOST('inventorycode', 'alphanohtml')
  361. );
  362. if ($result1 < 0) {
  363. $error++;
  364. }
  365. }
  366. if (!$error) {
  367. // Add stock
  368. $result2 = $object->correct_stock_batch(
  369. $user,
  370. GETPOST("id_entrepot_destination", 'int'),
  371. $nbpiece,
  372. 0,
  373. GETPOST("label", 'alphanohtml'),
  374. $pricedest,
  375. $eatby,
  376. $sellby,
  377. $batch,
  378. GETPOST('inventorycode', 'alphanohtml')
  379. );
  380. if ($result2 < 0) {
  381. $error++;
  382. }
  383. }
  384. } else {
  385. if (!$error) {
  386. // Remove stock
  387. $result1 = $object->correct_stock(
  388. $user,
  389. GETPOST("id_entrepot", 'int'),
  390. $nbpiece,
  391. 1,
  392. GETPOST("label", 'alphanohtml'),
  393. $pricesrc,
  394. GETPOST('inventorycode', 'alphanohtml')
  395. );
  396. if ($result1 < 0) {
  397. $error++;
  398. }
  399. }
  400. if (!$error) {
  401. // Add stock
  402. $result2 = $object->correct_stock(
  403. $user,
  404. GETPOST("id_entrepot_destination", 'int'),
  405. $nbpiece,
  406. 0,
  407. GETPOST("label", 'alphanohtml'),
  408. $pricedest,
  409. GETPOST('inventorycode', 'alphanohtml')
  410. );
  411. if ($result2 < 0) {
  412. $error++;
  413. }
  414. }
  415. }
  416. if (!$error && $result1 >= 0 && $result2 >= 0) {
  417. $db->commit();
  418. if ($backtopage) {
  419. header("Location: ".$backtopage);
  420. exit;
  421. } else {
  422. header("Location: product.php?id=".$object->id);
  423. exit;
  424. }
  425. } else {
  426. setEventMessages($object->error, $object->errors, 'errors');
  427. $db->rollback();
  428. $action = 'transfert';
  429. }
  430. }
  431. }
  432. }
  433. // Update batch information
  434. if ($action == 'updateline' && GETPOST('save') == $langs->trans("Save")) {
  435. $pdluo = new Productbatch($db);
  436. $result = $pdluo->fetch(GETPOST('pdluoid', 'int'));
  437. if ($result > 0) {
  438. if ($pdluo->id) {
  439. if ((!GETPOST("sellby")) && (!GETPOST("eatby")) && (!$batchnumber)) {
  440. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("atleast1batchfield")), null, 'errors');
  441. } else {
  442. $d_eatby = dol_mktime(0, 0, 0, GETPOST('eatbymonth', 'int'), GETPOST('eatbyday', 'int'), GETPOST('eatbyyear', 'int'));
  443. $d_sellby = dol_mktime(0, 0, 0, GETPOST('sellbymonth', 'int'), GETPOST('sellbyday', 'int'), GETPOST('sellbyyear', 'int'));
  444. $pdluo->batch = $batchnumber;
  445. $pdluo->eatby = $d_eatby;
  446. $pdluo->sellby = $d_sellby;
  447. $result = $pdluo->update($user);
  448. if ($result < 0) {
  449. setEventMessages($pdluo->error, $pdluo->errors, 'errors');
  450. }
  451. }
  452. } else {
  453. setEventMessages($langs->trans('BatchInformationNotfound'), null, 'errors');
  454. }
  455. } else {
  456. setEventMessages($pdluo->error, null, 'errors');
  457. }
  458. header("Location: product.php?id=".$id);
  459. exit;
  460. }
  461. /*
  462. * View
  463. */
  464. $form = new Form($db);
  465. $formproduct = new FormProduct($db);
  466. if (!empty($conf->project->enabled)) {
  467. $formproject = new FormProjets($db);
  468. }
  469. if ($id > 0 || $ref) {
  470. $object = new Product($db);
  471. $result = $object->fetch($id, $ref);
  472. $variants = $object->hasVariants();
  473. $object->load_stock();
  474. $title = $langs->trans('ProductServiceCard');
  475. $helpurl = '';
  476. $shortlabel = dol_trunc($object->label, 16);
  477. if (GETPOST("type") == '0' || ($object->type == Product::TYPE_PRODUCT)) {
  478. $title = $langs->trans('Product')." ".$shortlabel." - ".$langs->trans('Stock');
  479. $helpurl = 'EN:Module_Products|FR:Module_Produits|ES:M&oacute;dulo_Productos';
  480. }
  481. if (GETPOST("type") == '1' || ($object->type == Product::TYPE_SERVICE)) {
  482. $title = $langs->trans('Service')." ".$shortlabel." - ".$langs->trans('Stock');
  483. $helpurl = 'EN:Module_Services_En|FR:Module_Services|ES:M&oacute;dulo_Servicios';
  484. }
  485. llxHeader('', $title, $helpurl);
  486. if (!empty($conf->use_javascript_ajax)) {
  487. ?>
  488. <script type="text/javascript">
  489. $(document).ready(function() {
  490. $(".collapse_batch").click(function() {
  491. console.log("We click on collapse_batch");
  492. var id_entrepot = $(this).attr('id').replace('ent', '');
  493. if($(this).text().indexOf('+') > 0) {
  494. $(".batch_warehouse" + id_entrepot).show();
  495. $(this).html('(-)');
  496. jQuery("#show_all").hide();
  497. jQuery("#hide_all").show();
  498. }
  499. else {
  500. $(".batch_warehouse" + id_entrepot).hide();
  501. $(this).html('(+)');
  502. }
  503. return false;
  504. });
  505. $("#show_all").click(function() {
  506. console.log("We click on show_all");
  507. $("[class^=batch_warehouse]").show();
  508. $("[class^=collapse_batch]").html('(-)');
  509. jQuery("#show_all").hide();
  510. jQuery("#hide_all").show();
  511. return false;
  512. });
  513. $("#hide_all").click(function() {
  514. console.log("We click on hide_all");
  515. $("[class^=batch_warehouse]").hide();
  516. $("[class^=collapse_batch]").html('(+)');
  517. jQuery("#hide_all").hide();
  518. jQuery("#show_all").show();
  519. return false;
  520. });
  521. });
  522. </script>
  523. <?php
  524. }
  525. if ($result > 0) {
  526. $head = product_prepare_head($object);
  527. $titre = $langs->trans("CardProduct".$object->type);
  528. $picto = ($object->type == Product::TYPE_SERVICE ? 'service' : 'product');
  529. print dol_get_fiche_head($head, 'stock', $titre, -1, $picto);
  530. dol_htmloutput_events();
  531. $linkback = '<a href="'.DOL_URL_ROOT.'/product/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  532. $shownav = 1;
  533. if ($user->socid && !in_array('stock', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) {
  534. $shownav = 0;
  535. }
  536. dol_banner_tab($object, 'ref', $linkback, $shownav, 'ref');
  537. if (!$variants) {
  538. print '<div class="fichecenter">';
  539. print '<div class="fichehalfleft">';
  540. print '<div class="underbanner clearboth"></div>';
  541. print '<table class="border tableforfield centpercent">';
  542. // Type
  543. if (!empty($conf->product->enabled) && !empty($conf->service->enabled)) {
  544. $typeformat = 'select;0:'.$langs->trans("Product").',1:'.$langs->trans("Service");
  545. print '<tr><td class="">';
  546. print (empty($conf->global->PRODUCT_DENY_CHANGE_PRODUCT_TYPE)) ? $form->editfieldkey("Type", 'fk_product_type', $object->type, $object, 0, $typeformat) : $langs->trans('Type');
  547. print '</td><td>';
  548. print $form->editfieldval("Type", 'fk_product_type', $object->type, $object, 0, $typeformat);
  549. print '</td></tr>';
  550. }
  551. if (isModEnabled('productbatch')) {
  552. print '<tr><td class="">'.$langs->trans("ManageLotSerial").'</td><td>';
  553. print $object->getLibStatut(0, 2);
  554. print '</td></tr>';
  555. }
  556. // Cost price. Can be used for margin module for option "calculate margin on explicit cost price
  557. print '<tr><td>';
  558. $textdesc = $langs->trans("CostPriceDescription");
  559. $textdesc .= "<br>".$langs->trans("CostPriceUsage");
  560. $text = $form->textwithpicto($langs->trans("CostPrice"), $textdesc, 1, 'help', '');
  561. print $form->editfieldkey($text, 'cost_price', $object->cost_price, $object, $usercancreate, 'amount:6');
  562. print '</td><td>';
  563. print $form->editfieldval($text, 'cost_price', $object->cost_price, $object, $usercancreate, 'amount:6');
  564. print '</td></tr>';
  565. // AWP
  566. print '<tr><td class="titlefield">';
  567. print $form->textwithpicto($langs->trans("AverageUnitPricePMPShort"), $langs->trans("AverageUnitPricePMPDesc"));
  568. print '</td>';
  569. print '<td>';
  570. if ($object->pmp > 0) {
  571. print price($object->pmp).' '.$langs->trans("HT");
  572. }
  573. print '</td>';
  574. print '</tr>';
  575. // Minimum Price
  576. print '<tr><td>'.$langs->trans("BuyingPriceMin").'</td>';
  577. print '<td>';
  578. $product_fourn = new ProductFournisseur($db);
  579. if ($product_fourn->find_min_price_product_fournisseur($object->id) > 0) {
  580. if ($product_fourn->product_fourn_price_id > 0) {
  581. print $product_fourn->display_price_product_fournisseur();
  582. } else {
  583. print $langs->trans("NotDefined");
  584. }
  585. }
  586. print '</td></tr>';
  587. if (empty($conf->global->PRODUIT_MULTIPRICES)) {
  588. // Price
  589. print '<tr><td>'.$langs->trans("SellingPrice").'</td><td>';
  590. if ($object->price_base_type == 'TTC') {
  591. print price($object->price_ttc).' '.$langs->trans($object->price_base_type);
  592. } else {
  593. print price($object->price).' '.$langs->trans($object->price_base_type);
  594. }
  595. print '</td></tr>';
  596. // Price minimum
  597. print '<tr><td>'.$langs->trans("MinPrice").'</td><td>';
  598. if ($object->price_base_type == 'TTC') {
  599. print price($object->price_min_ttc).' '.$langs->trans($object->price_base_type);
  600. } else {
  601. print price($object->price_min).' '.$langs->trans($object->price_base_type);
  602. }
  603. print '</td></tr>';
  604. } else {
  605. // Price
  606. print '<tr><td>'.$langs->trans("SellingPrice").'</td><td>';
  607. print '<span class="opacitymedium">'.$langs->trans("Variable").'</span>';
  608. print '</td></tr>';
  609. // Price minimum
  610. print '<tr><td>'.$langs->trans("MinPrice").'</td><td>';
  611. print '<span class="opacitymedium">'.$langs->trans("Variable").'</span>';
  612. print '</td></tr>';
  613. }
  614. // Hook formObject
  615. $parameters = array();
  616. $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  617. print $hookmanager->resPrint;
  618. print '</table>';
  619. print '</div>';
  620. print '<div class="fichehalfright"><div class="underbanner clearboth"></div>';
  621. print '<table class="border tableforfield centpercent">';
  622. // Stock alert threshold
  623. print '<tr><td>'.$form->editfieldkey($form->textwithpicto($langs->trans("StockLimit"), $langs->trans("StockLimitDesc"), 1), 'seuil_stock_alerte', $object->seuil_stock_alerte, $object, $user->rights->produit->creer).'</td><td>';
  624. print $form->editfieldval("StockLimit", 'seuil_stock_alerte', $object->seuil_stock_alerte, $object, $user->rights->produit->creer, 'string');
  625. print '</td></tr>';
  626. // Desired stock
  627. print '<tr><td>'.$form->editfieldkey($form->textwithpicto($langs->trans("DesiredStock"), $langs->trans("DesiredStockDesc"), 1), 'desiredstock', $object->desiredstock, $object, $user->rights->produit->creer);
  628. print '</td><td>';
  629. print $form->editfieldval("DesiredStock", 'desiredstock', $object->desiredstock, $object, $user->rights->produit->creer, 'string');
  630. print '</td></tr>';
  631. // Real stock
  632. $text_stock_options = $langs->trans("RealStockDesc").'<br>';
  633. $text_stock_options .= $langs->trans("RealStockWillAutomaticallyWhen").'<br>';
  634. $text_stock_options .= (!empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT) || !empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE) ? '- '.$langs->trans("DeStockOnShipment").'<br>' : '');
  635. $text_stock_options .= (!empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) ? '- '.$langs->trans("DeStockOnValidateOrder").'<br>' : '');
  636. $text_stock_options .= (!empty($conf->global->STOCK_CALCULATE_ON_BILL) ? '- '.$langs->trans("DeStockOnBill").'<br>' : '');
  637. $text_stock_options .= (!empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL) ? '- '.$langs->trans("ReStockOnBill").'<br>' : '');
  638. $text_stock_options .= (!empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER) ? '- '.$langs->trans("ReStockOnValidateOrder").'<br>' : '');
  639. $text_stock_options .= (!empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER) ? '- '.$langs->trans("ReStockOnDispatchOrder").'<br>' : '');
  640. $text_stock_options .= (!empty($conf->global->STOCK_CALCULATE_ON_RECEPTION) || !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE) ? '- '.$langs->trans("StockOnReception").'<br>' : '');
  641. print '<tr><td>';
  642. print $form->textwithpicto($langs->trans("PhysicalStock"), $text_stock_options, 1);
  643. print '</td>';
  644. print '<td>'.price2num($object->stock_reel, 'MS');
  645. if ($object->seuil_stock_alerte != '' && ($object->stock_reel < $object->seuil_stock_alerte)) {
  646. print ' '.img_warning($langs->trans("StockLowerThanLimit", $object->seuil_stock_alerte));
  647. }
  648. print ' &nbsp; &nbsp;<a href="'.DOL_URL_ROOT.'/product/stock/stockatdate.php?productid='.$object->id.'">'.$langs->trans("StockAtDate").'</a>';
  649. print '</td>';
  650. print '</tr>';
  651. $stocktheo = price2num($object->stock_theorique, 'MS');
  652. $found = 0;
  653. $helpondiff = '<strong>'.$langs->trans("StockDiffPhysicTeoric").':</strong><br>';
  654. // Number of customer orders running
  655. if (!empty($conf->commande->enabled)) {
  656. if ($found) {
  657. $helpondiff .= '<br>';
  658. } else {
  659. $found = 1;
  660. }
  661. $helpondiff .= $langs->trans("ProductQtyInCustomersOrdersRunning").': '.$object->stats_commande['qty'];
  662. $result = $object->load_stats_commande(0, '0', 1);
  663. if ($result < 0) {
  664. dol_print_error($db, $object->error);
  665. }
  666. $helpondiff .= ' <span class="opacitymedium">('.$langs->trans("ProductQtyInDraft").': '.$object->stats_commande['qty'].')</span>';
  667. }
  668. // Number of product from customer order already sent (partial shipping)
  669. if (!empty($conf->expedition->enabled)) {
  670. require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
  671. $filterShipmentStatus = '';
  672. if (!empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT)) {
  673. $filterShipmentStatus = Expedition::STATUS_VALIDATED.','.Expedition::STATUS_CLOSED;
  674. } elseif (!empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE)) {
  675. $filterShipmentStatus = Expedition::STATUS_CLOSED;
  676. }
  677. if ($found) {
  678. $helpondiff .= '<br>';
  679. } else {
  680. $found = 1;
  681. }
  682. $result = $object->load_stats_sending(0, '2', 1, $filterShipmentStatus);
  683. $helpondiff .= $langs->trans("ProductQtyInShipmentAlreadySent").': '.$object->stats_expedition['qty'];
  684. }
  685. // Number of supplier order running
  686. if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled)) {
  687. if ($found) {
  688. $helpondiff .= '<br>';
  689. } else {
  690. $found = 1;
  691. }
  692. $result = $object->load_stats_commande_fournisseur(0, '3,4', 1);
  693. $helpondiff .= $langs->trans("ProductQtyInSuppliersOrdersRunning").': '.$object->stats_commande_fournisseur['qty'];
  694. $result = $object->load_stats_commande_fournisseur(0, '0,1,2', 1);
  695. if ($result < 0) {
  696. dol_print_error($db, $object->error);
  697. }
  698. $helpondiff .= ' <span class="opacitymedium">('.$langs->trans("ProductQtyInDraftOrWaitingApproved").': '.$object->stats_commande_fournisseur['qty'].')</span>';
  699. }
  700. // Number of product from supplier order already received (partial receipt)
  701. if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled)) {
  702. if ($found) {
  703. $helpondiff .= '<br>';
  704. } else {
  705. $found = 1;
  706. }
  707. $helpondiff .= $langs->trans("ProductQtyInSuppliersShipmentAlreadyRecevied").': '.$object->stats_reception['qty'];
  708. }
  709. // Number of product in production
  710. if (!empty($conf->mrp->enabled)) {
  711. if ($found) {
  712. $helpondiff .= '<br>';
  713. } else {
  714. $found = 1;
  715. }
  716. $helpondiff .= $langs->trans("ProductQtyToConsumeByMO").': '.$object->stats_mrptoconsume['qty'].'<br>';
  717. $helpondiff .= $langs->trans("ProductQtyToProduceByMO").': '.$object->stats_mrptoproduce['qty'];
  718. }
  719. // Calculating a theorical value
  720. print '<tr><td>';
  721. print $form->textwithpicto($langs->trans("VirtualStock"), $langs->trans("VirtualStockDesc"));
  722. print '</td>';
  723. print "<td>";
  724. //print (empty($stocktheo)?0:$stocktheo);
  725. print $form->textwithpicto((empty($stocktheo) ? 0 : $stocktheo), $helpondiff);
  726. if ($object->seuil_stock_alerte != '' && ($object->stock_theorique < $object->seuil_stock_alerte)) {
  727. print ' '.img_warning($langs->trans("StockLowerThanLimit", $object->seuil_stock_alerte));
  728. }
  729. print ' &nbsp; &nbsp;<a href="'.DOL_URL_ROOT.'/product/stock/stockatdate.php?mode=future&productid='.$object->id.'">'.$langs->trans("VirtualStockAtDate").'</a>';
  730. print '</td>';
  731. print '</tr>';
  732. // Last movement
  733. if (!empty($user->rights->stock->mouvement->lire)) {
  734. $sql = "SELECT max(m.datem) as datem";
  735. $sql .= " FROM ".MAIN_DB_PREFIX."stock_mouvement as m";
  736. $sql .= " WHERE m.fk_product = ".((int) $object->id);
  737. $resqlbis = $db->query($sql);
  738. if ($resqlbis) {
  739. $obj = $db->fetch_object($resqlbis);
  740. $lastmovementdate = $db->jdate($obj->datem);
  741. } else {
  742. dol_print_error($db);
  743. }
  744. print '<tr><td class="tdtop">'.$langs->trans("LastMovement").'</td><td>';
  745. if ($lastmovementdate) {
  746. print dol_print_date($lastmovementdate, 'dayhour').' ';
  747. print ' &nbsp; &nbsp; ';
  748. print img_picto($langs->trans("StockMovement"), 'movement', 'class="pictofixedwidth"');
  749. print '<a href="'.DOL_URL_ROOT.'/product/stock/movement_list.php?idproduct='.$object->id.'">'.$langs->trans("FullList").'</a>';
  750. } else {
  751. print img_picto($langs->trans("StockMovement"), 'movement', 'class="pictofixedwidth"');
  752. print '<a href="'.DOL_URL_ROOT.'/product/stock/movement_list.php?idproduct='.$object->id.'">'.$langs->trans("None").'</a>';
  753. }
  754. print "</td></tr>";
  755. }
  756. print "</table>";
  757. print '</div>';
  758. print '</div>';
  759. print '<div style="clear:both"></div>';
  760. }
  761. print dol_get_fiche_end();
  762. }
  763. // Correct stock
  764. if ($action == "correction") {
  765. include DOL_DOCUMENT_ROOT.'/product/stock/tpl/stockcorrection.tpl.php';
  766. print '<br><br>';
  767. }
  768. // Transfer of units
  769. if ($action == "transfert") {
  770. include DOL_DOCUMENT_ROOT.'/product/stock/tpl/stocktransfer.tpl.php';
  771. print '<br><br>';
  772. }
  773. } else {
  774. dol_print_error();
  775. }
  776. // Actions buttons
  777. $parameters = array();
  778. $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  779. if (empty($reshook)) {
  780. if (empty($action) && $object->id) {
  781. print "<div class=\"tabsAction\">\n";
  782. if ($user->rights->stock->mouvement->creer) {
  783. if (!$variants || !empty($conf->global->VARIANT_ALLOW_STOCK_MOVEMENT_ON_VARIANT_PARENT)) {
  784. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=transfert">'.$langs->trans("TransferStock").'</a>';
  785. } else {
  786. print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("ActionAvailableOnVariantProductOnly").'">'.$langs->trans("TransferStock").'</a>';
  787. }
  788. } else {
  789. print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotEnoughPermissions").'">'.$langs->trans("CorrectStock").'</a>';
  790. }
  791. if ($user->rights->stock->mouvement->creer) {
  792. if (!$variants || !empty($conf->global->VARIANT_ALLOW_STOCK_MOVEMENT_ON_VARIANT_PARENT)) {
  793. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=correction">'.$langs->trans("CorrectStock").'</a>';
  794. } else {
  795. print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("ActionAvailableOnVariantProductOnly").'">'.$langs->trans("CorrectStock").'</a>';
  796. }
  797. } else {
  798. print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotEnoughPermissions").'">'.$langs->trans("CorrectStock").'</a>';
  799. }
  800. print '</div>';
  801. }
  802. }
  803. if (!$variants) {
  804. /*
  805. * Stock detail (by warehouse). May go down into batch details.
  806. */
  807. print '<div class="div-table-responsive">';
  808. print '<table class="noborder centpercent">';
  809. print '<tr class="liste_titre">';
  810. print '<td colspan="4">'.$langs->trans("Warehouse").'</td>';
  811. print '<td class="right">'.$langs->trans("NumberOfUnit").'</td>';
  812. print '<td class="right">'.$form->textwithpicto($langs->trans("AverageUnitPricePMPShort"), $langs->trans("AverageUnitPricePMPDesc")).'</td>';
  813. print '<td class="right">'.$langs->trans("EstimatedStockValueShort").'</td>';
  814. print '<td class="right">'.$langs->trans("SellPriceMin").'</td>';
  815. print '<td class="right">'.$langs->trans("EstimatedStockValueSellShort").'</td>';
  816. print '<td></td>';
  817. print '<td></td>';
  818. print '</tr>';
  819. if ((!empty($conf->productbatch->enabled)) && $object->hasbatch()) {
  820. $colspan = 3;
  821. print '<tr class="liste_titre"><td class="minwidth200">';
  822. if (!empty($conf->use_javascript_ajax)) {
  823. print '<a id="show_all" href="#" class="hideobject">'.img_picto('', 'folder-open', 'class="paddingright"').$langs->trans("ShowAllLots").'</a>';
  824. //print ' &nbsp; ';
  825. print '<a id="hide_all" href="#">'.img_picto('', 'folder', 'class="paddingright"').$langs->trans("HideLots").'</a>';
  826. //print '&nbsp;'.$form->textwithpicto('', $langs->trans('CollapseBatchDetailHelp'), 1, 'help', '');
  827. }
  828. print '</td>';
  829. print '<td class="right">'.$langs->trans("batch_number").'</td>';
  830. if (empty($conf->global->PRODUCT_DISABLE_SELLBY)) {
  831. $colspan--;
  832. print '<td class="center width100">'.$langs->trans("SellByDate").'</td>';
  833. }
  834. if (empty($conf->global->PRODUCT_DISABLE_EATBY)) {
  835. $colspan--;
  836. print '<td class="center width100">'.$langs->trans("EatByDate").'</td>';
  837. }
  838. print '<td colspan="'.$colspan.'"></td>';
  839. print '<td></td>';
  840. print '<td></td>';
  841. print '<td></td>';
  842. print '<td></td>';
  843. print '<td></td>';
  844. print '<td></td>';
  845. print '</tr>';
  846. }
  847. $sql = "SELECT e.rowid, e.ref, e.lieu, e.fk_parent, e.statut as status, ps.reel, ps.rowid as product_stock_id, p.pmp";
  848. $sql .= " FROM ".MAIN_DB_PREFIX."entrepot as e,";
  849. $sql .= " ".MAIN_DB_PREFIX."product_stock as ps";
  850. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = ps.fk_product";
  851. // Added by MMI Mathieu Moulin iProspective
  852. if (!empty($conf->global->MMI_STOCK_SHOW_EVEN_IF_EMPTY))
  853. $sql .= " WHERE 1";
  854. else
  855. $sql .= " WHERE ps.reel != 0";
  856. $sql .= " AND ps.fk_entrepot = e.rowid";
  857. $sql .= " AND e.entity IN (".getEntity('stock').")";
  858. $sql .= " AND ps.fk_product = ".((int) $object->id);
  859. $sql .= " ORDER BY e.ref";
  860. $entrepotstatic = new Entrepot($db);
  861. $product_lot_static = new Productlot($db);
  862. $num = 0;
  863. $total = 0;
  864. $totalvalue = $totalvaluesell = 0;
  865. $totalwithpmp = 0;
  866. $resql = $db->query($sql);
  867. if ($resql) {
  868. $num = $db->num_rows($resql);
  869. $total = $totalwithpmp;
  870. $i = 0;
  871. $var = false;
  872. while ($i < $num) {
  873. $obj = $db->fetch_object($resql);
  874. $entrepotstatic->id = $obj->rowid;
  875. $entrepotstatic->ref = $obj->ref;
  876. $entrepotstatic->label = $obj->ref;
  877. $entrepotstatic->lieu = $obj->lieu;
  878. $entrepotstatic->fk_parent = $obj->fk_parent;
  879. $entrepotstatic->statut = $obj->status;
  880. $entrepotstatic->status = $obj->status;
  881. $stock_real = price2num($obj->reel, 'MS');
  882. print '<tr class="oddeven">';
  883. // Warehouse
  884. print '<td colspan="4">';
  885. print $entrepotstatic->getNomUrl(1);
  886. if (!empty($conf->use_javascript_ajax) && !empty($conf->productbatch->enabled) && $object->hasbatch()) {
  887. print '<a class="collapse_batch marginleftonly" id="ent' . $entrepotstatic->id . '" href="#">';
  888. print (empty($conf->global->STOCK_SHOW_ALL_BATCH_BY_DEFAULT) ? '(+)' : '(-)');
  889. print '</a>';
  890. }
  891. print '</td>';
  892. print '<td class="right">'.$stock_real.($stock_real < 0 ? ' '.img_warning() : '').'</td>';
  893. // PMP
  894. print '<td class="right nowraponall">'.(price2num($object->pmp) ? price2num($object->pmp, 'MU') : '').'</td>';
  895. // Value purchase
  896. print '<td class="right amount nowraponall">'.(price2num($object->pmp) ? price(price2num($object->pmp * $obj->reel, 'MT')) : '').'</td>';
  897. // Sell price
  898. $minsellprice = null; $maxsellprice = null;
  899. print '<td class="right">';
  900. if (!empty($conf->global->PRODUIT_MULTIPRICES)) {
  901. foreach ($object->multiprices as $priceforlevel) {
  902. if (is_numeric($priceforlevel)) {
  903. if (is_null($maxsellprice) || $priceforlevel > $maxsellprice) {
  904. $maxsellprice = $priceforlevel;
  905. }
  906. if (is_null($minsellprice) || $priceforlevel < $minsellprice) {
  907. $minsellprice = $priceforlevel;
  908. }
  909. }
  910. }
  911. print '<span class="valignmiddle">';
  912. if ($minsellprice != $maxsellprice) {
  913. print price(price2num($minsellprice, 'MU'), 1).' - '.price(price2num($maxsellprice, 'MU'), 1);
  914. } else {
  915. print price(price2num($minsellprice, 'MU'), 1);
  916. }
  917. print '</span>';
  918. print $form->textwithpicto('', $langs->trans("Variable"));
  919. } else {
  920. print price(price2num($object->price, 'MU'), 1);
  921. }
  922. print '</td>';
  923. // Value sell
  924. print '<td class="right amount nowraponall">';
  925. if (!empty($conf->global->PRODUIT_MULTIPRICES)) {
  926. print '<span class="valignmiddle">';
  927. if ($minsellprice != $maxsellprice) {
  928. print price(price2num($minsellprice * $obj->reel, 'MT'), 1).' - '.price(price2num($maxsellprice * $obj->reel, 'MT'), 1);
  929. } else {
  930. print price(price2num($minsellprice * $obj->reel, 'MT'), 1);
  931. }
  932. print '</span>';
  933. print $form->textwithpicto('', $langs->trans("Variable"));
  934. } else {
  935. print price(price2num($object->price * $obj->reel, 'MT'), 1);
  936. }
  937. print '</td>';
  938. print '<td></td>';
  939. print '<td></td>';
  940. print '</tr>';
  941. $total += $obj->reel;
  942. if (price2num($object->pmp)) {
  943. $totalwithpmp += $obj->reel;
  944. }
  945. $totalvalue = $totalvalue + ($object->pmp * $obj->reel);
  946. $totalvaluesell = $totalvaluesell + ($object->price * $obj->reel);
  947. // Batch Detail
  948. if ((!empty($conf->productbatch->enabled)) && $object->hasbatch()) {
  949. $details = Productbatch::findAll($db, $obj->product_stock_id, 0, $object->id);
  950. if ($details < 0) {
  951. dol_print_error($db);
  952. }
  953. foreach ($details as $pdluo) {
  954. $product_lot_static->id = $pdluo->lotid;
  955. $product_lot_static->batch = $pdluo->batch;
  956. $product_lot_static->eatby = $pdluo->eatby;
  957. $product_lot_static->sellby = $pdluo->sellby;
  958. if ($action == 'editline' && GETPOST('lineid', 'int') == $pdluo->id) { //Current line edit
  959. print "\n".'<tr>';
  960. print '<td colspan="9">';
  961. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  962. print '<input type="hidden" name="token" value="'.newToken().'">';
  963. print '<input type="hidden" name="pdluoid" value="'.$pdluo->id.'"><input type="hidden" name="action" value="updateline"><input type="hidden" name="id" value="'.$id.'"><table class="noborder centpercent"><tr><td width="10%"></td>';
  964. print '<td class="right" width="10%"><input type="text" name="batch_number" value="'.$pdluo->batch.'"></td>';
  965. if (empty($conf->global->PRODUCT_DISABLE_SELLBY)) {
  966. print '<td class="center" width="10%">';
  967. print $form->selectDate($pdluo->sellby, 'sellby', '', '', 1, '', 1, 0);
  968. print '</td>';
  969. }
  970. if (empty($conf->global->PRODUCT_DISABLE_EATBY)) {
  971. print '<td class="center" width="10%">';
  972. print $form->selectDate($pdluo->eatby, 'eatby', '', '', 1, '', 1, 0);
  973. print '</td>';
  974. }
  975. print '<td class="right" colspan="3">'.$pdluo->qty.($pdluo->qty < 0 ? ' '.img_warning() : '').'</td>';
  976. print '<td colspan="4"><input type="submit" class="button button-save" id="savelinebutton marginbottomonly" name="save" value="'.$langs->trans("Save").'">';
  977. print '<input type="submit" class="button button-cancel" id="cancellinebutton" name="Cancel" value="'.$langs->trans("Cancel").'"></td></tr>';
  978. print '</table>';
  979. print '</form>';
  980. print '</td>';
  981. print '<td></td>';
  982. print '<td></td>';
  983. print '</tr>';
  984. } else {
  985. print "\n".'<tr style="display:'.(empty($conf->global->STOCK_SHOW_ALL_BATCH_BY_DEFAULT) ? 'none' : 'visible').';" class="batch_warehouse'.$entrepotstatic->id.'"><td class="left">';
  986. print '</td>';
  987. print '<td class="right nowraponall">';
  988. print $product_lot_static->getNomUrl(1);
  989. print '</td>';
  990. $colspan = 3;
  991. if (empty($conf->global->PRODUCT_DISABLE_SELLBY)) {
  992. $colspan--;
  993. print '<td class="center">'.dol_print_date($pdluo->sellby, 'day').'</td>';
  994. }
  995. if (empty($conf->global->PRODUCT_DISABLE_EATBY)) {
  996. $colspan--;
  997. print '<td class="center">'.dol_print_date($pdluo->eatby, 'day').'</td>';
  998. }
  999. print '<td class="right" colspan="'.$colspan.'">'.$pdluo->qty.($pdluo->qty < 0 ? ' '.img_warning() : '').'</td>';
  1000. print '<td colspan="4"></td>';
  1001. print '<td class="center">';
  1002. if ($entrepotstatic->status != $entrepotstatic::STATUS_CLOSED) {
  1003. print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;id_entrepot='.$entrepotstatic->id.'&amp;action=transfert&amp;pdluoid='.$pdluo->id.'&amp;batch_number='.$pdluo->batch.'">';
  1004. print img_picto($langs->trans("TransferStock"), 'add', 'class="hideonsmartphone paddingright" style="color: #a69944"');
  1005. print $langs->trans("TransferStock");
  1006. print '</a>';
  1007. // Disabled, because edition of stock content must use the "Correct stock menu".
  1008. // Do not use this, or data will be wrong (bad tracking of movement label, inventory code, ...
  1009. //print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$id.'&action=editline&token='.newToken().'&lineid='.$pdluo->id.'#'.$pdluo->id.'">';
  1010. //print img_edit().'</a>';
  1011. }
  1012. print '</td>';
  1013. print '<td class="center">';
  1014. if ($entrepotstatic->status != $entrepotstatic::STATUS_CLOSED) {
  1015. print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;id_entrepot='.$entrepotstatic->id.'&amp;action=correction&amp;pdluoid='.$pdluo->id.'&amp;batch_number='.$pdluo->batch.'">';
  1016. print img_picto($langs->trans("CorrectStock"), 'add', 'class="hideonsmartphone paddingright" style="color: #a69944"');
  1017. print $langs->trans("CorrectStock");
  1018. print '</a>';
  1019. // Disabled, because edition of stock content must use the "Correct stock menu".
  1020. // Do not use this, or data will be wrong (bad tracking of movement label, inventory code, ...
  1021. //print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$id.'&action=editline&token='.newToken().'&lineid='.$pdluo->id.'#'.$pdluo->id.'">';
  1022. //print img_edit().'</a>';
  1023. }
  1024. print '</td>';
  1025. print '</tr>';
  1026. }
  1027. }
  1028. }
  1029. $i++;
  1030. }
  1031. } else {
  1032. dol_print_error($db);
  1033. }
  1034. // Total line
  1035. print '<tr class="liste_total"><td class="right liste_total" colspan="4">'.$langs->trans("Total").':</td>';
  1036. print '<td class="liste_total right">'.price2num($total, 'MS').'</td>';
  1037. print '<td class="liste_total right">';
  1038. print ($totalwithpmp ? price(price2num($totalvalue / $totalwithpmp, 'MU')) : '&nbsp;'); // This value may have rounding errors
  1039. print '</td>';
  1040. // Value purchase
  1041. print '<td class="liste_total right">';
  1042. print $totalvalue ? price(price2num($totalvalue, 'MT'), 1) : '&nbsp;';
  1043. print '</td>';
  1044. print '<td class="liste_total right">';
  1045. if ($num) {
  1046. if ($total) {
  1047. print '<span class="valignmiddle">';
  1048. if (!empty($conf->global->PRODUIT_MULTIPRICES)) {
  1049. print $form->textwithpicto('', $langs->trans("Variable"));
  1050. } else {
  1051. print price($totalvaluesell / $total, 1);
  1052. }
  1053. print '</span>';
  1054. }
  1055. }
  1056. print '</td>';
  1057. // Value to sell
  1058. print '<td class="liste_total right amount">';
  1059. if ($num) {
  1060. print '<span class="valignmiddle">';
  1061. if (empty($conf->global->PRODUIT_MULTIPRICES)) {
  1062. print price(price2num($totalvaluesell, 'MT'), 1);
  1063. } else {
  1064. print $form->textwithpicto('', $langs->trans("Variable"));
  1065. }
  1066. print '</span>';
  1067. }
  1068. print '</td>';
  1069. print '<td></td>';
  1070. print '<td></td>';
  1071. print "</tr>";
  1072. print "</table>";
  1073. print '</div>';
  1074. if (!empty($conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE)) {
  1075. print '<br><br>';
  1076. print load_fiche_titre($langs->trans('AddNewProductStockWarehouse'));
  1077. if (!empty($user->rights->produit->creer)) {
  1078. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  1079. print '<input type="hidden" name="token" value="'.newToken().'">';
  1080. print '<input type="hidden" name="action" value="addlimitstockwarehouse">';
  1081. print '<input type="hidden" name="id" value="'.$id.'">';
  1082. }
  1083. print '<table class="noborder centpercent">';
  1084. if (!empty($user->rights->produit->creer)) {
  1085. print '<tr class="liste_titre"><td>'.$formproduct->selectWarehouses('', 'fk_entrepot').'</td>';
  1086. print '<td class="right"><input name="seuil_stock_alerte" type="text" placeholder="'.$langs->trans("StockLimit").'" /></td>';
  1087. print '<td class="right"><input name="desiredstock" type="text" placeholder="'.$langs->trans("DesiredStock").'" /></td>';
  1088. print '<td class="right"><input type="submit" value="'.$langs->trans("Save").'" class="button button-save" /></td>';
  1089. print '</tr>';
  1090. } else {
  1091. print '<tr class="liste_titre"><td>'.$langs->trans("Warehouse").'</td>';
  1092. print '<td class="right">'.$langs->trans("StockLimit").'</td>';
  1093. print '<td class="right">'.$langs->trans("DesiredStock").'</td>';
  1094. print '</tr>';
  1095. }
  1096. $pse = new ProductStockEntrepot($db);
  1097. $lines = $pse->fetchAll($id);
  1098. if (!empty($lines)) {
  1099. $var = false;
  1100. foreach ($lines as $line) {
  1101. $ent = new Entrepot($db);
  1102. $ent->fetch($line['fk_entrepot']);
  1103. print '<tr class="oddeven"><td>'.$ent->getNomUrl(3).'</td>';
  1104. print '<td class="right">'.$line['seuil_stock_alerte'].'</td>';
  1105. print '<td class="right">'.$line['desiredstock'].'</td>';
  1106. if (!empty($user->rights->produit->creer)) {
  1107. print '<td class="right"><a href="'.$_SERVER['PHP_SELF'].'?id='.$id.'&fk_productstockwarehouse='.$line['id'].'&action=delete_productstockwarehouse&token='.newToken().'">'.img_delete().'</a></td>';
  1108. }
  1109. print '</tr>';
  1110. }
  1111. }
  1112. print "</table>";
  1113. if (!empty($user->rights->produit->creer)) {
  1114. print '</form>';
  1115. }
  1116. }
  1117. } else {
  1118. // List of variants
  1119. include_once DOL_DOCUMENT_ROOT.'/variants/class/ProductCombination.class.php';
  1120. include_once DOL_DOCUMENT_ROOT.'/variants/class/ProductCombination2ValuePair.class.php';
  1121. $prodstatic = new Product($db);
  1122. $prodcomb = new ProductCombination($db);
  1123. $comb2val = new ProductCombination2ValuePair($db);
  1124. $productCombinations = $prodcomb->fetchAllByFkProductParent($object->id);
  1125. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  1126. print '<input type="hidden" name="token" value="'.newToken().'">';
  1127. print '<input type="hidden" name="action" value="massaction">';
  1128. print '<input type="hidden" name="id" value="'.$id.'">';
  1129. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  1130. // load variants
  1131. $title = $langs->trans("ProductCombinations");
  1132. print_barre_liste($title, 0, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, '', 0);
  1133. print '<div class="div-table-responsive">';
  1134. ?>
  1135. <table class="liste">
  1136. <tr class="liste_titre">
  1137. <td class="liste_titre"><?php echo $langs->trans('Product') ?></td>
  1138. <td class="liste_titre"><?php echo $langs->trans('Combination') ?></td>
  1139. <td class="liste_titre center"><?php echo $langs->trans('OnSell') ?></td>
  1140. <td class="liste_titre center"><?php echo $langs->trans('OnBuy') ?></td>
  1141. <td class="liste_titre right"><?php echo $langs->trans('Stock') ?></td>
  1142. <td class="liste_titre"></td>
  1143. </tr>
  1144. <?php
  1145. if (count($productCombinations)) {
  1146. $stock_total = 0;
  1147. foreach ($productCombinations as $currcomb) {
  1148. $prodstatic->fetch($currcomb->fk_product_child);
  1149. $prodstatic->load_stock();
  1150. $stock_total += $prodstatic->stock_reel;
  1151. ?>
  1152. <tr class="oddeven">
  1153. <td><?php echo $prodstatic->getNomUrl(1) ?></td>
  1154. <td>
  1155. <?php
  1156. $productCombination2ValuePairs = $comb2val->fetchByFkCombination($currcomb->id);
  1157. $iMax = count($productCombination2ValuePairs);
  1158. for ($i = 0; $i < $iMax; $i++) {
  1159. echo dol_htmlentities($productCombination2ValuePairs[$i]);
  1160. if ($i !== ($iMax - 1)) {
  1161. echo ', ';
  1162. }
  1163. } ?>
  1164. </td>
  1165. <td style="text-align: center;"><?php echo $prodstatic->getLibStatut(2, 0) ?></td>
  1166. <td style="text-align: center;"><?php echo $prodstatic->getLibStatut(2, 1) ?></td>
  1167. <td class="right"><?php echo $prodstatic->stock_reel ?></td>
  1168. <td class="right">
  1169. <a class="paddingleft paddingright" href="<?php echo dol_buildpath('/product/stock/product.php?id='.$currcomb->fk_product_child, 2) ?>"><?php echo img_edit() ?></a>
  1170. </td>
  1171. <?php
  1172. ?>
  1173. </tr>
  1174. <?php
  1175. }
  1176. print '<tr class="liste_total">';
  1177. print '<td colspan="4" class="left">'.$langs->trans("Total").'</td>';
  1178. print '<td class="right">'.$stock_total.'</td>';
  1179. print '<td></td>';
  1180. print '</tr>';
  1181. } else {
  1182. print '<tr><td colspan="8"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
  1183. }
  1184. ?>
  1185. </table>
  1186. <?php
  1187. print '</div>';
  1188. print '</form>';
  1189. }
  1190. // End of page
  1191. llxFooter();
  1192. $db->close();