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';
42$langs->loadLangs(array(
"compta",
"bills",
"other",
"accountancy"));
44$action =
GETPOST(
'action',
'aZ09');
45$confirm =
GETPOST(
'confirm',
'aZ09');
46$fiscal_period_id =
GETPOSTINT(
'fiscal_period_id');
51if (!isModEnabled(
'accounting')) {
54if ($user->socid > 0) {
57if (!$user->hasRight(
'accounting',
'fiscalyear',
'write')) {
62$hookmanager->initHooks(array(
'accountancyclosure'));
67$fiscal_periods =
$object->getFiscalPeriods();
68if (!is_array($fiscal_periods)) {
73$active_fiscal_periods = array();
74$first_active_fiscal_period =
null;
75$last_fiscal_period =
null;
76$current_fiscal_period =
null;
77$next_fiscal_period =
null;
78$next_active_fiscal_period =
null;
79if (is_array($fiscal_periods)) {
80 foreach ($fiscal_periods as $fiscal_period) {
81 if (empty($first_active_fiscal_period) && empty($fiscal_period[
'status'])) {
82 $first_active_fiscal_period = $fiscal_period;
84 if (empty($fiscal_period[
'status'])) {
85 $active_fiscal_periods[] = $fiscal_period;
87 if (isset($current_fiscal_period)) {
88 if (!isset($next_fiscal_period)) {
89 $next_fiscal_period = $fiscal_period;
91 if (!isset($next_active_fiscal_period) && empty($fiscal_period[
'status'])) {
92 $next_active_fiscal_period = $fiscal_period;
95 if ($fiscal_period_id == $fiscal_period[
'id'] || (empty($fiscal_period_id) && $fiscal_period[
'date_start'] <= $now && $now <= $fiscal_period[
'date_end'])) {
96 $current_fiscal_period = $fiscal_period;
98 $last_fiscal_period = $fiscal_period;
105if (empty($current_fiscal_period) && !empty($first_active_fiscal_period)) {
106 $current_fiscal_period = $first_active_fiscal_period;
107 $last_fiscal_period =
null;
108 $foundcurrent =
false;
109 foreach ($fiscal_periods as $fiscal_period) {
111 $next_fiscal_period = $fiscal_period;
114 if ($fiscal_period[
'id'] == $current_fiscal_period[
'id']) {
115 $foundcurrent =
true;
117 if (!$foundcurrent) {
118 $last_fiscal_period = $fiscal_period;
123$accounting_groups_used_for_balance_sheet_account = array_filter(array_map(
'trim', explode(
',',
getDolGlobalString(
'ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_BALANCE_SHEET_ACCOUNT'))),
'strlen');
124$accounting_groups_used_for_income_statement = array_filter(array_map(
'trim', explode(
',',
getDolGlobalString(
'ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_INCOME_STATEMENT'))),
'strlen');
131$parameters = array(
'fiscal_periods' => $fiscal_periods,
'last_fiscal_period' => $last_fiscal_period,
'current_fiscal_period' => $current_fiscal_period,
'next_fiscal_period' => $next_fiscal_period);
132$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
137if (empty($reshook)) {
138 if (isset($current_fiscal_period)) {
139 if ($action ==
'confirm_step_1' && $confirm ==
"yes" && $user->hasRight(
'accounting',
'fiscalyear',
'write')) {
143 $result =
$object->validateMovementForFiscalPeriod($date_start, $date_end);
145 setEventMessages($langs->trans(
"AllMovementsWereRecordedAsValidated"),
null,
'mesgs');
147 header(
"Location: " . $_SERVER[
'PHP_SELF'] . (isset($current_fiscal_period) ?
'?fiscal_period_id=' . $current_fiscal_period[
'id'] :
''));
150 setEventMessages($langs->trans(
"NotAllMovementsCouldBeRecordedAsValidated"),
null,
'errors');
154 } elseif ($action ==
'confirm_step_2' && $confirm ==
"yes" && $user->hasRight(
'accounting',
'fiscalyear',
'write')) {
155 $new_fiscal_period_id =
GETPOSTINT(
'new_fiscal_period_id');
156 $separate_auxiliary_account =
GETPOST(
'separate_auxiliary_account',
'aZ09');
157 $generate_bookkeeping_records =
GETPOST(
'generate_bookkeeping_records',
'aZ09');
160 if ($generate_bookkeeping_records) {
161 if (!
getDolGlobalString(
'ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_BALANCE_SHEET_ACCOUNT')) {
163 setEventMessages($langs->trans(
"ErrorAccountingClosureSetupNotComplete"),
null,
'errors');
164 } elseif (!
getDolGlobalString(
'ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_INCOME_STATEMENT')) {
166 setEventMessages($langs->trans(
"ErrorAccountingClosureSetupNotComplete"),
null,
'errors');
171 $result =
$object->closeFiscalPeriod($current_fiscal_period[
'id'], $new_fiscal_period_id, $separate_auxiliary_account, $generate_bookkeeping_records);
175 setEventMessages($langs->trans(
"AccountancyClosureCloseSuccessfully"),
null,
'mesgs');
177 header(
"Location: " . $_SERVER[
'PHP_SELF'] . (isset($current_fiscal_period) ?
'?fiscal_period_id=' . $current_fiscal_period[
'id'] :
''));
181 } elseif ($action ==
'confirm_step_3' && $confirm ==
"yes" && $user->hasRight(
'accounting',
'fiscalyear',
'write')) {
182 $inventory_journal_id =
GETPOSTINT(
'inventory_journal_id');
183 $new_fiscal_period_id =
GETPOSTINT(
'new_fiscal_period_id');
187 $result =
$object->insertAccountingReversal($current_fiscal_period[
'id'], $inventory_journal_id, $new_fiscal_period_id, $date_start, $date_end);
191 setEventMessages($langs->trans(
"AccountancyClosureInsertAccountingReversalSuccessfully"),
null,
'mesgs');
193 header(
"Location: " . $_SERVER[
'PHP_SELF'] . (isset($current_fiscal_period) ?
'?fiscal_period_id=' . $current_fiscal_period[
'id'] :
''));
205$form =
new Form($db);
208$title = $langs->trans(
'Closure');
210$help_url =
'EN:Module_Double_Entry_Accounting|FR:Module_Comptabilité_en_Partie_Double#Cl.C3.B4ture_annuelle';
212llxHeader(
'', $title, $help_url,
'', 0, 0,
'',
'',
'',
'mod-accountancy page-closure-index');
216if (isset($current_fiscal_period)) {
217 if ($action ==
'step_1') {
218 $form_question = array();
220 $form_question[
'date_start'] = array(
221 'name' =>
'date_start',
223 'label' => $langs->trans(
'DateStart'),
224 'value' => $current_fiscal_period[
'date_start']
226 $form_question[
'date_end'] = array(
227 'name' =>
'date_end',
229 'label' => $langs->trans(
'DateEnd'),
230 'value' => $current_fiscal_period[
'date_end']
233 $formconfirm = $form->formconfirm(
234 $_SERVER[
"PHP_SELF"] .
'?fiscal_period_id=' . $current_fiscal_period[
'id'],
235 $langs->trans(
'ValidateMovements'),
236 $langs->trans(
'DescValidateMovements', $langs->transnoentitiesnoconv(
"RegistrationInAccounting")),
244 } elseif ($action ==
'step_2') {
245 $form_question = array();
247 $fiscal_period_arr = array();
248 foreach ($active_fiscal_periods as $info) {
249 $fiscal_period_arr[$info[
'id']] = $info[
'label'];
251 $form_question[
'new_fiscal_period_id'] = array(
252 'name' =>
'new_fiscal_period_id',
254 'label' => $langs->trans(
'AccountancyClosureStep3NewFiscalPeriod'),
255 'values' => $fiscal_period_arr,
256 'default' => isset($next_active_fiscal_period) ? $next_active_fiscal_period[
'id'] :
'',
258 $form_question[
'generate_bookkeeping_records'] = array(
259 'name' =>
'generate_bookkeeping_records',
260 'type' =>
'checkbox',
261 'label' => $langs->trans(
'AccountancyClosureGenerateClosureBookkeepingRecords'),
264 $form_question[
'separate_auxiliary_account'] = array(
265 'name' =>
'separate_auxiliary_account',
266 'type' =>
'checkbox',
267 'label' => $langs->trans(
'AccountancyClosureSeparateAuxiliaryAccounts'),
271 $formconfirm = $form->formconfirm(
272 $_SERVER[
"PHP_SELF"] .
'?fiscal_period_id=' . $current_fiscal_period[
'id'],
273 $langs->trans(
'AccountancyClosureClose'),
274 $langs->trans(
'AccountancyClosureConfirmClose'),
282 } elseif ($action ==
'step_3') {
283 $form_question = array();
285 $form_question[
'inventory_journal_id'] = array(
286 'name' =>
'inventory_journal_id',
288 'label' => $langs->trans(
'InventoryJournal'),
289 'value' => $formaccounting->select_journal(0,
"inventory_journal_id", 8, 1, 0, 0)
291 $fiscal_period_arr = array();
292 foreach ($active_fiscal_periods as $info) {
293 $fiscal_period_arr[$info[
'id']] = $info[
'label'];
295 $form_question[
'new_fiscal_period_id'] = array(
296 'name' =>
'new_fiscal_period_id',
298 'label' => $langs->trans(
'AccountancyClosureStep3NewFiscalPeriod'),
299 'values' => $fiscal_period_arr,
300 'default' => isset($next_active_fiscal_period) ? $next_active_fiscal_period[
'id'] :
'',
302 $form_question[
'date_start'] = array(
303 'name' =>
'date_start',
305 'label' => $langs->trans(
'DateStart'),
308 $form_question[
'date_end'] = array(
309 'name' =>
'date_end',
311 'label' => $langs->trans(
'DateEnd'),
312 'value' => $current_fiscal_period[
'date_end']
315 $formconfirm = $form->formconfirm(
316 $_SERVER[
"PHP_SELF"] .
'?fiscal_period_id=' . $current_fiscal_period[
'id'],
317 $langs->trans(
'AccountancyClosureAccountingReversal'),
318 $langs->trans(
'AccountancyClosureConfirmAccountingReversal'),
330$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);
331$reshook = $hookmanager->executeHooks(
'formConfirm', $parameters, $object, $action);
332if (empty($reshook)) {
333 $formconfirm .= $hookmanager->resPrint;
334} elseif ($reshook > 0) {
335 $formconfirm = $hookmanager->resPrint;
341$fiscal_period_nav_text = $langs->trans(
"FiscalPeriod");
343$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>';
344$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>';
345if (!empty($current_fiscal_period)) {
346 $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') .
')' :
'');
349print
load_fiche_titre($langs->trans(
"Closure") .
" - " . $fiscal_period_nav_text,
'',
'title_accountancy');
351if (empty($current_fiscal_period)) {
352 print $langs->trans(
'ErrorNoFiscalPeriodActiveFound', $langs->transnoentitiesnoconv(
"Accounting"), $langs->transnoentitiesnoconv(
"Setup"), $langs->transnoentitiesnoconv(
"FiscalPeriod"));
357 $head[0][0] = DOL_URL_ROOT .
'/accountancy/closure/index.php?fiscal_period_id=' . $current_fiscal_period[
'id'];
358 $head[0][1] = $langs->trans(
"Step").
' 1 - '.$langs->trans(
"AccountancyClosureStep1");
359 $head[0][2] =
'step1';
362 print
'<span class="opacitymedium">' . $langs->trans(
"AccountancyClosureStep1Desc") .
'</span><br>';
364 $count_by_month =
$object->getCountByMonthForFiscalPeriod($current_fiscal_period[
'date_start'], $current_fiscal_period[
'date_end']);
366 if (!is_array($count_by_month)) {
370 if (empty($count_by_month[
'total'])) {
371 $buttonvalidate =
'<a class="butActionRefused classfortooltip" href="#">' . $langs->trans(
"ValidateMovements") .
'</a>';
373 $buttonvalidate =
'<a class="butAction" href="' . $_SERVER[
"PHP_SELF"] .
'?action=step_1&token='.newToken().
'&fiscal_period_id=' . $current_fiscal_period[
'id'] .
'">' . $langs->trans(
"ValidateMovements") .
'</a>';
375 print_barre_liste($langs->trans(
"OverviewOfMovementsNotValidated"), 0,
'',
'',
'',
'',
'', -1,
'',
'', 0, $buttonvalidate,
'', 0, 1, 0);
377 print
'<div class="div-table-responsive-no-min">';
378 print
'<table class="noborder centpercent">';
380 print
'<tr class="liste_titre">';
381 $nb_years = is_array($count_by_month[
'list']) ? count($count_by_month[
'list']) : 0;
383 print
'<td class="right">' . $langs->trans(
"Year") .
'</td>';
385 for ($i = 1; $i <= 12; $i++) {
386 print
'<td class="right">' . $langs->trans(
'MonthShort' . str_pad((
string) $i, 2,
'0', STR_PAD_LEFT)) .
'</td>';
388 print
'<td class="right"><b>' . $langs->trans(
"Total") .
'</b></td>';
391 if (is_array($count_by_month[
'list'])) {
392 foreach ($count_by_month[
'list'] as $info) {
393 print
'<tr class="oddeven">';
395 print
'<td class="right">' . $info[
'year'] .
'</td>';
397 for ($i = 1; $i <= 12; $i++) {
398 print
'<td class="right">' . ((int) $info[
'count'][$i]) .
'</td>';
400 print
'<td class="right"><b>' . $info[
'total'] .
'</b></td></tr>';
412 $head[0][0] = DOL_URL_ROOT .
'/accountancy/closure/index.php?fiscal_period_id=' . $current_fiscal_period[
'id'];
413 $head[0][1] = $langs->trans(
"Step").(getDolGlobalString(
"ACCOUNTANCY_DISABLE_CLOSURE_LINE_BY_LINE") ?
'1' :
'2').
' - '.$langs->trans(
"AccountancyClosureStep2");
414 $head[0][2] =
'step2';
419 if ((empty($count_by_month[
'total']) ||
getDolGlobalString(
"ACCOUNTANCY_DISABLE_CLOSURE_LINE_BY_LINE")) && empty($current_fiscal_period[
'status'])) {
421 $button =
'<a class="butAction" href="' . $_SERVER[
"PHP_SELF"] .
'?action=step_2&token='.newToken().
'&fiscal_period_id=' . $current_fiscal_period[
'id'] .
'">' . $langs->trans(
"AccountancyClosureClose") .
'</a>';
423 if (!empty($current_fiscal_period[
'status'])) {
424 $button =
'<a class="butActionRefused classfortooltip" href="#" title="The period is already closed. Feature disabled.">' . $langs->trans(
"AccountancyClosureClose") .
'</a>';
425 } elseif (!empty($count_by_month[
'total'])) {
426 $button =
'<a class="butActionRefused classfortooltip" href="#" title="There is some lines not yet locked. Feature disabled.">' . $langs->trans(
"AccountancyClosureClose") .
'</a>';
429 print_barre_liste(
'', 0,
'',
'',
'',
'',
'', -1,
'',
'', 0, $button,
'', 0, 1, 0);
435 $head[0][0] = DOL_URL_ROOT .
'/accountancy/closure/index.php?fiscal_period_id=' . $current_fiscal_period[
'id'];
436 $head[0][1] = $langs->trans(
"Step").(getDolGlobalString(
"ACCOUNTANCY_DISABLE_CLOSURE_LINE_BY_LINE") ?
'2' :
'3').
' - '.$langs->trans(
"AccountancyClosureStep3");
437 $head[0][2] =
'step3';
442 if (empty($current_fiscal_period[
'status'])) {
443 $button =
'<a class="butActionRefused classfortooltip" href="#">' . $langs->trans(
"AccountancyClosureAccountingReversal") .
'</a>';
445 $button =
'<a class="butAction" href="' . $_SERVER[
"PHP_SELF"] .
'?action=step_3&token='.newToken().
'&fiscal_period_id=' . $current_fiscal_period[
'id'] .
'">' . $langs->trans(
"AccountancyClosureAccountingReversal") .
'</a>';
447 print_barre_liste(
'', 0,
'',
'',
'',
'',
'', -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.