fiscalyear.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <?php
  2. /* Copyright (C) 2013-2018 Alexandre Spangaro <aspangaro@open-dsi.fr>
  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 3 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 <https://www.gnu.org/licenses/>.
  16. */
  17. /**
  18. * \file htdocs/accountancy/admin/fiscalyear.php
  19. * \ingroup Accountancy (Double entries)
  20. * \brief Setup page to configure fiscal year
  21. */
  22. // Load Dolibarr environment
  23. require '../../main.inc.php';
  24. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/class/fiscalyear.class.php';
  26. $action = GETPOST('action', 'aZ09');
  27. // Load variable for pagination
  28. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  29. $sortfield = GETPOST('sortfield', 'aZ09comma');
  30. $sortorder = GETPOST('sortorder', 'aZ09comma');
  31. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  32. if (empty($page) || $page == -1) {
  33. $page = 0;
  34. } // If $page is not defined, or '' or -1
  35. $offset = $limit * $page;
  36. $pageprev = $page - 1;
  37. $pagenext = $page + 1;
  38. if (!$sortfield) {
  39. $sortfield = "f.rowid"; // Set here default search field
  40. }
  41. if (!$sortorder) {
  42. $sortorder = "ASC";
  43. }
  44. // Load translation files required by the page
  45. $langs->loadLangs(array("admin", "compta"));
  46. // Security check
  47. if ($user->socid > 0) {
  48. accessforbidden();
  49. }
  50. if (!$user->hasRight('accounting', 'fiscalyear', 'write')) { // If we can read accounting records, we should be able to see fiscal year.
  51. accessforbidden();
  52. }
  53. $error = 0;
  54. // List of status
  55. static $tmpstatut2label = array(
  56. '0' => 'OpenFiscalYear',
  57. '1' => 'CloseFiscalYear'
  58. );
  59. $statut2label = array(
  60. ''
  61. );
  62. foreach ($tmpstatut2label as $key => $val) {
  63. $statut2label[$key] = $langs->trans($val);
  64. }
  65. $errors = array();
  66. $object = new Fiscalyear($db);
  67. /*
  68. * Actions
  69. */
  70. /*
  71. * View
  72. */
  73. $max = 100;
  74. $form = new Form($db);
  75. $fiscalyearstatic = new Fiscalyear($db);
  76. $title = $langs->trans('AccountingPeriods');
  77. $help_url = "EN:Module_Double_Entry_Accounting";
  78. llxHeader('', $title, $help_url);
  79. $sql = "SELECT f.rowid, f.label, f.date_start, f.date_end, f.statut, f.entity";
  80. $sql .= " FROM ".MAIN_DB_PREFIX."accounting_fiscalyear as f";
  81. $sql .= " WHERE f.entity = ".$conf->entity;
  82. $sql .= $db->order($sortfield, $sortorder);
  83. // Count total nb of records
  84. $nbtotalofrecords = '';
  85. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
  86. $result = $db->query($sql);
  87. $nbtotalofrecords = $db->num_rows($result);
  88. if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
  89. $page = 0;
  90. $offset = 0;
  91. }
  92. }
  93. $sql .= $db->plimit($limit + 1, $offset);
  94. $result = $db->query($sql);
  95. if ($result) {
  96. $num = $db->num_rows($result);
  97. $i = 0;
  98. $addbutton .= dolGetButtonTitle($langs->trans('NewFiscalYear'), '', 'fa fa-plus-circle', 'fiscalyear_card.php?action=create', '', $user->hasRight('accounting', 'fiscalyear', 'write'));
  99. $title = $langs->trans('AccountingPeriods');
  100. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $params, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'title_accountancy', 0, $addbutton, '', $limit, 1);
  101. print '<div class="div-table-responsive">';
  102. print '<table class="tagtable liste centpercent">';
  103. print '<tr class="liste_titre">';
  104. print '<td>'.$langs->trans("Ref").'</td>';
  105. print '<td>'.$langs->trans("Label").'</td>';
  106. print '<td>'.$langs->trans("DateStart").'</td>';
  107. print '<td>'.$langs->trans("DateEnd").'</td>';
  108. print '<td class="center">'.$langs->trans("NumberOfAccountancyEntries").'</td>';
  109. print '<td class="center">'.$langs->trans("NumberOfAccountancyMovements").'</td>';
  110. print '<td class="right">'.$langs->trans("Statut").'</td>';
  111. print '</tr>';
  112. if ($num) {
  113. while ($i < $num && $i < $max) {
  114. $obj = $db->fetch_object($result);
  115. $fiscalyearstatic->id = $obj->rowid;
  116. print '<tr class="oddeven">';
  117. print '<td>';
  118. print $fiscalyearstatic->getNomUrl(1);
  119. print '</td>';
  120. print '<td class="left">'.$obj->label.'</td>';
  121. print '<td class="left">'.dol_print_date($db->jdate($obj->date_start), 'day').'</td>';
  122. print '<td class="left">'.dol_print_date($db->jdate($obj->date_end), 'day').'</td>';
  123. print '<td class="center">'.$object->getAccountancyEntriesByFiscalYear($obj->date_start, $obj->date_end).'</td>';
  124. print '<td class="center">'.$object->getAccountancyMovementsByFiscalYear($obj->date_start, $obj->date_end).'</td>';
  125. print '<td class="right">'.$fiscalyearstatic->LibStatut($obj->statut, 5).'</td>';
  126. print '</tr>';
  127. $i++;
  128. }
  129. } else {
  130. print '<tr class="oddeven"><td colspan="7" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
  131. }
  132. print '</table>';
  133. print '</div>';
  134. } else {
  135. dol_print_error($db);
  136. }
  137. // End of page
  138. llxFooter();
  139. $db->close();