|
@@ -1,117 +1,2 @@
|
|
-SELECT
|
|
|
|
- 'dynamic' as component,
|
|
|
|
- sqlpage.run_sql('cookie.sql') AS properties
|
|
|
|
-;
|
|
|
|
-
|
|
|
|
-SELECT 'shell' AS component,
|
|
|
|
- 'dark' AS theme,
|
|
|
|
- 'Transactions' AS title
|
|
|
|
-;
|
|
|
|
-
|
|
|
|
-SELECT
|
|
|
|
- 'dynamic' as component,
|
|
|
|
- sqlpage.run_sql('nav.sql') AS properties
|
|
|
|
-;
|
|
|
|
-
|
|
|
|
-SELECT
|
|
|
|
- 'table' AS component,
|
|
|
|
- TRUE AS sort,
|
|
|
|
- TRUE AS search,
|
|
|
|
- TRUE AS striped_rows,
|
|
|
|
- TRUE AS small,
|
|
|
|
- 'Price' AS align_right,
|
|
|
|
- 'Quantity' AS align_right,
|
|
|
|
- 'Unit' AS align_right,
|
|
|
|
- 'Notice' AS markdown
|
|
|
|
-;
|
|
|
|
-
|
|
|
|
-DROP TABLE IF EXISTS sqlpage_txn;
|
|
|
|
-CREATE TEMPORARY TABLE IF NOT EXISTS sqlpage_txn AS (
|
|
|
|
-SELECT
|
|
|
|
- to_char(
|
|
|
|
- (ts AT TIME ZONE 'UTC') AT TIME ZONE 'Pacific/Auckland', --COALESCE('$ParameterTZ', 'Pacific/Auckland'),
|
|
|
|
- 'Mon DD HH24:MI:SS'
|
|
|
|
- ) AS "Time",
|
|
|
|
- t.description AS Description,
|
|
|
|
- s.code AS "Store",
|
|
|
|
- p.name AS "Product",
|
|
|
|
- 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(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"
|
|
|
|
-FROM transactions t
|
|
|
|
-JOIN products p ON (product_id = p.id)
|
|
|
|
-JOIN categories c ON (category_id = c.id)
|
|
|
|
-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)
|
|
|
|
-JOIN sqlpage_options op ON op.type = 'product' AND p.name = op.name
|
|
|
|
-JOIN sqlpage_options oc ON oc.type = 'category' AND c.name = oc.name
|
|
|
|
-JOIN sqlpage_options og ON og.type = 'group' AND g.name = og.name
|
|
|
|
-LEFT JOIN sqlpage_options ouv ON ouv.type = 'unit_volume' AND ut.name = 'Volume'
|
|
|
|
-AND
|
|
|
|
- ouv.session = sqlpage.cookie('session')
|
|
|
|
-AND
|
|
|
|
- COALESCE(ouv.selected, TRUE)
|
|
|
|
-LEFT JOIN sqlpage_options oum ON oum.type = 'unit_mass' AND ut.name = 'Mass'
|
|
|
|
-AND
|
|
|
|
- oum.session = sqlpage.cookie('session')
|
|
|
|
-AND
|
|
|
|
- COALESCE(oum.selected, TRUE)
|
|
|
|
-WHERE
|
|
|
|
- COALESCE(op.selected, oc.selected, og.selected, TRUE)
|
|
|
|
-AND
|
|
|
|
- op.session = sqlpage.cookie('session')
|
|
|
|
-AND
|
|
|
|
- oc.session = sqlpage.cookie('session')
|
|
|
|
-AND
|
|
|
|
- og.session = sqlpage.cookie('session')
|
|
|
|
-AND
|
|
|
|
- ((ts AT TIME ZONE 'UTC') AT TIME ZONE 'Pacific/Auckland')::date
|
|
|
|
- BETWEEN (
|
|
|
|
- SELECT name FROM sqlpage_options WHERE type = 'start'
|
|
|
|
- )::date AND (
|
|
|
|
- SELECT name FROM sqlpage_options WHERE type = 'end'
|
|
|
|
- )::date
|
|
|
|
-AND
|
|
|
|
- (t.id IN (
|
|
|
|
- SELECT
|
|
|
|
- transaction_id
|
|
|
|
- FROM tags_map
|
|
|
|
- WHERE tag_id IN (
|
|
|
|
- SELECT
|
|
|
|
- id
|
|
|
|
- FROM tags
|
|
|
|
- JOIN sqlpage_options ot
|
|
|
|
- ON ot.type = 'tag' AND ot.name = tags.name
|
|
|
|
- WHERE COALESCE(ot.selected, TRUE)
|
|
|
|
- AND ot.session = sqlpage.cookie('session')
|
|
|
|
- )
|
|
|
|
- ) OR NOT EXISTS (
|
|
|
|
- SELECT 1
|
|
|
|
- FROM sqlpage_options ot
|
|
|
|
- WHERE ot.selected IS TRUE
|
|
|
|
- AND ot.session = sqlpage.cookie('session')
|
|
|
|
- AND ot.type = 'tag'
|
|
|
|
- )
|
|
|
|
-)
|
|
|
|
-ORDER BY ts DESC
|
|
|
|
-LIMIT 100);
|
|
|
|
-SELECT * FROM sqlpage_txn;
|
|
|
|
-
|
|
|
|
-SELECT
|
|
|
|
- '# No Data' AS "Notice"
|
|
|
|
-WHERE NOT EXISTS(SELECT * FROM sqlpage_txn LIMIT 1);
|
|
|
|
|
|
+SET title = 'Transactions';
|
|
|
|
+SELECT 'dynamic' AS component, sqlpage.run_sql('entry.sql') AS properties;
|