# Lot Configuration

:::overview
In this section, we're going to do all the configuration necessary to be able to trace the end-to-end process of receiving raw materials and performing the various operations to turn them into finished goods.
:::

***

## Generating Unique Lot Names (Serialization)

::embed-section{src="../../kanoa-ops/serialization.md" collapsed="true" summary="Reference Materials: Serialization"}

We're going to need a method for generating unique lot names. In actual implementation that may comes from ERP or another system, but we also provide a method for generating them.
**Serialization definitions** generate lot names. Each one has a name, a prefix, and a number of digits, so `RAL` with 10 digits gives `RAL0000000001`, `RAL0000000002` and so on. One definition per stage makes a lot's name tell you what it is.

::::action[Create the serialization definitions]

Navigate to **Configuration → Ops → Serialization** and create the following:

| Name | Prefix | Zfill |
| --- | --- | --- |
| `Raw Aluminum` | `RAL` | 10 |
| `Raw Blending Ingredients` | `RBI` | 10 |
| `WIP Machined Parts` | `WMP` | 10 |
| `WIP Coatings/Blends` | `WBL` | 10 |
| `WIP Coated Parts` | `WCP` | 10 |
| `Finished Goods Packages` | `FGP` | 10 |

Use these names exactly; the lessons and check scripts that follow look them up by name.

:::download[Download Serializations]

Skip ahead and import the serializations already made for you on the **Configuration → Ops → Serialization** page.
<a href="/files/trace-resources/serializations-export.json" download><code>serializations-export.json</code></a>
:::
::::

***

## Add New Assets to CoreForge

As material is received, inspected, machined, coated etc., We're going to want a place to store these lots before and after they have been operated on.
We're also going to be mixing blends, so we'll create those assets too.

::::action[Create Trace assets]

1. Navigate to **Configuration → Ops → Assets**.
2. Under `CoreForge\Philadelphia`, add an asset named `Storage` of type `Storage Location`.
3. Under `Storage`, add two storage locations called `Receiving` and `Shipping`, and a storage bin called `Bins`.
4. Under `CoreForge\Philadelphia`, add an asset named `Mixing` of type `Area`.
5. Under `Mixing`, add a line called `Mixer 1`, OEE Enable it and make its Process Type `Batch`.
6. Under `CoreForge\Philadelphia\Finishing`, add a line called `Auto Pack 1`, OEE Enable it and make its Process Type `Discrete`.
7. If you didn't take Quality Training, add a line called `QA Station` under `CoreForge\Philadelphia\Finishing` too. Leave OEE disabled.

:::download[Download Trace Assets]

Skip ahead and import the storage locations already made for you on the **Configuration → Ops → Assets** page.
<a href="/files/trace-resources/trace-assets.json" download><code>trace-assets.json</code></a>
:::

::::

***

## Create Mobile Transportation Assets

::embed-section{src="../../kanoa-trace/transports.md" collapsed="true" summary="Reference Materials: Transports (Mobile Assets)"}

Machined and coated parts travel between Machining, Coating, the QA Station and packing in reusable **parts totes**. A tote moves, so it isn't a location. A lot is **in** a location and **on** a tote. Totes are **mobile assets**, assets whose asset type has **Mobile** ticked. Mobile assets are offered as the **Transport** of a lot event, so you can ask what's on a tote, or which tote a lot is on, wherever the tote is.

::::action[Create the parts totes]

1. Navigate to **Configuration → Ops → Assets** and select any asset.
2. Click the edit button next to **Asset Type** to open the asset type editor.
3. In the asset type tree, select `area` and click **Add**. Name the new type `Tote`, tick **Mobile**, choose an icon, and click **Save**.
4. Under `CoreForge\Philadelphia`, add an asset named `Totes` of type `Area`. It's where the totes are kept in the asset tree, not a place lots go.
5. Under `Totes`, add three assets of type `Tote`: `Tote 01`, `Tote 02` and `Tote 03`.

The `trace-assets.json` download above includes the `Tote` type and the totes.

::::

***

## Create Coating Raw Materials

A couple of new raw materials are needed for the coatings, so import them here.

:::action[Add the coating items]

1. Download <a href="/files/trace-resources/items-coat.json" download><code>items-coat.json</code></a>: the `STD-COAT` and `PRM-COAT` raw materials in `CoreForge\RM`.
2. Navigate to **Configuration → Ops → Items** and import `items-coat.json`.

:::

***

## Configure The Lot Operations

::embed-section{src="../../kanoa-trace/lots.md#lot-operations" collapsed="true" summary="Reference Materials: Lot Operations configuration"}

Raw materials have operations performed upon them that eventually turn them into finished goods. We're going to create those lot operations here.

::::action[Create the lot operations]

1. Navigate to **Configuration → Ops → Lot Configuration** and create the following lot operations:

   | Operation | Allow Input Lots | Allow Output Lots |
   | --- | --- | --- |
   | `Blend` | Yes | Yes |
   | `Coat` | Yes | Yes |
   | `Inspect` | Yes | Yes |
   | `Machine` | Yes | Yes |
   | `Pack` | Yes | Yes |
   | `Ship` | Yes | **No** |

::::

The `Adjust` lot operation is already there. Leave it as it is: the Lot Editor uses it to correct a lot's quantity, so it's reserved. You can change its color, but not delete, rename or disable it.

The Lot Manager screen lets you execute any operation at any asset, on any item. Linking an operation to the assets where it happens and the items that go in and come out narrows the choices to the ones that make sense: Lot Manager then only offers `Mixer 1` for a `Blend`, and only the coating ingredients as its inputs. Linking an area, such as `Machining`, allows every asset in it. Linking an item class, such as `WIP\Coated`, allows every item in it. Links only narrow the choices on screens; they aren't database rules, so a script can still run an operation anywhere.

::::action[Link the operations to assets and items]

1. Navigate to **Configuration → Ops → Lot Configuration**.
2. For each operation in the table below, select it in the lot operations table, then:
   - On the **Asset Links** tab, select its assets in the tree and click **Link**, the chain-link icon next to the tree.
   - On the **Item Links** tab, select its input items or item classes in the tree and click **Link as input**, the icon with an arrow before the chain link. Then select its outputs and click **Link as output**, the icon with the arrow after the chain link.

   The link buttons are icons without text; hover over one to see its name.

   Assets are under `CoreForge\Philadelphia`, and items and item classes under `CoreForge`.

   | Operation | Assets | Inputs | Outputs |
   | --- | --- | --- | --- |
   | `Receive` | `Storage` | | `RM` |
   | `Machine` | `Machining` | `RM\AL2024`, `RM\AL6061`, `RM\AL7075` | `WIP\Machined` |
   | `Blend` | `Mixing\Mixer 1` | `RM\STD-COAT`, `RM\PRM-COAT` | `WIP\Coatings` |
   | `Coat` | `Coating` | `WIP\Machined`, `WIP\Coatings` | `WIP\Coated` |
   | `Inspect` | `Finishing\QA Station` | `WIP\Coated` | `WIP\Coated` |
   | `Pack` | `Finishing\Auto Pack 1`, `Finishing\Manual Pack 1` | `WIP\Coated` | `FG` |
   | `Ship` | `Storage\Shipping` | `FG` | |

3. Leave `Transfer` and `Scrap` unlinked. They happen almost anywhere, to almost anything.

`Receive` is linked to the `Storage` area, so material can only be received into the storage locations and bins under it, and to the `RM` class, so only raw materials are received. `Machine` links the three aluminum items rather than the `RM` class, because `RM` also holds the coating ingredients.

:::download[Download lot operations]

Skip ahead and import the lot operations, with their asset and item links, on the **Configuration → Ops → Lot Configuration** page. Import it after the Trace assets and coating items, because links to assets or items that don't exist yet are skipped.
<a href="/files/trace-resources/lot-operations.json" download><code>lot-operations.json</code></a>
:::

::::

***

## Define Lot States And Reasons

Every lot event records a **lot state**, the condition of the material: `OK`, `Hold` or `Scrap` to start with. A **lot state reason** says why, such as `Missing COA` for a hold. Linking a reason to an asset offers it only where it applies, and to the assets under it; a reason that isn't linked to any asset is offered everywhere.

::embed-section{src="../../kanoa-trace/lots.md#lot-states" collapsed="true" summary="Reference Materials: Lot States"}

::embed-section{src="../../kanoa-trace/lots.md#lot-state-reasons" collapsed="true" summary="Reference Materials: Lot State Reasons"}

::::action[Add lot states and reasons, and link them to assets]

1. Navigate to **Configuration → Ops → Lot Configuration** and open the **Lot States** tab.
2. Under **Lot States**, click **Add** and add a `Rework` state for material that goes back for another pass.
3. Under **Lot State Reasons**, add these reasons:

   | Reason | Lot state | Linked to |
   | --- | --- | --- |
   | `Missing COA` | `Hold` | `Storage\Receiving` |
   | `Awaiting lab results` | `Hold` | `Finishing\QA Station` |
   | `Failed visual inspection` | `Scrap` | `Finishing\QA Station` |
   | `Coating defect` | `Scrap` | `Coating` |
   | `Damaged in handling` | `Scrap` | |
   | `Recoat` | `Rework` | `Finishing\QA Station` |

4. Link each reason to its asset: select the reason, select the asset in the **Assets** tree, and click **Link**, the chain-link icon. Assets are under `CoreForge\Philadelphia`. Leave `Damaged in handling` unlinked, so it can be chosen anywhere.

:::download[Download Lot States & Reasons]

Skip ahead and import the lot states and reasons already made for you on the **Configuration → Ops → Lot Configuration** **Lot States** tab.
<a href="/files/trace-resources/lot-states-and-reasons.json" download><code>lot-states-and-reasons.json</code></a>
:::

::::

:::check

Copy this script into the Ignition Designer Script Console (**Tools → Script Console**) and run it. It checks the six lot operations, their input and output settings and their asset and item links, the coating items, the `Rework` state and the six lot state reasons with their asset links, the six serializations with their names, prefixes and digits, the `Storage` asset with its `Receiving`, `Shipping` and `Bins` locations, the `Mixing` area with `Mixer 1`, `Finishing\Auto Pack 1` and `Finishing\QA Station`, the three mobile parts totes and that Lot Manager offers them as a **Transport**, Mixer 1 and Auto Pack 1 must be OEE Enabled, `Mixer 1` with Process Type `batch` and `Auto Pack 1` with `discrete`. Each check prints PASS or FAIL with what to fix. It doesn't change anything.

<details>
<summary>Show the check script</summary>

::check-script{src="trace/02-lot-configuration.py" title="checkLesson-lotConfiguration.py"}

</details>

:::
