Add/fix filters and styling for product page, add drag and drop
This commit is contained in:
@@ -70,6 +70,23 @@ router.get('/', async (req, res) => {
|
||||
params.push(parseFloat(req.query.maxStock));
|
||||
}
|
||||
|
||||
if (req.query.daysOfStock) {
|
||||
conditions.push('pm.days_of_inventory >= ?');
|
||||
params.push(parseFloat(req.query.daysOfStock));
|
||||
}
|
||||
|
||||
// Handle boolean filters
|
||||
if (req.query.replenishable === 'true' || req.query.replenishable === 'false') {
|
||||
conditions.push('p.replenishable = ?');
|
||||
params.push(req.query.replenishable === 'true');
|
||||
}
|
||||
|
||||
if (req.query.managingStock === 'true' || req.query.managingStock === 'false') {
|
||||
conditions.push('p.managing_stock = ?');
|
||||
params.push(req.query.managingStock === 'true');
|
||||
}
|
||||
|
||||
// Handle price filters
|
||||
if (req.query.minPrice) {
|
||||
conditions.push('p.price >= ?');
|
||||
params.push(parseFloat(req.query.minPrice));
|
||||
@@ -80,6 +97,27 @@ router.get('/', async (req, res) => {
|
||||
params.push(parseFloat(req.query.maxPrice));
|
||||
}
|
||||
|
||||
if (req.query.minCostPrice) {
|
||||
conditions.push('p.cost_price >= ?');
|
||||
params.push(parseFloat(req.query.minCostPrice));
|
||||
}
|
||||
|
||||
if (req.query.maxCostPrice) {
|
||||
conditions.push('p.cost_price <= ?');
|
||||
params.push(parseFloat(req.query.maxCostPrice));
|
||||
}
|
||||
|
||||
if (req.query.minLandingCost) {
|
||||
conditions.push('p.landing_cost_price >= ?');
|
||||
params.push(parseFloat(req.query.minLandingCost));
|
||||
}
|
||||
|
||||
if (req.query.maxLandingCost) {
|
||||
conditions.push('p.landing_cost_price <= ?');
|
||||
params.push(parseFloat(req.query.maxLandingCost));
|
||||
}
|
||||
|
||||
// Handle sales metrics filters
|
||||
if (req.query.minSalesAvg) {
|
||||
conditions.push('pm.daily_sales_avg >= ?');
|
||||
params.push(parseFloat(req.query.minSalesAvg));
|
||||
@@ -90,6 +128,27 @@ router.get('/', async (req, res) => {
|
||||
params.push(parseFloat(req.query.maxSalesAvg));
|
||||
}
|
||||
|
||||
if (req.query.minWeeklySales) {
|
||||
conditions.push('pm.weekly_sales_avg >= ?');
|
||||
params.push(parseFloat(req.query.minWeeklySales));
|
||||
}
|
||||
|
||||
if (req.query.maxWeeklySales) {
|
||||
conditions.push('pm.weekly_sales_avg <= ?');
|
||||
params.push(parseFloat(req.query.maxWeeklySales));
|
||||
}
|
||||
|
||||
if (req.query.minMonthlySales) {
|
||||
conditions.push('pm.monthly_sales_avg >= ?');
|
||||
params.push(parseFloat(req.query.minMonthlySales));
|
||||
}
|
||||
|
||||
if (req.query.maxMonthlySales) {
|
||||
conditions.push('pm.monthly_sales_avg <= ?');
|
||||
params.push(parseFloat(req.query.maxMonthlySales));
|
||||
}
|
||||
|
||||
// Handle financial metrics filters
|
||||
if (req.query.minMargin) {
|
||||
conditions.push('pm.avg_margin_percent >= ?');
|
||||
params.push(parseFloat(req.query.minMargin));
|
||||
@@ -110,6 +169,32 @@ router.get('/', async (req, res) => {
|
||||
params.push(parseFloat(req.query.maxGMROI));
|
||||
}
|
||||
|
||||
// Handle lead time and coverage filters
|
||||
if (req.query.minLeadTime) {
|
||||
conditions.push('pm.avg_lead_time_days >= ?');
|
||||
params.push(parseFloat(req.query.minLeadTime));
|
||||
}
|
||||
|
||||
if (req.query.maxLeadTime) {
|
||||
conditions.push('pm.avg_lead_time_days <= ?');
|
||||
params.push(parseFloat(req.query.maxLeadTime));
|
||||
}
|
||||
|
||||
if (req.query.leadTimeStatus) {
|
||||
conditions.push('pm.lead_time_status = ?');
|
||||
params.push(req.query.leadTimeStatus);
|
||||
}
|
||||
|
||||
if (req.query.minStockCoverage) {
|
||||
conditions.push('(pm.days_of_inventory / pt.target_days) >= ?');
|
||||
params.push(parseFloat(req.query.minStockCoverage));
|
||||
}
|
||||
|
||||
if (req.query.maxStockCoverage) {
|
||||
conditions.push('(pm.days_of_inventory / pt.target_days) <= ?');
|
||||
params.push(parseFloat(req.query.maxStockCoverage));
|
||||
}
|
||||
|
||||
// Handle status filters
|
||||
if (req.query.stockStatus && req.query.stockStatus !== 'all') {
|
||||
conditions.push('pm.stock_status = ?');
|
||||
@@ -208,10 +293,10 @@ router.get('/', async (req, res) => {
|
||||
res.json({
|
||||
products,
|
||||
pagination: {
|
||||
page,
|
||||
limit,
|
||||
total,
|
||||
totalPages: Math.ceil(total / limit)
|
||||
currentPage: page,
|
||||
pages: Math.ceil(total / limit),
|
||||
limit
|
||||
},
|
||||
filters: {
|
||||
categories: categories.map(category => category.name),
|
||||
|
||||
Reference in New Issue
Block a user