Пример #1
0
        public long CoffeeCupsLeft(long pCustomerID, LineUsageData pCoffeeUsageData, int pServiceTypeID, int pTypicalPerKg)
        {
            long          _CupsLeft   = 0;
            LineUsageData _LatestData = GetLatestUsageData(pCustomerID, pServiceTypeID); // get the last record in the database

            _CupsLeft = (long)Math.Round((_LatestData.LastQty * pTypicalPerKg));
            if (_LatestData.LastCount > pCoffeeUsageData.LastCount)
            {
                _CupsLeft = _CupsLeft - (_LatestData.LastCount - pCoffeeUsageData.LastCount);
            }

            return(_CupsLeft);
        }
Пример #2
0
        // --- ALL Pure retrieval rotuines below, the do a simple Query and return the data, and a prefixed with Get

        /// <summary>
        /// Get the latest usage data from the client usage table
        /// </summary>
        /// <param name="pCustomerID">which customer</param>
        /// <param name="pServiceTypeID">which service type of data , or "" for no service type</param>
        /// <returns></returns>
        public LineUsageData GetLatestUsageData(long pCustomerID, int pServiceTypeID)
        {
            LineUsageData _LatestUsageData = new LineUsageData();

            ClientUsageLinesTbl _UsageData = new ClientUsageLinesTbl();

            _UsageData = _UsageData.GetLatestUsageData(pCustomerID, pServiceTypeID);

            if (_UsageData.CupCount > 0)
            {
                _LatestUsageData.LastCount = _UsageData.CupCount;
                _LatestUsageData.LastQty   = _UsageData.Qty;
                _LatestUsageData.UsageDate = _UsageData.LineDate;
            }

            return(_LatestUsageData);
        }
Пример #3
0
//    public double CalcDailyAverageForServiceItem(double pTypicalAvePerItem, int pServiceTypeID)
//    {

        #region OldVBACodeCalc
        //   Dim rstClientUsageLines As Recordset
        //   Dim strSQL As String
        //   Dim dt As Date
        //   Dim iLastCount, iCurrCount, iLastQty, iQty As Long
        //   Dim dtCurr As Date

        //   'Find the latest record with service type = "Filter"
        //'   GetNextRequireDate = ConstNullDate

        //   strSQL = "SELECT TOP 6 ClientUsageLinesTbl.Date, ClientUsageLinesTbl.CupCount, ClientUsageLinesTbl.Qty "
        //   strSQL = strSQL + " FROM ClientUsageLinesTbl"
        //   strSQL = strSQL + " WHERE ClientUsageLinesTbl.CustomerID = " + pCustomerID
        //   strSQL = strSQL + " AND ClientUsageLinesTbl.ServiceTypeID = " + sType
        //   strSQL = strSQL + " ORDER BY ClientUsageLinesTbl.Date DESC"

        //   Set rstClientUsageLines = CurrentDb.OpenRecordset(strSQL)

        //   ' set the variables to default so that
        //   nAve = 0
        //   iCurrCount = 0
        //   dtCurr = ConstNullDate

        //   ' Get the initial data if available
        //   If Not rstClientUsageLines.EOF Then
        //     rstClientUsageLines.MoveFirst ' Order is DESC

        //     iLastCount = rstClientUsageLines("CupCount")
        //     iCurrCount = iLastCount
        //     dtCurr = rstClientUsageLines("Date")
        //     iLastQty = rstClientUsageLines("Qty")
        //     If IsNull(iLastQty) Then
        //       iLastQty = 1
        //     End If
        //   Else
        //     ' Default Value is a rough estimate when they will need this type
        //     nAve = iDefVal
        //   End If

        //   ' take the last cup count and deducting the current count, dividing by the last qty calculate the
        //   ' difference and then roll the average

        //   Do While Not rstClientUsageLines.EOF
        //     'Calc a rolling average
        //     If nAve = 0 Then
        //       nAve = (iLastCount - rstClientUsageLines("CupCount")) / iLastQty
        //     Else
        //       nAve = (nAve + (iLastCount - rstClientUsageLines("CupCount")) / iLastQty) / 2
        //     End If

        //     iLastCount = rstClientUsageLines("CupCount")
        //     iLastQty = rstClientUsageLines("Qty")

        //     If IsNull(iLastQty) Then
        //       iLastQty = 1
        //     End If
        //     rstClientUsageLines.MoveNext

        //   Loop

        //   ' At this point we either have a average or zeros
        //   If nAve = 0 Then
        //     ' if 0- then one record was found, so set it to the last qty
        //     nAve = iLastCount / iLastQty
        //   End If

        //   ' if CurrCount is still zero there where no records, so next required date is initial date + nAve
        //   If iCurrCount = 0 Then
        //     dtCurr = LookupInstallDate(pCustomerID)
        //   End If

        //   ' Now either we have the default value or an average
        //   dtCurr = DateAdd("d", Round(nAve / nCupAve, 0), dtCurr)
        //'   d = dtCurr
        //   CalcNextRequiredDate = RemoveTimePortion(dtCurr)

        //   ' close the record set
        //   rstClientUsageLines.Close


        #endregion

//      return _Average;
//    }
        /// <summary>
        /// Set the service data for this client
        /// </summary>
        /// <param name="pCustomerID"></param>
        /// <param name="pTrackedServiceItemData"></param>
        /// <param name="pDailyAverage"></param>
        /// <returns></returns>
        private ClientServiceItem SetClientServiceData(long pCustomerID, TrackedServiceItemTbl pTrackedServiceItemData, double pDailyAverage)
        {
            int  _DaysLeftForItem;
            bool _IsPerDayCalc = (pDailyAverage == 0);

            ClientServiceItem _ClientServiceItem = new ClientServiceItem();

            _ClientServiceItem.UsageDateFieldName = pTrackedServiceItemData.UsageDateFieldName;
            _ClientServiceItem.UsageAveFieldName  = pTrackedServiceItemData.UsageAveFieldName;
            _ClientServiceItem.ThisItemsAverage   =
                CalcAveConsumption(pCustomerID, pTrackedServiceItemData.ServiceTypeID, pTrackedServiceItemData.TypicalAvePerItem, _IsPerDayCalc);

            /*NextDate for item is equal to LastDate + DaysLeftOfItemUse;
             * DaysLeftOfItemUse = (QtyLastProvided X TypicalUsePerKg) / KgDailConsumption */

            LineUsageData _LatestData = GetLatestUsageData(pCustomerID, pTrackedServiceItemData.ServiceTypeID); // get the last record in the database

            // check for minb date, and allocate the result to install date
            if (_LatestData.UsageDate == DateTime.MinValue)
            {
                _LatestData.UsageDate = GetInstallDate(pCustomerID);
            }
            //// xxx
            //  this is wrong we need to calculate the days left so we need to times qty by typical use per qty and then divide by average
            // daysleft = (lastQty * lastAveForItem) / ThisItemsAverage
            if (_IsPerDayCalc)
            {
                _DaysLeftForItem = (int)Math.Round(((_LatestData.LastQty * TrackerTools.CONST_TYPICALNUMCUPSPERKG) / _ClientServiceItem.ThisItemsAverage), 0);
            }
            else
            {
                _DaysLeftForItem = (int)Math.Round((_LatestData.LastQty * _ClientServiceItem.ThisItemsAverage) / pDailyAverage, 0);
            }

            // set the date deepending on holidays
            _ClientServiceItem.NextUsageDate = AddHolidayExtension(pCustomerID, _LatestData.UsageDate.AddDays(_DaysLeftForItem), pTrackedServiceItemData.ServiceTypeID);

            return(_ClientServiceItem);
        }
Пример #4
0
        public long CalcEstCupCount(long pCustomerID, LineUsageData pClientUsageData, bool pIsCoffee)
        {
            double _newCupCount = 1;

            if (pClientUsageData.UsageDate > DateTime.MinValue)
            {
                double _AveConsump = GetAveConsumption(pCustomerID);
                // Calculate the number of datys difference
                DateTime _AdjustedDate = RemoveHolidayPeriodFromDate(pCustomerID, pClientUsageData.UsageDate, TrackerDotNet.classes.TrackerTools.CONST_SERVTYPECOFFEE);
                int      _DateDiff     = Convert.ToInt32((DateTime.Now - _AdjustedDate).TotalDays);

                if ((!pIsCoffee) || (pClientUsageData.LastQty == 0))
                {
                    _newCupCount = pClientUsageData.LastCount + (_DateDiff * _AveConsump);
                }
                else
                {
                    _newCupCount = (pClientUsageData.LastCount + (pClientUsageData.LastQty * TrackerTools.CONST_TYPICALNUMCUPSPERKG));
                }
            }

            return(Convert.ToInt32(Math.Round(_newCupCount)));
        }
Пример #5
0
 public long CoffeeCupsLeft(long pCustomerID, LineUsageData pCoffeeUsageData)
 {
     return(CoffeeCupsLeft(pCustomerID, pCoffeeUsageData, TrackerTools.CONST_SERVTYPECOFFEE, TrackerTools.CONST_TYPICALNUMCUPSPERKG));
 }