Beispiel #1
0
 private async Task LoadSales()
 {
     using (var scope = new Core.DbScope())
     {
         dataGridView1.DataSource = await Core.InvoiceCore.Instance.GetSalesAsync(scope, DateTime.Today);
     }
 }
        public async void Init(GoodType goodType)
        {
            scope = new DbScope();
            goods = await InvoiceCore.Instance.GetGoodsAsync(scope);
            cmbGoodType.DataSource = goods.Select(g => g.Name).ToList();
            cmbGoodType.SelectedItem = goodType.Name;

            await RebindGridAsync(goodType);

            cmbGoodType.SelectedIndexChanged += CmbGoodType_SelectedIndexChanged;
        }
Beispiel #3
0
        public IEnumerable<Sale> GetSales(DbScope scope, DateTime startDate, DateTime endDate)
        {
            startDate = startDate.Date;
            endDate = endDate.Date.AddDays(1).AddSeconds(-1);
            if (startDate > endDate)
            {
                var t = endDate;
                endDate = startDate;
                startDate = t;
            }

            return scope.DataProvider.GetSales(startDate, endDate);
        }
Beispiel #4
0
        private async void RefreshGrid()
        {
            scope.Submit();
            scope = new DbScope();
            var g = await InvoiceCore.Instance.GetGoodsAsync(scope);

            if (g == null)
            {
                MessageBox.Show("Шото пішло не так. Типи товару не підгрузились.");
                throw new ArgumentException("goodTypes");
            }

            goodTypes = g.ToList();
            GoodTypesLoaded();
        }
Beispiel #5
0
        public MainForm()
        {
            InitializeComponent();

            this.Text += " " + Application.ProductVersion.ToString();

            dateTimePicker1.Value = DateTime.Now;
            dateTimePicker2.Value = DateTime.Now;

            scope = new DbScope();

            InvoiceCore.Instance.InitializationNotification += Instance_InitializationNotification;
            GoodTypesLoaded = () => BindGrid();


            RefreshGrid();
        }
Beispiel #6
0
        public static Sale ToSale(this SaleParsed s, DbScope scope)
        {
            var customer =  scope.DataProvider
                .GetCustomer(c => c.Name == s.Customer);

            if (customer == null)
                customer = new Customer()
                {
                    Name = s.Customer
                };

            return new Sale()
            {
                Customer = customer,
                Producer = s.Producer,
                DateTime = s.DateTime,
                GoodType = s.GoodType,
                Quantity = s.Quantity,
                Return = s.Return
            };
        }
Beispiel #7
0
 public IEnumerable<Customer> GetCustomers(DbScope scope)
 {
     return scope.DataProvider.GetCustomers();
 }
Beispiel #8
0
 public IEnumerable<Invoice> GetInvoicesByDatesRange(DbScope scope, DateTime startDate, DateTime endDate)
 {
     return GenerateInvoices(scope, GetSales(scope, startDate, endDate), Settings.Producer);
 }
Beispiel #9
0
 public async Task<IEnumerable<SpecialPrice>> GetSpecialPricesAsync(DbScope scope, bool includeDeleted = false)
 {
     return await scope.DataProvider.GetAllAsync<SpecialPrice>(includeDeleted);
 }
Beispiel #10
0
        public void ExportToDoc(DbScope scope, DateTime startDate, DateTime endDate, string savePath, string runningPath)
        {
                var inv = GetInvoicesByDatesRange(scope, startDate, endDate);

                if (!inv.Any())
                    throw new NoSalesException();

                SaveInvoices(scope, inv, savePath, runningPath);
        }
Beispiel #11
0
 public void SaveInvoices(DbScope scope, IEnumerable<Invoice> invoices, string path, string runningPath)
 {
     var generator = new InvoiceGenerator();
     generator.CreateInOneDocument(invoices, path, runningPath);
 }
Beispiel #12
0
 public void RemoveGoodType(DbScope scope, GoodType good)
 {
     scope.DataProvider.Remove(good);
 }
Beispiel #13
0
 public void SaveGoodType(DbScope scope, GoodType goodType)
 {
     scope.DataProvider.SaveEntity(goodType);
 }
Beispiel #14
0
 public IEnumerable<SpecialPrice> GetSpecialPrices(DbScope scope)
 {
     return scope.DataProvider.GetSpecialPrices();
 }
Beispiel #15
0
        private IEnumerable<Invoice> GenerateInvoices(DbScope scope, IEnumerable<Sale> sales, string producer)
        {
            var list = new List<Invoice>();

            var dates = sales.Select(s => s.DateTime).Distinct();
            var customers = sales.Select(s => s.Customer).Distinct();

            foreach (var d in dates)
            {
                foreach (var c in customers)
                {
                    var salesByCustomer = sales.Where(s => s.Customer.Name == c.Name && s.DateTime.Date == d.Date);
                    if (!salesByCustomer.Any())
                        continue;

                    var specialPrices =scope.DataProvider.GetSpecialPrices().Where(sp => sp.Customer == c);

                    var invoice = new Invoice();
                    invoice.Customer = c;
                    invoice.Producer = producer;
                    invoice.DateTime = d;
                    invoice.SoldItems = new List<SoldItem>();

                    foreach (var s in salesByCustomer)
                    {
                        var qt = (s.Quantity - s.Return) > 0 ? (s.Quantity - s.Return) : 0;
                        var sPrice = specialPrices.FirstOrDefault(sp => sp.GoodType == s.GoodType);

                        invoice.SoldItems.Add(new SoldItem(s.GoodType, qt, sPrice?.Price));
                    }

                    list.Add(invoice);
                }

            }
            return list;
        }
Beispiel #16
0
        public IEnumerable<Sale> ImportSalesFromXLS(DbScope scope, string path, IEnumerable<int> sheets, DateTime dateTime, bool saveToDb = true)
        {
            var goods = scope.DataProvider.GetGoods();
            var producer = Settings.Producer;
            var importer = new ExcellImporter();
            var sales = importer.ImportFromSheet(path, dateTime, sheets, goods, producer);

            var result = new List<Sale>();
            NewCustomers = 0;

            foreach (var sale in sales)
            {
                var salesByDay = sale.Value.Select(s => s.ToSale(scope)).ToList();
                NewCustomers += salesByDay.Count(s => !s.Customer.Id.HasValue);

                if (saveToDb)
                    scope.DataProvider.AddSales(salesByDay);

                result.AddRange(salesByDay);
            }

            return result;
        }
Beispiel #17
0
        private async void toDocButton_Click(object sender, EventArgs e)
        {
            var startDate = dateTimePicker1.Value.Date;
            var endDate = dateTimePicker2.Value.Date;

            try
            {
                scope.Submit();
                scope = new DbScope();
                var saveDlg = new SaveFileDialog();
                saveDlg.Filter = ".docx|*.docx";
                if (saveDlg.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
                {
                    var runningPath = Application.StartupPath;
                    statusProgress("Генеримо документ...", true);

                    await Task.Run(() =>
                    InvoiceCore.Instance.ExportToDoc(scope, startDate, endDate, saveDlg.FileName, runningPath));

                    statusProgress("Документ готовий", false);
                    return;
                }
            }
            catch (NoSalesException)
            {
                MessageBox.Show(string.Format("Немає продаж за {0}-{1}", startDate.ToShortDateString(), endDate.ToShortDateString()));
            }
            catch (Exception ex)
            {
                ShowErrorBox(ex);
            }

            statusProgress("", false);
        }
Beispiel #18
0
 public void AddSpecialPrice(DbScope scope, GoodType good, Customer client, double price)
 {
     scope.DataProvider.AddSpecialPrice(good, client, price);
 }
Beispiel #19
0
        public IEnumerable<Invoice> GenerateInvoicesByDate(DbScope scope, DateTime date)
        {
            IEnumerable<Sale> sales = scope.DataProvider.GetSales(date);

            return GenerateInvoices(scope, sales, Settings.Producer);
        }
Beispiel #20
0
 public void ClearSales(DbScope scope)
 {
     scope.DataProvider.ClearSales();
 }
Beispiel #21
0
 public IEnumerable<GoodType> GetGoods(DbScope scope)
 {
     return scope.DataProvider.GetGoods();
 }
Beispiel #22
0
 public async Task<IEnumerable<Sale>> GetSalesAsync(DbScope scope, DateTime day)
 {
     return await scope.DataProvider.GetSalesAsync(day, day);
 }
Beispiel #23
0
 public async Task<IEnumerable<GoodType>> GetGoodsAsync(DbScope scope, bool includeDeleted = false)
 {
     return await scope.DataProvider.GetAllAsync<GoodType>(includeDeleted);
 }
Beispiel #24
0
        private void importButton_Click(object sender, EventArgs e)
        {
            try
            {
                var sheetDialog = new SelectSheetsDialog();
                if (sheetDialog.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
                {
                    var inv = InvoiceCore.Instance.ImportSalesFromXLS(scope, sheetDialog.FilePath, sheetDialog.Sheets, sheetDialog.DateTime);
                    MessageBox.Show(string.Format("Імпортовано {0} продажів. {1} нових клієнтів.",
                        inv.Count(), InvoiceCore.Instance.NewCustomers));

                    scope.Submit();
                    scope = new DbScope();
                }
            }
            catch (Exception ex)
            {
                ShowErrorBox(ex);
            }
        }