fiscalyear.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <?php
  2. /* Copyright (C) 2013-2024 Alexandre Spangaro <aspangaro@easya.solutions>
  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. $error = 0;
  47. $errors = array();
  48. // List of status
  49. static $tmpstatut2label = array(
  50. '0' => 'OpenFiscalYear',
  51. '1' => 'CloseFiscalYear'
  52. );
  53. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  54. $object = new Fiscalyear($db);
  55. $hookmanager->initHooks(array('fiscalyearlist'));
  56. // Security check
  57. if ($user->socid > 0) {
  58. accessforbidden();
  59. }
  60. if (!$user->hasRight('accounting', 'fiscalyear', 'write')) { // If we can read accounting records, we should be able to see fiscal year.
  61. accessforbidden();
  62. }
  63. /*
  64. * Actions
  65. */
  66. /*
  67. * View
  68. */
  69. $max = 100;
  70. $form = new Form($db);
  71. $fiscalyearstatic = new Fiscalyear($db);
  72. $title = $langs->trans('AccountingPeriods');
  73. $help_url = 'EN:Module_Double_Entry_Accounting#Setup|FR:Module_Comptabilit&eacute;_en_Partie_Double#Configuration';
  74. llxHeader('', $title, $help_url);
  75. $sql = "SELECT f.rowid, f.label, f.date_start, f.date_end, f.statut as status, f.entity";
  76. $sql .= " FROM ".MAIN_DB_PREFIX."accounting_fiscalyear as f";
  77. $sql .= " WHERE f.entity = ".$conf->entity;
  78. $sql .= $db->order($sortfield, $sortorder);
  79. // Count total nb of records
  80. $nbtotalofrecords = '';
  81. if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
  82. $result = $db->query($sql);
  83. $nbtotalofrecords = $db->num_rows($result);
  84. if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
  85. $page = 0;
  86. $offset = 0;
  87. }
  88. }
  89. $sql .= $db->plimit($limit + 1, $offset);
  90. $result = $db->query($sql);
  91. if ($result) {
  92. $num = $db->num_rows($result);
  93. $param = '';
  94. $parameters = array('param' => $param);
  95. $reshook = $hookmanager->executeHooks('addMoreActionsButtonsList', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  96. if ($reshook < 0) {
  97. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  98. }
  99. $newcardbutton = empty($hookmanager->resPrint) ? '' : $hookmanager->resPrint;
  100. if (empty($reshook)) {
  101. $newcardbutton .= dolGetButtonTitle($langs->trans('NewFiscalYear'), '', 'fa fa-plus-circle', 'fiscalyear_card.php?action=create', '', $user->hasRight('accounting', 'fiscalyear', 'write'));
  102. }
  103. $title = $langs->trans('AccountingPeriods');
  104. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'calendar', 0, $newcardbutton, '', $limit, 1);
  105. print '<div class="div-table-responsive">';
  106. print '<table class="tagtable liste centpercent">';
  107. print '<tr class="liste_titre">';
  108. print '<td>'.$langs->trans("Ref").'</td>';
  109. print '<td>'.$langs->trans("Label").'</td>';
  110. print '<td>'.$langs->trans("DateStart").'</td>';
  111. print '<td>'.$langs->trans("DateEnd").'</td>';
  112. print '<td class="center">'.$langs->trans("NumberOfAccountancyEntries").'</td>';
  113. print '<td class="center">'.$langs->trans("NumberOfAccountancyMovements").'</td>';
  114. print '<td class="right">'.$langs->trans("Status").'</td>';
  115. print '</tr>';
  116. // Loop on record
  117. // --------------------------------------------------------------------
  118. $i = 0;
  119. if ($num) {
  120. while ($i < $num && $i < $max) {
  121. $obj = $db->fetch_object($result);
  122. $fiscalyearstatic->ref = $obj->rowid;
  123. $fiscalyearstatic->id = $obj->rowid;
  124. $fiscalyearstatic->date_start = $obj->date_start;
  125. $fiscalyearstatic->date_end = $obj->date_end;
  126. $fiscalyearstatic->statut = $obj->status;
  127. $fiscalyearstatic->status = $obj->status;
  128. print '<tr class="oddeven">';
  129. print '<td>';
  130. print $fiscalyearstatic->getNomUrl(1);
  131. print '</td>';
  132. print '<td class="left">'.$obj->label.'</td>';
  133. print '<td class="left">'.dol_print_date($db->jdate($obj->date_start), 'day').'</td>';
  134. print '<td class="left">'.dol_print_date($db->jdate($obj->date_end), 'day').'</td>';
  135. print '<td class="center">'.$object->getAccountancyEntriesByFiscalYear($obj->date_start, $obj->date_end).'</td>';
  136. print '<td class="center">'.$object->getAccountancyMovementsByFiscalYear($obj->date_start, $obj->date_end).'</td>';
  137. print '<td class="right">'.$fiscalyearstatic->LibStatut($obj->status, 5).'</td>';
  138. print '</tr>';
  139. $i++;
  140. }
  141. } else {
  142. print '<tr class="oddeven"><td colspan="7"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
  143. }
  144. print '</table>';
  145. print '</div>';
  146. } else {
  147. dol_print_error($db);
  148. }
  149. // End of page
  150. llxFooter();
  151. $db->close();