Изменил пороги цвета и привязку процента к выбранной дате

This commit is contained in:
Brusnitsyn
2026-07-06 13:36:30 +00:00
parent 9d8177c086
commit 86a33f2e46
5 changed files with 18 additions and 21 deletions

View File

@@ -43,12 +43,12 @@ class Department extends Model
return $this->belongsTo(UserDepartment::class, 'department_id', 'rf_department_id'); return $this->belongsTo(UserDepartment::class, 'department_id', 'rf_department_id');
} }
public function recipientPlanOfYear() public function recipientPlanOfYear(?Carbon $asOf = null)
{ {
$now = Carbon::now(); $asOf = $asOf ?? Carbon::now();
return $this->metrikaDefault() return $this->metrikaDefault()
->where('date_end', '>', $now) ->where('date_end', '>', $asOf)
->where('rf_metrika_item_id', 23) ->where('rf_metrika_item_id', 23)
->first(); ->first();
} }

View File

@@ -68,7 +68,7 @@ class PlanCalculator extends BaseMetricService implements MetricCalculatorInterf
$department = Department::find($departmentId); $department = Department::find($departmentId);
// Получаем годовой план // Получаем годовой план
$annualPlanModel = $department->recipientPlanOfYear(); $annualPlanModel = $department->recipientPlanOfYear($endDate);
$annualPlan = $annualPlanModel ? (int) $annualPlanModel->value : 0; $annualPlan = $annualPlanModel ? (int) $annualPlanModel->value : 0;
// План на 1 месяц (равномерно) // План на 1 месяц (равномерно)

View File

@@ -829,7 +829,7 @@ class ReportService
*/ */
public function getRecipientPlanOfYear(Department $department, DateRange $dateRange): array public function getRecipientPlanOfYear(Department $department, DateRange $dateRange): array
{ {
$periodPlanModel = $department->recipientPlanOfYear(); $periodPlanModel = $department->recipientPlanOfYear($dateRange->endDate);
$monthsInPeriod = ceil($dateRange->startDate->diffInMonths($dateRange->endDate)); $monthsInPeriod = ceil($dateRange->startDate->diffInMonths($dateRange->endDate));
$annualPlan = $periodPlanModel ? (int) $periodPlanModel->value : 0; $annualPlan = $periodPlanModel ? (int) $periodPlanModel->value : 0;
$oneMonthPlan = ceil($annualPlan / 12); $oneMonthPlan = ceil($annualPlan / 12);

View File

@@ -1,6 +1,8 @@
<script setup> <script setup>
import {NNumberAnimation, NTag, NFlex} from "naive-ui" import {NNumberAnimation, NTag, NFlex} from "naive-ui"
import {computed} from "vue"; import {computed} from "vue";
import {percentType} from "../../../Utils/numbers.js";
const props = defineProps({ const props = defineProps({
plan: { plan: {
type: Number, type: Number,
@@ -14,13 +16,7 @@ const props = defineProps({
const percentProgress = computed(() => { const percentProgress = computed(() => {
if (!Number(props.plan) && !Number(props.progress)) return 0 if (!Number(props.plan) && !Number(props.progress)) return 0
return (props.progress * 100) / props.plan return Math.round((props.progress * 100) / props.plan)
})
const percentColor = computed(() => {
if (percentProgress.value < 50) return 'color: var(--color-red-500);' // Ужасно
if (percentProgress.value >= 50 && percentProgress.value < 80) return 'color: var(--color-amber-500);' // Плохо
if (percentProgress.value >= 80) return 'color: var(--color-emerald-500);' // Хорошо
}) })
</script> </script>
@@ -30,12 +26,13 @@ const percentColor = computed(() => {
<NFlex align="center" justify="center"> <NFlex align="center" justify="center">
<div> <div>
План: План:
<span :style="percentColor"> <NNumberAnimation show-separator :from="0" :to="progress" />
<NNumberAnimation show-separator :from="0" :to="progress" />
</span>
из из
<NNumberAnimation show-separator :from="0" :to="plan" /> <NNumberAnimation show-separator :from="0" :to="plan" />
</div> </div>
<NTag :type="percentType(percentProgress)" round :bordered="false" size="small">
{{ percentProgress }}%
</NTag>
</NFlex> </NFlex>
</NTag> </NTag>
</template> </template>

View File

@@ -1,15 +1,15 @@
export const percentColor = (number) => { export const percentColor = (number) => {
if (!Number(number)) return if (!Number(number)) return
if (number < 50) return 'color: var(--color-red-500);' // Ужасно if (number >= 90) return 'color: var(--color-emerald-500);' // Хорошо
if (number >= 50 && number < 80) return 'color: var(--color-amber-500);' // Плохо if (number >= 80) return 'color: var(--color-amber-500);' // Плохо
if (number >= 80) return 'color: var(--color-emerald-500);' // Хорошо return 'color: var(--color-red-500);' // Ужасно
} }
export const percentType = (number) => { export const percentType = (number) => {
if (!Number(number)) return if (!Number(number)) return
if (number < 50) return 'error' // Ужасно if (number >= 90) return 'success' // Хорошо
if (number >= 50 && number < 80) return 'warning' // Плохо if (number >= 80) return 'warning' // Плохо
if (number >= 80) return 'success' // Хорошо return 'error' // Ужасно
} }
export const typePlan = (plan, completed) => { export const typePlan = (plan, completed) => {