コード例 #1
0
        public ActionResult CreateAdjustItems([Bind(Prefix = "updated")] List <AdjustItemModel> updatedItems,
                                              [Bind(Prefix = "created")] List <AdjustItemModel> createdItems,
                                              [Bind(Prefix = "deleted")] List <AdjustItemModel> deletedItems)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    //Create AdjustItems
                    if (updatedItems != null)
                    {
                        //get the current adjust
                        var adjustId    = updatedItems.Count > 0 ? updatedItems[0].AdjustId : 0;
                        var adjustItems = _adjustItemRepository.GetAll().Where(r => r.AdjustId == adjustId).ToList();
                        foreach (var model in updatedItems)
                        {
                            //we don't merge if the adjust item already existed
                            if (!adjustItems.Any(r => r.ItemId == model.ItemId))
                            {
                                //manually mapping here to set only foreign key
                                //if used AutoMapper, the reference property will also be mapped
                                //and EF will consider these properties as new and insert it
                                //so db records will be duplicated
                                //we can also ignore it in AutoMapper configuation instead of manually mapping
                                var adjustItem = new AdjustItem
                                {
                                    AdjustId        = model.AdjustId,
                                    ItemId          = model.ItemId,
                                    StoreLocatorId  = model.StoreLocator.Id,
                                    AdjustQuantity  = model.AdjustQuantity,
                                    AdjustUnitPrice = model.AdjustUnitPrice
                                };
                                _adjustService.UpdateAdjustCost(adjustItem);
                                _adjustItemRepository.Insert(adjustItem);
                            }
                        }
                    }

                    _dbContext.SaveChanges();
                    SuccessNotification(_localizationService.GetResource("Record.Saved"));
                    return(new NullJsonResult());
                }
                catch (Exception e)
                {
                    return(Json(new { Errors = e.Message }));
                }
            }
            else
            {
                return(Json(new { Errors = ModelState.SerializeErrors() }));
            }
        }
コード例 #2
0
        public virtual void Approve(PhysicalCount physicalCount)
        {
            if (physicalCount.IsApproved == false)
            {
                bool needAdjust = false;
                var  adjust     = new Adjust();

                //add adjust from physical count
                foreach (var item in physicalCount.PhysicalCountItems)
                {
                    var currentQuantity = _storeService.GetTotalQuantity(item.StoreLocator.StoreId, item.StoreLocatorId, item.ItemId);
                    if (item.Count.HasValue && item.Count != currentQuantity)
                    {
                        needAdjust = true;
                        var adjustItem = new AdjustItem
                        {
                            StoreLocatorId = item.StoreLocatorId,
                            ItemId         = item.ItemId,
                            AdjustQuantity = item.Count - currentQuantity
                        };
                        adjust.AdjustItems.Add(adjustItem);
                    }
                }

                if (needAdjust == true)
                {
                    adjust.Name       = adjust.Description = string.Format("Auto Generated adjust for PhysicalCount {0}", physicalCount.Number);
                    adjust.AdjustDate = DateTime.UtcNow;
                    adjust.SiteId     = physicalCount.SiteId;
                    adjust.StoreId    = physicalCount.StoreId;
                    string number = _autoNumberService.GenerateNextAutoNumber(_dateTimeHelper.ConvertToUserTime(DateTime.UtcNow, DateTimeKind.Utc), adjust);
                    adjust.Number          = number;
                    adjust.PhysicalCountId = physicalCount.Id;
                    _adjustRepository.InsertAndCommit(adjust);
                }

                physicalCount.IsApproved = true;
                if (needAdjust == true)
                {
                    physicalCount.AdjustId = adjust.Id;
                }

                _physicalCountRepository.UpdateAndCommit(physicalCount);
            }
        }
コード例 #3
0
        public virtual void UpdateAdjustCost(AdjustItem adjustItem)
        {
            if (adjustItem.AdjustQuantity > 0)
            {
                adjustItem.AdjustCost = adjustItem.AdjustQuantity * adjustItem.AdjustUnitPrice;
            }
            else
            {
                decimal?totalCost    = 0;
                var     storeLocator = _storeLocatorRepository.GetById(adjustItem.StoreLocatorId);
                _storeService.FindStoreLocatorItemRemovals(
                    storeLocator.StoreId,
                    adjustItem.StoreLocatorId,
                    adjustItem.ItemId,
                    -adjustItem.AdjustQuantity ?? 0,
                    out totalCost);

                adjustItem.AdjustCost = totalCost;
            }
        }
コード例 #4
0
        public ActionResult CreateAdjustItem(long adjustId)
        {
            //need to get adjust here to assign to new adjustItem
            //so when mapping to Model, we will have StoreId as defined
            //in AutoMapper configuration
            var adjust     = _adjustRepository.GetById(adjustId);
            var adjustItem = new AdjustItem
            {
                IsNew  = true,
                Adjust = adjust
            };

            _adjustItemRepository.Insert(adjustItem);

            this._dbContext.SaveChanges();

            var model = new AdjustItemModel();

            model = adjustItem.ToModel();
            var html = this.AdjustItemPanel(model);

            return(Json(new { Id = adjustItem.Id, Html = html }));
        }