Lot Code Customization Point

Customization point that checks the Lot Code to make sure it is eligible to be used as a material source.

This guide will step through the process of coding a LotCode customization. If you are just getting started, you can learn about getting started with customizations.

Creating the Class

To use custom logic for scheduling activities we will need to create a new class that inherits from EligibleMaterialCustomization. This customization class is located at: PT.Scheduler.Simulation.Customizations.EligibleMaterialCustomization

Here is what a basic class should look like:

public class LotUsageConstraint : PT.Scheduler.Simulation.Customizations.EligibleMaterialCustomization
{
public override string Name => "LotCodeConstraint";

public override string Description => "Restricts operations from using lots that do not match the Material Requirement's eligible lot codes";

/// <summary>
/// Restricts operations from using lots that do not match the Material Requirement's eligible lot codes
/// </summary>
/// <returns>Whether this lot can be used to satisfy the MR</returns>
protected override bool? IsEligibleInventory(ScenarioDetail a_sd, long a_simClock, object a_mrr, Inventory a_inv, Lot a_lot)
{
if (string.IsNullOrEmpty(a_lot?.Code)) return true;

if (a_mrr is InternalActivity act)
{
foreach (MaterialRequirement mr in act.Operation.MaterialRequirements)
{
if (mr.MustUseEligLot && !mr.BuyDirect && mr.Item.Id == a_inv.Item.Id)
{
if (mr.Warehouse != null)
{
if (mr.Warehouse.Id != a_inv.Warehouse.Id)
{
//The warehouse was specified and we are pulling from a different warehouse.
//Or the warehouse was not specified
return true;
}
}

bool codeMatch = false;
var enumerator = mr.GetEligibleLotsEnumerator();
while (enumerator.MoveNext())
{
if (enumerator.Current.Key == a_lot.Code)
{
codeMatch = true;
break;
}
}

if (!codeMatch)
{
return false;
}
}
}
}

return true;
}
}

Here we have a single override function that customizes' the Eligible Material Customization point:

IsEligibleInventory can be used to override which Lot Code to pull materials from to produce jobs.  

Notes about customization point:

  • Warehouses don't have to be set for MaterialRequirements.
  • IsEligibleInventory function can return null.
  • BuyDirect is a material that is not tracked in inventory. Item reference is null.

Let's take a look at the parameters for IsEligibleInventory:

  • ScenarioDetail a_sd: Via the various manager objects in this top-level object, all other data objects can be accessed.
  • long a_simClock: The ticks of the DateTime the scheduler is attempting to schedule an activity.
  • object a_mrr: The demand source that is trying to use the material.
  • Inventory a_inv: The item record in a warehouse of the material that is needed to complete the job.
  • Lot a_lot: The lot of material that has its eligibility checked. 

Next Steps

Example project of the customization coming soon...