dolibarr 24.0.0-beta
modAsset.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2004-2019 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2018-2024 Alexandre Spangaro <alexandre@inovea-conseil.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
27include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
28
29
34{
40 public function __construct($db)
41 {
42 global $langs, $conf;
43
44 $this->db = $db;
45
46 // Id for module (must be unique).
47 // Use here a free id (See in Home -> System information -> Dolibarr for list of used modules id).
48 $this->numero = 51000; // TODO Go on page https://wiki.dolibarr.org/index.php/List_of_modules_id to reserve id number for your module
49
50 // Family can be 'crm','financial','hr','projects','products','ecm','technic','interface','other'
51 // It is used to group modules by family in module setup page
52 $this->family = "financial";
53 // Module position in the family on 2 digits ('01', '10', '20', ...)
54 $this->module_position = '70';
55 // Gives the possibility to the module, to provide his own family info and position of this family (Overwrite $this->family and $this->module_position. Avoid this)
56 //$this->familyinfo = array('myownfamily' => array('position' => '01', 'label' => $langs->trans("MyOwnFamily")));
57
58 // Module label (no space allowed), used if translation string 'ModuleAssetsName' not found (MyModue is name of module).
59 $this->name = preg_replace('/^mod/i', '', get_class($this));
60 // Module description, used if translation string 'ModuleAssetsDesc' not found (MyModue is name of module).
61 $this->description = "Fixed asset management";
62 // Used only if file README.md and README-LL.md not found.
63 $this->descriptionlong = "Asset module to manage fixed asset module and depreciation charge";
64
65 // Possible values for version are: 'development', 'experimental', 'dolibarr', 'dolibarr_deprecated' or a version string like 'x.y.z'
66 $this->version = 'dolibarr';
67 // Key used in llx_const table to save module status enabled/disabled (where ASSETS is value of property name of module in uppercase)
68 $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
69 // Name of image file used for this module.
70 // If file is in theme/yourtheme/img directory under name object_pictovalue.png, use this->picto='pictovalue'
71 // If file is in module/img directory under name object_pictovalue.png, use this->picto='pictovalue@module'
72 $this->picto = 'asset';
73
74 // Defined all module parts (triggers, login, substitutions, menus, css, etc...)
75 // for default path (eg: /asset/core/xxxxx) (0=disable, 1=enable)
76 // for specific path of parts (eg: /asset/core/modules/barcode)
77 // for specific css file (eg: /asset/css/assets.css.php)
78 $this->module_parts = array();
79
80 // Data directories to create when module is enabled.
81 // Example: this->dirs = array("/asset/temp","/asset/subdir");
82 $this->dirs = array("/asset/temp");
83
84 // Config pages. Put here list of php page, stored into asset/admin directory, to use to setup module.
85 $this->config_page_url = array("setup.php@asset");
86
87 // Dependencies
88 $this->hidden = false; // A condition to hide module
89 $this->depends = array(); // List of module class names as string that must be enabled if this module is enabled
90 $this->requiredby = array(); // List of module ids to disable if this one is disabled
91 $this->conflictwith = array(); // List of module class names as string this module is in conflict with
92 $this->langfiles = array("assets");
93 $this->phpmin = array(7, 0); // Minimum version of PHP required by module
94 $this->need_dolibarr_version = array(7, 0); // Minimum version of Dolibarr required by module
95 $this->warnings_activation = array();
96 $this->warnings_activation_ext = array();
97 //$this->automatic_activation = array('FR'=>'AssetsWasAutomaticallyActivatedBecauseOfYourCountryChoice');
98
99 // Constants
100 // List of particular constants to add when module is enabled (key, 'chaine', value, desc, visible, 'current' or 'allentities', deleteonunactive)
101 // Example: $this->const=array(0=>array('ASSETS_MYNEWCONST1','chaine','myvalue','This is a constant to add',1),
102 // 1=>array('ASSETS_MYNEWCONST2','chaine','myvalue','This is another constant to add',0, 'current', 1)
103 // );
104 $this->const = array();
105 $this->const[1] = array(
106 "ASSET_DEPRECIATION_DURATION_PER_YEAR",
107 "chaine",
108 "360",
109 "Duration per year to calculate depreciation. In some case, can be 365 days",
110 0,
111 'current',
112 1
113 );
114
115 $this->const[2] = array(
116 "ASSET_ASSET_ADDON",
117 "chaine",
118 "mod_asset_standard",
119 "Name of numbering rules for fixed asset",
120 0,
121 'current',
122 1
123 );
124
125
126 if (!isModEnabled('asset')) {
127 $conf->asset = new stdClass();
128 $conf->asset->enabled = 0;
129 }
130
131
132 // Array to add new pages in new tabs
133 $this->tabs = array();
134 // Example:
135 // $this->tabs[] = array('data'=>'objecttype:+tabname1:Title1:mylangfile@assets:$user->hasRight("assets","read"):/asset/mynewtab1.php?id=__ID__'); // To add a new tab identified by code tabname1
136 // $this->tabs[] = array('data'=>'objecttype:+tabname2:SUBSTITUTION_Title2:mylangfile@assets:$user->hasRight("othermodule","read"):/asset/mynewtab2.php?id=__ID__', // To add another new tab identified by code tabname2. Label will be result of calling all substitution functions on 'Title2' key.
137 // $this->tabs[] = array('data'=>'objecttype:-tabname:NU:conditiontoremove'); // To remove an existing tab identified by code tabname
138 //
139 // Where objecttype can be
140 // 'categories_x' to add a tab in category view (replace 'x' by type of category (0=product, 1=supplier, 2=customer, 3=member)
141 // 'contact' to add a tab in contact view
142 // 'contract' to add a tab in contract view
143 // 'group' to add a tab in group view
144 // 'intervention' to add a tab in intervention view
145 // 'invoice' to add a tab in customer invoice view
146 // 'invoice_supplier' to add a tab in supplier invoice view
147 // 'member' to add a tab in foundation member view
148 // 'opensurveypoll' to add a tab in opensurvey poll view
149 // 'order' to add a tab in sales order view
150 // 'order_supplier' to add a tab in supplier order view
151 // 'payment' to add a tab in payment view
152 // 'payment_supplier' to add a tab in supplier payment view
153 // 'product' to add a tab in product view
154 // 'propal' to add a tab in propal view
155 // 'project' to add a tab in project view
156 // 'stock' to add a tab in stock view
157 // 'thirdparty' to add a tab in third party view
158 // 'user' to add a tab in user view
159
160
161 // Dictionaries
162 $this->dictionaries = array();
163
164
165 // Boxes/Widgets
166 // Add here list of php file(s) stored in asset/core/boxes that contains class to show a widget.
167 $this->boxes = array(
168 //0=>array('file'=>'assetswidget1.php@asset','note'=>'Widget provided by Assets','enabledbydefaulton'=>'Home'),
169 //1=>array('file'=>'assetswidget2.php@asset','note'=>'Widget provided by Assets'),
170 //2=>array('file'=>'assetswidget3.php@asset','note'=>'Widget provided by Assets')
171 );
172
173
174 // Cronjobs (List of cron jobs entries to add when module is enabled)
175 // unit_frequency must be 60 for minute, 3600 for hour, 86400 for day, 604800 for week
176 //$this->cronjobs = array(
177 // 0=>array('label'=>'MyJob label', 'jobtype'=>'method', 'class'=>'/asset/class/asset.class.php', 'objectname'=>'Asset', 'method'=>'doScheduledJob', 'parameters'=>'', 'comment'=>'Comment', 'frequency'=>2, 'unitfrequency'=>3600, 'status'=>0, 'test'=>true)
178 //);
179 // Example: $this->cronjobs=array(0=>array('label'=>'My label', 'jobtype'=>'method', 'class'=>'/dir/class/file.class.php', 'objectname'=>'MyClass', 'method'=>'myMethod', 'parameters'=>'param1, param2', 'comment'=>'Comment', 'frequency'=>2, 'unitfrequency'=>3600, 'status'=>0, 'test'=>true),
180 // 1=>array('label'=>'My label', 'jobtype'=>'command', 'command'=>'', 'parameters'=>'param1, param2', 'comment'=>'Comment', 'frequency'=>1, 'unitfrequency'=>3600*24, 'status'=>0, 'test'=>true)
181 // );
182
183
184 // Permissions
185 $this->rights = array(); // Permission array used by this module
186 $this->rights_class = 'asset';
187 $r = 0;
188
189 $r++;
190 $this->rights[$r][0] = 51001; // Permission id (must not be already used)
191 $this->rights[$r][1] = 'Read assets'; // Permission label
192 $this->rights[$r][2] = 'r';
193 $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
194 $this->rights[$r][4] = 'read'; // In php code, permission will be checked by test if ($user->rights->asset->level1->level2)
195 $this->rights[$r][5] = ''; // In php code, permission will be checked by test if ($user->rights->asset->level1->level2)
196
197 $r++;
198 $this->rights[$r][0] = 51002; // Permission id (must not be already used)
199 $this->rights[$r][1] = 'Create/Update assets'; // Permission label
200 $this->rights[$r][2] = 'w';
201 $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
202 $this->rights[$r][4] = 'write'; // In php code, permission will be checked by test if ($user->rights->asset->level1->level2)
203 $this->rights[$r][5] = ''; // In php code, permission will be checked by test if ($user->rights->asset->level1->level2)
204
205 $r++;
206 $this->rights[$r][0] = 51003; // Permission id (must not be already used)
207 $this->rights[$r][1] = 'Delete assets'; // Permission label
208 $this->rights[$r][2] = 'd';
209 $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
210 $this->rights[$r][4] = 'delete'; // In php code, permission will be checked by test if ($user->rights->asset->level1->level2)
211 $this->rights[$r][5] = ''; // In php code, permission will be checked by test if ($user->rights->asset->level1->level2)
212
213 $r++;
214 $this->rights[$r][0] = 51004; // Permission id (must not be already used)
215 $this->rights[$r][1] = 'Read asset models'; // Permission label
216 $this->rights[$r][2] = 'r';
217 $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
218 $this->rights[$r][4] = 'model_advance'; // In php code, permission will be checked by test if ($user->rights->asset->level1->level2)
219 $this->rights[$r][5] = 'read'; // In php code, permission will be checked by test if ($user->rights->asset->level1->level2)
220
221 $r++;
222 $this->rights[$r][0] = 51005; // Permission id (must not be already used)
223 $this->rights[$r][1] = 'Create/Update asset models'; // Permission label
224 $this->rights[$r][2] = 'w';
225 $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
226 $this->rights[$r][4] = 'model_advance'; // In php code, permission will be checked by test if ($user->rights->asset->level1->level2)
227 $this->rights[$r][5] = 'write'; // In php code, permission will be checked by test if ($user->rights->asset->level1->level2)
228
229 $r++;
230 $this->rights[$r][0] = 51006; // Permission id (must not be already used)
231 $this->rights[$r][1] = 'Delete asset models'; // Permission label
232 $this->rights[$r][2] = 'd';
233 $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
234 $this->rights[$r][4] = 'model_advance'; // In php code, permission will be checked by test if ($user->rights->asset->level1->level2)
235 $this->rights[$r][5] = 'delete'; // In php code, permission will be checked by test if ($user->rights->asset->level1->level2)
236
237 // Menus
238 //-------
239 $this->menu = 1; // This module add menu entries. They are coded into menu manager.
240 }
241
250 public function init($options = '')
251 {
252 $result = $this->_load_tables('/install/mysql/', 'asset');
253 if ($result < 0) {
254 return -1; // Do not activate module if error 'not allowed' returned when loading module SQL queries (the _load_table run sql with run_sql with the error allowed parameter set to 'default')
255 }
256
257 // Permissions
258 $this->remove($options);
259
260 $sql = array();
261
262 return $this->_init($sql, $options);
263 }
264}
Class DolibarrModules.
_init($array_sql, $options='')
Enables a module.
_load_tables($reldir, $onlywithsuffix='')
Create tables and keys required by module:
Description and activation class for module FixedAssets.
init($options='')
Function called when module is enabled.
__construct($db)
Constructor.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
isModEnabled($module)
Is Dolibarr module enabled.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:133