๐Ÿ“š ERP Documentation Viewer

Beautiful, colorful documentation for your ERP system

Project Material Controller Documentation

File: /controllers/projectmaterialController.php

Purpose: Manages raw materials and supplies for construction/project-based manufacturing

Last Updated: December 19, 2024

Total Functions: 12

Lines of Code: ~601

---

๐Ÿ“‹ Overview

The Project Material Controller manages raw materials and supplies specifically for construction projects and project-based manufacturing. It handles:

Primary Functions

Related Controllers

---

๐Ÿ—„๏ธ Database Tables

Primary Tables (Direct Operations)

Table NamePurposeKey Columns
`projectmaterials`Project material header`id`, `projectid`, `storeid`, `billdate`, `totalbuyprice`, `userid`
`projectmaterialdetails`Material line items`id`, `projectmaterialid`, `productid`, `productnumber`, `probuyprice`, `image`
### Related Tables (Projects & Inventory)

Table NamePurposeKey Columns
`project`Project master data`projectid`, `name`, `startdate`, `enddate`, `clientid`
`storedetail`Current inventory`storedetailid`, `storeid`, `productid`, `productquantity`
`storereport`Inventory movements`storereportid`, `productid`, `processname`, `productbefore`, `productafter`
`product`Material/product master`productId`, `productName`, `productBuyPrice`, `productSellPrice`
### Reference Tables

Table NamePurposeKey Columns
`store`Warehouse/site locations`storeid`, `storeName`
`client`Project clients/owners`clientid`, `clientname`
`costcenter`Cost centers for allocation`costcenterid`, `costcentername`
`user`System users`userid`, `employeename`
---

๐Ÿ”ง Key Functions

1. add() - Issue Materials to Project

Line: 345

Purpose: Creates material requisition and issues materials from warehouse to project

Parameters:

Process Flow:

โ”Œโ”€ Create Material Requisition โ”€โ”
โ–ผ
โ–ผ
โ–ผ
โ””โ”€ Create detail record
โ–ผ
โ–ผ

Code Example:

// Create material header
$projectmaterials = R::dispense('projectmaterials');
$projectmaterials->projectid = $projectid;
$projectmaterials->storeid = $storeid;
$projectmaterials->totalbuyprice = $finaltotalprice;
$projectmaterials->userid = $_SESSION['userid'];
$projectmaterialid = R::store($projectmaterials);

// Add material details with image handling
for ($i = 1; $i <= $offerhidden_itr; $i++) {
    $handle = new upload($_FILES['image'. $i]);
    $imagePhoto = uploadImageswhioutresize($handle, "../upload/projectmaterials");
    
    $projectmaterialdetails = R::dispense('projectmaterialdetails');
    $projectmaterialdetails->projectmaterialid = $projectmaterialid;
    $projectmaterialdetails->productid = $productid;
    $projectmaterialdetails->image = $imagePhoto;
    R::store($projectmaterialdetails);
}

---

2. show() - View Project Material Transactions

Line: 202

Purpose: Displays project material transactions with filtering options

Parameters:

Process Flow:

โ”Œโ”€ Material Transaction Report โ”€โ”
โ–ผ
โ–ผ
โ–ผ
โ–ผ
โ””โ”€ Add to results array
โ–ผ
โ–ผ

SQL Query Building:

$queryString = " where 1 ";
if (isset($projectid) && !empty($projectid)) {
    $queryString .= " and projectmaterials.projectid = " . $projectid;
}
if ($_SESSION['projectids'] != 0) {
    $queryString .= ' AND projectmaterials.projectid in (' . $_SESSION['projectids'] . ')';
}
if (isset($datefrom) && !empty($datefrom)) {
    $queryString .= ' and projectmaterials.sysdate >= "' . $datefrom . '" ';
}

---

3. edit() - Modify Material Requisition

Line: 255

Purpose: Allows editing of existing material requisitions

Process Flow:

โ”Œโ”€ Edit Material Requisition โ”€โ”
โ–ผ
โ–ผ
โ–ผ
โ–ผ
โ–ผ
โ””โ”€ Calculate totals
โ–ผ
โ–ผ

---

4. update() - Save Material Changes

Line: 404

Purpose: Updates material requisition by deleting old and recreating

Process Flow:

โ”Œโ”€ Update Material Requisition โ”€โ”
โ–ผ
โ–ผ
โ–ผ
โ–ผ
โ–ผ

Note: Uses delete-and-recreate pattern for simplicity

---

5. delete() - Remove Material Requisition

Line: 411

Purpose: Deletes material requisition and all associated details

Process Flow:

โ”Œโ”€ Delete Material Requisition โ”€โ”
โ–ผ
โ–ผ
โ–ผ
โ–ผ
โ–ผ
โ–ผ
โ–ผ

Code Example:

$projectmaterials = R::load('projectmaterials', $id);
$projectmaterialdetails = R::findAll("projectmaterialdetails", " projectmaterialid = ? ", [$id]);
R::trashAll($projectmaterialdetails);
R::trash($projectmaterials);

---

6. getStoredetailData() - Inventory Lookup

Line: 510

Purpose: Retrieves current inventory levels for a product in specific warehouse

Parameters:

Returns: Array containing store detail data, ID, and current quantity

---

7. decreaseProductQuantity() - Reduce Inventory

Line: 522

Purpose: Reduces product quantity in warehouse when materials are issued

Process Flow:

โ”Œโ”€ Reduce Inventory โ”€โ”
โ–ผ
โ–ผ
โ–ผ
โ–ผ
โ–ผ
โ–ผ

---

8. insertStorereport() - Audit Trail

Line: 542

Purpose: Creates inventory movement audit trail for material transactions

Parameters:

---

๐Ÿ”„ Business Logic Flow

Project Material Workflow

โ”Œโ”€ Project Planning โ”€โ”
โ–ผ
โ–ผ
โ”Œโ”€ Material Procurement โ”€โ”
โ€ข Purchase materials
โ€ข Receive in warehouse
โ€ข Quality inspection
โ€ข Update inventory
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€ Material Requisition โ”€โ”
โ€ข Request materials for project
โ€ข Specify quantities needed
โ€ข Attach supporting images
โ€ข Get approvals
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€ Material Issue โ”€โ”
โ€ข Verify inventory availability
โ€ข Issue materials to project
โ€ข Reduce warehouse inventory
โ€ข Create audit trail
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€ Project Consumption โ”€โ”
โ€ข Use materials in construction
โ€ข Track actual usage vs planned
โ€ข Record waste/spillage
โ€ข Update project costs
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Material Accountability Chain

Purchase โ†’ Warehouse โ†’ Project Site โ†’ Consumption
    โ†“          โ†“           โ†“             โ†“
Buy Bills โ†’ Store Detail โ†’ Project Materials โ†’ Project Costs

---

โš ๏ธ Common Issues

1. Material Shortage for Projects

Symptoms: Cannot issue required materials to project

Causes:

Solutions:

2. Image Upload Failures

Symptoms: Material images not saved or displayed

Causes:

Solutions:

3. Project Cost Allocation Issues

Symptoms: Incorrect project material costs

Causes:

Solutions:

---

๐Ÿ”— Dependencies

Required Files

Required DAOs

Upload Configuration

Session Dependencies

---

๐Ÿ“Š Project Material Formulas

Cost Allocation

// Project material cost allocation
$projectMaterialCost = ฮฃ(material_quantity ร— material_unit_cost);
$projectTotalCost += $projectMaterialCost;

// Cost per unit calculation
$costPerUnit = $projectTotalCost / $projectOutputUnits;

// Material utilization rate
$utilizationRate = $actualConsumption / $issuedQuantity ร— 100;

Inventory Valuation

// Project inventory value
$projectInventoryValue = ฮฃ(remaining_quantity ร— weighted_average_cost);

// Material efficiency
$materialEfficiency = $standardMaterialCost / $actualMaterialCost ร— 100;

// Waste percentage
$wastePercentage = ($issuedQuantity - $usedQuantity) / $issuedQuantity ร— 100;

---

๐Ÿ—๏ธ Construction Industry Features

Material Types Supported

Project Phases Integration

Documentation Features

---

Manufacturing Concepts Covered: Project-Based Manufacturing, Material Requisitions, Construction Materials Management, Project Cost Allocation, Material Accountability, Site Inventory Management, Material Documentation, Project Accounting Integration, Material Traceability, Construction Workflow Integration

โ†‘