fiscalyear.php 5.2 KB

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