dolibarr 20.0.0
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-2022 Frédéric France <frederic.france@netlogic.fr>
5 * Copyright (C) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
6 * Copyright (C) 2024 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 = 'experimental';
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 = array(); // List of module class names as string to disable if this one is disabled. Example: array('modModuleToDisable1', ...)
126 $this->conflictwith = array(); // 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 = array(); // Warning to show when we activate module. array('always'='text') or array('FR'='textfr','ES'='textes'...)
130 $this->warnings_activation_ext = array(); // Warning to show when we activate an external module. array('always'='text') or array('FR'='textfr','ES'='textes'...)
131 //$this->automatic_activation = array('FR'=>'StockTransferWasAutomaticallyActivatedBecauseOfYourCountryChoice');
132 //$this->always_enabled = true; // If true, can't be disabled
133
134 // Constants
135 // List of particular constants to add when module is enabled (key, 'chaine', value, desc, visible, 'current' or 'allentities', deleteonunactive)
136 // Example: $this->const=array(1 => array('STOCKTRANSFER_MYNEWCONST1', 'chaine', 'myvalue', 'This is a constant to add', 1),
137 // 2 => array('STOCKTRANSFER_MYNEWCONST2', 'chaine', 'myvalue', 'This is another constant to add', 0, 'current', 1)
138 // );
139 $this->const = array();
140
141 if (!isset($conf->stocktransfer) || !isset($conf->stocktransfer->enabled)) {
142 $conf->stocktransfer = new stdClass();
143 $conf->stocktransfer->enabled = 0;
144 }
145
146 // Array to add new pages in new tabs
147 $this->tabs = array();
148 // Example:
149 // $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
150 // $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.
151 // $this->tabs[] = array('data'=>'objecttype:-tabname:NU:conditiontoremove'); // To remove an existing tab identified by code tabname
152 //
153 // Where objecttype can be
154 // 'categories_x' to add a tab in category view (replace 'x' by type of category (0=product, 1=supplier, 2=customer, 3=member)
155 // 'contact' to add a tab in contact view
156 // 'contract' to add a tab in contract view
157 // 'group' to add a tab in group view
158 // 'intervention' to add a tab in intervention view
159 // 'invoice' to add a tab in customer invoice view
160 // 'invoice_supplier' to add a tab in supplier invoice view
161 // 'member' to add a tab in foundation member view
162 // 'opensurveypoll' to add a tab in opensurvey poll view
163 // 'order' to add a tab in sales order view
164 // 'order_supplier' to add a tab in supplier order view
165 // 'payment' to add a tab in payment view
166 // 'payment_supplier' to add a tab in supplier payment view
167 // 'product' to add a tab in product view
168 // 'propal' to add a tab in propal view
169 // 'project' to add a tab in project view
170 // 'stock' to add a tab in stock view
171 // 'thirdparty' to add a tab in third party view
172 // 'user' to add a tab in user view
173
174 // Dictionaries
175 $this->dictionaries = array();
176 /* Example:
177 $this->dictionaries=array(
178 'langs'=>'stocktransfer@stocktransfer',
179 // List of tables we want to see into dictonnary editor
180 'tabname'=>array(MAIN_DB_PREFIX."table1", MAIN_DB_PREFIX."table2", MAIN_DB_PREFIX."table3"),
181 // Label of tables
182 'tablib'=>array("Table1", "Table2", "Table3"),
183 // Request to select fields
184 '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'),
185 // Sort order
186 'tabsqlsort'=>array("label ASC", "label ASC", "label ASC"),
187 // List of fields (result of select to show dictionary)
188 'tabfield'=>array("code,label", "code,label", "code,label"),
189 // List of fields (list of fields to edit a record)
190 'tabfieldvalue'=>array("code,label", "code,label", "code,label"),
191 // List of fields (list of fields for insert)
192 'tabfieldinsert'=>array("code,label", "code,label", "code,label"),
193 // Name of columns with primary key (try to always name it 'rowid')
194 'tabrowid'=>array("rowid", "rowid", "rowid"),
195 // Condition to show each dictionary
196 'tabcond'=>array($conf->stocktransfer->enabled, $conf->stocktransfer->enabled, $conf->stocktransfer->enabled)
197 );
198 */
199
200 // Boxes/Widgets
201 // Add here list of php file(s) stored in stocktransfer/core/boxes that contains a class to show a widget.
202 $this->boxes = array(
203 // 0 => array(
204 // 'file' => 'stocktransferwidget1.php@stocktransfer',
205 // 'note' => 'Widget provided by StockTransfer',
206 // 'enabledbydefaulton' => 'Home',
207 // ),
208 // ...
209 );
210
211 // Cronjobs (List of cron jobs entries to add when module is enabled)
212 // unit_frequency must be 60 for minute, 3600 for hour, 86400 for day, 604800 for week
213 $this->cronjobs = array(
214 // 0 => array(
215 // 'label' => 'MyJob label',
216 // 'jobtype' => 'method',
217 // 'class' => '/stocktransfer/class/stocktransfer.class.php',
218 // 'objectname' => 'StockTransfer',
219 // 'method' => 'doScheduledJob',
220 // 'parameters' => '',
221 // 'comment' => 'Comment',
222 // 'frequency' => 2,
223 // 'unitfrequency' => 3600,
224 // 'status' => 0,
225 // 'test' => '$conf->stocktransfer->enabled',
226 // 'priority' => 50,
227 // ),
228 );
229 // Example: $this->cronjobs=array(
230 // 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),
231 // 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)
232 // );
233
234 // Permissions provided by this module
235 $this->rights = array();
236 $r = 10;
237 // Add here entries to declare new permissions
238 /* BEGIN MODULEBUILDER PERMISSIONS */
239 $this->rights[$r][0] = $this->numero + $r; // Permission id (must not be already used)
240 $this->rights[$r][1] = $langs->trans('StockTransferRightRead'); // Permission label
241 $this->rights[$r][4] = 'stocktransfer'; // In php code, permission will be checked by test if ($user->rights->stocktransfer->level1->level2)
242 $this->rights[$r][5] = 'read'; // In php code, permission will be checked by test if ($user->rights->stocktransfer->level1->level2)
243 $r++;
244 $this->rights[$r][0] = $this->numero + $r; // Permission id (must not be already used)
245 $this->rights[$r][1] = $langs->trans('StockTransferRightCreateUpdate'); // Permission label
246 $this->rights[$r][4] = 'stocktransfer'; // In php code, permission will be checked by test if ($user->rights->stocktransfer->level1->level2)
247 $this->rights[$r][5] = 'write'; // In php code, permission will be checked by test if ($user->rights->stocktransfer->level1->level2)
248 $r++;
249 $this->rights[$r][0] = $this->numero + $r; // Permission id (must not be already used)
250 $this->rights[$r][1] = $langs->trans('StockTransferRightDelete'); // Permission label
251 $this->rights[$r][4] = 'stocktransfer'; // In php code, permission will be checked by test if ($user->rights->stocktransfer->level1->level2)
252 $this->rights[$r][5] = 'delete'; // In php code, permission will be checked by test if ($user->rights->stocktransfer->level1->level2)
253 $r++;
254 /* END MODULEBUILDER PERMISSIONS */
255
256 // Main menu entries to add
257 $langs->load('stocktransfer@stocktransfer');
258 $this->menu = array();
259 $r = 0;
260 // Add here entries to declare new menus
261 /* BEGIN MODULEBUILDER TOPMENU */
262 /*$this->menu[$r++] = array(
263 'fk_menu'=>'', // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
264 'type'=>'top', // This is a Top menu entry
265 'titre'=>'ModuleStockTransferName',
266 'mainmenu'=>'stocktransfer',
267 'leftmenu'=>'',
268 'url'=>'/stocktransfer/stocktransferindex.php',
269 'langs'=>'stocktransfer@stocktransfer', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
270 'position'=>1000 + $r,
271 'enabled'=>'$conf->stocktransfer->enabled', // Define condition to show or hide menu entry. Use '$conf->stocktransfer->enabled' if entry must be visible if module is enabled.
272 'perms'=>'1', // Use 'perms'=>'$user->rights->stocktransfer->stocktransfer->read' if you want your menu with a permission rules
273 'target'=>'',
274 'user'=>2, // 0=Menu for internal users, 1=external users, 2=both
275 );*/
276 /* END MODULEBUILDER TOPMENU */
277 /* BEGIN MODULEBUILDER LEFTMENU STOCKTRANSFER
278 $this->menu[$r++]=array(
279 'fk_menu'=>'fk_mainmenu=stocktransfer', // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
280 'type'=>'left', // This is a Top menu entry
281 'titre'=>'StockTransfer',
282 'mainmenu'=>'stocktransfer',
283 'leftmenu'=>'stocktransfer',
284 'url'=>'/stocktransfer/stocktransferindex.php',
285 'langs'=>'stocktransfer@stocktransfer', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
286 'position'=>1000+$r,
287 'enabled'=>'$conf->stocktransfer->enabled', // Define condition to show or hide menu entry. Use '$conf->stocktransfer->enabled' if entry must be visible if module is enabled.
288 'perms'=>'$user->rights->stocktransfer->stocktransfer->read', // Use 'perms'=>'$user->rights->stocktransfer->level1->level2' if you want your menu with a permission rules
289 'target'=>'',
290 'user'=>2, // 0=Menu for internal users, 1=external users, 2=both
291 );
292 $this->menu[$r++]=array(
293 'fk_menu'=>'fk_mainmenu=stocktransfer,fk_leftmenu=stocktransfer', // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
294 'type'=>'left', // This is a Left menu entry
295 'titre'=>'List StockTransfer',
296 'mainmenu'=>'stocktransfer',
297 'leftmenu'=>'stocktransfer_stocktransfer_list',
298 'url'=>'/stocktransfer/stocktransfer_list.php',
299 'langs'=>'stocktransfer@stocktransfer', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
300 'position'=>1000+$r,
301 'enabled'=>'$conf->stocktransfer->enabled', // Define condition to show or hide menu entry. Use '$conf->stocktransfer->enabled' if entry must be visible if module is enabled. Use '$leftmenu==\'system\'' to show if leftmenu system is selected.
302 'perms'=>'$user->rights->stocktransfer->stocktransfer->read', // Use 'perms'=>'$user->rights->stocktransfer->level1->level2' if you want your menu with a permission rules
303 'target'=>'',
304 'user'=>2, // 0=Menu for internal users, 1=external users, 2=both
305 );
306 $this->menu[$r++]=array(
307 'fk_menu'=>'fk_mainmenu=stocktransfer,fk_leftmenu=stocktransfer', // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
308 'type'=>'left', // This is a Left menu entry
309 'titre'=>'New StockTransfer',
310 'mainmenu'=>'stocktransfer',
311 'leftmenu'=>'stocktransfer_stocktransfer_new',
312 'url'=>'/stocktransfer/stocktransfer_card.php?action=create',
313 'langs'=>'stocktransfer@stocktransfer', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
314 'position'=>1000+$r,
315 'enabled'=>'$conf->stocktransfer->enabled', // Define condition to show or hide menu entry. Use '$conf->stocktransfer->enabled' if entry must be visible if module is enabled. Use '$leftmenu==\'system\'' to show if leftmenu system is selected.
316 'perms'=>'$user->rights->stocktransfer->stocktransfer->write', // Use 'perms'=>'$user->rights->stocktransfer->level1->level2' if you want your menu with a permission rules
317 'target'=>'',
318 'user'=>2, // 0=Menu for internal users, 1=external users, 2=both
319 );
320 */
321
322 /*$this->menu[$r++]=array(
323 // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
324 'fk_menu'=>'fk_mainmenu=products,fk_leftmenu=stock',
325 // This is a Left menu entry
326 'type'=>'left',
327 'titre'=>$langs->trans('StockTransferNew'),
328 'mainmenu'=>'products',
329 'leftmenu'=>'stocktransfer_stocktransfer',
330 'url'=>'/stocktransfer/stocktransfer_card.php?action=create',
331 // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
332 'langs'=>'stocktransfer@stocktransfer',
333 'position'=>1100+$r,
334 // Define condition to show or hide menu entry. Use '$conf->stocktransfer->enabled' if entry must be visible if module is enabled. Use '$leftmenu==\'system\'' to show if leftmenu system is selected.
335 'enabled'=>'$conf->stocktransfer->enabled',
336 // Use 'perms'=>'$user->rights->stocktransfer->level1->level2' if you want your menu with a permission rules
337 'perms'=>'1',
338 'target'=>'',
339 // 0=Menu for internal users, 1=external users, 2=both
340 'user'=>2
341 );
342 $this->menu[$r++]=array(
343 // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
344 'fk_menu'=>'fk_mainmenu=products,fk_leftmenu=stock',
345 // This is a Left menu entry
346 'type'=>'left',
347 'titre'=>$langs->trans('StockTransferList'),
348 'mainmenu'=>'products',
349 'leftmenu'=>'stocktransfer_stocktransferlist',
350 'url'=>'/stocktransfer/stocktransfer_list.php',
351 // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
352 'langs'=>'stocktransfer@stocktransfer',
353 'position'=>1100+$r,
354 // Define condition to show or hide menu entry. Use '$conf->stocktransfer->enabled' if entry must be visible if module is enabled. Use '$leftmenu==\'system\'' to show if leftmenu system is selected.
355 'enabled'=>'$conf->stocktransfer->enabled',
356 // Use 'perms'=>'$user->rights->stocktransfer->level1->level2' if you want your menu with a permission rules
357 'perms'=>'1',
358 'target'=>'',
359 // 0=Menu for internal users, 1=external users, 2=both
360 'user'=>2,
361 );*/
362
363 /* END MODULEBUILDER LEFTMENU STOCKTRANSFER */
364
365 // Exports profiles provided by this module
366 $r = 1;
367 /* BEGIN MODULEBUILDER EXPORT STOCKTRANSFER */
368 /*
369 $langs->load("stocktransfer@stocktransfer");
370 $this->export_code[$r]=$this->rights_class.'_'.$r;
371 $this->export_label[$r]='StockTransferLines'; // Translation key (used only if key ExportDataset_xxx_z not found)
372 $this->export_icon[$r]='stocktransfer@stocktransfer';
373 // Define $this->export_fields_array, $this->export_TypeFields_array and $this->export_entities_array
374 $keyforclass = 'StockTransfer'; $keyforclassfile='/stocktransfer/class/stocktransfer.class.php'; $keyforelement='stocktransfer@stocktransfer';
375 include DOL_DOCUMENT_ROOT.'/core/commonfieldsinexport.inc.php';
376 //$this->export_fields_array[$r]['t.fieldtoadd']='FieldToAdd'; $this->export_TypeFields_array[$r]['t.fieldtoadd']='Text';
377 //unset($this->export_fields_array[$r]['t.fieldtoremove']);
378 //$keyforclass = 'StockTransferLine'; $keyforclassfile='/stocktransfer/class/stocktransfer.class.php'; $keyforelement='stocktransferline@stocktransfer'; $keyforalias='tl';
379 //include DOL_DOCUMENT_ROOT.'/core/commonfieldsinexport.inc.php';
380 $keyforselect='stocktransfer'; $keyforaliasextra='extra'; $keyforelement='stocktransfer@stocktransfer';
381 include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
382 //$keyforselect='stocktransferline'; $keyforaliasextra='extraline'; $keyforelement='stocktransferline@stocktransfer';
383 //include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
384 //$this->export_dependencies_array[$r] = array('stocktransferline'=>array('tl.rowid','tl.ref')); // To force to activate one or several fields if we select some fields that need same (like to select a unique key if we ask a field of a child to avoid the DISTINCT to discard them, or for computed field than need several other fields)
385 //$this->export_special_array[$r] = array('t.field'=>'...');
386 //$this->export_examplevalues_array[$r] = array('t.field'=>'Example');
387 //$this->export_help_array[$r] = array('t.field'=>'FieldDescHelp');
388 $this->export_sql_start[$r]='SELECT DISTINCT ';
389 $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'stocktransfer as t';
390 //$this->export_sql_end[$r] =' LEFT JOIN '.MAIN_DB_PREFIX.'stocktransfer_line as tl ON tl.fk_stocktransfer = t.rowid';
391 $this->export_sql_end[$r] .=' WHERE 1 = 1';
392 $this->export_sql_end[$r] .=' AND t.entity IN ('.getEntity('stocktransfer').')';
393 $r++; */
394 /* END MODULEBUILDER EXPORT STOCKTRANSFER */
395
396 // Imports profiles provided by this module
397 $r = 1;
398 /* BEGIN MODULEBUILDER IMPORT STOCKTRANSFER */
399 /*
400 $langs->load("stocktransfer@stocktransfer");
401 $this->export_code[$r]=$this->rights_class.'_'.$r;
402 $this->export_label[$r]='StockTransferLines'; // Translation key (used only if key ExportDataset_xxx_z not found)
403 $this->export_icon[$r]='stocktransfer@stocktransfer';
404 $keyforclass = 'StockTransfer'; $keyforclassfile='/stocktransfer/class/stocktransfer.class.php'; $keyforelement='stocktransfer@stocktransfer';
405 include DOL_DOCUMENT_ROOT.'/core/commonfieldsinexport.inc.php';
406 $keyforselect='stocktransfer'; $keyforaliasextra='extra'; $keyforelement='stocktransfer@stocktransfer';
407 include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
408 //$this->export_dependencies_array[$r]=array('mysubobject'=>'ts.rowid', 't.myfield'=>array('t.myfield2','t.myfield3')); // To force to activate one or several fields if we select some fields that need same (like to select a unique key if we ask a field of a child to avoid the DISTINCT to discard them, or for computed field than need several other fields)
409 $this->export_sql_start[$r]='SELECT DISTINCT ';
410 $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'stocktransfer as t';
411 $this->export_sql_end[$r] .=' WHERE 1 = 1';
412 $this->export_sql_end[$r] .=' AND t.entity IN ('.getEntity('stocktransfer').')';
413 $r++; */
414 /* END MODULEBUILDER IMPORT STOCKTRANSFER */
415 }
416
425 public function init($options = '')
426 {
427 global $conf, $langs;
428
429 $result = $this->_load_tables('/install/mysql/tables/', 'stocktransfer');
430 if ($result < 0) {
431 return -1;
432 } // 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')
433
434 // Permissions
435 $this->remove($options);
436
437 $sql = array();
438
439 // Roles
440 $resql = $this->db->query("SELECT rowid FROM ".MAIN_DB_PREFIX."c_type_contact WHERE code = 'STDEST' AND element = 'stocktransfer' AND source = 'internal'");
441 $res = $this->db->fetch_object($resql);
442 $nextid = $this->getNextId();
443 if (empty($res)) {
444 $this->db->query("INSERT INTO ".MAIN_DB_PREFIX."c_type_contact(rowid, element, source, code, libelle, active, module, position) VALUES(".((int) $nextid).", 'stocktransfer', 'internal', 'STRESP', 'Responsible for stock transfers', 1, NULL, 0)");
445 }
446
447 $resql = $this->db->query("SELECT rowid FROM ".MAIN_DB_PREFIX."c_type_contact WHERE code = 'STFROM' AND element = 'stocktransfer' AND source = 'external'");
448 $res = $this->db->fetch_object($resql);
449 $nextid = $this->getNextId();
450 if (empty($res)) {
451 $this->db->query("INSERT INTO ".MAIN_DB_PREFIX."c_type_contact(rowid, element, source, code, libelle, active, module, position) VALUES(".((int) $nextid).", 'stocktransfer', 'external', 'STFROM', 'Contact sending the stock transfer', 1, NULL, 0)");
452 }
453
454 $resql = $this->db->query("SELECT rowid FROM ".MAIN_DB_PREFIX."c_type_contact WHERE code = 'STDEST' AND element = 'stocktransfer' AND source = 'external'");
455 $res = $this->db->fetch_object($resql);
456 $nextid = $this->getNextId();
457 if (empty($res)) {
458 $this->db->query("INSERT INTO ".MAIN_DB_PREFIX."c_type_contact(rowid, element, source, code, libelle, active, module, position) VALUES(".((int) $nextid).", 'stocktransfer', 'external', 'STDEST', 'Contact receiving the stock transfer', 1, NULL, 0)");
459 }
460
461 return $this->_init($sql, $options);
462 }
463
468 public function getNextId()
469 {
470 // Get free id for insert
471 $newid = 0;
472 $sql = "SELECT MAX(rowid) newid from ".MAIN_DB_PREFIX."c_type_contact";
473 $result = $this->db->query($sql);
474 if ($result) {
475 $obj = $this->db->fetch_object($result);
476 $newid = ($obj->newid + 1);
477 } else {
478 dol_print_error($this->db);
479 return -1;
480 }
481 return $newid;
482 }
483
492 public function remove($options = '')
493 {
494 $sql = array();
495 return $this->_remove($sql, $options);
496 }
497}
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.
getNextId()
Returns next available id to insert new roles in llx_c_type_contact.
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.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:142