Show all clients in clients page
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 56s
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 56s
This commit is contained in:
@@ -235,27 +235,24 @@ const getClientAnalytics = async (range = {}) => {
|
||||
const { params, whereClause } = buildDateFilter(range);
|
||||
const result = await pool.query(`
|
||||
SELECT
|
||||
MAX(cliente_nome) as name,
|
||||
cliente_fone as phone,
|
||||
COALESCE(NULLIF(cliente_nome, ''), 'Cliente Desconhecido') as name,
|
||||
MAX(NULLIF(cliente_fone, '')) as phone,
|
||||
COALESCE(SUM(quantidade), 0) as quantity_purchased,
|
||||
COALESCE(SUM(quantidade * valor_unitario), 0) as total_spent,
|
||||
COUNT(*)::int as order_line_count,
|
||||
COUNT(DISTINCT COALESCE(NULLIF(pedido_id, ''), data_pedido || '_' || valor_pedido::text))::int as order_count,
|
||||
MAX(data_pedido_date) as last_purchase_date
|
||||
FROM orders
|
||||
${whereClause}
|
||||
AND cliente_fone IS NOT NULL
|
||||
AND cliente_fone != ''
|
||||
GROUP BY cliente_fone
|
||||
ORDER BY total_spent DESC
|
||||
LIMIT 500;
|
||||
GROUP BY COALESCE(NULLIF(cliente_nome, ''), 'Cliente Desconhecido')
|
||||
ORDER BY total_spent DESC;
|
||||
`, params);
|
||||
|
||||
return result.rows.map(row => ({
|
||||
name: row.name,
|
||||
phone: row.phone,
|
||||
phone: row.phone || '',
|
||||
quantityPurchased: toNumber(row.quantity_purchased),
|
||||
totalSpent: toNumber(row.total_spent),
|
||||
orderLineCount: toNumber(row.order_line_count),
|
||||
orderCount: toNumber(row.order_count),
|
||||
lastPurchaseDate: row.last_purchase_date
|
||||
}));
|
||||
};
|
||||
@@ -282,8 +279,7 @@ const getRfmAnalytics = async (range = {}) => {
|
||||
AND cliente_fone IS NOT NULL
|
||||
AND cliente_fone != ''
|
||||
GROUP BY cliente_fone
|
||||
ORDER BY monetary DESC
|
||||
LIMIT 1000;
|
||||
ORDER BY monetary DESC;
|
||||
`, params),
|
||||
pool.query(`
|
||||
SELECT
|
||||
|
||||
Reference in New Issue
Block a user