I have an application where each user can request their vacations. There are two types of users, fixed
and temporary
. Fixed users have 24 days a year for vacations. The doubt comes with the temporary users.
Temporary users are added 2 days per month worked until December 31 of that year. For example:
user1
entered the company on 25/01/2019, until 31/12/2019 would have to increase it 2 days per month worked until that date, in total 22 days. As of 01/01/2020, those 2 days, will be increased every calendar month and start from 0, so that 01/01/2020 would have 0 days and 01/02/2020 would have 2 days.
Is there a PHP
function or in MySQL
a procedure for those 2 days to automatically add them to the database?
In the database I have a user
table that has the following fields:
name available_days start_date
======= ================= ============
user1 0 25/01/2019
To those available_days
is to which the days must be increased.
I have this function that calculates the difference in months since the user entered the company until today:
function difcurrentmonth($startdate){
$date = new DateTime($startdate);
$currentdate= (new DateTime)->format('Y-m-d H:i');
$finaldate = new DateTime($currentdate);
$dif = $date->diff($finaldate );
$month = ( $dif->y * 12 ) + $dif->m;
return $month;
}
$month = difcurrentmonth("2019-01-25");
$available_days= $month * 2;