Esempio n. 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;
        }
Esempio n. 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);
        }
Esempio n. 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();
        }
Esempio n. 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();
        }
Esempio n. 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
            };
        }
Esempio n. 7
0
 public IEnumerable<Customer> GetCustomers(DbScope scope)
 {
     return scope.DataProvider.GetCustomers();
 }
Esempio n. 8
0
 public IEnumerable<Invoice> GetInvoicesByDatesRange(DbScope scope, DateTime startDate, DateTime endDate)
 {
     return GenerateInvoices(scope, GetSales(scope, startDate, endDate), Settings.Producer);
 }
Esempio n. 9
0
 public async Task<IEnumerable<SpecialPrice>> GetSpecialPricesAsync(DbScope scope, bool includeDeleted = false)
 {
     return await scope.DataProvider.GetAllAsync<SpecialPrice>(includeDeleted);
 }
Esempio n. 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);
        }
Esempio n. 11
0
 public void SaveInvoices(DbScope scope, IEnumerable<Invoice> invoices, string path, string runningPath)
 {
     var generator = new InvoiceGenerator();
     generator.CreateInOneDocument(invoices, path, runningPath);
 }
Esempio n. 12
0
 public void RemoveGoodType(DbScope scope, GoodType good)
 {
     scope.DataProvider.Remove(good);
 }
Esempio n. 13
0
 public void SaveGoodType(DbScope scope, GoodType goodType)
 {
     scope.DataProvider.SaveEntity(goodType);
 }
Esempio n. 14
0
 public IEnumerable<SpecialPrice> GetSpecialPrices(DbScope scope)
 {
     return scope.DataProvider.GetSpecialPrices();
 }
Esempio n. 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;
        }
Esempio n. 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;
        }
Esempio n. 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);
        }
Esempio n. 18
0
 public void AddSpecialPrice(DbScope scope, GoodType good, Customer client, double price)
 {
     scope.DataProvider.AddSpecialPrice(good, client, price);
 }
Esempio n. 19
0
        public IEnumerable<Invoice> GenerateInvoicesByDate(DbScope scope, DateTime date)
        {
            IEnumerable<Sale> sales = scope.DataProvider.GetSales(date);

            return GenerateInvoices(scope, sales, Settings.Producer);
        }
Esempio n. 20
0
 public void ClearSales(DbScope scope)
 {
     scope.DataProvider.ClearSales();
 }
Esempio n. 21
0
 public IEnumerable<GoodType> GetGoods(DbScope scope)
 {
     return scope.DataProvider.GetGoods();
 }
Esempio n. 22
0
 public async Task<IEnumerable<Sale>> GetSalesAsync(DbScope scope, DateTime day)
 {
     return await scope.DataProvider.GetSalesAsync(day, day);
 }
Esempio n. 23
0
 public async Task<IEnumerable<GoodType>> GetGoodsAsync(DbScope scope, bool includeDeleted = false)
 {
     return await scope.DataProvider.GetAllAsync<GoodType>(includeDeleted);
 }
Esempio n. 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);
            }
        }