I am trying to figure out the best way to do this. So where I work, there is a manufacturer that has a "5/6" Discount, here it is explained:

Quote

For every 5 pieces of Wee Forest Folk you purchase, receive a 50% Discount on the 6th piece:

6th Piece's retail price must not be greater than one of the first 5 pieces. If so, then the discount will only be up to 50% of the highest price of one of the first 5 pieces.

The majority of this code was written by the previous developer and I am trying to fix it. I have everything working fine, except I need to exclude the most recent piece if the price of it was more than the previous ones. I am unsure of the best way to do this. Every purchase of this manufacturer is stored in it's own table and it grabs the highest price once they have ordered the right amount.