PageRenderTime 59ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/product/inventory/card.php

http://github.com/Dolibarr/dolibarr
PHP | 487 lines | 249 code | 102 blank | 136 comment | 81 complexity | 512b6bff0fa1d552d2d95bb1301a569b MD5 | raw file
Possible License(s): GPL-2.0, AGPL-3.0, LGPL-2.0, CC-BY-SA-4.0, BSD-3-Clause, MPL-2.0-no-copyleft-exception, LGPL-3.0, GPL-3.0, LGPL-2.1, MIT
  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. require '../../main.inc.php';
  23. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  24. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/product/inventory/class/inventory.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/product/inventory/lib/inventory.lib.php';
  28. // Load translation files required by the page
  29. $langs->loadLangs(array("stocks", "other"));
  30. // Get parameters
  31. $id = GETPOST('id', 'int');
  32. $ref = GETPOST('ref', 'alpha');
  33. $action = GETPOST('action', 'aZ09');
  34. $confirm = GETPOST('confirm', 'alpha');
  35. $cancel = GETPOST('cancel', 'aZ09');
  36. $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'inventorycard'; // To manage different context of search
  37. $backtopage = GETPOST('backtopage', 'alpha');
  38. if (empty($conf->global->MAIN_USE_ADVANCED_PERMS)) {
  39. $result = restrictedArea($user, 'stock', $id);
  40. } else {
  41. $result = restrictedArea($user, 'stock', $id, '', 'inventory_advance');
  42. }
  43. // Initialize technical objects
  44. $object = new Inventory($db);
  45. $extrafields = new ExtraFields($db);
  46. // no inventory docs yet
  47. $includedocgeneration = false;
  48. $diroutputmassaction = null;
  49. // $diroutputmassaction = $conf->stock->dir_output.'/temp/massgeneration/'.$user->id;
  50. $hookmanager->initHooks(array('inventorycard', 'globalcard')); // Note that conf->hooks_modules contains array
  51. // Fetch optionals attributes and labels
  52. $extrafields->fetch_name_optionals_label($object->table_element);
  53. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  54. // Initialize array of search criterias
  55. $search_all = GETPOST("search_all", 'alpha');
  56. $search = array();
  57. foreach ($object->fields as $key => $val) {
  58. if (GETPOST('search_'.$key, 'alpha')) {
  59. $search[$key] = GETPOST('search_'.$key, 'alpha');
  60. }
  61. }
  62. if (empty($action) && empty($id) && empty($ref)) {
  63. $action = 'view';
  64. }
  65. // Load object
  66. include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
  67. // Security check - Protection if external user
  68. //if ($user->socid > 0) accessforbidden();
  69. //if ($user->socid > 0) $socid = $user->socid;
  70. //$result = restrictedArea($user, 'mymodule', $id);
  71. if (empty($conf->global->MAIN_USE_ADVANCED_PERMS)) {
  72. $permissiontoread = $user->rights->stock->lire;
  73. $permissiontoadd = $user->rights->stock->creer;
  74. $permissiontodelete = $user->rights->stock->supprimer;
  75. $permissionnote = $user->rights->stock->creer; // Used by the include of actions_setnotes.inc.php
  76. $permissiondellink = $user->rights->stock->creer; // Used by the include of actions_dellink.inc.php
  77. $upload_dir = $conf->stock->multidir_output[isset($object->entity) ? $object->entity : 1];
  78. } else {
  79. $permissiontoread = $user->rights->stock->inventory_advance->read;
  80. $permissiontoadd = $user->rights->stock->inventory_advance->write;
  81. $permissiontodelete = $user->rights->stock->inventory_advance->write;
  82. $permissionnote = $user->rights->stock->inventory_advance->write; // Used by the include of actions_setnotes.inc.php
  83. $permissiondellink = $user->rights->stock->inventory_advance->write; // Used by the include of actions_dellink.inc.php
  84. $upload_dir = $conf->stock->multidir_output[isset($object->entity) ? $object->entity : 1];
  85. }
  86. /*
  87. * Actions
  88. */
  89. $parameters = array();
  90. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  91. if ($reshook < 0) {
  92. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  93. }
  94. if (empty($reshook)) {
  95. $error = 0;
  96. $backurlforlist = DOL_URL_ROOT.'/product/inventory/list.php';
  97. if (empty($backtopage) || ($cancel && empty($id))) {
  98. if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
  99. if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
  100. $backtopage = $backurlforlist;
  101. } else {
  102. $backtopage = dol_buildpath('/product/inventory/card.php', 1).'?id='.($id > 0 ? $id : '__ID__');
  103. }
  104. }
  105. }
  106. $triggermodname = 'STOCK_INVENTORY_MODIFY'; // Name of trigger action code to execute when we modify record
  107. // Actions cancel, add, update, update_extras, confirm_validate, confirm_delete, confirm_deleteline, confirm_clone, confirm_close, confirm_setdraft, confirm_reopen
  108. include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php';
  109. // Actions when linking object each other
  110. include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php';
  111. // Actions when printing a doc from card
  112. include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
  113. // Action to move up and down lines of object
  114. //include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php';
  115. // Action to build doc
  116. include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
  117. /*if ($action == 'set_thirdparty' && $permissiontoadd)
  118. {
  119. $object->setValueFrom('fk_soc', GETPOST('fk_soc', 'int'), '', '', 'date', '', $user, 'MYOBJECT_MODIFY');
  120. }*/
  121. if ($action == 'classin' && $permissiontoadd) {
  122. $object->setProject(GETPOST('projectid', 'int'));
  123. }
  124. // Actions to send emails
  125. $triggersendname = 'INVENTORY_SENTBYMAIL';
  126. $autocopy = 'MAIN_MAIL_AUTOCOPY_INVENTORY_TO';
  127. $trackid = 'stockinv'.$object->id;
  128. include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
  129. }
  130. /*
  131. * View
  132. */
  133. $form = new Form($db);
  134. $formfile = new FormFile($db);
  135. $formproject = new FormProjets($db);
  136. $title = $langs->trans("Inventory");
  137. $help_url = 'EN:Module_Stocks_En|FR:Module_Stock|ES:Módulo_Stocks|DE:Modul_Bestände';
  138. llxHeader('', $title, $help_url);
  139. // Part to create
  140. if ($action == 'create') {
  141. print load_fiche_titre($langs->trans("NewInventory"), '', 'product');
  142. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  143. print '<input type="hidden" name="token" value="'.newToken().'">';
  144. print '<input type="hidden" name="action" value="add">';
  145. if ($backtopage) {
  146. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  147. }
  148. if (!empty($backtopageforcancel)) {
  149. print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
  150. }
  151. print dol_get_fiche_head(array(), '');
  152. // Set some default values
  153. //if (! GETPOSTISSET('fieldname')) $_POST['fieldname'] = 'myvalue';
  154. print '<table class="border centpercent tableforfieldcreate">'."\n";
  155. // Common attributes
  156. include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_add.tpl.php';
  157. // Other attributes
  158. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
  159. print '</table>'."\n";
  160. print dol_get_fiche_end();
  161. print $form->buttonsSaveCancel("Create");
  162. print '</form>';
  163. dol_set_focus('input[name="ref"]');
  164. }
  165. // Part to edit record
  166. if (($id || $ref) && $action == 'edit') {
  167. print load_fiche_titre($langs->trans("Inventory"), '', 'product');
  168. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  169. print '<input type="hidden" name="token" value="'.newToken().'">';
  170. print '<input type="hidden" name="action" value="update">';
  171. print '<input type="hidden" name="id" value="'.$object->id.'">';
  172. if ($backtopage) {
  173. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  174. }
  175. if ($backtopageforcancel) {
  176. print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
  177. }
  178. print dol_get_fiche_head();
  179. print '<table class="border centpercent tableforfieldedit">'."\n";
  180. // Common attributes
  181. include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_edit.tpl.php';
  182. // Other attributes
  183. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php';
  184. print '</table>';
  185. print dol_get_fiche_end();
  186. print $form->buttonsSaveCancel();
  187. print '</form>';
  188. }
  189. // Part to show record
  190. if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
  191. $res = $object->fetch_optionals();
  192. $head = inventoryPrepareHead($object);
  193. print dol_get_fiche_head($head, 'card', $langs->trans("Inventory"), -1, 'stock');
  194. $formconfirm = '';
  195. // Confirmation to delete
  196. if ($action == 'delete') {
  197. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteInventory'), $langs->trans('ConfirmDeleteObject'), 'confirm_delete', '', 0, 1);
  198. }
  199. // Clone confirmation
  200. if ($action == 'clone') {
  201. // Create an array for form
  202. $formquestion = array();
  203. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneAsk', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);
  204. }
  205. // Confirmation of action xxxx
  206. if ($action == 'xxx') {
  207. $formquestion = array();
  208. /*
  209. $forcecombo=0;
  210. if ($conf->browser->name == 'ie') $forcecombo = 1; // There is a bug in IE10 that make combo inside popup crazy
  211. $formquestion = array(
  212. // 'text' => $langs->trans("ConfirmClone"),
  213. // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
  214. // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
  215. // array('type' => 'other', 'name' => 'idwarehouse', 'label' => $langs->trans("SelectWarehouseForStockDecrease"), 'value' => $formproduct->selectWarehouses(GETPOST('idwarehouse')?GETPOST('idwarehouse'):'ifone', 'idwarehouse', '', 1, 0, 0, '', 0, $forcecombo))
  216. );
  217. */
  218. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('XXX'), $text, 'confirm_xxx', $formquestion, 0, 1, 220);
  219. }
  220. // Call Hook formConfirm
  221. $parameters = array('formConfirm' => $formconfirm);
  222. $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  223. if (empty($reshook)) {
  224. $formconfirm .= $hookmanager->resPrint;
  225. } elseif ($reshook > 0) {
  226. $formconfirm = $hookmanager->resPrint;
  227. }
  228. // Print form confirm
  229. print $formconfirm;
  230. // Object card
  231. // ------------------------------------------------------------
  232. $linkback = '<a href="'.DOL_URL_ROOT.'/product/inventory/list.php'.(!empty($socid) ? '?socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  233. $morehtmlref = '<div class="refidno">';
  234. /*
  235. // Ref bis
  236. $morehtmlref.=$form->editfieldkey("RefBis", 'ref_client', $object->ref_client, $object, $user->rights->inventory->creer, 'string', '', 0, 1);
  237. $morehtmlref.=$form->editfieldval("RefBis", 'ref_client', $object->ref_client, $object, $user->rights->inventory->creer, 'string', '', null, null, '', 1);
  238. // Thirdparty
  239. $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $soc->getNomUrl(1);
  240. // Project
  241. if (! empty($conf->projet->enabled))
  242. {
  243. $langs->load("projects");
  244. $morehtmlref.='<br>'.$langs->trans('Project') . ' ';
  245. if ($permissiontoadd)
  246. {
  247. if ($action != 'classify')
  248. {
  249. $morehtmlref .= '<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token='.newToken().'&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
  250. if ($action == 'classify') {
  251. //$morehtmlref .= $form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
  252. $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
  253. $morehtmlref .= '<input type="hidden" name="action" value="classin">';
  254. $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
  255. $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
  256. $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
  257. $morehtmlref .= '</form>';
  258. } else {
  259. $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
  260. }
  261. }
  262. } else {
  263. if (! empty($object->fk_project)) {
  264. $proj = new Project($db);
  265. $proj->fetch($object->fk_project);
  266. $morehtmlref .= $proj->getNomUrl();
  267. } else {
  268. $morehtmlref.='';
  269. }
  270. }
  271. }
  272. */
  273. $morehtmlref .= '</div>';
  274. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  275. print '<div class="fichecenter">';
  276. print '<div class="fichehalfleft">';
  277. print '<div class="underbanner clearboth"></div>';
  278. print '<table class="border centpercent tableforfield">'."\n";
  279. // Common attributes
  280. include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_view.tpl.php';
  281. // Other attributes. Fields from hook formObjectOptions and Extrafields.
  282. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
  283. print '</table>';
  284. print '</div>';
  285. print '</div>';
  286. print '<div class="clearboth"></div>';
  287. print dol_get_fiche_end();
  288. // Buttons for actions
  289. if ($action != 'presend' && $action != 'editline') {
  290. print '<div class="tabsAction">'."\n";
  291. $parameters = array();
  292. $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  293. if ($reshook < 0) {
  294. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  295. }
  296. if (empty($reshook)) {
  297. // Send
  298. if (empty($user->socid)) {
  299. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=presend&mode=init&token='.newToken().'#formmailbeforetitle">'.$langs->trans('SendMail').'</a>'."\n";
  300. }
  301. // Back to draft
  302. if ($object->status == $object::STATUS_VALIDATED) {
  303. if ($permissiontoadd) {
  304. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=confirm_setdraft&confirm=yes&token='.newToken().'">'.$langs->trans("SetToDraft").'</a>';
  305. }
  306. }
  307. // Back to validate
  308. if ($object->status == $object::STATUS_RECORDED) {
  309. if ($permissiontoadd) {
  310. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=confirm_validate&confirm=yes&token='.newToken().'">'.$langs->trans("ReOpen").'</a>';
  311. }
  312. }
  313. // Modify
  314. if ($object->status == $object::STATUS_DRAFT) {
  315. if ($permissiontoadd) {
  316. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit&token='.newToken().'">'.$langs->trans("Modify").'</a>'."\n";
  317. } else {
  318. print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans('Modify').'</a>'."\n";
  319. }
  320. }
  321. // Validate
  322. if ($object->status == $object::STATUS_DRAFT || $object->status == $object::STATUS_CANCELED) {
  323. if ($permissiontoadd) {
  324. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=confirm_validate&confirm=yes&token='.newToken().'">'.$langs->trans("Validate").' ('.$langs->trans("Start").')</a>';
  325. }
  326. }
  327. // Clone
  328. /*if ($permissiontoadd)
  329. {
  330. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&socid='.$object->socid.'&action=clone&object=myobject">'.$langs->trans("ToClone").'</a>'."\n";
  331. }*/
  332. // Delete (need delete permission, or if draft, just need create/modify permission)
  333. if ($permissiontodelete || ($object->status == $object::STATUS_DRAFT && $permissiontoadd)) {
  334. print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken().'">'.$langs->trans('Delete').'</a>'."\n";
  335. } else {
  336. print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans('Delete').'</a>'."\n";
  337. }
  338. }
  339. print '</div>'."\n";
  340. }
  341. // Select mail models is same action as presend
  342. if (GETPOST('modelselected')) {
  343. $action = 'presend';
  344. }
  345. if ($action != 'presend') {
  346. print '<div class="fichecenter"><div class="fichehalfleft">';
  347. print '<a name="builddoc"></a>'; // ancre
  348. // Documents
  349. if ($includedocgeneration) {
  350. $objref = dol_sanitizeFileName($object->ref);
  351. $relativepath = $objref.'/'.$objref.'.pdf';
  352. $filedir = $conf->mymodule->dir_output.'/'.$object->element.'/'.$objref;
  353. $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
  354. $genallowed = $user->rights->mymodule->myobject->read; // If you can read, you can build the PDF to read content
  355. $delallowed = $user->rights->mymodule->myobject->write; // If you can create/edit, you can remove a file on card
  356. print $formfile->showdocuments('mymodule:MyObject', $object->element.'/'.$objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $langs->defaultlang);
  357. }
  358. // Show links to link elements
  359. $linktoelem = $form->showLinkToObjectBlock($object, null, array('inventory'));
  360. $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
  361. print '</div><div class="fichehalfright">';
  362. $MAXEVENT = 10;
  363. $morehtmlright = '<a href="'.dol_buildpath('/product/inventory/inventory_info.php', 1).'?id='.$object->id.'">';
  364. $morehtmlright .= $langs->trans("SeeAll");
  365. $morehtmlright .= '</a>';
  366. // List of actions on element
  367. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
  368. $formactions = new FormActions($db);
  369. $somethingshown = $formactions->showactions($object, $object->element, 0, 1, '', $MAXEVENT, '', $morehtmlright);
  370. print '</div></div>';
  371. }
  372. //Select mail models is same action as presend
  373. if (GETPOST('modelselected')) {
  374. $action = 'presend';
  375. }
  376. // Presend form
  377. $modelmail = 'inventory';
  378. $defaulttopic = 'InformationMessage';
  379. $diroutput = $conf->product->dir_output.'/inventory';
  380. $trackid = 'stockinv'.$object->id;
  381. include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
  382. }
  383. // End of page
  384. llxFooter();
  385. $db->close();