productlot_document.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. <?php
  2. /* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
  5. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  6. * Copyright (C) 2005 Simon TOSSER <simon@kornog-computing.com>
  7. * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
  8. * Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
  9. * Copyright (C) 2017 Ferran Marcet <fmarcet@2byte.es>
  10. * Copyright (C) 2018 All-3kcis <contact@all-3kcis.fr>
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 3 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  24. */
  25. /**
  26. * \file htdocs/product/stock/productlot_document.php
  27. * \ingroup product
  28. * \brief Page of attached documents for product lots
  29. */
  30. // Load Dolibarr environment
  31. require '../../main.inc.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
  33. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
  36. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  37. require_once DOL_DOCUMENT_ROOT.'/product/stock/class/productlot.class.php';
  38. global $conf, $db, $langs, $user;
  39. // Load translation files required by the page
  40. $langs->loadLangs(array('other', 'products'));
  41. $id = GETPOST('id', 'int');
  42. $ref = GETPOST('ref', 'alpha');
  43. $action = GETPOST('action', 'aZ09');
  44. $confirm = GETPOST('confirm', 'alpha');
  45. // Security check
  46. $fieldvalue = (!empty($id) ? $id : '');
  47. $fieldtype = 'rowid';
  48. if ($user->socid) {
  49. $socid = $user->socid;
  50. }
  51. $result = restrictedArea($user, 'produit|service');
  52. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  53. $hookmanager->initHooks(array('productlotdocuments'));
  54. // Get parameters
  55. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  56. $sortfield = GETPOST('sortfield', 'aZ09comma');
  57. $sortorder = GETPOST('sortorder', 'aZ09comma');
  58. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  59. if (empty($page) || $page == -1) {
  60. $page = 0;
  61. } // If $page is not defined, or '' or -1
  62. $offset = $limit * $page;
  63. $pageprev = $page - 1;
  64. $pagenext = $page + 1;
  65. if (!$sortorder) {
  66. $sortorder = "ASC";
  67. }
  68. if (!$sortfield) {
  69. $sortfield = "position_name";
  70. }
  71. $modulepart = 'product_batch';
  72. $object = new Productlot($db);
  73. if ($id || $ref) {
  74. if ($ref) {
  75. $tmp = explode('_', $ref);
  76. $productid = $tmp[0];
  77. $batch = $tmp[1];
  78. }
  79. $object->fetch($id, $productid, $batch);
  80. $object->ref = $object->batch; // Old system for document management ( it uses $object->ref)
  81. if (isModEnabled('productbatch')) {
  82. $upload_dir = $conf->productbatch->multidir_output[$object->entity].'/'.get_exdir(0, 0, 0, 1, $object, $modulepart);
  83. $filearray = dol_dir_list($upload_dir, "files");
  84. if (empty($filearray)) {
  85. // If no files linked yet, use new system on lot id. (Batch is not unique and can be same on different product)
  86. $object->fetch($id, $productid, $batch);
  87. $upload_dir = $conf->productbatch->multidir_output[$object->entity].'/'.get_exdir(0, 0, 0, 1, $object, $modulepart);
  88. }
  89. }
  90. }
  91. $usercanread = $user->hasRight('produit', 'lire');
  92. $usercancreate = $user->hasRight('produit', 'creer');
  93. $usercandelete = $user->hasRight('produit', 'supprimer');
  94. if (empty($upload_dir)) {
  95. $upload_dir = $conf->productbatch->multidir_output[$conf->entity];
  96. }
  97. $permissiontoread = $usercanread;
  98. $permissiontoadd = $usercancreate;
  99. $permtoedit = $user->rights->produit->creer;
  100. //$permissiontodelete = $usercandelete;
  101. // Security check
  102. if (!isModEnabled('productbatch')) {
  103. accessforbidden('Module not enabled');
  104. }
  105. $socid = 0;
  106. if ($user->socid > 0) { // Protection if external user
  107. //$socid = $user->socid;
  108. accessforbidden();
  109. }
  110. //$result = restrictedArea($user, 'productbatch');
  111. if (!$permissiontoread) {
  112. accessforbidden();
  113. }
  114. /*
  115. * Actions
  116. */
  117. $parameters = array('id'=>$id);
  118. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  119. if ($reshook < 0) {
  120. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  121. }
  122. if (empty($reshook)) {
  123. // Action submit/delete file/link
  124. include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
  125. }
  126. /*
  127. * View
  128. */
  129. $form = new Form($db);
  130. llxHeader('', $langs->trans('ProductLot'), '');
  131. if ($object->id) {
  132. $head = productlot_prepare_head($object);
  133. print dol_get_fiche_head($head, 'documents', $langs->trans("Batch"), -1, 'barcode');
  134. $parameters = array();
  135. $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  136. print $hookmanager->resPrint;
  137. if ($reshook < 0) {
  138. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  139. }
  140. // Build file list
  141. $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ? SORT_DESC : SORT_ASC), 1);
  142. $totalsize = 0;
  143. foreach ($filearray as $key => $file) {
  144. $totalsize += $file['size'];
  145. }
  146. $linkback = '<a href="'.DOL_URL_ROOT.'/product/stock/productlot_list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  147. $shownav = 1;
  148. if ($user->socid && !in_array('batch', explode(',', getDolGlobalString('MAIN_MODULES_FOR_EXTERNAL')))) {
  149. $shownav = 0;
  150. }
  151. dol_banner_tab($object, 'id', $linkback, $shownav, 'rowid', 'batch');
  152. print '<div class="fichecenter">';
  153. print '<div class="underbanner clearboth"></div>';
  154. print '<table class="border tableforfield" width="100%">';
  155. // Product
  156. print '<tr><td class="titlefield">'.$langs->trans("Product").'</td><td>';
  157. $producttmp = new Product($db);
  158. $producttmp->fetch($object->fk_product);
  159. print $producttmp->getNomUrl(1, 'stock')." - ".$producttmp->label;
  160. print '</td></tr>';
  161. print '<tr><td class="titlefield">'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
  162. print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.dol_print_size($totalsize, 1, 1).'</td></tr>';
  163. print '</table>';
  164. print '</div>';
  165. print '<div class="clearboth"></div>';
  166. print dol_get_fiche_end();
  167. $param = '&id='.$object->id;
  168. include DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
  169. } else {
  170. print $langs->trans("ErrorUnknown");
  171. }
  172. llxFooter();
  173. $db->close();