PageRenderTime 48ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/core/modules/modTakePos.class.php

http://github.com/Dolibarr/dolibarr
PHP | 310 lines | 103 code | 43 blank | 164 comment | 2 complexity | 87b5b37e97a6f075c8d57529cab6262c MD5 | raw file
Possible License(s): GPL-2.0, AGPL-3.0, LGPL-2.0, CC-BY-SA-4.0, BSD-3-Clause, MPL-2.0-no-copyleft-exception, LGPL-3.0, GPL-3.0, LGPL-2.1, MIT
  1. <?php
  2. /* Copyright (C) 2004-2018 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2018 SuperAdmin
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \defgroup takepos Module TakePos
  20. * \brief TakePos module descriptor.
  21. *
  22. * \file htdocs/core/modules/modTakePos.class.php
  23. * \ingroup takepos
  24. * \brief Description and activation file for the module TakePos
  25. */
  26. include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
  27. /**
  28. * Class to describe and enable module TakePos
  29. */
  30. class modTakePos extends DolibarrModules
  31. {
  32. /**
  33. * Constructor. Define names, constants, directories, boxes, permissions
  34. *
  35. * @param DoliDB $db Database handler
  36. */
  37. public function __construct($db)
  38. {
  39. global $langs, $conf;
  40. $this->db = $db;
  41. // Id for module (must be unique).
  42. // Use here a free id (See in Home -> System information -> Dolibarr for list of used modules id).
  43. $this->numero = 50150;
  44. // Key text used to identify module (for permissions, menus, etc...)
  45. $this->rights_class = 'takepos';
  46. // Family can be 'crm','financial','hr','projects','products','ecm','technic','interface','other'
  47. // It is used to group modules by family in module setup page
  48. $this->family = "portal";
  49. // Module position in the family on 2 digits ('01', '10', '20', ...)
  50. $this->module_position = '60';
  51. // Gives the possibility to the module, to provide his own family info and position of this family (Overwrite $this->family and $this->module_position. Avoid this)
  52. //$this->familyinfo = array('myownfamily' => array('position' => '01', 'label' => $langs->trans("MyOwnFamily")));
  53. // Module label (no space allowed), used if translation string 'ModuleTakePosName' not found (MyModue is name of module).
  54. $this->name = preg_replace('/^mod/i', '', get_class($this));
  55. // Module description, used if translation string 'ModuleTakePosDesc' not found (MyModue is name of module).
  56. $this->description = "Point of sales module (Touch Screen POS)";
  57. // Used only if file README.md and README-LL.md not found.
  58. $this->descriptionlong = "Point Of Sales (compliant with touch screen)";
  59. // Possible values for version are: 'development', 'experimental', 'dolibarr', 'dolibarr_deprecated' or a version string like 'x.y.z'
  60. $this->version = 'dolibarr';
  61. // Key used in llx_const table to save module status enabled/disabled (where TAKEPOS is value of property name of module in uppercase)
  62. $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
  63. // Name of image file used for this module.
  64. // If file is in theme/yourtheme/img directory under name object_pictovalue.png, use this->picto='pictovalue'
  65. // If file is in module/img directory under name object_pictovalue.png, use this->picto='pictovalue@module'
  66. $this->picto = 'cash-register';
  67. // Defined all module parts (triggers, login, substitutions, menus, css, etc...)
  68. // for default path (eg: /takepos/core/xxxxx) (0=disable, 1=enable)
  69. // for specific path of parts (eg: /takepos/core/modules/barcode)
  70. // for specific css file (eg: /takepos/css/takepos.css.php)
  71. $this->module_parts = array(
  72. 'triggers' => 0, // Set this to 1 if module has its own trigger directory (core/triggers)
  73. 'login' => 0, // Set this to 1 if module has its own login method file (core/login)
  74. 'substitutions' => 1, // Set this to 1 if module has its own substitution function file (core/substitutions)
  75. 'menus' => 0, // Set this to 1 if module has its own menus handler directory (core/menus)
  76. 'theme' => 0, // Set this to 1 if module has its own theme directory (theme)
  77. 'tpl' => 0, // Set this to 1 if module overwrite template dir (core/tpl)
  78. 'barcode' => 0, // Set this to 1 if module has its own barcode directory (core/modules/barcode)
  79. 'models' => 0, // Set this to 1 if module has its own models directory (core/modules/xxx)
  80. 'hooks' => array() // 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 'all'
  81. );
  82. // Data directories to create when module is enabled.
  83. // Example: this->dirs = array("/takepos/temp","/takepos/subdir");
  84. $this->dirs = array();
  85. // Config pages. Put here list of php page, stored into takepos/admin directory, to use to setup module.
  86. $this->config_page_url = array("setup.php@takepos");
  87. // Dependencies
  88. $this->hidden = false; // A condition to hide module
  89. $this->depends = array('always1'=>"modBanque", 'always2'=>"modFacture", 'always3'=>"modProduct", 'always4'=>'modCategorie', 'FR1'=>'modBlockedLog'); // List of module class names as string that must be enabled if this module is enabled
  90. $this->requiredby = array(); // List of module ids to disable if this one is disabled
  91. $this->conflictwith = array(); // List of module class names as string this module is in conflict with
  92. $this->langfiles = array("cashdesk");
  93. $this->phpmin = array(5, 6); // Minimum version of PHP required by module
  94. $this->need_dolibarr_version = array(4, 0); // Minimum version of Dolibarr required by module
  95. $this->warnings_activation = array('FR'=>'WarningNoteModulePOSForFrenchLaw'); // Warning to show when we activate module. array('always'='text') or array('FR'='text')
  96. $this->warnings_activation_ext = array(); // Warning to show when we activate an external module. array('always'='text') or array('FR'='textfr','ES'='textes'...)
  97. //$this->automatic_activation = array('FR'=>'TakePosWasAutomaticallyActivatedBecauseOfYourCountryChoice');
  98. //$this->always_enabled = true; // If true, can't be disabled
  99. // Constants
  100. // List of particular constants to add when module is enabled (key, 'chaine', value, desc, visible, 'current' or 'allentities', deleteonunactive)
  101. // Example: $this->const=array(0=>array('TAKEPOS_MYNEWCONST1','chaine','myvalue','This is a constant to add',1),
  102. // 1=>array('TAKEPOS_MYNEWCONST2','chaine','myvalue','This is another constant to add',0, 'current', 1)
  103. // );
  104. $this->const = array(
  105. //1=>array('TAKEPOS_MYCONSTANT', 'chaine', 'avalue', 'This is a constant to add', 1, 'allentities', 1)
  106. );
  107. if (!isset($conf->takepos) || !isset($conf->takepos->enabled)) {
  108. $conf->takepos = new stdClass();
  109. $conf->takepos->enabled = 0;
  110. }
  111. // Array to add new pages in new tabs
  112. $this->tabs = array();
  113. // Example:
  114. // $this->tabs[] = array('data'=>'objecttype:+tabname1:Title1:mylangfile@takepos:$user->rights->takepos->read:/takepos/mynewtab1.php?id=__ID__'); // To add a new tab identified by code tabname1
  115. // $this->tabs[] = array('data'=>'objecttype:+tabname2:SUBSTITUTION_Title2:mylangfile@takepos:$user->rights->othermodule->read:/takepos/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.
  116. // $this->tabs[] = array('data'=>'objecttype:-tabname:NU:conditiontoremove'); // To remove an existing tab identified by code tabname
  117. //
  118. // Where objecttype can be
  119. // 'categories_x' to add a tab in category view (replace 'x' by type of category (0=product, 1=supplier, 2=customer, 3=member)
  120. // 'contact' to add a tab in contact view
  121. // 'contract' to add a tab in contract view
  122. // 'group' to add a tab in group view
  123. // 'intervention' to add a tab in intervention view
  124. // 'invoice' to add a tab in customer invoice view
  125. // 'invoice_supplier' to add a tab in supplier invoice view
  126. // 'member' to add a tab in fundation member view
  127. // 'opensurveypoll' to add a tab in opensurvey poll view
  128. // 'order' to add a tab in customer order view
  129. // 'order_supplier' to add a tab in supplier order view
  130. // 'payment' to add a tab in payment view
  131. // 'payment_supplier' to add a tab in supplier payment view
  132. // 'product' to add a tab in product view
  133. // 'propal' to add a tab in propal view
  134. // 'project' to add a tab in project view
  135. // 'stock' to add a tab in stock view
  136. // 'thirdparty' to add a tab in third party view
  137. // 'user' to add a tab in user view
  138. // Dictionaries
  139. $this->dictionaries = array();
  140. /* Example:
  141. $this->dictionaries=array(
  142. 'langs'=>'mylangfile@takepos',
  143. 'tabname'=>array(MAIN_DB_PREFIX."table1",MAIN_DB_PREFIX."table2",MAIN_DB_PREFIX."table3"), // List of tables we want to see into dictonnary editor
  144. 'tablib'=>array("Table1","Table2","Table3"), // Label of tables
  145. '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'), // Request to select fields
  146. 'tabsqlsort'=>array("label ASC","label ASC","label ASC"), // Sort order
  147. 'tabfield'=>array("code,label","code,label","code,label"), // List of fields (result of select to show dictionary)
  148. 'tabfieldvalue'=>array("code,label","code,label","code,label"), // List of fields (list of fields to edit a record)
  149. 'tabfieldinsert'=>array("code,label","code,label","code,label"), // List of fields (list of fields for insert)
  150. 'tabrowid'=>array("rowid","rowid","rowid"), // Name of columns with primary key (try to always name it 'rowid')
  151. 'tabcond'=>array($conf->takepos->enabled,$conf->takepos->enabled,$conf->takepos->enabled) // Condition to show each dictionary
  152. );
  153. */
  154. // Boxes/Widgets
  155. // Add here list of php file(s) stored in takepos/core/boxes that contains class to show a widget.
  156. $this->boxes = array(
  157. //0=>array('file'=>'takeposwidget1.php@takepos','note'=>'Widget provided by TakePos','enabledbydefaulton'=>'Home'),
  158. //1=>array('file'=>'takeposwidget2.php@takepos','note'=>'Widget provided by TakePos'),
  159. //2=>array('file'=>'takeposwidget3.php@takepos','note'=>'Widget provided by TakePos')
  160. );
  161. // Cronjobs (List of cron jobs entries to add when module is enabled)
  162. // unit_frequency must be 60 for minute, 3600 for hour, 86400 for day, 604800 for week
  163. $this->cronjobs = array(
  164. //0=>array('label'=>'MyJob label', 'jobtype'=>'method', 'class'=>'/takepos/class/myobject.class.php', 'objectname'=>'MyObject', 'method'=>'doScheduledJob', 'parameters'=>'', 'comment'=>'Comment', 'frequency'=>2, 'unitfrequency'=>3600, 'status'=>0, 'test'=>true)
  165. );
  166. // Example: $this->cronjobs=array(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'=>true),
  167. // 1=>array('label'=>'My label', 'jobtype'=>'command', 'command'=>'', 'parameters'=>'param1, param2', 'comment'=>'Comment', 'frequency'=>1, 'unitfrequency'=>3600*24, 'status'=>0, 'test'=>true)
  168. // );
  169. // Permissions
  170. $this->rights = array(); // Permission array used by this module
  171. $r = 0;
  172. $r++;
  173. $this->rights[$r][0] = 50151;
  174. $this->rights[$r][1] = 'Use Point Of Sale (record a sale, add products, record payment)';
  175. $this->rights[$r][2] = 'a';
  176. $this->rights[$r][3] = 0;
  177. $this->rights[$r][4] = 'run';
  178. $r++;
  179. $this->rights[$r][0] = 50152;
  180. $this->rights[$r][1] = 'Can modify added sales lines (prices, discount)';
  181. $this->rights[$r][2] = 'a';
  182. $this->rights[$r][3] = 0;
  183. $this->rights[$r][4] = 'editlines';
  184. $r++;
  185. $this->rights[$r][0] = 50153;
  186. $this->rights[$r][1] = 'Edit ordered sales lines (useful only when option "Order printers" has been enabled). Allow to edit sales lines even after the order has been printed';
  187. $this->rights[$r][2] = 'a';
  188. $this->rights[$r][3] = 0;
  189. $this->rights[$r][4] = 'editorderedlines';
  190. // Main menu entries
  191. $this->menu = array(); // List of menus to add
  192. $r = 0;
  193. // Add here entries to declare new menus
  194. /* BEGIN MODULEBUILDER TOPMENU */
  195. $this->menu[$r++] = array('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
  196. 'type'=>'top', // This is a Top menu entry
  197. 'titre'=>'PointOfSaleShort',
  198. 'mainmenu'=>'takepos',
  199. 'leftmenu'=>'',
  200. 'prefix' => img_picto('', $this->picto, 'class="paddingright pictofixedwidth"'),
  201. 'url'=>'/takepos/index.php',
  202. 'langs'=>'cashdesk', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
  203. 'position'=>1000 + $r,
  204. 'enabled'=>'$conf->takepos->enabled', // Define condition to show or hide menu entry. Use '$conf->takepos->enabled' if entry must be visible if module is enabled.
  205. 'perms'=>'$user->rights->takepos->run', // Use 'perms'=>'$user->rights->takepos->level1->level2' if you want your menu with a permission rules
  206. 'target'=>'takepos',
  207. 'user'=>2); // 0=Menu for internal users, 1=external users, 2=both
  208. /* END MODULEBUILDER TOPMENU */
  209. /* BEGIN MODULEBUILDER LEFTMENU MYOBJECT
  210. $this->menu[$r++]=array( 'fk_menu'=>'fk_mainmenu=takepos', // '' 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
  211. 'type'=>'left', // This is a Left menu entry
  212. 'titre'=>'List MyObject',
  213. 'mainmenu'=>'takepos',
  214. 'leftmenu'=>'takepos_myobject_list',
  215. 'url'=>'/takepos/myobject_list.php',
  216. 'langs'=>'cashdesk', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
  217. 'position'=>1000+$r,
  218. 'enabled'=>'$conf->takepos->enabled', // Define condition to show or hide menu entry. Use '$conf->takepos->enabled' if entry must be visible if module is enabled. Use '$leftmenu==\'system\'' to show if leftmenu system is selected.
  219. 'perms'=>'1', // Use 'perms'=>'$user->rights->takepos->level1->level2' if you want your menu with a permission rules
  220. 'target'=>'',
  221. 'user'=>2); // 0=Menu for internal users, 1=external users, 2=both
  222. $this->menu[$r++]=array( 'fk_menu'=>'fk_mainmenu=takepos,fk_leftmenu=takepos', // '' 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
  223. 'type'=>'left', // This is a Left menu entry
  224. 'titre'=>'New MyObject',
  225. 'mainmenu'=>'takepos',
  226. 'leftmenu'=>'takepos_myobject_new',
  227. 'url'=>'/takepos/myobject_page.php?action=create',
  228. 'langs'=>'cashdesk', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
  229. 'position'=>1000+$r,
  230. 'enabled'=>'$conf->takepos->enabled', // Define condition to show or hide menu entry. Use '$conf->takepos->enabled' if entry must be visible if module is enabled. Use '$leftmenu==\'system\'' to show if leftmenu system is selected.
  231. 'perms'=>'1', // Use 'perms'=>'$user->rights->takepos->level1->level2' if you want your menu with a permission rules
  232. 'target'=>'',
  233. 'user'=>2); // 0=Menu for internal users, 1=external users, 2=both
  234. END MODULEBUILDER LEFTMENU MYOBJECT */
  235. }
  236. /**
  237. * Function called when module is enabled.
  238. * The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
  239. * It also creates data directories
  240. *
  241. * @param string $options Options when enabling module ('', 'noboxes')
  242. * @return int 1 if OK, 0 if KO
  243. */
  244. public function init($options = '')
  245. {
  246. global $conf, $db;
  247. dolibarr_set_const($db, "TAKEPOS_PRINT_METHOD", "browser", 'chaine', 0, '', $conf->entity);
  248. $this->_load_tables('/takepos/sql/');
  249. $sql = array();
  250. // Remove permissions and default values
  251. $this->remove($options);
  252. return $this->_init($sql, $options);
  253. }
  254. /**
  255. * Function called when module is disabled.
  256. * Remove from database constants, boxes and permissions from Dolibarr database.
  257. * Data directories are not deleted
  258. *
  259. * @param string $options Options when enabling module ('', 'noboxes')
  260. * @return int 1 if OK, 0 if KO
  261. */
  262. public function remove($options = '')
  263. {
  264. $sql = array();
  265. return $this->_remove($sql, $options);
  266. }
  267. }