dolibarr  7.0.0-beta
modMultiCurrency.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2016 Regis Houssin <regis.houssin@capnetworks.com>
5  * Copyright (C) 2016 Pierre-Henry Favre <phf@atm-consulting.fr>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
28 include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
29 
30 
35 {
41  public function __construct($db)
42  {
43  global $langs, $conf;
44 
45  $this->db = $db;
46 
47  // Id for module (must be unique).
48  // Use here a free id (See in Home -> System information -> Dolibarr for list of used modules id).
49  $this->numero = 40000;
50  // Key text used to identify module (for permissions, menus, etc...)
51  $this->rights_class = 'multicurrency';
52 
53  // Family can be 'crm','financial','hr','projects','products','ecm','technic','other'
54  // It is used to group modules in module setup page
55  $this->family = "technic";
56  // Module position in the family
57  $this->module_position = 40;
58 
59  // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
60  $this->name = preg_replace('/^mod/i', '', get_class($this));
61  // Module description, used if translation string 'ModuleXXXDesc' not found (where XXX is value of numeric property 'numero' of module)
62  $this->description = "Module to enter elements with a foreign currency";
63 
64  // Possible values for version are: 'development', 'experimental', 'dolibarr' or 'dolibarr_deprecated' or version
65  $this->version = 'dolibarr';
66  // Key used in llx_const table to save module status enabled/disabled (where MYMODULE is value of property name of module in uppercase)
67  $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
68  // Where to store the module in setup page (0=common,1=interface,2=others,3=very specific)
69  $this->special = 0;
70  // Name of image file used for this module.
71  // If file is in theme/yourtheme/img directory under name object_pictovalue.png, use this->picto='pictovalue'
72  // If file is in module/img directory under name object_pictovalue.png, use this->picto='pictovalue@module'
73  $this->picto = 'multicurrency';
74 
75  // Defined all module parts (triggers, login, substitutions, menus, css, etc...)
76  // for default path (eg: /multicurrency/core/xxxxx) (0=disable, 1=enable)
77  // for specific path of parts (eg: /multicurrency/core/modules/barcode)
78  // for specific css file (eg: /multicurrency/css/multicurrency.css.php)
79  //$this->module_parts = array(
80  // 'triggers' => 0, // Set this to 1 if module has its own trigger directory (core/triggers)
81  // 'login' => 0, // Set this to 1 if module has its own login method directory (core/login)
82  // 'substitutions' => 0, // Set this to 1 if module has its own substitution function file (core/substitutions)
83  // 'menus' => 0, // Set this to 1 if module has its own menus handler directory (core/menus)
84  // 'theme' => 0, // Set this to 1 if module has its own theme directory (theme)
85  // 'tpl' => 0, // Set this to 1 if module overwrite template dir (core/tpl)
86  // 'barcode' => 0, // Set this to 1 if module has its own barcode directory (core/modules/barcode)
87  // 'models' => 0, // Set this to 1 if module has its own models directory (core/modules/xxx)
88  // 'css' => array('/multicurrency/css/multicurrency.css.php'), // Set this to relative path of css file if module has its own css file
89  // 'js' => array('/multicurrency/js/multicurrency.js'), // Set this to relative path of js file if module must load a js on all pages
90  // 'hooks' => array('hookcontext1','hookcontext2') // Set here all hooks context managed by module
91  // 'dir' => array('output' => 'othermodulename'), // To force the default directories names
92  // 'workflow' => array('WORKFLOW_MODULE1_YOURACTIONTYPE_MODULE2'=>array('enabled'=>'! empty($conf->module1->enabled) && ! empty($conf->module2->enabled)', 'picto'=>'yourpicto@multicurrency')) // Set here all workflow context managed by module
93  // );
94  $this->module_parts = array();
95 
96  // Data directories to create when module is enabled.
97  // Example: this->dirs = array("/multicurrency/temp");
98  $this->dirs = array();
99 
100  // Config pages. Put here list of php page, stored into multicurrency/admin directory, to use to setup module.
101  $this->config_page_url = array("multicurrency.php");
102 
103  // Dependencies
104  $this->hidden = false; // A condition to hide module
105  $this->depends = array(); // List of modules id that must be enabled if this module is enabled
106  $this->requiredby = array(); // List of modules id to disable if this one is disabled
107  $this->conflictwith = array(); // List of modules id this module is in conflict with
108  $this->phpmin = array(5, 0); // Minimum version of PHP required by module
109  $this->need_dolibarr_version = array(3, 0); // Minimum version of Dolibarr required by module
110  $this->langfiles = array("multicurrency");
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('MYMODULE_MYNEWCONST1','chaine','myvalue','This is a constant to add',1),
115  // 1=>array('MYMODULE_MYNEWCONST2','chaine','myvalue','This is another constant to add',0, 'current', 1)
116  // );
117  $this->const = array();
118 
119  // Array to add new pages in new tabs
120  // Example: $this->tabs = array('objecttype:+tabname1:Title1:mylangfile@multicurrency:$user->rights->multicurrency->read:/multicurrency/mynewtab1.php?id=__ID__', // To add a new tab identified by code tabname1
121  // 'objecttype:+tabname2:SUBSTITUTION_Title2:mylangfile@multicurrency:$user->rights->othermodule->read:/multicurrency/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.
122  // 'objecttype:-tabname:NU:conditiontoremove'); // To remove an existing tab identified by code tabname
123  // where objecttype can be
124  // 'categories_x' to add a tab in category view (replace 'x' by type of category (0=product, 1=supplier, 2=customer, 3=member)
125  // 'contact' to add a tab in contact view
126  // 'contract' to add a tab in contract view
127  // 'group' to add a tab in group view
128  // 'intervention' to add a tab in intervention view
129  // 'invoice' to add a tab in customer invoice view
130  // 'invoice_supplier' to add a tab in supplier invoice view
131  // 'member' to add a tab in fundation member view
132  // 'opensurveypoll' to add a tab in opensurvey poll view
133  // 'order' to add a tab in customer order view
134  // 'order_supplier' to add a tab in supplier order view
135  // 'payment' to add a tab in payment view
136  // 'payment_supplier' to add a tab in supplier payment view
137  // 'product' to add a tab in product view
138  // 'propal' to add a tab in propal view
139  // 'project' to add a tab in project view
140  // 'stock' to add a tab in stock view
141  // 'thirdparty' to add a tab in third party view
142  // 'user' to add a tab in user view
143  $this->tabs = array();
144 
145  // Dictionaries
146  if (!isset($conf->multicurrency->enabled))
147  {
148  $conf->multicurrency = new stdClass();
149  $conf->multicurrency->enabled = 0;
150  }
151  $this->dictionaries = array();
152  /* Example:
153  if (! isset($conf->multicurrency->enabled)) $conf->multicurrency->enabled=0; // This is to avoid warnings
154  $this->dictionaries=array(
155  'langs'=>'mylangfile@multicurrency',
156  'tabname'=>array(MAIN_DB_PREFIX."table1",MAIN_DB_PREFIX."table2",MAIN_DB_PREFIX."table3"), // List of tables we want to see into dictonnary editor
157  'tablib'=>array("Table1","Table2","Table3"), // Label of tables
158  '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
159  'tabsqlsort'=>array("label ASC","label ASC","label ASC"), // Sort order
160  'tabfield'=>array("code,label","code,label","code,label"), // List of fields (result of select to show dictionary)
161  'tabfieldvalue'=>array("code,label","code,label","code,label"), // List of fields (list of fields to edit a record)
162  'tabfieldinsert'=>array("code,label","code,label","code,label"), // List of fields (list of fields for insert)
163  'tabrowid'=>array("rowid","rowid","rowid"), // Name of columns with primary key (try to always name it 'rowid')
164  'tabcond'=>array($conf->multicurrency->enabled,$conf->multicurrency->enabled,$conf->multicurrency->enabled) // Condition to show each dictionary
165  );
166  */
167 
168  // Boxes
169  // Add here list of php file(s) stored in core/boxes that contains class to show a box.
170  $this->boxes = array(); // List of boxes
171  // Example:
172  //$this->boxes=array(
173  // 0=>array('file'=>'myboxa.php@multicurrency','note'=>'','enabledbydefaulton'=>'Home'),
174  // 1=>array('file'=>'myboxb.php@multicurrency','note'=>''),
175  // 2=>array('file'=>'myboxc.php@multicurrency','note'=>'')
176  //);
177 
178  // Permissions
179  $this->rights = array(); // Permission array used by this module
180  $r = 0;
181 
182  // Add here list of permission defined by an id, a label, a boolean and two constant strings.
183  // Example:
184  // $this->rights[$r][0] = $this->numero + $r; // Permission id (must not be already used)
185  // $this->rights[$r][1] = 'Permision label'; // Permission label
186  // $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
187  // $this->rights[$r][4] = 'level1'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
188  // $this->rights[$r][5] = 'level2'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
189  // $r++;
190 
191  // Main menu entries
192  $this->menu = array(); // List of menus to add
193  $r = 0;
194 
195  // Add here entries to declare new menus
196  //
197  // Example to declare a new Top Menu entry and its Left menu entry:
198  // $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
199  // 'type'=>'top', // This is a Top menu entry
200  // 'titre'=>'MyModule top menu',
201  // 'mainmenu'=>'multicurrency',
202  // 'leftmenu'=>'multicurrency',
203  // 'url'=>'/multicurrency/pagetop.php',
204  // 'langs'=>'mylangfile@multicurrency', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
205  // 'position'=>100,
206  // 'enabled'=>'$conf->multicurrency->enabled', // Define condition to show or hide menu entry. Use '$conf->multicurrency->enabled' if entry must be visible if module is enabled.
207  // 'perms'=>'1', // Use 'perms'=>'$user->rights->multicurrency->level1->level2' if you want your menu with a permission rules
208  // 'target'=>'',
209  // 'user'=>2); // 0=Menu for internal users, 1=external users, 2=both
210  // $r++;
211  //
212  // Example to declare a Left Menu entry into an existing Top menu entry:
213  // $this->menu[$r]=array( 'fk_menu'=>'fk_mainmenu=xxx', // '' 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
214  // 'type'=>'left', // This is a Left menu entry
215  // 'titre'=>'MyModule left menu',
216  // 'mainmenu'=>'xxx',
217  // 'leftmenu'=>'multicurrency',
218  // 'url'=>'/multicurrency/pagelevel2.php',
219  // 'langs'=>'mylangfile@multicurrency', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
220  // 'position'=>100,
221  // 'enabled'=>'$conf->multicurrency->enabled', // Define condition to show or hide menu entry. Use '$conf->multicurrency->enabled' if entry must be visible if module is enabled. Use '$leftmenu==\'system\'' to show if leftmenu system is selected.
222  // 'perms'=>'1', // Use 'perms'=>'$user->rights->multicurrency->level1->level2' if you want your menu with a permission rules
223  // 'target'=>'',
224  // 'user'=>2); // 0=Menu for internal users, 1=external users, 2=both
225  // $r++;
226 
227 
228  // Exports
229  $r = 1;
230 
231  // Example:
232  // $this->export_code[$r]=$this->rights_class.'_'.$r;
233  // $this->export_label[$r]='MyModule'; // Translation key (used only if key ExportDataset_xxx_z not found)
234  // $this->export_enabled[$r]='1'; // Condition to show export in list (ie: '$user->id==3'). Set to 1 to always show when module is enabled.
235  // $this->export_icon[$r]='generic:MyModule';
236  // $this->export_permission[$r]=array(array("multicurrency","level1","level2"));
237  // $this->export_fields_array[$r]=array('s.rowid'=>"IdCompany",'s.nom'=>'CompanyName','s.address'=>'Address','s.zip'=>'Zip','s.town'=>'Town','s.fk_pays'=>'Country','s.phone'=>'Phone','s.siren'=>'ProfId1','s.siret'=>'ProfId2','s.ape'=>'ProfId3','s.idprof4'=>'ProfId4','s.code_compta'=>'CustomerAccountancyCode','s.code_compta_fournisseur'=>'SupplierAccountancyCode','f.rowid'=>"InvoiceId",'f.facnumber'=>"InvoiceRef",'f.datec'=>"InvoiceDateCreation",'f.datef'=>"DateInvoice",'f.total'=>"TotalHT",'f.total_ttc'=>"TotalTTC",'f.tva'=>"TotalVAT",'f.paye'=>"InvoicePaid",'f.fk_statut'=>'InvoiceStatus','f.note'=>"InvoiceNote",'fd.rowid'=>'LineId','fd.description'=>"LineDescription",'fd.price'=>"LineUnitPrice",'fd.tva_tx'=>"LineVATRate",'fd.qty'=>"LineQty",'fd.total_ht'=>"LineTotalHT",'fd.total_tva'=>"LineTotalTVA",'fd.total_ttc'=>"LineTotalTTC",'fd.date_start'=>"DateStart",'fd.date_end'=>"DateEnd",'fd.fk_product'=>'ProductId','p.ref'=>'ProductRef');
238  // $this->export_TypeFields_array[$r]=array('t.date'=>'Date', 't.qte'=>'Numeric', 't.poids'=>'Numeric', 't.fad'=>'Numeric', 't.paq'=>'Numeric', 't.stockage'=>'Numeric', 't.fadparliv'=>'Numeric', 't.livau100'=>'Numeric', 't.forfait'=>'Numeric', 's.nom'=>'Text','s.address'=>'Text','s.zip'=>'Text','s.town'=>'Text','c.code'=>'Text','s.phone'=>'Text','s.siren'=>'Text','s.siret'=>'Text','s.ape'=>'Text','s.idprof4'=>'Text','s.code_compta'=>'Text','s.code_compta_fournisseur'=>'Text','s.tva_intra'=>'Text','f.facnumber'=>"Text",'f.datec'=>"Date",'f.datef'=>"Date",'f.date_lim_reglement'=>"Date",'f.total'=>"Numeric",'f.total_ttc'=>"Numeric",'f.tva'=>"Numeric",'f.paye'=>"Boolean",'f.fk_statut'=>'Status','f.note_private'=>"Text",'f.note_public'=>"Text",'fd.description'=>"Text",'fd.subprice'=>"Numeric",'fd.tva_tx'=>"Numeric",'fd.qty'=>"Numeric",'fd.total_ht'=>"Numeric",'fd.total_tva'=>"Numeric",'fd.total_ttc'=>"Numeric",'fd.date_start'=>"Date",'fd.date_end'=>"Date",'fd.special_code'=>'Numeric','fd.product_type'=>"Numeric",'fd.fk_product'=>'List:product:label','p.ref'=>'Text','p.label'=>'Text','p.accountancy_code_sell'=>'Text');
239  // $this->export_entities_array[$r]=array('s.rowid'=>"company",'s.nom'=>'company','s.address'=>'company','s.zip'=>'company','s.town'=>'company','s.fk_pays'=>'company','s.phone'=>'company','s.siren'=>'company','s.siret'=>'company','s.ape'=>'company','s.idprof4'=>'company','s.code_compta'=>'company','s.code_compta_fournisseur'=>'company','f.rowid'=>"invoice",'f.facnumber'=>"invoice",'f.datec'=>"invoice",'f.datef'=>"invoice",'f.total'=>"invoice",'f.total_ttc'=>"invoice",'f.tva'=>"invoice",'f.paye'=>"invoice",'f.fk_statut'=>'invoice','f.note'=>"invoice",'fd.rowid'=>'invoice_line','fd.description'=>"invoice_line",'fd.price'=>"invoice_line",'fd.total_ht'=>"invoice_line",'fd.total_tva'=>"invoice_line",'fd.total_ttc'=>"invoice_line",'fd.tva_tx'=>"invoice_line",'fd.qty'=>"invoice_line",'fd.date_start'=>"invoice_line",'fd.date_end'=>"invoice_line",'fd.fk_product'=>'product','p.ref'=>'product');
240  // $this->export_dependencies_array[$r]=array('invoice_line'=>'fd.rowid','product'=>'fd.rowid'); // To add unique key if we ask a field of a child to avoid the DISTINCT to discard them
241  // $this->export_sql_start[$r]='SELECT DISTINCT ';
242  // $this->export_sql_end[$r] =' FROM ('.MAIN_DB_PREFIX.'facture as f, '.MAIN_DB_PREFIX.'facturedet as fd, '.MAIN_DB_PREFIX.'societe as s)';
243  // $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on (fd.fk_product = p.rowid)';
244  // $this->export_sql_end[$r] .=' WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_facture';
245  // $this->export_sql_order[$r] .=' ORDER BY s.nom';
246  // $r++;
247  }
248 
257  public function init($options = '')
258  {
259  $sql = array();
260 
261  //$this->_load_tables('/multicurrency/sql/');
262  $res = $this->_init($sql, $options);
263 
264  if ($res)
265  {
266  $this->createFirstCurrency();
267  }
268 
269  return $res;
270  }
271 
280  public function remove($options = '')
281  {
282  $sql = array();
283 
284  return $this->_remove($sql, $options);
285  }
286 
293  private function createFirstCurrency()
294  {
295  global $conf, $user, $langs;
296 
297  if (!MultiCurrency::checkCodeAlreadyExists($conf->currency))
298  {
299  $langs->loadCacheCurrencies('');
300 
301  $multicurrency = new MultiCurrency($this->db);
302  $multicurrency->code = $conf->currency;
303  $multicurrency->name = $langs->cache_currencies[$conf->currency]['label'].' ('.$langs->getCurrencySymbol($conf->currency).')';
304  $r = $multicurrency->create($user);
305 
306  if ($r > 0) $multicurrency->addRate(1);
307  }
308  }
309 }
310 
Class DolibarrModules.
_remove($array_sql, $options='')
Disable function.
</td >< tdclass="liste_titre"align="right"></td ></tr >< trclass="liste_titre">< inputtype="checkbox"onClick="toggle(this)"/> Ref p ref Label p label Duration p duration warehouseinternal SELECT description FROM product_lang WHERE qty< br > qty qty qty StockTooLow img yes disabled img no img no< trclass="oddeven">< td >< inputtype="checkbox"class="check"name="'.$i.'"'.$disabled.'></td >< td >< inputtype="checkbox"class="check"name="choose'.$i.'"></td >< tdclass="nowrap"></td >< td >< inputtype="hidden"name="desc'.$i.'"value="'.dol_escape_htmltag($objp-> description
Only used if Module[ID]Desc translation string is not found.
Definition: replenish.php:554
Description and activation class for module MyModule.
static checkCodeAlreadyExists($code)
Check in database if the current code already exists.
createFirstCurrency()
Function called when module is enabled Create the currency from general setting.
init($options= '')
Function called when module is enabled.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:104
__construct($db)
Constructor.
_init($array_sql, $options='')
Enables a module.
Class Currency.