card.php 18 KB

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