dolibarr 20.0.0
productlot_document.php
Go to the documentation of this file.
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
32// Load Dolibarr environment
33require '../../main.inc.php';
34require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
35require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
36require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
37require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
38require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
39require_once DOL_DOCUMENT_ROOT.'/product/stock/class/productlot.class.php';
40
41global $conf, $db, $langs, $user;
42
43// Load translation files required by the page
44$langs->loadLangs(array('other', 'products'));
45
46$id = GETPOSTINT('id');
47$ref = GETPOST('ref', 'alpha');
48$action = GETPOST('action', 'aZ09');
49$confirm = GETPOST('confirm', 'alpha');
50
51// Security check
52$fieldvalue = (!empty($id) ? $id : '');
53$fieldtype = 'rowid';
54if ($user->socid) {
55 $socid = $user->socid;
56}
57$result = restrictedArea($user, 'produit|service');
58
59// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
60$hookmanager->initHooks(array('productlotdocuments'));
61
62// Get parameters
63$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
64$sortfield = GETPOST('sortfield', 'aZ09comma');
65$sortorder = GETPOST('sortorder', 'aZ09comma');
66$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
67if (empty($page) || $page == -1) {
68 $page = 0;
69} // If $page is not defined, or '' or -1
70$offset = $limit * $page;
71$pageprev = $page - 1;
72$pagenext = $page + 1;
73if (!$sortorder) {
74 $sortorder = "ASC";
75}
76if (!$sortfield) {
77 $sortfield = "position_name";
78}
79
80$modulepart = 'product_batch';
81$object = new Productlot($db);
82if ($id || $ref) {
83 if ($ref) {
84 $tmp = explode('_', $ref);
85 $productid = $tmp[0];
86 $batch = $tmp[1];
87 }
88 $object->fetch($id, $productid, $batch);
89 $object->ref = $object->batch; // Old system for document management ( it uses $object->ref)
90
91 if (isModEnabled('productbatch')) {
92 $upload_dir = $conf->productbatch->multidir_output[$object->entity].'/'.get_exdir(0, 0, 0, 1, $object, $modulepart);
93 $filearray = dol_dir_list($upload_dir, "files");
94 if (empty($filearray)) {
95 // If no files linked yet, use new system on lot id. (Batch is not unique and can be same on different product)
96 $object->fetch($id, $productid, $batch);
97 $upload_dir = $conf->productbatch->multidir_output[$object->entity].'/'.get_exdir(0, 0, 0, 1, $object, $modulepart);
98 }
99 }
100}
101
102$usercanread = $user->hasRight('produit', 'lire');
103$usercancreate = $user->hasRight('produit', 'creer');
104$usercandelete = $user->hasRight('produit', 'supprimer');
105
106if (empty($upload_dir)) {
107 $upload_dir = $conf->productbatch->multidir_output[$conf->entity];
108}
109
110$permissiontoread = $usercanread;
111$permissiontoadd = $usercancreate;
112$permtoedit = $user->hasRight('produit', 'creer');
113//$permissiontodelete = $usercandelete;
114
115// Security check
116if (!isModEnabled('productbatch')) {
117 accessforbidden('Module not enabled');
118}
119$socid = 0;
120if ($user->socid > 0) { // Protection if external user
121 //$socid = $user->socid;
123}
124//$result = restrictedArea($user, 'productbatch');
125if (!$permissiontoread) {
127}
128
129
130/*
131 * Actions
132 */
133
134$parameters = array('id'=>$id);
135$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
136if ($reshook < 0) {
137 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
138}
139
140if (empty($reshook)) {
141 // Action submit/delete file/link
142 include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
143}
144
145
146/*
147 * View
148 */
149
150$form = new Form($db);
151
152llxHeader('', $langs->trans('ProductLot'), '', '', 0, 0, '', '', '', 'mod-product page-stock_productlot_document');
153
154
155if ($object->id) {
156 $head = productlot_prepare_head($object);
157 print dol_get_fiche_head($head, 'documents', $langs->trans("Batch"), -1, 'barcode');
158
159
160 $parameters = array();
161 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
162 print $hookmanager->resPrint;
163 if ($reshook < 0) {
164 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
165 }
166
167 // Build file list
168 $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ? SORT_DESC : SORT_ASC), 1);
169
170 $totalsize = 0;
171 foreach ($filearray as $key => $file) {
172 $totalsize += $file['size'];
173 }
174
175
176 $linkback = '<a href="'.DOL_URL_ROOT.'/product/stock/productlot_list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
177
178 $shownav = 1;
179 if ($user->socid && !in_array('batch', explode(',', getDolGlobalString('MAIN_MODULES_FOR_EXTERNAL')))) {
180 $shownav = 0;
181 }
182
183 dol_banner_tab($object, 'id', $linkback, $shownav, 'rowid', 'batch');
184
185 print '<div class="fichecenter">';
186
187 print '<div class="underbanner clearboth"></div>';
188 print '<table class="border tableforfield" width="100%">';
189
190 // Product
191 print '<tr><td class="titlefield">'.$langs->trans("Product").'</td><td>';
192 $producttmp = new Product($db);
193 $producttmp->fetch($object->fk_product);
194 print $producttmp->getNomUrl(1, 'stock')." - ".$producttmp->label;
195 print '</td></tr>';
196
197 print '<tr><td class="titlefield">'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
198 print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.dol_print_size($totalsize, 1, 1).'</td></tr>';
199 print '</table>';
200
201 print '</div>';
202 print '<div class="clearboth"></div>';
203
204 print dol_get_fiche_end();
205
206 $param = '&id='.$object->id;
207 include DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
208} else {
209 print $langs->trans("ErrorUnknown");
210}
211
212
213llxFooter();
214$db->close();
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:55
llxFooter()
Empty footer.
Definition wrapper.php:69
Class to manage generation of HTML components Only common components must be here.
Class to manage products or services.
Class with list of lots and properties.
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition files.lib.php:63
dol_print_size($size, $shortvalue=0, $shortunit=0)
Return string with formatted size.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
productlot_prepare_head($object)
Prepare array with list of tabs.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.