PageRenderTime 45ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

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

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