card.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  1. <?php
  2. /* Copyright (C) 2007-2017 Laurent Destailleur <eldy@users.sourceforge.net>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. */
  17. /**
  18. * \file htdocs/product/inventory/card.php
  19. * \ingroup inventory
  20. * \brief Inventory card
  21. */
  22. // Load Dolibarr environment
  23. require '../../main.inc.php';
  24. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formcompany.class.php';
  25. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php';
  26. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formprojet.class.php';
  27. require_once DOL_DOCUMENT_ROOT . '/product/inventory/class/inventory.class.php';
  28. require_once DOL_DOCUMENT_ROOT . '/product/inventory/lib/inventory.lib.php';
  29. require_once DOL_DOCUMENT_ROOT . '/custom/rollerstorage/class/statuses.class.php';
  30. // Load translation files required by the page
  31. $langs->loadLangs(array("stocks", "other"));
  32. // Get parameters
  33. $id = GETPOST('id', 'int');
  34. $ref = GETPOST('ref', 'alpha');
  35. $action = GETPOST('action', 'aZ09');
  36. $confirm = GETPOST('confirm', 'alpha');
  37. $cancel = GETPOST('cancel', 'aZ09');
  38. $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'inventorycard'; // To manage different context of search
  39. $backtopage = GETPOST('backtopage', 'alpha');
  40. $warehouseFrom = GETPOST('warehouse_from', 'int') ? GETPOST('warehouse_from', 'int') : null;
  41. $statusFrom = GETPOST('status_from', 'int') ? GETPOST('status_from', 'int') : null;
  42. $inventory_id = GETPOST('inventory_id', 'int') ? GETPOST('inventory_id', 'int') : null;
  43. $idmenu = GETPOST('idmenu', 'int');
  44. /* $cancelbackpage = $backtopage;
  45. $cancelbackpage .= !$inventory_id ? '?' : '&';
  46. $cancelbackpage .= 'idmenu=' . $idmenu . '&leftmenu='; */
  47. /* if (empty($conf->global->MAIN_USE_ADVANCED_PERMS)) {
  48. $result = restrictedArea($user, 'stock', $id);
  49. } else {
  50. $result = restrictedArea($user, 'stock', $id, '', 'inventory_advance');
  51. } */
  52. // Initialize technical objects
  53. $object = new Inventory($db);
  54. $extrafields = new ExtraFields($db);
  55. $stasusesObj = new Statuses($db);
  56. // no inventory docs yet
  57. $includedocgeneration = false;
  58. $diroutputmassaction = null;
  59. // $diroutputmassaction = $conf->stock->dir_output.'/temp/massgeneration/'.$user->id;
  60. $hookmanager->initHooks(array('inventorycard', 'globalcard')); // Note that conf->hooks_modules contains array
  61. // Fetch optionals attributes and labels
  62. $extrafields->fetch_name_optionals_label($object->table_element);
  63. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  64. // Initialize array of search criterias
  65. $search_all = GETPOST("search_all", 'alpha');
  66. $search = array();
  67. foreach ($object->fields as $key => $val) {
  68. if (GETPOST('search_' . $key, 'alpha')) {
  69. $search[$key] = GETPOST('search_' . $key, 'alpha');
  70. }
  71. }
  72. if (empty($action) && empty($id) && empty($ref)) {
  73. $action = 'view';
  74. }
  75. // Load object
  76. include DOL_DOCUMENT_ROOT . '/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
  77. // Security check - Protection if external user
  78. //if ($user->socid > 0) accessforbidden();
  79. //if ($user->socid > 0) $socid = $user->socid;
  80. //$result = restrictedArea($user, 'mymodule', $id);
  81. if (empty($conf->global->MAIN_USE_ADVANCED_PERMS)) {
  82. //$permissiontoread = $user->rights->stock->lire;
  83. //$permissiontoadd = $user->rights->stock->creer;
  84. //$permissiontodelete = $user->rights->stock->supprimer;
  85. $read = 'read_' . $inventory_id;
  86. $write = 'write_' . $inventory_id;
  87. $delete = 'delete_' . $inventory_id;
  88. $permissiontoread = $user->rights->rollerstorage->rollerhistory->$read;
  89. $permissiontoadd = $user->rights->rollerstorage->rollerhistory->$write;
  90. $permissiontodelete = $user->rights->rollerstorage->rollerhistory->$delete;
  91. /* $permissiontoread = $user->rights->rollerstorage->rollerhistory->read;
  92. $permissiontoadd = $user->rights->rollerstorage->rollerhistory->write;
  93. $permissiontodelete = $user->rights->rollerstorage->rollerhistory->delete; */
  94. //$permissionnote = $user->rights->stock->creer; // Used by the include of actions_setnotes.inc.php
  95. //$permissiondellink = $user->rights->stock->creer; // Used by the include of actions_dellink.inc.php
  96. $permissionnote = $user->rights->rollerstorage->rollerhistory->write; // Used by the include of actions_setnotes.inc.php
  97. $permissiondellink = $user->rights->rollerstorage->rollerhistory->write; // Used by the include of actions_dellink.inc.php
  98. $upload_dir = $conf->stock->multidir_output[isset($object->entity) ? $object->entity : 1];
  99. } else {
  100. $permissiontoread = $user->rights->stock->inventory_advance->read;
  101. $permissiontoadd = $user->rights->stock->inventory_advance->write;
  102. $permissiontodelete = $user->rights->stock->inventory_advance->write;
  103. $permissionnote = $user->rights->stock->inventory_advance->write; // Used by the include of actions_setnotes.inc.php
  104. $permissiondellink = $user->rights->stock->inventory_advance->write; // Used by the include of actions_dellink.inc.php
  105. $upload_dir = $conf->stock->multidir_output[isset($object->entity) ? $object->entity : 1];
  106. }
  107. /* if($action == 'list'){
  108. header("Location: " . DOL_URL_ROOT . '/custom/rollerstorage/card.php?id=1');
  109. } */
  110. /*
  111. * Actions
  112. */
  113. if (!is_null($warehouseFrom)) {
  114. $object->egyebAdatok = array("warehouse_from" => $warehouseFrom, "status_from" => $statusFrom);
  115. }
  116. $parameters = array();
  117. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  118. if ($reshook < 0) {
  119. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  120. }
  121. if (empty($reshook)) {
  122. $savaction = $action;
  123. $error = 0;
  124. $backurlforlist = DOL_URL_ROOT . '/custom/rollerstorage/rollerstorageindex.php';
  125. if (empty($backtopage) || ($cancel && empty($id))) {
  126. if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
  127. if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
  128. $backtopage = $backurlforlist;
  129. } else {
  130. $backtopage = dol_buildpath('/custom/rollerstorage/card.php', 1) . '?id=' . ($id > 0 ? $id : '__ID__');
  131. }
  132. }
  133. }
  134. $triggermodname = 'STOCK_INVENTORY_MODIFY'; // Name of trigger action code to execute when we modify record
  135. // Actions cancel, add, update, update_extras, confirm_validate, confirm_delete, confirm_deleteline, confirm_clone, confirm_close, confirm_setdraft, confirm_reopen
  136. include DOL_DOCUMENT_ROOT . '/custom/rollerstorage/actions_addupdatedelete.inc.php';
  137. // Actions when linking object each other
  138. include DOL_DOCUMENT_ROOT . '/core/actions_dellink.inc.php';
  139. // Actions when printing a doc from card
  140. include DOL_DOCUMENT_ROOT . '/core/actions_printing.inc.php';
  141. // Action to move up and down lines of object
  142. //include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php';
  143. // Action to build doc
  144. include DOL_DOCUMENT_ROOT . '/core/actions_builddoc.inc.php';
  145. /*if ($action == 'set_thirdparty' && $permissiontoadd)
  146. {
  147. $object->setValueFrom('fk_soc', GETPOST('fk_soc', 'int'), '', '', 'date', '', $user, 'MYOBJECT_MODIFY');
  148. }*/
  149. if ($action == 'classin' && $permissiontoadd) {
  150. $object->setProject(GETPOST('projectid', 'int'));
  151. }
  152. // Actions to send emails
  153. $triggersendname = 'INVENTORY_SENTBYMAIL';
  154. $autocopy = 'MAIN_MAIL_AUTOCOPY_INVENTORY_TO';
  155. $trackid = 'stockinv' . $object->id;
  156. include DOL_DOCUMENT_ROOT . '/core/actions_sendmails.inc.php';
  157. if (!$error && $savaction == 'confirm_validate' && $action == '' && $object->id > 0) {
  158. // Switch to the tab inventory
  159. header("Location: " . DOL_URL_ROOT . '/product/inventory/inventory.php?id=' . $object->id);
  160. exit;
  161. }
  162. }
  163. /*
  164. * View
  165. */
  166. $form = new Form($db);
  167. $formfile = new FormFile($db);
  168. $formproject = new FormProjets($db);
  169. $title = $langs->trans("Inventory");
  170. $help_url = 'EN:Module_Stocks_En|FR:Module_Stock|ES:Módulo_Stocks|DE:Modul_Bestände';
  171. llxHeader('', $title, $help_url);
  172. // Part to create
  173. if ($action == 'create') {
  174. print load_fiche_titre($langs->trans("NewInventory"), '', 'product');
  175. print '<form method="POST" action="' . $_SERVER["PHP_SELF"] . '?inventory_id='.$inventory_id.'">';
  176. print '<input type="hidden" name="token" value="' . newToken() . '">';
  177. print '<input type="hidden" name="action" value="add">';
  178. if ($backtopage) {
  179. print '<input type="hidden" name="backtopage" value="' . $backtopage . '">';
  180. }
  181. if (!empty($backtopageforcancel)) {
  182. print '<input type="hidden" name="backtopageforcancel" value="' . $backtopageforcancel . '">';
  183. }
  184. print dol_get_fiche_head(array(), '');
  185. print '<table class="border centpercent tableforfieldcreate">' . "\n";
  186. // Common attributes
  187. //include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_add.tpl.php';
  188. include DOL_DOCUMENT_ROOT . '/custom/rollerstorage/tpl/commonfields_add.tpl.php';
  189. // Other attributes
  190. include DOL_DOCUMENT_ROOT . '/custom/rollerstorage/tpl/extrafields_add.tpl.php';
  191. //print '<tr><td class="titlefield fieldname_invcode">'.$langs->trans("InventoryCode").'</td><td>INV'.$object->id.'</td></tr>';
  192. print '</table>' . "\n";
  193. print dol_get_fiche_end();
  194. //print $form->buttonsSaveCancel("Create");
  195. print '<div class="center">';
  196. print '<input type="submit" class="button button-add " name="add" value="' . $langs->trans('Create') . '">';
  197. print '<a class="button button-cancel" href="/custom/rollerstorage/rollerstorageinventoryindex.php?inventory_id='.$inventory_id.'">' . $langs->trans('Cancel') . '</a>';
  198. print '</div>';
  199. print '</form>';
  200. dol_set_focus('input[name="ref"]');
  201. }
  202. // Part to edit record
  203. if (($id || $ref) && $action == 'edit') {
  204. if($permissiontoadd){
  205. $href = $backtopage . '&inventory_id='.$inventory_id;
  206. $backtopageforMegsem = '&backtopage=/custom/rollerstorage/rollerstorageinventoryindex.php?inventory_id=' .$inventory_id;
  207. $href .= $backtopageforMegsem;
  208. //$backtopage .= '&inventory_id='.$inventory_id;
  209. print load_fiche_titre($langs->trans("Inventory"), '', 'product');
  210. print '<form method="POST" action="' . $_SERVER["PHP_SELF"] . '?id='.$object->id.'&inventory_id='.$inventory_id.'">';
  211. print '<input type="hidden" name="token" value="' . newToken() . '">';
  212. print '<input type="hidden" name="action" value="update">';
  213. print '<input type="hidden" name="id" value="' . $object->id . '">';
  214. if ($backtopage) {
  215. print '<input type="hidden" name="backtopage" value="' . $href . '">';
  216. }
  217. if ($backtopageforcancel) {
  218. print '<input type="hidden" name="backtopageforcancel" value="' . $backtopageforcancel . '">';
  219. }
  220. $statuses2 = new Statuses($db);
  221. $status_id_from_statuses = $statuses2->getRowIdFromStatusId($db, $object->status);
  222. print '<input type="hidden" name="warehouse_from" value="' . $object->fk_warehouse . '">';
  223. print '<input type="hidden" name="status_from" value="' . $status_id_from_statuses . '">';
  224. print dol_get_fiche_head();
  225. print '<table class="border centpercent tableforfieldedit">' . "\n";
  226. // Common attributes
  227. //include DOL_DOCUMENT_ROOT . '/core/tpl/commonfields_edit.tpl.php';
  228. include DOL_DOCUMENT_ROOT . '/custom/rollerstorage/tpl/commonfields_edit.tpl.php';
  229. // Other attributes
  230. include DOL_DOCUMENT_ROOT . '/custom/rollerstorage/tpl/extrafields_edit.tpl.php';
  231. print '</table>';
  232. print dol_get_fiche_end();
  233. //print $form->buttonsSaveCancel();
  234. print '<div class="center">';
  235. print '<input type="submit" class="button button-save " name="save" value="' . $langs->trans('Save') . '">';
  236. print '<a class="button button-cancel" href="'.$href.'">' . $langs->trans('Cancel') . '</a>';
  237. print '</div>';
  238. print '</form>';
  239. } else{
  240. print '<div class="error">Hozzáférés megtagadva.<br>Egy letiltott modul oldalához, területéhez vagy szolgáltatásához próbál hozzáférni, vagy anélkül, hogy hitelesített munkamenetben lenne, vagy amely nem engedélyezett a felhasználó számára.</div>';
  241. }
  242. }
  243. // Part to show record
  244. if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
  245. $res = $object->fetch_optionals();
  246. $tabs = array(
  247. array(dol_buildpath('/custom/rollerstorage/card.php?id=' . $object->id . $get . '&inventory_id='.$inventory_id.'&backtopage=' . $backtopage, 1), $langs->trans('Roller'), 'roller'),
  248. array(dol_buildpath('/custom/rollerstorage/rollerhistory_list.php?id=' . $object->id . $get . '&inventory_id='.$inventory_id . '&backtopage=' . $backtopage, 1), $langs->trans('Rollerhistory'), 'rollerhistory')
  249. );
  250. $head = $tabs;
  251. //$head = inventoryPrepareHead($object);
  252. //$head[] = array(' /custom/rollerstorage/card.php?id=' . $object->id, $object->ref, 'card');
  253. //print_r($head);
  254. print dol_get_fiche_head($head, 'roller', $langs->trans("Roller"), -1, 'stock');
  255. $formconfirm = '';
  256. // Confirmation to delete
  257. if ($action == 'delete') {
  258. $backtopage .= '?id=' . $object->id . '&inventory_id=' . $inventory_id;
  259. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id. '&inventory_id='.$inventory_id.'&backtopage=' . $backtopage, $langs->trans('DeleteInventory'), $langs->trans('ConfirmDeleteObject'), 'confirm_delete', '', 0, 1);
  260. }
  261. // Confirmation of action xxxx
  262. if ($action == 'xxx') {
  263. $formquestion = array();
  264. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('XXX'), $text, 'confirm_xxx', $formquestion, 0, 1, 220);
  265. }
  266. // Call Hook formConfirm
  267. $parameters = array('formConfirm' => $formconfirm);
  268. $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  269. if (empty($reshook)) {
  270. $formconfirm .= $hookmanager->resPrint;
  271. } elseif ($reshook > 0) {
  272. $formconfirm = $hookmanager->resPrint;
  273. }
  274. // Print form confirm
  275. print $formconfirm;
  276. // Object card
  277. // ------------------------------------------------------------
  278. $linkback = '<a href="' . DOL_URL_ROOT . $backtopage . (!empty($socid) ? '?socid=' . $socid : '') . '">' . $langs->trans("BackToList") . '</a>';
  279. $morehtmlref = '<div class="refidno">';
  280. $morehtmlref .= '</div>';
  281. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  282. print '<div class="fichecenter">';
  283. print '<div class="fichehalfleft">';
  284. print '<div class="underbanner clearboth"></div>';
  285. print '<table class="border centpercent tableforfield">' . "\n";
  286. // Common attributes
  287. include DOL_DOCUMENT_ROOT . '/custom/rollerstorage/tpl/commonfields_view.tpl.php';
  288. // Other attributes. Fields from hook formObjectOptions and Extrafields.
  289. include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
  290. print '</table>';
  291. print '</div>';
  292. print '</div>';
  293. print '<div class="clearboth"></div>';
  294. print dol_get_fiche_end();
  295. // Buttons for actions
  296. if ($action != 'presend' && $action != 'editline') {
  297. print '<div class="tabsAction">' . "\n";
  298. $parameters = array();
  299. $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  300. if ($reshook < 0) {
  301. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  302. }
  303. if (empty($reshook)) {
  304. // Modify
  305. $backtopage = '/custom/rollerstorage/card.php?id=' .$object->id. '&inventory_id='.$inventory_id;
  306. if ($permissiontoadd) {
  307. print '<a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&backtopage='.$backtopage.'&action=edit&token=' . newToken() . '">' . $langs->trans("Modify") . '</a>' . "\n";
  308. } else {
  309. print '<a class="butActionRefused classfortooltip" href="#" title="' . dol_escape_htmltag($langs->trans("NotEnoughPermissions")) . '">' . $langs->trans('Modify') . '</a>' . "\n";
  310. }
  311. // Delete
  312. print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&inventory_id=' . $inventory_id . '&backtopage=' . $backurlforlist. '&action=delete&token=' . newToken(), 'delete', $permissiontodelete);
  313. }
  314. print '</div>' . "\n";
  315. }
  316. // Select mail models is same action as presend
  317. if (GETPOST('modelselected')) {
  318. $action = 'presend';
  319. }
  320. if ($action != 'presend') {
  321. print '<div class="fichecenter"><div class="fichehalfleft">';
  322. print '<a name="builddoc"></a>'; // ancre
  323. // Documents
  324. if ($includedocgeneration) {
  325. $objref = dol_sanitizeFileName($object->ref);
  326. $relativepath = $objref . '/' . $objref . '.pdf';
  327. $filedir = $conf->mymodule->dir_output . '/' . $object->element . '/' . $objref;
  328. $urlsource = $_SERVER["PHP_SELF"] . "?id=" . $object->id;
  329. $genallowed = $user->rights->mymodule->myobject->read; // If you can read, you can build the PDF to read content
  330. $delallowed = $user->rights->mymodule->myobject->write; // If you can create/edit, you can remove a file on card
  331. print $formfile->showdocuments('mymodule:MyObject', $object->element . '/' . $objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $langs->defaultlang);
  332. }
  333. // Show links to link elements
  334. $linktoelem = $form->showLinkToObjectBlock($object, null, array('inventory'));
  335. //$somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
  336. print '</div><div class="fichehalfright">';
  337. $MAXEVENT = 10;
  338. //$morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT.'/product/inventory/inventory_info.php?id='.$object->id);
  339. $morehtmlcenter = '';
  340. // List of actions on element
  341. //include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
  342. //$formactions = new FormActions($db);
  343. //$somethingshown = $formactions->showactions($object, $object->element, 0, 1, '', $MAXEVENT, '', $morehtmlcenter);
  344. print '</div></div>';
  345. }
  346. //Select mail models is same action as presend
  347. if (GETPOST('modelselected')) {
  348. $action = 'presend';
  349. }
  350. // Presend form
  351. $modelmail = 'inventory';
  352. $defaulttopic = 'InformationMessage';
  353. $diroutput = $conf->product->dir_output . '/inventory';
  354. $trackid = 'stockinv' . $object->id;
  355. include DOL_DOCUMENT_ROOT . '/core/tpl/card_presend.tpl.php';
  356. include DOL_DOCUMENT_ROOT . '/custom/rollerstorage/tpl/rollerhistory.tpl.php';
  357. }
  358. // End of page
  359. llxFooter();
  360. $db->close();