• Stars
    star
    123
  • Rank 284,001 (Top 6 %)
  • Language
    Ruby
  • License
    MIT License
  • Created over 12 years ago
  • Updated about 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A web-based reporting system for the Ledger command line accounting program

Ledger Web

Note: Development of this codebase is not active, but the project is in a stable state.

Ledger Web is a web-based, postgresql-backed reporting system for the Ledger command-line accounting system. It 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.

To install:

$ gem install ledger_web
$ createdb ledger

To run:

$ ledger_web

From there, open up http://localhost:9090 in your browser and poke around. You'll see a few example reports.

Configuration

Configuring Ledger Web is pretty simple. Create a file at ~/.ledger_web/config.rb that looks something like this:

LedgerWeb::Config.new do |config|
  config.set :database_url, "postgres://localhost/ledger"
end

: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:

  • :index_report is the report that Ledger Web will redirect your browser to when you open it up the first time. Defaults to :help
  • :port is the port that Ledger Web will run on. Defaults to 9090
  • :ledger_file is the file that Ledger Web will read. Defaults to the LEDGER_FILE environment variable
  • :ledger_bin_path is the path to the ledger binary. Defaults to finding it in the PATH

Writing Reports

Reports 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:

<% @query = query do %>
select
    xtn_month,
    account,
    sum(amount)
from
    ledger
where
    (account ~ 'Income'
    or account ~ 'Expenses')
    and xtn_date between :from and :to
group by
    xtn_month,
    account
<% end %>
<%= table @query %>

The query helper takes a block of SQL and returns a LedgerWeb::Report instance. It can take a few options:

  • :pivot is the name of a column to pivot the report on.
  • :pivot_sort_order says how to order the resulting pivoted columns. Can be asc or desc. Defaults to asc.

Ledger Web uses Twitter Bootstrap for formatting, so you can use whatever you want to format your reports from there.

The 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:

:links => {"Account" => "/reports/register?account=:1"}

This says that every value in the Account column will be surrounded with an <a> 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.

Customizing

You can put Sequel migrations in ~/.ledger_web/migrate and they'll get applied as necessary at startup.

Hooks

Ledger Web provides several different hooks that get run during the data load process.

  • :before_insert_row gets the Sequel database and the current row immediatley before insertion. Row is to be modified in place.
  • :after_insert_row gets the Sequel database and the current row. Row modifications don't matter.
  • :before_load gets the Sequel database
  • :after_load gets the Sequel database

To define a hook, put something like this in your config file:

config.add_hook :before_insert_row do |db, row|
  # modify the row in place
end

Schema

The base table is named ledger. Here's the DDL:

create table ledger (
    xtn_id integer,  -- line number of the first line of the transaction
    xtn_date date,   -- date of the transaction
    xtn_month date,  -- month pre-extracted from the date
    xtn_year date,   -- year pre-extracted from the date
    checknum text,   -- check number (code)
    note text,       -- payee
    account text,    -- account name
    commodity text,  -- commodity
    amount number,   -- amount
    tags text,       -- any tags attached to the transaction
    virtual boolean, -- if the transaction is virutal or not
    cleared boolean  -- if the transaction is cleared or not
)

In addition, there's a few predefined views:

create view accounts_months as
with
    _a as (select account from ledger group by account),
    _m as (select xtn_month from ledger group by xtn_month)
select
    account,
    xtn_month
from
    _a cross join _m
;

create view accounts_days as
with
    _a as (select account from ledger group by account),
    _d as (select xtn_date from ledger group by xtn_date)
select
    account,
    xtn_date
from
    _a cross join _d
;

create view accounts_years as
with
    _a as (select account from ledger group by account),
    _y as (select xtn_year from ledger group by xtn_year)
select
    account,
    xtn_year
from
    _a cross join _y
;

More Repositories

1

dokuen

A personal PaaS for mac and linux
Ruby
551
star
2

sites

Simple wiki-based site generator.
Ruby
87
star
3

trading

A toy trading engine that only supports BUY and SELL limit orders
Ruby
86
star
4

calorific

Command-line nutrient tracking tool
Perl
79
star
5

marginalia

Marginalia
CSS
75
star
6

heroku-buildpack-vendorbinaries

A Heroku Buildpack for vendoring binaries into your application
Shell
63
star
7

capistrano-buildpack

Deploy 12-factor applications with Capistrano
Ruby
43
star
8

mmp-builder

Code for building Mastering Modern Payments
Ruby
37
star
9

proclaunch

A pure-perl process management system
Perl
28
star
10

Ledger-Tools-Demo

Tools that I use in association with Ledger
Python
26
star
11

git-hooks

Git hooks I use on my gitolite server
Python
23
star
12

route53_ddns

Route53 DDNS Updater
Ruby
15
star
13

dokuen-scripts

14
star
14

dotfiles

These are my dotfiles
Shell
14
star
15

herokubrew

A binary dependency build system for Heroku
Ruby
13
star
16

tailscale-op-proxy

Ruby
13
star
17

stripe_reporter

Simple reporting tool for Stripe SQLite Export
Ruby
13
star
18

ledger-web-config

My personal Ledger Weg config
Ruby
12
star
19

docker-compose-stack

Use docker-compose and watchtower to self-deploy and auto-update a stack
Shell
7
star
20

speedee

A web-based mail client for notmuch
JavaScript
7
star
21

sequins

Temporal sequences
Ruby
6
star
22

foreman-export-nginx

Export foreman applications to nginx configs.
Ruby
6
star
23

nomic

A game of Nomic
6
star
24

diycdn

Hosting my own CDN for fun and profit
Ruby
5
star
25

page_viewer

View a directory of markdown files as a series of web pages
Ruby
4
star
26

fly-proxy

Dockerfile
4
star
27

homer

Self-contained system for managing home directories
3
star
28

Phytos

A simple photo gallery rails app
Ruby
3
star
29

homelab

My homelab configs
HTML
3
star
30

bugsplat.info

Source code for http://bugsplat.info
JavaScript
3
star
31

ledger-snap

Backup ledger files to tarsnap
Shell
2
star
32

kata

Various code kata projects. Mostly lisp implementations.
Perl
2
star
33

rubyquiz

Ruby quiz answers
Ruby
2
star
34

ledger_gen

Generate ledger-cli files
Ruby
2
star
35

baroque

An elegant email client for a more civilized age
JavaScript
2
star
36

plaid-gateway

Gateway for Plaid transactions
2
star
37

demosite

Code for the sites demosite
2
star
38

marginalia-io

Marginalia Ruby API and command-line client
Ruby
2
star
39

emacs

My emacs config
Emacs Lisp
2
star
40

bbiz-archive

Archive for bbiz slack chat
Ruby
2
star
41

wyse3040setup

Shell
1
star
42

roku-parental-controls

Ruby
1
star
43

moves-backup

Moves Backup
Ruby
1
star
44

feeds

RSS to Email feed reader
Ruby
1
star
45

macguffin

A stupid usenet client
Go
1
star
46

fax-twimlet

Fax -> Email gateway
Ruby
1
star
47

is-kettleman-still-open.github.com

JavaScript
1
star
48

painkillerjane

A tiny sinatra/datamapper app to track painkiller dosing
Ruby
1
star
49

bugsplat-puppet-conf

standalone puppet config for bugsplat ec2 images
Ruby
1
star
50

sequel-reporter

A small opinionated framework for writing reporting applications using Sequel
JavaScript
1
star
51

uploads

A little application for uploading files to a remote server
JavaScript
1
star
52

calendar-remixer

Scrub, filter, and mix multiple calendars into one iCal feed
Ruby
1
star
53

trimet-iframe

An embeddable iframe for Trimet arrival info
Ruby
1
star
54

ssl-management

How I manage my certificates
1
star
55

aioesphomeserver

Python
1
star