Esempio n. 1
0
        public IngStockCountController()
        {
            _factory            = new StockCountFactory();
            _InventoryFactory   = new InventoryFactory();
            _BusinessDayFactory = new BusinessDayFactory();

            ViewBag.ListStore = GetListStore();
            //==========
            lstStore    = ViewBag.ListStore;
            listStoreId = lstStore.Select(x => x.Value).ToList();
        }
Esempio n. 2
0
        public ResultModels Insert(StockUsageRequestModel info)
        {
            //_logger.Info(info);
            NSLog.Logger.Info("Start insert [Stock Usage] data.......................", info);

            var result = new ResultModels();

            if (info.ListDetails != null && info.ListDetails.Any())
            {
                StockUsageFactory stockUsageFactory = new StockUsageFactory();
                result.IsOk = stockUsageFactory.Insert(info);
            }
            else
            {
                //AutoCreate DataEntry
                StockCountFactory _stockCountFactory = new StockCountFactory();
                Task.Run(() => _stockCountFactory.AutoCreatedStockCount(info.CompanyId, info.StoreId, info.BusinessId, info.DateFrom, info.DateTo, null));
            }
            return(result);
        }
Esempio n. 3
0
        public bool InsertAlocation(List <IngredientsUsageModels> lstInput, string createdBy, ref string msg)
        {
            bool         result       = true;
            ResultModels resultModels = new ResultModels();
            string       allocationId = string.Empty;

            using (NuWebContext cxt = new NuWebContext())
            {
                using (var transaction = cxt.Database.BeginTransaction())
                {
                    try
                    {
                        List <StockCountDetailModels> lstStockCount = new List <StockCountDetailModels>();

                        var lstDate = lstInput.GroupBy(gg => new { BusinessId = gg.BusinessId, StoreId = gg.StoreId }).ToList();
                        List <I_Allocation>       lstHeaderInsert = new List <I_Allocation>();
                        I_Allocation              allocation      = new I_Allocation();
                        List <I_AllocationDetail> lstDetailInsert = new List <I_AllocationDetail>();
                        I_AllocationDetail        itemDetail      = new I_AllocationDetail();
                        foreach (var item in lstDate)
                        {
                            allocation              = new I_Allocation();
                            allocation.ApplyDate    = item.Select(ss => ss.Date).FirstOrDefault();
                            allocation.StoreId      = item.Key.StoreId;
                            allocation.BusinessId   = item.Key.BusinessId;
                            allocation.IsActived    = true;
                            allocation.Id           = Guid.NewGuid().ToString();
                            allocationId            = allocation.Id;
                            allocation.CreatedBy    = createdBy;
                            allocation.ModifierBy   = createdBy;
                            allocation.CreatedDate  = DateTime.Now;
                            allocation.ModifierDate = DateTime.Now;

                            lstHeaderInsert.Add(allocation);

                            //Details
                            foreach (var subItem in item.ToList())
                            {
                                itemDetail              = new I_AllocationDetail();
                                itemDetail.Id           = Guid.NewGuid().ToString();
                                itemDetail.AllocationId = allocation.Id;
                                itemDetail.IngredientId = subItem.IngredientId;
                                itemDetail.OpenBal      = subItem.OpenBal;
                                itemDetail.CloseBal     = subItem.CloseBal;
                                itemDetail.Sales        = subItem.Sales;
                                itemDetail.ActualSold   = subItem.ActualSold;
                                itemDetail.Damage       = subItem.Damage;
                                itemDetail.Wast         = subItem.Wast;
                                itemDetail.Others       = subItem.Others;

                                if (string.IsNullOrEmpty(subItem.Reasons))
                                {
                                    itemDetail.Reasons = string.Empty;
                                }
                                else
                                {
                                    itemDetail.Reasons = subItem.Reasons;
                                }


                                lstDetailInsert.Add(itemDetail);

                                //for stockcount
                                lstStockCount.Add(new StockCountDetailModels()
                                {
                                    StoreId      = item.Key.StoreId,
                                    BusinessId   = item.Key.BusinessId,
                                    IngredientId = subItem.IngredientId,
                                    Damage       = subItem.Damage,
                                    Wastage      = subItem.Wast,
                                    OtherQty     = subItem.Others,
                                    Reasons      = itemDetail.Reasons
                                });
                            }
                        }

                        cxt.I_Allocation.AddRange(lstHeaderInsert);
                        cxt.I_AllocationDetail.AddRange(lstDetailInsert);
                        cxt.SaveChanges();
                        transaction.Commit();

                        //uppdate stockcount
                        StockCountFactory _stockCountFactory = new StockCountFactory();
                        _stockCountFactory.UpdateStockCountWhenInsertAllocation(lstStockCount, ref resultModels);
                        _logger.Info(string.Format("UpdateStockCountWhenInsertAllocation: [{0}] - [{1}]", resultModels.IsOk, resultModels.Message));
                    }
                    catch (Exception ex)
                    {
                        _logger.Error(ex);
                        result = false;
                        transaction.Rollback();
                    }
                    finally
                    {
                        if (cxt != null)
                        {
                            cxt.Dispose();
                        }
                    }
                }
            }
            return(result);
        }