Compare commits
7 Commits
feature/is
...
c04586f76a
| Author | SHA1 | Date | |
|---|---|---|---|
| c04586f76a | |||
|
|
d23644d90f | ||
|
|
b29e17998d | ||
| bbccbd09ed | |||
|
|
bf4d365357 | ||
|
|
6eb3169be3 | ||
| 3209adcf40 |
130
app/components/inventory/ExpiryDashboard.vue
Normal file
130
app/components/inventory/ExpiryDashboard.vue
Normal file
@@ -0,0 +1,130 @@
|
||||
<template>
|
||||
<UCard v-if="expiringItems.length > 0">
|
||||
<template #header>
|
||||
<div class="flex items-center justify-between">
|
||||
<div class="flex items-center gap-2">
|
||||
<UIcon name="i-heroicons-exclamation-triangle" class="w-5 h-5 text-orange-500" />
|
||||
<h3 class="text-lg font-semibold">Items Expiring Soon</h3>
|
||||
</div>
|
||||
<UBadge color="orange" variant="soft">
|
||||
{{ expiringItems.length }}
|
||||
</UBadge>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<div class="space-y-2">
|
||||
<div
|
||||
v-for="item in displayedItems"
|
||||
:key="item.id"
|
||||
class="flex items-center justify-between p-3 rounded-lg hover:bg-gray-50 transition-colors"
|
||||
:class="getItemBgClass(item)"
|
||||
>
|
||||
<div class="flex-1 min-w-0">
|
||||
<p class="font-medium text-gray-900 truncate">{{ item.name }}</p>
|
||||
<div class="flex items-center gap-2 text-sm">
|
||||
<UBadge :color="getExpiryColor(item)" size="xs">
|
||||
{{ getExpiryText(item) }}
|
||||
</UBadge>
|
||||
<span class="text-gray-600">
|
||||
{{ item.quantity }} {{ item.unit?.abbreviation }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<UButton
|
||||
size="xs"
|
||||
color="gray"
|
||||
variant="ghost"
|
||||
icon="i-heroicons-arrow-right"
|
||||
@click="$emit('view-item', item)"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<UButton
|
||||
v-if="expiringItems.length > maxDisplay"
|
||||
color="gray"
|
||||
variant="soft"
|
||||
size="sm"
|
||||
class="w-full"
|
||||
@click="expanded = !expanded"
|
||||
>
|
||||
{{ expanded ? 'Show Less' : `Show ${expiringItems.length - maxDisplay} More` }}
|
||||
</UButton>
|
||||
</div>
|
||||
</UCard>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
const props = defineProps<{
|
||||
items: any[]
|
||||
maxDisplay?: number
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
'view-item': [item: any]
|
||||
}>()
|
||||
|
||||
const expanded = ref(false)
|
||||
const maxDisplay = props.maxDisplay || 5
|
||||
|
||||
// Filter and sort items by expiry
|
||||
const expiringItems = computed(() => {
|
||||
const now = new Date()
|
||||
const thirtyDaysFromNow = new Date()
|
||||
thirtyDaysFromNow.setDate(now.getDate() + 30)
|
||||
|
||||
return props.items
|
||||
.filter(item => {
|
||||
if (!item.expiry_date) return false
|
||||
const expiryDate = new Date(item.expiry_date)
|
||||
return expiryDate <= thirtyDaysFromNow
|
||||
})
|
||||
.sort((a, b) => {
|
||||
const dateA = new Date(a.expiry_date)
|
||||
const dateB = new Date(b.expiry_date)
|
||||
return dateA.getTime() - dateB.getTime()
|
||||
})
|
||||
})
|
||||
|
||||
const displayedItems = computed(() => {
|
||||
if (expanded.value) {
|
||||
return expiringItems.value
|
||||
}
|
||||
return expiringItems.value.slice(0, maxDisplay)
|
||||
})
|
||||
|
||||
// Helper functions
|
||||
const getDaysUntilExpiry = (item: any) => {
|
||||
if (!item.expiry_date) return null
|
||||
const today = new Date()
|
||||
const expiry = new Date(item.expiry_date)
|
||||
return Math.ceil((expiry.getTime() - today.getTime()) / (1000 * 60 * 60 * 24))
|
||||
}
|
||||
|
||||
const getExpiryColor = (item: any) => {
|
||||
const days = getDaysUntilExpiry(item)
|
||||
if (days === null) return 'gray'
|
||||
if (days < 0) return 'red'
|
||||
if (days <= 3) return 'orange'
|
||||
if (days <= 7) return 'yellow'
|
||||
return 'green'
|
||||
}
|
||||
|
||||
const getExpiryText = (item: any) => {
|
||||
const days = getDaysUntilExpiry(item)
|
||||
if (days === null) return 'No expiry'
|
||||
if (days < 0) return `Expired ${Math.abs(days)}d ago`
|
||||
if (days === 0) return 'Expires today'
|
||||
if (days === 1) return 'Expires tomorrow'
|
||||
if (days <= 7) return `${days} days left`
|
||||
return `${days} days left`
|
||||
}
|
||||
|
||||
const getItemBgClass = (item: any) => {
|
||||
const days = getDaysUntilExpiry(item)
|
||||
if (days === null) return ''
|
||||
if (days < 0) return 'bg-red-50'
|
||||
if (days <= 3) return 'bg-orange-50'
|
||||
return ''
|
||||
}
|
||||
</script>
|
||||
110
app/components/inventory/LowStockDashboard.vue
Normal file
110
app/components/inventory/LowStockDashboard.vue
Normal file
@@ -0,0 +1,110 @@
|
||||
<template>
|
||||
<UCard v-if="lowStockItems.length > 0">
|
||||
<template #header>
|
||||
<div class="flex items-center justify-between">
|
||||
<div class="flex items-center gap-2">
|
||||
<UIcon name="i-heroicons-arrow-trending-down" class="w-5 h-5 text-orange-500" />
|
||||
<h3 class="text-lg font-semibold">Low Stock Items</h3>
|
||||
</div>
|
||||
<UBadge color="orange" variant="soft">
|
||||
{{ lowStockItems.length }}
|
||||
</UBadge>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<div class="space-y-2">
|
||||
<div
|
||||
v-for="item in displayedItems"
|
||||
:key="item.id"
|
||||
class="flex items-center justify-between p-3 rounded-lg bg-orange-50 hover:bg-orange-100 transition-colors"
|
||||
>
|
||||
<div class="flex-1 min-w-0">
|
||||
<p class="font-medium text-gray-900 truncate">{{ item.name }}</p>
|
||||
<div class="flex items-center gap-2 text-sm">
|
||||
<UBadge color="orange" size="xs">
|
||||
{{ item.quantity }}/{{ item.low_stock_threshold }} {{ item.unit?.abbreviation }}
|
||||
</UBadge>
|
||||
<span class="text-gray-600">
|
||||
{{ getUrgencyText(item) }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex gap-1">
|
||||
<UButton
|
||||
size="xs"
|
||||
color="green"
|
||||
variant="soft"
|
||||
icon="i-heroicons-arrow-trending-up"
|
||||
@click="$emit('restock-item', item)"
|
||||
>
|
||||
Restock
|
||||
</UButton>
|
||||
<UButton
|
||||
size="xs"
|
||||
color="gray"
|
||||
variant="ghost"
|
||||
icon="i-heroicons-pencil"
|
||||
@click="$emit('view-item', item)"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<UButton
|
||||
v-if="lowStockItems.length > maxDisplay"
|
||||
color="gray"
|
||||
variant="soft"
|
||||
size="sm"
|
||||
class="w-full"
|
||||
@click="expanded = !expanded"
|
||||
>
|
||||
{{ expanded ? 'Show Less' : `Show ${lowStockItems.length - maxDisplay} More` }}
|
||||
</UButton>
|
||||
</div>
|
||||
</UCard>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
const props = defineProps<{
|
||||
items: any[]
|
||||
maxDisplay?: number
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
'view-item': [item: any]
|
||||
'restock-item': [item: any]
|
||||
}>()
|
||||
|
||||
const expanded = ref(false)
|
||||
const maxDisplay = props.maxDisplay || 5
|
||||
|
||||
// Filter and sort items by low stock urgency
|
||||
const lowStockItems = computed(() => {
|
||||
return props.items
|
||||
.filter(item => {
|
||||
if (!item.low_stock_threshold) return false
|
||||
return Number(item.quantity) <= Number(item.low_stock_threshold)
|
||||
})
|
||||
.sort((a, b) => {
|
||||
// Sort by urgency: items closest to 0 first
|
||||
const urgencyA = Number(a.quantity) / Number(a.low_stock_threshold)
|
||||
const urgencyB = Number(b.quantity) / Number(b.low_stock_threshold)
|
||||
return urgencyA - urgencyB
|
||||
})
|
||||
})
|
||||
|
||||
const displayedItems = computed(() => {
|
||||
if (expanded.value) {
|
||||
return lowStockItems.value
|
||||
}
|
||||
return lowStockItems.value.slice(0, maxDisplay)
|
||||
})
|
||||
|
||||
// Helper function
|
||||
const getUrgencyText = (item: any) => {
|
||||
const ratio = Number(item.quantity) / Number(item.low_stock_threshold)
|
||||
if (ratio <= 0.25) return 'Critical'
|
||||
if (ratio <= 0.5) return 'Very low'
|
||||
return 'Low'
|
||||
}
|
||||
</script>
|
||||
@@ -83,6 +83,22 @@
|
||||
@updated="handleItemUpdated"
|
||||
/>
|
||||
|
||||
<!-- Dashboard Cards -->
|
||||
<div class="grid gap-6 mb-6 md:grid-cols-2">
|
||||
<!-- Expiry Dashboard -->
|
||||
<InventoryExpiryDashboard
|
||||
:items="inventoryItems"
|
||||
@view-item="editingItem = $event"
|
||||
/>
|
||||
|
||||
<!-- Low Stock Dashboard -->
|
||||
<InventoryLowStockDashboard
|
||||
:items="inventoryItems"
|
||||
@view-item="editingItem = $event"
|
||||
@restock-item="handleRestockFromDashboard"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- Inventory List -->
|
||||
<InventoryList
|
||||
ref="inventoryListRef"
|
||||
@@ -111,9 +127,21 @@ const inventoryListRef = ref()
|
||||
const prefilledData = ref<any>(null)
|
||||
const selectedTagFilters = ref<string[]>([])
|
||||
const searchQuery = ref('')
|
||||
const inventoryItems = ref<any[]>([])
|
||||
|
||||
// Load inventory for dashboard
|
||||
const { getInventory } = useInventory()
|
||||
|
||||
const loadInventoryData = async () => {
|
||||
const { data } = await getInventory()
|
||||
inventoryItems.value = data || []
|
||||
}
|
||||
|
||||
// Handle scan-to-add flow (Issue #25)
|
||||
onMounted(() => {
|
||||
onMounted(async () => {
|
||||
// Load inventory for dashboard
|
||||
await loadInventoryData()
|
||||
|
||||
if (route.query.action === 'add') {
|
||||
// Pre-fill data from query params (from scan)
|
||||
prefilledData.value = {
|
||||
@@ -136,15 +164,22 @@ const handleCloseAddForm = () => {
|
||||
prefilledData.value = null
|
||||
}
|
||||
|
||||
const handleItemAdded = (item: any) => {
|
||||
const handleItemAdded = async (item: any) => {
|
||||
showAddForm.value = false
|
||||
prefilledData.value = null
|
||||
// Reload the inventory list
|
||||
// Reload the inventory list and dashboard
|
||||
inventoryListRef.value?.reload()
|
||||
await loadInventoryData()
|
||||
}
|
||||
|
||||
const handleItemUpdated = (item: any) => {
|
||||
const handleItemUpdated = async (item: any) => {
|
||||
editingItem.value = null
|
||||
inventoryListRef.value?.reload()
|
||||
await loadInventoryData()
|
||||
}
|
||||
|
||||
const handleRestockFromDashboard = (item: any) => {
|
||||
// Open edit modal with the item (user can use Restock button there)
|
||||
editingItem.value = item
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user