dolibarr  16.0.5
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-2020 Frédéric France <frederic.france@netlogic.fr>
5  * Copyright (C) 2021 SuperAdmin
6  * Copyright (C) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
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 
30 include_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 = "other";
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 = "StockTransfer description (Long)";
66  $this->editor_name = 'Editor name';
67  $this->editor_url = 'https://www.example.com';
68  // Possible values for version are: 'development', 'experimental', 'dolibarr', 'dolibarr_deprecated' or a version string like 'x.y.z'
69  $this->version = 'development';
70  // Url to the file with your last numberversion of this module
71  //$this->url_last_version = 'http://www.example.com/versionmodule.txt';
72 
73  // Key used in llx_const table to save module status enabled/disabled (where STOCKTRANSFER is value of property name of module in uppercase)
74  $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
75  // Name of image file used for this module.
76  // If file is in theme/yourtheme/img directory under name object_pictovalue.png, use this->picto='pictovalue'
77  // If file is in module/img directory under name object_pictovalue.png, use this->picto='pictovalue@module'
78  $this->picto = 'stock';
79  // Define some features supported by module (triggers, login, substitutions, menus, css, etc...)
80  $this->module_parts = array(
81  // Set this to 1 if module has its own trigger directory (core/triggers)
82  'triggers' => 0,
83  // Set this to 1 if module has its own login method file (core/login)
84  'login' => 0,
85  // Set this to 1 if module has its own substitution function file (core/substitutions)
86  'substitutions' => 0,
87  // Set this to 1 if module has its own menus handler directory (core/menus)
88  'menus' => 0,
89  // Set this to 1 if module overwrite template dir (core/tpl)
90  'tpl' => 0,
91  // Set this to 1 if module has its own barcode directory (core/modules/barcode)
92  'barcode' => 0,
93  // Set this to 1 if module has its own models directory (core/modules/xxx)
94  'models' => 1,
95  // Set this to 1 if module has its own theme directory (theme)
96  'theme' => 0,
97  // Set this to relative path of css file if module has its own css file
98  'css' => array(
99  // '/stocktransfer/css/stocktransfer.css.php',
100  ),
101  // Set this to relative path of js file if module must load a js on all pages
102  'js' => array(
103  // '/stocktransfer/js/stocktransfer.js.php',
104  ),
105  // 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'
106  'hooks' => array(
107  // 'data' => array(
108  // 'hookcontext1',
109  // 'hookcontext2',
110  // ),
111  // 'entity' => '0',
112  ),
113  // Set this to 1 if features of module are opened to external users
114  'moduleforexternal' => 0,
115  'contactelement'=>1
116  );
117  // Data directories to create when module is enabled.
118  // Example: this->dirs = array("/stocktransfer/temp","/stocktransfer/subdir");
119  $this->dirs = array("/stocktransfer/temp");
120  // Config pages. Put here list of php page, stored into stocktransfer/admin directory, to use to setup module.
121  $this->config_page_url = array("stocktransfer.php");
122  // Dependencies
123  // A condition to hide module
124  $this->hidden = false;
125  // List of module class names as string that must be enabled if this module is enabled. Example: array('always1'=>'modModuleToEnable1','always2'=>'modModuleToEnable2', 'FR1'=>'modModuleToEnableFR'...)
126  $this->depends = array('modStock', 'modProduct');
127  $this->requiredby = array(); // List of module class names as string to disable if this one is disabled. Example: array('modModuleToDisable1', ...)
128  $this->conflictwith = array(); // List of module class names as string this module is in conflict with. Example: array('modModuleToDisable1', ...)
129  $this->langfiles = array("stocktransfer@stocktransfer");
130  $this->phpmin = array(5, 5); // Minimum version of PHP required by module
131  $this->need_dolibarr_version = array(11, -3); // Minimum version of Dolibarr required by module
132  $this->warnings_activation = array(); // Warning to show when we activate module. array('always'='text') or array('FR'='textfr','ES'='textes'...)
133  $this->warnings_activation_ext = array(); // Warning to show when we activate an external module. array('always'='text') or array('FR'='textfr','ES'='textes'...)
134  //$this->automatic_activation = array('FR'=>'StockTransferWasAutomaticallyActivatedBecauseOfYourCountryChoice');
135  //$this->always_enabled = true; // If true, can't be disabled
136 
137  // Constants
138  // List of particular constants to add when module is enabled (key, 'chaine', value, desc, visible, 'current' or 'allentities', deleteonunactive)
139  // Example: $this->const=array(1 => array('STOCKTRANSFER_MYNEWCONST1', 'chaine', 'myvalue', 'This is a constant to add', 1),
140  // 2 => array('STOCKTRANSFER_MYNEWCONST2', 'chaine', 'myvalue', 'This is another constant to add', 0, 'current', 1)
141  // );
142  $this->const = array();
143 
144  // Some keys to add into the overwriting translation tables
145  /*$this->overwrite_translation = array(
146  'en_US:ParentCompany'=>'Parent company or reseller',
147  'fr_FR:ParentCompany'=>'Maison mère ou revendeur'
148  )*/
149 
150  if (!isset($conf->stocktransfer) || !isset($conf->stocktransfer->enabled)) {
151  $conf->stocktransfer = new stdClass();
152  $conf->stocktransfer->enabled = 0;
153  }
154 
155  // Array to add new pages in new tabs
156  $this->tabs = array();
157  // Example:
158  // $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
159  // $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.
160  // $this->tabs[] = array('data'=>'objecttype:-tabname:NU:conditiontoremove'); // To remove an existing tab identified by code tabname
161  //
162  // Where objecttype can be
163  // 'categories_x' to add a tab in category view (replace 'x' by type of category (0=product, 1=supplier, 2=customer, 3=member)
164  // 'contact' to add a tab in contact view
165  // 'contract' to add a tab in contract view
166  // 'group' to add a tab in group view
167  // 'intervention' to add a tab in intervention view
168  // 'invoice' to add a tab in customer invoice view
169  // 'invoice_supplier' to add a tab in supplier invoice view
170  // 'member' to add a tab in fundation member view
171  // 'opensurveypoll' to add a tab in opensurvey poll view
172  // 'order' to add a tab in customer order view
173  // 'order_supplier' to add a tab in supplier order view
174  // 'payment' to add a tab in payment view
175  // 'payment_supplier' to add a tab in supplier payment view
176  // 'product' to add a tab in product view
177  // 'propal' to add a tab in propal view
178  // 'project' to add a tab in project view
179  // 'stock' to add a tab in stock view
180  // 'thirdparty' to add a tab in third party view
181  // 'user' to add a tab in user view
182 
183  // Dictionaries
184  $this->dictionaries = array();
185  /* Example:
186  $this->dictionaries=array(
187  'langs'=>'stocktransfer@stocktransfer',
188  // List of tables we want to see into dictonnary editor
189  'tabname'=>array(MAIN_DB_PREFIX."table1", MAIN_DB_PREFIX."table2", MAIN_DB_PREFIX."table3"),
190  // Label of tables
191  'tablib'=>array("Table1", "Table2", "Table3"),
192  // Request to select fields
193  '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'),
194  // Sort order
195  'tabsqlsort'=>array("label ASC", "label ASC", "label ASC"),
196  // List of fields (result of select to show dictionary)
197  'tabfield'=>array("code,label", "code,label", "code,label"),
198  // List of fields (list of fields to edit a record)
199  'tabfieldvalue'=>array("code,label", "code,label", "code,label"),
200  // List of fields (list of fields for insert)
201  'tabfieldinsert'=>array("code,label", "code,label", "code,label"),
202  // Name of columns with primary key (try to always name it 'rowid')
203  'tabrowid'=>array("rowid", "rowid", "rowid"),
204  // Condition to show each dictionary
205  'tabcond'=>array($conf->stocktransfer->enabled, $conf->stocktransfer->enabled, $conf->stocktransfer->enabled)
206  );
207  */
208 
209  // Boxes/Widgets
210  // Add here list of php file(s) stored in stocktransfer/core/boxes that contains a class to show a widget.
211  $this->boxes = array(
212  // 0 => array(
213  // 'file' => 'stocktransferwidget1.php@stocktransfer',
214  // 'note' => 'Widget provided by StockTransfer',
215  // 'enabledbydefaulton' => 'Home',
216  // ),
217  // ...
218  );
219 
220  // Cronjobs (List of cron jobs entries to add when module is enabled)
221  // unit_frequency must be 60 for minute, 3600 for hour, 86400 for day, 604800 for week
222  $this->cronjobs = array(
223  // 0 => array(
224  // 'label' => 'MyJob label',
225  // 'jobtype' => 'method',
226  // 'class' => '/stocktransfer/class/stocktransfer.class.php',
227  // 'objectname' => 'StockTransfer',
228  // 'method' => 'doScheduledJob',
229  // 'parameters' => '',
230  // 'comment' => 'Comment',
231  // 'frequency' => 2,
232  // 'unitfrequency' => 3600,
233  // 'status' => 0,
234  // 'test' => '$conf->stocktransfer->enabled',
235  // 'priority' => 50,
236  // ),
237  );
238  // Example: $this->cronjobs=array(
239  // 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),
240  // 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)
241  // );
242 
243  // Permissions provided by this module
244  $this->rights = array();
245  $r = 10;
246  // Add here entries to declare new permissions
247  /* BEGIN MODULEBUILDER PERMISSIONS */
248  $this->rights[$r][0] = $this->numero + $r; // Permission id (must not be already used)
249  $this->rights[$r][1] = $langs->trans('StockTransferRightRead'); // 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] = 'read'; // In php code, permission will be checked by test if ($user->rights->stocktransfer->level1->level2)
252  $r++;
253  $this->rights[$r][0] = $this->numero + $r; // Permission id (must not be already used)
254  $this->rights[$r][1] = $langs->trans('StockTransferRightCreateUpdate'); // Permission label
255  $this->rights[$r][4] = 'stocktransfer'; // In php code, permission will be checked by test if ($user->rights->stocktransfer->level1->level2)
256  $this->rights[$r][5] = 'write'; // In php code, permission will be checked by test if ($user->rights->stocktransfer->level1->level2)
257  $r++;
258  $this->rights[$r][0] = $this->numero + $r; // Permission id (must not be already used)
259  $this->rights[$r][1] = $langs->trans('StockTransferRightDelete'); // Permission label
260  $this->rights[$r][4] = 'stocktransfer'; // In php code, permission will be checked by test if ($user->rights->stocktransfer->level1->level2)
261  $this->rights[$r][5] = 'delete'; // In php code, permission will be checked by test if ($user->rights->stocktransfer->level1->level2)
262  $r++;
263  /* END MODULEBUILDER PERMISSIONS */
264 
265  // Main menu entries to add
266  $langs->load('stocktransfer@stocktransfer');
267  $this->menu = array();
268  $r = 0;
269  // Add here entries to declare new menus
270  /* BEGIN MODULEBUILDER TOPMENU */
271  /*$this->menu[$r++] = array(
272  '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
273  'type'=>'top', // This is a Top menu entry
274  'titre'=>'ModuleStockTransferName',
275  'mainmenu'=>'stocktransfer',
276  'leftmenu'=>'',
277  'url'=>'/stocktransfer/stocktransferindex.php',
278  'langs'=>'stocktransfer@stocktransfer', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
279  'position'=>1000 + $r,
280  '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.
281  'perms'=>'1', // Use 'perms'=>'$user->rights->stocktransfer->stocktransfer->read' if you want your menu with a permission rules
282  'target'=>'',
283  'user'=>2, // 0=Menu for internal users, 1=external users, 2=both
284  );*/
285  /* END MODULEBUILDER TOPMENU */
286  /* BEGIN MODULEBUILDER LEFTMENU STOCKTRANSFER
287  $this->menu[$r++]=array(
288  '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
289  'type'=>'left', // This is a Top menu entry
290  'titre'=>'StockTransfer',
291  'mainmenu'=>'stocktransfer',
292  'leftmenu'=>'stocktransfer',
293  'url'=>'/stocktransfer/stocktransferindex.php',
294  'langs'=>'stocktransfer@stocktransfer', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
295  'position'=>1000+$r,
296  '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.
297  'perms'=>'$user->rights->stocktransfer->stocktransfer->read', // Use 'perms'=>'$user->rights->stocktransfer->level1->level2' if you want your menu with a permission rules
298  'target'=>'',
299  'user'=>2, // 0=Menu for internal users, 1=external users, 2=both
300  );
301  $this->menu[$r++]=array(
302  '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
303  'type'=>'left', // This is a Left menu entry
304  'titre'=>'List StockTransfer',
305  'mainmenu'=>'stocktransfer',
306  'leftmenu'=>'stocktransfer_stocktransfer_list',
307  'url'=>'/stocktransfer/stocktransfer_list.php',
308  'langs'=>'stocktransfer@stocktransfer', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
309  'position'=>1000+$r,
310  '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.
311  'perms'=>'$user->rights->stocktransfer->stocktransfer->read', // Use 'perms'=>'$user->rights->stocktransfer->level1->level2' if you want your menu with a permission rules
312  'target'=>'',
313  'user'=>2, // 0=Menu for internal users, 1=external users, 2=both
314  );
315  $this->menu[$r++]=array(
316  '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
317  'type'=>'left', // This is a Left menu entry
318  'titre'=>'New StockTransfer',
319  'mainmenu'=>'stocktransfer',
320  'leftmenu'=>'stocktransfer_stocktransfer_new',
321  'url'=>'/stocktransfer/stocktransfer_card.php?action=create',
322  'langs'=>'stocktransfer@stocktransfer', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
323  'position'=>1000+$r,
324  '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.
325  'perms'=>'$user->rights->stocktransfer->stocktransfer->write', // Use 'perms'=>'$user->rights->stocktransfer->level1->level2' if you want your menu with a permission rules
326  'target'=>'',
327  'user'=>2, // 0=Menu for internal users, 1=external users, 2=both
328  );
329  */
330 
331  /*$this->menu[$r++]=array(
332  // '' 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
333  'fk_menu'=>'fk_mainmenu=products,fk_leftmenu=stock',
334  // This is a Left menu entry
335  'type'=>'left',
336  'titre'=>$langs->trans('StockTransferNew'),
337  'mainmenu'=>'products',
338  'leftmenu'=>'stocktransfer_stocktransfer',
339  'url'=>'/stocktransfer/stocktransfer_card.php?action=create',
340  // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
341  'langs'=>'stocktransfer@stocktransfer',
342  'position'=>1100+$r,
343  // 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.
344  'enabled'=>'$conf->stocktransfer->enabled',
345  // Use 'perms'=>'$user->rights->stocktransfer->level1->level2' if you want your menu with a permission rules
346  'perms'=>'1',
347  'target'=>'',
348  // 0=Menu for internal users, 1=external users, 2=both
349  'user'=>2
350  );
351  $this->menu[$r++]=array(
352  // '' 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
353  'fk_menu'=>'fk_mainmenu=products,fk_leftmenu=stock',
354  // This is a Left menu entry
355  'type'=>'left',
356  'titre'=>$langs->trans('StockTransferList'),
357  'mainmenu'=>'products',
358  'leftmenu'=>'stocktransfer_stocktransferlist',
359  'url'=>'/stocktransfer/stocktransfer_list.php',
360  // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
361  'langs'=>'stocktransfer@stocktransfer',
362  'position'=>1100+$r,
363  // 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.
364  'enabled'=>'$conf->stocktransfer->enabled',
365  // Use 'perms'=>'$user->rights->stocktransfer->level1->level2' if you want your menu with a permission rules
366  'perms'=>'1',
367  'target'=>'',
368  // 0=Menu for internal users, 1=external users, 2=both
369  'user'=>2,
370  );*/
371 
372  /* END MODULEBUILDER LEFTMENU STOCKTRANSFER */
373 
374  // Exports profiles provided by this module
375  $r = 1;
376  /* BEGIN MODULEBUILDER EXPORT STOCKTRANSFER */
377  /*
378  $langs->load("stocktransfer@stocktransfer");
379  $this->export_code[$r]=$this->rights_class.'_'.$r;
380  $this->export_label[$r]='StockTransferLines'; // Translation key (used only if key ExportDataset_xxx_z not found)
381  $this->export_icon[$r]='stocktransfer@stocktransfer';
382  // Define $this->export_fields_array, $this->export_TypeFields_array and $this->export_entities_array
383  $keyforclass = 'StockTransfer'; $keyforclassfile='/stocktransfer/class/stocktransfer.class.php'; $keyforelement='stocktransfer@stocktransfer';
384  include DOL_DOCUMENT_ROOT.'/core/commonfieldsinexport.inc.php';
385  //$this->export_fields_array[$r]['t.fieldtoadd']='FieldToAdd'; $this->export_TypeFields_array[$r]['t.fieldtoadd']='Text';
386  //unset($this->export_fields_array[$r]['t.fieldtoremove']);
387  //$keyforclass = 'StockTransferLine'; $keyforclassfile='/stocktransfer/class/stocktransfer.class.php'; $keyforelement='stocktransferline@stocktransfer'; $keyforalias='tl';
388  //include DOL_DOCUMENT_ROOT.'/core/commonfieldsinexport.inc.php';
389  $keyforselect='stocktransfer'; $keyforaliasextra='extra'; $keyforelement='stocktransfer@stocktransfer';
390  include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
391  //$keyforselect='stocktransferline'; $keyforaliasextra='extraline'; $keyforelement='stocktransferline@stocktransfer';
392  //include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
393  //$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)
394  //$this->export_special_array[$r] = array('t.field'=>'...');
395  //$this->export_examplevalues_array[$r] = array('t.field'=>'Example');
396  //$this->export_help_array[$r] = array('t.field'=>'FieldDescHelp');
397  $this->export_sql_start[$r]='SELECT DISTINCT ';
398  $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'stocktransfer as t';
399  //$this->export_sql_end[$r] =' LEFT JOIN '.MAIN_DB_PREFIX.'stocktransfer_line as tl ON tl.fk_stocktransfer = t.rowid';
400  $this->export_sql_end[$r] .=' WHERE 1 = 1';
401  $this->export_sql_end[$r] .=' AND t.entity IN ('.getEntity('stocktransfer').')';
402  $r++; */
403  /* END MODULEBUILDER EXPORT STOCKTRANSFER */
404 
405  // Imports profiles provided by this module
406  $r = 1;
407  /* BEGIN MODULEBUILDER IMPORT STOCKTRANSFER */
408  /*
409  $langs->load("stocktransfer@stocktransfer");
410  $this->export_code[$r]=$this->rights_class.'_'.$r;
411  $this->export_label[$r]='StockTransferLines'; // Translation key (used only if key ExportDataset_xxx_z not found)
412  $this->export_icon[$r]='stocktransfer@stocktransfer';
413  $keyforclass = 'StockTransfer'; $keyforclassfile='/stocktransfer/class/stocktransfer.class.php'; $keyforelement='stocktransfer@stocktransfer';
414  include DOL_DOCUMENT_ROOT.'/core/commonfieldsinexport.inc.php';
415  $keyforselect='stocktransfer'; $keyforaliasextra='extra'; $keyforelement='stocktransfer@stocktransfer';
416  include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
417  //$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)
418  $this->export_sql_start[$r]='SELECT DISTINCT ';
419  $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'stocktransfer as t';
420  $this->export_sql_end[$r] .=' WHERE 1 = 1';
421  $this->export_sql_end[$r] .=' AND t.entity IN ('.getEntity('stocktransfer').')';
422  $r++; */
423  /* END MODULEBUILDER IMPORT STOCKTRANSFER */
424  }
425 
434  public function init($options = '')
435  {
436  global $conf, $langs;
437 
438  $result = $this->_load_tables('/install/mysql/tables/', 'stocktransfer');
439  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')
440 
441  // Create extrafields during init
442  //include_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
443  //$extrafields = new ExtraFields($this->db);
444  //$result1=$extrafields->addExtraField('stocktransfer_myattr1', "New Attr 1 label", 'boolean', 1, 3, 'thirdparty', 0, 0, '', '', 1, '', 0, 0, '', '', 'stocktransfer@stocktransfer', '$conf->stocktransfer->enabled');
445  //$result2=$extrafields->addExtraField('stocktransfer_myattr2', "New Attr 2 label", 'varchar', 1, 10, 'project', 0, 0, '', '', 1, '', 0, 0, '', '', 'stocktransfer@stocktransfer', '$conf->stocktransfer->enabled');
446  //$result3=$extrafields->addExtraField('stocktransfer_myattr3', "New Attr 3 label", 'varchar', 1, 10, 'bank_account', 0, 0, '', '', 1, '', 0, 0, '', '', 'stocktransfer@stocktransfer', '$conf->stocktransfer->enabled');
447  //$result4=$extrafields->addExtraField('stocktransfer_myattr4', "New Attr 4 label", 'select', 1, 3, 'thirdparty', 0, 1, '', array('options'=>array('code1'=>'Val1','code2'=>'Val2','code3'=>'Val3')), 1,'', 0, 0, '', '', 'stocktransfer@stocktransfer', '$conf->stocktransfer->enabled');
448  //$result5=$extrafields->addExtraField('stocktransfer_myattr5', "New Attr 5 label", 'text', 1, 10, 'user', 0, 0, '', '', 1, '', 0, 0, '', '', 'stocktransfer@stocktransfer', '$conf->stocktransfer->enabled');
449 
450  // Permissions
451  $this->remove($options);
452 
453  $sql = array();
454 
455  // Rôles
456  $resql = $this->db->query('SELECT rowid FROM '.MAIN_DB_PREFIX.'c_type_contact WHERE code = "STDEST" AND element = "StockTransfer" AND source = "internal"');
457  $res = $this->db->fetch_object($resql);
458  $nextid=$this->getNextId();
459  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)');
460 
461  $resql = $this->db->query('SELECT rowid FROM '.MAIN_DB_PREFIX.'c_type_contact WHERE code = "STFROM" AND element = "StockTransfer" AND source = "external"');
462  $res = $this->db->fetch_object($resql);
463  $nextid=$this->getNextId();
464  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)');
465 
466  $resql = $this->db->query('SELECT rowid FROM '.MAIN_DB_PREFIX.'c_type_contact WHERE code = "STDEST" AND element = "StockTransfer" AND source = "external"');
467  $res = $this->db->fetch_object($resql);
468  $nextid=$this->getNextId();
469  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)');
470 
471  return $this->_init($sql, $options);
472  }
473 
478  public function getNextId()
479  {
480  // Get free id for insert
481  $newid = 0;
482  $sql = "SELECT max(rowid) newid from ".MAIN_DB_PREFIX."c_type_contact";
483  $result = $this->db->query($sql);
484  if ($result) {
485  $obj = $this->db->fetch_object($result);
486  $newid = ($obj->newid + 1);
487  } else {
488  dol_print_error($this->db);
489  return -1;
490  }
491  return $newid;
492  }
493 
502  public function remove($options = '')
503  {
504  $sql = array();
505  return $this->_remove($sql, $options);
506  }
507 }
db
$conf db
API class for accounts.
Definition: inc.php:41
modStockTransfer
Description and activation class for module StockTransfer.
Definition: modStockTransfer.class.php:35
description
print *****$script_file(".$version.") pid cd cd cd description as description
Definition: email_expire_services_to_customers.php:83
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
DolibarrModules\_load_tables
_load_tables($reldir, $onlywithsuffix='')
Create tables and keys required by module:
Definition: DolibarrModules.class.php:1070
name
$conf db name
Definition: repair.php:122
modStockTransfer\getNextId
getNextId()
Returns next available id to insert new roles in llx_c_type_contact.
Definition: modStockTransfer.class.php:478
DolibarrModules\_remove
_remove($array_sql, $options='')
Disable function.
Definition: DolibarrModules.class.php:482
modStockTransfer\init
init($options='')
Function called when module is enabled.
Definition: modStockTransfer.class.php:434
DolibarrModules\_init
_init($array_sql, $options='')
Enables a module.
Definition: DolibarrModules.class.php:383
modStockTransfer\__construct
__construct($db)
Constructor.
Definition: modStockTransfer.class.php:42
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->supplier_invoice->lire)) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
DolibarrModules
Class DolibarrModules.
Definition: DolibarrModules.class.php:37