PageRenderTime 49ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/core/lib/bank.lib.php

https://bitbucket.org/speedealing/speedealing
PHP | 225 lines | 132 code | 37 blank | 56 comment | 35 complexity | 0dcc433bcfa1dfce0d503d1e0b99fe6e MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  1. <?php
  2. /* Copyright (C) 2006-2007 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2012 Regis Houssin <regis.houssin@capnetworks.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. * or see http://www.gnu.org/
  18. */
  19. /**
  20. * \file htdocs/core/lib/bank.lib.php
  21. * \brief Ensemble de fonctions de base pour le module banque
  22. * \ingroup banque
  23. */
  24. /**
  25. * Prepare array with list of tabs
  26. *
  27. * @param Object $object Object related to tabs
  28. * @return array Array of tabs to shoc
  29. */
  30. function bank_prepare_head($object)
  31. {
  32. global $langs, $conf, $user;
  33. $h = 0;
  34. $head = array();
  35. $head[$h][0] = DOL_URL_ROOT.'/compta/bank/fiche.php?id='.$object->id;
  36. $head[$h][1] = $langs->trans("AccountCard");
  37. $head[$h][2] = 'bankname';
  38. $h++;
  39. if ($object->type == 0 || $object->type == 1)
  40. {
  41. $head[$h][0] = DOL_URL_ROOT.'/compta/bank/bankid_fr.php?id='.$object->id;
  42. $head[$h][1] = $langs->trans("RIB");
  43. $head[$h][2] = 'bankid';
  44. $h++;
  45. }
  46. $head[$h][0] = DOL_URL_ROOT."/compta/bank/account.php?id=".$object->id;
  47. $head[$h][1] = $langs->trans("Transactions");
  48. $head[$h][2] = 'journal';
  49. $h++;
  50. // if ($conf->global->MAIN_FEATURES_LEVEL >= 1)
  51. // {
  52. $head[$h][0] = DOL_URL_ROOT."/compta/bank/treso.php?account=".$object->id;
  53. $head[$h][1] = $langs->trans("PlannedTransactions");
  54. $head[$h][2] = 'cash';
  55. $h++;
  56. // }
  57. $head[$h][0] = DOL_URL_ROOT."/compta/bank/annuel.php?account=".$object->id;
  58. $head[$h][1] = $langs->trans("IOMonthlyReporting");
  59. $head[$h][2] = 'annual';
  60. $h++;
  61. $head[$h][0] = DOL_URL_ROOT."/compta/bank/graph.php?account=".$object->id;
  62. $head[$h][1] = $langs->trans("Graph");
  63. $head[$h][2] = 'graph';
  64. $h++;
  65. if ($object->courant != 2)
  66. {
  67. $head[$h][0] = DOL_URL_ROOT."/compta/bank/releve.php?account=".$object->id;
  68. $head[$h][1] = $langs->trans("AccountStatements");
  69. $head[$h][2] = 'statement';
  70. $h++;
  71. }
  72. return $head;
  73. }
  74. /**
  75. * Check account number informations for a bank account
  76. *
  77. * @param Account $account A bank account
  78. * @return int True if informations are valid, false otherwise
  79. */
  80. function checkBanForAccount($account)
  81. {
  82. $country_code=$account->getCountryCode();
  83. // For compatibility between
  84. // account of type CompanyBankAccount class (we use number, cle_rib)
  85. // account of type Account class (we use num_compte, cle)
  86. if (empty($account->number)) $account->number=$account->num_compte;
  87. if (empty($account->cle)) $account->cle=$account->cle_rib;
  88. dol_syslog("Bank.lib::checkBanForAccount account->code_banque=".$account->code_banque." account->code_guichet=".$account->code_guichet." account->number=".$account->number." account->cle=".$account->cle." account->iban=".$account->iban." country_code=".$country_code, LOG_DEBUG);
  89. if ($country_code == 'FR') // France rules
  90. {
  91. $coef = array(62, 34, 3);
  92. // Concatenation des differents codes.
  93. $rib = strtolower(trim($account->code_banque).trim($account->code_guichet).trim($account->number).trim($account->cle));
  94. // On remplace les eventuelles lettres par des chiffres.
  95. //$rib = strtr($rib, "abcdefghijklmnopqrstuvwxyz","12345678912345678912345678"); //Ne marche pas
  96. $rib = strtr($rib, "abcdefghijklmnopqrstuvwxyz","12345678912345678923456789");
  97. // Separation du rib en 3 groupes de 7 + 1 groupe de 2.
  98. // Multiplication de chaque groupe par les coef du tableau
  99. for ($i=0, $s=0; $i<3; $i++)
  100. {
  101. $code = substr($rib, 7 * $i, 7);
  102. $s += (0 + $code) * $coef[$i] ;
  103. }
  104. // Soustraction du modulo 97 de $s a 97 pour obtenir la cle
  105. $cle_rib = 97 - ($s % 97);
  106. if ($cle_rib == $account->cle)
  107. {
  108. return true;
  109. }
  110. return false;
  111. }
  112. if ($country_code == 'BE') // Belgium rules
  113. {
  114. }
  115. if ($country_code == 'ES') // Spanish rules
  116. {
  117. $CCC = strtolower(trim($account->number));
  118. $rib = strtolower(trim($account->code_banque).trim($account->code_guichet));
  119. $cle_rib=strtolower(checkES($rib,$CCC));
  120. if ($cle_rib == strtolower($account->cle))
  121. {
  122. return true;
  123. }
  124. return false;
  125. }
  126. if ($country_code == 'AU') // Australian
  127. {
  128. if (strlen($account->code_banque) > 7) return false; // Sould be 6 but can be 123-456
  129. else if (strlen($account->code_banque) < 6) return false; // Sould be 6
  130. else return true;
  131. }
  132. // No particular rule
  133. // If account is CompanyBankAccount class, we use number
  134. // If account is Account class, we use num_compte
  135. if (empty($account->number))
  136. {
  137. return false;
  138. }
  139. return true;
  140. }
  141. /**
  142. * Returns the key for Spanish Banks Accounts
  143. *
  144. * @param string $IentOfi IentOfi
  145. * @param string $InumCta InumCta
  146. * @return string Key
  147. */
  148. function checkES($IentOfi,$InumCta)
  149. {
  150. if (empty($IentOfi)||empty($InumCta)||strlen($IentOfi)!=8||strlen($InumCta)!=10)
  151. {
  152. $keycontrol ="";
  153. return $keycontrol;
  154. }
  155. $ccc= $IentOfi . $InumCta;
  156. $numbers = "1234567890";
  157. $i = 0;
  158. while ($i<=strlen($ccc)-1)
  159. {
  160. if (strpos($numbers,substr($ccc,$i,1)) === false)
  161. {
  162. $keycontrol ="";
  163. return $keycontrol;
  164. }
  165. $i++;
  166. }
  167. $values = array(1,2,4,8,5,10,9,7,3,6);
  168. $sum = 0;
  169. for($i=2; $i<10; $i++)
  170. {
  171. $sum += $values[$i] * substr($IentOfi, $i-2, 1);
  172. }
  173. $key = 11-$sum%11;
  174. if ($key==10) $key=1;
  175. if ($key==11) $key=0;
  176. $keycontrol = $key;
  177. $sum = 0;
  178. for($i=0; $i<11; $i++)
  179. {
  180. $sum += $values[$i] * substr($InumCta,$i, 1);
  181. }
  182. $key = 11-$sum%11;
  183. if ($key==10) $key=1;
  184. if ($key==11) $key=0;
  185. $keycontrol .= $key;
  186. return $keycontrol;
  187. }
  188. ?>