|
@@ -11,19 +11,20 @@ SELECT
|
|
|
c.name AS "Category",
|
|
|
g.name AS "Group",
|
|
|
CASE WHEN t.organic THEN 'yes' ELSE 'no' END AS "Organic",
|
|
|
- to_char(t.price, 'FM999999999.00') AS "Price"
|
|
|
+ to_char(t.price, 'FM999999999.00') AS "Price",
|
|
|
--to_char(quantity, '9.'||repeat('9',3-1)||'EEEE') AS Quantity,
|
|
|
- -- to_char(CASE
|
|
|
- -- WHEN ut.name = 'Count' THEN t.price
|
|
|
- -- ELSE t.quantity * convert_unit(u.name, CASE
|
|
|
- -- WHEN ut.name = 'Volume' THEN ouv.name
|
|
|
- -- WHEN ut.name = 'Mass' THEN oum.name
|
|
|
- -- END, p.name) END, 'FM999999999.000') AS "Quantity",
|
|
|
- -- CASE
|
|
|
- -- WHEN ut.name = 'Count' THEN u.name
|
|
|
- -- WHEN ut.name = 'Volume' THEN ouv.name
|
|
|
- -- WHEN ut.name = 'Mass' THEN oum.name
|
|
|
- -- END AS "Unit"
|
|
|
+ to_char(CASE
|
|
|
+ WHEN ut.name = 'Count' THEN t.quantity
|
|
|
+ ELSE t.quantity * convert_unit(u.name, CASE
|
|
|
+ WHEN ut.name = 'Volume' THEN $unit_volume
|
|
|
+ WHEN ut.name = 'Mass' THEN $unit_mass
|
|
|
+ END, p.name)
|
|
|
+ END, 'FM999999999.000') AS "Quantity",
|
|
|
+ CASE
|
|
|
+ WHEN ut.name = 'Count' THEN u.name
|
|
|
+ WHEN ut.name = 'Volume' THEN $unit_volume
|
|
|
+ WHEN ut.name = 'Mass' THEN $unit_mass
|
|
|
+ END AS "Unit"
|
|
|
FROM transactions t
|
|
|
JOIN products p ON (product_id = p.id)
|
|
|
JOIN categories c ON (category_id = c.id)
|
|
@@ -31,13 +32,18 @@ JOIN groups g ON (group_id = g.id)
|
|
|
JOIN stores s ON (store_id = s.id)
|
|
|
JOIN units u ON (t.unit_id = u.id)
|
|
|
JOIN unit_types ut ON (u.unit_type_id = ut.id)
|
|
|
---LEFT JOIN sqlpage_options ouv ON ouv.type = 'unit_volume' AND ut.name = 'Volume'
|
|
|
WHERE
|
|
|
(p.name IN (SELECT v#>>'{}' FROM json_array_elements($products::json) j(v)) OR $products IS NULL)
|
|
|
AND
|
|
|
(c.name IN (SELECT v#>>'{}' FROM json_array_elements($categories::json) j(v)) OR $categories IS NULL)
|
|
|
AND
|
|
|
(g.name IN (SELECT v#>>'{}' FROM json_array_elements($groups::json) j(v)) OR $groups IS NULL)
|
|
|
+AND
|
|
|
+ CASE
|
|
|
+ WHEN ut.name = 'Count'
|
|
|
+ THEN (u.name IN (SELECT v#>>'{}' FROM json_array_elements($unit_count::json) j(v)) OR $unit_count IS NULL)
|
|
|
+ ELSE TRUE
|
|
|
+ END
|
|
|
AND
|
|
|
((ts AT TIME ZONE 'UTC') AT TIME ZONE 'Pacific/Auckland')::date
|
|
|
BETWEEN $start::date AND $end::date
|
|
@@ -50,4 +56,4 @@ AND
|
|
|
)
|
|
|
) OR $tags IS NULL)
|
|
|
ORDER BY ts DESC
|
|
|
-LIMIT 100);
|
|
|
+LIMIT 1000);
|