Add worked time tracking for projects. - TEMPLATE COMMIT.
1.1 --- a/forms/project.frm Wed Dec 28 22:33:30 2011 +0100
1.2 +++ b/forms/project.frm Wed Dec 28 23:31:27 2011 +0100
1.3 @@ -1,7 +1,8 @@
1.4 <form id="project">
1.5 <field id="project_type_no" updates="project_stage_no"/>
1.6 <field id="project_stage_no"/>
1.7 - <field id="descript"/>
1.8 + <field id="project_code"/>
1.9 + <field id="descript"/>
1.10 <field id="status"/>
1.11 <field id="goal"/>
1.12 <linked table="user_project" label="Employees" id="users" input="dropdown"/>
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/share/postprocessclass_project.php Wed Dec 28 23:31:27 2011 +0100
2.3 @@ -0,0 +1,33 @@
2.4 +<?php // (c) 2011 Olof Tjerngren, GPLv3
2.5 +require_once("../2lib/deletehelp.php");
2.6 +
2.7 +class Postprocessor_project extends Postprocessor {
2.8 +
2.9 + function process($type) {
2.10 + $fields=$this->getNewValues();
2.11 + if ($type=="insert") {
2.12 + } else if ($type=="update") {
2.13 + $old=$this->getOldValues();
2.14 + if ($fields['project_code']!=$old['project_code']) {
2.15 + // if project_code value has changed, update all timereport descriptors
2.16 + // Note that existing reported time is not updated with the new
2.17 + // description, only new reported time. This is hopefully a rare case.
2.18 + $res=mysql_query("select * from worked_user_reportable where ref_table='project' and ref_link=".$fields['project_no'],$GLOBALS['conn']);
2.19 + while ($row=mysql_fetch_assoc($res)) {
2.20 + $row['description']=$fields['project_code'];
2.21 + doUpdate('worked_user_reportable',$row);
2.22 + }
2.23 + mysql_free_result($res);
2.24 + }
2.25 + } else if ($type=="delete") {
2.26 + $fields=$this->getOldValues();
2.27 + $res=mysql_query("select * from worked_user_reportable where ref_table='project' and ref_link=".$fields['project_no'],$GLOBALS['conn']);
2.28 + while ($row=mysql_fetch_assoc($res)) {
2.29 + deleteRec('worked_user_reportable',$row);
2.30 + }
2.31 + mysql_free_result($res);
2.32 + }
2.33 + }
2.34 +}
2.35 +
2.36 +?>
2.37 \ No newline at end of file
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/share/postprocessclass_user_project.php Wed Dec 28 23:31:27 2011 +0100
3.3 @@ -0,0 +1,35 @@
3.4 +<?php // (c) 2011 Olof Tjerngren, GPLv3
3.5 +require_once("../2lib/deletehelp.php");
3.6 +
3.7 +class Postprocessor_user_project extends Postprocessor {
3.8 +
3.9 + function process($type) {
3.10 + $fields=$this->getNewValues();
3.11 +
3.12 + if ($type=="insert") {
3.13 + // Insert a record for the new user to make it available for
3.14 + // time reporting.
3.15 + $project_code=selectOneValue("select project_code from project where project_no=".((int)$fields['project_no']));
3.16 + $worked_user_reportable=
3.17 + array('user_no'=>(int)$fields['user_no'],
3.18 + 'ref_table'=>'project',
3.19 + 'ref_link'=>(int)$fields['project_no'],
3.20 + 'description'=>$project_code);
3.21 + doInsert('worked_user_reportable',$worked_user_reportable);
3.22 + } else if ($type=="update") {
3.23 + // Only account for insert and delete here, not updates.
3.24 + // They way the system works records are added to connect and
3.25 + // removed to disconnect users to projects,
3.26 + // if this changes, this will have to be updated to handle updates
3.27 + // of both user_no and project_no values.
3.28 + } else if ($type=="delete") {
3.29 + $fields=$this->getOldValues();
3.30 + $row=selectOne("select * from worked_user_reportable where ref_table='project' and ref_link=".$fields['project_no'].' and user_no='.$fields['user_no']);
3.31 + if ($row) {
3.32 + deleteRec('worked_user_reportable',$row);
3.33 + }
3.34 + }
3.35 + }
3.36 +}
3.37 +
3.38 +?>
3.39 \ No newline at end of file
4.1 --- a/tables.struct Wed Dec 28 22:33:30 2011 +0100
4.2 +++ b/tables.struct Wed Dec 28 23:31:27 2011 +0100
4.3 @@ -2429,12 +2429,14 @@
4.4 <field id="project_no" type="int" notnull="yes" extra="auto_increment"/>
4.5 <field id="project_type_no" type="int" notnull="yes" references="project_type"/>
4.6 <field id="project_stage_no" type="int" notnull="yes" references="project_stage"/>
4.7 + <field id="project_code" type="varchar" len="20" notnull="yes"/>
4.8 <field id="descript" type="varchar" len="120" notnull="yes"/>
4.9 <field id="status" type="set('Completed','Cancelled')" notnull="yes"/>
4.10 <field id="goal" type="text" notnull="yes"/>
4.11 <primarykey field="project_no"/>
4.12 <display id="table" name="Project" width="400" height="300"/>
4.13 <display id="project_type_no" name="Project type"/>
4.14 + <display id="project_code" name="Project"/>
4.15 <display id="descript" name="Project Name"/>
4.16 <display id="project_stage_no" name="Project stage"/>
4.17 <display id="status" name="Status"/>