Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgergo committed Dec 29, 2023
1 parent b76787c commit 795a502
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Fields/Repeater.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public function withFields(Closure $callback): static
{
$this->optionFieldsResolver = function (Request $request, Model $model, Model $tmpModel) use ($callback): Fields {
$fields = new Fields([
Hidden::make(__('Key'), '_key')
Hidden::make(__('Key'), '_key'),
]);

$fields->register(call_user_func_array($callback, [$request, $model, $tmpModel]));
Expand Down
20 changes: 17 additions & 3 deletions src/Widgets/Value.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,29 @@ function (Builder $query) use ($period, $dateColumn): Builder {
*/
public function result(Builder $query): array
{
$result = array_merge(['current' => 0, 'pervious' => 0], parent::result($query));
$result = array_merge(['current' => 0, 'previous' => 0], parent::result($query));

return [
'current' => round($result['current'], 2),
'pervious' => round($result['previous'], 2),
'trend' => round(($result['current'] - $result['previous']) / (($result['current'] + $result['previous']) / 2) * 100, 1),
'previous' => round($result['previous'], 2),
'trend' => $this->trend($result),
];
}

/**
* Calculate the trend value.
*/
protected function trend(array $result): float
{
$divider = ($result['current'] + $result['previous']);

if ($divider == 0) {
return 0;
}

return round(($result['current'] - $result['previous']) / ($divider / 2) * 100, 1);
}

/**
* Convert the widget to an array.
*/
Expand Down

0 comments on commit 795a502

Please sign in to comment.