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) {
}
} else if ($workperiod) {
if (!$obj->change_period($obj->timesheet_period)) {
$AppUI->setMsg( "Timesheet workperiod failed", UI_MSG_ERROR );
$AppUI->setMsg( "Timesheet period failed", UI_MSG_ERROR );
} else {
$AppUI->setMsg( "Timesheet period changed", UI_MSG_ALERT);
$msg = "m=timesheet&a=addedit&timesheet_id=" . $obj->timesheet_id;
......@@ -70,7 +70,7 @@ if ($del) {
if (!$obj->store()) {
$AppUI->setMsg( "Timesheet saving failed", UI_MSG_ERROR );
} else {
$isNotNew = $obj->timesheet_id; //_POST['timesheet_id'];
$isNotNew = $obj->timesheet_id;
$AppUI->setMsg( $isNotNew ? 'Timesheet updated' : 'Timesheet inserted', UI_MSG_OK);
}
}
......
......@@ -95,11 +95,11 @@ class CTimesheet extends w2p_Core_BaseObject {
return true;
}
protected function project_store()
protected function project_store($workperiod)
{
// Get the current timesheet period
$period = new w2p_UtilitiesDate($_POST['timesheet_period']);
$period->setDate($_POST['timesheet_period'],DATE_FORMAT_UNIXTIME);
$period = new w2p_Utilities_Date();
$period->setDate($workperiod,DATE_FORMAT_UNIXTIME);
$q = $this->_getQuery();
$q->addQuery('project_id');
......@@ -217,40 +217,48 @@ class CTimesheet extends w2p_Core_BaseObject {
public function change_status() {
$this->clearErrors();
if ($this->canEdit()) {
$this->_action='updated';
$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();
if (!$this->canEdit())
return false;
if ($timesheet_id == 0) {
if (!$this->canCreate())
return false;
}
return true;
$this->init();
}
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) {
$result = false;
$this->clearErrors();
if ($this->canEdit()) {
$this->_action='updated';
$q = $this->_getQuery();
$q->addTable('timesheet');
$q->addUpdate('timesheet_period', $period);
$q->addWhere('timesheet_id = ' . $this->timesheet_id);
if (!($q->exec())) {
$this->_error['change-period-timesheet'] = db_error();
return $result;
}
$result = true;
$purge_result = $this->project_purge();
$store_result = $this->project_store();
$result = $result && $purge_result && $store_result;
//if (!$this->canEdit())
// return false;
if ($timesheet_id == 0) {
if (!$this->canCreate())
return false;
$this->init();
}
$q = $this->_getQuery();
$q->addTable('timesheet');
$q->addUpdate('timesheet_period', $period);
$q->addWhere('timesheet_id = ' . $this->timesheet_id);
if (!($q->exec())) {
$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() {
......
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