コード例 #1
0
        // Update status Of Abonament
        // Verificam daca a expirat abonament (in functie de data)
        // Verificam daca a atins nr maxim de sedinte
        public void RefreshStatusAbonament(int abonamentID, ReportDbContext context)
        {
            AbonamentModel abonament = GetAbonamentByAbID(abonamentID, context);

            if (abonament == null)
            {
                return;
            }
            if (abonament.NrSedinteEfectuate >= abonament.TipAbonament.NrTotalSedinte)
            {
                abonament.StareAbonament = StareAbonament.Finalizat;
                context.Update(abonament);
                context.SaveChanges();
                return;
            }
            if (abonament.DataStop <= DateTime.Now)
            {
                abonament.StareAbonament = StareAbonament.Finalizat;
                context.Update(abonament);
                context.SaveChanges();
                return;
            }
            if ((abonament.DataStop - abonament.DataStart).TotalDays > 32)
            {
                abonament.StareAbonament = StareAbonament.Extins;
            }
            else
            {
                abonament.StareAbonament = StareAbonament.Activ;
            }

            context.Update(abonament);
            context.SaveChanges();
        }
コード例 #2
0
        public async Task RemoveUser(string userName)
        {
            var user = await _crmDbContext.User.FirstOrDefaultAsync(f => f.Account == userName);

            if (user == null)
            {
                return;
            }
            _crmDbContext.Remove(user);
            _crmDbContext.SaveChanges();
        }
コード例 #3
0
 public bool AddReport(ReportModel model)
 {
     try
     {
         reportDbContext.ReportModels.Add(model);
         reportDbContext.SaveChanges();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
コード例 #4
0
        public void InsertList(List <CodeAnalysisInfo> loInfos)
        {
            loInfos.ForEach((info) =>
            {
                this.Insert(info);
            });

            _dbContext.SaveChanges();
        }
コード例 #5
0
        // Update Nr sedinte efectuate
        // Daca o persoana a fost adaugata la un antrenament
        public void UpdateNrSedinteEfAbonamentbyID(int nr, int abonamentID, ReportDbContext context)
        {
            var abonamentModel = context.AbonamentModels
                                 .Include(t => t.TipAbonament)
                                 .Include(a => a.PersoanaModel)
                                 .FirstOrDefault(m => m.AbonamentModelID == abonamentID);

            abonamentModel.NrSedinteEfectuate += nr;

            context.Update(abonamentModel);
            context.SaveChanges();
        }
コード例 #6
0
        // Remove Person From Atrenament
        // Remove Person Atrenament Abonament From PersAntrAbTable Table
        // Remove From aboanament 1 sedinta efectuata
        public string RemovePersonFromAntrenament(AntrenamentModel antrenament, int abonamentID, ReportDbContext context)
        {
            PersoanaModel persoana        = GetAbonamentByAbID(abonamentID, context).PersoanaModel;
            var           persAntrAbTable = context.PersAntrAbTables
                                            .Include(t => t.Abonament)
                                            .Include(a => a.Persoana)
                                            .Include(aa => aa.Antrenament)
                                            .FirstOrDefault(m => m.AntrenamentModelID == antrenament.AntrenamentModelID && m.AbonamentModelID == abonamentID);

            if (persAntrAbTable == null)
            {
                return($"Nu s-a gasit persoana cu numele: {persoana.NumeComplet} in antrenament!");
            }
            context.PersAntrAbTables.Remove(persAntrAbTable);
            context.SaveChanges();
            UpdateNrSedinteEfAbonamentbyID(-1, abonamentID, context); // Update nr sedinte efectuate abonament
            return($"Persoana {persoana.NumeComplet} a fost stearsa din antrenament");
        }
コード例 #7
0
        public async Task <IActionResult> ImportFile(List <IFormFile> files)
        {
            // Verificam daca lista de fisiera incarcata  are 0 elemente si returnam msj
            if (files.Count == 0)
            {
                ViewBag.Hidden = "";
                ViewBag.Mesaj  = "Fisierul nu s-a incarcat";
                return(View());
            }

            // Cream fisier din primul lelement din lista de fisiere
            IFormFile formFile = files[0];

            // Verificam daca fisierul are extensia .xlsx
            if (!formFile.FileName.EndsWith(".xlsx"))
            {
                ViewBag.Hidden = "";
                ViewBag.Mesaj  = "Fisierul nu are extensia .xlsx!";
                return(View());
            }

            //Cream lista de blumuri din fisier excel
            List <PlcModel> lista = await _auxiliar.GetBlumsListFromExcelFileBySarjaAsync(formFile);

            // Actualizam baza de date cu lista de blumuri din fisier
            if (lista != null)
            {
                foreach (var item in lista)
                {
                    _context.Add(item);
                    _context.SaveChanges();
                }
            }

            // Redirection la Index
            return(RedirectToAction("Index", "Test", new
            {
                nume = "Nume din import File",
                numar = 1000
            }));
        }
コード例 #8
0
        public bool DayStartAll(string shopId, DateTime date)
        {
            date = date.Date;
            DateTime yesterday = date.AddDays(-1).Date;

            ReportDbContext   rDb = new ReportDbContext();
            BusinessDbContext bDb = new BusinessDbContext();
            List <string>     ids = bDb.AccountHeads.Where(x => x.ShopId == shopId).Select(x => x.Id).ToList();

            foreach (var id in ids)
            {
                this.QuickUpdate(shopId, id, yesterday);
            }

            foreach (string id in ids)
            {
                var todayReport = this.GetReportObject(id, bDb);
                this.SetDefaults(todayReport, shopId, date);

                var yesterdayReport = rDb.AccountReports.Where(x => x.ShopId == shopId && x.AccountHeadId == id)
                                      .FirstOrDefault(x => DbFunctions.TruncateTime(x.Date) == yesterday);
                if (yesterdayReport != null)
                {
                    todayReport.AmountTotalStarting = yesterdayReport.AmountTotalEnding;
                }

                var todayExists = rDb.AccountReports.Any(
                    x => x.ShopId == shopId && x.AccountHeadId == id && DbFunctions.TruncateTime(x.Date) == date);
                if (todayExists)
                {
                    this.QuickUpdate(shopId, id, date);
                }
                else
                {
                    rDb.AccountReports.Add(todayReport);
                    rDb.SaveChanges();
                }
            }

            return(true);
        }
コード例 #9
0
        public bool QuickUpdate(DateTime date, string shopId)
        {
            BusinessDbContext db       = BusinessDbContext.Create();
            ReportDbContext   reportDb = new ReportDbContext();

            date = date.Date;

            var salesToday = db.Sales.Where(x => x.ShopId == shopId && DbFunctions.TruncateTime(x.Created) == date)
                             .ToList();

            var report = reportDb.SaleReports.Where(x => x.ShopId == shopId).FirstOrDefault(x => x.Date == date);

            if (report == null)
            {
                bool b = ShopStart(date, shopId);
            }

            List <SaleReport> allReports        = reportDb.SaleReports.Where(x => x.ShopId == shopId && DbFunctions.TruncateTime(x.Date) == date).ToList();
            SaleReport        reportSaleTypeAll = allReports.First(x => x.SaleType == SaleType.All);

            CalculateAmounts(reportSaleTypeAll, salesToday);
            reportSaleTypeAll.Modified = DateTime.Now;
            reportDb.Entry(reportSaleTypeAll).State = EntityState.Modified;
            SaleReport  reportDealerSale = allReports.First(x => x.SaleType == SaleType.DealerSale);
            List <Sale> dealerSalesToday = salesToday.Where(x => x.IsDealerSale).ToList();

            CalculateAmounts(reportDealerSale, dealerSalesToday);
            reportDealerSale.Modified = DateTime.Now;
            reportDb.Entry(reportDealerSale).State = EntityState.Modified;
            SaleReport  reportCustomerSale = allReports.First(x => x.SaleType == SaleType.CustomerSale);
            List <Sale> customerSalesToday = salesToday.Where(x => x.IsDealerSale == false).ToList();

            CalculateAmounts(reportCustomerSale, customerSalesToday);
            reportCustomerSale.Modified = DateTime.Now;
            reportDb.Entry(reportCustomerSale).State = EntityState.Modified;
            reportDb.SaveChanges();
            return(true);
        }
コード例 #10
0
        public bool ShopStart(DateTime date, string shopId)
        {
            ReportDbContext reportDb = ReportDbContext.Create();

            date = date.Date;

            SaleReport report = reportDb.SaleReports.Where(x => x.ShopId == shopId).FirstOrDefault(x => x.Date == date);

            if (report == null)
            {
                report = new SaleReport {
                    SaleType = SaleType.All
                };
                this.SetDefaults(report, shopId, date);

                var dealerReport = new SaleReport {
                    SaleType = SaleType.DealerSale
                };
                this.SetDefaults(dealerReport, shopId, date);

                var customerReport = new SaleReport {
                    SaleType = SaleType.CustomerSale
                };
                this.SetDefaults(customerReport, shopId, date);

                var collection = new List <SaleReport>()
                {
                    report, dealerReport, customerReport
                };
                reportDb.SaleReports.AddRange(collection);
                int i = reportDb.SaveChanges();
                return(i > 0);
            }

            return(true);
        }
コード例 #11
0
        // Add Person To Atrenament
        // Add Person Atrenament Abonament to PersAntrAbTable Table
        // Add To aboanament 1 sedinta efectuata
        public string AddPersonToAntrenament(AntrenamentModel antrenament, int abonamentID, ReportDbContext context)
        {
            AbonamentModel ab = GetAbonamentByAbID(abonamentID, context);

            if (!context.PersAntrAbTables.Any(item => item.AntrenamentModelID == antrenament.AntrenamentModelID &&
                                              item.AbonamentModelID == abonamentID))
            {
                if (ab.StareAbonament == StareAbonament.Finalizat)
                {
                    return($"Persoana {ab.PersoanaModel.NumeComplet} are abonamentul finalizat!!!");
                }

                context.PersAntrAbTables.Add(new PersAntrAbTable
                {
                    AntrenamentModelID = antrenament.AntrenamentModelID,
                    AbonamentModelID   = abonamentID,
                    PersoanaModelID    = (int)GetAbonamentByAbID(abonamentID, context).PersoanaModelID
                });
                context.SaveChanges();
                UpdateNrSedinteEfAbonamentbyID(1, abonamentID, context); // Update nr sedinte efectuate abonament
                return($"Persoana {ab.PersoanaModel.NumeComplet} a fost adaugata la antrenament!");
            }
            return($"Persoana {ab.PersoanaModel.NumeComplet} este deja adaugata in antrenament");
        }
コード例 #12
0
        public bool DayStartAll(string shopId, DateTime startDate)
        {
            startDate = startDate.Date;
            DateTime yesterday = startDate.AddDays(-1).Date;

            DayEndUpdateAll(shopId, yesterday);

            ReportDbContext   rDb = new ReportDbContext();
            BusinessDbContext bDb = new BusinessDbContext();
            List <string>     ids = bDb.ProductDetails.Where(x => x.ShopId == shopId).Select(x => x.Id).ToList();

            foreach (string pId in ids)
            {
                ProductReport report = GetReportObject(pId, bDb);
                this.SetDefaults(report, shopId, startDate);

                ProductReport yesterdayReport = rDb.ProductReports.Where(x => x.ShopId == shopId && x.ProductDetailId == pId).FirstOrDefault(x => DbFunctions.TruncateTime(x.Date) == yesterday);
                if (yesterdayReport != null)
                {
                    report.QuantityStartingToday = yesterdayReport.QuantityEndingToday;
                }
                var todayExists = rDb.ProductReports.Any(
                    x => x.ShopId == shopId && x.ProductDetailId == pId && DbFunctions.TruncateTime(x.Date) == startDate);
                if (todayExists)
                {
                    this.QuickUpdate(shopId, pId, startDate);
                }
                else
                {
                    rDb.ProductReports.Add(report);
                    rDb.SaveChanges();
                }
            }

            return(true);
        }
コード例 #13
0
        public IActionResult Index(DateTime startDate, string submitBtn, double val1, double val2, double val3, double val4, double val5, double val6, double val7, double val8, double val9, double val10, double val11, double val12, double val13, double val14, double val15, double val16, double val17, double val18, double val19, double val20, double val21, double val22, double val23, double val24)
        {
            // Show Data For previous Day
            if (submitBtn == "Previous")
            {
                startDate = startDate.AddDays(-1);
            }
            else if (submitBtn == "Next") // Show Data For next  Day
            {
                startDate = startDate.AddDays(1);
            }
            ViewBag.start = startDate.ToString("yyyy-MM-dd");
            DailyViewModel dvm = new DailyViewModel
            {
                ListaConsumPerZi = _context.Indexes.Where(elem => elem.DataOra.Year == startDate.Year &&
                                                          elem.DataOra.Month == startDate.Month &&
                                                          elem.DataOra.Day == startDate.Day).ToList(),
                ListaPrognozaPerZi = _context.PrognozaEnergieModels.Where(elem => elem.DataOra.Year == startDate.Year &&
                                                                          elem.DataOra.Month == startDate.Month &&
                                                                          elem.DataOra.Day == startDate.Day).ToList()
            };

            List <AxisLabelData> chartData = new List <AxisLabelData>();

            for (int i = 0; i < dvm.ListaPrognozaPerZi.Count; i++)
            {
                chartData.Add(new AxisLabelData {
                    x = dvm.ListaPrognozaPerZi[i].Ora, y = dvm.ListaPrognozaPerZi[i].Valoare, y1 = dvm.ListaConsumPerZi.Count > 1 ? Math.Round(dvm.ListaConsumPerZi[i].ValueEnergyPlusA / 1000, 1) : 0
                });

                // Update Elements in Database
                if (submitBtn == "Save data")
                {
                    switch (i)
                    {
                    case 0: dvm.ListaPrognozaPerZi[i].Valoare = val1;
                        break;

                    case 1:
                        dvm.ListaPrognozaPerZi[i].Valoare = val2;
                        break;

                    case 2:
                        dvm.ListaPrognozaPerZi[i].Valoare = val3;
                        break;

                    case 3:
                        dvm.ListaPrognozaPerZi[i].Valoare = val4;
                        break;

                    case 4:
                        dvm.ListaPrognozaPerZi[i].Valoare = val5;
                        break;

                    case 5:
                        dvm.ListaPrognozaPerZi[i].Valoare = val6;
                        break;

                    case 6:
                        dvm.ListaPrognozaPerZi[i].Valoare = val7;
                        break;

                    case 7:
                        dvm.ListaPrognozaPerZi[i].Valoare = val8;
                        break;

                    case 8:
                        dvm.ListaPrognozaPerZi[i].Valoare = val9;
                        break;

                    case 9:
                        dvm.ListaPrognozaPerZi[i].Valoare = val10;
                        break;

                    case 10:
                        dvm.ListaPrognozaPerZi[i].Valoare = val11;
                        break;

                    case 11:
                        dvm.ListaPrognozaPerZi[i].Valoare = val12;
                        break;

                    case 12:
                        dvm.ListaPrognozaPerZi[i].Valoare = val13;
                        break;

                    case 13:
                        dvm.ListaPrognozaPerZi[i].Valoare = val14;
                        break;

                    case 14:
                        dvm.ListaPrognozaPerZi[i].Valoare = val15;
                        break;

                    case 15:
                        dvm.ListaPrognozaPerZi[i].Valoare = val16;
                        break;

                    case 16:
                        dvm.ListaPrognozaPerZi[i].Valoare = val17;
                        break;

                    case 17:
                        dvm.ListaPrognozaPerZi[i].Valoare = val18;
                        break;

                    case 18:
                        dvm.ListaPrognozaPerZi[i].Valoare = val19;
                        break;

                    case 19:
                        dvm.ListaPrognozaPerZi[i].Valoare = val20;
                        break;

                    case 20:
                        dvm.ListaPrognozaPerZi[i].Valoare = val21;
                        break;

                    case 21:
                        dvm.ListaPrognozaPerZi[i].Valoare = val22;
                        break;

                    case 22:
                        dvm.ListaPrognozaPerZi[i].Valoare = val23;
                        break;

                    case 23:
                        dvm.ListaPrognozaPerZi[i].Valoare = val24;
                        break;

                    default:
                        break;
                    }
                    _context.PrognozaEnergieModels.Update(dvm.ListaPrognozaPerZi[i]);
                }
            }
            // Save to Database
            _context.SaveChanges();

            // Add ChartData
            dvm.ChartData      = chartData;
            ViewBag.dataSource = chartData;

            // Save to Excel File
            if (submitBtn == "Get File")
            {
                var    filePath  = _reportService.SaveExcelFileToDisk(dvm, _env, startDate).ToString();
                byte[] fileBytes = System.IO.File.ReadAllBytes(filePath);
                return(File(fileBytes, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "Prognoza zilnic.xlsx"));
            }

            // Send Mail With File Per one day Forecast
            if (submitBtn == "Send Mail")
            {
                var       fisierDeTrimis    = _reportService.SaveExcelFileToDisk(dvm, _env, startDate).ToString();
                string    filePathMailModel = Path.Combine(_env.WebRootPath, "Fisiere\\MailDate.JSON");
                MailModel mailModel         = _reportService.GetMailModelAsync(filePathMailModel).Result;
                _emailSender.SendEmailAsync(mailModel.FromAdress, mailModel.ToAddress, mailModel.Subjsect, mailModel.Messaege, fisierDeTrimis);
            }

            return(View(dvm));
        }
コード例 #14
0
        public string QuickUpdate(string shopId, string itemId, DateTime date)
        {
            date = date.Date;
            ReportDbContext   rDb = new ReportDbContext();
            BusinessDbContext bDb = new BusinessDbContext();

            AccountReport report = rDb.AccountReports.FirstOrDefault(
                x => x.ShopId == shopId && x.AccountHeadId == itemId && DbFunctions.TruncateTime(x.Date) == date);

            if (report == null)
            {
                report = this.GetReportObject(itemId, bDb);
                this.SetDefaults(report, shopId, date);
                rDb.AccountReports.Add(report);
                rDb.SaveChanges();
                report = rDb.AccountReports.First(x => x.Id == report.Id);
            }

            var incomeDetails = bDb.Transactions
                                .Where(x => x.ShopId == shopId && DbFunctions.TruncateTime(x.Created) == date).Where(
                x => x.AccountHeadId == itemId && x.TransactionFlowType == TransactionFlowType.Income)
                                .AsQueryable();

            var expenseDetails = bDb.Transactions
                                 .Where(x => x.ShopId == shopId && DbFunctions.TruncateTime(x.Created) == date).Where(
                x => x.AccountHeadId == itemId && x.TransactionFlowType == TransactionFlowType.Expense)
                                 .AsQueryable();

            var incomesToday  = incomeDetails.ToList();
            var expensesToday = expenseDetails.ToList();

            report.AmountTotalIn     = incomesToday.Sum(x => x.Amount);
            report.AmountTotalOut    = expensesToday.Sum(x => x.Amount);
            report.AmountTotalEnding = report.AmountTotalStarting + report.AmountTotalIn - report.AmountTotalOut;
            report.CountTotalTrx     = incomesToday.Count + expensesToday.Count;

            // cash
            var cashIns = incomesToday.Where(x => x.TransactionMedium == TransactionMedium.Cash).ToList();

            report.AmountCashIn = cashIns.Sum(x => x.Amount);

            var cashOuts = expensesToday.Where(x => x.TransactionMedium == TransactionMedium.Cash).ToList();

            report.AmountCashOut = cashOuts.Sum(x => x.Amount);

            report.AmountCashEnding = report.AmountCashStarting + report.AmountCashIn - report.AmountCashOut;
            report.CountCashTrx     = cashIns.Count + cashOuts.Count;

            // bank
            var bankIns = incomesToday.Where(
                x => x.TransactionMedium == TransactionMedium.Bank || x.TransactionMedium == TransactionMedium.Card ||
                x.TransactionMedium
                == TransactionMedium.Cheque)
                          .ToList();

            report.AmountBankIn = bankIns.Sum(x => x.Amount);

            var bankOuts = expensesToday.Where(
                x => x.TransactionMedium == TransactionMedium.Bank || x.TransactionMedium == TransactionMedium.Card ||
                x.TransactionMedium
                == TransactionMedium.Cheque)
                           .ToList();

            report.AmountBankOut = bankOuts.Sum(x => x.Amount);

            report.AmountBankEnding = report.AmountBankStarting + report.AmountBankIn - report.AmountBankOut;
            report.CountBankTrx     = bankIns.Count + bankOuts.Count;

            // mobile
            var mobileIns = incomesToday.Where(x => x.TransactionMedium == TransactionMedium.Mobile).ToList();

            report.AmountMobileIn = mobileIns.Sum(x => x.Amount);

            var mobileOuts = expensesToday.Where(x => x.TransactionMedium == TransactionMedium.Mobile).ToList();

            report.AmountMobileOut = mobileOuts.Sum(x => x.Amount);

            report.AmountMobileEnding = report.AmountMobileStarting + report.AmountMobileIn - report.AmountMobileOut;
            report.CountMobileTrx     = mobileIns.Count + mobileOuts.Count;

            // other
            var otherIns = incomesToday.Where(x => x.TransactionMedium == TransactionMedium.Other).ToList();

            report.AmountOtherIn = otherIns.Sum(x => x.Amount);

            var otherOuts = expensesToday.Where(x => x.TransactionMedium == TransactionMedium.Other).ToList();

            report.AmountOtherOut = otherOuts.Sum(x => x.Amount);

            report.AmountOtherEnding = report.AmountOtherStarting + report.AmountOtherIn - report.AmountOtherOut;
            report.CountOtherTrx     = otherIns.Count + otherOuts.Count;

            report.Modified = DateTime.Now;
            int i = rDb.SaveChanges();

            return(report.Id);
        }
コード例 #15
0
        public bool DayEndUpdate(string shopId, string itemId, DateTime date)
        {
            date = date.Date;
            ReportDbContext   rDb = new ReportDbContext();
            BusinessDbContext bDb = new BusinessDbContext();
            var report            = rDb.ProductReports.FirstOrDefault(
                x => x.ShopId == shopId && x.ProductDetailId == itemId && x.Date == date);

            if (report == null)
            {
                string id = this.QuickUpdate(shopId, itemId, date);
                report = rDb.ProductReports.Find(id);
            }

            var saleDetailsAllProduct = bDb.SaleDetails
                                        .Where(x => x.ShopId == shopId &&
                                               DbFunctions.TruncateTime(x.Modified) == date);

            var purchaseDetailsAllProduct = bDb.PurchaseDetails
                                            .Where(x => x.ShopId == shopId &&
                                                   DbFunctions.TruncateTime(x.Modified) == date);

            var allProductPurchase = purchaseDetailsAllProduct.Select(x => new { x.Quantity, x.CostTotal, x.Paid }).ToList();
            var allProductSale     = saleDetailsAllProduct.Select(
                x => new { x.Quantity, x.Total, x.CostTotal, x.Created, Profit = (x.Total - x.CostTotal) }).ToList();

            if (allProductPurchase.Sum(x => x.Quantity) > 0)
            {
                report.QuantityPurchasePercentInAllProductsToday =
                    report.QuantityPurchaseToday * 100 / allProductPurchase.Sum(x => x.Quantity);
            }

            if (allProductPurchase.Sum(x => x.CostTotal) > 0)
            {
                report.AmountPurchasePercentInAllProductsToday =
                    report.AmountPurchaseToday * 100 / allProductPurchase.Sum(x => x.CostTotal);
            }

            if (allProductSale.Count > 0)
            {
                report.QuantitySalePercentInAllProductsToday =
                    allProductSale.Sum(x => x.Quantity) > 0
                        ? report.QuantitySaleToday * 100 / allProductSale.Sum(x => x.Quantity)
                        : 0;
                report.AmountSalePercentInAllProductsToday =
                    allProductSale.Sum(x => x.Total) > 0
                        ? report.AmountSaleToday * 100 / allProductSale.Sum(x => x.Total)
                        : 0;

                report.AmountProfitPercentInAllProductsToday =
                    allProductSale.Sum(x => x.Profit) > 0 ?
                    report.AmountProfitToday * 100 / allProductSale.Sum(x => x.Profit) : 0;
            }

            var saleDetailsWithSaleByProduct = saleDetailsAllProduct.Include(x => x.Sale).Where(x => x.ProductDetailId == itemId).ToList();
            var dealerSales   = saleDetailsWithSaleByProduct.Where(x => x.Sale.IsDealerSale).ToList();
            var customerSales = saleDetailsWithSaleByProduct.Where(x => x.Sale.IsDealerSale == false).ToList();

            report.QuantitySaleToDealerToday   = dealerSales.Sum(x => x.Quantity);
            report.AmountSaleToDealerToday     = dealerSales.Sum(x => x.Total);
            report.QuantitySaleToCustomerToday = customerSales.Sum(x => x.Quantity);
            report.AmountSaleToCustomerToday   = customerSales.Sum(x => x.Total);

            return(rDb.SaveChanges() > 0);
        }
コード例 #16
0
        public string QuickUpdate(string shopId, string itemId, DateTime date)
        {
            date = date.Date;
            ReportDbContext   rDb = new ReportDbContext();
            BusinessDbContext bDb = new BusinessDbContext();

            ProductReport report = rDb.ProductReports.FirstOrDefault(
                x => x.ShopId == shopId && x.ProductDetailId == itemId && x.Date == date);

            if (report == null)
            {
                report = GetReportObject(itemId, bDb);

                this.SetDefaults(report, shopId, date);
                rDb.ProductReports.Add(report);
                rDb.SaveChanges();
                report = rDb.ProductReports.First(x => x.Id == report.Id);
            }

            var saleDetails =
                bDb.SaleDetails
                .Where(x => x.ShopId == shopId &&
                       DbFunctions.TruncateTime(x.Created) == date)
                .Where(x => x.ProductDetailId == itemId).AsQueryable();
            var purchaseDetails =
                bDb.PurchaseDetails
                .Where(x => x.ShopId == shopId &&
                       DbFunctions.TruncateTime(x.Created) == date)
                .Where(x => x.ProductDetailId == itemId).AsQueryable();

            var saleListToday     = saleDetails.ToList();
            var purchaseListToday = purchaseDetails.ToList();

            // quantities
            report.QuantityPurchaseToday = purchaseListToday.Sum(x => x.Quantity);
            report.QuantitySaleToday     = saleListToday.Sum(x => x.Quantity);
            report.QuantityEndingToday   =
                report.QuantityStartingToday + report.QuantityPurchaseToday - report.QuantitySaleToday;

            // sale amounts
            report.AmountSaleToday        = saleListToday.Sum(x => x.Total);
            report.AmountCostForSaleToday = saleListToday.Sum(x => x.CostTotal);
            report.AmountReceivedToday    = saleListToday.Sum(x => x.PaidAmount);
            report.AmountReceivableToday  = saleListToday.Sum(x => x.DueAmount);
            if (report.QuantitySaleToday > 0)
            {
                report.AmountAverageSalePriceToday = report.AmountSaleToday / report.QuantitySaleToday;
            }

            report.AmountProfitToday = report.AmountSaleToday - report.AmountCostForSaleToday;

            if (report.AmountCostForSaleToday > 0)
            {
                report.AmountProfitPercentToday = report.AmountProfitToday * 100 / report.AmountCostForSaleToday;
            }

            // purchase amounts
            report.AmountPurchaseToday = purchaseListToday.Sum(x => x.CostTotal);
            report.AmountPaidToday     = purchaseListToday.Sum(x => x.Paid);
            report.AmountPayableToday  = purchaseListToday.Sum(x => x.Payable);

            if (report.QuantityPurchaseToday > 0)
            {
                report.AmountAveragePurchasePricePerUnitToday = report.AmountPurchaseToday / report.QuantityPurchaseToday;
            }

            report.Modified = DateTime.Now;
            int i = rDb.SaveChanges();

            return(report.Id);
        }
コード例 #17
0
        public void CreateReport()
        {
            DateTime date = DateTime.Now;

            List <string> measurements = GetMeasurements();

            foreach (var measurement in measurements)
            {
                if (measurement == Measurement.NumberOfMetadataTotal)
                {
                    var result = GetMetadataResult("");

                    foreach (var data in result)
                    {
                        _dbContext.StatisticalData.Add(new Models.Statistics {
                            Date = date, Organization = data.Key, Measurement = measurement, Count = data.Value
                        });
                    }
                }
                else if (measurement == Measurement.NumberOfMetadataForDatasetTotal)
                {
                    var result = GetMetadataResult("dataset");

                    foreach (var data in result)
                    {
                        _dbContext.StatisticalData.Add(new Models.Statistics {
                            Date = date, Organization = data.Key, Measurement = measurement, Count = data.Value
                        });
                    }
                }
                else if (measurement == Measurement.NumberOfMetadataForServicesTotal)
                {
                    var result = GetMetadataResult("service");

                    foreach (var data in result)
                    {
                        _dbContext.StatisticalData.Add(new Models.Statistics {
                            Date = date, Organization = data.Key, Measurement = measurement, Count = data.Value
                        });
                    }
                }
                else if (measurement == Measurement.NumberOfMetadataForApplicationsTotal)
                {
                    var result = GetMetadataResult("software");

                    foreach (var data in result)
                    {
                        _dbContext.StatisticalData.Add(new Models.Statistics {
                            Date = date, Organization = data.Key, Measurement = measurement, Count = data.Value
                        });
                    }
                }
                else if (measurement == Measurement.NumberOfMetadataForServiceLayerTotal)
                {
                    var result = GetMetadataResult("servicelayer");

                    foreach (var data in result)
                    {
                        _dbContext.StatisticalData.Add(new Models.Statistics {
                            Date = date, Organization = data.Key, Measurement = measurement, Count = data.Value
                        });
                    }
                }
                else if (measurement == Measurement.NumberOfProductSpesifications)
                {
                    var result = GetRegisterResult("8e726684-f216-4497-91be-6ab2496a84d3");

                    foreach (var data in result)
                    {
                        _dbContext.StatisticalData.Add(new Models.Statistics {
                            Date = date, Organization = data.Key, Measurement = measurement, Count = data.Value
                        });
                    }
                }
                else if (measurement == Measurement.NumberOfCartographyDocuments)
                {
                    var result = GetRegisterResult("5eacb130-d61f-469d-8454-e96943491ba0");

                    foreach (var data in result)
                    {
                        _dbContext.StatisticalData.Add(new Models.Statistics {
                            Date = date, Organization = data.Key, Measurement = measurement, Count = data.Value
                        });
                    }
                }
                else if (measurement == Measurement.NumberOfProductsheets)
                {
                    var result = GetRegisterResult("a42bc2b3-2314-4b7e-8007-71d9b10f2c04");

                    foreach (var data in result)
                    {
                        _dbContext.StatisticalData.Add(new Models.Statistics {
                            Date = date, Organization = data.Key, Measurement = measurement, Count = data.Value
                        });
                    }
                }
                else if (measurement == Measurement.NumberOfCartographyFiles)
                {
                    var result = GetRegisterCartographyResult();

                    foreach (var data in result)
                    {
                        _dbContext.StatisticalData.Add(new Models.Statistics {
                            Date = date, Organization = data.Key, Measurement = measurement, Count = data.Value
                        });
                    }
                }

                else if (measurement == Measurement.NumberOfSymbols)
                {
                    var result = GetRegisterSymbolResult();

                    foreach (var data in result)
                    {
                        _dbContext.StatisticalData.Add(new Models.Statistics {
                            Date = date, Organization = data.Key, Measurement = measurement, Count = data.Value
                        });
                    }
                }
                else if (measurement == Measurement.NumberOfSymbolPackages)
                {
                    var result = GetRegisterSymbolPackagesResult();

                    foreach (var data in result)
                    {
                        _dbContext.StatisticalData.Add(new Models.Statistics {
                            Date = date, Organization = data.Key, Measurement = measurement, Count = data.Value
                        });
                    }
                }

                else if (measurement == Measurement.NumberOfCodelists)
                {
                    var result = GetCodelists();

                    foreach (var data in result)
                    {
                        _dbContext.StatisticalData.Add(new Models.Statistics {
                            Date = date, Organization = data.Organization, Measurement = data.Measurement, Count = data.Count
                        });
                    }
                }

                _dbContext.SaveChanges();
            }
        }