/**
  * Retrieve the previous pay period and show the employee timesheets.
  */
 function prevAction()
 {
     // Set the page title.
     $this->view->title = "Payroll Timesheets";
     // Get the requested date.
     $day = $this->getDate('day');
     // Get the ids of the employees whose timesheets are to be displayed.
     $ids = $this->getInts('ids');
     // Retrieve the current pay period and save it to the view.
     $payPeriodDao = new PayPeriodDao();
     $payPeriod = $payPeriodDao->getContaining($day);
     // Get the previous pay period.
     $prev = PayPeriodHelper::getPrev($payPeriod);
     // Attempt to retrieve the previous pay period from the database.
     $realprev = $payPeriodDao->get($prev->start);
     // Make sure it was found.
     if (!isset($realprev)) {
         // Create the new pay period.
         $payPeriodDao->add(array('start' => $prev->start, 'end' => $prev->end, 'type' => $prev->type));
         $realprev = $prev;
     }
     // Get the previous pay period.
     $this->view->payPeriod = $realprev;
     // Save the active pay period in the session.
     $session = new Zend_Session_Namespace('Web');
     $session->activePayPeriod = $this->view->payPeriod;
     // Get the DAO.
     $timesheetDao = new TimesheetDao();
     // This will hold all the timesheets.
     $this->view->timesheets = array();
     // Retrieve all the timesheets.
     foreach ($ids as $id) {
         $this->view->timesheets[] = $timesheetDao->getForEmployee($id, $this->view->payPeriod);
     }
     // Set the timesheet layout for this action.
     $this->_helper->layout->setLayout('timesheet');
     // Render the view.phtml page.
     $this->render('view');
 }
 /**
  * Retrieve the previous pay period and go back to the payroll page.
  */
 function prevAction()
 {
     // Set the page title.
     $this->view->title = "Payroll Management";
     // Get the requested date.
     $day = $this->getDate('day');
     // Retrieve the current pay period and save it to the view.
     $payPeriodDao = new PayPeriodDao();
     $payPeriod = $payPeriodDao->getContaining($day);
     // Get the previous pay period.
     $prev = PayPeriodHelper::getPrev($payPeriod);
     // Attempt to retrieve the previous pay period from the database.
     $realprev = $payPeriodDao->get($prev->start);
     // Make sure it was found.
     if (!isset($realprev)) {
         // Create the new pay period.
         $payPeriodDao->add(array('start' => $prev->start, 'end' => $prev->end, 'type' => $prev->type));
         $realprev = $prev;
     }
     // Get the previous pay period.
     $this->view->payPeriod = $realprev;
     // Save the active pay period in the session.
     $session = new Zend_Session_Namespace('Web');
     $session->activePayPeriod = $this->view->payPeriod;
     // Set the manage layout for this action.
     $this->_helper->layout->setLayout('manage');
     // Include the payroll management scripts on the page.
     $this->view->scripts = "payroll";
     // Use the index view.
     $this->render('index');
 }
Example #3
0
 /**
  * Populate the pay periods up through the current pay period.
  *
  * @return Returns the current timesheet after it is created.
  */
 public function addThroughCurrent()
 {
     // Get the latest pay period.
     $latest = $this->getLatest();
     // Get the milliseconds for right now.
     $now = strtotime(date('Y-m-d'));
     // Make sure the latest pay period was found.
     while (isset($latest) && !PayPeriodHelper::isCurrent($latest)) {
         // Get the next pay period.
         $latest = PayPeriodHelper::getNext($latest);
         // Add this pay period to the database.
         $this->add(array('start' => $latest->start, 'end' => $latest->end, 'type' => $latest->type));
     }
     // Return the latest pay period, which is the current pay period.
     return $latest;
 }
 /**
  * Retrieve the next timesheet and show it on the timesheet page.
  */
 function nextAction()
 {
     // Set the page title.
     $this->view->title = "Viewer";
     // Get the current pay period start date.
     $currstart = $this->getStr('currstart');
     // Attempt to convert the current start time into a date.
     if (!strtotime($currstart)) {
         // Throw an exception.
         throw new Exception("Invalid pay period start date passed into " . "the timesheet controller: {$currstart}");
     }
     // Get the requested pay period.
     $payPeriodDao = new PayPeriodDao();
     $payPeriod = $payPeriodDao->get($currstart);
     // Get the next pay period.
     $next = PayPeriodHelper::getNext($payPeriod);
     // Attempt to retrieve the next pay period from the database.
     $realnext = $payPeriodDao->get($next->start);
     // Make sure it was found.
     if (!isset($realnext)) {
         // Create the new pay period.
         $payPeriodDao->add(array('start' => $next->start, 'end' => $next->end, 'type' => $next->type));
         $realnext = $next;
     }
     // Get the employee id.
     $id = $this->view->employee->id;
     // Get the employee's latest timesheet and save it to the view.
     $timesheetDao = new TimesheetDao();
     $this->view->timesheet = $timesheetDao->getForEmployee($id, $realnext);
     // Set the timesheet layout for this action.
     $this->_helper->layout->setLayout('timesheet');
     // Render the timesheet using the index view.
     $this->render('index');
 }