• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 772
  • Last Modified:

Should I use a label function to calculate overtime?

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

0
aduvall
Asked:
aduvall
  • 4
  • 4
1 Solution
 
zzynxSoftware engineerCommented:
Currently, you use a datafield for each of the columns.
Why wouldn't you use another one for the overtime?
0
 
aduvallAuthor 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);
            }
            }
0
 
aduvallAuthor 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

0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
zzynxSoftware engineerCommented:
>> So if I add a datafield for overtime how would i make that work? I am not sure I understand.
That's rather easy.

In your original code snippet
>> 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);
>> }
the return value is determined by using item.totalhoursworkedfordaterange, item.totalhoursworkedforday, & item.wage.
That means that all information is available in "item" (whatever that is)
Let's assume that "item" is an instance of the class "MyData", then you can add

this variable

   private var _overtime:String;

and these functions

[Bindable]
public function set overtime(o:String):void {
   _overtime = o;
}
public function get overtime():String {
   if (_overtime==null) {
      // Do the calculation as in the code snippet:
      if(totalhoursworkedfordaterange > 40) {
          // ... and eventually assign it to _overtime:
          _overtime =
      } else
         _overtime = "";
   }
   return _overtime;
}

Now for your DG you can simply write:

   <mx:DataGridColumn headerText="Overtime" dataField="overtime"/>
0
 
aduvallAuthor 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
0
 
zzynxSoftware engineerCommented:
>> 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.
0
 
aduvallAuthor Commented:
That's fine I'll exept that and ask a new question.
0
 
zzynxSoftware engineerCommented:
Thanx 4 axxepting
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now