dolibarr  16.0.5
modAccounting.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2013-2014 Olivier Geffroy <jeff@jeffinfo.com>
3  * Copyright (C) 2013-2021 Alexandre Spangaro <aspangaro@open-dsi.fr>
4  * Copyright (C) 2014 Ari Elbaz (elarifr) <github@accedinfo.com>
5  * Copyright (C) 2014 Florian Henry <florian.henry@open-concept.pro>
6  * Copyright (C) 2016-2017 Laurent Destailleur <eldy@users.sourceforge.net>
7  * Copyright (C) 2017-2021 Open-DSI <support@open-dsi.fr>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <https://www.gnu.org/licenses/>.
21  */
22 
28 include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
29 
34 {
40  public function __construct($db)
41  {
42  global $conf;
43 
44  $this->db = $db;
45  $this->numero = 50400;
46 
47  $this->family = "financial";
48  $this->module_position = '61';
49  // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
50  $this->name = preg_replace('/^mod/i', '', get_class($this));
51  $this->description = "Double entry accounting management";
52 
53  // Possible values for version are: 'development', 'experimental', 'dolibarr' or 'dolibarr_deprecated' or version
54  $this->version = 'dolibarr';
55 
56  $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
57  $this->picto = 'accountancy';
58 
59  // Data directories to create when module is enabled
60  $this->dirs = array('/accounting/temp');
61 
62  // Config pages
63  $this->config_page_url = array('accounting.php?mainmenu=accountancy&leftmenu=accountancy_admin');
64 
65  // Dependencies
66  $this->depends = array("modFacture", "modBanque", "modTax"); // List of modules id that must be enabled if this module is enabled
67  $this->requiredby = array(); // List of modules id to disable if this one is disabled
68  $this->conflictwith = array("modComptabilite"); // List of modules are in conflict with this module
69  $this->phpmin = array(5, 6); // Minimum version of PHP required by module
70  $this->need_dolibarr_version = array(3, 9); // Minimum version of Dolibarr required by module
71  $this->langfiles = array("accountancy", "compta");
72 
73  // Constants
74  // List of particular constants to add when module is enabled (key, 'chaine', value, desc, visible, 'current' or 'allentities', deleteonunactive)
75  // Example: $this->const=array(0=>array('MYMODULE_MYNEWCONST1','chaine','myvalue','This is a constant to add',1),
76  // 1=>array('MYMODULE_MYNEWCONST2','chaine','myvalue','This is another constant to add',0, 'current', 1)
77  // );
78  $this->const = array();
79  $this->const[1] = array(
80  "MAIN_COMPANY_CODE_ALWAYS_REQUIRED",
81  "chaine",
82  "1",
83  "With this constants on, third party code is always required whatever is numbering module behaviour", 0, 'current', 1
84  );
85  $this->const[2] = array(
86  "MAIN_BANK_ACCOUNTANCY_CODE_ALWAYS_REQUIRED",
87  "chaine",
88  "1",
89  "With this constants on, bank account number is always required", 0, 'current', 1
90  );
91  $this->const[3] = array(
92  "ACCOUNTING_ACCOUNT_SUSPENSE",
93  "chaine",
94  "471",
95  "", 0, 'current', 0
96  );
97  $this->const[4] = array(
98  "ACCOUNTING_ACCOUNT_TRANSFER_CASH",
99  "chaine",
100  "58",
101  "", 0, 'current', 0
102  );
103  $this->const[5] = array(
104  "CHARTOFACCOUNTS",
105  "chaine",
106  "2",
107  "", 0, 'current', 0
108  );
109  $this->const[6] = array(
110  "ACCOUNTING_EXPORT_MODELCSV",
111  "chaine",
112  "1",
113  "", 0, 'current', 0
114  );
115  $this->const[7] = array(
116  "ACCOUNTING_LENGTH_GACCOUNT",
117  "chaine",
118  "",
119  "", 0, 'current', 0
120  );
121  $this->const[8] = array(
122  "ACCOUNTING_LENGTH_AACCOUNT",
123  "chaine",
124  "",
125  "", 0, 'current', 0
126  );
127  $this->const[9] = array(
128  "ACCOUNTING_LIST_SORT_VENTILATION_TODO",
129  "yesno",
130  "1",
131  "", 0, 'current', 0
132  );
133  $this->const[10] = array(
134  "ACCOUNTING_LIST_SORT_VENTILATION_DONE",
135  "yesno",
136  "1",
137  "", 0, 'current', 0
138  );
139  $this->const[11] = array(
140  "ACCOUNTING_EXPORT_DATE",
141  "chaine",
142  "%d%m%Y",
143  "", 0, 'current', 0
144  );
145  $this->const[12] = array(
146  "ACCOUNTING_EXPORT_SEPARATORCSV",
147  "string",
148  ",",
149  "", 0, 'current', 0
150  );
151  $this->const[13] = array(
152  "ACCOUNTING_EXPORT_FORMAT",
153  "chaine",
154  "csv",
155  "", 0, 'current', 0
156  );
157 
158  // Tabs
159  $this->tabs = array();
160 
161  // Css
162  $this->module_parts = array();
163 
164  // Boxes
165  $this->boxes = array(
166  0=>array('file'=>'box_accountancy_last_manual_entries.php', 'enabledbydefaulton'=>'accountancyindex'),
167  1=>array('file'=>'box_accountancy_suspense_account.php', 'enabledbydefaulton'=>'accountancyindex')
168  );
169 
170  // Permissions
171  $this->rights_class = 'accounting';
172 
173  $this->rights = array(); // Permission array used by this module
174  $r = 0;
175 
176  $this->rights[$r][0] = 50440;
177  $this->rights[$r][1] = 'Manage chart of accounts, setup of accountancy';
178  $this->rights[$r][2] = 'r';
179  $this->rights[$r][3] = 0;
180  $this->rights[$r][4] = 'chartofaccount';
181  $this->rights[$r][5] = '';
182  $r++;
183 
184  $this->rights[$r][0] = 50401;
185  $this->rights[$r][1] = 'Bind products and invoices with accounting accounts';
186  $this->rights[$r][2] = 'r';
187  $this->rights[$r][3] = 0;
188  $this->rights[$r][4] = 'bind';
189  $this->rights[$r][5] = 'write';
190  $r++;
191 
192  $this->rights[$r][0] = 50411;
193  $this->rights[$r][1] = 'Read operations in Ledger';
194  $this->rights[$r][2] = 'r';
195  $this->rights[$r][3] = 0;
196  $this->rights[$r][4] = 'mouvements';
197  $this->rights[$r][5] = 'lire';
198  $r++;
199 
200  $this->rights[$r][0] = 50412;
201  $this->rights[$r][1] = 'Write/Edit operations in Ledger';
202  $this->rights[$r][2] = 'w';
203  $this->rights[$r][3] = 0;
204  $this->rights[$r][4] = 'mouvements';
205  $this->rights[$r][5] = 'creer';
206  $r++;
207 
208  $this->rights[$r][0] = 50414;
209  $this->rights[$r][1] = 'Delete operations in Ledger';
210  $this->rights[$r][2] = 'd';
211  $this->rights[$r][3] = 0;
212  $this->rights[$r][4] = 'mouvements';
213  $this->rights[$r][5] = 'supprimer';
214  $r++;
215 
216  $this->rights[$r][0] = 50415;
217  $this->rights[$r][1] = 'Delete all operations by year and journal in Ledger';
218  $this->rights[$r][2] = 'd';
219  $this->rights[$r][3] = 0;
220  $this->rights[$r][4] = 'mouvements';
221  $this->rights[$r][5] = 'supprimer_tous';
222  $r++;
223 
224  $this->rights[$r][0] = 50418;
225  $this->rights[$r][1] = 'Export operations of the Ledger';
226  $this->rights[$r][2] = 'r';
227  $this->rights[$r][3] = 0;
228  $this->rights[$r][4] = 'mouvements';
229  $this->rights[$r][5] = 'export';
230  $r++;
231 
232  $this->rights[$r][0] = 50420;
233  $this->rights[$r][1] = 'Report and export reports (turnover, balance, journals, ledger)';
234  $this->rights[$r][2] = 'r';
235  $this->rights[$r][3] = 0;
236  $this->rights[$r][4] = 'comptarapport';
237  $this->rights[$r][5] = 'lire';
238  $r++;
239 
240  $this->rights[$r][0] = 50430;
241  $this->rights[$r][1] = 'Manage fiscal periods, validate movements and close periods';
242  $this->rights[$r][2] = 'r';
243  $this->rights[$r][3] = 0;
244  $this->rights[$r][4] = 'fiscalyear';
245  $this->rights[$r][5] = 'write';
246  $r++;
247 
248  // Menus
249  //-------
250  $this->menu = 1; // This module add menu entries. They are coded into menu manager.
251 
252  // Exports
253  //--------
254  $r = 0;
255 
256  $r++;
257  $this->export_code[$r] = $this->rights_class.'_'.$r;
258  $this->export_label[$r] = 'Chartofaccounts';
259  $this->export_icon[$r] = $this->picto;
260  $this->export_permission[$r] = array(array("accounting", "chartofaccount"));
261  $this->export_fields_array[$r] = array('ac.rowid'=>'ChartofaccountsId', 'ac.pcg_version'=>'Chartofaccounts', 'aa.rowid'=>'ID', 'aa.account_number'=>"AccountAccounting", 'aa.label'=>"Label", 'aa2.account_number'=>"Accountparent", 'aa.pcg_type'=>"Pcgtype", 'aa.active'=>'Status');
262  $this->export_TypeFields_array[$r] = array('ac.rowid'=>'List:accounting_system:pcg_version', 'ac.pcg_version'=>'Text', 'aa.rowid'=>'Numeric', 'aa.account_number'=>"Text", 'aa.label'=>"Text", 'aa2.account_number'=>"Text", 'aa.pcg_type'=>'Text', 'aa.active'=>'Status');
263  $this->export_entities_array[$r] = array(); // We define here only fields that use another picto
264 
265  $this->export_sql_start[$r] = 'SELECT DISTINCT ';
266  $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'accounting_account as aa';
267  $this->export_sql_end[$r] .= ' ,'.MAIN_DB_PREFIX.'accounting_system as ac';
268  $this->export_sql_end[$r] .= ' ,'.MAIN_DB_PREFIX.'accounting_account as aa2';
269  $this->export_sql_end[$r] .= ' WHERE ac.pcg_version = aa.fk_pcg_version AND aa.entity IN ('.getEntity('accounting').')';
270  $this->export_sql_end[$r] .= ' AND aa2.rowid = aa.account_parent AND aa2.active = 1 AND ac.pcg_version = aa2.fk_pcg_version AND aa2.entity IN ('.getEntity('accounting').')';
271 
272 
273  // Imports
274  //--------
275  $r = 0;
276 
277  // Chart of accounts
278  $r++;
279  $this->import_code[$r] = $this->rights_class.'_'.$r;
280  $this->import_label[$r] = "Chartofaccounts"; // Translation key
281  $this->import_icon[$r] = $this->picto;
282  $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
283  $this->import_tables_array[$r] = array('aa'=>MAIN_DB_PREFIX.'accounting_account');
284  $this->import_tables_creator_array[$r] = array('aa'=>'fk_user_author'); // Fields to store import user id
285  $this->import_fields_array[$r] = array('aa.fk_pcg_version'=>"Chartofaccounts*", 'aa.account_number'=>"AccountAccounting*", 'aa.label'=>"Label*", 'aa.account_parent'=>"Accountparent", "aa.fk_accounting_category"=>"AccountingCategory", "aa.pcg_type"=>"Pcgtype*", 'aa.active'=>'Status*', 'aa.datec'=>"DateCreation");
286  $this->import_regex_array[$r] = array('aa.fk_pcg_version'=>'pcg_version@'.MAIN_DB_PREFIX.'accounting_system', 'aa.account_number'=>'^.{1,32}$', 'aa.label'=>'^.{1,255}$', 'aa.account_parent'=>'^.{0,32}$', 'aa.fk_accounting_category'=>'rowid@'.MAIN_DB_PREFIX.'c_accounting_category', 'aa.pcg_type'=>'^.{1,20}$', 'aa.active'=>'^0|1$', 'aa.datec'=>'^\d{4}-\d{2}-\d{2}$');
287  $this->import_convertvalue_array[$r] = array(
288  'aa.account_number'=>array('rule'=>'accountingaccount'),
289  'aa.account_parent'=>array('rule'=>'fetchidfromref', 'classfile'=>'/accountancy/class/accountingaccount.class.php', 'class'=>'AccountingAccount', 'method'=>'fetch', 'element'=>'AccountingAccount'),
290  'aa.fk_accounting_category'=>array('rule'=>'fetchidfromcodeorlabel', 'classfile'=>'/accountancy/class/accountancycategory.class.php', 'class'=>'AccountancyCategory', 'method'=>'fetch', 'dict'=>'DictionaryAccountancyCategory'),
291  );
292  $this->import_examplevalues_array[$r] = array('aa.fk_pcg_version'=>"PCG99-ABREGE", 'aa.account_number'=>"707", 'aa.label'=>"Product sales", 'aa.account_parent'=>"ref:7 or id:1407", "aa.fk_accounting_category"=>"", "aa.pcg_type"=>"PROD", 'aa.active'=>'1', 'aa.datec'=>"2017-04-28");
293  $this->import_updatekeys_array[$r] = array('aa.fk_pcg_version'=>'Chartofaccounts', 'aa.account_number'=>'AccountAccounting');
294 
295  // General ledger
296  $r++;
297  $this->import_code[$r] = $this->rights_class.'_'.$r;
298  $this->import_label[$r] = 'ImportAccountingEntries';
299  $this->import_icon[$r] = $this->picto;
300  $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
301  $this->import_tables_array[$r] = array('b'=>MAIN_DB_PREFIX.'accounting_bookkeeping'); // List of tables to insert into (insert done in same order)
302  $this->import_fields_array[$r] = array(
303  'b.piece_num'=>"TransactionNumShort",
304  'b.doc_date'=>"Docdate",
305  //'b.doc_type'=>'Doctype',
306  'b.doc_ref'=>'Piece',
307  'b.code_journal'=>'Codejournal',
308  'b.journal_label'=>'JournalLabel',
309  'b.numero_compte'=>'AccountAccounting',
310  'b.label_compte'=>'LabelAccount',
311  'b.subledger_account'=>'SubledgerAccount',
312  'b.subledger_label'=>'SubledgerAccountLabel',
313  'b.label_operation'=>'LabelOperation',
314  'b.debit'=>"Debit",
315  'b.credit'=>"Credit",
316  'b.sens'=>'Direction' // This field is still used by accounting export. We can remove it once it has been replaced into accountancyexport.class.php by a detection using ->debit and ->credit
317  );
318  $this->import_fieldshidden_array[$r] = array('b.doc_type'=>'const-import_from_external', 'b.fk_doc'=>'const-0', 'b.fk_docdet'=>'const-0', 'b.fk_user_author'=>'user->id', 'b.date_creation'=>'const-'.dol_print_date(dol_now(), 'standard')); // aliastable.field => ('user->id' or 'lastrowid-'.tableparent)
319  $this->import_regex_array[$r] = array('b.doc_date'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$');
320  $this->import_convertvalue_array[$r] = array(
321  'b.numero_compte' => array('rule' => 'accountingaccount'),
322  'b.subledger_account' => array('rule' => 'accountingaccount')
323  );
324  $this->import_examplevalues_array[$r] = array(
325  'b.piece_num'=>'123 (!!! use next value not already used)',
326  'b.doc_date'=>dol_print_date(dol_now(), "%Y-%m-%d"),
327  //'b.doc_type'=>'import',
328  'b.doc_ref'=>'My document ABC',
329  'b.code_journal'=>"VTE",
330  'b.journal_label'=>"Sale journal",
331  'b.numero_compte'=>"707",
332  'b.label_compte'=>'Product account 707',
333  'b.subledger_account'=>'',
334  'b.subledger_label'=>'',
335  'b.label_operation'=>"Sale of ABC",
336  'b.debit'=>"0",
337  'b.credit'=>"100",
338  'b.sens'=>'C' // This field is still used by accounting export. We can remove it once it has been replace into accountancyexport.class.php by a detection using ->debit and ->credit
339  );
340 
341  // General ledger - Fichier FEC
342  $r++;
343  $this->import_code[$r] = $this->rights_class.'_'.$r;
344  $this->import_label[$r] = 'ImportAccountingEntriesFECFormat';
345  $this->import_icon[$r] = $this->picto;
346  $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
347  $this->import_tables_array[$r] = array('b'=>MAIN_DB_PREFIX.'accounting_bookkeeping'); // List of tables to insert into (insert done in same order)
348  $this->import_fields_array[$r] = array(
349  'b.code_journal'=>'FECFormatJournalCode*',
350  'b.journal_label'=>'FECFormatJournalLabel',
351  'b.piece_num'=>'FECFormatEntryNum*',
352  'b.doc_date'=>'FECFormatEntryDate*',
353  'b.numero_compte'=>'FECFormatGeneralAccountNumber*',
354  'b.label_compte'=>'FECFormatGeneralAccountLabel*',
355  'b.subledger_account'=>'FECFormatSubledgerAccountNumber',
356  'b.subledger_label'=>'FECFormatSubledgerAccountLabel',
357  'b.doc_ref'=>'FECFormatPieceRef*',
358  'b.date_creation'=>'FECFormatPieceDate',
359  'b.label_operation'=>'FECFormatLabelOperation',
360  'b.debit'=>'FECFormatDebit*',
361  'b.credit'=>'FECFormatCredit*',
362  'b.lettering_code'=>'FECFormatReconcilableCode',
363  'b.date_lettering'=>'FECFormatReconcilableDate',
364  'b.date_validated'=>'FECFormatValidateDate',
365  'b.multicurrency_amount'=>'FECFormatMulticurrencyAmount',
366  'b.multicurrency_code'=>'FECFormatMulticurrencyCode'
367  );
368  $this->import_fieldshidden_array[$r] = array(
369  'b.doc_type'=>'const-import_from_external',
370  'b.fk_doc'=>'const-0',
371  'b.fk_docdet'=>'const-0',
372  'b.fk_user_author'=>'user->id',
373  'b.montant'=>'rule-computeAmount',
374  'b.sens'=>'rule-computeDirection'
375  ); // aliastable.field => ('user->id' or 'lastrowid-'.tableparent)
376  $this->import_convertvalue_array[$r]=array(
377  'b.piece_num' => array('rule' => 'compute', 'classfile' => '/accountancy/class/accountancyimport.class.php', 'class' => 'AccountancyImport', 'method' => 'cleanValue', 'element' => 'Accountancy'),
378  'b.numero_compte'=>array('rule'=>'accountingaccount'),
379  'b.subledger_account'=>array('rule'=>'accountingaccount'),
380  'b.debit' => array('rule' => 'compute', 'classfile' => '/accountancy/class/accountancyimport.class.php', 'class' => 'AccountancyImport', 'method' => 'cleanAmount', 'element' => 'Accountancy'),
381  'b.credit' => array('rule' => 'compute', 'classfile' => '/accountancy/class/accountancyimport.class.php', 'class' => 'AccountancyImport', 'method' => 'cleanAmount', 'element' => 'Accountancy'),
382  'b.multicurrency_amount' => array('rule' => 'compute', 'classfile' => '/accountancy/class/accountancyimport.class.php', 'class' => 'AccountancyImport', 'method' => 'cleanAmount', 'element' => 'Accountancy'),
383  'b.montant' => array('rule' => 'compute', 'classfile' => '/accountancy/class/accountancyimport.class.php', 'class' => 'AccountancyImport', 'method' => 'computeAmount', 'element' => 'Accountancy'),
384  'b.sens' => array('rule' => 'compute', 'classfile' => '/accountancy/class/accountancyimport.class.php', 'class' => 'AccountancyImport', 'method' => 'computeDirection', 'element' => 'Accountancy'),
385  );
386  $this->import_regex_array[$r] = array(
387  //'b.doc_date'=>'^\d{4}\d{2}\d{2}$',
388  'b.doc_ref'=>'^.{1,300}$',
389  'b.numero_compte'=>'^.{1,32}$',
390  'b.label_compte'=>'^.{1,255}$',
391  'b.subledger_compte'=>'^.{1,32}$',
392  'b.subledger_label'=>'^.{1,255}$',
393  'b.label_operation'=>'^.{1,255}$',
394  //'b.sens'=>'^[D|C]$',
395  );
396  $this->import_examplevalues_array[$r] = array(
397  'b.code_journal'=>"VT",
398  'b.journal_label'=>"Sale journal",
399  'b.piece_num'=>'123 (!!! use next value not already used)',
400  'b.doc_date'=>dol_print_date(dol_now(), "%Y%m%d"),
401  'b.numero_compte'=>"707",
402  'b.label_compte'=>'Sale',
403  'b.subledger_account'=>'',
404  'b.subledger_label'=>'',
405  'b.doc_ref'=>'My document ABC',
406  'b.date_creation'=>dol_print_date(dol_now(), "%Y%m%d"),
407  'b.label_operation'=>"Sale of ABC",
408  'b.debit'=>"0",
409  'b.credit'=>"100",
410  'b.lettering_code'=>'ABC',
411  'b.date_lettering'=>dol_print_date(dol_now(), "%Y%m%d"),
412  'b.date_validated'=>dol_print_date(dol_now(), "%Y%m%d"),
413  'b.multicurrency_amount'=>"90 (Necessary if devise is different than EUR)",
414  'b.multicurrency_code'=>"US (Necessary if devise is different than EUR)",
415  );
416  }
417 }
db
$conf db
API class for accounts.
Definition: inc.php:41
description
print *****$script_file(".$version.") pid cd cd cd description as description
Definition: email_expire_services_to_customers.php:83
name
$conf db name
Definition: repair.php:122
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2514
modAccounting\__construct
__construct($db)
Constructor.
Definition: modAccounting.class.php:40
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2845
DolibarrModules
Class DolibarrModules.
Definition: DolibarrModules.class.php:37
modAccounting
Class to describe and enable double entry accounting module.
Definition: modAccounting.class.php:33