Skip to content

Commit e6fbc93

Browse files
committed
doc: update readme
1 parent 032410d commit e6fbc93

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed

README.md

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,94 @@
2020
$ npm install @seneca/ledger
2121
```
2222

23+
## Quick Example
24+
25+
```js
26+
// Setup
27+
const seneca = Seneca().use('promisify').use('entity').use('ledger')
28+
await seneca.ready()
29+
30+
// Create an account
31+
await seneca.post('biz:ledger,create:account', {
32+
account: { oref: 'o0', path: 'Asset', name: 'Cash', normal: 'debit' },
33+
})
34+
35+
// Get an account
36+
await seneca.post('biz:ledger,get:account', { aref: 'o0/Asset/Cash' })
37+
38+
// List accounts
39+
await seneca.post('biz:ledger,list:account', { org_id: 'o0' })
40+
41+
// Update an account
42+
await seneca.post('biz:ledger,update:account', {
43+
aref: 'o0/Asset/Cash',
44+
account: { custom_field: 'value' },
45+
})
46+
47+
// Create a book (accounting period)
48+
await seneca.post('biz:ledger,create:book', {
49+
book: { oref: 'o0', name: 'Q1', start: 20220101, end: 20220331 },
50+
})
51+
52+
// Get a book
53+
await seneca.post('biz:ledger,get:book', { bref: 'o0/Q1/20220101' })
54+
55+
// List books
56+
await seneca.post('biz:ledger,list:book', { oref: 'o0' })
57+
58+
// Update a book
59+
await seneca.post('biz:ledger,update:book', {
60+
bref: 'o0/Q1/20220101',
61+
book: { end: 20220331 },
62+
})
63+
64+
// Create a journal entry (double-entry: debit + credit)
65+
await seneca.post('biz:ledger,create:entry', {
66+
bref: 'o0/Q1/20220101',
67+
daref: 'o0/Asset/Cash',
68+
caref: 'o0/Income/Sales',
69+
val: 100,
70+
desc: 'Jan Sales',
71+
date: 20220131,
72+
})
73+
74+
// List entries
75+
await seneca.post('biz:ledger,list:entry', {
76+
oref: 'o0',
77+
bref: 'o0/Q1/20220101',
78+
})
79+
80+
// Balance an account
81+
await seneca.post('biz:ledger,balance:account', {
82+
aref: 'o0/Asset/Cash',
83+
bref: 'o0/Q1/20220101',
84+
})
85+
86+
// Close an account (zero balance and optionally carry forward to target book)
87+
await seneca.post('biz:ledger,close:account', {
88+
aref: 'o0/Asset/Cash',
89+
bref: 'o0/Q1/20220101',
90+
target_bref: 'o0/Q2/20220401',
91+
})
92+
93+
// Close a book (close all accounts and mark book as closed)
94+
await seneca.post('biz:ledger,close:book', {
95+
bref: 'o0/Q1/20220101',
96+
target_bref: 'o0/Q2/20220401',
97+
})
98+
99+
// Export account to CSV
100+
await seneca.post('biz:ledger,export:account,format:csv', {
101+
aref: 'o0/Asset/Cash',
102+
bref: 'o0/Q1/20220101',
103+
})
104+
105+
// Export book to CSV (all accounts summary)
106+
await seneca.post('biz:ledger,export:book,format:csv', {
107+
bref: 'o0/Q1/20220101',
108+
})
109+
```
110+
23111
<!--START:options-->
24112

25113
## Options

0 commit comments

Comments
 (0)