dolibarr  9.0.0
fiscalyear.php
Go to the documentation of this file.
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 
24 require '../../main.inc.php';
25 require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
26 require_once DOL_DOCUMENT_ROOT . '/core/class/fiscalyear.class.php';
27 
28 $action = GETPOST('action','aZ09');
29 
30 // Load variable for pagination
31 $limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
32 $sortfield = GETPOST('sortfield','alpha');
33 $sortorder = GETPOST('sortorder','alpha');
34 $page = GETPOST('page','int');
35 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
36 $offset = $limit * $page;
37 $pageprev = $page - 1;
38 $pagenext = $page + 1;
39 if (! $sortfield) $sortfield="f.rowid"; // Set here default search field
40 if (! $sortorder) $sortorder="ASC";
41 
42 // Load translation files required by the page
43 $langs->loadLangs(array("admin","compta"));
44 
45 // Security check
46 if ($user->societe_id > 0)
48 if (! $user->rights->accounting->fiscalyear) // If we can read accounting records, we shoul be able to see fiscal year.
50 
51 $error = 0;
52 
53 // List of status
54 static $tmpstatut2label = array (
55  '0' => 'OpenFiscalYear',
56  '1' => 'CloseFiscalYear'
57 );
58 $statut2label = array (
59  ''
60 );
61 foreach ( $tmpstatut2label as $key => $val )
62  $statut2label[$key] = $langs->trans($val);
63 
64 $errors = array ();
65 
66 $object = new Fiscalyear($db);
67 
68 
69 /*
70  * Actions
71  */
72 
73 
74 
75 /*
76  * View
77  */
78 
79 $max = 100;
80 
81 $form = new Form($db);
82 
83 $title = $langs->trans('AccountingPeriods');
84 $helpurl = "";
85 llxHeader('', $title, $helpurl);
86 
87 $sql = "SELECT f.rowid, f.label, f.date_start, f.date_end, f.statut, f.entity";
88 $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_fiscalyear as f";
89 $sql .= " WHERE f.entity = " . $conf->entity;
90 $sql.=$db->order($sortfield,$sortorder);
91 
92 // Count total nb of records
93 $nbtotalofrecords = '';
94 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
95 {
96  $result = $db->query($sql);
97  $nbtotalofrecords = $db->num_rows($result);
98  if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0
99  {
100  $page = 0;
101  $offset = 0;
102  }
103 }
104 
105 $sql.= $db->plimit($limit+1, $offset);
106 
107 $result = $db->query($sql);
108 if ($result)
109 {
110  $num = $db->num_rows($result);
111 
112  $i = 0;
113 
114  if (! empty($user->rights->accounting->fiscalyear))
115  {
116  $addbutton = '<a class="butAction" href="fiscalyear_card.php?action=create">' . $langs->trans("NewFiscalYear") . '</a>';
117  }
118  else
119  {
120  $addbutton = '<a class="butActionRefused" href="#">' . $langs->trans("NewFiscalYear") . '</a>';
121  }
122 
123  $title = $langs->trans('AccountingPeriods');
124  print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $params, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'title_accountancy', 0, $addbutton, '', $limit, 1);
125 
126  // Load attribute_label
127  print '<table class="noborder" width="100%">';
128  print '<tr class="liste_titre">';
129  print '<td>' . $langs->trans("Ref") . '</td>';
130  print '<td>' . $langs->trans("Label") . '</td>';
131  print '<td>' . $langs->trans("DateStart") . '</td>';
132  print '<td>' . $langs->trans("DateEnd") . '</td>';
133  print '<td align="right">' . $langs->trans("Statut") . '</td>';
134  print '</tr>';
135 
136  if ($num) {
137  $fiscalyearstatic = new Fiscalyear($db);
138 
139  while ( $i < $num && $i < $max ) {
140  $obj = $db->fetch_object($result);
141  $fiscalyearstatic->id = $obj->rowid;
142  print '<tr class="oddeven">';
143  print '<td><a href="fiscalyear_card.php?id=' . $obj->rowid . '">' . img_object($langs->trans("ShowFiscalYear"), "technic") . ' ' . $obj->rowid . '</a></td>';
144  print '<td align="left">' . $obj->label . '</td>';
145  print '<td align="left">' . dol_print_date($db->jdate($obj->date_start), 'day') . '</td>';
146  print '<td align="left">' . dol_print_date($db->jdate($obj->date_end), 'day') . '</td>';
147  print '<td align="right">' . $fiscalyearstatic->LibStatut($obj->statut, 5) . '</td>';
148  print '</tr>';
149  $i++;
150  }
151  } else {
152  print '<tr class="oddeven"><td colspan="5" class="opacitymedium">' . $langs->trans("None") . '</td></tr>';
153  }
154  print '</table>';
155 } else {
156  dol_print_error($db);
157 }
158 
159 // End of page
160 llxFooter();
161 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:56
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print
Draft customers invoices.
Definition: index.php:91
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Class to manage generation of HTML components Only common components must be here.
print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='title_generic.png', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0)
Print a title with navigation controls for pagination.
Class to manage fiscal year.
llxHeader()
Empty header.
Definition: wrapper.php:44
dol_print_date($time, $format='', $tzoutput='tzserver', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)