{"id":13558248,"url":"https://github.com/peterkeen/ledger-web","last_synced_at":"2025-04-15T21:47:43.887Z","repository":{"id":2136641,"uuid":"3080293","full_name":"peterkeen/ledger-web","owner":"peterkeen","description":"A web-based reporting system for the Ledger command line accounting program","archived":false,"fork":false,"pushed_at":"2020-06-03T10:16:43.000Z","size":354,"stargazers_count":123,"open_issues_count":8,"forks_count":13,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-15T21:47:38.021Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/peterkeen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2011-12-31T17:46:52.000Z","updated_at":"2025-04-07T20:12:24.000Z","dependencies_parsed_at":"2022-09-13T17:51:30.710Z","dependency_job_id":null,"html_url":"https://github.com/peterkeen/ledger-web","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterkeen%2Fledger-web","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterkeen%2Fledger-web/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterkeen%2Fledger-web/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterkeen%2Fledger-web/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/peterkeen","download_url":"https://codeload.github.com/peterkeen/ledger-web/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249161105,"owners_count":21222468,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T12:04:50.186Z","updated_at":"2025-04-15T21:47:43.815Z","avatar_url":"https://github.com/peterkeen.png","language":"Ruby","readme":"Ledger Web\n----------\n\n**Note:** Development of this codebase is not active, but the project is in a stable state.\n\nLedger Web is a web-based, postgresql-backed reporting system for the [Ledger](http://www.ledger-cli.org) command-line accounting system.\nIt is intended to be completely flexible, allowing you to write whatever reports you want. Note that Ledger Web requires **PostgreSQL version 9.0 or greater**.\n\nTo install:\n\n    $ gem install ledger_web\n    $ createdb ledger\n    \nTo run:\n\n    $ ledger_web\n    \nFrom there, open up http://localhost:9090 in your browser and poke around. You'll see a few example reports.\n\n#### Configuration\n\nConfiguring Ledger Web is pretty simple. Create a file at `~/.ledger_web/config.rb` that looks something like this:\n\n\n    LedgerWeb::Config.new do |config|\n      config.set :database_url, \"postgres://localhost/ledger\"\n    end\n\n`:database_url` should point at your database instance. It doesn't have to be local, but the configured user needs to be able to alter the schema. There are a bunch more settings that you can set:\n\n* `:index_report` is the report that Ledger Web will redirect your browser to when you open it up the first time. Defaults to `:help`\n* `:port` is the port that Ledger Web will run on. Defaults to `9090`\n* `:ledger_file` is the file that Ledger Web will read. Defaults to the `LEDGER_FILE` environment variable\n* `:ledger_bin_path` is the path to the ledger binary. Defaults to finding it in the `PATH`\n\n#### Writing Reports\n\nReports are just HTML ERB files that live in `~/.ledger_web/reports`. Ledger Web provides a few useful helpers that let you easily define SQL queries. Here's an example report:\n\n    \u003c% @query = query do %\u003e\n    select\n        xtn_month,\n        account,\n        sum(amount)\n    from\n        ledger\n    where\n        (account ~ 'Income'\n        or account ~ 'Expenses')\n        and xtn_date between :from and :to\n    group by\n        xtn_month,\n        account\n    \u003c% end %\u003e\n    \u003c%= table @query %\u003e\n\nThe `query` helper takes a block of SQL and returns a `LedgerWeb::Report` instance. It can take a few options:\n\n* `:pivot` is the name of a column to pivot the report on. \n* `:pivot_sort_order` says how to order the resulting pivoted columns. Can be `asc` or `desc`. Defaults to `asc`.\n\nLedger Web uses [Twitter Bootstrap](http://twitter.github.com/bootstrap) for formatting, so you can use whatever you want to format your reports from there. \n\nThe `table` helper takes a query produced by the `query` helper and some options and builds an HTML table. Also, it can take a `:links` option which will linkify values in the table. Here's an example:\n\n    :links =\u003e {\"Account\" =\u003e \"/reports/register?account=:1\"}\n    \nThis says that every value in the `Account` column will be surrounded with an `\u003ca\u003e` tag pointing at `/reports/register?account=:1`, where `:1` will be replaced by the value in column 1 of that particular row. You can also use `:title` in a link template. It will get replaced with the title of the column that is currently getting linked. In this case, `:title` would get replaced with `Account`. \n\n#### Customizing\n\nYou can put [Sequel migrations](http://sequel.rubyforge.org/rdoc/files/doc/migration_rdoc.html) in `~/.ledger_web/migrate` and they'll get applied as necessary at startup.\n\n#### Hooks\n\nLedger Web provides several different hooks that get run during the data load process. \n\n* `:before_insert_row` gets the Sequel database and the current row immediatley before insertion. Row is to be modified in place.\n* `:after_insert_row` gets the Sequel database and the current row. Row modifications don't matter.\n* `:before_load` gets the Sequel database\n* `:after_load` gets the Sequel database\n\nTo define a hook, put something like this in your config file:\n\n    config.add_hook :before_insert_row do |db, row|\n      # modify the row in place\n    end\n    \n#### Schema\n\nThe base table is named `ledger`. Here's the DDL:\n\n    create table ledger (\n        xtn_id integer,  -- line number of the first line of the transaction\n        xtn_date date,   -- date of the transaction\n        xtn_month date,  -- month pre-extracted from the date\n        xtn_year date,   -- year pre-extracted from the date\n        checknum text,   -- check number (code)\n        note text,       -- payee\n        account text,    -- account name\n        commodity text,  -- commodity\n        amount number,   -- amount\n        tags text,       -- any tags attached to the transaction\n        virtual boolean, -- if the transaction is virutal or not\n        cleared boolean  -- if the transaction is cleared or not\n    )\n\nIn addition, there's a few predefined views:\n\n    create view accounts_months as\n    with\n        _a as (select account from ledger group by account),\n        _m as (select xtn_month from ledger group by xtn_month)\n    select\n        account,\n        xtn_month\n    from\n        _a cross join _m\n    ;\n    \n    create view accounts_days as\n    with\n        _a as (select account from ledger group by account),\n        _d as (select xtn_date from ledger group by xtn_date)\n    select\n        account,\n        xtn_date\n    from\n        _a cross join _d\n    ;\n    \n    create view accounts_years as\n    with\n        _a as (select account from ledger group by account),\n        _y as (select xtn_year from ledger group by xtn_year)\n    select\n        account,\n        xtn_year\n    from\n        _a cross join _y\n    ;\n    \n","funding_links":[],"categories":["Ruby","others"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeterkeen%2Fledger-web","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpeterkeen%2Fledger-web","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeterkeen%2Fledger-web/lists"}