Clean code for v10
This commit is contained in:
parent
18071fb238
commit
3bf162dcd6
@ -234,6 +234,8 @@ if ($action=="create" || $action=="start")
|
||||
{
|
||||
$posmodule = GETPOST('posmodule', 'alpha');
|
||||
$terminalid = GETPOST('posnumber', 'alpha');
|
||||
$terminaltouse = $terminalid;
|
||||
if ($terminaltouse == '1') $terminaltouse = '';
|
||||
|
||||
// Calculate $initialbalanceforterminal for terminal 0
|
||||
foreach($arrayofpaymentmode as $key => $val)
|
||||
@ -245,24 +247,33 @@ if ($action=="create" || $action=="start")
|
||||
}
|
||||
|
||||
// Get the bank account dedicated to this point of sale module/terminal
|
||||
$bankid = $conf->global->CASHDESK_ID_BANKACCOUNT_CASH; // This value is ok for 'Terminal 0' for module 'CashDesk' and 'TakePos' (they manage only 1 terminal)
|
||||
$vartouse=CASHDESK_ID_BANKACCOUNT_CASH.$terminaltouse;
|
||||
$bankid = $conf->global->$vartouse; // This value is ok for 'Terminal 0' for module 'CashDesk' and 'TakePos' (they manage only 1 terminal)
|
||||
// Hook to get the good bank id according to posmodule and posnumber.
|
||||
// @TODO add hook here
|
||||
|
||||
$sql = "SELECT SUM(amount) as total FROM ".MAIN_DB_PREFIX."bank";
|
||||
$sql.= " WHERE fk_account = ".$bankid;
|
||||
if ($syear && ! $smonth) $sql.= " AND dateo < '".$db->idate(dol_get_first_day($syear, 1))."'";
|
||||
elseif ($syear && $smonth && ! $sday) $sql.= " AND dateo < '".$db->idate(dol_get_first_day($syear, $smonth))."'";
|
||||
elseif ($syear && $smonth && $sday) $sql.= " AND dateo < '".$db->idate(dol_mktime(0, 0, 0, $smonth, $sday, $syear))."'";
|
||||
else dol_print_error('', 'Year not defined');
|
||||
|
||||
$resql = $db->query($sql);
|
||||
if ($resql)
|
||||
if ($bankid > 0)
|
||||
{
|
||||
$obj = $db->fetch_object($resql);
|
||||
if ($obj) $initialbalanceforterminal[$terminalid][$key] = $obj->total;
|
||||
$sql = "SELECT SUM(amount) as total FROM ".MAIN_DB_PREFIX."bank";
|
||||
$sql.= " WHERE fk_account = ".$bankid;
|
||||
if ($syear && ! $smonth) $sql.= " AND dateo < '".$db->idate(dol_get_first_day($syear, 1))."'";
|
||||
elseif ($syear && $smonth && ! $sday) $sql.= " AND dateo < '".$db->idate(dol_get_first_day($syear, $smonth))."'";
|
||||
elseif ($syear && $smonth && $sday) $sql.= " AND dateo < '".$db->idate(dol_mktime(0, 0, 0, $smonth, $sday, $syear))."'";
|
||||
else dol_print_error('', 'Year not defined');
|
||||
|
||||
$resql = $db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$obj = $db->fetch_object($resql);
|
||||
if ($obj) $initialbalanceforterminal[$terminalid][$key] = $obj->total;
|
||||
}
|
||||
else dol_print_error($db);
|
||||
}
|
||||
else
|
||||
{
|
||||
setEventMessages($langs->trans("SetupOfTerminalNotComplete", $terminalid), null, 'errors');
|
||||
$error++;
|
||||
}
|
||||
else dol_print_error($db);
|
||||
}
|
||||
|
||||
// Calculate $theoricalamountforterminal for terminal 0
|
||||
@ -332,7 +343,16 @@ if ($action=="create" || $action=="start")
|
||||
|
||||
print '<tr class="oddeven">';
|
||||
print '<td>'.$form->selectarray('posmodule', $arrayofposavailable, GETPOST('posmodule', 'alpha'), (count($arrayofposavailable)>1?1:0)).'</td>';
|
||||
print '<td><input name="posnumber" type="text" class="maxwidth50" value="'.(GETPOSTISSET('posnumber')?GETPOST('posnumber', 'alpha'):'0').'"></td>';
|
||||
print '<td>';
|
||||
$array=array(1=>"1", 2=>"2", 3=>"3", 4=>"4", 5=>"5", 6=>"6", 7=>"7", 8=>"8", 9=>"9");
|
||||
$selectedposnumber=0; $showempty=1;
|
||||
if ($conf->global->TAKEPOS_NUM_TERMINALS == '1')
|
||||
{
|
||||
$selectedposnumber=1; $showempty=0;
|
||||
}
|
||||
print $form->selectarray('posnumber', $array, GETPOSTISSET('posnumber')?GETPOST('posnumber','int'):$selectedposnumber, $showempty);
|
||||
//print '<input name="posnumber" type="text" class="maxwidth50" value="'.(GETPOSTISSET('posnumber')?GETPOST('posnumber', 'alpha'):'0').'">';
|
||||
print '</td>';
|
||||
// Year
|
||||
print '<td>';
|
||||
$retstring='<select'.($disabled?' disabled':'').' class="flat valignmiddle maxwidth75imp" id="'.$prefix.'year" name="'.$prefix.'year">';
|
||||
@ -380,6 +400,7 @@ if ($action=="create" || $action=="start")
|
||||
print '</td>';
|
||||
print '</table>';
|
||||
|
||||
// Table to see/enter balance
|
||||
if ($action == 'start' && GETPOST('posnumber') != '' && GETPOST('posnumber') != '' && GETPOST('posnumber') != '-1')
|
||||
{
|
||||
$posmodule = GETPOST('posmodule', 'alpha');
|
||||
|
||||
@ -59,15 +59,18 @@ $arrayofparameters=array(
|
||||
);
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Actions
|
||||
*/
|
||||
|
||||
if ((float) DOL_VERSION >= 6)
|
||||
{
|
||||
include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* View
|
||||
*/
|
||||
@ -85,7 +88,7 @@ $head = mymoduleAdminPrepareHead();
|
||||
dol_fiche_head($head, 'settings', '', -1, "mymodule@mymodule");
|
||||
|
||||
// Setup page goes here
|
||||
echo $langs->trans("MyModuleSetupPage").'<br><br>';
|
||||
echo '<span class="opacitymedium">'.$langs->trans("MyModuleSetupPage").'</span><br><br>';
|
||||
|
||||
|
||||
if ($action == 'edit')
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/* Copyright (C) 2004-2018 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2018-2019 Nicolas ZABOURI <info@inovea-conseil.com>
|
||||
* Copyright (C) 2018-2019 Nicolas ZABOURI <info@inovea-conseil.com>
|
||||
* Copyright (C) 2019 Frédéric France <frederic.france@netlogic.fr>
|
||||
* Copyright (C) ---Put here your own copyright and developer email---
|
||||
*
|
||||
@ -17,6 +17,7 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \defgroup mymodule Module MyModule
|
||||
* \brief MyModule module descriptor.
|
||||
@ -26,6 +27,7 @@
|
||||
* \brief Description and activation file for module MyModule
|
||||
*/
|
||||
include_once DOL_DOCUMENT_ROOT .'/core/modules/DolibarrModules.class.php';
|
||||
|
||||
/**
|
||||
* Description and activation class for module MyModule
|
||||
*/
|
||||
@ -40,9 +42,10 @@ class modMyModule extends DolibarrModules
|
||||
{
|
||||
global $langs,$conf;
|
||||
$this->db = $db;
|
||||
|
||||
// Id for module (must be unique).
|
||||
// Use here a free id (See in Home -> System information -> Dolibarr for list of used modules id).
|
||||
$this->numero = 500000; // TODO Go on page https://wiki.dolibarr.org/index.php/List_of_modules_id to reserve id number for your module
|
||||
$this->numero = 500000; // TODO Go on page https://wiki.dolibarr.org/index.php/List_of_modules_id to reserve an id number for your module
|
||||
// Key text used to identify module (for permissions, menus, etc...)
|
||||
$this->rights_class = 'mymodule';
|
||||
// Family can be 'base' (core modules),'crm','financial','hr','projects','products','ecm','technic' (transverse modules),'interface' (link with external tools),'other','...'
|
||||
@ -62,8 +65,9 @@ class modMyModule extends DolibarrModules
|
||||
$this->editor_url = 'https://www.example.com';
|
||||
// Possible values for version are: 'development', 'experimental', 'dolibarr', 'dolibarr_deprecated' or a version string like 'x.y.z'
|
||||
$this->version = '1.0';
|
||||
//Url to the file with your last numberversion of this module
|
||||
// Url to the file with your last numberversion of this module
|
||||
//$this->url_last_version = 'http://www.example.com/versionmodule.txt';
|
||||
|
||||
// Key used in llx_const table to save module status enabled/disabled (where MYMODULE is value of property name of module in uppercase)
|
||||
$this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
|
||||
// Name of image file used for this module.
|
||||
@ -96,7 +100,7 @@ class modMyModule extends DolibarrModules
|
||||
'js' => array(
|
||||
// '/mymodule/js/mymodule.js.php',
|
||||
),
|
||||
// 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'
|
||||
// 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'
|
||||
'hooks' => array(
|
||||
// 'data' => array(
|
||||
// 'hookcontext1',
|
||||
@ -104,7 +108,7 @@ class modMyModule extends DolibarrModules
|
||||
// ),
|
||||
// 'entity' => '0',
|
||||
),
|
||||
// Set this to 1 if feature of module are opened to external users
|
||||
// Set this to 1 if features of module are opened to external users
|
||||
'moduleforexternal' => 0,
|
||||
);
|
||||
// Data directories to create when module is enabled.
|
||||
@ -120,8 +124,8 @@ class modMyModule extends DolibarrModules
|
||||
$this->requiredby = array(); // List of module class names as string to disable if this one is disabled. Example: array('modModuleToDisable1', ...)
|
||||
$this->conflictwith = array(); // List of module class names as string this module is in conflict with. Example: array('modModuleToDisable1', ...)
|
||||
$this->langfiles = array("mymodule@mymodule");
|
||||
//$this->phpmin = array(5,4); // Minimum version of PHP required by module
|
||||
$this->need_dolibarr_version = array(4,0); // Minimum version of Dolibarr required by module
|
||||
$this->phpmin = array(5,5); // Minimum version of PHP required by module
|
||||
$this->need_dolibarr_version = array(8,0); // Minimum version of Dolibarr required by module
|
||||
$this->warnings_activation = array(); // Warning to show when we activate module. array('always'='text') or array('FR'='textfr','ES'='textes'...)
|
||||
$this->warnings_activation_ext = array(); // Warning to show when we activate an external module. array('always'='text') or array('FR'='textfr','ES'='textes'...)
|
||||
//$this->automatic_activation = array('FR'=>'MyModuleWasAutomaticallyActivatedBecauseOfYourCountryChoice');
|
||||
@ -134,15 +138,18 @@ class modMyModule extends DolibarrModules
|
||||
$this->const = array(
|
||||
// 1 => array('MYMODULE_MYCONSTANT', 'chaine', 'avalue', 'This is a constant to add', 1, 'allentities', 1)
|
||||
);
|
||||
|
||||
// Some keys to add into the overwriting translation tables
|
||||
/*$this->overwrite_translation = array(
|
||||
'en_US:ParentCompany'=>'Parent company or reseller',
|
||||
'fr_FR:ParentCompany'=>'Maison mère ou revendeur'
|
||||
)*/
|
||||
|
||||
if (! isset($conf->mymodule) || ! isset($conf->mymodule->enabled)) {
|
||||
$conf->mymodule=new stdClass();
|
||||
$conf->mymodule->enabled=0;
|
||||
}
|
||||
|
||||
// Array to add new pages in new tabs
|
||||
$this->tabs = array();
|
||||
// Example:
|
||||
@ -198,15 +205,14 @@ class modMyModule extends DolibarrModules
|
||||
*/
|
||||
|
||||
// Boxes/Widgets
|
||||
// Add here list of php file(s) stored in mymodule/core/boxes that contains class to show a widget.
|
||||
// Add here list of php file(s) stored in mymodule/core/boxes that contains a class to show a widget.
|
||||
$this->boxes = array(
|
||||
// 0 => array(
|
||||
// 'file' => 'mymodulewidget1.php@mymodule',
|
||||
// 'note' => 'Widget provided by MyModule',
|
||||
// 'enabledbydefaulton' => 'Home',
|
||||
// ),
|
||||
//1=>array('file'=>'mymodulewidget2.php@mymodule','note'=>'Widget provided by MyModule'),
|
||||
//2=>array('file'=>'mymodulewidget3.php@mymodule','note'=>'Widget provided by MyModule')
|
||||
// ...
|
||||
);
|
||||
|
||||
// Cronjobs (List of cron jobs entries to add when module is enabled)
|
||||
@ -232,29 +238,30 @@ class modMyModule extends DolibarrModules
|
||||
// 1=>array('label'=>'My label', 'jobtype'=>'command', 'command'=>'', 'parameters'=>'param1, param2', 'comment'=>'Comment', 'frequency'=>1, 'unitfrequency'=>3600*24, 'status'=>0, 'test'=>'$conf->mymodule->enabled', 'priority'=>50)
|
||||
// );
|
||||
|
||||
// Permissions
|
||||
$this->rights = array(); // Permission array used by this module
|
||||
// Permissions provided by this module
|
||||
$this->rights = array();
|
||||
$r=0;
|
||||
// Add here entries to declare new permissions
|
||||
/* BEGIN MODULEBUILDER PERMISSIONS */
|
||||
$this->rights[$r][0] = $this->numero + $r; // Permission id (must not be already used)
|
||||
$this->rights[$r][1] = 'Read objects of MyModule'; // Permission label
|
||||
$this->rights[$r][3] = 0; // Permission by default for new user (0/1)
|
||||
$this->rights[$r][4] = 'read'; // In php code, permission will be checked by test if ($user->rights->mymodule->level1->level2)
|
||||
$this->rights[$r][5] = ''; // In php code, permission will be checked by test if ($user->rights->mymodule->level1->level2)
|
||||
$r++;
|
||||
$this->rights[$r][0] = $this->numero + $r; // Permission id (must not be already used)
|
||||
$this->rights[$r][1] = 'Create/Update objects of MyModule'; // Permission label
|
||||
$this->rights[$r][3] = 0; // Permission by default for new user (0/1)
|
||||
$this->rights[$r][4] = 'write'; // In php code, permission will be checked by test if ($user->rights->mymodule->level1->level2)
|
||||
$this->rights[$r][5] = ''; // In php code, permission will be checked by test if ($user->rights->mymodule->level1->level2)
|
||||
$r++;
|
||||
$this->rights[$r][0] = $this->numero + $r; // Permission id (must not be already used)
|
||||
$this->rights[$r][1] = 'Delete objects of MyModule'; // Permission label
|
||||
$this->rights[$r][3] = 0; // Permission by default for new user (0/1)
|
||||
$this->rights[$r][4] = 'delete'; // In php code, permission will be checked by test if ($user->rights->mymodule->level1->level2)
|
||||
$this->rights[$r][5] = ''; // In php code, permission will be checked by test if ($user->rights->mymodule->level1->level2)
|
||||
$r++;
|
||||
/* END MODULEBUILDER PERMISSIONS */
|
||||
|
||||
// Main menu entries
|
||||
$this->menu = array(); // List of menus to add
|
||||
// Main menu entries to add
|
||||
$this->menu = array();
|
||||
$r=0;
|
||||
// Add here entries to declare new menus
|
||||
/* BEGIN MODULEBUILDER TOPMENU */
|
||||
@ -304,7 +311,7 @@ class modMyModule extends DolibarrModules
|
||||
);
|
||||
END MODULEBUILDER LEFTMENU MYOBJECT */
|
||||
|
||||
// Exports
|
||||
// Exports profiles provided by this module
|
||||
$r=1;
|
||||
/* BEGIN MODULEBUILDER EXPORT MYOBJECT */
|
||||
/*
|
||||
@ -324,7 +331,7 @@ class modMyModule extends DolibarrModules
|
||||
$r++; */
|
||||
/* END MODULEBUILDER EXPORT MYOBJECT */
|
||||
|
||||
// Imports
|
||||
// Imports profiles provided by this module
|
||||
$r=1;
|
||||
/* BEGIN MODULEBUILDER IMPORT MYOBJECT */
|
||||
/*
|
||||
@ -344,6 +351,7 @@ class modMyModule extends DolibarrModules
|
||||
$r++; */
|
||||
/* END MODULEBUILDER IMPORT MYOBJECT */
|
||||
}
|
||||
|
||||
/**
|
||||
* Function called when module is enabled.
|
||||
* The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
|
||||
@ -355,18 +363,21 @@ class modMyModule extends DolibarrModules
|
||||
public function init($options = '')
|
||||
{
|
||||
$result=$this->_load_tables('/mymodule/sql/');
|
||||
if ($result < 0) return -1; // Do not activate module if not allowed errors found on module SQL queries (the _load_table run sql with run_sql with error allowed parameter to 'default')
|
||||
// Create extrafields
|
||||
include_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
|
||||
$extrafields = new ExtraFields($this->db);
|
||||
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')
|
||||
|
||||
// Create extrafields during init
|
||||
//include_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
|
||||
//$extrafields = new ExtraFields($this->db);
|
||||
//$result1=$extrafields->addExtraField('myattr1', "New Attr 1 label", 'boolean', 1, 3, 'thirdparty', 0, 0, '', '', 1, '', 0, 0, '', '', 'mymodule@mymodule', '$conf->mymodule->enabled');
|
||||
//$result2=$extrafields->addExtraField('myattr2', "New Attr 2 label", 'varchar', 1, 10, 'project', 0, 0, '', '', 1, '', 0, 0, '', '', 'mymodule@mymodule', '$conf->mymodule->enabled');
|
||||
//$result3=$extrafields->addExtraField('myattr3', "New Attr 3 label", 'varchar', 1, 10, 'bank_account', 0, 0, '', '', 1, '', 0, 0, '', '', 'mymodule@mymodule', '$conf->mymodule->enabled');
|
||||
//$result4=$extrafields->addExtraField('myattr4', "New Attr 4 label", 'select', 1, 3, 'thirdparty', 0, 1, '', array('options'=>array('code1'=>'Val1','code2'=>'Val2','code3'=>'Val3')), 1,'', 0, 0, '', '', 'mymodule@mymodule', '$conf->mymodule->enabled');
|
||||
//$result5=$extrafields->addExtraField('myattr5', "New Attr 5 label", 'text', 1, 10, 'user', 0, 0, '', '', 1, '', 0, 0, '', '', 'mymodule@mymodule', '$conf->mymodule->enabled');
|
||||
|
||||
$sql = array();
|
||||
return $this->_init($sql, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function called when module is disabled.
|
||||
* Remove from database constants, boxes and permissions from Dolibarr database.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user