card.php 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003
  1. <?php
  2. /* Copyright (C) 2003-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005 Simon Tosser <simon@kornog-computing.com>
  5. * Copyright (C) 2005-2014 Regis Houssin <regis.houssin@inodbox.com>
  6. * Copyright (C) 2016 Francis Appels <francis.appels@yahoo.com>
  7. * Copyright (C) 2021 Noé Cendrier <noe.cendrier@altairis.fr>
  8. * Copyright (C) 2021 Frédéric France <frederic.france@netlogic.fr>
  9. * Copyright (C) 2022 Charlene Benke <charlene@patas-monkey.com>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 3 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  23. */
  24. /**
  25. * \file htdocs/product/stock/card.php
  26. * \ingroup stock
  27. * \brief Page fiche entrepot
  28. */
  29. // Load Dolibarr environment
  30. require '../../main.inc.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/lib/stock.lib.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
  36. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  37. require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
  38. require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
  39. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  40. if (!empty($conf->project->enabled)) {
  41. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  42. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
  43. }
  44. // Load translation files required by the page
  45. $langs->loadLangs(array('products', 'stocks', 'companies', 'categories'));
  46. $action = GETPOST('action', 'aZ09');
  47. $cancel = GETPOST('cancel', 'alpha');
  48. $confirm = GETPOST('confirm');
  49. $projectid = GETPOST('projectid', 'int');
  50. $id = GETPOST('id', 'int');
  51. $socid = GETPOST('socid', 'int');
  52. $ref = GETPOST('ref', 'alpha');
  53. $sortfield = GETPOST('sortfield', 'aZ09comma');
  54. $sortorder = GETPOST('sortorder', 'aZ09comma');
  55. if (!$sortfield) {
  56. $sortfield = "p.ref";
  57. }
  58. if (!$sortorder) {
  59. $sortorder = "DESC";
  60. }
  61. $backtopage = GETPOST('backtopage', 'alpha');
  62. // Security check
  63. //$result=restrictedArea($user,'stock', $id, 'entrepot&stock');
  64. $result = restrictedArea($user, 'stock');
  65. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  66. $hookmanager->initHooks(array('warehousecard', 'globalcard'));
  67. $object = new Entrepot($db);
  68. $extrafields = new ExtraFields($db);
  69. // fetch optionals attributes and labels
  70. $extrafields->fetch_name_optionals_label($object->table_element);
  71. // Load object
  72. if ($id > 0 || !empty($ref)) {
  73. $ret = $object->fetch($id, $ref);
  74. if ($ret <= 0) {
  75. setEventMessages($object->error, $object->errors, 'errors');
  76. $action = '';
  77. }
  78. }
  79. $usercanread = (($user->rights->stock->lire));
  80. $usercancreate = (($user->rights->stock->creer));
  81. $usercandelete = (($user->rights->stock->supprimer));
  82. /*
  83. * Actions
  84. */
  85. $error = 0;
  86. $parameters = array('id'=>$id, 'ref'=>$ref);
  87. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  88. if ($reshook < 0) {
  89. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  90. }
  91. if (empty($reshook)) {
  92. $backurlforlist = DOL_URL_ROOT.'/product/stock/list.php';
  93. if (empty($backtopage) || ($cancel && empty($id))) {
  94. if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
  95. if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
  96. $backtopage = $backurlforlist;
  97. } else {
  98. $backtopage = DOL_URL_ROOT.'/product/stock/card.php?id='.((!empty($id) && $id > 0) ? $id : '__ID__');
  99. }
  100. }
  101. }
  102. if ($cancel) {
  103. if (!empty($backtopageforcancel)) {
  104. header("Location: ".$backtopageforcancel);
  105. exit;
  106. } elseif (!empty($backtopage)) {
  107. header("Location: ".$backtopage);
  108. exit;
  109. }
  110. $action = '';
  111. }
  112. // Ajout entrepot
  113. if ($action == 'add' && $user->rights->stock->creer) {
  114. $object->ref = (string) GETPOST("ref", "alpha");
  115. $object->fk_parent = (int) GETPOST("fk_parent", "int");
  116. $object->fk_project = GETPOST('projectid', 'int');
  117. $object->label = (string) GETPOST("libelle", "alpha");
  118. $object->description = (string) GETPOST("desc", "alpha");
  119. $object->statut = GETPOST("statut", "int");
  120. $object->lieu = (string) GETPOST("lieu", "alpha");
  121. $object->address = (string) GETPOST("address", "alpha");
  122. $object->zip = (string) GETPOST("zipcode", "alpha");
  123. $object->town = (string) GETPOST("town", "alpha");
  124. $object->country_id = GETPOST("country_id");
  125. $object->phone = (string) GETPOST("phone", "alpha");
  126. $object->fax = (string) GETPOST("fax", "alpha");
  127. if (!empty($object->label)) {
  128. // Fill array 'array_options' with data from add form
  129. $ret = $extrafields->setOptionalsFromPost(null, $object);
  130. if ($ret < 0) {
  131. $error++;
  132. $action = 'create';
  133. }
  134. if (!$error) {
  135. $id = $object->create($user);
  136. if ($id > 0) {
  137. setEventMessages($langs->trans("RecordSaved"), null, 'mesgs');
  138. $categories = GETPOST('categories', 'array');
  139. $object->setCategories($categories);
  140. if (!empty($backtopage)) {
  141. $backtopage = str_replace("__ID__", $id, $backtopage);
  142. header("Location: ".$backtopage);
  143. exit;
  144. } else {
  145. header("Location: card.php?id=".urlencode($id));
  146. exit;
  147. }
  148. } else {
  149. $action = 'create';
  150. setEventMessages($object->error, $object->errors, 'errors');
  151. }
  152. }
  153. } else {
  154. setEventMessages($langs->trans("ErrorWarehouseRefRequired"), null, 'errors');
  155. $action = "create"; // Force retour sur page creation
  156. }
  157. }
  158. // Delete warehouse
  159. if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->stock->supprimer) {
  160. $object->fetch(GETPOST('id', 'int'));
  161. $result = $object->delete($user);
  162. if ($result > 0) {
  163. setEventMessages($langs->trans("RecordDeleted"), null, 'mesgs');
  164. header("Location: ".DOL_URL_ROOT.'/product/stock/list.php?restore_lastsearch_values=1');
  165. exit;
  166. } else {
  167. setEventMessages($object->error, $object->errors, 'errors');
  168. $action = '';
  169. }
  170. }
  171. // Modification entrepot
  172. if ($action == 'update' && !$cancel) {
  173. if ($object->fetch($id)) {
  174. $object->label = GETPOST("libelle");
  175. $object->fk_parent = GETPOST("fk_parent");
  176. $object->fk_project = GETPOST('projectid');
  177. $object->description = GETPOST("desc");
  178. $object->statut = GETPOST("statut");
  179. $object->lieu = GETPOST("lieu");
  180. $object->address = GETPOST("address");
  181. $object->zip = GETPOST("zipcode");
  182. $object->town = GETPOST("town");
  183. $object->country_id = GETPOST("country_id");
  184. $object->phone = GETPOST("phone");
  185. $object->fax = GETPOST("fax");
  186. // Fill array 'array_options' with data from add form
  187. $ret = $extrafields->setOptionalsFromPost(null, $object, '@GETPOSTISSET');
  188. if ($ret < 0) {
  189. $error++;
  190. }
  191. if (!$error) {
  192. $ret = $object->update($id, $user);
  193. if ($ret < 0) {
  194. $error++;
  195. }
  196. }
  197. if ($error) {
  198. $action = 'edit';
  199. setEventMessages($object->error, $object->errors, 'errors');
  200. } else {
  201. $categories = GETPOST('categories', 'array');
  202. $object->setCategories($categories);
  203. $action = '';
  204. }
  205. } else {
  206. $action = 'edit';
  207. setEventMessages($object->error, $object->errors, 'errors');
  208. }
  209. } elseif ($action == 'update_extras') {
  210. $object->oldcopy = dol_clone($object);
  211. // Fill array 'array_options' with data from update form
  212. $ret = $extrafields->setOptionalsFromPost(null, $object, GETPOST('attribute', 'restricthtml'));
  213. if ($ret < 0) {
  214. $error++;
  215. }
  216. if (!$error) {
  217. $result = $object->insertExtraFields();
  218. if ($result < 0) {
  219. setEventMessages($object->error, $object->errors, 'errors');
  220. $error++;
  221. }
  222. }
  223. if ($error) {
  224. $action = 'edit_extras';
  225. }
  226. } elseif ($action == 'classin' && $usercancreate) {
  227. // Link to a project
  228. $object->setProject(GETPOST('projectid', 'int'));
  229. }
  230. if ($cancel == $langs->trans("Cancel")) {
  231. $action = '';
  232. }
  233. // Actions to build doc
  234. $upload_dir = $conf->stock->dir_output;
  235. $permissiontoadd = $user->rights->stock->creer;
  236. include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
  237. }
  238. /*
  239. * View
  240. */
  241. $productstatic = new Product($db);
  242. $form = new Form($db);
  243. $formproduct = new FormProduct($db);
  244. $formcompany = new FormCompany($db);
  245. $formfile = new FormFile($db);
  246. if (!empty($conf->project->enabled)) {
  247. $formproject = new FormProjets($db);
  248. }
  249. $title = $langs->trans("WarehouseCard");
  250. if ($action == 'create') {
  251. $title = $langs->trans("NewWarehouse");
  252. }
  253. $help_url = 'EN:Module_Stocks_En|FR:Module_Stock|ES:M&oacute;dulo_Stocks';
  254. llxHeader("", $title, $help_url);
  255. if ($action == 'create') {
  256. print load_fiche_titre($langs->trans("NewWarehouse"), '', 'stock');
  257. dol_set_focus('input[name="libelle"]');
  258. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">'."\n";
  259. print '<input type="hidden" name="token" value="'.newToken().'">';
  260. print '<input type="hidden" name="action" value="add">';
  261. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  262. print dol_get_fiche_head();
  263. print '<table class="border centpercent">';
  264. // Ref
  265. print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("Ref").'</td><td><input name="libelle" size="20" value=""></td></tr>';
  266. print '<tr><td>'.$langs->trans("LocationSummary").'</td><td><input name="lieu" size="40" value="'.(!empty($object->lieu) ? $object->lieu : '').'"></td></tr>';
  267. // Parent entrepot
  268. print '<tr><td>'.$langs->trans("AddIn").'</td><td>';
  269. print img_picto('', 'stock').$formproduct->selectWarehouses((GETPOSTISSET('fk_parent') ? GETPOST('fk_parent', 'int') : 'ifone'), 'fk_parent', '', 1);
  270. print '</td></tr>';
  271. // Project
  272. if (!empty($conf->project->enabled)) {
  273. $langs->load('projects');
  274. print '<tr><td>'.$langs->trans('Project').'</td><td colspan="2">';
  275. print img_picto('', 'project').$formproject->select_projects(($socid > 0 ? $socid : -1), $projectid, 'projectid', 0, 0, 1, 1, 0, 0, 0, '', 1, 0, 'maxwidth500');
  276. print ' <a href="'.DOL_URL_ROOT.'/projet/card.php?socid='.$socid.'&action=create&status=1&backtopage='.urlencode($_SERVER["PHP_SELF"].'?action=create&socid='.$socid).'"><span class="fa fa-plus-circle valignmiddle" title="'.$langs->trans("AddProject").'"></span></a>';
  277. print '</td></tr>';
  278. }
  279. // Description
  280. print '<tr><td class="tdtop">'.$langs->trans("Description").'</td><td>';
  281. // Editeur wysiwyg
  282. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  283. $doleditor = new DolEditor('desc', (!empty($object->description) ? $object->description : ''), '', 180, 'dolibarr_notes', 'In', false, true, empty($conf->fckeditor->enabled) ? '' : $conf->fckeditor->enabled, ROWS_5, '90%');
  284. $doleditor->Create();
  285. print '</td></tr>';
  286. print '<tr><td>'.$langs->trans('Address').'</td><td><textarea name="address" class="quatrevingtpercent" rows="3" wrap="soft">';
  287. print (!empty($object->address) ? $object->address : '');
  288. print '</textarea></td></tr>';
  289. // Zip / Town
  290. print '<tr><td>'.$langs->trans('Zip').'</td><td>';
  291. print $formcompany->select_ziptown((!empty($object->zip) ? $object->zip : ''), 'zipcode', array('town', 'selectcountry_id', 'state_id'), 6);
  292. print '</td></tr>';
  293. print '<tr><td>'.$langs->trans('Town').'</td><td>';
  294. print $formcompany->select_ziptown((!empty($object->town) ? $object->town : ''), 'town', array('zipcode', 'selectcountry_id', 'state_id'));
  295. print '</td></tr>';
  296. // Country
  297. print '<tr><td>'.$langs->trans('Country').'</td><td>';
  298. print img_picto('', 'globe-americas', 'class="paddingright"');
  299. print $form->select_country((!empty($object->country_id) ? $object->country_id : $mysoc->country_code), 'country_id');
  300. if ($user->admin) {
  301. print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
  302. }
  303. print '</td></tr>';
  304. // Phone / Fax
  305. print '<tr><td class="titlefieldcreate">'.$form->editfieldkey('Phone', 'phone', '', $object, 0).'</td><td>';
  306. print img_picto('', 'object_phoning', 'class="paddingright"');
  307. print '<input name="phone" size="20" value="'.$object->phone.'"></td></tr>';
  308. print '<tr><td class="titlefieldcreate">'.$form->editfieldkey('Fax', 'fax', '', $object, 0).'</td>';
  309. print '<td>';
  310. print img_picto('', 'object_phoning_fax', 'class="paddingright"');
  311. print '<input name="fax" size="20" value="'.$object->fax.'"></td></tr>';
  312. // Status
  313. print '<tr><td>'.$langs->trans("Status").'</td><td>';
  314. print '<select id="warehousestatus" name="statut" class="flat minwidth100">';
  315. foreach ($object->statuts as $key => $value) {
  316. if ($key == 1) {
  317. print '<option value="'.$key.'" selected>'.$langs->trans($value).'</option>';
  318. } else {
  319. print '<option value="'.$key.'">'.$langs->trans($value).'</option>';
  320. }
  321. }
  322. print '</select>';
  323. print ajax_combobox('warehousestatus');
  324. print '</td></tr>';
  325. // Other attributes
  326. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
  327. if (isModEnabled('categorie')) {
  328. // Categories
  329. print '<tr><td>'.$langs->trans("Categories").'</td><td colspan="3">';
  330. $cate_arbo = $form->select_all_categories(Categorie::TYPE_WAREHOUSE, '', 'parent', 64, 0, 1);
  331. print img_picto('', 'category').$form->multiselectarray('categories', $cate_arbo, GETPOST('categories', 'array'), '', 0, 'quatrevingtpercent widthcentpercentminusx', 0, 0);
  332. print "</td></tr>";
  333. }
  334. print '</table>';
  335. print dol_get_fiche_end();
  336. print $form->buttonsSaveCancel("Create");
  337. print '</form>';
  338. } else {
  339. $id = GETPOST("id", 'int');
  340. if ($id > 0 || $ref) {
  341. $object = new Entrepot($db);
  342. $result = $object->fetch($id, $ref);
  343. if ($result <= 0) {
  344. print 'No record found';
  345. exit;
  346. }
  347. /*
  348. * Affichage fiche
  349. */
  350. if ($action <> 'edit' && $action <> 're-edit') {
  351. $head = stock_prepare_head($object);
  352. print dol_get_fiche_head($head, 'card', $langs->trans("Warehouse"), -1, 'stock');
  353. $formconfirm = '';
  354. // Confirm delete warehouse
  355. if ($action == 'delete') {
  356. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("DeleteAWarehouse"), $langs->trans("ConfirmDeleteWarehouse", $object->label), "confirm_delete", '', 0, 2);
  357. }
  358. // Call Hook formConfirm
  359. $parameters = array('formConfirm' => $formconfirm);
  360. $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  361. if (empty($reshook)) {
  362. $formconfirm .= $hookmanager->resPrint;
  363. } elseif ($reshook > 0) {
  364. $formconfirm = $hookmanager->resPrint;
  365. }
  366. // Print form confirm
  367. print $formconfirm;
  368. // Warehouse card
  369. $linkback = '<a href="'.DOL_URL_ROOT.'/product/stock/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  370. $morehtmlref = '<div class="refidno">';
  371. $morehtmlref .= $langs->trans("LocationSummary").' : '.$object->lieu;
  372. // Project
  373. if (!empty($conf->project->enabled)) {
  374. $langs->load("projects");
  375. $morehtmlref .= '<br>'.img_picto('', 'project').' '.$langs->trans('Project').' ';
  376. if ($usercancreate) {
  377. if ($action != 'classify') {
  378. $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> : ';
  379. }
  380. if ($action == 'classify') {
  381. $projectid = $object->fk_project;
  382. $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
  383. $morehtmlref .= '<input type="hidden" name="action" value="classin">';
  384. $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
  385. $morehtmlref .= $formproject->select_projects(($socid > 0 ? $socid : -1), $projectid, 'projectid', 0, 0, 1, 1, 0, 0, 0, '', 1, 0, 'maxwidth500');
  386. $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
  387. $morehtmlref .= '</form>';
  388. } else {
  389. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, ($socid > 0 ? $socid : -1), $object->fk_project, 'none', 0, 0, 0, 1, '', 'maxwidth300');
  390. }
  391. } else {
  392. if (!empty($object->fk_project)) {
  393. $proj = new Project($db);
  394. $proj->fetch($object->fk_project);
  395. $morehtmlref .= ' : '.$proj->getNomUrl(1);
  396. if ($proj->title) {
  397. $morehtmlref .= ' - '.$proj->title;
  398. }
  399. } else {
  400. $morehtmlref .= '';
  401. }
  402. }
  403. }
  404. $morehtmlref .= '</div>';
  405. $shownav = 1;
  406. if ($user->socid && !in_array('stock', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) {
  407. $shownav = 0;
  408. }
  409. dol_banner_tab($object, 'ref', $linkback, $shownav, 'ref', 'ref', $morehtmlref);
  410. print '<div class="fichecenter">';
  411. print '<div class="fichehalfleft">';
  412. print '<div class="underbanner clearboth"></div>';
  413. print '<table class="border centpercent tableforfield">';
  414. // Parent entrepot
  415. $parentwarehouse = new Entrepot($db);
  416. if (!empty($object->fk_parent) && $parentwarehouse->fetch($object->fk_parent) > 0) {
  417. print '<tr><td>'.$langs->trans("ParentWarehouse").'</td><td>';
  418. print $parentwarehouse->getNomUrl(3);
  419. print '</td></tr>';
  420. }
  421. print '<tr>';
  422. // Description
  423. print '<td class="titlefield tdtop">'.$langs->trans("Description").'</td><td>'.dol_htmlentitiesbr($object->description).'</td></tr>';
  424. $calcproductsunique = $object->nb_different_products();
  425. $calcproducts = $object->nb_products();
  426. // Total nb of different products
  427. print '<tr><td>'.$langs->trans("NumberOfDifferentProducts").'</td><td>';
  428. print empty($calcproductsunique['nb']) ? '0' : $calcproductsunique['nb'];
  429. print "</td></tr>";
  430. // Nb of products
  431. print '<tr><td>'.$langs->trans("NumberOfProducts").'</td><td>';
  432. $valtoshow = price2num($calcproducts['nb'], 'MS');
  433. print empty($valtoshow) ? '0' : $valtoshow;
  434. print "</td></tr>";
  435. print '</table>';
  436. print '</div>';
  437. print '<div class="fichehalfright">';
  438. print '<div class="underbanner clearboth"></div>';
  439. print '<table class="border centpercent tableforfield">';
  440. // Value
  441. print '<tr><td class="titlefield">'.$langs->trans("EstimatedStockValueShort").'</td><td>';
  442. print price((empty($calcproducts['value']) ? '0' : price2num($calcproducts['value'], 'MT')), 0, $langs, 0, -1, -1, $conf->currency);
  443. print "</td></tr>";
  444. // Last movement
  445. if (!empty($user->rights->stock->mouvement->lire)) {
  446. $sql = "SELECT max(m.datem) as datem";
  447. $sql .= " FROM ".MAIN_DB_PREFIX."stock_mouvement as m";
  448. $sql .= " WHERE m.fk_entrepot = ".((int) $object->id);
  449. $resqlbis = $db->query($sql);
  450. if ($resqlbis) {
  451. $obj = $db->fetch_object($resqlbis);
  452. $lastmovementdate = $db->jdate($obj->datem);
  453. } else {
  454. dol_print_error($db);
  455. }
  456. print '<tr><td>'.$langs->trans("LastMovement").'</td><td>';
  457. if ($lastmovementdate) {
  458. print dol_print_date($lastmovementdate, 'dayhour');
  459. print ' &nbsp; &nbsp; ';
  460. print img_picto($langs->trans('LastMovement'), 'movement', 'class="pictofixedwidth"');
  461. print '<a href="'.DOL_URL_ROOT.'/product/stock/movement_list.php?id='.$object->id.'">'.$langs->trans("FullList").'</a>';
  462. } else {
  463. print $langs->trans("None");
  464. }
  465. print "</td></tr>";
  466. }
  467. // Other attributes
  468. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
  469. // Categories
  470. if (isModEnabled('categorie')) {
  471. print '<tr><td valign="middle">'.$langs->trans("Categories").'</td><td colspan="3">';
  472. print $form->showCategories($object->id, Categorie::TYPE_WAREHOUSE, 1);
  473. print "</td></tr>";
  474. }
  475. print "</table>";
  476. print '</div>';
  477. print '</div>';
  478. print '<div class="clearboth"></div>';
  479. print dol_get_fiche_end();
  480. /*
  481. * Action bar
  482. */
  483. print "<div class=\"tabsAction\">\n";
  484. $parameters = array();
  485. $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  486. if (empty($reshook)) {
  487. if (empty($action) || $action == 'classin') {
  488. if ($user->rights->stock->creer) {
  489. print '<a class="butAction" href="card.php?action=edit&token='.newToken().'&id='.$object->id.'">'.$langs->trans("Modify").'</a>';
  490. } else {
  491. print '<a class="butActionRefused classfortooltip" href="#">'.$langs->trans("Modify").'</a>';
  492. }
  493. if ($user->rights->stock->supprimer) {
  494. print '<a class="butActionDelete" href="card.php?action=delete&token='.newToken().'&id='.$object->id.'">'.$langs->trans("Delete").'</a>';
  495. } else {
  496. print '<a class="butActionRefused classfortooltip" href="#">'.$langs->trans("Delete").'</a>';
  497. }
  498. }
  499. }
  500. print "</div>";
  501. /* ************************************************************************** */
  502. /* */
  503. /* Affichage de la liste des produits de l'entrepot */
  504. /* */
  505. /* ************************************************************************** */
  506. print '<br>';
  507. print '<table class="noborder centpercent">';
  508. print "<tr class=\"liste_titre\">";
  509. $parameters = array();
  510. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
  511. print $hookmanager->resPrint;
  512. print_liste_field_titre("Product", "", "p.ref", "&amp;id=".$id, "", "", $sortfield, $sortorder);
  513. print_liste_field_titre("Label", "", "p.label", "&amp;id=".$id, "", "", $sortfield, $sortorder);
  514. print_liste_field_titre("NumberOfUnit", "", "ps.reel", "&amp;id=".$id, "", '', $sortfield, $sortorder, 'right ');
  515. if (!empty($conf->global->PRODUCT_USE_UNITS)) {
  516. print_liste_field_titre("Unit", "", "p.fk_unit", "&amp;id=".$id, "", 'align="left"', $sortfield, $sortorder);
  517. }
  518. print_liste_field_titre($form->textwithpicto($langs->trans("AverageUnitPricePMPShort"), $langs->trans("AverageUnitPricePMPDesc")), "", "p.pmp", "&amp;id=".$id, "", '', $sortfield, $sortorder, 'right ');
  519. print_liste_field_titre("EstimatedStockValueShort", "", "", "&amp;id=".$id, "", '', $sortfield, $sortorder, 'right ');
  520. if (empty($conf->global->PRODUIT_MULTIPRICES)) {
  521. print_liste_field_titre("SellPriceMin", "", "p.price", "&amp;id=".$id, "", '', $sortfield, $sortorder, 'right ');
  522. }
  523. if (empty($conf->global->PRODUIT_MULTIPRICES)) {
  524. print_liste_field_titre("EstimatedStockValueSellShort", "", "", "&amp;id=".$id, "", '', $sortfield, $sortorder, 'right ');
  525. }
  526. if ($user->rights->stock->mouvement->creer) {
  527. print_liste_field_titre('');
  528. }
  529. if ($user->rights->stock->creer) {
  530. print_liste_field_titre('');
  531. }
  532. // Hook fields
  533. $parameters = array('sortfield'=>$sortfield, 'sortorder'=>$sortorder);
  534. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
  535. print $hookmanager->resPrint;
  536. print "</tr>\n";
  537. $totalunit = 0;
  538. $totalvalue = $totalvaluesell = 0;
  539. //For MultiCompany PMP per entity
  540. $separatedPMP = false;
  541. if (!empty($conf->global->MULTICOMPANY_PRODUCT_SHARING_ENABLED) && !empty($conf->global->MULTICOMPANY_PMP_PER_ENTITY_ENABLED)) {
  542. $separatedPMP = true;
  543. }
  544. $sql = "SELECT p.rowid as rowid, p.ref, p.label as produit, p.tobatch, p.fk_product_type as type, p.price, p.price_ttc, p.entity,";
  545. $sql .= "p.tosell, p.tobuy,";
  546. $sql .= "p.accountancy_code_sell,";
  547. $sql .= "p.accountancy_code_sell_intra,";
  548. $sql .= "p.accountancy_code_sell_export,";
  549. $sql .= "p.accountancy_code_buy,";
  550. $sql .= "p.accountancy_code_buy_intra,";
  551. $sql .= "p.accountancy_code_buy_export,";
  552. $sql .= 'p.barcode,';
  553. if ($separatedPMP) {
  554. $sql .= " pa.pmp as ppmp,";
  555. } else {
  556. $sql .= " p.pmp as ppmp,";
  557. }
  558. $sql .= " ps.reel as value";
  559. if (!empty($conf->global->PRODUCT_USE_UNITS)) {
  560. $sql .= ",fk_unit";
  561. }
  562. // Add fields from hooks
  563. $parameters = array();
  564. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
  565. if ($reshook > 0) { //Note that $sql is replaced if reshook > 0
  566. $sql = "";
  567. }
  568. $sql .= $hookmanager->resPrint;
  569. $sql .= " FROM ".MAIN_DB_PREFIX."product_stock as ps, ".MAIN_DB_PREFIX."product as p";
  570. if ($separatedPMP) {
  571. $sql .= ", ".MAIN_DB_PREFIX."product_perentity as pa";
  572. }
  573. $sql .= " WHERE ps.fk_product = p.rowid";
  574. $sql .= " AND ps.reel <> 0"; // We do not show if stock is 0 (no product in this warehouse)
  575. $sql .= " AND ps.fk_entrepot = ".((int) $object->id);
  576. if ($separatedPMP) {
  577. $sql .= " AND pa.fk_product = p.rowid AND pa.entity = ".(int) $conf->entity;
  578. }
  579. $sql .= $db->order($sortfield, $sortorder);
  580. dol_syslog('List products', LOG_DEBUG);
  581. $resql = $db->query($sql);
  582. if ($resql) {
  583. $num = $db->num_rows($resql);
  584. $i = 0;
  585. $sameunits = true;
  586. while ($i < $num) {
  587. $objp = $db->fetch_object($resql);
  588. // Multilangs
  589. if (getDolGlobalInt('MAIN_MULTILANGS')) { // si l'option est active
  590. $sql = "SELECT label";
  591. $sql .= " FROM ".MAIN_DB_PREFIX."product_lang";
  592. $sql .= " WHERE fk_product = ".((int) $objp->rowid);
  593. $sql .= " AND lang = '".$db->escape($langs->getDefaultLang())."'";
  594. $sql .= " LIMIT 1";
  595. $result = $db->query($sql);
  596. if ($result) {
  597. $objtp = $db->fetch_object($result);
  598. if ($objtp->label != '') {
  599. $objp->produit = $objtp->label;
  600. }
  601. }
  602. }
  603. //print '<td>'.dol_print_date($objp->datem).'</td>';
  604. print '<tr class="oddeven">';
  605. $parameters = array('obj'=>$objp);
  606. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
  607. print $hookmanager->resPrint;
  608. $productstatic->id = $objp->rowid;
  609. $productstatic->ref = $objp->ref;
  610. $productstatic->label = $objp->produit;
  611. $productstatic->type = $objp->type;
  612. $productstatic->entity = $objp->entity;
  613. $productstatic->status_batch = $objp->tobatch;
  614. if (!empty($conf->global->PRODUCT_USE_UNITS)) {
  615. $productstatic->fk_unit = $objp->fk_unit;
  616. }
  617. $productstatic->status = $objp->tosell;
  618. $productstatic->status_buy = $objp->tobuy;
  619. $productstatic->barcode = $objp->barcode;
  620. $productstatic->accountancy_code_sell = $objp->accountancy_code_sell;
  621. $productstatic->accountancy_code_sell_intra = $objp->accountancy_code_sell_intra;
  622. $productstatic->accountancy_code_sell_export = $objp->accountancy_code_sell_export;
  623. $productstatic->accountancy_code_buy = $objp->accountancy_code_buy;
  624. $productstatic->accountancy_code_buy_intra = $objp->accountancy_code_buy_intra;
  625. $productstatic->accountancy_code_buy_export = $objp->accountancy_code_buy_export;
  626. print "<td>";
  627. print $productstatic->getNomUrl(1, 'stock', 16);
  628. print '</td>';
  629. // Label
  630. print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($objp->produit).'">'.dol_escape_htmltag($objp->produit).'</td>';
  631. print '<td class="right">';
  632. $valtoshow = price(price2num($objp->value, 'MS'), 0, '', 0, 0); // TODO replace with a qty() function
  633. print empty($valtoshow) ? '0' : $valtoshow;
  634. print '</td>';
  635. $totalunit += $objp->value;
  636. if (!empty($conf->global->PRODUCT_USE_UNITS)) {
  637. // Units
  638. print '<td align="left">';
  639. if (is_null($productstatic->fk_unit)) {
  640. $productstatic->fk_unit = 1;
  641. }
  642. print $langs->trans($productstatic->getLabelOfUnit());
  643. print '</td>';
  644. }
  645. // Price buy PMP
  646. print '<td class="right nowraponall">'.price(price2num($objp->ppmp, 'MU')).'</td>';
  647. // Total PMP
  648. print '<td class="right amount nowraponall">'.price(price2num($objp->ppmp * $objp->value, 'MT')).'</td>';
  649. $totalvalue += price2num($objp->ppmp * $objp->value, 'MT');
  650. // Price sell min
  651. if (empty($conf->global->PRODUIT_MULTIPRICES)) {
  652. $pricemin = $objp->price;
  653. print '<td class="right">';
  654. print price(price2num($pricemin, 'MU'), 1);
  655. print '</td>';
  656. // Total sell min
  657. print '<td class="right">';
  658. print price(price2num($pricemin * $objp->value, 'MT'), 1);
  659. print '</td>';
  660. }
  661. $totalvaluesell += price2num($pricemin * $objp->value, 'MT');
  662. if ($user->rights->stock->mouvement->creer) {
  663. print '<td class="center"><a href="'.DOL_URL_ROOT.'/product/stock/product.php?dwid='.$object->id.'&id='.$objp->rowid.'&action=transfert&backtopage='.urlencode($_SERVER["PHP_SELF"].'?id='.$id).'">';
  664. print img_picto($langs->trans("TransferStock"), 'add', 'class="hideonsmartphone pictofixedwidth" style="color: #a69944"');
  665. print $langs->trans("TransferStock");
  666. print "</a></td>";
  667. }
  668. if ($user->rights->stock->creer) {
  669. print '<td class="center"><a href="'.DOL_URL_ROOT.'/product/stock/product.php?dwid='.$object->id.'&id='.$objp->rowid.'&action=correction&backtopage='.urlencode($_SERVER["PHP_SELF"].'?id='.$id).'">';
  670. print img_picto($langs->trans("CorrectStock"), 'add', 'class="hideonsmartphone pictofixedwidth" style="color: #a69944"');
  671. print $langs->trans("CorrectStock");
  672. print "</a></td>";
  673. }
  674. if (!empty($conf->global->PRODUCT_USE_UNITS)) {
  675. if ($i == 0) {
  676. $units = $productstatic->fk_unit;
  677. } elseif ($productstatic->fk_unit != $units) {
  678. $sameunits = false;
  679. }
  680. }
  681. print "</tr>";
  682. $i++;
  683. }
  684. $db->free($resql);
  685. // Total
  686. print '<tr class="liste_total"><td class="liste_total" colspan="2">'.$langs->trans("Total").'</td>';
  687. print '<td class="liste_total right">';
  688. $valtoshow = price2num($totalunit, 'MS');
  689. if (empty($conf->global->PRODUCT_USE_UNITS) || $sameunits) {
  690. print empty($valtoshow) ? '0' : $valtoshow;
  691. }
  692. print '</td>';
  693. print '<td class="liste_total">';
  694. if (empty($conf->global->PRODUCT_USE_UNITS) && $sameunits) {
  695. print $langs->trans($productstatic->getLabelOfUnit());
  696. }
  697. print '</td>';
  698. print '<td class="liste_total right">'.price(price2num($totalvalue, 'MT')).'</td>';
  699. if (empty($conf->global->PRODUIT_MULTIPRICES)) {
  700. print '<td class="liste_total">&nbsp;</td>';
  701. print '<td class="liste_total right">'.price(price2num($totalvaluesell, 'MT')).'</td>';
  702. }
  703. if ($user->rights->stock->mouvement->creer) {
  704. print '<td class="liste_total">&nbsp;</td>';
  705. }
  706. if ($user->rights->stock->creer) {
  707. print '<td class="liste_total">&nbsp;</td>';
  708. }
  709. print '</tr>';
  710. } else {
  711. dol_print_error($db);
  712. }
  713. print "</table>\n";
  714. }
  715. /*
  716. * Edit
  717. */
  718. if ($action == 'edit' || $action == 're-edit') {
  719. $langs->trans("WarehouseEdit");
  720. print '<form action="card.php" method="POST">';
  721. print '<input type="hidden" name="token" value="'.newToken().'">';
  722. print '<input type="hidden" name="action" value="update">';
  723. print '<input type="hidden" name="id" value="'.$object->id.'">';
  724. $head = stock_prepare_head($object);
  725. print dol_get_fiche_head($head, 'card', $langs->trans("Warehouse"), 0, 'stock');
  726. print '<table class="border centpercent">';
  727. // Ref
  728. print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("Ref").'</td><td><input name="libelle" size="20" value="'.$object->label.'"></td></tr>';
  729. print '<tr><td>'.$langs->trans("LocationSummary").'</td><td><input name="lieu" class="minwidth300" value="'.$object->lieu.'"></td></tr>';
  730. // Parent entrepot
  731. print '<tr><td>'.$langs->trans("AddIn").'</td><td>';
  732. print $formproduct->selectWarehouses($object->fk_parent, 'fk_parent', '', 1);
  733. print '</td></tr>';
  734. // Project
  735. if (!empty($conf->project->enabled)) {
  736. $projectid = $object->fk_project;
  737. $langs->load('projects');
  738. print '<tr><td>'.$langs->trans('Project').'</td><td colspan="2">';
  739. print img_picto('', 'project').$formproject->select_projects(($socid > 0 ? $socid : -1), $projectid, 'projectid', 0, 0, 1, 1, 0, 0, 0, '', 1, 0, 'maxwidth500');
  740. print ' <a href="'.DOL_URL_ROOT.'/projet/card.php?socid='.($socid > 0 ? $socid : "").'&action=create&status=1&backtopage='.urlencode($_SERVER["PHP_SELF"].'?action=create'.($socid > 0 ? '&socid='.$socid : "")).'"><span class="fa fa-plus-circle valignmiddle" title="'.$langs->trans("AddProject").'"></span></a>';
  741. print '</td></tr>';
  742. }
  743. // Description
  744. print '<tr><td class="tdtop">'.$langs->trans("Description").'</td><td>';
  745. // Editeur wysiwyg
  746. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  747. $doleditor = new DolEditor('desc', $object->description, '', 180, 'dolibarr_notes', 'In', false, true, $conf->fckeditor->enabled, ROWS_5, '90%');
  748. $doleditor->Create();
  749. print '</td></tr>';
  750. print '<tr><td>'.$langs->trans('Address').'</td><td><textarea name="address" class="quatrevingtpercent" rows="3" wrap="soft">';
  751. print $object->address;
  752. print '</textarea></td></tr>';
  753. // Zip / Town
  754. print '<tr><td>'.$langs->trans('Zip').'</td><td>';
  755. print $formcompany->select_ziptown($object->zip, 'zipcode', array('town', 'selectcountry_id', 'state_id'), 6);
  756. print '</td></tr>';
  757. print '<tr><td>'.$langs->trans('Town').'</td><td>';
  758. print $formcompany->select_ziptown($object->town, 'town', array('zipcode', 'selectcountry_id', 'state_id'));
  759. print '</td></tr>';
  760. // Country
  761. print '<tr><td>'.$langs->trans('Country').'</td><td>';
  762. print img_picto('', 'globe-americas', 'class="paddingright"');
  763. print $form->select_country($object->country_id ? $object->country_id : $mysoc->country_code, 'country_id');
  764. if ($user->admin) {
  765. print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
  766. }
  767. print '</td></tr>';
  768. // Phone / Fax
  769. print '<tr><td class="titlefieldcreate">'.$form->editfieldkey('Phone', 'phone', '', $object, 0).'</td><td>';
  770. print img_picto('', 'object_phoning', 'class="paddingright"');
  771. print '<input name="phone" size="20" value="'.$object->phone.'"></td></tr>';
  772. print '<tr><td class="titlefieldcreate">'.$form->editfieldkey('Fax', 'fax', '', $object, 0).'</td><td>';
  773. print img_picto('', 'object_phoning_fax', 'class="paddingright"');
  774. print '<input name="fax" size="20" value="'.$object->fax.'"></td></tr>';
  775. // Status
  776. print '<tr><td>'.$langs->trans("Status").'</td><td>';
  777. print '<select id="warehousestatus" name="statut" class="flat">';
  778. foreach ($object->statuts as $key => $value) {
  779. if ($key == $object->statut) {
  780. print '<option value="'.$key.'" selected>'.$langs->trans($value).'</option>';
  781. } else {
  782. print '<option value="'.$key.'">'.$langs->trans($value).'</option>';
  783. }
  784. }
  785. print '</select>';
  786. print ajax_combobox('warehousestatus');
  787. print '</td></tr>';
  788. // Other attributes
  789. $parameters = array('colspan' => ' colspan="3"', 'cols' => '3');
  790. $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  791. print $hookmanager->resPrint;
  792. if (empty($reshook)) {
  793. print $object->showOptionals($extrafields, 'edit', $parameters);
  794. }
  795. // Tags-Categories
  796. if (isModEnabled('categorie')) {
  797. print '<tr><td class="tdtop">'.$langs->trans("Categories").'</td><td colspan="3">';
  798. $cate_arbo = $form->select_all_categories(Categorie::TYPE_WAREHOUSE, '', 'parent', 64, 0, 1);
  799. $c = new Categorie($db);
  800. $cats = $c->containing($object->id, Categorie::TYPE_WAREHOUSE);
  801. $arrayselected = array();
  802. foreach ($cats as $cat) {
  803. $arrayselected[] = $cat->id;
  804. }
  805. print img_picto('', 'category').$form->multiselectarray('categories', $cate_arbo, $arrayselected, '', 0, 'quatrevingtpercent widthcentpercentminusx', 0, 0);
  806. print "</td></tr>";
  807. }
  808. print '</table>';
  809. print dol_get_fiche_end();
  810. print $form->buttonsSaveCancel();
  811. print '</form>';
  812. }
  813. }
  814. }
  815. /*
  816. * Documents generated
  817. */
  818. $modulepart = 'stock';
  819. if ($action != 'create' && $action != 'edit' && $action != 'delete') {
  820. print '<br>';
  821. print '<div class="fichecenter"><div class="fichehalfleft">';
  822. print '<a name="builddoc"></a>'; // ancre
  823. // Documents
  824. $objectref = dol_sanitizeFileName($object->ref);
  825. $relativepath = $object->ref.'/'.$objectref.'.pdf';
  826. $filedir = $conf->stock->dir_output.'/'.$objectref;
  827. $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
  828. $genallowed = $usercanread;
  829. $delallowed = $usercancreate;
  830. $modulepart = 'stock';
  831. print $formfile->showdocuments($modulepart, $objectref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 0, 0, 0, 28, 0, '', 0, '', '', '', $object);
  832. $somethingshown = $formfile->numoffiles;
  833. print '</div><div class="fichehalfright">';
  834. $MAXEVENT = 10;
  835. $morehtmlcenter = '';
  836. //$morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT.'/product/stock/agenda.php?id='.$object->id);
  837. // List of actions on element
  838. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
  839. $formactions = new FormActions($db);
  840. $somethingshown = $formactions->showactions($object, 'stock', 0, 1, '', $MAXEVENT, '', $morehtmlcenter); // Show all action for product
  841. print '</div></div>';
  842. }
  843. // End of page
  844. llxFooter();
  845. $db->close();