extrafield totalizable
This commit is contained in:
parent
0c0c9269d5
commit
2dd907a8e1
@ -988,27 +988,40 @@ if ($resql)
|
||||
}
|
||||
|
||||
// Show total line
|
||||
if (isset($totalarray['totalhtfield'])
|
||||
if (isset($totalarray['totalhtfield'])
|
||||
|| isset($totalarray['totalvatfield'])
|
||||
|| isset($totalarray['totalttcfield'])
|
||||
|| isset($totalarray['totalamfield'])
|
||||
|| isset($totalarray['totalrtpfield'])
|
||||
|| isset($totalarray['totalizable'])
|
||||
)
|
||||
{
|
||||
print '<tr class="liste_total">';
|
||||
$i=0;
|
||||
while ($i < $totalarray['nbfield'])
|
||||
{
|
||||
$i++;
|
||||
if ($i == 1)
|
||||
{
|
||||
$i++;
|
||||
if ($i == 1)
|
||||
{
|
||||
if ($num < $limit && empty($offset)) print '<td align="left">'.$langs->trans("Total").'</td>';
|
||||
else print '<td align="left">'.$langs->trans("Totalforthispage").'</td>';
|
||||
}
|
||||
elseif ($totalarray['totalhtfield'] == $i) print '<td align="right">'.price($totalarray['totalht']).'</td>';
|
||||
elseif ($totalarray['totalvatfield'] == $i) print '<td align="right">'.price($totalarray['totalvat']).'</td>';
|
||||
elseif ($totalarray['totalttcfield'] == $i) print '<td align="right">'.price($totalarray['totalttc']).'</td>';
|
||||
else print '<td></td>';
|
||||
}
|
||||
elseif ($totalarray['totalhtfield'] == $i) print '<td align="right">'.price($totalarray['totalht']).'</td>';
|
||||
elseif ($totalarray['totalvatfield'] == $i) print '<td align="right">'.price($totalarray['totalvat']).'</td>';
|
||||
elseif ($totalarray['totalttcfield'] == $i) print '<td align="right">'.price($totalarray['totalttc']).'</td>';
|
||||
elseif ($totalarray['totalizable']) {
|
||||
$printed = false;
|
||||
foreach ($totalarray['totalizable'] as $totalizable) {
|
||||
if ($totalizable['pos']==$i && ! $printed) {
|
||||
print '<td align="right">'.price($totalizable['total']).'</td>';
|
||||
$printed = true;
|
||||
}
|
||||
}
|
||||
if (! $printed) {
|
||||
print '<td></td>';
|
||||
}
|
||||
}
|
||||
else print '<td></td>';
|
||||
}
|
||||
print '</tr>';
|
||||
}
|
||||
|
||||
@ -181,7 +181,9 @@ if ($action == 'add')
|
||||
GETPOST('help','alpha'),
|
||||
GETPOST('computed_value','alpha'),
|
||||
(GETPOST('entitycurrentorall', 'alpha')?0:''),
|
||||
GETPOST('langfile', 'alpha')
|
||||
GETPOST('langfile', 'alpha'),
|
||||
1,
|
||||
(GETPOST('totalizable', 'alpha')?1:0)
|
||||
);
|
||||
if ($result > 0)
|
||||
{
|
||||
@ -331,7 +333,7 @@ if ($action == 'update')
|
||||
$visibility = GETPOST('list', 'alpha');
|
||||
if ($type == 'separate') $visibility=3;
|
||||
|
||||
$result=$extrafields->update(
|
||||
$result=$extrafields->update(
|
||||
GETPOST('attrname', 'alpha'),
|
||||
GETPOST('label', 'alpha'),
|
||||
$type,
|
||||
@ -348,7 +350,9 @@ if ($action == 'update')
|
||||
GETPOST('default_value','alpha'),
|
||||
GETPOST('computed_value','alpha'),
|
||||
(GETPOST('entitycurrentorall', 'alpha')?0:''),
|
||||
GETPOST('langfile')
|
||||
GETPOST('langfile'),
|
||||
1,
|
||||
(GETPOST('totalizable', 'alpha')?1:0)
|
||||
);
|
||||
if ($result > 0)
|
||||
{
|
||||
|
||||
@ -9,6 +9,7 @@
|
||||
* Copyright (C) 2015 Charles-Fr BENKE <charles.fr@benke.fr>
|
||||
* Copyright (C) 2016 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
|
||||
* Copyright (C) 2017 Nicolas ZABOURI <info@inovea-conseil.com>
|
||||
* Copyright (C) 2018 Frédéric France <frederic.france@netlogic.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
|
||||
@ -516,14 +517,15 @@ class ExtraFields
|
||||
* @param string $entity Entity of extrafields
|
||||
* @param string $langfile Language file
|
||||
* @param string $enabled Condition to have the field enabled or not
|
||||
* @param int $totalizable Is extrafield totalizable on list
|
||||
* @return int >0 if OK, <=0 if KO
|
||||
*/
|
||||
function update($attrname, $label, $type, $length, $elementtype, $unique=0, $required=0, $pos=0, $param='', $alwayseditable=0, $perms='', $list='', $help='', $default='', $computed='', $entity='', $langfile='', $enabled='1')
|
||||
function update($attrname, $label, $type, $length, $elementtype, $unique=0, $required=0, $pos=0, $param='', $alwayseditable=0, $perms='', $list='', $help='', $default='', $computed='', $entity='', $langfile='', $enabled='1', $totalizable=0)
|
||||
{
|
||||
if ($elementtype == 'thirdparty') $elementtype='societe';
|
||||
if ($elementtype == 'contact') $elementtype='socpeople';
|
||||
|
||||
$table=$elementtype.'_extrafields';
|
||||
$table=$elementtype.'_extrafields';
|
||||
if ($elementtype == 'categorie') $table='categories_extrafields';
|
||||
|
||||
if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-_]*$/",$attrname))
|
||||
@ -568,7 +570,7 @@ class ExtraFields
|
||||
{
|
||||
if ($label)
|
||||
{
|
||||
$result=$this->update_label($attrname,$label,$type,$length,$elementtype,$unique,$required,$pos,$param,$alwayseditable,$perms,$list,$help,$default,$computed,$entity,$langfile,$enabled);
|
||||
$result=$this->update_label($attrname,$label,$type,$length,$elementtype,$unique,$required,$pos,$param,$alwayseditable,$perms,$list,$help,$default,$computed,$entity,$langfile,$enabled, $totalizable);
|
||||
}
|
||||
if ($result > 0)
|
||||
{
|
||||
@ -625,12 +627,13 @@ class ExtraFields
|
||||
* @param string $entity Entity of extrafields
|
||||
* @param string $langfile Language file
|
||||
* @param string $enabled Condition to have the field enabled or not
|
||||
* @return int <=0 if KO, >0 if OK
|
||||
* @param int $totalizable Is extrafield totalizable on list
|
||||
* @return int <=0 if KO, >0 if OK
|
||||
*/
|
||||
private function update_label($attrname,$label,$type,$size,$elementtype,$unique=0,$required=0,$pos=0,$param='',$alwayseditable=0,$perms='',$list='0',$help='',$default='',$computed='',$entity='',$langfile='',$enabled='1')
|
||||
private function update_label($attrname,$label,$type,$size,$elementtype,$unique=0,$required=0,$pos=0,$param='',$alwayseditable=0,$perms='',$list='0',$help='',$default='',$computed='',$entity='',$langfile='',$enabled='1', $totalizable=0)
|
||||
{
|
||||
global $conf, $user;
|
||||
dol_syslog(get_class($this)."::update_label ".$attrname.", ".$label.", ".$type.", ".$size.", ".$elementtype.", ".$unique.", ".$required.", ".$pos.", ".$alwayseditable.", ".$perms.", ".$list.", ".$default.", ".$computed.", ".$entity.", ".$langfile.", ".$enabled);
|
||||
dol_syslog(get_class($this)."::update_label ".$attrname.", ".$label.", ".$type.", ".$size.", ".$elementtype.", ".$unique.", ".$required.", ".$pos.", ".$alwayseditable.", ".$perms.", ".$list.", ".$default.", ".$computed.", ".$entity.", ".$langfile.", ".$enabled.", ".$totalizable);
|
||||
|
||||
// Clean parameters
|
||||
if ($elementtype == 'thirdparty') $elementtype='societe';
|
||||
@ -638,6 +641,9 @@ class ExtraFields
|
||||
|
||||
if (empty($pos)) $pos=0;
|
||||
if (empty($list)) $list='0';
|
||||
if (empty($totalizable)) {
|
||||
$totalizable = 0;
|
||||
}
|
||||
if (empty($required)) $required=0;
|
||||
if (empty($unique)) $unique=0;
|
||||
if (empty($alwayseditable)) $alwayseditable=0;
|
||||
@ -681,6 +687,7 @@ class ExtraFields
|
||||
$sql.= " alwayseditable,";
|
||||
$sql.= " param,";
|
||||
$sql.= " list,";
|
||||
$sql.= " totalizable,";
|
||||
$sql.= " fielddefault,";
|
||||
$sql.= " fieldcomputed,";
|
||||
$sql.= " fk_user_author,";
|
||||
@ -703,6 +710,7 @@ class ExtraFields
|
||||
$sql.= " '".$this->db->escape($alwayseditable)."',";
|
||||
$sql.= " '".$this->db->escape($params)."',";
|
||||
$sql.= " '".$this->db->escape($list)."', ";
|
||||
$sql.= " ".$totalizable.",";
|
||||
$sql.= " ".(($default!='')?"'".$this->db->escape($default)."'":"null").",";
|
||||
$sql.= " ".($computed?"'".$this->db->escape($computed)."'":"null").",";
|
||||
$sql .= " " . $user->id . ",";
|
||||
@ -773,7 +781,7 @@ class ExtraFields
|
||||
// We should not have several time this log. If we have, there is some optimization to do by calling a simple $object->fetch_optionals() that include cache management.
|
||||
dol_syslog("fetch_name_optionals_label elementtype=".$elementtype);
|
||||
|
||||
$sql = "SELECT rowid,name,label,type,size,elementtype,fieldunique,fieldrequired,param,pos,alwayseditable,perms,langs,list,fielddefault,fieldcomputed,entity,enabled,help";
|
||||
$sql = "SELECT rowid,name,label,type,size,elementtype,fieldunique,fieldrequired,param,pos,alwayseditable,perms,langs,list,totalizable,fielddefault,fieldcomputed,entity,enabled,help";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."extrafields";
|
||||
$sql.= " WHERE entity IN (0,".$conf->entity.")";
|
||||
if ($elementtype) $sql.= " AND elementtype = '".$elementtype."'"; // Filed with object->table_element
|
||||
@ -807,6 +815,7 @@ class ExtraFields
|
||||
$this->attribute_perms[$tab->name]=(strlen($tab->perms) == 0 ? 1 : $tab->perms);
|
||||
$this->attribute_langfile[$tab->name]=$tab->langs;
|
||||
$this->attribute_list[$tab->name]=$tab->list;
|
||||
$this->attribute_totalizable[$tab->name]=$tab->totalizable;
|
||||
$this->attribute_entityid[$tab->name]=$tab->entity;
|
||||
$this->attribute_entitylabel[$tab->name]=(empty($labelmulticompany[$tab->entity])?'Entity'.$tab->entity:$labelmulticompany[$tab->entity]);
|
||||
|
||||
@ -825,6 +834,7 @@ class ExtraFields
|
||||
$this->attributes[$tab->elementtype]['perms'][$tab->name]=(strlen($tab->perms) == 0 ? 1 : $tab->perms);
|
||||
$this->attributes[$tab->elementtype]['langfile'][$tab->name]=$tab->langs;
|
||||
$this->attributes[$tab->elementtype]['list'][$tab->name]=$tab->list;
|
||||
$this->attributes[$tab->elementtype]['totalizable'][$tab->name]=$tab->totalizable;
|
||||
$this->attributes[$tab->elementtype]['entityid'][$tab->name]=$tab->entity;
|
||||
$this->attributes[$tab->elementtype]['entitylabel'][$tab->name]=(empty($labelmulticompany[$tab->entity])?'Entity'.$tab->entity:$labelmulticompany[$tab->entity]);
|
||||
$this->attributes[$tab->elementtype]['enabled'][$tab->name]=$tab->enabled;
|
||||
@ -886,6 +896,7 @@ class ExtraFields
|
||||
$perms=dol_eval($this->attributes[$extrafieldsobjectkey]['perms'][$key], 1);
|
||||
$langfile=$this->attributes[$extrafieldsobjectkey]['langfile'][$key];
|
||||
$list=dol_eval($this->attributes[$extrafieldsobjectkey]['list'][$key], 1);
|
||||
$totalizable=$this->attributes[$extrafieldsobjectkey]['totalizable'][$key];
|
||||
$help=$this->attributes[$extrafieldsobjectkey]['help'][$key];
|
||||
$hidden=(empty($list) ? 1 : 0); // If empty, we are sure it is hidden, otherwise we show. If it depends on mode (view/create/edit form or list, this must be filtered by caller)
|
||||
}
|
||||
@ -902,6 +913,7 @@ class ExtraFields
|
||||
$param=$this->attribute_param[$key];
|
||||
$langfile=$this->attribute_langfile[$key];
|
||||
$list=$this->attribute_list[$key];
|
||||
$totalizable=$this->attribute_totalizable[$key];
|
||||
$hidden=(empty($list) ? 1 : 0); // If empty, we are sure it is hidden, otherwise we show. If it depends on mode (view/create/edit form or list, this must be filtered by caller)
|
||||
}
|
||||
|
||||
@ -1753,7 +1765,7 @@ class ExtraFields
|
||||
|
||||
$align='';
|
||||
|
||||
if ($type == 'date')
|
||||
if ($type == 'date')
|
||||
{
|
||||
$align="center";
|
||||
}
|
||||
@ -1781,6 +1793,10 @@ class ExtraFields
|
||||
{
|
||||
$align="center";
|
||||
}
|
||||
elseif ($type == 'price')
|
||||
{
|
||||
$align="right";
|
||||
}
|
||||
|
||||
return $align;
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
/* Copyright (C) 2010-2017 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2012 Regis Houssin <regis.houssin@capnetworks.com>
|
||||
* Copyright (C) 2016 Charlie Benke <charlie@patas-monkey.com>
|
||||
* Copyright (C) 2018 Frédéric France <frederic.france@netlogic.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
|
||||
@ -52,6 +53,7 @@ $langs->load("modulebuilder");
|
||||
var required = jQuery("#required");
|
||||
var alwayseditable = jQuery("#alwayseditable");
|
||||
var list = jQuery("#list");
|
||||
var totalizable = jQuery("#totalizable");
|
||||
<?php
|
||||
if ((GETPOST('type','alpha') != "select") && (GETPOST('type','alpha') != "sellist"))
|
||||
{
|
||||
@ -189,6 +191,8 @@ $langs->load("modulebuilder");
|
||||
<!-- Visibility -->
|
||||
<tr><td class="extra_list"><?php echo $form->textwithpicto($langs->trans("Visibility"), $langs->trans("VisibleDesc")); ?>
|
||||
</td><td class="valeur"><input id="list" class="minwidth100" type="text" name="list" value="<?php echo GETPOST('list','int')!='' ? GETPOST('list','int') : '1'; ?>"></td></tr>
|
||||
<!-- Totalizable -->
|
||||
<tr class="extra_totalizable"><td><?php echo $langs->trans("Totalizable"); ?></td><td class="valeur"><input id="totalizable" type="checkbox" name="totalizable"<?php echo ((GETPOST('totalizable','alpha') || GETPOST('button','alpha'))?' checked':''); ?>></td></tr>
|
||||
<!-- Help tooltip -->
|
||||
<tr class="help"><td><?php echo $form->textwithpicto($langs->trans("HelpOnTooltip"), $langs->trans("HelpOnTooltipDesc")); ?></td><td class="valeur"><input id="help" class="quatrevingtpercent" type="text" name="help" value="<?php echo dol_escape_htmltag($help); ?>"></td></tr>
|
||||
<?php if ($conf->multicompany->enabled) { ?>
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
/* Copyright (C) 2010-2012 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2012 Regis Houssin <regis.houssin@capnetworks.com>
|
||||
* Copyright (C) 2018 Frédéric France <frederic.france@netlogic.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
|
||||
@ -51,6 +52,7 @@ $langs->load("modulebuilder");
|
||||
var required = jQuery("#required");
|
||||
var alwayseditable = jQuery("#alwayseditable");
|
||||
var list = jQuery("#list");
|
||||
var totalizable = jQuery("#totalizable");
|
||||
<?php
|
||||
if((GETPOST('type','alpha') != "select") && (GETPOST('type','alpha') != "sellist"))
|
||||
{
|
||||
@ -156,6 +158,7 @@ $param=$extrafields->attributes[$elementtype]['param'][$attrname];
|
||||
$perms=$extrafields->attributes[$elementtype]['perms'][$attrname];
|
||||
$langfile=$extrafields->attributes[$elementtype]['langfile'][$attrname];
|
||||
$list=$extrafields->attributes[$elementtype]['list'][$attrname];
|
||||
$totalizable = $extrafields->attributes[$elementtype]['totalizable'][$attrname];
|
||||
$help=$extrafields->attributes[$elementtype]['help'][$attrname];
|
||||
$entitycurrentorall=$extrafields->attributes[$elementtype]['entityid'][$attrname];
|
||||
|
||||
@ -251,6 +254,7 @@ else
|
||||
<tr class="extra_alwayseditable"><td><?php echo $langs->trans("AlwaysEditable"); ?></td><td class="valeur"><input id="alwayseditable" type="checkbox" name="alwayseditable"<?php echo ($alwayseditable?' checked':''); ?>></td></tr>
|
||||
<tr><td class="extra_list"><?php echo $form->textwithpicto($langs->trans("Visibility"), $langs->trans("VisibleDesc")); ?>
|
||||
</td><td class="valeur"><input id="list" class="minwidth100" type="text" name="list" value="<?php echo ($list!=''?$list:'1'); ?>"></td></tr>
|
||||
<tr class="extra_totalizable"><td><?php echo $form->textwithpicto($langs->trans("Totalizable"), $langs->trans("TotalizableDesc")); ?></td><td class="valeur"><input id="totalizable" type="checkbox" name="totalizable"<?php echo ($totalizable?' checked':''); ?>></td></tr>
|
||||
<!-- Help tooltip -->
|
||||
<tr class="help"><td><?php echo $form->textwithpicto($langs->trans("HelpOnTooltip"), $langs->trans("HelpOnTooltipDesc")); ?></td><td class="valeur"><input id="help" class="quatrevingtpercent" type="text" name="help" value="<?php echo dol_escape_htmltag($help); ?>"></td></tr>
|
||||
<?php if ($conf->multicompany->enabled) { ?>
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
/* Copyright (C) 2010-2018 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2012-2017 Regis Houssin <regis.houssin@capnetworks.com>
|
||||
* Copyright (C) 2018 Frédéric France <frederic.france@netlogic.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
|
||||
@ -61,6 +62,7 @@ print '<td align="center">'.$langs->trans("Unique").'</td>';
|
||||
print '<td align="center">'.$langs->trans("Required").'</td>';
|
||||
print '<td align="center">'.$langs->trans("AlwaysEditable").'</td>';
|
||||
print '<td align="center">'.$form->textwithpicto($langs->trans("Visible"), $langs->trans("VisibleDesc")).'</td>';
|
||||
print '<td align="center">'.$form->textwithpicto($langs->trans("Totalizable"), $langs->trans("TotalizableDesc")).'</td>';
|
||||
if ($conf->multicompany->enabled) {
|
||||
print '<td align="center">'.$langs->trans("Entities").'</td>';
|
||||
}
|
||||
@ -88,6 +90,7 @@ if (is_array($extrafields->attributes[$elementtype]['type']) && count($extrafiel
|
||||
print '<td align="center">'.yn($extrafields->attributes[$elementtype]['required'][$key])."</td>\n";
|
||||
print '<td align="center">'.yn($extrafields->attributes[$elementtype]['alwayseditable'][$key])."</td>\n";
|
||||
print '<td align="center">'.$extrafields->attributes[$elementtype]['list'][$key]."</td>\n";
|
||||
print '<td align="center">'.yn($extrafields->attributes[$elementtype]['totalizable'][$key])."</td>\n";
|
||||
if (! empty($conf->multicompany->enabled)) {
|
||||
print '<td align="center">'.($extrafields->attributes[$elementtype]['entityid'][$key]==0?$langs->trans("All"):$extrafields->attributes[$elementtype]['entitylabel'][$key]).'</td>';
|
||||
}
|
||||
|
||||
@ -40,6 +40,14 @@ if (! empty($extrafieldsobjectkey)) // $extrafieldsobject is the $object->table_
|
||||
print $extrafields->showOutputField($key, $value, '', $extrafieldsobjectkey);
|
||||
print '</td>';
|
||||
if (! $i) $totalarray['nbfield']++;
|
||||
|
||||
if ($extrafields->attributes[$extrafieldsobjectkey]['totalizable'][$key]) {
|
||||
if (! $i) {
|
||||
// we keep position for the first line
|
||||
$totalarray['totalizable'][$key]['pos'] = $totalarray['nbfield'];
|
||||
}
|
||||
$totalarray['totalizable'][$key]['total'] += $obj->$tmpkey;
|
||||
}
|
||||
if (! empty($val['isameasure']))
|
||||
{
|
||||
if (! $i) $totalarray['pos'][$totalarray['nbfield']]='ef.'.$tmpkey;
|
||||
|
||||
@ -30,6 +30,7 @@
|
||||
|
||||
|
||||
ALTER TABLE llx_extrafields ADD COLUMN help text NULL;
|
||||
ALTER TABLE llx_extrafields ADD COLUMN totalizable boolean DEFAULT FALSE after list;
|
||||
|
||||
|
||||
ALTER TABLE llx_user ADD COLUMN dateemploymentend date after dateemployment;
|
||||
|
||||
@ -36,6 +36,7 @@ create table llx_extrafields
|
||||
alwayseditable integer DEFAULT 0, -- 1 if field can be edited whatever is element status
|
||||
param text, -- extra parameters to define possible values of field
|
||||
list varchar(255) DEFAULT '1', -- visibility of field. 0=Never visible, 1=Visible on list and forms, 2=Visible on list only. Using a negative value means field is not shown by default on list but can be selected for viewing
|
||||
totalizable boolean DEFAULT FALSE, -- is extrafield totalizable on list
|
||||
langs varchar(64), -- example: fileofmymodule@mymodule
|
||||
help text, -- to store help tooltip
|
||||
fk_user_author integer, -- user making creation
|
||||
|
||||
@ -733,6 +733,8 @@ Result=Result
|
||||
ToTest=Test
|
||||
ValidateBefore=Card must be validated before using this feature
|
||||
Visibility=Visibility
|
||||
Totalizable=Totalizable
|
||||
TotalizableDesc=This field is totalizable in list
|
||||
Private=Private
|
||||
Hidden=Hidden
|
||||
Resources=Resources
|
||||
|
||||
Loading…
Reference in New Issue
Block a user