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);
 }
 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);
 }
 function __construct($year, $month, $uid = null)
 {
     $this->db = Staple_DB::get();
     if ($uid == null) {
         //Get batchID
         $user = new userModel();
         $this->batch = $user->getBatchId();
     } else {
         $user = new userModel($uid);
     }
     //Current Dates
     $currentDate = new DateTime();
     $currentDate->setTime(0, 0, 0);
     $currentDate->setDate($year, $month, 1);
     $this->currentYear = $currentDate->format('Y');
     $this->currentMonth = $currentDate->format('m');
     $this->currentMonthText = $currentDate->format('F');
     $this->startDate = $currentDate->modify('-1 month +25 day')->format('Y-m-d');
     $this->startDateTimeString = $currentDate->format('U');
     $currentDate->setDate($year, $month, 1);
     $currentDate->modify('+24 day');
     $currentDate->setTime(23, 59, 59);
     $this->endDate = $currentDate->format('Y-m-d');
     $this->endDateTimeString = $currentDate->format('U');
     //Previous Dates
     $previousDate = new DateTime();
     $previousDate->setTime(0, 0, 0);
     $previousDate->setDate($year, $month, 1);
     $previousDate->modify('-1 month');
     $this->previousMonth = $previousDate->format('m');
     $this->previousMonthText = $previousDate->format('F');
     $previousDate->setDate($year, $month, 1);
     $previousDate->modify('-1 year');
     $this->previousYear = $previousDate->format('Y');
     //Future Dates
     $furtureDate = new DateTime();
     $furtureDate->setTime(23, 59, 59);
     $furtureDate->setDate($year, $month, 1);
     $furtureDate->modify('+1 month');
     $this->nextMonth = $furtureDate->format('m');
     $this->nextMonthText = $furtureDate->format('F');
     $furtureDate->setDate($year, $month, 1);
     $furtureDate->modify('+1 year');
     $this->nextYear = $furtureDate->format('Y');
     //Time Entries
     $this->entries = $this->timeEntries($uid);
     $timeCode = new codeModel();
     //Get time code totals
     $totals = array();
     foreach ($timeCode->allCodes() as $code) {
         $codeId = $timeCode->getIdFor($code);
         $totals[$code] = $this->calculatedTotals($codeId['id'], $this->startDate, $this->endDate, $uid);
     }
     $totals['Total Time'] = array_sum($totals);
     $this->setTotals($totals);
     $this->userId = $user->getId();
 }
 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')) . "");
     }
 }