I wrote something along the lines of this for income statements. YMMV
--- I'm definitely not an accountant or any sort of financial
professional.

```
#!/bin/bash

# This script generates an income statement for the given year.
# This is designed to be run by apenwarr's redo.
# To use it standalone, make it executable and give it
# three arguments:
#
# - $1: (doesn't matter)
# - $2: the name of the file minus the extension (should be a year with a 
corresponding .journal file)
# - $3: the name of a temp file which will hold the output
#
# You'll have to make changes to suit your own needs.

name="Your name here"

year=$(basename $2)

redo-ifchange $year.journal

# Change these commands to suit your needs ########################

cmd="ledger -f $year.journal -HX $ -p $year bal"
income=$($cmd ^Income --account "tag('country')" --invert)
expenses=$($cmd ^Expenses)
total=$($cmd ^Income ^Expenses --invert | tail -n 2 | sed -e '1s/-/=/g' -e 
'2s/$/  Net Income/')


# Go to the end of the year if year is past
if test "$(date +%Y)" -le "$year"; then
    todate=$(date +%D)
else
    todate=$(date -d $year-12-31 +%D)
fi

intro="This document is the income statement for $name for the calendar
year of $year to $todate. Amounts in CNY have been converted to USD at their
historical prices according to the time of transaction."

printf "Income statement for %d to %s\n" $year $todate  >> $3
( printf "%39s\n" | tr " "  = )                         >> $3
printf "\n%s\n" "$intro" "$income" "$expenses" "$total" >> $3

unix2dos $3
mv $3 $(dirname $3)/$(basename $3 .tmp)
```

For example, with the following journal file:

```
; 2022.journal
2022-01-01 Employer
        Assets:Bank           $2,000.00
        Income:Employer      $-2,000.00
2022-01-02 Paycheck Party!
        Expenses:Beer           $200.00
        Expenses:Food           $100.00
        Assets:Bank            $-300.00
2022-01-03 Savings
        Assets:Savings        $1,000.00
        Assets:Bank          $-1,000.00
```

Running `./incomestmt.sh '' 2022 2022.income.txt.tmp`, I get the following:

```
Income statement for 2022 to 02/20/22
=======================================

This document is the income statement for Your name here for the calendar
year of 2022 to 02/20/22. Amounts in CNY have been converted to USD at their
historical prices according to the time of transaction.

           $2,000.00  Income:Employer

             $300.00  Expenses
             $200.00    Beer
             $100.00    Food
--------------------
             $300.00

====================
           $1,700.00  Net Income
```

Hope this helps someone!
On Saturday, February 5, 2022 at 12:10:56 PM UTC+8 [email protected] 
wrote:

> Just a followup for posterity, in case someone else manages to google-fu 
> their way to this post.
>
> Besides Stanko's solution above which is quite configurable and might meet 
> your needs better, I ended up using ledger-pyreport for the task (a small 
> python flask app which pumps out 3 of the 4 management summaries - does not 
> have a Retained earnings report for corp filings.). The author was super 
> responsive when I could not get it going and pointed me quickly to the 
> problem. The reports also look great. 
>
> https://yingtongli.me/blog/2020/03/31/ledger-pyreport.html
>
> Three caveats that tripped me up getting it going - as it can be affected 
> by the way you've recorded your ledger file: 
>
>    1. You need to have your Assets and Liabilities structured so accounts 
>    have a Current and Non-current "subcategory" ie. Assets:Current:SG Bank 
>    Account. So, had to find/replace some category names in the journal file 
> to 
>    get pyreport to work (but irrelevant to me really and makes obvious sense 
>    when you think about it if you need management summaries. Serves me right 
>    for not paying more attention in Biz 257.).
>    2. It expects a foreign currency conversion for each and every 
>    transaction not in the main report currency (for me SGD).  So,  5000 EUR @ 
>    1.6789 SGD or similar so it can get reports out properly.
>    3. remove --pedantic from the example config file so that it is not 
>    expecting all accounts to be predeclared before you actually use them. 
>    
> Other than that, worked smoothly and quite happy with it. Recommend it. 
> Good luck and happy Year of the Tiger! 🐯
>
> ciao !
> Daryl.
> PS> Thanks to everyone that also responded directly to me on the post. 
>
> google juice signposting:
> ledger
> ledger-pyreport error
> TypeError('Cannot compare Amount with non-zero number')
> Error: Unknown account
>
> On Wednesday, February 2, 2022 at 7:27:52 PM UTC+8 Daryl Manning wrote:
>
>> *TLDR*
>>
>> I need some reasonably nicely formatted management summaries (balance, 
>> income, cashflow, retained) to hand to my lawyers for small business 
>> filing. What are people using for pdfs or indelible reports to interoperate 
>> with lawyers/accountants? 
>>
>> *Longer Story*
>> I've been using ledger for some time now and took the plunge during covid 
>> to use it to run my small-ish business. For personal use have been using a 
>> combination of it and reckon to automate entry. It's been great so far: 
>> https://daryl.wakatara.com/tracking-your-finances-with-reckon-and-ledger
>>
>> I'm in the position now of having to file for 2020 and 2021 and need to 
>> get some reasonably decent looking reports out of it (or export the text 
>> and then format it) to hand to the lawyers for the government filings here. 
>>
>> What are people using to do this? What core snippets/resources are 
>> available? My google-fu failed me searching for blog posts or code 
>> resources on this one (I'm aware of ledger-pyreports though am having it 
>> throw an error despite my ledger file being fine from ledger's perspective. 
>> Have pinged author for a pointer... but what else is there and what are 
>> people who aree needing to do this actually doing?).
>>
>> thanks! (and happy year of the tiger everyone!)
>> Daryl. 
>>
>>
>>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"Ledger" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ledger-cli/2c7f50b4-9579-4a80-919c-e55c9d45e553n%40googlegroups.com.

Attachment: 2022.journal
Description: Binary data

Attachment: incomestmt.sh
Description: application/shellscript

Income statement for 2022 to 02/20/22
=======================================

This document is the income statement for Your name here for the calendar
year of 2022 to 02/20/22. Amounts in CNY have been converted to USD at their
historical prices according to the time of transaction.

           $2,000.00  Income:Employer

             $300.00  Expenses
             $200.00    Beer
             $100.00    Food
--------------------
             $300.00

====================
           $1,700.00  Net Income

Reply via email to