dolibarr  19.0.0-dev
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  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <https://www.gnu.org/licenses/>.
19  */
20 
29 include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
30 
35 {
41  public function __construct($db)
42  {
43  global $langs, $conf;
44  $this->db = $db;
45 
46  $langs->load('stocks');
47  // Id for module (must be unique).
48  // Use here a free id (See in Home -> System information -> Dolibarr for list of used modules id).
49  $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
50  // Key text used to identify module (for permissions, menus, etc...)
51  $this->rights_class = 'stocktransfer';
52  // Family can be 'base' (core modules),'crm','financial','hr','projects','products','ecm','technic' (transverse modules),'interface' (link with external tools),'other','...'
53  // It is used to group modules by family in module setup page
54  $this->family = "products";
55  // Module position in the family on 2 digits ('01', '10', '20', ...)
56  $this->module_position = '90';
57  // 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)
58  //$this->familyinfo = array('myownfamily' => array('position' => '01', 'label' => $langs->trans("MyOwnFamily")));
59  // Module label (no space allowed), used if translation string 'ModuleStockTransferName' not found (StockTransfer is name of module).
60  $this->name = preg_replace('/^mod/i', '', get_class($this));
61  // Module description, used if translation string 'ModuleStockTransferDesc' not found (StockTransfer is name of module).
62  $this->description = $langs->trans("ModuleStockTransferDesc");
63  // Used only if file README.md and README-LL.md not found.
64  $this->descriptionlong = "Advanced management of stock transfer orders with generation of stock transfer sheets";
65  // Possible values for version are: 'development', 'experimental', 'dolibarr', 'dolibarr_deprecated' or a version string like 'x.y.z'
66  $this->version = 'experimental';
67  // Url to the file with your last numberversion of this module
68  //$this->url_last_version = 'http://www.example.com/versionmodule.txt';
69 
70  // Key used in llx_const table to save module status enabled/disabled (where STOCKTRANSFER is value of property name of module in uppercase)
71  $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
72  // Name of image file used for this module.
73  // If file is in theme/yourtheme/img directory under name object_pictovalue.png, use this->picto='pictovalue'
74  // If file is in module/img directory under name object_pictovalue.png, use this->picto='pictovalue@module'
75  $this->picto = 'stock';
76  // Define some features supported by module (triggers, login, substitutions, menus, css, etc...)
77  $this->module_parts = array(
78  // Set this to 1 if module has its own trigger directory (core/triggers)
79  'triggers' => 0,
80  // Set this to 1 if module has its own login method file (core/login)
81  'login' => 0,
82  // Set this to 1 if module has its own substitution function file (core/substitutions)
83  'substitutions' => 0,
84  // Set this to 1 if module has its own menus handler directory (core/menus)
85  'menus' => 0,
86  // Set this to 1 if module overwrite template dir (core/tpl)
87  'tpl' => 0,
88  // Set this to 1 if module has its own barcode directory (core/modules/barcode)
89  'barcode' => 0,
90  // Set this to 1 if module has its own models directory (core/modules/xxx)
91  'models' => 1,
92  // Set this to 1 if module has its own theme directory (theme)
93  'theme' => 0,
94  // Set this to relative path of css file if module has its own css file
95  'css' => array(
96  // '/stocktransfer/css/stocktransfer.css.php',
97  ),
98  // Set this to relative path of js file if module must load a js on all pages
99  'js' => array(
100  // '/stocktransfer/js/stocktransfer.js.php',
101  ),
102  // 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'
103  'hooks' => array(
104  // 'data' => array(
105  // 'hookcontext1',
106  // 'hookcontext2',
107  // ),
108  // 'entity' => '0',
109  ),
110  // Set this to 1 if features of module are opened to external users
111  'moduleforexternal' => 0,
112  'contactelement'=>1
113  );
114  // Data directories to create when module is enabled.
115  // Example: this->dirs = array("/stocktransfer/temp","/stocktransfer/subdir");
116  $this->dirs = array("/stocktransfer/temp");
117  // Config pages. Put here list of php page, stored into stocktransfer/admin directory, to use to setup module.
118  $this->config_page_url = array("stocktransfer.php");
119  // Dependencies
120  // A condition to hide module
121  $this->hidden = false;
122  // 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'...))
123  $this->depends = array('modStock', 'modProduct');
124  $this->requiredby = array(); // List of module class names as string to disable if this one is disabled. Example: array('modModuleToDisable1', ...)
125  $this->conflictwith = array(); // List of module class names as string this module is in conflict with. Example: array('modModuleToDisable1', ...)
126  $this->langfiles = array("stocktransfer@stocktransfer");
127  $this->phpmin = array(7, 0); // Minimum version of PHP required by module
128  $this->warnings_activation = array(); // Warning to show when we activate module. array('always'='text') or array('FR'='textfr','ES'='textes'...)
129  $this->warnings_activation_ext = array(); // Warning to show when we activate an external module. array('always'='text') or array('FR'='textfr','ES'='textes'...)
130  //$this->automatic_activation = array('FR'=>'StockTransferWasAutomaticallyActivatedBecauseOfYourCountryChoice');
131  //$this->always_enabled = true; // If true, can't be disabled
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 = array();
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 = array();
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 fundation 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 = array();
175  /* Example:
176  $this->dictionaries=array(
177  'langs'=>'stocktransfer@stocktransfer',
178  // List of tables we want to see into dictonnary 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' => '$conf->stocktransfer->enabled',
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 = array();
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  // Main menu entries to add
256  $langs->load('stocktransfer@stocktransfer');
257  $this->menu = array();
258  $r = 0;
259  // Add here entries to declare new menus
260  /* BEGIN MODULEBUILDER TOPMENU */
261  /*$this->menu[$r++] = array(
262  '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
263  'type'=>'top', // This is a Top menu entry
264  'titre'=>'ModuleStockTransferName',
265  'mainmenu'=>'stocktransfer',
266  'leftmenu'=>'',
267  'url'=>'/stocktransfer/stocktransferindex.php',
268  'langs'=>'stocktransfer@stocktransfer', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
269  'position'=>1000 + $r,
270  '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.
271  'perms'=>'1', // Use 'perms'=>'$user->rights->stocktransfer->stocktransfer->read' if you want your menu with a permission rules
272  'target'=>'',
273  'user'=>2, // 0=Menu for internal users, 1=external users, 2=both
274  );*/
275  /* END MODULEBUILDER TOPMENU */
276  /* BEGIN MODULEBUILDER LEFTMENU STOCKTRANSFER
277  $this->menu[$r++]=array(
278  '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
279  'type'=>'left', // This is a Top menu entry
280  'titre'=>'StockTransfer',
281  'mainmenu'=>'stocktransfer',
282  'leftmenu'=>'stocktransfer',
283  'url'=>'/stocktransfer/stocktransferindex.php',
284  'langs'=>'stocktransfer@stocktransfer', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
285  'position'=>1000+$r,
286  '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.
287  'perms'=>'$user->rights->stocktransfer->stocktransfer->read', // Use 'perms'=>'$user->rights->stocktransfer->level1->level2' if you want your menu with a permission rules
288  'target'=>'',
289  'user'=>2, // 0=Menu for internal users, 1=external users, 2=both
290  );
291  $this->menu[$r++]=array(
292  '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
293  'type'=>'left', // This is a Left menu entry
294  'titre'=>'List StockTransfer',
295  'mainmenu'=>'stocktransfer',
296  'leftmenu'=>'stocktransfer_stocktransfer_list',
297  'url'=>'/stocktransfer/stocktransfer_list.php',
298  'langs'=>'stocktransfer@stocktransfer', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
299  'position'=>1000+$r,
300  '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.
301  'perms'=>'$user->rights->stocktransfer->stocktransfer->read', // Use 'perms'=>'$user->rights->stocktransfer->level1->level2' if you want your menu with a permission rules
302  'target'=>'',
303  'user'=>2, // 0=Menu for internal users, 1=external users, 2=both
304  );
305  $this->menu[$r++]=array(
306  '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
307  'type'=>'left', // This is a Left menu entry
308  'titre'=>'New StockTransfer',
309  'mainmenu'=>'stocktransfer',
310  'leftmenu'=>'stocktransfer_stocktransfer_new',
311  'url'=>'/stocktransfer/stocktransfer_card.php?action=create',
312  'langs'=>'stocktransfer@stocktransfer', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
313  'position'=>1000+$r,
314  '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.
315  'perms'=>'$user->rights->stocktransfer->stocktransfer->write', // Use 'perms'=>'$user->rights->stocktransfer->level1->level2' if you want your menu with a permission rules
316  'target'=>'',
317  'user'=>2, // 0=Menu for internal users, 1=external users, 2=both
318  );
319  */
320 
321  /*$this->menu[$r++]=array(
322  // '' 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
323  'fk_menu'=>'fk_mainmenu=products,fk_leftmenu=stock',
324  // This is a Left menu entry
325  'type'=>'left',
326  'titre'=>$langs->trans('StockTransferNew'),
327  'mainmenu'=>'products',
328  'leftmenu'=>'stocktransfer_stocktransfer',
329  'url'=>'/stocktransfer/stocktransfer_card.php?action=create',
330  // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
331  'langs'=>'stocktransfer@stocktransfer',
332  'position'=>1100+$r,
333  // 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.
334  'enabled'=>'$conf->stocktransfer->enabled',
335  // Use 'perms'=>'$user->rights->stocktransfer->level1->level2' if you want your menu with a permission rules
336  'perms'=>'1',
337  'target'=>'',
338  // 0=Menu for internal users, 1=external users, 2=both
339  'user'=>2
340  );
341  $this->menu[$r++]=array(
342  // '' 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
343  'fk_menu'=>'fk_mainmenu=products,fk_leftmenu=stock',
344  // This is a Left menu entry
345  'type'=>'left',
346  'titre'=>$langs->trans('StockTransferList'),
347  'mainmenu'=>'products',
348  'leftmenu'=>'stocktransfer_stocktransferlist',
349  'url'=>'/stocktransfer/stocktransfer_list.php',
350  // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
351  'langs'=>'stocktransfer@stocktransfer',
352  'position'=>1100+$r,
353  // 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.
354  'enabled'=>'$conf->stocktransfer->enabled',
355  // Use 'perms'=>'$user->rights->stocktransfer->level1->level2' if you want your menu with a permission rules
356  'perms'=>'1',
357  'target'=>'',
358  // 0=Menu for internal users, 1=external users, 2=both
359  'user'=>2,
360  );*/
361 
362  /* END MODULEBUILDER LEFTMENU STOCKTRANSFER */
363 
364  // Exports profiles provided by this module
365  $r = 1;
366  /* BEGIN MODULEBUILDER EXPORT STOCKTRANSFER */
367  /*
368  $langs->load("stocktransfer@stocktransfer");
369  $this->export_code[$r]=$this->rights_class.'_'.$r;
370  $this->export_label[$r]='StockTransferLines'; // Translation key (used only if key ExportDataset_xxx_z not found)
371  $this->export_icon[$r]='stocktransfer@stocktransfer';
372  // Define $this->export_fields_array, $this->export_TypeFields_array and $this->export_entities_array
373  $keyforclass = 'StockTransfer'; $keyforclassfile='/stocktransfer/class/stocktransfer.class.php'; $keyforelement='stocktransfer@stocktransfer';
374  include DOL_DOCUMENT_ROOT.'/core/commonfieldsinexport.inc.php';
375  //$this->export_fields_array[$r]['t.fieldtoadd']='FieldToAdd'; $this->export_TypeFields_array[$r]['t.fieldtoadd']='Text';
376  //unset($this->export_fields_array[$r]['t.fieldtoremove']);
377  //$keyforclass = 'StockTransferLine'; $keyforclassfile='/stocktransfer/class/stocktransfer.class.php'; $keyforelement='stocktransferline@stocktransfer'; $keyforalias='tl';
378  //include DOL_DOCUMENT_ROOT.'/core/commonfieldsinexport.inc.php';
379  $keyforselect='stocktransfer'; $keyforaliasextra='extra'; $keyforelement='stocktransfer@stocktransfer';
380  include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
381  //$keyforselect='stocktransferline'; $keyforaliasextra='extraline'; $keyforelement='stocktransferline@stocktransfer';
382  //include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
383  //$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)
384  //$this->export_special_array[$r] = array('t.field'=>'...');
385  //$this->export_examplevalues_array[$r] = array('t.field'=>'Example');
386  //$this->export_help_array[$r] = array('t.field'=>'FieldDescHelp');
387  $this->export_sql_start[$r]='SELECT DISTINCT ';
388  $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'stocktransfer as t';
389  //$this->export_sql_end[$r] =' LEFT JOIN '.MAIN_DB_PREFIX.'stocktransfer_line as tl ON tl.fk_stocktransfer = t.rowid';
390  $this->export_sql_end[$r] .=' WHERE 1 = 1';
391  $this->export_sql_end[$r] .=' AND t.entity IN ('.getEntity('stocktransfer').')';
392  $r++; */
393  /* END MODULEBUILDER EXPORT STOCKTRANSFER */
394 
395  // Imports profiles provided by this module
396  $r = 1;
397  /* BEGIN MODULEBUILDER IMPORT STOCKTRANSFER */
398  /*
399  $langs->load("stocktransfer@stocktransfer");
400  $this->export_code[$r]=$this->rights_class.'_'.$r;
401  $this->export_label[$r]='StockTransferLines'; // Translation key (used only if key ExportDataset_xxx_z not found)
402  $this->export_icon[$r]='stocktransfer@stocktransfer';
403  $keyforclass = 'StockTransfer'; $keyforclassfile='/stocktransfer/class/stocktransfer.class.php'; $keyforelement='stocktransfer@stocktransfer';
404  include DOL_DOCUMENT_ROOT.'/core/commonfieldsinexport.inc.php';
405  $keyforselect='stocktransfer'; $keyforaliasextra='extra'; $keyforelement='stocktransfer@stocktransfer';
406  include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
407  //$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)
408  $this->export_sql_start[$r]='SELECT DISTINCT ';
409  $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'stocktransfer as t';
410  $this->export_sql_end[$r] .=' WHERE 1 = 1';
411  $this->export_sql_end[$r] .=' AND t.entity IN ('.getEntity('stocktransfer').')';
412  $r++; */
413  /* END MODULEBUILDER IMPORT STOCKTRANSFER */
414  }
415 
424  public function init($options = '')
425  {
426  global $conf, $langs;
427 
428  $result = $this->_load_tables('/install/mysql/tables/', 'stocktransfer');
429  if ($result < 0) 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')
430 
431  // Permissions
432  $this->remove($options);
433 
434  $sql = array();
435 
436  // Rôles
437  $resql = $this->db->query('SELECT rowid FROM '.MAIN_DB_PREFIX.'c_type_contact WHERE code = "STDEST" AND element = "StockTransfer" AND source = "internal"');
438  $res = $this->db->fetch_object($resql);
439  $nextid=$this->getNextId();
440  if (empty($res)) $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", "Responsable du transfert de stocks", 1, NULL, 0)');
441 
442  $resql = $this->db->query('SELECT rowid FROM '.MAIN_DB_PREFIX.'c_type_contact WHERE code = "STFROM" AND element = "StockTransfer" AND source = "external"');
443  $res = $this->db->fetch_object($resql);
444  $nextid=$this->getNextId();
445  if (empty($res)) $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 expéditeur transfert de stocks", 1, NULL, 0)');
446 
447  $resql = $this->db->query('SELECT rowid FROM '.MAIN_DB_PREFIX.'c_type_contact WHERE code = "STDEST" AND element = "StockTransfer" AND source = "external"');
448  $res = $this->db->fetch_object($resql);
449  $nextid=$this->getNextId();
450  if (empty($res)) $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 destinataire transfert de stocks", 1, NULL, 0)');
451 
452  return $this->_init($sql, $options);
453  }
454 
459  public function getNextId()
460  {
461  // Get free id for insert
462  $newid = 0;
463  $sql = "SELECT max(rowid) newid from ".MAIN_DB_PREFIX."c_type_contact";
464  $result = $this->db->query($sql);
465  if ($result) {
466  $obj = $this->db->fetch_object($result);
467  $newid = ($obj->newid + 1);
468  } else {
469  dol_print_error($this->db);
470  return -1;
471  }
472  return $newid;
473  }
474 
483  public function remove($options = '')
484  {
485  $sql = array();
486  return $this->_remove($sql, $options);
487  }
488 }
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.
if(isModEnabled('facture') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
Definition: index.php:746
print *****$script_file(".$version.") pid cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_print_error($db='', $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:123