modStockTransfer.class.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  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. /**
  21. * \defgroup stocktransfer Module StockTransfer
  22. * \brief StockTransfer module descriptor.
  23. *
  24. * \file htdocs/stocktransfer/core/modules/modStockTransfer.class.php
  25. * \ingroup stocktransfer
  26. * \brief Description and activation file for module StockTransfer
  27. */
  28. include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
  29. /**
  30. * Description and activation class for module StockTransfer
  31. */
  32. class modStockTransfer extends DolibarrModules
  33. {
  34. /**
  35. * Constructor. Define names, constants, directories, boxes, permissions
  36. *
  37. * @param DoliDB $db Database handler
  38. */
  39. public function __construct($db)
  40. {
  41. global $langs, $conf;
  42. $this->db = $db;
  43. $langs->load('stocks');
  44. // Id for module (must be unique).
  45. // Use here a free id (See in Home -> System information -> Dolibarr for list of used modules id).
  46. $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
  47. // Key text used to identify module (for permissions, menus, etc...)
  48. $this->rights_class = 'stocktransfer';
  49. // Family can be 'base' (core modules),'crm','financial','hr','projects','products','ecm','technic' (transverse modules),'interface' (link with external tools),'other','...'
  50. // It is used to group modules by family in module setup page
  51. $this->family = "products";
  52. // Module position in the family on 2 digits ('01', '10', '20', ...)
  53. $this->module_position = '90';
  54. // 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)
  55. //$this->familyinfo = array('myownfamily' => array('position' => '01', 'label' => $langs->trans("MyOwnFamily")));
  56. // Module label (no space allowed), used if translation string 'ModuleStockTransferName' not found (StockTransfer is name of module).
  57. $this->name = preg_replace('/^mod/i', '', get_class($this));
  58. // Module description, used if translation string 'ModuleStockTransferDesc' not found (StockTransfer is name of module).
  59. $this->description = $langs->trans("ModuleStockTransferDesc");
  60. // Used only if file README.md and README-LL.md not found.
  61. $this->descriptionlong = "Advanced management of stock transfer orders with generation of stock transfer sheets";
  62. // Possible values for version are: 'development', 'experimental', 'dolibarr', 'dolibarr_deprecated' or a version string like 'x.y.z'
  63. $this->version = 'experimental';
  64. // Url to the file with your last numberversion of this module
  65. //$this->url_last_version = 'http://www.example.com/versionmodule.txt';
  66. // Key used in llx_const table to save module status enabled/disabled (where STOCKTRANSFER is value of property name of module in uppercase)
  67. $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
  68. // Name of image file used for this module.
  69. // If file is in theme/yourtheme/img directory under name object_pictovalue.png, use this->picto='pictovalue'
  70. // If file is in module/img directory under name object_pictovalue.png, use this->picto='pictovalue@module'
  71. $this->picto = 'stock';
  72. // Define some features supported by module (triggers, login, substitutions, menus, css, etc...)
  73. $this->module_parts = array(
  74. // Set this to 1 if module has its own trigger directory (core/triggers)
  75. 'triggers' => 0,
  76. // Set this to 1 if module has its own login method file (core/login)
  77. 'login' => 0,
  78. // Set this to 1 if module has its own substitution function file (core/substitutions)
  79. 'substitutions' => 0,
  80. // Set this to 1 if module has its own menus handler directory (core/menus)
  81. 'menus' => 0,
  82. // Set this to 1 if module overwrite template dir (core/tpl)
  83. 'tpl' => 0,
  84. // Set this to 1 if module has its own barcode directory (core/modules/barcode)
  85. 'barcode' => 0,
  86. // Set this to 1 if module has its own models directory (core/modules/xxx)
  87. 'models' => 1,
  88. // Set this to 1 if module has its own theme directory (theme)
  89. 'theme' => 0,
  90. // Set this to relative path of css file if module has its own css file
  91. 'css' => array(
  92. // '/stocktransfer/css/stocktransfer.css.php',
  93. ),
  94. // Set this to relative path of js file if module must load a js on all pages
  95. 'js' => array(
  96. // '/stocktransfer/js/stocktransfer.js.php',
  97. ),
  98. // 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'
  99. 'hooks' => array(
  100. // 'data' => array(
  101. // 'hookcontext1',
  102. // 'hookcontext2',
  103. // ),
  104. // 'entity' => '0',
  105. ),
  106. // Set this to 1 if features of module are opened to external users
  107. 'moduleforexternal' => 0,
  108. 'contactelement'=>1
  109. );
  110. // Data directories to create when module is enabled.
  111. // Example: this->dirs = array("/stocktransfer/temp","/stocktransfer/subdir");
  112. $this->dirs = array("/stocktransfer/temp");
  113. // Config pages. Put here list of php page, stored into stocktransfer/admin directory, to use to setup module.
  114. $this->config_page_url = array("stocktransfer.php");
  115. // Dependencies
  116. // A condition to hide module
  117. $this->hidden = false;
  118. // 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'...))
  119. $this->depends = array('modStock', 'modProduct');
  120. $this->requiredby = array(); // List of module class names as string to disable if this one is disabled. Example: array('modModuleToDisable1', ...)
  121. $this->conflictwith = array(); // List of module class names as string this module is in conflict with. Example: array('modModuleToDisable1', ...)
  122. $this->langfiles = array("stocktransfer@stocktransfer");
  123. $this->phpmin = array(7, 0); // Minimum version of PHP required by module
  124. $this->warnings_activation = array(); // Warning to show when we activate module. array('always'='text') or array('FR'='textfr','ES'='textes'...)
  125. $this->warnings_activation_ext = array(); // Warning to show when we activate an external module. array('always'='text') or array('FR'='textfr','ES'='textes'...)
  126. //$this->automatic_activation = array('FR'=>'StockTransferWasAutomaticallyActivatedBecauseOfYourCountryChoice');
  127. //$this->always_enabled = true; // If true, can't be disabled
  128. // Constants
  129. // List of particular constants to add when module is enabled (key, 'chaine', value, desc, visible, 'current' or 'allentities', deleteonunactive)
  130. // Example: $this->const=array(1 => array('STOCKTRANSFER_MYNEWCONST1', 'chaine', 'myvalue', 'This is a constant to add', 1),
  131. // 2 => array('STOCKTRANSFER_MYNEWCONST2', 'chaine', 'myvalue', 'This is another constant to add', 0, 'current', 1)
  132. // );
  133. $this->const = array();
  134. if (!isset($conf->stocktransfer) || !isset($conf->stocktransfer->enabled)) {
  135. $conf->stocktransfer = new stdClass();
  136. $conf->stocktransfer->enabled = 0;
  137. }
  138. // Array to add new pages in new tabs
  139. $this->tabs = array();
  140. // Example:
  141. // $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
  142. // $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.
  143. // $this->tabs[] = array('data'=>'objecttype:-tabname:NU:conditiontoremove'); // To remove an existing tab identified by code tabname
  144. //
  145. // Where objecttype can be
  146. // 'categories_x' to add a tab in category view (replace 'x' by type of category (0=product, 1=supplier, 2=customer, 3=member)
  147. // 'contact' to add a tab in contact view
  148. // 'contract' to add a tab in contract view
  149. // 'group' to add a tab in group view
  150. // 'intervention' to add a tab in intervention view
  151. // 'invoice' to add a tab in customer invoice view
  152. // 'invoice_supplier' to add a tab in supplier invoice view
  153. // 'member' to add a tab in fundation member view
  154. // 'opensurveypoll' to add a tab in opensurvey poll view
  155. // 'order' to add a tab in sales order view
  156. // 'order_supplier' to add a tab in supplier order view
  157. // 'payment' to add a tab in payment view
  158. // 'payment_supplier' to add a tab in supplier payment view
  159. // 'product' to add a tab in product view
  160. // 'propal' to add a tab in propal view
  161. // 'project' to add a tab in project view
  162. // 'stock' to add a tab in stock view
  163. // 'thirdparty' to add a tab in third party view
  164. // 'user' to add a tab in user view
  165. // Dictionaries
  166. $this->dictionaries = array();
  167. /* Example:
  168. $this->dictionaries=array(
  169. 'langs'=>'stocktransfer@stocktransfer',
  170. // List of tables we want to see into dictonnary editor
  171. 'tabname'=>array(MAIN_DB_PREFIX."table1", MAIN_DB_PREFIX."table2", MAIN_DB_PREFIX."table3"),
  172. // Label of tables
  173. 'tablib'=>array("Table1", "Table2", "Table3"),
  174. // Request to select fields
  175. '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'),
  176. // Sort order
  177. 'tabsqlsort'=>array("label ASC", "label ASC", "label ASC"),
  178. // List of fields (result of select to show dictionary)
  179. 'tabfield'=>array("code,label", "code,label", "code,label"),
  180. // List of fields (list of fields to edit a record)
  181. 'tabfieldvalue'=>array("code,label", "code,label", "code,label"),
  182. // List of fields (list of fields for insert)
  183. 'tabfieldinsert'=>array("code,label", "code,label", "code,label"),
  184. // Name of columns with primary key (try to always name it 'rowid')
  185. 'tabrowid'=>array("rowid", "rowid", "rowid"),
  186. // Condition to show each dictionary
  187. 'tabcond'=>array($conf->stocktransfer->enabled, $conf->stocktransfer->enabled, $conf->stocktransfer->enabled)
  188. );
  189. */
  190. // Boxes/Widgets
  191. // Add here list of php file(s) stored in stocktransfer/core/boxes that contains a class to show a widget.
  192. $this->boxes = array(
  193. // 0 => array(
  194. // 'file' => 'stocktransferwidget1.php@stocktransfer',
  195. // 'note' => 'Widget provided by StockTransfer',
  196. // 'enabledbydefaulton' => 'Home',
  197. // ),
  198. // ...
  199. );
  200. // Cronjobs (List of cron jobs entries to add when module is enabled)
  201. // unit_frequency must be 60 for minute, 3600 for hour, 86400 for day, 604800 for week
  202. $this->cronjobs = array(
  203. // 0 => array(
  204. // 'label' => 'MyJob label',
  205. // 'jobtype' => 'method',
  206. // 'class' => '/stocktransfer/class/stocktransfer.class.php',
  207. // 'objectname' => 'StockTransfer',
  208. // 'method' => 'doScheduledJob',
  209. // 'parameters' => '',
  210. // 'comment' => 'Comment',
  211. // 'frequency' => 2,
  212. // 'unitfrequency' => 3600,
  213. // 'status' => 0,
  214. // 'test' => '$conf->stocktransfer->enabled',
  215. // 'priority' => 50,
  216. // ),
  217. );
  218. // Example: $this->cronjobs=array(
  219. // 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),
  220. // 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)
  221. // );
  222. // Permissions provided by this module
  223. $this->rights = array();
  224. $r = 10;
  225. // Add here entries to declare new permissions
  226. /* BEGIN MODULEBUILDER PERMISSIONS */
  227. $this->rights[$r][0] = $this->numero + $r; // Permission id (must not be already used)
  228. $this->rights[$r][1] = $langs->trans('StockTransferRightRead'); // Permission label
  229. $this->rights[$r][4] = 'stocktransfer'; // In php code, permission will be checked by test if ($user->rights->stocktransfer->level1->level2)
  230. $this->rights[$r][5] = 'read'; // In php code, permission will be checked by test if ($user->rights->stocktransfer->level1->level2)
  231. $r++;
  232. $this->rights[$r][0] = $this->numero + $r; // Permission id (must not be already used)
  233. $this->rights[$r][1] = $langs->trans('StockTransferRightCreateUpdate'); // Permission label
  234. $this->rights[$r][4] = 'stocktransfer'; // In php code, permission will be checked by test if ($user->rights->stocktransfer->level1->level2)
  235. $this->rights[$r][5] = 'write'; // In php code, permission will be checked by test if ($user->rights->stocktransfer->level1->level2)
  236. $r++;
  237. $this->rights[$r][0] = $this->numero + $r; // Permission id (must not be already used)
  238. $this->rights[$r][1] = $langs->trans('StockTransferRightDelete'); // Permission label
  239. $this->rights[$r][4] = 'stocktransfer'; // In php code, permission will be checked by test if ($user->rights->stocktransfer->level1->level2)
  240. $this->rights[$r][5] = 'delete'; // In php code, permission will be checked by test if ($user->rights->stocktransfer->level1->level2)
  241. $r++;
  242. /* END MODULEBUILDER PERMISSIONS */
  243. // Main menu entries to add
  244. $langs->load('stocktransfer@stocktransfer');
  245. $this->menu = array();
  246. $r = 0;
  247. // Add here entries to declare new menus
  248. /* BEGIN MODULEBUILDER TOPMENU */
  249. /*$this->menu[$r++] = array(
  250. '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
  251. 'type'=>'top', // This is a Top menu entry
  252. 'titre'=>'ModuleStockTransferName',
  253. 'mainmenu'=>'stocktransfer',
  254. 'leftmenu'=>'',
  255. 'url'=>'/stocktransfer/stocktransferindex.php',
  256. 'langs'=>'stocktransfer@stocktransfer', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
  257. 'position'=>1000 + $r,
  258. '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.
  259. 'perms'=>'1', // Use 'perms'=>'$user->rights->stocktransfer->stocktransfer->read' if you want your menu with a permission rules
  260. 'target'=>'',
  261. 'user'=>2, // 0=Menu for internal users, 1=external users, 2=both
  262. );*/
  263. /* END MODULEBUILDER TOPMENU */
  264. /* BEGIN MODULEBUILDER LEFTMENU STOCKTRANSFER
  265. $this->menu[$r++]=array(
  266. '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
  267. 'type'=>'left', // This is a Top menu entry
  268. 'titre'=>'StockTransfer',
  269. 'mainmenu'=>'stocktransfer',
  270. 'leftmenu'=>'stocktransfer',
  271. 'url'=>'/stocktransfer/stocktransferindex.php',
  272. 'langs'=>'stocktransfer@stocktransfer', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
  273. 'position'=>1000+$r,
  274. '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.
  275. 'perms'=>'$user->rights->stocktransfer->stocktransfer->read', // Use 'perms'=>'$user->rights->stocktransfer->level1->level2' if you want your menu with a permission rules
  276. 'target'=>'',
  277. 'user'=>2, // 0=Menu for internal users, 1=external users, 2=both
  278. );
  279. $this->menu[$r++]=array(
  280. '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
  281. 'type'=>'left', // This is a Left menu entry
  282. 'titre'=>'List StockTransfer',
  283. 'mainmenu'=>'stocktransfer',
  284. 'leftmenu'=>'stocktransfer_stocktransfer_list',
  285. 'url'=>'/stocktransfer/stocktransfer_list.php',
  286. 'langs'=>'stocktransfer@stocktransfer', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
  287. 'position'=>1000+$r,
  288. '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.
  289. 'perms'=>'$user->rights->stocktransfer->stocktransfer->read', // Use 'perms'=>'$user->rights->stocktransfer->level1->level2' if you want your menu with a permission rules
  290. 'target'=>'',
  291. 'user'=>2, // 0=Menu for internal users, 1=external users, 2=both
  292. );
  293. $this->menu[$r++]=array(
  294. '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
  295. 'type'=>'left', // This is a Left menu entry
  296. 'titre'=>'New StockTransfer',
  297. 'mainmenu'=>'stocktransfer',
  298. 'leftmenu'=>'stocktransfer_stocktransfer_new',
  299. 'url'=>'/stocktransfer/stocktransfer_card.php?action=create',
  300. 'langs'=>'stocktransfer@stocktransfer', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
  301. 'position'=>1000+$r,
  302. '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.
  303. 'perms'=>'$user->rights->stocktransfer->stocktransfer->write', // Use 'perms'=>'$user->rights->stocktransfer->level1->level2' if you want your menu with a permission rules
  304. 'target'=>'',
  305. 'user'=>2, // 0=Menu for internal users, 1=external users, 2=both
  306. );
  307. */
  308. /*$this->menu[$r++]=array(
  309. // '' 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
  310. 'fk_menu'=>'fk_mainmenu=products,fk_leftmenu=stock',
  311. // This is a Left menu entry
  312. 'type'=>'left',
  313. 'titre'=>$langs->trans('StockTransferNew'),
  314. 'mainmenu'=>'products',
  315. 'leftmenu'=>'stocktransfer_stocktransfer',
  316. 'url'=>'/stocktransfer/stocktransfer_card.php?action=create',
  317. // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
  318. 'langs'=>'stocktransfer@stocktransfer',
  319. 'position'=>1100+$r,
  320. // 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.
  321. 'enabled'=>'$conf->stocktransfer->enabled',
  322. // Use 'perms'=>'$user->rights->stocktransfer->level1->level2' if you want your menu with a permission rules
  323. 'perms'=>'1',
  324. 'target'=>'',
  325. // 0=Menu for internal users, 1=external users, 2=both
  326. 'user'=>2
  327. );
  328. $this->menu[$r++]=array(
  329. // '' 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
  330. 'fk_menu'=>'fk_mainmenu=products,fk_leftmenu=stock',
  331. // This is a Left menu entry
  332. 'type'=>'left',
  333. 'titre'=>$langs->trans('StockTransferList'),
  334. 'mainmenu'=>'products',
  335. 'leftmenu'=>'stocktransfer_stocktransferlist',
  336. 'url'=>'/stocktransfer/stocktransfer_list.php',
  337. // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
  338. 'langs'=>'stocktransfer@stocktransfer',
  339. 'position'=>1100+$r,
  340. // 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.
  341. 'enabled'=>'$conf->stocktransfer->enabled',
  342. // Use 'perms'=>'$user->rights->stocktransfer->level1->level2' if you want your menu with a permission rules
  343. 'perms'=>'1',
  344. 'target'=>'',
  345. // 0=Menu for internal users, 1=external users, 2=both
  346. 'user'=>2,
  347. );*/
  348. /* END MODULEBUILDER LEFTMENU STOCKTRANSFER */
  349. // Exports profiles provided by this module
  350. $r = 1;
  351. /* BEGIN MODULEBUILDER EXPORT STOCKTRANSFER */
  352. /*
  353. $langs->load("stocktransfer@stocktransfer");
  354. $this->export_code[$r]=$this->rights_class.'_'.$r;
  355. $this->export_label[$r]='StockTransferLines'; // Translation key (used only if key ExportDataset_xxx_z not found)
  356. $this->export_icon[$r]='stocktransfer@stocktransfer';
  357. // Define $this->export_fields_array, $this->export_TypeFields_array and $this->export_entities_array
  358. $keyforclass = 'StockTransfer'; $keyforclassfile='/stocktransfer/class/stocktransfer.class.php'; $keyforelement='stocktransfer@stocktransfer';
  359. include DOL_DOCUMENT_ROOT.'/core/commonfieldsinexport.inc.php';
  360. //$this->export_fields_array[$r]['t.fieldtoadd']='FieldToAdd'; $this->export_TypeFields_array[$r]['t.fieldtoadd']='Text';
  361. //unset($this->export_fields_array[$r]['t.fieldtoremove']);
  362. //$keyforclass = 'StockTransferLine'; $keyforclassfile='/stocktransfer/class/stocktransfer.class.php'; $keyforelement='stocktransferline@stocktransfer'; $keyforalias='tl';
  363. //include DOL_DOCUMENT_ROOT.'/core/commonfieldsinexport.inc.php';
  364. $keyforselect='stocktransfer'; $keyforaliasextra='extra'; $keyforelement='stocktransfer@stocktransfer';
  365. include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
  366. //$keyforselect='stocktransferline'; $keyforaliasextra='extraline'; $keyforelement='stocktransferline@stocktransfer';
  367. //include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
  368. //$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)
  369. //$this->export_special_array[$r] = array('t.field'=>'...');
  370. //$this->export_examplevalues_array[$r] = array('t.field'=>'Example');
  371. //$this->export_help_array[$r] = array('t.field'=>'FieldDescHelp');
  372. $this->export_sql_start[$r]='SELECT DISTINCT ';
  373. $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'stocktransfer as t';
  374. //$this->export_sql_end[$r] =' LEFT JOIN '.MAIN_DB_PREFIX.'stocktransfer_line as tl ON tl.fk_stocktransfer = t.rowid';
  375. $this->export_sql_end[$r] .=' WHERE 1 = 1';
  376. $this->export_sql_end[$r] .=' AND t.entity IN ('.getEntity('stocktransfer').')';
  377. $r++; */
  378. /* END MODULEBUILDER EXPORT STOCKTRANSFER */
  379. // Imports profiles provided by this module
  380. $r = 1;
  381. /* BEGIN MODULEBUILDER IMPORT STOCKTRANSFER */
  382. /*
  383. $langs->load("stocktransfer@stocktransfer");
  384. $this->export_code[$r]=$this->rights_class.'_'.$r;
  385. $this->export_label[$r]='StockTransferLines'; // Translation key (used only if key ExportDataset_xxx_z not found)
  386. $this->export_icon[$r]='stocktransfer@stocktransfer';
  387. $keyforclass = 'StockTransfer'; $keyforclassfile='/stocktransfer/class/stocktransfer.class.php'; $keyforelement='stocktransfer@stocktransfer';
  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. //$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)
  392. $this->export_sql_start[$r]='SELECT DISTINCT ';
  393. $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'stocktransfer as t';
  394. $this->export_sql_end[$r] .=' WHERE 1 = 1';
  395. $this->export_sql_end[$r] .=' AND t.entity IN ('.getEntity('stocktransfer').')';
  396. $r++; */
  397. /* END MODULEBUILDER IMPORT STOCKTRANSFER */
  398. }
  399. /**
  400. * Function called when module is enabled.
  401. * The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
  402. * It also creates data directories
  403. *
  404. * @param string $options Options when enabling module ('', 'noboxes')
  405. * @return int 1 if OK, 0 if KO
  406. */
  407. public function init($options = '')
  408. {
  409. global $conf, $langs;
  410. $result = $this->_load_tables('/install/mysql/tables/', 'stocktransfer');
  411. 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')
  412. // Permissions
  413. $this->remove($options);
  414. $sql = array();
  415. // Rôles
  416. $resql = $this->db->query('SELECT rowid FROM '.MAIN_DB_PREFIX.'c_type_contact WHERE code = "STDEST" AND element = "StockTransfer" AND source = "internal"');
  417. $res = $this->db->fetch_object($resql);
  418. $nextid=$this->getNextId();
  419. 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)');
  420. $resql = $this->db->query('SELECT rowid FROM '.MAIN_DB_PREFIX.'c_type_contact WHERE code = "STFROM" AND element = "StockTransfer" AND source = "external"');
  421. $res = $this->db->fetch_object($resql);
  422. $nextid=$this->getNextId();
  423. 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)');
  424. $resql = $this->db->query('SELECT rowid FROM '.MAIN_DB_PREFIX.'c_type_contact WHERE code = "STDEST" AND element = "StockTransfer" AND source = "external"');
  425. $res = $this->db->fetch_object($resql);
  426. $nextid=$this->getNextId();
  427. 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)');
  428. return $this->_init($sql, $options);
  429. }
  430. /**
  431. * Returns next available id to insert new roles in llx_c_type_contact
  432. * @return int > 0 if OK, < 0 if KO
  433. */
  434. public function getNextId()
  435. {
  436. // Get free id for insert
  437. $newid = 0;
  438. $sql = "SELECT max(rowid) newid from ".MAIN_DB_PREFIX."c_type_contact";
  439. $result = $this->db->query($sql);
  440. if ($result) {
  441. $obj = $this->db->fetch_object($result);
  442. $newid = ($obj->newid + 1);
  443. } else {
  444. dol_print_error($this->db);
  445. return -1;
  446. }
  447. return $newid;
  448. }
  449. /**
  450. * Function called when module is disabled.
  451. * Remove from database constants, boxes and permissions from Dolibarr database.
  452. * Data directories are not deleted
  453. *
  454. * @param string $options Options when enabling module ('', 'noboxes')
  455. * @return int 1 if OK, 0 if KO
  456. */
  457. public function remove($options = '')
  458. {
  459. $sql = array();
  460. return $this->_remove($sql, $options);
  461. }
  462. }