pig-monkey.com - plaintextaccountinghttps://pig-monkey.com/2020-08-12T20:30:26-07:00Tracking My Phone Bill with Ledger2020-08-12T00:00:00-07:002020-08-12T20:30:26-07:00Pig Monkeytag:pig-monkey.com,2020-08-12:/2020/08/phone-ledger/<p>Back in 2013 I bought my first smartphone and signed up for a T-Mobile prepaid plan, referred to at the time as the <a href="https://blog.bn.ee/posts/ice-cream-sandwich-for-30month">&ldquo;Walmart Plan&rdquo;</a>. The plan cost $30 per month, was intended for new customers only, and was supposed to only be available to those who purchased the SIM …</p><p>Back in 2013 I bought my first smartphone and signed up for a T-Mobile prepaid plan, referred to at the time as the <a href="https://blog.bn.ee/posts/ice-cream-sandwich-for-30month">&ldquo;Walmart Plan&rdquo;</a>. The plan cost $30 per month, was intended for new customers only, and was supposed to only be available to those who purchased the SIM card at a Walmart. It offered a small amount of voice minutes and a large amount of data, which struck me as what one would want with one of these newfangled computer-phones. I bought a SIM card, figured out how to get T-Mobile to sign me up on the plan despite not stepping foot into a Walmart, and haven&rsquo;t looked back since.</p> <p>One of the things that appeals to me about the setup is the level of separation it gives me from the service provider. I purchased the phone from the manufacturer and the SIM card I bought with cash. I fund the plan by purchasing refill cards from third-party vendors. I have never provided T-Mobile with any financial information. They have no ability to take any money from me, except what I give them when trading in the refill cards. Obviously, the primary business of any mobile communications provider is location tracking, so I can&rsquo;t refer to my relationship with them as &ldquo;privacy preserving&rdquo;, but I like to think it does allow me to retain some level of agency that is lost in a more traditional relationship.</p> <p>If there is a downside to this setup, it is that it can be difficult to understand what I actually pay per month. The plan costs $30. There is some limit to the number of SMS messages, but I have no idea what it is. Data is &ldquo;unlimited&rdquo;, which means throttled over 4GB, but I don&rsquo;t think I&rsquo;ve ever approached even half that limit. Minutes are limited, and if I go over the allotment I&rsquo;m charged a higher rate, but the service continues as long as the balance of the account remains positive.</p> <p>I always want to keep more than $30 in the account, in case I do go over the allotted minutes. So I buy $50 refill cards. They have $50 of value, and are supposed to cost me $50. But the vendor I tend to by them from charges a $1 service fee, offers a points program that sometimes results in a discount being applied, and frequently has sales that offer a couple dollars off. So I end up paying something like $48-51. If I do exceed the limits of the plan, I may end up buying a $50 card one month and the next. More often, I buy a $50 card one month and have enough left over in the account that I do not need to refill it the following month. My plan renews on the 5th of the month, so some months I may end up spending $100 by buying one refill card on the first day of the month and another on the last in anticipation of the following month&rsquo;s renewal.</p> <p>All of that is to say that it is difficult to have an intuitive feel for what my average monthly phone expense is, but it&rsquo;s important that I can get that number so that I can determine if the plan is still working or if I should look for a better offer. Fortunately, this is a thing that <a href="https://www.ledger-cli.org/">Ledger</a> makes extremely simple.</p> <p>Whenever I purchase a refill card, I log the transaction in the <code>Expenses:Utilities:Phone</code> account. With that done, I can ask Ledger to report on all transactions in that account, grouped by month, with a running average in the final column.</p> <div class="highlight"><pre><span></span><code>$ ledger register utilities:phone --monthly --average --begin <span class="m">2019</span>-08 <span class="m">2019</span>-09-01 - <span class="m">2019</span>-09-30 Expenses:Utilities:Phone <span class="nv">$48</span>.50 <span class="nv">$48</span>.50 <span class="m">2019</span>-10-01 - <span class="m">2019</span>-10-31 &lt;None&gt; <span class="m">0</span> <span class="nv">$24</span>.25 <span class="m">2019</span>-11-01 - <span class="m">2019</span>-11-30 Expenses:Utilities:Phone <span class="nv">$46</span>.50 <span class="nv">$31</span>.67 <span class="m">2019</span>-12-01 - <span class="m">2019</span>-12-31 &lt;None&gt; <span class="m">0</span> <span class="nv">$23</span>.75 <span class="m">2020</span>-01-01 - <span class="m">2020</span>-01-31 Expenses:Utilities:Phone <span class="nv">$51</span>.00 <span class="nv">$29</span>.20 <span class="m">2020</span>-02-01 - <span class="m">2020</span>-02-29 &lt;None&gt; <span class="m">0</span> <span class="nv">$24</span>.33 <span class="m">2020</span>-03-01 - <span class="m">2020</span>-03-31 Expenses:Utilities:Phone <span class="nv">$48</span>.50 <span class="nv">$27</span>.79 <span class="m">2020</span>-04-01 - <span class="m">2020</span>-04-30 &lt;None&gt; <span class="m">0</span> <span class="nv">$24</span>.31 <span class="m">2020</span>-05-01 - <span class="m">2020</span>-05-31 Expenses:Utilities:Phone <span class="nv">$48</span>.50 <span class="nv">$27</span>.00 <span class="m">2020</span>-06-01 - <span class="m">2020</span>-06-30 Expenses:Utilities:Phone <span class="nv">$46</span>.50 <span class="nv">$28</span>.95 <span class="m">2020</span>-07-01 - <span class="m">2020</span>-07-31 &lt;None&gt; <span class="m">0</span> <span class="nv">$26</span>.32 <span class="m">2020</span>-08-01 - <span class="m">2020</span>-08-31 Expenses:Utilities:Phone <span class="nv">$51</span>.00 <span class="nv">$28</span>.38 </code></pre></div> <p>Over the past 12 months, I have spent an average of $28.38 per month on phone service. I&rsquo;m ok with that.</p>Adding Metadata to Ledger2020-08-07T00:00:00-07:002020-08-07T20:00:00-07:00Pig Monkeytag:pig-monkey.com,2020-08-07:/2020/08/metadata-ledger/<p>As <a href="/2020/08/reconciling-ledger/">mentioned previously</a>, two of the primary reasons I use <a href="https://www.ledger-cli.org/">Ledger</a> are the intimate awareness it provides of how money is moving, and its timely representation of current balances. The third primary reason I use the tool is for the activity history it provides.</p> <p>Recording almost every transaction I make …</p><p>As <a href="/2020/08/reconciling-ledger/">mentioned previously</a>, two of the primary reasons I use <a href="https://www.ledger-cli.org/">Ledger</a> are the intimate awareness it provides of how money is moving, and its timely representation of current balances. The third primary reason I use the tool is for the activity history it provides.</p> <p>Recording almost every transaction I make (excepting only some <a href="/2020/08/ledger-cash/">small petty cash</a>) allows me to look at years past and build an accurate picture of what I was doing. Most activities leave some sort of financial record, even if the transaction is only tangential to the activity itself. This is the sort of information that I would be extremely uncomfortable providing to a <a href="https://www.intuit.com/">third-party</a>, but is quite useful to have myself.</p> <p><a href="/2020/08/receipts-ledger/">Storing receipts</a> provides an additional layer of detail to the history created in the Ledger journal. As an intermediate between the full receipt and the basic journal entry, I find it is extremely valuable to use <a href="https://www.ledger-cli.org/3.0/doc/ledger3.html#Commenting-on-your-Journal">comments</a> and <a href="https://www.ledger-cli.org/3.0/doc/ledger3.html#Metadata-tags">tags</a> within the journal. Almost every transaction in my Ledger journal that is not for food has a comment describing what goods or service was purchased.</p> <p>In Ledger, comments begin with a semicolon. I store them below the first line of the transaction. When placed here, Ledger refers to these comments as <a href="https://www.ledger-cli.org/3.0/doc/ledger3.html#Transaction-notes">notes</a>. When purchasing goods, I add one comment &ndash; or note &ndash; for each unique item on the transaction. For instance, I might buy socks:</p> <div class="highlight"><pre><span></span><code><span class="mf">2018</span><span class="o">-</span><span class="mf">07</span><span class="o">-</span><span class="mf">02</span><span class="o">=</span><span class="mf">2018</span><span class="o">-</span><span class="mf">07</span><span class="o">-</span><span class="mf">01</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">Socks</span><span class="w"> </span><span class="n">Addict</span><span class="w"></span> <span class="w"> </span><span class="p">;</span><span class="w"> </span><span class="n">Darn</span><span class="w"> </span><span class="kr">To</span><span class="n">ugh</span><span class="w"> </span><span class="n">Light</span><span class="w"> </span><span class="n">Cushion</span><span class="w"> </span><span class="n">No</span><span class="w"> </span><span class="n">Show</span><span class="w"> </span><span class="nb">Tab</span><span class="p">,</span><span class="w"> </span><span class="n">Black</span><span class="o">/</span><span class="n">Grey</span><span class="p">,</span><span class="w"> </span><span class="n">Large</span><span class="p">,</span><span class="w"> </span><span class="mf">2</span><span class="n">x</span><span class="w"></span> <span class="w"> </span><span class="nb">Exp</span><span class="n">enses</span><span class="p">:</span><span class="n">Clothing</span><span class="p">:</span><span class="n">Footwear</span><span class="w"> </span><span class="err">$</span><span class="mf">33.40</span><span class="w"></span> <span class="w"> </span><span class="n">Liabilities</span><span class="p">:</span><span class="n">Bank</span><span class="p">:</span><span class="n">Visa</span><span class="w"></span> </code></pre></div> <p>The comment tells me exactly what was purchased. More importantly, it tells me the model name, the color, and the size of the item. If I want to purchase another pair of identical socks, I can do so easily. This seems like a minor thing, but when it is applied to everything I buy, it is hard to overstate how greatly this ability has improved my quality of life over the past decade.</p> <p>In Ledger, comments are searchable. Say I want to list every transaction where I purchased a pair of Darn Tough socks. I buy them from different retailers, so I can&rsquo;t filter by the payee. All the transactions are in the <code>Expenses:Clothing:Footwear</code> category, but that category includes socks from other manufacturers and well as other things that go on my feet, so I can&rsquo;t filter by that. But I can query all transactions with a note which includes the string &ldquo;darn tough&rdquo;.</p> <div class="highlight"><pre><span></span><code>$ ledger register note darn tough </code></pre></div> <p>A tag is a special kind of comment. Tags are useful if you have the foresight to realize that a particular transaction should be grouped with other transactions, but that transactions within the group will likely have different payees or accounts. Tags start and end with a <code>:</code>. Multiple tags can be chained together.</p> <p>I use tags for vacations. Expenses related to any vacation are tagged with two tags: a generic <code>:vacation:</code> tag, and a tag specific to the vacation. This allows me to easily see what I spend on vacations in general, or any one vacation specifically. For example, in 2018 I took a 24-hour trip to Las Vegas <a href="/2018/12/reflecting-chrome/">to see Nine Inch Nails</a>. That trip included numerous transactions in unrelated accounts: concert tickets, airline tickets, accommodations, ground transport, food, etc. All transactions were tagged with <code>:vacation:</code> and <code>:nin-vegas-2018:</code>. As an example, here is the transaction for purchasing the concert tickets:</p> <div class="highlight"><pre><span></span><code><span class="mf">2018</span><span class="o">-</span><span class="mf">03</span><span class="o">-</span><span class="mf">30</span><span class="o">=</span><span class="mf">2018</span><span class="o">-</span><span class="mf">03</span><span class="o">-</span><span class="mf">28</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">AXS</span><span class="w"></span> <span class="w"> </span><span class="p">;</span><span class="w"> </span><span class="n">Nine</span><span class="w"> </span><span class="n">Inch</span><span class="w"> </span><span class="n">Nails</span><span class="w"> </span><span class="n">at</span><span class="w"> </span><span class="n">The</span><span class="w"> </span><span class="n">Joint</span><span class="p">,</span><span class="w"> </span><span class="n">Las</span><span class="w"> </span><span class="n">Vegas</span><span class="w"></span> <span class="w"> </span><span class="p">;</span><span class="w"> </span><span class="p">:</span><span class="n">nin</span><span class="o">-</span><span class="n">vegas</span><span class="o">-</span><span class="mf">2018</span><span class="p">:</span><span class="n">vacation</span><span class="p">:</span><span class="w"></span> <span class="w"> </span><span class="nb">Exp</span><span class="n">enses</span><span class="p">:</span><span class="n">Entertainment</span><span class="p">:</span><span class="n">Performance</span><span class="w"> </span><span class="err">$</span><span class="mf">95.50</span><span class="w"></span> <span class="w"> </span><span class="n">Assets</span><span class="p">:</span><span class="n">Bank</span><span class="p">:</span><span class="n">Checking</span><span class="w"></span> </code></pre></div> <p>Ledger makes it easy to see all the expenses associated with that trip, both in total and broken out into different expense accounts.</p> <div class="highlight"><pre><span></span><code>$ ledger balance expense and %nin-vegas-2018 </code></pre></div> <p>I also use tags to indicate transactions that occur via the same merchant system but have different payees. Specifically, things I buy on Etsy are tagged <code>:esty:</code> and things I buy on eBay are tagged <code>:ebay:</code>. Without these tags I would have no way to list all the Etsy purchases I have made, since I send the money to individual sellers and not Etsy itself.</p> <p>I also use tags to indicate transactions related to keeping my apartment. Rent goes to the <code>Expenses:Rent</code> account. Electricity charges go to <code>Expenses:Utilities:Electric</code>. Gas charges go to <code>Expenses:Utilities:Gas</code>. My cell phone payment goes to <code>Expenses:Utilities:Phone</code>. The first three charges I consider apartment expenses. My cell phone is not. By tagging the first three with <code>:apt:</code> I can easily see the total monthly cost of keeping my apartment, without a bunch of complicated querying to exclude things like the cell phone bill.</p> <p>My final use for tags is indicating transactions that I think should be deducted from my taxes. Some people do this with accounts, but I find that with the account structure that makes sense to me I often end up with a mix of deductible and non-deductible transactions within a single account. Tagging deductible transactions with <code>:deduct:</code> makes it easy to dump a list of all transactions that should be considered when completing yearly taxes.</p>Reconciling Ledger2020-08-06T00:00:00-07:002020-08-06T20:01:18-07:00Pig Monkeytag:pig-monkey.com,2020-08-06:/2020/08/reconciling-ledger/<p>For me, one of the primary appeals of using <a href="https://www.ledger-cli.org/">Ledger</a> &ndash; or really any accounting system &ndash; is that it let&rsquo;s me know how much money I have (or don&rsquo;t have) <em>right now</em>. Other people&rsquo;s records lag behind reality.</p> <p>If I submit an order for a $50 widget on …</p><p>For me, one of the primary appeals of using <a href="https://www.ledger-cli.org/">Ledger</a> &ndash; or really any accounting system &ndash; is that it let&rsquo;s me know how much money I have (or don&rsquo;t have) <em>right now</em>. Other people&rsquo;s records lag behind reality.</p> <p>If I submit an order for a $50 widget on a website today, I consider that $50 gone, even though the vendor likely didn&rsquo;t collect the money immediately. They probably placed a hold on the funds, but will not actually capture the money until they ship the order, which may take a couple days. When they do capture the funds, it may still be another day or two until that action posts to my online bank statement. Were I dependent on the bank, I could go a week thinking that I have $50 more than I actually have.</p> <p>It is important to me that I log transactions without waiting for them to appear elsewhere, but at some point I do want to reconcile my records against what my bank believes. I accomplish this with <a href="https://www.ledger-cli.org/3.0/doc/ledger3.html#Auxiliary-dates">auxiliary dates</a>.</p> <p>Were I to submit that order for a $50 widget today, I would create the entry using today&rsquo;s date. Even if it takes me a few days to actually record the entry, I will still use the date the order was submitted.</p> <div class="highlight"><pre><span></span><code><span class="mf">2020</span><span class="o">-</span><span class="mf">08</span><span class="o">-</span><span class="mf">06</span><span class="w"> </span><span class="n">Acme</span><span class="p">,</span><span class="w"> </span><span class="n">Inc</span><span class="w"></span> <span class="w"> </span><span class="nb">Exp</span><span class="n">enses</span><span class="p">:</span><span class="n">Misc</span><span class="w"> </span><span class="err">$</span><span class="mf">50.00</span><span class="w"></span> <span class="w"> </span><span class="n">Assets</span><span class="p">:</span><span class="n">Bank</span><span class="p">:</span><span class="n">Checking</span><span class="w"></span> </code></pre></div> <p>Periodically, I will manually reconcile every transaction in my journal against my bank&rsquo;s online statements. Usually this happens every other week or so. Many people will simply dump a CSV from their bank and <a href="https://github.com/ledger/ledger/wiki/CSV-Import">use a script to parse and import the results into their journal</a>. I prefer to do it manually. This rarely takes more than 30 minutes, and for me it is one of the other primary appeals of using Ledger: it forces me to be intimately aware of how money is flowing in my life, and makes it extremely easy to spot problems or errors. It is difficult to accomplish that reliably without manually touching every transaction.</p> <p>So a week or two later I&rsquo;ll login to the bank and make sure there is a $50 payment to Acme, Inc. If the date listed by the bank for that transaction is different from what I recorded &ndash; which for online transactions is almost always the case &ndash; I&rsquo;ll prepend that date to my entry.</p> <div class="highlight"><pre><span></span><code><span class="mf">2020</span><span class="o">-</span><span class="mf">08</span><span class="o">-</span><span class="mf">10</span><span class="o">=</span><span class="mf">2020</span><span class="o">-</span><span class="mf">08</span><span class="o">-</span><span class="mf">06</span><span class="w"> </span><span class="n">Acme</span><span class="p">,</span><span class="w"> </span><span class="n">Inc</span><span class="w"></span> <span class="w"> </span><span class="nb">Exp</span><span class="n">enses</span><span class="p">:</span><span class="n">Misc</span><span class="w"> </span><span class="err">$</span><span class="mf">50.00</span><span class="w"></span> <span class="w"> </span><span class="n">Assets</span><span class="p">:</span><span class="n">Bank</span><span class="p">:</span><span class="n">Checking</span><span class="w"></span> </code></pre></div> <p>When there are two dates, Ledger considers the date to the left of the <code>=</code> to be the primary date. The other date is the auxiliary date. Previously, when only one date was listed, it was the equivalent to <code>2020-08-06=2020-08-06</code>. By using the bank&rsquo;s date as the primary date, I know that the default output from a report like <code>ledger register assets:bank:checking</code> will match the bank&rsquo;s statements. If I want to report on what I consider to be the real dates of the transactions, I can pass the <code>--aux-date</code> flag.</p> <p>The journal files themselves I edit manually in vim, with a little help from <a href="https://github.com/ledger/vim-ledger/">vim-ledger</a>. I have <code>&lt;leader&gt;t</code> <a href="https://github.com/pigmonkey/dotfiles/blob/master/vim/ftplugin/ledger.vim#L20">mapped to set today&rsquo;s date as the primary date of the current transaction</a>. Because I usually only reconcile two or three times a month, today&rsquo;s date is often not the date I actually want, but this shortcut allows me to immediately insert a new date in the correct format. I can then quickly change the day number to whatever it should actually be.</p> <p>I consider the transaction to be cleared once the bank statement and the Ledger journal file agree on the date, payee, and dollar amount. In Ledger, transactions are marked as cleared by inserting an <code>*</code> between the date and the payee. In vim I <a href="https://github.com/pigmonkey/dotfiles/blob/master/vim/ftplugin/ledger.vim#L17">map this to <code>&lt;leader&gt;c</code></a>. A complete transaction thus looks like this:</p> <div class="highlight"><pre><span></span><code><span class="mf">2020</span><span class="o">-</span><span class="mf">08</span><span class="o">-</span><span class="mf">10</span><span class="o">=</span><span class="mf">2020</span><span class="o">-</span><span class="mf">08</span><span class="o">-</span><span class="mf">06</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">Acme</span><span class="p">,</span><span class="w"> </span><span class="n">Inc</span><span class="w"></span> <span class="w"> </span><span class="nb">Exp</span><span class="n">enses</span><span class="p">:</span><span class="n">Misc</span><span class="w"> </span><span class="err">$</span><span class="mf">50.00</span><span class="w"></span> <span class="w"> </span><span class="n">Assets</span><span class="p">:</span><span class="n">Bank</span><span class="p">:</span><span class="n">Checking</span><span class="w"></span> </code></pre></div> <p>Ledger defaults to including all transactions in its reporting and calculations. By passing the <code>--cleared</code> flag it will only include transactions that have been marked as cleared. So after I think I&rsquo;m done reconciling all transactions against my bank statement, I will run <code>ledger balance assets:bank:checking --cleared</code> and verify that the resulting balance matches what the bank shows. If I want to know how much money I actually have in that account, I will run <code>ledger balance assets:bank:checking</code>. The output of this will likely include transactions that the bank hasn&rsquo;t caught on to yet.</p> <p>If for some reason Ledger&rsquo;s output of the cleared balance does not agree with the bank, my first step will be to make sure that all transactions are sorted by their primary date. If I already have the file open in vim, I have <a href="https://github.com/pigmonkey/dotfiles/blob/master/vim/ftplugin/ledger.vim#L28">a shortcut for that</a>. Otherwise I keep a one-liner script called <code>ledger-sort</code> that takes the name of a ledger file as input, sorts it, and shows me the diff.</p> <div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span> <span class="normal">2</span> <span class="normal">3</span></pre></div></td><td class="code"><div><pre><span></span><code><span class="ch">#!/bin/sh</span> ledger -f <span class="nv">$1</span> print --sort d &gt; <span class="nv">$1</span>.sort <span class="o">&amp;&amp;</span> mv <span class="nv">$1</span><span class="o">{</span>.sort,<span class="o">}</span> <span class="o">&amp;&amp;</span> git diff </code></pre></div></td></tr></table></div> <p>Checking the diff of the sorted output before continuing is important. Sometimes I&rsquo;ll make a silly mistake like typing the wrong year when entering the transaction. This sort of mistake is obvious when looking at the diff.</p> <p>Once the file is sorted, I&rsquo;ll run <code>ledger register assets:bank:checking --cleared</code>. The final column in this output is a running total of the account balance. The only difference between the output and my bank statement should be the ordering of transactions within a day, which I do not care about.</p> <p>I&rsquo;ll know that I last cleared my journal around a certain date, and that the account balance was accurate as of that date.<sup class="footnote-ref" id="fnref:assert"><a rel="footnote" href="#fn:assert" title="see footnote">1</a></sup> If I was doing this on 2020-08-06, I might say to myself &ldquo;I know I cleared Ledger sometime in mid-July, so let&rsquo;s look at my account balance at end of day on 2020-07-15&rdquo;. If the bank and Ledger both agree on the balance at the end of day on that date (regardless of the ordering of the multiple transactions that may have occurred on the day), I&rsquo;ll know that the error is somewhere between 2020-07-16 and 2020-08-06. Next I&rsquo;ll jump to another random day in that period &ndash; maybe 2020-07-22 &ndash; and perform the same exercise. This is repeated until I find the first day where the two systems disagree on the ending balance. Then I look at every transaction on that day and find the error. Usually it will be a simple data entry error, such as me typing <code>$12.10</code> instead of <code>$12.01</code>. Having <a href="/2020/08/receipts-ledger/">my receipts stored</a> allows me to verify that I did indeed agree to pay <code>$12.10</code> and that the error is mine rather than the payee&rsquo;s. This whole process of finding errors rarely requires more than two minutes, and occurs maybe once every three months.</p> <p>Though I don&rsquo;t use CSV exports from my banks for anything, I do like to periodically download and archive them. When I generate the exports I ask for one file per month. I refer to these as &ldquo;bank dumps&rdquo; and store them in directory named <code>dump</code>. Each file is named for the account and month it represents. For example, an account named <code>Assets:Bank:Savings</code> will have last month&rsquo;s dump stored at <code>dump/assets-bank-savings-202007.csv</code>. I pretty much never open these files, but I like having them archived. They allow me to see how much money a bank thought I had at any point in time, even if the account is no longer open, and provide assurance that I can always true my records if I somehow mess them up.</p> <div id="footnotes"> <h2>Notes</h2> <ol> <li id="fn:assert"><a rev="footnote" href="#fnref:assert" class="footnote-return" title="return to article">&crarr;</a> Ledger has the ability to <a href="https://www.ledger-cli.org/3.0/doc/ledger3.html#Balance-assertions">record assertions</a>. I have never used this feature, but I probably should.</li> </ol> </div>Receipts and Ledger2020-08-05T00:00:00-07:002020-08-05T21:50:13-07:00Pig Monkeytag:pig-monkey.com,2020-08-05:/2020/08/receipts-ledger/<p>As <a href="/2020/08/organizing-ledger/">previously mentioned</a>, I store receipts in the same repository as my <a href="https://www.ledger-cli.org/">Ledger</a> data files.</p> <p>Purchasing something online automatically generates a receipt; it&rsquo;s just a simple matter of saving the confirmation web page or email as a PDF and moving it into the proper directory with the proper filename …</p><p>As <a href="/2020/08/organizing-ledger/">previously mentioned</a>, I store receipts in the same repository as my <a href="https://www.ledger-cli.org/">Ledger</a> data files.</p> <p>Purchasing something online automatically generates a receipt; it&rsquo;s just a simple matter of saving the confirmation web page or email as a PDF and moving it into the proper directory with the proper filename. That&rsquo;s a low enough bar that I cannot justify not storing them. I have a receipt for every digital transaction I have made since I began using Ledger in 2012.</p> <p>I&rsquo;m less strict about storing receipts for transactions that occur in meatspace. These transactions usually result in a paper receipt (which may not be initially even be offered), which then requires scanning or photographing. That is just enough effort that I don&rsquo;t always want to do it. I&rsquo;ll store the receipt for a meatspace transaction if the amount is greater than $100, or if I think it might be tax deductible, or if I think I might make a warranty claim. But if the transaction is a $10 sandwich for lunch, I probably won&rsquo;t bother storing the receipt.</p> <p>My naming scheme for the receipt files consists of the date of the transaction, the amount, and the payee. This is enough information to go from a Ledger journal entry to a receipt, or from a receipt to a Ledger journal entry. For example, consider a transaction with a journal entry like this:</p> <div class="highlight"><pre><span></span><code><span class="mf">2020</span><span class="o">-</span><span class="mf">07</span><span class="o">-</span><span class="mf">14</span><span class="w"> </span><span class="n">Acme</span><span class="w"> </span><span class="n">Widgets</span><span class="w"></span> <span class="w"> </span><span class="nb">Exp</span><span class="n">enses</span><span class="p">:</span><span class="n">Bicycle</span><span class="p">:</span><span class="n">Parts</span><span class="w"> </span><span class="err">$</span><span class="mf">23.72</span><span class="w"></span> <span class="w"> </span><span class="n">Assets</span><span class="p">:</span><span class="n">PayPal</span><span class="w"></span> </code></pre></div> <p>The receipt for that transaction will be at <code>receipts/20200714_23.72-acme_widgets.pdf</code>.</p> <p>When I first began using Ledger and came up with this file naming scheme, I figured I would write some sort of script that would parse the components of a journal entry and generate the expected receipt filename so that I could quickly jump from one to the other. What I found is that the scheme is simple enough to make such a script unnecessary. When I look at a journal entry I intuitively know what the receipt filename is, and when I look at a receipt filename I intuitively know what the journal entry is. Writing a simple script to generate one from the other would take more energy than I have collectively spent over the past eight years solving the problem manually. So I never wrote it.</p> <p>I also store invoices in the same repository, in a directory creatively named <code>invoices</code>. These are invoices that vendors send me &ndash; primarily things like rent statements and utility bills &ndash; not invoices that I send to people. The naming scheme is the same as what I use for receipts, except in this case the date in the filename is the date the vendor included on the invoice rather than the date I received it or paid it. I chose this because if I ever need to dispute a charge or a payment, this date is an easy way for both the vendor and I to quickly verify that we are discussing the same thing. Each invoice will of course have an associated receipt in the <code>receipts</code> directory after I pay it, and the date on this file will be the date on which I submitted the payment.</p> <p>Every now and then I need to write someone an old-fashioned paper check. These get scanned and stored in a <code>checks</code> directory. The file naming scheme for these is similar to that of receipts, except that in addition to the date, amount and payee, I also include the check number. Ledger supports <a href="https://www.ledger-cli.org/3.0/doc/ledger3.html#Codes">including the check number in the journal entry</a>, so including it in the filename provides another way to link the two things. For example, back in 2015 I renewed my passport book and bought a passport card:</p> <div class="highlight"><pre><span></span><code><span class="mf">2015</span><span class="o">-</span><span class="mf">11</span><span class="o">-</span><span class="mf">09</span><span class="o">=</span><span class="mf">2015</span><span class="o">-</span><span class="mf">10</span><span class="o">-</span><span class="mf">31</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="p">(</span><span class="err">#</span><span class="mf">1047</span><span class="p">)</span><span class="w"> </span><span class="n">US</span><span class="w"> </span><span class="n">Department</span><span class="w"> </span><span class="n">of</span><span class="w"> </span><span class="n">State</span><span class="w"></span> <span class="w"> </span><span class="p">;</span><span class="w"> </span><span class="n">Passport</span><span class="w"> </span><span class="n">Book</span><span class="w"> </span><span class="n">Renewal</span><span class="w"></span> <span class="w"> </span><span class="p">;</span><span class="w"> </span><span class="n">Passport</span><span class="w"> </span><span class="n">Card</span><span class="w"> </span><span class="n">Purchase</span><span class="w"></span> <span class="w"> </span><span class="nb">Exp</span><span class="n">enses</span><span class="p">:</span><span class="n">Travel</span><span class="p">:</span><span class="n">Documentation</span><span class="w"> </span><span class="err">$</span><span class="mf">140.00</span><span class="w"></span> <span class="w"> </span><span class="n">Assets</span><span class="p">:</span><span class="n">Bank</span><span class="p">:</span><span class="n">Checking</span><span class="w"></span> </code></pre></div> <p>The scan of the check from that transaction lives at <code>checks/20151031_140.00-1047-us_department_of_state.pdf</code>.</p>Tracking Cash with Ledger2020-08-04T00:00:00-07:002020-08-04T19:13:56-07:00Pig Monkeytag:pig-monkey.com,2020-08-04:/2020/08/ledger-cash/<p>In a double-entry accounting system like <a href="https://www.ledger-cli.org/">Ledger</a>, money always moves from one account to another. Money cannot be magicked in or out of existence.</p> <p>Previously <a href="/2020/08/organizing-ledger/#fn:cash">I mentioned that I sometimes do not track cash transactions</a>. If the transaction is less than $20 and is not related to a category of …</p><p>In a double-entry accounting system like <a href="https://www.ledger-cli.org/">Ledger</a>, money always moves from one account to another. Money cannot be magicked in or out of existence.</p> <p>Previously <a href="/2020/08/organizing-ledger/#fn:cash">I mentioned that I sometimes do not track cash transactions</a>. If the transaction is less than $20 and is not related to a category of expense I care about, I may not bother with it. At first glance, this may seem like it conflicts with the inability to magically disappear money. If I take cash out of my checking account, I have to represent that withdrawal or else the balance of the account will be screwy and I&rsquo;ll never be able to reconcile it against the bank&rsquo;s statement. Transforming money from electrons in a bank account to Federal Reserve Notes in my pocket has no impact on its value, so one&rsquo;s initial thought may to represent the cash as an asset account.</p> <div class="highlight"><pre><span></span><code><span class="mf">2020</span><span class="o">-</span><span class="mf">07</span><span class="o">-</span><span class="mf">13</span><span class="w"> </span><span class="n">ATM</span><span class="w"></span> <span class="w"> </span><span class="n">Assets</span><span class="p">:</span><span class="n">Cash</span><span class="w"> </span><span class="err">$</span><span class="mf">40.00</span><span class="w"></span> <span class="w"> </span><span class="n">Assets</span><span class="p">:</span><span class="n">Bank</span><span class="p">:</span><span class="n">Checking</span><span class="w"></span> </code></pre></div> <p>This would be technically correct, and the best way to do things if every last penny of that cash was going to be tracked. But logging the withdrawal that way will not work if, over some period of time, I spend the $40 cash in a serious of small, untracked transactions. In that case, my <code>Assets:Cash</code> account would show that I have $40 more than reality. When asset accounts are not accurate, the world ends.</p> <p>The solution is to <a href="https://www.ledger-cli.org/3.0/doc/ledger3.html#Dealing-with-Petty-Cash">treat cash as an expense account</a>. The balance of an expense account is less important. It tells you how much money you&rsquo;ve spent on that category of thing, but it doesn&rsquo;t represent money that you hold. Effectively, this is saying that the $40 was spent when it was withdrawn at the ATM. It no longer contributes to assets or net worth.</p> <div class="highlight"><pre><span></span><code><span class="mf">2020</span><span class="o">-</span><span class="mf">07</span><span class="o">-</span><span class="mf">13</span><span class="w"> </span><span class="n">ATM</span><span class="w"></span> <span class="w"> </span><span class="nb">Exp</span><span class="n">enses</span><span class="p">:</span><span class="n">Cash</span><span class="w"> </span><span class="err">$</span><span class="mf">40.00</span><span class="w"></span> <span class="w"> </span><span class="n">Assets</span><span class="p">:</span><span class="n">Bank</span><span class="p">:</span><span class="n">Checking</span><span class="w"></span> </code></pre></div> <p>The transaction would look similar if I asked for cash back while buying groceries.</p> <div class="highlight"><pre><span></span><code><span class="mf">2020</span><span class="o">-</span><span class="mf">03</span><span class="o">-</span><span class="mf">20</span><span class="w"> </span><span class="n">Lucky</span><span class="w"> </span><span class="n">Dragon</span><span class="w"> </span><span class="n">Markets</span><span class="w"></span> <span class="w"> </span><span class="nb">Exp</span><span class="n">enses</span><span class="p">:</span><span class="n">Food</span><span class="p">:</span><span class="n">Groceries</span><span class="w"> </span><span class="err">$</span><span class="mf">58.89</span><span class="w"></span> <span class="w"> </span><span class="nb">Exp</span><span class="n">enses</span><span class="p">:</span><span class="n">Cash</span><span class="w"> </span><span class="err">$</span><span class="mf">40.00</span><span class="w"></span> <span class="w"> </span><span class="n">Assets</span><span class="p">:</span><span class="n">Bank</span><span class="p">:</span><span class="n">Checking</span><span class="w"></span> </code></pre></div> <p>But the trick is that money doesn&rsquo;t have to move between an expense account and an asset account. Money can move between any accounts, including two expense accounts. I am strict about tracking food related expenses, so if I buy a burrito with that cash, I&rsquo;ll want to log it. I can do that like this:</p> <div class="highlight"><pre><span></span><code><span class="mf">2020</span><span class="o">-</span><span class="mf">07</span><span class="o">-</span><span class="mf">18</span><span class="w"> </span><span class="n">A</span><span class="w"> </span><span class="n">Taqueria</span><span class="w"></span> <span class="w"> </span><span class="nb">Exp</span><span class="n">enses</span><span class="p">:</span><span class="n">Food</span><span class="p">:</span><span class="n">Dining</span><span class="p">:</span><span class="n">Lunch</span><span class="w"> </span><span class="err">$</span><span class="mf">8.23</span><span class="w"></span> <span class="w"> </span><span class="nb">Exp</span><span class="n">enses</span><span class="p">:</span><span class="n">Cash</span><span class="w"></span> </code></pre></div> <p>If part of your savings are in cash &ndash; in a safe deposit box, stuffed in your mattress, buried in the hills, whatever &ndash; you would want to treat it as an asset so that you can track the balance.</p> <div class="highlight"><pre><span></span><code><span class="mf">2020</span><span class="o">-</span><span class="mf">08</span><span class="o">-</span><span class="mf">30</span><span class="w"> </span><span class="n">ATM</span><span class="w"></span> <span class="w"> </span><span class="n">Assets</span><span class="p">:</span><span class="n">Mattress</span><span class="w"> </span><span class="err">$</span><span class="mf">100.00</span><span class="w"></span> <span class="w"> </span><span class="n">Assets</span><span class="p">:</span><span class="n">Bank</span><span class="p">:</span><span class="n">Checking</span><span class="w"></span> </code></pre></div> <p>To illustrate the degree to which I do track cash: Ledger currently reports the balance of <code>Expenses:Cash</code> to be $3797.29. I&rsquo;ve certainly dealt with significantly more cash than that since 2012. The balance of that account is simply the amount of cash I have acquired but failed to log as spent.</p>Organizing Ledger2020-08-03T00:00:00-07:002020-08-05T15:17:03-07:00Pig Monkeytag:pig-monkey.com,2020-08-03:/2020/08/organizing-ledger/<p><a href="https://www.ledger-cli.org/">Ledger</a> is a <a href="https://en.wikipedia.org/wiki/Double-entry_bookkeeping">double-entry accounting system</a> that stores data in plain text. I began using it in 2012. Almost every dollar that has passed through my world since then is tracked by Ledger.<sup class="footnote-ref" id="fnref:cash"><a rel="footnote" href="#fn:cash" title="see footnote">1</a></sup></p> <p>Ledger is not the only <a href="https://plaintextaccounting.org/">plain text accounting system</a> out there. It has inspired others, such …</p><p><a href="https://www.ledger-cli.org/">Ledger</a> is a <a href="https://en.wikipedia.org/wiki/Double-entry_bookkeeping">double-entry accounting system</a> that stores data in plain text. I began using it in 2012. Almost every dollar that has passed through my world since then is tracked by Ledger.<sup class="footnote-ref" id="fnref:cash"><a rel="footnote" href="#fn:cash" title="see footnote">1</a></sup></p> <p>Ledger is not the only <a href="https://plaintextaccounting.org/">plain text accounting system</a> out there. It has inspired others, such as <a href="https://hledger.org/">hledger</a> and <a href="http://furius.ca/beancount/">beancount</a>. I began with Ledger for lack of a compelling argument in favor of the alternatives. After close to a decade of use, my only regret is that I didn&rsquo;t start using earlier.</p> <p>My Ledger repository is stored at <code>~/library/ledger</code>. This repository contains a <code>data</code> directory, which includes yearly Ledger journal files such as <code>data/2019.ldg</code> and <code>data/2020.ldg</code>. Ledger files don&rsquo;t necessarily need to be split at all, but I like having one file per year. In January, after I clear the last transaction from the previous year, I know the year is locked and the file never gets touched again (unless I go back in to rejigger my account structure).</p> <p>The root of the directory has a <code>.ledger</code> file which includes all of these data files, plus a special journal file with periodic transactions that I sometimes use for budgeting. My <code>~/.ledgerrc</code> file tells Ledger to use the <code>.ledger</code> file as the primary journal, which has the effect of including all the yearly files.</p> <div class="highlight"><pre><span></span><code>$ cat ~/.ledgerrc --file ~/library/ledger/.ledger --date-format<span class="o">=</span>%Y-%m-%d $ cat ~/library/ledger/.ledger include data/periodic.ldg include data/2012.ldg include data/2013.ldg include data/2014.ldg include data/2015.ldg include data/2016.ldg include data/2017.ldg include data/2018.ldg include data/2019.ldg include data/2020.ldg </code></pre></div> <p>Ledger&rsquo;s include format does support globbing (ie <code>include data/*.ldg</code>) but the ordering of the transactions can get weird, so I prefer to be explicit.</p> <p>The repository also contains receipts in the <code>receipts</code> directory, invoices in the <code>invoices</code> directory, scans of checks (remember those?) in the <code>checks</code> directory, and CSV dumps from banks in the <code>dump</code> directory.</p> <div class="highlight"><pre><span></span><code>$ tree -d ~/library/ledger /home/pigmonkey/library/ledger ├── checks ├── data ├── dump ├── invoices └── receipts <span class="m">5</span> directories </code></pre></div> <p>The repository is managed using a mix of vanilla git and <a href="https://git-annex.branchable.com/">git-annex</a>.<sup class="footnote-ref" id="fnref:annex"><a rel="footnote" href="#fn:annex" title="see footnote">2</a></sup> It is important to me that the Ledger journal files in the <code>data</code> directory are stored directly in git. I want the ability to diff changes before committing them, and to be able to pull the history of those files. Every other file I want stored in git-annex. I don&rsquo;t care about the history of files like PDF receipts. They never change. In fact, I want to make them read-only so I can&rsquo;t accidentally change them. I want encrypted versions of them distributed to my numerous <a href="/2016/08/rclone/">special remotes</a> for safekeeping, and someday I may even want to drop old receipts or invoices from my local store so that they don&rsquo;t take up disk space until I actually need to read them. That sounds like asking a lot, but git-annex magically solves all the problems with its <a href="https://git-annex.branchable.com/tips/largefiles/"><code>largefiles</code> configuration option</a>.</p> <div class="highlight"><pre><span></span><code>$ cat ~/library/ledger/.gitattributes *.ldg annex.largefiles<span class="o">=</span>nothing </code></pre></div> <p>This tells git-annex that any file ending with <code>*.ldg</code> should not be treated as a &ldquo;large file&rdquo;, which means it should be added directly to git. Any other file should be added to git-annex and <a href="https://git-annex.branchable.com/git-annex-lock/">locked</a>, making it read-only. Having this configured means that I can just blindly <code>git annex add .</code> or <code>git add .</code> within the repository and git-annex will always do the right thing.</p> <p>I don&rsquo;t run the <a href="https://git-annex.branchable.com/assistant/">git-annex assistant</a> in this repository because I don&rsquo;t want any automatic commits. Like a traditional git repository, I only commit changes to Ledger&rsquo;s journal files after reviewing the diffs, and I want those commits to have meaningful messages.</p> <div id="footnotes"> <h2>Notes</h2> <ol> <li id="fn:cash"><a rev="footnote" href="#fnref:cash" class="footnote-return" title="return to article">&crarr;</a> I do not always track miscellaneous cash transactions less than $20. If a thing costs more than that, it is worth tracking, regardless of what it is or how it was purchased. If it costs less than that, and it isn't part of a meaningful expense account, I'll probably let laziness win out. If I buy a $8 sandwich for lunch with cash, it'll get logged, because I care about tracking dining expenses. If I buy a $1 pencil erasure, I probably won't log it, because it isn't part of an account worth considering.</li> <li id="fn:annex"><a rev="footnote" href="#fnref:annex" class="footnote-return" title="return to article">&crarr;</a> I bet you <a href="/tag/annex/">saw that coming</a>.</li> </ol> </div>