fiscalyear.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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 <http://www.gnu.org/licenses/>.
  16. */
  17. /**
  18. * \file htdocs/accountancy/admin/fiscalyear.php
  19. * \ingroup Advanced accountancy
  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. if (! empty($user->rights->accounting->fiscalyear))
  91. {
  92. $addbutton = '<a class="butActionNew" href="fiscalyear_card.php?action=create"><span class="valignmiddle">' . $langs->trans("NewFiscalYear") .'</span><span class="fa fa-plus-circle valignmiddle"></span></a>';
  93. }
  94. else
  95. {
  96. $addbutton = '<a class="butActionRefused classfortooltip" href="#"><span class="valignmiddle" title="'.dol_escape_htmltag($langs->trans("NotAllowed")).'">' . $langs->trans("NewFiscalYear") .'</span><span class="fa fa-plus-circle valignmiddle"></span></a>';
  97. }
  98. $title = $langs->trans('AccountingPeriods');
  99. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $params, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'title_accountancy', 0, $addbutton, '', $limit, 1);
  100. // Load attribute_label
  101. print '<div class="div-table-responsive">';
  102. print '<table class="tagtable liste" width="100%">';
  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 align="center">' . $langs->trans("NumberOfAccountancyEntries") . '</td>';
  109. print '<td align="center">' . $langs->trans("NumberOfAccountancyMovements") . '</td>';
  110. print '<td class="right">' . $langs->trans("Statut") . '</td>';
  111. print '</tr>';
  112. if ($num) {
  113. $fiscalyearstatic = new Fiscalyear($db);
  114. while ( $i < $num && $i < $max ) {
  115. $obj = $db->fetch_object($result);
  116. $fiscalyearstatic->id = $obj->rowid;
  117. print '<tr class="oddeven">';
  118. print '<td><a href="fiscalyear_card.php?id=' . $obj->rowid . '">' . img_object($langs->trans("ShowFiscalYear"), "technic") . ' ' . $obj->rowid . '</a></td>';
  119. print '<td class="left">' . $obj->label . '</td>';
  120. print '<td class="left">' . dol_print_date($db->jdate($obj->date_start), 'day') . '</td>';
  121. print '<td class="left">' . dol_print_date($db->jdate($obj->date_end), 'day') . '</td>';
  122. print '<td align="center">' . $object->getAccountancyEntriesByFiscalYear($obj->date_start, $obj->date_end) . '</td>';
  123. print '<td align="center">' . $object->getAccountancyMovementsByFiscalYear($obj->date_start, $obj->date_end) . '</td>';
  124. print '<td class="right">' . $fiscalyearstatic->LibStatut($obj->statut, 5) . '</td>';
  125. print '</tr>';
  126. $i++;
  127. }
  128. } else {
  129. print '<tr class="oddeven"><td colspan="5" class="opacitymedium">' . $langs->trans("None") . '</td></tr>';
  130. }
  131. print '</table>';
  132. print '</div>';
  133. } else {
  134. dol_print_error($db);
  135. }
  136. // End of page
  137. llxFooter();
  138. $db->close();