fiscalyear.php 4.6 KB

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