.
This commit is contained in:
parent
af3df58b47
commit
9be8e8f764
6 changed files with 48 additions and 75 deletions
|
|
@ -223,7 +223,7 @@ class ApiHomeView(APIView):
|
|||
from opportunity.models import SalesGoal
|
||||
|
||||
goal_filter = Q(assigned_to=profile) | Q(team__in=profile.user_teams.all())
|
||||
if profile.role == "ADMIN":
|
||||
if is_admin:
|
||||
goal_filter |= Q(assigned_to__isnull=True, team__isnull=True)
|
||||
|
||||
active_goals = (
|
||||
|
|
|
|||
|
|
@ -257,7 +257,7 @@ class TestSalesGoalAPI:
|
|||
),
|
||||
}
|
||||
response = admin_client.post(self.GOALS_URL, data, format="json")
|
||||
assert response.status_code == 200
|
||||
assert response.status_code == 201
|
||||
assert response.data["error"] is False
|
||||
assert SalesGoal.objects.filter(name="New Goal", org=org_a).exists()
|
||||
|
||||
|
|
|
|||
|
|
@ -44,7 +44,9 @@ class SalesGoalListView(APIView, LimitOffsetPagination):
|
|||
if params.get("search"):
|
||||
queryset = queryset.filter(name__icontains=params["search"])
|
||||
|
||||
return queryset.distinct()
|
||||
return queryset.select_related(
|
||||
"assigned_to", "assigned_to__user", "team"
|
||||
).distinct()
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
queryset = self.get_queryset(request)
|
||||
|
|
@ -52,11 +54,8 @@ class SalesGoalListView(APIView, LimitOffsetPagination):
|
|||
serializer = SalesGoalSerializer(results, many=True)
|
||||
|
||||
total_count = self.count
|
||||
offset = None
|
||||
if results:
|
||||
offset = queryset.filter(id__gte=results[-1].id).count()
|
||||
if offset == total_count:
|
||||
offset = None
|
||||
next_offset = self.offset + len(results) if results else None
|
||||
offset = next_offset if (results and next_offset < total_count) else None
|
||||
|
||||
return Response(
|
||||
{
|
||||
|
|
@ -82,7 +81,7 @@ class SalesGoalListView(APIView, LimitOffsetPagination):
|
|||
)
|
||||
return Response(
|
||||
{"error": False, "message": "Goal Created Successfully"},
|
||||
status=status.HTTP_200_OK,
|
||||
status=status.HTTP_201_CREATED,
|
||||
)
|
||||
return Response(
|
||||
{"error": True, "errors": serializer.errors},
|
||||
|
|
|
|||
|
|
@ -4,39 +4,12 @@
|
|||
import { formatCurrency } from '$lib/utils/formatting.js';
|
||||
import { orgSettings } from '$lib/stores/org.js';
|
||||
import { resolve } from '$app/paths';
|
||||
import { getStatusColor, getProgressColor } from '$lib/utils/goals.js';
|
||||
|
||||
/** @type {{ goals?: any[] }} */
|
||||
let { goals = [] } = $props();
|
||||
|
||||
const orgCurrency = $derived($orgSettings.default_currency || 'USD');
|
||||
|
||||
/**
|
||||
* @param {string} statusValue
|
||||
*/
|
||||
function getStatusColor(statusValue) {
|
||||
switch (statusValue) {
|
||||
case 'on_track':
|
||||
return 'text-emerald-600 dark:text-emerald-400';
|
||||
case 'at_risk':
|
||||
return 'text-amber-600 dark:text-amber-400';
|
||||
case 'behind':
|
||||
return 'text-red-600 dark:text-red-400';
|
||||
case 'completed':
|
||||
return 'text-blue-600 dark:text-blue-400';
|
||||
default:
|
||||
return 'text-[var(--text-secondary)]';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {number} percent
|
||||
*/
|
||||
function getProgressColor(percent) {
|
||||
if (percent >= 100) return '[&>[data-slot=progress-indicator]]:bg-blue-500';
|
||||
if (percent >= 75) return '[&>[data-slot=progress-indicator]]:bg-emerald-500';
|
||||
if (percent >= 50) return '[&>[data-slot=progress-indicator]]:bg-amber-500';
|
||||
return '[&>[data-slot=progress-indicator]]:bg-red-500';
|
||||
}
|
||||
</script>
|
||||
|
||||
<div
|
||||
|
|
@ -74,7 +47,7 @@
|
|||
</div>
|
||||
{:else}
|
||||
<div class="space-y-4">
|
||||
{#each goals as goal}
|
||||
{#each goals as goal (goal.id)}
|
||||
<div class="space-y-1.5">
|
||||
<div class="flex items-center justify-between">
|
||||
<span class="truncate text-sm font-medium text-[var(--text-primary)]">{goal.name}</span>
|
||||
|
|
|
|||
29
frontend/src/lib/utils/goals.js
Normal file
29
frontend/src/lib/utils/goals.js
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
/**
|
||||
* Get Tailwind color classes for a goal status value.
|
||||
* @param {string} statusValue
|
||||
*/
|
||||
export function getStatusColor(statusValue) {
|
||||
switch (statusValue) {
|
||||
case 'on_track':
|
||||
return 'text-emerald-600 dark:text-emerald-400';
|
||||
case 'at_risk':
|
||||
return 'text-amber-600 dark:text-amber-400';
|
||||
case 'behind':
|
||||
return 'text-red-600 dark:text-red-400';
|
||||
case 'completed':
|
||||
return 'text-blue-600 dark:text-blue-400';
|
||||
default:
|
||||
return 'text-[var(--text-secondary)]';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Tailwind progress bar color class based on percent.
|
||||
* @param {number} percent
|
||||
*/
|
||||
export function getProgressColor(percent) {
|
||||
if (percent >= 100) return '[&>[data-slot=progress-indicator]]:bg-blue-500';
|
||||
if (percent >= 75) return '[&>[data-slot=progress-indicator]]:bg-emerald-500';
|
||||
if (percent >= 50) return '[&>[data-slot=progress-indicator]]:bg-amber-500';
|
||||
return '[&>[data-slot=progress-indicator]]:bg-red-500';
|
||||
}
|
||||
|
|
@ -15,6 +15,7 @@
|
|||
import { formatCurrency } from '$lib/utils/formatting.js';
|
||||
import { orgSettings } from '$lib/stores/org.js';
|
||||
import { getCurrentUser } from '$lib/api.js';
|
||||
import { getStatusColor, getProgressColor } from '$lib/utils/goals.js';
|
||||
|
||||
const goalTypeOptions = [
|
||||
{
|
||||
|
|
@ -149,23 +150,22 @@
|
|||
const now = new Date();
|
||||
const year = now.getFullYear();
|
||||
const month = now.getMonth();
|
||||
const pad = (/** @type {number} */ n) => String(n).padStart(2, '0');
|
||||
|
||||
switch (periodType) {
|
||||
case 'MONTHLY': {
|
||||
const start = new Date(year, month, 1);
|
||||
const end = new Date(year, month + 1, 0);
|
||||
const lastDay = new Date(year, month + 1, 0).getDate();
|
||||
return {
|
||||
start: start.toISOString().split('T')[0],
|
||||
end: end.toISOString().split('T')[0]
|
||||
start: `${year}-${pad(month + 1)}-01`,
|
||||
end: `${year}-${pad(month + 1)}-${pad(lastDay)}`
|
||||
};
|
||||
}
|
||||
case 'QUARTERLY': {
|
||||
const qStart = Math.floor(month / 3) * 3;
|
||||
const start = new Date(year, qStart, 1);
|
||||
const end = new Date(year, qStart + 3, 0);
|
||||
const lastDay = new Date(year, qStart + 3, 0).getDate();
|
||||
return {
|
||||
start: start.toISOString().split('T')[0],
|
||||
end: end.toISOString().split('T')[0]
|
||||
start: `${year}-${pad(qStart + 1)}-01`,
|
||||
end: `${year}-${pad(qStart + 3)}-${pad(lastDay)}`
|
||||
};
|
||||
}
|
||||
case 'YEARLY': {
|
||||
|
|
@ -226,6 +226,7 @@
|
|||
/** @param {Event} e */
|
||||
async function handleSubmit(e) {
|
||||
e.preventDefault();
|
||||
if (!isAdmin) return;
|
||||
const form = /** @type {HTMLFormElement} */ (e.target);
|
||||
const fd = new FormData(form);
|
||||
|
||||
|
|
@ -315,35 +316,6 @@
|
|||
return goals;
|
||||
});
|
||||
|
||||
/**
|
||||
* Get color class for status
|
||||
* @param {string} statusValue
|
||||
*/
|
||||
function getStatusColor(statusValue) {
|
||||
switch (statusValue) {
|
||||
case 'on_track':
|
||||
return 'text-emerald-600 dark:text-emerald-400';
|
||||
case 'at_risk':
|
||||
return 'text-amber-600 dark:text-amber-400';
|
||||
case 'behind':
|
||||
return 'text-red-600 dark:text-red-400';
|
||||
case 'completed':
|
||||
return 'text-blue-600 dark:text-blue-400';
|
||||
default:
|
||||
return 'text-[var(--text-secondary)]';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get progress bar color
|
||||
* @param {number} percent
|
||||
*/
|
||||
function getProgressColor(percent) {
|
||||
if (percent >= 100) return '[&>[data-slot=progress-indicator]]:bg-blue-500';
|
||||
if (percent >= 75) return '[&>[data-slot=progress-indicator]]:bg-emerald-500';
|
||||
if (percent >= 50) return '[&>[data-slot=progress-indicator]]:bg-amber-500';
|
||||
return '[&>[data-slot=progress-indicator]]:bg-red-500';
|
||||
}
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
|
|
|
|||
Loading…
Reference in a new issue