New: add product admin page for mass conversion
This commit is contained in:
parent
2a3db5a3ac
commit
01f1674231
@ -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";
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -131,7 +131,7 @@ llxHeader('',$title);
|
||||
$linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
|
||||
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);
|
||||
|
||||
@ -82,7 +82,7 @@ $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$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');
|
||||
|
||||
|
||||
177
htdocs/product/admin/product_tools.php
Normal file
177
htdocs/product/admin/product_tools.php
Normal file
@ -0,0 +1,177 @@
|
||||
<?php
|
||||
/* Copyright (C) 2012 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/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='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
|
||||
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 '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
|
||||
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'" />';
|
||||
print '<input type="hidden" name="action" value="convert" />';
|
||||
|
||||
print '<table class="noborder" width="100%">';
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td>'.$langs->trans("Parameters").'</td>'."\n";
|
||||
print '<td align="right" width="60">'.$langs->trans("Value").'</td>'."\n";
|
||||
print '</tr>'."\n";
|
||||
|
||||
$var=!$var;
|
||||
print '<tr '.$bc[$var].'>'."\n";
|
||||
print '<td>'.$langs->trans("OldVATRates").'</td>'."\n";
|
||||
print '<td width="60" align="right">'."\n";
|
||||
print $form->load_tva('oldvatrate', $oldvatrate);
|
||||
print '</td>'."\n";
|
||||
print '</tr>'."\n";
|
||||
|
||||
$var=!$var;
|
||||
print '<tr '.$bc[$var].'>'."\n";
|
||||
print '<td>'.$langs->trans("NewVATRates").'</td>'."\n";
|
||||
print '<td width="60" align="right">'."\n";
|
||||
print $form->load_tva('newvatrate', $newvatrate);
|
||||
print '</td>'."\n";
|
||||
print '</tr>'."\n";
|
||||
|
||||
$var=!$var;
|
||||
print '<tr '.$bc[$var].'>'."\n";
|
||||
print '<td>'.$langs->trans("PriceBaseType").'</td>'."\n";
|
||||
print '<td width="60" align="right">'."\n";
|
||||
print $form->load_PriceBaseType($price_base_type);
|
||||
print '</td>'."\n";
|
||||
print '</tr>'."\n";
|
||||
|
||||
print '</table>';
|
||||
print '</div>';
|
||||
|
||||
// Boutons actions
|
||||
print '<div class="tabsAction">';
|
||||
print '<input type="submit" id="convert_vatrate" name="convert_vatrate" value="'.$langs->trans("Convert").'" />';
|
||||
print '</div>';
|
||||
|
||||
print '</form>';
|
||||
|
||||
dol_htmloutput_mesg($mesg);
|
||||
|
||||
llxFooter();
|
||||
|
||||
$db->close();
|
||||
|
||||
?>
|
||||
Loading…
Reference in New Issue
Block a user