dolibarr  17.0.4
modTakePos.class.php
Go to the documentation of this file.
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 
27 include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
28 
29 
34 {
40  public function __construct($db)
41  {
42  global $langs, $conf;
43 
44  $this->db = $db;
45 
46  // Id for module (must be unique).
47  // Use here a free id (See in Home -> System information -> Dolibarr for list of used modules id).
48  $this->numero = 50150;
49  // Key text used to identify module (for permissions, menus, etc...)
50  $this->rights_class = 'takepos';
51 
52  // Family can be 'crm','financial','hr','projects','products','ecm','technic','interface','other'
53  // It is used to group modules by family in module setup page
54  $this->family = "portal";
55  // Module position in the family on 2 digits ('01', '10', '20', ...)
56  $this->module_position = '60';
57  // 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)
58  //$this->familyinfo = array('myownfamily' => array('position' => '01', 'label' => $langs->trans("MyOwnFamily")));
59 
60  // Module label (no space allowed), used if translation string 'ModuleTakePosName' not found (MyModue is name of module).
61  $this->name = preg_replace('/^mod/i', '', get_class($this));
62  // Module description, used if translation string 'ModuleTakePosDesc' not found (MyModue is name of module).
63  $this->description = "Point of sales module (Touch Screen POS)";
64  // Used only if file README.md and README-LL.md not found.
65  $this->descriptionlong = "Point Of Sales (compliant with touch screen)";
66 
67  // Possible values for version are: 'development', 'experimental', 'dolibarr', 'dolibarr_deprecated' or a version string like 'x.y.z'
68  $this->version = 'dolibarr';
69  // Key used in llx_const table to save module status enabled/disabled (where TAKEPOS 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 = 'cash-register';
75 
76  // Defined all module parts (triggers, login, substitutions, menus, css, etc...)
77  // for default path (eg: /takepos/core/xxxxx) (0=disable, 1=enable)
78  // for specific path of parts (eg: /takepos/core/modules/barcode)
79  // for specific css file (eg: /takepos/css/takepos.css.php)
80  $this->module_parts = array(
81  'triggers' => 0, // Set this to 1 if module has its own trigger directory (core/triggers)
82  'login' => 0, // Set this to 1 if module has its own login method file (core/login)
83  'substitutions' => 1, // Set this to 1 if module has its own substitution function file (core/substitutions)
84  'menus' => 0, // Set this to 1 if module has its own menus handler directory (core/menus)
85  'theme' => 0, // Set this to 1 if module has its own theme directory (theme)
86  'tpl' => 0, // Set this to 1 if module overwrite template dir (core/tpl)
87  'barcode' => 0, // Set this to 1 if module has its own barcode directory (core/modules/barcode)
88  'models' => 0, // Set this to 1 if module has its own models directory (core/modules/xxx)
89  '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'
90  );
91 
92  // Data directories to create when module is enabled.
93  // Example: this->dirs = array("/takepos/temp","/takepos/subdir");
94  $this->dirs = array();
95 
96  // Config pages. Put here list of php page, stored into takepos/admin directory, to use to setup module.
97  $this->config_page_url = array("setup.php@takepos");
98 
99  // Dependencies
100  $this->hidden = false; // A condition to hide module
101  $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
102  $this->requiredby = array(); // List of module ids to disable if this one is disabled
103  $this->conflictwith = array(); // List of module class names as string this module is in conflict with
104  $this->langfiles = array("cashdesk");
105  $this->phpmin = array(7, 0); // Minimum version of PHP required by module
106  $this->need_dolibarr_version = array(4, 0); // Minimum version of Dolibarr required by module
107  $this->warnings_activation = array('FR'=>'WarningNoteModulePOSForFrenchLaw'); // Warning to show when we activate module. array('always'='text') or array('FR'='text')
108  $this->warnings_activation_ext = array(); // Warning to show when we activate an external module. array('always'='text') or array('FR'='textfr','ES'='textes'...)
109  //$this->automatic_activation = array('FR'=>'TakePosWasAutomaticallyActivatedBecauseOfYourCountryChoice');
110  //$this->always_enabled = true; // If true, can't be disabled
111 
112  // Constants
113  // List of particular constants to add when module is enabled (key, 'chaine', value, desc, visible, 'current' or 'allentities', deleteonunactive)
114  // Example: $this->const=array(0=>array('TAKEPOS_MYNEWCONST1','chaine','myvalue','This is a constant to add',1),
115  // 1=>array('TAKEPOS_MYNEWCONST2','chaine','myvalue','This is another constant to add',0, 'current', 1)
116  // );
117  $this->const = array(
118  //1=>array('TAKEPOS_MYCONSTANT', 'chaine', 'avalue', 'This is a constant to add', 1, 'allentities', 1)
119  );
120 
121 
122  if (!isset($conf->takepos) || !isset($conf->takepos->enabled)) {
123  $conf->takepos = new stdClass();
124  $conf->takepos->enabled = 0;
125  }
126 
127 
128  // Array to add new pages in new tabs
129  $this->tabs = array();
130  // Example:
131  // $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
132  // $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.
133  // $this->tabs[] = array('data'=>'objecttype:-tabname:NU:conditiontoremove'); // To remove an existing tab identified by code tabname
134  //
135  // Where objecttype can be
136  // 'categories_x' to add a tab in category view (replace 'x' by type of category (0=product, 1=supplier, 2=customer, 3=member)
137  // 'contact' to add a tab in contact view
138  // 'contract' to add a tab in contract view
139  // 'group' to add a tab in group view
140  // 'intervention' to add a tab in intervention view
141  // 'invoice' to add a tab in customer invoice view
142  // 'invoice_supplier' to add a tab in supplier invoice view
143  // 'member' to add a tab in fundation member view
144  // 'opensurveypoll' to add a tab in opensurvey poll view
145  // 'order' to add a tab in sales order view
146  // 'order_supplier' to add a tab in supplier order view
147  // 'payment' to add a tab in payment view
148  // 'payment_supplier' to add a tab in supplier payment view
149  // 'product' to add a tab in product view
150  // 'propal' to add a tab in propal view
151  // 'project' to add a tab in project view
152  // 'stock' to add a tab in stock view
153  // 'thirdparty' to add a tab in third party view
154  // 'user' to add a tab in user view
155 
156 
157  // Dictionaries
158  $this->dictionaries = array();
159 
160 
161  // Boxes/Widgets
162  // Add here list of php file(s) stored in takepos/core/boxes that contains class to show a widget.
163  $this->boxes = array(
164  //0=>array('file'=>'takeposwidget1.php@takepos','note'=>'Widget provided by TakePos','enabledbydefaulton'=>'Home'),
165  //1=>array('file'=>'takeposwidget2.php@takepos','note'=>'Widget provided by TakePos'),
166  //2=>array('file'=>'takeposwidget3.php@takepos','note'=>'Widget provided by TakePos')
167  );
168 
169 
170  // Cronjobs (List of cron jobs entries to add when module is enabled)
171  // unit_frequency must be 60 for minute, 3600 for hour, 86400 for day, 604800 for week
172  $this->cronjobs = array(
173  //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)
174  );
175  // 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),
176  // 1=>array('label'=>'My label', 'jobtype'=>'command', 'command'=>'', 'parameters'=>'param1, param2', 'comment'=>'Comment', 'frequency'=>1, 'unitfrequency'=>3600*24, 'status'=>0, 'test'=>true)
177  // );
178 
179 
180  // Permissions
181  $this->rights = array(); // Permission array used by this module
182 
183  $r = 0;
184 
185  $r++;
186  $this->rights[$r][0] = 50151;
187  $this->rights[$r][1] = 'Use Point Of Sale (record a sale, add products, record payment)';
188  $this->rights[$r][2] = 'a';
189  $this->rights[$r][3] = 0;
190  $this->rights[$r][4] = 'run';
191 
192  $r++;
193  $this->rights[$r][0] = 50152;
194  $this->rights[$r][1] = 'Can modify added sales lines (prices, discount)';
195  $this->rights[$r][2] = 'a';
196  $this->rights[$r][3] = 0;
197  $this->rights[$r][4] = 'editlines';
198 
199  $r++;
200  $this->rights[$r][0] = 50153;
201  $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';
202  $this->rights[$r][2] = 'a';
203  $this->rights[$r][3] = 0;
204  $this->rights[$r][4] = 'editorderedlines';
205 
206 
207  // Main menu entries
208  $this->menu = array(); // List of menus to add
209  $r = 0;
210 
211  // Add here entries to declare new menus
212 
213  /* BEGIN MODULEBUILDER TOPMENU */
214  $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
215  'type'=>'top', // This is a Top menu entry
216  'titre'=>'PointOfSaleShort',
217  'mainmenu'=>'takepos',
218  'leftmenu'=>'',
219  'prefix' => img_picto('', $this->picto, 'class="paddingright pictofixedwidth"'),
220  'url'=>'/takepos/index.php',
221  'langs'=>'cashdesk', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
222  'position'=>1000 + $r,
223  '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.
224  'perms'=>'$user->rights->takepos->run', // Use 'perms'=>'$user->rights->takepos->level1->level2' if you want your menu with a permission rules
225  'target'=>'takepos',
226  'user'=>2); // 0=Menu for internal users, 1=external users, 2=both
227 
228  /* END MODULEBUILDER TOPMENU */
229 
230  /* BEGIN MODULEBUILDER LEFTMENU MYOBJECT
231  $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
232  'type'=>'left', // This is a Left menu entry
233  'titre'=>'List MyObject',
234  'mainmenu'=>'takepos',
235  'leftmenu'=>'takepos_myobject_list',
236  'url'=>'/takepos/myobject_list.php',
237  'langs'=>'cashdesk', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
238  'position'=>1000+$r,
239  '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.
240  'perms'=>'1', // Use 'perms'=>'$user->rights->takepos->level1->level2' if you want your menu with a permission rules
241  'target'=>'',
242  'user'=>2); // 0=Menu for internal users, 1=external users, 2=both
243  $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
244  'type'=>'left', // This is a Left menu entry
245  'titre'=>'New MyObject',
246  'mainmenu'=>'takepos',
247  'leftmenu'=>'takepos_myobject_new',
248  'url'=>'/takepos/myobject_page.php?action=create',
249  'langs'=>'cashdesk', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
250  'position'=>1000+$r,
251  '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.
252  'perms'=>'1', // Use 'perms'=>'$user->rights->takepos->level1->level2' if you want your menu with a permission rules
253  'target'=>'',
254  'user'=>2); // 0=Menu for internal users, 1=external users, 2=both
255  END MODULEBUILDER LEFTMENU MYOBJECT */
256  }
257 
266  public function init($options = '')
267  {
268  global $conf, $db;
269 
270  dolibarr_set_const($db, "TAKEPOS_PRINT_METHOD", "browser", 'chaine', 0, '', $conf->entity);
271 
272  $sql = array();
273 
274  // Remove permissions and default values
275  $this->remove($options);
276 
277  return $this->_init($sql, $options);
278  }
279 
288  public function remove($options = '')
289  {
290  $sql = array();
291 
292  return $this->_remove($sql, $options);
293  }
294 }
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
Definition: admin.lib.php:632
Class DolibarrModules.
_init($array_sql, $options='')
Enables a module.
_remove($array_sql, $options='')
Disable function.
Class to describe and enable module TakePos.
init($options='')
Function called when module is enabled.
__construct($db)
Constructor.
print *****$script_file(".$version.") pid cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:122
$conf db
API class for accounts.
Definition: inc.php:41