<?php
    function retrieveUsersBonusesAsList($db, $userRow, $forWhat, $currentUsersCompany){
        // Determine if this is a super user
        if ($userRow["CompanyID"]==1){
            // Determine if this user is a SU
            if (($userRow["UserLevel"]=='SU' ||
                 $userRow["UserLevel"]=='EXECUTIVE')){
                // Initialize the quarter hours to zero
                $currentQuarterHoursWorked = 0;
                $currentQuarterMinus1HoursWorked = 0;
                $currentQuarterMinus2HoursWorked = 0;
                $currentQuarterMinus3HoursWorked = 0;
                
                // Calculate the quarter start.
                $quarterStart = calculateQuarterStart(null);

                // Create the previous quarter from start
                $quarterStartPlus1 = clone $quarterStart;
                $quarterStartPlus1->modify('+3 months');

                // Create the previous quarter from start
                $quarterStartMinus1 = clone $quarterStart;
                $quarterStartMinus1->modify('-3 months');

                // Create the previous quarter from the previous quarter
                $quarterStartMinus2 = clone $quarterStartMinus1;
                $quarterStartMinus2->modify('-3 months');

                // Create the previous quarter from the previous quarter
                $quarterStartMinus3 = clone $quarterStartMinus2;
                $quarterStartMinus3->modify('-3 months');

                // Initialize the quarters and order
                $currentQuarter = getQuarterNumber($quarterStart->format("n"));
                $currentQuarterMinus1 = getQuarterNumber($quarterStartMinus1->format("n"));
                $currentQuarterMinus2 = getQuarterNumber($quarterStartMinus2->format("n"));
                $currentQuarterMinus3 = getQuarterNumber($quarterStartMinus3->format("n"));
                
                // Initialize the return
                $result = 
                    '<li class="ui-state-default ui-state-disabled Table">
                        <div class="Heading">
                            <div class="cell nameCell">
                                <p><b>Last Name</b></p>
                            </div>
                            <div class="cell nameCell">
                                <p><b>First Name</b></p>
                            </div>
                            <div class="cell levelCell">
                                <p><b>Level</b></p>
                            </div>
                            <div class="cell quarterCell">
                                <p><b>Q' . $currentQuarterMinus3 . ' ' . $quarterStartMinus3->format("Y") . '</b></p>
                            </div>
                            <div class="cell quarterCell">
                                <p><b>Q' . $currentQuarterMinus2 . ' ' . $quarterStartMinus2->format("Y") . '</b></p>
                            </div>
                            <div class="cell quarterCell">
                                <p><b>Q' . $currentQuarterMinus1 . ' ' . $quarterStartMinus1->format("Y") . '</b></p>
                            </div>
                            <div class="cell quarterCell">
                                <p><b>Q' . $currentQuarter . ' ' . $quarterStart->format("Y") . '</b></p>
                            </div>
                        </div>
                    </li>';

                try {
                    // Setup a query with a company name added
                    $sql='SELECT * ' .
                         'FROM users u, companies c ' .
                         'WHERE u.CompanyID=c.CompanyID ' .
                         'AND u.CompanyID=' . $currentUsersCompany . ' ' .
                         'AND u.UserTemplateOnly=0 ' .
                         'AND SUEmployee=1 ' .
                         'AND AccountStatus="ACTIVE" ' .
                         'ORDER BY c.CompanyName ASC, u.LastName ASC, u.FirstName ASC;';

                    // Query the database for the users 
                    $rows = $db->queryDB($sql, $userRow, "users_presentation Form occurance 1");

                    // Loop through the returned results
                    while ($row=mysqli_fetch_array($rows)){
                        // Determine what color this row should be
                        $color='';
                        switch ($row["UserLevel"]){
                            case 'SU':
                                // Set the color to be blueish
                                $color='#708df5';

                                // Break out of this case statement
                                break;
                            case 'EXECUTIVE':
                                // Set the color to be greenish
                                $color='#2bd566';

                                // Break out of this case statement
                                break;
                            case 'MANAGEMENT':
                                // Set the color to be yellowish
                                $color='#f5fd93';

                                // Break out of this case statement
                                break;
                            case 'MID-MANAGEMENT' :
                                // Set the color to be purpleish
                                $color='#8b62cf';

                                // Break out of this case statement
                                break;
                            case 'TYPICAL' :
                                // Set the color to be orangeish
                                $color='#e9a82f';

                                // Break out of this case statement
                                break;
                            default:
                                // Set the color to be redish
                                $color='#ee4462';

                                // Break out of this case statement
                                break;
                        }

                        // Create a query to get the amount of seconds in this current quarter
                        $sql = 'SELECT SUM((UNIX_TIMESTAMP(EndTime) - UNIX_TIMESTAMP(StartTime))) as QuarterPaySeconds ' .
                               'FROM laborclock ' . 
                               'WHERE StartTime >= "' . $quarterStart->format('Y-m-d\ H:i:s') . '" ' .
                               'AND StartTime < "' . $quarterStartPlus1->format('Y-m-d\ H:i:s') . '" ' .
                               'AND UserID=' . $row["UserID"] . ';';

                        // Attempt to get the most recent quarter seconds worked
                        $innerRow = $db->queryDB($sql, $userRow, "financials Form occurance 2");

                        // determine if there is any current time put in
                        if ($innerRow!=null){
                            // Attempt to get the timecard amount row as an ASS
                            $innerAssocRow = $innerRow->fetch_assoc();

                            // Get the amount of mili-seconds they have currently logged
                            $currentQuarterHoursWorked = round($innerAssocRow["QuarterPaySeconds"]/60/60,2);
                        }

                        // Create a query to get the amount of seconds in the previous quarter
                        $sql = 'SELECT SUM((UNIX_TIMESTAMP(EndTime) - UNIX_TIMESTAMP(StartTime))) as QuarterPaySeconds ' .
                               'FROM laborclock ' . 
                               'WHERE StartTime >= "' . $quarterStartMinus1->format('Y-m-d\ H:i:s') . '" ' .
                               'AND StartTime < "' . $quarterStart->format('Y-m-d\ H:i:s') . '" ' .
                               'AND UserID=' . $row["UserID"] . ';';

                        // Attempt to get the previous quarter seconds worked
                        $innerRow = $db->queryDB($sql, $userRow, "financials Form occurance 3");

                        // determine if there is any previous time put in
                        if ($innerRow!=null){
                            // Attempt to get the timecard amount row as an ASS
                            $innerAssocRow = $innerRow->fetch_assoc();

                            // Get the amount of milliseconds they have previously logged
                            $currentQuarterMinus1HoursWorked = round($innerAssocRow["QuarterPaySeconds"]/60/60,2);
                        }
                
                        // Create a query to get the amount of seconds in an earlier quarter
                        $sql = 'SELECT SUM((UNIX_TIMESTAMP(EndTime) - UNIX_TIMESTAMP(StartTime))) as QuarterPaySeconds ' .
                               'FROM laborclock ' . 
                               'WHERE StartTime >= "' . $quarterStartMinus2->format('Y-m-d\ H:i:s') . '" ' .
                               'AND StartTime < "' . $quarterStartMinus1->format('Y-m-d\ H:i:s') . '" ' .
                               'AND UserID=' . $row["UserID"] . ';';

                        // Attempt to get the quarter seconds in an earlier quarter worked
                        $innerRow = $db->queryDB($sql, $userRow, "financials Form occurance 4");

                        // determine if there is any time put in
                        if ($innerRow!=null){
                            // Attempt to get the timecard amount row as an ASS
                            $innerAssocRow = $innerRow->fetch_assoc();

                            // Get the amount of mili-seconds they logged
                            $currentQuarterMinus2HoursWorked = round($innerAssocRow["QuarterPaySeconds"]/60/60,2);
                        }
                
                        // Create a query to get the amount of seconds in an earlier quarter
                        $sql = 'SELECT SUM((UNIX_TIMESTAMP(EndTime) - UNIX_TIMESTAMP(StartTime))) as QuarterPaySeconds ' .
                               'FROM laborclock ' . 
                               'WHERE StartTime >= "' . $quarterStartMinus3->format('Y-m-d\ H:i:s') . '" ' .
                               'AND StartTime < "' . $quarterStartMinus2->format('Y-m-d\ H:i:s') . '" ' .
                               'AND UserID=' . $row["UserID"] . ';';

                        // Attempt to get the quarter seconds in an earlier quarter worked
                        $innerRow = $db->queryDB($sql, $userRow, "financials Form occurance 5");

                        // determine if there is any time put in
                        if ($innerRow!=null){
                            // Attempt to get the timecard amount row as an ASS
                            $innerAssocRow = $innerRow->fetch_assoc();

                            // Get the amount of mili-seconds they logged
                            $currentQuarterMinus3HoursWorked = round($innerAssocRow["QuarterPaySeconds"]/60/60,2);
                        }
                
                        // Add this option to the select
                        $order=1;
                        $result = $result .
                            '<li id="User_' . $order . '" class="ui-state-default Table" >
                                <div class="Row" style="background-color: '. $color . ';" border-style: solid; border-color: '. $color . ';">
                                    <div class="cell nameCell">
                                        <p>' . $row["LastName"] . '</p>
                                    </div>
                                    <div class="cell nameCell">
                                        <p>' . $row["FirstName"] . '</p>
                                    </div>
                                    <div class="cell levelCell">
                                        <p>' . $row["UserLevel"] . '</p>
                                    </div>
                                    <div class="cell quarterCell">
                                        <p><b>$' . round(($currentQuarterMinus3HoursWorked*$row["HourlyPayQ" . $currentQuarterMinus3]*
                                                          ($row["PercentToGoalQ" . $currentQuarterMinus3] + 
                                                           $row["PercentToGoalAdjustmentQ" . $currentQuarterMinus3])*
                                                          ($row["GoalFudgeFactorQ" . $currentQuarterMinus3]*.01)*
                                                          ($row["GoalPercentOfPayQ" . $currentQuarterMinus3]*.01)), 2) . '</b></p>
                                    </div>
                                    <div class="cell quarterCell">
                                        <p><b>$' . round(($currentQuarterMinus2HoursWorked*$row["HourlyPayQ" . $currentQuarterMinus2]*
                                                          ($row["PercentToGoalQ" . $currentQuarterMinus2] + 
                                                           $row["PercentToGoalAdjustmentQ" . $currentQuarterMinus2])*
                                                          ($row["GoalFudgeFactorQ" . $currentQuarterMinus2]*.01)*
                                                          ($row["GoalPercentOfPayQ" . $currentQuarterMinus2]*.01)), 2) . '</b></p>
                                    </div>
                                    <div class="cell quarterCell">
                                        <p><b>$' . round(($currentQuarterMinus1HoursWorked*$row["HourlyPayQ" . $currentQuarterMinus1]*
                                                          ($row["PercentToGoalQ" . $currentQuarterMinus1] + 
                                                           $row["PercentToGoalAdjustmentQ" . $currentQuarterMinus1])*
                                                          ($row["GoalFudgeFactorQ" . $currentQuarterMinus1]*.01)*
                                                          ($row["GoalPercentOfPayQ" . $currentQuarterMinus1]*.01)), 2) . '</b></p>
                                    </div>
                                    <div class="cell quarterCell">
                                        <p><b>$' . round(($currentQuarterHoursWorked*$row["HourlyPayQ" . $currentQuarter]*
                                                          ($row["PercentToGoalQ" . $currentQuarter] + 
                                                           $row["PercentToGoalAdjustmentQ" . $currentQuarter])*
                                                          ($row["GoalFudgeFactorQ" . $currentQuarter]*.01)*
                                                          ($row["GoalPercentOfPayQ" . $currentQuarter]*.01)), 2) . '</b></p>
                                    </div>
                                </div>
                            </li>';
                    }

                } catch (Exception $ex) {
                    // Assign the output string as to what happened
                    return $result;
                }
            }
            else {

            }
        }

        // Return whatever we got
        return $result;
    }

    function getBonus($db, $userRow, $employeeAssocRow){
        // Set the return to nothing
        $returnValue = '';

        // Determine if there is a timecard user row and a user row or not
        if ($employeeAssocRow!=null &&
            $userRow!=null) {
            $editableHTML = 'readonly="readonly"';
            $controlsHiddenStyle = 'display: none;';

            // HTML for super company
            $currentGoalHTML='';
            $previousGoalHTML='';

            // Fill in any variables that we can from the query
            $companyID = $employeeAssocRow["CompanyID"];

            // Initialize variable that will be used in the HTML and Javascript
            $amountOfQuarterPayMilliSeconds = 0;
            $amountOfPreviousQuarterHoursWorked=0;
            $isClockedIn = 'false';
            $clockToUse = '';

            // Calculate the quarter start.
            $quarterStart = calculateQuarterStart(null);

            // Create the next quarter
            $nextQuarterStart = clone $quarterStart;
            $nextQuarterStart->modify('+3 months');

            // Create the previous quarter
            $previousQuarterStart = clone $quarterStart;
            $previousQuarterStart->modify('-3 months');
            
            // Get the amount of seconds in the full quarter
            $secondsInQuarter = $nextQuarterStart->getTimestamp() - $quarterStart->getTimestamp();

            // Get the amount of seconds already passed
            $secondsGoneByInQuarter = (new DateTime())->getTimestamp() - $quarterStart->getTimestamp();
            
            // Calculate what percentage we are into the quarter
            $percentageIntoQuarter = $secondsGoneByInQuarter / $secondsInQuarter * 100;

            // Create a query to to get most recent timecard information if it is still running
            $sql = 'SELECT * FROM laborclock lc1  ' . 
                   'WHERE lc1.UserID=' . $employeeAssocRow["UserID"] . ' ' .
                   'AND lc1.PayDateStart = (SELECT MAX(PayDateStart) FROM laborclock lc2 WHERE lc1.UserID = lc2.UserID) ' .
                   'AND lc1.StartTime = (SELECT MAX(StartTime) FROM laborclock lc2 WHERE lc1.UserID = lc2.UserID);';

            // Attempt to get the most recent timecard info
            $timecardRow = $db->queryDB($sql, $userRow, "financials Form occurance 6");

            // determine if the is a last entry in the database
            if ($timecardRow!=null){
                // Attempt to get the timecard row
                $timecardAssocRow = $timecardRow->fetch_assoc();

                // Set the things we can
                $clockID = $timecardAssocRow["ClockID"];
                $startTime=str_replace(" ","T",$timecardAssocRow["StartTime"]);
                $endTime=str_replace(" ","T",$timecardAssocRow["EndTime"]);

                // Determine if there is an end time or not
                if ($endTime == null ||
                    $endTime == ''){
                    // Determine if we have a start time
                    if ($startTime != null &&
                        $startTime != ''){
                        // set the text for the isClockedIn to denote that they are
                        $isClockedIn = 'true';

                        // Change the clock to use to be the last start time
                        $clockToUse = "'" . $timecardAssocRow["StartTime"] . "'";
                    }
                }

                // Create a query to get the amount of seconds in this current pay day
                $sql = 'SELECT SUM((UNIX_TIMESTAMP(EndTime) - UNIX_TIMESTAMP(StartTime))) as CurrentQuarterPaySeconds ' .
                       'FROM laborclock ' . 
                       'WHERE StartTime >= "' . $quarterStart->format('Y-m-d\ H:i:s') . '" ' .
                       'AND StartTime < "' . $nextQuarterStart->format('Y-m-d\ H:i:s') . '" ' .
                       'AND UserID=' . $employeeAssocRow["UserID"] . ';';

                // Attempt to get the most recent quarter seconds worked
                $quarterAmountRow = $db->queryDB($sql, $userRow, "financials Form occurance 7");

                // determine if there is any current time put in
                if ($quarterAmountRow!=null){
                    // Attempt to get the timecard amount row as an ASS
                    $quarterAmountAssocRow = $quarterAmountRow->fetch_assoc();

                    // Get the amount of mili-seconds they have currently logged
                    $amountOfQuarterPayMilliSeconds = $quarterAmountAssocRow["CurrentQuarterPaySeconds"]*1000;
                }

                // Create a query to get the amount of seconds in this current pay day
                $sql = 'SELECT SUM((UNIX_TIMESTAMP(EndTime) - UNIX_TIMESTAMP(StartTime))) as PreviousQuarterPaySeconds ' .
                       'FROM laborclock ' . 
                       'WHERE StartTime >= "' . $previousQuarterStart->format('Y-m-d\ H:i:s') . '" ' .
                       'AND StartTime < "' . $quarterStart->format('Y-m-d\ H:i:s') . '" ' .
                       'AND UserID=' . $employeeAssocRow["UserID"] . ';';

                // Attempt to get the most recent quarter seconds worked
                $previousQuarterAmountRow = $db->queryDB($sql, $userRow, "financials Form occurance 8");

                // determine if there is any current time put in
                if ($previousQuarterAmountRow!=null){
                    // Attempt to get the timecard amount row as an ASS
                    $previousQuarterAmountAssocRow = $previousQuarterAmountRow->fetch_assoc();

                    // Get the amount of mili-seconds they have currently logged
                    $amountOfPreviousQuarterHoursWorked = round($previousQuarterAmountAssocRow["PreviousQuarterPaySeconds"]/60/60,2);
                }
            }

            // Determine if we have a super user or the bonus user's executive looking at it
            if ($userRow["UserLevel"]=='SU' ||
                ($userRow["UserLevel"]=='EXECUTIVE' &&
                 $userRow["CompanyID"]==$companyID)){
                // Allow for edits
                $editableHTML='';

                // Show controls
                $controlsHiddenStyle = 'display: table-row;';
            }

            // Create a query get company info
            $sql = 'SELECT * FROM companies ' . 
                   'WHERE CompanyID=' . $companyID . ';';

            // Attempt to get the most recent company info
            $companyRow = $db->queryDB($sql, $userRow, "financials Form occurance 9");

            // Set defaults for the company variables
            $currentGoalPercentage=0;
            $fudgeFactor=1;
            
            // Determine if we have company info
            if ($companyRow!=null){
                // Attempt to get the timecard row
                $companyAssocRow = $companyRow->fetch_assoc();
                
                // Set the variables to the real values
                $currentGoalPercentage=$companyAssocRow["PercentToGoalQ" . getQuarterNumber($quarterStart->format("n"))];
                $currentGoalPercentAdjustment=$companyAssocRow["PercentToGoalAdjustmentQ" . getQuarterNumber($quarterStart->format("n"))];
                $currentGoalFudgeFactor=$companyAssocRow["GoalFudgeFactorQ" . getQuarterNumber($quarterStart->format("n"))];
                $currentPercentOfPay=$companyAssocRow["GoalPercentOfPayQ" . getQuarterNumber($quarterStart->format("n"))];
                $currentHourlyPay=$employeeAssocRow["HourlyPayQ" . getQuarterNumber($quarterStart->format("n"))];
                
                // Set the variables to the real values
                $previousGoalPercentage=$companyAssocRow["PercentToGoalQ" . getQuarterNumber($previousQuarterStart->format("n"))];
                $previousGoalPercentAdjustment=$companyAssocRow["PercentToGoalAdjustmentQ" . getQuarterNumber($previousQuarterStart->format("n"))];
                $previousGoalFudgeFactor=$companyAssocRow["GoalFudgeFactorQ" . getQuarterNumber($previousQuarterStart->format("n"))];
                $previousPercentOfPay=$companyAssocRow["GoalPercentOfPayQ" . getQuarterNumber($previousQuarterStart->format("n"))];
                $previousHourlyPay=$employeeAssocRow["HourlyPayQ" . getQuarterNumber($previousQuarterStart->format("n"))];
                
                // Determine if this is the super company
                if ($companyAssocRow["CompanyID"]==1){
                    // Create the current quarter goal information
                    $currentGoalHTML=' 
                                <tr width=100%>
                                    <td height="39" align="left" valign="center">
                                        <strong>Current Goal Percentage: </strong>
                                        <input name="percentToGoal" id="percentToGoal" type="text" maxlength="15" class="intext" style="width: 100%;" value="' . $currentGoalPercentage . '">
                                    </td>
                                </tr>
                                <tr width=100%>
                                    <td height="39" align="left" valign="bottom">
                                        <strong>Current Percent Of Pay: </strong>
                                        <input name="percentOfPay" id="percentOfPay" type="text" maxlength="15" class="intext" style="width: 100%;" value="' . $currentPercentOfPay . '">
                                    </td>
                                </tr>
                                <tr width=100%>
                                    <td height="39" align="left" valign="bottom">
                                        <strong>Current Goal Fudge Factor: </strong>
                                        <input name="goalFudgeFactor" id="goalFudgeFactor" type="text" maxlength="15" class="intext" style="width: 100%;" value="' . $currentGoalFudgeFactor . '">
                                    </td>
                                </tr>';
                    
                    // Create the previous quarter goal information
                    $previousGoalHTML=' 
                                <tr width=100%>
                                    <td height="39" align="left" valign="center">
                                        <strong>Previous Goal Percentage: </strong>
                                        <input name="previousPercentToGoal" id="previousPercentToGoal" type="text" maxlength="15" class="intext" style="width: 100%;" value="' . $previousGoalPercentage . '">
                                    </td>
                                </tr>
                                <tr width=100%>
                                    <td height="39" align="left" valign="bottom">
                                        <strong>Previous Percent Of Pay: </strong>
                                        <input name="previousPercentOfPay" id="previousPercentOfPay" type="text" maxlength="15" class="intext" style="width: 100%;" value="' . $previousPercentOfPay . '">
                                    </td>
                                </tr>
                                <tr width=100%>
                                    <td height="39" align="left" valign="bottom">
                                        <strong>Previous Goal Fudge Factor: </strong>
                                        <input name="previousGoalFudgeFactor" id="previousGoalFudgeFactor" type="text" maxlength="15" class="intext" style="width: 100%;" value="' . $previousGoalFudgeFactor . '">
                                    </td>
                                </tr>';
                }
            }
            
            $returnValue = '
                <script language="JavaScript">
                    // Create the clock in hours to be whatever seconds that were calculated ny PHP
                    hoursWorked = new Date((new Date(' . $clockToUse . ')).getTime()-' . $amountOfQuarterPayMilliSeconds . ');
                        
                    // Set their hourly pay to whatever it is currently
                    hourlyPay=' . $currentHourlyPay . ';

                    // Set the companys current percent to goal
                    percentToGoal=' . $currentGoalPercentage . ';
                        
                    // Set the companys current goal percentage adjustment
                    goalPercentAdjustment=' . $currentGoalPercentAdjustment . ';

                    // Set how far we are into the quarter
                    percentIntoQuarter=' . $percentageIntoQuarter . ';

                    // Set the fudge factor
                    fudgeFactor=' . $currentGoalFudgeFactor . ';

                    // Set the quarters percent of pay
                    percentOfPay=' . $currentPercentOfPay .';
                
                    // setup the is clocked in flag
                    isClockedIn = ' . $isClockedIn . ';
                </script>
                <form action="financials.php" method="post" name="financials" enctype="multipart/form-data">  
                    <table width="100%" border="0" cellspacing="0" cellpadding="0">
                        <tr align="middle" valign="top">
                            <td width="48%" valign="top" align="middle">
                                <table width="100%" border="0" cellpadding="0" cellspacing="0" class="usial">
                                    <tr>
                                        <td align="center" valign="top">
                                            <font size="5"><strong>2023 New Year/New Program</strong></font>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td align="center" valign="middle">
                                            <font size="4">' .
                                           'To be determined...</font>
                                        </td>
                                    </tr>
                                </table>
                            </td>
                            <td width="2%" valign="middle" align="top">
                            </td>
                            <td width="2%" valign="top" align="center" style="border-left: 2px dotted blue;">
                            </td>
                            <td width="48%" valign="top" align="center">
                                <table width="100%" border="0" cellpadding="0" cellspacing="0" class="usial">
                                    <tr>
                                        <td align="center" valign="top">
                                            <font size="5"><strong>Previous Quarters Estimated Bonus</strong></font>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td align="center" valign="top">
                                            <font size="4">Worked Hours: <font color="seagreen"><b>' . $amountOfPreviousQuarterHoursWorked . '</b></font><font color="maroon"> * </font><br> ' .
                                                          'Hourly Pay: <font color="seagreen"><b>$***.**</b></font><font color="maroon"> * </font><br> ' .
                                                          'Percent of pay: <font color="seagreen"><b>%' . $previousPercentOfPay . '</b></font><font color="maroon"> * </font><br> ' .
                                                          '(Goal Percent Accomplished: <font color="seagreen"><b>%' . round($previousGoalPercentage*$previousGoalFudgeFactor,2) . '</b></font><font color="maroon"> + </font><br> ' .
                                                          'Goal Percentage Adjustment: <font color="seagreen"><b>%' . round($previousGoalPercentAdjustment,2) . '</b></font><font color="maroon">) = </font><br> ' .
                                                          'Approximate Bonus Amount: <font color="seagreen"><b> $' . round(($amountOfPreviousQuarterHoursWorked*$previousHourlyPay*($previousGoalPercentage+$previousGoalPercentAdjustment)*($previousGoalFudgeFactor*.01)*($previousPercentOfPay*.01)),2) . '</b></font>' .
                                           '</font>
                                        </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                        <tr align="middle" valign="top" style="border-top: 2px dotted blue;' . $controlsHiddenStyle . '">
                            <td width="48%" valign="middle" align="center">
                            </td>
                            <td width="2%" valign="middle" align="top">
                            </td>
                            <td width="2%" valign="middle" align="top" style="border-left: 2px dotted blue;">
                            </td>
                            <td width="48%" valign="bottom" align="center">
                                <br>
                                <table width="100%" border="0" cellpadding="0" cellspacing="0" class="usial">
                                    <tr>
                                        <td align="center" valign="middle">
                                            <font size="5"><strong>Previous Extra Bonuses</strong></font>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td align="center" valign="middle">
                                            <br>
                                            <strong>Previous Goal Percentage Adjustment:</strong> 
                                            <input name="previousGoalPercentAdjustment" id="previousGoalPercentAdjustment" type="text" maxlength="15" class="intext" style="width: 100%;" value="' . $previousGoalPercentAdjustment . '">
                                        </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                        <tr align="middle" valign="top" style="border-top: 2px dotted blue;' . $controlsHiddenStyle . '">
                            <td width="48%" valign="middle" align="center">
                            </td>
                            <td width="2%" valign="middle" align="top">
                            </td>
                            <td width="2%" valign="middle" align="top" style="border-left: 2px dotted blue;">
                            </td>
                            <td width="48%" valign="bottom" align="center">
                                <br>
                                <table width="100%" border="0" cellpadding="0" cellspacing="0" class="usial">
                                    <tr>
                                        <td align="center" valign="middle">
                                            <font size="5"><strong>Previous Modifiable Factors</strong></font>
                                            <input type="hidden" name="CompanyID" id="CompanyID" value="' . $companyID . '">
                                            <input type="hidden" name="UserID" id="UserID" value="' . $employeeAssocRow["UserID"] . '">
                                        </td>
                                    </tr>
                                    <tr>
                                        <td align="center" valign="middle">
                                            <br>' 
                                            . 
                                            $previousGoalHTML
                                            .
                                        '</td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                        <tr align="middle" valign="top" style="border-top: 2px dotted blue;' . $controlsHiddenStyle . '">
                            <td colspan=4 width="49%" valign="bottom" align="right">
                                <input type="hidden" id="formSubmitted" name="formSubmitted" value="TRUE">
                                <br>
                                <input id="formSubmit" type="submit" style="cursor: hand; cursor: pointer;" value="Update All" />
                            </td>
                        </tr>
                    </table>
                </form>
                <script language="JavaScript">
                    // Code for validating the form
                    // Visit http://www.javascript-coder.com/html-form/javascript-form-validation.phtml
                    // for details
                    var frmvalidator = new Validator("financials", "formSubmit");
                    frmvalidator.addValidation("percentToGoal",
                                               "dec",
                                               "The current goal percentage should be a decimal.");
                    frmvalidator.addValidation("goalPercentAdjustment",
                                               "dec",
                                               "The current goal percentage adjustment should be a decimal.");
                    frmvalidator.addValidation("percentOfPay",
                                               "dec",
                                               "The current percentage of pay should be a decimal.");
                    frmvalidator.addValidation("goalFudgeFactor",
                                               "dec",
                                               "The current fudge factor should be a decimal.");
                    frmvalidator.addValidation("previousPercentToGoal",
                                               "dec",
                                               "The previous goal percentage should be a decimal.");
                    frmvalidator.addValidation("previousGoalPercentAdjustment",
                                               "dec",
                                               "The previous goal percentage adjustment should be a decimal.");
                    frmvalidator.addValidation("previousPercentOfPay",
                                               "dec",
                                               "The previous percentage of pay should be a decimal.");
                    frmvalidator.addValidation("previousGoalFudgeFactor",
                                               "dec",
                                               "The previous fudge factor should be a decimal.");
                </script>';
        }

        // Set a just clocked in field to false
        $_SESSION['justClockedIn']='FALSE';

        // Return whatever was created
        return $returnValue;
    }
?>
