Exemplo n.º 1
0
 public function testCRUD()
 {
     midcom::get('auth')->request_sudo('org.openpsa.projects');
     $report = new org_openpsa_projects_hour_report_dba();
     $report->task = self::$_task->id;
     $report->hours = 2.5;
     $stat = $report->create();
     $this->assertTrue($stat);
     $this->register_object($report);
     $parent = $report->get_parent();
     $this->assertEquals($parent->guid, self::$_task->guid);
     self::$_task->refresh();
     $this->assertEquals(self::$_task->reportedHours, 2.5);
     $task_hours = self::$_project->get_task_hours();
     $this->assertEquals($task_hours['reportedHours'], 2.5);
     $report->invoiceable = true;
     $report->hours = 3.5;
     $stat = $report->update();
     $this->assertTrue($stat);
     self::$_task->refresh();
     $this->assertEquals(self::$_task->invoiceableHours, 3.5);
     $task_hours = self::$_project->get_task_hours();
     $this->assertEquals($task_hours['reportedHours'], 3.5);
     $stat = $report->delete();
     $this->assertTrue($stat);
     self::$_task->refresh();
     $this->assertEquals(self::$_task->reportedHours, 0);
     $task_hours = self::$_project->get_task_hours();
     $this->assertEquals($task_hours['reportedHours'], 0);
     midcom::get('auth')->drop_sudo();
 }
Exemplo n.º 2
0
 /**
  * DM2 creation callback
  */
 public function &dm2_create_callback(&$controller)
 {
     $this->_hour_report = new org_openpsa_projects_hour_report_dba();
     if ($task = $controller->formmanager->get_value('task')) {
         $this->_hour_report->task = $task;
     } else {
         if ($this->_request_data['task']) {
             $this->_hour_report->task = $this->_request_data['task'];
         }
     }
     if (!$this->_hour_report->create()) {
         debug_print_r('We operated on this object:', $this->_hour_report);
         throw new midcom_error("Failed to create a new hour_report under hour_report group #{$this->_request_data['task']}. Error: " . midcom_connection::get_error_string());
     }
     return $this->_hour_report;
 }
Exemplo n.º 3
0
 /**
  * Report hours based on time used
  *
  * @return boolean
  */
 private function _report_hours($description, $invoiceable = false)
 {
     $hour_report = new org_openpsa_projects_hour_report_dba();
     $hour_report->invoiceable = $invoiceable;
     $hour_report->date = $this->start;
     $hour_report->person = $this->person->id;
     $hour_report->task = $this->task->id;
     $hour_report->description = $description;
     $hour_report->hours = $this->time / 3600;
     $stat = $hour_report->create();
     if (!$stat) {
         midcom::get('uimessages')->add(midcom::get('i18n')->get_string('org.openpsa.mypage', 'org.openpsa.mypage'), sprintf(midcom::get('i18n')->get_string('reporting %d hours to task %s failed, reason %s', 'org.openpsa.mypage'), $hour_report->hours, $this->task->title, midcom_connection::get_error_string()), 'error');
         return false;
     }
     //apply minimum_time_slot
     $hour_report->modify_hours_by_time_slot();
     midcom::get('uimessages')->add(midcom::get('i18n')->get_string('org.openpsa.mypage', 'org.openpsa.mypage'), sprintf(midcom::get('i18n')->get_string('successfully reported %d hours to task %s', 'org.openpsa.mypage'), $hour_report->hours, $this->task->title), 'ok');
     return true;
 }