diff --git a/htdocs/core/class/conf.class.php b/htdocs/core/class/conf.class.php index c4ccd6fe982..0ea6af8d5de 100644 --- a/htdocs/core/class/conf.class.php +++ b/htdocs/core/class/conf.class.php @@ -375,6 +375,10 @@ class Conf $this->service->dir_output=$rootfordata."/produit"; $this->service->dir_temp =$rootfordata."/produit/temp"; + // Module productbatch + $this->productbatch->multidir_output=array($this->entity => $rootfordata."/produitlot"); + $this->productbatch->multidir_temp =array($this->entity => $rootfordata."/produitlot/temp"); + // Module contrat $this->contrat->dir_output=$rootfordata."/contracts"; $this->contrat->dir_temp =$rootfordata."/contracts/temp"; diff --git a/htdocs/core/class/fileupload.class.php b/htdocs/core/class/fileupload.class.php index e25709fd303..648f1295c25 100644 --- a/htdocs/core/class/fileupload.class.php +++ b/htdocs/core/class/fileupload.class.php @@ -94,6 +94,9 @@ class FileUpload elseif ($element == 'product') { $dir_output = $conf->product->multidir_output[$conf->entity]; } + elseif ($element == 'productbatch') { + $dir_output = $conf->productbatch->multidir_output[$conf->entity]; + } elseif ($element == 'action') { $pathname = 'comm/action'; $filename='actioncomm'; $dir_output=$conf->agenda->dir_output; diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php index 0e125a7b944..50386e277a1 100644 --- a/htdocs/core/class/html.formfile.class.php +++ b/htdocs/core/class/html.formfile.class.php @@ -469,6 +469,15 @@ class FormFile $modellist=ModelePDFProduct::liste_modeles($this->db); } } + elseif ($modulepart == 'product_batch') + { + if (is_array($genallowed)) $modellist=$genallowed; + else + { + include_once DOL_DOCUMENT_ROOT.'/core/modules/product_batch/modules_product_batch.class.php'; + $modellist=ModelePDFProductBatch::liste_modeles($this->db); + } + } elseif ($modulepart == 'export') { if (is_array($genallowed)) $modellist=$genallowed; @@ -740,7 +749,7 @@ class FormFile // Show file size $size=(! empty($file['size'])?$file['size']:dol_filesize($filedir."/".$file["name"])); - $out.= ''.dol_print_size($size).''; + $out.= ''.dol_print_size($size,1,1).''; // Show file date $date=(! empty($file['date'])?$file['date']:dol_filemtime($filedir."/".$file["name"])); diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index 6ea633f1f1d..844399caaf2 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -2625,6 +2625,17 @@ function dol_check_secure_access_document($modulepart, $original_file, $entity, elseif (! empty($conf->service->enabled)) $original_file=$conf->service->multidir_output[$entity].'/'.$original_file; } + // Wrapping pour les lots produits + else if ($modulepart == 'product_batch') + { + if (empty($entity) || (empty($conf->productbatch->multidir_output[$entity]))) return array('accessallowed'=>0, 'error'=>'Value entity must be provided'); + if (($fuser->rights->produit->{$lire} ) || preg_match('/^specimen/i',$original_file)) + { + $accessallowed=1; + } + if (! empty($conf->productbatch->enabled)) $original_file=$conf->productbatch->multidir_output[$entity].'/'.$original_file; + } + // Wrapping pour les contrats else if ($modulepart == 'contract' && !empty($conf->contrat->dir_output)) { diff --git a/htdocs/core/lib/product.lib.php b/htdocs/core/lib/product.lib.php index 8d40f11d472..e3c10eb9a89 100644 --- a/htdocs/core/lib/product.lib.php +++ b/htdocs/core/lib/product.lib.php @@ -199,7 +199,19 @@ function productlot_prepare_head($object) $head[$h][0] = DOL_URL_ROOT."/product/stock/productlot_card.php?id=".$object->id; $head[$h][1] = $langs->trans("Card"); $head[$h][2] = 'card'; - $h++; + $h++; + + // Attachments + require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; + require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php'; + $upload_dir = $conf->productbatch->multidir_output[$object->entity].'/'.$object->id; + $nbFiles = count(dol_dir_list($upload_dir,'files',0,'','(\.meta|_preview.*\.png)$')); + $nbLinks=Link::count($db, $object->element, $object->id); + $head[$h][0] = DOL_URL_ROOT."/product/stock/productlot_document.php?id=".$object->id; + $head[$h][1] = $langs->trans("Documents"); + if (($nbFiles+$nbLinks) > 0) $head[$h][1].= ' '.($nbFiles+$nbLinks).''; + $head[$h][2] = 'documents'; + $h++; // Show more tabs from modules // Entries must be declared in modules descriptor with line diff --git a/htdocs/core/modules/product_batch/index.html b/htdocs/core/modules/product_batch/index.html new file mode 100644 index 00000000000..e69de29bb2d diff --git a/htdocs/core/modules/product_batch/modules_product_batch.class.php b/htdocs/core/modules/product_batch/modules_product_batch.class.php new file mode 100644 index 00000000000..94818d17531 --- /dev/null +++ b/htdocs/core/modules/product_batch/modules_product_batch.class.php @@ -0,0 +1,63 @@ + + * Copyright (C) 2004-2010 Laurent Destailleur + * Copyright (C) 2004 Eric Seigne + * Copyright (C) 2005-2012 Regis Houssin + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * or see http://www.gnu.org/ + */ + + +/** + * \class ModeleProductCode + * \brief Parent class for product code generators + */ + +/** + * \file htdocs/core/modules/contract/modules_contract.php + * \ingroup contract + * \brief File with parent class for generating contracts to PDF and File of class to manage contract numbering + */ + + require_once DOL_DOCUMENT_ROOT.'/core/class/commondocgenerator.class.php'; + +/** + * Parent class to manage intervention document templates + */ +abstract class ModelePDFProductBatch extends CommonDocGenerator +{ + var $error=''; + + + /** + * Return list of active generation modules + * + * @param DoliDB $db Database handler + * @param integer $maxfilenamelength Max length of value to show + * @return array List of templates + */ + static function liste_modeles($db,$maxfilenamelength=0) + { + global $conf; + + $type='product_batch'; + $liste=array(); + + include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; + $liste=getListOfModels($db,$type,$maxfilenamelength); + return $liste; + } +} + diff --git a/htdocs/product/stock/class/productlot.class.php b/htdocs/product/stock/class/productlot.class.php index 56c9e1cebe4..f420ec3b501 100644 --- a/htdocs/product/stock/class/productlot.class.php +++ b/htdocs/product/stock/class/productlot.class.php @@ -91,6 +91,7 @@ class Productlot extends CommonObject */ public function create(User $user, $notrigger = false) { + global $conf; dol_syslog(__METHOD__, LOG_DEBUG); $error = 0; @@ -133,7 +134,7 @@ class Productlot extends CommonObject $sql.= 'fk_user_modif,'; $sql.= 'import_key'; $sql .= ') VALUES ('; - $sql .= ' '.(! isset($this->entity)?'NULL':$this->entity).','; + $sql .= ' '.(! isset($this->entity)?$conf->entity:$this->entity).','; $sql .= ' '.(! isset($this->fk_product)?'NULL':$this->fk_product).','; $sql .= ' '.(! isset($this->batch)?'NULL':"'".$this->db->escape($this->batch)."'").','; $sql .= ' '.(! isset($this->eatby) || dol_strlen($this->eatby)==0?'NULL':"'".$this->db->idate($this->eatby)."'").','; @@ -232,7 +233,6 @@ class Productlot extends CommonObject //$this->ref = $obj->fk_product.'_'.$obj->batch; $this->batch = $obj->batch; - $this->entity = $obj->entity; $this->fk_product = $obj->fk_product; $this->eatby = $this->db->jdate($obj->eatby); diff --git a/htdocs/product/stock/productlot_card.php b/htdocs/product/stock/productlot_card.php index 937e6c1240f..56ab0ec39c0 100644 --- a/htdocs/product/stock/productlot_card.php +++ b/htdocs/product/stock/productlot_card.php @@ -31,6 +31,7 @@ if (! $res && file_exists("../../../dolibarr/htdocs/main.inc.php")) $res=@includ if (! $res && file_exists("../../../../dolibarr/htdocs/main.inc.php")) $res=@include '../../../../dolibarr/htdocs/main.inc.php'; // Used on dev env only if (! $res) die("Include of main fails"); // Change this following line to use the correct relative path from htdocs +require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; include_once(DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'); include_once(DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php'); include_once(DOL_DOCUMENT_ROOT.'/product/class/product.class.php'); @@ -70,6 +71,7 @@ if ($user->societe_id > 0) $object = new ProductLot($db); $extrafields = new ExtraFields($db); +$formfile = new FormFile($db); // fetch optionals attributes and labels $extralabels = $extrafields->fetch_name_optionals_label($object->table_element); @@ -95,6 +97,9 @@ $permissionnote = $user->rights->stock->creer; // Used by the include of actio $permissiondellink = $user->rights->stock->creer; // Used by the include of actions_dellink.inc.php $permissionedit = $user->rights->stock->creer; // Used by the include of actions_lineupdown.inc.php +$usercanread = $user->rights->produit->lire; +$usercancreate = $user->rights->produit->creer; +$usercandelete = $user->rights->produit->supprimer; /* * Actions @@ -253,6 +258,12 @@ if (empty($reshook)) else setEventMessages($object->error, null, 'errors'); } } + + // Actions to build doc + $upload_dir = $conf->productbatch->multidir_output[$conf->entity]; + $permissioncreate = $usercancreate; + include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php'; + } @@ -389,6 +400,32 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea } + +/* + * Documents generes + */ + +if (empty($action)) +{ + print '
'; + print ''; // ancre + + // Documents + $filedir = $conf->productbatch->multidir_output[$object->entity].'/'.get_exdir(0, 0, 0, 0, $object, 'product_batch').$object->id; + $urlsource=$_SERVER["PHP_SELF"]."?id=".$object->id; + $genallowed=$usercanread; + $delallowed=$usercancreate; + + $var=true; + + print $formfile->showdocuments('product_batch',$object->id,$filedir,$urlsource,$genallowed,$delallowed,'',0,0,0,28,0,'',0,'',$object->default_lang, '', $object); + $somethingshown=$formfile->numoffiles; + + print '
'; + +} + + // End of page llxFooter(); $db->close(); diff --git a/htdocs/product/stock/productlot_document.php b/htdocs/product/stock/productlot_document.php new file mode 100644 index 00000000000..e40f1a20ed0 --- /dev/null +++ b/htdocs/product/stock/productlot_document.php @@ -0,0 +1,179 @@ + + * Copyright (C) 2004-2010 Laurent Destailleur + * Copyright (C) 2005 Marc Barilley / Ocebo + * Copyright (C) 2005-2012 Regis Houssin + * Copyright (C) 2005 Simon TOSSER + * Copyright (C) 2013 Florian Henry + * Copyright (C) 2013 Cédric Salvador + * Copyright (C) 2017 Ferran Marcet + * Copyright (C) 2018 All-3kcis + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file htdocs/product/stock/productlot_document.php + * \ingroup product + * \brief Page des documents joints sur les lots produits + */ + +// Change this following line to use the correct relative path (../, ../../, etc) +$res=0; +if (! $res && file_exists("../main.inc.php")) $res=@include '../main.inc.php'; // to work if your module directory is into dolibarr root htdocs directory +if (! $res && file_exists("../../main.inc.php")) $res=@include '../../main.inc.php'; // to work if your module directory is into a subdir of root htdocs directory +if (! $res && file_exists("../../../dolibarr/htdocs/main.inc.php")) $res=@include '../../../dolibarr/htdocs/main.inc.php'; // Used on dev env only +if (! $res && file_exists("../../../../dolibarr/htdocs/main.inc.php")) $res=@include '../../../../dolibarr/htdocs/main.inc.php'; // Used on dev env only +if (! $res) die("Include of main fails"); +require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; +dol_include_once('/product/stock/class/productlot.class.php'); + +$langs->load("other"); +$langs->load("products"); + +$id = GETPOST('id', 'int'); +$ref = GETPOST('ref', 'alpha'); +$action = GETPOST('action','alpha'); +$confirm= GETPOST('confirm','alpha'); + +// Security check +$fieldvalue = (! empty($id) ? $id : ''); +$fieldtype = 'rowid'; +if ($user->societe_id) $socid=$user->societe_id; +$result=restrictedArea($user,'produit|service'); + +// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context +$hookmanager->initHooks(array('productlotdocuments')); + +// Get parameters +$sortfield = GETPOST("sortfield",'alpha'); +$sortorder = GETPOST("sortorder",'alpha'); +$page = GETPOST("page",'int'); +if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 +$offset = $conf->liste_limit * $page; +$pageprev = $page - 1; +$pagenext = $page + 1; +if (! $sortorder) $sortorder="ASC"; +if (! $sortfield) $sortfield="position_name"; + + +$object = new Productlot($db); +if ($id || $ref) +{ + if ($ref) + { + $tmp=explode('_',$ref); + $productid=$tmp[0]; + $batch=$tmp[1]; + } + $object->fetch($id, $productid, $batch); +} +$modulepart='product_batch'; +if ($id > 0 || ! empty($ref)) +{ + $result = $object->fetch($id, $ref); + + if (! empty($conf->productbatch->enabled)) $upload_dir = $conf->productbatch->multidir_output[$object->entity].'/'.get_exdir(0, 0, 0, 0, $object, $modulepart).$object->id; +} + + +/* + * Actions + */ + +$parameters=array('id'=>$id); +$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks +if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + +if (empty($reshook)) +{ + + // Action submit/delete file/link + include_once DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php'; + +} + +$permtoedit = $user->rights->produit->creer; + + +/* + * View + */ + +$form = new Form($db); + +llxHeader('', $langs->trans('ProductLot'), ''); + + +if ($object->id) +{ + + $head = productlot_prepare_head($object); + dol_fiche_head($head, 'documents', $langs->trans("Batch"), -1, 'barcode'); + + + $parameters=array(); + $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook + print $hookmanager->resPrint; + if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + + // Construit liste des fichiers + $filearray=dol_dir_list($upload_dir,"files",0,'','(\.meta|_preview.*\.png)$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1); + + $totalsize=0; + foreach($filearray as $key => $file) + { + $totalsize+=$file['size']; + } + + + $linkback = '' . $langs->trans("BackToList") . ''; + + $shownav = 1; + if ($user->societe_id && ! in_array('batch', explode(',',$conf->global->MAIN_MODULES_FOR_EXTERNAL))) $shownav=0; + + dol_banner_tab($object, 'id', $linkback, $shownav, 'rowid', 'batch'); + + print '
'; + + print '
'; + print ''; + + print ''; + print ''; + print '
'.$langs->trans("NbOfAttachedFiles").''.count($filearray).'
'.$langs->trans("TotalSizeOfAttachedFiles").''.dol_print_size($totalsize,1,1).'
'; + + print '
'; + print '
'; + + dol_fiche_end(); + + $permission = ( $user->rights->produit->creer ); + $param = '&id=' . $object->id; + include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_post_headers.tpl.php'; + + +} +else +{ + print $langs->trans("ErrorUnknown"); +} + + +llxFooter(); +$db->close();