예제 #1
0
        private void buttonSet_Click(object sender, RoutedEventArgs e)
        {
            PosDialogWindow         window  = IngredientAmountControl.CreateInDefaultWindow(Strings.InventorySetAmount);
            IngredientAmountControl control = window.DockedControl as IngredientAmountControl;
            PosDialogWindow         parent  = Window.GetWindow(this) as PosDialogWindow;

            control.Amount          = 0;
            control.MeasurementUnit = ActiveIngredient.MeasurementUnit;

            window.ShowDialog(parent);
            if (!window.ClosedByUser)
            {
                if (control.Amount > 0)
                {
                    double amount = UnitConversion.Convert(control.Amount, control.MeasurementUnit,
                                                           ActiveIngredient.MeasurementUnit);

                    IngredientAdjustment.Add(SessionManager.ActiveEmployee.Id, ActiveIngredient.Id,
                                             ActiveIngredient.InventoryAmount, amount, ActiveIngredient.MeasurementUnit);

                    ActiveIngredient.SetInventoryAmount(amount);
                    ActiveIngredient.Update();
                }
                UpdateListBoxItem();
            }
        }
예제 #2
0
        private void AdjustInventory(string windowTitle, int factor)
        {
            PosDialogWindow         window  = IngredientAmountControl.CreateInDefaultWindow(windowTitle);
            IngredientAmountControl control = window.DockedControl as IngredientAmountControl;
            PosDialogWindow         parent  = Window.GetWindow(this) as PosDialogWindow;

            control.Amount          = 0;
            control.MeasurementUnit = ActiveIngredient.MeasurementUnit;

            window.ShowDialog(parent);
            if (!window.ClosedByUser)
            {
                if (control.Amount > 0)
                {
                    double amount = UnitConversion.Convert(control.Amount, control.MeasurementUnit,
                                                           ActiveIngredient.MeasurementUnit) * factor;

                    IngredientAdjustment.Add(SessionManager.ActiveEmployee.Id, ActiveIngredient.Id,
                                             ActiveIngredient.InventoryAmount,
                                             ActiveIngredient.InventoryAmount + amount,
                                             ActiveIngredient.MeasurementUnit);

                    ActiveIngredient.SetInventoryAmount(ActiveIngredient.InventoryAmount + amount);
                    ActiveIngredient.Update();
                }
            }
        }
예제 #3
0
        internal bool UpdateItem()
        {
            string          fullName        = EditorDetails.FullName;
            string          shortName       = EditorDetails.ShortName;
            double          inventoryAmount = EditorDetails.InventoryAmount;
            MeasurementUnit unit            = EditorDetails.MeasurementUnit;
            double          costPerUnit     = EditorDetails.CostPerUnit;
            double?         parQuantity     = EditorDetails.ParQuantity;

            // Is there an ActiveItem?
            if (ActiveIngredient == null)
            {
                ActiveIngredient = Ingredient.Add(fullName, shortName,
                                                  inventoryAmount, unit, costPerUnit, parQuantity);
                EditorPreparation.Update(ActiveIngredient.Id);
                ActiveIngredient = Ingredient.Get(ActiveIngredient.Id);
            }
            else
            {
                if (Math.Abs(ActiveIngredient.InventoryAmount - inventoryAmount) > double.Epsilon)
                {
                    double originalAmount = UnitConversion.Convert(ActiveIngredient.InventoryAmount,
                                                                   ActiveIngredient.MeasurementUnit, unit);
                    IngredientAdjustment.Add(SessionManager.ActiveEmployee.Id,
                                             ActiveIngredient.Id, originalAmount, inventoryAmount, unit);
                }
                if (ActiveIngredient.MeasurementUnit != unit)
                {
                    IngredientAdjustment.Add(SessionManager.ActiveEmployee.Id,
                                             ActiveIngredient.Id, -1, -1, ActiveIngredient.MeasurementUnit, (int)unit);
                }

                if (EditorDetails.IsAdjustedByRecipe)
                {
                    ProcessInventoryChangesForPrepIngredients(
                        ActiveIngredient.InventoryAmount,
                        inventoryAmount);
                }
                // Update the category values for the ActiveItem
                ActiveIngredient.SetFullName(fullName);
                ActiveIngredient.SetShortName(shortName);
                ActiveIngredient.SetInventoryAmount(inventoryAmount);
                ActiveIngredient.SetMeasurementUnit(unit);
                ActiveIngredient.SetCostPerUnit(costPerUnit);
                ActiveIngredient.SetParQuantity(parQuantity);

                // Update the database
                ActiveIngredient.Update();

                EditorPreparation.Update(ActiveIngredient.Id);
                ActiveIngredient = Ingredient.Get(ActiveIngredient.Id);
            }


            return(true);
        }
        public void Update(int activeIngredientId)
        {
            Ingredient ingredient = Ingredient.Get(activeIngredientId);

            // Yield
            if (ingredient.ExtendedIngredientYield != ExtendedIngredientYield)
            {
                IngredientAdjustment.Add(SessionManager.ActiveEmployee.Id, ingredient.Id,
                                         ingredient.ExtendedIngredientYield, ExtendedIngredientYield,
                                         MeasurementUnit.None, -1);
                ingredient.UpdateExtendedIngredientYield(ExtendedIngredientYield);
            }

            // Added Ingredients
            foreach (IngredientSet ingredientSet in _ingredientSetsAdded)
            {
                ingredientSet.SetExtendedIngredientId(activeIngredientId);
                ingredientSet.Update();
                IngredientAdjustment.Add(SessionManager.ActiveEmployee.Id,
                                         ingredientSet.IngredientId, null, ingredientSet.Amount, ingredientSet.MeasurementUnit,
                                         activeIngredientId);
            }

            // Changed Ingredients
            foreach (IngredientSet ingredientSet in _ingredientSetsNeedingUpdate)
            {
                IngredientSet original  = IngredientSet.Get(ingredientSet.Id);
                double        oldAmount = UnitConversion.Convert(original.Amount, original.MeasurementUnit,
                                                                 ingredientSet.MeasurementUnit);
                ingredientSet.Update();
                IngredientAdjustment.Add(SessionManager.ActiveEmployee.Id,
                                         ingredientSet.IngredientId, oldAmount, ingredientSet.Amount, ingredientSet.MeasurementUnit,
                                         activeIngredientId);
            }

            // Removed Ingredients
            foreach (IngredientSet ingredientSet in _ingredientSetsRemoved)
            {
                IngredientSet original = IngredientSet.Get(ingredientSet.Id);
                IngredientSet.Delete(ingredientSet.Id);
                IngredientAdjustment.Add(SessionManager.ActiveEmployee.Id,
                                         ingredientSet.IngredientId, original.Amount, null, original.MeasurementUnit,
                                         activeIngredientId);
            }

            _ingredientSetsAdded.Clear();
            _ingredientSetsNeedingUpdate.Clear();
            _ingredientSetsRemoved.Clear();
        }
예제 #5
0
        private void AdjustInventoryByRecipe(string windowTitle, int factor)
        {
            if (ActiveIngredient.ExtendedIngredientYield == null)
            {
                PosDialogWindow.ShowDialog(Strings.InventoryError, Strings.Error);
                return;
            }
            double?amount = PosDialogWindow.PromptNumber(windowTitle, (double)0);

            if ((amount != null) && (amount.Value > 0))
            {
                double amountDelta = (ActiveIngredient.ExtendedIngredientYield.Value * amount.Value * factor);

                IngredientAdjustment.Add(SessionManager.ActiveEmployee.Id, ActiveIngredient.Id,
                                         ActiveIngredient.InventoryAmount,
                                         ActiveIngredient.InventoryAmount + amountDelta,
                                         ActiveIngredient.MeasurementUnit);

                ActiveIngredient.SetInventoryAmount(ActiveIngredient.InventoryAmount + amountDelta);
                ActiveIngredient.Update();

                AddIngredientPreparation(ActiveIngredient.Id, amountDelta);
            }
        }