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