/** * Autofill WU ("Not justified") for users without reporting anything. * * This function is used to verify that a user has $config["hours_perday"] * (as minimum) in each labor day in a period of time going from * now - $config["autowu_completion"] until now - ($config["autowu_completion"]*2) * If user dont have WU in that days, will create a WU associated * to task "Not Justified" inside special project -1. */ function run_autowu() { global $config; $now = date("Y-m-d"); // getWorkingDays($startDate,$endDate,$holidays){ $autowu = $config["autowu_completion"]; if ($autowu == 0) { return; } $autowu2 = $autowu + 7; // Always work with one week of margin // Calc interval dates $start_date = date('Y-m-d', strtotime("{$now} - {$autowu2} days")); $end_date = date('Y-m-d', strtotime("{$now} - {$autowu} days")); $current_date = $start_date; // For each user $users = get_db_all_rows_sql("SELECT * FROM tusuario"); $end_loop = 0; while ($end_loop == 0) { foreach ($users as $user) { if (!is_working_day($current_date)) { continue; } // If this user is in no_wu_completion list, skip it. if (strpos("_____" . $config["no_wu_completion"], $user["id_usuario"]) > 0) { continue; } $user_wu = get_wu_hours_user($user["id_usuario"], $current_date); if ($user_wu < $config["hours_perday"]) { $nombre = $user['nombre_real']; $email = $user['direccion']; $mail_description = "Integria IMS has entered an automated Workunit to 'Not justified' task because you've more than {$autowu} days without filling by a valid Workunit."; integria_sendmail($email, "[" . $config["sitename"] . "] Automatic WU (Non justified) has been entered", $mail_description); create_wu_task(-3, $user["id_usuario"], $mail_description, 0, 0, 0, $config["hours_perday"] - $user_wu, $current_date); } } $current_date = date('Y-m-d', strtotime("{$current_date} +1 day")); if ($current_date == $end_date) { $end_loop = 1; } } }
function calendar_get_holidays_by_timerange($begin_unix, $end_unix) { $day_in_seconds = 3600 * 24; //Normalize dates to 00:00:00 $norm = date('Y-m-d', $begin_unix); $begin_unix = strtotime($norm); $norm = date('Y-m-d', $end_unix); $end_unix = strtotime($norm); $holidays = array(); for ($i = $begin_unix; $i <= $end_unix; $i = $i + $day_in_seconds) { $str_date = date('Y-m-d', $i); if (!is_working_day($str_date)) { array_push($holidays, $str_date); } } return $holidays; }
function incidents_get_holidays_seconds_by_timerange($begin, $end) { //Get all holidays in this range and convert to seconds $holidays = calendar_get_holidays_by_timerange($begin, $end); $day_in_seconds = 3600 * 24; $holidays_seconds = count($holidays) * $day_in_seconds; //We need to tune a bit the amount of seconds calculated before //1.- If start date was holiday only discount seconds from creation time to next day $str_date = date('Y-m-d', $begin); if (!is_working_day($str_date)) { //Calculate seconds to next day $start_day = strtotime($str_date); $finish_time = $start_day + $day_in_seconds; $aux_seconds = $finish_time - $begin; $holidays_seconds = $holidays_seconds - $aux_seconds; } //2.- If finish date was holiday only discount seconds from now to begining of the day $str_date = date('Y-m-d', $end); if (!is_working_day($str_date)) { //Calculate seconds to next day $begining_day = strtotime($str_date); $aux_seconds = $end - $begining_day; $holidays_seconds = $holidays_seconds - $aux_seconds; } return $holidays_seconds; }