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 <https://www.gnu.org/licenses/>. 16 */ 17 18/** 19 * \file htdocs/accountancy/admin/fiscalyear.php 20 * \ingroup Accountancy (Double entries) 21 * \brief Setup page to configure fiscal year 22 */ 23 24require '../../main.inc.php'; 25require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; 26require_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', 'aZ09comma'); 33$sortorder = GETPOST('sortorder', 'aZ09comma'); 34$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); 35if (empty($page) || $page == -1) { 36 $page = 0; 37} // If $page is not defined, or '' or -1 38$offset = $limit * $page; 39$pageprev = $page - 1; 40$pagenext = $page + 1; 41if (!$sortfield) { 42 $sortfield = "f.rowid"; // Set here default search field 43} 44if (!$sortorder) { 45 $sortorder = "ASC"; 46} 47 48// Load translation files required by the page 49$langs->loadLangs(array("admin", "compta")); 50 51// Security check 52if ($user->socid > 0) { 53 accessforbidden(); 54} 55if (!$user->rights->accounting->fiscalyear->write) { // If we can read accounting records, we should be able to see fiscal year. 56 accessforbidden(); 57} 58 59$error = 0; 60 61// List of status 62static $tmpstatut2label = array( 63 '0' => 'OpenFiscalYear', 64 '1' => 'CloseFiscalYear' 65); 66$statut2label = array( 67 '' 68); 69foreach ($tmpstatut2label as $key => $val) { 70 $statut2label[$key] = $langs->trans($val); 71} 72 73$errors = array(); 74 75$object = new Fiscalyear($db); 76 77 78/* 79 * Actions 80 */ 81 82 83 84/* 85 * View 86 */ 87 88$max = 100; 89 90$form = new Form($db); 91$fiscalyearstatic = new Fiscalyear($db); 92 93$title = $langs->trans('AccountingPeriods'); 94 95$help_url = "EN:Module_Double_Entry_Accounting"; 96 97llxHeader('', $title, $help_url); 98 99$sql = "SELECT f.rowid, f.label, f.date_start, f.date_end, f.statut, f.entity"; 100$sql .= " FROM ".MAIN_DB_PREFIX."accounting_fiscalyear as f"; 101$sql .= " WHERE f.entity = ".$conf->entity; 102$sql .= $db->order($sortfield, $sortorder); 103 104// Count total nb of records 105$nbtotalofrecords = ''; 106if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { 107 $result = $db->query($sql); 108 $nbtotalofrecords = $db->num_rows($result); 109 if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0 110 $page = 0; 111 $offset = 0; 112 } 113} 114 115$sql .= $db->plimit($limit + 1, $offset); 116 117$result = $db->query($sql); 118if ($result) { 119 $num = $db->num_rows($result); 120 121 $i = 0; 122 123 124 $addbutton .= dolGetButtonTitle($langs->trans('NewFiscalYear'), '', 'fa fa-plus-circle', 'fiscalyear_card.php?action=create', '', $user->rights->accounting->fiscalyear->write); 125 126 127 $title = $langs->trans('AccountingPeriods'); 128 print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $params, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'title_accountancy', 0, $addbutton, '', $limit, 1); 129 130 // Load attribute_label 131 print '<div class="div-table-responsive">'; 132 print '<table class="tagtable liste centpercent">'; 133 print '<tr class="liste_titre">'; 134 print '<td>'.$langs->trans("Ref").'</td>'; 135 print '<td>'.$langs->trans("Label").'</td>'; 136 print '<td>'.$langs->trans("DateStart").'</td>'; 137 print '<td>'.$langs->trans("DateEnd").'</td>'; 138 print '<td class="center">'.$langs->trans("NumberOfAccountancyEntries").'</td>'; 139 print '<td class="center">'.$langs->trans("NumberOfAccountancyMovements").'</td>'; 140 print '<td class="right">'.$langs->trans("Statut").'</td>'; 141 print '</tr>'; 142 143 if ($num) { 144 while ($i < $num && $i < $max) { 145 $obj = $db->fetch_object($result); 146 147 $fiscalyearstatic->id = $obj->rowid; 148 149 print '<tr class="oddeven">'; 150 print '<td>'; 151 print $fiscalyearstatic->getNomUrl(1); 152 print '</td>'; 153 print '<td class="left">'.$obj->label.'</td>'; 154 print '<td class="left">'.dol_print_date($db->jdate($obj->date_start), 'day').'</td>'; 155 print '<td class="left">'.dol_print_date($db->jdate($obj->date_end), 'day').'</td>'; 156 print '<td class="center">'.$object->getAccountancyEntriesByFiscalYear($obj->date_start, $obj->date_end).'</td>'; 157 print '<td class="center">'.$object->getAccountancyMovementsByFiscalYear($obj->date_start, $obj->date_end).'</td>'; 158 print '<td class="right">'.$fiscalyearstatic->LibStatut($obj->statut, 5).'</td>'; 159 print '</tr>'; 160 $i++; 161 } 162 } else { 163 print '<tr class="oddeven"><td colspan="7" class="opacitymedium">'.$langs->trans("None").'</td></tr>'; 164 } 165 print '</table>'; 166 print '</div>'; 167} else { 168 dol_print_error($db); 169} 170 171// End of page 172llxFooter(); 173$db->close(); 174