Commit 23df88df authored by Jean-Paul Saman's avatar Jean-Paul Saman

Show selected timesheet

parent 4be46f9b
......@@ -30,25 +30,22 @@ $timesheet_id = (int)w2PgetParam($_GET, "timesheet_id", 0);
$timesheet = new CTimesheet();
$timesheet->timesheet_id = $timesheet_id;
$obj = $timesheet;
$canEdit = $obj->canEdit();
$canDelete = $obj->canDelete();
// check permissions for this record
if (!$canEdit) {
// we check for permissions on this module
$perms = $AppUI->acl();
if (!$perms->checkModuleItem('timesheet', 'access')) {
$AppUI->redirect(ACCESS_DENIED);
}
$obj = $AppUI->restoreObject();
if ($obj) {
$timesheet = $obj;
$timesheet_id = $timesheet->timesheet_id;
}
else {
$timesheet->load(null, $timesheet_id);
$canView = $perms->checkModule( $m, 'view' );
$canEdit = $perms->checkModule( $m, 'edit' );
$canDelete = $perms->checkModule( $m, 'delete' );
if (!$canEdit || !$canView) {
$AppUI->redirect(ACCESS_DENIED);
}
// load the record data in case of that this script is used to edit the timesheet(timesheet_id(
// Load object
$timesheet->load(null, $timesheet_id);
// load the record data in case of that this script is used to edit the timesheet(timesheet_id)
if (!$timesheet && $timesheet_id > 0) {
$AppUI->setMsg('Timesheet');
$AppUI->setMsg('invalidID', UI_MSG_ERROR, true);
......@@ -56,13 +53,11 @@ if (!$timesheet && $timesheet_id > 0) {
}
// Read in all configuration data from timesheet_config
print "configuration options loading";
$config_options = $obj->get_config();
$config_options = $timesheet->get_config();
if (!$config_options) {
$AppUI->setMsg('no configuration options found', UI_MSG_ERROR);
$AppUI->redirect();
}
print "configuration options loaded";
// setup the title block
// Fill the title block either with 'Edit' or with 'New' depending on
......@@ -110,7 +105,7 @@ $titleBlock->show();
// create a form providing to add/edit a timesheet
//Pull all users
$q = new DBQuery();
$q = new w2p_Database_Query();
$q->addQuery('user_id, contact_first_name, contact_last_name');
$q->addTable('users');
$q->addTable('contacts');
......@@ -122,47 +117,47 @@ while ( $row = $q->fetchRow()) {
$users[$row['user_id']] = $row['contact_last_name'] . ', ' . $row['contact_first_name'];
}
// Get current submitter name
if ("$obj->timesheet_creator" == "") {
if ("$timesheet->timesheet_creator" == "") {
$submitter = $users[$AppUI->user_id];
$obj->timesheet_creator = $AppUI->user_id;
$timesheet->timesheet_creator = $AppUI->user_id;
} else {
$submitter = $users[$obj->timesheet_creator];
$submitter = $users[$timesheet->timesheet_creator];
}
$q->Clear();
// Get the current timesheet period
$period = new CDate();
if (intval($obj->timesheet_period)) {
$period->setDate($obj->timesheet_period,DATE_FORMAT_UNIXTIME);
$period = new w2p_Utilities_Date();
if (intval($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']) );
}
$obj->timesheet_period = $period->getTime();
$timesheet->timesheet_period = $period->getTime();
}
// Get the current timesheet status
$status = $obj->timesheet_status;
$status = $timesheet->timesheet_status;
// Get the current timesheet creation date
$creation_date = new CDate();
if (intval($obj->timesheet_date)) {
$creation_date->setDate($obj->timesheet_date,DATE_FORMAT_UNIXTIME);
$creation_date = new w2p_Utilities_Date();
if (intval($timesheet->timesheet_date)) {
$creation_date->setDate($timesheet->timesheet_date,DATE_FORMAT_UNIXTIME);
} else {
$obj->timesheet_date = $creation_date->getTime();
$timesheet->timesheet_date = $creation_date->getTime();
}
if (intval($obj->timesheet_worked)) {
$timesheet_worked = $obj->timesheet_worked;
if (intval($timesheet->timesheet_worked)) {
$timesheet_worked = $timesheet->timesheet_worked;
} else {
$obj->timesheet_worked = 0;
$timesheet->timesheet_worked = 0;
}
// function TimesheetEditForm()
echo '<table cellspacing="0" cellpadding="4" border="0" width="100%" class="std">';
echo '<form name="editFrm" action="./index.php?m=timesheet" method="post">';
// if set, the value of dosql is automatically executed by the dP core application
// if set, the value of dosql is automatically executed by the w2P core application
// do_timesheet_aed.php will be the target of this form
// it will execute all database relevant commands
echo '<input type="hidden" name="dosql" value="do_timesheet_aed" />';
......@@ -177,9 +172,9 @@ if (intval($obj->timesheet_worked)) {
// 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
echo '<input type="hidden" name="timesheet_id" value="'.$timesheet_id.'" />';
echo '<input type="hidden" name="timesheet_date" value="'.$obj->timesheet_date.'" />';
echo '<input type="hidden" name="timesheet_creator" value="'.$obj->timesheet_creator.'" />';
echo '<input type="hidden" name="timesheet_worked" value="'.$obj->timesheet_worked.'" />';
echo '<input type="hidden" name="timesheet_date" value="'.$timesheet->timesheet_date.'" />';
echo '<input type="hidden" name="timesheet_creator" value="'.$timesheet->timesheet_creator.'" />';
echo '<input type="hidden" name="timesheet_worked" value="'.$timesheet->timesheet_worked.'" />';
// please notice that html tags that have no </closing tag> should be closed
// like you find it here (<tag />) for xhtml compliance
......@@ -195,38 +190,38 @@ if (intval($obj->timesheet_worked)) {
echo '<td width="100%">';
if ( ($canEdit) && ($status < 1) && ($timesheet_id == 0) ) {
$newdate = new CDate();
$newdate->setDate($obj->timesheet_period,DATE_FORMAT_UNIXTIME);
$newdate = new w2p_Utilities_Date();
$newdate->setDate($timesheet->timesheet_period,DATE_FORMAT_UNIXTIME);
$newdate->setMonth(1);
?>
<select name="timesheet_period" size="1" class="text" onChange="periodChange();">
<option <?php if ($period->getMonth() == 1) echo "selected"; ?> value=<?php echo '"'. $newdate->getTime() .'"'; ?>><?php echo dPformSafe('January'); ?></option> <?php $newdate->setMonth(2); ?>
<option <?php if ($period->getMonth() == 2) echo "selected"; ?> value=<?php echo '"'. $newdate->getTime() .'"'; ?>><?php echo dPformSafe('February'); ?></option> <?php $newdate->setMonth(3); ?>
<option <?php if ($period->getMonth() == 3) echo "selected"; ?> value=<?php echo '"'. $newdate->getTime() .'"'; ?>><?php echo dPformSafe('March'); ?></option> <?php $newdate->setMonth(4); ?>
<option <?php if ($period->getMonth() == 4) echo "selected"; ?> value=<?php echo '"'. $newdate->getTime() .'"'; ?>><?php echo dPformSafe('April'); ?></option> <?php $newdate->setMonth(5); ?>
<option <?php if ($period->getMonth() == 5) echo "selected"; ?> value=<?php echo '"'. $newdate->getTime() .'"'; ?>><?php echo dPformSafe('May'); ?></option> <?php $newdate->setMonth(6); ?>
<option <?php if ($period->getMonth() == 6) echo "selected"; ?> value=<?php echo '"'. $newdate->getTime() .'"'; ?>><?php echo dPformSafe('June'); ?></option> <?php $newdate->setMonth(7); ?>
<option <?php if ($period->getMonth() == 7) echo "selected"; ?> value=<?php echo '"'. $newdate->getTime() .'"'; ?>><?php echo dPformSafe('July'); ?></option> <?php $newdate->setMonth(8); ?>
<option <?php if ($period->getMonth() == 8) echo "selected"; ?> value=<?php echo '"'. $newdate->getTime() .'"'; ?>><?php echo dPformSafe('August'); ?></option> <?php $newdate->setMonth(9); ?>
<option <?php if ($period->getMonth() == 9) echo "selected"; ?> value=<?php echo '"'. $newdate->getTime() .'"'; ?>><?php echo dPformSafe('September'); ?></option> <?php $newdate->setMonth(10); ?>
<option <?php if ($period->getMonth() == 10) echo "selected"; ?> value=<?php echo '"'. $newdate->getTime() .'"'; ?>><?php echo dPformSafe('October'); ?></option> <?php $newdate->setMonth(11); ?>
<option <?php if ($period->getMonth() == 11) echo "selected"; ?> value=<?php echo '"'. $newdate->getTime() .'"'; ?>><?php echo dPformSafe('November'); ?></option> <?php $newdate->setMonth(12); ?>
<option <?php if ($period->getMonth() == 12) echo "selected"; ?> value=<?php echo '"'. $newdate->getTime() .'"'; ?>><?php echo dPformSafe('December'); ?></option>
<option <?php if ($period->getMonth() == 1) echo "selected"; ?> value=<?php echo '"'. $newdate->getTime() .'"'; ?>><?php echo w2PformSafe('January'); ?></option> <?php $newdate->setMonth(2); ?>
<option <?php if ($period->getMonth() == 2) echo "selected"; ?> value=<?php echo '"'. $newdate->getTime() .'"'; ?>><?php echo w2PformSafe('February'); ?></option> <?php $newdate->setMonth(3); ?>
<option <?php if ($period->getMonth() == 3) echo "selected"; ?> value=<?php echo '"'. $newdate->getTime() .'"'; ?>><?php echo w2PformSafe('March'); ?></option> <?php $newdate->setMonth(4); ?>
<option <?php if ($period->getMonth() == 4) echo "selected"; ?> value=<?php echo '"'. $newdate->getTime() .'"'; ?>><?php echo w2PformSafe('April'); ?></option> <?php $newdate->setMonth(5); ?>
<option <?php if ($period->getMonth() == 5) echo "selected"; ?> value=<?php echo '"'. $newdate->getTime() .'"'; ?>><?php echo w2PformSafe('May'); ?></option> <?php $newdate->setMonth(6); ?>
<option <?php if ($period->getMonth() == 6) echo "selected"; ?> value=<?php echo '"'. $newdate->getTime() .'"'; ?>><?php echo w2PformSafe('June'); ?></option> <?php $newdate->setMonth(7); ?>
<option <?php if ($period->getMonth() == 7) echo "selected"; ?> value=<?php echo '"'. $newdate->getTime() .'"'; ?>><?php echo w2PformSafe('July'); ?></option> <?php $newdate->setMonth(8); ?>
<option <?php if ($period->getMonth() == 8) echo "selected"; ?> value=<?php echo '"'. $newdate->getTime() .'"'; ?>><?php echo w2PformSafe('August'); ?></option> <?php $newdate->setMonth(9); ?>
<option <?php if ($period->getMonth() == 9) echo "selected"; ?> value=<?php echo '"'. $newdate->getTime() .'"'; ?>><?php echo w2PformSafe('September'); ?></option> <?php $newdate->setMonth(10); ?>
<option <?php if ($period->getMonth() == 10) echo "selected"; ?> value=<?php echo '"'. $newdate->getTime() .'"'; ?>><?php echo w2PformSafe('October'); ?></option> <?php $newdate->setMonth(11); ?>
<option <?php if ($period->getMonth() == 11) echo "selected"; ?> value=<?php echo '"'. $newdate->getTime() .'"'; ?>><?php echo w2PformSafe('November'); ?></option> <?php $newdate->setMonth(12); ?>
<option <?php if ($period->getMonth() == 12) echo "selected"; ?> value=<?php echo '"'. $newdate->getTime() .'"'; ?>><?php echo w2PformSafe('December'); ?></option>
</select>
<?php
} else {
if ($period->getMonth() == 1) echo dPformSafe('January');
else if ($period->getMonth() == 2) echo dPformSafe('February');
else if ($period->getMonth() == 3) echo dPformSafe('March');
else if ($period->getMonth() == 4) echo dPformSafe('April');
else if ($period->getMonth() == 5) echo dPformSafe('May');
else if ($period->getMonth() == 6) echo dPformSafe('June');
else if ($period->getMonth() == 7) echo dPformSafe('July');
else if ($period->getMonth() == 8) echo dPformSafe('August');
else if ($period->getMonth() == 9) echo dPformSafe('September');
else if ($period->getMonth() == 10) echo dPformSafe('October');
else if ($period->getMonth() == 11) echo dPformSafe('November');
else if ($period->getMonth() == 12) echo dPformSafe('December');
if ($period->getMonth() == 1) echo w2PformSafe('January');
else if ($period->getMonth() == 2) echo w2PformSafe('February');
else if ($period->getMonth() == 3) echo w2PformSafe('March');
else if ($period->getMonth() == 4) echo w2PformSafe('April');
else if ($period->getMonth() == 5) echo w2PformSafe('May');
else if ($period->getMonth() == 6) echo w2PformSafe('June');
else if ($period->getMonth() == 7) echo w2PformSafe('July');
else if ($period->getMonth() == 8) echo w2PformSafe('August');
else if ($period->getMonth() == 9) echo w2PformSafe('September');
else if ($period->getMonth() == 10) echo w2PformSafe('October');
else if ($period->getMonth() == 11) echo w2PformSafe('November');
else if ($period->getMonth() == 12) echo w2PformSafe('December');
}
echo '</td>';
echo '</tr>';
......@@ -243,21 +238,21 @@ if (intval($obj->timesheet_worked)) {
($config_options['approval_by']['value'] == $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 dPformSafe('Open for Editing'); ?> </option>
<option <?php if (intval($status) == '1') { echo "selected"; } ?> value="1"> <?php echo dPformSafe('Submitted'); ?> </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>
<?php
// Only the user with Timesheet Approval rights may set a timesheet to approved status.
if ( $config_options['approval_by']['value'] == $AppUI->user_id ) {
?>
<option <?php if ($status == '2') { echo "selected"; } ?> value="2"> <?php echo dPformSafe('Approved'); ?> </option>
<option <?php if ($status == '2') { echo "selected"; } ?> value="2"> <?php echo w2PformSafe('Approved'); ?> </option>
<?php
}
echo "</select>";
} else {
if ($status == 1)
echo dPformSafe('Submitted');
echo w2PformSafe('Submitted');
else if ($status == 2)
echo dPformSafe('Approved');
echo w2PformSafe('Approved');
}
echo '</td>';
echo '</tr>';
......@@ -287,15 +282,15 @@ if (intval($obj->timesheet_worked)) {
echo '</table>';
// Get Project Status information.
$project_types = dPgetSysVal("ProjectStatus");
$project_types = w2PgetSysVal("ProjectStatus");
// FIXME: Move this function to the Timesheet class
// Find all tasks in this timesheet period and account them to the project.
function showproject()
{
global $AppUI, $period, $obj, $project_types;
global $AppUI, $period, $timesheet, $project_types;
$q = new DBQuery();
$q = new w2p_Database_Query();
$q->addQuery('project_id');
$q->addQuery('project_name');
$q->addQuery('project_company');
......@@ -306,7 +301,7 @@ function showproject()
$timesheet_worked = 0;
foreach ($projects as $row) {
$project_id = $row["project_id"];
$t = new DBQuery;
$t = new w2p_Database_Query();
$t->addQuery('task_id');
$t->addQuery('task_name');
$t->addQuery('task_owner');
......@@ -347,7 +342,7 @@ function showproject()
$log = $t->LoadList();
foreach ($log as $logitem) {
if (intval($logitem['task_log_date'])) {
$taskDate = new CDate($logitem['task_log_date']);
$taskDate = new w2p_Utilities_Date($logitem['task_log_date']);
if ( ($period->GetMonth() == $taskDate->GetMonth()) &&
($period->GetYear() == $taskDate->GetYear()) ) {
$amount = $amount + $logitem['task_log_hours'];
......@@ -368,8 +363,8 @@ function showproject()
echo '</tr>';
}
}
$obj->timesheet_worked = $timesheet_worked;
echo '<tr><td>&nbsp;</td><td>&nbsp;</td><td><b>'.dPformSafe('Total').'</b></td><td><b>'.$timesheet_worked.'</b></td><td>&nbsp;</td></tr>';
$timesheet->timesheet_worked = $timesheet_worked;
echo '<tr><td>&nbsp;</td><td>&nbsp;</td><td><b>'.w2PformSafe('Total').'</b></td><td><b>'.$timesheet_worked.'</b></td><td>&nbsp;</td></tr>';
} // end of function showproject()
// Print the overview table
......@@ -387,13 +382,13 @@ function showproject()
echo '<input type="hidden" name="projects" value="0" />';
echo '<input type="hidden" name="timesheet_id" value="'. $timesheet_id .'" />';
echo '<input type="hidden" name="timesheet_date" value="'. $obj->timesheet_date .'" />';
echo '<input type="hidden" name="timesheet_creator" value="'. $obj->timesheet_creator .'" />';
echo '<input type="hidden" name="timesheet_worked" value="'. $obj->timesheet_worked .'" />';
echo '<input type="hidden" name="timesheet_date" value="'. $timesheet->timesheet_date .'" />';
echo '<input type="hidden" name="timesheet_creator" value="'. $timesheet->timesheet_creator .'" />';
echo '<input type="hidden" name="timesheet_worked" value="'. $timesheet->timesheet_worked .'" />';
showproject();
echo '<script language="javascript">workedHoursChange('. $obj->timesheet_worked .');</script>';
echo '<script language="javascript">workedHoursChange('. $timesheet->timesheet_worked .');</script>';
echo "</form>";
echo "</table>";
?>
......@@ -45,7 +45,6 @@ class CTimesheet extends w2p_Core_BaseObject {
// the constructor of the CTimesheet class, always combined with the table name and the unique key of the table
public function __construct() {
parent::__construct('timesheet', 'timesheet_id');
$this->timesheet_id=$_POST["timesheet_id"];
}
public function isValid() {
......@@ -56,8 +55,16 @@ class CTimesheet extends w2p_Core_BaseObject {
return (count($this->_error)) ? false : true;
}
public function loadFull() {
// loadFull information for this timesheet
public function loadFull($notUsed = null, $timesheet_id) {
// loadFull information for this timesheet\
}
public function load($notUsed = null, $timesheet_id) {
$q = $this->_getQuery();
$q->addQuery('*');
$q->addTable('timesheet');
$q->addWhere('timesheet_id =' . (int)$timesheet_id);
$q->loadObject($this, true, false);
}
protected function init() {
......@@ -80,7 +87,7 @@ class CTimesheet extends w2p_Core_BaseObject {
{
$q = $this->_getQuery();
$q->setDelete('timesheet_project');
$q->addWhere('timesheet_id = '. $this->timesheet_id);
$q->addWhere('timesheet_id = '. (int) $this->timesheet_id);
if (!($q->exec())) {
$this->_error['project-purge-timesheet'] = db_error();
return false;
......@@ -92,7 +99,7 @@ class CTimesheet extends w2p_Core_BaseObject {
{
// Get the current timesheet period
$period = new w2p_UtilitiesDate($_POST['timesheet_period']);
//$period->setDate($_POST['timesheet_period'],DATE_FORMAT_UNIXTIME);
$period->setDate($_POST['timesheet_period'],DATE_FORMAT_UNIXTIME);
$q = $this->_getQuery();
$q->addQuery('project_id');
......
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