Esempio n. 1
0
        public void UpdateDailyBalance()
        {
            this.ClearDailyBalance();
            var dailySales = this.Query.GroupBy(t => new { t.TransactionDate })
                             .Select(go => new
            {
                IncomeAmount    = go.Sum(i => i.Total),
                TransactionDate = go.Key.TransactionDate
            }).ToList();

            Console.WriteLine("> {0} Update Daily Sales Balance {2} [{1}]", DateTime.Now.ToLongTimeString(), dailySales.Count(), this.transactionType.ToString());

            erpNodeDBContext.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;

            dailySales.ForEach(ds =>
            {
                var dailySale = new CommercialDailyBalance()
                {
                    TransactionDate = ds.TransactionDate,
                    Balance         = ds.IncomeAmount,
                    Type            = this.transactionType,
                    Id = Guid.NewGuid()
                };
                this.erpNodeDBContext.CommercialDailyBalances.Add(dailySale);
            });

            erpNodeDBContext.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.TrackAll;
            erpNodeDBContext.ChangeTracker.DetectChanges();
            erpNodeDBContext.SaveChanges();
        }
Esempio n. 2
0
        public List <CommercialDailyBalance> ListDailyBalances(int duration)
        {
            DateTime StartDate = DateTime.Now.AddDays(duration * -1);

            var dailyBalances = this.erpNodeDBContext.CommercialDailyBalances
                                .Where(db => db.TransactionDate > StartDate && db.Type == this.transactionType)
                                .ToList();

            var firstDateBalance = dailyBalances.Where(b => b.TransactionDate == StartDate).FirstOrDefault();

            if (firstDateBalance == null)
            {
                firstDateBalance = new CommercialDailyBalance()
                {
                    TransactionDate = StartDate,
                    Balance         = 0,
                    Type            = this.transactionType,
                    Id = Guid.NewGuid()
                };

                dailyBalances.Add(firstDateBalance);
            }

            return(dailyBalances);
        }