tags:

views:

58

answers:

1

I have a database table like this:

wagetable
 name     lowhours  highhours  wage 
 Default  0         40         10   
 Default  40        9999       15   
 Brian    0         40         15   
 Brian    40        50         20   
 Brian    50        9999       22   
 Chad     0         40         13   
 Chad     40        9999       17 

If 'Brian' worked 43.5151587 hours, I want it to figure out that he made (40*15)+(3.5151587*20) = 670.303174.

This is a SQLite database, so I know I will use:

SELECT wage FROM wagetable WHERE name LIKE 'Brian' AND 'HourNum' BETWEEN lowhours AND highhours;

With a combination of floor and %... I am just not putting the logic together in my head.

Please note answers in C# and PHP accepted, as I can convert the logic to what I need. I am looking for pseudo code but will accept drawn out answers

Edit: please note...The hours worked will never be an exact integer, why I let overlapping happen.

Edit2:

I want to take an employees total hours worked (example: 43.5151587) and then realize that the first 40 hours, he was making standard pay @ $15 an hour. so (40*15)...Then he worked 3.5151587 hours of overtime @ $20 an hour. so (40*15) add to it (3.5151587*20)...The total amount earned was 670.303174

A: 

From what I gather from your post (psuedocode):

foreach pay_bracket p:
    if hours > p.length
        pay += p.length * p.pay
        hours -= p.length
    else
        pay += hours * p.pay
        end

Where length is highhours - lowhours (and that pay brackets are right next to each other, of course).

Anon.
pay brackets will not be right next to each other most likely. However I could just take sort them in a sense. Thia is what I wanted though. Thanks
BHare
One thing I want to add, dont forget to set hours to zero in the else statement. :)
BHare
Nevermind, I guess thats the idea why you put end...I didnt implement end :)
BHare