Commit 99a941fd authored by Jean-Paul Saman's avatar Jean-Paul Saman

Fix timesheet creation and month selection.

After initial creation timesheet_period can be changed. The second time it is edited this is no longer possible. Either:
1) Fix 2nd time editing, or
2) Make checkbox non-modifiable for 2nd time opening.

BUGS:
1) Changing from "submitted" to "open for editing" by administrator doesn't work
2) Changing from "approved" to "open for editing" by adminstrator doesn't work
3) Status combobox show always "open for editing" as status even when it is one of the other statuses
4) Inserting 2 timesheets with the exact same month and year is not considered an error, while this should not be allowed.
5) Delete icon from timesheet overview doesn't work. It will forward you to timesheet details instead. You can delete the timesheet from there.

TODO:
- Remove debug statements
- Show Customer in timesheet details
- Show Customer in timesheet overview
- Show total amount of hours worked in timesheet details
- Show total amount of days worked in timesheet details
- Show total amount of days worked in timesheet overview
parent 5abe59c3
...@@ -128,12 +128,11 @@ if ("$obj->timesheet_creator" == "") { ...@@ -128,12 +128,11 @@ if ("$obj->timesheet_creator" == "") {
$q->Clear(); $q->Clear();
// Get the current timesheet period // Get the current timesheet period
$period = new CDate();
if (intval($obj->timesheet_period)) { if (intval($obj->timesheet_period)) {
$period = new CDate();
$period->setDate($obj->timesheet_period,DATE_FORMAT_UNIXTIME); $period->setDate($obj->timesheet_period,DATE_FORMAT_UNIXTIME);
} else { } else {
$period = new CDate(); $obj->timesheet_period = $period->getTime();
$obj->timesheet_period = $period->getDate();
} }
// Get the current timesheet status // Get the current timesheet status
...@@ -145,11 +144,10 @@ else { ...@@ -145,11 +144,10 @@ else {
} }
// Get the current timesheet creation date // Get the current timesheet creation date
$creation_date = new CDate();
if (intval($obj->timesheet_date)) { if (intval($obj->timesheet_date)) {
$creation_date = new CDate();
$creation_date->setDate($obj->timesheet_date,DATE_FORMAT_UNIXTIME); $creation_date->setDate($obj->timesheet_date,DATE_FORMAT_UNIXTIME);
} else { } else {
$creation_date = new CDate();
$obj->timesheet_date = $creation_date->getTime(); $obj->timesheet_date = $creation_date->getTime();
} }
...@@ -172,7 +170,6 @@ if (intval($obj->timesheet_worked)) { ...@@ -172,7 +170,6 @@ if (intval($obj->timesheet_worked)) {
// or in case of mouse click on the delete icon it will set to '1' by javaScript (delete object with given timesheet_id) // or in case of mouse click on the delete icon it will set to '1' by javaScript (delete object with given timesheet_id)
echo '<input type="hidden" name="del" value="0" />'; echo '<input type="hidden" name="del" value="0" />';
echo '<input type="hidden" name="stat" value="0" />'; echo '<input type="hidden" name="stat" value="0" />';
echo '<input type="hidden" name="workperiod" value="0" />';
// the value of timesheet_id will be the id of the timesheet to edit // the value of timesheet_id will be the id of the timesheet to edit
// or in case of addition of a new timesheet it will contain '0' as value // or in case of addition of a new timesheet it will contain '0' as value
...@@ -195,36 +192,50 @@ if (intval($obj->timesheet_worked)) { ...@@ -195,36 +192,50 @@ if (intval($obj->timesheet_worked)) {
echo '<td width="100%">'; echo '<td width="100%">';
if ( ($canEdit) && ($status < 1) ) { if ( ($canEdit) && ($status < 1) ) {
$newdate = new CDate();
$newdate->setDate($obj->timesheet_period,DATE_FORMAT_UNIXTIME);
$newdate->setMonth(1);
?> ?>
<select name="ts_period" size="1' class="text" onChange="periodChange();"> <select name="timesheet_period" size="1' class="text" onChange="periodChange();">
<option <?php if ($period->getMonth() == 1) echo "selected"; ?> value="1"><? echo dPformSafe('January'); ?></option> <option <?php if ($period->getMonth() == 1) echo "selected"; ?> value=<?php echo '"'. $newdate->getTime() .'"'; ?>><? echo dPformSafe('January'); ?></option> <?php $newdate->setMonth(2); ?>
<option <?php if ($period->getMonth() == 2) echo "selected"; ?> value="2"><? echo dPformSafe('February'); ?></option> <option <?php if ($period->getMonth() == 2) echo "selected"; ?> value=<?php echo '"'. $newdate->getTime() .'"'; ?>><? echo dPformSafe('February'); ?></option> <?php $newdate->setMonth(3); ?>
<option <?php if ($period->getMonth() == 3) echo "selected"; ?> value="3"><? echo dPformSafe('March'); ?></option> <option <?php if ($period->getMonth() == 3) echo "selected"; ?> value=<?php echo '"'. $newdate->getTime() .'"'; ?>><? echo dPformSafe('March'); ?></option> <?php $newdate->setMonth(4); ?>
<option <?php if ($period->getMonth() == 4) echo "selected"; ?> value="4"><? echo dPformSafe('April'); ?></option> <option <?php if ($period->getMonth() == 4) echo "selected"; ?> value=<?php echo '"'. $newdate->getTime() .'"'; ?>><? echo dPformSafe('April'); ?></option> <?php $newdate->setMonth(5); ?>
<option <?php if ($period->getMonth() == 5) echo "selected"; ?> value="5"><? echo dPformSafe('May'); ?></option> <option <?php if ($period->getMonth() == 5) echo "selected"; ?> value=<?php echo '"'. $newdate->getTime() .'"'; ?>><? echo dPformSafe('May'); ?></option> <?php $newdate->setMonth(6); ?>
<option <?php if ($period->getMonth() == 6) echo "selected"; ?> value="6"><? echo dPformSafe('June'); ?></option> <option <?php if ($period->getMonth() == 6) echo "selected"; ?> value=<?php echo '"'. $newdate->getTime() .'"'; ?>><? echo dPformSafe('June'); ?></option> <?php $newdate->setMonth(7); ?>
<option <?php if ($period->getMonth() == 7) echo "selected"; ?> value="7"><? echo dPformSafe('July'); ?></option> <option <?php if ($period->getMonth() == 7) echo "selected"; ?> value=<?php echo '"'. $newdate->getTime() .'"'; ?>><? echo dPformSafe('July'); ?></option> <?php $newdate->setMonth(8); ?>
<option <?php if ($period->getMonth() == 8) echo "selected"; ?> value="8"><? echo dPformSafe('August'); ?></option> <option <?php if ($period->getMonth() == 8) echo "selected"; ?> value=<?php echo '"'. $newdate->getTime() .'"'; ?>><? echo dPformSafe('August'); ?></option> <?php $newdate->setMonth(9); ?>
<option <?php if ($period->getMonth() == 9) echo "selected"; ?> value="9"><? echo dPformSafe('September'); ?></option> <option <?php if ($period->getMonth() == 9) echo "selected"; ?> value=<?php echo '"'. $newdate->getTime() .'"'; ?>><? echo dPformSafe('September'); ?></option> <?php $newdate->setMonth(10); ?>
<option <?php if ($period->getMonth() == 10) echo "selected"; ?> value="10"><? echo dPformSafe('October'); ?></option> <option <?php if ($period->getMonth() == 10) echo "selected"; ?> value=<?php echo '"'. $newdate->getTime() .'"'; ?>><? echo dPformSafe('October'); ?></option> <?php $newdate->setMonth(11); ?>
<option <?php if ($period->getMonth() == 11) echo "selected"; ?> value="11"><? echo dPformSafe('November'); ?></option> <option <?php if ($period->getMonth() == 11) echo "selected"; ?> value=<?php echo '"'. $newdate->getTime() .'"'; ?>><? echo dPformSafe('November'); ?></option> <?php $newdate->setMonth(12); ?>
<option <?php if ($period->getMonth() == 12) echo "selected"; ?> value="12"><? echo dPformSafe('December'); ?></option> <option <?php if ($period->getMonth() == 12) echo "selected"; ?> value=<?php echo '"'. $newdate->getTime() .'"'; ?>><? echo dPformSafe('December'); ?></option>
</select> </select>
<?php <?php
// FIXME: FOR SOME STUPID REASON THE FOLLOWING IS NOT EXACTLY THE SAME AS THE ABOVE. ??? // FIXME: FOR SOME STUPID REASON THE FOLLOWING IS NOT EXACTLY THE SAME AS THE ABOVE. ???
// echo '<select name="ts_period" size="1" class="text" onChange="periodChange();">'; // echo '<select name="timesheet_period" size="1" class="text" onChange="periodChange();">';
// echo '<option '; if ($period->getMonth() == 1) echo "selected"; echo 'value="1">' . dPformSafe('January') . '</option>'; // echo '<option '; if ($period->getMonth() == 1) echo "selected"; echo 'value="'. $newdate->getDate() .'">' . dPformSafe('January') . '</option>';
// echo '<option '; if ($period->getMonth() == 2) echo "selected"; echo 'value="2">' . dPformSafe('February') .'</option>'; // $newdate->setMonth(2);
// echo '<option '; if ($period->getMonth() == 3) echo "selected"; echo 'value="3">' . dPformSafe('March') . '</option>'; // echo '<option '; if ($period->getMonth() == 2) echo "selected"; echo 'value="'. $newdate->getDate() .'">' . dPformSafe('February') .'</option>';
// echo '<option '; if ($period->getMonth() == 4) echo "selected"; echo 'value="4">' . dPformSafe('April') . '</option>'; // $newdate->setMonth(3);
// echo '<option '; if ($period->getMonth() == 5) echo "selected"; echo 'value="5">' . dPformSafe('May') . '</option>'; // echo '<option '; if ($period->getMonth() == 3) echo "selected"; echo 'value="'. $newdate->getDate() .'">' . dPformSafe('March') . '</option>';
// echo '<option '; if ($period->getMonth() == 6) echo "selected"; echo 'value="6">' . dPformSafe('June') . '</option>'; // $newdate->setMonth(4);
// echo '<option '; if ($period->getMonth() == 7) echo "selected"; echo 'value="7">' . dPformSafe('July') . '</option>'; // echo '<option '; if ($period->getMonth() == 4) echo "selected"; echo 'value="'. $newdate->getDate() .'">' . dPformSafe('April') . '</option>';
// echo '<option '; if ($period->getMonth() == 8) echo "selected"; echo 'value="8">' . dPformSafe('August') . '</option>'; // $newdate->setMonth(5);
// echo '<option '; if ($period->getMonth() == 9) echo "selected"; echo 'value="9">' . dPformSafe('September') . '</option>'; // echo '<option '; if ($period->getMonth() == 5) echo "selected"; echo 'value="'. $newdate->getDate() .'">' . dPformSafe('May') . '</option>';
// echo '<option '; if ($period->getMonth() == 10) echo "selected"; echo 'value="10">' . dPformSafe('October') . '</option>'; // $newdate->setMonth(6);
// echo '<option '; if ($period->getMonth() == 11) echo "selected"; echo 'value="11">' . dPformSafe('November') . '</option>'; // echo '<option '; if ($period->getMonth() == 6) echo "selected"; echo 'value="'. $newdate->getDate() .'">' . dPformSafe('June') . '</option>';
// echo '<option '; if ($period->getMonth() == 12) echo "selected"; echo 'value="12">' . dPformSafe('December') . '</option>'; // $newdate->setMonth(7);
// echo '<option '; if ($period->getMonth() == 7) echo "selected"; echo 'value="'. $newdate->getDate() .'">' . dPformSafe('July') . '</option>';
// $newdate->setMonth(8);
// echo '<option '; if ($period->getMonth() == 8) echo "selected"; echo 'value="'. $newdate->getDate() .'">' . dPformSafe('August') . '</option>';
// $newdate->setMonth(9);
// echo '<option '; if ($period->getMonth() == 9) echo "selected"; echo 'value="'. $newdate->getDate() .'">' . dPformSafe('September') . '</option>';
// $newdate->setMonth(10);
// echo '<option '; if ($period->getMonth() == 10) echo "selected"; echo 'value="'. $newdate->getDate() .'">' . dPformSafe('October') . '</option>';
// $newdate->setMonth(11);
// echo '<option '; if ($period->getMonth() == 11) echo "selected"; echo 'value="'. $newdate->getDate() .'">' . dPformSafe('November') . '</option>';
// $newdate->setMonth(12);
// echo '<option '; if ($period->getMonth() == 12) echo "selected"; echo 'value="'. $newdate->getDate() .'">' . dPformSafe('December') . '</option>';
// echo '</select>'; // echo '</select>';
// FIXME: END OF STRANGENESS // FIXME: END OF STRANGENESS
} else { } else {
......
...@@ -36,7 +36,7 @@ $del = dPgetParam($_POST, 'del', 0); ...@@ -36,7 +36,7 @@ $del = dPgetParam($_POST, 'del', 0);
$obj->timesheet_id = $_POST["timesheet_id"]; $obj->timesheet_id = $_POST["timesheet_id"];
$obj->timesheet_status = $_POST["timesheet_status"]; $obj->timesheet_status = $_POST["timesheet_status"];
$obj->timesheet_period = $_POST["ts_period"]; $obj->timesheet_period = $_POST["timesheet_period"];
$obj->timesheet_date = $_POST["timesheet_date"]; $obj->timesheet_date = $_POST["timesheet_date"];
$obj->timesheet_creator = $_POST["timesheet_creator"]; $obj->timesheet_creator = $_POST["timesheet_creator"];
$obj->timesheet_worked = $_POST["timesheet_worked"]; $obj->timesheet_worked = $_POST["timesheet_worked"];
......
...@@ -66,10 +66,12 @@ class CTimesheet extends CDpObject { ...@@ -66,10 +66,12 @@ class CTimesheet extends CDpObject {
$q = new DBQuery(); $q = new DBQuery();
$q->addTable('timesheet'); $q->addTable('timesheet');
$q->addInsert('timesheet_period,timesheet_status,timesheet_date,timesheet_creator,timesheet_worked', $q->addInsert('timesheet_period,timesheet_status,timesheet_date,timesheet_creator,timesheet_worked',
$this->timesheet_period.','.$_POST['timesheet_status'].','. $_POST['timesheet_period'].','.$_POST['timesheet_status'].','.
$_POST['timesheet_date'].','.$_POST['timesheet_creator'].','. $_POST['timesheet_date'].','.$_POST['timesheet_creator'].','.
$_POST['timesheet_worked'], true); $_POST['timesheet_worked'], true);
$q->exec(); if (!$q->exec()) {
return dberror();
}
$this->timesheet_id = db_insert_id(); $this->timesheet_id = db_insert_id();
} }
...@@ -85,12 +87,10 @@ class CTimesheet extends CDpObject { ...@@ -85,12 +87,10 @@ class CTimesheet extends CDpObject {
function project_store() function project_store()
{ {
// Get the current timesheet period // Get the current timesheet period
if (intval($_POST['ts_period'])) { $period = new CDate();
$period = new CDate(); if (intval($_POST['timesheet_period'])) {
$period->setMonth($_POST['ts_period']); $period->setDate($_POST['timesheet_period'],DATE_FORMAT_UNIXTIME);
} }
else
$period = new CDate();
$q = new DBQuery(); $q = new DBQuery();
$q->addQuery('project_id'); $q->addQuery('project_id');
...@@ -143,7 +143,7 @@ class CTimesheet extends CDpObject { ...@@ -143,7 +143,7 @@ class CTimesheet extends CDpObject {
$sheet->addInsert('timesheet_id,timesheet_project,timesheet_project_amount', $sheet->addInsert('timesheet_id,timesheet_project,timesheet_project_amount',
$this->timesheet_id.','.$row["project_id"].','.$amount, true); $this->timesheet_id.','.$row["project_id"].','.$amount, true);
if (!$sheet->exec()) { if (!$sheet->exec()) {
echo db_error(); return db_error();
} }
} }
} }
...@@ -156,7 +156,7 @@ class CTimesheet extends CDpObject { ...@@ -156,7 +156,7 @@ class CTimesheet extends CDpObject {
$q->addUpdate('timesheet_worked', $this->timesheet_worked); $q->addUpdate('timesheet_worked', $this->timesheet_worked);
$q->addWhere('timesheet_id = ' . $this->timesheet_id); $q->addWhere('timesheet_id = ' . $this->timesheet_id);
if (!$q->exec()) { if (!$q->exec()) {
echo db_error(); return db_error();
} }
} }
else { else {
...@@ -169,7 +169,7 @@ class CTimesheet extends CDpObject { ...@@ -169,7 +169,7 @@ class CTimesheet extends CDpObject {
$this->timesheet_date.','.$this->timesheet_creator.',' . $this->timesheet_date.','.$this->timesheet_creator.',' .
$this->timesheet_worked, true); $this->timesheet_worked, true);
if (!$q->exec()) if (!$q->exec())
echo db_error(); return db_error();
} }
} }
......
...@@ -149,7 +149,7 @@ function timesheets($type) ...@@ -149,7 +149,7 @@ function timesheets($type)
echo "<td>"; echo "<td>";
echo "\n".'<a href="?m=timesheet&a=addedit&timesheet_id=' . $row["timesheet_id"] . '">'; echo "\n".'<a href="?m=timesheet&a=addedit&timesheet_id=' . $row["timesheet_id"] . '">';
$period = new CDate(); $period = new CDate();
if (intval($row["timesheet_period"])<=12) { if (intval($row["timesheet_period"])<=12) { // << hack for previouse timesheet versions
$period->setMonth($row["timesheet_period"]); $period->setMonth($row["timesheet_period"]);
$period->setYear(2007); $period->setYear(2007);
} }
......
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