Add files management on products lot

This commit is contained in:
All-3kcis 2018-04-12 15:10:37 +02:00
parent 6cb0793d14
commit f7e58f3c73
10 changed files with 322 additions and 4 deletions

View File

@ -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";

View File

@ -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;

View File

@ -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.= '<td align="right" class="nowrap">'.dol_print_size($size).'</td>';
$out.= '<td align="right" class="nowrap">'.dol_print_size($size,1,1).'</td>';
// Show file date
$date=(! empty($file['date'])?$file['date']:dol_filemtime($filedir."/".$file["name"]));

View File

@ -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))
{

View File

@ -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].= ' <span class="badge">'.($nbFiles+$nbLinks).'</span>';
$head[$h][2] = 'documents';
$h++;
// Show more tabs from modules
// Entries must be declared in modules descriptor with line

View File

@ -0,0 +1,63 @@
<?php
/* Copyright (C) 2003-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
*
* 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 <http://www.gnu.org/licenses/>.
* 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;
}
}

View File

@ -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);

View File

@ -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 '<div class="fichecenter"><div class="fichehalfleft">';
print '<a name="builddoc"></a>'; // 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 '</div>';
}
// End of page
llxFooter();
$db->close();

View File

@ -0,0 +1,179 @@
<?php
/* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2005 Simon TOSSER <simon@kornog-computing.com>
* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
* Copyright (C) 2017 Ferran Marcet <fmarcet@2byte.es>
* Copyright (C) 2018 All-3kcis <contact@all-3kcis.fr>
*
* 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 <http://www.gnu.org/licenses/>.
*/
/**
* \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 = '<a href="' . DOL_URL_ROOT . '/product/stock/productlot_list.php' . '">' . $langs->trans("BackToList") . '</a>';
$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 '<div class="fichecenter">';
print '<div class="underbanner clearboth"></div>';
print '<table class="border tableforfield" width="100%">';
print '<tr><td class="titlefield">'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.dol_print_size($totalsize,1,1).'</td></tr>';
print '</table>';
print '</div>';
print '<div style="clear:both"></div>';
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();