diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index a9d215da757..8582cb1a498 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -2903,8 +2903,9 @@ class Form function load_cache_vatrates($country_code) { global $langs; - - if (count($this->cache_vatrates)) return 0; // Cache deja charge + + $num = count($this->cache_vatrates); + if ($num > 0) return $num; // Cache deja charge $sql = "SELECT DISTINCT t.taux, t.recuperableonly"; $sql.= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_pays as p"; diff --git a/htdocs/core/lib/product.lib.php b/htdocs/core/lib/product.lib.php index f025a34e045..b5c5f822673 100644 --- a/htdocs/core/lib/product.lib.php +++ b/htdocs/core/lib/product.lib.php @@ -139,35 +139,42 @@ function product_prepare_head($object, $user) * Return array head with list of tabs to view object informations. * * @param Object $object Product -* @param string $tab Tab id * @return array head array with tabs */ -function product_admin_prepare_head($object, $tab) +function product_admin_prepare_head($object=null) { - global $langs, $conf, $user; - - $h = 0; - $head = array(); - - $head[$h][0] = DOL_URL_ROOT."/product/admin/product.php"; - $head[$h][1] = $tab; - $head[$h][2] = 'general'; - $h++; - - // Show more tabs from modules - // Entries must be declared in modules descriptor with line - // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab - // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab - complete_head_from_modules($conf,$langs,$object,$head,$h,'product_admin'); - - $head[$h][0] = DOL_URL_ROOT.'/product/admin/product_extrafields.php'; - $head[$h][1] = $langs->trans("ExtraFields"); - $head[$h][2] = 'attributes'; - $h++; - - complete_head_from_modules($conf,$langs,$object,$head,$h,'product_admin','remove'); - - return $head; + global $langs, $conf, $user; + + $h = 0; + $head = array(); + + $head[$h][0] = DOL_URL_ROOT."/product/admin/product.php"; + $head[$h][1] = $langs->trans('Parameters'); + $head[$h][2] = 'general'; + $h++; + + if ($conf->global->MAIN_FEATURES_LEVEL > 1) + { + $head[$h][0] = DOL_URL_ROOT.'/product/admin/product_tools.php'; + $head[$h][1] = $langs->trans("Tools"); + $head[$h][2] = 'tools'; + $h++; + } + + // Show more tabs from modules + // Entries must be declared in modules descriptor with line + // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab + // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab + complete_head_from_modules($conf,$langs,$object,$head,$h,'product_admin'); + + $head[$h][0] = DOL_URL_ROOT.'/product/admin/product_extrafields.php'; + $head[$h][1] = $langs->trans("ExtraFields"); + $head[$h][2] = 'attributes'; + $h++; + + complete_head_from_modules($conf,$langs,$object,$head,$h,'product_admin','remove'); + + return $head; } diff --git a/htdocs/product/admin/product.php b/htdocs/product/admin/product.php index 5e4acbea39d..7340502119c 100644 --- a/htdocs/product/admin/product.php +++ b/htdocs/product/admin/product.php @@ -131,7 +131,7 @@ llxHeader('',$title); $linkback=''.$langs->trans("BackToModuleList").''; print_fiche_titre($title,$linkback,'setup'); -$head = product_admin_prepare_head(null, $tab); +$head = product_admin_prepare_head(); dol_fiche_head($head, 'general', $tab, 0, 'product'); $form=new Form($db); diff --git a/htdocs/product/admin/product_extrafields.php b/htdocs/product/admin/product_extrafields.php index c24782a9396..d417b7319c5 100755 --- a/htdocs/product/admin/product_extrafields.php +++ b/htdocs/product/admin/product_extrafields.php @@ -82,7 +82,7 @@ $linkback=''.$langs->trans("BackToM print_fiche_titre($title,$linkback,'setup'); -$head = product_admin_prepare_head(null, $tab); +$head = product_admin_prepare_head(); dol_fiche_head($head, 'attributes', $tab, 0, 'product'); diff --git a/htdocs/product/admin/product_tools.php b/htdocs/product/admin/product_tools.php new file mode 100644 index 00000000000..85299312e4b --- /dev/null +++ b/htdocs/product/admin/product_tools.php @@ -0,0 +1,177 @@ + + * + * 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 . + */ + +/** + * \file htdocs/product/admin/product_tools.php + * \ingroup product + * \brief Setup page of product module + */ + +require("../../main.inc.php"); +require_once(DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php"); +require_once(DOL_DOCUMENT_ROOT."/core/lib/product.lib.php"); +require_once(DOL_DOCUMENT_ROOT."/product/class/product.class.php"); + +$langs->load("admin"); +$langs->load("products"); + +// Security check +if (! $user->admin) accessforbidden(); + +$action = GETPOST('action','alpha'); +$oldvatrate=GETPOST('oldvatrate'); +$newvatrate=GETPOST('newvatrate'); +$price_base_type=GETPOST('price_base_type'); + +/* + * Actions + */ + +if ($action == 'convert') +{ + $error=0; + + $object = new Product($db); + + $db->begin(); + + $sql = 'SELECT rowid'; + $sql.= ' FROM '.MAIN_DB_PREFIX.'product'; + $sql.= ' WHERE entity IN ('.getEntity('product',1).')'; + $sql.= ' AND tva_tx = "'.$oldvatrate.'"'; + + $resql=$db->query($sql); + if ($resql) + { + $num = $db->num_rows($resql); + if ($num) + { + $i = 0; + while ($i < $num) + { + $obj = $db->fetch_object($result); + + $object->fetch($obj->rowid); + + if ($price_base_type == 'TTC') + { + $newprice=price2num($object->price_ttc,'MU'); + } + else + { + $newprice=price2num($object->price,'MU'); + } + + $newvat=str_replace('*','',$newvatrate); + + $ret=$object->updatePrice($object->id, $newprice, $price_base_type, $user, $newvat); + if ($ret < 0) $error++; + + $i++; + } + + if (! $error) + { + $db->commit(); + } + else + { + $db->rollback(); + } + } + } +} + +/* + * View + */ + +$title = $langs->trans('ProductServiceSetup'); +$tab = $langs->trans("ProductsAndServices"); +if (empty($conf->produit->enabled)) +{ + $title = $langs->trans('ServiceSetup'); + $tab = $langs->trans('Services'); +} +else if (empty($conf->service->enabled)) +{ + $title = $langs->trans('ProductSetup'); + $tab = $langs->trans('Products'); +} + +llxHeader('',$title); + +$linkback=''.$langs->trans("BackToModuleList").''; +print_fiche_titre($title,$linkback,'setup'); + +$head = product_admin_prepare_head(); +dol_fiche_head($head, 'tools', $tab, 0, 'product'); + +$form=new Form($db); +$var=true; + +print '
'; +print ''; +print ''; + +print ''; +print ''; +print ''."\n"; +print ''."\n"; +print ''."\n"; + +$var=!$var; +print ''."\n"; +print ''."\n"; +print ''."\n"; +print ''."\n"; + +$var=!$var; +print ''."\n"; +print ''."\n"; +print ''."\n"; +print ''."\n"; + +$var=!$var; +print ''."\n"; +print ''."\n"; +print ''."\n"; +print ''."\n"; + +print '
'.$langs->trans("Parameters").''.$langs->trans("Value").'
'.$langs->trans("OldVATRates").''."\n"; +print $form->load_tva('oldvatrate', $oldvatrate); +print '
'.$langs->trans("NewVATRates").''."\n"; +print $form->load_tva('newvatrate', $newvatrate); +print '
'.$langs->trans("PriceBaseType").''."\n"; +print $form->load_PriceBaseType($price_base_type); +print '
'; +print ''; + +// Boutons actions +print '
'; +print ''; +print '
'; + +print '
'; + +dol_htmloutput_mesg($mesg); + +llxFooter(); + +$db->close(); + +?>