Ejemplo n.º 1
0
        /// <summary>
        /// Calculate Charge
        /// </summary>
        public RaHireGroup CalculateCharge(DateTime recCreatedDate, DateTime rAStDate, DateTime rAEndDate, DateTime stDate, DateTime eDate,
                                           Int64 operationId, Int64 hireGroupDetailId, Int32 outOdometer, Int32 inOdometer, List <TariffType> oTariffTypeList)
        {
            PricingStrategy objPs = PricingStrategyFactory.GetPricingStrategy(recCreatedDate, rAStDate, rAEndDate, operationId, oTariffTypeList);

            if (objPs == null)
            {
                throw new CaresException(Resources.RentalAgreement.RentalAgreement.TariffTypeNotDefinedForRentalCharge, null);
            }

            List <StandardRate> standardRates = standardRateRepository.GetForRaBilling(objPs.TariffType.TariffTypeCode, hireGroupDetailId, recCreatedDate).ToList();

            if (standardRates.Count == 0)
            {
                throw new CaresException(Resources.RentalAgreement.RentalAgreement.StandardTariffRateNotDefinedForRentalCharge, null);
            }

            StandardRate otStRate = standardRates[0];

            RaHireGroup tmp = objPs.CalculateRentalCharge(stDate, eDate, otStRate);

            // need to get RA vehicle as well for calculating Excess Mileage Charge for edit case
            tmp.TotalExcMileage       = objPs.GetExcessMileage(outOdometer, inOdometer, tmp.AllowedMileage ?? 0);
            tmp.TotalExcMileageCharge = objPs.GetExcessMileageCharge(tmp.TotalExcMileage, (float)tmp.ExcessMileageRt);

            return(tmp);
        }
Ejemplo n.º 2
0
 /// <summary>
 ///  Create web model from entity
 /// </summary>
 public static DomainModels.RaHireGroup CreateFrom(this RaHireGroup source)
 {
     return(new DomainModels.RaHireGroup
     {
         RaHireGroupId = source.RaHireGroupId,
         HireGroupDetailId = source.HireGroupDetailId,
         RaMainId = source.RaMainId,
         VehicleId = source.VehicleId,
         RentalChargeStartDate = source.RentalChargeStartDate,
         RentalChargeEndDate = source.RentalChargeEndDate,
         AllocationStatusId = source.AllocationStatusId,
         AllowedMileage = source.AllowedMileage,
         ChargedDay = source.ChargedDay,
         ChargedHour = source.ChargedHour,
         ChargedMinute = source.ChargedMinute,
         DropOffCharge = source.DropOffCharge,
         ExcessMileageRt = source.ExcessMileageRt,
         GraceDay = source.GraceDay,
         GraceHour = source.GraceHour,
         GraceMinute = source.GraceMinute,
         StandardRate = source.StandardRate,
         TariffTypeCode = source.TariffTypeCode,
         TotalExcMileage = source.TotalExcMileage,
         TotalExcMileageCharge = source.TotalExcMileageCharge,
         TotalStandardCharge = source.TotalStandardCharge,
         VehicleMovements = source.VehicleMovements != null?source.VehicleMovements.Select(vm => vm.CreateFrom()).ToList() :
                                new List <DomainModels.VehicleMovement>(),
                                RaHireGroupInsurances = source.RaHireGroupInsurances != null?source.RaHireGroupInsurances.Select(hgi => hgi.CreateFrom()).ToList() :
                                                            new List <DomainModels.RaHireGroupInsurance>(),
                                                            RaHireGroupDiscounts = source.RaHireGroupDiscounts != null?source.RaHireGroupDiscounts.Select(hgd => hgd.CreateFrom()).ToList() :
                                                                                       new List <DomainModels.RaHireGroupDiscount>(),
                                                                                       RaVehicleCheckLists = source.RaVehicleCheckLists != null?source.RaVehicleCheckLists.Select(vch => vch.CreateFrom()).ToList() :
                                                                                                                 new List <DomainModels.RaVehicleCheckList>()
     });
 }
Ejemplo n.º 3
0
 private static void MapRaHireGroupCharge(RaHireGroup item, RaHireGroup chargeHireGroup)
 {
     item.TariffTypeCode        = chargeHireGroup.TariffTypeCode;
     item.RentalChargeStartDate = chargeHireGroup.RentalChargeStartDate;
     item.RentalChargeEndDate   = chargeHireGroup.RentalChargeEndDate;
     item.StandardRate          = chargeHireGroup.StandardRate;
     item.TotalStandardCharge   = chargeHireGroup.TotalStandardCharge;
     item.DropOffCharge         = chargeHireGroup.DropOffCharge;
     item.AllowedMileage        = chargeHireGroup.AllowedMileage;
     item.ExcessMileageRt       = chargeHireGroup.ExcessMileageRt;
     item.GraceDay      = chargeHireGroup.GraceDay;
     item.GraceHour     = chargeHireGroup.GraceHour;
     item.GraceMinute   = chargeHireGroup.GraceMinute;
     item.ChargedDay    = chargeHireGroup.ChargedDay;
     item.ChargedHour   = chargeHireGroup.ChargedHour;
     item.ChargedMinute = chargeHireGroup.ChargedMinute;
 }
Ejemplo n.º 4
0
        public override RaHireGroup CalculateRentalCharge(DateTime StartDate, DateTime EndDate, StandardRate tSTrate)
        {
            RaHireGroup oRentalCharge = null;
            //calculate total rental duration as a time span object
            TimeSpan dtSpan = EndDate - StartDate;
            TimeSpan ChargeSpan;
            TimeSpan GraceSpan;
            //convert rental duration to minutes for standardization
            float RentalDurationInMinutes = GetDurationInMinutes(dtSpan, Convert.ToInt32(TariffType.MeasurementUnitId));
            //convert tariff type FromDuration to Minute for standardization
            float TariffDurationFrom = GetDurationInMinutes(TariffType.DurationFrom, Convert.ToInt32(TariffType.MeasurementUnitId));
            //convert tariff type ToDuration to Minute for standardization
            float TariffDurationTo = GetDurationInMinutes(TariffType.DurationTo, Convert.ToInt32(TariffType.MeasurementUnitId));
            //convert tariff type GracePeriod to Minute for standardization
            float TariffGracePeriod = GetDurationInMinutes((float)TariffType.GracePeriod, Convert.ToInt32(TariffType.MeasurementUnitId));

            //set rental charge object common parameters
            oRentalCharge = new RaHireGroup();
            oRentalCharge.RentalChargeStartDate = StartDate;
            oRentalCharge.RentalChargeEndDate   = EndDate;
            oRentalCharge.TariffTypeCode        = TariffType.TariffTypeCode;
            //condition 1: if rental duration lies between From and To

            if (RentalDurationInMinutes >= TariffDurationFrom && RentalDurationInMinutes <= TariffDurationTo)
            {
                oRentalCharge.StandardRate        = tSTrate.StandardRt;
                oRentalCharge.TotalStandardCharge = tSTrate.StandardRt;
                //excess milage charge for edit case
                oRentalCharge.ExcessMileageRt       = tSTrate.ExcessMileageChrg;
                oRentalCharge.TotalExcMileageCharge = 0;
                oRentalCharge.GraceDay       = 0;
                oRentalCharge.GraceHour      = 0;
                oRentalCharge.GraceMinute    = 0;
                oRentalCharge.ChargedDay     = dtSpan.Days;
                oRentalCharge.ChargedHour    = dtSpan.Hours;
                oRentalCharge.ChargedMinute  = dtSpan.Minutes;
                oRentalCharge.AllowedMileage = tSTrate.AllowedMileage;
            }
            else
            {
                GraceSpan  = GetGrace(RentalDurationInMinutes, TariffDurationTo, Convert.ToInt32(TariffType.MeasurementUnitId), TariffGracePeriod);
                ChargeSpan = new TimeSpan(dtSpan.Days - GraceSpan.Days, dtSpan.Hours - GraceSpan.Hours, dtSpan.Minutes - GraceSpan.Minutes, 0);
                float ChargeDuration = GetDurationInMinutes(ChargeSpan, Convert.ToInt32(TariffType.MeasurementUnitId));
                oRentalCharge.TotalStandardCharge = (float)Math.Round((ChargeDuration / TariffDurationTo) * tSTrate.StandardRt, base.DecimalRounding, MidpointRounding.AwayFromZero);
                oRentalCharge.StandardRate        = tSTrate.StandardRt;
                //excess milage charge for edit case
                //drop off charge
                oRentalCharge.DropOffCharge         = 0;
                oRentalCharge.ExcessMileageRt       = tSTrate.ExcessMileageChrg;
                oRentalCharge.TotalExcMileageCharge = 0;
                oRentalCharge.AllowedMileage        = tSTrate.AllowedMileage;
                oRentalCharge.GraceDay      = GraceSpan.Days;
                oRentalCharge.GraceHour     = GraceSpan.Hours;
                oRentalCharge.GraceMinute   = GraceSpan.Minutes;
                oRentalCharge.ChargedDay    = ChargeSpan.Days;
                oRentalCharge.ChargedHour   = ChargeSpan.Hours;
                oRentalCharge.ChargedMinute = ChargeSpan.Minutes;
            }

            return(oRentalCharge);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Calculate HireGroup Charges
        /// </summary>
        public void CalculateHireGroupCharges(DateTime RACreatedDate, DateTime StartDate, DateTime EndDate, Int64 OperationID, ref List <RaHireGroup> RAHireGroupList, List <TariffType> oTariffTypeList)
        {
            Int32       OutOdometer = 0, InOdometer = 0;
            Int64       DesiredHireGroupID = 0;
            RaHireGroup oRAHGDesired       = GetDesiredHireGroup(RAHireGroupList);

            if (oRAHGDesired != null)
            {
                DesiredHireGroupID = oRAHGDesired.HireGroupDetailId;
            }
            foreach (RaHireGroup item in RAHireGroupList)
            {
                if (item.IsDeleted != true)
                {
                    VehicleMovement vehicleMovementOut = item.VehicleMovements.FirstOrDefault(vm => vm.Status == Convert.ToBoolean(VehicleMovementEnum.Out));
                    VehicleMovement vehicleMovementIn  = item.VehicleMovements.FirstOrDefault(vm => vm.Status == Convert.ToBoolean(VehicleMovementEnum.In));
                    if (vehicleMovementOut != null && vehicleMovementOut.Odometer != null)
                    {
                        OutOdometer = Convert.ToInt32(vehicleMovementOut.Odometer);
                    }
                    if (vehicleMovementIn != null && vehicleMovementIn.Odometer != null)
                    {
                        InOdometer = Convert.ToInt32(vehicleMovementIn.Odometer);
                    }
                    if (vehicleMovementIn != null && vehicleMovementOut != null)
                    {
                        RaHireGroup chargeHireGroup = rentalCharge.CalculateCharge(RACreatedDate, StartDate, EndDate,
                                                                                   Convert.ToDateTime(vehicleMovementOut.DtTime),
                                                                                   Convert.ToDateTime(vehicleMovementIn.DtTime), OperationID,
                                                                                   (item.AllocationStatusId == (short)AllocationStatusEnum.Upgraded ?
                                                                                    DesiredHireGroupID : item.HireGroupDetailId), OutOdometer, InOdometer, oTariffTypeList);

                        MapRaHireGroupCharge(item, chargeHireGroup);
                    }

                    List <RaHireGroupInsurance> RAHireGroupInsList = item.RaHireGroupInsurances.ToList();
                    foreach (RaHireGroupInsurance raHireGroupInsurance in RAHireGroupInsList)
                    {
                        if (raHireGroupInsurance.IsDeleted)
                        {
                            continue;
                        }


                        RaHireGroupInsurance insurance = insuranceRateService.CalculateCharge(RACreatedDate, Convert.ToDateTime(raHireGroupInsurance.StartDtTime),
                                                                                              Convert.ToDateTime(raHireGroupInsurance.EndDtTime), OperationID, item.HireGroupDetailId,
                                                                                              raHireGroupInsurance.InsuranceTypeId, oTariffTypeList);

                        MapRaHireGroupInsuranceCharge(raHireGroupInsurance, insurance);
                    }
                    //Discount Scheme change
                    RaHireGroupDiscount standardDiscount = item.RaHireGroupDiscounts.
                                                           FirstOrDefault(discount => discount.DiscountKey == (short)DiscountTypeEnum.StandardDiscount);
                    RaHireGroupDiscount seasonalDiscount = item.RaHireGroupDiscounts.
                                                           FirstOrDefault(discount => discount.DiscountKey == (short)DiscountTypeEnum.SeasonalDiscount);

                    if (seasonalDiscount != null)
                    {
                        seasonalDiscount.DiscountAmount = CalculateDiscount(item.TotalStandardCharge, seasonalDiscount.DiscountPerc);
                    }
                    if (standardDiscount != null)
                    {
                        standardDiscount.DiscountAmount = CalculateDiscount(item.TotalStandardCharge, standardDiscount.DiscountPerc);
                    }
                }
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Generates Rental Charge
        /// </summary>
        public override RaHireGroup CalculateRentalCharge(DateTime StartDate, DateTime EndDate, StandardRate tSTrate)
        {
            RaHireGroup oRentalCharge = null;
            //calculate total rental duration as a time span object
            TimeSpan dtSpan = EndDate - StartDate;
            TimeSpan ChargeSpan;
            TimeSpan GraceSpan;
            //convert rental duration to minutes for standardization
            float RentalDurationInMinutes = GetDurationInMinutes(dtSpan, Convert.ToInt32(TariffType.MeasurementUnitId));
            //convert tariff type FromDuration to Minute for standardization
            float TariffDurationFrom = GetDurationInMinutes(TariffType.DurationFrom, Convert.ToInt32(TariffType.MeasurementUnitId));
            //convert tariff type ToDuration to Minute for standardization
            float TariffDurationTo = GetDurationInMinutes(TariffType.DurationTo, Convert.ToInt32(TariffType.MeasurementUnitId));
            //convert tariff type GracePeriod to Minute for standardization
            float TariffGracePeriod = GetDurationInMinutes((float)TariffType.GracePeriod, Convert.ToInt32(TariffType.MeasurementUnitId));

            //set rental charge object common parameters
            oRentalCharge = new RaHireGroup();
            oRentalCharge.RentalChargeStartDate = StartDate;
            oRentalCharge.RentalChargeEndDate   = EndDate;
            oRentalCharge.TariffTypeCode        = this.TariffType.TariffTypeCode;
            //condition 1: if rental duration lies between From and To
            if (RentalDurationInMinutes >= TariffDurationFrom && RentalDurationInMinutes <= TariffDurationTo)
            {
                oRentalCharge.StandardRate        = (float)tSTrate.StandardRt;
                oRentalCharge.TotalStandardCharge = (float)tSTrate.StandardRt;
                //excess milage charge for edit case
                oRentalCharge.ExcessMileageRt       = (float)tSTrate.ExcessMileageChrg;
                oRentalCharge.TotalExcMileageCharge = 0;
                oRentalCharge.AllowedMileage        = tSTrate.AllowedMileage;
                oRentalCharge.GraceDay      = 0;
                oRentalCharge.GraceHour     = 0;
                oRentalCharge.GraceMinute   = 0;
                oRentalCharge.ChargedDay    = dtSpan.Days;
                oRentalCharge.ChargedHour   = dtSpan.Hours;
                oRentalCharge.ChargedMinute = dtSpan.Minutes;
            }
            else
            {
                Int16 Quotient = Int16.Parse(Math.Floor(Convert.ToDouble(RentalDurationInMinutes / TariffDurationTo)).ToString());

                //check if grace is applicable or not
                float y = RentalDurationInMinutes % TariffDurationTo;
                // since RentalDurationInMinutes % TariffDurationTo gives us how many units the rental duration is greater than TariffDurationTo,
                // the y part gives us the remainder of those units.if y times this.TariffType.DurationTo is less than and equal to this.TariffType.Graceperiod , then grace is applicable

                //if (y * this.TariffType.DurationTo <= this.TariffType.GracePeriod)
                if (y <= this.TariffType.GracePeriod)
                {
                    GraceSpan = GetGrace(RentalDurationInMinutes, TariffDurationTo, Quotient);
                }
                else
                {
                    GraceSpan = new TimeSpan(0, 0, 0, 0);
                }
                ChargeSpan = new TimeSpan(dtSpan.Days - GraceSpan.Days, dtSpan.Hours - GraceSpan.Hours, dtSpan.Minutes - GraceSpan.Minutes, 0);
                float ChargeDuration = GetDurationInMinutes(ChargeSpan, Convert.ToInt32(this.TariffType.MeasurementUnitId));
                oRentalCharge.TotalStandardCharge = (float)Math.Round(((float)Math.Ceiling(Convert.ToDouble((ChargeDuration / TariffDurationTo)))) * tSTrate.StandardRt, base.DecimalRounding, MidpointRounding.AwayFromZero);
                oRentalCharge.StandardRate        = tSTrate.StandardRt;
                //excess milage charge for edit case
                //drop off charge
                oRentalCharge.DropOffCharge         = 0;
                oRentalCharge.ExcessMileageRt       = tSTrate.ExcessMileageChrg;
                oRentalCharge.TotalExcMileageCharge = 0;
                oRentalCharge.GraceDay       = GraceSpan.Days;
                oRentalCharge.GraceHour      = GraceSpan.Hours;
                oRentalCharge.GraceMinute    = GraceSpan.Minutes;
                oRentalCharge.ChargedDay     = ChargeSpan.Days;
                oRentalCharge.ChargedHour    = ChargeSpan.Hours;
                oRentalCharge.ChargedMinute  = ChargeSpan.Minutes;
                oRentalCharge.AllowedMileage = tSTrate.AllowedMileage;
            }
            return(oRentalCharge);
        }