dolibarr 25.0.0-alpha
modStockTransfer.class.php
1<?php
2/* Copyright (C) 2004-2018 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2018-2019 Nicolas ZABOURI <info@inovea-conseil.com>
4 * Copyright (C) 2019-2026 Frédéric France <frederic.france@free.fr>
5 * Copyright (C) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
6 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
30include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
31
36{
42 public function __construct($db)
43 {
44 global $langs, $conf;
45 $this->db = $db;
46
47 $langs->load('stocks');
48 // Id for module (must be unique).
49 // Use here a free id (See in Home -> System information -> Dolibarr for list of used modules id).
50 $this->numero = 701; // TODO Go on page https://wiki.dolibarr.org/index.php/List_of_modules_id to reserve an id number for your module
51 // Key text used to identify module (for permissions, menus, etc...)
52 $this->rights_class = 'stocktransfer';
53 // Family can be 'base' (core modules),'crm','financial','hr','projects','products','ecm','technic' (transverse modules),'interface' (link with external tools),'other','...'
54 // It is used to group modules by family in module setup page
55 $this->family = "products";
56 // Module position in the family on 2 digits ('01', '10', '20', ...)
57 $this->module_position = '90';
58 // Gives the possibility for the module, to provide his own family info and position of this family (Overwrite $this->family and $this->module_position. Avoid this)
59 //$this->familyinfo = array('myownfamily' => array('position' => '01', 'label' => $langs->trans("MyOwnFamily")));
60 // Module label (no space allowed), used if translation string 'ModuleStockTransferName' not found (StockTransfer is name of module).
61 $this->name = preg_replace('/^mod/i', '', get_class($this));
62 // Module description, used if translation string 'ModuleStockTransferDesc' not found (StockTransfer is name of module).
63 $this->description = $langs->trans("ModuleStockTransferDesc");
64 // Used only if file README.md and README-LL.md not found.
65 $this->descriptionlong = "Advanced management of stock transfer orders with generation of stock transfer sheets";
66 // Possible values for version are: 'development', 'experimental', 'dolibarr', 'dolibarr_deprecated' or a version string like 'x.y.z'
67 $this->version = 'dolibarr';
68 // Url to the file with your last numberversion of this module
69 //$this->url_last_version = 'http://www.example.com/versionmodule.txt';
70
71 // Key used in llx_const table to save module status enabled/disabled (where STOCKTRANSFER is value of property name of module in uppercase)
72 $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
73 // Name of image file used for this module.
74 // If file is in theme/yourtheme/img directory under name object_pictovalue.png, use this->picto='pictovalue'
75 // If file is in module/img directory under name object_pictovalue.png, use this->picto='pictovalue@module'
76 $this->picto = 'stock';
77 // Define some features supported by module (triggers, login, substitutions, menus, css, etc...)
78 $this->module_parts = array(
79 // Set this to 1 if module has its own trigger directory (core/triggers)
80 'triggers' => 0,
81 // Set this to 1 if module has its own login method file (core/login)
82 'login' => 0,
83 // Set this to 1 if module has its own substitution function file (core/substitutions)
84 'substitutions' => 0,
85 // Set this to 1 if module has its own menus handler directory (core/menus)
86 'menus' => 0,
87 // Set this to 1 if module overwrite template dir (core/tpl)
88 'tpl' => 0,
89 // Set this to 1 if module has its own barcode directory (core/modules/barcode)
90 'barcode' => 0,
91 // Set this to 1 if module has its own models directory (core/modules/xxx)
92 'models' => 1,
93 // Set this to 1 if module has its own theme directory (theme)
94 'theme' => 0,
95 // Set this to relative path of css file if module has its own css file
96 'css' => array(
97 // '/stocktransfer/css/stocktransfer.css.php',
98 ),
99 // Set this to relative path of js file if module must load a js on all pages
100 'js' => array(
101 // '/stocktransfer/js/stocktransfer.js.php',
102 ),
103 // Set here all hooks context managed by module. To find available hook context, make a "grep -r '>initHooks(' *" on source code. You can also set hook context to 'all'
104 'hooks' => array(
105 // 'data' => array(
106 // 'hookcontext1',
107 // 'hookcontext2',
108 // ),
109 // 'entity' => '0',
110 ),
111 // Set this to 1 if features of module are opened to external users
112 'moduleforexternal' => 0,
113 'contactelement' => 1
114 );
115 // Data directories to create when module is enabled.
116 // Example: this->dirs = array("/stocktransfer/temp","/stocktransfer/subdir");
117 $this->dirs = array("/stocktransfer/temp");
118 // Config pages. Put here list of php page, stored into stocktransfer/admin directory, to use to setup module.
119 $this->config_page_url = array("stocktransfer.php");
120 // Dependencies
121 // A condition to hide module
122 $this->hidden = false;
123 // List of module class names as string that must be enabled if this module is enabled. Example: array('always'=>array('modModuleToEnable1','modModuleToEnable2'), 'FR'=>array('modModuleToEnableFR'...))
124 $this->depends = array('modStock', 'modProduct');
125 $this->requiredby = []; // List of module class names as string to disable if this one is disabled. Example: array('modModuleToDisable1', ...)
126 $this->conflictwith = []; // List of module class names as string this module is in conflict with. Example: array('modModuleToDisable1', ...)
127 $this->langfiles = array("stocktransfer@stocktransfer");
128 $this->phpmin = array(7, 0); // Minimum version of PHP required by module
129 $this->warnings_activation = [];
130 $this->warnings_activation_ext = [];
131 //$this->automatic_activation = array('FR'=>'StockTransferWasAutomaticallyActivatedBecauseOfYourCountryChoice');
132
133 // Constants
134 // List of particular constants to add when module is enabled (key, 'chaine', value, desc, visible, 'current' or 'allentities', deleteonunactive)
135 // Example: $this->const=array(1 => array('STOCKTRANSFER_MYNEWCONST1', 'chaine', 'myvalue', 'This is a constant to add', 1),
136 // 2 => array('STOCKTRANSFER_MYNEWCONST2', 'chaine', 'myvalue', 'This is another constant to add', 0, 'current', 1)
137 // );
138 $this->const = [];
139
140 if (!isset($conf->stocktransfer) || !isset($conf->stocktransfer->enabled)) {
141 $conf->stocktransfer = new stdClass();
142 $conf->stocktransfer->enabled = 0;
143 }
144
145 // Array to add new pages in new tabs
146 $this->tabs = [];
147 // Example:
148 // $this->tabs[] = array('data'=>'objecttype:+tabname1:Title1:mylangfile@stocktransfer:$user->rights->stocktransfer->read:/stocktransfer/mynewtab1.php?id=__ID__'); // To add a new tab identified by code tabname1
149 // $this->tabs[] = array('data'=>'objecttype:+tabname2:SUBSTITUTION_Title2:mylangfile@stocktransfer:$user->rights->othermodule->read:/stocktransfer/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.
150 // $this->tabs[] = array('data'=>'objecttype:-tabname:NU:conditiontoremove'); // To remove an existing tab identified by code tabname
151 //
152 // Where objecttype can be
153 // 'categories_x' to add a tab in category view (replace 'x' by type of category (0=product, 1=supplier, 2=customer, 3=member)
154 // 'contact' to add a tab in contact view
155 // 'contract' to add a tab in contract view
156 // 'group' to add a tab in group view
157 // 'intervention' to add a tab in intervention view
158 // 'invoice' to add a tab in customer invoice view
159 // 'invoice_supplier' to add a tab in supplier invoice view
160 // 'member' to add a tab in foundation member view
161 // 'opensurveypoll' to add a tab in opensurvey poll view
162 // 'order' to add a tab in sales order view
163 // 'order_supplier' to add a tab in supplier order view
164 // 'payment' to add a tab in payment view
165 // 'payment_supplier' to add a tab in supplier payment view
166 // 'product' to add a tab in product view
167 // 'propal' to add a tab in propal view
168 // 'project' to add a tab in project view
169 // 'stock' to add a tab in stock view
170 // 'thirdparty' to add a tab in third party view
171 // 'user' to add a tab in user view
172
173 // Dictionaries
174 $this->dictionaries = [];
175 /* Example:
176 $this->dictionaries=array(
177 'langs'=>'stocktransfer@stocktransfer',
178 // List of tables we want to see into dictionary editor
179 'tabname'=>array(MAIN_DB_PREFIX."table1", MAIN_DB_PREFIX."table2", MAIN_DB_PREFIX."table3"),
180 // Label of tables
181 'tablib'=>array("Table1", "Table2", "Table3"),
182 // Request to select fields
183 'tabsql'=>array('SELECT f.rowid as rowid, f.code, f.label, f.active FROM '.MAIN_DB_PREFIX.'table1 as f', 'SELECT f.rowid as rowid, f.code, f.label, f.active FROM '.MAIN_DB_PREFIX.'table2 as f', 'SELECT f.rowid as rowid, f.code, f.label, f.active FROM '.MAIN_DB_PREFIX.'table3 as f'),
184 // Sort order
185 'tabsqlsort'=>array("label ASC", "label ASC", "label ASC"),
186 // List of fields (result of select to show dictionary)
187 'tabfield'=>array("code,label", "code,label", "code,label"),
188 // List of fields (list of fields to edit a record)
189 'tabfieldvalue'=>array("code,label", "code,label", "code,label"),
190 // List of fields (list of fields for insert)
191 'tabfieldinsert'=>array("code,label", "code,label", "code,label"),
192 // Name of columns with primary key (try to always name it 'rowid')
193 'tabrowid'=>array("rowid", "rowid", "rowid"),
194 // Condition to show each dictionary
195 'tabcond'=>array($conf->stocktransfer->enabled, $conf->stocktransfer->enabled, $conf->stocktransfer->enabled)
196 );
197 */
198
199 // Boxes/Widgets
200 // Add here list of php file(s) stored in stocktransfer/core/boxes that contains a class to show a widget.
201 $this->boxes = array(
202 // 0 => array(
203 // 'file' => 'stocktransferwidget1.php@stocktransfer',
204 // 'note' => 'Widget provided by StockTransfer',
205 // 'enabledbydefaulton' => 'Home',
206 // ),
207 // ...
208 );
209
210 // Cronjobs (List of cron jobs entries to add when module is enabled)
211 // unit_frequency must be 60 for minute, 3600 for hour, 86400 for day, 604800 for week
212 $this->cronjobs = array(
213 // 0 => array(
214 // 'label' => 'MyJob label',
215 // 'jobtype' => 'method',
216 // 'class' => '/stocktransfer/class/stocktransfer.class.php',
217 // 'objectname' => 'StockTransfer',
218 // 'method' => 'doScheduledJob',
219 // 'parameters' => '',
220 // 'comment' => 'Comment',
221 // 'frequency' => 2,
222 // 'unitfrequency' => 3600,
223 // 'status' => 0,
224 // 'test' => 'isModEnabled('stocktransfer')',
225 // 'priority' => 50,
226 // ),
227 );
228 // Example: $this->cronjobs=array(
229 // 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'=>'$conf->stocktransfer->enabled', 'priority'=>50),
230 // 1=>array('label'=>'My label', 'jobtype'=>'command', 'command'=>'', 'parameters'=>'param1, param2', 'comment'=>'Comment', 'frequency'=>1, 'unitfrequency'=>3600*24, 'status'=>0, 'test'=>'$conf->stocktransfer->enabled', 'priority'=>50)
231 // );
232
233 // Permissions provided by this module
234 $this->rights = [];
235 $r = 10;
236 // Add here entries to declare new permissions
237 /* BEGIN MODULEBUILDER PERMISSIONS */
238 $this->rights[$r][0] = $this->numero + $r; // Permission id (must not be already used)
239 $this->rights[$r][1] = $langs->trans('StockTransferRightRead'); // Permission label
240 $this->rights[$r][4] = 'stocktransfer'; // In php code, permission will be checked by test if ($user->rights->stocktransfer->level1->level2)
241 $this->rights[$r][5] = 'read'; // In php code, permission will be checked by test if ($user->rights->stocktransfer->level1->level2)
242 $r++;
243 $this->rights[$r][0] = $this->numero + $r; // Permission id (must not be already used)
244 $this->rights[$r][1] = $langs->trans('StockTransferRightCreateUpdate'); // Permission label
245 $this->rights[$r][4] = 'stocktransfer'; // In php code, permission will be checked by test if ($user->rights->stocktransfer->level1->level2)
246 $this->rights[$r][5] = 'write'; // In php code, permission will be checked by test if ($user->rights->stocktransfer->level1->level2)
247 $r++;
248 $this->rights[$r][0] = $this->numero + $r; // Permission id (must not be already used)
249 $this->rights[$r][1] = $langs->trans('StockTransferRightDelete'); // Permission label
250 $this->rights[$r][4] = 'stocktransfer'; // In php code, permission will be checked by test if ($user->rights->stocktransfer->level1->level2)
251 $this->rights[$r][5] = 'delete'; // In php code, permission will be checked by test if ($user->rights->stocktransfer->level1->level2)
252 $r++;
253 /* END MODULEBUILDER PERMISSIONS */
254 }
255
264 public function init($options = '')
265 {
266 $result = $this->_load_tables('/install/mysql/', 'stocktransfer');
267 if ($result < 0) {
268 return -1;
269 } // 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')
270
271 // Permissions
272 $this->remove($options);
273
274 $sql = [];
275
276 return $this->_init($sql, $options);
277 }
278
287 public function remove($options = '')
288 {
289 $sql = [];
290 return $this->_remove($sql, $options);
291 }
292}
Class DolibarrModules.
_init($array_sql, $options='')
Enables a module.
_remove($array_sql, $options='')
Disable function.
_load_tables($reldir, $onlywithsuffix='')
Create tables and keys required by module:
Description and activation class for module StockTransfer.
__construct($db)
Constructor.
init($options='')
Function called when module is enabled.
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:
$conf browser version
Definition main.inc.php:229
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:140