dolibarr  16.0.5
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 {
38 
44  public function __construct($db)
45  {
46  global $conf;
47 
48  $this->db = $db;
49  $this->numero = 85;
50 
51  $this->family = "financial";
52  $this->module_position = '51';
53  // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
54  $this->name = preg_replace('/^mod/i', '', get_class($this));
55  $this->description = "Gestion des comptes financiers de type Comptes bancaires ou postaux";
56 
57  // Possible values for version are: 'development', 'experimental', 'dolibarr' or version
58  $this->version = 'dolibarr';
59 
60  $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
61  $this->picto = 'account';
62 
63  // Data directories to create when module is enabled
64  $this->dirs = array("/banque/temp");
65 
66  // Config pages
67  //-------------
68  $this->config_page_url = array("bank.php");
69 
70  // Dependancies
71  $this->depends = array();
72  $this->requiredby = array("modComptabilite", "modAccounting", "modPrelevement");
73  $this->conflictwith = array();
74  $this->langfiles = array("banks", "compta", "bills", "companies", "accounting");
75 
76  // Constants
77  $this->const = array();
78 
79  // Boxes
80  $this->boxes = array(0=>array('file'=>'box_comptes.php', 'enabledbydefaulton'=>'Home'));
81 
82  // Permissions
83  $this->rights = array();
84  $this->rights_class = 'banque';
85  $r = 0;
86 
87  $r++;
88  $this->rights[$r][0] = 111; // id de la permission
89  $this->rights[$r][1] = 'Read bank account and transactions';
90  $this->rights[$r][2] = 'r';
91  $this->rights[$r][3] = 0;
92  $this->rights[$r][4] = 'lire';
93 
94  $r++;
95  $this->rights[$r][0] = 112; // id de la permission
96  $this->rights[$r][1] = 'Creer/modifier montant/supprimer ecriture bancaire';
97  $this->rights[$r][2] = 'w';
98  $this->rights[$r][3] = 0;
99  $this->rights[$r][4] = 'modifier';
100 
101  $r++;
102  $this->rights[$r][0] = 113; // id de la permission
103  $this->rights[$r][1] = 'Configurer les comptes bancaires (creer, gerer categories)';
104  $this->rights[$r][2] = 'a';
105  $this->rights[$r][3] = 0;
106  $this->rights[$r][4] = 'configurer';
107 
108  $r++;
109  $this->rights[$r][0] = 114; // id de la permission
110  $this->rights[$r][1] = 'Rapprocher les ecritures bancaires';
111  $this->rights[$r][2] = 'w';
112  $this->rights[$r][3] = 0;
113  $this->rights[$r][4] = 'consolidate';
114 
115  $r++;
116  $this->rights[$r][0] = 115; // id de la permission
117  $this->rights[$r][1] = 'Exporter transactions et releves';
118  $this->rights[$r][2] = 'r';
119  $this->rights[$r][3] = 0;
120  $this->rights[$r][4] = 'export';
121 
122  $r++;
123  $this->rights[$r][0] = 116; // id de la permission
124  $this->rights[$r][1] = 'Virements entre comptes';
125  $this->rights[$r][2] = 'w';
126  $this->rights[$r][3] = 0;
127  $this->rights[$r][4] = 'transfer';
128 
129  $r++;
130  $this->rights[$r][0] = 117; // id de la permission
131  $this->rights[$r][1] = 'Gerer les envois de cheques';
132  $this->rights[$r][2] = 'w';
133  $this->rights[$r][3] = 0;
134  $this->rights[$r][4] = 'cheque';
135 
136 
137  // Menus
138  //-------
139  $this->menu = 1; // This module add menu entries. They are coded into menu manager.
140 
141 
142  // Exports
143  //--------
144  $r = 0;
145 
146  // Bank lines
147  $r++;
148  $this->export_code[$r] = $this->rights_class.'_'.$r;
149  $this->export_label[$r] = 'Ecritures bancaires et releves';
150  $this->export_permission[$r] = array(array("banque", "export"));
151  $this->export_fields_array[$r] = array(
152  'b.rowid'=>'IdTransaction', 'ba.ref'=>'AccountRef', 'ba.label'=>'AccountLabel', 'b.datev'=>'DateValue', 'b.dateo'=>'DateOperation', 'b.label'=>'Label',
153  'b.num_chq'=>'ChequeOrTransferNumber', 'b.fk_bordereau'=>'ChequeBordereau', '-b.amount'=>'Debit', 'b.amount'=>'Credit',
154  'b.num_releve'=>'AccountStatement', 'b.rappro'=>'BankLineReconciled', 'b.datec'=>"DateCreation", "bu.url_id"=>"IdThirdParty",
155  "s.nom"=>"ThirdParty", "s.code_compta"=>"CustomerAccountancyCode", "s.code_compta_fournisseur"=>"SupplierAccountancyCode"
156  );
157  $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");
158  $this->export_entities_array[$r] = array(
159  'b.rowid'=>'account', 'ba.ref'=>'account', 'ba.label'=>'account', 'b.datev'=>'account', 'b.dateo'=>'account', 'b.label'=>'account',
160  'b.num_chq'=>'account', 'b.fk_bordereau'=>'account', '-b.amount'=>'account', 'b.amount'=>'account',
161  'b.num_releve'=>'account', 'b.rappro'=>'account', 'b.datec'=>"account", "bu.url_id"=>"company",
162  "s.nom"=>"company", "s.code_compta"=>"company", "s.code_compta_fournisseur"=>"company"
163  );
164  $this->export_special_array[$r] = array('-b.amount'=>'NULLIFNEG', 'b.amount'=>'NULLIFNEG');
165  if ((empty($conf->fournisseur->enabled) && !empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || empty($conf->supplier_order->enabled) || empty($conf->supplier_invoice->enabled)) {
166  unset($this->export_fields_array[$r]['s.code_compta_fournisseur']);
167  unset($this->export_entities_array[$r]['s.code_compta_fournisseur']);
168  }
169  $this->export_sql_start[$r] = 'SELECT DISTINCT ';
170  $this->export_sql_end[$r] = ' FROM ('.MAIN_DB_PREFIX.'bank_account as ba, '.MAIN_DB_PREFIX.'bank as b)';
171  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX."bank_url as bu ON (bu.fk_bank = b.rowid AND bu.type = 'company')";
172  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON bu.url_id = s.rowid';
173  $this->export_sql_end[$r] .= ' WHERE ba.rowid = b.fk_account';
174  $this->export_sql_end[$r] .= ' AND ba.entity IN ('.getEntity('bank_account').')';
175  $this->export_sql_order[$r] = ' ORDER BY b.datev, b.num_releve';
176 
177  //
178  $r++;
179  $this->export_code[$r] = $this->rights_class.'_'.$r;
180  $this->export_label[$r] = 'Bordereaux remise Chq/Fact';
181  $this->export_permission[$r] = array(array("banque", "export"));
182  $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",
183  "bch.date_bordereau"=>"Date", "bch.amount"=>"Total", "bch.nbcheque"=>"NbCheque", "bu.url_id"=>"IdThirdParty", "s.nom"=>"ThirdParty", "s.code_compta"=>"CustomerAccountancyCode", "f.ref"=>"InvoiceRef"
184  );
185  $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",
186  "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"
187  );
188  $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",
189  "bu.url_id"=>"company", "s.nom"=>"company", "s.code_compta"=>"company", "s.code_compta_fournisseur"=>"company", "f.ref"=>"invoice");
190  $this->export_special_array[$r] = array('b.amount'=>'NULLIFNEG');
191 
192  $this->export_sql_start[$r] = 'SELECT DISTINCT ';
193  $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)';
194  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX."bank_url as bu ON (bu.fk_bank = b.rowid AND bu.type = 'company')";
195  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiement as p ON b.rowid = p.fk_bank';
196  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiement_facture as pf ON p.rowid = pf.fk_paiement';
197  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'facture as f ON f.rowid = pf.fk_facture';
198  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON f.fk_soc = s.rowid';
199  $this->export_sql_end[$r] .= ' WHERE ba.rowid = b.fk_account AND bch.rowid = b.fk_bordereau and bch.fk_bank_account=ba.rowid';
200  $this->export_sql_end[$r] .= " AND b.fk_type = 'CHQ'";
201  $this->export_sql_end[$r] .= ' AND p.fk_paiement = 7';
202  $this->export_sql_end[$r] .= ' AND ba.entity IN ('.getEntity('bank_account').')';
203  $this->export_sql_order[$r] = ' ORDER BY b.datev, b.num_releve';
204 
205  // Various Payment
206  $r++;
207  $this->export_code[$r] = $this->rights_class.'_'.$r;
208  $this->export_label[$r] = 'VariousPayment';
209  $this->export_permission[$r] = array(array("banque", "export"));
210  $this->export_fields_array[$r] = array(
211  'v.rowid'=>'VariousPaymentId', 'v.label'=>'VariousPaymentLabel', 'v.datev'=>'DateValue', 'v.datep'=>'DateOperation',
212  'v.num_payment'=>'ChequeOrTransferNumber', 'v.amount'=>'Amount', 'v.sens'=>'Sens',
213  'cp.id'=>"PaymentMode",
214  'v.accountancy_code'=>'AccountAccounting', 'v.subledger_account'=>'SubledgerAccount',
215  'v.note'=>'Note', 'v.datec'=>'DateCreation',
216  'p.ref'=>'ProjectRef', 'p.title'=>'ProjectLabel'
217  );
218  $this->export_TypeFields_array[$r] = array(
219  'v.rowid'=>'Text', 'v.label'=>'Text', 'v.datep'=>'Date', 'v.datev'=>'Date',
220  'v.num_payment'=>'Text', 'v.amount'=>'Numeric', 'v.sens'=>'Numeric',
221  'cp.id'=>'List:c_paiement:code:id:code',
222  "v.accountancy_code"=>"Text", "v.subledger_account"=>"Text",
223  "v.note"=>"Text", 'v.datec'=>"Date",
224  "p.ref"=>"Text", "p.title"=>"Text"
225  );
226  $this->export_entities_array[$r] = array(
227  'v.rowid'=>'payment', 'v.label'=>'payment', 'v.datev'=>'payment', 'v.datep'=>'payment',
228  'v.num_payment'=>'payment', 'v.amount'=>'payment', 'v.sens'=>'payment',
229  'cp.id'=>'payment',
230  'v.accountancy_code'=>'payment', 'v.subledger_account'=>"payment",
231  'v.note'=>"payment", 'v.datec'=>"payment",
232  "p.ref"=>"project", "p.title"=>"project"
233  );
234  $this->export_sql_start[$r] = 'SELECT ';
235  $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'payment_various as v';
236  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX."projet as p ON v.fk_projet = p.rowid";
237  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX."c_paiement as cp ON v.fk_typepayment = cp.id";
238  $this->export_sql_end[$r] .= ' WHERE v.entity IN ('.getEntity('payment_various').')';
239  $this->export_sql_order[$r] = ' ORDER BY v.datep';
240  }
241 
242 
251  public function init($options = '')
252  {
253  global $conf;
254 
255  // Permissions
256  $this->remove($options);
257 
258  $sql = array();
259 
260  return $this->_init($sql, $options);
261  }
262 }
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
modBanque\__construct
__construct($db)
Constructor.
Definition: modBanque.class.php:44
name
$conf db name
Definition: repair.php:122
modBanque\init
init($options='')
Function called when module is enabled.
Definition: modBanque.class.php:251
modBanque
Class to describe and enable module Banque.
Definition: modBanque.class.php:36
DolibarrModules\_init
_init($array_sql, $options='')
Enables a module.
Definition: DolibarrModules.class.php:383
DolibarrModules
Class DolibarrModules.
Definition: DolibarrModules.class.php:37