Beispiel #1
0
        //* * * CREATION METHODS

        public int createInvoice(int meterId, string billDate, string startDate, string endDate, int kWh,
                                 double consumptionCharge, double standingCharge, double otherCharge, int propertyId)
        {
            Invoice newInvoice = new Invoice
            {
                BillDate  = Convert.ToDateTime(billDate),
                StartDate = Convert.ToDateTime(startDate),
                EndDate   = Convert.ToDateTime(endDate),

                KWh = kWh,

                ConsumptionCharge = consumptionCharge,
                StandingCharge    = standingCharge,
                OtherCharge       = otherCharge,
            };

            newInvoice.Meter = mediator.DataManager.getMeter(meterId);
            int invoiceId = mediator.DataManager.saveInvoice(newInvoice);

            mediator.validateInvoice(invoiceId, true);

            mediator.updatePropertyAnnualTotalCost(propertyId);

            return(invoiceId);
        }
Beispiel #2
0
        /// <summary>
        /// Generates a 'dummy' invoice with a kWh amount based on change in performance from the same period last year, then uses validator to calculate the cost
        /// of the forecasted consumption & standing charge.  The invoice is not saved to the database.
        /// </summary>
        /// <param name="lastInvoice">most recent invoice on meter, determined using InvoiceManager.getLastInvoice(meterId)</param>
        /// <returns>Invoice object with forecasted data</returns>
        private Invoice forecastInvoice(Invoice lastInvoice)
        {
            Invoice forecastedInvoice = new Invoice();

            TimeSpan lengthOfInvoice = lastInvoice.EndDate - lastInvoice.StartDate;
            TimeSpan oneDay          = new TimeSpan(1, 0, 0, 0);

            ///to account for seasonality, determine consumption of the same time period one year ago
            TimeSpan oneYear          = new TimeSpan(365, 0, 0, 0);
            DateTime kWhLastYearStart = lastInvoice.StartDate - oneYear;
            DateTime kWhLastYearEnd   = lastInvoice.EndDate - oneYear;

            double kWhSameTimeLastYear = mediator.getDataFromMeter(lastInvoice.Meter.Id, kWhLastYearStart.ToString(), kWhLastYearEnd.ToString(), (int)DataType.Energy);

            ///determine the variance between the kWh consumed in the two time periods - this accounts for change in performance from then to now
            double variance;

            ///if kWh used during the same period last year is 0, we have no reason to believe the performance has changed, therefore kWh will be the same
            ///and the variance will be one
            ///otherwise the variance is the change in kWh as a percentage of the kWh of the last invoice
            ///where -ve value means kWh has decreased
            if (kWhSameTimeLastYear == 0)
            {
                variance = 1;
            }
            else
            {
                variance = (lastInvoice.KWh - kWhSameTimeLastYear) / (double)lastInvoice.KWh;
            }

            ///apply variance to give forecasted energy consumption for next invoice
            forecastedInvoice.KWh = (int)Math.Round((double)(lastInvoice.KWh) * variance);

            ///set start and end dates of forecasted invoice
            forecastedInvoice.StartDate = lastInvoice.StartDate + oneDay;
            forecastedInvoice.EndDate   = forecastedInvoice.StartDate + lengthOfInvoice;

            ///assign the releveant meter to the invoice as this contains tariff data used to forcast costs
            forecastedInvoice.Meter = lastInvoice.Meter;

            ///use validation manager to populated cost variance attribute
            forecastedInvoice = mediator.validateInvoice(forecastedInvoice, false);


            if (forecastedInvoice.CostCanBeValidated.Value)
            {
                ///use the cost variance to generated forecasted invoice cost
                ///NB cost variance will be negative since calulated cost is bigger than cost on invoice (0)
                forecastedInvoice.ConsumptionCharge = 0 - forecastedInvoice.CostVariance;
                return(forecastedInvoice);
            }

            else
            {
                return(null);
            }
        }