public IActionResult OnGet(int?Id = null)
        {
            if (Id.HasValue)
            {
                Editing  = true;
                Material = _db.SearchRawMaterialItems(Id.Value);
                if (Material == default)
                {
                    Editing      = false;
                    ErrorMessage = "Purchase not found. Please return to the previous page and try again.";
                    Material     = new RawMaterialItem();
                    return(Page());
                }

                foreach (var item in Material.Purchases)
                {
                    if (item.CurrentInventory > 0)
                    {
                        Purchases.Add(item);
                    }
                    TotalValue     += item.CurrentInventory * item.LandedCostPerUnit;
                    TotalInventory += item.CurrentInventory;
                    ScrapValue     += item.ScrapValue.GetValueOrDefault(0);
                }
            }
            else
            {
                Editing  = false;
                Material = new RawMaterialItem();
            }

            return(Page());
        }
        public void UpdateItem(int material)
        {
            RawMaterialItem temp = _db.SearchRawMaterialItems(material);

            UpdateCurrentInventory(temp);
            UpdateCostPerUnit(temp);
            UpdateLandedCost(temp);
            _db.AddRawMaterial(temp);
        }
Ejemplo n.º 3
0
        public void Test1()
        {
            IDBContext             context = new SQLDBContext();
            RawMaterialItemManager item    = new RawMaterialItemManager(context);

            item.UpdateItem(4);

            RawMaterialItem rawMaterialItem = context.SearchRawMaterialItems(4);

            //Assert.True(Math.Round(rawMaterialItem.CostPerUnit, 2) == 0.29);
            //Assert.True(Math.Round(rawMaterialItem.LandedCostPerUnit, 2) == 0.43);
        }
Ejemplo n.º 4
0
 public bool AddRawMaterial(RawMaterialItem rawMaterialItem)
 {
     try
     {
         RawMaterialItem.Update(rawMaterialItem);
         SaveChanges();
         return(true);
     }
     catch (Exception e)
     {
         return(false);
     }
 }
 private void UpdateCostPerUnit(RawMaterialItem item)
 {
     /*try
      * {
      *  item.LandedCostPerUnit = item.Purchases.WeightedAverage(e => e.LandedCostPerUnit, e => e.CurrentInventory);
      *  item.CostPerUnit = item.Purchases.WeightedAverage(e => e.CostPerUnit, e => e.CurrentInventory);
      * }
      * catch (DivideByZeroException)
      * {
      *  item.LandedCostPerUnit = 0;
      *  item.CostPerUnit = 0;
      * }*/
 }
Ejemplo n.º 6
0
 public RawMaterialItem SearchRawMaterialItems(int id)
 {
     return(RawMaterialItem
            .Include(e => e.Purchases)
            .FirstOrDefault(e => e.RawMaterialItemId == id));
 }
Ejemplo n.º 7
0
 public IEnumerable <RawMaterialItem> GetRawMaterialItems(string search = null)
 {
     return(RawMaterialItem.Where(e => search == null || e.MaterialName.Contains(search)));
 }
 private void UpdateLandedCost(RawMaterialItem temp)
 {
     //temp.LandedCost = temp.Purchases.Sum(e => e.LandedCost);
 }
 private void UpdateCurrentInventory(RawMaterialItem temp)
 {
     //temp.CurrentInventory = temp.Purchases.Sum(e => e.CurrentInventory);
 }