public SupplyUpdateViewModel()
        {
            _safeServ           = new SafeServices();
            _supplyServ         = new SupplyServices();
            _categoryServ       = new CategoryServices();
            _clientAccountServ  = new ClientAccountServices();
            _supplyCategoryServ = new SupplyCategoryServices();
            _categoriesDialog   = new CategoriesShowDialog();

            _currentWindow    = Application.Current.Windows.OfType <MetroWindow>().LastOrDefault();
            _supplyCategories = new ObservableCollection <SupplyCategoryVM>(_supplyCategoryServ.GetSupplyCategoriesVM(ID));
            _selectedSupply   = _supplyServ.GetSupply(ID);
        }
Пример #2
0
 public SupplyUpdateViewModel()
 {
     _currentWindow        = Application.Current.Windows.OfType <MetroWindow>().LastOrDefault();
     _categoriesDialog     = new CategoriesShowDialog();
     _categoryDialog       = new SupplyCategoryInfromationDialog();
     _supplyCategories     = new ObservableCollection <SupplyCategoryVM>(_supplyCategoryServ.GetSupplyCategoriesVM(ID));
     _selectedSupply       = _supplyServ.GetSupply(ID);
     _selectedSupplyFuture = _supplyFutureServ.GetSupplyFuture(ID);
     if (SelectedSupplyFuture == null)
     {
         SelectedSupplyFuture      = new SupplyFuture();
         SelectedSupplyFuture.Date = DateTime.Now;
     }
     PlacesSuggestions = _supplyFutureServ.GetPlacesSuggetions();
 }
        public SupplyShowViewModel()
        {
            _supplyServ         = new SupplyServices();
            _categoryServ       = new CategoryServices();
            _supplyRecallServ   = new SupplyRecallServices();
            _clientAccountServ  = new ClientAccountServices();
            _supplyCategoryServ = new SupplyCategoryServices();
            _supplyRecallDialog = new SupplyRecallDialog();

            _state            = "Normal";
            _isFocused        = true;
            _currentWindow    = Application.Current.Windows.OfType <MetroWindow>().LastOrDefault();
            _selectedSupply   = _supplyServ.GetSupply(ID);
            _supplyCategories = new ObservableCollection <SupplyCategoryVM>(_supplyCategoryServ.GetSupplyCategoriesVM(ID));
            _categories       = new ObservableCollection <SupplyRecallVM>(_supplyRecallServ.GetSupplyCategoriesVM(ID));
            RecallsQty        = _supplyRecallServ.GetSupplyRecallsSum(ID);
        }
        private async void ExecuteAddPremiumAsync()
        {
            if (NewPremium.Amount == null || SelectedStatement == null)
            {
                return;
            }
            if (_newPremium.Amount > _selectedSupply.SupplyFuture.Change)
            {
                return;
            }
            DateTime _dt = DateTime.Now;

            _newPremium.RegistrationDate = _dt;
            _newPremium.SupplyID         = _selectedSupply.ID;
            _newPremium.Statement        = _selectedstatement.Statement;
            _supplyPremiumServ.AddPremium(_newPremium);

            if (_selectedstatement.Statement == "دفع")
            {
                ClientAccount _account = new ClientAccount
                {
                    ClientID         = _selectedSupply.ClientID,
                    Date             = _newPremium.Date,
                    RegistrationDate = _dt,
                    Statement        = "دفع قسط فاتورة المشتريات رقم  " + _selectedSupply.ID,
                    Credit           = 0,
                    Debit            = _newPremium.Amount
                };
                _clientAccountServ.AddAccount(_account);
                Safe _safe = new Safe
                {
                    Date             = _newPremium.Date,
                    RegistrationDate = _dt,
                    Statement        = "دفع قسط فاتورة المشتريات رقم  " + _selectedSupply.ID + " للعميل: " + _selectedSupply.Client.Name,
                    Amount           = -_newPremium.Amount,
                    Source           = 9
                };
                _safeServ.AddSafe(_safe);
            }
            else
            {
                ClientAccount _account = new ClientAccount
                {
                    ClientID         = _selectedSupply.ClientID,
                    Date             = _newPremium.Date,
                    RegistrationDate = _dt,
                    Statement        = "تسوية قسط فاتورة المشتريات رقم  " + _selectedSupply.ID,
                    Credit           = 0,
                    Debit            = _newPremium.Amount
                };
                _clientAccountServ.AddAccount(_account);
            }
            var supplyFuture = _supplyFutureServ.GetSupplyFuture(_selectedSupply.ID);

            supplyFuture.Change -= _newPremium.Amount;
            _supplyFutureServ.UpdateSupplyFuture(supplyFuture);
            SelectedSupply = _supplyServ.GetSupply(_selectedSupply.ID);
            _placesSuggestions.Add(_newPremium.Place);
            NewPremium        = new SupplyPremium();
            NewPremium.Date   = DateTime.Now;
            SelectedStatement = null;
            SupplyPremiums    = new ObservableCollection <SupplyPremium>(_supplyPremiumServ.GetPremiums(_selectedSupply.ID));
            if (SelectedSupply.SupplyFuture.Change == 0)
            {
                Visibility = "Collapsed";
            }
            else
            {
                Visibility = "Visible";
            }
            await _currentWindow.ShowMessageAsync("نجاح الإضافة", "تم الإضافة بنجاح", MessageDialogStyle.Affirmative, new MetroDialogSettings()
            {
                AffirmativeButtonText = "موافق",
                DialogMessageFontSize = 25,
                DialogTitleFontSize   = 30
            });
        }