Project Documentation
Project Master Management Controller Documentation
File: /controllers/projectController.php
Purpose: Complete project lifecycle management - creation, editing, finishing, and deletion
Last Updated: 2024-12-20
---
๐ Overview
Primary Functions
- โ Project creation with client/cost center integration
- โ Project editing and timeline management
- โ Project finishing with financial calculations
- โ Project deletion with dependency checking
- โ Project stage management
- โ Project timeline items management
- โ Accounting tree integration
Related Controllers
- โข projectKindController.php - Project type management
- โข projectoperationController.php - Material operations
- โข projectReportController.php - Project analytics
- โข clientController.php - Client management
---
๐๏ธ Database Tables
Primary Tables
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| project | Master project data | id, name, clientid, costcenterid, treeid, treeproid, totalcontract | |
| projectstagechosse | Project stages selection | projectid, projectstageid | |
| projecttimetableitems | Timeline/milestones | projectid, clause, amount, startdate, enddate | |
| projectstages | Available stages | id, name, is_active |
| Table Name | Purpose | Relationship | |
|---|---|---|---|
| client | Customer data | Foreign Key: project.clientid | |
| costcenter | Project cost centers | Foreign Key: project.costcenterid | |
| accountstree | Accounting structure | Foreign Key: project.treeid, treeproid | |
| projectkind | Project types | Foreign Key: project.projectkindid | |
| dailyentry | Financial entries | Foreign Key: project.entryid |
๐ง Key Functions
1. add()
Purpose: Create new project with integrated financial setup
Called By: POST action to ?do=add
Parameters:
- โข
$txtName(string) - Project name - โข
$txtDebt(float) - Total contract value - โข
$chwckaddclient(int) - Whether to create client - โข
$projectkindid(int) - Project type - โข
$projectstageids(array) - Selected stages - โข
$timetableitemsitr(int) - Number of timeline items
Returns: Redirects to success/error page
Database Operations:
- โข INSERT into
costcenter- Creates cost center - โข INSERT into
client(optional) - Creates client if requested - โข INSERT into
accountstree- Creates two tree entries (debtor/asset) - โข INSERT into
project- Master project record - โข INSERT into
projectstagechosse- Project stages - โข INSERT into
projecttimetableitems- Timeline items
Business Logic:
1. Create cost center for project tracking
2. Optionally create client with accounting tree entry
3. Create accounting tree entries for project (debtor side & asset side)
4. Insert project with all metadata
5. Link selected stages to project
6. Create timeline items with dates and amounts
Example:
// Create project with stages and timeline
$_POST['txtName'] = 'New Building Project';
$_POST['txtDebt'] = 100000;
$_POST['projectstageids'] = [1, 2, 3]; // Design, Construction, Completion
add();
2. update()
Purpose: Update existing project information
Called By: POST action to ?do=update
Parameters:
- โข
$editid(int) - Project ID - โข Same parameters as add() function
Returns: Redirects to success/error page
Database Operations:
- โข UPDATE
costcenter- Updates cost center name - โข UPDATE
client- Updates client information - โข UPDATE
accountstree- Updates tree entries - โข UPDATE
project- Updates all project fields - โข DELETE/INSERT
projectstagechosse- Updates stage selections - โข UPDATE/INSERT
projecttimetableitems- Updates timeline
Business Logic:
1. Update cost center and client names
2. Update accounting tree entries with new values
3. Update project record with all changes
4. Synchronize stage selections (remove old, add new)
5. Update timeline items (modify existing, add new)
3. finishproject($projectid)
Purpose: Complete project with financial closure calculations
Called By: GET action to ?do=finish&id=$projectid
Parameters:
- โข
$projectid(int) - Project to finish
Returns: Success/error redirect
Database Operations:
- โข UPDATE
projectSET finish = 1 - โข UPDATE
clientSET conditions = 1 (mark as finished) - โข UPDATE
costcenterSET condation = 1 - โข INSERT into
dailyentry- Final accounting entry - โข Complex SELECT queries for financial calculations
Business Logic:
1. Mark project as finished in all related tables
2. Calculate client payments vs project costs
3. Calculate goods under settlement value
4. Create final accounting entry:
- FROM: Client account (payments - goods value)
- FROM: Goods under settlement (full cost)
- TO: Sales account (total client payments)
Accounting Formula:
Client Account = Client Payments - Project Costs
Sales = Client Payments
Goods Under Settlement = Project Material Costs
4. deleteproject($projectid)
Purpose: Delete project with dependency validation
Called By: GET action to ?do=delete&id=$projectid
Parameters:
- โข
$projectid(int) - Project to delete
Returns: Integer (1 = success, 0 = has dependencies)
Database Operations:
- โข SELECT from
projectexchmaterial- Check for materials - โข DELETE from
project,client,costcenter - โข DELETE from
accountstree- Remove tree entries - โข Reverse daily entries
Business Logic:
1. Check if project has material operations (prevents deletion)
2. If no dependencies:
- Reverse all accounting entries
- Delete tree elements by name
- Delete project, client, and cost center
- Mark as deleted (soft delete)
5. entryinsert_data($projectname, $value, $clientid, $projectid)
Purpose: Create double-entry accounting record for project creation
Parameters:
- โข
$projectname(string) - Project description - โข
$value(float) - Transaction amount - โข
$clientid(int) - Client tree ID (debtor) - โข
$projectid(int) - Project tree ID (creditor)
Returns: Entry ID
Accounting Entry:
DR: Client Account (Asset) $value
CR: Goods Under Settlement $value
Comment: "ุชู
ุงุถุงูุฉ ู
ุดุฑูุน ุงุณู
ู {$projectname}"
---
๐ Main Workflows
Workflow 1: Project Creation
1. User fills project form
โ
2. Validate required fields
โ
3. Create Cost Center
โ
4. Create Client (optional)
โ
5. Create Accounting Tree Entries
โ
6. Insert Project Master Record
โ
7. Link Project Stages
โ
8. Create Timeline Items
โ
9. Success/Error Response
Files Involved:
- โข View:
/views/default/projectview/add.html - โข Model:
/models/dto/Project.class.php - โข DAO:
/models/mysql/ProjectMySqlDAO.class.php
Workflow 2: Project Finishing
1. Validate Project ID
โ
2. Calculate Financial Position
โ
3. Mark All Records as Finished
โ
4. Create Final Accounting Entry
โ
5. Success Response
Workflow 3: Project Deletion
1. Check Material Dependencies
โ
2. If Dependencies Found โ Block Deletion
โ
3. Reverse All Accounting Entries
โ
4. Delete Tree Elements
โ
5. Soft Delete All Records
โ
6. Success Response
---
๐ File Dependencies
Includes
include("../public/impOpreation.php");
include_once("../library/uploadImages.php");
include_once("../public/config.php");
include("../public/include_dao.php");
include_once("dailyentryfun.php");
Required Models
- โข Project, Client, Costcenter, Accountstree, ProjectKind
- โข Dailyentry, Dailyentrycreditor, Dailyentrydebtor
- โข Projectexchmaterial, Programsettings, YoutubeLink
Related Views
- โข
/views/default/projectview/add.html- Project creation form - โข
/views/default/projectview/show.html- Project listing - โข
/views/default/projectview/edit.html- Project editing - โข
/views/default/projectview/detailtimetableitems.html- Timeline view
---
๐ฏ URL Routes & Actions
| Action (`?do=`) | Method | Description | View Template | |
|---|---|---|---|---|
| (empty) | GET | Display creation form | add.html | |
| show | POST | List projects with filters | show.html | |
| add | POST | Create new project | - | |
| edit | GET | Display edit form | edit.html | |
| timetableitems | GET | Show timeline items | detailtimetableitems.html | |
| update | POST | Update existing project | - | |
| delete | GET | Delete project | - | |
| finish | GET | Mark project as finished | - | |
| sucess | GET | Success message | succes.html | |
| error | GET | Error message | error.html |
โ ๏ธ Known Issues & Fixes
Issue 1: Undefined Variable in Tree Creation (Line 433)
Problem: $txtName used instead of $projectName in tree creation
Cause: Copy-paste error from another function
Fix: Replace $txtName with $projectName
File: Line 433
Issue 2: Unused Entry ID in Update (Line 567)
Problem: $NEWentryid used but never defined
Cause: Incomplete refactoring
Fix: Remove unused variable or implement entry update logic
File: Line 567
Issue 3: Stage Array Check (Lines 443, 582)
Problem: Array check may fail with non-array inputs
Cause: User input validation
Fix: Add is_array() check before in_array()
File: Lines 443, 582
---
๐ Permissions & Security
Required Permissions
- โข Project management access
- โข Client creation (if enabled)
- โข Accounting tree modification
- โข Cost center management
Security Checks
include_once("../public/authentication.php");
Input Validation
- โข All POST data filtered with
filter_input() - โข File uploads validated through upload library
- โข Session-based user permissions
---
๐ Notes
Important Considerations
- โข Project deletion only allowed if no material operations exist
- โข Finishing a project creates irreversible accounting entries
- โข Timeline items support date ranges and amounts
- โข Stage selection affects project workflow
Future Improvements
- โป๏ธ Add project templates
- โป๏ธ Implement project approval workflow
- โป๏ธ Add project status history
- โป๏ธ Enhance timeline management with dependencies
---