dolibarr  20.0.0-beta
modBanque.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2003-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2008 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
5  * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
6  * Copyright (C) 2008-2011 Regis Houssin <regis.houssin@inodbox.com>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <https://www.gnu.org/licenses/>.
20  */
21 
30 include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
31 
32 
37 {
43  public function __construct($db)
44  {
45  global $conf;
46 
47  $this->db = $db;
48  $this->numero = 85;
49 
50  $this->family = "financial";
51  $this->module_position = '51';
52  // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
53  $this->name = preg_replace('/^mod/i', '', get_class($this));
54  $this->description = "Gestion des comptes financiers de type Comptes bancaires ou postaux";
55 
56  // Possible values for version are: 'development', 'experimental', 'dolibarr' or version
57  $this->version = 'dolibarr';
58 
59  $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
60  $this->picto = 'account';
61 
62  // Data directories to create when module is enabled
63  $this->dirs = array("/banque/temp");
64 
65  // Config pages
66  //-------------
67  $this->config_page_url = array("bank.php");
68 
69  // Dependencies
70  $this->depends = array();
71  $this->requiredby = array("modComptabilite", "modAccounting", "modPrelevement");
72  $this->conflictwith = array();
73  $this->langfiles = array("banks", "compta", "bills", "companies", "accounting");
74 
75  // Constants
76  $this->const = array();
77 
78  // Boxes
79  $this->boxes = array(0=>array('file'=>'box_comptes.php', 'enabledbydefaulton'=>'Home'));
80 
81  // Permissions
82  $this->rights = array();
83  $this->rights_class = 'banque';
84  $r = 0;
85 
86  $r++;
87  $this->rights[$r][0] = 111; // id de la permission
88  $this->rights[$r][1] = 'Read bank account and transactions';
89  $this->rights[$r][2] = 'r';
90  $this->rights[$r][3] = 0;
91  $this->rights[$r][4] = 'lire';
92 
93  $r++;
94  $this->rights[$r][0] = 112; // id de la permission
95  $this->rights[$r][1] = 'Creer/modifier montant/supprimer ecriture bancaire';
96  $this->rights[$r][2] = 'w';
97  $this->rights[$r][3] = 0;
98  $this->rights[$r][4] = 'modifier';
99 
100  $r++;
101  $this->rights[$r][0] = 113; // id de la permission
102  $this->rights[$r][1] = 'Configurer les comptes bancaires (creer, gerer categories)';
103  $this->rights[$r][2] = 'a';
104  $this->rights[$r][3] = 0;
105  $this->rights[$r][4] = 'configurer';
106 
107  $r++;
108  $this->rights[$r][0] = 114; // id de la permission
109  $this->rights[$r][1] = 'Rapprocher les ecritures bancaires';
110  $this->rights[$r][2] = 'w';
111  $this->rights[$r][3] = 0;
112  $this->rights[$r][4] = 'consolidate';
113 
114  $r++;
115  $this->rights[$r][0] = 115; // id de la permission
116  $this->rights[$r][1] = 'Exporter transactions et releves';
117  $this->rights[$r][2] = 'r';
118  $this->rights[$r][3] = 0;
119  $this->rights[$r][4] = 'export';
120 
121  $r++;
122  $this->rights[$r][0] = 116; // id de la permission
123  $this->rights[$r][1] = 'Virements entre comptes';
124  $this->rights[$r][2] = 'w';
125  $this->rights[$r][3] = 0;
126  $this->rights[$r][4] = 'transfer';
127 
128  $r++;
129  $this->rights[$r][0] = 117; // id de la permission
130  $this->rights[$r][1] = 'Gerer les envois de cheques';
131  $this->rights[$r][2] = 'w';
132  $this->rights[$r][3] = 0;
133  $this->rights[$r][4] = 'cheque';
134 
135 
136  // Menus
137  //-------
138  $this->menu = 1; // This module add menu entries. They are coded into menu manager.
139 
140 
141  // Exports
142  //--------
143  $r = 0;
144 
145  // Bank lines
146  $r++;
147  $this->export_code[$r] = $this->rights_class.'_'.$r;
148  $this->export_label[$r] = 'Ecritures bancaires et releves';
149  $this->export_permission[$r] = array(array("banque", "export"));
150  $this->export_fields_array[$r] = array(
151  'b.rowid'=>'IdTransaction', 'ba.ref'=>'AccountRef', 'ba.label'=>'AccountLabel', 'b.datev'=>'DateValue', 'b.dateo'=>'DateOperation', 'b.label'=>'Label',
152  'b.num_chq'=>'ChequeOrTransferNumber', 'b.fk_bordereau'=>'ChequeBordereau', '-b.amount'=>'Debit', 'b.amount'=>'Credit',
153  'b.num_releve'=>'AccountStatement', 'b.rappro'=>'BankLineReconciled', 'b.datec'=>"DateCreation", "bu.url_id"=>"IdThirdParty",
154  "s.nom"=>"ThirdParty", "s.code_compta"=>"CustomerAccountancyCode", "s.code_compta_fournisseur"=>"SupplierAccountancyCode"
155  );
156  $this->export_TypeFields_array[$r] = array('ba.ref'=>'Text', 'ba.label'=>'Text', 'b.datev'=>'Date', 'b.dateo'=>'Date', 'b.label'=>'Text', 'b.num_chq'=>'Text', 'b.fk_bordereau'=>'Text', '-b.amount'=>'Numeric', 'b.amount'=>'Numeric', 'b.num_releve'=>'Text', 'b.rappro'=>'Boolean', 'b.datec'=>"Date", "bu.url_id"=>"Text", "s.nom"=>"Text", "s.code_compta"=>"Text", "s.code_compta_fournisseur"=>"Text");
157  $this->export_entities_array[$r] = array(
158  'b.rowid'=>'account', 'ba.ref'=>'account', 'ba.label'=>'account', 'b.datev'=>'account', 'b.dateo'=>'account', 'b.label'=>'account',
159  'b.num_chq'=>'account', 'b.fk_bordereau'=>'account', '-b.amount'=>'account', 'b.amount'=>'account',
160  'b.num_releve'=>'account', 'b.rappro'=>'account', 'b.datec'=>"account", "bu.url_id"=>"company",
161  "s.nom"=>"company", "s.code_compta"=>"company", "s.code_compta_fournisseur"=>"company"
162  );
163  $this->export_special_array[$r] = array('-b.amount'=>'NULLIFNEG', 'b.amount'=>'NULLIFNEG');
164  if (!isModEnabled('supplier_order') && !isModEnabled('supplier_invoice')) {
165  unset($this->export_fields_array[$r]['s.code_compta_fournisseur']);
166  unset($this->export_entities_array[$r]['s.code_compta_fournisseur']);
167  }
168  $this->export_sql_start[$r] = 'SELECT DISTINCT ';
169  $this->export_sql_end[$r] = ' FROM ('.MAIN_DB_PREFIX.'bank_account as ba, '.MAIN_DB_PREFIX.'bank as b)';
170  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX."bank_url as bu ON (bu.fk_bank = b.rowid AND bu.type = 'company')";
171  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON bu.url_id = s.rowid';
172  $this->export_sql_end[$r] .= ' WHERE ba.rowid = b.fk_account';
173  $this->export_sql_end[$r] .= ' AND ba.entity IN ('.getEntity('bank_account').')';
174  $this->export_sql_order[$r] = ' ORDER BY b.datev, b.num_releve';
175 
176  //
177  $r++;
178  $this->export_code[$r] = $this->rights_class.'_'.$r;
179  $this->export_label[$r] = 'Bordereaux remise Chq/Fact';
180  $this->export_permission[$r] = array(array("banque", "export"));
181  $this->export_fields_array[$r] = array("bch.rowid"=>"DepositId", "bch.ref"=>"Numero", "bch.ref_ext"=>"RefExt", 'ba.ref'=>'AccountRef', 'ba.label'=>'AccountLabel', 'b.datev'=>'DateValue', 'b.num_chq'=>'ChequeOrTransferNumber', 'b.amount'=>'Credit', 'b.num_releve'=>'AccountStatement', 'b.datec'=>"DateCreation",
182  "bch.date_bordereau"=>"Date", "bch.amount"=>"Total", "bch.nbcheque"=>"NbCheque", "bu.url_id"=>"IdThirdParty", "s.nom"=>"ThirdParty", "s.code_compta"=>"CustomerAccountancyCode", "f.ref"=>"InvoiceRef"
183  );
184  $this->export_TypeFields_array[$r] = array('ba.ref'=>'Text', 'ba.label'=>'Text', 'b.datev'=>'Date', 'b.num_chq'=>'Text', 'b.amount'=>'Numeric', 'b.num_releve'=>'Text', 'b.datec'=>"Date",
185  "bch.date_bordereau"=>"Date", "bch.rowid"=>"Numeric", "bch.ref"=>"Numeric", "bch.ref_ext"=>"Text", "bch.amount"=>"Numeric", "bch.nbcheque"=>"Numeric", "bu.url_id"=>"Text", "s.nom"=>"Text", "s.code_compta"=>"Text", "f.ref"=>"Text"
186  );
187  $this->export_entities_array[$r] = array('ba.ref'=>'account', 'ba.label'=>'account', 'b.datev'=>'account', 'b.num_chq'=>'account', 'b.amount'=>'account', 'b.num_releve'=>'account', 'b.datec'=>"account",
188  "bu.url_id"=>"company", "s.nom"=>"company", "s.code_compta"=>"company", "s.code_compta_fournisseur"=>"company", "f.ref"=>"invoice");
189  $this->export_special_array[$r] = array('b.amount'=>'NULLIFNEG');
190 
191  $this->export_sql_start[$r] = 'SELECT DISTINCT ';
192  $this->export_sql_end[$r] = ' FROM ('.MAIN_DB_PREFIX.'bordereau_cheque as bch, '.MAIN_DB_PREFIX.'bank_account as ba, '.MAIN_DB_PREFIX.'bank as b)';
193  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX."bank_url as bu ON (bu.fk_bank = b.rowid AND bu.type = 'company')";
194  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiement as p ON b.rowid = p.fk_bank';
195  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiement_facture as pf ON p.rowid = pf.fk_paiement';
196  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'facture as f ON f.rowid = pf.fk_facture';
197  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON f.fk_soc = s.rowid';
198  $this->export_sql_end[$r] .= ' WHERE ba.rowid = b.fk_account AND bch.rowid = b.fk_bordereau and bch.fk_bank_account=ba.rowid';
199  $this->export_sql_end[$r] .= " AND b.fk_type = 'CHQ'";
200  $this->export_sql_end[$r] .= ' AND p.fk_paiement = 7';
201  $this->export_sql_end[$r] .= ' AND ba.entity IN ('.getEntity('bank_account').')';
202  $this->export_sql_order[$r] = ' ORDER BY b.datev, b.num_releve';
203 
204  // Various Payment
205  $r++;
206  $this->export_code[$r] = $this->rights_class.'_'.$r;
207  $this->export_label[$r] = 'VariousPayment';
208  $this->export_permission[$r] = array(array("banque", "export"));
209  $this->export_fields_array[$r] = array(
210  'v.rowid'=>'VariousPaymentId', 'v.label'=>'VariousPaymentLabel', 'v.datev'=>'DateValue', 'v.datep'=>'DateOperation',
211  'v.num_payment'=>'ChequeOrTransferNumber', 'v.amount'=>'Amount', 'v.sens'=>'Sens',
212  'cp.id'=>"PaymentMode",
213  'v.accountancy_code'=>'AccountAccounting', 'v.subledger_account'=>'SubledgerAccount',
214  'v.note'=>'Note', 'v.datec'=>'DateCreation',
215  'p.ref'=>'ProjectRef', 'p.title'=>'ProjectLabel'
216  );
217  $this->export_TypeFields_array[$r] = array(
218  'v.rowid'=>'Text', 'v.label'=>'Text', 'v.datep'=>'Date', 'v.datev'=>'Date',
219  'v.num_payment'=>'Text', 'v.amount'=>'Numeric', 'v.sens'=>'Numeric',
220  'cp.id'=>'List:c_paiement:code:id:code',
221  "v.accountancy_code"=>"Text", "v.subledger_account"=>"Text",
222  "v.note"=>"Text", 'v.datec'=>"Date",
223  "p.ref"=>"Text", "p.title"=>"Text"
224  );
225  $this->export_entities_array[$r] = array(
226  'v.rowid'=>'payment', 'v.label'=>'payment', 'v.datev'=>'payment', 'v.datep'=>'payment',
227  'v.num_payment'=>'payment', 'v.amount'=>'payment', 'v.sens'=>'payment',
228  'cp.id'=>'payment',
229  'v.accountancy_code'=>'payment', 'v.subledger_account'=>"payment",
230  'v.note'=>"payment", 'v.datec'=>"payment",
231  "p.ref"=>"project", "p.title"=>"project"
232  );
233  $this->export_sql_start[$r] = 'SELECT ';
234  $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'payment_various as v';
235  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX."projet as p ON v.fk_projet = p.rowid";
236  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX."c_paiement as cp ON v.fk_typepayment = cp.id";
237  $this->export_sql_end[$r] .= ' WHERE v.entity IN ('.getEntity('payment_various').')';
238  $this->export_sql_order[$r] = ' ORDER BY v.datep';
239  }
240 
241 
250  public function init($options = '')
251  {
252  global $conf;
253 
254  // Permissions
255  $this->remove($options);
256 
257  $sql = array();
258 
259  return $this->_init($sql, $options);
260  }
261 }
Class DolibarrModules.
_init($array_sql, $options='')
Enables a module.
Class to describe and enable module Banque.
__construct($db)
Constructor.
init($options='')
Function called when module is enabled.
if(isModEnabled('invoice') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&!getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') && $user->hasRight('tax', 'charges', 'lire')) if(isModEnabled('invoice') &&isModEnabled('order') && $user->hasRight("commande", "lire") &&!getDolGlobalString('WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER')) $sql
Social contributions to pay.
Definition: index.php:745
print *****$script_file(".$version.") pid cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
isModEnabled($module)
Is Dolibarr module enabled.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:126