using RestSharp; using System; using System.Collections.Generic; using Tanshu.Accounts.Contracts; using Tanshu.Accounts.Entities; using Tanshu.Common.Helpers; namespace Tanshu.Accounts.Repository { public class CheckoutBI { public Dictionary amounts = new Dictionary(); public Dictionary info = new Dictionary(); private User _cashier; public IList Cashiers { get; private set; } public DateTime StartDate { get; private set; } public DateTime FinishDate { get; private set; } public string Manager { get { return Session.User.Name; } } public CheckoutBI(DateTime startDate, DateTime finishDate) { StartDate = startDate.Date.AddHours(6); FinishDate = finishDate.Date.AddDays(1).AddHours(5); Cashiers = GetActiveCashiers(); } public User Cashier { get { return _cashier; } set { _cashier = value; GetBillDetails(); } } public string ActiveCashiers { get { var cashiers = ""; foreach (var item in Cashiers) cashiers += item.Name + ", "; return cashiers; } } public void GetBillDetails() { if (FinishDate <= StartDate) return; var request = new RestRequest(); request.Resource = "Checkout/{id}.json"; request.AddParameter("id", Cashier.UserID, ParameterType.UrlSegment); request.AddQueryParameter("s", StartDate.ToString("dd-MMM-yyyy HH:mm")); request.AddQueryParameter("f", FinishDate.ToString("dd-MMM-yyyy HH:mm")); var data = JsonStore.Execute(request); foreach (var item in data) { var setOp = (SettleOption)int.Parse(item.Key); if (!amounts.ContainsKey(setOp)) { amounts.Add(setOp, 0); info.Add(setOp, string.Format("\n\r--- {0} ", setOp.Display()).PadRight(44, '-')); } foreach (var so in item.Value) { string customer = ""; string billID = ""; string date = ""; int amount = 0; foreach (var items in so) { if (items.Key == "Date") date = items.Value; else if (items.Key == "BillID") billID = items.Value; else if (items.Key == "Customer") customer = items.Value; else if (items.Key == "Amount") amount = (int)items.Value; } amounts[setOp] += amount; info[setOp] += string.Format("\n\r{0} {1} {2}", date, billID, customer); info[setOp] += string.Format("\n\rAmount: {0:#0.00}", amount); info[setOp] += "\n\r------------------------------------------"; } } } private List GetActiveCashiers() { var request = new RestRequest(); request.Resource = "Cashiers.json"; request.AddQueryParameter("s", StartDate.ToString("dd-MMM-yyyy HH:mm")); request.AddQueryParameter("f", FinishDate.ToString("dd-MMM-yyyy HH:mm")); return JsonStore.Execute>(request); } } }