Solved

Should I use a label function to calculate overtime?

Posted on 2009-03-29
8
740 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
Industry Leaders: 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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Suggested Solutions

I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
I have found that much of my time doing support ends up being a constant repetition of the same steps to different people.  Early on I stated using web pages with Frequently Asked Questions (FAQs) to alleviate most of the burden.  Sometimes this jus…
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 how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.

752 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