예제 #1
0
 static async Task GetStockInfoFromYahoo(StockViewModel stock)
 {
     var completUrl = yahooRestApiUrl1 + stock.Symbol + yahooRestApiUrl2;
     var infos = GetSymbolInfo(completUrl);
     XDocument doc = XDocument.Parse(infos);
     var quote = doc.Elements("query").Elements("results").Elements("quote");
     stock.DaysRange = quote.Elements().First(x => x.Name == "DaysRange").Value;
     stock.LastTradePrice = Double.Parse(quote.Elements().First(x => x.Name == "LastTradePrice").Value);
 }
        public static StockListViewModel GetStockByUser(string username)
        {
            Entities           entities = new Entities();
            StockListViewModel result   = new StockListViewModel();
            DateTime           current  = DateTime.Now;

            var stocks = entities.Assets.Include("StockTransactions").Include("Liabilities").Where(x => x.Username.Equals(username) &&
                                                                                                   x.AssetType == (int)Constants.Constants.ASSET_TYPE.STOCK &&
                                                                                                   !x.DisabledDate.HasValue);

            foreach (var stock in stocks)
            {
                StockViewModel stockViewModel = new StockViewModel();
                stockViewModel.Id   = stock.Id;
                stockViewModel.Name = stock.AssetName;
                stockViewModel.Note = stock.Note;

                foreach (var transactions in stock.StockTransactions.Where(x => !x.DisabledDate.HasValue))
                {
                    StockTransactionViewModel transactionViewModel = StockQueries.CreateViewModel(transactions);
                    stockViewModel.Transactions.Transactions.Add(transactionViewModel);
                }

                var liabilities = stockViewModel.Transactions.Transactions.Select(x => x.Liabilities.Liabilities.Where(y => y.StartDate <= current && y.EndDate >= current));
                stockViewModel.TotalLiabilityValue          = liabilities.Sum(x => x.Sum(y => y.Value.HasValue ? y.Value.Value : 0));
                stockViewModel.TotalOriginalPayment         = liabilities.Sum(x => x.Sum(y => y.MonthlyOriginalPayment));
                stockViewModel.TotalInterestPayment         = liabilities.Sum(x => x.Sum(y => y.MonthlyInterestPayment));
                stockViewModel.TotalMonthlyPayment          = liabilities.Sum(x => x.Sum(y => y.TotalMonthlyPayment));
                stockViewModel.TotalPayment                 = liabilities.Sum(x => x.Sum(y => y.TotalPayment));
                stockViewModel.TotalRemainedValue           = liabilities.Sum(x => x.Sum(y => y.RemainedValue));
                stockViewModel.TotalOriginalInterestPayment = liabilities.Sum(x => x.Sum(y => y.OriginalInterestPayment));
                stockViewModel.TotalInterestRate            = stockViewModel.TotalLiabilityValue > 0 ? stockViewModel.TotalOriginalInterestPayment / stockViewModel.TotalLiabilityValue * 12 : 0;
                stockViewModel.RowSpan = stockViewModel.Transactions.Transactions.Any() ? stockViewModel.Transactions.Transactions.Count() + stockViewModel.Transactions.Transactions.Select(x => x.Liabilities.Liabilities).Count() + 4 : 4;

                if (stockViewModel.Transactions.Transactions.Any())
                {
                    stockViewModel.RowSpan = 4;
                    bool flag = false;
                    foreach (var transaction in stockViewModel.Transactions.Transactions)
                    {
                        if (transaction.Liabilities.Liabilities.Count() > 0)
                        {
                            if (flag == false)
                            {
                                flag = true;
                            }
                            stockViewModel.RowSpan += transaction.Liabilities.Liabilities.Count();
                        }
                    }
                    if (flag == true)
                    {
                        stockViewModel.RowSpan += 1;
                    }
                }
                else
                {
                    stockViewModel.RowSpan = 4;
                }

                result.Stocks.Add(stockViewModel);
            }

            result.TotalValue    = result.Stocks.Select(x => x.Transactions.Transactions).Sum(x => x.Sum(y => y.StockValue.Value));
            result.IsInitialized = UserQueries.IsCompleteInitialized(username);

            return(result);
        }
예제 #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="StocksView"/> class.
        /// </summary>
        public StocksView()
        {
            InitializeComponent();

            // Lets grab the data context
            _vm = DataContext as StockViewModel;
            if (_vm == null)
            {
                var error = new NullReferenceException("DataContext must be of type StockViewModel");
                DebugManager.LogError(error);
                throw error;
            }

            _vm.PropertyChanged += OnViewModelPropertyChanged;
            // If we have any saved information for last run, lets load it
            //_vm.Load();

            // Add some default data
            _vm.AddStockToWatchList(new List <string> {
                "ADBE", "MSFT", "INTC"
            });
            //_vm.AddStockToWatchList(new List<string> { "MSFT", });

            // get names of all axis scales
            var listAxisScales = new List <string>
            {
                AppStrings.Chart_AxisScale_Linear,
                AppStrings.Chart_AxisScale_Logarithmic
            };

            // bind axis scales to the chart's scale ComboBox
            this.ChartScaleComboBox.ItemsSource   = listAxisScales;
            this.ChartScaleComboBox.SelectedIndex = 0;

            // get names of all axis scales
            var listTrendlineTypes = new List <TrendLineType>
            {
                TrendLineType.None,
                TrendLineType.CubicFit,
                TrendLineType.CumulativeAverage,
                TrendLineType.ExponentialAverage,
                TrendLineType.ExponentialFit,
                TrendLineType.LinearFit,
                TrendLineType.LogarithmicFit,
                TrendLineType.ModifiedAverage,
                TrendLineType.PowerLawFit,
                TrendLineType.QuadraticFit,
                TrendLineType.QuarticFit,
                TrendLineType.QuinticFit,
                TrendLineType.SimpleAverage,
                TrendLineType.WeightedAverage
            };

            // bind trendline types to the chart's trendline ComboBox
            this.ChartTrendLineComboBox.ItemsSource   = listTrendlineTypes;
            this.ChartTrendLineComboBox.SelectedIndex = 0;

            // Select the First Stock
            //  _vm.SelectStockCommand.Execute("INTC");
            this.Loaded += OnNavigationPageLoaded;
        }
 public void ClearSVM(StockViewModel vm)
 {
     vm.portfolio.Clear();
     vm.stock = null;
 }
예제 #5
0
 public ActionResult Index()
 {
     var userName = System.Web.HttpContext.Current.User.Identity.Name;
     var user = this._systemService.GetUserAndRole(0, userName);
     if (user == null) return RedirectToAction("Index", "Login");
     if (user.StockR == 0) return RedirectToAction("Index", "Home");
     var model = new StockViewModel
     {
         UserLogin = user,
         Stores = new SelectList(_systemService.StoreList(), "Id", "Name"),
         Types = new SelectList(_systemService.TypeStockList(), "Id", "Name"),
         Categories = new SelectList(_systemService.CategoryStockList(0), "Id", "Name")
     };
     return View(model);
 }
예제 #6
0
        public JsonResult Create(StockViewModel model)
        {
            if (model.V3 != true)
            {
                return Json(new { result = Constants.UnSuccess });
            }

            return model.Stock.Id == 0 ? CreateData(model) : EditData(model);
        }
예제 #7
0
        public StockViewModel GetStockById(int id)
        {
            var            URL_Id  = id.ToString().PadLeft(4, '0');
            StockViewModel stockVM = new StockViewModel()
            {
                StockID = URL_Id
            };

            string URL = "q/q?s=" + URL_Id;
            var    dom = BrowsingContext.New(config).OpenAsync(yahooStockURL + URL).Result;

            #region Hide
            var mainSelector = @"center > table:nth-child(9) > tbody > tr > td > table > tbody > tr:nth-child(2) > ";

            StockSelector stock = new StockSelector()
            {
                StockName       = mainSelector + "td:nth-child(1) > a:nth-child(1)",
                StockTime       = mainSelector + "td:nth-child(2)",
                StockDeal       = mainSelector + "td:nth-child(3)",
                StockBuy        = mainSelector + "td:nth-child(4)",
                StockSell       = mainSelector + "td:nth-child(5)",
                StockGainDrop   = mainSelector + "td:nth-child(6) > font",
                StockShareCount = mainSelector + "td:nth-child(7)",
                StockYesterday  = mainSelector + "td:nth-child(8)",
                StockOpen       = mainSelector + "td:nth-child(9)",
                StockTop        = mainSelector + "td:nth-child(10)",
                StockDown       = mainSelector + "td:nth-child(11)",
            };

            //判斷是否有此股票
            var page = dom.QuerySelector(stock.StockName);

            if (page == null)
            {
                return(null);
            }

            var newStockProp = (from x in TypeDescriptor.GetProperties(stock).Cast <PropertyDescriptor>()
                                where x.Name != "StockID"
                                select x);

            var setStockProp = (from x in TypeDescriptor.GetProperties(stockVM).Cast <PropertyDescriptor>()
                                where x.Name != "StockID"
                                select x);

            foreach (var prop in newStockProp)
            {
                var selectorString = prop.GetValue(stock).ToString();
                var data           = (Object)dom.QuerySelectorAll(selectorString)
                                     .Select(x => x.TextContent).FirstOrDefault().Replace("\n", "").Replace(URL_Id, "");

                foreach (var item in setStockProp)
                {
                    if (prop.Name == item.Name)
                    {
                        if (item.Name == "StockGainDrop")
                        {
                            data = (Object)data.ToString();
                        }

                        PropertyInfo p = stockVM.GetType().GetProperty(item.Name);
                        p.SetValue(stockVM, data);
                    }
                }
            }

            #endregion

            return(stockVM);
        }
예제 #8
0
        public ActionResult SearchStockStockReturnFilter(int page, int size, string stockCode, string stockName, int project, int type, int category)
        {
            var totalRecord = _stockService.StockReturnListConditionCount(page, size, stockCode, stockName, project, type, category);
            var totalTemp = Convert.ToDecimal(totalRecord) / Convert.ToDecimal(size);
            var totalPages = Convert.ToInt32(Math.Ceiling(totalTemp));
            var model = new StockViewModel
            {
                StockVs = _stockService.StockReturnListCondition(page, size, stockCode, stockName, project, type, category),
                TotalRecords = Convert.ToInt32(totalRecord),
                TotalPages = totalPages,
                CurrentPage = page,
                PageSize = size
            };

            return PartialView("Partials/_SearchStockStockReturnPartial", model);
        }
        public ActionResult AddToOrders([Bind(Include = "OrderID,status,CustomerID,Total")] Order order, StockViewModel svm)
        {
            //try
            //{
            DateTime today    = DateTime.Now.Date;
            int      stockid  = Convert.ToInt16(svm.StockID);
            int      quantity = Convert.ToInt16(svm.QuantityWanted);
            var      cropvar  = db.Stocks.Where(x => x.StockID == stockid).Select(y => y.CropID).First();
            int      cropid   = Convert.ToInt16(cropvar);
            var      cropname = db.CropInfoes.Where(x => x.CropID == cropid).Select(y => y.Name).First();
            var      price    = db.Stocks.Where(a => a.StockID == stockid).Select(b => b.Price).Single();

            bool check = svm.lowQuantitycheck(quantity);

            if (check == true)
            {
                string name = User.Identity.Name;

                var getAcctId = (from x in db.Accounts
                                 where x.UserName == name
                                 select x.AccountID).First();

                int accid = Convert.ToInt16(getAcctId);

                var getCustId = (from x in db.Customers
                                 where x.AccountID == accid
                                 select x.CustomerID).First();

                int customerID = Convert.ToInt16(getCustId);

                order.CustomerID = customerID;

                var findCust = db.Customers.Where(a => a.CustomerID == order.CustomerID).Select(b => b.CustomerID).Count();

                var checkCustOrders = db.Orders.Where(a => a.CustomerID == order.CustomerID).Select(b => b.OrderID).Count();

                var oDate = db.Orders.Where(a => a.CustomerID == order.CustomerID).OrderByDescending(x => x.OrderID).Select(b => b.DateOfOrder).Count();

                // DateTime orderDate = Convert.ToDateTime(oDate);

                order.DateOfOrder = today;

                if (checkCustOrders > 0 && oDate > 0)
                {
                    var oId = db.Orders.Where(a => a.CustomerID == order.CustomerID).OrderByDescending(x => x.OrderID).Select(b => b.OrderID).First();

                    var total = db.Orders.Where(a => a.CustomerID == order.CustomerID).OrderByDescending(x => x.OrderID).Select(b => b.Total).First();
                    order.OrderID = Convert.ToInt16(oId);

                    order.Total  = (Convert.ToDouble(price) * quantity) + Convert.ToDouble(total);
                    order.status = "Pending";

                    db.Entry(order).State = EntityState.Modified;
                    db.SaveChanges();
                }
                else
                {
                    order.Total  = (Convert.ToDouble(price)) * quantity;
                    order.status = "Pending";

                    db.Orders.Add(order);
                    db.SaveChanges();
                }

                int stockID = Convert.ToInt16(stockid);

                var subPrice = db.Stocks.Where(x => x.StockID == stockID).Select(s => s.Price).Single();

                StockOrder so = new StockOrder();
                so.StockID  = stockID;
                so.OrderID  = order.OrderID;
                so.Quantity = quantity;
                so.SubPrice = Convert.ToInt16(subPrice);

                StockOrdersController soc = new StockOrdersController();
                soc.AddStockOrders(so);

                Stock st = new Stock();
                st.stockDeduct(so.Quantity, stockid);

                TempData["SuccessMessage"] = quantity + " " + cropname + " successfully added to orders";

                return(RedirectToAction("Store", "Stocks"));
            }
            else
            {
                TempData["lessQuantityMessage"] = "Selected Quantity not available";
                return(RedirectToAction("Store", "Stocks"));
            }
            //}
            //catch
            //{
            //    return Content("Failed");
            //}
        }
예제 #10
0
        private JsonResult EditData(StockViewModel model)
        {
            if (model.CheckCode != model.Stock.vStockID)
            {
                if (_service.ExistedCode(model.Stock.vStockID))
                {
                    return Json(new { result = Constants.DuplicateCode });
                }
            }

            if (model.CheckName != model.Stock.vStockName)
            {
                if (_service.ExistedName(model.Stock.vStockName))
                {
                    return Json(new { result = Constants.Duplicate });
                }
            }

            var entity = _service.GetByKey(model.Stock.Id);
            if (!Convert.ToBase64String(model.Stock.Timestamp).Equals(Convert.ToBase64String(entity.Timestamp)))
            {
                return Json(new { result = Constants.DataJustChanged });
            }

            try
            {
                entity.vStockID = model.Stock.vStockID;
                entity.vStockName = model.Stock.vStockName;
                entity.vRemark = model.Stock.vRemark;
                entity.bUnitID = model.Stock.bUnitID;
                entity.vBrand = model.Stock.vBrand;
                entity.bCategoryID = model.Stock.bCategoryID;
                entity.bPositionID = model.Stock.bPositionID;
                //entity.bLabelID = model.Stock.bLabelID;
                entity.bWeight = model.Stock.bWeight;
                entity.vAccountCode = model.Stock.vAccountCode;
                entity.iType = model.Stock.iType;
                entity.PartNo = model.Stock.PartNo;
                entity.PartNoFor = model.Stock.PartNoFor;
                entity.PartNoMiniQty = model.Stock.PartNoMiniQty;
                entity.RalNo = model.Stock.RalNo;
                entity.ColorName = model.Stock.ColorName;
                entity.Position = model.Stock.Position;
                entity.SubCategory = model.Stock.SubCategory;
                entity.UserForPaint = model.Stock.UserForPaint;
                entity.iModified = model.LoginId;
                entity.dModified = DateTime.Now;
                _service.Update(entity);

                return Json(new { result = Constants.Success });
            }
            catch (Exception e)
            {
                Log.Error("Update Stock!", e);
                return Json(new { result = Constants.UnSuccess });
            }
        }
예제 #11
0
        private JsonResult CreateData(StockViewModel model)
        {
            if (_service.ExistedCode(model.Stock.vStockID))
            {
                return Json(new { result = Constants.DuplicateCode });
            }

            if (_service.ExistedName(model.Stock.vStockName))
            {
                return Json(new { result = Constants.Duplicate });
            }

            try
            {
                model.Stock.iEnable = true;
                model.Stock.iCreated = model.LoginId;
                model.Stock.dCreated = DateTime.Now;
                _service.Insert(model.Stock);

                return Json(new { result = Constants.Success, id= model.Stock.Id });
            }
            catch (Exception e)
            {
                Log.Error("Create New Stock!", e);
                return Json(new { result = Constants.UnSuccess });
            }
        }
예제 #12
0
        public ActionResult Create(int? id)
        {
            var userName = System.Web.HttpContext.Current.User.Identity.Name;
            var user = _systemService.GetUserAndRole(0, userName);
            if (user == null)
            {
                return RedirectToAction("Index", "Login");
            }

            if (user.StockR == 0)
            {
                return RedirectToAction("Index", "Home");
            }

            var item = new WAMS_STOCK();

            if (id.HasValue)
            {
                item = _service.GetByKey(id.Value);
            }

            var model = new StockViewModel
            {
                Id = item.Id,
                vStockID = item.vStockID,
                vStockName = item.vStockName,
                vRemark = item.vRemark,
                bUnitID = item.bUnitID,
                vBrand = item.vBrand,
                bCategoryID = item.bCategoryID,
                bPositionID = item.bPositionID,
                //bLabelID = item.bLabelID,
                bWeight = item.bWeight,
                vAccountCode = item.vAccountCode,
                iType = item.iType,
                PartNo = item.PartNo,
                PartNoFor = item.PartNoFor,
                PartNoMiniQty = item.PartNoMiniQty,
                RalNo = item.RalNo,
                ColorName = item.ColorName,
                Position = item.Position,
                SubCategory = item.SubCategory,
                UserForPaint = item.UserForPaint,
                Timestamp = item.Timestamp,
                UserLogin = user,
                Types = new SelectList(_systemService.TypeStockList(), "Id", "Name"),
                Categories = new SelectList(_systemService.CategoryStockList(0), "Id", "Name"),
                Units = new SelectList(_systemService.UnitStockList(0), "Id", "Name"),
                Positions = new SelectList(_systemService.PositionStockList(), "Id", "Name")
                //Labels = new SelectList(_systemService.LabelStockList(0), "Id", "Name")
            };

            return View(model);
        }
예제 #13
0
        public ActionResult Manage(int? id)
        {
            if (!id.HasValue)
            {
                id = 0;
            }

            var information = _systemService.GetStockInformation(id.Value, 0);
            var model = new StockViewModel
            {
                StockInformation = information,
                iType = information.TypeId,
                bCategoryID = information.CategoryId,
                vStockName = information.Stock_Name,
                vStockID = information.Stock_Code,
                Stores = new SelectList(_systemService.StoreList(), "Id", "Name"),
                Types = new SelectList(_systemService.TypeStockList(), "Id", "Name"),
                Categories = new SelectList(_systemService.CategoryStockList(0), "Id", "Name"),
                Units = new SelectList(_systemService.UnitStockList(0), "Id", "Name"),
                Positions = new SelectList(_systemService.PositionStockList(), "Id", "Name"),
                //Labels = new SelectList(_systemService.LabelStockList(0), "Id", "Name")
            };
            return View(model);
        }
예제 #14
0
 public ActionResult GetStockManagementQty(int page, int size, string stockCode, string stockName, string store, int type, int category, string fd, string td, string enable)
 {
     var totalRecord = _service.ListStockQuantityCount(page, size, stockCode, stockName, store, type, category, fd, td, enable);
     var totalTemp = Convert.ToDecimal(totalRecord) / Convert.ToDecimal(size);
     var totalPages = Convert.ToInt32(Math.Ceiling(totalTemp));
     var model = new StockViewModel
                     {
                         StockQuantityManagementResults = _service.ListStockQuantity(page, size, stockCode, stockName, store, type, category, fd, td, enable),
                         TotalRecords = Convert.ToInt32(totalRecord),
                         TotalPages = totalPages,
                         CurrentPage = page,
                         PageSize = size
                     };
     return PartialView("_LstQtyMngPartial", model);
 }
예제 #15
0
 public async Task <IActionResult> UpdateStock([FromBody] StockViewModel request)
 {
     return(Ok((await new StockService(_db).UpdateStock(request))));
 }
예제 #16
0
 public ActionResult SearchStock()
 {
     var model = new StockViewModel
     {
         Stores = new SelectList(this._systemService.StoreList(), "Id", "Name"),
         Types = new SelectList(this._systemService.TypeStockList(), "Id", "Name"),
         Categories = new SelectList(this._systemService.CategoryStockList(0), "Id", "Name"),
         Units = new SelectList(this._systemService.UnitStockList(0), "Id", "Name"),
         Positions = new SelectList(this._systemService.PositionStockList(), "Id", "Name"),
         Labels = new SelectList(this._systemService.LabelStockList(0), "Id", "Name"),
     };
     return PartialView("Partials/_FindStockPartial", model);
 }
예제 #17
0
        public ActionResult Budget()
        {
            ViewData["Title"]    = "Inventario";
            ViewData["Subtitle"] = "Detalle de existencias";
            ViewData["Label"]    = "Todos los productos";

            ICollection <StockViewModel> itemStock = new HashSet <StockViewModel>();

            foreach (var itemName in _context.Stocks.Select(r => r.Item.Name).Distinct())
            {
                StockViewModel svm = new StockViewModel()
                {
                    ItemName      = itemName,
                    TotalQuantity = _context.Stocks
                                    .Where(x =>
                                           x.Item.Name == itemName &&
                                           x.StockType == StockType.Ingreso)
                                    .Select(y =>
                                            y.Quantity)
                                    .Sum() -
                                    _context.Stocks
                                    .Where(x =>
                                           x.Item.Name == itemName &&

                                           x.StockType == StockType.Venta)
                                    .Select(y =>
                                            y.Quantity)
                                    .Sum() -
                                    _context.Stocks
                                    .Where(x =>
                                           x.Item.Name == itemName &&
                                           x.StockType == StockType.Mortalidad)
                                    .Select(y =>
                                            y.Quantity)
                                    .Sum(),
                    TotalWeight = _context.Stocks
                                  .Where(x =>
                                         x.Item.Name == itemName &&
                                         x.StockType == StockType.Ingreso)
                                  .Select(y =>
                                          y.Weight)
                                  .Sum() -
                                  _context.Stocks
                                  .Where(x =>
                                         x.Item.Name == itemName &&
                                         x.StockType == StockType.Venta)
                                  .Select(y =>
                                          y.Weight)
                                  .Sum() -
                                  _context.Stocks
                                  .Where(x =>
                                         x.Item.Name == itemName &&
                                         x.StockType == StockType.Mortalidad)
                                  .Select(y =>
                                          y.Weight)
                                  .Sum(),
                };
                //ICollection<DetailsViewModel> itemSizes = new HashSet<DetailsViewModel>();
                //foreach (var itemSizeName in _context.Stocks.Where(x => x.Item.Name == itemName).Select(y => y.ItemSize.Name).Distinct())
                //{
                //    DetailsViewModel dvm = new DetailsViewModel()
                //    {
                //        ItemSizeName= itemSizeName,
                //        TotalQuantity = _context.Stocks
                //            .Where(x =>
                //                x.Item.Name == itemName &&
                //                x.ItemSize.Name == itemSizeName &&
                //                x.StockType == StockType.Ingreso)
                //            .Select(y =>
                //                y.Quantity)
                //            .Sum() -
                //        _context.Stocks
                //            .Where(x =>
                //                x.Item.Name == itemName &&
                //                x.ItemSize.Name == itemSizeName &&
                //                x.StockType == StockType.Venta)
                //            .Select(y =>
                //                y.Quantity)
                //            .Sum() -
                //        _context.Stocks
                //            .Where(x =>
                //                x.Item.Name == itemName &&
                //                x.ItemSize.Name == itemSizeName &&
                //                x.StockType == StockType.Mortalidad)
                //            .Select(y =>
                //                y.Quantity)
                //            .Sum(),
                //     TotalWeight = _context.Stocks
                //            .Where(x =>
                //                x.Item.Name == itemName &&
                //                x.ItemSize.Name == itemSizeName &&
                //                x.StockType == StockType.Ingreso)
                //            .Select(y =>
                //                y.Weight)
                //            .Sum() -
                //    _context.Stocks
                //            .Where(x =>
                //                x.Item.Name == itemName &&
                //                x.ItemSize.Name == itemSizeName &&
                //                x.StockType == StockType.Venta)
                //            .Select(y =>
                //                y.Weight)
                //            .Sum() -
                //    _context.Stocks
                //            .Where(x =>
                //                x.Item.Name == itemName &&
                //                x.ItemSize.Name == itemSizeName &&
                //                x.StockType == StockType.Mortalidad)
                //            .Select(y =>
                //                y.Weight)
                //            .Sum()
                //    };
                //    svm.DetailsList.Add(dvm);
                //}
                itemStock.Add(svm);
            }
            return(View(itemStock));
        }
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='version'>
 /// </param>
 /// <param name='stockViewModel'>
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task AddNewStockAsync(this IStockBoardProject operations, string version, StockViewModel stockViewModel = default(StockViewModel), CancellationToken cancellationToken = default(CancellationToken))
 {
     (await operations.AddNewStockWithHttpMessagesAsync(version, stockViewModel, null, cancellationToken).ConfigureAwait(false)).Dispose();
 }
        public List <StockViewModel> sortValue(string sort)
        {
            Sprint_3_V1Context db = new Sprint_3_V1Context();

            List <StockViewModel> searchStockList = new List <StockViewModel>();

            if (sort != null)
            {
                if (sort == "Name Ascending")
                {
                    var mergedList = (from c in db.CropInfoes
                                      join x in db.Stocks
                                      on c.CropID equals x.CropID
                                      join y in db.StocksImages
                                      on x.StockID equals y.StockID
                                      orderby c.Name ascending
                                      select new
                    {
                        x.StockID,
                        c.CropID,
                        c.Name,
                        x.CurQuantity,
                        x.Expiery,
                        x.Price,
                        y.StockImage
                    }).ToList();

                    if (mergedList.Count() > 0)
                    {
                        foreach (var item in mergedList)
                        {
                            StockViewModel stk = new StockViewModel();
                            stk.StockID     = item.StockID;
                            stk.CropID      = item.CropID;
                            stk.CropName    = item.Name;
                            stk.CurQuantity = item.CurQuantity;
                            stk.Expiery     = item.Expiery;
                            stk.StockImage  = item.StockImage;
                            stk.Price       = item.Price;
                            searchStockList.Add(stk);
                        }
                    }
                }
                else if (sort == "Name Descending")
                {
                    var mergedList = (from c in db.CropInfoes
                                      join x in db.Stocks
                                      on c.CropID equals x.CropID
                                      join y in db.StocksImages
                                      on x.StockID equals y.StockID
                                      orderby c.Name descending
                                      select new
                    {
                        x.StockID,
                        c.CropID,
                        c.Name,
                        x.CurQuantity,
                        x.Expiery,
                        x.Price,
                        y.StockImage
                    }).ToList();

                    if (mergedList.Count() > 0)
                    {
                        foreach (var item in mergedList)
                        {
                            StockViewModel stk = new StockViewModel();
                            stk.StockID     = item.StockID;
                            stk.CropID      = item.CropID;
                            stk.CropName    = item.Name;
                            stk.CurQuantity = item.CurQuantity;
                            stk.Expiery     = item.Expiery;
                            stk.StockImage  = item.StockImage;
                            stk.Price       = item.Price;
                            searchStockList.Add(stk);
                        }
                    }
                }
                else if (sort == "Price Ascending")
                {
                    var mergedList = (from c in db.CropInfoes
                                      join x in db.Stocks
                                      on c.CropID equals x.CropID
                                      join y in db.StocksImages
                                      on x.StockID equals y.StockID
                                      orderby x.Price ascending
                                      select new
                    {
                        x.StockID,
                        c.CropID,
                        c.Name,
                        x.CurQuantity,
                        x.Expiery,
                        x.Price,
                        y.StockImage
                    }).ToList();

                    if (mergedList.Count() > 0)
                    {
                        foreach (var item in mergedList)
                        {
                            StockViewModel stk = new StockViewModel();
                            stk.StockID     = item.StockID;
                            stk.CropID      = item.CropID;
                            stk.CropName    = item.Name;
                            stk.CurQuantity = item.CurQuantity;
                            stk.Expiery     = item.Expiery;
                            stk.StockImage  = item.StockImage;
                            stk.Price       = item.Price;
                            searchStockList.Add(stk);
                        }
                    }
                }
                else if (sort == "Price Descending")
                {
                    var mergedList = (from c in db.CropInfoes
                                      join x in db.Stocks
                                      on c.CropID equals x.CropID
                                      join y in db.StocksImages
                                      on x.StockID equals y.StockID
                                      orderby x.Price descending
                                      select new
                    {
                        x.StockID,
                        c.CropID,
                        c.Name,
                        x.CurQuantity,
                        x.Expiery,
                        x.Price,
                        y.StockImage
                    }).ToList();

                    if (mergedList.Count() > 0)
                    {
                        foreach (var item in mergedList)
                        {
                            StockViewModel stk = new StockViewModel();
                            stk.StockID     = item.StockID;
                            stk.CropID      = item.CropID;
                            stk.CropName    = item.Name;
                            stk.CurQuantity = item.CurQuantity;
                            stk.Expiery     = item.Expiery;
                            stk.StockImage  = item.StockImage;
                            stk.Price       = item.Price;
                            searchStockList.Add(stk);
                        }
                    }
                }
            }
            return(searchStockList);
        }
예제 #20
0
 public MainWindow()
 {
     InitializeComponent();
     DataContext = new StockViewModel();
 }
예제 #21
0
        public IActionResult Index()
        {
            var model = new StockViewModel();

            return(View(model));
        }
예제 #22
0
        public IHttpActionResult Data(StockRequestModel request)
        {
            StockViewModel stockViewModel = service.Search(request);

            return(Ok(stockViewModel));
        }
예제 #23
0
 public void CanCreateViewModel()
 {
     var viewModel = new StockViewModel();
 }
예제 #24
0
        public ActionResult LoadStock(int page, int size, string stockCode, string stockName, string store, int type, int category, string enable)
        {
            var userName = System.Web.HttpContext.Current.User.Identity.Name;
            var totalRecord = _service.ListConditionCount(page, size, stockCode, stockName, store, type, category, enable);
            var totalTemp = Convert.ToDecimal(totalRecord) / Convert.ToDecimal(size);
            var totalPages = Convert.ToInt32(Math.Ceiling(totalTemp));
            var model = new StockViewModel
            {
                UserLogin = _systemService.GetUserAndRole(0, userName),
                StockVs = _service.ListCondition(page, size, stockCode, stockName, store, type, category, enable),
                StoreVs = _systemService.StoreList(),
                TotalRecords = Convert.ToInt32(totalRecord),
                TotalPages = totalPages,
                CurrentPage = page,
                PageSize = size
            };

            return PartialView("_StockPartial", model);
        }
예제 #25
0
 public void HasInputPrice()
 {
     var viewModel = new StockViewModel();
     var price     = viewModel.InputPrice;
 }
예제 #26
0
        public void QueryStock(StockQueryParm stockParam)
        {
            Goods_ClassModel goodsClass      = bllMaterialClasl.GetModelByClassName(stockParam.MaterialCate);
            string           materialClassID = stockParam.MaterialCate;

            if (materialClassID != "所有")
            {
                if (goodsClass != null)
                {
                    materialClassID = goodsClass.Goods_Class_ID;
                }
                else
                {
                    this.View.ShowMessage("信息提示", "物料类别错误!");
                }
            }
            ViewDataManager.STOCKQUERYDATAVIEWDATA.StockList.Clear();
            ViewDataManager.STOCKQUERYDATAVIEWDATA.StockDetailList.Clear();
            List <View_StockListModel> stockList = bllViewStockList.GetListByParams(stockParam.HouseName, stockParam.Rowth, stockParam.Colth, stockParam.Layer, materialClassID, stockParam.PalletCode);



            var sdf = stockList.Distinct(new ListCompare <View_StockListModel>((x, y)
                                                                               => x.Stock_Tray_Barcode == y.Stock_Tray_Barcode));
            List <View_StockListModel> distinctStockList = sdf.ToList();

            //foreach (View_StockListModel vsm in stockList)
            //{
            //    var existPallet = distinctStockList.Where(s => s.Stock_Tray_Barcode == vsm.Stock_Tray_Barcode);
            //    if (existPallet == null || existPallet.Count() == 0)
            //    {
            //        distinctStockList.Add(vsm);
            //    }
            //}

            foreach (View_StockListModel item in distinctStockList)
            {
                StockViewModel svm = new StockViewModel();
                svm.货位编码 = item.Cell_Chlid_ID;
                svm.托盘条码 = item.Stock_Tray_Barcode;
                svm.货位名称 = item.Cell_Name;
                if (item.Cell_Type != EnumCellType.货位.ToString())
                {
                    svm.库房名称 = "暂存工位";
                    svm.位置   = item.Cell_Name;
                }
                else
                {
                    svm.库房名称 = item.WareHouse_Name;
                    svm.位置   = item.Cell_Chlid_Position;
                }

                svm.库区 = item.Area_Name;

                if (item.Stock_List_Entry_Time != null)
                {
                    svm.入库时间 = item.Stock_List_Entry_Time.ToString();
                }


                ViewDataManager.STOCKQUERYDATAVIEWDATA.StockList.Add(svm);
            }
        }
예제 #27
0
 public void HasInputQuantity()
 {
     var viewModel = new StockViewModel();
     var quantity  = viewModel.InputQuantity;
 }
 void PortfolioManager_Loaded(object sender, RoutedEventArgs e)
 {
     this._vm = this.DataContext as StockViewModel;
 }
예제 #29
0
        public void IsInTheRedIsTrueForEquityWithTransactionCostOverTwoHundredThousand()
        {
            var sut = new StockViewModel(new Equity(10000.0m, 10000));

            Assert.IsTrue(sut.IsInTheRed);
        }
 public MainWindow()
 {
     InitializeComponent();
     StockViewModel   = new StockViewModel();
     this.DataContext = StockViewModel;
 }
예제 #31
0
        public void IsInTheRedIsFalseForARegularEquity()
        {
            var sut = new StockViewModel(new Equity(10.0m, 5));

            Assert.IsFalse(sut.IsInTheRed);
        }
예제 #32
0
        public async Task <IActionResult> CreateStock([FromBody] StockViewModel request)

        {
            return(Ok((await new StockService(_db).Create(request))));
            //we use FromBody because we are posting json
        }
예제 #33
0
        public StockViewModel Search(StockRequestModel request)
        {
            request.StartDate = request.StartDate.Date;
            request.EndDate   = request.EndDate.Date.AddDays(1).AddMinutes(-1);

            Bookmark bookmark = db.Bookmarks.OrderByDescending(x => x.Created).FirstOrDefault(x => x.Created < request.StartDate);

            if (bookmark == null)
            {
                return(null);
            }
            IQueryable <ProductBookmark> queryablePBookmarks = bookmark.ProductBookmarks.AsQueryable();

            ProductBookmarkRequestModel pbRequestModel = new ProductBookmarkRequestModel(request.Keyword, "Modified", "False");

            queryablePBookmarks = pbRequestModel.GetOrderedData(queryablePBookmarks);
            queryablePBookmarks = pbRequestModel.SkipAndTake(queryablePBookmarks);
            List <ProductBookmarkViewModel> productBookmarks = queryablePBookmarks.ToList().ConvertAll(x => new ProductBookmarkViewModel(x)).ToList();

            var bookmarkDate = bookmark.Created.Date;
            List <SaleDetailViewModel> saleDetails = db.SaleDetails.Include(x => x.Product).Where(x => x.Created >= bookmarkDate && x.Created <= request.EndDate).ToList().ConvertAll(x => new SaleDetailViewModel(x)).ToList();
            var purchaseDetails       = db.PurchaseDetails.Include(x => x.Product).Where(x => x.Created >= bookmarkDate && x.Created <= request.EndDate).ToList().ConvertAll(x => new PurchaseDetailViewModel(x));
            var stockDetailViewModels = new List <StockDetailViewModel>();

            foreach (var pb in productBookmarks)
            {
                var purchaseDqBefore = purchaseDetails.Where(x => x.Created < request.StartDate && x.ProductId == pb.ProductId).ToList();
                int purchasedBefore  = purchaseDqBefore.Any() ? purchaseDqBefore.Sum(x => x.Quantity) : 0;
                var purchaseDqAfter  = purchaseDetails.Where(x => x.Created >= request.StartDate && x.ProductId == pb.ProductId).ToList();
                int purchasedAfter   = purchaseDqAfter.Any() ? purchaseDqAfter.Sum(x => x.Quantity) : 0;
                var saleDqBefore     = saleDetails.Where(x => x.Created < request.StartDate && x.ProductId == pb.ProductId).ToList();
                int soldBefore       = saleDqBefore.Any() ? saleDqBefore.Sum(x => x.Quantity) : 0;
                var saleDqAfter      = saleDetails.Where(x => x.Created >= request.StartDate && x.ProductId == pb.ProductId).ToList();
                int soldAfter        = saleDqAfter.Any() ? saleDqAfter.Sum(x => x.Quantity) : 0;

                StockDetailViewModel sdetail = new StockDetailViewModel
                {
                    StartingOnHand         = pb.PhysicalOnHand + purchasedBefore - soldBefore,
                    StockIn                = purchasedAfter,
                    ProductName            = pb.ProductName,
                    StockOut               = soldAfter,
                    BookmarkStartingOnHand = pb.PhysicalOnHand
                };
                sdetail.EndOnHand = sdetail.StartingOnHand + sdetail.StockIn - sdetail.StockOut;
                sdetail.CostTotal = pb.CostPrice * sdetail.EndOnHand;
                stockDetailViewModels.Add(sdetail);
            }

            StockViewModel stockViewModel = new StockViewModel()
            {
                BookmarkDate          = bookmarkDate,
                StartDate             = request.StartDate,
                EndDate               = request.EndDate,
                CostTotal             = stockDetailViewModels.Sum(x => x.CostTotal),
                StockDetailViewModels = stockDetailViewModels
            };

            // get purchase detail by productid & date range
            // get sale detail by productid & date range
            // prepare view model & return
            return(stockViewModel);
        }
예제 #34
0
        public ActionResult SearchStockPeFilter(int page, int size, string stockCode, string stockName, string store, int type, int category, string enable,int supplier)
        {
            var totalRecord = _stockService.PeListConditionCount(page, size, stockCode, stockName, store, type, category, enable, supplier);
            var totalTemp = Convert.ToDecimal(totalRecord) / Convert.ToDecimal(size);
            var totalPages = Convert.ToInt32(Math.Ceiling(totalTemp));
            var model = new StockViewModel
            {
                StockVs = _stockService.PeListCondition(page, size, stockCode, stockName, store, type, category, enable, supplier),
                StoreVs = _systemService.StoreList(),
                TotalRecords = Convert.ToInt32(totalRecord),
                TotalPages = totalPages,
                CurrentPage = page,
                PageSize = size,
            };

            return PartialView("Partials/_SearchStockPEPartial", model);
        }
예제 #35
0
        public void AddNewStock(StockViewModel stockViewModel)
        {
            var addCommand = _mapper.Map <AddNewStockCommand>(stockViewModel);

            _bus.SendCommand(addCommand);
        }
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='version'>
 /// </param>
 /// <param name='stockViewModel'>
 /// </param>
 public static void AddNewStock(this IStockBoardProject operations, string version, StockViewModel stockViewModel = default(StockViewModel))
 {
     operations.AddNewStockAsync(version, stockViewModel).GetAwaiter().GetResult();
 }
예제 #37
0
        public void Update(StockViewModel stockViewModel)
        {
            var updateCommand = _mapper.Map <UpdateStockCommand>(stockViewModel);

            _bus.SendCommand(updateCommand);
        }
예제 #38
0
 public StockViewWindow()
 {
     InitializeComponent ();
     DataContext = new StockViewModel ();
 }
예제 #39
0
        public ActionResult Search(StockViewModel stockViewModel)
        {
            var salesDetailses = _salesManager.GetAll();

            var purchasesDetailses = _purchaseManager.GetAll();

            var sales = _salesManager.SGetAll();

            var purchases = _purchaseManager.PGetAll();

            var category = _categoryManager.GetAll();

            var product = _productManager.GetAll();

            //  StockViewModel stockViewModel = new StockViewModel();

            stockViewModel.CategorySelectListItems = _categoryManager.GetAll()
                                                     .Select(c => new SelectListItem()
            {
                Value = c.Id.ToString(),
                Text  = c.Name
            }).ToList();



            //productNcategoryList
            var productNcategoryList = from pr in product
                                       join ca in category on pr.CategoryId equals ca.Id
                                       select new { productId = pr.Id, pr.Code, pr.Name, category = ca.Name, categoryId = ca.Id, pr.ReorderLevel };
            //productNcategoryList.Dump();

            //purchaseList
            var purchaseList = from p in purchases
                               join pd in purchasesDetailses on p.Id equals pd.PurchasesId
                               select new { p.Date, pd.ExpireDate, pd.Quantity, pd.ProductId };
            //purchaseList.Dump();

            //salesList
            var salesList = from s in sales
                            join sd in salesDetailses on s.Id equals sd.SalesId
                            select new { s.Date, sd.Quantity, sd.ProductId };
            //salesList.Dump();

            //purchaseNsalesList
            var purchaseNsalesList = from p in purchaseList
                                     join s in salesList on p.ProductId equals s.ProductId
                                     select new { purchaseDate = p.Date, p.ExpireDate, purchaseQuantity = p.Quantity, purchaseProductId = p.ProductId, saleDate = s.Date, saleQuantity = s.Quantity, saleProductId = s.ProductId };
            //purchaseNsalesList.Dump();

            // //purchaseNsalesList N productNcategoryList
            var results = from ps in purchaseNsalesList
                          join pc in productNcategoryList on ps.purchaseProductId equals pc.productId
                          select new { pc.Code, pc.Name, pc.category, pc.ReorderLevel, ps.purchaseDate, ps.ExpireDate, pq = ps.purchaseQuantity, ps.purchaseProductId, ps.saleDate, sq = ps.saleQuantity, ps.saleProductId, avlQty = ps.purchaseQuantity - ps.saleQuantity };
            // results.Dump();



            var rsOB1 = from r in results.Where(c => c.purchaseProductId == stockViewModel.ProductId)
                        //.Where(c => c.saleProductId == stockViewModel.ProductId)
                        //.Where(c => c.purchaseDate < stockViewModel.StartDate)
                        //.Where(c => c.saleDate < stockViewModel.StartDate)
                        select new { r.Code, r.Name, r.category, r.ReorderLevel, r.purchaseDate, r.ExpireDate, r.pq, r.purchaseProductId, r.saleDate, r.sq, r.saleProductId };

            var rsOBP2 = from r in rsOB1.Where(c => c.purchaseDate < stockViewModel.StartDate)
                         //.Where(c => c.saleDate < stockViewModel.StartDate)
                         select new { r.Code, r.Name, r.category, r.ReorderLevel, r.purchaseDate, r.ExpireDate, r.pq, r.purchaseProductId, r.saleDate, r.sq, r.saleProductId };

            var rsOBS3 = from r in rsOBP2.Where(c => c.saleDate < stockViewModel.StartDate)
                         select new { r.Code, r.Name, r.category, r.ReorderLevel, r.purchaseDate, r.ExpireDate, r.pq, r.purchaseProductId, r.saleDate, r.sq, r.saleProductId };

            int TPQOB = 0;
            int TSQOB = 0;
            int OB    = 0;

            foreach (var r in rsOBS3)
            {
                //TPQOB = TPQOB + r.pq;
                TPQOB += r.pq;
            }
            foreach (var r in rsOBS3)
            {
                TSQOB += r.sq;
            }
            OB = TPQOB - TSQOB;

            var rsIn1 = from r in results.Where(c => c.purchaseProductId == stockViewModel.ProductId)
                        //.Where(c => stockViewModel.StartDate <= c.purchaseDate && c.purchaseDate <= stockViewModel.EndDate)
                        select new { r.Code, r.Name, r.category, r.ReorderLevel, r.purchaseDate, r.ExpireDate, r.pq, r.purchaseProductId, r.saleDate, r.sq, r.saleProductId };

            var rsIn2 = from r in rsIn1.Where(c => stockViewModel.StartDate <= c.purchaseDate)
                        select new { r.Code, r.Name, r.category, r.ReorderLevel, r.purchaseDate, r.ExpireDate, r.pq, r.purchaseProductId, r.saleDate, r.sq, r.saleProductId };

            var rsIn3 = from r in rsIn2.Where(c => c.purchaseDate <= stockViewModel.EndDate)
                        select new { r.Code, r.Name, r.category, r.ReorderLevel, r.purchaseDate, r.ExpireDate, r.pq, r.purchaseProductId, r.saleDate, r.sq, r.saleProductId };


            int In = 0;

            foreach (var r in rsIn3)
            {
                In += r.pq;
            }

            var rsOut1 = from r in results.Where(c => c.purchaseProductId == stockViewModel.ProductId)
                         // .Where(c => stockViewModel.StartDate <= c.saleDate && c.saleDate <= stockViewModel.EndDate)
                         select new { r.Code, r.Name, r.category, r.ReorderLevel, r.purchaseDate, r.ExpireDate, r.pq, r.purchaseProductId, r.saleDate, r.sq, r.saleProductId };

            var rsOut2 = from r in rsOut1.Where(c => stockViewModel.StartDate <= c.saleDate && c.saleDate <= stockViewModel.EndDate)
                         select new { r.Code, r.Name, r.category, r.ReorderLevel, r.purchaseDate, r.ExpireDate, r.pq, r.purchaseProductId, r.saleDate, r.sq, r.saleProductId };

            int Out = 0;

            foreach (var r in rsOut2)
            {
                Out += r.sq;
            }

            int CB = OB + In - Out;



            foreach (var r in rsOut2)
            {
                stockViewModel.Code           = r.Code;
                stockViewModel.Name           = r.Name;
                stockViewModel.Category       = r.category;
                stockViewModel.ReorderLevel   = r.ReorderLevel;
                stockViewModel.OpeningBalance = OB;
                stockViewModel.In             = In;
                stockViewModel.Out            = Out;
                stockViewModel.ClosingBalance = CB;
            }

            stockViewModel.StockView.Add(stockViewModel);


            ViewBag.Category = stockViewModel.CategorySelectListItems;
            return(View(stockViewModel));
        }
예제 #40
0
 public ActionResult Search(StockViewModel stockViewModel)
 {
     return(View());
 }
 public MainPage()
 {
     InitializeComponent();
     BindingContext = new StockViewModel();
 }
예제 #42
0
        /// <summary>
        /// Create, update and delete Stock Posting for one record.
        /// </summary>
        /// <param name="StockViewModel_New"></param>
        /// <param name="StockViewModel_Old"></param>
        /// <returns></returns>
        public string StockPost(StockViewModel StockViewModel_New, StockViewModel StockViewModel_Old)
        {
            string      ErrorText = "";
            StockHeader StockHeader;


            if (StockViewModel_New != null)
            {
                StockHeader = _stockHeaderService.FindByDocHeader(StockViewModel_New.DocHeaderId, StockViewModel_New.StockHeaderId, StockViewModel_New.DocTypeId, StockViewModel_New.SiteId, StockViewModel_New.DivisionId);

                if (StockViewModel_New.StockHeaderExist == 0 || StockViewModel_New.StockHeaderExist == null)
                {
                    if (StockHeader == null)
                    {
                        StockHeader H = new StockHeader();

                        H.DocHeaderId  = StockViewModel_New.DocHeaderId;
                        H.DocTypeId    = StockViewModel_New.DocTypeId;
                        H.DocDate      = StockViewModel_New.StockHeaderDocDate;
                        H.DocNo        = StockViewModel_New.DocNo;
                        H.DivisionId   = StockViewModel_New.DivisionId;
                        H.SiteId       = StockViewModel_New.SiteId;
                        H.CurrencyId   = StockViewModel_New.CurrencyId;
                        H.PersonId     = StockViewModel_New.PersonId;
                        H.ProcessId    = StockViewModel_New.HeaderProcessId;
                        H.FromGodownId = StockViewModel_New.HeaderFromGodownId;
                        H.GodownId     = StockViewModel_New.HeaderGodownId;
                        H.Remark       = StockViewModel_New.Remark;
                        H.Status       = StockViewModel_New.Status;
                        H.CreatedBy    = StockViewModel_New.CreatedBy;
                        H.CreatedDate  = StockViewModel_New.CreatedDate;
                        H.ModifiedBy   = StockViewModel_New.ModifiedBy;
                        H.ModifiedDate = StockViewModel_New.ModifiedDate;

                        _stockHeaderService.Create(H);

                        StockHeader = H;
                    }
                    else
                    {
                        StockHeader.DocHeaderId  = StockViewModel_New.DocHeaderId;
                        StockHeader.DocTypeId    = StockViewModel_New.DocTypeId;
                        StockHeader.DocDate      = StockViewModel_New.StockHeaderDocDate;
                        StockHeader.DocNo        = StockViewModel_New.DocNo;
                        StockHeader.DivisionId   = StockViewModel_New.DivisionId;
                        StockHeader.SiteId       = StockViewModel_New.SiteId;
                        StockHeader.CurrencyId   = StockViewModel_New.CurrencyId;
                        StockHeader.PersonId     = StockViewModel_New.PersonId;
                        StockHeader.ProcessId    = StockViewModel_New.HeaderProcessId;
                        StockHeader.FromGodownId = StockViewModel_New.HeaderFromGodownId;
                        StockHeader.GodownId     = StockViewModel_New.HeaderGodownId;
                        StockHeader.Remark       = StockViewModel_New.Remark;
                        StockHeader.Status       = StockViewModel_New.Status;
                        StockHeader.CreatedBy    = StockViewModel_New.CreatedBy;
                        StockHeader.CreatedDate  = StockViewModel_New.CreatedDate;
                        StockHeader.ModifiedBy   = StockViewModel_New.ModifiedBy;
                        StockHeader.ModifiedDate = StockViewModel_New.ModifiedDate;

                        _stockHeaderService.Update(StockHeader);
                    }
                }
            }
            else
            {
                StockHeader = _stockHeaderService.FindByDocHeader(StockViewModel_Old.DocHeaderId, StockViewModel_Old.StockHeaderId, StockViewModel_Old.DocTypeId, StockViewModel_Old.SiteId, StockViewModel_Old.DivisionId);
            }


            if (StockViewModel_Old != null)
            {
                Stock Stock_Old = Find(StockViewModel_Old.StockHeaderId, StockViewModel_Old.ProductId, StockViewModel_Old.StockDocDate, StockViewModel_Old.Dimension1Id, StockViewModel_Old.Dimension2Id, StockViewModel_Old.ProcessId, StockViewModel_Old.LotNo, StockViewModel_Old.GodownId, StockViewModel_Old.CostCenterId);

                if (Stock_Old != null)
                {
                    Stock_Old.Qty_Iss       = Stock_Old.Qty_Iss - StockViewModel_Old.Qty_Iss;
                    Stock_Old.Qty_Rec       = Stock_Old.Qty_Rec - StockViewModel_Old.Qty_Rec;
                    Stock_Old.Rate          = StockViewModel_Old.Rate;
                    Stock_Old.ExpiryDate    = StockViewModel_Old.ExpiryDate;
                    Stock_Old.Specification = StockViewModel_Old.Specification;

                    Update(Stock_Old);

                    //if (Stock_Old.Qty_Iss == 0 && Stock_Old.Qty_Rec == 0) { Delete(Stock_Old); }
                    //else { Update(Stock_Old); }

                    StockBalance StockBalance_Old = FindStockBalance(StockViewModel_Old.ProductId, StockViewModel_Old.Dimension1Id, StockViewModel_Old.Dimension2Id, StockViewModel_Old.ProcessId, StockViewModel_Old.LotNo, StockViewModel_Old.GodownId, StockViewModel_Old.CostCenterId);

                    if (StockBalance_Old != null)
                    {
                        StockBalance_Old.Qty = StockBalance_Old.Qty - StockViewModel_Old.Qty_Rec;
                        StockBalance_Old.Qty = StockBalance_Old.Qty + StockViewModel_Old.Qty_Iss;

                        if (StockBalance_Old.Qty == 0)
                        {
                            _stockBalanceService.Delete(StockBalance_Old);
                        }
                        else
                        {
                            _stockBalanceService.Update(StockBalance_Old);
                        }
                    }
                }
            }

            if (StockViewModel_New != null)
            {
                Stock Stock_New;

                if (StockHeader != null)
                {
                    Stock_New = Find(StockHeader.StockHeaderId, StockViewModel_New.ProductId, StockViewModel_New.StockDocDate, StockViewModel_New.Dimension1Id, StockViewModel_New.Dimension2Id, StockViewModel_New.ProcessId, StockViewModel_New.LotNo, StockViewModel_New.GodownId, StockViewModel_New.CostCenterId);
                }
                else
                {
                    Stock_New = null;
                }

                if (Stock_New == null)
                {
                    Stock L = new Stock();

                    L.DocDate       = StockViewModel_New.StockDocDate;
                    L.ProductId     = StockViewModel_New.ProductId;
                    L.ProcessId     = StockViewModel_New.ProcessId;
                    L.GodownId      = StockViewModel_New.GodownId;
                    L.LotNo         = StockViewModel_New.LotNo;
                    L.CostCenterId  = StockViewModel_New.CostCenterId;
                    L.Qty_Iss       = StockViewModel_New.Qty_Iss;
                    L.Qty_Rec       = StockViewModel_New.Qty_Rec;
                    L.Rate          = StockViewModel_New.Rate;
                    L.ExpiryDate    = StockViewModel_New.ExpiryDate;
                    L.Specification = StockViewModel_New.Specification;
                    L.Dimension1Id  = StockViewModel_New.Dimension1Id;
                    L.Dimension2Id  = StockViewModel_New.Dimension2Id;
                    L.CreatedBy     = StockViewModel_New.CreatedBy;
                    L.CreatedDate   = StockViewModel_New.CreatedDate;
                    L.ModifiedBy    = StockViewModel_New.ModifiedBy;
                    L.ModifiedDate  = StockViewModel_New.ModifiedDate;


                    if (StockHeader != null)
                    {
                        L.StockHeaderId = StockHeader.StockHeaderId;
                    }

                    Create(L);
                }
                else
                {
                    Stock_New.Qty_Iss       = Stock_New.Qty_Iss + StockViewModel_New.Qty_Iss;
                    Stock_New.Qty_Rec       = Stock_New.Qty_Rec + StockViewModel_New.Qty_Rec;
                    Stock_New.Rate          = StockViewModel_New.Rate;
                    Stock_New.ExpiryDate    = StockViewModel_New.ExpiryDate;
                    Stock_New.Specification = StockViewModel_New.Specification;
                    Stock_New.ModifiedBy    = StockViewModel_New.ModifiedBy;
                    Stock_New.ModifiedDate  = StockViewModel_New.ModifiedDate;

                    Update(Stock_New);
                }

                StockBalance StockBalance_New = FindStockBalance(StockViewModel_New.ProductId, StockViewModel_New.Dimension1Id, StockViewModel_New.Dimension2Id, StockViewModel_New.ProcessId, StockViewModel_New.LotNo, StockViewModel_New.GodownId, StockViewModel_New.CostCenterId);

                if (StockBalance_New == null)
                {
                    StockBalance Sb = new StockBalance();

                    Sb.ProductId    = StockViewModel_New.ProductId;
                    Sb.Dimension1Id = StockViewModel_New.Dimension1Id;
                    Sb.Dimension2Id = StockViewModel_New.Dimension2Id;
                    Sb.ProcessId    = StockViewModel_New.ProcessId;
                    Sb.GodownId     = StockViewModel_New.GodownId;
                    Sb.CostCenterId = StockViewModel_New.CostCenterId;
                    Sb.LotNo        = StockViewModel_New.LotNo;
                    if (StockViewModel_New.Qty_Iss != 0)
                    {
                        Sb.Qty = StockViewModel_New.Qty_Iss;
                    }
                    if (StockViewModel_New.Qty_Rec != 0)
                    {
                        Sb.Qty = StockViewModel_New.Qty_Rec;
                    }

                    _stockBalanceService.Create(Sb);
                }
                else
                {
                    StockBalance_New.Qty = StockBalance_New.Qty + StockViewModel_New.Qty_Rec;
                    StockBalance_New.Qty = StockBalance_New.Qty - StockViewModel_New.Qty_Iss;

                    _stockBalanceService.Update(StockBalance_New);
                }
            }

            return(ErrorText);
        }
예제 #43
0
 public MainPage()
 {
     this.InitializeComponent();
     viewModel             = new StockViewModel();
     ButtonGetQuote.Click += ButtonGetQuote_Click;
 }