New: barcode is now visible on main tab.

This commit is contained in:
Laurent Destailleur 2011-12-07 12:58:39 +01:00
parent 1f37dc906f
commit 740c24e991
4 changed files with 103 additions and 191 deletions

View File

@ -64,15 +64,6 @@ function product_prepare_head($object, $user)
$h++;
}
// Show barcode tab
if ($conf->global->MAIN_MODULE_BARCODE && $user->rights->barcode->lire)
{
$head[$h][0] = DOL_URL_ROOT."/product/barcode.php?id=".$object->id;
$head[$h][1] = $langs->trans("BarCode");
$head[$h][2] = 'barcode';
$h++;
}
// Multilangs
if($conf->global->MAIN_MULTILANGS)
{

View File

@ -1,165 +0,0 @@
<?php
/* Copyright (C) 2001-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2011 Regis Houssin <regis@dolibarr.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 2 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/barcode.php
* \ingroup product
* \brief Page with bar code informations of product
*/
require("../main.inc.php");
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/class/html.formbarcode.class.php");
$langs->load("products");
$langs->load("bills");
$id = GETPOST('id','int');
$ref = GETPOST('ref','alpha');
$action = GETPOST('action','alpha');
// Security check
$fieldvalue = (! empty($id) ? $id : $ref);
$fieldname = (! empty($ref) ? 'ref' : 'rowid');
if ($user->societe_id) $socid=$user->societe_id;
$result=restrictedArea($user,'produit|service&barcode',$fieldvalue,'product','','',$fieldname);
$object = new Product($db);
/*
* Actions
*/
// Modification du type de code barre
if ($action == 'setbarcodetype' && $user->rights->barcode->creer)
{
$object->fetch($id);
$object->barcode_type = $_POST['barcodetype_id'];
$result = $object->update_barcode_type($user);
Header("Location: ".$_SERVER['PHP_SELF']."?id=".$id);
exit;
}
// Modification du code barre
if ($action == 'setbarcode' && $user->rights->barcode->creer)
{
$object->fetch($id);
$object->barcode = $_POST['barcode']; //Todo: ajout verification de la validite du code barre en fonction du type
$result = $object->update_barcode($user);
Header("Location: ".$_SERVER['PHP_SELF']."?id=".$id);
exit;
}
/*
* View
*/
llxHeader("","",$langs->trans("BarCode"));
$form = new Form($db);
$formbarcode = new FormBarCode($db);
$result = $object->fetch($id,$ref);
$head=product_prepare_head($object, $user);
$titre=$langs->trans("CardProduct".$object->type);
$picto=($object->type==1?'service':'product');
dol_fiche_head($head, 'barcode', $titre, 0, $picto);
print '<table class="border" width="100%">'."\n";
// Reference
print '<tr>';
print '<td width="15%">'.$langs->trans("Ref").'</td><td colspan="3">';
print $form->showrefnav($object,'ref','',1,'ref');
print '</td>';
print '</tr>'."\n";
// Libelle
print '<tr><td>'.$langs->trans("Label").'</td><td colspan="2">'.$object->libelle.'</td>';
// Barcode image
$url=DOL_URL_ROOT.'/viewimage.php?modulepart=barcode&generator='.urlencode($object->barcode_type_coder).'&code='.urlencode($object->barcode).'&encoding='.urlencode($object->barcode_type_code);
print '<td width="300" align="center" rowspan="5">';
print '<!-- url barcode = '.$url.' -->';
print '<img src="'.$url.'">';
print '</td>';
print '</tr>'."\n";
// Status (to sell)
print '<tr><td>'.$langs->trans("Status").' ('.$langs->trans("Sell").')'.'</td><td>';
print $object->getLibStatut(2,0);
print '</td></tr>';
// Status (to buy)
print '<tr><td>'.$langs->trans("Status").' ('.$langs->trans("Buy").')'.'</td><td>';
print $object->getLibStatut(2,1);
print '</td></tr>';
// Barcode type
print '<tr><td nowrap>';
print '<table width="100%" class="nobordernopadding"><tr><td nowrap>';
print $langs->trans("BarcodeType");
print '<td>';
if (($_GET['action'] != 'editbarcodetype') && $user->rights->barcode->creer) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editbarcodetype&amp;id='.$object->id.'">'.img_edit($langs->trans('SetBarcodeType'),1).'</a></td>';
print '</tr></table>';
print '</td><td colspan="2">';
if ($_GET['action'] == 'editbarcodetype')
{
$formbarcode->form_barcode_type($_SERVER['PHP_SELF'].'?id='.$object->id,$object->barcode_type,'barcodetype_id');
}
else
{
print $object->barcode_type_label?$object->barcode_type_label:'<div class="warning">'.$langs->trans("SetDefaultBarcodeType").'<div>';
}
print '</td></tr>'."\n";
// Barcode value
print '<tr><td nowrap>';
print '<table width="100%" class="nobordernopadding"><tr><td nowrap>';
print $langs->trans("BarcodeValue");
print '<td>';
if (($_GET['action'] != 'editbarcode') && $user->rights->barcode->creer) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editbarcode&amp;id='.$object->id.'">'.img_edit($langs->trans('SetBarcode'),1).'</a></td>';
print '</tr></table>';
print '</td><td colspan="2">';
if ($_GET['action'] == 'editbarcode')
{
print '<form method="post" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="setbarcode">';
print '<input size="40" type="text" name="barcode" value="'.$object->barcode.'">';
print '&nbsp;<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
}
else
{
print $object->barcode;
}
print '</td></tr>'."\n";
print "</table>\n";
print "</div>\n";
$db->close();
llxFooter();
?>

View File

@ -403,7 +403,7 @@ class Product extends CommonObject
global $langs, $conf;
$error=0;
// Verification parametres
if (! $this->libelle) $this->libelle = 'MISSING LABEL';
@ -2547,18 +2547,18 @@ class Product extends CommonObject
/**
* Show photos of a product (nbmax maximum)
* Show photos of a product (nbmax maximum)
* TODO Move this into html.formproduct.class.php
*
* @param sdir Directory to scan
* @param size 0=original size, 1 use thumbnail if possible
* @param nbmax Nombre maximum de photos (0=pas de max)
* @param nbbyrow Nombre vignettes par ligne (si mode vignette)
* @param showfilename 1=Show filename
* @param showaction 1=Show icon with action links (resize, delete)
* @param maxHeight Max height of image when size=1
* @param maxWidth Max width of image when size=1
* @return string Html code to show photo. Number of photos shown is saved in this->nbphoto
* TODO Move this into html.formproduct.class.php
* @param sdir Directory to scan
* @param size 0=original size, 1 use thumbnail if possible
* @param nbmax Nombre maximum de photos (0=pas de max)
* @param nbbyrow Nombre vignettes par ligne (si mode vignette)
* @param showfilename 1=Show filename
* @param showaction 1=Show icon with action links (resize, delete)
* @param maxHeight Max height of image when size=1
* @param maxWidth Max width of image when size=1
* @return string Html code to show photo. Number of photos shown is saved in this->nbphoto
*/
function show_photos($sdir,$size=0,$nbmax=0,$nbbyrow=5,$showfilename=0,$showaction=0,$maxHeight=120,$maxWidth=160)
{
@ -2572,7 +2572,6 @@ class Product extends CommonObject
$dirthumb = $dir.'thumbs/';
$pdirthumb = $pdir.'thumbs/';
$return ='<!-- Photo -->'."\n";
/*$return.="<script type=\"text/javascript\">
jQuery(function() {
@ -2715,6 +2714,23 @@ class Product extends CommonObject
return $return;
}
/**
* Show barcode of a product (nbmax maximum)
*
* @return string Html code to show barcode.
* TODO Move this into html.formproduct.class.php
*/
function show_barcode()
{
// Barcode image
$url=DOL_URL_ROOT.'/viewimage.php?modulepart=barcode&generator='.urlencode($this->barcode_type_coder).'&code='.urlencode($this->barcode).'&encoding='.urlencode($this->barcode_type_code);
$out='<!-- url barcode = '.$url.' -->';
$out.='<img src="'.$url.'">';
return $out;
}
/**
* Retourne tableau de toutes les photos du produit
*

View File

@ -87,6 +87,26 @@ $error=$hookmanager->error; $errors=$hookmanager->errors;
if (empty($reshook))
{
// Barcode type
if ($action == 'setbarcodetype' && $user->rights->barcode->creer)
{
$object->fetch($id);
$object->barcode_type = $_POST['barcodetype_id'];
$result = $object->update_barcode_type($user);
Header("Location: ".$_SERVER['PHP_SELF']."?id=".$id);
exit;
}
// Barcode value
if ($action == 'setbarcode' && $user->rights->barcode->creer)
{
$object->fetch($id);
$object->barcode = $_POST['barcode']; //Todo: ajout verification de la validite du code barre en fonction du type
$result = $object->update_barcode($user);
Header("Location: ".$_SERVER['PHP_SELF']."?id=".$id);
exit;
}
if ($action == 'setproductaccountancycodebuy')
{
$product = new Product($db);
@ -981,13 +1001,14 @@ else
if ($ret == 'html') print '<br>';
}
$isphoto=$object->is_photo_available($conf->product->dir_output);
$showphoto=$object->is_photo_available($conf->product->dir_output);
$showbarcode=$conf->barcode->enabled && $user->rights->barcode->lire;
// En mode visu
print '<table class="border" width="100%"><tr>';
// Ref
print '<td width="15%">'.$langs->trans("Ref").'</td><td colspan="'.(2+($isphoto?1:0)).'">';
print '<td width="15%">'.$langs->trans("Ref").'</td><td colspan="'.(2+(($showphoto||$showbarcode)?1:0)).'">';
print $form->showrefnav($object,'ref','',1,'ref');
print '</td>';
@ -1000,17 +1021,66 @@ else
if ($object->type!=1) $nblignes++;
if ($object->isservice()) $nblignes++;
else $nblignes+=4;
if ($showbarcode) $nblignes+=2;
// Photo
if ($isphoto)
if ($showphoto || $showbarcode)
{
print '<td valign="middle" align="center" width="25%" rowspan="'.$nblignes.'">';
print $object->show_photos($conf->product->dir_output,1,1,0,0,0,80);
if ($showphoto) print $object->show_photos($conf->product->dir_output,1,1,0,0,0,80);
if ($showphoto && $showbarcode) print '<br><br>';
if ($showbarcode) print $object->show_barcode();
print '</td>';
}
print '</tr>';
if ($showbarcode)
{
require_once(DOL_DOCUMENT_ROOT."/core/class/html.formbarcode.class.php");
$formbarcode = new FormBarCode($db);
// Barcode type
print '<tr><td nowrap>';
print '<table width="100%" class="nobordernopadding"><tr><td nowrap>';
print $langs->trans("BarcodeType");
print '<td>';
if (($_GET['action'] != 'editbarcodetype') && $user->rights->barcode->creer) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editbarcodetype&amp;id='.$object->id.'">'.img_edit($langs->trans('SetBarcodeType'),1).'</a></td>';
print '</tr></table>';
print '</td><td colspan="2">';
if ($_GET['action'] == 'editbarcodetype')
{
$formbarcode->form_barcode_type($_SERVER['PHP_SELF'].'?id='.$object->id,$object->barcode_type,'barcodetype_id');
}
else
{
print $object->barcode_type_label?$object->barcode_type_label:'<div class="warning">'.$langs->trans("SetDefaultBarcodeType").'<div>';
}
print '</td></tr>'."\n";
// Barcode value
print '<tr><td nowrap>';
print '<table width="100%" class="nobordernopadding"><tr><td nowrap>';
print $langs->trans("BarcodeValue");
print '<td>';
if (($_GET['action'] != 'editbarcode') && $user->rights->barcode->creer) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editbarcode&amp;id='.$object->id.'">'.img_edit($langs->trans('SetBarcode'),1).'</a></td>';
print '</tr></table>';
print '</td><td colspan="2">';
if ($_GET['action'] == 'editbarcode')
{
print '<form method="post" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="setbarcode">';
print '<input size="40" type="text" name="barcode" value="'.$object->barcode.'">';
print '&nbsp;<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
}
else
{
print $object->barcode;
}
print '</td></tr>'."\n";
}
// Accountancy sell code
print '<tr><td>'.$form->editfieldkey("ProductAccountancySellCode",'productaccountancycodesell',$object->accountancy_code_sell,$object,$user->rights->produit->creer|$user->rights->service->creer).'</td><td colspan="2">';
print $form->editfieldval("ProductAccountancySellCode",'productaccountancycodesell',$object->accountancy_code_sell,$object,$user->rights->produit->creer|$user->rights->service->creer);