Ledger to potężne narzędzie wiersza poleceń do prowadzenia księgowości podwójnego zapisu w formacie zwykłego tekstu. Zapisując finanse w czytelnych plikach tekstowych, Ledger pozwala na bieżąco obliczać salda, tworzyć rejestry i generować raporty finansowe.
Podstawowe pojęcia i wprowadzenie
Równanie księgowości podwójnego zapisu
W Ledger każda transakcja składa się z co najmniej dwóch wpisów, których suma musi wynosić dokładnie zero:
$$\text{Assets} + \text{Expenses} = \text{Liabilities} + \text{Equity} + \text{Income}$$
Assets:Checking -$600.00 ; Asset decreases (credit)
Expenses:Rent $600.00 ; Expense increases (debit)
---------------------------------
Saldo netto = $0.00
Przegląd głównych poleceń
| Polecenie | Pełna forma | Opis |
|---|---|---|
ledger bal |
ledger balance |
Oblicza i wyświetla bieżące salda wszystkich kont |
ledger reg |
ledger register |
Wyświetla chronologicznie wpisy transakcji wraz z saldem bieżącym |
ledger print |
ledger print |
Formatuje i drukuje wpisy dziennika |
ledger csv |
ledger csv |
Eksportuje przefiltrowane transakcje do formatu CSV |
ledger payees |
ledger payees |
Wyświetla listę wszystkich kontrahentów w dzienniku |
ledger accounts |
ledger accounts |
Wyświetla nazwy zdefiniowanych kont i ich hierarchię |
Specyfikacja składni dziennika
Podstawowa struktura transakcji
2024/01/03 * (CODE#001) Landlord John ; tag:rent
Expenses:Rent:Apartment $600.00
Assets:Checking:MainBank
- Struktura wiersza nagłówka::
2024/01/03 * (CODE#001) Landlord John ; tag:rent
^ ^ ^ ^ ^
Date State Code/Check# Payee/Description Comment & Tags
- Automatyczne dopełnienie: Ledger może automatycznie wyliczyć kwotę jednego wpisu, aby transakcja bilansowała się do zera.
Flagi stanu transakcji
| Flaga | Stan | Opis i typowe zastosowanie |
|---|---|---|
| (None) | Nierozliczona | Nowe transakcje jeszcze niezweryfikowane z wyciągiem bankowym |
! |
Oczekująca | Zainicjowane transakcje oczekujące na rozliczenie |
* |
Rozliczona | Transakcje uzgodnione i zaksięgowane na rachunku |
Daty pomocnicze
Znak równości pozwala oddzielić datę zdarzenia od rzeczywistej daty rozliczenia:
; Format: EventDate=SettlementDate
2024/01/01=2024/01/15 Consulting Client A
Assets:AccountsReceivable $1,000.00
Income:Consulting
Asercje i przypisania salda
- Asercja salda (= $VALUE): sprawdza, czy narastające saldo konta dokładnie odpowiada podanej wartości.
- Przypisanie salda (= $VALUE): wylicza różnicę niezbędną do doprowadzenia konta do podanego salda.
; 1. Balance Assertion
2024/01/01 * Restaurant
Expenses:Food:Dinner $20.00
Assets:Cash -$20.00 = $500.00
; 2. Balance Assignment
2024/01/01 * Opening Balance
Assets:Cash = $500.00
Equity:OpeningBalances
Account Declarations & Validation
account Expenses:Food
note Dining and grocery expenses
alias food
payee ^(KFC|McDonalds|Starbucks)$
check commodity == "$"
assert commodity == "$"
default
account Assets:Cash
alias cash
Commodities & Currencies
; 1. Per-unit cost (@ symbol)
2024/05/31 * Farmers Market
Expenses:Food:Apples 10 APPLE @ $1.50
Assets:Checking -$15.00
; 2. Total cost (@@ symbol)
2024/06/01 * Brokerage
Assets:Investments:AAPL 5 AAPL @@ $950.00
Assets:Checking -$950.00
; 3. Explicit currency price history
P 2024/06/01 00:00:00 EUR $1.0850
Directives
; Global default currency
D $1,000.00
; Set default year
Y2024
Including Sub-Journals
include accounts.journal
include 2023.journal
include 2024.journal
account Business
include company_expenses.journal
end
Budgeting
~ Monthly
Expenses:Rent $600.00
Expenses:Food $400.00
Expenses:Utilities $100.00
Expenses $100.00
Assets
~ Yearly
Expenses:Insurance $1,200.00
Assets
ledger bal --budget Expensesledger bal --unbudgeted Expenses
Wyrażenia okresów
Ledger umożliwia filtrowanie czasowe w języku naturalnym za pomocą opcji -p lub --period.
Syntax Structure
[INTERVAL] [BEGIN] [END]
Interwały
| Interwał | Znaczenie |
|---|---|
every day / daily |
Daily |
every week / weekly |
Weekly |
biweekly |
Every two weeks |
every month / monthly |
Monthly |
every quarter / quarterly |
Quarterly |
every year / yearly |
Yearly |
every N days/weeks/months |
Custom interval |
Period Filtering Examples
ledger reg -p "since last month"
ledger reg Expenses -p "every month from 2024 to 2024/12/31" -M
ledger bal -p "from 2024/01/01 until this month"
ledger bal Expenses:Food -p "last quarter"
Wyrażenia zapytań i filtrowanie
| Syntax | Cel | Przykład | Opis |
|---|---|---|---|
Account |
Account name | ledger bal Assets |
Substring/regex match |
^Account |
Root account | ledger bal ^Expenses |
Accounts starting with Expenses |
@Payee |
Payee name | ledger reg @Starbucks |
Match payee field |
%Tag |
Tag presence | ledger reg %reimburse |
Match tagged transactions |
%Tag=Value |
Tag value | ledger reg %project=alpha |
Match tag key-value pairs |
=Note |
Memo note | ledger reg =taxi |
Match memo text |
#Code |
Transaction code | ledger reg #1042 |
Match check or order number |
Logika Boole'a
ledger reg Expenses:Food and @Starbucks and not dining
ledger bal Rent or Transportation
ledger bal Expenses and not \( Drinks or Food \)
Popularne opcje filtrowania
| Flaga | Opcja | Opis |
|---|---|---|
-b DATE |
--begin DATE |
Filter transactions on or after date |
-e DATE |
--end DATE |
Filter transactions before date |
-C |
--cleared |
Only cleared transactions (*) |
-U |
--uncleared |
Only uncleared transactions |
--pending |
--pending |
Only pending transactions (!) |
-R |
--real |
Exclude virtual postings |
-r |
--related |
Show the offsetting balancing postings |
Raporty i eksport danych
-s, --subtotal # Calculate subtotals for grouped postings
-n, --collapse # Collapse multi-line postings into one line
--flat # Render account tree as a flat list
--tail N # Limit output to last N lines
--invert # Invert numerical signs (display expenses as positive)
-X CUR, --exchange CUR # Convert foreign holdings to specified currency at latest rate
# Export all entries to CSV
ledger csv > report.csv
# Export this month's dining expenses
ledger csv Expenses:Food -p "this month"
Przykłady praktyczne
# Current assets vs liabilities
ledger bal ^Assets ^Liabilities
# Net revenue this month with positive expenses
ledger bal ^Expenses ^Income -p "this month" --invert
# Top 10 largest expenses
ledger reg Expenses -S amount --tail 10
# Monthly average daily expenses
ledger reg Expenses -M -n --average