dolibarr 18.0.6
index.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2019 Open-DSI <support@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
24// Load Dolibarr environment
25require '../../main.inc.php';
26require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
27require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
28require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
29require_once DOL_DOCUMENT_ROOT.'/accountancy/class/bookkeeping.class.php';
30
31// Load translation files required by the page
32$langs->loadLangs(array("compta", "bills", "other", "accountancy"));
33
34$validatemonth = GETPOST('validatemonth', 'int');
35$validateyear = GETPOST('validateyear', 'int');
36
37$action = GETPOST('action', 'aZ09');
38
39$object = new BookKeeping($db);
40
41$month_start = ($conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1);
42if (GETPOST("year", 'int')) {
43 $year_start = GETPOST("year", 'int');
44} else {
45 $year_start = dol_print_date(dol_now(), '%Y');
46 if (dol_print_date(dol_now(), '%m') < $month_start) {
47 $year_start--; // If current month is lower that starting fiscal month, we start last year
48 }
49}
50$year_end = $year_start + 1;
51$month_end = $month_start - 1;
52if ($month_end < 1) {
53 $month_end = 12;
54 $year_end--;
55}
56$search_date_start = dol_mktime(0, 0, 0, $month_start, 1, $year_start);
57$search_date_end = dol_get_last_day($year_end, $month_end);
58$year_current = $year_start;
59
60// Security check
61if (!isModEnabled('accounting')) {
63}
64if ($user->socid > 0) {
66}
67if (!$user->hasRight('accounting', 'fiscalyear', 'write')) {
69}
70
71
72
73/*
74 * Actions
75 */
76
77$now = dol_now();
78
79if ($action == 'validate_movements_confirm' && $user->hasRight('accounting', 'fiscalyear', 'write')) {
80 $date_start = dol_mktime(0, 0, 0, GETPOST('date_startmonth', 'int'), GETPOST('date_startday', 'int'), GETPOST('date_startyear', 'int'));
81 $date_end = dol_mktime(23, 59, 59, GETPOST('date_endmonth', 'int'), GETPOST('date_endday', 'int'), GETPOST('date_endyear', 'int'));
82
83 $error = 0;
84
85 $db->begin();
86
87 // Specify as export : update field date_validated on selected month/year
88 $sql = " UPDATE ".MAIN_DB_PREFIX."accounting_bookkeeping";
89 $sql .= " SET date_validated = '".$db->idate($now)."'";
90 $sql .= " WHERE entity = " . ((int) $conf->entity);
91 $sql .= " AND doc_date >= '" . $db->idate($date_start) . "'";
92 $sql .= " AND doc_date <= '" . $db->idate($date_end) . "'";
93 $sql .= " AND date_validated IS NULL";
94
95 dol_syslog("/accountancy/closure/index.php action=validate_movement_confirm -> Set movements as validated", LOG_DEBUG);
96 $result = $db->query($sql);
97 if (!$result) {
98 $error++;
99 }
100
101 if (!$error) {
102 $db->commit();
103
104 setEventMessages($langs->trans("AllMovementsWereRecordedAsValidated"), null, 'mesgs');
105
106 header("Location: ".$_SERVER['PHP_SELF']."?year=".$year_start);
107 exit;
108 } else {
109 $db->rollback();
110
111 setEventMessages($langs->trans("NotAllMovementsCouldBeRecordedAsValidated"), null, 'errors');
112 $action = '';
113 }
114}
115
116
117/*
118 * View
119 */
120
121$form = new Form($db);
122$formaccounting = new FormAccounting($db);
123
124$title = $langs->trans('Closure');
125
126$help_url ='EN:Module_Double_Entry_Accounting';
127
128llxHeader('', $title, $help_url);
129
130if ($action == 'validate_movements') {
131 $form_question = array();
132
133 $month = isset($conf->global->SOCIETE_FISCAL_MONTH_START) ? intval($conf->global->SOCIETE_FISCAL_MONTH_START) : 1;
134 $date_start = new DateTime(sprintf('%04d-%02d-%02d', $year_start, $month, 1));
135 $date_end = new DateTime(sprintf('%04d-%02d-%02d', $year_start, $month, 1));
136 $date_end->add(new DateInterval('P1Y'));
137 $date_end->sub(new DateInterval('P1D'));
138
139 $form_question['date_start'] = array(
140 'name' => 'date_start',
141 'type' => 'date',
142 'label' => $langs->trans('DateStart'),
143 'value' => $date_start->format('Y-m-d')
144 );
145 $form_question['date_end'] = array(
146 'name' => 'date_end',
147 'type' => 'date',
148 'label' => $langs->trans('DateEnd'),
149 'value' => $date_end->format('Y-m-d')
150 );
151
152 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?year='.$year_start, $langs->trans('ValidateMovements'), $langs->trans('DescValidateMovements', $langs->transnoentitiesnoconv("RegistrationInAccounting")), 'validate_movements_confirm', $form_question, '', 1, 300);
153 print $formconfirm;
154}
155
156$textprevyear = '<a href="'.$_SERVER["PHP_SELF"].'?year='.($year_current - 1).'">'.img_previous().'</a>';
157$textnextyear = '&nbsp;<a href="'.$_SERVER["PHP_SELF"].'?year='.($year_current + 1).'">'.img_next().'</a>';
158
159
160print load_fiche_titre($langs->trans("Closure")." ".$textprevyear." ".$langs->trans("Year")." ".$year_start." ".$textnextyear, '', 'title_accountancy');
161
162print '<span class="opacitymedium">'.$langs->trans("DescClosure").'</span><br>';
163print '<br>';
164
165
166$y = $year_current;
167
168$buttonvalidate = '<a class="butAction" name="button_validate_movements" href="'.$_SERVER["PHP_SELF"].'?action=validate_movements&year='.$year_start.'">'.$langs->trans("ValidateMovements").'</a>';
169
170print_barre_liste($langs->trans("OverviewOfMovementsNotValidated"), '', '', '', '', '', '', -1, '', '', 0, $buttonvalidate, '', 0, 1, 0);
171
172print '<div class="div-table-responsive-no-min">';
173print '<table class="noborder centpercent">';
174for ($i = 1; $i <= 12; $i++) {
175 $j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START ? $conf->global->SOCIETE_FISCAL_MONTH_START : 1) - 1;
176 if ($j > 12) {
177 $j -= 12;
178 }
179 print '<td width="60" class="right">'.$langs->trans('MonthShort'.str_pad($j, 2, '0', STR_PAD_LEFT)).'</td>';
180}
181print '<td width="60" class="right"><b>'.$langs->trans("Total").'</b></td></tr>';
182
183if (getDolGlobalString("ACCOUNTANCY_DISABLE_CLOSURE_LINE_BY_LINE")) {
184 // TODO Analyse is done by finding record not into a closed period
185 $sql = "SELECT COUNT(b.rowid) as detail,";
186 for ($i = 1; $i <= 12; $i++) {
187 $j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START ? $conf->global->SOCIETE_FISCAL_MONTH_START : 1) - 1;
188 if ($j > 12) {
189 $j -= 12;
190 }
191 $sql .= " SUM(".$db->ifsql("MONTH(b.doc_date)=".$j, "1", "0").") AS month".str_pad($j, 2, "0", STR_PAD_LEFT).",";
192 }
193 $sql .= " COUNT(b.rowid) as total";
194 $sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as b";
195 $sql .= " WHERE b.doc_date >= '".$db->idate($search_date_start)."'";
196 $sql .= " AND b.doc_date <= '".$db->idate($search_date_end)."'";
197 $sql .= " AND b.entity IN (".getEntity('bookkeeping', 0).")"; // We don't share object for accountancy
198 // Loop on each closed period
199 $sql .= " AND b.doc_date BETWEEN 0 AND 0";
200} else {
201 // Analyse closed record using the unitary flag/date on each record
202 $sql = "SELECT COUNT(b.rowid) as detail,";
203 for ($i = 1; $i <= 12; $i++) {
204 $j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START ? $conf->global->SOCIETE_FISCAL_MONTH_START : 1) - 1;
205 if ($j > 12) {
206 $j -= 12;
207 }
208 $sql .= " SUM(".$db->ifsql("MONTH(b.doc_date)=".$j, "1", "0").") AS month".str_pad($j, 2, "0", STR_PAD_LEFT).",";
209 }
210 $sql .= " COUNT(b.rowid) as total";
211 $sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as b";
212 $sql .= " WHERE b.doc_date >= '".$db->idate($search_date_start)."'";
213 $sql .= " AND b.doc_date <= '".$db->idate($search_date_end)."'";
214 $sql .= " AND b.entity IN (".getEntity('bookkeeping', 0).")"; // We don't share object for accountancy
215 $sql .= " AND date_validated IS NULL";
216}
217
218dol_syslog('htdocs/accountancy/closure/index.php', LOG_DEBUG);
219$resql = $db->query($sql);
220if ($resql) {
221 $num = $db->num_rows($resql);
222
223 while ($row = $db->fetch_row($resql)) {
224 print '<tr class="oddeven">';
225 for ($i = 1; $i <= 12; $i++) {
226 print '<td class="right">'.$row[$i].'</td>';
227 }
228 print '<td class="right"><b>'.$row[13].'</b></td>';
229 print '</tr>';
230 }
231
232 $db->free($resql);
233} else {
234 print $db->lasterror(); // Show last sql error
235}
236print "</table>\n";
237print '</div>';
238
239// End of page
240llxFooter();
241$db->close();
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:56
llxFooter()
Empty footer.
Definition wrapper.php:70
Class to manage Ledger (General Ledger and Subledger)
Class to manage generation of HTML components for accounting management.
Class to manage generation of HTML components Only common components must be here.
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition date.lib.php:597
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
img_previous($titlealt='default', $moreatt='')
Show previous logo.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
img_next($titlealt='default', $moreatt='')
Show next logo.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.