Commit d77d2183 authored by Jean-Paul Saman's avatar Jean-Paul Saman

Cleanup tabs and replace them with spaces.

parent 60badb2a
<?php <?php
/* /*
* Copyright (C) 2007, M2X * Copyright (C) 2007-2008, M2X
* *
* Authors: Jean-Paul Saman * Authors: Jean-Paul Saman
* *
...@@ -25,196 +25,197 @@ ...@@ -25,196 +25,197 @@
// a class named (like this) in the form: module/module.class.php is automatically loaded by the dPFramework // a class named (like this) in the form: module/module.class.php is automatically loaded by the dPFramework
/** /**
* @package dotProject * @package dotProject
* @subpackage modules * @subpackage modules
* @version $Revision: 1.0 $ * @version $Revision: 1.0 $
*/ */
// include the powerful parent class that we want to extend for timesheet // include the powerful parent class that we want to extend for timesheet
require_once( $AppUI->getSystemClass('dp') ); // use the dPFramework for easy inclusion of this class here // use the dPFramework for easy inclusion of this class here
require_once( $AppUI->getSystemClass('dp') );
/** /**
* The Timesheet Class * The Timesheet Class
*/ */
class CTimesheet extends CDpObject { class CTimesheet extends CDpObject {
// link variables to the timesheet object (according to the existing columns in the database table timesheet) // link variables to the timesheet object (according to the existing columns in the database table timesheet)
//use NULL for a NEW object, so the database automatically assigns an unique id by 'NOT NULL'-functionality //use null for a new object, so the database automatically assigns an unique id by 'not null'-functionality
var $timesheet_id = NULL; var $timesheet_id = null;
var $timesheet_period = NULL; var $timesheet_period = null;
var $timesheet_status = NULL; var $timesheet_status = null;
var $timesheet_date = NULL; var $timesheet_date = null;
var $timesheet_creator = NULL; var $timesheet_creator = null;
var $timesheet_worked = NULL; var $timesheet_worked = null;
// the constructor of the CTimesheet class, always combined with the table name and the unique key of the table // the constructor of the CTimesheet class, always combined with the table name and the unique key of the table
function CTimesheet() { function CTimesheet() {
$this->CDpObject( 'timesheet', 'timesheet_id' ); $this->CDpObject( 'timesheet', 'timesheet_id' );
$this->timesheet_id=$_POST["timesheet_id"]; $this->timesheet_id=$_POST["timesheet_id"];
} }
function check() { function check() {
if ( $this->timesheet_id == "0" ) { if ( $this->timesheet_id == "0" ) {
$this->init(); $this->init();
} }
return NULL; return NULL;
} }
function init() { function init() {
$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',
$_POST['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(); $q->exec();
$this->timesheet_id = db_insert_id(); $this->timesheet_id = db_insert_id();
} }
function project_purge() function project_purge()
{ {
$q = new DBQuery(); $q = new DBQuery();
$q->setDelete('timesheet_project'); $q->setDelete('timesheet_project');
$q->addWhere('timesheet_id = '. $this->timesheet_id ); $q->addWhere('timesheet_id = '. $this->timesheet_id );
if (!$q->exec()) if (!$q->exec())
return db_error(); return db_error();
} }
function project_store() function project_store()
{ {
// Get the current timesheet period // Get the current timesheet period
if (intval($_POST['timesheet_period'])) { if (intval($_POST['timesheet_period'])) {
$period = new CDate(); $period = new CDate();
$period->setMonth($_POST['timesheet_period']); $period->setMonth($_POST['timesheet_period']);
} }
else else
$period = new CDate(); $period = new CDate();
$q = new DBQuery(); $q = new DBQuery();
$q->addQuery('project_id'); $q->addQuery('project_id');
$q->addQuery('project_name'); $q->addQuery('project_name');
$q->addQuery('project_status'); $q->addQuery('project_status');
$q->addTable('projects'); $q->addTable('projects');
$q->addOrder('project_name ASC'); $q->addOrder('project_name ASC');
$projects = $q->LoadList(); $projects = $q->LoadList();
foreach ($projects as $row) { foreach ($projects as $row) {
$t = new DBQuery; $t = new DBQuery;
$t->addQuery('task_id'); $t->addQuery('task_id');
$t->addQuery('task_name'); $t->addQuery('task_name');
$t->addQuery('task_owner'); $t->addQuery('task_owner');
$t->addQuery('task_start_date'); $t->addQuery('task_start_date');
$t->addQuery('task_hours_worked'); $t->addQuery('task_hours_worked');
$t->addTable('tasks'); $t->addTable('tasks');
$t->addWhere('task_project = '. $row["project_id"]); $t->addWhere('task_project = '. $row["project_id"]);
$t->addOrder('task_start_date DESC'); $t->addOrder('task_start_date DESC');
$tasks = $t->LoadList(); $tasks = $t->LoadList();
$t->Clear(); $t->Clear();
$amount = 0; $amount = 0;
foreach ($tasks as $item) { foreach ($tasks as $item) {
// Query the task_log table for actual start dates. // Query the task_log table for actual start dates.
$t->addQuery('task_log_id'); $t->addQuery('task_log_id');
$t->addQuery('task_log_name'); $t->addQuery('task_log_name');
$t->addQuery('task_log_creator'); $t->addQuery('task_log_creator');
$t->addQuery('task_log_date'); $t->addQuery('task_log_date');
$t->addQuery('task_log_hours'); $t->addQuery('task_log_hours');
$t->addTable('task_log'); $t->addTable('task_log');
$t->addWhere('task_log_task = '. $item["task_id"]); $t->addWhere('task_log_task = '. $item["task_id"]);
// What if this is different then current user? // What if this is different then current user?
$t->addWhere('task_log_creator = ' . $this->timesheet_creator); $t->addWhere('task_log_creator = ' . $this->timesheet_creator);
$t->addOrder('task_log_date DESC'); $t->addOrder('task_log_date DESC');
// TODO: select on user and date // TODO: select on user and date
$log = $t->LoadList(); $log = $t->LoadList();
foreach ($log as $logitem) { foreach ($log as $logitem) {
if (intval($logitem['task_log_date'])) if (intval($logitem['task_log_date']))
{ {
$taskDate = new CDate($logitem['task_log_date']); $taskDate = new CDate($logitem['task_log_date']);
if ($period->GetMonth() == $taskDate->GetMonth()) { if ($period->GetMonth() == $taskDate->GetMonth()) {
$amount = $amount + $logitem["task_log_hours"]; $amount = $amount + $logitem["task_log_hours"];
} }
// else do not account the worked hours to the project for this month // else do not account the worked hours to the project for this month
} }
} }
} }
$sheet = new DBQuery(); $sheet = new DBQuery();
$sheet->addTable('timesheet_project'); $sheet->addTable('timesheet_project');
$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(); echo db_error();
} }
} }
} }
function store() { function store() {
if ($this->timesheet_id != 0) { if ($this->timesheet_id != 0) {
$this->_action='updated'; $this->_action='updated';
$q = new DBQuery(); $q = new DBQuery();
$q->addTable('timesheet'); $q->addTable('timesheet');
$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(); echo db_error();
} }
} }
else { else {
$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.','.$this->timesheet_status.','. $this->timesheet_period.','.$this->timesheet_status.','.
$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(); echo db_error();
} }
} }
// overload the delete method of the parent class for adaptation for timesheet's needs // overload the delete method of the parent class for adaptation for timesheet's needs
function delete() { function delete() {
$q = new DBQuery(); $q = new DBQuery();
$q->setDelete('timesheet_project'); $q->setDelete('timesheet_project');
$q->addWhere('timesheet_id = '. $this->timesheet_id ); $q->addWhere('timesheet_id = '. $this->timesheet_id );
$q->exec(); $q->exec();
echo db_error(); echo db_error();
$q->clear(); $q->clear();
$q->setDelete('timesheet'); $q->setDelete('timesheet');
$q->addWhere('timesheet_id = '. $this->timesheet_id ); $q->addWhere('timesheet_id = '. $this->timesheet_id );
if (!$q->exec()) { if (!$q->exec()) {
return db_error(); return db_error();
} else { } else {
return NULL; return NULL;
} }
} }
function change_status($stat) function change_status($stat)
{ {
$msg = $this->check(); $msg = $this->check();
$this->_action='updated'; $this->_action='updated';
$q = new DBQuery(); $q = new DBQuery();
$q->addTable('timesheet'); $q->addTable('timesheet');
$q->addUpdate('timesheet_status', $stat); $q->addUpdate('timesheet_status', $stat);
$q->addWhere('timesheet_id = ' . $this->timesheet_id); $q->addWhere('timesheet_id = ' . $this->timesheet_id);
if (!$q->exec()) { if (!$q->exec()) {
return db_error(); return db_error();
} }
// Why is this needed ?? // Why is this needed ??
echo $q; echo $q;
if ($stat>0) { if ($stat>0) {
$this->project_purge(); $this->project_purge();
$this->project_store(); $this->project_store();
} }
} }
function change_period($period) function change_period($period)
{ {
$msg = $this->check(); $msg = $this->check();
$this->_action='updated'; $this->_action='updated';
$q = new DBQuery(); $q = new DBQuery();
$q->addTable('timesheet'); $q->addTable('timesheet');
$q->addUpdate('timesheet_period', $period); $q->addUpdate('timesheet_period', $period);
$q->addWhere('timesheet_id = ' . $this->timesheet_id); $q->addWhere('timesheet_id = ' . $this->timesheet_id);
if (!$q->exec()) { if (!$q->exec()) {
return db_error(); return 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