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