Solved

Should I use a label function to calculate overtime?

Posted on 2009-03-29
8
744 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

0
Comment
Question by:aduvall
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 37

Expert Comment

by:zzynx
ID: 24019597
Currently, you use a datafield for each of the columns.
Why wouldn't you use another one for the overtime?
0
 

Author Comment

by:aduvall
ID: 24020322
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
 

Author Comment

by:aduvall
ID: 24021861
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 37

Accepted Solution

by:
zzynx earned 500 total points
ID: 24026388
>> 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
 

Author Comment

by:aduvall
ID: 24040014
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
 
LVL 37

Expert Comment

by:zzynx
ID: 24040087
>> 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
 

Author Comment

by:aduvall
ID: 24040133
That's fine I'll exept that and ask a new question.
0
 
LVL 37

Expert Comment

by:zzynx
ID: 24040303
Thanx 4 axxepting
0

Featured Post

Enroll in July's Course of the Month

July's Course of the Month is now available! Enroll to learn HTML5 and prepare for certification. It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is a very simple example to help those of you who are still migrating from AS2 to AS3 understand the redesigned event model in AS3. In AS2.0, event functions (that is, the function to be performed when an event is fired) were stored as a pro…
Sometimes you know that one object has a specific child in it, but you can't find the child. This happened to me when I was trying to code some actionScript to make a toolbar work with its embedded buttons.  My partner had created the toolbar usi…
The goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question