Update department daily targets to support floats
- Refactored `department_daily_targets` logic to accept and process float values instead of integers. - Adjusted relevant type declarations, validations, and calculations in `GoalsCriteria`. - Updated OpenAPI schema to align with new data type for per-department daily targets.
This commit is contained in:
+29
-8
@@ -8390,11 +8390,12 @@ components:
|
||||
department_daily_targets:
|
||||
type: object
|
||||
description: |
|
||||
Optional per-department custom daily targets. Keys are department IDs and values are non-negative integers representing the target per operating day for that department.
|
||||
Optional per-department custom daily targets. Keys are department IDs and values are non-negative numbers representing the target per operating day for that department.
|
||||
If omitted, the daily target is split evenly across selected departments. The canonical field name is snake_case `department_daily_targets`.
|
||||
For backward-compatibility the API also accepts camelCase `departmentDailyTargets` on input.
|
||||
x-additionalPropertiesName: department_id
|
||||
additionalProperties:
|
||||
type: integer
|
||||
type: number
|
||||
minimum: 0
|
||||
example:
|
||||
"12": 3
|
||||
@@ -8410,6 +8411,20 @@ components:
|
||||
type: number
|
||||
description: Target value for the period
|
||||
|
||||
DepartmentGoalProgress:
|
||||
type: object
|
||||
title: Department progress details
|
||||
description: Goal progress details for a single department across multiple timeframes
|
||||
properties:
|
||||
all:
|
||||
$ref: '#/components/schemas/GoalProgressDetails'
|
||||
today:
|
||||
$ref: '#/components/schemas/GoalProgressDetails'
|
||||
week:
|
||||
$ref: '#/components/schemas/GoalProgressDetails'
|
||||
month:
|
||||
$ref: '#/components/schemas/GoalProgressDetails'
|
||||
|
||||
DepartmentGoal:
|
||||
type: object
|
||||
properties:
|
||||
@@ -8438,17 +8453,23 @@ components:
|
||||
departmental_distribution:
|
||||
type: object
|
||||
description: Progress details broken down by department. Keys are department IDs.
|
||||
x-additionalPropertiesName: department_id
|
||||
additionalProperties:
|
||||
type: object
|
||||
properties:
|
||||
$ref: '#/components/schemas/DepartmentGoalProgress'
|
||||
example:
|
||||
"12":
|
||||
all:
|
||||
$ref: '#/components/schemas/GoalProgressDetails'
|
||||
count: 15
|
||||
target: 100
|
||||
today:
|
||||
$ref: '#/components/schemas/GoalProgressDetails'
|
||||
count: 2
|
||||
target: 5
|
||||
week:
|
||||
$ref: '#/components/schemas/GoalProgressDetails'
|
||||
count: 10
|
||||
target: 35
|
||||
month:
|
||||
$ref: '#/components/schemas/GoalProgressDetails'
|
||||
count: 15
|
||||
target: 100
|
||||
created_at:
|
||||
type: string
|
||||
description: Creation timestamp
|
||||
|
||||
@@ -79,7 +79,7 @@ class goals_criteria implements goals_criteria_i
|
||||
public ?string $progress_alert_time_of_day = null;
|
||||
/**
|
||||
* Optional per-department custom daily targets (department_id => daily_target)
|
||||
* @var array<int,int>
|
||||
* @var array<int,float>
|
||||
*/
|
||||
public array $department_daily_targets;
|
||||
/**
|
||||
@@ -265,7 +265,7 @@ class goals_criteria implements goals_criteria_i
|
||||
foreach ($data['department_daily_targets'] as $deptId => $target) {
|
||||
if (is_numeric($deptId) && is_numeric($target)) {
|
||||
$id = (int)$deptId;
|
||||
$t = max(0, (int)$target);
|
||||
$t = max(0.0, (float)$target);
|
||||
$targets[$id] = $t;
|
||||
}
|
||||
}
|
||||
@@ -552,7 +552,7 @@ class goals_criteria implements goals_criteria_i
|
||||
$deptIds = $this->departments?->listIDs() ?? [];
|
||||
foreach ($this->department_daily_targets as $k => $v) {
|
||||
if (!is_numeric($k) || !is_numeric($v)) { continue; }
|
||||
$dk = (int)$k; $dv = (int)$v;
|
||||
$dk = (int)$k; $dv = (float)$v;
|
||||
if ($dk > 0 && $dv >= 0 && in_array($dk, $deptIds)) {
|
||||
$normalized[$dk] = $dv;
|
||||
}
|
||||
@@ -707,23 +707,23 @@ class goals_criteria implements goals_criteria_i
|
||||
$this->setTimeframeByName($timeframe);
|
||||
}
|
||||
|
||||
$target = 0;
|
||||
$target = 0.0;
|
||||
$active_dept_ids = $this->departments->listIDs();
|
||||
|
||||
if ($timeframe === 'today') {
|
||||
foreach ($active_dept_ids as $id) {
|
||||
$target += $this->department_daily_targets[$id] ?? 0;
|
||||
$target += (float)($this->department_daily_targets[$id] ?? 0);
|
||||
}
|
||||
} elseif ($timeframe === 'week') {
|
||||
foreach ($active_dept_ids as $id) {
|
||||
$target += ($this->department_daily_targets[$id] ?? 0) * 7;
|
||||
$target += (float)($this->department_daily_targets[$id] ?? 0) * 7;
|
||||
}
|
||||
} elseif ($timeframe === 'month') {
|
||||
foreach ($active_dept_ids as $id) {
|
||||
$target += ($this->department_daily_targets[$id] ?? 0) * 30;
|
||||
$target += (float)($this->department_daily_targets[$id] ?? 0) * 30;
|
||||
}
|
||||
} else {
|
||||
$target = (int)$this->target;
|
||||
$target = (float)$this->target;
|
||||
}
|
||||
|
||||
return [
|
||||
|
||||
Reference in New Issue
Block a user