From 218bfff6fa402417b95f1260d2f9ac6f7f910529 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 30 Sep 2024 11:55:32 +0200 Subject: [PATCH 1/8] Tooltip to explain why button is disabled. --- htdocs/accountancy/closure/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/accountancy/closure/index.php b/htdocs/accountancy/closure/index.php index 0b6739bf742..b01f3f1616d 100644 --- a/htdocs/accountancy/closure/index.php +++ b/htdocs/accountancy/closure/index.php @@ -381,7 +381,7 @@ if (isset($current_fiscal_period)) { if (empty($count_by_month['total']) && empty($current_fiscal_period['status'])) { $button = '' . $langs->trans("AccountancyClosureClose") . ''; } else { - $button = '' . $langs->trans("AccountancyClosureClose") . ''; + $button = '' . $langs->trans("AccountancyClosureClose") . ''; } print_barre_liste('', '', '', '', '', '', '', -1, '', '', 0, $button, '', 0, 1, 0); From d2a279cc7df34cca7555b66dac8da9afe5f580ff Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 30 Sep 2024 13:12:42 +0200 Subject: [PATCH 2/8] FIX autoselect the fiscal period by default --- .../accountancy/class/bookkeeping.class.php | 2 +- htdocs/accountancy/closure/index.php | 38 +++++++++++++++---- htdocs/langs/en_US/accountancy.lang | 2 +- 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/htdocs/accountancy/class/bookkeeping.class.php b/htdocs/accountancy/class/bookkeeping.class.php index 1e4afa2d45f..66bd62cce11 100644 --- a/htdocs/accountancy/class/bookkeeping.class.php +++ b/htdocs/accountancy/class/bookkeeping.class.php @@ -2533,7 +2533,7 @@ class BookKeeping extends CommonObject } /** - * 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], ...] diff --git a/htdocs/accountancy/closure/index.php b/htdocs/accountancy/closure/index.php index 43f9179c599..c59a8652375 100644 --- a/htdocs/accountancy/closure/index.php +++ b/htdocs/accountancy/closure/index.php @@ -60,33 +60,57 @@ if (!is_array($fiscal_periods)) { 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'); @@ -315,9 +339,7 @@ print load_fiche_titre($langs->trans("Closure") . " - " . $fiscal_period_nav_tex 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']; diff --git a/htdocs/langs/en_US/accountancy.lang b/htdocs/langs/en_US/accountancy.lang index b799215f95d..b48493f6600 100644 --- a/htdocs/langs/en_US/accountancy.lang +++ b/htdocs/langs/en_US/accountancy.lang @@ -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 From 7b61965042faf573d267aa0b14678cdbb324ac0f Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 30 Sep 2024 13:12:42 +0200 Subject: [PATCH 3/8] FIX autoselect the fiscal period by default --- .../accountancy/class/bookkeeping.class.php | 2 +- htdocs/accountancy/closure/index.php | 38 +++++++++++++++---- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/htdocs/accountancy/class/bookkeeping.class.php b/htdocs/accountancy/class/bookkeeping.class.php index 97387198fcd..be140363e3c 100644 --- a/htdocs/accountancy/class/bookkeeping.class.php +++ b/htdocs/accountancy/class/bookkeeping.class.php @@ -2462,7 +2462,7 @@ class BookKeeping extends CommonObject } /** - * 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], ...] diff --git a/htdocs/accountancy/closure/index.php b/htdocs/accountancy/closure/index.php index b01f3f1616d..b140dff0704 100644 --- a/htdocs/accountancy/closure/index.php +++ b/htdocs/accountancy/closure/index.php @@ -60,33 +60,57 @@ if (!is_array($fiscal_periods)) { 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'); @@ -315,9 +339,7 @@ print load_fiche_titre($langs->trans("Closure") . " - " . $fiscal_period_nav_tex 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']; From 946726779c6d5d703b6b383de60f8b288d5d8dd4 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 30 Sep 2024 13:23:04 +0200 Subject: [PATCH 4/8] Fix test on setup --- htdocs/accountancy/closure/index.php | 7 +++---- htdocs/langs/en_US/errors.lang | 1 + 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/htdocs/accountancy/closure/index.php b/htdocs/accountancy/closure/index.php index b140dff0704..9489e519218 100644 --- a/htdocs/accountancy/closure/index.php +++ b/htdocs/accountancy/closure/index.php @@ -151,11 +151,10 @@ if (empty($reshook)) { if ($generate_bookkeeping_records) { if (!getDolGlobalString('ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_BALANCE_SHEET_ACCOUNT')) { $error++; - setEventMessages($langs->trans("ErrorSetupNotComplete"), null, 'errors'); - } - if (!getDolGlobalString('ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_INCOME_STATEMENT')) { + setEventMessages($langs->trans("ErrorAccountingClosureSetupNotComplete"), null, 'errors'); + } elseif (!getDolGlobalString('ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_INCOME_STATEMENT')) { $error++; - setEventMessages($langs->trans("ErrorSetupNotComplete"), null, 'errors'); + setEventMessages($langs->trans("ErrorAccountingClosureSetupNotComplete"), null, 'errors'); } } diff --git a/htdocs/langs/en_US/errors.lang b/htdocs/langs/en_US/errors.lang index 681abb1aedc..29558bfd042 100644 --- a/htdocs/langs/en_US/errors.lang +++ b/htdocs/langs/en_US/errors.lang @@ -58,6 +58,7 @@ ErrorSubjectIsRequired=The email subject is required ErrorFailedToCreateDir=Failed to create a directory. Check that Web server user has permissions to write into Dolibarr documents directory. If parameter safe_mode is enabled on this PHP, check that Dolibarr php files owns to web server user (or group). ErrorNoMailDefinedForThisUser=No mail defined for this user ErrorSetupOfEmailsNotComplete=Setup of emails is not complete +ErrorAccountingClosureSetupNotComplete=Setup of closure accounts not complete ErrorFeatureNeedJavascript=This feature needs JavaScript to be activated to work. Change this in setup - display. ErrorTopMenuMustHaveAParentWithId0=A menu of type 'Top' can't have a parent menu. Put 0 in parent menu or choose a menu of type 'Left'. ErrorLeftMenuMustHaveAParentId=A menu of type 'Left' must have a parent id. From fde37d8172af5a28a753324503c17f3971da161b Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 30 Sep 2024 13:36:30 +0200 Subject: [PATCH 5/8] Fix deadlock situation by adding a constant in hope to save user --- htdocs/accountancy/admin/fiscalyear_card.php | 23 ++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/htdocs/accountancy/admin/fiscalyear_card.php b/htdocs/accountancy/admin/fiscalyear_card.php index 06dc52d3247..ebf576ca34a 100644 --- a/htdocs/accountancy/admin/fiscalyear_card.php +++ b/htdocs/accountancy/admin/fiscalyear_card.php @@ -94,7 +94,7 @@ if ($reshook < 0) { setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); } -if ($action == 'confirm_delete' && $confirm == "yes") { +if ($action == 'confirm_delete' && $confirm == "yes" && $permissiontoadd) { $result = $object->delete($id); if ($result >= 0) { header("Location: fiscalyear.php"); @@ -102,7 +102,7 @@ if ($action == 'confirm_delete' && $confirm == "yes") { } else { setEventMessages($object->error, $object->errors, 'errors'); } -} elseif ($action == 'add') { +} elseif ($action == 'add' && $permissiontoadd) { if (!GETPOST('cancel', 'alpha')) { $error = 0; @@ -144,7 +144,7 @@ if ($action == 'confirm_delete' && $confirm == "yes") { header("Location: ./fiscalyear.php"); exit(); } -} elseif ($action == 'update') { +} elseif ($action == 'update' && $permissiontoadd) { // Update record if (!GETPOST('cancel', 'alpha')) { $result = $object->fetch($id); @@ -166,8 +166,19 @@ if ($action == 'confirm_delete' && $confirm == "yes") { header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); exit(); } -} +} elseif ($action == 'reopen' && $permissiontoadd && getDolGlobalString('ACCOUNTING_CAN_REOPEN_CLOSED_PERIOD')) { + $result = $object->fetch($id); + $object->status = GETPOST('status', 'int'); + $result = $object->update($user); + + if ($result > 0) { + header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); + exit(); + } else { + setEventMessages($object->error, $object->errors, 'errors'); + } +} /* @@ -345,6 +356,10 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea if ($user->hasRight('accounting', 'fiscalyear', 'write')) { print '
'; + if (getDolGlobalString('ACCOUNTING_CAN_REOPEN_CLOSED_PERIOD') && $object->status == $object::STATUS_CLOSED) { + print dolGetButtonAction($langs->trans("ReOpen"), '', 'reopen', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=reopen&token='.newToken(), 'reopen', $permissiontoadd); + } + print ''.$langs->trans('Modify').''; //print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', $permissiontodelete); From 4b9ce8a9bcb8ee11d25dd834d2808362b238b551 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 30 Sep 2024 15:38:31 +0200 Subject: [PATCH 6/8] Fix: method getImagePublicURLOfObject can't work on WebsitePage so add a method getImageFromHtmlContent to compensate. --- htdocs/core/lib/website.lib.php | 44 ++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/htdocs/core/lib/website.lib.php b/htdocs/core/lib/website.lib.php index 6f0abb8e1ca..e1a2a3f4217 100644 --- a/htdocs/core/lib/website.lib.php +++ b/htdocs/core/lib/website.lib.php @@ -1023,7 +1023,7 @@ function getNbOfImagePublicURLOfObject($object) * @param int $no Numero of image (if there is several images. 1st one by default) * @param string $extName Extension to differentiate thumb file name ('', '_small', '_mini') * @return string HTML img content or '' if no image found - * @see getNbOfImagePublicURLOfObject() + * @see getNbOfImagePublicURLOfObject(), getImageFromHtmlContent() */ function getImagePublicURLOfObject($object, $no = 1, $extName = '') { @@ -1315,6 +1315,48 @@ function getPagesFromSearchCriterias($type, $algo, $searchstring, $max = 25, $so return $arrayresult; } +/** + * Return the URL of an image found into a HTML content. + * To get image from an external URL to download first, see getAllImages() + * + * @param string $htmlContent HTML content + * @param int $imageNumber The position of image. 1 by default = first image found + * @return string URL of image or '' if not foud + * @see getImagePublicURLOfObject() + */ +function getImageFromHtmlContent($htmlContent, $imageNumber = 1) +{ + $dom = new DOMDocument(); + + libxml_use_internal_errors(false); // Avoid to fill memory with xml errors + if (LIBXML_VERSION < 20900) { + // Avoid load of external entities (security problem). + // Required only if LIBXML_VERSION < 20900 + // @phan-suppress-next-line PhanDeprecatedFunctionInternal + libxml_disable_entity_loader(true); + } + + // Load HTML content into object + $dom->loadHTML($htmlContent); + + // Re-enable HTML load errors + libxml_clear_errors(); + + // Load all img tags + $images = $dom->getElementsByTagName('img'); + + // Check if nb of image is valid + if ($imageNumber > 0 && $imageNumber <= $images->length) { + // Récupère l'image correspondante (index - 1 car $imageNumber est 1-based) + $img = $images->item($imageNumber - 1); + if ($img instanceof DOMElement) { + return $img->getAttribute('src'); + } + } + + return ''; +} + /** * Download all images found into page content $tmp. * If $modifylinks is set, links to images will be replace with a link to viewimage wrapper. From 5886355a879d5fb22fb31c697edde07218132672 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 30 Sep 2024 16:09:19 +0200 Subject: [PATCH 7/8] Fix image in RSS --- htdocs/core/lib/xcal.lib.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/htdocs/core/lib/xcal.lib.php b/htdocs/core/lib/xcal.lib.php index 5101f70959a..f8db5833635 100644 --- a/htdocs/core/lib/xcal.lib.php +++ b/htdocs/core/lib/xcal.lib.php @@ -397,6 +397,18 @@ function build_rssfile($format, $title, $desc, $events_array, $outputfile, $filt $tmpevent['desc'] = $event->description; if (!empty($event->image)) { $tmpevent['image'] = $GLOBALS['website']->virtualhost.'/medias/'.$event->image; + } else { + include_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php'; + $tmpimage = getImageFromHtmlContent($event->content); + if ($tmpimage) { + if (strpos($tmpimage, '/') === 0) { // If $tmpimage is an absolute path + $tmpevent['image'] = $GLOBALS['website']->virtualhost.$tmpimage; + } elseif (stripos($tmpimage, 'http:') === 0) { // If $tmpimage is a full URI + $tmpevent['image'] = $tmpimage; + } else { + $tmpevent['image'] = $GLOBALS['website']->virtualhost.'/medias/'.$tmpimage; + } // TODO If $tmpimage is "data:..." + } } $tmpevent['content'] = $event->content; From 4a86964e1851bd93c2cfb29afcde189e04e36158 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 30 Sep 2024 16:18:46 +0200 Subject: [PATCH 8/8] Fix image in RSS --- htdocs/core/lib/xcal.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/lib/xcal.lib.php b/htdocs/core/lib/xcal.lib.php index f8db5833635..8b4fef3ed5f 100644 --- a/htdocs/core/lib/xcal.lib.php +++ b/htdocs/core/lib/xcal.lib.php @@ -403,7 +403,7 @@ function build_rssfile($format, $title, $desc, $events_array, $outputfile, $filt if ($tmpimage) { if (strpos($tmpimage, '/') === 0) { // If $tmpimage is an absolute path $tmpevent['image'] = $GLOBALS['website']->virtualhost.$tmpimage; - } elseif (stripos($tmpimage, 'http:') === 0) { // If $tmpimage is a full URI + } elseif (stripos($tmpimage, 'http') === 0) { // If $tmpimage is a full URI $tmpevent['image'] = $tmpimage; } else { $tmpevent['image'] = $GLOBALS['website']->virtualhost.'/medias/'.$tmpimage;