modStockTransfer.class.php 30 KB

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