Ejemplo n.º 1
0
        public static ReservationDateRangeItem Create(int reservationId, int resourceId, string resourceName, int procTechId, string procTechName, int clientId, string username, string lname, string fname, int activityId, string activityName, int accountId, string accountName, string shortCode, int chargeTypeId, bool isActive, bool isStarted, DateTime beginDateTime, DateTime endDateTime, DateTime?actualBeginDateTime, DateTime?actualEndDateTime, DateTime lastModifiedOn, DateTime?cancelledDateTime, double chargeMultiplier, IEnumerable <ICost> costs)
        {
            // we need to truncate dates to remove milliseconds or else we end up with very small
            // transfer durations (the difference between charged and utilized durations)

            var truncatedCancelledDateTime   = Utility.Truncate(cancelledDateTime);
            var truncatedBeginDateTime       = Utility.Truncate(beginDateTime);
            var truncatedEndDateTime         = Utility.Truncate(endDateTime);
            var truncatedActualBeginDateTime = Utility.Truncate(actualBeginDateTime);
            var truncatedActualEndDateTime   = Utility.Truncate(actualEndDateTime);

            bool          isCancelledBeforeCutoff = Reservations.GetIsCancelledBeforeCutoff(truncatedCancelledDateTime, truncatedBeginDateTime);
            IResourceCost cost = ResourceCost.CreateResourceCosts(costs.Where(c => (c.RecordID == resourceId || c.RecordID == 0) && c.ChargeTypeID == chargeTypeId)).FirstOrDefault();

            var chargeBeginDateTime = (truncatedActualBeginDateTime.HasValue && truncatedActualBeginDateTime < truncatedBeginDateTime) ? truncatedActualBeginDateTime.Value : truncatedBeginDateTime;
            var chargeEndDateTime   = (truncatedActualEndDateTime.HasValue && truncatedActualEndDateTime > truncatedEndDateTime) ? truncatedActualEndDateTime.Value : truncatedEndDateTime;

            var item = new ReservationDateRangeItem
            {
                ReservationID           = reservationId,
                ResourceID              = resourceId,
                ResourceName            = resourceName,
                ProcessTechID           = procTechId,
                ProcessTechName         = procTechName,
                ClientID                = clientId,
                UserName                = username,
                LName                   = lname,
                FName                   = fname,
                ActivityID              = activityId,
                ActivityName            = activityName,
                AccountID               = accountId,
                AccountName             = accountName,
                ShortCode               = shortCode,
                ChargeTypeID            = chargeTypeId,
                IsActive                = isActive,
                IsStarted               = isStarted,
                BeginDateTime           = truncatedBeginDateTime,
                EndDateTime             = truncatedEndDateTime,
                ActualBeginDateTime     = truncatedActualBeginDateTime,
                ActualEndDateTime       = truncatedActualEndDateTime,
                ChargeBeginDateTime     = chargeBeginDateTime,
                ChargeEndDateTime       = chargeEndDateTime,
                LastModifiedOn          = lastModifiedOn,
                IsCancelledBeforeCutoff = isCancelledBeforeCutoff,
                ChargeMultiplier        = chargeMultiplier,
                Cost = cost
            };

            return(item);
        }
Ejemplo n.º 2
0
        public decimal EstimateToolRunCost(int chargeTypeId, int resourceId, double duration)
        {
            //duration is minutes

            var costs = Provider.Data.Cost.FindToolCosts(resourceId, chargeTypeId: chargeTypeId);

            List <IResourceCost> resCosts = ResourceCost.CreateResourceCosts(costs).ToList();

            var rc = resCosts.FirstOrDefault();

            decimal result = 0;
            decimal dur    = Convert.ToDecimal(duration) / 60M;

            if (rc != null)
            {
                result = (rc.HourlyRate() * dur) + rc.PerUseRate();
            }

            return(result);
        }
Ejemplo n.º 3
0
        private static ReservationDateRangeItem CreateReservation(IReservationItem rsv, IEnumerable <ICost> costs)
        {
            var           filtered = costs.Where(c => (c.RecordID == rsv.ResourceID || c.RecordID == 0) && c.ChargeTypeID == rsv.ChargeTypeID).ToList();
            IResourceCost rc       = ResourceCost.CreateResourceCosts(filtered).FirstOrDefault();

            if (rc == null)
            {
                throw new Exception($"Cannot determine cost for Resource: [{rsv.ResourceID}] {rsv.ResourceName}");
            }

            return(new ReservationDateRangeItem()
            {
                ReservationID = rsv.ReservationID,
                ResourceID = rsv.ResourceID,
                ResourceName = rsv.ResourceName,
                ProcessTechID = rsv.ProcessTechID,
                ProcessTechName = rsv.ProcessTechName,
                ClientID = rsv.ClientID,
                UserName = rsv.UserName,
                LName = rsv.LName,
                FName = rsv.FName,
                ActivityID = rsv.ActivityID,
                ActivityName = rsv.ActivityName,
                AccountID = rsv.AccountID,
                AccountName = rsv.AccountName,
                ShortCode = rsv.ShortCode,
                ChargeTypeID = rsv.ChargeTypeID,
                IsActive = rsv.IsActive,
                IsStarted = rsv.IsStarted,
                BeginDateTime = rsv.BeginDateTime,
                EndDateTime = rsv.EndDateTime,
                ActualBeginDateTime = rsv.ActualBeginDateTime,
                ActualEndDateTime = rsv.ActualEndDateTime,
                ChargeBeginDateTime = rsv.ChargeBeginDateTime,
                ChargeEndDateTime = rsv.ChargeEndDateTime,
                LastModifiedOn = rsv.LastModifiedOn,
                IsCancelledBeforeCutoff = rsv.IsCancelledBeforeCutoff,
                ChargeMultiplier = rsv.ChargeMultiplier,
                Cost = rc
            });
        }
Ejemplo n.º 4
0
        public IEnumerable <IResourceCost> GetCurrentResourceCosts(int resourceId)
        {
            var costs = Cost.FindCurrentToolCosts(resourceId);

            return(ResourceCost.CreateResourceCosts(costs));
        }
Ejemplo n.º 5
0
        public IEnumerable <IResourceCost> GetResourceCosts(int resourceId, DateTime?cutoff = null)
        {
            var costs = Cost.FindToolCosts(resourceId, cutoff);

            return(ResourceCost.CreateResourceCosts(costs));
        }