UNLV-ShaneD / unlvCS473kilo

5 stars 4 forks source link

Transactions and Adjustments #16

Open strongd opened 12 years ago

strongd commented 12 years ago

Okay, so quick question, or clarification if you will.

Do the adjustments in each item affect each transaction individually? Or are the adjustments calculated on groups of transactions in between the time intervals? Do you get where I'm trying to go here?

UNLV-ShaneD commented 12 years ago

Okay, to do a projection of an item, all you're doing is predicting when the next transaction will occur and what value it will be. You do this prediction recursively until when the next transaction should occur goes beyond the end date charting has provided.

To find the first projected transaction date, you must first find the last actual transaction date in that item. Once you have that last actual transaction, you add the item's interval (int in days, create a method to get this on itemEntity) to that date to get the projected transaction's date. Now, you'll need the base value of the item. Get this by creating a method on itemEntity - say getBaseValue. Once you have the date (oldDate), interval (oldInterval), and the value (oldAmount), you iterate through all of the itemAdjustments (for that item) to fine tune the date and value for the projected transaction.

For each iteration through the itemAdjustments list: check if the projected date is later than the itemAdjustment's effective date (make a new method: boolean isEffective(Date date, Branch branch)) - if it is not effective, skip this adjustment.

Now, using the int oldInterval from the last iteration, call projectTransactionInterval(oldInterval) to get the nextInterval. Then, calculate the nextDate from nextInterval and oldDate.

Now you know when the next transaction should be given that this itemAdjustment holds. Now you need to determine how much the transaction is worth. Using the moneyValue oldAmount from the last iteration, call projectTransactionAmount to get the nextAmount.

Now, we need to see if this itemAdjustment should actually be considered. Call determineRecurrence - if this is false, revert the interval and amount to before this adjustment. If it is true, keep the updates to the interval and amount.

Now, continue iterating over the itemAdjustments.

Once you've completed iterating the adjustments, project another transaction if the date of this projected transaction did not exceed the charting end date.

UNLV-ShaneD commented 12 years ago

I would strongly recommend using these imports for working with dates:

import org.joda.time.DateTime; import org.joda.time.Days;

I adding joda time to pom.xml. I will push the change very soon.

strongd commented 12 years ago

Alright, thanks for the clarification. I was using the Calendar type, which seemed to work just fine in adding days, but I'll take a look at Joda Time.

Oh, and who is giving me the actual Item object that has all the data in it to work with? Is that Charting?

UNLV-ShaneD commented 12 years ago

Item managing holds item data. I would use the command pattern and send a command to item managing to iterate through the items. You will need to talk with Corbin.

strongd commented 12 years ago

Apologies in advance, but after looking at my code again, I've gotten myself confused with what you mean by the base value of an item. Does that mean the summation of all the transactions that are part of that item?

UNLV-ShaneD commented 12 years ago

Base value is the predicted value of the next transaction based on the average of recurring transactions in that item.

UNLV-ShaneD commented 12 years ago

You calculate it by averaging the recurring transactions in the item if the item is set for automatic determination of the base value, which is determined by checking a boolean field in the item.

I thought I already implemented a method for all of this so you wouldn't have to worry about it.

strongd commented 12 years ago

Ok, so for when you said here:

to do a projection of an item, all you're doing is predicting when the next transaction will occur and what value it will be.

Do you mean that I predict each individual transaction for the item, or all transactions as a whole? Reading transaction singular and transactions plural is getting a little ambiguous.

Also, would the one-time only transactions not be accounted for in the base value? And would the base value stay the same through all the iterations?

UNLV-ShaneD commented 12 years ago

To answer your first question: the key word is "recursively" - which gets you multiple transacitons.

As for the second, if you look at the implementation of getBaseRecurrenceInterval, you'll probably be able to glean exactly how getBaseValue would work.