public static decimal GetItemQuantityforSale(int itemId)
        {
            decimal qty = 0;

            using (AprosysAccountingEntities db = new AprosysAccountingEntities())
            {
                var obj = db.GetStockList(itemId).FirstOrDefault();
                if (obj != null)
                {
                    qty = obj.QTY ?? 0;
                }
            }
            return(qty);
        }
Exemple #2
0
        public static IList <BO_Inventory> LoadInventory(JQueryDataTableParamModel Param)
        {
            List <BO_Inventory> lst_inventory = new List <BO_Inventory>();

            using (AprosysAccountingEntities db_aa = new AprosysAccountingEntities())
            {
                BO_Inventory obj;
                var          lst = db_aa.GetStockList(0).ToList();
                foreach (var item in lst.ToList())
                {
                    obj              = new BO_Inventory();
                    obj.itemId       = item.ItemId ?? 0;
                    obj.itemCode     = item.ItemCode;
                    obj.itemName     = item.Name;
                    obj.itemquantity = item.QTY ?? 0;
                    lst_inventory.Add(obj);
                }

                //if (Param.SearchType != 0)
                //{
                //    if (Param.SearchType == 1 && Param.SearchValue != null && Param.SearchValue != "")// && Param.SearchValue != null && Param.SearchValue != " ")
                //    {
                //        List = List.Where(x => x.name.ToLower().Contains(Param.SearchValue.Trim().ToLower())).ToList();
                //    }
                //    else if (Param.SearchType == 2)// && Param.SearchValue != null && Param.SearchValue != " ")
                //    {
                //        List = List.Where(x => x.itemCode.ToLower().Contains(Param.SearchValue.Trim().ToLower())).ToList();

                //    }

                //}

                //List<BO_Inventory> ListtoReturn = new List<BO_Inventory>();
                //ListtoReturn = lst;
                return(lst_inventory);
            }
        }
        public static IList <BO_Item> LoadItems(JQueryDataTableParamModel Param)
        {
            using (AprosysAccountingEntities db_aa = new AprosysAccountingEntities())
            {
                List <BO_Item> List = (from _item in db_aa.Items
                                       //join og in db_aa.OilGrades on _item.OilGradeId equals og.Id
                                       where _item.IsActive == true
                                       orderby _item.Id descending
                                       select new BO_Item

                {
                    id = _item.Id,
                    name = _item.Name ?? "",
                    itemCode = _item.ItemCode ?? "",
                    unit = _item.Unit ?? "",
                    description = _item.Description ?? "",
                    purchasePrice = _item.PurchasePrice ?? 0,
                    sellPrice = _item.SellPrice ?? 0,
                    taxPercent = _item.TaxPercent ?? 0,
                    minQuantity = _item.MinQty ?? 0,
                    //oilGrade = og.OilGade,
                    oilGradeId = _item.OilGradeId ?? 0,
                    quantityInCarton = _item.QuantityInCarton ?? 0,
                    packingInLitre = _item.PackingInLitre ?? 0
                }).OrderByDescending(x => x.id).ToList();
                IDictionary <int, string> oilGradesDict = db_aa.OilGrades.Select(z => new { z.Id, z.OilGade }).ToDictionary(z => Convert.ToInt32(z.Id), q => q.OilGade);
                var itemStock = db_aa.GetStockList(0).ToList();
                foreach (var item in List)
                {
                    var stock = itemStock.Where(x => x.ItemId == item.id).FirstOrDefault();
                    item.stock = stock == null ? 0 : stock.QTY;

                    if (item.oilGradeId > 0)
                    {
                        item.oilGrade = oilGradesDict[item.oilGradeId];
                    }
                    // Stock in Amount by Fifo based
                    decimal?amount        = 0;
                    var     itemPurchased = db_aa.Acc_GL.Where(x => x.ItemId == item.id && (x.TranTypeId == 1 || x.TranTypeId == 7) && x.IsActive == true).ToList();
                    foreach (var objpurchase in itemPurchased)
                    {
                        amount = amount + (objpurchase.QuantityBalance * objpurchase.UnitPrice);
                    }
                    item.stockInAmount = amount;
                }
                if (Param.SearchType != 0)
                {
                    if (Param.SearchType == 1 && Param.SearchValue != null && Param.SearchValue != "")// && Param.SearchValue != null && Param.SearchValue != " ")
                    {
                        List = List.Where(x => x.name.ToLower().Contains(Param.SearchValue.Trim().ToLower())).ToList();
                    }
                    else if (Param.SearchType == 2)// && Param.SearchValue != null && Param.SearchValue != " ")
                    {
                        List = List.Where(x => x.itemCode.ToLower().Contains(Param.SearchValue.Trim().ToLower())).ToList();
                    }
                }
                List <BO_Item> ListtoReturn = new List <BO_Item>();
                ListtoReturn = List;
                return(ListtoReturn);
            }
        }