Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New: add configuration to choose if holiday are updated at the end of month #29438

Merged

Conversation

YannisHoareau
Copy link
Contributor

If the configuration is selected, the holiday balance is not updated when clicked on approve, it is now updated at the end of the month, when the balance get increased.
If a leave period gets cancelled, only the already consummated days are credited again in balance.

YannisHoareau and others added 24 commits April 18, 2024 16:36
…ustRaosha/dolibarr into new-holiday-update-at-the-end-of-month
…ustRaosha/dolibarr into new-holiday-update-at-the-end-of-month
// Get month of last update
$lastUpdate = $this->getConfCP('lastUpdate', $newdateforlastupdate);
$monthLastUpdate = $lastUpdate[4].$lastUpdate[5];
$lastUpdate = strtotime($this->getConfCP('lastUpdate', dol_print_date($now, '%Y%m%d%H%M%S')));
Copy link
Member

@eldy eldy May 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The use of strtotime is forbidden because it does not deal correctly the timezone.
You can use dol_stringtotime()


// If month date is not same than the one of last update (the one we saved in database), then we update the timestamp and balance of each open user,
// catching up to the current month if a gap is detected
while (date('Ym', $lastUpdate) < date('Ym', $now)) {
Copy link
Member

@eldy eldy May 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The use of date() function is forbidden because it does not deal correctly the timezone.
You can use dol_print_date
PS: to avoid call to a function inside the while (function()). You should set 2 variables, for example $yearmonth = ... and $yearmonthnow = ... and then do
while (yearmonth < $yearmonthnow)

@eldy eldy added the PR to fix - See feedback in comments PR needs to be fixed to be integrated (some comments should describes the fix to do) label May 10, 2024
return 1;
} else {
//updating the date of the last monthly balance update
$lastUpdate = strtotime('+1 month', strtotime(date('Ym01His', $lastUpdate)));
Copy link
Member

@eldy eldy May 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strtotime is forbidden as it does not deal correctly the timezone and daylight times.

// We add a log for each user
$this->addLogCP($user->id, $userCounter['rowid'], $langs->trans('HolidaysMonthlyUpdate'), $newSolde, $userCounter['type']);
// We add a log for each user when its balance gets increased
$this->addLogCP($user->id, $userCounter['rowid'], $langs->trans('HolidayMonthlyCredit'), $newSolde, $userCounter['type']);
Copy link
Member

@eldy eldy May 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the goal of adding the translation key HolidayMonthlyCredit compared to HolidayMonthlyUpdate ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The goal is to be more understandable when reading the logs of the update because update could mean increasing or decreasing. Now, the user would know if his balance is credited or debited.

@YannisHoareau
Copy link
Contributor Author

YannisHoareau commented Sep 3, 2024

Hello @eldy, I have updated this branch to the latest commits and it is working, could you please take a look at this new feature and give any feedback if I have to improve anything.

@YannisHoareau
Copy link
Contributor Author

Hey @eldy, any news about this new feature ?

@eldy eldy merged commit 42089e3 into Dolibarr:develop Oct 9, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR to fix - See feedback in comments PR needs to be fixed to be integrated (some comments should describes the fix to do)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants