Merge pull request #1184 from altatof/saisie_marges

define and manage user permissions for margin module
This commit is contained in:
Juanjo Menent 2013-08-20 03:24:03 -07:00
commit 9e16d505c9
6 changed files with 107 additions and 27 deletions

View File

@ -49,6 +49,8 @@ For users:
- New : Add pdf link into supplier invoice list and supplier order list
- New : Genrate auto the PDF for supplier invoice
- New : Add category into filter webservice thirdparty method getListOfThirdParties
- New : Allow to define margin or mark rate during quoting, ordering, invoicing
- New : User permissions on margin module
For translators:
- Qual: Normalized sort order of all languages files with english reference files.

View File

@ -2609,6 +2609,7 @@ abstract class CommonObject
{
global $conf,$langs,$object,$hookmanager;
global $form,$bcnd,$var;
global $user;
//Line extrafield
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
$extrafieldsline = new ExtraFields($this->db);
@ -2633,6 +2634,7 @@ abstract class CommonObject
{
global $conf,$langs,$object,$hookmanager;
global $form,$bcnd,$var;
global $user;
//Line extrafield
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
@ -2658,6 +2660,7 @@ abstract class CommonObject
{
global $conf,$user,$langs,$object,$hookmanager;
global $form,$bcnd,$var;
global $user;
//Line extrafield
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
@ -2729,9 +2732,9 @@ abstract class CommonObject
else
print '<td align="right" width="80">'.$langs->trans('CostPrice').'</td>';
if (! empty($conf->global->DISPLAY_MARGIN_RATES))
if (! empty($conf->global->DISPLAY_MARGIN_RATES) && $user->rights->margins->liretous)
print '<td align="right" width="50">'.$langs->trans('MarginRate').'</td>';
if (! empty($conf->global->DISPLAY_MARK_RATES))
if (! empty($conf->global->DISPLAY_MARK_RATES) && $user->rights->margins->liretous)
print '<td align="right" width="50">'.$langs->trans('MarkRate').'</td>';
}
@ -3167,6 +3170,8 @@ abstract class CommonObject
global $langs, $conf, $user;
if (! empty($user->societe_id)) return;
if (! $user->rights->margins->liretous) return;
$marginInfo = $this->getMarginInfos($force_price);
@ -3220,3 +3225,4 @@ abstract class CommonObject
}
}
?>

View File

@ -79,8 +79,8 @@ class modMargin extends DolibarrModules
// New pages on tabs
$this->tabs = array(
'product:+margin:Margins:margins:$conf->margin->enabled:/margin/tabs/productMargins.php?id=__ID__',
'thirdparty:+margin:Margins:margins:$conf->margin->enabled && empty($user->societe_id):/margin/tabs/thirdpartyMargins.php?socid=__ID__'
'product:+margin:Margins:margins:$user->rights->margins->liretous:/margin/tabs/productMargins.php?id=__ID__',
'thirdparty:+margin:Margins:margins:empty($user->societe_id) && $user->rights->margins->liretous:/margin/tabs/thirdpartyMargins.php?socid=__ID__'
);
@ -106,11 +106,30 @@ class modMargin extends DolibarrModules
'url'=>'/margin/index.php',
'langs'=>'margins', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
'position'=>100,
'enabled'=>'$conf->margin->enabled', // Define condition to show or hide menu entry. Use '$conf->monmodule->enabled' if entry must be visible if module is enabled.
'enabled'=>'$user->rights->margins->liretous', // Define condition to show or hide menu entry. Use '$conf->monmodule->enabled' if entry must be visible if module is enabled.
'perms'=>'1', // Use 'perms'=>'$user->rights->monmodule->level1->level2' if you want your menu with a permission rules
'target'=>'',
'user'=>2); // 0=Menu for internal users, 1=external users, 2=both
$r++;
// Permissions
$this->rights = array();
$this->rights_class = 'margins';
$r=0;
$r++;
$this->rights[$r][0] = 59001; // id de la permission
$this->rights[$r][1] = 'Visualiser les marges'; // libelle de la permission
$this->rights[$r][2] = 'r'; // type de la permission (deprecie a ce jour)
$this->rights[$r][3] = 1; // La permission est-elle une permission par defaut
$this->rights[$r][4] = 'liretous';
$r++;
$this->rights[$r][0] = 59002; // id de la permission
$this->rights[$r][1] = 'Définir les marges'; // libelle de la permission
$this->rights[$r][2] = 'w'; // type de la permission (deprecie a ce jour)
$this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
$this->rights[$r][4] = 'creer';
}
/**

View File

@ -61,13 +61,21 @@ if (! empty($conf->margin->enabled) && ! empty($object->element) && in_array($ob
?>
</td>
<?php
if(! empty($conf->global->DISPLAY_MARGIN_RATES))
if ($user->rights->margins->creer)
{
echo '<td align="right">'.$langs->trans('MarginRate').'</td>';
if(! empty($conf->global->DISPLAY_MARGIN_RATES))
{
echo '<td align="right">'.$langs->trans('MarginRate').'</td>';
}
if(! empty($conf->global->DISPLAY_MARK_RATES))
{
echo '<td align="right">'.$langs->trans('MarkRate').'</td>';
}
}
if(! empty($conf->global->DISPLAY_MARK_RATES))
else
{
echo '<td align="right">'.$langs->trans('MarkRate').'</td>';
if (! empty($conf->global->DISPLAY_MARGIN_RATES)) $colspan++;
if (! empty($conf->global->DISPLAY_MARK_RATES)) $colspan++;
}
}
?>
@ -125,12 +133,26 @@ if (! empty($conf->margin->enabled) && ! empty($object->element) && in_array($ob
value="<?php echo (isset($_POST["buying_price"])?$_POST["buying_price"]:''); ?>">
</td>
<?php
if ($user->rights->margins->creer)
{
if (! empty($conf->global->DISPLAY_MARGIN_RATES)) {
echo '<td align="right"><input type="text" size="2" name="np_marginRate" value="'.(isset($_POST["np_marginRate"])?$_POST["np_marginRate"]:'').'">%</td>';
}
elseif (! empty($conf->global->DISPLAY_MARK_RATES)) {
echo '<td align="right"><input type="text" size="2" name="np_markRate" value="'.(isset($_POST["np_markRate"])?$_POST["np_markRate"]:'').'">%</td>';
}
}
else
{
if (! empty($conf->global->DISPLAY_MARGIN_RATES)) {
$colspan++;
$coldisplay++;
}
if (! empty($conf->global->DISPLAY_MARK_RATES)) {
$colspan++;
$coldisplay++;
}
}
}
?>
<td align="center" valign="middle" colspan="<?php echo $colspan; ?>"><input type="submit" class="button" value="<?php echo $langs->trans('Add'); ?>" name="addline"></td>
@ -190,7 +212,9 @@ if (! empty($conf->service->enabled) && $dateSelector)
</form>
<?php if ($conf->margin->enabled) { ?>
<?php if ($conf->margin->enabled && $user->rights->margins->creer)
{
?>
<script type="text/javascript">
var npRate = null;
<?php

View File

@ -123,11 +123,11 @@
if (! empty($conf->margin->enabled) && empty($user->societe_id)) {
?>
<td align="right" class="nowrap"><?php $coldisplay++; ?><?php echo price($line->pa_ht); ?></td>
<?php if (! empty($conf->global->DISPLAY_MARGIN_RATES)) {?>
<?php if (! empty($conf->global->DISPLAY_MARGIN_RATES) && $user->rights->margins->liretous) {?>
<td align="right" class="nowrap"><?php $coldisplay++; ?><?php echo (($line->pa_ht == 0)?'n/a':price($line->marge_tx).'%'); ?></td>
<?php
}
if (! empty($conf->global->DISPLAY_MARK_RATES)) {?>
if (! empty($conf->global->DISPLAY_MARK_RATES) && $user->rights->margins->liretous) {?>
<td align="right" class="nowrap"><?php $coldisplay++; ?><?php echo price($line->marque_tx).'%'; ?></td>
<?php } } ?>

View File

@ -63,14 +63,6 @@ jQuery(document).ready(function() {
$colspan = 4;
if (! empty($usemargins))
{
if(! empty($conf->global->DISPLAY_MARGIN_RATES))
{
echo '<td align="right">'.$langs->trans('MarginRate').'</td>';
}
if(! empty($conf->global->DISPLAY_MARK_RATES))
{
echo '<td align="right">'.$langs->trans('MarkRate').'</td>';
}
?>
<td align="right">
<?php
@ -78,6 +70,23 @@ if (! empty($usemargins))
echo $langs->trans('BuyingPrice');
else
echo $langs->trans('CostPrice');
if ($user->rights->margins->creer)
{
if(! empty($conf->global->DISPLAY_MARGIN_RATES))
{
echo '<td align="right">'.$langs->trans('MarginRate').'</td>';
}
if(! empty($conf->global->DISPLAY_MARK_RATES))
{
echo '<td align="right">'.$langs->trans('MarkRate').'</td>';
}
}
else
{
if (! empty($conf->global->DISPLAY_MARGIN_RATES)) $colspan++;
if (! empty($conf->global->DISPLAY_MARK_RATES)) $colspan++;
}
?>
</td>
<?php
@ -125,18 +134,32 @@ else {
$colspan = 4;
if (! empty($usemargins))
{
if (! empty($conf->global->DISPLAY_MARGIN_RATES)) {
echo '<td align="right"><input type="text" size="2" name="np_marginRate" value="'.(isset($_POST["np_marginRate"])?$_POST["np_marginRate"]:'').'">%</td>';
}
elseif (! empty($conf->global->DISPLAY_MARK_RATES)) {
echo '<td align="right"><input type="text" size="2" name="np_markRate" value="'.(isset($_POST["np_markRate"])?$_POST["np_markRate"]:'').'">%</td>';
}
?>
<td align="right">
<select id="fournprice" name="fournprice" class="flat" style="display: none;"></select>
<input type="text" size="5" id="buying_price" name="buying_price" class="flat" value="<?php echo (isset($_POST["buying_price"])?$_POST["buying_price"]:''); ?>">
</td>
<?php
if ($user->rights->margins->creer)
{
if (! empty($conf->global->DISPLAY_MARGIN_RATES)) {
echo '<td align="right"><input type="text" size="2" name="np_marginRate" value="'.(isset($_POST["np_marginRate"])?$_POST["np_marginRate"]:'').'">%</td>';
}
elseif (! empty($conf->global->DISPLAY_MARK_RATES)) {
echo '<td align="right"><input type="text" size="2" name="np_markRate" value="'.(isset($_POST["np_markRate"])?$_POST["np_markRate"]:'').'">%</td>';
}
}
else
{
if (! empty($conf->global->DISPLAY_MARGIN_RATES)) {
$colspan++;
$coldisplay++;
}
if (! empty($conf->global->DISPLAY_MARK_RATES)) {
$colspan++;
$coldisplay++;
}
}
}
?>
<td align="center" valign="middle" colspan="<?php echo $colspan; ?>">
@ -204,6 +227,10 @@ if (! empty($usemargins))
{
?>
<script type="text/javascript">
<?php
if ($user->rights->margins->creer)
{
?>
var npRate = null;
<?php
if (! empty($conf->global->DISPLAY_MARGIN_RATES)) { ?>
@ -294,7 +321,9 @@ if (! empty($usemargins))
function formatFloat(num) {
return roundFloat(num).replace('.', ',');
}
<?php
}
?>
$("#idprod").change(function() {
$("#fournprice options").remove();
$("#fournprice").hide();