fiscalyear.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <?php
  2. /* Copyright (C) 2013-2016 Alexandre Spangaro <aspangaro@zendsi.com>
  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")?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. $langs->load("admin");
  38. $langs->load("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 shoul 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. }
  79. $sql.= $db->plimit($limit+1, $offset);
  80. $result = $db->query($sql);
  81. if ($result) {
  82. $var = false;
  83. $num = $db->num_rows($result);
  84. $i = 0;
  85. $title = $langs->trans('AccountingPeriods');
  86. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $params, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'title_accountancy', 0, '', '', $limit, 1);
  87. // Load attribute_label
  88. print '<table class="noborder" width="100%">';
  89. print '<tr class="liste_titre">';
  90. print '<td>' . $langs->trans("Ref") . '</td>';
  91. print '<td>' . $langs->trans("Label") . '</td>';
  92. print '<td>' . $langs->trans("DateStart") . '</td>';
  93. print '<td>' . $langs->trans("DateEnd") . '</td>';
  94. print '<td align="right">' . $langs->trans("Statut") . '</td>';
  95. print '</tr>';
  96. if ($num) {
  97. $fiscalyearstatic = new Fiscalyear($db);
  98. while ( $i < $num && $i < $max ) {
  99. $obj = $db->fetch_object($result);
  100. $fiscalyearstatic->id = $obj->rowid;
  101. print '<tr class="oddeven">';
  102. print '<td><a href="fiscalyear_card.php?id=' . $obj->rowid . '">' . img_object($langs->trans("ShowFiscalYear"), "technic") . ' ' . $obj->rowid . '</a></td>';
  103. print '<td align="left">' . $obj->label . '</td>';
  104. print '<td align="left">' . dol_print_date($db->jdate($obj->date_start), 'day') . '</td>';
  105. print '<td align="left">' . dol_print_date($db->jdate($obj->date_end), 'day') . '</td>';
  106. print '<td align="right">' . $fiscalyearstatic->LibStatut($obj->statut, 5) . '</td>';
  107. print '</tr>';
  108. $var = ! $var;
  109. $i ++;
  110. }
  111. } else {
  112. print '<tr class="oddeven"><td colspan="5" class="opacitymedium">' . $langs->trans("None") . '</td></tr>';
  113. }
  114. print '</table>';
  115. } else {
  116. dol_print_error($db);
  117. }
  118. dol_fiche_end();
  119. // Buttons
  120. print '<div class="tabsAction">';
  121. if (! empty($user->rights->accounting->fiscalyear))
  122. {
  123. print '<a class="butAction" href="fiscalyear_card.php?action=create">' . $langs->trans("NewFiscalYear") . '</a>';
  124. }
  125. else
  126. {
  127. print '<a class="butActionRefused" href="#">' . $langs->trans("NewFiscalYear") . '</a>';
  128. }
  129. print '</div>';
  130. llxFooter();
  131. $db->close();