dolibarr/htdocs/product/class/html.formproduct.class.php

200 lines
6.6 KiB
PHP
Raw Normal View History

2008-10-25 17:53:16 +02:00
<?php
/* Copyright (C) 2008-2009 Laurent Destailleur <eldy@users.sourceforge.net>
2008-10-25 17:53:16 +02:00
*
* 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
2008-10-25 17:53:16 +02:00
* (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
2011-08-01 01:19:04 +02:00
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2008-10-25 17:53:16 +02:00
*/
/**
2010-07-21 14:35:56 +02:00
* \file htdocs/product/class/html.formproduct.class.php
* \brief Fichier de la classe des fonctions predefinie de composants html
2008-10-25 17:53:16 +02:00
*/
/**
* \class FormProduct
* \brief Class with static methods for building HTML components related to products
2008-10-25 17:53:16 +02:00
* \remarks Only common components must be here.
*/
class FormProduct
{
var $db;
var $error;
// Cache arrays
var $cache_warehouses=array();
var $tva_taux_value;
var $tva_taux_libelle;
/**
* Constructor
*
* @param DoliDB $db Database handler
2008-10-25 17:53:16 +02:00
*/
function __construct($db)
2008-10-25 17:53:16 +02:00
{
$this->db = $db;
2008-10-25 17:53:16 +02:00
return 1;
}
/**
* Load in cache array list of warehouses
* If fk_product is not 0, we do not use cache
*
* @param int $fk_product Add quantity of stock in label for product with id fk_product. Nothing if 0.
* @return int Nb of loaded lines, 0 if already loaded, <0 if KO
2008-10-25 17:53:16 +02:00
*/
2010-06-17 22:24:11 +02:00
function loadWarehouses($fk_product=0)
2008-10-25 17:53:16 +02:00
{
global $conf, $langs;
2008-10-25 17:53:16 +02:00
2011-09-17 21:49:50 +02:00
if (empty($fk_product) && count($this->cache_warehouses)) return 0; // Cache already loaded and we do not want a list with information specific to a product
2008-10-25 17:53:16 +02:00
2010-06-17 22:24:11 +02:00
$sql = "SELECT e.rowid, e.label";
if ($fk_product) $sql.= ", ps.reel";
$sql.= " FROM ".MAIN_DB_PREFIX."entrepot as e";
if ($fk_product)
{
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_stock as ps on ps.fk_entrepot = e.rowid";
$sql.= " AND ps.fk_product = '".$fk_product."'";
}
$sql.= " WHERE e.entity = ".$conf->entity;
$sql.= " AND e.statut = 1";
2010-06-17 22:24:11 +02:00
$sql.= " ORDER BY e.label";
2008-10-28 22:59:53 +01:00
dol_syslog(get_class($this).'::loadWarehouses sql='.$sql,LOG_DEBUG);
2008-10-25 17:53:16 +02:00
$resql = $this->db->query($sql);
if ($resql)
{
$num = $this->db->num_rows($resql);
$i = 0;
while ($i < $num)
{
$obj = $this->db->fetch_object($resql);
$this->cache_warehouses[$obj->rowid]['id'] =$obj->rowid;
$this->cache_warehouses[$obj->rowid]['label']=$obj->label;
2010-06-17 22:24:11 +02:00
if ($fk_product) $this->cache_warehouses[$obj->rowid]['stock']=$obj->reel;
2008-10-25 17:53:16 +02:00
$i++;
}
return $num;
}
2008-10-28 22:59:53 +01:00
else
2008-10-25 17:53:16 +02:00
{
dol_print_error($this->db);
2008-10-25 17:53:16 +02:00
return -1;
}
}
2008-10-28 22:59:53 +01:00
2008-10-25 17:53:16 +02:00
/**
* Return list of warehouses
*
* @param int $selected Id of preselected warehouse ('' for no value, 'ifone'=select value if one value otherwise no value)
* @param string $htmlname Name of html select html
* @param string $filtertype For filter
* @param int $empty 1=Can be empty, 0 if not
* @param int $disabled 1=Select is disabled
* @param int $fk_product Add quantity of stock in label for product with id fk_product. Nothing if 0.
2013-04-20 00:10:20 +02:00
* @param string $empty_label Empty label if needed (only if $empty=1)
* @return string HTML select
2008-10-25 17:53:16 +02:00
*/
2013-04-20 00:10:20 +02:00
function selectWarehouses($selected='',$htmlname='idwarehouse',$filtertype='',$empty=0,$disabled=0,$fk_product=0,$empty_label='')
2008-10-25 17:53:16 +02:00
{
global $langs,$user;
dol_syslog(get_class($this)."::selectWarehouses $selected, $htmlname, $filtertype, $empty, $disabled, $fk_product",LOG_DEBUG);
2008-10-25 17:53:16 +02:00
2010-06-17 22:24:11 +02:00
$this->loadWarehouses($fk_product);
$nbofwarehouses=count($this->cache_warehouses);
2011-11-07 15:04:02 +01:00
$out='<select class="flat"'.($disabled?' disabled="disabled"':'').' id="'.$htmlname.'" name="'.($htmlname.($disabled?'_disabled':'')).'">';
2013-04-20 00:10:20 +02:00
if ($empty) $out.='<option value="-1">'.($empty_label?$empty_label:'&nbsp;').'</option>';
2008-10-25 17:53:16 +02:00
foreach($this->cache_warehouses as $id => $arraytypes)
{
$out.='<option value="'.$id.'"';
if ($selected == $id || ($selected == 'ifone' && $nbofwarehouses == 1)) $out.=' selected="selected"';
$out.='>';
$out.=$arraytypes['label'];
if ($fk_product) $out.=' ('.$langs->trans("Stock").': '.($arraytypes['stock']>0?$arraytypes['stock']:'?').')';
$out.='</option>';
2008-10-25 17:53:16 +02:00
}
$out.='</select>';
if ($disabled) $out.='<input type="hidden" name="'.$htmlname.'" value="'.(($selected>0)?$selected:'').'">';
2010-06-17 18:53:26 +02:00
return $out;
2008-10-25 17:53:16 +02:00
}
2010-05-13 01:03:33 +02:00
2008-10-25 19:27:15 +02:00
/**
2012-01-04 13:54:07 +01:00
* Output a combo box with list of units
* pour l'instant on ne definit pas les unites dans la base
*
* @param string $name Name of HTML field
* @param string $measuring_style Unit to show: weight, size, surface, volume
* @param string $default Force unit
* @param int $adddefault Add empty unit called "Default"
* @return void
2008-10-25 19:27:15 +02:00
*/
function select_measuring_units($name='measuring_units', $measuring_style='', $default='0', $adddefault=0)
{
print $this->load_measuring_units($name, $measuring_style, $default, $adddefault);
}
2010-05-13 01:03:33 +02:00
/**
2010-08-26 13:59:41 +02:00
* Return a combo box with list of units
2012-01-04 13:54:07 +01:00
* For the moment, units labels are defined in measuring_units_string
*
* @param string $name Name of HTML field
* @param string $measuring_style Unit to show: weight, size, surface, volume
* @param string $default Force unit
* @param int $adddefault Add empty unit called "Default"
* @return void
*/
function load_measuring_units($name='measuring_units', $measuring_style='', $default='0', $adddefault=0)
2008-10-25 19:27:15 +02:00
{
global $langs,$conf,$mysoc;
$langs->load("other");
2010-05-13 01:03:33 +02:00
$return='';
2008-10-25 19:27:15 +02:00
2010-08-24 20:40:17 +02:00
$measuring_units=array();
if ($measuring_style == 'weight') $measuring_units=array(-6=>1,-3=>1,0=>1,3=>1,99=>1);
else if ($measuring_style == 'size') $measuring_units=array(-3=>1,-2=>1,-1=>1,0=>1,98=>1,99=>1);
else if ($measuring_style == 'surface') $measuring_units=array(-6=>1,-4=>1,-2=>1,0=>1,98=>1,99=>1);
else if ($measuring_style == 'volume') $measuring_units=array(-9=>1,-6=>1,-3=>1,0=>1,88=>1,89=>1,97=>1,99=>1,/* 98=>1 */); // Liter is not used as already available with dm3
2008-10-25 19:27:15 +02:00
$return.= '<select class="flat" name="'.$name.'">';
if ($adddefault) $return.= '<option value="0">'.$langs->trans("Default").'</option>';
2008-10-25 19:27:15 +02:00
foreach ($measuring_units as $key => $value)
{
$return.= '<option value="'.$key.'"';
2008-10-25 19:27:15 +02:00
if ($key == $default)
{
2010-11-01 17:00:38 +01:00
$return.= ' selected="selected"';
2008-10-25 19:27:15 +02:00
}
2010-08-24 20:40:17 +02:00
//$return.= '>'.$value.'</option>';
$return.= '>'.measuring_units_string($key,$measuring_style).'</option>';
2008-10-25 19:27:15 +02:00
}
$return.= '</select>';
2010-05-13 01:03:33 +02:00
return $return;
2008-10-25 19:27:15 +02:00
}
2008-10-28 22:59:53 +01:00
2008-10-25 17:53:16 +02:00
}
?>