function showTimeRequestTable($config, $filters, $orderBy = "ORDER BY REFER DESC", $hiddenInput = '')
{
    $mysqli = $config->mysqli;
    if (isset($_POST['timeRequestTableRows'])) {
        $totalRows = $_POST['timeRequestTableRows'];
        $btnPushed = false;
        for ($i = 0; $i <= $totalRows; $i++) {
            if (isset($_POST['pendingBtn' . $i])) {
                $refNo = $_POST['refNo' . $i];
                $hrNotes = isset($_POST['hrReason' . $i]) ? $_POST['hrReason' . $i] : '';
                sendRequestToPending($config, $refNo, $hrNotes);
                $btnPushed = true;
            } elseif (isset($_POST['approve' . $i])) {
                $postReason = isset($_POST['reason' . $i]) ? $_POST['reason' . $i] : '';
                approveLeaveRequest($config, $_POST['refNo' . $i], "APPROVED", $postReason);
                $btnPushed = true;
            } elseif (isset($_POST['deny' . $i])) {
                approveLeaveRequest($config, $_POST['refNo' . $i], "DENIED", $_POST['reason' . $i]);
                $btnPushed = true;
            } elseif (isset($_POST['hrApproveBtn' . $i])) {
                $hrNotes = isset($_POST['hrReason' . $i]) ? $_POST['hrReason' . $i] : isset($_POST['hrOldNotes' . $i]) ? $_POST['hrOldNotes' . $i] : '';
                hrApproveLeaveRequest($config, $_POST['refNo' . $i], $hrNotes);
                $btnPushed = true;
            } elseif (isset($_POST['expungeBtn' . $i]) || isset($_POST['unExpungeBtn' . $i])) {
                $toExpungeRefNo = $_POST['refNo' . $i];
                $toExpungeIndex = $i;
                $toExpungeTotalRows = $totalRows;
                $toExpunge = true;
                $toUnExpunge = false;
                if (isset($_POST['unExpungeBtn' . $i])) {
                    $toUnExpunge = true;
                }
                $btnPushed = true;
            }
            if ($btnPushed) {
                echo "<script language=\"javascript\" >\r\n                    document.body.onload = new  function () {\r\n                        window.location.hash = '#editBtn" . $i . "';\r\n                    }\r\n                </script>\r\n                ";
                break;
            }
        }
    }
    if ($config->adminLvl < 25) {
        //only allow to search own reference numbers
        $filters = "'WHERE REQUEST.IDNUM = '" . $config->mysqli->real_escape_string($_SESSION['userIDnum']);
    }
    $myq = "SELECT REFER 'RefNo', REQ.MUNIS 'Munis', CONCAT_WS(', ',REQ.LNAME,REQ.FNAME) 'Name', \r\n                DATE_FORMAT(USEDATE,'%b %d, %Y - %a') 'Used', STATUS 'Status',\r\n                    DATE_FORMAT(BEGTIME,'%H%i') 'Start',\r\n                    DATE_FORMAT(ENDTIME,'%H%i') 'End', HOURS 'Hrs',\r\n                    T.DESCR 'Type', SUBTYPE 'Subtype', CALLOFF 'Calloff', NOTE 'Comment', \r\n                    APR.LNAME 'ApprovedBy', \r\n                    DATE_FORMAT(REQUEST.ApprovedTS,'%b %d, %Y') 'approveTS',\r\n                    REASON 'Reason', HRAPP_IS 'HR_Approved', HR.LNAME 'HRLName', HR.FNAME 'HRFName', REQUEST.HR_NOTES AS 'HRNOTES'\r\n                FROM REQUEST\r\n                LEFT JOIN EMPLOYEE AS REQ ON REQ.IDNUM=REQUEST.IDNUM\r\n                LEFT JOIN EMPLOYEE AS APR ON APR.IDNUM=REQUEST.APPROVEDBY\r\n                LEFT JOIN EMPLOYEE AS HR ON HR.IDNUM=REQUEST.HRAPP_ID\r\n                INNER JOIN TIMETYPE AS T ON T.TIMETYPEID=REQUEST.TIMETYPEID\r\n                " . $filters . "\r\n                " . $config->mysqli->real_escape_string($orderBy) . "\r\n                ";
    $result = $mysqli->query($myq);
    SQLerrorCatch($mysqli, $result, $myq, $debug = FALSE);
    $theTable = array(array());
    $x = 0;
    $y = 0;
    $theTable[$x][$y] = "Actions";
    $y++;
    $theTable[$x][$y] = "Ref#";
    $y++;
    $theTable[$x][$y] = "Employee";
    $y++;
    $theTable[$x][$y] = "Date_of_Use";
    $y++;
    $theTable[$x][$y] = "Start Time";
    $y++;
    $theTable[$x][$y] = "End Time";
    $y++;
    $theTable[$x][$y] = "Hours";
    $y++;
    $theTable[$x][$y] = "Type";
    $y++;
    $theTable[$x][$y] = "Subtype";
    $y++;
    $theTable[$x][$y] = "Call Off";
    $y++;
    $theTable[$x][$y] = "Comment";
    $y++;
    $theTable[$x][$y] = 'Status';
    $y++;
    $theTable[$x][$y] = 'Approved By';
    $y++;
    $theTable[$x][$y] = 'Approved Time';
    $y++;
    $theTable[$x][$y] = 'Reason';
    $y++;
    $theTable[$x][$y] = 'HR Approval';
    $y++;
    $theTable[$x][$y] = 'HR Notes';
    $y++;
    $x++;
    while ($row = $result->fetch_assoc()) {
        $y = 0;
        $theTable[$x][$y] = '<input type="submit" id="editBtn' . $x . '" name="editBtn' . $x . '" value="Edit/View" onClick="this.form.action=' . "'?leave=true'" . '; this.form.submit()" />' . '<input type="hidden" name="requestID' . $x . '" value="' . $row['RefNo'] . '" />';
        if ($row['Status'] == "EXPUNGED") {
            $theTable[$x][$y] .= '';
        } else {
            if (!$row['HR_Approved']) {
                $theTable[$x][$y] .= '<input type="submit" name="expungeBtn' . $x . '" value="Delete" />';
            }
            if ($row['HR_Approved'] && $config->adminLvl >= 50 && $config->adminLvl != 75) {
                $theTable[$x][$y] .= '<input type="submit" name="expungeBtn' . $x . '" value="Delete" />';
            }
        }
        $y++;
        $theTable[$x][$y] = '<input type="hidden" name="refNo' . $x . '" value="' . $row['RefNo'] . '" />' . $row['RefNo'];
        $y++;
        $empMunis = $row['Munis'];
        $empName = $row['Name'];
        $theTable[$x][$y] = $empName;
        $y++;
        $theTable[$x][$y] = $row['Used'];
        $y++;
        $theTable[$x][$y] = $row['Start'];
        $y++;
        $theTable[$x][$y] = $row['End'];
        $y++;
        $theTable[$x][$y] = $row['Hrs'];
        $y++;
        $theTable[$x][$y] = $row['Type'];
        $y++;
        $theTable[$x][$y] = $row['Subtype'];
        $y++;
        $theTable[$x][$y] = $row['Calloff'];
        $y++;
        $theTable[$x][$y] = $row['Comment'];
        $y++;
        if ($row['Status'] != 'PENDING' && $config->adminLvl >= 25) {
            $theTable[$x][$y] = $row['Status'];
            if (!empty($row['Reason'])) {
                $theTable[$x][$y] .= '<br/><font color="darkred">' . $row['Reason'] . '</font>';
            }
            if (!$row['HR_Approved']) {
                $theTable[$x][$y] .= '<Br/><input type="submit" name="pendingBtn' . $x . '" value="Send to Pending" />';
            } elseif ($row['HR_Approved'] && $config->adminLvl >= 50 && $config->adminLvl != 75) {
                $theTable[$x][$y] .= '<Br/><input type="submit" name="pendingBtn' . $x . '" value="Send to Pending" />';
            }
        } elseif ($row['Status'] == 'PENDING' && $config->adminLvl >= 25) {
            $theTable[$x][$y] = $row['Status'];
            $theTable[$x][$y] .= "<br/><input type='submit' name='approve{$x}' value='APPROVED' size='15'/> ";
            $theTable[$x][$y] .= "<input type='submit' name='deny{$x}' value='DENIED' size='15'><br/>";
            $theTable[$x][$y] .= 'Reason:<br/><textarea rows="2" cols="21" name="reason' . $x . '" ></textarea>';
        } else {
            $theTable[$x][$y] = $row['Status'] . '</br><font color="darkred">' . $row['Reason'] . '</font>';
        }
        $y++;
        $theTable[$x][$y] = $row['ApprovedBy'];
        $y++;
        $theTable[$x][$y] = $row['approveTS'];
        $y++;
        $theTable[$x][$y] = $row['Reason'];
        $y++;
        if (!$row['HR_Approved'] && $row['Status'] != "DENIED") {
            $theTable[$x][$y] = 'Pending';
            if ($row['Status'] == "APPROVED" && $config->adminLvl >= 50 && $config->adminLvl != 75) {
                $theTable[$x][$y] = '<font color="darkred">Pending</font>';
                $theTable[$x][$y] .= '<input type="submit" name="hrApproveBtn' . $x . '" value="HR Approve" />';
                $y++;
                $theTable[$x][$y] = '<textarea rows="2" cols="21" name="hrReason' . $x . '" ></textarea>';
            } else {
                $y++;
                $theTable[$x][$y] = '';
            }
        } elseif ($row['Status'] == "DENIED") {
            $theTable[$x][$y] = 'No Action Required';
            $y++;
            $theTable[$x][$y] = '<font color="darkred">
                    <input type="hidden" name="hrOldNotes' . $x . '" value="' . $row['HRNOTES'] . '" />' . $row['HRNOTES'] . '</font>';
        } else {
            $theTable[$x][$y] = '<div align="center"><h3><font color="darkred">Approved</font></h3></div>';
            $y++;
            $theTable[$x][$y] = '<font color="darkred">
                    <input type="hidden" name="hrOldNotes' . $x . '" value="' . $row['HRNOTES'] . '" />' . $row['HRNOTES'] . '</font>';
        }
        $y++;
        $x++;
    }
    if ($config->adminLvl >= 50 && $config->adminLvl != 75) {
        showSortableTable($theTable, 2, "timeRequestTable");
    } else {
        showSortableTable($theTable, 2, "timeRequestTable");
    }
    echo '<input type="hidden" name="timeRequestTableRows" value="' . $x . '" />';
    if ($toExpunge) {
        echo '</form>';
        $hiddenInput .= '<input type="hidden" name="timeRequestTableRows" value="2" />
                <input type="hidden" name="expungeBtn1" value="true" />
                <input type="hidden" name="refNo1" value="' . $toExpungeRefNo . '" />
                ';
        expungeRequest($config->mysqli, $toExpungeRefNo, $toUnExpunge, $toExpungeIndex, $toExpungeTotalRows, $hiddenInput);
        echo '<form method=POST name="requestTable">';
    }
}
Ejemplo n.º 2
0
function empTimeReportByPay($config, $startDate, $endDate, $empID)
{
    $mysqli = $config->mysqli;
    $refNo = '';
    //Was Approve Button Pressed
    if (isset($_POST['totalRows'])) {
        $totalRows = $_POST['totalRows'];
        for ($i = 0; $i <= $totalRows; $i++) {
            if (isset($_POST['hrApprove' . $i])) {
                $refNo = $_POST['refNo' . $i];
                break;
            }
            if (isset($_POST['pendingBtn' . $i])) {
                $refNo = $_POST['refNo' . $i];
                $myq = $myq = "UPDATE REQUEST \r\n                    SET STATUS='PENDING',\r\n                    `HRAPP_IS` = '0',\r\n                    APPROVEDBY=''\r\n                    WHERE REFER=" . $refNo;
                $result = $mysqli->query($myq);
                SQLerrorCatch($mysqli, $result, $myq);
                addLog($config, 'Ref# ' . $refNo . ' status was changed to pending');
                break;
            }
        }
    }
    if (!empty($refNo)) {
        $myq = "UPDATE REQUEST SET `TSTAMP` = NOW( ) ,\r\n            `HRAPP_IS` = '1',\r\n            `HRAPP_ID` = '" . $_SESSION['userIDnum'] . "',\r\n            `HRAPP_IP` = INET_ATON('" . $_SERVER['REMOTE_ADDR'] . "'),\r\n            `HRAPP_TIME` = NOW( ) WHERE `REQUEST`.`REFER` =" . $refNo;
        $result = $mysqli->query($myq);
        SQLerrorCatch($mysqli, $result);
        addLog($config, 'HR Approved Request with ref# ' . $refNo);
    }
    $myq = "SELECT REFER 'RefNo', REQ.MUNIS 'Munis', CONCAT_WS(', ',REQ.LNAME,REQ.FNAME) 'Name', \r\n                DATE_FORMAT(USEDATE,'%a %b %d %Y') 'Used', STATUS 'Status',\r\n                    DATE_FORMAT(BEGTIME,'%H%i') 'Start',\r\n                    DATE_FORMAT(ENDTIME,'%H%i') 'End', HOURS 'Hrs',\r\n                    T.DESCR 'Type', SUBTYPE 'Subtype', CALLOFF 'Calloff', NOTE 'Comment', \r\n                    APR.LNAME 'ApprovedBy', \r\n                    DATE_FORMAT(REQUEST.ApprovedTS,'%a %b %d %Y') 'approveTS',\r\n                    REASON 'Reason', HRAPP_IS 'HR_Approved', HR.LNAME 'HRLName', HR.FNAME 'HRFName'\r\n                FROM REQUEST\r\n                LEFT JOIN EMPLOYEE AS REQ ON REQ.IDNUM=REQUEST.IDNUM\r\n                LEFT JOIN EMPLOYEE AS APR ON APR.IDNUM=REQUEST.APPROVEDBY\r\n                LEFT JOIN EMPLOYEE AS HR ON HR.IDNUM=REQUEST.HRAPP_ID\r\n                INNER JOIN TIMETYPE AS T ON T.TIMETYPEID=REQUEST.TIMETYPEID\r\n                WHERE USEDATE BETWEEN '" . $startDate->format('Y-m-d') . "' AND '" . $endDate->format('Y-m-d') . "'\r\n                AND REQ.IDNUM='" . $empID . "'\r\n                AND (STATUS='APPROVED' OR STATUS='DENIED')\r\n                ";
    $result = $mysqli->query($myq);
    SQLerrorCatch($mysqli, $result);
    $theTable = array(array());
    $x = 0;
    $y = 0;
    if ($config->adminLvl >= 50 && $config->adminLvl != 75) {
        $theTable[$x][$y] = "HR Approve";
        $y++;
        $theTable[$x][$y] = "Expunge";
        $y++;
    }
    $theTable[$x][$y] = "Ref #";
    $y++;
    $theTable[$x][$y] = "Date of Use";
    $y++;
    $theTable[$x][$y] = "Start Time";
    $y++;
    $theTable[$x][$y] = "End Time";
    $y++;
    $theTable[$x][$y] = "Hours";
    $y++;
    $theTable[$x][$y] = "Type";
    $y++;
    $theTable[$x][$y] = "Subtype";
    $y++;
    $theTable[$x][$y] = "Call Off";
    $y++;
    $theTable[$x][$y] = "Comment";
    $y++;
    $theTable[$x][$y] = 'Status';
    $y++;
    $theTable[$x][$y] = 'ApprovedBy';
    $y++;
    $theTable[$x][$y] = 'Approved Time';
    $y++;
    $theTable[$x][$y] = 'Reason';
    while ($row = $result->fetch_assoc()) {
        $x++;
        $y = 0;
        if ($config->adminLvl >= 50 && $config->adminLvl != 75) {
            if (!$row['HR_Approved']) {
                $theTable[$x][$y] = '<input type="submit" name="hrApprove' . $x . '" value="Approve" />';
            } else {
                $theTable[$x][$y] = '<div align="center"><h3><font color="red">Approved</font></h3></div>';
            }
            $theTable[$x][$y] .= '<input type="submit" name="editBtn0" value="Edit/View" onClick="this.form.action=' . "'?leave=true'" . '; this.form.submit()" />' . '<input type="hidden" name="formName" value="' . $_SERVER['REQUEST_URI'] . '"/>
                      <input type="hidden" name="requestID0" value="' . $row['RefNo'] . '" />
                      <input type="hidden" value="2" name="totalRows" />';
            $y++;
            $theTable[$x][$y] = '<br/><input type="submit" name="deleteBtn' . $x . '" value="Expunge" />';
            $y++;
        }
        $theTable[$x][$y] = '<input type="hidden" name="refNo' . $x . '" value="' . $row['RefNo'] . '" />' . $row['RefNo'];
        $y++;
        $empMunis = $row['Munis'];
        $empName = $row['Name'];
        $theTable[$x][$y] = $row['Used'];
        $y++;
        $theTable[$x][$y] = $row['Start'];
        $y++;
        $theTable[$x][$y] = $row['End'];
        $y++;
        $theTable[$x][$y] = $row['Hrs'];
        $y++;
        $theTable[$x][$y] = $row['Type'];
        $y++;
        $theTable[$x][$y] = $row['Subtype'];
        $y++;
        $theTable[$x][$y] = $row['Calloff'];
        $y++;
        $theTable[$x][$y] = $row['Comment'];
        $y++;
        if ($row['Status'] != 'PENDING' && $config->adminLvl >= 25) {
            $theTable[$x][$y] = $row['Status'] . '<input type="submit" name="pendingBtn' . $x . '" value="Send to Pending" />';
        } else {
            $theTable[$x][$y] = $row['Status'];
        }
        $y++;
        $theTable[$x][$y] = $row['ApprovedBy'];
        $y++;
        $theTable[$x][$y] = $row['approveTS'];
        $y++;
        $theTable[$x][$y] = $row['Reason'];
    }
    if (empty($empName)) {
        $myq = "SELECT REQ.MUNIS 'Munis', CONCAT_WS(', ',REQ.LNAME,REQ.FNAME) 'Name'\r\n                FROM EMPLOYEE REQ\r\n                WHERE REQ.IDNUM='" . $empID . " LIMIT 1'\r\n                ";
        $result = $mysqli->query($myq);
        SQLerrorCatch($mysqli, $result, $myq);
        $row = $result->fetch_assoc();
        $empMunis = $row['Munis'];
        $empName = $row['Name'];
    }
    echo '<div align="center"><h3>Employee: ' . $empName . '</h3>Munis# ' . $empMunis . '</div>';
    showSortableTable($theTable, 7, "hrDetails", array(2));
    echo '<input type="hidden" name="totalRows" value="' . $x . '" />
              <input type="hidden" value="View" name="viewDetailsBtn">
              <input type="hidden" value="' . $empID . '" name="empID">';
    echo '</form>';
    //Show Hour Adjustment Table
    $totalsTable = array(array());
    $x = 0;
    $totalTable[$x][0] = "Type";
    $totalTable[$x][1] = "Hours Gained/Used";
    $myq = "SELECT HOURS 'Hrs', T.DESCR 'Type', R.TIMETYPEID 'timeType', HRAPP_IS 'HRApproved'\r\n                FROM REQUEST R\r\n                INNER JOIN TIMETYPE AS T ON T.TIMETYPEID=R.TIMETYPEID\r\n                WHERE USEDATE BETWEEN '" . $startDate->format('Y-m-d') . "' AND '" . $endDate->format('Y-m-d') . "'\r\n                AND R.IDNUM='" . $empID . "'\r\n                AND STATUS='APPROVED'\r\n                ORDER BY R.TIMETYPEID\r\n                ";
    $result = $mysqli->query($myq);
    SQLerrorCatch($mysqli, $result);
    $lastTimeType = '';
    while ($row = $result->fetch_assoc()) {
        if ($row['HRApproved']) {
            if (strcmp($row['timeType'], $lastTimeType) == 0) {
                $totalTable[$x][1] += $row['Hrs'];
            } else {
                $x++;
                $lastTimeType = $row['timeType'];
                $totalTable[$x][0] = $row['Type'];
                $totalTable[$x][1] = $row['Hrs'];
            }
        }
    }
    echo '<div id="wrapper">';
    $echo = '<table class="sortable">
            <tr>';
    for ($y = 0; $y < sizeof($totalTable[0]); $y++) {
        $echo .= '<th>' . $totalTable[0][$y] . '</th>';
    }
    $echo .= '</tr>
        ';
    $x = 1;
    for ($x; $x < sizeof($totalTable); $x++) {
        $echo .= '<tr>';
        for ($y = 0; $y < sizeof($totalTable[$x]); $y++) {
            $echo .= '<td>' . $totalTable[$x][$y] . '</td>';
        }
        $echo .= '</tr>
            ';
    }
    $echo .= '</table></div>';
    echo $echo;
    $refNo = '';
    //Was Approve Button Pressed
    if (isset($_POST['totalRows'])) {
        $totalRows = $_POST['totalRows'];
        for ($i = 0; $i <= $totalRows; $i++) {
            if (isset($_POST['hrEdit' . $i])) {
                $refNo = $_POST['refNo' . $i];
                echo '<input type="hidden"  name="editBtn1" value="Edit" />
                      <input type="hidden" name="requestID1" value="' . $refNo . '" />
                      <input type="hidden" value="2" name="totalRows" 
                        onLoad="this.form.action=' . "'?leave=true'" . '; this.form.submit()" />';
            }
            if (isset($_POST['deleteBtn' . $i])) {
                $refNo = $_POST['refNo' . $i];
                echo '</form>';
                $extraInputs = '<input type="hidden" value="View" name="viewDetailsBtn" />
                    <input type="hidden" name="empID" value="' . $_POST['empID'] . '" />
                     <input type="hidden" name="refNo' . $i . '" value="' . $refNo . '" />';
                expungeRequest($mysqli, $refNo, false, $deleteIndex = $i, $totalRows, $extraInputs);
            }
        }
    }
}