public async Task <IActionResult> Sells(int Page = 1) { var se = await _context.CustomerOrderDetails.AsNoTracking() .Include(s => s.CustomerOrderedTable). ThenInclude(s => s.Customers). Include(s => s.FoodItem).Where(s => s.PaymentStatus == true).ToListAsync(); var sent = new List <TempSell>(); foreach (var item in se.OrderByDescending(aa => aa.CustomerOrderDetailsId)) { var a = new TempSell() { Date = item.CustomerOrderedTable.Date, Total = item.FoodItem.Price * item.Quantity, FoodName = item.FoodItem.FoodName, Quantity = item.Quantity, FoodPrice = item.FoodItem.Price, CustomerName = item.CustomerOrderedTable.Customers.CustomersName }; sent.Add(a); } var list = sent.ToPagedList(Page, 5); return(View(list)); }
public async Task <IActionResult> Index() { var SellSRecord = from sells in await _context.CustomerOrderDetails.AsNoTracking() .Include(s => s.CustomerOrderedTable).Include(s => s.FoodItem) .Where(s => s.PaymentStatus == true). Where(a => a.CustomerOrderedTable.Date.Month == DateTime.Now.Month) .ToListAsync() group sells by sells.CustomerOrderedTable.Date.Day into p let temp = ( from val in p select new { Total = p.Sum(s => s.Quantity * s.FoodItem.Price), Day = p.Key } ) select temp; List <float> TotalSells = new List <float>(); List <string> Day = new List <string>(); var s = new List <TempSell>(); foreach (var item in SellSRecord) { foreach (var t in item) { var p = new TempSell() { Day = t.Day, Total = t.Total }; s.Add(p); break; } } var data = s.OrderBy(s => s.Day); for (int i = 0; i < 31; i++) { TotalSells.Add(0); } foreach (var item in data) { var index = item.Day - 1; var total = item.Total; TotalSells[index] = total; } ViewBag.TotalFoodSells = TotalSells; return(View()); }
public async Task <IActionResult> TotalSells(int Page = 1) { var SellSRecord = from sells in await _context.CustomerOrderDetails.AsNoTracking() .Include(s => s.CustomerOrderedTable).Include(s => s.FoodItem) .Where(s => s.PaymentStatus == true) .ToListAsync() group sells by sells.CustomerOrderedTable.Date.Day into ps let temp = ( from val in ps select new { Total = ps.Sum(s => s.Quantity * s.FoodItem.Price), Day = ps.Key, Quantity = ps.Sum(s => s.Quantity), Data = val.CustomerOrderedTable.Date } ) select temp; var s = new List <TempSell>(); foreach (var item in SellSRecord) { foreach (var t in item) { var pa = new TempSell() { Day = t.Day, Total = t.Total, Quantity = t.Quantity, Date = t.Data }; s.Add(pa); break; } } var p = s.OrderByDescending(s => s.Date); var list1 = p.ToPagedList(Page, 5); return(View(list1)); }
private void button2_Click(object sender, EventArgs e) { try { DBManager manager = new DBManager(); SqlConnection connection = manager.Connection(); String query = "select * from Temp_Sell_Counter"; SqlCommand command = new SqlCommand(query, connection); connection.Open(); List <TempSell> tempSells = new List <TempSell>(); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { int id = Convert.ToInt16(reader[0]); string bookname = reader[1].ToString(); string writer = reader[2].ToString(); string edition = reader[3].ToString(); string type = reader[4].ToString(); string print = reader[5].ToString(); int quantity = Convert.ToInt16(reader[6]); double unitpirce = Convert.ToDouble(reader[7]); double total = Convert.ToDouble(reader[8]); double pay = Convert.ToDouble(reader[9]); double due = Convert.ToDouble(reader[10]); int memoNumber = Convert.ToInt16(reader[11]); TempSell aSell = new TempSell(); aSell.Id = id; aSell.BookName = bookname; aSell.WriterName = writer; aSell.Edition = edition; aSell.Type = type; aSell.Print = print; aSell.Quantity = quantity; aSell.Unitprice = unitpirce; aSell.Total = total; aSell.Pay = pay; aSell.Due = due; aSell.Memonumber = memoNumber; tempSells.Add(aSell); } connection.Close(); SellReprotUI sellReprot = new SellReprotUI(tempSells); sellReprot.ShowDialog(); System.Windows.Forms.DialogResult dialog = MessageBox.Show("Did you print the document?", "Print Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question); SqlCommand command1; String deletequery = "delete from Temp_Sell_Counter"; if (dialog == DialogResult.Yes) { command1 = new SqlCommand(deletequery, connection); connection.Open(); command1.ExecuteNonQuery(); string que = "DBCC CHECKIDENT (Temp_Sell_Counter,Reseed,0)"; command1 = new SqlCommand(que, connection); command1.ExecuteNonQuery(); string que1 = "set identity_insert Temp_Sell_Counter on"; command1 = new SqlCommand(que1, connection); command1.ExecuteNonQuery(); string insQuery = "insert into Memo_Counter values(@date)"; command1 = new SqlCommand(insQuery, connection); command1.Parameters.Clear(); command1.Parameters.AddWithValue("@date", DateTime.Now.Date); command1.ExecuteNonQuery(); memoNumver = GetLastMemoNumber(); } else if (dialog == DialogResult.No) { System.Windows.Forms.DialogResult dialog1 = MessageBox.Show("Are you want to print now?", "Print Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dialog1 == DialogResult.Yes) { sellReprot = new SellReprotUI(tempSells); sellReprot.ShowDialog(); connection.Open(); command1 = new SqlCommand(deletequery, connection); command1.ExecuteNonQuery(); string que = "DBCC CHECKIDENT (Temp_Sell_Counter,Reseed,0)"; command1 = new SqlCommand(que, connection); command1.ExecuteNonQuery(); string que1 = "set identity_insert Temp_Sell_Counter on"; command1 = new SqlCommand(que1, connection); command1.ExecuteNonQuery(); string insQuery = "insert into Memo_Counter values(@date)"; command1 = new SqlCommand(insQuery, connection); command1.Parameters.Clear(); command1.Parameters.AddWithValue("@date", DateTime.Now.Date); command1.ExecuteNonQuery(); memoNumver = GetLastMemoNumber(); DialogResult d2 = MessageBox.Show(" Print Sucessful! Are you want ot exit? ", "Print Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (d2 == DialogResult.Yes) { this.Close(); } else if (d2 == DialogResult.No) { } } else if (dialog1 == DialogResult.No) { this.Close(); } } } catch (Exception exception) { MessageBox.Show(exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }