emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* (ledger?) The fair Christmas problem: splitting expenses automatically
@ 2021-12-29 16:09 Uwe Brauer
  2021-12-30 17:55 ` [SOLVED] (was: (ledger?) The fair Christmas problem: splitting expenses automatically) Uwe Brauer
  0 siblings, 1 reply; 2+ messages in thread
From: Uwe Brauer @ 2021-12-29 16:09 UTC (permalink / raw)
  To: Org Mode List

[-- 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 --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [SOLVED] (was: (ledger?) The fair Christmas problem: splitting expenses automatically)
  2021-12-29 16:09 (ledger?) The fair Christmas problem: splitting expenses automatically Uwe Brauer
@ 2021-12-30 17:55 ` Uwe Brauer
  0 siblings, 0 replies; 2+ messages in thread
From: Uwe Brauer @ 2021-12-30 17:55 UTC (permalink / raw)
  To: emacs-orgmode

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

>>> "UB" == Uwe Brauer <oub@mat.ucm.es> writes:

> 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?



The solution consists of
#+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  ((110-60)*0.5)
  expenses:User1:User1-Compensation
#+end_src

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-12-30 18:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-12-29 16:09 (ledger?) The fair Christmas problem: splitting expenses automatically Uwe Brauer
2021-12-30 17:55 ` [SOLVED] (was: (ledger?) The fair Christmas problem: splitting expenses automatically) Uwe Brauer

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).