27require
'../../main.inc.php';
28require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
29require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
30require_once DOL_DOCUMENT_ROOT.
'/core/class/fiscalyear.class.php';
31require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formaccounting.class.php';
32require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/bookkeeping.class.php';
43$langs->loadLangs(array(
"accountancy",
"bills",
"compta",
"exports",
"other"));
45$action =
GETPOST(
'action',
'aZ09');
46$confirm =
GETPOST(
'confirm',
'aZ09');
47$fiscal_period_id =
GETPOSTINT(
'fiscal_period_id');
52if (!isModEnabled(
'accounting')) {
55if ($user->socid > 0) {
58if (!$user->hasRight(
'accounting',
'fiscalyear',
'write')) {
63$hookmanager->initHooks(array(
'accountancyclosure'));
68$fiscal_periods =
$object->getFiscalPeriods();
69if (!is_array($fiscal_periods)) {
74$active_fiscal_periods = array();
75$first_active_fiscal_period =
null;
76$last_fiscal_period =
null;
77$current_fiscal_period =
null;
78$next_fiscal_period =
null;
79$next_active_fiscal_period =
null;
80if (is_array($fiscal_periods)) {
81 foreach ($fiscal_periods as $fiscal_period) {
82 if (empty($first_active_fiscal_period) && empty($fiscal_period[
'status'])) {
83 $first_active_fiscal_period = $fiscal_period;
85 if (empty($fiscal_period[
'status'])) {
86 $active_fiscal_periods[] = $fiscal_period;
88 if (isset($current_fiscal_period)) {
89 if (!isset($next_fiscal_period)) {
90 $next_fiscal_period = $fiscal_period;
92 if (!isset($next_active_fiscal_period) && empty($fiscal_period[
'status'])) {
93 $next_active_fiscal_period = $fiscal_period;
96 if ($fiscal_period_id == $fiscal_period[
'id'] || (empty($fiscal_period_id) && $fiscal_period[
'date_start'] <= $now && $now <= $fiscal_period[
'date_end'])) {
97 $current_fiscal_period = $fiscal_period;
99 $last_fiscal_period = $fiscal_period;
106if (empty($current_fiscal_period) && !empty($first_active_fiscal_period)) {
107 $current_fiscal_period = $first_active_fiscal_period;
108 $last_fiscal_period =
null;
109 $foundcurrent =
false;
110 foreach ($fiscal_periods as $fiscal_period) {
112 $next_fiscal_period = $fiscal_period;
115 if ($fiscal_period[
'id'] == $current_fiscal_period[
'id']) {
116 $foundcurrent =
true;
118 if (!$foundcurrent) {
119 $last_fiscal_period = $fiscal_period;
124$accounting_groups_used_for_balance_sheet_account = array_filter(array_map(
'trim', explode(
',',
getDolGlobalString(
'ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_BALANCE_SHEET_ACCOUNT'))),
'strlen');
125$accounting_groups_used_for_income_statement = array_filter(array_map(
'trim', explode(
',',
getDolGlobalString(
'ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_INCOME_STATEMENT'))),
'strlen');
132$parameters = array(
'fiscal_periods' => $fiscal_periods,
'last_fiscal_period' => $last_fiscal_period,
'current_fiscal_period' => $current_fiscal_period,
'next_fiscal_period' => $next_fiscal_period);
133$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
138if (empty($reshook)) {
139 if (isset($current_fiscal_period)) {
140 if ($action ==
'confirm_step_1' && $confirm ==
"yes" && $user->hasRight(
'accounting',
'fiscalyear',
'write')) {
144 $result =
$object->validateMovementForFiscalPeriod($date_start, $date_end);
146 setEventMessages($langs->trans(
"AllMovementsWereRecordedAsValidated"),
null,
'mesgs');
148 header(
"Location: " . $_SERVER[
'PHP_SELF'] . (isset($current_fiscal_period) ?
'?fiscal_period_id=' . $current_fiscal_period[
'id'] :
''));
151 setEventMessages($langs->trans(
"NotAllMovementsCouldBeRecordedAsValidated"),
null,
'errors');
155 } elseif ($action ==
'confirm_step_2' && $confirm ==
"yes" && $user->hasRight(
'accounting',
'fiscalyear',
'write')) {
156 $new_fiscal_period_id =
GETPOSTINT(
'new_fiscal_period_id');
157 $separate_auxiliary_account =
GETPOST(
'separate_auxiliary_account',
'aZ09');
158 $generate_bookkeeping_records =
GETPOST(
'generate_bookkeeping_records',
'aZ09');
161 if ($generate_bookkeeping_records) {
162 if (!
getDolGlobalString(
'ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_BALANCE_SHEET_ACCOUNT')) {
164 setEventMessages($langs->trans(
"ErrorAccountingClosureSetupNotComplete"),
null,
'errors');
165 } elseif (!
getDolGlobalString(
'ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_INCOME_STATEMENT')) {
167 setEventMessages($langs->trans(
"ErrorAccountingClosureSetupNotComplete"),
null,
'errors');
172 $result =
$object->closeFiscalPeriod($current_fiscal_period[
'id'], $new_fiscal_period_id, $separate_auxiliary_account, $generate_bookkeeping_records);
176 setEventMessages($langs->trans(
"AccountancyClosureCloseSuccessfully"),
null,
'mesgs');
178 header(
"Location: " . $_SERVER[
'PHP_SELF'] . (isset($current_fiscal_period) ?
'?fiscal_period_id=' . $current_fiscal_period[
'id'] :
''));
182 } elseif ($action ==
'confirm_step_3' && $confirm ==
"yes" && $user->hasRight(
'accounting',
'fiscalyear',
'write')) {
183 $inventory_journal_id =
GETPOSTINT(
'inventory_journal_id');
184 $new_fiscal_period_id =
GETPOSTINT(
'new_fiscal_period_id');
188 $result =
$object->insertAccountingReversal($current_fiscal_period[
'id'], $inventory_journal_id, $new_fiscal_period_id, $date_start, $date_end);
192 setEventMessages($langs->trans(
"AccountancyClosureInsertAccountingReversalSuccessfully"),
null,
'mesgs');
194 header(
"Location: " . $_SERVER[
'PHP_SELF'] . (isset($current_fiscal_period) ?
'?fiscal_period_id=' . $current_fiscal_period[
'id'] :
''));
206$form =
new Form($db);
209$title = $langs->trans(
'Closure');
211$help_url =
'EN:Module_Double_Entry_Accounting|FR:Module_Comptabilité_en_Partie_Double#Cl.C3.B4ture_annuelle';
213llxHeader(
'', $title, $help_url,
'', 0, 0,
'',
'',
'',
'mod-accountancy page-closure-index');
217if (isset($current_fiscal_period)) {
218 if ($action ==
'step_1') {
219 $form_question = array();
221 $form_question[
'date_start'] = array(
222 'name' =>
'date_start',
224 'label' => $langs->trans(
'DateStart'),
225 'value' => $current_fiscal_period[
'date_start']
227 $form_question[
'date_end'] = array(
228 'name' =>
'date_end',
230 'label' => $langs->trans(
'DateEnd'),
231 'value' => $current_fiscal_period[
'date_end']
234 $formconfirm = $form->formconfirm(
235 $_SERVER[
"PHP_SELF"] .
'?fiscal_period_id=' . $current_fiscal_period[
'id'],
236 $langs->trans(
'ValidateMovements'),
237 $langs->trans(
'DescValidateMovements', $langs->transnoentitiesnoconv(
"RegistrationInAccounting")),
245 } elseif ($action ==
'step_2') {
246 $form_question = array();
248 $fiscal_period_arr = array();
249 foreach ($active_fiscal_periods as $info) {
250 $fiscal_period_arr[$info[
'id']] = $info[
'label'];
252 $form_question[
'new_fiscal_period_id'] = array(
253 'name' =>
'new_fiscal_period_id',
255 'label' => $langs->trans(
'AccountancyClosureStep3NewFiscalPeriod'),
256 'values' => $fiscal_period_arr,
257 'default' => isset($next_active_fiscal_period) ? $next_active_fiscal_period[
'id'] :
'',
259 $form_question[
'generate_bookkeeping_records'] = array(
260 'name' =>
'generate_bookkeeping_records',
261 'type' =>
'checkbox',
262 'label' => $langs->trans(
'AccountancyClosureGenerateClosureBookkeepingRecords'),
265 $form_question[
'separate_auxiliary_account'] = array(
266 'name' =>
'separate_auxiliary_account',
267 'type' =>
'checkbox',
268 'label' => $langs->trans(
'AccountancyClosureSeparateAuxiliaryAccounts'),
272 $formconfirm = $form->formconfirm(
273 $_SERVER[
"PHP_SELF"] .
'?fiscal_period_id=' . $current_fiscal_period[
'id'],
274 $langs->trans(
'AccountancyClosureClose'),
275 $langs->trans(
'AccountancyClosureConfirmClose'),
283 } elseif ($action ==
'step_3') {
284 $form_question = array();
286 $form_question[
'inventory_journal_id'] = array(
287 'name' =>
'inventory_journal_id',
289 'label' => $langs->trans(
'InventoryJournal'),
290 'value' => $formaccounting->select_journal(0,
"inventory_journal_id", 8, 1, 0, 0)
292 $fiscal_period_arr = array();
293 foreach ($active_fiscal_periods as $info) {
294 $fiscal_period_arr[$info[
'id']] = $info[
'label'];
296 $form_question[
'new_fiscal_period_id'] = array(
297 'name' =>
'new_fiscal_period_id',
299 'label' => $langs->trans(
'AccountancyClosureStep3NewFiscalPeriod'),
300 'values' => $fiscal_period_arr,
301 'default' => isset($next_active_fiscal_period) ? $next_active_fiscal_period[
'id'] :
'',
303 $form_question[
'date_start'] = array(
304 'name' =>
'date_start',
306 'label' => $langs->trans(
'DateStart'),
309 $form_question[
'date_end'] = array(
310 'name' =>
'date_end',
312 'label' => $langs->trans(
'DateEnd'),
313 'value' => $current_fiscal_period[
'date_end']
316 $formconfirm = $form->formconfirm(
317 $_SERVER[
"PHP_SELF"] .
'?fiscal_period_id=' . $current_fiscal_period[
'id'],
318 $langs->trans(
'AccountancyClosureAccountingReversal'),
319 $langs->trans(
'AccountancyClosureConfirmAccountingReversal'),
331$parameters = array(
'formConfirm' => $formconfirm,
'fiscal_periods' => $fiscal_periods,
'last_fiscal_period' => $last_fiscal_period,
'current_fiscal_period' => $current_fiscal_period,
'next_fiscal_period' => $next_fiscal_period);
332$reshook = $hookmanager->executeHooks(
'formConfirm', $parameters, $object, $action);
333if (empty($reshook)) {
334 $formconfirm .= $hookmanager->resPrint;
335} elseif ($reshook > 0) {
336 $formconfirm = $hookmanager->resPrint;
342$fiscal_period_nav_text = $langs->trans(
"FiscalPeriod");
344$fiscal_period_nav_text .=
' <a href="' . (isset($last_fiscal_period) ? $_SERVER[
"PHP_SELF"] .
'?fiscal_period_id=' . $last_fiscal_period[
'id'] :
'#" class="disabled') .
'">' .
img_previous() .
'</a>';
345$fiscal_period_nav_text .=
' <a href="' . (isset($next_fiscal_period) ? $_SERVER[
"PHP_SELF"] .
'?fiscal_period_id=' . $next_fiscal_period[
'id'] :
'#" class="disabled') .
'">' .
img_next() .
'</a>';
346if (!empty($current_fiscal_period)) {
347 $fiscal_period_nav_text .= $current_fiscal_period[
'label'].
' (' . (isset($current_fiscal_period) ?
dol_print_date($current_fiscal_period[
'date_start'],
'day') .
' - ' .
dol_print_date($current_fiscal_period[
'date_end'],
'day') .
')' :
'');
350print
load_fiche_titre($langs->trans(
"Closure") .
" - " . $fiscal_period_nav_text,
'',
'title_accountancy');
352if (empty($current_fiscal_period)) {
353 print $langs->trans(
'ErrorNoFiscalPeriodActiveFound', $langs->transnoentitiesnoconv(
"Accounting"), $langs->transnoentitiesnoconv(
"Setup"), $langs->transnoentitiesnoconv(
"FiscalPeriod"));
358 $head[0][0] = DOL_URL_ROOT .
'/accountancy/closure/index.php?fiscal_period_id=' . $current_fiscal_period[
'id'];
359 $head[0][1] = $langs->trans(
"Step").
' 1 - '.$langs->trans(
"AccountancyClosureStep1");
360 $head[0][2] =
'step1';
363 print
'<span class="opacitymedium">' . $langs->trans(
"AccountancyClosureStep1Desc") .
'</span><br>';
365 $count_by_month =
$object->getCountByMonthForFiscalPeriod($current_fiscal_period[
'date_start'], $current_fiscal_period[
'date_end']);
367 if (!is_array($count_by_month)) {
371 if (empty($count_by_month[
'total'])) {
372 $buttonvalidate =
'<a class="butActionRefused classfortooltip" href="#">' . $langs->trans(
"ValidateMovements") .
'</a>';
374 $buttonvalidate =
'<a class="butAction" href="' . $_SERVER[
"PHP_SELF"] .
'?action=step_1&token='.newToken().
'&fiscal_period_id=' . $current_fiscal_period[
'id'] .
'">' . $langs->trans(
"ValidateMovements") .
'</a>';
376 print_barre_liste($langs->trans(
"OverviewOfMovementsNotValidated"), 0,
'',
'',
'',
'',
'', -1,
'',
'', 0, $buttonvalidate,
'', 0, 1, 0);
378 print
'<div class="div-table-responsive-no-min">';
379 print
'<table class="noborder centpercent">';
381 print
'<tr class="liste_titre">';
382 $nb_years = is_array($count_by_month[
'list']) ? count($count_by_month[
'list']) : 0;
384 print
'<td class="right">' . $langs->trans(
"Year") .
'</td>';
386 for ($i = 1; $i <= 12; $i++) {
387 print
'<td class="right">' . $langs->trans(
'MonthShort' . str_pad((
string) $i, 2,
'0', STR_PAD_LEFT)) .
'</td>';
389 print
'<td class="right"><b>' . $langs->trans(
"Total") .
'</b></td>';
392 if (is_array($count_by_month[
'list'])) {
393 foreach ($count_by_month[
'list'] as $info) {
394 print
'<tr class="oddeven">';
396 print
'<td class="right">' . $info[
'year'] .
'</td>';
398 for ($i = 1; $i <= 12; $i++) {
399 print
'<td class="right">' . ((int) $info[
'count'][$i]) .
'</td>';
401 print
'<td class="right"><b>' . $info[
'total'] .
'</b></td></tr>';
413 $head[0][0] = DOL_URL_ROOT .
'/accountancy/closure/index.php?fiscal_period_id=' . $current_fiscal_period[
'id'];
414 $head[0][1] = $langs->trans(
"Step").
' ' . (
getDolGlobalString(
"ACCOUNTANCY_DISABLE_CLOSURE_LINE_BY_LINE") ?
'1' :
'2').
' - '.$langs->trans(
"AccountancyClosureStep2");
415 $head[0][2] =
'step2';
420 if ((empty($count_by_month[
'total']) ||
getDolGlobalString(
"ACCOUNTANCY_DISABLE_CLOSURE_LINE_BY_LINE")) && empty($current_fiscal_period[
'status'])) {
422 $button =
'<a class="butAction" href="' . $_SERVER[
"PHP_SELF"] .
'?action=step_2&token='.newToken().
'&fiscal_period_id=' . $current_fiscal_period[
'id'] .
'">' . $langs->trans(
"AccountancyClosureClose") .
'</a>';
424 if (!empty($current_fiscal_period[
'status'])) {
425 $button =
'<a class="butActionRefused classfortooltip" href="#" title="The period is already closed. Feature disabled.">' . $langs->trans(
"AccountancyClosureClose") .
'</a>';
426 } elseif (!empty($count_by_month[
'total'])) {
427 $button =
'<a class="butActionRefused classfortooltip" href="#" title="There is some lines not yet locked. Feature disabled.">' . $langs->trans(
"AccountancyClosureClose") .
'</a>';
430 print_barre_liste(
'', 0,
'',
'',
'',
'',
'', -1,
'',
'', 0, $button,
'', 0, 1, 0);
436 $head[0][0] = DOL_URL_ROOT .
'/accountancy/closure/index.php?fiscal_period_id=' . $current_fiscal_period[
'id'];
437 $head[0][1] = $langs->trans(
"Step").
' ' . (
getDolGlobalString(
"ACCOUNTANCY_DISABLE_CLOSURE_LINE_BY_LINE") ?
'2' :
'3').
' - '.$langs->trans(
"AccountancyClosureStep3");
438 $head[0][2] =
'step3';
443 if (empty($current_fiscal_period[
'status'])) {
444 $button =
'<a class="butActionRefused classfortooltip" href="#">' . $langs->trans(
"AccountancyClosureAccountingReversal") .
'</a>';
446 $button =
'<a class="butAction" href="' . $_SERVER[
"PHP_SELF"] .
'?action=step_3&token='.newToken().
'&fiscal_period_id=' . $current_fiscal_period[
'id'] .
'">' . $langs->trans(
"AccountancyClosureAccountingReversal") .
'</a>';
448 print_barre_liste(
'', 0,
'',
'',
'',
'',
'', -1,
'',
'', 0, $button,
'', 0, 1, 0);
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Class to manage Ledger (General Ledger and Subledger)
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $selectlimitsuffix=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_now($mode='auto')
Return date for now.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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.
img_next($titlealt='default', $moreatt='')
Show next logo.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.