The Material Ledger system includes comprehensive cost tracking that automatically calculates and propagates costs as materials flow through the manufacturing process.

Core Costing Components

  1. CostingInterface: Equipment classes implement this interface to calculate incremental costs for material movements
  2. CostingEvent: Standardized data structure for tracking cost components (material, labor, processing, storage, overhead)
  3. Multi-source Integration: Costing uses the enhanced event propagation framework for complex flow cost allocation

How Cost Tracking Works

When a transaction is completed in closeTransaction(), the costing system:

  1. Incremental Cost Calculation: Destination equipment calculates costs specific to its processing
  2. Multi-Source Cost Retrieval: System retrieves cost events from all upstream movements across all source accounts
  3. Mass-Weighted Allocation: Applies propagation rules to allocate upstream costs proportionally across multiple sources
  4. Cost Combination: Combines incremental and allocated costs using Propagation::add()
  5. Transaction-Wide Attachment: Attaches final cost event to all ledger entries in the transaction

Cost Allocation Examples

Multi-Source Blending Operation:

  • Source A: 60kg raw material with $600 total cost
  • Source B: 40kg additive with $400 total cost
  • Blending equipment: $50 processing cost
  • Result: 100kg final product with $1,050 total cost ($600 + $400 + $50)
  • Per-unit cost: $10.50/kg for downstream operations

Complex Multi-Stage Flow:

  • Multiple tanks → Mixing → Heating → Final product
  • Each stage adds incremental costs and allocates upstream costs proportionally
  • Final product carries complete cost genealogy from all contributing sources

 

Material Transformation Support

The Material Ledger now includes sophisticated material transformation capabilities:

MaterialTransformationInterface

Equipment can implement this interface to define custom material transformation logic:

interface MaterialTransformationInterface
{
public function getTransformedMaterial(array $upstream_entries, float $movement_amount): array;
}

Material Deduction Logic

The MaterialLedgerHelpers::determineMaterial() method uses a sophisticated ruleset:

  1. Transformation Check: If equipment implements MaterialTransformationInterface, use custom logic
  2. Smart Overlap Detection: Find materials common between sources and destination
  3. Weight-Based Selection: Choose materials based on mass contribution from sources
  4. Fallback Hierarchies: Use destination materials or most abundant upstream materials

 

How Material Tracking and Costing Work Together

The complete material tracking system works as follows:

1. Detection Phase

    • The FeedChain class analyzes equipment relationships and sensor data
    • It determines if material is actively flowing between connected equipment
    • When it finds active flows, it identifies all source accounts feeding into a destination
  1. 2. Transaction Management Phase

    • New Flows: When FeedChain detects new sources, Account::processSources() either starts a new transaction or updates an existing one
    • Ongoing Flows: The Transaction class tracks multiple active sources and their last-seen timestamps
    • Dynamic Changes: Sources can be added or removed from active transactions as flow patterns change

    3. Recording Phase

    • Outflow Entries: Each source account gets a LedgerEntry recording material leaving
    • Unified Inflow: Single inflow LedgerEntry at destination accumulates from all sources
    • Real-time Updates: Transaction maintains relationships between all entries

    4. Closure Phase

    • Flow Cessation: When FeedChain detects that all sources have stopped flowing, Transaction::closeTransaction() is called
    • Amount Calculation: Final amounts calculated based on balance changes across all accounts
    • Material Deduction: Complex material determination logic handles multi-source scenarios
    • Cost Propagation: Mass-weighted cost allocation across all upstream sources
    • Event Attachment: Costing and other events attached to all entries in the transaction

    5. Analysis Phase

    • Complete Traceability: Full genealogy maintained across complex multi-source operations
    • Accurate Costing: Proper cost allocation enables precise product costing
    • Mass Balance Verification: System ensures total inflow = sum of all valid outflows
    • Rich Analytics: Complex material flows can be analyzed for optimization and compliance

This creates a complete record of material movements through the manufacturing process, with exact quantities derived from the balance attributes (typically sensors measuring tank levels, scale weights, etc.) and accurate cost tracking that follows the physical flow of materials.