Skip to content

Commit

Permalink
FIX autoselect the fiscal period by default
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Sep 30, 2024
1 parent 218bfff commit 7b61965
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
2 changes: 1 addition & 1 deletion htdocs/accountancy/class/bookkeeping.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2462,7 +2462,7 @@ public function loadFiscalPeriods($force = false, $mode = 'active')
}

/**
* Get list of fiscal period
* Get list of fiscal period ordered by start date.
*
* @param string $filter Filter
* @return array|int Return integer <0 if KO, Fiscal periods : [[id, date_start, date_end, label], ...]
Expand Down
38 changes: 30 additions & 8 deletions htdocs/accountancy/closure/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,33 +60,57 @@
setEventMessages($object->error, $object->errors, 'errors');
}

// Define the arrays of fiscal periods
$active_fiscal_periods = array();
$first_active_fiscal_period = null;
$last_fiscal_period = null;
$current_fiscal_period = null;
$next_fiscal_period = null;
$next_active_fiscal_period = null;
if (is_array($fiscal_periods)) {
foreach ($fiscal_periods as $fiscal_period) {
if (empty($fiscal_period['status'])) {
foreach ($fiscal_periods as $fiscal_period) { // List of fiscal periods sorted by date start
if (empty($first_active_fiscal_period) && empty($fiscal_period['status'])) {
$first_active_fiscal_period = $fiscal_period;
}
if (empty($fiscal_period['status'])) { // if not closed
$active_fiscal_periods[] = $fiscal_period;
}
if (isset($current_fiscal_period)) {
if (isset($current_fiscal_period)) { // If we already reach then current fiscal period, then this one is the next one just after
if (!isset($next_fiscal_period)) {
$next_fiscal_period = $fiscal_period;
}
if (!isset($next_active_fiscal_period) && empty($fiscal_period['status'])) {
$next_active_fiscal_period = $fiscal_period;
}
} else {
} else { // If we did not found the current fiscal period
if ($fiscal_period_id == $fiscal_period['id'] || (empty($fiscal_period_id) && $fiscal_period['date_start'] <= $now && $now <= $fiscal_period['date_end'])) {
$current_fiscal_period = $fiscal_period;
} else {
$last_fiscal_period = $fiscal_period;
$last_fiscal_period = $fiscal_period; // $last_fiscal_period is in fact $previous_fiscal_period
}
}
}
}

// If a current fiscal period open with an end and start date was not found, we autoselect the first one that is open and has a start and end date defined
if (empty($current_fiscal_period) && !empty($first_active_fiscal_period)) {
$current_fiscal_period = $first_active_fiscal_period;
$last_fiscal_period = null;
$foundcurrent = false;
foreach ($fiscal_periods as $fiscal_period) { // List of fiscal periods sorted by date start
if ($foundcurrent) {
$next_fiscal_period = $fiscal_period;
break;
}
if ($fiscal_period['id'] == $current_fiscal_period['id']) {
$foundcurrent = true;
}
if (!$foundcurrent) {
$last_fiscal_period = $fiscal_period;
}
}
}

$accounting_groups_used_for_balance_sheet_account = array_filter(array_map('trim', explode(',', getDolGlobalString('ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_BALANCE_SHEET_ACCOUNT'))), 'strlen');
$accounting_groups_used_for_income_statement = array_filter(array_map('trim', explode(',', getDolGlobalString('ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_INCOME_STATEMENT'))), 'strlen');

Expand Down Expand Up @@ -315,9 +339,7 @@

if (empty($current_fiscal_period)) {
print $langs->trans('ErrorNoFiscalPeriodActiveFound');
}

if (isset($current_fiscal_period)) {
} else {
// Step 1
$head = array();
$head[0][0] = DOL_URL_ROOT . '/accountancy/closure/index.php?fiscal_period_id=' . $current_fiscal_period['id'];
Expand Down

0 comments on commit 7b61965

Please sign in to comment.