box_comptes.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <?php
  2. /* Copyright (C) 2005 Christophe
  3. * Copyright (C) 2005-2013 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2013 Juanjo Menent <jmenent@2byte.es>
  6. * Copyright (C) 2015 Frederic France <frederic.france@free.fr>
  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. * \file htdocs/core/boxes/box_comptes.php
  23. * \ingroup banque
  24. * \brief Module to generate box for bank accounts
  25. */
  26. include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
  27. include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  28. /**
  29. * Class to manage the box to show last users
  30. */
  31. class box_comptes extends ModeleBoxes
  32. {
  33. public $boxcode = "currentaccounts";
  34. public $boximg = "bank_account";
  35. public $boxlabel = "BoxCurrentAccounts";
  36. public $depends = array("banque"); // Box active if module banque active
  37. /**
  38. * @var DoliDB Database handler.
  39. */
  40. public $db;
  41. public $param;
  42. public $enabled = 1;
  43. public $info_box_head = array();
  44. public $info_box_contents = array();
  45. /**
  46. * Constructor
  47. *
  48. * @param DoliDB $db Database handler
  49. * @param string $param More parameters
  50. */
  51. public function __construct($db, $param = '')
  52. {
  53. global $conf, $user;
  54. $this->db = $db;
  55. // disable module for such cases
  56. $listofmodulesforexternal = explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL);
  57. if (!in_array('banque', $listofmodulesforexternal) && !empty($user->socid)) {
  58. $this->enabled = 0; // disabled for external users
  59. }
  60. $this->hidden = !($user->rights->banque->lire);
  61. }
  62. /**
  63. * Load data into info_box_contents array to show array later.
  64. *
  65. * @param int $max Maximum number of records to load
  66. * @return void
  67. */
  68. public function loadBox($max = 5)
  69. {
  70. global $user, $langs, $conf;
  71. $this->max = $max;
  72. $this->info_box_head = array('text' => $langs->trans("BoxTitleCurrentAccounts"));
  73. if ($user->rights->banque->lire) {
  74. $sql = "SELECT b.rowid, b.ref, b.label, b.bank,b.number, b.courant, b.clos, b.rappro, b.url";
  75. $sql .= ", b.code_banque, b.code_guichet, b.cle_rib, b.bic, b.iban_prefix as iban";
  76. $sql .= ", b.domiciliation, b.proprio, b.owner_address";
  77. $sql .= ", b.account_number, b.currency_code";
  78. $sql .= ", b.min_allowed, b.min_desired, comment";
  79. $sql .= ', b.fk_accountancy_journal';
  80. $sql .= ', aj.code as accountancy_journal';
  81. $sql .= " FROM ".MAIN_DB_PREFIX."bank_account as b";
  82. $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'accounting_journal as aj ON aj.rowid=b.fk_accountancy_journal';
  83. $sql .= " WHERE b.entity = ".$conf->entity;
  84. $sql .= " AND clos = 0";
  85. //$sql.= " AND courant = 1";
  86. $sql .= " ORDER BY label";
  87. $sql .= $this->db->plimit($max, 0);
  88. dol_syslog(get_class($this)."::loadBox", LOG_DEBUG);
  89. $result = $this->db->query($sql);
  90. if ($result) {
  91. $num = $this->db->num_rows($result);
  92. $line = 0;
  93. $solde_total = array();
  94. $account_static = new Account($this->db);
  95. while ($line < $num) {
  96. $objp = $this->db->fetch_object($result);
  97. $account_static->id = $objp->rowid;
  98. $account_static->ref = $objp->ref;
  99. $account_static->label = $objp->label;
  100. $account_static->number = $objp->number;
  101. $account_static->account_number = $objp->account_number;
  102. $account_static->currency_code = $objp->currency_code;
  103. $account_static->accountancy_journal = $objp->accountancy_journal;
  104. $solde = $account_static->solde(0);
  105. $solde_total[$objp->currency_code] += $solde;
  106. $this->info_box_contents[$line][] = array(
  107. 'td' => '',
  108. 'text' => $account_static->getNomUrl(1),
  109. 'asis' => 1,
  110. );
  111. $this->info_box_contents[$line][] = array(
  112. 'td' => '',
  113. 'text' => $objp->number,
  114. );
  115. $this->info_box_contents[$line][] = array(
  116. 'td' => 'class="right nowraponall"',
  117. 'text' => price($solde, 0, $langs, 1, -1, -1, $objp->currency_code)
  118. );
  119. $line++;
  120. }
  121. // Total
  122. foreach ($solde_total as $key => $solde) {
  123. $this->info_box_contents[$line][] = array(
  124. 'tr' => 'class="liste_total"',
  125. 'td' => 'class="liste_total left"',
  126. 'text' => $langs->trans('Total').' '.$key,
  127. );
  128. $this->info_box_contents[$line][] = array(
  129. 'td' => 'class="liste_total right"',
  130. 'text' => '&nbsp;'
  131. );
  132. $this->info_box_contents[$line][] = array(
  133. 'td' => 'class="liste_total right nowraponall"',
  134. 'text' => price($solde, 0, $langs, 0, -1, -1, $key)
  135. );
  136. $line++;
  137. }
  138. $this->db->free($result);
  139. } else {
  140. $this->info_box_contents[0][0] = array(
  141. 'td' => '',
  142. 'maxlength'=>500,
  143. 'text' => ($this->db->error().' sql='.$sql),
  144. );
  145. }
  146. } else {
  147. $this->info_box_contents[0][0] = array(
  148. 'td' => 'class="nohover opacitymedium left"',
  149. 'text' => $langs->trans("ReadPermissionNotAllowed")
  150. );
  151. }
  152. }
  153. /**
  154. * Method to show box
  155. *
  156. * @param array $head Array with properties of box title
  157. * @param array $contents Array with properties of box lines
  158. * @param int $nooutput No print, only return string
  159. * @return string
  160. */
  161. public function showBox($head = null, $contents = null, $nooutput = 0)
  162. {
  163. return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
  164. }
  165. }