28require
'../../main.inc.php';
29require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
30require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
31require_once DOL_DOCUMENT_ROOT.
'/core/class/fiscalyear.class.php';
32require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formaccounting.class.php';
33require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/bookkeeping.class.php';
44$langs->loadLangs(array(
"accountancy",
"bills",
"compta",
"exports",
"other"));
46$action =
GETPOST(
'action',
'aZ09');
47$confirm =
GETPOST(
'confirm',
'aZ09');
48$fiscal_period_id =
GETPOSTINT(
'fiscal_period_id');
53if (!isModEnabled(
'accounting')) {
56if ($user->socid > 0) {
59if (!$user->hasRight(
'accounting',
'fiscalyear',
'write')) {
64$hookmanager->initHooks(array(
'accountancyclosure'));
69$fiscal_periods =
$object->getFiscalPeriods();
70if (!is_array($fiscal_periods)) {
75$active_fiscal_periods = array();
76$first_active_fiscal_period =
null;
77$last_fiscal_period =
null;
78$current_fiscal_period =
null;
79$next_fiscal_period =
null;
80$next_active_fiscal_period =
null;
81if (is_array($fiscal_periods)) {
82 foreach ($fiscal_periods as $fiscal_period) {
83 if (empty($first_active_fiscal_period) && empty($fiscal_period[
'status'])) {
84 $first_active_fiscal_period = $fiscal_period;
86 if (empty($fiscal_period[
'status'])) {
87 $active_fiscal_periods[] = $fiscal_period;
89 if (isset($current_fiscal_period)) {
90 if (!isset($next_fiscal_period)) {
91 $next_fiscal_period = $fiscal_period;
93 if (!isset($next_active_fiscal_period) && empty($fiscal_period[
'status'])) {
94 $next_active_fiscal_period = $fiscal_period;
98 if (!empty($fiscal_period_id) && $fiscal_period_id == $fiscal_period[
'id']) {
99 $current_fiscal_period = $fiscal_period;
101 $last_fiscal_period = $fiscal_period;
108if (empty($current_fiscal_period) && !empty($first_active_fiscal_period)) {
109 $current_fiscal_period = $first_active_fiscal_period;
110 $last_fiscal_period =
null;
111 $foundcurrent =
false;
112 foreach ($fiscal_periods as $fiscal_period) {
114 $next_fiscal_period = $fiscal_period;
117 if ($fiscal_period[
'id'] == $current_fiscal_period[
'id']) {
118 $foundcurrent =
true;
120 if (!$foundcurrent) {
121 $last_fiscal_period = $fiscal_period;
126$accounting_groups_used_for_balance_sheet_account = array_filter(array_map(
'trim', explode(
',',
getDolGlobalString(
'ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_BALANCE_SHEET_ACCOUNT'))),
'strlen');
127$accounting_groups_used_for_income_statement = array_filter(array_map(
'trim', explode(
',',
getDolGlobalString(
'ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_INCOME_STATEMENT'))),
'strlen');
134$parameters = array(
'fiscal_periods' => $fiscal_periods,
'last_fiscal_period' => $last_fiscal_period,
'current_fiscal_period' => $current_fiscal_period,
'next_fiscal_period' => $next_fiscal_period);
135$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
140if (empty($reshook)) {
141 if (isset($current_fiscal_period)) {
142 if ($action ==
'confirm_step_1' && $confirm ==
"yes" && $user->hasRight(
'accounting',
'fiscalyear',
'write')) {
146 $result =
$object->validateMovementForFiscalPeriod($date_start, $date_end);
148 setEventMessages($langs->trans(
"AllMovementsWereRecordedAsValidated"),
null,
'mesgs');
150 header(
"Location: " . $_SERVER[
'PHP_SELF'] . (isset($current_fiscal_period) ?
'?fiscal_period_id=' . $current_fiscal_period[
'id'] :
''));
153 setEventMessages($langs->trans(
"NotAllMovementsCouldBeRecordedAsValidated"),
null,
'errors');
157 } elseif ($action ==
'confirm_step_2' && $confirm ==
"yes" && $user->hasRight(
'accounting',
'fiscalyear',
'write')) {
158 $new_fiscal_period_id =
GETPOSTINT(
'new_fiscal_period_id');
159 $separate_auxiliary_account = (!empty(
GETPOST(
'separate_auxiliary_account')) ? 1 : 0);
160 $generate_bookkeeping_records = (!empty(
GETPOST(
'generate_bookkeeping_records')) ? 1 : 0);
163 if ($generate_bookkeeping_records) {
164 if (!
getDolGlobalString(
'ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_BALANCE_SHEET_ACCOUNT')) {
166 setEventMessages($langs->trans(
"ErrorAccountingClosureSetupNotComplete"),
null,
'errors');
167 } elseif (!
getDolGlobalString(
'ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_INCOME_STATEMENT')) {
169 setEventMessages($langs->trans(
"ErrorAccountingClosureSetupNotComplete"),
null,
'errors');
174 $result =
$object->closeFiscalPeriod($current_fiscal_period[
'id'], $new_fiscal_period_id, (
bool) $separate_auxiliary_account, (
bool) $generate_bookkeeping_records);
178 setEventMessages($langs->trans(
"AccountancyClosureCloseSuccessfully"),
null,
'mesgs');
180 header(
"Location: " . $_SERVER[
'PHP_SELF'] . (isset($current_fiscal_period) ?
'?fiscal_period_id=' . $current_fiscal_period[
'id'] :
''));
184 } elseif ($action ==
'confirm_step_3' && $confirm ==
"yes" && $user->hasRight(
'accounting',
'fiscalyear',
'write')) {
185 $inventory_journal_id =
GETPOSTINT(
'inventory_journal_id');
186 $new_fiscal_period_id =
GETPOSTINT(
'new_fiscal_period_id');
190 $result =
$object->insertAccountingReversal($current_fiscal_period[
'id'], $inventory_journal_id, $new_fiscal_period_id, $date_start, $date_end);
194 setEventMessages($langs->trans(
"AccountancyClosureInsertAccountingReversalSuccessfully"),
null,
'mesgs');
196 header(
"Location: " . $_SERVER[
'PHP_SELF'] . (isset($current_fiscal_period) ?
'?fiscal_period_id=' . $current_fiscal_period[
'id'] :
''));
208$form =
new Form($db);
211$title = $langs->trans(
'Closure');
213$help_url =
'EN:Module_Double_Entry_Accounting|FR:Module_Comptabilité_en_Partie_Double#Cl.C3.B4ture_annuelle';
215llxHeader(
'', $title, $help_url,
'', 0, 0,
'',
'',
'',
'mod-accountancy page-closure-index');
219if (isset($current_fiscal_period)) {
220 if ($action ==
'step_1') {
221 $form_question = array();
223 $form_question[
'date_start'] = array(
224 'name' =>
'date_start',
226 'label' => $langs->trans(
'DateStart'),
227 'value' => $current_fiscal_period[
'date_start']
229 $form_question[
'date_end'] = array(
230 'name' =>
'date_end',
232 'label' => $langs->trans(
'DateEnd'),
233 'value' => $current_fiscal_period[
'date_end']
236 $formconfirm = $form->formconfirm(
237 $_SERVER[
"PHP_SELF"] .
'?fiscal_period_id=' . $current_fiscal_period[
'id'],
238 $langs->trans(
'ValidateMovements'),
239 $langs->trans(
'DescValidateMovements', $langs->transnoentitiesnoconv(
"RegistrationInAccounting")),
247 } elseif ($action ==
'step_2') {
248 $form_question = array();
250 $fiscal_period_arr = array();
251 foreach ($active_fiscal_periods as $info) {
252 $fiscal_period_arr[$info[
'id']] = $info[
'label'];
254 $form_question[
'new_fiscal_period_id'] = array(
255 'name' =>
'new_fiscal_period_id',
257 'label' => $langs->trans(
'AccountancyClosureStep3NewFiscalPeriod'),
258 'values' => $fiscal_period_arr,
259 'default' => isset($next_active_fiscal_period) ? $next_active_fiscal_period[
'id'] :
'',
261 $form_question[
'generate_bookkeeping_records'] = array(
262 'name' =>
'generate_bookkeeping_records',
263 'type' =>
'checkbox',
264 'label' => $langs->trans(
'AccountancyClosureGenerateClosureBookkeepingRecords'),
267 $form_question[
'separate_auxiliary_account'] = array(
268 'name' =>
'separate_auxiliary_account',
269 'type' =>
'checkbox',
270 'label' => $langs->trans(
'AccountancyClosureSeparateAuxiliaryAccounts'),
274 $formconfirm = $form->formconfirm(
275 $_SERVER[
"PHP_SELF"] .
'?fiscal_period_id=' . $current_fiscal_period[
'id'],
276 $langs->trans(
'AccountancyClosureClose'),
277 $langs->trans(
'AccountancyClosureConfirmClose'),
285 } elseif ($action ==
'step_3') {
286 $form_question = array();
288 $form_question[
'inventory_journal_id'] = array(
289 'name' =>
'inventory_journal_id',
291 'label' => $langs->trans(
'InventoryJournal'),
292 'value' => $formaccounting->select_journal(
'0',
"inventory_journal_id", 8, 1, 0, 0)
294 $fiscal_period_arr = array();
295 foreach ($active_fiscal_periods as $info) {
296 $fiscal_period_arr[$info[
'id']] = $info[
'label'];
298 $form_question[
'new_fiscal_period_id'] = array(
299 'name' =>
'new_fiscal_period_id',
301 'label' => $langs->trans(
'AccountancyClosureStep3NewFiscalPeriod'),
302 'values' => $fiscal_period_arr,
303 'default' => isset($next_active_fiscal_period) ? $next_active_fiscal_period[
'id'] :
'',
305 $form_question[
'date_start'] = array(
306 'name' =>
'date_start',
308 'label' => $langs->trans(
'DateStart'),
311 $form_question[
'date_end'] = array(
312 'name' =>
'date_end',
314 'label' => $langs->trans(
'DateEnd'),
315 'value' => $current_fiscal_period[
'date_end']
318 $formconfirm = $form->formconfirm(
319 $_SERVER[
"PHP_SELF"] .
'?fiscal_period_id=' . $current_fiscal_period[
'id'],
320 $langs->trans(
'AccountancyClosureAccountingReversal'),
321 $langs->trans(
'AccountancyClosureConfirmAccountingReversal'),
333$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);
334$reshook = $hookmanager->executeHooks(
'formConfirm', $parameters, $object, $action);
335if (empty($reshook)) {
336 $formconfirm .= $hookmanager->resPrint;
337} elseif ($reshook > 0) {
338 $formconfirm = $hookmanager->resPrint;
344$fiscal_period_nav_text = $langs->trans(
"FiscalPeriod");
346$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>';
347$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>';
348if (!empty($current_fiscal_period)) {
349 $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') .
')' :
'');
352print
load_fiche_titre($langs->trans(
"Closure") .
" - " . $fiscal_period_nav_text,
'',
'title_accountancy');
354if (empty($current_fiscal_period)) {
355 print $langs->trans(
'ErrorNoFiscalPeriodActiveFound', $langs->transnoentitiesnoconv(
"Accounting"), $langs->transnoentitiesnoconv(
"Setup"), $langs->transnoentitiesnoconv(
"FiscalPeriod"));
360 $head[0][0] = DOL_URL_ROOT .
'/accountancy/closure/index.php?fiscal_period_id=' . $current_fiscal_period[
'id'];
361 $head[0][1] = $langs->trans(
"Step").
' 1 - '.$langs->trans(
"AccountancyClosureStep1");
362 $head[0][2] =
'step1';
365 print
'<span class="opacitymedium">' . $langs->trans(
"AccountancyClosureStep1Desc") .
'</span><br>';
367 $count_by_month =
$object->getCountByMonthForFiscalPeriod((
int) $current_fiscal_period[
'date_start'], (
int) $current_fiscal_period[
'date_end']);
369 if (!is_array($count_by_month)) {
373 if (empty($count_by_month[
'total'])) {
374 $buttonvalidate =
'<a class="butActionRefused classfortooltip" href="#">' . $langs->trans(
"ValidateMovements") .
'</a>';
376 $buttonvalidate =
'<a class="butAction" href="' . $_SERVER[
"PHP_SELF"] .
'?action=step_1&token='.newToken().
'&fiscal_period_id=' . $current_fiscal_period[
'id'] .
'">' . $langs->trans(
"ValidateMovements") .
'</a>';
378 print_barre_liste($langs->trans(
"OverviewOfMovementsNotValidated"), 0,
'',
'',
'',
'',
'', -1,
'',
'', 0, $buttonvalidate,
'', 0, 1, 0);
380 print
'<div class="div-table-responsive-no-min">';
381 print
'<table class="noborder centpercent">';
383 print
'<tr class="liste_titre">';
384 $nb_years = is_array($count_by_month[
'list']) ? count($count_by_month[
'list']) : 0;
386 print
'<td class="right">' . $langs->trans(
"Year") .
'</td>';
388 for ($i = 1; $i <= 12; $i++) {
389 print
'<td class="right">' . $langs->trans(
'MonthShort' . str_pad((
string) $i, 2,
'0', STR_PAD_LEFT)) .
'</td>';
391 print
'<td class="right"><b>' . $langs->trans(
"Total") .
'</b></td>';
394 if (is_array($count_by_month[
'list'])) {
395 foreach ($count_by_month[
'list'] as $info) {
396 print
'<tr class="oddeven">';
398 print
'<td class="right">' . $info[
'year'] .
'</td>';
400 for ($i = 1; $i <= 12; $i++) {
401 print
'<td class="right">' . ((int) $info[
'count'][$i]) .
'</td>';
403 print
'<td class="right"><b>' . $info[
'total'] .
'</b></td></tr>';
415 $head[0][0] = DOL_URL_ROOT .
'/accountancy/closure/index.php?fiscal_period_id=' . $current_fiscal_period[
'id'];
416 $head[0][1] = $langs->trans(
"Step").
' ' . (
getDolGlobalString(
"ACCOUNTANCY_DISABLE_CLOSURE_LINE_BY_LINE") ?
'1' :
'2').
' - '.$langs->trans(
"AccountancyClosureStep2");
417 $head[0][2] =
'step2';
422 if ((empty($count_by_month[
'total']) ||
getDolGlobalString(
"ACCOUNTANCY_DISABLE_CLOSURE_LINE_BY_LINE")) && empty($current_fiscal_period[
'status'])) {
424 $button =
'<a class="butAction" href="' . $_SERVER[
"PHP_SELF"] .
'?action=step_2&token='.newToken().
'&fiscal_period_id=' . $current_fiscal_period[
'id'] .
'">' . $langs->trans(
"AccountancyClosureClose") .
'</a>';
426 if (!empty($current_fiscal_period[
'status'])) {
427 $button =
'<a class="butActionRefused classfortooltip" href="#" title="The period is already closed. Feature disabled.">' . $langs->trans(
"AccountancyClosureClose") .
'</a>';
428 } elseif (!empty($count_by_month[
'total'])) {
429 $button =
'<a class="butActionRefused classfortooltip" href="#" title="There is some lines not yet locked. Feature disabled.">' . $langs->trans(
"AccountancyClosureClose") .
'</a>';
432 print_barre_liste(
'', 0,
'',
'',
'',
'',
'', -1,
'',
'', 0, $button,
'', 0, 1, 0);
438 $head[0][0] = DOL_URL_ROOT .
'/accountancy/closure/index.php?fiscal_period_id=' . $current_fiscal_period[
'id'];
439 $head[0][1] = $langs->trans(
"Step").
' ' . (
getDolGlobalString(
"ACCOUNTANCY_DISABLE_CLOSURE_LINE_BY_LINE") ?
'2' :
'3').
' - '.$langs->trans(
"AccountancyClosureStep3");
440 $head[0][2] =
'step3';
445 if (empty($current_fiscal_period[
'status'])) {
446 $button =
'<a class="butActionRefused classfortooltip" href="#">' . $langs->trans(
"AccountancyClosureAccountingReversal") .
'</a>';
448 $button =
'<a class="butAction" href="' . $_SERVER[
"PHP_SELF"] .
'?action=step_3&token='.newToken().
'&fiscal_period_id=' . $current_fiscal_period[
'id'] .
'">' . $langs->trans(
"AccountancyClosureAccountingReversal") .
'</a>';
450 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, $morecssdiv='')
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.