protected bool AddLastOrder(bool pSetDates) { //string _LastOrderSQL, _sFrom, _sWhere; //string _sCustID; bool _LastOrder = (Session[CONST_LINESADDED] != null) ? (bool)Session[CONST_LINESADDED] : false; if (ddlContacts.SelectedValue != null) { SetUpdateBools(); // retrieve the last order items from the database. long _CustID = Convert.ToInt64(ddlContacts.SelectedValue); // if they want us to set the delivery and roast dates if (pSetDates) { SetPrepAndDeliveryValues(_CustID); } ItemUsageTbl _ItemUsage = new ItemUsageTbl(); List <ItemUsageTbl> _LastItemsOrdered = _ItemUsage.GetLastItemsUsed(_CustID, TrackerTools.CONST_SERVTYPECOFFEE); if (_LastItemsOrdered.Count > 0) { foreach (ItemUsageTbl _LastItemOrder in _LastItemsOrdered) { if (_LastItemOrder.ItemProvidedID > 0) // now a a order line { _LastOrder = (AddNewOrderLine(_LastItemOrder.ItemProvidedID, _LastItemOrder.AmountProvided, _LastItemOrder.PackagingID) || (_LastOrder)); if (!string.IsNullOrEmpty(_LastItemOrder.Notes)) { tbxNotes.Text += String.Format("{0}last order used a group item, so next item in group selected.", (tbxNotes.Text.Length > 0) ? "; " : ""); } } } } else { TrackerTools _TT = new TrackerTools(); TrackerTools.ContactPreferedItems _ContactPreferedItems = _TT.RetrieveCustomerPrefs(_CustID); _LastOrder = (AddNewOrderLine(_ContactPreferedItems.PreferedItem, _ContactPreferedItems.PreferedQty, _ContactPreferedItems.PrefPackagingID) || (_LastOrder)); } Session[CONST_LINESADDED] = _LastOrder; } return(_LastOrder); }
ContactsUpdated CheckNoneCoffeeCustomer(ContactType pCustomer, ContactsUpdated pContact) { // customer is a none coffee customer check if this is correct ClientUsageLinesTbl _LatestUsageData = new ClientUsageLinesTbl(); ItemUsageTbl _LatestItemData = new ItemUsageTbl(); // the client is set to not have coffee tracked but has taken coffee check if they have taken anything else List <ItemUsageTbl> _LatestCoffeeItems = _LatestItemData.GetLastItemsUsed(pCustomer.CustomerID, TrackerTools.CONST_SERVTYPECOFFEE); _LatestItemData = _LatestItemData.GetLastMaintenanceItem(pCustomer.CustomerID); if (_LatestCoffeeItems.Count > 0) { // they ordered coffee from us but are marked as a none coffee client DateTime _InstallDate = _LatestUsageData.GetCustomerInstallDate(pCustomer.CustomerID); if (_LatestUsageData.LineDate >= _InstallDate) { // there is only coffee for the installation date if (_LatestItemData == null) { pContact.ContactTypeID = CustomerTypeTbl.CONST_INFO_ONLY; // they have no coffee or maint items so they are info only } } else { // they have take coffee past the install date if (_LatestItemData == null) { pContact.ContactTypeID = CustomerTypeTbl.CONST_COFFEE_ONLY; // they have no maint items so they are coffee only } } // else they should be set correctly } else { if (_LatestItemData == null) { pContact.ContactTypeID = CustomerTypeTbl.CONST_INFO_ONLY; // they have no coffee or main items so they are info only } } _LatestCoffeeItems.Clear(); return(pContact); }
private void AddAllContactsToRemind(ref List <ContactToRemindWithItems> pContactsToRemind) //, ref List<string> strs, ref List<DateTime> dts) { // strs.Add("add all the rest of the clients"); // dts.Add(DateTime.Now); /* now add all the rest of the clients * /// 3. Then for all the other clies not in the temp table, and have not received reminders today (see below) * /// and whose nextrequireddate for each serviceitem is < NextCityDeliveryDate add to temp table * /// check if item type is the same and also */ ContactsThatMayNeedNextWeek _ContactsThatMayNeedNextWeek = new control.ContactsThatMayNeedNextWeek(); // strs.Add("GetContactsThatMayNeedNextWeek"); // dts.Add(DateTime.Now); List <ContactsThayMayNeedData> _ContactsThayMayNeed = _ContactsThatMayNeedNextWeek.GetContactsThatMayNeedNextWeek(); // List<ContactToRemind> _ContactsToRemind = new List<ContactToRemind>(); CustomerTrackedServiceItems _CustomterTrackerItem = new CustomerTrackedServiceItems(); // strs.Add("add them including a check for if they need other items: " + _ContactsThayMayNeedData.Count.ToString()); // dts.Add(DateTime.Now); for (int i = 0; i < _ContactsThayMayNeed.Count; i++) { ///// now add them including a check for if they need other items. List <CustomerTrackedServiceItems.CustomerTrackedServiceItemsData> _ThisCustItems = _CustomterTrackerItem.GetAllByCustomerTypeID(_ContactsThayMayNeed[i].CustomerData.CustomerTypeID); ContactToRemindWithItems _ContactToRemind = new ContactToRemindWithItems(); // copy all data across _ContactToRemind.CustomerID = _ContactsThayMayNeed[i].CustomerData.CustomerID; _ContactToRemind.CompanyName = _ContactsThayMayNeed[i].CustomerData.CompanyName; _ContactToRemind.ContactFirstName = _ContactsThayMayNeed[i].CustomerData.ContactFirstName; _ContactToRemind.ContactAltFirstName = _ContactsThayMayNeed[i].CustomerData.ContactAltFirstName; _ContactToRemind.EmailAddress = _ContactsThayMayNeed[i].CustomerData.EmailAddress; _ContactToRemind.AltEmailAddress = _ContactsThayMayNeed[i].CustomerData.AltEmailAddress; _ContactToRemind.CityID = _ContactsThayMayNeed[i].CustomerData.City; _ContactToRemind.CustomerTypeID = _ContactsThayMayNeed[i].CustomerData.CustomerTypeID; _ContactToRemind.enabled = _ContactsThayMayNeed[i].CustomerData.enabled; _ContactToRemind.EquipTypeID = _ContactsThayMayNeed[i].CustomerData.EquipType; _ContactToRemind.TypicallySecToo = _ContactsThayMayNeed[i].CustomerData.TypicallySecToo; _ContactToRemind.PreferedAgentID = _ContactsThayMayNeed[i].CustomerData.PreferedAgent; _ContactToRemind.SalesAgentID = _ContactsThayMayNeed[i].CustomerData.SalesAgentID; _ContactToRemind.UsesFilter = _ContactsThayMayNeed[i].CustomerData.UsesFilter; _ContactToRemind.enabled = _ContactsThayMayNeed[i].CustomerData.enabled; _ContactToRemind.AlwaysSendChkUp = _ContactsThayMayNeed[i].CustomerData.AlwaysSendChkUp; _ContactToRemind.RequiresPurchOrder = _ContactsThayMayNeed[i].RequiresPurchOrder; _ContactToRemind.ReminderCount = _ContactsThayMayNeed[i].CustomerData.ReminderCount; // prep and delivery dates _ContactToRemind.NextPrepDate = _ContactsThayMayNeed[i].NextRoastDateByCityData.PrepDate.Date; _ContactToRemind.NextDeliveryDate = _ContactsThayMayNeed[i].NextRoastDateByCityData.DeliveryDate.Date; // usage dates /// ClientUsageTbl _ClientUsage = new ClientUsageTbl(); // _ClientUsage.GetUsageData(_ContactToRemind.CustomerID); _ContactToRemind.NextCoffee = _ContactsThayMayNeed[i].ClientUsageData.NextCoffeeBy.Date; _ContactToRemind.NextClean = _ContactsThayMayNeed[i].ClientUsageData.NextCleanOn.Date; _ContactToRemind.NextDescal = _ContactsThayMayNeed[i].ClientUsageData.NextDescaleEst.Date; _ContactToRemind.NextFilter = _ContactsThayMayNeed[i].ClientUsageData.NextFilterEst.Date; _ContactToRemind.NextService = _ContactsThayMayNeed[i].ClientUsageData.NextServiceEst.Date; /// now add the items the customer needs. DateTime _dtNextRequired = DateTime.MaxValue; ItemUsageTbl _ItemUsage = new ItemUsageTbl(); List <ItemUsageTbl> _LastItemsOrder = null; for (int j = 0; j < _ThisCustItems.Count; j++) { switch (_ThisCustItems[j].ServiceTypeID) { case TrackerTools.CONST_SERVTYPECOFFEE: _dtNextRequired = _ContactToRemind.NextCoffee; break; case TrackerTools.CONST_SERVTYPECLEAN: _dtNextRequired = _ContactToRemind.NextClean; break; case TrackerTools.CONST_SERVTYPEDESCALE: _dtNextRequired = _ContactToRemind.NextDescal; break; case TrackerTools.CONST_SERVTYPEFILTER: _dtNextRequired = _ContactToRemind.NextFilter; break; case TrackerTools.CONST_SERVTYPESERVICE: _dtNextRequired = _ContactToRemind.NextService; break; default: _dtNextRequired = DateTime.MaxValue; break; } // do a tweak so that if they have had this thing for over year they do not get reminded and then if the will need? if ((_dtNextRequired > DateTime.Now.AddYears(-1)) && (_dtNextRequired <= _ContactsThayMayNeed[i].NextRoastDateByCityData.DeliveryDate)) { // add items they are marked as needing _LastItemsOrder = _ItemUsage.GetLastItemsUsed(_ContactsThayMayNeed[i].CustomerData.CustomerID, _ThisCustItems[j].ServiceTypeID); // they are done for needing this item for (int k = 0; k < _LastItemsOrder.Count; k++) { // only add an item if they need that item ItemContactRequires _ItemRequired = new ItemContactRequires(); _ItemRequired.CustomerID = _ContactsThayMayNeed[i].CustomerData.CustomerID; _ItemRequired.AutoFulfill = _ContactsThayMayNeed[i].CustomerData.autofulfill; // we mark it as an autofulfill so it gets added _ItemRequired.ReoccurID = 0; /// false it is not from reoccuring _ItemRequired.ItemID = _LastItemsOrder[k].ItemProvidedID; _ItemRequired.ItemQty = _LastItemsOrder[k].AmountProvided; _ItemRequired.ItemPackagID = _LastItemsOrder[k].PackagingID; // check if the customer exists if (!pContactsToRemind.Exists(x => x.CustomerID == _ItemRequired.CustomerID)) { _ContactToRemind.ItemsContactRequires.Add(_ItemRequired); pContactsToRemind.Add(_ContactToRemind); } else { int _ContactIdx = pContactsToRemind.FindIndex(x => x.CustomerID == _ItemRequired.CustomerID); if (!pContactsToRemind[_ContactIdx].ItemsContactRequires.Exists(x => x.ItemID == _ItemRequired.ItemID)) { // only add an item if it does not exists pContactsToRemind[_ContactIdx].ItemsContactRequires.Add(_ItemRequired); } } } } // if they need this before the next delivery date. // _LastItemsOrder = null; } } }