예제 #1
0
 public function _start()
 {
     $this->setLayout('editFormLayout');
     $this->setName('editTimeForm');
     $date = new Staple_Form_FoundationTextElement('date', 'Date');
     $date->setRequired()->addValidator(new Staple_Form_Validate_Length('1', '10'))->addValidator(new Staple_Form_Validate_Date())->addAttrib('placeholder', 'mm/dd/yyyy');
     $inTime = new Staple_Form_FoundationTextElement('inTime', 'Time In');
     $inTime->setRequired()->addFilter(new Staple_Form_Filter_Trim())->addValidator(new Staple_Form_Validate_Length('1', '8'))->addValidator(new Staple_Form_Validate_Regex('/^(0|[0-9]|1[012]):[0-5][0-9] ?((a|p)m|(A|P)M)$/', 'Invalid time format. Expected format: h:mm am/pm.'))->addAttrib('placeholder', 'h:mm am/pm');
     $outTime = new Staple_Form_FoundationTextElement('outTime', 'Time Out');
     $outTime->setRequired()->addFilter(new Staple_Form_Filter_Trim())->addValidator(new Staple_Form_Validate_Length('1', '8'))->addValidator(new Staple_Form_Validate_Regex('/^(0|[0-9]|1[012]):[0-5][0-9] ?((a|p)m|(A|P)M)$/', 'Invalid time format. Expected format: h:mm am/pm.'))->addAttrib('placeholder', 'h:mm am/pm');
     $lessTime = new Staple_Form_FoundationSelectElement('lessTime', 'Less Time');
     $lessTime->setRequired()->addOptionsArray(array("0" => "None", "60" => "1 Hour", "30" => "30 Minutes"))->addValidator(new Staple_Form_Validate_InArray(array('0', '60', '30')));
     $timeCodes = new codeModel();
     $code = new Staple_Form_FoundationSelectElement('code', 'Code');
     $code->setRequired()->addOptionsArray($timeCodes->allCodes());
     $submit = new Staple_Form_FoundationSubmitElement('submit', 'Update');
     $submit->addClass('button success expand radius');
     $this->addField($date, $inTime, $outTime, $lessTime, $code, $submit);
 }
예제 #2
0
 public function _start()
 {
     $auth = Staple_Auth::get();
     $user = new userModel();
     $user->userInfo($auth->getAuthId());
     $this->accountLevel = $user->getAuthLevel();
     $this->setLayout('insertFormLayout');
     $this->setName('insertTimeForm')->setAction($this->link(array('timesheet')));
     $date = new Staple_Form_FoundationTextElement('date', 'Date');
     $date->setRequired()->addValidator(new Staple_Form_Validate_Date())->addAttrib('placeholder', 'mm/dd/yyyy');
     $inTime = new Staple_Form_FoundationTextElement('inTime', 'Time In');
     $inTime->setRequired()->addFilter(new Staple_Form_Filter_Trim())->addValidator(new Staple_Form_Validate_Regex('/^(0|[0-9]|1[012]):[0-5][0-9] ?((a|p)m|(A|P)M)$/', 'Invalid time format. Expected format: h:mm am/pm.'))->addAttrib('placeholder', 'h:mm am/pm');
     $outTime = new Staple_Form_FoundationTextElement('outTime', 'Time Out');
     $outTime->setRequired()->addFilter(new Staple_Form_Filter_Trim())->addValidator(new Staple_Form_Validate_Regex('/^(0|[0-9]|1[012]):[0-5][0-9] ?((a|p)m|(A|P)M)$/', 'Invalid time format. Expected format: h:mm am/pm.'))->addAttrib('placeholder', 'h:mm am/pm');
     $lessTime = new Staple_Form_FoundationSelectElement('lessTime', 'Less Time');
     $lessTime->setRequired()->addOptionsArray(array("0" => "None", "60" => "1 Hour", "30" => "30 Minutes"))->addValidator(new Staple_Form_Validate_InArray(array('0', '60', '30')));
     $timeCodes = new codeModel();
     $code = new Staple_Form_FoundationSelectElement('code', 'Code');
     $code->setRequired()->addOption("x", "Select an option")->addOptionsArray($timeCodes->allCodes())->addValidator(new Staple_Form_Validate_InArray(array_keys($timeCodes->allCodes())));
     $code->setValue($timeCodes->getIdFor('Normal')['id']);
     $submit = new Staple_Form_FoundationSubmitElement('submit', 'Submit');
     $submit->addClass('button expand radius');
     $this->addField($date, $inTime, $outTime, $lessTime, $code, $submit);
 }
예제 #3
0
 function calculatedTotals($code, $startDate, $endDate, $uid = null)
 {
     //Get user ID from Auth
     $user = new userModel();
     if ($uid == null) {
         $userId = $user->getId();
     } else {
         $account = $user->userInfo($uid);
         $userId = $account['id'];
     }
     $sql = "SELECT codeId, inTime, outTime, lessTime FROM timeEntries WHERE inTime > UNIX_TIMESTAMP('{$startDate} 00:00:00') AND outTime < UNIX_TIMESTAMP('{$endDate} 23:59:59') AND userId = {$userId} AND codeId = {$code};";
     if ($this->db->query($sql)->fetch_row() > 0) {
         $query = $this->db->query($sql);
         $total = 0;
         while ($result = $query->fetch_assoc()) {
             $inTime = $result['inTime'];
             $outTime = $result['outTime'];
             switch ($result['lessTime']) {
                 case 60:
                     $lessTime = 1;
                     break;
                 case 30:
                     $lessTime = 0.5;
                     break;
                 case 15:
                     $lessTime = 0.25;
                     break;
                 default:
                     $lessTime = 0;
             }
             $roundedInTime = $this->nearestQuarterHour($inTime);
             $roundedOutTime = $this->nearestQuarterHour($outTime);
             $lapse = $roundedOutTime - $roundedInTime;
             $lapseHours = gmdate('H:i', $lapse);
             $decimalHours = $this->timeToDecimal($lapseHours);
             $total = $total + $decimalHours;
             $total = $total - $lessTime;
             $code = new codeModel();
             $codeId = $code->getIdFor("Unpaid Leave");
             if ($codeId['id'] == $result['codeId']) {
                 $total = -1 * $total;
             }
         }
         return $total;
     } else {
         return 0;
     }
 }
예제 #4
0
 function __construct($id = null)
 {
     $this->db = Staple_DB::get();
     if ($id !== null) {
         $sql = "SELECT * FROM timeEntries WHERE id = '" . $this->db->real_escape_string($id) . "'";
         if ($this->db->query($sql)->fetch_row() > 0) {
             $query = $this->db->query($sql);
             $result = $query->fetch_assoc();
             //Set ID and Date
             $this->setId($result['id']);
             $this->setBatchId($result['batchId']);
             $this->setDate(date("m/d/Y", $result['inTime']));
             $this->setFullDate(date("l, F jS Y", $result['inTime']));
             //Set inTime
             $inTime = new DateTime();
             $inTime->setTimestamp($result['inTime']);
             $this->setInTime($inTime->format('g:i A'));
             $this->setInTimeRaw($result['inTime']);
             $this->setRoundedInTime($this->nearestQuarterHour($result['inTime']));
             $this->setInTimeDate(date("Y-m-d", $result['inTime']));
             //Out Time
             $outTime = new DateTime();
             $outTime->setTimestamp($result['outTime']);
             $this->setOutTime($outTime->format('g:i A'));
             $this->setOutTimeRaw($result['outTime']);
             $this->setRoundedOutTime($this->nearestQuarterHour($result['outTime']));
             $this->setOutTimeDate(date("Y-m-d", $result['outTime']));
             $this->setLessTime($result['lessTime']);
             //Calculate Time Worked
             switch ($result['lessTime']) {
                 case 60:
                     $lessTime = 1;
                     break;
                 case 30:
                     $lessTime = 0.5;
                     break;
                 case 15:
                     $lessTime = 0.25;
                     break;
                 default:
                     $lessTime = 0;
             }
             //Total Worked Time
             $dateTime1 = new DateTime($this->roundedInTime);
             $dateTime1->setDate(date('Y', strtotime($this->inTimeDate)), date('m', strtotime($this->inTimeDate)), date('d', strtotime($this->inTimeDate)));
             $dateTime2 = new DateTime($this->roundedOutTime);
             $dateTime2->setDate(date('Y', strtotime($this->outTimeDate)), date('m', strtotime($this->outTimeDate)), date('d', strtotime($this->outTimeDate)));
             $interval = $dateTime1->diff($dateTime2);
             $timeWorked = $this->timeToDecimal($interval->h . ":" . $interval->i) - $lessTime;
             if ($timeWorked !== 0) {
                 $this->setTimeWorked($timeWorked);
             } else {
                 $this->setTimeWorked(0);
             }
             //Get Code Information
             $code = new codeModel();
             $this->setCodeId($result['codeId']);
             $code->load($result['codeId']);
             $this->setCodeName($code->getName());
             $this->setUserId($result['userId']);
             $this->setTimestamp($result['timestamp']);
             $this->setNote($result['note']);
             return true;
         }
     }
 }
예제 #5
0
 function calculateEntry($id)
 {
     $sql = "\n            SELECT * FROM timeEntries WHERE id = '" . $this->db->real_escape_string($id) . "';\n        ";
     $query = $this->db->query($sql);
     $result = $query->fetch_assoc();
     //Set inTime
     $inTime = new DateTime();
     $inTime->setTimestamp($result['inTime']);
     $roundedInTime = $this->nearestQuarterHour($result['inTime']);
     $inTimeRaw = $result['inTime'];
     $inTimeDate = date("Y-m-d", $result['inTime']);
     //Out Time
     $outTime = new DateTime();
     $outTime->setTimestamp($result['outTime']);
     $roundedOutTime = $this->nearestQuarterHour($result['outTime']);
     $outTimeRaw = $result['outTime'];
     $roundedOutTime = $this->nearestQuarterHour($result['outTime']);
     $outTimeDate = date("Y-m-d", $result['outTime']);
     $lessTime = $result['lessTime'];
     $timestamp = $result['timestamp'];
     $note = $result['note'];
     //Calculate Time Worked
     switch ($result['lessTime']) {
         case 60:
             $lessTime = 1;
             break;
         case 30:
             $lessTime = 0.5;
             break;
         case 15:
             $lessTime = 0.25;
             break;
         default:
             $lessTime = 0;
     }
     //Total Worked Time
     $dateTime1 = new DateTime($roundedInTime);
     $dateTime1->setDate(date('Y', strtotime($inTimeDate)), date('m', strtotime($inTimeDate)), date('d', strtotime($inTimeDate)));
     $dateTime2 = new DateTime($roundedOutTime);
     $dateTime2->setDate(date('Y', strtotime($outTimeDate)), date('m', strtotime($outTimeDate)), date('d', strtotime($outTimeDate)));
     $interval = $dateTime1->diff($dateTime2);
     $timeWorked = $this->timeToDecimal($interval->h . ":" . $interval->i) - $lessTime;
     if ($timeWorked !== 0) {
         $timeWorked = $timeWorked;
     } else {
         $timeWorked = 0;
     }
     //Get Code Information
     $code = new codeModel();
     $codeId = $result['codeId'];
     $code->load($result['codeId']);
     $codeName = $code->getName();
     $data['date'] = date('Y-m-d', $inTimeRaw);
     $data['inTime'] = $inTimeRaw;
     $data['outTime'] = $outTimeRaw;
     $data['lessTime'] = $lessTime;
     $data['timeWorked'] = $timeWorked;
     $data['code'] = $codeName;
     $data['timestamp'] = $timestamp;
     $data['note'] = $note;
     //Get the user of the entry.
     $entry = new timeEntryModel($id);
     if ($entry->validated($id, $result['userId'])) {
         $data['validated'] = 0;
     } else {
         $data['validated'] = 1;
     }
     return $data;
 }
예제 #6
0
 public function payrollprint($year = null, $month = null)
 {
     if ($year != null || $month != null) {
         $this->_setLayout('print');
         if ($year == null) {
             $year = date('Y');
         }
         if ($month == null) {
             $month = date('m');
         }
         $this->view->year = $year;
         $date = new DateTime();
         $date->setDate($year, $month, 26);
         $date->setTime(0, 0, 0);
         $this->view->month = $date->format('m');
         $date->modify('-1 month');
         $this->view->previousMonth = $date->format('m');
         $date2 = new DateTime();
         $date2->setDate($year, $month, 25);
         $date2->setTime(24, 0, 0);
         $interval = date_diff($date, $date2);
         $this->view->span = $interval->days;
         $reports = new reportModel($year, $month);
         $this->view->report = $reports->payroll($year, $month);
         $this->view->startDate = $date->format("F jS Y");
         $days = $interval->days - 1;
         $date->modify("+{$days} days");
         $this->view->endDate = $date->format("F jS Y");
         $codes = new codeModel();
         $this->view->codes = $codes->allCodes();
     } else {
         header("location:" . $this->_link(array('reports', 'payroll')) . "");
     }
 }