/**
  * 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');
 }
 /**
  * Used to enhance the provided timesheet with data from other tables.
  *
  * @param obj The timesheet object to enhance.
  *
  * @return Returns the enhanced timesheet.
  */
 public function enhanceTimesheet($obj)
 {
     // Set the other timesheet information.
     if (is_numeric($obj->id)) {
         // Set the bills in the timesheet.
         $billDao = new BillDao();
         $obj->bills = $billDao->getForTimesheet($obj->id, $obj->employee_id);
         // Set the employee.
         $employeeDao = new EmployeeDao();
         $obj->employee = $employeeDao->get($obj->employee_id);
         // Set the audit log info.
         $auditLogDao = new AuditLogDao();
         $obj->audit_log = $auditLogDao->getForTimesheet($obj->id);
         // Set the pay period.
         $payPeriodDao = new PayPeriodDao();
         $obj->pay_period = $payPeriodDao->get($obj->pp_start);
         // Set the employee's contracts.
         $contractDao = new ContractDao();
         $obj->contracts = $contractDao->getEmployeeContractsForPayPeriod($obj->employee_id, $obj->pay_period);
         // Set the holidays.
         $holidayDao = new HolidayDao();
         $obj->holidays = $holidayDao->getForPayPeriod($obj->pay_period);
     }
     // Perform post-processing.
     $this->postProcess($obj);
     // Return the enhanced timesheet object.
     return $obj;
 }
 /**
  * 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');
 }