Commit 28807ad4 authored by Jean-Paul Saman's avatar Jean-Paul Saman

Fix changing of timesheet status

parent feac3d38
......@@ -126,16 +126,22 @@ if ("$timesheet->timesheet_creator" == "") {
$q->Clear();
// Get the current timesheet period
// FIXME: after changing timesheet_status a new timesheet is opened
// instead of the one we changed. All information is then mixed from
// the old timesheet and new timesheet. Luckily the database is not
// updated with the 'new' timesheet
// print "timesheet id " . $timesheet->timesheet_id . "<br";
$period = new w2p_Utilities_Date();
if (intval($timesheet->timesheet_period)) {
if ($timesheet->timesheet_period) {
$period->setDate($timesheet->timesheet_period,DATE_FORMAT_UNIXTIME);
} else {
// Set the correct year
if ( $config_options['book_year']['value'] != '' ) {
$period->setYear( intval($config_options['book_year']['value']) );
if ( $config_options['timesheet_book_year'] != '' ) {
$period->setYear( intval($config_options['timesheet_book_year']) );
}
$timesheet->timesheet_period = $period->getTime();
}
print "timesheet period " . $period->GetMonth() . "<br>";
// Get the current timesheet status
$status = $timesheet->timesheet_status;
......@@ -235,14 +241,14 @@ if (intval($timesheet->timesheet_worked)) {
echo '<td width="100%" align="right"">';
if ( ($canEdit) && (($status == 0) ||
($config_options['approval_by']['value'] == $AppUI->user_id)) ) {
($config_options['timesheet_approval_by'] == $AppUI->user_id)) ) {
?>
<select name="timesheet_status" size="1" class="text" onChange="changeIt()">
<option <?php if (intval($status) == '0') { echo "selected"; } ?> value="0"> <?php echo w2PformSafe('Open for Editing'); ?> </option>
<option <?php if (intval($status) == '1') { echo "selected"; } ?> value="1"> <?php echo w2PformSafe('Submitted'); ?> </option>
<?php
// Only the user with Timesheet Approval rights may set a timesheet to approved status.
if ( $config_options['approval_by']['value'] == $AppUI->user_id ) {
if ( $config_options['timesheet_approval_by'] == $AppUI->user_id ) {
?>
<option <?php if ($status == '2') { echo "selected"; } ?> value="2"> <?php echo w2PformSafe('Approved'); ?> </option>
<?php
......@@ -267,7 +273,7 @@ if (intval($timesheet->timesheet_worked)) {
// If $status is not "Open for Editing" then don't allow to change the status.
// There is one exception to this rule the 'administrator' can always change the status.
if ( ($canEdit) && (($status == 0) ||
($config_options['approval_by']['value'] == $AppUI->user_id)) ) {
($config_options['timesheet_approval_by'] == $AppUI->user_id)) ) {
?>
<input class="button" type="button" name="cancel" value="<?php echo $AppUI->_('cancel'); ?>" onClick="javascript:if(confirm('Are you sure you want to cancel.')){location.href = './index.php?m=timesheet';}" />
<?php
......
......@@ -52,7 +52,7 @@ if ($del) {
$AppUI->setMsg( "Timesheet deleted", UI_MSG_ALERT);
}
} else if ($stat) {
if (!$obj->change_status()) {
if (!$obj->change_status($obj->timesheet_status)) {
$AppUI->setMsg( "Timesheet changing status failed", UI_MSG_ERROR );
} else {
$AppUI->setMsg( "Timesheet status updated", UI_MSG_ALERT);
......
......@@ -215,20 +215,21 @@ class CTimesheet extends w2p_Core_BaseObject {
return true;
}
public function change_status() {
public function change_status($status) {
$this->clearErrors();
if (!$this->canEdit())
return false;
//if (!$this->canEdit())
// return false;
if ($timesheet_id == 0) {
if (!$this->canCreate())
return false;
$this->init();
}
//if ($timesheet_id == 0) {
// if (!$this->canCreate())
// return false;
// $this->init();
// $this->load(null, $timesheet_id);
//}
$q = $this->_getQuery();
$q->addTable('timesheet');
$q->addUpdate('timesheet_status', $this->timesheet_status);
$q->addUpdate('timesheet_status', $status);
$q->addWhere('timesheet_id = ' . $this->timesheet_id);
if (!($q->exec())) {
$this->_error['change-status-timesheet'] = db_error();
......
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