PHP code example of azaharizaman / nexus-manufacturing
1. Go to this page and download the library: Download azaharizaman/nexus-manufacturing library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
azaharizaman / nexus-manufacturing example snippets
use Nexus\Manufacturing\Services\BomManager;
use Nexus\Manufacturing\ValueObjects\BomLine;
// Create BOM manager with repository dependency
$bomManager = new BomManager($bomRepository);
// Create a new BOM
$bom = $bomManager->create(
productId: 'PROD-001',
version: '1.0',
type: 'manufacturing',
lines: [],
effectiveFrom: new DateTimeImmutable('2024-01-01')
);
// Add components
$bomManager->addLine($bom->getId(), new BomLine(
productId: 'COMP-001',
quantity: 2.0,
uomCode: 'EA',
lineNumber: 10,
scrapFactor: 0.05
));
$bomManager->addLine($bom->getId(), new BomLine(
productId: 'COMP-002',
quantity: 1.5,
uomCode: 'KG',
lineNumber: 20,
));
// Explode BOM to get all materials
$materials = $bomManager->explode($bom->getId(), quantity: 100);
use Nexus\Manufacturing\Services\WorkOrderManager;
use Nexus\Manufacturing\Enums\WorkOrderStatus;
$workOrderManager = new WorkOrderManager($repository, $bomManager, $routingManager);
// Create work order
$workOrder = $workOrderManager->create(
productId: 'PROD-001',
quantity: 100.0,
plannedStartDate: new DateTimeImmutable('2024-02-01'),
plannedEndDate: new DateTimeImmutable('2024-02-15'),
bomId: 'bom-001',
routingId: 'routing-001'
);
// Release for production
$workOrderManager->release($workOrder->getId());
// Start production
$workOrderManager->start($workOrder->getId());
// Record operation completion
$workOrderManager->completeOperation(
workOrderId: $workOrder->getId(),
operationSequence: 10,
completedQty: 100.0,
scrapQty: 2.0,
laborHours: 8.5
);
// Complete and close
$workOrderManager->complete($workOrder->getId());
$workOrderManager->close($workOrder->getId());
use Nexus\Manufacturing\Services\MrpEngine;
use Nexus\Manufacturing\ValueObjects\PlanningHorizon;
use Nexus\Manufacturing\Enums\LotSizingStrategy;
$mrpEngine = new MrpEngine(
$bomManager,
$inventoryProvider,
$demandProvider,
$plannedOrderRepository
);
// Define planning horizon
$horizon = new PlanningHorizon(
startDate: new DateTimeImmutable('2024-01-01'),
endDate: new DateTimeImmutable('2024-03-31'),
bucketSize: 7, // Weekly buckets
frozenDays: 14,
slushyDays: 28
);
// Run MRP
$result = $mrpEngine->run(
productIds: ['PROD-001', 'PROD-002'],
horizon: $horizon,
lotSizingStrategy: LotSizingStrategy::ECONOMIC_ORDER_QUANTITY
);
// Process planned orders
foreach ($result->getPlannedOrders() as $order) {
echo sprintf(
"Product: %s, Qty: %.2f, Due: %s\n",
$order->getProductId(),
$order->getQuantity(),
$order->getDueDate()->format('Y-m-d')
);
}
use Nexus\Manufacturing\Services\CapacityPlanner;
use Nexus\Manufacturing\Enums\CapacityLoadType;
$capacityPlanner = new CapacityPlanner(
$workCenterRepository,
$workOrderRepository,
$routingManager,
$capacityResolver
);
// Check capacity for work center
$profile = $capacityPlanner->getCapacityProfile(
workCenterId: 'WC-001',
startDate: new DateTimeImmutable('2024-02-01'),
endDate: new DateTimeImmutable('2024-02-28'),
loadType: CapacityLoadType::FINITE
);
// Get utilization by period
foreach ($profile->getPeriods() as $period) {
echo sprintf(
"%s: %.1f%% utilized\n",
$period->getDate()->format('Y-m-d'),
$period->getUtilizationPercent()
);
}
// Get resolution suggestions for overloads
$suggestions = $capacityPlanner->getResolutionSuggestions('WC-001', $overloadPeriod);
foreach ($suggestions as $suggestion) {
echo sprintf(
"Action: %s, Estimated Savings: %.1f hours\n",
$suggestion->getAction()->value,
$suggestion->getEstimatedImpact()
);
}
// Implement InventoryDataProviderInterface
class InventoryAdapter implements InventoryDataProviderInterface
{
public function __construct(
private readonly StockManagerInterface $stockManager
) {}
public function getOnHandQuantity(string $productId, string $warehouseId): float
{
return $this->stockManager->getAvailableStock($productId, $warehouseId);
}
}
// Implement ForecastProviderInterface for ML predictions
class MlForecastAdapter implements ForecastProviderInterface
{
public function __construct(
private readonly AnomalyDetectionServiceInterface $mlService
) {}
public function getForecast(string $productId, DateTimeImmutable $date): ?DemandForecast
{
$prediction = $this->mlService->predict('demand_forecast', [
'product_id' => $productId,
'date' => $date->format('Y-m-d'),
]);
return new DemandForecast(
productId: $productId,
forecastDate: $date,
quantity: $prediction['quantity'],
confidence: ForecastConfidence::from($prediction['confidence'])
);
}
}