From 1e7df0ba9fe9f8b247e77ac8b0f75b98a969bb01 Mon Sep 17 00:00:00 2001 From: Marc de Lima Lucio <68746600+marc-dll@users.noreply.github.com> Date: Thu, 10 Jun 2021 21:53:06 +0200 Subject: [PATCH 1/3] NEW: holiday: handle monthly updates with cronjob --- htdocs/core/modules/modHoliday.class.php | 22 ++++++++++++++++++++++ htdocs/holiday/class/holiday.class.php | 2 +- htdocs/holiday/define_holiday.php | 4 ---- htdocs/holiday/list.php | 3 --- htdocs/hrm/index.php | 10 ---------- htdocs/langs/en_US/holiday.lang | 1 + test/phpunit/HolidayTest.php | 2 +- 7 files changed, 25 insertions(+), 19 deletions(-) diff --git a/htdocs/core/modules/modHoliday.class.php b/htdocs/core/modules/modHoliday.class.php index 23cbf7eddf8..76700b59b31 100644 --- a/htdocs/core/modules/modHoliday.class.php +++ b/htdocs/core/modules/modHoliday.class.php @@ -135,6 +135,28 @@ class modHoliday extends DolibarrModules //$r++; + // Cronjobs + $arraydate = dol_getdate(dol_now()); + $datestart = dol_mktime(4, 0, 0, $arraydate['mon'], $arraydate['mday'], $arraydate['year']); + $this->cronjobs = array( + 0 => array( + 'label' => 'HolidayBalanceMonthlyUpdate', + 'jobtype' => 'method', + 'class' => 'holiday/class/holiday.class.php', + 'objectname' => 'Holiday', + 'method' => 'updateBalance', + 'parameters' => '', + 'comment' => 'Update holiday balance every month', + 'frequency' => 1, + 'unitfrequency' => 3600 * 24, + 'priority' => 50, + 'status' => 1, + 'test' => '$conf->holiday->enabled', + 'datestart' => $datestart + ) + ); + + // Permissions $this->rights = array(); // Permission array used by this module $r = 0; diff --git a/htdocs/holiday/class/holiday.class.php b/htdocs/holiday/class/holiday.class.php index 55dd1c4bafb..b885202f3a9 100644 --- a/htdocs/holiday/class/holiday.class.php +++ b/htdocs/holiday/class/holiday.class.php @@ -227,7 +227,7 @@ class Holiday extends CommonObject if ($result >= 0) { $this->db->commit(); - return 1; + return 0; // for cronjob use (0 is OK, any other value is an error code) } else { $this->db->rollback(); return -1; diff --git a/htdocs/holiday/define_holiday.php b/htdocs/holiday/define_holiday.php index b3d2c25adda..fcb8b73d486 100644 --- a/htdocs/holiday/define_holiday.php +++ b/htdocs/holiday/define_holiday.php @@ -193,10 +193,6 @@ llxHeader('', $langs->trans('CPTitreMenu')); $typeleaves = $holiday->getTypes(1, 1); -$result = $holiday->updateBalance(); // Create users into table holiday if they don't exists. TODO Remove this whif we use field into table user. -if ($result < 0) { - setEventMessages($holiday->error, $holiday->errors, 'errors'); -} print '
'; diff --git a/htdocs/holiday/list.php b/htdocs/holiday/list.php index c62185d5f2a..9d569f4344e 100644 --- a/htdocs/holiday/list.php +++ b/htdocs/holiday/list.php @@ -231,9 +231,6 @@ $formfile = new FormFile($db); $fuser = new User($db); $holidaystatic = new Holiday($db); -// Update sold -$result = $object->updateBalance(); - $title = $langs->trans('CPTitreMenu'); llxHeader('', $title); diff --git a/htdocs/hrm/index.php b/htdocs/hrm/index.php index 50fd4c3f521..6cc4dc3b5bd 100644 --- a/htdocs/hrm/index.php +++ b/htdocs/hrm/index.php @@ -68,16 +68,6 @@ if (empty($conf->global->MAIN_INFO_SOCIETE_NOM) || empty($conf->global->MAIN_INF $max = $conf->global->MAIN_SIZE_SHORTLIST_LIMIT; -/* - * Actions - */ - -// Update sold -if (!empty($conf->holiday->enabled) && !empty($setupcompanynotcomplete)) { - $holidaystatic = new Holiday($db); - $result = $holidaystatic->updateBalance(); -} - /* * View diff --git a/htdocs/langs/en_US/holiday.lang b/htdocs/langs/en_US/holiday.lang index 2393a02ee50..0e6b1d69b36 100644 --- a/htdocs/langs/en_US/holiday.lang +++ b/htdocs/langs/en_US/holiday.lang @@ -132,3 +132,4 @@ FreeLegalTextOnHolidays=Free text on PDF WatermarkOnDraftHolidayCards=Watermarks on draft leave requests HolidaysToApprove=Holidays to approve NobodyHasPermissionToValidateHolidays=Nobody has permission to validate holidays +HolidayBalanceMonthlyUpdate=Monthly update of holiday balance diff --git a/test/phpunit/HolidayTest.php b/test/phpunit/HolidayTest.php index bba5d68c41e..415d45da674 100644 --- a/test/phpunit/HolidayTest.php +++ b/test/phpunit/HolidayTest.php @@ -366,6 +366,6 @@ class HolidayTest extends PHPUnit\Framework\TestCase $localobjecta->updateConfCP('lastUpdate', '20100101120000'); $result = $localobjecta->updateBalance(); - $this->assertEquals($result, 1); + $this->assertEquals($result, 0); } } From 82feb57fcfbfdd971a1a4c7581878fbc1c1349fc Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Thu, 10 Jun 2021 19:56:03 +0000 Subject: [PATCH 2/3] Fixing style errors. --- htdocs/core/modules/modHoliday.class.php | 28 ++++++++++++------------ 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/htdocs/core/modules/modHoliday.class.php b/htdocs/core/modules/modHoliday.class.php index 76700b59b31..71ab96e65bd 100644 --- a/htdocs/core/modules/modHoliday.class.php +++ b/htdocs/core/modules/modHoliday.class.php @@ -140,20 +140,20 @@ class modHoliday extends DolibarrModules $datestart = dol_mktime(4, 0, 0, $arraydate['mon'], $arraydate['mday'], $arraydate['year']); $this->cronjobs = array( 0 => array( - 'label' => 'HolidayBalanceMonthlyUpdate', - 'jobtype' => 'method', - 'class' => 'holiday/class/holiday.class.php', - 'objectname' => 'Holiday', - 'method' => 'updateBalance', - 'parameters' => '', - 'comment' => 'Update holiday balance every month', - 'frequency' => 1, - 'unitfrequency' => 3600 * 24, - 'priority' => 50, - 'status' => 1, - 'test' => '$conf->holiday->enabled', - 'datestart' => $datestart - ) + 'label' => 'HolidayBalanceMonthlyUpdate', + 'jobtype' => 'method', + 'class' => 'holiday/class/holiday.class.php', + 'objectname' => 'Holiday', + 'method' => 'updateBalance', + 'parameters' => '', + 'comment' => 'Update holiday balance every month', + 'frequency' => 1, + 'unitfrequency' => 3600 * 24, + 'priority' => 50, + 'status' => 1, + 'test' => '$conf->holiday->enabled', + 'datestart' => $datestart + ) ); From 4d6372dda12f9c36c00c1901fb0c9f529f7a8ab1 Mon Sep 17 00:00:00 2001 From: Marc de Lima Lucio <68746600+marc-dll@users.noreply.github.com> Date: Fri, 16 Jul 2021 12:10:25 +0200 Subject: [PATCH 3/3] FIX: holiday balances: revert part of commit 1e7df0ba9 to still increment on page visit --- htdocs/holiday/define_holiday.php | 4 ++++ htdocs/holiday/list.php | 3 +++ htdocs/hrm/index.php | 10 ++++++++++ 3 files changed, 17 insertions(+) diff --git a/htdocs/holiday/define_holiday.php b/htdocs/holiday/define_holiday.php index fcb8b73d486..b3d2c25adda 100644 --- a/htdocs/holiday/define_holiday.php +++ b/htdocs/holiday/define_holiday.php @@ -193,6 +193,10 @@ llxHeader('', $langs->trans('CPTitreMenu')); $typeleaves = $holiday->getTypes(1, 1); +$result = $holiday->updateBalance(); // Create users into table holiday if they don't exists. TODO Remove this whif we use field into table user. +if ($result < 0) { + setEventMessages($holiday->error, $holiday->errors, 'errors'); +} print ''; diff --git a/htdocs/holiday/list.php b/htdocs/holiday/list.php index 9d569f4344e..c62185d5f2a 100644 --- a/htdocs/holiday/list.php +++ b/htdocs/holiday/list.php @@ -231,6 +231,9 @@ $formfile = new FormFile($db); $fuser = new User($db); $holidaystatic = new Holiday($db); +// Update sold +$result = $object->updateBalance(); + $title = $langs->trans('CPTitreMenu'); llxHeader('', $title); diff --git a/htdocs/hrm/index.php b/htdocs/hrm/index.php index 6cc4dc3b5bd..50fd4c3f521 100644 --- a/htdocs/hrm/index.php +++ b/htdocs/hrm/index.php @@ -68,6 +68,16 @@ if (empty($conf->global->MAIN_INFO_SOCIETE_NOM) || empty($conf->global->MAIN_INF $max = $conf->global->MAIN_SIZE_SHORTLIST_LIMIT; +/* + * Actions + */ + +// Update sold +if (!empty($conf->holiday->enabled) && !empty($setupcompanynotcomplete)) { + $holidaystatic = new Holiday($db); + $result = $holidaystatic->updateBalance(); +} + /* * View