public void SetDeadline(BHDmini b, CompanySpecifics CompSpec) { string tpCode = b.SALE4.Trim(); if (CompSpec.dictDeadlines.ContainsKey(tpCode)) { maxNbDaysQuoting = CompSpec.dictDeadlines[tpCode].MaxDaysQuoting; maxNbDayContracting = CompSpec.dictDeadlines[tpCode].MaxDaysContracting; } else if (tpCode == "I") { // Several dates placed offer if (b.UDTEXT4.Trim() != "") { DateTime deadlineDate = DateTime.Parse(b.UDTEXT4.Trim(), new System.Globalization.CultureInfo("fr-FR", true)); DateTime dtSent = DateSent; if (dtSent <= deadlineDate) { maxNbDaysQuoting = 9999; maxNbDayContracting = 9999; } else { maxNbDaysQuoting = -1; maxNbDayContracting = -1; } } } }
public StagesDates(IEnumerable <BStage> iBStage, CompanySpecifics cs) { // get the first stage which is beyond sent ( sent , confirmed , cancelled) -> DateSent // get the first stage which is beyond confirmed ( confirmed , cancelled)-> DateConfirmed // get the first stage which is cancelled ( cancelled)-> DateCancelled iBStage = iBStage.OrderBy(bs => bs.FromDate); var firstSent = iBStage.FirstOrDefault(bs => cs.IsSent(bs.Status) || cs.IsConfirmed(bs.Status) || cs.IsCancelled(bs.Status)); if (firstSent != null) { DateSent = firstSent.FromDate; } var firstConf = iBStage.FirstOrDefault(bs => cs.IsConfirmed(bs.Status) || cs.IsCancelled(bs.Status)); if (firstConf != null) { DateConfirmed = firstConf.FromDate; } var firstCanc = iBStage.FirstOrDefault(bs => cs.IsCancelled(bs.Status)); if (firstCanc != null) { DateCancelled = firstCanc.FromDate; } BHD_ID = (iBStage.FirstOrDefault().BHD_ID).Value; DateEntered = iBStage.FirstOrDefault().FromDate; }
public void SetMissingData(CompanySpecifics cs, IEnumerable <string> validSeriesReferences, Func <string, string> MinimiseRef) { if (cs.bookingTypes["Brochure"].Contains(bhdMini.SALE6.Trim())) { // brochure // Missing series reference if (bhdMini.UDTEXT1.Trim() == "") { MissingSeriesReference = true; AtLeastOneMissingItem = true; } // Incorrect series reference if (bhdMini.UDTEXT1.Trim() != "") { //string refPattern = @"^[A-Z]{4}\d{6}$"; //if (!Regex.IsMatch(bhdMini.UDTEXT1.Trim(), refPattern)) //{ // IncorrectSeriesReference = true; // AtLeastOneMissingItem = true; //} if (!validSeriesReferences.Contains(MinimiseRef(bhdMini.UDTEXT1.Trim()))) { IncorrectSeriesReference = true; AtLeastOneMissingItem = true; } } } // Missing Sales Update // 22/06/2017 : missing Sales update is only for bookings which are not pending var pendingStatuses = cs.BookingStageCodes[bookingStage.pending]; var bStatus = bhdMini.STATUS.Trim(); if (bhdMini.UDTEXT5.Trim() == "" && !pendingStatuses.Contains(bStatus)) { // only if it is not FIT department if (cs.RetrieveDepartment(bhdMini.FULL_REFERENCE.Trim()) != "FIT") { MissingSalesUpdate = true; AtLeastOneMissingItem = true; } } // Missing estimated turnover if (!cs.BookingStageCodes[bookingStage.pending].Contains(bhdMini.STATUS.Trim())) { // not pending if (bhdMini.UDTEXT3.Trim() == "") { MissingEstimatedTurnover = true; AtLeastOneMissingItem = true; } } }
public Dictionary <int, StagesDates> RetrieveKeyStagesDates() { // For each booking entered after the 01/05/2017 , return the object { date sent , date confirmed , date cancelled} // extract all the booking stages , for bookings entered after the 01/05/2017 var GroupedBStages = GroupedBStagesEnquiries(); var cs = new CompanySpecifics(); var AllStagesDates = GroupedBStages.Select(gp => new StagesDates(gp, cs)); return(AllStagesDates.ToDictionary(sd => sd.BHD_ID, sd => sd)); }
public Dictionary <string, Dictionary <string, Dictionary <string, List <T> > > > EvalAllDepartments <T>(List <T> AllBookingsFiltered) where T : class, IPerformanceItems <T> { // departments and consultants are on the same levels // the success rate is not calculated directly but should be easily calculated by the client var dictReturned = new Dictionary <string, Dictionary <string, Dictionary <string, List <T> > > >(); CompanySpecifics cs = new CompanySpecifics(); List <string> dptList = cs.DptsList.Keys.ToList(); // foreach department foreach (string dpt in dptList) { Dictionary <string, Dictionary <string, List <T> > > dictAllTheDpt = new Dictionary <string, Dictionary <string, List <T> > >(); // split success failure items for the department selected List <T> itemsDpt = AllBookingsFiltered.Where(t => t.IsDepartment(cs, dpt)).ToList(); Dictionary <string, List <T> > dictSplitItems = new Dictionary <string, List <T> >(); dictSplitItems.Add("Success", itemsDpt.Where(t => t.IsSuccess(cs)).ToList()); dictSplitItems.Add("Unsuccess", itemsDpt.Where(t => !t.IsSuccess(cs)).ToList()); dictAllTheDpt.Add("DepartmentOnly", dictSplitItems); // split success failure items for all the consultants associated with the department selected T firstItem = AllBookingsFiltered.FirstOrDefault(); List <string> listAllCslForSelectedDpt = firstItem.GetAllCslFromListOfItems(itemsDpt); foreach (string csl in listAllCslForSelectedDpt) { // split success failure items for the csl selected List <T> itemsCsl = AllBookingsFiltered.Where(t => t.IsCsl(csl)).ToList(); Dictionary <string, List <T> > dictCslSplitItems = new Dictionary <string, List <T> >(); dictCslSplitItems.Add("Success", itemsCsl.Where(t => t.IsSuccess(cs)).ToList()); dictCslSplitItems.Add("Unsuccess", itemsCsl.Where(t => !t.IsSuccess(cs)).ToList()); dictAllTheDpt.Add(csl, dictCslSplitItems); } // order by total success+unsuccess except for missing data if (typeof(T) == typeof(BHDmissingData)) { dictAllTheDpt = dictAllTheDpt.OrderByDescending(kvp => kvp.Value["Unsuccess"].Count()).ToDictionary(kvp => kvp.Key, kvp => kvp.Value); } else { dictAllTheDpt = dictAllTheDpt.OrderByDescending(kvp => kvp.Value["Success"].Count() + kvp.Value["Unsuccess"].Count()).ToDictionary(kvp => kvp.Key, kvp => kvp.Value); } dictReturned.Add(dpt, dictAllTheDpt); } return(dictReturned); }
public virtual List <BHDmini> ExtractQuotingContractingEnquiries(CompanySpecifics cs) { // get all the enquiries which are currently under quoting or contracting Dictionary <string, string> Sa1ToCsl = GenerateUniqueCslList(); var filterStatuses = cs.BookingStageCodes[bookingStage.pendingContract] .Concat(cs.BookingStageCodes[bookingStage.pendingSalesBDOPS]); return(tpContext3.BHDs .Where(_bhd => filterStatuses.Contains(_bhd.STATUS.Trim())) .ToList() .Select(_bhd => new BHDmini(_bhd, Sa1ToCsl)) .ToList()); }
private void GenerateBookingStageItems() { var cs = new CompanySpecifics(); bookingStageItems = cs.LoadBookingStageItems(); // exceptionally for this service the bedbanks are added because they contain a valid cost/room_nights bookingStageItems = bookingStageItems.Select(bsi => { if (bsi.Name == "All" || bsi.Name == "Unconfirmed") { bsi.Statuses.AddRange(cs.BookingStageCodes[bookingStage.Bedbank]); } return(bsi); }).ToList(); }
public Performance(ICompanyDBRepository _compDbRepo, IThirdpartyDBrepository _tpRepo) { CompSpec = new CompanySpecifics(); compDbRepo = _compDbRepo; tpRepo = _tpRepo; }
public virtual async Task <List <SuppliersAnalysisData> > InitialLoadingSuppliersAnalysisAsync(int currentFY, List <string> validStatuses) { // get list of master suppliers for later var taskSuppliersChains = GetSuppliersChainsAsync(); // get locations var locTask = GetLOCAsync(); // get bd consultant var bdCslTask = GetSA1Async(); // service types var srvTask = GetServiceTypesAsync(); var cs = new CompanySpecifics(); // for previous and current financial year //var currentFY = DatesUtilities.GetCurrentFinancialYear(); DateTime beginDt = new DateTime(currentFY - 1, 2, 1); DateTime endDt = new DateTime(currentFY + 2, 1, 31); //var validStatuses = cs.BookingStageCodes[bookingStage.received]; var excludedSL = cs.ServiceLinesCodes[ServiceLineType.Unconfirmed]; // get BSL joined with BSD var sadList = await GetServicesAndCostsForSAD(beginDt, endDt, validStatuses, excludedSL); // async calls following // get OPT joined with CRM var listOpt = sadList.Select(sad => sad.OPT_ID).Distinct(); Task <List <SuppliersAnalysisData> > taskOpt = GetSuppliersFromOptsAsync(listOpt); // await all the tasks and finish filling sadList sadList = sadList.Join(await taskOpt, sad1 => sad1.OPT_ID, sad2 => sad2.OPT_ID, (sad1, sad2) => { sad1.SUPPLIER_CODE = sad2.SUPPLIER_CODE; sad1.SUPPLIER_NAME = sad2.SUPPLIER_NAME; sad1.CHAIN_CODE = sad2.CHAIN_CODE; sad1.Service_Type_Name = sad2.Service_Type_Name; return(sad1); }) .ToList(); var dictSuppliersChains = await taskSuppliersChains; var locs = await locTask; var bdCsl = await bdCslTask; var srv = await srvTask; sadList = sadList.Select(sad => { if (sad.CHAIN_CODE.Trim() == "") { sad.CHAIN_NAME = "No chain"; } else { sad.CHAIN_NAME = dictSuppliersChains.FirstOrDefault(kvp => kvp.Key == sad.CHAIN_CODE).Value; // sometimes the chain is not defined as a chain (master_supplier =="N") if (sad.CHAIN_NAME == null) { sad.CHAIN_NAME = sadList.FirstOrDefault(sad2 => sad2.SUPPLIER_CODE == sad.CHAIN_CODE).SUPPLIER_NAME; } } sad.LOCATION_NAME = locs.FirstOrDefault(l => l.CODE == sad.LOCATION_CODE).NAME; sad.BDConsultant_NAME = bdCsl.FirstOrDefault(b => b.CODE == sad.BDConsultant_CODE).DESCRIPTION; sad.Service_Type_Name = srv.FirstOrDefault(s => s.CODE == sad.Service_Type_Code).NAME; sad.DEPARTMENT = cs.RetrieveDepartment(sad.FULL_REFERENCE); // room-night calculation to disregard anything non accommodation sad.Rooms_Nights = sad.Service_Type_Name.Contains("Accommodation") ? sad.ROOMCOUNT * sad.SCU_QTY : 0; return(sad); }) .ToList(); return(sadList); }
public virtual async Task <IEnumerable <ContractTBAsInfo> > ExtractTBAsListAsync() { var selectedCRMs = tpContext3.CRMs.Where(c => c.NAME.Contains("advised")); var validCRMs = selectedCRMs.Select(c => c.CRM_ID); var selectedOPTs = tpContext3.OPTs.Where(o => o.AC == "Y"); var validOPTs = selectedOPTs.Select(o => o.OPT_ID); var selectedLOCs = tpContext3.LOCs; var cs = new CompanySpecifics(); var validStatus = cs.BookingStageCodes[bookingStage.confirmed]; DateTime beginDt = new DateTime(2016, 2, 1); // to remove past irrelevant service lines var filteredBSLs = tpContext3.BSLs //.Include(_bsl => _bsl.BHD) .Where(_bsl => _bsl.SL_STATUS.Trim() == "TB") .Where(_bsl => validStatus.Contains(_bsl.BHD.STATUS.Trim())) .Where(_bsl => validCRMs.Contains(_bsl.CRM_ID)) .Where(_bsl => validOPTs.Contains(_bsl.OPT_ID)) .Where(_bsl => _bsl.DATE > beginDt); if (!filteredBSLs.Any()) { return(null); } var selectedBSLs = filteredBSLs.Select(_bsl => _bsl.BSL_ID).ToList(); var dictBSLs = tpContext3.BSLs.Where(sl => selectedBSLs.Contains(sl.BSL_ID)) .ToDictionary(sl => sl.BSL_ID, sl => sl); var dictCRMs = selectedCRMs.ToDictionary(c => c.CRM_ID, c => c); var listOptsId = dictBSLs.Select(kvp => kvp.Value.OPT_ID).Distinct(); var dictOPTs = selectedOPTs.Where(o => listOptsId.Contains(o.OPT_ID)) .ToDictionary(o => o.OPT_ID, o => o); var listLocs = dictOPTs.Select(kvp => kvp.Value.LOCATION).Distinct(); var dictLOCs = selectedLOCs.Where(l => listLocs.Contains(l.CODE)) .ToDictionary(l => l.CODE, l => l); IEnumerable <ContractTBAsInfo> itemsVM = selectedBSLs.Select(_bslId => { var vm = new ContractTBAsInfo(); vm.BSL_ID = _bslId; var bsl = dictBSLs[_bslId]; vm.Booking_Name = bsl.BHD.NAME; vm.FULL_REFERENCE = bsl.BHD.FULL_REFERENCE; vm.Service_Date = bsl.DATE.ToString("dd MMM yyyy"); vm.Supplier_Name = dictCRMs[bsl.CRM_ID].NAME; var opt = dictOPTs[bsl.OPT_ID]; vm.LocCode = opt.LOCATION; vm.Option_Name = opt.DESCRIPTION; vm.Location_Name = dictLOCs[opt.LOCATION].NAME; return(vm); }) .ToList(); return(itemsVM); }
public IEnumerable <BkgAnalysisInfo> TransformAllBookings(DateTime BeginningFY15, List <PendingEnquiryTableRow> deadlineTable, Dictionary <int, StagesDates> keyStagesDates) { // used for the Bookings Overview analysis CompanySpecifics compSpec = new CompanySpecifics(); IEnumerable <BHD> BkgsSelected = tpContext3.BHDs .Where(b => b.DATE_ENTERED >= BeginningFY15) .ToList() .Where(b => compSpec.BookingStageCodes[bookingStage.received].Contains(b.STATUS.Trim())); // Extraction of DRM , SA3 , DA6 , SA1 , CSL and using them as dictionaries var _DRM = tpContext3.DRMs.ToDictionary(d => d.CODE, d => new { d.NAME, d.ANALYSIS_MASTER6, d.AGENCYCHAIN }); Dictionary <string, string> _SA3 = tpContext3.SA3.ToDictionary(c => c.CODE, c => c.DESCRIPTION); Dictionary <string, string> _DA6 = tpContext3.DA6.ToDictionary(d => d.CODE, d => d.DESCRIPTION); // creation of a dictionary for the pending areas Dictionary <string, string> _PendingAreas = compSpec.BookingStageCodes[bookingStage.received] .ToDictionary(s => s, s => compSpec.pendingOffersPlaces.FirstOrDefault(kvp => kvp.Value.Contains(s)).Key ?? ""); // calculate the pending bookings past deadline Func <BHD, Boolean> PastDeadline = b => { var TableRow = deadlineTable.FirstOrDefault(tr => tr.Full_Reference == b.FULL_REFERENCE.Trim()); return(TableRow == null ? false : TableRow.Days_Before_Deadline < 0); }; if (DictCsls == null || DictSA1 == null) { GetAllConsultants(); } Func <BHD, BkgAnalysisInfo> ProjectOnBkgMinInfo = b => { BkgAnalysisInfo bk = new BkgAnalysisInfo(); bk.AgentName = _DRM[b.AGENT].NAME.Trim(); bk.AgentChain = _DRM[b.AGENT].AGENCYCHAIN.Trim(); bk.BDConsultant = DictSA1[b.SALE1.Trim()].Trim(); bk.BkgType = b.SALE6.Trim(); bk.BookingStatus = b.STATUS.Trim(); bk.ClientCategory = _DA6[_DRM[b.AGENT].ANALYSIS_MASTER6].Trim(); bk.Consultant = DictCsls[b.CONSULTANT.Trim()].Trim(); // agreed with JM on the 8/12/2016 that if no date confirmed , date entered should be default bk.DateConfirmed = keyStagesDates.ContainsKey(b.BHD_ID) ? keyStagesDates[b.BHD_ID].GetLastStageDate() : b.DATE_ENTERED; bk.DateEntered = b.DATE_ENTERED; bk.DEPARTMENT = b.DEPARTMENT.Trim(); bk.EstimatedTurnover = b.UDTEXT3.Trim(); bk.Full_Reference = b.FULL_REFERENCE.Trim(); bk.LocationName = _SA3[b.SALE3].Trim(); bk.CompanyDepartment = compSpec.RetrieveDepartment(b.FULL_REFERENCE); bk.PendingArea = _PendingAreas[b.STATUS.Trim()]; bk.PastDeadline = PastDeadline(b); //bk.TravelDate = b.UDTEXT4.Trim(); bk.TravelDate = b.TRAVELDATE; return(bk); }; // projection with use of dictionary : return(BkgsSelected.Select(b => ProjectOnBkgMinInfo(b)).ToList()); }