gp_DailyReport_Result IHistoryDAO.DailyReport(String MerchantID, String ClerkID, String WhereFrom, String MerchSeqNum, String TerminalID, DateTime LocalTime) { InitializeConnection(); gp_DailyReport_Result Res = GiftEntity.gp_DailyReport(MerchantID, ClerkID, "A", WhereFrom, MerchSeqNum, TerminalID, LocalTime).FirstOrDefault(); return(Res); }
//**************************************************************** // // R e p o r t s /// <summary> /// Daily Report /// </summary> /// <param name="MerchantID"></param> /// <param name="ClerkID"></param> /// <param name="MerchSeqNum"></param> /// <param name="WhereFrom"></param> /// <returns></returns> DailySalesInformation ITransactionService.DailyReport( String MerchantID, String ClerkID, char WhereFrom, String MerchSeqNum, String TerminalID, DateTime LocalTime) { DailySalesInformation DSI = new DailySalesInformation(); IHistoryDAO IHR = new HistoryDAO(); gp_DailyReport_Result DRR = IHR.DailyReport(MerchantID, ClerkID, Convert.ToString(WhereFrom), MerchSeqNum, TerminalID, LocalTime); IHR.DailyReportToWeb(DRR, DSI, LocalTime); return(DSI); }
public void DailyReportToWeb(gp_DailyReport_Result Res, DailySalesInformation Web, DateTime When) { Web.When = When; Web.ResponseCode = (char)Res.ResponseCode[0]; Web.ErrorCode = (string)Res.ErrorCode; Web.GiftActive = false; if (Res.GiftActive.Length > 0) { if (Res.GiftActive[0] == 'A') { Web.GiftActive = true; } } Web.GiftActivations = 0; if (Res.GiftActivates.HasValue) { Web.GiftActivations = Res.GiftActivates.Value; } Web.GiftActivationAmount = 0.00M; if (Res.GiftActiveTotal.HasValue) { Web.GiftActivationAmount = Res.GiftActiveTotal.Value; } Web.GiftSales = 0; if (Res.GiftSales.HasValue) { Web.GiftSales = Res.GiftSales.Value; } Web.GiftSalesAmount = 0.00M; if (Res.GiftSalesTotal.HasValue) { Web.GiftSalesAmount = Res.GiftSalesTotal.Value; } Web.GiftCredits = 0; if (Res.GiftCredits.HasValue) { Web.GiftCredits = Res.GiftCredits.Value; } Web.GiftCreditAmount = 0.00M; if (Res.GiftCreditTotal.HasValue) { Web.GiftCreditAmount = Res.GiftCreditTotal.Value; } Web.NetGiftAmount = 0; if (Res.NetGiftTotal.HasValue) { Web.NetGiftAmount = Res.NetGiftTotal.Value; } }
// Do the prior day's report again gp_DailyReport_Result IHistoryDAO.PriorDailyReport(String MerchantID, String ClerkID, String WhereFrom, DateTime EndingDate) { char GiftActive = 'N'; char LoyaltyActive = 'N'; int GiftActivations = 0; Decimal GiftActivationsTotal = 0.00M; int GiftSales = 0; Decimal GiftSalesTotal = 0.00M; int GiftCredits = 0; Decimal GiftCreditsTotal = 0.00M; Decimal NetGiftTotal = 0.00M; InitializeConnection(); gp_DailyReport_Result Res = new gp_DailyReport_Result(); Res.ReceiptTime = DateTime.Now; Res.ErrorCode = "APP"; Merchant Merch = GiftEntity.Merchants.FirstOrDefault(d => d.MerchantID == MerchantID); // default to zero and the first transaction from this merchant long StartingID = 0; DateTime StartingTime = (from h in GiftEntity.Histories where h.WhichMerchantGUID == Merch.MerchantGUID orderby h.ID select h.WhenHappened).First(); // although we have an ending date, // that is lacking the seconds and will cause problems. // find the ID of the close in question // Yes, if someone did two closes within a minute, this will give wrong results // but that is not something that happens often DateTime CompareTime = EndingDate.AddMinutes(1); long EndingID = (from h in GiftEntity.Histories where h.WhichMerchantGUID == Merch.MerchantGUID && h.TransType == "CLOS" && h.WhenHappened <= CompareTime orderby h.ID descending select h.ID).First(); var LastRun = (from h in GiftEntity.Histories where h.WhichMerchantGUID == Merch.MerchantGUID && h.TransType == "CLOS" && h.WhenHappened <= CompareTime orderby h.ID descending select new { h.ID, h.WhenHappened } ).Take(2).ToList(); // see if we are to start within a range if (LastRun.Count() == 2) { StartingID = LastRun[1].ID; StartingTime = LastRun[1].WhenHappened; } // get what services are active GiftActive = Merch.GiftActive[0]; // do the summations if (GiftActive == 'A') { GiftActivations = (from h in GiftEntity.Histories where h.WhichMerchantGUID == Merch.MerchantGUID && h.WhenHappened > StartingTime && h.ID < EndingID && h.ErrorCode == "APP " && h.TransType == "ACTV" select h.Amount).Count(); GiftActivationsTotal = (from h in GiftEntity.Histories where h.WhichMerchantGUID == Merch.MerchantGUID && h.WhenHappened > StartingTime && h.ID < EndingID && h.ErrorCode == "APP " && h.TransType == "ACTV" select h).Sum(h => (decimal?)(h.Amount)) ?? 0; GiftSales = (from h in GiftEntity.Histories where h.WhichMerchantGUID == Merch.MerchantGUID && h.WhenHappened > StartingTime && h.ID < EndingID && h.ErrorCode == "APP " && h.TransType == "SALE" select h.Amount).Count(); GiftSalesTotal = (from h in GiftEntity.Histories where h.WhichMerchantGUID == Merch.MerchantGUID && h.WhenHappened > StartingTime && h.ID < EndingID && h.ErrorCode == "APP " && h.TransType == "SALE" select h).Sum(h => (decimal?)(h.Amount)) ?? 0; GiftCredits = (from h in GiftEntity.Histories where h.WhichMerchantGUID == Merch.MerchantGUID && h.WhenHappened > StartingTime && h.ID < EndingID && h.ErrorCode == "APP " && h.TransType == "CRED" select h.Amount).Count(); GiftCreditsTotal = (from h in GiftEntity.Histories where h.WhichMerchantGUID == Merch.MerchantGUID && h.WhenHappened > StartingTime && h.ID < EndingID && h.ErrorCode == "APP " && h.TransType == "CRED" select h).Sum(h => (decimal?)(h.Amount)) ?? 0; NetGiftTotal = GiftActivationsTotal - GiftSalesTotal + GiftCreditsTotal; } int Voids = (from h in GiftEntity.Histories where h.WhichMerchantGUID == Merch.MerchantGUID && h.WhenHappened > StartingTime && h.ID < EndingID && h.ErrorCode == "APP " && h.TransType == "VOID" select h.ID).Count(); Res.GiftActive = GiftActive.ToString(); Res.GiftSales = GiftSales; Res.GiftSalesTotal = GiftSalesTotal; Res.GiftCredits = GiftCredits; Res.GiftCreditTotal = GiftCreditsTotal; Res.GiftActivates = GiftActivations; Res.GiftActiveTotal = GiftActivationsTotal; Res.NetGiftTotal = NetGiftTotal; Res.Voids = Voids; Res.LoyaltyActive = LoyaltyActive.ToString(); Res.ResponseCode = "A"; return(Res); }
// Yes, there was a stored procedure to do the detail report, // but it returns two result sets and the second one can have // a bunch of records in it. DetailHistory IHistoryDAO.DetailReport(String MerchantID, String ClerkID, String WhereFrom, String MerchSeqNum, String TerminalID, DateTime LocalTime) { InitializeConnection(); // need to resolve any merchant sequence number issues DetailHistory Results = new DetailHistory(); Results.DetailItems = new List <CardHistory>(); gp_DailyReport_Result Res = GiftEntity.gp_DailyReport(MerchantID, ClerkID, "E", WhereFrom, MerchSeqNum, TerminalID, LocalTime).FirstOrDefault(); if (Res.ResponseCode == "A") { Results.When = DateTime.Now; Results.ResponseCode = Res.ResponseCode[0]; Results.ErrorCode = (string)Res.ErrorCode; Results.Summary = new DailySalesInformation(); DailyReportToWeb(Res, Results.Summary, LocalTime); // now get the details Merchant Merch = GiftEntity.Merchants.FirstOrDefault(d => d.MerchantID == MerchantID); var LastRun = (from h in GiftEntity.Histories where h.WhichMerchantGUID == Merch.MerchantGUID && h.TransType == "CLOS" orderby h.ID descending select h.ID).FirstOrDefault(); //if (LastRun == null) // LastRun = 0; var DailyHistories = from h in GiftEntity.Histories where h.WhichMerchantGUID == Merch.MerchantGUID && h.ID > LastRun && h.ErrorCode == "APP " && h.TransType != "DYRP" && // keep the daily report out of this h.TransType != "SHIP" // keep the card shipments out of the report orderby h.ID //c.Card2 == WhichCard.ID select new { ID = h.ID, CardGUID = h.CardGUID, TransType = h.TransType, When = h.WhenHappened, LocalTime = h.LocalTime, Amount = h.Amount, PointsGranted = 0, MerchWhere = h.WhichMerchantGUID, Clrk = h.Clerk, Text = h.TransactionText, CardGUID2 = h.CardGUID2, CouponUsed = 0, CouponIssued = 0, PrizeAwardedGUID = Guid.NewGuid(), InvoiceNumber = h.InvoiceNumber }; foreach (var his in DailyHistories) { CardHistory nHistory = new CardHistory(); nHistory.ID = his.ID; nHistory.CardNumber = (from c in GiftEntity.Cards where c.CardGUID == his.CardGUID select c.CardNumLast4).FirstOrDefault().ToString(); nHistory.Amount = his.Amount; nHistory.Clerk = his.Clrk; nHistory.MerchWhere = (from m in GiftEntity.Merchants where m.MerchantGUID == his.MerchWhere select m.MerchantName).FirstOrDefault(); nHistory.TransType = his.TransType; nHistory.Transaction = ConvertTransactionType(his.TransType); nHistory.When = his.When; if (his.LocalTime.HasValue) { nHistory.LocalTime = his.LocalTime.Value; } nHistory.Text = his.Text; nHistory.PointsGranted = his.PointsGranted; if (his.CardGUID2 != null) { nHistory.Card2 = GiftEntity.Cards .FirstOrDefault(c => c.CardGUID == his.CardGUID2).CardNumLast4; } nHistory.InvoiceNumber = his.InvoiceNumber; Results.DetailItems.Add(nHistory); } } else { Results.ResponseCode = Res.ResponseCode[0]; Results.ErrorCode = (string)Res.ErrorCode; } return(Results); }