Complementary attributes: Difference between revisions
Tag: 2017 source edit |
m (→Introduction) Tag: 2017 source edit |
||
| (7 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
{{TemplateDocUser}} | {{TemplateDocUser}} | ||
=Introduction= | =Introduction= | ||
Most of the Dolibarr modules have the possibilities to enhance the standard fields by new | Most of the Dolibarr modules have the possibilities to enhance the standard fields by new custom fields. | ||
These fields are called "Complementary attributes" can be defined for objects or object lines. | |||
=How to use= | =How to use= | ||
| Line 15: | Line 16: | ||
==Label or translation key== | ==Label or translation key== | ||
* '''Mandatory field''' | |||
* Label of the new field. This can be a translation key (new or existing), then you also need to set the 'language file' field. | *'''Mandatory field''' | ||
*Label of the new field. This can be a translation key (new or existing), then you also need to set the 'language file' field. | |||
==Attribute code== | ==Attribute code== | ||
* '''Mandatory field''' | |||
* Code of the new field. Can only contain alphanumerical and lower case characters without space | *'''Mandatory field''' | ||
*Code of the new field. Can only contain alphanumerical and lower case characters without space | |||
==Type== | ==Type== | ||
* '''String (1 line)''' : Text on one line. | |||
* '''Long text (n lines)''' : Text on several lines. | *'''String (1 line)''' : Text on one line. | ||
* '''Html text''' : Text with HTML tags. | *'''Long text (n lines)''' : Text on several lines. | ||
* '''Integer''' : | *'''Html text''' : Text with HTML tags. | ||
* '''Float''' : | *'''Integer''' : | ||
* '''Date''' : | *'''Float''' : | ||
* '''Date and hour''' : | *'''Date''' : | ||
* '''Boolean (one checkbox)''' : | *'''Date and hour''' : | ||
* '''Price''' : | *'''Boolean (one checkbox)''' : | ||
* '''Phone''' : | *'''Price''' : | ||
* '''Email''' : | *'''Phone''' : | ||
* '''Url''' : | *'''Email''' : | ||
* '''Password''' : | *'''Url''' : | ||
* '''Select list''' : | *'''Password''' : | ||
* '''Select from table''' : | *'''Select list''' : | ||
* '''Radio buttons (one choice only)''' : | *'''Select from table''' : | ||
* '''Checkboxes''' : | *'''Radio buttons (one choice only)''' : | ||
* '''Checkboxes from table''' : | *'''Checkboxes''' : | ||
* '''Link to an object''' : | *'''Checkboxes from table''' : | ||
* '''Separator (not a field)''' : | *'''Link to an object''' : | ||
*'''Separator (not a field)''' : | |||
==Size== | ==Size== | ||
| Line 63: | Line 67: | ||
==Visibility== | ==Visibility== | ||
Define when a complementary attributes will be visible. | |||
==Display on PDF== | ==Display on PDF== | ||
Do we have to show the value into the generated PDF ? | |||
==Totalizable== | ==Totalizable== | ||
Define is this new attribute can be summed and if the application must show the value of the sum on the line "Total" at the bottom of lists. | |||
==Help text to show on tooltip== | ==Help text to show on tooltip== | ||
= Tips= | =Tips= | ||
==Select from table== | ==Select from table== | ||
===List of suppliers in a Category === | ===List of suppliers in a Category=== | ||
== Computed Fields== | *On phpmyadmin use the following code <code>SELECT cs.fk_soc, cs.fk_categorie, soc.nom FROM llx_categorie_societe cs inner join llx_societe soc WHERE cs.fk_soc=soc.rowid</code> to create a new "view" that you can name <code>llx_mylistcategorie</code> | ||
*Then on the complementary attribute, use <code>mylistcategorie:nom:fk_soc::fk_categorie=10</code> | |||
==Computed Fields== | |||
You can enter here a formula using other properties of object or any PHP coding to get a dynamic computed value. You can use any PHP compatible formulas including the "?" condition operator, and following global object: '''$db, $conf, $langs, $mysoc, $user, $object'''. | You can enter here a formula using other properties of object or any PHP coding to get a dynamic computed value. You can use any PHP compatible formulas including the "?" condition operator, and following global object: '''$db, $conf, $langs, $mysoc, $user, $object'''. | ||
| Line 100: | Line 109: | ||
<code>(($reloadedobj = new Task($db)) && ($reloadedobj->fetchNoCompute($object->id) > 0) && ($secondloadedobj = new Project($db)) && ($secondloadedobj->fetchNoCompute($reloadedobj->fk_project) > 0)) ? $secondloadedobj->ref: 'Parent project not found'</code> | <code>(($reloadedobj = new Task($db)) && ($reloadedobj->fetchNoCompute($object->id) > 0) && ($secondloadedobj = new Project($db)) && ($secondloadedobj->fetchNoCompute($reloadedobj->fk_project) > 0)) ? $secondloadedobj->ref: 'Parent project not found'</code> | ||
== Visibility== | ===Example to have the third party balance=== | ||
<code>(($c = new Categorie($db)) && ($cats = $c->containing($object->id, Categorie::TYPE_PRODUCT))&& (in_array(' | <code>(($reloadedobj = new Societe($db)) && ($reloadedobj->fetchNoCompute($obj->rowid)) && ( $ret=$reloadedobj->getOutStandingBills()) | ||
) ? $ret['opened']: 666</code> | |||
===Example to have the third party open invoices=== | |||
<code>(($reloadedobj = new Societe($db)) && ($reloadedobj->fetchNoCompute($obj->rowid)) && ( $ret=$reloadedobj->getOutStandingBills()) | |||
) ? sizeof($ret['refsopened']): 666</code> | |||
==Visibility== | |||
To display one attribute only if the object belongs to a certain category, you can use the following code : | |||
<code>(($c = new Categorie($db)) && ($cats = $c->containing($object->id, Categorie::TYPE_PRODUCT))&& (in_array('mycategory_id',$cats ))) ? 1 : 0</code> | |||
To display one attribute only if the object is a product : | |||
<code>((preg_match('/type=product',$_SERVER['QUERY_STRING']) || preg_match('/type=0',$_SERVER['QUERY_STRING']))? 1 : 0</code> | |||
Latest revision as of 11:20, 10 March 2022
Introduction
Most of the Dolibarr modules have the possibilities to enhance the standard fields by new custom fields. These fields are called "Complementary attributes" can be defined for objects or object lines.
How to use
Go to the parameters of the module where you want to create new user fileds
On the configuration page, select the complementary attribute menu
Then click on New Attribute
List of fields for each complementary attribute
Each attribute has a some fields that need to be set
Label or translation key
- Mandatory field
- Label of the new field. This can be a translation key (new or existing), then you also need to set the 'language file' field.
Attribute code
- Mandatory field
- Code of the new field. Can only contain alphanumerical and lower case characters without space
Type
- String (1 line) : Text on one line.
- Long text (n lines) : Text on several lines.
- Html text : Text with HTML tags.
- Integer :
- Float :
- Date :
- Date and hour :
- Boolean (one checkbox) :
- Price :
- Phone :
- Email :
- Url :
- Password :
- Select list :
- Select from table :
- Radio buttons (one choice only) :
- Checkboxes :
- Checkboxes from table :
- Link to an object :
- Separator (not a field) :
Size
Position
Value
Language file
Computed field
Default value (Database)
Unique
Required
Can always be edited
Visibility
Define when a complementary attributes will be visible.
Display on PDF
Do we have to show the value into the generated PDF ?
Totalizable
Define is this new attribute can be summed and if the application must show the value of the sum on the line "Total" at the bottom of lists.
Help text to show on tooltip
Tips
Select from table
List of suppliers in a Category
- On phpmyadmin use the following code
SELECT cs.fk_soc, cs.fk_categorie, soc.nom FROM llx_categorie_societe cs inner join llx_societe soc WHERE cs.fk_soc=soc.rowidto create a new "view" that you can namellx_mylistcategorie - Then on the complementary attribute, use
mylistcategorie:nom:fk_soc::fk_categorie=10
Computed Fields
You can enter here a formula using other properties of object or any PHP coding to get a dynamic computed value. You can use any PHP compatible formulas including the "?" condition operator, and following global object: $db, $conf, $langs, $mysoc, $user, $object.
WARNING: Only some properties of $object may be available. If you need a properties not loaded, just fetch yourself the object into your formula like in the second example.
Using a computed field means you can't enter yourself any value from interface. Also, if there is a syntax error, the formula may return nothing.
Example of formula:
$object->id < 10 ? round($object->id / 2, 2): ($object->id + 2 * $user->id) * (int) substr($mysoc->zip, 1, 2)
Example to reload object
(($reloadedobj = new Societe($db)) && ($reloadedobj->fetchNoCompute($obj->id ? $obj->id: ($obj->rowid ? $obj->rowid: $object->id)) > 0)) ? $reloadedobj->array_options['options_extrafieldkey'] * $reloadedobj->capital / 5: '-1'
Other example of formula to force load of object and its parent object:
(($reloadedobj = new Task($db)) && ($reloadedobj->fetchNoCompute($object->id) > 0) && ($secondloadedobj = new Project($db)) && ($secondloadedobj->fetchNoCompute($reloadedobj->fk_project) > 0)) ? $secondloadedobj->ref: 'Parent project not found'
Example to have the third party balance
(($reloadedobj = new Societe($db)) && ($reloadedobj->fetchNoCompute($obj->rowid)) && ( $ret=$reloadedobj->getOutStandingBills())
) ? $ret['opened']: 666
Example to have the third party open invoices
(($reloadedobj = new Societe($db)) && ($reloadedobj->fetchNoCompute($obj->rowid)) && ( $ret=$reloadedobj->getOutStandingBills())
) ? sizeof($ret['refsopened']): 666
Visibility
To display one attribute only if the object belongs to a certain category, you can use the following code :
(($c = new Categorie($db)) && ($cats = $c->containing($object->id, Categorie::TYPE_PRODUCT))&& (in_array('mycategory_id',$cats ))) ? 1 : 0
To display one attribute only if the object is a product :
((preg_match('/type=product',$_SERVER['QUERY_STRING']) || preg_match('/type=0',$_SERVER['QUERY_STRING']))? 1 : 0

