#### Topic: Calculating Money Spent

Hello,

I'm trying to keep track of dollars that employees spend on clothes, and I'm having a hard time get my discount to work. Basically, each employee gets $150 to buy clothes a year at full catalog price. Once they spend their $150, the money comes out of their paycheck, but they get a 40% discount off the catalog price.

This is what I have, but after the person gets into the negative(spending their own money), my calculation doesn't work correctly.

```
@order.order_line_items = @items
@total = @order.order_line_items.inject(0) do |sum, element| sum + ((element.quantity * element.unit_price))
end
if (@person.balance.to_i - @total.to_i) > 0
@person.balance = (@person.balance.to_i - @total.to_i)
else (@person.ending_balance.to_i - @total.to_i) < 0
@person.balance = @person.balance.to_i - (((@total.to_i - @person.balance.to_i) * 0.60) + @person.balance.to_i)
end
```

Any help you can provide will be greatly appreciated.

Thanks,

Zack

*Last edited by zreed20 (2007-01-22 12:07:07)*