/// <summary> /// Creates a Dispute using the specified TDN and Docket number if it does not already exists /// </summary> /// <param name="writer"></param> /// <param name="message"></param> /// <param name="count"></param> private static void CreateDispute(StreamWriter writer, MimeMessage message, int count) { try { // Skip if this dispute has already been read/processed if (message.Date.Date <= ConfigSettings.SystemRules.LastDisputeMonitorRun?.Date) { return; } // Skip if this email is not a dispute if (!message.Subject.ToLower().Contains("chep transaction in dispute")) { return; } string text = message.TextBody ?? message.HtmlBody; if (string.IsNullOrWhiteSpace(text)) { Info(writer, $" x EMPTY Email Body FOUND for email #{count}! SKIPPING MessageId {message.MessageId} @{DateTime.Now}"); return; } if (!text.ToLower().Contains("tdn number:") || !text.ToLower().Contains("docket number:")) { Info(writer, $" x Email Body for email #{count} does not contain TDN or DOCKET number! SKIPPING MessageId {message.MessageId} @{DateTime.Now}"); return; } List <string> lines = text.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries) .Where(l => l.ToLower().Contains("tdn number:") || l.ToLower().Contains("docket number:") || l.ToLower().Contains("sender:") || l.ToLower().Contains("receiver:") || l.ToLower().Contains("declarer:") || l.ToLower().Contains("effect date:") || l.ToLower().Contains("product:") || l.ToLower().Contains("quantity:") || l.ToLower().Contains("actioned by:") || l.ToLower().Contains("status changed from") ) .ToList(); if (!lines.NullableAny()) { Info(writer, $" x Email Body for email #{count} does not contain ALL required information! SKIPPING MessageId {message.MessageId} @{DateTime.Now}"); return; } using (UserService uservice = new UserService()) using (DisputeService dservice = new DisputeService()) using (ChepLoadService clservice = new ChepLoadService()) { string docketNumber = lines.FirstOrDefault(l => l.Contains("docket number:")).Split(':')[1].Trim(); // Try and locate a ChepLoad using the email's DocketNumber ChepLoad cl = clservice.GetByDocketNumber(docketNumber); Dispute dispute = dservice.GetByDocketNumber(docketNumber); if (dispute != null) { Info(writer, $" x Dispute email #{count} with Docket Number {docketNumber} ALREADY EXISTS on the system! SKIPPING MessageId {message.MessageId} @{DateTime.Now}"); return; } string[] disputeReason = lines.FirstOrDefault(l => l.Contains("status changed from")).Split(':'); int.TryParse(lines.FirstOrDefault(l => l.Contains("quantity:")).Split(':')[1].Trim(), out int quantity); string actionBy = lines.FirstOrDefault(l => l.Contains("actioned by:")).Split(':')[1].Trim(); User user = uservice.GetByNameAndSurname(actionBy.Split(' ')[0].Trim(), actionBy.Split(' ')[1].Trim()); dispute = new Dispute() { Imported = true, ChepLoadId = cl?.Id, Quantity = quantity, ActionBy = actionBy, ActionedById = user?.Id, Status = ( int )Status.Active, DisputeEmail = string.Join(";", message.From), //DisputeReason = disputeReason[ disputeReason.Length - 1 ], Sender = lines.FirstOrDefault(l => l.Contains("sender:")).Split(':')[1].Trim(), Product = lines.FirstOrDefault(l => l.Contains("product:")).Split(':')[1].Trim(), Declarer = lines.FirstOrDefault(l => l.Contains("declarer:")).Split(':')[1].Trim(), Receiver = lines.FirstOrDefault(l => l.Contains("receiver:")).Split(':')[1].Trim(), Equipment = lines.FirstOrDefault(l => l.Contains("product:")).Split(':')[1].Trim(), TDNNumber = lines.FirstOrDefault(l => l.Contains("tdn number:")).Split(':')[1].Trim(), Reference = lines.FirstOrDefault(l => l.Contains("docket number:")).Split(':')[1].Trim(), DocketNumber = lines.FirstOrDefault(l => l.Contains("docket number:")).Split(':')[1].Trim(), }; dispute = dservice.Create(dispute); Info(writer, $" - SUCCESSFULLY CREATED Dispute for Docket Number {docketNumber} ({dispute.Id}) @{DateTime.Now}"); } } catch (Exception ex) { Error(writer, ex, "CreateDispute"); } }
// // POST || GET: /DashBoard/AgeOfOutstandingPallets public ActionResult AgeOfOutstandingPallets(CustomSearchModel csm, bool givedata = false) { using (ChepLoadService service = new ChepLoadService()) { csm.BalanceStatus = BalanceStatus.NotBalanced; if (givedata) { List <ChepLoadCustomModel> loads = service.List1(new PagingModel() { Take = int.MaxValue }, csm); return(PartialView("_AgeOfOutstandingPalletsData", loads)); } List <AgeOfOutstandingPallets> reps = new List <AgeOfOutstandingPallets>(); // 0-30 Days csm.FromDate = DateTime.Now.AddDays(-30).Date; csm.ToDate = DateTime.Now.Date; AgeOfOutstandingPallets rep = service.AgeOfOutstandingPallets(csm); rep.DurationNumber = 30; rep.DurationName = "0-30 Days"; reps.Add(rep); // 31-60 Days csm.FromDate = DateTime.Now.AddDays(-60).Date; csm.ToDate = DateTime.Now.AddDays(-31).Date; rep = service.AgeOfOutstandingPallets(csm); rep.DurationNumber = 60; rep.DurationName = "31-60 Days"; reps.Add(rep); // 61-90 Days csm.FromDate = DateTime.Now.AddDays(-90).Date; csm.ToDate = DateTime.Now.AddDays(-61).Date; rep = service.AgeOfOutstandingPallets(csm); rep.DurationNumber = 90; rep.DurationName = "61-90 Days"; reps.Add(rep); // 91-120 Days csm.FromDate = DateTime.Now.AddDays(-120).Date; csm.ToDate = DateTime.Now.AddDays(-91).Date; rep = service.AgeOfOutstandingPallets(csm); rep.DurationNumber = 120; rep.DurationName = "91-120 Days"; reps.Add(rep); // 121-183 Days csm.FromDate = DateTime.Now.AddDays(-183).Date; csm.ToDate = DateTime.Now.AddDays(-121).Date; rep = service.AgeOfOutstandingPallets(csm); rep.DurationNumber = 183; rep.DurationName = "121-183 Days"; reps.Add(rep); // 184-270 Days csm.FromDate = DateTime.Now.AddDays(-270).Date; csm.ToDate = DateTime.Now.AddDays(-184).Date; rep = service.AgeOfOutstandingPallets(csm); rep.DurationNumber = 270; rep.DurationName = "184-270 Days"; reps.Add(rep); // 271-365 Days csm.FromDate = DateTime.Now.AddDays(-365).Date; csm.ToDate = DateTime.Now.AddDays(-271).Date; rep = service.AgeOfOutstandingPallets(csm); rep.DurationNumber = 365; rep.DurationName = "271-365 Days"; reps.Add(rep); // By Years? Get MIN YEAR DateTime minYear = service.MinDateTime("ShipmentDate") ?? DateTime.Now; if (minYear.Year == DateTime.Now.Year) { reps = reps.OrderBy(o => o.DurationNumber).ToList(); return(PartialView("_AgeOfOutstandingPallets", reps)); } // -1 Year int minus1Year = DateTime.Now.AddYears(-1).Year; csm.FromDate = new DateTime(DateTime.Now.AddYears(-1).Year, 1, 1); csm.ToDate = DateTime.Now.AddDays(-366).Date; rep = service.AgeOfOutstandingPallets(csm); rep.DurationNumber = minus1Year; rep.DurationName = minus1Year.ToString(); reps.Add(rep); if (minus1Year == minYear.Year) { reps = reps.OrderBy(o => o.DurationNumber).ToList(); return(PartialView("_AgeOfOutstandingPallets", reps)); } for (int i = (minus1Year - 1); i >= minYear.Year; i--) { csm.FromDate = new DateTime(i, 1, 1); csm.ToDate = new DateTime(i, 12, 31); rep = service.AgeOfOutstandingPallets(csm); rep.DurationNumber = i; rep.DurationName = i.ToString(); reps.Add(rep); } reps = reps.OrderBy(o => o.DurationNumber).ToList(); return(PartialView("_AgeOfOutstandingPallets", reps)); } }