示例#1
0
        private async void ExecuteSaveAsync()
        {
            if (NewSpending.Statement == null || NewSpending.Amount == null)
            {
                return;
            }
            DateTime dt = DateTime.Now;

            _newSpending.RegistrationDate = dt;
            _newSpending = _spendingServ.AddSpending(_newSpending);
            spendings.Add(_spendingServ.GetLastSpending());
            Safe _safe = new Safe
            {
                Amount           = -_newSpending.Amount,
                CanDelete        = false,
                Date             = _newSpending.Date,
                Statement        = _newSpending.Statement,
                RegistrationDate = dt,
                Source           = 2
            };

            _safeServ.AddSafe(_safe);
            _statementSuggestions.Add(_newSpending.Statement);
            NewSpending      = new Spending();
            NewSpending.Date = DateTime.Now;
            await _currentWindow.ShowMessageAsync("نجاح الإضافة", "تم الإضافة بنجاح", MessageDialogStyle.Affirmative, new MetroDialogSettings()
            {
                AffirmativeButtonText = "موافق",
                DialogMessageFontSize = 25,
                DialogTitleFontSize   = 30
            });
        }
 private async void ExecuteSaveAsync()
 {
     if (NewSafe.Statement == null || NewSafe.Amount == null)
     {
         return;
     }
     _newSafe.RegistrationDate = DateTime.Now;
     _newSafe.CanDelete        = true;
     _newSafe.Source           = 1;
     _safeServ.AddSafe(_newSafe);
     _statementSuggestions.Add(_newSafe.Statement);
     NewSafe      = new Safe();
     NewSafe.Date = DateTime.Now;
     await _currentWindow.ShowMessageAsync("نجاح الإضافة", "تم الإضافة بنجاح", MessageDialogStyle.Affirmative, new MetroDialogSettings()
     {
         AffirmativeButtonText = "موافق",
         DialogMessageFontSize = 25,
         DialogTitleFontSize   = 30
     });
 }
        private void ExecuteSave()
        {
            try
            {
                _supplyServ.UpdateSupply(_selectedSupply);
                _safeServ.DeleteSafe(_selectedSupply.RegistrationDate);
                _clientAccountServ.DeleteAccount(_selectedSupply.RegistrationDate);
                var supplyCategories = _supplyCategoryServ.GetSupplyCategories(_selectedSupply.ID);
                foreach (var item in supplyCategories)
                {
                    Category cat = _categoryServ.GetCategory(item.CategoryID);
                    if (cat.Qty - item.Qty != 0)
                    {
                        cat.Cost = ((cat.Cost * cat.Qty) - item.CostTotal) / (cat.Qty - item.Qty);
                    }
                    if (cat.Cost < 0)
                    {
                        cat.Cost = 0;
                    }
                    cat.Qty = cat.Qty - item.Qty;
                    _categoryServ.UpdateCategory(cat);
                }
                _supplyCategoryServ.DeleteSupplyCategories(ID);

                foreach (var item in _supplyCategories)
                {
                    SupplyCategory _supplyCategory = new SupplyCategory
                    {
                        CategoryID = item.CategoryID,
                        Cost       = item.Cost,
                        CostTotal  = item.CostTotal,
                        SupplyID   = ID,
                        Qty        = item.Qty,
                        Price      = item.Price
                    };
                    _supplyCategoryServ.AddSupplyCategory(_supplyCategory);

                    Category cat = _categoryServ.GetCategory(item.CategoryID);
                    if (cat.Qty + item.Qty != 0)
                    {
                        cat.Cost = (item.CostTotal + (cat.Cost * cat.Qty)) / (cat.Qty + item.Qty);
                    }
                    cat.Qty   = cat.Qty + item.Qty;
                    cat.Price = item.Price;
                    _categoryServ.UpdateCategory(cat);
                }


                ClientAccount _account = new ClientAccount
                {
                    ClientID         = _selectedSupply.ClientID,
                    Date             = _selectedSupply.Date,
                    RegistrationDate = _selectedSupply.RegistrationDate,
                    Statement        = "فاتورة مشتريات رقم " + ID,
                    Credit           = _selectedSupply.Cost,
                    Debit            = _selectedSupply.CashPaid + _selectedSupply.DiscountPaid
                };
                _clientAccountServ.AddAccount(_account);

                if (_selectedSupply.CashPaid > 0)
                {
                    Safe _safe = new Safe
                    {
                        Date             = _selectedSupply.Date,
                        RegistrationDate = _selectedSupply.RegistrationDate,
                        Statement        = "فاتورة مشتريات رقم " + ID + " من العميل : " + _selectedSupply.Client.Name,
                        Amount           = -_selectedSupply.CashPaid,
                        Source           = 3
                    };
                    _safeServ.AddSafe(_safe);
                }
                _currentWindow.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
        private async void ExecuteSaveAsync()
        {
            if (NewDebt == null)
            {
                return;
            }
            DateTime dt = DateTime.Now;

            _newClientAccount.RegistrationDate = dt;
            _newClientAccount.CanDelete        = true;
            _newClientAccount.Statement        = SelectedStatement.Statement;
            if (_newClientAccount.Statement == "سند دفع له")
            {
                _newClientAccount.Debit  = _amount;
                _newClientAccount.Credit = 0;
                Safe safe = new Safe
                {
                    Amount           = -_newClientAccount.Debit,
                    Date             = _newClientAccount.Date,
                    RegistrationDate = dt,
                    Statement        = "سند دفع للعميل : " + _selectedClient.Name,
                    Source           = 5
                };
                _safeServ.AddSafe(safe);
            }
            else if (_newClientAccount.Statement == "تسوية تنزيل منه")
            {
                _newClientAccount.Debit  = _amount;
                _newClientAccount.Credit = 0;
            }
            else if (_newClientAccount.Statement == "سند قبض منه")
            {
                _newClientAccount.Credit = _amount;
                _newClientAccount.Debit  = 0;
                Safe safe = new Safe
                {
                    Amount           = _newClientAccount.Credit,
                    Date             = _newClientAccount.Date,
                    RegistrationDate = dt,
                    Statement        = "سند قبض من العميل : " + _selectedClient.Name,
                    Source           = 6
                };
                _safeServ.AddSafe(safe);
            }
            else if (_newClientAccount.Statement == "تسوية إضافة له")
            {
                _newClientAccount.Credit = _amount;
                _newClientAccount.Debit  = 0;
            }

            _clientAccountServ.AddAccount(_newClientAccount);
            clientAccounts.Add(_clientAccountServ.GetAccount(_newClientAccount.ID));
            SelectedStatement = null;
            NewClientAccount  = new ClientAccount
            {
                Date = DateTime.Now
            };
            Amount = null;
            await _currentWindow.ShowMessageAsync("نجاح الإضافة", "تم الإضافة بنجاح", MessageDialogStyle.Affirmative, new MetroDialogSettings()
            {
                AffirmativeButtonText = "موافق",
                DialogMessageFontSize = 25,
                DialogTitleFontSize   = 30
            });
        }
        private void ExecuteSave()
        {
            Mouse.OverrideCursor = Cursors.Wait;
            DateTime _dt = DateTime.Now;

            _newSale.RegistrationDate = _dt;
            _saleServ.AddSale(_newSale);
            int _saleID = _saleServ.GetLastSaleID();

            foreach (var item in _saleCategories)
            {
                SaleCategory _saleCategory = new SaleCategory
                {
                    CategoryID              = item.CategoryID,
                    Cost                    = item.Cost,
                    PriceAfterDiscount      = item.PriceAfterDiscount,
                    PriceTotalAfterDiscount = item.PriceTotalAfterDiscount,
                    CostTotal               = item.CostTotal,
                    Price                   = item.Price,
                    PriceTotal              = item.PriceTotal,
                    Discount                = item.Discount,
                    DiscountValue           = item.DiscountValue,
                    DiscountValueTotal      = item.DiscountValueTotal,
                    SaleID                  = _saleID,
                    Qty = item.Qty
                };
                _saleCategoryServ.AddSaleCategory(_saleCategory);

                Category cat = _categoryServ.GetCategory(item.CategoryID);
                cat.Qty = cat.Qty - item.Qty;
                _categoryServ.UpdateCategory(cat);
            }

            ClientAccount _account = new ClientAccount
            {
                ClientID         = _newSale.ClientID,
                Date             = _newSale.Date,
                RegistrationDate = _dt,
                Statement        = "فاتورة مبيعات رقم " + _saleID,
                Credit           = _newSale.Paid,
                Debit            = _newSale.PriceAfterDiscount + _newSale.TransportCost
            };

            _clientAccountServ.AddAccount(_account);

            if (_newSale.Paid > 0)
            {
                Safe _safe = new Safe
                {
                    Date             = _newSale.Date,
                    RegistrationDate = _dt,
                    Statement        = "فاتورة مبيعات رقم " + _saleID + " للعميل: " + _selectedClient.Name,
                    Amount           = _newSale.Paid,
                    Source           = 4
                };
                _safeServ.AddSafe(_safe);
            }


            DS ds = new DS();

            ds.Sale.Rows.Clear();
            int i = 0;

            foreach (var item in _saleCategories)
            {
                ds.Sale.Rows.Add();
                ds.Sale[i]["ID"]            = _saleID;
                ds.Sale[i]["Date"]          = _newSale.Date;
                ds.Sale[i]["Client"]        = _selectedClient.Name;
                ds.Sale[i]["Serial"]        = i + 1;
                ds.Sale[i]["Category"]      = item.Category + " " + item.Company;
                ds.Sale[i]["Qty"]           = item.Qty;
                ds.Sale[i]["Price"]         = Math.Round(Convert.ToDecimal(item.PriceAfterDiscount), 2);
                ds.Sale[i]["TotalPrice"]    = Math.Round(Convert.ToDecimal(item.PriceTotalAfterDiscount), 2);
                ds.Sale[i]["BillPrice"]     = Math.Round(Convert.ToDecimal(_newSale.PriceAfterDiscount), 2);;
                ds.Sale[i]["OldDebt"]       = Math.Abs(Convert.ToDecimal(_newSale.OldDebt));
                ds.Sale[i]["TransportCost"] = _newSale.TransportCost;
                ds.Sale[i]["BillTotal"]     = Math.Abs(Math.Round(Convert.ToDecimal(_newSale.PriceTotal), 2));
                ds.Sale[i]["Paid"]          = _newSale.Paid;
                ds.Sale[i]["NewDebt"]       = Math.Abs(Math.Round(Convert.ToDecimal(_newSale.NewDebt), 2));
                if (_newSale.NewDebt > 0)
                {
                    ds.Sale[i]["Type"] = "له";
                }
                else if (_newSale.NewDebt < 0)
                {
                    ds.Sale[i]["Type"] = "عليه";
                }
                ds.Sale[i]["Salesperson"] = _selectedSalesperson.Name;
                ds.Sale[i]["PrintingMan"] = _newSale.PrintingMan;

                if (_newSale.OldDebt > 0)
                {
                    ds.Sale[i]["Type2"] = "له";
                }
                else if (_newSale.OldDebt < 0)
                {
                    ds.Sale[i]["Type2"] = "عليه";
                }
                ds.Sale[i]["Address"] = _selectedClient.Address;
                try
                {
                    ToWord toWord = new ToWord(Math.Abs(Convert.ToDecimal(_newSale.NewDebt)), currencies[0]);
                    ds.Sale[i]["NewDebtAR"] = toWord.ConvertToArabic();
                }
                catch
                {
                    ds.Sale[i]["NewDebtAR"] = string.Empty;
                }
                i++;
            }
            ReportWindow rpt     = new ReportWindow();
            SaleReport   saleRPT = new SaleReport();

            saleRPT.SetDataSource(ds.Tables["Sale"]);
            rpt.crv.ViewerCore.ReportSource = saleRPT;
            Mouse.OverrideCursor            = null;
            _currentWindow.Hide();
            rpt.ShowDialog();
            NewSale         = new Sale();
            NewSaleCategory = new SaleCategoryVM();
            SaleCategories  = new ObservableCollection <SaleCategoryVM>();
            NewSale.Date    = DateTime.Now;
            OldPrices       = new ObservableCollection <SaleCategory>();
            _currentWindow.ShowDialog();
        }
        private async void ExecuteSaveAsync()
        {
            if (NewSupply.Future == true && NewSupplyFuture.Place == null)
            {
                await _currentWindow.ShowMessageAsync("فشل الإضافة", "يجب كتابة مكان الدفع", MessageDialogStyle.Affirmative, new MetroDialogSettings()
                {
                    AffirmativeButtonText = "موافق",
                    DialogMessageFontSize = 25,
                    DialogTitleFontSize   = 30
                });

                return;
            }
            Mouse.OverrideCursor = Cursors.Wait;
            DateTime _dt = DateTime.Now;

            _newSupply.RegistrationDate = _dt;
            _supplyServ.AddSupply(_newSupply);
            int _supplyID = _supplyServ.GetLastSupplyID();

            foreach (var item in _supplyCategories)
            {
                SupplyCategory _supplyCategory = new SupplyCategory
                {
                    CategoryID             = item.CategoryID,
                    Cost                   = item.Cost,
                    CostAfterDiscount      = item.CostAfterDiscount,
                    CostAfterTax           = item.CostAfterTax,
                    CostTotal              = item.CostTotal,
                    CostTotalAfterDiscount = item.CostTotalAfterDiscount,
                    CostTotalAfterTax      = item.CostTotalAfterTax,
                    Discount               = item.Discount,
                    DiscountValue          = item.DiscountValue,
                    DiscountValueTotal     = item.DiscountValueTotal,
                    SupplyID               = _supplyID,
                    Qty           = item.Qty,
                    Tax           = item.Tax,
                    TaxValue      = item.TaxValue,
                    TaxValueTotal = item.TaxValueTotal,
                    Price         = item.Price
                };
                _supplyCategoryServ.AddSupplyCategory(_supplyCategory);

                Category cat = _categoryServ.GetCategory(item.CategoryID);
                if (cat.Qty + item.Qty != 0)
                {
                    cat.Cost = (item.CostTotalAfterDiscount + (cat.Cost * cat.Qty)) / (cat.Qty + item.Qty);
                }
                cat.Qty   = cat.Qty + item.Qty;
                cat.Price = item.Price;
                _categoryServ.UpdateCategory(cat);
            }

            if (_newSupply.Future == true)
            {
                _newSupplyFuture.Change   = _newSupply.Change;
                _newSupplyFuture.SupplyID = _supplyID;
                if (_newSupplyFuture.Cheque == false)
                {
                    _newSupplyFuture.ChequeNumber = null;
                }
                _supplyFutureServ.AddSupplyFuture(_newSupplyFuture);
                _placesSuggestions.Add(_newSupplyFuture.Place);
            }
            ClientAccount _account = new ClientAccount
            {
                ClientID         = _newSupply.ClientID,
                Date             = _newSupply.Date,
                RegistrationDate = _dt,
                Statement        = "فاتورة مشتريات رقم " + _supplyID,
                Credit           = _newSupply.CostAfterTax,
                Debit            = _newSupply.CashPaid
            };

            _clientAccountServ.AddAccount(_account);
            if (_newSupply.DiscountPaid != 0 || _newSupply.TotalDiscount != 0)
            {
                _account = new ClientAccount
                {
                    ClientID         = _newSupply.ClientID,
                    Date             = _newSupply.Date,
                    RegistrationDate = _dt,
                    Statement        = "خصومات فاتورة مشتريات رقم " + _supplyID,
                    Credit           = _newSupply.DiscountPaid,
                    Debit            = _newSupply.TotalDiscount
                };
                _clientAccountServ.AddAccount(_account);
            }
            if (_newSupply.CashPaid > 0)
            {
                Safe _safe = new Safe
                {
                    Date             = _newSupply.Date,
                    RegistrationDate = _dt,
                    Statement        = "فاتورة مشتريات رقم " + _supplyID + " من العميل : " + _selectedClient.Name,
                    Amount           = -_newSupply.CashPaid,
                    Source           = 3
                };
                _safeServ.AddSafe(_safe);
            }

            DS ds = new DS();

            ds.Sale.Rows.Clear();
            int i = 0;

            foreach (var item in _supplyCategories)
            {
                ds.Sale.Rows.Add();
                ds.Sale[i]["ID"]         = _supplyID;
                ds.Sale[i]["Date"]       = _newSupply.Date;
                ds.Sale[i]["Client"]     = _selectedClient.Name;
                ds.Sale[i]["Serial"]     = i + 1;
                ds.Sale[i]["Category"]   = item.Category + " " + item.Company;
                ds.Sale[i]["Qty"]        = item.Qty;
                ds.Sale[i]["Price"]      = Math.Round(Convert.ToDecimal(item.CostAfterTax), 2);
                ds.Sale[i]["TotalPrice"] = Math.Round(Convert.ToDecimal(item.CostTotalAfterTax), 2);
                ds.Sale[i]["BillPrice"]  = Math.Round(Convert.ToDecimal(_newSupply.CostAfterTax), 2);
                ds.Sale[i]["OldDebt"]    = Math.Abs(Math.Round(Convert.ToDecimal(_newSupply.OldDebt), 2));

                ds.Sale[i]["Paid"]    = Math.Abs(Math.Round(Convert.ToDecimal(_newSupply.CashPaid + _newSupply.DiscountPaid), 2));
                ds.Sale[i]["NewDebt"] = Math.Abs(Math.Round(Convert.ToDecimal(_newSupply.NewDebt), 2));
                if (_newSupply.NewDebt > 0)
                {
                    ds.Sale[i]["PrintingMan"] = "له";
                }
                else if (_newSupply.NewDebt < 0)
                {
                    ds.Sale[i]["PrintingMan"] = "عليه";
                }

                if (_newSupply.OldDebt > 0)
                {
                    ds.Sale[i]["Type"] = "له";
                }
                else if (_newSupply.OldDebt < 0)
                {
                    ds.Sale[i]["Type"] = "عليه";
                }
                ds.Sale[i]["BillTotal"] = Math.Abs(Math.Round(Convert.ToDecimal(_newSupply.OldDebt), 2) + Math.Round(Convert.ToDecimal(_newSupply.CostAfterTax), 2));
                if (Math.Round(Convert.ToDecimal(_newSupply.OldDebt), 2) + Math.Round(Convert.ToDecimal(_newSupply.CostAfterTax), 2) > 0)
                {
                    ds.Sale[i]["Type2"] = "له";
                }
                else if (Math.Round(Convert.ToDecimal(_newSupply.OldDebt), 2) + Math.Round(Convert.ToDecimal(_newSupply.CostAfterTax), 2) < 0)
                {
                    ds.Sale[i]["Type2"] = "عليه";
                }
                i++;
            }
            ReportWindow rpt       = new ReportWindow();
            SupplyReport supplyRPT = new SupplyReport();

            supplyRPT.SetDataSource(ds.Tables["Sale"]);
            rpt.crv.ViewerCore.ReportSource = supplyRPT;
            Mouse.OverrideCursor            = null;
            _currentWindow.Hide();
            rpt.ShowDialog();

            NewSupply            = new Supply();
            NewSupplyCategory    = new SupplyCategoryVM();
            NewSupplyFuture      = new SupplyFuture();
            SupplyCategories     = new ObservableCollection <SupplyCategoryVM>();
            NewSupply.Date       = DateTime.Now;
            NewSupplyFuture.Date = DateTime.Now;
            OldCosts             = new ObservableCollection <SupplyCategory>();
            _currentWindow.ShowDialog();
        }
示例#7
0
        private async void ExecuteSaveAsync()
        {
            if (NewDebt == null)
            {
                return;
            }
            DateTime dt = DateTime.Now;

            _newClientAccount.RegistrationDate = dt;
            _newClientAccount.CanDelete        = true;
            _newClientAccount.Statement        = SelectedStatement.Statement;
            if (_newClientAccount.Statement == "سند دفع")
            {
                _newClientAccount.Debit  = _amount;
                _newClientAccount.Credit = 0;
                Safe safe = new Safe
                {
                    Amount           = -_newClientAccount.Debit,
                    Date             = _newClientAccount.Date,
                    RegistrationDate = dt,
                    Statement        = "سند دفع للعميل : " + _selectedClient.Name,
                    Source           = 5
                };
                _safeServ.AddSafe(safe);
            }

            else if (_newClientAccount.Statement == "دفع شيك")
            {
                _newClientAccount.Debit  = _amount;
                _newClientAccount.Credit = 0;
                Safe safe = new Safe
                {
                    Amount           = -_newClientAccount.Debit,
                    Date             = _newClientAccount.Date,
                    RegistrationDate = dt,
                    Statement        = "دفع شيك للعميل : " + _selectedClient.Name,
                    Source           = 7
                };
                _safeServ.AddSafe(safe);
            }

            else if (_newClientAccount.Statement == "دفع سلف")
            {
                _newClientAccount.Debit  = _amount;
                _newClientAccount.Credit = 0;
                Safe safe = new Safe
                {
                    Amount           = -_newClientAccount.Debit,
                    Date             = _newClientAccount.Date,
                    RegistrationDate = dt,
                    Statement        = "دفع سلف للعميل : " + _selectedClient.Name,
                    Source           = 7
                };
                _safeServ.AddSafe(safe);
            }
            else if (_newClientAccount.Statement == "تسوية تنزيل")
            {
                _newClientAccount.Debit  = _amount;
                _newClientAccount.Credit = 0;
            }
            else if (_newClientAccount.Statement == "سند قبض")
            {
                _newClientAccount.Credit = _amount;
                _newClientAccount.Debit  = 0;
                Safe safe = new Safe
                {
                    Amount           = _newClientAccount.Credit,
                    Date             = _newClientAccount.Date,
                    RegistrationDate = dt,
                    Statement        = "سند قبض من العميل : " + _selectedClient.Name,
                    Source           = 6
                };
                _safeServ.AddSafe(safe);
            }
            else if (_newClientAccount.Statement == "قبض شيك")
            {
                _newClientAccount.Credit = _amount;
                _newClientAccount.Debit  = 0;
                Safe safe = new Safe
                {
                    Amount           = _newClientAccount.Credit,
                    Date             = _newClientAccount.Date,
                    RegistrationDate = dt,
                    Statement        = "قبض شيك من العميل : " + _selectedClient.Name,
                    Source           = 6
                };
                _safeServ.AddSafe(safe);
            }
            else if (_newClientAccount.Statement == "قبض سلف")
            {
                _newClientAccount.Credit = _amount;
                _newClientAccount.Debit  = 0;
                Safe safe = new Safe
                {
                    Amount           = _newClientAccount.Credit,
                    Date             = _newClientAccount.Date,
                    RegistrationDate = dt,
                    Statement        = "قبض سلف من العميل : " + _selectedClient.Name,
                    Source           = 8
                };
                _safeServ.AddSafe(safe);
            }
            else if (_newClientAccount.Statement == "تسوية إضافة")
            {
                _newClientAccount.Credit = _amount;
                _newClientAccount.Debit  = 0;
            }
            if (!string.IsNullOrEmpty(Url))
            {
                Directory.CreateDirectory(@"E:\صور الشيكات \" + SelectedClient.Name);
                _newClientAccount.Url = @"E:\صور الشيكات \" + SelectedClient.Name + @"\" + DateTime.Now.ToShortDateString().Replace('/', '-') + " - " + DateTime.Now.ToLongTimeString().Replace(':', '-') + Path.GetExtension(Url);
                File.Copy(Url, _newClientAccount.Url, true);
                Url = "";
            }
            _clientAccountServ.AddAccount(_newClientAccount);
            SelectedStatement = null;
            NewClientAccount  = new ClientAccount
            {
                Date = DateTime.Now
            };
            Amount = null;

            await _currentWindow.ShowMessageAsync("نجاح الإضافة", "تم الإضافة بنجاح", MessageDialogStyle.Affirmative, new MetroDialogSettings()
            {
                AffirmativeButtonText = "موافق",
                DialogMessageFontSize = 25,
                DialogTitleFontSize   = 30
            });
        }
示例#8
0
        private void ExecuteSave(string parameter)
        {
            try
            {
                Mouse.OverrideCursor = Cursors.Wait;
                DateTime _dt = DateTime.Now;
                _newSale.RegistrationDate = _dt;
                _saleServ.AddSale(_newSale);
                int _saleID = _saleServ.GetLastSaleID();

                foreach (var item in _saleCategories)
                {
                    SaleCategory _saleCategory = new SaleCategory
                    {
                        CategoryID = item.CategoryID,
                        Cost       = item.Cost,
                        CostTotal  = item.CostTotal,
                        Price      = item.Price,
                        PriceTotal = item.PriceTotal,
                        SaleID     = _saleID,
                        Qty        = item.Qty
                    };
                    _saleCategoryServ.AddSaleCategory(_saleCategory);

                    Category cat = _categoryServ.GetCategory(item.CategoryID);
                    cat.Qty = cat.Qty - item.Qty;
                    _categoryServ.UpdateCategory(cat);
                }

                ClientAccount _account = new ClientAccount
                {
                    ClientID         = _newSale.ClientID,
                    Date             = _newSale.Date,
                    RegistrationDate = _dt,
                    Statement        = "فاتورة مبيعات رقم " + _saleID,
                    Credit           = _newSale.CashPaid + _newSale.DiscountPaid,
                    Debit            = _newSale.Price
                };
                _clientAccountServ.AddAccount(_account);

                if (_newSale.CashPaid > 0)
                {
                    Safe _safe = new Safe
                    {
                        Date             = _newSale.Date,
                        RegistrationDate = _dt,
                        Statement        = "فاتورة مبيعات رقم " + _saleID + " للعميل: " + _selectedClient.Name,
                        Amount           = _newSale.CashPaid,
                        Source           = 4
                    };
                    _safeServ.AddSafe(_safe);
                }

                DS ds = new DS();
                ds.Sale.Rows.Clear();
                int i = 0;
                foreach (var item in _saleCategories)
                {
                    ds.Sale.Rows.Add();
                    ds.Sale[i]["ID"]           = _saleID;
                    ds.Sale[i]["Date"]         = _newSale.Date;
                    ds.Sale[i]["Client"]       = _selectedClient.Name;
                    ds.Sale[i]["Serial"]       = i + 1;
                    ds.Sale[i]["Category"]     = item.Category + " " + item.Company;
                    ds.Sale[i]["Qty"]          = item.Qty;
                    ds.Sale[i]["Price"]        = Math.Round(Convert.ToDecimal(item.Price), 2);
                    ds.Sale[i]["TotalPrice"]   = Math.Round(Convert.ToDecimal(item.PriceTotal), 2);
                    ds.Sale[i]["BillPrice"]    = Math.Round(Convert.ToDecimal(_newSale.Price), 2);;
                    ds.Sale[i]["OldDebt"]      = Math.Abs(Convert.ToDecimal(_newSale.OldDebt));
                    ds.Sale[i]["BillTotal"]    = Math.Abs(Math.Round(Convert.ToDecimal(_newSale.PriceTotal), 2));
                    ds.Sale[i]["Paid"]         = _newSale.CashPaid;
                    ds.Sale[i]["DiscountPaid"] = _newSale.DiscountPaid;
                    ds.Sale[i]["NewDebt"]      = Math.Abs(Math.Round(Convert.ToDecimal(_newSale.NewDebt), 2));
                    if (_newSale.NewDebt > 0)
                    {
                        ds.Sale[i]["Type"] = "له";
                    }
                    else if (_newSale.NewDebt < 0)
                    {
                        ds.Sale[i]["Type"] = "عليه";
                    }

                    if (_newSale.OldDebt > 0)
                    {
                        ds.Sale[i]["Type2"] = "له";
                    }
                    else if (_newSale.OldDebt < 0)
                    {
                        ds.Sale[i]["Type2"] = "عليه";
                    }

                    i++;
                }
                ReportWindow rpt = new ReportWindow();
                if (parameter == "Client")
                {
                    SaleReport saleRPT = new SaleReport();
                    saleRPT.SetDataSource(ds.Tables["Sale"]);
                    rpt.crv.ViewerCore.ReportSource = saleRPT;
                    Mouse.OverrideCursor            = null;
                }
                else
                {
                    SaleReport2 saleRPT = new SaleReport2();
                    saleRPT.SetDataSource(ds.Tables["Sale"]);
                    rpt.crv.ViewerCore.ReportSource = saleRPT;
                    Mouse.OverrideCursor            = null;
                }
                _currentWindow.Hide();
                rpt.ShowDialog();
                NewSale         = new Sale();
                NewSaleCategory = new SaleCategoryVM();
                SaleCategories  = new ObservableCollection <SaleCategoryVM>();
                NewSale.Date    = DateTime.Now;
                OldPrices       = new ObservableCollection <SaleCategory>();
                _currentWindow.ShowDialog();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
        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
            });
        }