string AddLastOrderTableRow(ItemContactRequires pItemContactRequires, bool bAltRow) { string _TableRow = bAltRow ? CONST_SUMMARYTABLEALTCELLBOLD : CONST_SUMMARYTABLECELLBOLD; string _QtyDesc = AddUnitsToQty(pItemContactRequires.ItemID, pItemContactRequires.ItemQty); if (pItemContactRequires.ItemPackagID > 0) { if (bAltRow) { _TableRow += CONST_SUMMARYTABLEALTCELL1 + CONST_SUMMARYTABLEALTCELL2; } else { _TableRow += CONST_SUMMARYTABLECELL1 + CONST_SUMMARYTABLECELL2; } _TableRow = String.Format(_TableRow, GetItemDesc(pItemContactRequires.ItemID), _QtyDesc, GetPackagingDesc(pItemContactRequires.ItemPackagID)); } else { if (bAltRow) { _TableRow += CONST_SUMMARYTABLEALTCELL2COL; } else { _TableRow += CONST_SUMMARYTABLECELL2COL; } _TableRow = String.Format(_TableRow, GetItemDesc(pItemContactRequires.ItemID), _QtyDesc); } return(_TableRow); }
private List <ContactToRemind> GetReocurringContacts() { List <ContactToRemind> _ContactsToRemind = new List <ContactToRemind>(); List <ItemContactRequires> ItemsContactRequires = new List <ItemContactRequires>(); // make sure the dates in the Reoccuring table match the last delivery date QOnT.control.ReoccuringOrderTbl _ReoccuringOrder = new control.ReoccuringOrderTbl(); _ReoccuringOrder.SetReoccuringItemsLastDate(); // now make sure that only records the are enbabled and need to be added from Reoccuring Are added List <control.ReoccuringOrderTbl> _ReoccuringOrders = _ReoccuringOrder.GetAll(true); control.CustomersTbl _Customer = new control.CustomersTbl(); for (int i = 0; i < _ReoccuringOrders.Count; i++) { // if DateNext < NextDeliveryDate for client ItemContactRequires _ItemRequired = new ItemContactRequires(); /* !!!!!!!!!!!!!!!!!!!!!!!! * * need to add this logic * * need to see if they need this item and then add a record if required marking as a reocurring item */ /* !!!!!!!!!!!!11 * * If CustomerID exists then add to item list otherwise add to list * */ ContactToRemind _ContactToRemind = new ContactToRemind(); _Customer = _Customer.GetCustomersByCustomerID(_ReoccuringOrder.CustomerID); _ContactToRemind.CustomerID = _ReoccuringOrder.CustomerID; _ContactToRemind.CompanyName = _Customer.CompanyName; _ContactToRemind.ContactFirstName = _Customer.ContactFirstName; _ContactToRemind.ContactAltFirstName = _Customer.ContactAltFirstName; _ContactToRemind.EmailAddress = _Customer.EmailAddress; _ContactToRemind.AltEmailAddress = _Customer.AltEmailAddress; _ContactToRemind.City = _Customer.City; _ContactToRemind.CustomerTypeID = _Customer.CustomerTypeID; _ContactToRemind.enabled = _Customer.enabled; _ContactToRemind.EquipType = _Customer.EquipType; _ContactToRemind.TypicallySecToo = _Customer.TypicallySecToo; _ContactToRemind.PreferedAgent = _Customer.PreferedAgent; _ContactToRemind.SalesAgentID = _Customer.SalesAgentID; _ContactToRemind.UsesFilter = _Customer.UsesFilter; _ContactToRemind.enabled = _Customer.enabled; _ContactToRemind.AlwaysSendChkUp = _Customer.AlwaysSendChkUp; _ContactToRemind.ReminderCount = _Customer.ReminderCount; // now add the reocurring item ItemContactRequires _ItemContactRequires = new ItemContactRequires(); ItemsContactRequires.Add(_ItemContactRequires); } return(_ContactsToRemind); }
private List <ContactToRemindWithItems> GetReocurringContacts() { // General VAR definitions List <ContactToRemindWithItems> _ContactsToRemind = new List <ContactToRemindWithItems>(); TrackerTools _TrackerTools = new classes.TrackerTools(); // . from TrackerDotNet.classes. DateTime _dtTemp = DateTime.MinValue; DateTime _dtNextRoast = DateTime.MinValue; // get the syustem minimum date for if we are closed SysDataTbl _SysData = new SysDataTbl(); DateTime _MinDate = _SysData.GetMinReminderDate(); // 1. // make sure the dates in the Reoccuring table match the last delivery date ReoccuringOrderDAL _ReoccuringOrderDAL = new ReoccuringOrderDAL(); // Need to add this to the classs if (!_ReoccuringOrderDAL.SetReoccuringItemsLastDate()) { showMessageBox _smb = new showMessageBox(this.Page, "Set Reoccuring Item Last Date", "Could not set the re-occuring last date"); return(_ContactsToRemind); } // if we get here we could set the last date ?????????????? /* 2. For each enabled record in the ReoccuringTbl: * if the LastDatePerItem + DateAdd(ReocurranceType) < NextCityDeliveryDate * then add them into the temporary reminder table, but set the value in the tempoary reminder table to remember that it is a reoccuring and an auto fulfil. */ // now make sure that only records the are enbabled and need to be added from Reoccuring Are added List <ReoccuringOrderExtData> _ReoccuringOrders = _ReoccuringOrderDAL.GetAll(ReoccuringOrderDAL.CONST_ENABLEDONLY, "CustomersTbl.CustomerID"); // -1 is all re ///////////// perhaps we should return all details in the above query? for (int i = 0; i < _ReoccuringOrders.Count; i++) { switch (_ReoccuringOrders[i].ReoccuranceTypeID) { case ReoccuranceTypeTbl.CONST_WEEKTYPEID: _ReoccuringOrders[i].NextDateRequired = _ReoccuringOrders[i].DateLastDone.AddDays(_ReoccuringOrders[i].ReoccuranceValue * 7).Date; break; case ReoccuranceTypeTbl.CONST_DAYOFMONTHID: _ReoccuringOrders[i].NextDateRequired = _ReoccuringOrders[i].DateLastDone.AddMonths(1).Date; _ReoccuringOrders[i].NextDateRequired = new DateTime(_ReoccuringOrders[i].NextDateRequired.Year, _ReoccuringOrders[i].NextDateRequired.Month, _ReoccuringOrders[i].ReoccuranceValue).Date; break; default: break; // not a type we know so exit } // disable the order if this is the last time if ((_ReoccuringOrders[i].RequireUntilDate > TrackerTools.STATIC_TrackerMinDate) && (_ReoccuringOrders[i].NextDateRequired > _ReoccuringOrders[i].RequireUntilDate)) { _ReoccuringOrders[i].Enabled = false; } _dtNextRoast = _TrackerTools.GetNextRoastDateByCustomerID(_ReoccuringOrders[i].CustomerID, ref _dtTemp); // check if the the Next roast date is less than the system Minimum date if (_dtNextRoast < _MinDate) { _dtNextRoast = _MinDate; } // if DateNext < NextDeliveryDate for client the add to list if (_ReoccuringOrders[i].NextDateRequired <= _dtNextRoast) { // we have a winner we need to add this item but first check if there is an order for this item type. OrderCheck _orderCheck = new OrderCheck(); List <OrderCheckData> _OrdersToCheck = _orderCheck.GetSimilarItemInOrders(_ReoccuringOrders[i].CustomerID, _ReoccuringOrders[i].ItemRequiredID, DateTimeExtensions.GetFirstDayOfWeek(_dtNextRoast), DateTimeExtensions.GetLastDayOfWeek(_dtNextRoast)); if (_OrdersToCheck == null) { // there are no orders that have the same item type ItemContactRequires _ItemRequired = new ItemContactRequires(); _ItemRequired.CustomerID = _ReoccuringOrders[i].CustomerID; _ItemRequired.AutoFulfill = false; // it is a reoccuring order not auto ff _ItemRequired.ReoccurID = _ReoccuringOrders[i].ReoccuringOrderID; _ItemRequired.ReoccurOrder = true; // remember it is from reoccuring _ItemRequired.ItemID = _ReoccuringOrders[i].ItemRequiredID; _ItemRequired.ItemQty = _ReoccuringOrders[i].QtyRequired; _ItemRequired.ItemPackagID = _ReoccuringOrders[i].PackagingID; // check if the customer exists if (!_ContactsToRemind.Exists(x => x.CustomerID == _ItemRequired.CustomerID)) { ContactToRemindWithItems _ContactToRemind = new ContactToRemindWithItems(); _ContactToRemind = _ContactToRemind.GetCustomerDetails(_ItemRequired.CustomerID); _ContactToRemind.ItemsContactRequires.Add(_ItemRequired); _ContactsToRemind.Add(_ContactToRemind); } else { int _ContactIdx = _ContactsToRemind.FindIndex(x => x.CustomerID == _ItemRequired.CustomerID); _ContactsToRemind[_ContactIdx].ItemsContactRequires.Add(_ItemRequired); } } else { List <OrderCheckData> _OrderCheckData = null; // store that and order has identified if (Session[CONST_SESSIONVAR_EXISTINGORDERS] == null) { _OrderCheckData = new List <OrderCheckData>(); } else { _OrderCheckData = (List <OrderCheckData>)Session[CONST_SESSIONVAR_EXISTINGORDERS]; } for (int j = 0; j < _OrdersToCheck.Count; j++) { _OrderCheckData.Add(_OrdersToCheck[j]); } // this.gvReminderOfOrdersPlaced.DataSource = _OrderCheckData; // this.gvReminderOfOrdersPlaced.DataBind(); // Session[CONST_SESSIONVAR_EXISTINGORDERS] = _OrderCheckData; } } /// we found an item in reoccuring that we need to send a reminder too } return(_ContactsToRemind); }
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; } } }