๐Ÿ“š ERP Documentation Viewer

Beautiful, colorful documentation for your ERP system

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

Related Controllers

---

๐Ÿ—„๏ธ Database Tables

Primary Tables

Table NamePurposeKey Columns
projectMaster project dataid, name, clientid, costcenterid, treeid, treeproid, totalcontract
projectstagechosseProject stages selectionprojectid, projectstageid
projecttimetableitemsTimeline/milestonesprojectid, clause, amount, startdate, enddate
projectstagesAvailable stagesid, name, is_active
### Secondary Tables (Referenced)

Table NamePurposeRelationship
clientCustomer dataForeign Key: project.clientid
costcenterProject cost centersForeign Key: project.costcenterid
accountstreeAccounting structureForeign Key: project.treeid, treeproid
projectkindProject typesForeign Key: project.projectkindid
dailyentryFinancial entriesForeign Key: project.entryid
---

๐Ÿ”ง Key Functions

1. add()

Purpose: Create new project with integrated financial setup

Called By: POST action to ?do=add

Parameters:

Returns: Redirects to success/error page

Database Operations:

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:

Returns: Redirects to success/error page

Database Operations:

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:

Returns: Success/error redirect

Database Operations:

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:

Returns: Integer (1 = success, 0 = has dependencies)

Database Operations:

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:

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:

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

Related Views

---

๐ŸŽฏ URL Routes & Actions

Action (`?do=`)MethodDescriptionView Template
(empty)GETDisplay creation formadd.html
showPOSTList projects with filtersshow.html
addPOSTCreate new project-
editGETDisplay edit formedit.html
timetableitemsGETShow timeline itemsdetailtimetableitems.html
updatePOSTUpdate existing project-
deleteGETDelete project-
finishGETMark project as finished-
sucessGETSuccess messagesucces.html
errorGETError messageerror.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

Security Checks

include_once("../public/authentication.php");

Input Validation

---

๐Ÿ“ Notes

Important Considerations

Future Improvements

---

๐Ÿ“š Related Documentation

โ†‘