emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Uwe Brauer <oub@mat.ucm.es>
To: Org Mode List <emacs-orgmode@gnu.org>
Subject: (ledger?) The fair Christmas problem: splitting expenses automatically
Date: Wed, 29 Dec 2021 17:09:40 +0100	[thread overview]
Message-ID: <87o84zs88r.fsf@mat.ucm.es> (raw)

[-- Attachment #1: Type: text/plain, Size: 2888 bytes --]



Hi 

I am not sure whether this is the right place to ask this, but anyhow.


Suppose two friends want to buy Christmas presents, but when they have
finished, they want to have spent the same amount of money. If they
don't a compensation must be transferred.

Here is an example

** Start
#+name: presents
#+begin_src ledger   
2010/01/01 * Starting balance
  assets:bank:savings  0
  income:starting balances
2021/12/01 User1:Jacket
  expenses:User1:Jacket  80
  income:User1:creditcard1
2010/07/24 User1:Pajama
  expenses:User1:Pajama  30
  income:User1:creditcard1
2010/07/23 User2:Flowers
  expenses:User2:Flowers  20
  income:User2:creditcard2
2010/07/23 User2:ChristmasTree
  expenses:User2:ChristmasTree  40.00
  income:User2:creditcard2
#+end_src

#+RESULTS: presents
#+begin_example
                 170  expenses
                 110    User1
                  80      Jacket
                  30      Pajama
                  60    User2
                  40      ChristmasTree
                  20      Flowers
                -170  income
                -110    User1:creditcard1
                 -60    User2:creditcard2
--------------------
                   0
#+end_example

So user1 spent 110, while  user2 spent 60

** Compensation manually
So the compensation is (trivally)

| User1 | User2 | User2-->Uwer1 |
|-------+-------+---------------|
|   110 |    60 |           -25 |
#+TBLFM: $3=($2-$1)/2;f2

Leading to 
#+name: compensated
#+begin_src ledger   
2010/01/01 * Starting balance
  assets:bank:savings  0
  income:starting balances
2021/12/01 User1:Jacket
  expenses:User1:Jacket  80
  income:User1:creditcard1
2010/07/24 User1:Pajama
  expenses:User1:Pajama  30
  income:User1:creditcard1
2010/07/23 User2:Flowers
  expenses:User2:Flowers  20
  income:User2:creditcard2
2010/07/23 User2:ChristmasTree
  expenses:User2:ChristmasTree  40.00
  income:User2:creditcard2
2010/07/23 User2:User1-Compensation
  expenses:User2:User1-Compensation  25.00
  expenses:User1:User1-Compensation
#+end_src

#+RESULTS: compensated
#+begin_example
                 170  expenses
                  85    User1
                  80      Jacket
                  30      Pajama
                 -25      User1-Compensation
                  85    User2
                  40      ChristmasTree
                  20      Flowers
                  25      User1-Compensation
                -170  income
                -110    User1:creditcard1
                 -60    User2:creditcard2
--------------------
                   0
#+end_example




The question is can this be done automatically?

By this I mean
can
2010/07/23 User2:User1-Compensation
  expenses:User2:User1-Compensation  25.00
  expenses:User1:User1-Compensation

Somehow be generated automatically?

[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 5673 bytes --]

             reply	other threads:[~2021-12-29 16:10 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-29 16:09 Uwe Brauer [this message]
2021-12-30 17:55 ` [SOLVED] (was: (ledger?) The fair Christmas problem: splitting expenses automatically) Uwe Brauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87o84zs88r.fsf@mat.ucm.es \
    --to=oub@mat.ucm.es \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).