|
@@ -1,119 +1,24 @@
|
|
-SET height = '500';
|
|
|
|
-SET type = 'pie';
|
|
|
|
-
|
|
|
|
-SET unit_count_chart = (SELECT v#>>'{}' FROM json_array_elements($unit_count::json) j(v) LIMIT 1);
|
|
|
|
-SET display_by_count = (SELECT count(*) FROM json_array_elements($unit_count::json) j(v)) == 1
|
|
|
|
-AND (EXISTS (SELECT 1 FROM sqlpage_txn WHERE unit = $unit_count_chart LIMIT 1));
|
|
|
|
-SET display_by_mass = (EXISTS (SELECT 1 FROM sqlpage_txn WHERE unit = $unit_mass LIMIT 1));
|
|
|
|
-SET display_by_volume = (EXISTS (SELECT 1 FROM sqlpage_txn WHERE unit = $unit_volume LIMIT 1));
|
|
|
|
-
|
|
|
|
-SET group_by = (CASE
|
|
|
|
-WHEN (SELECT count(DISTINCT "group") FROM sqlpage_txn WHERE unit = $unit_mass) > 2
|
|
|
|
-THEN 'Group'
|
|
|
|
-WHEN (SELECT count(DISTINCT category) FROM sqlpage_txn WHERE unit = $unit_mass) > 2
|
|
|
|
-THEN 'Category'
|
|
|
|
-ELSE 'Product'
|
|
|
|
-END);
|
|
|
|
-SET total = (SELECT sum(quantity) FROM sqlpage_txn WHERE unit = $unit_mass);
|
|
|
|
-SELECT 'chart' AS component
|
|
|
|
-, 'Share by Weight - Total: '||$total||' '||$unit_mass AS title
|
|
|
|
-, $height AS height
|
|
|
|
-, $type AS type
|
|
|
|
-, TRUE AS labels
|
|
|
|
-WHERE $display_by_mass::bool
|
|
|
|
-;
|
|
|
|
-SELECT "group" AS series
|
|
|
|
-, sum(quantity) AS value
|
|
|
|
-FROM sqlpage_txn
|
|
|
|
-WHERE $display_by_mass::bool
|
|
|
|
-AND $group_by = 'Group' AND unit = $unit_mass
|
|
|
|
-GROUP BY "group"
|
|
|
|
-;
|
|
|
|
-SELECT category AS series
|
|
|
|
-, sum(quantity) AS value
|
|
|
|
-FROM sqlpage_txn
|
|
|
|
-WHERE $display_by_mass::bool
|
|
|
|
-AND $group_by = 'Category' AND unit = $unit_mass
|
|
|
|
-GROUP BY category
|
|
|
|
-;
|
|
|
|
-SELECT product AS series
|
|
|
|
-, sum(quantity) AS value
|
|
|
|
-FROM sqlpage_txn
|
|
|
|
-WHERE $display_by_mass::bool
|
|
|
|
-AND $group_by = 'Product' AND unit = $unit_mass
|
|
|
|
-GROUP BY product
|
|
|
|
|
|
+SELECT 'card' AS component
|
|
|
|
+, 'Volume by Expendature and Quantity' AS title
|
|
|
|
+, 2 AS columns
|
|
;
|
|
;
|
|
|
|
+SELECT '/grocery/volume/Expense.sql?_sqlpage_embed' AS embed
|
|
|
|
+, '' AS footer
|
|
|
|
+WHERE EXISTS (SELECT 1 FROM sqlpage_txn LIMIT 1);
|
|
|
|
|
|
-SET group_by = (CASE
|
|
|
|
-WHEN (SELECT count(DISTINCT "group") FROM sqlpage_txn WHERE unit = $unit_volume) > 2
|
|
|
|
-THEN 'Group'
|
|
|
|
-WHEN (SELECT count(DISTINCT category) FROM sqlpage_txn WHERE unit = $unit_volume) > 2
|
|
|
|
-THEN 'Category'
|
|
|
|
-ELSE 'Product'
|
|
|
|
-END);
|
|
|
|
-SET total = (SELECT sum(quantity) FROM sqlpage_txn WHERE unit = $unit_volume);
|
|
|
|
-SELECT 'chart' AS component
|
|
|
|
-, 'Share by Volume - Total: '||$total||' '||$unit_volume AS title
|
|
|
|
-, $height AS height
|
|
|
|
-, $type AS type
|
|
|
|
-, TRUE AS labels
|
|
|
|
-WHERE $display_by_volume::bool
|
|
|
|
-;
|
|
|
|
-SELECT "group" AS series
|
|
|
|
-, sum(quantity) AS value
|
|
|
|
-FROM sqlpage_txn
|
|
|
|
-WHERE $display_by_volume::bool
|
|
|
|
-AND $group_by = 'Group' AND unit = $unit_volume
|
|
|
|
-GROUP BY "group"
|
|
|
|
-;
|
|
|
|
-SELECT category AS series
|
|
|
|
-, sum(quantity) AS value
|
|
|
|
-FROM sqlpage_txn
|
|
|
|
-WHERE $display_by_volume::bool
|
|
|
|
-AND $group_by = 'Category' AND unit = $unit_volume
|
|
|
|
-GROUP BY category
|
|
|
|
-;
|
|
|
|
-SELECT product AS series
|
|
|
|
-, sum(quantity) AS value
|
|
|
|
-FROM sqlpage_txn
|
|
|
|
-WHERE $display_by_volume::bool
|
|
|
|
-AND $group_by = 'Product' AND unit = $unit_volume
|
|
|
|
-GROUP BY product
|
|
|
|
|
|
+SELECT '/grocery/volume/Quantity.sql?unit='||$unit_mass||'&_sqlpage_embed' AS embed
|
|
|
|
+, '' AS footer
|
|
|
|
+WHERE EXISTS (SELECT 1 FROM sqlpage_txn WHERE unit = $unit_mass LIMIT 1)
|
|
;
|
|
;
|
|
|
|
|
|
-SET group_by = (CASE
|
|
|
|
-WHEN (SELECT count(DISTINCT "group") FROM sqlpage_txn WHERE unit = $unit_count_chart) > 2
|
|
|
|
-THEN 'Group'
|
|
|
|
-WHEN (SELECT count(DISTINCT category) FROM sqlpage_txn WHERE unit = $unit_count_chart) > 2
|
|
|
|
-THEN 'Category'
|
|
|
|
-ELSE 'Product'
|
|
|
|
-END);
|
|
|
|
-SET total = (SELECT sum(quantity) FROM sqlpage_txn WHERE unit = $unit_count_chart);
|
|
|
|
-SELECT 'chart' AS component
|
|
|
|
-, 'Share by Volume - Total: '||$total||' '||$unit_count_chart AS title
|
|
|
|
-, $height AS height
|
|
|
|
-, $type AS type
|
|
|
|
-, TRUE AS labels
|
|
|
|
-WHERE $display_by_count::bool
|
|
|
|
|
|
+SELECT '/grocery/volume/Quantity.sql?unit='||$unit_volume||'&_sqlpage_embed' AS embed
|
|
|
|
+, '' AS footer
|
|
|
|
+WHERE EXISTS (SELECT 1 FROM sqlpage_txn WHERE unit = $unit_volume LIMIT 1)
|
|
;
|
|
;
|
|
-SELECT "group" AS series
|
|
|
|
-, sum(quantity) AS value
|
|
|
|
-FROM sqlpage_txn
|
|
|
|
-WHERE $display_by_count::bool
|
|
|
|
-AND $group_by = 'Group' AND unit = $unit_count_chart
|
|
|
|
-GROUP BY "group"
|
|
|
|
-;
|
|
|
|
-SELECT category AS series
|
|
|
|
-, sum(quantity) AS value
|
|
|
|
-FROM sqlpage_txn
|
|
|
|
-WHERE $display_by_count::bool
|
|
|
|
-AND $group_by = 'Category' AND unit = $unit_count_chart
|
|
|
|
-GROUP BY category
|
|
|
|
|
|
+
|
|
|
|
+SET unit_count_chart = (SELECT v#>>'{}' FROM json_array_elements($unit_count::json) j(v) LIMIT 1);
|
|
|
|
+SELECT '/grocery/volume/Quantity.sql?unit='||$unit_count_chart||'&_sqlpage_embed' AS embed
|
|
|
|
+, '' AS footer
|
|
|
|
+WHERE EXISTS (SELECT 1 FROM sqlpage_txn WHERE unit = $unit_count_chart LIMIT 1)
|
|
|
|
+AND (SELECT count(DISTINCT v#>>'{}') FROM json_array_elements($unit_count::json) j(v)) == 1
|
|
;
|
|
;
|
|
-SELECT product AS series
|
|
|
|
-, sum(quantity) AS value
|
|
|
|
-FROM sqlpage_txn
|
|
|
|
-WHERE $display_by_count::bool
|
|
|
|
-AND $group_by = 'Product' AND unit = $unit_count_chart
|
|
|
|
-GROUP BY product
|
|
|
|
-;
|
|
|