productlot_document.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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 porudct 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. // Load translation files required by the page
  39. $langs->loadLangs(array('other', 'products'));
  40. $id = GETPOST('id', 'int');
  41. $ref = GETPOST('ref', 'alpha');
  42. $action = GETPOST('action', 'aZ09');
  43. $confirm = GETPOST('confirm', 'alpha');
  44. // Security check
  45. $fieldvalue = (!empty($id) ? $id : '');
  46. $fieldtype = 'rowid';
  47. if ($user->socid) {
  48. $socid = $user->socid;
  49. }
  50. $result = restrictedArea($user, 'produit|service');
  51. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  52. $hookmanager->initHooks(array('productlotdocuments'));
  53. // Get parameters
  54. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  55. $sortfield = GETPOST('sortfield', 'aZ09comma');
  56. $sortorder = GETPOST('sortorder', 'aZ09comma');
  57. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  58. if (empty($page) || $page == -1) {
  59. $page = 0;
  60. } // If $page is not defined, or '' or -1
  61. $offset = $limit * $page;
  62. $pageprev = $page - 1;
  63. $pagenext = $page + 1;
  64. if (!$sortorder) {
  65. $sortorder = "ASC";
  66. }
  67. if (!$sortfield) {
  68. $sortfield = "position_name";
  69. }
  70. $modulepart = 'product_batch';
  71. $object = new Productlot($db);
  72. if ($id || $ref) {
  73. if ($ref) {
  74. $tmp = explode('_', $ref);
  75. $productid = $tmp[0];
  76. $batch = $tmp[1];
  77. }
  78. $object->fetch($id, $productid, $batch);
  79. $object->ref = $object->batch; // Old system for document management ( it uses $object->ref)
  80. if (isModEnabled('productbatch')) {
  81. $upload_dir = $conf->productbatch->multidir_output[$object->entity].'/'.get_exdir(0, 0, 0, 1, $object, $modulepart);
  82. $filearray = dol_dir_list($upload_dir, "files");
  83. if (empty($filearray)) {
  84. // If no files linked yet, use new system on lot id. (Batch is not unique and can be same on different product)
  85. $object->fetch($id, $productid, $batch);
  86. $upload_dir = $conf->productbatch->multidir_output[$object->entity].'/'.get_exdir(0, 0, 0, 1, $object, $modulepart);
  87. }
  88. }
  89. }
  90. $usercanread = $user->rights->produit->lire;
  91. $usercancreate = $user->rights->produit->creer;
  92. $usercandelete = $user->rights->produit->supprimer;
  93. if (empty($upload_dir)) {
  94. $upload_dir = $conf->productbatch->multidir_output[$conf->entity];
  95. }
  96. $permissiontoread = $usercanread;
  97. $permissiontoadd = $usercancreate;
  98. $permtoedit = $user->rights->produit->creer;
  99. //$permissiontodelete = $usercandelete;
  100. // Security check
  101. if (empty($conf->productbatch->enabled)) {
  102. accessforbidden('Module not enabled');
  103. }
  104. $socid = 0;
  105. if ($user->socid > 0) { // Protection if external user
  106. //$socid = $user->socid;
  107. accessforbidden();
  108. }
  109. //$result = restrictedArea($user, 'productbatch');
  110. if (!$permissiontoread) {
  111. accessforbidden();
  112. }
  113. /*
  114. * Actions
  115. */
  116. $parameters = array('id'=>$id);
  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. // Action submit/delete file/link
  123. include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
  124. }
  125. /*
  126. * View
  127. */
  128. $form = new Form($db);
  129. llxHeader('', $langs->trans('ProductLot'), '');
  130. if ($object->id) {
  131. $head = productlot_prepare_head($object);
  132. print dol_get_fiche_head($head, 'documents', $langs->trans("Batch"), -1, 'barcode');
  133. $parameters = array();
  134. $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  135. print $hookmanager->resPrint;
  136. if ($reshook < 0) {
  137. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  138. }
  139. // Build file list
  140. $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1);
  141. $totalsize = 0;
  142. foreach ($filearray as $key => $file) {
  143. $totalsize += $file['size'];
  144. }
  145. $linkback = '<a href="'.DOL_URL_ROOT.'/product/stock/productlot_list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  146. $shownav = 1;
  147. if ($user->socid && !in_array('batch', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) {
  148. $shownav = 0;
  149. }
  150. dol_banner_tab($object, 'id', $linkback, $shownav, 'rowid', 'batch');
  151. print '<div class="fichecenter">';
  152. print '<div class="underbanner clearboth"></div>';
  153. print '<table class="border tableforfield" width="100%">';
  154. // Product
  155. print '<tr><td class="titlefield">'.$langs->trans("Product").'</td><td>';
  156. $producttmp = new Product($db);
  157. $producttmp->fetch($object->fk_product);
  158. print $producttmp->getNomUrl(1, 'stock')." - ".$producttmp->label;
  159. print '</td></tr>';
  160. print '<tr><td class="titlefield">'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
  161. print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.dol_print_size($totalsize, 1, 1).'</td></tr>';
  162. print '</table>';
  163. print '</div>';
  164. print '<div style="clear:both"></div>';
  165. print dol_get_fiche_end();
  166. $param = '&id='.$object->id;
  167. include DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
  168. } else {
  169. print $langs->trans("ErrorUnknown");
  170. }
  171. llxFooter();
  172. $db->close();