/// <summary>
    /// Adds a prediction listing for the item to be scheduled.
    /// </summary>
    /// <param name="master"></param>
    public void AddPredictionOrder(ProductMasterItem master)
    {
        var order = PredictionList.FirstOrDefault(p => p.MasterID == master.MasterID);

        if (order == null)
        {
            PredictionList.Add(new MakeOrder(master.MasterID, master.TargetSupply * master.PiecesPerUnit));
        }
        else
        {
            order.PiecesToMake += (int)(master.PiecesPerUnit * master.TargetSupply);
        }
    }
    /// <summary>
    /// Update schedule generation data with the last scheduled item on the line
    /// </summary>
    /// <param name="item"></param>
    /// <param name="lineIndex"></param>
    public void MarkItemScheduled(ProductMasterItem item, int lineIndex, double unitsMade)
    {
        int pcsMade = (int)(unitsMade * item.PiecesPerUnit);
        var line    = StaticFactoryValuesManager.CoatingLines[lineIndex];

        LastWidth[line]     = item.Width;
        LastThickness[line] = item.Thickness;

        // remove prediction
        var prediction = PredictionList.FirstOrDefault(p => p.MasterID == item.MasterID);

        if (prediction != null)
        {
            PredictionList.Remove(prediction);
        }

        // remove sale
        var sale        = SalesList.FirstOrDefault(s => s.MasterID == item.MasterID);
        int pcsToRemove = pcsMade;

        while (sale != null)
        {
            if (sale.PiecesToMake > pcsToRemove)
            {
                sale.PiecesToMake -= pcsToRemove;
            }
            else
            {
                // made more or equal to the amount for this sale
                pcsToRemove -= sale.PiecesToMake;
                SalesList.Remove(sale);
                sale = SalesList.FirstOrDefault(s => s.MasterID == item.MasterID);
            }
        }

        // update inventory
        var invItem = CurrentInventory.FirstOrDefault(i => i.MasterID == item.MasterID);

        if (invItem != null)
        {
            invItem.Units += unitsMade;
        }
        CurrentWaste += item.Waste * unitsMade;
    }