|
20 | 20 | $ npm install @seneca/ledger |
21 | 21 | ``` |
22 | 22 |
|
| 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 | + |
23 | 111 | <!--START:options--> |
24 | 112 |
|
25 | 113 | ## Options |
|
0 commit comments