Jump to content

math help


Ninjakreborn

Recommended Posts

This is related to php, but more of math.
I have a donation list.
When one is deleted it's updating a monetary value, by removing it from that value, which is subtraction, when it adds one, it takes the value, and adds the amount on the donation to it.
I don't know what do to when they edit the donaiton, adding, or just subtracting won't work, what process should I use.
Basically I have 1 monetary value, say
500.00
If a new donation is added which is 250.00 it adds 250.00 to the 500.00 which is 750.00
easy, just adding
what if it's then deleted, ok that's fine just 750 -250.00 = 500.00
done, but say it's added 250.00
Later they want to edit that, to they change it to 240, or 360 or something, I can;t just add this new number to the total, or subtract it, it won't turn out correct, so how do I correctly edit the total with the new value, without miscalculation?
Link to comment
Share on other sites

My first question: do you have anywhere that you are storing the individual donations? If not, you should. This would easily allow them to add, delete or edit a donation, and all you have to do is run a SUM() query on the amount of all your donations to get your total.

Another thought: why on earth are people being allowed to edit or delete a donation? Isn't that sort of bad business practice? Just curious...
Link to comment
Share on other sites

"in case of wrong input etc" is that he just said, he's on msn.
See I have each donation stored in the database yes, the delete was fine, I pulled the information, and when they delete I subtract.  It's a little more involved, because it also goes on category, but I ahve all that programmed, it's just the math to do the editing itself.  Even the total is fine, so far I just add them all up, adn the total is done.  I just need to figure out how to handle the editing situation with math?
When they add one, it tells what category, adds the donation to teh category amount, then updates the total, and full balance, no problem
Same with deleting, it subtracts it, adds up total, works up balance.  No problem, but the deleting has me stumped, since straight add or subtract won't work.
Link to comment
Share on other sites

What if you when they removed they are not deleted, but rather brought up in a negative number. Same thing with editing.

Example:
$500 deposit from person A
$240 deposit from person B
*Person A changes mind*
*Person B wants to subtract $10 for beer*

So your table would look like:
Amount | Person | Reason
$500          A     
$240          B       
-$500        A        N/A
-$10          B        Beer
Link to comment
Share on other sites

I am a little confused with what you mean, with this,w hen they delete it's a little different.  Once the donations are made theycan't be changed by the person, but it's just there for incase they made mistakes.  The numbers can go negative, there is a lot of math here so far.  THe structure's already done, it's just on editing, I am confused on what to do calculation wise.
Link to comment
Share on other sites

I think it would work like this.
Stored value = 500.00
Current total = 1000.00

New edited value = 450.00

Database work
Pull stored value
subtract stored value from total
take add editid value back to total
so you have
1000 - 500.00 = 500.00
Then you add back in the new edited value
500 + 450 = 950.00
that is the new total, I think that will work each time, won't it.
Link to comment
Share on other sites

Basically, take the value from [b]after[/b] the edit and subtract the value from [b]before[/b] the edit. Then, you take that value and add it to the total. With that pattern, if they [i]subtract[/i] from their original donation, you come up with a negative number that will appropriately modify the grand total down.

Make sense?
Link to comment
Share on other sites

i'm with obsidian's first post with this one. if someone donates, they donate cos they want to - not because they need or will use some sort of money-back guarantee, so that takes away having to deduct.

as for additions - keep additional donations seperate. why would they/you need to adjust it? if i make a mistake using paypal to donate £50 instead of £5, then I do believe that it's down to the recipient to refund me if they so choose. but there's enough 'please confirm' to make sure that i dont do something stupid.

once you've got a list of donations (with no negative ones) then you just do what obsidian said and tot them all up.

am I missing something?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.