dolibarr 24.0.0-beta
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 * Copyright (C) 2024-2026 Frédéric France <frederic.france@free.fr>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
28include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
29include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
30
31
36{
42 public function __construct($db)
43 {
44 global $conf;
45
46 $this->db = $db;
47
48 // Id for module (must be unique).
49 // Use here a free id (See in Home -> System information -> Dolibarr for list of used modules id).
50 $this->numero = 50150;
51 // Key text used to identify module (for permissions, menus, etc...)
52 $this->rights_class = 'takepos';
53
54 // Family can be 'crm','financial','hr','projects','products','ecm','technic','interface','other'
55 // It is used to group modules by family in module setup page
56 $this->family = "portal";
57 // Module position in the family on 2 digits ('01', '10', '20', ...)
58 $this->module_position = '45';
59 // 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)
60 //$this->familyinfo = array('myownfamily' => array('position' => '01', 'label' => $langs->trans("MyOwnFamily")));
61
62 // Module label (no space allowed), used if translation string 'ModuleTakePosName' not found (MyModue is name of module).
63 $this->name = preg_replace('/^mod/i', '', get_class($this));
64 // Module description, used if translation string 'ModuleTakePosDesc' not found (MyModue is name of module).
65 $this->description = "Point of sales module (Touch Screen POS)";
66 // Used only if file README.md and README-LL.md not found.
67 $this->descriptionlong = "Point Of Sales (compliant with touch screen)";
68
69 // Possible values for version are: 'development', 'experimental', 'dolibarr', 'dolibarr_deprecated' or a version string like 'x.y.z'
70 $this->version = 'dolibarr';
71 // Key used in llx_const table to save module status enabled/disabled (where TAKEPOS is value of property name of module in uppercase)
72 $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
73 // Name of image file used for this module.
74 // If file is in theme/yourtheme/img directory under name object_pictovalue.png, use this->picto='pictovalue'
75 // If file is in module/img directory under name object_pictovalue.png, use this->picto='pictovalue@module'
76 $this->picto = 'cash-register';
77
78 // Defined all module parts (triggers, login, substitutions, menus, css, etc...)
79 // for default path (eg: /takepos/core/xxxxx) (0=disable, 1=enable)
80 // for specific path of parts (eg: /takepos/core/modules/barcode)
81 // for specific css file (eg: /takepos/css/takepos.css.php)
82 $this->module_parts = array(
83 'triggers' => 0, // Set this to 1 if module has its own trigger directory (core/triggers)
84 'login' => 0, // Set this to 1 if module has its own login method file (core/login)
85 'substitutions' => 1, // Set this to 1 if module has its own substitution function file (core/substitutions)
86 'menus' => 0, // Set this to 1 if module has its own menus handler directory (core/menus)
87 'theme' => 0, // Set this to 1 if module has its own theme directory (theme)
88 'tpl' => 0, // Set this to 1 if module overwrite template dir (core/tpl)
89 'barcode' => 0, // Set this to 1 if module has its own barcode directory (core/modules/barcode)
90 'models' => 0, // Set this to 1 if module has its own models directory (core/modules/xxx)
91 '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'
92 );
93
94 // Data directories to create when module is enabled.
95 // Example: this->dirs = array("/takepos/temp","/takepos/subdir");
96 $this->dirs = array();
97
98 // Config pages. Put here list of php page, stored into takepos/admin directory, to use to setup module.
99 $this->config_page_url = array("setup.php@takepos");
100
101 // Dependencies
102 $this->hidden = false; // A condition to hide module
103 // 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'...))
104 $this->depends = array('always'=>array("modBanque", "modFacture", "modProduct", "modCategorie"), 'FR'=>array('modBlockedLog'));
105 $this->requiredby = array(); // List of module ids to disable if this one is disabled
106 $this->conflictwith = array(); // List of module class names as string this module is in conflict with
107 $this->langfiles = array("cashdesk");
108 $this->phpmin = array(7, 0); // Minimum version of PHP required by module
109 $this->need_dolibarr_version = array(4, 0); // Minimum version of Dolibarr required by module
110 $this->warnings_activation = array('FR' => array('WarningNoteModulePOSForFrenchLaw', 'WarningNoteModulePOSForFrenchLaw2', 'WarningNoteModulePOSForFrenchLaw3')); // Warning to show when we activate module. array('always' => 'text') or array('FR' => array('text1', 'text2))
111 $this->warnings_activation_ext = array();
112 //$this->automatic_activation = array('FR'=>'TakePosWasAutomaticallyActivatedBecauseOfYourCountryChoice');
113
114 // Constants
115 // List of particular constants to add when module is enabled (key, 'chaine', value, desc, visible, 'current' or 'allentities', deleteonunactive)
116 // Example: $this->const=array(0=>array('TAKEPOS_MYNEWCONST1','chaine','myvalue','This is a constant to add',1),
117 // 1=>array('TAKEPOS_MYNEWCONST2','chaine','myvalue','This is another constant to add',0, 'current', 1)
118 // );
119 $this->const = array(
120 //1=>array('TAKEPOS_MYCONSTANT', 'chaine', 'avalue', 'This is a constant to add', 1, 'allentities', 1)
121 );
122
123 // To avoid warning
124 if (!isModEnabled('takepos')) {
125 $conf->takepos = new stdClass();
126 $conf->takepos->enabled = 0;
127 }
128
129
130 // Array to add new pages in new tabs
131 $this->tabs = array();
132 // Example:
133 // $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
134 // $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.
135 // $this->tabs[] = array('data'=>'objecttype:-tabname:NU:conditiontoremove'); // To remove an existing tab identified by code tabname
136 //
137 // Where objecttype can be
138 // 'categories_x' to add a tab in category view (replace 'x' by type of category (0=product, 1=supplier, 2=customer, 3=member)
139 // 'contact' to add a tab in contact view
140 // 'contract' to add a tab in contract view
141 // 'group' to add a tab in group view
142 // 'intervention' to add a tab in intervention view
143 // 'invoice' to add a tab in customer invoice view
144 // 'invoice_supplier' to add a tab in supplier invoice view
145 // 'member' to add a tab in foundation member view
146 // 'opensurveypoll' to add a tab in opensurvey poll view
147 // 'order' to add a tab in sales order view
148 // 'order_supplier' to add a tab in supplier order view
149 // 'payment' to add a tab in payment view
150 // 'payment_supplier' to add a tab in supplier payment view
151 // 'product' to add a tab in product view
152 // 'propal' to add a tab in propal view
153 // 'project' to add a tab in project view
154 // 'stock' to add a tab in stock view
155 // 'thirdparty' to add a tab in third party view
156 // 'user' to add a tab in user view
157
158
159 // Dictionaries
160 $this->dictionaries = array();
161
162
163 // Boxes/Widgets
164 // Add here list of php file(s) stored in takepos/core/boxes that contains class to show a widget.
165 $this->boxes = array(
166 //0=>array('file'=>'takeposwidget1.php@takepos','note'=>'Widget provided by TakePos','enabledbydefaulton'=>'Home'),
167 //1=>array('file'=>'takeposwidget2.php@takepos','note'=>'Widget provided by TakePos'),
168 //2=>array('file'=>'takeposwidget3.php@takepos','note'=>'Widget provided by TakePos')
169 );
170
171
172 // Cronjobs (List of cron jobs entries to add when module is enabled)
173 // unit_frequency must be 60 for minute, 3600 for hour, 86400 for day, 604800 for week
174 $this->cronjobs = array(
175 //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)
176 );
177 // 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),
178 // 1=>array('label'=>'My label', 'jobtype'=>'command', 'command'=>'', 'parameters'=>'param1, param2', 'comment'=>'Comment', 'frequency'=>1, 'unitfrequency'=>3600*24, 'status'=>0, 'test'=>true)
179 // );
180
181
182 // Permissions
183 $this->rights = array(); // Permission array used by this module
184
185 $r = 0;
186
187 $r++;
188 $this->rights[$r][0] = 50151;
189 $this->rights[$r][1] = 'Use Point Of Sale (record a sale, add products, record payment)';
190 $this->rights[$r][2] = 'a';
191 $this->rights[$r][3] = 0;
192 $this->rights[$r][4] = 'run';
193
194 $r++;
195 $this->rights[$r][0] = 50152;
196 $this->rights[$r][1] = 'Can modify added sales lines (prices, discount)';
197 $this->rights[$r][2] = 'a';
198 $this->rights[$r][3] = 0;
199 $this->rights[$r][4] = 'editlines';
200
201 $r++;
202 $this->rights[$r][0] = 50153;
203 $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';
204 $this->rights[$r][2] = 'a';
205 $this->rights[$r][3] = 0;
206 $this->rights[$r][4] = 'editorderedlines';
207
208 // Main menu entries
209 $this->menu = array(); // List of menus to add
210 $r = 0;
211
212 // Add here entries to declare new menus
213
214 /* BEGIN MODULEBUILDER TOPMENU */
215 $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
216 'type'=>'top', // This is a Top menu entry
217 'titre'=>'PointOfSaleShort',
218 'mainmenu'=>'takepos',
219 'leftmenu'=>'',
220 'prefix' => img_picto('', $this->picto, 'class="pictofixedwidth"'),
221 'url'=>'/takepos/index.php',
222 'langs'=>'cashdesk', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
223 'position'=>1000 + $r,
224 'enabled'=>'isModEnabled("takepos")', // Define condition to show or hide menu entry. Use '$conf->takepos->enabled' if entry must be visible if module is enabled.
225 'perms'=>'$user->hasRight("takepos", "run")', // Use 'perms'=>'$user->rights->takepos->level1->level2' if you want your menu with a permission rules
226 'target'=>'takepos',
227 'user'=>2); // 0=Menu for internal users, 1=external users, 2=both
228
229 /* END MODULEBUILDER TOPMENU */
230
231 /* BEGIN MODULEBUILDER LEFTMENU MYOBJECT
232 $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
233 'type'=>'left', // This is a Left menu entry
234 'titre'=>'List MyObject',
235 'mainmenu'=>'takepos',
236 'leftmenu'=>'takepos_myobject_list',
237 'url'=>'/takepos/myobject_list.php',
238 'langs'=>'cashdesk', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
239 'position'=>1000+$r,
240 '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.
241 'perms'=>'1', // Use 'perms'=>'$user->rights->takepos->level1->level2' if you want your menu with a permission rules
242 'target'=>'',
243 'user'=>2); // 0=Menu for internal users, 1=external users, 2=both
244 $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
245 'type'=>'left', // This is a Left menu entry
246 'titre'=>'New MyObject',
247 'mainmenu'=>'takepos',
248 'leftmenu'=>'takepos_myobject_new',
249 'url'=>'/takepos/myobject_page.php?action=create',
250 'langs'=>'cashdesk', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
251 'position'=>1000+$r,
252 '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.
253 'perms'=>'1', // Use 'perms'=>'$user->rights->takepos->level1->level2' if you want your menu with a permission rules
254 'target'=>'',
255 'user'=>2); // 0=Menu for internal users, 1=external users, 2=both
256 END MODULEBUILDER LEFTMENU MYOBJECT */
257 }
258
267 public function init($options = '')
268 {
269 global $conf, $langs, $user, $mysoc;
270
271 $langs->load("cashdesk");
272
273 dolibarr_set_const($this->db, "TAKEPOS_PRINT_METHOD", "browser", 'chaine', 0, '', $conf->entity);
274
275 // Default customer for Point of sale
276 if (!getDolGlobalInt('CASHDESK_ID_THIRDPARTY1')) { // If a customer has already ben set into the TakePos setup page
277 $societe = new Societe($this->db);
278 $nametouse = $langs->trans("DefaultPOSThirdLabel");
279
280 $searchcompanyid = $societe->fetch(0, $nametouse);
281 if ($searchcompanyid == 0) {
282 $societe->name = $nametouse;
283 $societe->client = 1;
284 $societe->code_client = '-1';
285 $societe->code_fournisseur = '-1';
286 $societe->country_id = $mysoc->country_id ? $mysoc->country_id : 1; // By default we consider the default customer is in the same country than the company
287 $societe->note_private = "Default customer automatically created by Point Of Sale module activation. Can be used as the default generic customer in the Point Of Sale setup. Can also be edited or removed if you don't need a generic customer.";
288
289 $searchcompanyid = $societe->create($user);
290 }
291 if ($searchcompanyid > 0) {
292 // We already have or we have create a thirdparty with id = $searchcompanyid, so we link use it into setup
293 dolibarr_set_const($this->db, "CASHDESK_ID_THIRDPARTY1", $searchcompanyid, 'chaine', 0, '', $conf->entity);
294 } else {
295 setEventMessages($societe->error, $societe->errors, 'errors');
296 }
297 }
298
299 // Create product category DefaultPOSCatLabel if not exists
300 $categories = new Categorie($this->db);
301 $cate_arbo = $categories->get_full_arbo('product', 0, 1);
302 if (is_array($cate_arbo)) {
303 if (!count($cate_arbo) || (!getDolGlobalString('TAKEPOS_ROOT_CATEGORY_ID') || getDolGlobalString('TAKEPOS_ROOT_CATEGORY_ID') == '-1')) {
304 $category = new Categorie($this->db);
305
306 $category->label = $langs->trans("DefaultPOSCatLabel");
307 $category->type = Categorie::TYPE_PRODUCT;
308
309 $result = $category->create($user);
310
311 if ($result > 0) {
312 dolibarr_set_const($this->db, 'TAKEPOS_ROOT_CATEGORY_ID', $result, 'chaine', 0, 'Id of category for products visible in TakePOS', $conf->entity);
313
314 /* TODO Create a generic product only if there is no product yet. If 0 product, we create 1. If there is already product, it is better to show a message to ask to add product in the category */
315 /*
316 $product = new Product($this->db);
317 $product->status = 1;
318 $product->ref = "takepos";
319 $product->label = $langs->trans("DefaultPOSProductLabel");
320 $product->create($user);
321 $product->setCategories($result);
322 */
323 } else {
324 setEventMessages($category->error, $category->errors, 'errors');
325 }
326 }
327 }
328
329 // Create cash account CASH-POS / DefaultCashPOSLabel if not exists
330 if (!getDolGlobalInt('CASHDESK_ID_BANKACCOUNT_CASH1')) {
331 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
332 $cashaccount = new Account($this->db);
333 $searchaccountid = $cashaccount->fetch(0, "CASH-POS");
334 if ($searchaccountid == 0) {
335 $cashaccount->ref = "CASH-POS";
336 $cashaccount->label = $langs->trans("DefaultCashPOSLabel");
337 $cashaccount->courant = Account::TYPE_CASH; // deprecated
338 $cashaccount->type = Account::TYPE_CASH;
339 $cashaccount->country_id = $mysoc->country_id ? $mysoc->country_id : 1;
340 $cashaccount->date_solde = dol_now();
341 $idjournal = dol_getIdFromCode($this->db, 'BQ', 'accounting_journal', 'code', 'rowid');
342 $cashaccount->fk_accountancy_journal = (int) $idjournal;
343 $searchaccountid = $cashaccount->create($user);
344 }
345 if ($searchaccountid > 0) {
346 dolibarr_set_const($this->db, "CASHDESK_ID_BANKACCOUNT_CASH1", $searchaccountid, 'chaine', 0, '', $conf->entity);
347 } else {
348 setEventMessages($cashaccount->error, $cashaccount->errors, 'errors');
349 }
350 }
351
352 $result = $this->_load_tables('/install/mysql/', 'takepos');
353 if ($result < 0) {
354 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')
355 }
356
357 // Clean before activation
358 $this->remove($options);
359
360 $sql = array();
361
362 return $this->_init($sql, $options);
363 }
364
373 public function remove($options = '')
374 {
375 $sql = array();
376
377 return $this->_remove($sql, $options);
378 }
379}
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).
Class to manage bank accounts.
const TYPE_CASH
Cash account.
Class to manage categories.
Class DolibarrModules.
_init($array_sql, $options='')
Enables a module.
_remove($array_sql, $options='')
Disable function.
_load_tables($reldir, $onlywithsuffix='')
Create tables and keys required by module:
Class to manage third parties objects (customers, suppliers, prospects...)
Class to describe and enable module TakePos.
init($options='')
Function called when module is enabled.
__construct($db)
Constructor.
global $mysoc
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
dol_now($mode='gmt')
Return date for now.
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='', $useCache=true)
Return an id or code from a code or id.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:133