fruitl00p / php-mt940

A mt940 parser in PHP
MIT License
103 stars 60 forks source link

Add a getRelativePrice() function to retrieve the price relative to the bank account #52

Closed rikvdh closed 5 years ago

rikvdh commented 6 years ago

A lot of times you want to get the relative price, (negative when it is debit or positive when it is credit). A small helper function makes this easier.

fruitl00p commented 6 years ago

This doesn't really seem like it should be part of the library as this is just a wrapper around isDebit/isCredit... ? More of an implementation thing as the relevance of isDebit/isCredit is mostly up to the implementation is it not?

rikvdh commented 6 years ago

I think it could be a valuable convenience function for this library. In my accounting system journal-rules are stored as a positive or negative number which increment or decrement the amount. Instead of:

$amount = ($line->isDebit() ? -$line->getPrice() : $line->getPrice());

I can do just:

$amount = $line->getRelativePrice();

Which seems more readable to me. It's your library, do with my proposal whatever you want. But I think it is a valuable addition for a lot of use-cases.

fruitl00p commented 5 years ago

@rikvdh i guess it's a small addition and although i dont see use cases where the oneliner from your example is non-trivial when using the library, it's also too small of an addition to leave out... :smile: