Files
wehub-resource-sync d718c5a372
CI / windows_test (push) Waiting to run
CI / compile_and_lint (push) Failing after 0s
CI / docker_build (linux/amd64, -linux-amd64-duckdb, duckdb) (push) Failing after 0s
CI / docker_build (linux/arm64, -linux-arm64, minimal) (push) Failing after 2s
CI / docker_build (linux/arm64, -linux-arm64-duckdb, duckdb) (push) Failing after 1s
CI / docker_build (linux/amd64, minimal) (push) Failing after 1s
CI / test (, sqlite, sqlite::memory:) (push) Has been skipped
CI / test (mssql, mssql, mssql://root:Password123!@127.0.0.1/sqlpage) (push) Has been skipped
CI / test (mysql, mysql, mysql://root:Password123!@127.0.0.1/sqlpage) (push) Has been skipped
CI / test (oracle, oracle, Driver=Oracle 21 ODBC driver;Dbq=//127.0.0.1:1521/FREEPDB1;Uid=root;Pwd=Password123!) (push) Has been skipped
CI / test (postgres, odbc, Driver=PostgreSQL Unicode;Server=127.0.0.1;Port=5432;Database=sqlpage;UID=root;PWD=Password123!, true) (push) Has been skipped
CI / test (postgres, postgres, postgres://root:Password123!@127.0.0.1/sqlpage) (push) Has been skipped
CI / playwright (push) Has been skipped
CI / docker_build (linux/arm/v7, -linux-arm-v7, minimal) (push) Failing after 0s
CI / hurl_examples (push) Failing after 8s
deploy website / deploy_official_site (push) Failing after 1s
CI / docker_push (duckdb) (push) Waiting to run
CI / docker_push (minimal) (push) Waiting to run
CI / hurl (${{ matrix.example }}) (push) Has been skipped
chore: import upstream snapshot with attribution
2026-07-13 12:31:57 +08:00

49 lines
1.9 KiB
SQL

-- Write the name of the group in the title of the page
SELECT 'title' as component, name as contents FROM expense_group WHERE id = $id;
-- Handle the form to add a member to the group (we do it at the top of the page to see it right away)
INSERT INTO group_member(group_id, name)
SELECT $id, :new_member_name WHERE :new_member_name IS NOT NULL;
-- List of members of the group
SELECT 'list' as component, 'Members' as title;
SELECT name AS title FROM group_member WHERE group_id = $id;
-- Form to add a new member to the group
SELECT 'form' as component, 'Add a member to the group' as validate;
SELECT 'Member Name' AS 'label', 'new_member_name' AS name;
SELECT 'title' as component, 'Expenses' as contents
-- Form to add an expense
SELECT 'form' as component, 'Add an expense' as title, 'Add' as validate;
SELECT 'Description' AS name;
SELECT 'Amount' AS name, 'number' AS type;
SELECT 'Spent By' AS name, 'select' as type,
json_group_array(json_object('label', name, 'value', id)) as options
FROM group_member WHERE group_id = $id;
-- Insert the expense posted by the form into the database
INSERT INTO expense(spent_by, name, amount)
SELECT :"Spent By", :Description, :Amount WHERE :Amount IS NOT NULL;
-- List of expenses of the group
SELECT 'card' as component, 'Expenses' as title;
SELECT expense.name as title,
'By ' || group_member.name || ', on ' || expense.date as description,
expense.amount || ' €' as footer,
CASE
WHEN expense.amount > 100 THEN 'red'
WHEN expense.amount > 50 THEN 'orange'
ELSE 'blue'
END AS color
FROM expense
INNER JOIN group_member on expense.spent_by = group_member.id
WHERE group_member.group_id = $id;
-- Show the positive and negative debts of each member
SELECT 'chart' AS component, 'Debts by Person' AS title, 'bar' AS type, TRUE AS horizontal;
SELECT member_name AS label, is_owed AS value FROM individual_debts
WHERE group_id = $id ORDER BY is_owed DESC;