We help IT Professionals succeed at work.

Should I use a label function to calculate overtime?

aduvall
aduvall asked
on
803 Views
Last Modified: 2013-11-11
I have built an app that works as a time card.  I gives you the total hours worked for the day and multiplies this by the hourly wage and then gives you the total earned by day, then it totals the entire wage based on the selected date range and is displayed at the end of the DG.  I want to calculate overtime.  

If the total hours worked for any given week exceeds 40 I  need overtime to begin calculating by day and return it to the DG. Here are some of my thoughts so far.
//item.wage = 16.00
if(item.totalhoursworkedfordaterange > 40){
var i:int = 0;
var total:Number = item.totalhoursworkedforday;
var overtime = item.wage * 2.5;  //should now be 40.00 per hour
var grandtotal:Number= total * overtime;
return currencyFormatter.format(grandtotal);
}



Current DG that uses Label Functions tp perform some calcs.
 
<mx:DataGrid x="10" y="133" width="635" fontSize="10" fontFamily="Arial" height="256" dataProvider="{etime}" id="datagrid0" textAlign="left">
					<mx:columns>
						<mx:DataGridColumn headerText="Date" dataField="dates" width="100" />
						<mx:DataGridColumn headerText="Employee" dataField="employee" width="140"/
					
						
	<mx:DataGridColumn headerText="Total Job Time" dataField="total" visible="true"/>
						<mx:DataGridColumn headerText="Bonus Amount" dataField="bpaid" visible="true" labelFunction="formatCure"/>
						<mx:DataGridColumn headerText="THWFD" dataField="totaltime"/>
					    <mx:DataGridColumn headerText="Earned" dataField="earned" labelFunction="dayWage"/>
					    
						
					</mx:columns>
				</mx:DataGrid>

Open in new window

Comment
Watch Question

zzynxSr. Software engineer
CERTIFIED EXPERT

Commented:
Currently, you use a datafield for each of the columns.
Why wouldn't you use another one for the overtime?

Author

Commented:
So if I add a datafield for overtime how would i make that work? I am not sure I understand.

I do know what I have now is not working at all. It ignores the if statement below.  But even if it did work it would total every row in the DG with overtime.  I only want it to calc. overtime on a row that has a running total greater than 39.99. So if row 2 is 35.00 total hours so far it would be regular wage * hoursworkedforday.  If row 3 is 42 hours it would be regular wage  * hoursworkedforday which is 5 and then overtime hours * 2;
             

private function dayWage(item : Object, column : DataGridColumn ) : String {
                        
           var totalhoursworkedforweek:Number = 0;
for(var i:int = 0; i < etime.length; i++)
{
totalhoursworkedforweek += ac.getItemAt(i).totaltime * 1;
}
           
            //totaltime = total hours worked for day.
            if(totalhoursworkedforweek > 39.99){        
           var totals:Number = item.totaltime;
           var overtime:Number = remp0.selectedItem.wage * 2.5;  //wage * time and a half.
           var subtotal:Number = totals * overtime;
           var grandtotal:Number = subtotal + item.bpaid;//subtotal + any bonus paid
           return currencyFormatter.format(grandtotal);
            }
            else {
                  var total:Number = item.totaltime * remp0.selectedItem.wage;
                  var totalbon:Number = item.bpaid;
                  total = (total+totalbon);
                  return currencyFormatter.format(total);
            }
            }

Author

Commented:
Ok I am going to tackle this with a differnt approach.
  private function dayWage(item : Object, column : DataGridColumn ) : String {
                        
           var totalhoursworked:Number = 0;
for(var i:int = 0; i < etime.length; i++)
{
totalhoursworked += etime.getItemAt(i).totaltime * 1;
//trace(totalhoursworked);
var b = totalhoursworked+etime.length;
}
         
             //total = total job time
            //totaltime = total hours worked for day.
            if(totalhoursworked > 39.99){        
           var totals:Number = item.totaltime;
           var overtime:Number = remp0.selectedItem.wage * 2.5;  //16.00 times time and a half.
           var subtotal:Number = totals * overtime;
           var grandtotal:Number = subtotal + item.bpaid;
           return currencyFormatter.format(grandtotal);
            }
            else {
                  var total:Number = item.totaltime * remp0.selectedItem.wage;
                  var totalbon:Number = item.bpaid;
                  total = (total+totalbon);
                  return currencyFormatter.format(total);
            }
            }
  Based on the current AC data this traces,
8.38
20.01
30.34
35.59
44.07
49.57

How do I get these running totals into the AC so I can use them to do my calculations? So I need something like this in these data columns. I tried the label function but no luck.
date:2009-03-11,totalhoursforday:8.38,runningtotal:8.38
date:2009-03-12,totalhoursforday:11.63,runningtotal:20.01
date:2009-03-13,totalhoursforday:10.33,runningtotal:30.34
date:2009-03-14,totalhoursforday:5.25,runningtotal:35.59
date:2009-03-15,totalhoursforday:8.48,runningtotal:44.07 // over time begins
date:2009-03-16,totalhoursforday:5.50,runningtotal:49.57

Sr. Software engineer
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
That worked but It calcs OT for everyday when the totalhoursworked is > 40.01.  So how do I get something like this. Because as of now it returns OT for every day on the overtime data field.  I am thinking I need a running total column. How would I do that.
Date                      Total Hours For Day  Running Total Hours      Wage       Regular Pay  Overtime Pay
2009-03-01           15                                  15                               $16.00         $240.00             $0.00
2009-03-02           15                                  30                               $16.00         $240.00             $0.00
2009-03-03           15                                  45                               $16.00         $160.00             $200.00
Total Hours           45.00
zzynxSr. Software engineer
CERTIFIED EXPERT

Commented:
>> That worked but It calcs OT for everyday when the totalhoursworked is > 40.01.
Wasn't that your initial question?
>> If the total hours worked for any given week exceeds 40 I  need overtime to begin calculating by day and return it to the DG.

Author

Commented:
That's fine I'll exept that and ask a new question.
zzynxSr. Software engineer
CERTIFIED EXPERT

Commented:
Thanx 4 axxepting

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.