Skip to content

Commit

Permalink
2.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Levdbas committed Mar 30, 2023
1 parent c0af3e3 commit 61385c1
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 14 deletions.
9 changes: 7 additions & 2 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
Contributors: levdbas
Tags: time, hours, tracking, client, pre-paid, freelance, support, development, developer
Requires at least: 4.6
Tested up to: 6.1.1
Stable tag: 2.1.0
Tested up to: 6.2.0
Stable tag: 2.2.0
Requires PHP: 7.4
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Expand Down Expand Up @@ -46,6 +46,11 @@ Yes! Feel free to sent me any suggestions or feedback. I think this plugin can b

== Changelog ==

= 2.2.0 =
* Compatibility check with new WP version
* Fixed a bug where overusage wasn't calculated correctly.
* Fixed a bug where you could not save the settings when you didn't added the first timeslot.

= 2.1.0 =
* Update minimal php version to 7.4
* Refactored classes so the plugin only does the calculations when loading a backend page.
Expand Down
32 changes: 26 additions & 6 deletions admin/class-support-hours-data.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,14 @@ public function __construct()
self::$email = $this->options['email'];
}

if (isset($this->options['workFields'])) {
if (!empty($this->options['workFields'])) {

$first_work_field = $this->options['workFields'][0];

if (empty($first_work_field['date']) || empty($first_work_field['used'])) {
return;
}

self::$work_fields = $this->options['workFields'];
self::$total_used_minutes = $this->add_time_entries('time-used');
self::$total_bought_minutes = $this->add_time_entries('time-added');
Expand Down Expand Up @@ -152,7 +159,7 @@ function ($var) use ($type) {
);

foreach ($filtered_fields as $time) {
if ('' !== $time['type']) {
if ('' !== $time['type'] && !empty($time['used'])) {
list($hour, $minute) = explode(':', $time['used']);
$minutes += $hour * 60;
$minutes += $minute;
Expand Down Expand Up @@ -204,6 +211,7 @@ public function set_time_output()
$leftovers = $bought_time_without_last - self::$total_used_minutes < 0 ? 0 : $bought_time_without_last - self::$total_used_minutes;
$remaining_time = self::$total_bought_minutes - self::$total_used_minutes;
$bought_minutes_output = self::$last_added_time + $leftovers;

$used_minutes_output = self::$total_used_minutes - $bought_time_without_last;
$overusage = self::$total_bought_minutes - self::$total_used_minutes;
$percentage = 0;
Expand All @@ -213,7 +221,7 @@ public function set_time_output()
}

if ($overusage < 0) {
$used_minutes_output = abs($overusage);
$used_minutes_output = abs($overusage - self::$last_added_time);
}

if (0 !== $used_minutes_output && 0 !== $bought_minutes_output) {
Expand All @@ -224,10 +232,22 @@ public function set_time_output()

$bought_time_in_hours_minutes = $this->convert_minutes_to_hours_minutes($bought_minutes_output);
$used_time_in_hours_minutes = $this->convert_minutes_to_hours_minutes($used_minutes_output);

$text_size = 0 == $used_minutes_output % 60 && $bought_minutes_output < 5940 ? 'big' : 'small';

self::$time_output = [
/* 'debug' => [
'used_minutes' => $used_minutes_output,
'bought_minutes' => $bought_minutes_output,
'leftovers' => $leftovers,
'remaining_time' => $remaining_time,
'last_added_time' => self::$last_added_time,
'total_used_minutes' => self::$total_used_minutes,
'total_bought_minutes' => self::$total_bought_minutes,
'used_time_in_hours' => $used_time_in_hours_minutes,
'bought_time_in_hours' => $bought_time_in_hours_minutes,
'percentage' => $percentage,
'text_size' => $text_size,
], */
'used_time_in_percentage' => $percentage,
'time_full' => $used_time_in_hours_minutes . ' / ' . $bought_time_in_hours_minutes,
'time_total' => $this->convert_minutes_to_hours_minutes(self::$total_used_minutes) . ' / ' . $this->convert_minutes_to_hours_minutes(self::$total_bought_minutes),
Expand Down Expand Up @@ -278,8 +298,8 @@ private function maybe_hide_minutes($minutes)
*/
public static function get_time_output($type)
{
if (!isset(self::$time_output[$type])) {
throw new \Exception('Type not found in time output array.');
if (!key_exists($type, self::$time_output)) {
throw new \Exception('Type ' . $type . ' not found in time output array.');
}

return self::$time_output[$type];
Expand Down
8 changes: 4 additions & 4 deletions admin/views/settings/work-table-fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<fieldset class="type-switch">
<label for="<?php echo esc_attr($name); ?>[workFields][<?php echo esc_attr($i); ?>][type][used]">
<?php $time_used_checked = (isset($field['type']) && 'time-used' == $field['type']) ? 'checked="checked"' : ''; ?>
<input id="<?php echo esc_attr($name); ?>[workFields][<?php echo esc_attr($i); ?>][type][used]" required type="radio" class="radio time-used" value="time-used" name="<?php echo esc_attr($name); ?>[workFields][<?php echo esc_attr($i); ?>][type]" <?php echo esc_attr($time_used_checked); ?>>
<input id="<?php echo esc_attr($name); ?>[workFields][<?php echo esc_attr($i); ?>][type][used]" <?php echo false == $first ? 'required' : ''; ?> type="radio" class="radio time-used" value="time-used" name="<?php echo esc_attr($name); ?>[workFields][<?php echo esc_attr($i); ?>][type]" <?php echo esc_attr($time_used_checked); ?>>
<span><?php esc_html_e('Time used', 'support-hours'); ?></span>
</label>

Expand All @@ -33,17 +33,17 @@

<td data-th="<?php esc_html_e('Date', 'support-hours'); ?>" data-colname="<?php esc_html_e('Date', 'support-hours'); ?>">
<?php $date_value = !empty($field['date']) ? $field['date'] : ''; ?>
<input type="date" required class="regular-text date validate sh-datepicker" id="<?php echo esc_attr($name); ?>-workFields-date" name="<?php echo esc_attr($name); ?>[workFields][<?php echo esc_attr($i); ?>][date]" value="<?php echo esc_attr($date_value); ?>" />
<input type="date" <?php echo false == $first ? 'required' : ''; ?> class="regular-text date validate sh-datepicker" id="<?php echo esc_attr($name); ?>-workFields-date" name="<?php echo esc_attr($name); ?>[workFields][<?php echo esc_attr($i); ?>][date]" value="<?php echo esc_attr($date_value); ?>" />
</td>

<td data-th="<?php esc_html_e('Time', 'support-hours'); ?>" data-colname="<?php esc_html_e('Time', 'support-hours'); ?>">
<?php $used_value = !empty($field['used']) ? $field['used'] : ''; ?>
<input type="time" placeholder="00:00" class="regular-text time validate" id="<?php echo esc_attr($name); ?>-workFields-used" name="<?php echo esc_attr($name); ?>[workFields][<?php echo esc_attr($i); ?>][used]" required value="<?php echo esc_attr($used_value); ?>" />
<input type="time" placeholder="00:00" class="regular-text time validate" id="<?php echo esc_attr($name); ?>-workFields-used" name="<?php echo esc_attr($name); ?>[workFields][<?php echo esc_attr($i); ?>][used]" <?php echo false == $first ? 'required' : ''; ?> value="<?php echo esc_attr($used_value); ?>" />
</td>

<td data-th="<?php esc_html_e('Description', 'support-hours'); ?>" data-colname="<?php esc_html_e('Description', 'support-hours'); ?>">
<?php $description_value = !empty($field['description']) ? $field['description'] : ''; ?>
<input type="text" required placeholder="<?php esc_html_e('Description of the activity', 'support-hours'); ?>" class="regular-text description validate" id="<?php echo esc_attr($name); ?>-workFields-description" name="<?php echo esc_attr($name); ?>[workFields][<?php echo esc_attr($i); ?>][description]" value="<?php echo esc_attr($description_value); ?>" />
<input type="text" <?php echo false == $first ? 'required' : ''; ?> placeholder="<?php esc_html_e('Description of the activity', 'support-hours'); ?>" class="regular-text description validate" id="<?php echo esc_attr($name); ?>-workFields-description" name="<?php echo esc_attr($name); ?>[workFields][<?php echo esc_attr($i); ?>][description]" value="<?php echo esc_attr($description_value); ?>" />
</td>
<td class="remove">
<a class="remove-item remove-row"><span class="dashicons dashicons-trash"></span></a>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "support-hours",
"version": "2.1.0",
"version": "2.2.0",
"description": "Project short description.",
"main": "app.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion support-hours.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* Plugin Name: Support Hours
* Plugin URI: https://basedonline.nl
* Description: Use Support hours to give yourself and your clients insights on the status of pre-paid work.
* Version: 2.1.0
* Version: 2.2.0
* Author: Erik van der Bas
* Author URI: https://basedonline.nl
* License: GPL-2.0+
Expand Down

0 comments on commit 61385c1

Please # to comment.