ProductionExecution Documentation

Production Execution Controller Documentation

File: /controllers/productionExecutionController.php

Purpose: Manages manufacturing execution, BOM consumption, production output, and inventory updates

Last Updated: December 19, 2024

Total Functions: 17

Lines of Code: ~1,881

---

๐Ÿ“‹ Overview

The Production Execution Controller is the core component for executing manufacturing processes in the ERP system. It handles:

Primary Functions

Related Controllers

---

๐Ÿ—„๏ธ Database Tables

Primary Tables (Direct Operations)

Table NamePurposeKey Columns
`productionexecution`Main production execution records`id`, `taskorderid`, `num`, `notes`, `executiondate`
`productionexecutionproduct`Raw materials consumed`id`, `productionexecutionid`, `productid`, `quantity`, `actualquantity`
`productionexecutionoutput`Finished goods produced`id`, `productionexecutionid`, `productid`, `num`
`productionexecutionwaste`Production waste/scrap`id`, `productionexecutionid`, `productid`, `num`
`taskorder`Source production orders`taskorderid`, `name`, `num`, `startdate`, `enddate`
`taskorderproducts`Task order materials list`id`, `taskorderid`, `productid`, `quantity`
### Related Tables (Inventory & Costing)

Table NamePurposeKey Columns
`storedetail`Current inventory quantities`storedetailid`, `storeid`, `productid`, `productquantity`
`storereport`Inventory movement history`storereportid`, `productid`, `storeid`, `productquantity`, `processname`
`buypriceshistorybook`Purchase price tracking`id`, `storeid`, `productid`, `buyprice`, `buyquantity`, `sellquantity`
`sizecolorstoredetail`Size/color variant inventory`id`, `productid`, `sizeid`, `colorid`, `quantity`
`productionrate`BOM header`productionRateId`, `ratename`, `finalproductid`
`productionrateproduct`BOM line items`id`, `productionRateId`, `productid`, `quantity`
### Reference Tables

Table NamePurposeKey Columns
`product`Product master data`productId`, `productName`, `productBuyPrice`, `productSellPrice`
`store`Warehouse/location master`storeid`, `storeName`
`simplemanufacturesetting`Manufacturing configuration`id`, `storeid`, `reducestoreamount`
---

๐Ÿ”ง Key Functions

1. add() - Create Production Execution

Line: 549

Purpose: Creates a new production execution record from task order

Parameters:

Process Flow:

โ”Œโ”€ Start Production Execution โ”€โ”
โ–ผ
โ–ผ
โ–ผ
โ–ผ
โ””โ”€ Create storereport entry
โ–ผ
โ–ผ

Return: Redirects to success/error page

---

2. executeAdd() - Process Material Consumption

Line: 702

Purpose: Handles raw material deduction from inventory during production execution

Parameters:

Process Flow:

โ”Œโ”€ Material Consumption โ”€โ”
โ–ผ
โ–ผ
โ–ผ
โ””โ”€ Generate storereport entry
โ–ผ
โ–ผ
โ–ผ
โ–ผ

Code Example:

// Calculate material consumption based on BOM
$requiredQty = $productionQty * $bomQty * $conversionFactor;

// Reduce inventory
$newInventory = decreaseProductQuantity($storeDetailId, $currentQty, $requiredQty);

// Update buy price history for costing
getBuyPriceFromAndHandleBuyPricesHistoryBook($storeId, $productId, $sizeId, $colorId, $buyPrice, $requiredQty, 0);

---

3. execute() - Complete Production Process

Line: 1074

Purpose: Completes production by adding finished goods to inventory

Parameters:

Process Flow:

โ”Œโ”€ Complete Production โ”€โ”
โ–ผ
โ–ผ
โ–ผ
โ””โ”€ Calculate new mean buy price
โ–ผ
โ–ผ
โ””โ”€ Record waste in system
โ–ผ
โ–ผ

---

4. update() - Modify Production Execution

Line: 926

Purpose: Updates existing production execution with new quantities

Process Flow:

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

---

5. delete() - Remove Production Execution

Line: 1442

Purpose: Deletes production execution and reverses all inventory effects

Process Flow:

โ”Œโ”€ Delete Production โ”€โ”
โ–ผ
โ–ผ
โ–ผ
โ””โ”€ Create reversal storereport
โ–ผ
โ–ผ

---

6. getBuyPriceFromAndHandleBuyPricesHistoryBook() - FIFO Costing

Line: 1746

Purpose: Manages buy price history for FIFO/LIFO inventory costing

Parameters:

Process Flow:

โ”Œโ”€ FIFO Costing Process โ”€โ”
โ–ผ
โ–ผ
โ–ผ
โ””โ”€ Remove fully consumed lots
โ–ผ
โ–ผ

---

7. doInventoryDailyEntry() - Accounting Integration

Line: 1849

Purpose: Creates daily accounting entries for production costs

Parameters:

Process Flow:

โ”Œโ”€ Accounting Entry โ”€โ”
โ–ผ
โ–ผ
โ–ผ
โ–ผ
โ–ผ
โ–ผ
โ–ผ

---

๐Ÿ”„ Business Logic Flow

Production Execution Workflow

โ”Œโ”€ Task Order Created โ”€โ”
โ–ผ
โ–ผ
โ–ผ
โ”Œโ”€ Material Consumption Phase โ”€โ”
1Get BOM for product
2Calculate required materials
3Check inventory availability
4Reduce raw material stock
5Update buy price history
6Record consumption
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€ Production Phase โ”€โ”
1Execute manufacturing
2Record actual output
3Track waste/scrap
4Quality control check
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€ Output Recording Phase โ”€โ”
1Add finished goods to inventory
2Calculate production cost
3Update product mean buy price
4Generate accounting entries
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

BOM Consumption Formula

Required Quantity = Production Qty ร— BOM Qty ร— Unit Conversion Factor

Example:
- Produce 100 units of Product A
- BOM requires 2.5kg Material X per unit
- Material X stored in grams (conversion factor = 1000)
- Required = 100 ร— 2.5 ร— 1000 = 250,000 grams

---

โš ๏ธ Common Issues

1. Inventory Shortage During Production

Symptoms: Production fails with insufficient stock error

Causes:

Solutions:

2. Buy Price History Inconsistencies

Symptoms: Incorrect cost calculations, negative inventory values

Causes:

Solutions:

3. BOM Formula Calculation Errors

Symptoms: Wrong material consumption amounts

Causes:

Solutions:

---

๐Ÿ”— Dependencies

Required Files

Required DAOs

Required Session Variables

External Dependencies

---

๐Ÿงฎ Manufacturing Formulas

Cost Calculation

// Weighted average cost per unit
$newMeanPrice = (($oldQuantity ร— $oldMeanPrice) + ($newQuantity ร— $newPrice)) / ($oldQuantity + $newQuantity);

// Total production cost
$totalCost = $materialCost + $laborCost + $overheadCost;

// Unit production cost  
$unitCost = $totalCost / $outputQuantity;

Inventory Valuation Methods

---

Manufacturing Concepts Covered: Production Execution, BOM Management, Material Consumption, FIFO Costing, Inventory Valuation, Production Costing, Waste Tracking, Quality Control Integration, Accounting Integration