Ejemplo n.º 1
0
        public void CreateDraftStockAdjustment(List <ViewModelFromNew> list)
        {
            userService            = new UserService(Context);
            stockAdjustmentService = new StockAdjustmentService(Context);
            itemService            = new ItemService(Context);
            notificationService    = new NotificationService(Context);

            List <StockAdjustmentDetail> detaillist = new List <StockAdjustmentDetail>();
            StockAdjustment s = new StockAdjustment();

            s.StockAdjustmentId = IdService.GetNewStockAdjustmentId(Context);
            s.CreatedBy         = userService.FindUserByEmail(CurrentUserName);
            s.CreatedDateTime   = DateTime.Now;

            foreach (ViewModelFromNew v in list)
            {
                StockAdjustmentDetail sd = new StockAdjustmentDetail();
                string itemcode          = v.Itemcode;
                Item   item = itemService.FindItemByItemCode(itemcode);
                sd.ItemCode          = itemcode;
                sd.Reason            = (v.Reason == null) ? "" : v.Reason;
                sd.StockAdjustmentId = s.StockAdjustmentId;
                sd.OriginalQuantity  = item.Inventory.Quantity;
                sd.AfterQuantity     = v.Adjustment + sd.OriginalQuantity;
                detaillist.Add(sd);
                //  stockAdjustmentDetailRepository.Save(sd);
            }
            s.StockAdjustmentDetails = detaillist;
            stockAdjustmentService.CreateDraftStockAdjustment(s);
        }
 public void TestInitialize()
 {
     context          = new ApplicationDbContext();
     saService        = new StockAdjustmentService(context);
     saRepository     = new StockAdjustmentRepository(context);
     sadRepository    = new StockAdjustmentDetailRepository(context);
     statusRepository = new StatusRepository(context);
     itemRepository   = new ItemRepository(context);
     smRepository     = new StockMovementRepository(context);
     userService      = new UserService(context);
 }
Ejemplo n.º 3
0
        public IHttpActionResult Save(List <MobileSADViewModel> models)
        {
            stockAdjustmentService = new StockAdjustmentService(Context);
            userService            = new UserService(Context);
            itemService            = new ItemService(Context);
            notificationService    = new NotificationService(Context);

            StockAdjustment SA;

            try
            {
                //create new StockAdjustment object
                SA = new StockAdjustment()
                {
                    StockAdjustmentId      = IdService.GetNewStockAdjustmentId(Context),
                    StockAdjustmentDetails = new List <StockAdjustmentDetail>(),
                    CreatedDateTime        = DateTime.Now,
                    CreatedBy = userService.FindUserByEmail(models.First().UserName)
                };

                //convert viewmodels to StockAdmustmentDetails list and link to stockadjustment object
                foreach (MobileSADViewModel m in models)
                {
                    Item item = itemService.FindItemByItemCode(m.ItemCode);
                    SA.StockAdjustmentDetails.Add(new StockAdjustmentDetail()
                    {
                        StockAdjustment  = SA,
                        ItemCode         = m.ItemCode,
                        Item             = item,
                        OriginalQuantity = Int32.Parse(m.OriginalQuantity),
                        AfterQuantity    = Int32.Parse(m.AfterQuantity),
                        Reason           = m.Reason
                    });
                }

                bool flag = false;
                foreach (StockAdjustmentDetail detail in SA.StockAdjustmentDetails)
                {
                    foreach (ItemPrice p in detail.Item.ItemPrices)
                    {
                        if (p.Price >= 250)
                        {
                            flag = true; break;
                        }
                    }
                }

                ApplicationUser supervisor = userService.FindUserByEmail(models.First().UserName).Supervisor;
                ApplicationUser manager    = supervisor.Supervisor;
                if (flag == true)
                {
                    Notification n = notificationService.CreateNotification(SA, manager);
                    new NotificationApiController().SendNotification(n.NotificationId.ToString());
                    new NotificationApiController().SendEmail(n.NotificationId.ToString());
                }
                if (flag == false)
                {
                    Notification n = notificationService.CreateNotification(SA, supervisor);
                    new NotificationApiController().SendNotification(n.NotificationId.ToString());
                    new NotificationApiController().SendEmail(n.NotificationId.ToString());
                }

                //save SA object into database
                stockAdjustmentService.updateToPendingStockAdjustment(SA);
            }
            catch (ArgumentException)
            {
                return(BadRequest("Unable to save Stock Adjustments!"));
            }

            return(Ok(SA.StockAdjustmentId));
        }