Commit 0051ca5e authored by Jean-Paul Saman's avatar Jean-Paul Saman

Fix changing of work period on new timesheets.

parent cb055bf6
...@@ -60,7 +60,7 @@ if ($del) { ...@@ -60,7 +60,7 @@ if ($del) {
} }
} else if ($workperiod) { } else if ($workperiod) {
if (!$obj->change_period($obj->timesheet_period)) { if (!$obj->change_period($obj->timesheet_period)) {
$AppUI->setMsg( "Timesheet workperiod failed", UI_MSG_ERROR ); $AppUI->setMsg( "Timesheet period failed", UI_MSG_ERROR );
} else { } else {
$AppUI->setMsg( "Timesheet period changed", UI_MSG_ALERT); $AppUI->setMsg( "Timesheet period changed", UI_MSG_ALERT);
$msg = "m=timesheet&a=addedit&timesheet_id=" . $obj->timesheet_id; $msg = "m=timesheet&a=addedit&timesheet_id=" . $obj->timesheet_id;
...@@ -70,7 +70,7 @@ if ($del) { ...@@ -70,7 +70,7 @@ if ($del) {
if (!$obj->store()) { if (!$obj->store()) {
$AppUI->setMsg( "Timesheet saving failed", UI_MSG_ERROR ); $AppUI->setMsg( "Timesheet saving failed", UI_MSG_ERROR );
} else { } else {
$isNotNew = $obj->timesheet_id; //_POST['timesheet_id']; $isNotNew = $obj->timesheet_id;
$AppUI->setMsg( $isNotNew ? 'Timesheet updated' : 'Timesheet inserted', UI_MSG_OK); $AppUI->setMsg( $isNotNew ? 'Timesheet updated' : 'Timesheet inserted', UI_MSG_OK);
} }
} }
......
...@@ -95,11 +95,11 @@ class CTimesheet extends w2p_Core_BaseObject { ...@@ -95,11 +95,11 @@ class CTimesheet extends w2p_Core_BaseObject {
return true; return true;
} }
protected function project_store() protected function project_store($workperiod)
{ {
// Get the current timesheet period // Get the current timesheet period
$period = new w2p_UtilitiesDate($_POST['timesheet_period']); $period = new w2p_Utilities_Date();
$period->setDate($_POST['timesheet_period'],DATE_FORMAT_UNIXTIME); $period->setDate($workperiod,DATE_FORMAT_UNIXTIME);
$q = $this->_getQuery(); $q = $this->_getQuery();
$q->addQuery('project_id'); $q->addQuery('project_id');
...@@ -217,40 +217,48 @@ class CTimesheet extends w2p_Core_BaseObject { ...@@ -217,40 +217,48 @@ class CTimesheet extends w2p_Core_BaseObject {
public function change_status() { public function change_status() {
$this->clearErrors(); $this->clearErrors();
if ($this->canEdit()) { if (!$this->canEdit())
$this->_action='updated'; return false;
$q = $this->_getQuery();
$q->addTable('timesheet'); if ($timesheet_id == 0) {
$q->addUpdate('timesheet_status', $this->timesheet_status); if (!$this->canCreate())
$q->addWhere('timesheet_id = ' . $this->timesheet_id);
if (!($q->exec())) {
$this->_error['change-status-timesheet'] = db_error();
return false; return false;
} $this->init();
return true;
} }
return false;
$q = $this->_getQuery();
$q->addTable('timesheet');
$q->addUpdate('timesheet_status', $this->timesheet_status);
$q->addWhere('timesheet_id = ' . $this->timesheet_id);
if (!($q->exec())) {
$this->_error['change-status-timesheet'] = db_error();
return false;
}
return true;
} }
public function change_period($period) { public function change_period($period) {
$result = false;
$this->clearErrors(); $this->clearErrors();
if ($this->canEdit()) { //if (!$this->canEdit())
$this->_action='updated'; // return false;
$q = $this->_getQuery(); if ($timesheet_id == 0) {
$q->addTable('timesheet'); if (!$this->canCreate())
$q->addUpdate('timesheet_period', $period); return false;
$q->addWhere('timesheet_id = ' . $this->timesheet_id); $this->init();
if (!($q->exec())) { }
$this->_error['change-period-timesheet'] = db_error();
return $result; $q = $this->_getQuery();
} $q->addTable('timesheet');
$result = true; $q->addUpdate('timesheet_period', $period);
$purge_result = $this->project_purge(); $q->addWhere('timesheet_id = ' . $this->timesheet_id);
$store_result = $this->project_store(); if (!($q->exec())) {
$result = $result && $purge_result && $store_result; $this->_error['change-period-timesheet'] = db_error();
return false;
} }
return $result; $purge_result = $this->project_purge();
$store_result = $this->project_store($period);
$timesheet_period = $period;
return $purge_result && $store_result;
} }
public function get_config() { public function get_config() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment