26require
'../../main.inc.php';
27require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
28require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
29require_once DOL_DOCUMENT_ROOT.
'/core/class/fiscalyear.class.php';
30require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formaccounting.class.php';
31require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/bookkeeping.class.php';
34$langs->loadLangs(array(
"compta",
"bills",
"other",
"accountancy"));
36$action =
GETPOST(
'action',
'aZ09');
37$confirm =
GETPOST(
'confirm',
'aZ09');
38$fiscal_period_id =
GETPOSTINT(
'fiscal_period_id');
43if (!isModEnabled(
'accounting')) {
46if ($user->socid > 0) {
49if (!$user->hasRight(
'accounting',
'fiscalyear',
'write')) {
54$hookmanager->initHooks(array(
'accountancyclosure'));
59$fiscal_periods =
$object->getFiscalPeriods();
60if (!is_array($fiscal_periods)) {
65$active_fiscal_periods = array();
66$first_active_fiscal_period =
null;
67$last_fiscal_period =
null;
68$current_fiscal_period =
null;
69$next_fiscal_period =
null;
70$next_active_fiscal_period =
null;
71if (is_array($fiscal_periods)) {
72 foreach ($fiscal_periods as $fiscal_period) {
73 if (empty($first_active_fiscal_period) && empty($fiscal_period[
'status'])) {
74 $first_active_fiscal_period = $fiscal_period;
76 if (empty($fiscal_period[
'status'])) {
77 $active_fiscal_periods[] = $fiscal_period;
79 if (isset($current_fiscal_period)) {
80 if (!isset($next_fiscal_period)) {
81 $next_fiscal_period = $fiscal_period;
83 if (!isset($next_active_fiscal_period) && empty($fiscal_period[
'status'])) {
84 $next_active_fiscal_period = $fiscal_period;
87 if ($fiscal_period_id == $fiscal_period[
'id'] || (empty($fiscal_period_id) && $fiscal_period[
'date_start'] <= $now && $now <= $fiscal_period[
'date_end'])) {
88 $current_fiscal_period = $fiscal_period;
90 $last_fiscal_period = $fiscal_period;
97if (empty($current_fiscal_period) && !empty($first_active_fiscal_period)) {
98 $current_fiscal_period = $first_active_fiscal_period;
99 $last_fiscal_period =
null;
100 $foundcurrent =
false;
101 foreach ($fiscal_periods as $fiscal_period) {
103 $next_fiscal_period = $fiscal_period;
106 if ($fiscal_period[
'id'] == $current_fiscal_period[
'id']) {
107 $foundcurrent =
true;
109 if (!$foundcurrent) {
110 $last_fiscal_period = $fiscal_period;
115$accounting_groups_used_for_balance_sheet_account = array_filter(array_map(
'trim', explode(
',',
getDolGlobalString(
'ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_BALANCE_SHEET_ACCOUNT'))),
'strlen');
116$accounting_groups_used_for_income_statement = array_filter(array_map(
'trim', explode(
',',
getDolGlobalString(
'ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_INCOME_STATEMENT'))),
'strlen');
123$parameters = array(
'fiscal_periods' => $fiscal_periods,
'last_fiscal_period' => $last_fiscal_period,
'current_fiscal_period' => $current_fiscal_period,
'next_fiscal_period' => $next_fiscal_period);
124$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
129if (empty($reshook)) {
130 if (isset($current_fiscal_period)) {
131 if ($action ==
'confirm_step_1' && $confirm ==
"yes" && $user->hasRight(
'accounting',
'fiscalyear',
'write')) {
135 $result =
$object->validateMovementForFiscalPeriod($date_start, $date_end);
137 setEventMessages($langs->trans(
"AllMovementsWereRecordedAsValidated"),
null,
'mesgs');
139 header(
"Location: " . $_SERVER[
'PHP_SELF'] . (isset($current_fiscal_period) ?
'?fiscal_period_id=' . $current_fiscal_period[
'id'] :
''));
142 setEventMessages($langs->trans(
"NotAllMovementsCouldBeRecordedAsValidated"),
null,
'errors');
146 } elseif ($action ==
'confirm_step_2' && $confirm ==
"yes" && $user->hasRight(
'accounting',
'fiscalyear',
'write')) {
147 $new_fiscal_period_id =
GETPOSTINT(
'new_fiscal_period_id');
148 $separate_auxiliary_account =
GETPOST(
'separate_auxiliary_account',
'aZ09');
149 $generate_bookkeeping_records =
GETPOST(
'generate_bookkeeping_records',
'aZ09');
152 if ($generate_bookkeeping_records) {
153 if (!
getDolGlobalString(
'ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_BALANCE_SHEET_ACCOUNT')) {
155 setEventMessages($langs->trans(
"ErrorAccountingClosureSetupNotComplete"),
null,
'errors');
156 } elseif (!
getDolGlobalString(
'ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_INCOME_STATEMENT')) {
158 setEventMessages($langs->trans(
"ErrorAccountingClosureSetupNotComplete"),
null,
'errors');
163 $result =
$object->closeFiscalPeriod($current_fiscal_period[
'id'], $new_fiscal_period_id, $separate_auxiliary_account, $generate_bookkeeping_records);
167 setEventMessages($langs->trans(
"AccountancyClosureCloseSuccessfully"),
null,
'mesgs');
169 header(
"Location: " . $_SERVER[
'PHP_SELF'] . (isset($current_fiscal_period) ?
'?fiscal_period_id=' . $current_fiscal_period[
'id'] :
''));
173 } elseif ($action ==
'confirm_step_3' && $confirm ==
"yes" && $user->hasRight(
'accounting',
'fiscalyear',
'write')) {
174 $inventory_journal_id =
GETPOSTINT(
'inventory_journal_id');
175 $new_fiscal_period_id =
GETPOSTINT(
'new_fiscal_period_id');
179 $result =
$object->insertAccountingReversal($current_fiscal_period[
'id'], $inventory_journal_id, $new_fiscal_period_id, $date_start, $date_end);
183 setEventMessages($langs->trans(
"AccountancyClosureInsertAccountingReversalSuccessfully"),
null,
'mesgs');
185 header(
"Location: " . $_SERVER[
'PHP_SELF'] . (isset($current_fiscal_period) ?
'?fiscal_period_id=' . $current_fiscal_period[
'id'] :
''));
197$form =
new Form($db);
200$title = $langs->trans(
'Closure');
202$help_url =
'EN:Module_Double_Entry_Accounting|FR:Module_Comptabilité_en_Partie_Double#Cl.C3.B4ture_annuelle';
204llxHeader(
'', $title, $help_url,
'', 0, 0,
'',
'',
'',
'mod-accountancy page-closure-index');
208if (isset($current_fiscal_period)) {
209 if ($action ==
'step_1') {
210 $form_question = array();
212 $form_question[
'date_start'] = array(
213 'name' =>
'date_start',
215 'label' => $langs->trans(
'DateStart'),
216 'value' => $current_fiscal_period[
'date_start']
218 $form_question[
'date_end'] = array(
219 'name' =>
'date_end',
221 'label' => $langs->trans(
'DateEnd'),
222 'value' => $current_fiscal_period[
'date_end']
225 $formconfirm = $form->formconfirm(
226 $_SERVER[
"PHP_SELF"] .
'?fiscal_period_id=' . $current_fiscal_period[
'id'],
227 $langs->trans(
'ValidateMovements'),
228 $langs->trans(
'DescValidateMovements', $langs->transnoentitiesnoconv(
"RegistrationInAccounting")),
236 } elseif ($action ==
'step_2') {
237 $form_question = array();
239 $fiscal_period_arr = array();
240 foreach ($active_fiscal_periods as $info) {
241 $fiscal_period_arr[$info[
'id']] = $info[
'label'];
243 $form_question[
'new_fiscal_period_id'] = array(
244 'name' =>
'new_fiscal_period_id',
246 'label' => $langs->trans(
'AccountancyClosureStep3NewFiscalPeriod'),
247 'values' => $fiscal_period_arr,
248 'default' => isset($next_active_fiscal_period) ? $next_active_fiscal_period[
'id'] :
'',
250 $form_question[
'generate_bookkeeping_records'] = array(
251 'name' =>
'generate_bookkeeping_records',
252 'type' =>
'checkbox',
253 'label' => $langs->trans(
'AccountancyClosureGenerateClosureBookkeepingRecords'),
256 $form_question[
'separate_auxiliary_account'] = array(
257 'name' =>
'separate_auxiliary_account',
258 'type' =>
'checkbox',
259 'label' => $langs->trans(
'AccountancyClosureSeparateAuxiliaryAccounts'),
263 $formconfirm = $form->formconfirm(
264 $_SERVER[
"PHP_SELF"] .
'?fiscal_period_id=' . $current_fiscal_period[
'id'],
265 $langs->trans(
'AccountancyClosureClose'),
266 $langs->trans(
'AccountancyClosureConfirmClose'),
274 } elseif ($action ==
'step_3') {
275 $form_question = array();
277 $form_question[
'inventory_journal_id'] = array(
278 'name' =>
'inventory_journal_id',
280 'label' => $langs->trans(
'InventoryJournal'),
281 'value' => $formaccounting->select_journal(0,
"inventory_journal_id", 8, 1, 0, 0)
283 $fiscal_period_arr = array();
284 foreach ($active_fiscal_periods as $info) {
285 $fiscal_period_arr[$info[
'id']] = $info[
'label'];
287 $form_question[
'new_fiscal_period_id'] = array(
288 'name' =>
'new_fiscal_period_id',
290 'label' => $langs->trans(
'AccountancyClosureStep3NewFiscalPeriod'),
291 'values' => $fiscal_period_arr,
292 'default' => isset($next_active_fiscal_period) ? $next_active_fiscal_period[
'id'] :
'',
294 $form_question[
'date_start'] = array(
295 'name' =>
'date_start',
297 'label' => $langs->trans(
'DateStart'),
300 $form_question[
'date_end'] = array(
301 'name' =>
'date_end',
303 'label' => $langs->trans(
'DateEnd'),
304 'value' => $current_fiscal_period[
'date_end']
307 $formconfirm = $form->formconfirm(
308 $_SERVER[
"PHP_SELF"] .
'?fiscal_period_id=' . $current_fiscal_period[
'id'],
309 $langs->trans(
'AccountancyClosureAccountingReversal'),
310 $langs->trans(
'AccountancyClosureConfirmAccountingReversal'),
322$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);
323$reshook = $hookmanager->executeHooks(
'formConfirm', $parameters, $object, $action);
324if (empty($reshook)) {
325 $formconfirm .= $hookmanager->resPrint;
326} elseif ($reshook > 0) {
327 $formconfirm = $hookmanager->resPrint;
333$fiscal_period_nav_text = $langs->trans(
"FiscalPeriod");
335$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>';
336$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>';
337if (!empty($current_fiscal_period)) {
338 $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') .
')' :
'');
341print
load_fiche_titre($langs->trans(
"Closure") .
" - " . $fiscal_period_nav_text,
'',
'title_accountancy');
343if (empty($current_fiscal_period)) {
344 print $langs->trans(
'ErrorNoFiscalPeriodActiveFound', $langs->transnoentitiesnoconv(
"Accounting"), $langs->transnoentitiesnoconv(
"Setup"), $langs->transnoentitiesnoconv(
"FiscalPeriod"));
349 $head[0][0] = DOL_URL_ROOT .
'/accountancy/closure/index.php?fiscal_period_id=' . $current_fiscal_period[
'id'];
350 $head[0][1] = $langs->trans(
"Step").
' 1 - '.$langs->trans(
"AccountancyClosureStep1");
351 $head[0][2] =
'step1';
354 print
'<span class="opacitymedium">' . $langs->trans(
"AccountancyClosureStep1Desc") .
'</span><br>';
356 $count_by_month =
$object->getCountByMonthForFiscalPeriod($current_fiscal_period[
'date_start'], $current_fiscal_period[
'date_end']);
358 if (!is_array($count_by_month)) {
362 if (empty($count_by_month[
'total'])) {
363 $buttonvalidate =
'<a class="butActionRefused classfortooltip" href="#">' . $langs->trans(
"ValidateMovements") .
'</a>';
365 $buttonvalidate =
'<a class="butAction" href="' . $_SERVER[
"PHP_SELF"] .
'?action=step_1&token='.newToken().
'&fiscal_period_id=' . $current_fiscal_period[
'id'] .
'">' . $langs->trans(
"ValidateMovements") .
'</a>';
367 print_barre_liste($langs->trans(
"OverviewOfMovementsNotValidated"),
'',
'',
'',
'',
'',
'', -1,
'',
'', 0, $buttonvalidate,
'', 0, 1, 0);
369 print
'<div class="div-table-responsive-no-min">';
370 print
'<table class="noborder centpercent">';
372 print
'<tr class="liste_titre">';
373 $nb_years = is_array($count_by_month[
'list']) ? count($count_by_month[
'list']) : 0;
375 print
'<td class="right">' . $langs->trans(
"Year") .
'</td>';
377 for ($i = 1; $i <= 12; $i++) {
378 print
'<td class="right">' . $langs->trans(
'MonthShort' . str_pad((
string) $i, 2,
'0', STR_PAD_LEFT)) .
'</td>';
380 print
'<td class="right"><b>' . $langs->trans(
"Total") .
'</b></td>';
383 if (is_array($count_by_month[
'list'])) {
384 foreach ($count_by_month[
'list'] as $info) {
385 print
'<tr class="oddeven">';
387 print
'<td class="right">' . $info[
'year'] .
'</td>';
389 for ($i = 1; $i <= 12; $i++) {
390 print
'<td class="right">' . ((int) $info[
'count'][$i]) .
'</td>';
392 print
'<td class="right"><b>' . $info[
'total'] .
'</b></td></tr>';
404 $head[0][0] = DOL_URL_ROOT .
'/accountancy/closure/index.php?fiscal_period_id=' . $current_fiscal_period[
'id'];
405 $head[0][1] = $langs->trans(
"Step").(getDolGlobalString(
"ACCOUNTANCY_DISABLE_CLOSURE_LINE_BY_LINE") ?
'1' :
'2').
' - '.$langs->trans(
"AccountancyClosureStep2");
406 $head[0][2] =
'step2';
411 if ((empty($count_by_month[
'total']) ||
getDolGlobalString(
"ACCOUNTANCY_DISABLE_CLOSURE_LINE_BY_LINE")) && empty($current_fiscal_period[
'status'])) {
413 $button =
'<a class="butAction" href="' . $_SERVER[
"PHP_SELF"] .
'?action=step_2&token='.newToken().
'&fiscal_period_id=' . $current_fiscal_period[
'id'] .
'">' . $langs->trans(
"AccountancyClosureClose") .
'</a>';
415 if (!empty($current_fiscal_period[
'status'])) {
416 $button =
'<a class="butActionRefused classfortooltip" href="#" title="The period is already closed. Feature disabled.">' . $langs->trans(
"AccountancyClosureClose") .
'</a>';
417 } elseif (!empty($count_by_month[
'total'])) {
418 $button =
'<a class="butActionRefused classfortooltip" href="#" title="There is some lines not yet locked. Feature disabled.">' . $langs->trans(
"AccountancyClosureClose") .
'</a>';
421 print_barre_liste(
'',
'',
'',
'',
'',
'',
'', -1,
'',
'', 0, $button,
'', 0, 1, 0);
427 $head[0][0] = DOL_URL_ROOT .
'/accountancy/closure/index.php?fiscal_period_id=' . $current_fiscal_period[
'id'];
428 $head[0][1] = $langs->trans(
"Step").(getDolGlobalString(
"ACCOUNTANCY_DISABLE_CLOSURE_LINE_BY_LINE") ?
'2' :
'3').
' - '.$langs->trans(
"AccountancyClosureStep3");
429 $head[0][2] =
'step3';
434 if (empty($current_fiscal_period[
'status'])) {
435 $button =
'<a class="butActionRefused classfortooltip" href="#">' . $langs->trans(
"AccountancyClosureAccountingReversal") .
'</a>';
437 $button =
'<a class="butAction" href="' . $_SERVER[
"PHP_SELF"] .
'?action=step_3&token='.newToken().
'&fiscal_period_id=' . $current_fiscal_period[
'id'] .
'">' . $langs->trans(
"AccountancyClosureAccountingReversal") .
'</a>';
439 print_barre_liste(
'',
'',
'',
'',
'',
'',
'', -1,
'',
'', 0, $button,
'', 0, 1, 0);
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
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.