Esempio n. 1
0
        public bool ChangeStatus(List <string> lstId, int status)
        {
            using (var cxt = new NuWebContext())
            {
                var lstObj = cxt.I_Work_Order.Where(ww => lstId.Contains(ww.Id)).ToList();
                if (lstObj != null && lstObj.Count > 0)
                {
                    lstObj.ForEach(ss => ss.Status = status);
                    cxt.SaveChanges();

                    //Approved
                    if (status == (int)Commons.EPOStatus.Approved)
                    {
                        List <InventoryModels> _lstWODetail = new List <InventoryModels>();
                        foreach (var item in lstObj)
                        {
                            //var storeId = lstObj.Select(ss => ss.StoreId).FirstOrDefault();
                            //update inventory
                            var lstWODetail = cxt.I_Work_Order_Detail.Where(ww => ww.WorkOrderId == item.Id).Select(ss => new InventoryModels
                            {
                                StoreId      = item.StoreId,
                                IngredientId = ss.IngredientId,
                                Price        = ss.UnitPrice.Value,
                                Quantity     = ss.BaseQty.HasValue ? ss.BaseQty.Value : 0
                            }).ToList();

                            _lstWODetail.AddRange(lstWODetail);
                        }
                        //Update inventory
                        var isUpdateInentoryWO = _inventoryFactory.UpdateInventoryForWO(_lstWODetail);
                        _logger.Info(string.Format("UpdateInventoryForWO: [{0}] when approved", isUpdateInentoryWO));
                    }
                    else //close
                    {
                        List <InventoryModels> _lstWODetail = new List <InventoryModels>();
                        foreach (var item in lstObj)
                        {
                            var lstWODetail = cxt.I_Work_Order_Detail.Where(ww => ww.WorkOrderId == item.Id).Select(ss => new InventoryModels
                            {
                                StoreId      = item.StoreId,
                                IngredientId = ss.IngredientId,
                                Price        = ss.UnitPrice.Value,
                                Quantity     = ss.BaseQty.HasValue ? ss.BaseQty.Value : 0,
                                POQty        = ss.Qty,
                                ReceiptQty   = ss.ReceiptNoteQty.HasValue ? ss.ReceiptNoteQty.Value : 0,
                                ReturnQty    = ss.ReturnReceiptNoteQty.HasValue ? ss.ReturnReceiptNoteQty.Value : 0
                            }).ToList();

                            _lstWODetail.AddRange(lstWODetail);
                        }
                        //Update inventory
                        var isUpdateInentoryWO = _inventoryFactory.UpdateInventoryForWOForCloseManual(_lstWODetail);
                        _logger.Info(string.Format("UpdateInventoryForWO: [{0}] when close manual", isUpdateInentoryWO));
                    }
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }