private IList <SentEnquiry> AddSentEnquiries(IEnumerable <IGrouping <int?, BStage> > groupedBStages, Dictionary <string, string> consultNames) { IList <SentEnquiry> listSentEnquiries = new List <SentEnquiry>(); foreach (var gp in groupedBStages) { // count nbDaysQuoting // count nbDaysContracting // check the date sent and add an objet sentEnquiry int bhdId = gp.FirstOrDefault().BHD_ID.Value; DateTime dateEntered = gp.OrderBy(bs => bs.FromDate) .First() .FromDate; SentEnquiry se = new SentEnquiry() { BHD_ID = bhdId, Date_Entered = dateEntered }; bool hasQuoted = false; bool hasContracted = false; foreach (BStage bs in gp.OrderBy(bs => bs.FromDate)) { // if quoting if (CompSpec.BookingStageCodes[bookingStage.pendingSalesBDOPS].Contains(bs.Status.Trim())) { // calculate and add the number of days // add the consultant if not already there se.nbDaysQuoting += DatesUtilities.GetNbWorkingDays(bs.FromDate, bs.ToDate); if (!se.dictQuoting.ContainsKey(bs.Consultant.Trim())) { se.dictQuoting.Add(bs.Consultant.Trim(), consultNames[bs.Consultant.Trim()]); } hasQuoted = true; } // if contracting if (CompSpec.BookingStageCodes[bookingStage.pendingContract].Contains(bs.Status.Trim())) { // calculate and add the number of days // add the consultant if not already there se.nbDaysContracting += DatesUtilities.GetNbWorkingDays(bs.FromDate, bs.ToDate); if (!se.dictContracting.ContainsKey(bs.Consultant.Trim())) { se.dictContracting.Add(bs.Consultant.Trim(), consultNames[bs.Consultant.Trim()]); } hasContracted = true; } // if past the "sent" stage (not pending) and was preceded by quoting or contracting stages if (!CompSpec.BookingStageCodes[bookingStage.pending].Contains(bs.Status.Trim())) { bool isOneDayer = bs.FromDate == dateEntered; // create a new SentEnquiry object and add it to the list if (hasQuoted || hasContracted || isOneDayer) { se.FullReference = bs.FullReference; se.Department = CompSpec.RetrieveDepartment(se.FullReference); // add the consultant name if not there : if (!se.dictQuoting.ContainsKey(bs.Consultant.Trim())) { se.dictQuoting.Add(bs.Consultant.Trim(), consultNames[bs.Consultant.Trim()]); } // 12/06/2017 clean dictQuoting and dictContracting of unassigned if there is at least one consultant if (se.dictQuoting.Count >= 2) { se.dictQuoting.Remove(""); } if (se.dictContracting.Count >= 2) { se.dictContracting.Remove(""); } se.DateSent = bs.FromDate; se.nbDaysQuoting++; // the day counts as being quoting listSentEnquiries.Add(se); // reset se = new SentEnquiry() { BHD_ID = bhdId, Date_Entered = dateEntered }; hasQuoted = false; hasContracted = false; } } } } return(listSentEnquiries); }
public PendingEnquiryTableRow GenerateTableRow(BHDmini b) { PendingEnquiryTableRow tr = new PendingEnquiryTableRow(); tr.Full_Reference = b.FULL_REFERENCE.Trim(); tr.Booking_Name = b.NAME.Trim(); tr.Last_Stage = CompSpec.GetCurrentStage(b.STATUS.Trim()); // to get the number of days of the current process: // foreach BStage going backward in time // if same as current stage -> add days // if beyond sent stage or not pending -> exit for // take into account that the last BStage will be recorded until yesterday max int nbDaysCurrentStage = 0; var listBS = compDbRepo.listBStage.Where(bs => MinimiseRef(bs.FullReference.Trim()) == MinimiseRef(b.FULL_REFERENCE.Trim())); foreach (BStage bs in listBS.OrderByDescending(_bs => _bs.FromDate)) { string stage = CompSpec.GetCurrentStage(bs.Status.Trim()); if (stage == tr.Last_Stage) { // add days nbDaysCurrentStage += DatesUtilities.GetNbWorkingDays(bs.FromDate, bs.ToDate); } // if not pending at all -> break for if (!CompSpec.BookingStageCodes[bookingStage.pending].Contains(bs.Status.Trim())) { break; } } nbDaysCurrentStage++; // to include today's working day // establish the number of days before deadline // if response code other than "I" -> difference between deadline and nbDaysCurrentStage // if response code is "I" -> difference between today and the target date string responseCode = b.SALE4.Trim(); if (responseCode == "I") { DateTime deadlineDate; if (b.UDTEXT4.Trim() == "") { deadlineDate = new DateTime(2017, 2, 1); } else { deadlineDate = DateTime.Parse(b.UDTEXT4.Trim(), new System.Globalization.CultureInfo("fr-FR", true)); } tr.Days_Before_Deadline = (int)deadlineDate.Subtract(DateTime.Today).TotalDays; } else { int nbMaxDays = 0; if (CompSpec.dictDeadlines.ContainsKey(responseCode)) { nbMaxDays = tr.Last_Stage == "Quoting" ? CompSpec.dictDeadlines[responseCode].MaxDaysQuoting : CompSpec.dictDeadlines[responseCode].MaxDaysContracting; } tr.Days_Before_Deadline = (nbMaxDays - nbDaysCurrentStage); } //if (tpRepo.DictCsls == null) tpRepo.GetAllConsultants(); tr.Last_Consultant = tpRepo.DictCsls[b.CONSULTANT.Trim()]; tr.BD_Consultant = tpRepo.DictCsls[b.SALE1.Trim()]; return(tr); }