ProductionOrder Documentation

Production Order Controller Documentation

File: /controllers/productionOrderController.php

Purpose: Manages production orders, work orders, manufacturing schedules, and production planning

Last Updated: December 19, 2024

Total Functions: 23

Lines of Code: ~1,517

---

๐Ÿ“‹ Overview

The Production Order Controller is responsible for managing production orders and work orders in the ERP system. It handles:

Primary Functions

Related Controllers

---

๐Ÿ—„๏ธ Database Tables

Primary Tables (Direct Operations)

Table NamePurposeKey Columns
`productionorder`Main production orders`productionOrderid`, `name`, `orderDate`, `startDate`, `endDate`, `outQuantity`, `orderStatus`
`productionrate`Production formulas/BOM`productionRateId`, `ratename`, `finalproductid`
`productionrateproduct`BOM line items`id`, `productionRateId`, `productid`, `quantity`, `productBuyPrice`
`damagedproduct`Production waste/damage`damagedProductId`, `productionOrderId`, `productId`, `productQuantity`
### Related Tables (Workflow & Resources)

Table NamePurposeKey Columns
`stage`Manufacturing stages`stageid`, `stagename`
`stagestep`Stage operations`id`, `stageId`, `operationId`
`workstation`Production workstations`workstationid`, `workstationname`
`workstationworker`Worker assignments`id`, `workstationid`, `employeeid`, `Hourlyrate`
`workstationassets`Machine assignments`id`, `workstationid`, `assetsId`, `Hourlyrate`
`settingoperation`Operation time settings`id`, `operationid`, `workStationID`, `realTime`
### Inventory Tables

Table NamePurposeKey Columns
`storedetail`Current inventory`storedetailid`, `storeid`, `productid`, `productquantity`
`storereport`Inventory movements`storereportid`, `productid`, `processname`, `productbefore`, `productafter`
`productunit`Unit conversions`productunitid`, `productid`, `unitid`, `productnumber`
### Reference Tables

Table NamePurposeKey Columns
`product`Product master data`productId`, `productName`, `productBuyPrice`
`store`Warehouse locations`storeid`, `storeName`
`employee`Workers`employeeid`, `employeename`, `Hourlyrate`
`assets`Equipment/machines`assetsId`, `assetsName`, `Hourlyrate`
---

๐Ÿ”ง Key Functions

1. add() - Create Production Order

Line: 779

Purpose: Creates a new production order and reserves raw materials

Parameters:

Process Flow:

โ”Œโ”€ Create Production Order โ”€โ”
โ–ผ
โ–ผ
โ–ผ
โ–ผ
โ–ผ
โ””โ”€ Update material costs
โ–ผ
โ–ผ

Code Example:

// Calculate required raw material quantity
$finalquantity = $_POST["outQuantity"] * $productnumber * $Finalproductnumber * $Productionrateproduct[$i]->quantity;

// Reduce inventory
if (count($allStoredetailData) > 0) {
    $productquantityAfter = decreaseProductQuantity($storedetailId, $productquantityBefore, $finalquantity);
    insertStorereport($productId, $_POST["store"], $finalquantity, $productquantityBefore, $productquantityAfter, 1, $productionOrderId, "ุชุตู†ูŠุน", "productionOrderController.php");
}

---

2. update() - Modify Production Order

Line: 887

Purpose: Updates production order quantities and adjusts material reservations

Parameters:

Process Flow:

โ”Œโ”€ Update Production Order โ”€โ”
โ–ผ
โ–ผ
โ–ผ
โ–ผ
โ–ผ
โ””โ”€ Create adjustment storereport
โ–ผ
โ–ผ

Business Rule: Only allows quantity increases to prevent inventory complications

---

3. recievedone() - Complete Production Order

Line: 1005

Purpose: Completes production by adding finished goods to inventory

Process Flow:

โ”Œโ”€ Complete Production โ”€โ”
โ–ผ
โ–ผ
โ–ผ
โ–ผ
โ–ผ
โ–ผ
โ–ผ
โ–ผ
โ–ผ

---

4. details() - Production Cost Analysis

Line: 336

Purpose: Displays detailed production cost breakdown

Process Flow:

โ”Œโ”€ Cost Analysis โ”€โ”
โ–ผ
โ–ผ
โ–ผ
โ–ผ
โ–ผ
โ””โ”€ Sum total labor cost
โ–ผ
โ–ผ
โ””โ”€ Sum total equipment cost
โ–ผ
โ–ผ
โ–ผ
โ–ผ

---

5. getRawMaterialsAndTotalCostOfIt() - BOM Costing

Line: 1240

Purpose: Calculates raw material requirements and costs for production

Parameters:

Process Flow:

โ”Œโ”€ BOM Costing โ”€โ”
โ–ผ
โ–ผ
โ–ผ
โ””โ”€ Store component details
โ–ผ
โ–ผ

Formula:

Required Quantity = Output Quantity ร— BOM Quantity ร— Unit Conversion Factor
Component Cost = Required Quantity ร— Buy Price ร— Unit Factor  
Total Material Cost = ฮฃ(Component Costs)

---

6. addDamageProduct() - Track Production Waste

Line: 1052

Purpose: Records damaged/waste products during production

Parameters:

Process Flow:

โ”Œโ”€ Record Production Waste โ”€โ”
โ–ผ
โ–ผ
โ–ผ
โ–ผ
โ–ผ
โ””โ”€ Track waste in costing

---

7. getuniqueArrayAndTotal() - Resource Aggregation

Line: 1295

Purpose: Aggregates worker/machine time and costs across production stages

Parameters:

Process Flow:

โ”Œโ”€ Resource Aggregation โ”€โ”
โ–ผ
โ””โ”€ Calculate total cost
โ–ผ
โ–ผ

---

8. delete() - Remove Production Order

Line: 1183

Purpose: Deletes production order and reverses all inventory effects

Process Flow:

โ”Œโ”€ Delete Production Order โ”€โ”
โ–ผ
โ–ผ
โ–ผ
โ””โ”€ Reverse material costs
โ–ผ
โ–ผ

---

๐Ÿ”„ Business Logic Flow

Production Order Lifecycle

โ”Œโ”€ Production Planning โ”€โ”
โ–ผ
โ–ผ
โ”Œโ”€ Material Reservation โ”€โ”
โ€ข Calculate BOM requirements
โ€ข Check inventory availability
โ€ข Reserve raw materials
โ€ข Update inventory records
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€ Production Execution โ”€โ”
โ€ข Assign workers & machines
โ€ข Execute manufacturing
โ€ข Track actual consumption
โ€ข Record waste/damage
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€ Production Completion โ”€โ”
โ€ข Add finished goods to stock
โ€ข Calculate actual costs
โ€ข Update order status
โ€ข Generate cost reports
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Stage-Based Manufacturing

Stage 1: Preparation
โ”œโ”€ Material preparation
โ”œโ”€ Workstation setup
โ””โ”€ Worker assignment

Stage 2: Processing  
โ”œโ”€ Raw material consumption
โ”œโ”€ Manufacturing operations
โ””โ”€ Quality control checks

Stage 3: Assembly
โ”œโ”€ Component assembly
โ”œโ”€ Finishing operations
โ””โ”€ Final inspection

Stage 4: Packaging
โ”œโ”€ Product packaging
โ”œโ”€ Labeling
โ””โ”€ Transfer to finished goods

---

โš ๏ธ Common Issues

1. Insufficient Raw Material Inventory

Symptoms: Production order creation fails with inventory shortage

Causes:

Solutions:

2. Production Cost Calculation Errors

Symptoms: Incorrect unit costs, negative costs

Causes:

Solutions:

3. Production Order Status Inconsistencies

Symptoms: Orders stuck in "In Progress" status

Causes:

Solutions:

---

๐Ÿ”— Dependencies

Required Files

Required DAOs

Session Variables

External Systems

---

๐Ÿ“Š Production Formulas

Material Requirement Calculation

// Basic BOM calculation
$requiredQuantity = $outputQuantity ร— $bomQuantity ร— $unitConversionFactor;

// Multi-level BOM (recursive)
function calculateTotalRequirement($finalProduct, $quantity, $level = 0) {
    $totalRequirements = [];
    $bom = getBOMForProduct($finalProduct);
    
    foreach ($bom as $component) {
        $required = $quantity ร— $component->quantity;
        if (hasSubBOM($component->productId)) {
            $subRequirements = calculateTotalRequirement($component->productId, $required, $level + 1);
            $totalRequirements = array_merge($totalRequirements, $subRequirements);
        } else {
            $totalRequirements[] = ['product' => $component->productId, 'quantity' => $required];
        }
    }
    return $totalRequirements;
}

Production Cost Formula

// Total production cost calculation
$materialCost = ฮฃ(component_quantity ร— component_unit_cost);
$laborCost = ฮฃ(worker_hours ร— hourly_rate);
$equipmentCost = ฮฃ(machine_hours ร— hourly_rate);
$wasteCost = ฮฃ(waste_quantity ร— waste_unit_cost);

$totalProductionCost = $materialCost + $laborCost + $equipmentCost + $wasteCost;
$unitProductionCost = $totalProductionCost / $outputQuantity;

Efficiency Metrics

// Material yield efficiency
$materialYield = ($outputQuantity ร— standardMaterialPerUnit) / $actualMaterialUsed ร— 100;

// Labor efficiency  
$laborEfficiency = $standardLaborHours / $actualLaborHours ร— 100;

// Overall Equipment Effectiveness (OEE)
$oee = $availability ร— $performance ร— $quality;

---

Manufacturing Concepts Covered: Production Orders, Work Order Management, Bill of Materials (BOM), Material Requirements Planning (MRP), Stage-Based Manufacturing, Production Costing, Resource Planning, Waste Tracking, Production Scheduling, Inventory Reservation