Example #1
0
 private void SaveCommand_Execute(object obj)
 {
     SelectedLedgerAccount.CompanyId = 1;
     if (SelectedLedgerAccount.IsSystemLedger)
     {
         ////MessageBox.Show("Sorry Cannot Modify System Ledgers");
         return;
     }
     SelectedLedgerAccount.IsSystemLedger = false;
     if (Service.SaveLedgerAccount(SelectedLedgerAccount) > 0)
     {
         var parentaccount = SelectedLedgerAccount.parentLedgerAccount;
         if (parentaccount != null)
         {
             var lgs = Ledgergenerals.Where(a => a.LedgerAccountId == parentaccount.LedgerAccountId);
             foreach (var item in lgs)
             {
                 item.LedgerAccountId = SelectedLedgerAccount.LedgerAccountId;
                 Service.SaveLedgerGeneral(item);
             }
             var ltds = LedgerTransactionDetails.Where(a => a.LedgerAccountId == parentaccount.LedgerAccountId);
             foreach (var item in ltds)
             {
                 item.LedgerAccountId = SelectedLedgerAccount.LedgerAccountId;
                 Service.SaveLedgerTransactionDetail(item);
             }
         }
     }
     Task.Run(() => Init());
     SelectedLedgerAccount = null;
 }
        //internal void LoadChart(LedgerAccount ledgerAccount, Chart chart)
        //{
        //    throw new NotImplementedException();
        //}
        internal void LoadChartForSingleAccount()
        {
            //    if (SelectedLedgerAccount != null)
            //    {
            //        var measurements = LedgerTransactionDetails
            //            .Join(LedgerTransactions,
            //            a => a.LedgerTransactionId,
            //            b => b.LedgerTransactionId,
            //            (a, b) =>
            //            new
            //            {
            //                Date = b.Date,
            //                Amount = a.Amount,
            //                Account = a.LedgerAccount.AccountName
            //            }).ToList();
            //        var k = measurements.Where(a => a.Account == SelectedLedgerAccount.AccountName)
            //       .GroupBy(s => s.Date)
            //       .Select(s => new { name = s.Key, sum = s.Sum(a => a.Amount) })
            //       .OrderBy(s => s.sum).AsEnumerable()
            //       .Select(a => new KeyValuePair<string, decimal>(a.name.Date.ToShortDateString(), (decimal)a.sum)).ToList();
            //        ChartData = k;
            //}

            try
            {
                PlotModel = new PlotModel();
                SetUpModelNew();
                var dataPerDetector = LedgerTransactionDetails.Where(a => a.LedgerAccountId == SelectedLedgerAccount.LedgerAccountId)
                                      .Take(10).OrderBy(a => a.LedgerTransaction.Date.Date)
                                      .GroupBy(m => m.LedgerTransaction.Date.Date)
                                      .Select(g => new
                {
                    Total   = g.Sum(p => p.Amount),
                    date    = g.Key,
                    Account = g.Select(a => a.LedgerAccount.AccountName).FirstOrDefault()
                })
                                      .ToList();

                //string bevname = GetBeverageName(data.Key);
                var lineSerie = new OxyPlot.Series.LineSeries
                {
                    ToolTip = string.Format(" {0} Sales", dataPerDetector.Select(a => a.Account).FirstOrDefault()),
                    // LabelFormatString = string.Format("{0} Sales", dataPerDetector.Select(a => a.Item).FirstOrDefault()),
                    StrokeThickness = 1,
                    MarkerSize      = 3,
                    MarkerStroke    = OxyColor.FromUInt32((uint)SelectedLedgerAccount.LedgerAccountId),

                    MarkerType = MarkerType.Diamond,// markerTypes[data.Key],
                    CanTrackerInterpolatePoints = false,
                    Title = string.Format("{0} Sales", dataPerDetector.Select(a => a.Account).FirstOrDefault())
                };
                dataPerDetector.ForEach(d => lineSerie.Points.Add(new DataPoint(OxyPlot.Axes.DateTimeAxis.ToDouble(d.date), double.Parse(d.Total.ToString()))));
                PlotModel.Series.Add(lineSerie);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 internal void LoadChart()
 {
     try
     {
         foreach (var item in LedgerAccounts)
         {
             var dataPerDetector = LedgerTransactionDetails.Where(a => a.LedgerAccountId == item.LedgerAccountId).OrderByDescending(m => m.LedgerTransaction.Date.Date).GroupBy(m => m.LedgerTransaction.Date.Date).
                                   Select(g => new { Total = g.Sum(p => p.Amount), date = g.Key }).Take(100).ToList();
             var lineSerie = new OxyPlot.Series.LineSeries
             {
                 // LabelFormatString = item.AccountName,
                 StrokeThickness             = 1,
                 MarkerSize                  = 3,
                 MarkerStroke                = OxyColor.FromUInt32((UInt32)item.LedgerAccountId),
                 MarkerType                  = MarkerType.Diamond,
                 CanTrackerInterpolatePoints = false,
                 Title   = item.AccountName,
                 ToolTip = item.AccountName
             };
             foreach (var item2 in dataPerDetector)
             {
                 lineSerie.Points.Add(new DataPoint(OxyPlot.Axes.DateTimeAxis.ToDouble(item2.date), (double)item2.Total));
             }
             PlotModel.Series.Add(lineSerie);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
     //if (SelectedLedgerAccount != null)
     //{
     //    var measurements = LedgerTransactionDetails
     //        .Join(LedgerTransactions,
     //        a => a.LedgerTransactionId,
     //        b => b.LedgerTransactionId,
     //        (a, b) =>
     //        new
     //        {
     //            Date = b.Date,
     //            Amount = a.Amount,
     //            Account = a.LedgerAccount.AccountName
     //        }).ToList();
     //    var k = measurements.Where(a => a.Account == SelectedLedgerAccount.AccountName)
     //   .GroupBy(s => s.Date)
     //   .Select(s => new { name = s.Key, sum = s.Sum(a => a.Amount) })
     //   .OrderBy(s => s.sum).AsEnumerable()
     //   .Select(a => new KeyValuePair<string, decimal>(a.name.Date.ToShortDateString(), (decimal)a.sum)).ToList();
     //    ChartData = k;
     //}
 }