Adjusted monthly quotas plugin to use configurable holidays.
authorNik Okuntseff <support@anuko.com>
Sat, 27 Apr 2019 15:16:45 +0000 (15:16 +0000)
committerNik Okuntseff <support@anuko.com>
Sat, 27 Apr 2019 15:16:45 +0000 (15:16 +0000)
WEB-INF/lib/form/Calendar.class.php
WEB-INF/lib/ttTimeHelper.class.php
WEB-INF/templates/footer.tpl
plugins/MonthlyQuota.class.php

index f160cfa..d3845e8 100644 (file)
@@ -171,16 +171,9 @@ class Calendar extends FormElement {
               $stl_cell = ' class="CalendarDay"';
             }
 
-            // Handle holidays.
-            // Prepare a date to check in DB_DATEFORMAT.
-            $date_to_check = "$thisyear-";
-            if (strlen($thismonth) == 1) $date_to_check .= '0';
-            $date_to_check .= "$thismonth-";
-            if (strlen($start_date+$j) == 1) $date_to_check .= '0';
-            $date_to_check .= $start_date+$j;
-
-            // Check if it falls on a holiday.
-            if (ttTimeHelper::isHoliday2($date_to_check)) {
+            // holidays
+            $date_to_check = ttTimeHelper::dateInDatabaseFormat($thisyear, $thismonth, $start_date+$j);
+            if (ttTimeHelper::isHoliday($date_to_check)) {
               $stl_cell = ' class="CalendarDayHoliday"';
               $stl_link = ' class="CalendarLinkHoliday"';
             }
index 2b5b39b..6fd816e 100644 (file)
@@ -40,22 +40,6 @@ class ttTimeHelper {
   // isHoliday determines if $date falls on a holiday.
   static function isHoliday($date) {
     global $user;
-    global $i18n;
-
-    if (!$user->show_holidays) return false;
-
-    // $date is expected as string in DB_DATEFORMAT.
-    $month = date('m', strtotime($date));
-    $day = date('d', strtotime($date));
-    if (in_array($month.'/'.$day, $i18n->holidays))
-      return true;
-
-    return false;
-  }
-
-  // isHoliday determines if $date falls on a holiday.
-  static function isHoliday2($date) {
-    global $user;
 
     $holidays = $user->getHolidays();
     if (!$holidays)
@@ -88,6 +72,16 @@ class ttTimeHelper {
     return true;
   }
 
+  // dateInDatabaseFormat prepares a date string in DB_DATEFORMAT out of year, month, and day.
+  static function dateInDatabaseFormat($year, $month, $day) {
+    $date = "$year-";
+    if (strlen($month) == 1) $date .= '0';
+    $date .= "$month-";
+    if (strlen($day) == 1) $date .= '0';
+    $date .= $day;
+    return $date;
+  }
+
   // isValidTime validates a value as a time string.
   static function isValidTime($value) {
     if (strlen($value)==0 || !isset($value)) return false;
index 7efa4d6..6710c5c 100644 (file)
@@ -12,7 +12,7 @@
       <br>
       <table cellspacing="0" cellpadding="4" width="100%" border="0">
         <tr>
-          <td align="center">&nbsp;Anuko Time Tracker 1.19.4.4992 | Copyright &copy; <a href="https://www.anuko.com/lp/tt_3.htm" target="_blank">Anuko</a> |
+          <td align="center">&nbsp;Anuko Time Tracker 1.19.4.4993 | Copyright &copy; <a href="https://www.anuko.com/lp/tt_3.htm" target="_blank">Anuko</a> |
             <a href="https://www.anuko.com/lp/tt_4.htm" target="_blank">{$i18n.footer.credits}</a> |
             <a href="https://www.anuko.com/lp/tt_5.htm" target="_blank">{$i18n.footer.license}</a> |
             <a href="https://www.anuko.com/lp/tt_7.htm" target="_blank">{$i18n.footer.improve}</a>
index 2185467..c8559ad 100644 (file)
@@ -104,7 +104,7 @@ class MonthlyQuota {
     // Iterate from 1st up to selected date.
     $workdaysFrom1st = 0;
     for ($i = 1; $i <= $selected_date->mDate; $i++) {
-      $date = "$selected_date->mYear-$selected_date->mMonth-$i";
+      $date = ttTimeHelper::dateInDatabaseFormat($selected_date->mYear, $selected_date->mMonth, $i);
       if (!ttTimeHelper::isWeekend($date) && !ttTimeHelper::isHoliday($date)) {
         $workdaysFrom1st++;
       }
@@ -139,6 +139,7 @@ class MonthlyQuota {
     // Iterate through the entire month.
     for ($i = 1; $i <= $daysInMonth; $i++) {
       $date = "$year-$month-$i";
+      $date = ttTimeHelper::dateInDatabaseFormat($year, $month, $i);
       if (!ttTimeHelper::isWeekend($date) && !ttTimeHelper::isHoliday($date)) {
         $workdaysInMonth++;
       }