dolibarr 21.0.0-alpha
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
58// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
59$hookmanager->initHooks(array('productlotdocuments'));
60
61$result = restrictedArea($user, 'produit|service');
62
63// Get parameters
64$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
65$sortfield = GETPOST('sortfield', 'aZ09comma');
66$sortorder = GETPOST('sortorder', 'aZ09comma');
67$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
68if (empty($page) || $page == -1) {
69 $page = 0;
70} // If $page is not defined, or '' or -1
71$offset = $limit * $page;
72$pageprev = $page - 1;
73$pagenext = $page + 1;
74if (!$sortorder) {
75 $sortorder = "ASC";
76}
77if (!$sortfield) {
78 $sortfield = "position_name";
79}
80
81$modulepart = 'product_batch';
82$object = new Productlot($db);
83if ($id || $ref) {
84 if ($ref) {
85 $tmp = explode('_', $ref);
86 $productid = $tmp[0];
87 $batch = $tmp[1];
88 }
89 $object->fetch($id, $productid, $batch);
90 $object->ref = $object->batch; // Old system for document management ( it uses $object->ref)
91
92 if (isModEnabled('productbatch')) {
93 $upload_dir = $conf->productbatch->multidir_output[$object->entity].'/'.get_exdir(0, 0, 0, 1, $object, $modulepart);
94 $filearray = dol_dir_list($upload_dir, "files");
95 if (empty($filearray)) {
96 // If no files linked yet, use new system on lot id. (Batch is not unique and can be same on different product)
97 $object->fetch($id, $productid, $batch);
98 $upload_dir = $conf->productbatch->multidir_output[$object->entity].'/'.get_exdir(0, 0, 0, 1, $object, $modulepart);
99 }
100 }
101}
102
103$usercanread = $user->hasRight('produit', 'lire');
104$usercancreate = $user->hasRight('produit', 'creer');
105$usercandelete = $user->hasRight('produit', 'supprimer');
106
107if (empty($upload_dir)) {
108 $upload_dir = $conf->productbatch->multidir_output[$conf->entity];
109}
110
111$permissiontoread = $usercanread;
112$permissiontoadd = $usercancreate;
113$permtoedit = $user->hasRight('produit', 'creer');
114//$permissiontodelete = $usercandelete;
115
116// Security check
117if (!isModEnabled('productbatch')) {
118 accessforbidden('Module not enabled');
119}
120$socid = 0;
121if ($user->socid > 0) { // Protection if external user
122 //$socid = $user->socid;
124}
125//$result = restrictedArea($user, 'productbatch');
126if (!$permissiontoread) {
128}
129
130
131/*
132 * Actions
133 */
134
135$parameters = array('id'=>$id);
136$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
137if ($reshook < 0) {
138 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
139}
140
141if (empty($reshook)) {
142 // Action submit/delete file/link
143 include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
144}
145
146
147/*
148 * View
149 */
150
151$form = new Form($db);
152
153llxHeader('', $langs->trans('ProductLot'), '', '', 0, 0, '', '', '', 'mod-product page-stock_productlot_document');
154
155
156if ($object->id) {
157 $head = productlot_prepare_head($object);
158 print dol_get_fiche_head($head, 'documents', $langs->trans("Batch"), -1, 'barcode');
159
160
161 $parameters = array();
162 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
163 print $hookmanager->resPrint;
164 if ($reshook < 0) {
165 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
166 }
167
168 // Build file list
169 $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ? SORT_DESC : SORT_ASC), 1);
170
171 $totalsize = 0;
172 foreach ($filearray as $key => $file) {
173 $totalsize += $file['size'];
174 }
175
176
177 $linkback = '<a href="'.DOL_URL_ROOT.'/product/stock/productlot_list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
178
179 $shownav = 1;
180 if ($user->socid && !in_array('batch', explode(',', getDolGlobalString('MAIN_MODULES_FOR_EXTERNAL')))) {
181 $shownav = 0;
182 }
183
184 dol_banner_tab($object, 'id', $linkback, $shownav, 'rowid', 'batch');
185
186 print '<div class="fichecenter">';
187
188 print '<div class="underbanner clearboth"></div>';
189 print '<table class="border tableforfield" width="100%">';
190
191 // Product
192 print '<tr><td class="titlefield">'.$langs->trans("Product").'</td><td>';
193 $producttmp = new Product($db);
194 $producttmp->fetch($object->fk_product);
195 print $producttmp->getNomUrl(1, 'stock')." - ".$producttmp->label;
196 print '</td></tr>';
197
198 print '<tr><td class="titlefield">'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
199 print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.dol_print_size($totalsize, 1, 1).'</td></tr>';
200 print '</table>';
201
202 print '</div>';
203 print '<div class="clearboth"></div>';
204
205 print dol_get_fiche_end();
206
207 $param = '&id='.$object->id;
208 include DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
209} else {
210 print $langs->trans("ErrorUnknown");
211}
212
213
214llxFooter();
215$db->close();
$id
Definition account.php:39
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($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
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.
llxFooter()
Footer empty.
Definition document.php:107
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
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.
getDolGlobalString($key, $default='')
Return a 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.