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" == "") { ...@@ -126,16 +126,22 @@ if ("$timesheet->timesheet_creator" == "") {
$q->Clear(); $q->Clear();
// Get the current timesheet period // 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(); $period = new w2p_Utilities_Date();
if (intval($timesheet->timesheet_period)) { if ($timesheet->timesheet_period) {
$period->setDate($timesheet->timesheet_period,DATE_FORMAT_UNIXTIME); $period->setDate($timesheet->timesheet_period,DATE_FORMAT_UNIXTIME);
} else { } else {
// Set the correct year // Set the correct year
if ( $config_options['book_year']['value'] != '' ) { if ( $config_options['timesheet_book_year'] != '' ) {
$period->setYear( intval($config_options['book_year']['value']) ); $period->setYear( intval($config_options['timesheet_book_year']) );
} }
$timesheet->timesheet_period = $period->getTime(); $timesheet->timesheet_period = $period->getTime();
} }
print "timesheet period " . $period->GetMonth() . "<br>";
// Get the current timesheet status // Get the current timesheet status
$status = $timesheet->timesheet_status; $status = $timesheet->timesheet_status;
...@@ -235,14 +241,14 @@ if (intval($timesheet->timesheet_worked)) { ...@@ -235,14 +241,14 @@ if (intval($timesheet->timesheet_worked)) {
echo '<td width="100%" align="right"">'; echo '<td width="100%" align="right"">';
if ( ($canEdit) && (($status == 0) || 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()"> <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) == '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> <option <?php if (intval($status) == '1') { echo "selected"; } ?> value="1"> <?php echo w2PformSafe('Submitted'); ?> </option>
<?php <?php
// Only the user with Timesheet Approval rights may set a timesheet to approved status. // 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> <option <?php if ($status == '2') { echo "selected"; } ?> value="2"> <?php echo w2PformSafe('Approved'); ?> </option>
<?php <?php
...@@ -267,7 +273,7 @@ if (intval($timesheet->timesheet_worked)) { ...@@ -267,7 +273,7 @@ if (intval($timesheet->timesheet_worked)) {
// If $status is not "Open for Editing" then don't allow to change the status. // 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. // There is one exception to this rule the 'administrator' can always change the status.
if ( ($canEdit) && (($status == 0) || 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';}" /> <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 <?php
......
...@@ -52,7 +52,7 @@ if ($del) { ...@@ -52,7 +52,7 @@ if ($del) {
$AppUI->setMsg( "Timesheet deleted", UI_MSG_ALERT); $AppUI->setMsg( "Timesheet deleted", UI_MSG_ALERT);
} }
} else if ($stat) { } else if ($stat) {
if (!$obj->change_status()) { if (!$obj->change_status($obj->timesheet_status)) {
$AppUI->setMsg( "Timesheet changing status failed", UI_MSG_ERROR ); $AppUI->setMsg( "Timesheet changing status failed", UI_MSG_ERROR );
} else { } else {
$AppUI->setMsg( "Timesheet status updated", UI_MSG_ALERT); $AppUI->setMsg( "Timesheet status updated", UI_MSG_ALERT);
......
...@@ -215,20 +215,21 @@ class CTimesheet extends w2p_Core_BaseObject { ...@@ -215,20 +215,21 @@ class CTimesheet extends w2p_Core_BaseObject {
return true; return true;
} }
public function change_status() { public function change_status($status) {
$this->clearErrors(); $this->clearErrors();
if (!$this->canEdit()) //if (!$this->canEdit())
return false; // return false;
if ($timesheet_id == 0) { //if ($timesheet_id == 0) {
if (!$this->canCreate()) // if (!$this->canCreate())
return false; // return false;
$this->init(); // $this->init();
} // $this->load(null, $timesheet_id);
//}
$q = $this->_getQuery(); $q = $this->_getQuery();
$q->addTable('timesheet'); $q->addTable('timesheet');
$q->addUpdate('timesheet_status', $this->timesheet_status); $q->addUpdate('timesheet_status', $status);
$q->addWhere('timesheet_id = ' . $this->timesheet_id); $q->addWhere('timesheet_id = ' . $this->timesheet_id);
if (!($q->exec())) { if (!($q->exec())) {
$this->_error['change-status-timesheet'] = db_error(); $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