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 9eed195 commit d2a279c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 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 @@ -2533,7 +2533,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<array{id:int,label:string,date_start:string,date_end:string,status:int}>|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', $langs->transnoentitiesnoconv("Accounting"), $langs->transnoentitiesnoconv("Setup"), $langs->transnoentitiesnoconv("FiscalPeriod"));
}

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
2 changes: 1 addition & 1 deletion htdocs/langs/en_US/accountancy.lang
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ AccountancyErrorMismatchBalanceAmount=The balance (%s) is not equal to 0
AccountancyErrorLetteringBookkeeping=Errors have occurred concerning the transactions: %s
ErrorAccountNumberAlreadyExists=The accounting number %s already exists
ErrorArchiveAddFile=Can't put "%s" file in archive
ErrorNoFiscalPeriodActiveFound=No active fiscal period found. You can create one from menu %s - %s - %s.
ErrorNoFiscalPeriodActiveFound=No active fiscal period (with a start and end date defined) found. You can create one from menu %s - %s - %s.
ErrorBookkeepingDocDateNotOnActiveFiscalPeriod=The bookkeeping doc date is not inside the active fiscal period
ErrorBookkeepingDocDateIsOnAClosedFiscalPeriod=The bookkeeping doc date is inside a closed fiscal period
## Import
Expand Down

0 comments on commit d2a279c

Please sign in to comment.