Example #1
0
        private void calcFSC(DriverCompDS.DriverRouteTableRow dayComp, RouteRatings ratings)
        {
            //Calculate FSC if required
            try {
                //1. FSC applies only if miles rates are present in the rating
                if (ratings.MileBaseRate > 0 || ratings.MileRate > 0)
                {
                    dayComp.FSCMiles = dayComp.Miles;
                }

                //2. Copy rates (for reference)
                dayComp.FuelCost = FinanceFactory.GetFuelCost(this.EndDate, this.mAgentNumber);
                dayComp.FSCGal   = EnterpriseFactory.GetDriverEquipmentMPG(dayComp.EquipmentTypeID);
                if (dayComp.FSCGal <= 0.0M)
                {
                    throw new ApplicationException("FSCGal (" + dayComp.FSCGal.ToString() + "MPG) is invalid.");
                }
                dayComp.FSCBaseRate = this.mTerminalConfig.FSBase;

                //3. Calculate FSC
                dayComp.FSC = dayComp.FSCMiles / dayComp.FSCGal * (dayComp.FuelCost - dayComp.FSCBaseRate);
                if (dayComp.FSC < 0)
                {
                    dayComp.FSC = 0.0M;
                }
            }
            catch (ApplicationException ex) { throw ex; }
            catch (Exception ex) { throw new ApplicationException("Unexpected error while calculating FSC.", ex); }
        }
Example #2
0
        private void applyRates(DriverCompDS.DriverRouteTableRow dayComp, RouteRatings ratings)
        {
            //Apply ratings to this route
            try {
                //1. Copy rates (for reference)
                dayComp.RateTypeID        = ratings.RateTypeID;
                dayComp.MilesBaseRate     = ratings.MileBaseRate;
                dayComp.MilesRate         = ratings.MileRate;
                dayComp.DayRate           = ratings.DayRate;
                dayComp.TripRate          = ratings.TripRate;
                dayComp.StopsRate         = ratings.StopRate;
                dayComp.CartonsRate       = ratings.CartonRate;
                dayComp.PalletsRate       = ratings.PalletRate;
                dayComp.PickupCartonsRate = ratings.PickupCartonRate;
                dayComp.MinimunAmount     = ratings.MinimumAmount;

                //2. Calculate ratings -------------------------------------------------------------
                //2.1 Standard computations
                dayComp.MilesAmount         = dayComp.MilesBaseRate + dayComp.Miles * dayComp.MilesRate;
                dayComp.DayAmount           = dayComp.DayRate;
                dayComp.TripAmount          = dayComp.Trip * dayComp.TripRate;
                dayComp.StopsAmount         = dayComp.Stops * dayComp.StopsRate;
                dayComp.CartonsAmount       = dayComp.Cartons * dayComp.CartonsRate;
                dayComp.PalletsAmount       = dayComp.Pallets * dayComp.PalletsRate;
                dayComp.PickupCartonsAmount = dayComp.PickupCartons * dayComp.PickupCartonsRate;

                //2.2 Override: apply maximums to miles amount based upon trigger field (i.e. Trip, Stops, Cartons, Pallets)
                if (ratings.MaximumAmount > 0)
                {
                    //Maximum applies: find the MaximumTriggerField and compare it's value to MaximumTriggerValue
                    if (dayComp[ratings.MaximumTriggerField] != null)
                    {
                        int trigVal = Convert.ToInt32(dayComp[ratings.MaximumTriggerField]);
                        if (trigVal < ratings.MaximumTriggerValue)
                        {
                            dayComp.MilesAmount = ratings.MaximumAmount;
                        }
                    }
                }

                //2.3 Override: apply additional carton compensation for tractors in Ridgefield
                //01/27/10- remove per MK (as per Jean)
                //DateTime effDate = new DateTime(2009,5,17);
                //if(this.mStart.CompareTo(effDate) >= 0 && this.mAgentNumber == "0001" && dayComp.EquipmentTypeID == 4 && dayComp.Cartons > 699)
                //    dayComp.CartonsAmount += 0.15M * (dayComp.Cartons - 699);

                //3. Calculate totals and apply minimum amount
                decimal total = dayComp.DayAmount + dayComp.MilesAmount + dayComp.TripAmount + dayComp.StopsAmount + dayComp.CartonsAmount + dayComp.PalletsAmount + dayComp.PickupCartonsAmount;
                dayComp.TotalAmount = (total < dayComp.MinimunAmount) ? dayComp.MinimunAmount : total;
            }
            catch (Exception ex) { throw new ApplicationException("Unexpected error while rating.", ex); }
        }
Example #3
0
        public RouteRatings GetRouteRatings(string agentNumber, int equipmentTypeID, string route, decimal miles)
        {
            //Determine route ratings
            RouteRatings rates = new RouteRatings();

            try {
                DriverRatesDS.RateMileageRouteTableRow ratesMR = getMileRouteRates(agentNumber, route, miles);
                if (ratesMR != null)
                {
                    rates.RateTypeID          = RouteRatings.RATETYPE_ROUTE;
                    rates.MileBaseRate        = ratesMR.BaseRate;
                    rates.MileRate            = ratesMR.Rate;
                    rates.DayRate             = 0.0M;
                    rates.TripRate            = 0.0M;
                    rates.StopRate            = 0.0M;
                    rates.CartonRate          = 0.0M;
                    rates.PalletRate          = 0.0M;
                    rates.PickupCartonRate    = 0.0M;
                    rates.MinimumAmount       = 0.0M;
                    rates.MaximumAmount       = 0.0M;
                    rates.MaximumTriggerField = "";
                    rates.MaximumTriggerValue = 0;
                    rates.FSBase = 0.0M;
                }
                DriverRatesDS.RateUnitRouteTableRow ratesUR = getUnitRouteRates(agentNumber, route);
                if (ratesUR != null)
                {
                    rates.RateTypeID          = RouteRatings.RATETYPE_ROUTE;
                    rates.DayRate             = ratesUR.DayRate;
                    rates.TripRate            = ratesUR.MultiTripRate;
                    rates.StopRate            = ratesUR.StopRate;
                    rates.CartonRate          = ratesUR.CartonRate;
                    rates.PalletRate          = ratesUR.PalletRate;
                    rates.PickupCartonRate    = ratesUR.PickupCartonRate;
                    rates.MinimumAmount       = ratesUR.MinimumAmount;
                    rates.MaximumAmount       = ratesUR.MaximumAmount;
                    rates.MaximumTriggerField = ratesUR.MaximumTriggerField;
                    rates.MaximumTriggerValue = ratesUR.MaximumTriggerValue;
                    rates.FSBase = ratesUR.FSBase;
                }
                if (rates.RateTypeID == RouteRatings.RATETYPE_NONE)
                {
                    rates.RateTypeID = RouteRatings.RATETYPE_VEHICLE;
                    DriverRatesDS.RateMileageTableRow ratesMV = getMileRates(agentNumber, equipmentTypeID, miles);
                    if (ratesMV != null)
                    {
                        rates.MileBaseRate        = ratesMV.BaseRate;
                        rates.MileRate            = ratesMV.Rate;
                        rates.DayRate             = 0.0M;
                        rates.TripRate            = 0.0M;
                        rates.StopRate            = 0.0M;
                        rates.CartonRate          = 0.0M;
                        rates.PalletRate          = 0.0M;
                        rates.PickupCartonRate    = 0.0M;
                        rates.MinimumAmount       = 0.0M;
                        rates.MaximumAmount       = 0.0M;
                        rates.MaximumTriggerField = "";
                        rates.MaximumTriggerValue = 0;
                        rates.FSBase = 0.0M;
                    }
                    DriverRatesDS.RateUnitTableRow ratesUV = getUnitRates(agentNumber, equipmentTypeID);
                    if (ratesUV != null)
                    {
                        rates.DayRate             = ratesUV.DayRate;
                        rates.TripRate            = ratesUV.MultiTripRate;
                        rates.StopRate            = ratesUV.StopRate;
                        rates.CartonRate          = ratesUV.CartonRate;
                        rates.PalletRate          = ratesUV.PalletRate;
                        rates.PickupCartonRate    = ratesUV.PickupCartonRate;
                        rates.MinimumAmount       = ratesUV.MinimumAmount;
                        rates.MaximumAmount       = ratesUV.MaximumAmount;
                        rates.MaximumTriggerField = ratesUV.MaximumTriggerField;
                        rates.MaximumTriggerValue = ratesUV.MaximumTriggerValue;
                        rates.FSBase = ratesUV.FSBase;
                    }
                }
            }
            catch (Exception ex) { throw new ApplicationException("Unexpected error creating new DriverRates instance.", ex); }
            return(rates);
        }
Example #4
0
        public void ConvertRoadshowRoutes()
        {
            //Add all new (selected) Roadshow routes to the compensation package
            try {
                for (int i = 0; i < this.mRoutesDS.RoadshowRouteTable.Rows.Count; i++)
                {
                    //Check if new (i.e. selected by user)
                    DriverCompDS.RoadshowRouteTableRow _route = this.mRoutesDS.RoadshowRouteTable[i];
                    if (_route.New)
                    {
                        //Validate route depot matches this agent
                        if (_route.DepotNumber.ToString("0000") == this.mAgentNumber)
                        {
                            //Add operator summary (parent) record if required
                            if (this.mCompDS.DriverCompTable.Select("Operator='" + _route.Operator + "'").Length == 0)
                            {
                                //Add the summary record for this operator
                                DriverCompDS.DriverCompTableRow sumComp = this.mCompDS.DriverCompTable.NewDriverCompTableRow();
                                #region Set members
                                sumComp.Select          = true;
                                sumComp.IsNew           = sumComp.IsCombo = sumComp.IsAdjust = false;
                                sumComp.AgentNumber     = _route.DepotNumber.ToString("0000");
                                sumComp.FinanceVendorID = (!_route.IsFinanceVendIDNull() ? _route.FinanceVendID : "00000");
                                sumComp.FinanceVendor   = (!_route.IsPayeeNull() ? _route.Payee : "");
                                sumComp.Operator        = _route.Operator;
                                //sumComp.EquipmentTypeID = _route.EquipmentID;
                                sumComp.Miles         = sumComp.Trip = sumComp.Stops = sumComp.Cartons = sumComp.Pallets = sumComp.PickupCartons = 0;
                                sumComp.MilesAmount   = sumComp.DayAmount = sumComp.TripAmount = sumComp.StopsAmount = sumComp.CartonsAmount = sumComp.PalletsAmount = sumComp.PickupCartonsAmount = sumComp.Amount = 0.0M;
                                sumComp.FSCMiles      = 0;
                                sumComp.FuelCost      = sumComp.FSCGal = sumComp.FSCBaseRate = sumComp.FSC = 0.0M;
                                sumComp.MinimunAmount = sumComp.AdminCharge = sumComp.AdjustmentAmount1 = sumComp.AdjustmentAmount2 = sumComp.TotalAmount = 0.0M;
                                #endregion
                                this.mCompDS.DriverCompTable.AddDriverCompTableRow(sumComp);
                            }

                            //Validate daily route doesn't exist; add if doesn't exist
                            if (this.mCompDS.DriverRouteTable.Select("Operator='" + _route.Operator + "' AND RouteDate='" + _route.Rt_Date + "' AND RouteName='" + _route.Rt_Name + "'").Length == 0)
                            {
                                //Create daily compensation from the Roadshow route
                                DriverCompDS.DriverRouteTableRow dayComp = this.mCompDS.DriverRouteTable.NewDriverRouteTableRow();
                                #region Set members
                                dayComp.ID                      = 0;
                                dayComp.IsNew                   = false;
                                dayComp.IsCombo                 = false; //Do on refresh (this.mCompDS.DriverRouteTable.Select("Operator='" + _route.Operator + "' AND RouteDate='" + _route.Rt_Date + "'").Length > 1);
                                dayComp.IsAdjust                = false; //Do on refresh  _route.Rt_Name.Contains("ADJUST");
                                dayComp.AgentNumber             = _route.DepotNumber.ToString("0000");
                                dayComp.FinanceVendorID         = (!_route.IsFinanceVendIDNull() ? _route.FinanceVendID : "00000");
                                dayComp.EquipmentTypeID         = _route.EquipmentID;
                                dayComp.RouteDate               = _route.Rt_Date;
                                dayComp.RouteName               = _route.Rt_Name;
                                dayComp.Operator                = _route.Operator;
                                dayComp.Payee                   = (!_route.IsPayeeNull() ? _route.Payee : "");
                                dayComp.RateTypeID              = RouteRatings.RATETYPE_NONE;
                                dayComp.Miles                   = (!_route.IsTtlMilesNull()) ? _route.TtlMiles : 0;
                                dayComp.MilesBaseRate           = 0.0M;
                                dayComp.MilesRate               = 0.0M;
                                dayComp.MilesAmount             = 0.0M;
                                dayComp.DayRate                 = 0.0M;
                                dayComp.DayAmount               = 0.0M;
                                dayComp.Trip                    = (!_route.IsMultiTrpNull()) ? _route.MultiTrp : 0;
                                dayComp.TripRate                = 0.0M;
                                dayComp.TripAmount              = 0.0M;
                                dayComp.Stops                   = (!_route.IsUniqueStopsNull()) ? _route.UniqueStops : 0;
                                dayComp.StopsRate               = 0.0M;
                                dayComp.StopsAmount             = 0.0M;
                                dayComp.Cartons                 = (!_route.IsDelCtnsNull()) ? (int)_route.DelCtns : 0;
                                dayComp.CartonsRate             = 0.0M;
                                dayComp.CartonsAmount           = 0.0M;
                                dayComp.Pallets                 = (!_route.IsDelPltsorRcksNull()) ? (int)_route.DelPltsorRcks : 0;
                                dayComp.PalletsRate             = 0.0M;
                                dayComp.PalletsAmount           = 0.0M;
                                dayComp.PickupCartons           = (!_route.IsRtnCtnNull()) ? (int)_route.RtnCtn : 0;
                                dayComp.PickupCartonsRate       = 0.0M;
                                dayComp.PickupCartonsAmount     = 0.0M;
                                dayComp.FSCMiles                = 0;
                                dayComp.FSCGal                  = 0.0M;
                                dayComp.FSCBaseRate             = 0.0M;
                                dayComp.FSC                     = 0.0M;
                                dayComp.MinimunAmount           = 0.0M;
                                dayComp.AdminCharge             = 0.0M;
                                dayComp.AdjustmentAmount1       = 0.0M;
                                dayComp.AdjustmentAmount1TypeID = "";
                                dayComp.AdjustmentAmount2       = 0.0M;
                                dayComp.AdjustmentAmount2TypeID = "";
                                dayComp.TotalAmount             = 0.0M;
                                //dayComp.Imported = DateTime.Today;
                                //dayComp.Exported = ;
                                dayComp.ArgixRtType = _route.ArgixRtType;
                                dayComp.LastUpdated = DateTime.Today;
                                dayComp.UserID      = Environment.UserName;

                                #endregion

                                //Apply ratings and fuel surcharge to the daily compensation
                                RouteRatings ratings = this.mRates.GetRouteRatings(dayComp.EquipmentTypeID, dayComp.RouteName, dayComp.Miles);
                                if (!dayComp.IsAdjust)
                                {
                                    applyRates(dayComp, ratings);
                                }
                                calcFSC(dayComp, ratings);
                                this.mCompDS.DriverRouteTable.AddDriverRouteTableRow(dayComp);

                                //Update summary compensation
                                applyAdminFee(_route.Operator);
                                UpdateSummary(_route.Operator);
                            }
                            else
                            {
                                //Route exists
                                System.Windows.Forms.MessageBox.Show("Route exists for " + _route.Operator + " on " + _route.Rt_Date.ToShortDateString());
                            }
                            _route.New = false;
                        }
                        else
                        {
                            //Wrong terminal
                            System.Windows.Forms.MessageBox.Show("Route belongs to " + _route.Depot + " terminal.");
                        }
                    }
                }
                Save();
                RefreshRoadshowRoutes();
            }
            catch (ApplicationException ex) { throw ex; }
            catch (Exception ex) { throw new ApplicationException("Unexpected error while converting Roadshow routes to driver compensation...", ex); }
        }