feat(freezer): remove expiration tracking for freezer compatibility and clean stock management
Build and Push Fridger Container / Build & Push Fridger Image (push) Successful in 1m20s
Build and Push Fridger Container / Build & Push Fridger Image (push) Successful in 1m20s
This commit is contained in:
@@ -68,30 +68,15 @@ function getAllItems({ search = '', category = '', location = '', status = 'all'
|
||||
params.push(location);
|
||||
}
|
||||
|
||||
const today = new Date().toISOString().slice(0, 10);
|
||||
|
||||
if (status === 'expired') {
|
||||
query += ` AND expiry_date IS NOT NULL AND expiry_date != '' AND expiry_date < ?`;
|
||||
params.push(today);
|
||||
} else if (status === 'expiring_soon') {
|
||||
const next3Days = new Date(Date.now() + 3 * 24 * 60 * 60 * 1000).toISOString().slice(0, 10);
|
||||
query += ` AND expiry_date IS NOT NULL AND expiry_date != '' AND expiry_date >= ? AND expiry_date <= ?`;
|
||||
params.push(today, next3Days);
|
||||
} else if (status === 'fresh') {
|
||||
const next3Days = new Date(Date.now() + 3 * 24 * 60 * 60 * 1000).toISOString().slice(0, 10);
|
||||
query += ` AND (expiry_date IS NULL OR expiry_date = '' OR expiry_date > ?)`;
|
||||
params.push(next3Days);
|
||||
if (status === 'opened') {
|
||||
query += ` AND (is_opened = 1 OR quantity < initial_quantity)`;
|
||||
} else if (status === 'full') {
|
||||
query += ` AND (is_opened = 0 AND quantity >= initial_quantity)`;
|
||||
} else if (status === 'low') {
|
||||
query += ` AND (quantity <= (initial_quantity * 0.25) OR quantity = 0)`;
|
||||
}
|
||||
|
||||
query += ` ORDER BY
|
||||
CASE
|
||||
WHEN expiry_date IS NULL OR expiry_date = '' THEN 1
|
||||
ELSE 0
|
||||
END,
|
||||
expiry_date ASC,
|
||||
updated_at DESC`;
|
||||
query += ` ORDER BY updated_at DESC, name ASC`;
|
||||
|
||||
const stmt = db.prepare(query);
|
||||
return stmt.all(...params);
|
||||
@@ -362,27 +347,21 @@ function getActivityLogs(limit = 50) {
|
||||
}
|
||||
|
||||
function getStats() {
|
||||
const today = new Date().toISOString().slice(0, 10);
|
||||
const next3Days = new Date(Date.now() + 3 * 24 * 60 * 60 * 1000).toISOString().slice(0, 10);
|
||||
|
||||
const totalStmt = db.prepare(`SELECT COUNT(*) as count FROM items`);
|
||||
const total = totalStmt.get().count;
|
||||
|
||||
const expiredStmt = db.prepare(`
|
||||
const openedStmt = db.prepare(`
|
||||
SELECT COUNT(*) as count FROM items
|
||||
WHERE expiry_date IS NOT NULL AND expiry_date != '' AND expiry_date < ?
|
||||
WHERE is_opened = 1 OR quantity < initial_quantity
|
||||
`);
|
||||
const expired = expiredStmt.get(today).count;
|
||||
|
||||
const expiringSoonStmt = db.prepare(`
|
||||
SELECT COUNT(*) as count FROM items
|
||||
WHERE expiry_date IS NOT NULL AND expiry_date != '' AND expiry_date >= ? AND expiry_date <= ?
|
||||
`);
|
||||
const expiringSoon = expiringSoonStmt.get(today, next3Days).count;
|
||||
|
||||
const openedStmt = db.prepare(`SELECT COUNT(*) as count FROM items WHERE is_opened = 1`);
|
||||
const opened = openedStmt.get().count;
|
||||
|
||||
const fullStmt = db.prepare(`
|
||||
SELECT COUNT(*) as count FROM items
|
||||
WHERE is_opened = 0 AND quantity >= initial_quantity
|
||||
`);
|
||||
const full = fullStmt.get().count;
|
||||
|
||||
const lowStmt = db.prepare(`
|
||||
SELECT COUNT(*) as count FROM items
|
||||
WHERE quantity <= (initial_quantity * 0.25) AND quantity > 0
|
||||
@@ -391,11 +370,9 @@ function getStats() {
|
||||
|
||||
return {
|
||||
total,
|
||||
expired,
|
||||
expiringSoon,
|
||||
full,
|
||||
opened,
|
||||
low,
|
||||
fresh: total - expired - expiringSoon
|
||||
low
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user