julien-nc / cospend-nc

💰 💲hared budget manager Nextcloud app
GNU Affero General Public License v3.0
226 stars 29 forks source link

Importing SplitWise CSV displays wrong people on "For whom?" #203

Open Porrumentzio opened 1 year ago

Porrumentzio commented 1 year ago

This is definitely related to #159 and might be so to #182

I exported a SplitWise CSV and needed to edit column names to English (following #159). As said in that issue, there is a tiny difference in balances due to the rounding up thing, but it's a matter of cents.

However, the person who paid is excluded from "For whom?" section, when it should not be in every cases. See this example: SplitWise Cospend imported
Porru paid 2,84, divided equally between the four people (25 %, so it should be 0,71 per person, including Porru) image

As I already said, the balances are the same, but showing the info that way (the cost and the people to pay being different) is rather confusing. Besides, it may affect the statistics, right?

julien-nc commented 1 year ago

Hi, Yes it definitely affects the stats.

Let's figure out the algorithm to compute the bill to create in Cospend Relevant info/columns in a Splitwise export line:

I think we can safely assume there can be only one payer in SplitWise, anyway if it's not the case, I don't care if we support importing this :grin:.

There should be only one person with a positive effect. This is the payer. Let's call the effect on the payer eP, it's the only positive value in the effect list. I think it's reasonable to only support those 2 cases:

  1. If the cost is is equal to the effect on the payer (C == eP), then the payer is not in the "for whom" list (not an ower). For example:

    • C = 30
    • e1 = 30
    • e2 = -15
    • e3 = -15

    This would lead to a Cospend bill payed by 1, amount would be 30, it would include 2, and 3

  2. If the effects on the owers are all equal (e1 == e2 == e3) and if the cost equals the effect on the payer minus the effect on one ower (C == eP - e2) this is an evenly split bill. For example:

    • C = 30
    • e1 = 20
    • e2 = -10
    • e3 = -10

    This would lead to a Cospend bill payed by 1, amount would be 30, it would include 1, 2, and 3

Any other case would be treated like it's implemented now.

Do you think there's a flaw in this?

I see a first obstacle making this hard to implement, this kind of line:

2022-07-05,desc,cat1,8.20,EUR,-2.73,5.47,-2.74

The negative values are not equal...