box_accountancy_suspense_account.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. /* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2009 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2019 Alexandre Spangaro <aspangaro@open-dsi.fr>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/core/boxes/box_accountancy_suspense_account.php
  22. * \ingroup Accountancy
  23. * \brief Module to generated widget of suspense account
  24. */
  25. include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
  26. /**
  27. * Class to manage the box to show suspense account
  28. */
  29. class box_accountancy_suspense_account extends ModeleBoxes
  30. {
  31. public $boxcode = "accountancy_suspense_account";
  32. public $boximg = "accounting";
  33. public $boxlabel = "BoxSuspenseAccount";
  34. public $depends = array("accounting");
  35. /**
  36. * @var DoliDB Database handler.
  37. */
  38. public $db;
  39. public $param;
  40. public $info_box_head = array();
  41. public $info_box_contents = array();
  42. /**
  43. * Constructor
  44. *
  45. * @param DoliDB $db Database handler
  46. * @param string $param More parameters
  47. */
  48. public function __construct($db, $param)
  49. {
  50. global $user;
  51. $this->db = $db;
  52. $this->hidden = empty($user->rights->accounting->mouvements->lire);
  53. }
  54. /**
  55. * Load data for box to show them later
  56. *
  57. * @return void
  58. */
  59. public function loadBox()
  60. {
  61. global $user, $langs, $conf;
  62. include_once DOL_DOCUMENT_ROOT.'/accountancy/class/bookkeeping.class.php';
  63. //$bookkeepingstatic = new BookKeeping($this->db);
  64. $this->info_box_head = array('text' => $langs->trans("BoxTitleSuspenseAccount"));
  65. if ($user->hasRight('accounting', 'mouvements, 'lire')) {
  66. $suspenseAccount = $conf->global->ACCOUNTING_ACCOUNT_SUSPENSE;
  67. if (!empty($suspenseAccount) && $suspenseAccount > 0) {
  68. $sql = "SELECT COUNT(*) as nb_suspense_account";
  69. $sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as b";
  70. $sql .= " WHERE b.numero_compte = '".$this->db->escape($suspenseAccount)."'";
  71. $sql .= " AND b.entity = ".$conf->entity;
  72. $result = $this->db->query($sql);
  73. $nbSuspenseAccount = 0;
  74. if ($result) {
  75. $obj = $this->db->fetch_object($result);
  76. $nbSuspenseAccount = $obj->nb_suspense_account;
  77. }
  78. $this->info_box_contents[0][0] = array(
  79. 'td' => '',
  80. 'text' => $langs->trans("NumberOfLinesInSuspenseAccount").':'
  81. );
  82. $this->info_box_contents[0][1] = array(
  83. 'td' => 'class="right"',
  84. 'text' => '<a href="'.DOL_URL_ROOT.'/accountancy/bookkeeping/list.php?search_accountancy_code_start='.urlencode($suspenseAccount).'&search_accountancy_code_end='.urlencode($suspenseAccount).'">'.$nbSuspenseAccount.'</a>',
  85. 'asis' => 1
  86. );
  87. } else {
  88. $this->info_box_contents[0][0] = array(
  89. 'td' => 'class="nohover"',
  90. 'text' => '<span class="opacitymedium">'.$langs->trans("SuspenseAccountNotDefined").'</span>'
  91. );
  92. }
  93. } else {
  94. $this->info_box_contents[0][0] = array(
  95. 'td' => 'class="nohover"',
  96. 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
  97. );
  98. }
  99. }
  100. /**
  101. * Method to show box
  102. *
  103. * @param array $head Array with properties of box title
  104. * @param array $contents Array with properties of box lines
  105. * @param int $nooutput No print, only return string
  106. * @return string
  107. */
  108. public function showBox($head = null, $contents = null, $nooutput = 0)
  109. {
  110. return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
  111. }
  112. }