private void SellProduct() { Transaction transaction = new Transaction { ProductID = _selectedProductIDs.FirstOrDefault(), Date = DateTime.Now, TypeID = (int) TranType.Sold, OperatorID = OperatorManager.Instance.CurrentUserID, Price = Price }; try { _mainViewModel.Context.Transactions.Add(transaction); _mainViewModel.Context.SaveChanges(); } catch (Exception exception) { MessageBox.Show(("Не удалось продать товар."), "Error", MessageBoxButton.OK, MessageBoxImage.Error); Logging.WriteToLog("Failed to sell OnStock product. " + exception.Message); } _mainViewModel.CashInHand += Price; var productToSell = _productsViewModel.Products.FirstOrDefault( x => x.IDs.FirstOrDefault() == _selectedProductIDs.FirstOrDefault()); if (productToSell != null) _mainViewModel.ProductsValue -= productToSell.MoneySpentForProduct; _productsViewModel.Update(); _mainViewModel.SoldProductsViewModel.Update(); _productsViewModel.SellProductDialogViewModel = null; }
public CashTransactionViewModel(Transaction transaction) { ID = transaction.ID; Date = transaction.Date; CashTranType = (TranType) transaction.TypeID; Salesman = new SalesmanViewModel(transaction.Operator.Salesman); if (transaction.Contragent != null) Contragent = new ContragentViewModel(transaction.Contragent); if (transaction.Price != null) Price = transaction.Price.Value; Notes = transaction.Notes; }
private void RepairedProduct() { if (_repairedProduct == null) { MessageBox.Show(("Не удалось вернуть товар с ремонта. Товар не был выбран."), "Error", MessageBoxButton.OK, MessageBoxImage.Error); Logging.WriteToLog("Failed to take ToRepair product from repairer. Product was not selected."); _mainViewModel.ToRepairProductsViewModel.RepairedDialogViewModel = null; } int? lastRepairerID = null; try { lastRepairerID = _mainViewModel.Context.Transactions.OrderBy(x => x.Date).ToList().LastOrDefault(x => x.ProductID == _repairedProduct.IDs.FirstOrDefault() && x.TypeID == (int) TranType.OnRepair).ContragentID; } catch (Exception e) { Logging.WriteToLog("Failed take lastRepairerID"); } Transaction transaction = new Transaction { ProductID = _repairedProduct.IDs.FirstOrDefault(), Date = DateTime.Now, TypeID = (int)TranType.Repaired, ContragentID = lastRepairerID, OperatorID = OperatorManager.Instance.CurrentUserID, Price = Price }; try { _mainViewModel.Context.Transactions.Add(transaction); _mainViewModel.Context.SaveChanges(); } catch (Exception exception) { MessageBox.Show(("Не удалось вернуть товар с ремонта."), "Error", MessageBoxButton.OK, MessageBoxImage.Error); Logging.WriteToLog("Failed add to DB take ToRepair product from repairer" + exception.Message); } _mainViewModel.ToRepairProductsViewModel.Update(); _mainViewModel.CashInHand -= Price; _mainViewModel.ProductsValue += Price; _mainViewModel.ToRepairProductsViewModel.RepairedDialogViewModel = null; }
public TransactionViewModel(Transaction transaction) { ID = transaction.ID; Type = (TranType)transaction.TypeID; Price = transaction.Price; Date = transaction.Date; var product = transaction.Product; if (product != null) { ProductID = product.ID; ModelName = product.Model.Name; CategoryName = product.Model.Category.Name; SerialNumber = product.SerialNumber; } if (transaction.Operator != null) Salesman = new SalesmanViewModel(transaction.Operator.Salesman); if (transaction.Contragent != null) ContragentLastName = new ContragentViewModel(transaction.Contragent); }
private void AddProduct() { Product product = new Product { ModelID = _selectedProduct.ModelID, SerialNumber = _selectedProduct.SerialNumber, Notes = _selectedProduct.Notes, SellingPrice = _selectedProduct.SellingPrice, DateSellTo = _selectedProduct.DateSellTo }; _mainViewModel.Context.Products.Add(product); Transaction transaction = new Transaction { Product = product, Date = DateTime.Now, TypeID = (int)TranType.Bought, OperatorID = OperatorManager.Instance.CurrentUserID, Price = _selectedProduct.Price }; _mainViewModel.Context.Transactions.Add(transaction); }
/// <summary> /// Add new transaction with Selected product and TransactionType "ToBought" /// </summary> public void SendToOnStockProduct() { MessageBoxResult answer = MessageBox.Show("Перенести выбранный товар на приход?", "Question", MessageBoxButton.YesNo); if (answer != MessageBoxResult.Yes) return; var transaction = new Transaction {ProductID = SelectedProduct.IDs.FirstOrDefault(), Date = DateTime.Now, TypeID = (int) TranType.Bought, OperatorID = OperatorManager.Instance.CurrentUserID, Price = 0}; try { _mainViewModel.Context.Transactions.Add(transaction); _mainViewModel.Context.SaveChanges(); MessageBox.Show("Товар поставлен на приход"); } catch (Exception e) { MessageBox.Show(("Не удалось поставить товар на приход"), "Error", MessageBoxButton.OK, MessageBoxImage.Error); Logging.WriteToLog("Failed ToPawn -> Bought. " + e.Message); } Update(); _mainViewModel.OnStockProductsViewModel.Update(); }
private void AddProduct() { ModelName = Trim(ModelName); FirstName = Trim(FirstName); LastName = Trim(LastName); SerialNumber = Trim(SerialNumber); Notes = Trim(Notes); Product product = new Product {SerialNumber = SerialNumber, SellingPrice = SellingPrice, Notes = Notes}; if (Models.Contains(ModelName)) product.Model = GetModelIDByName(ModelName); if (!Models.Contains(ModelName) || product.Model == null) { Model model = new Model {Name = ModelName, CategoryID = SelectedCategory.ID}; _mainViewModel.Context.Models.Add(model); product.Model = model; } _mainViewModel.Context.Products.Add(product); var client = _mainViewModel.Context.Clients.FirstOrDefault( x => x.Contragent.FirstName == FirstName && x.Contragent.LastName == LastName); if (client == null) { var contragent = new Contragent { LastName = LastName, FirstName = FirstName }; client = new Client { Contragent = contragent }; _mainViewModel.Context.Clients.Add(client); } Transaction transaction = new Transaction { Product = product, Date = DateTime.Now, TypeID = (int) TranType.ToRepair, OperatorID = OperatorManager.Instance.CurrentUserID, Contragent = client.Contragent, Price = 0 }; _mainViewModel.Context.Transactions.Add(transaction); try { _mainViewModel.Context.SaveChanges(); } catch (Exception e) { MessageBox.Show(("Не удалось добавить новый товар"), "Error", MessageBoxButton.OK, MessageBoxImage.Error); Logging.WriteToLog("Failed add new bought transaction. " + e.Message); } _mainViewModel.ToRepairProductsViewModel.Update(); _mainViewModel.ToRepairProductsViewModel.AddDialogViewModel = null; }
private void WriteOffProduct() { if (SelectedProduct == null) return; MessageBoxResult answer = MessageBox.Show("Списать выбранный товар?", "Question", MessageBoxButton.YesNo); if (answer != MessageBoxResult.Yes) return; foreach (var id in SelectedProduct.IDs) { Transaction transaction = new Transaction { ProductID = id, Date = DateTime.Now, TypeID = (int) TranType.Sold, OperatorID = OperatorManager.Instance.CurrentUserID, Price = 0 }; _mainViewModel.Context.Transactions.Add(transaction); } try { var productToWriteOff = Products.FirstOrDefault(x => x.IDs.Contains(SelectedProduct.IDs.FirstOrDefault())); if (productToWriteOff != null) _mainViewModel.ProductsValue -= productToWriteOff.MoneySpentForProduct*SelectedProduct.IDs.Count; _mainViewModel.Context.SaveChanges(); } catch (Exception e) { MessageBox.Show(("Не удалось списать товар"), "Error", MessageBoxButton.OK, MessageBoxImage.Error); Logging.WriteToLog("Failed write off product. " + e.InnerException.Message); } Update(); _mainViewModel.SoldProductsViewModel.Update(); }
private void AddCash() { int typeID = (int) TranType.Zero; switch (SelectedType) { case "Взять деньги": typeID = (int) TranType.CashOut; _mainViewModel.CashInHand -= Amount; break; case "Положить деньги": typeID = (int) TranType.CashIn; _mainViewModel.CashInHand += Amount; break; case "Кофе/чай": typeID = (int) TranType.Coffee; _mainViewModel.CashInHand += Amount; break; } var transaction = new Transaction {Date = DateTime.Now, Price = Amount, TypeID = typeID, OperatorID = OperatorManager.Instance.CurrentUserID, Notes = Notes}; _mainViewModel.Context.Transactions.Add(transaction); try { _mainViewModel.Context.SaveChanges(); } catch (Exception e) { MessageBox.Show(("Не удалось провести проводку"), "Error", MessageBoxButton.OK, MessageBoxImage.Error); Logging.WriteToLog("Failed add new cash transaction. " + e.Message); } _mainViewModel.CashTransactionsViewModel.Update(); _mainViewModel.CashTransactionsViewModel.AddCashViewModel = null; }
public SoldTransactionViewModel(Transaction transaction) : base(transaction) { if (Type == TranType.Sold && transaction.Product != null) SoldProduct = new SoldProductViewModel(transaction.Product); }
private void Add() { if (SelectedOperator == null) _mainViewModel.MobileTransactionsViewModel.AddDialogViewModel = null; Transaction transaction = new Transaction { Date = DateTime.Now, TypeID = (int) TranType.TopUp, OperatorID = OperatorManager.Instance.CurrentUserID, Price = Price }; LastName = Trim(LastName); FirstName = Trim(FirstName); if (!string.IsNullOrEmpty(LastName) && !string.IsNullOrEmpty(FirstName)) { var client =_mainViewModel.Context.Clients.FirstOrDefault( x => x.Contragent.FirstName == FirstName && x.Contragent.LastName == LastName); if (client == null) { var contragent = new Contragent { LastName = LastName, FirstName = FirstName }; client = new Client { Contragent = contragent }; _mainViewModel.Context.Clients.Add(client); } transaction.Contragent = client.Contragent; } MobileTransaction mobileTransaction = new MobileTransaction { Transaction = transaction, CreditSum = CreditSum, MobileOperatorID = SelectedOperator.ID }; _mainViewModel.Context.MobileTransactions.Add(mobileTransaction); try { _mainViewModel.Context.SaveChanges(); } catch (Exception e) { MessageBox.Show(("Не удалось провести пополнение"), "Error", MessageBoxButton.OK, MessageBoxImage.Error); Logging.WriteToLog("Failed add new mobile transaction. " + e.Message); } _mainViewModel.MobileTransactionsViewModel.Update(); _mainViewModel.CashInHand += Price; _mainViewModel.MobileTransactionsViewModel.AddDialogViewModel = null; }
private void PaySalary() { if (SelectedEmployee == null) _mainViewModel.CashTransactionsViewModel.PaySalaryViewModel = null; var transaction = new Transaction {Date = DateTime.Now, Price = Amount, TypeID = (int) TranType.Salary, ContragentID = SelectedEmployee.ID, OperatorID = OperatorManager.Instance.CurrentUserID, Notes = Notes}; _mainViewModel.Context.Transactions.Add(transaction); try { _mainViewModel.Context.SaveChanges(); } catch (Exception e) { MessageBox.Show(("Не удалось провести проводку"), "Error", MessageBoxButton.OK, MessageBoxImage.Error); Logging.WriteToLog("Failed add new salary transaction. " + e.Message); } _mainViewModel.CashTransactionsViewModel.Update(); _mainViewModel.CashInHand -= Amount; _mainViewModel.CashTransactionsViewModel.PaySalaryViewModel = null; }
private void RepairProduct() { if (_productToRepair == null) { MessageBox.Show(("Не удалось отправить товар на ремонт. Товар не был выбран."), "Error", MessageBoxButton.OK, MessageBoxImage.Error); Logging.WriteToLog("Failed to send OnStock product to repair. Product was not selected."); _mainViewModel.ToRepairProductsViewModel.RepairDialogViewModel = null; } Transaction transaction = new Transaction {ProductID = _productToRepair.IDs.FirstOrDefault(), Date = DateTime.Now, TypeID = (int) TranType.OnRepair, ContragentID = SelectedRepairer.ID, OperatorID = OperatorManager.Instance.CurrentUserID, Price = 0}; try { _mainViewModel.Context.Transactions.Add(transaction); _mainViewModel.Context.SaveChanges(); } catch (Exception exception) { MessageBox.Show(("Не удалось отправить товар на ремонт."), "Error", MessageBoxButton.OK, MessageBoxImage.Error); Logging.WriteToLog("Failed to add to DB send ToRepair product to repair" + exception.Message); } _mainViewModel.ToRepairProductsViewModel.Update(); _mainViewModel.ToRepairProductsViewModel.RepairDialogViewModel = null; }