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:
- โข Project-specific material requisitions and consumption
- โข Material transfers to project sites
- โข Project-based inventory tracking
- โข Construction material cost tracking
- โข Project material receipt and issuing
- โข Material accountability by project
- โข Integration with project accounting
- โข Image documentation for materials
- โข Material cost allocation to projects
Primary Functions
- โ Create material requisitions for projects
- โ Issue materials to project sites
- โ Track material consumption by project
- โ Record material receipts from suppliers
- โ Manage project material inventory
- โ Upload material images and documentation
- โ Generate project material reports
- โ Allocate material costs to projects
- โ Handle material returns from projects
- โ Integrate with project accounting
Related Controllers
- โข projectController.php - Project management
- โข storeController.php - Main inventory management
- โข productController.php - Product/material master data
- โข buyBillController.php - Material procurement
- โข supplierController.php - Supplier management
- โข clientController.php - Client/project owner management
- โข costcenterController.php - Cost center allocation
- โข dailyentryController.php - Accounting entries
- โข storedetailController.php - Inventory management
---
๐๏ธ Database Tables
Primary Tables (Direct Operations)
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| `projectmaterials` | Project material header | `id`, `projectid`, `storeid`, `billdate`, `totalbuyprice`, `userid` | |
| `projectmaterialdetails` | Material line items | `id`, `projectmaterialid`, `productid`, `productnumber`, `probuyprice`, `image` |
| Table Name | Purpose | Key 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` |
| Table Name | Purpose | Key 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:
- โข
$_POST['projectname']- Project ID - โข
$_POST['storeid']- Source warehouse - โข
$_POST['billdate']- Issue date - โข
$_POST['totalpronumber']- Total items count - โข
$_POST['finaltotalprice']- Total value - โข
$_POST['casesid']- Case/purpose ID - โข Material details arrays for each line item
Process Flow:
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:
- โข
$_POST['projectname']- Filter by project - โข
$_POST['datefrom'],$_POST['dateto']- Date range filter - โข
$_POST['casesid']- Filter by case/purpose
Process Flow:
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:
---
4. update() - Save Material Changes
Line: 404
Purpose: Updates material requisition by deleting old and recreating
Process Flow:
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:
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:
- โข
$storeid- Warehouse ID - โข
$productid- Product/material ID
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:
---
8. insertStorereport() - Audit Trail
Line: 542
Purpose: Creates inventory movement audit trail for material transactions
Parameters:
- โข Product and store information
- โข Quantities before/after transaction
- โข Process description
- โข Reference IDs
---
๐ Business Logic Flow
Project Material Workflow
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:
- โข Insufficient warehouse inventory
- โข Materials committed to other projects
- โข Incorrect quantity calculations
Solutions:
- โข Implement material reservation system
- โข Add inventory checking before requisition approval
- โข Create material availability reports
2. Image Upload Failures
Symptoms: Material images not saved or displayed
Causes:
- โข Upload directory permissions
- โข File size limitations
- โข Invalid file formats
Solutions:
- โข Verify upload directory permissions (../upload/projectmaterials)
- โข Check PHP upload settings
- โข Validate file types before upload
3. Project Cost Allocation Issues
Symptoms: Incorrect project material costs
Causes:
- โข Missing cost allocation entries
- โข Incorrect material prices
- โข Exchange rate fluctuations for imported materials
Solutions:
- โข Implement automated cost allocation
- โข Regular price validation procedures
- โข Currency conversion tracking
---
๐ Dependencies
Required Files
- โข
../public/impOpreation.php- Core operations - โข
../public/config.php- Database configuration - โข
../public/include_dao.php- Data access objects - โข
../library/uploadImages.php- Image upload handling - โข
dailyentryfun.php- Accounting functions
Required DAOs
- โข RedBean ORM for database operations
- โข Project-related DAOs for project data
- โข Product DAOs for material information
- โข Store DAOs for inventory management
Upload Configuration
- โข Upload directory:
../upload/projectmaterials/ - โข Supported formats: Images for material documentation
- โข Permission requirements: Write access for web server
Session Dependencies
- โข
$_SESSION['userid']- Current user for audit trail - โข
$_SESSION['projectids']- User's accessible projects - โข
$_SESSION['storenegative']- Allow negative inventory setting
---
๐ 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
- โข Raw Materials: Cement, steel, sand, gravel
- โข Finished Components: Doors, windows, fixtures
- โข Consumables: Welding rods, bolts, fasteners
- โข Equipment Supplies: Fuel, lubricants, spare parts
Project Phases Integration
- โข Foundation Phase: Concrete materials, reinforcement
- โข Structure Phase: Steel, formwork, scaffolding
- โข Finishing Phase: Tiles, paint, fixtures
- โข MEP Phase: Electrical, plumbing, HVAC materials
Documentation Features
- โข Material delivery receipts with photos
- โข Quality certificates and test reports
- โข Material inspection records
- โข Usage certificates and approvals
---
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