modBanque.class.php 12 KB

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