private void applyFSC(DriverCompDataset.DriverRouteTableRow driverRoute, RouteRates rates) { //Calculate FSC if required try { //1. FSC applies only if miles rates are present in the rating if (rates.MileBaseRate > 0 || rates.MileRate > 0) { driverRoute.FSCMiles = driverRoute.Miles; } //2. Copy rates (for reference) driverRoute.FuelCost = this.mFuelCost; driverRoute.FSCGal = FinanceGateway.GetDriverEquipmentMPG(driverRoute.EquipmentTypeID); if (driverRoute.FSCGal <= 0.0M) { throw new ApplicationException("FSCGal (" + driverRoute.FSCGal.ToString() + "MPG) is invalid."); } driverRoute.FSCBaseRate = this.mTerminalConfig.FSBase; //3. Calculate FSC driverRoute.FSC = driverRoute.FSCMiles / driverRoute.FSCGal * (driverRoute.FuelCost - driverRoute.FSCBaseRate); if (driverRoute.FSC < 0) { driverRoute.FSC = 0.0M; } } catch (ApplicationException ex) { throw ex; } catch (Exception ex) { throw new ApplicationException(ex.Message, ex); } }
public RouteRates GetRates(int equipmentTypeID, string route, decimal miles) { //Determine rates for a single driver route RouteRates rates = new RouteRates(); try { DriverCompDataset.RateMileageRouteTableRow ratesMR = getRouteMileRates(route, miles); if (ratesMR != null) { rates.RateTypeID = RouteRates.RATETYPE_ROUTE; rates.MileBaseRate = ratesMR.BaseRate; rates.MileRate = ratesMR.Rate; } DriverCompDataset.RateUnitRouteTableRow ratesUR = getRouteUnitRates(route); if (ratesUR != null) { rates.RateTypeID = RouteRates.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 == RouteRates.RATETYPE_NONE) { rates.RateTypeID = RouteRates.RATETYPE_VEHICLE; DriverCompDataset.RateMileageTableRow ratesMV = getVehicleMileRates(equipmentTypeID, miles); if (ratesMV != null) { rates.MileBaseRate = ratesMV.BaseRate; rates.MileRate = ratesMV.Rate; } DriverCompDataset.RateUnitTableRow ratesUV = getVehicleUnitRates(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(ex.Message, ex); } return(rates); }
private void applyRates(DriverCompDataset.DriverRouteTableRow driverRoute, RouteRates rates) { //Apply rates to this route try { //1. Copy rates (for reference) driverRoute.RateTypeID = rates.RateTypeID; driverRoute.MilesBaseRate = rates.MileBaseRate; driverRoute.MilesRate = rates.MileRate; driverRoute.DayRate = rates.DayRate; driverRoute.TripRate = rates.TripRate; driverRoute.StopsRate = rates.StopRate; driverRoute.CartonsRate = rates.CartonRate; driverRoute.PalletsRate = rates.PalletRate; driverRoute.PickupCartonsRate = rates.PickupCartonRate; driverRoute.MinimunAmount = rates.MinimumAmount; //2. Calculate rates ------------------------------------------------------------- //2.1 Standard computations driverRoute.MilesAmount = driverRoute.MilesBaseRate + driverRoute.Miles * driverRoute.MilesRate; driverRoute.DayAmount = driverRoute.DayRate; driverRoute.TripAmount = driverRoute.Trip * driverRoute.TripRate; driverRoute.StopsAmount = driverRoute.Stops * driverRoute.StopsRate; driverRoute.CartonsAmount = driverRoute.Cartons * driverRoute.CartonsRate; driverRoute.PalletsAmount = driverRoute.Pallets * driverRoute.PalletsRate; driverRoute.PickupCartonsAmount = driverRoute.PickupCartons * driverRoute.PickupCartonsRate; //2.2 Override: apply maximums to miles amount based upon trigger field (i.e. Trip, Stops, Cartons, Pallets) if (rates.MaximumAmount > 0) { //Maximum applies: find the MaximumTriggerField and compare it's value to MaximumTriggerValue if (driverRoute[rates.MaximumTriggerField] != null) { int trigVal = Convert.ToInt32(driverRoute[rates.MaximumTriggerField]); if (trigVal < rates.MaximumTriggerValue) { driverRoute.MilesAmount = rates.MaximumAmount; } } } //3. Calculate totals and apply minimum amount decimal total = driverRoute.DayAmount + driverRoute.MilesAmount + driverRoute.TripAmount + driverRoute.StopsAmount + driverRoute.CartonsAmount + driverRoute.PalletsAmount + driverRoute.PickupCartonsAmount; driverRoute.TotalAmount = (total < driverRoute.MinimunAmount) ? driverRoute.MinimunAmount : total; } catch (Exception ex) { throw new ApplicationException(ex.Message, ex); } }
public void CreateCompensation() { //Add all new (selected) imported routes to the driver compensation try { for (int i = 0; i < this.mRoutes.RoadshowRouteTable.Rows.Count; i++) { //Check if a new route (i.e. selected by user) DriverCompDataset.RoadshowRouteTableRow route = this.mRoutes.RoadshowRouteTable[i]; if (route.New) { //Validate route depot matches this agent if (route.DepotNumber.ToString("0000") == this.mAgentNumber) { //Add driver compensation (parent) record if required if (this.mCompensation.DriverCompTable.Select("Operator='" + route.Operator + "'").Length == 0) { //Add a driver compensation for this operator DriverCompDataset.DriverCompTableRow driverComp = this.mCompensation.DriverCompTable.NewDriverCompTableRow(); #region Initialize members driverComp.Select = true; driverComp.IsNew = driverComp.IsCombo = driverComp.IsAdjust = false; driverComp.AgentNumber = route.DepotNumber.ToString("0000"); driverComp.FinanceVendorID = (!route.IsFinanceVendIDNull() ? route.FinanceVendID : "00000"); driverComp.FinanceVendor = (!route.IsPayeeNull() ? route.Payee : ""); driverComp.Operator = route.Operator; //driverComp.EquipmentTypeID = route.EquipmentID; driverComp.Miles = driverComp.Trip = driverComp.Stops = driverComp.Cartons = driverComp.Pallets = driverComp.PickupCartons = 0; driverComp.MilesAmount = driverComp.DayAmount = driverComp.TripAmount = driverComp.StopsAmount = driverComp.CartonsAmount = driverComp.PalletsAmount = driverComp.PickupCartonsAmount = driverComp.Amount = 0.0M; driverComp.FSCMiles = 0; driverComp.FuelCost = driverComp.FSCGal = driverComp.FSCBaseRate = driverComp.FSC = 0.0M; driverComp.MinimunAmount = driverComp.AdminCharge = driverComp.AdjustmentAmount1 = driverComp.AdjustmentAmount2 = driverComp.TotalAmount = 0.0M; #endregion this.mCompensation.DriverCompTable.AddDriverCompTableRow(driverComp); } //Validate driver route doesn't exist; add if doesn't exist if (this.mCompensation.DriverRouteTable.Select("Operator='" + route.Operator + "' AND RouteDate='" + route.Rt_Date + "' AND RouteName='" + route.Rt_Name + "'").Length == 0) { //Create a driver route from the Roadshow route DriverCompDataset.DriverRouteTableRow driverRoute = this.mCompensation.DriverRouteTable.NewDriverRouteTableRow(); #region Set members driverRoute.ID = 0; driverRoute.IsNew = false; driverRoute.IsCombo = (this.mRoutes.RoadshowRouteTable.Select("Operator='" + route.Operator + "' AND Rt_Date='" + route.Rt_Date + "'").Length > 1); driverRoute.IsAdjust = route.Rt_Name.Contains("ADJUST"); driverRoute.AgentNumber = route.DepotNumber.ToString("0000"); driverRoute.FinanceVendorID = (!route.IsFinanceVendIDNull() ? route.FinanceVendID : "00000"); driverRoute.EquipmentTypeID = route.EquipmentID; driverRoute.RouteIndex = route.RouteIndex; driverRoute.RouteDate = route.Rt_Date; driverRoute.RouteName = route.Rt_Name; driverRoute.Operator = route.Operator; driverRoute.OperatorHireDate = route.OperatorHireDate; driverRoute.Payee = (!route.IsPayeeNull() ? route.Payee : ""); driverRoute.RateTypeID = RouteRates.RATETYPE_NONE; driverRoute.Miles = (!route.IsTtlMilesNull()) ? route.TtlMiles : 0; driverRoute.MilesBaseRate = 0.0M; driverRoute.MilesRate = 0.0M; driverRoute.MilesAmount = 0.0M; driverRoute.DayRate = 0.0M; driverRoute.DayAmount = 0.0M; driverRoute.Trip = (!route.IsMultiTrpNull()) ? route.MultiTrp : 0; driverRoute.TripRate = 0.0M; driverRoute.TripAmount = 0.0M; driverRoute.Stops = (!route.IsUniqueStopsNull()) ? route.UniqueStops : 0; driverRoute.StopsRate = 0.0M; driverRoute.StopsAmount = 0.0M; driverRoute.Cartons = (!route.IsDelCtnsNull()) ? (int)route.DelCtns : 0; driverRoute.CartonsRate = 0.0M; driverRoute.CartonsAmount = 0.0M; driverRoute.Pallets = (!route.IsDelPltsorRcksNull()) ? (int)route.DelPltsorRcks : 0; driverRoute.PalletsRate = 0.0M; driverRoute.PalletsAmount = 0.0M; driverRoute.PickupCartons = (!route.IsRtnCtnNull()) ? (int)route.RtnCtn : 0; driverRoute.PickupCartonsRate = 0.0M; driverRoute.PickupCartonsAmount = 0.0M; driverRoute.FSCMiles = 0; driverRoute.FSCGal = 0.0M; driverRoute.FSCBaseRate = 0.0M; driverRoute.FSC = 0.0M; driverRoute.MinimunAmount = 0.0M; driverRoute.AdminCharge = 0.0M; driverRoute.AdjustmentAmount1 = 0.0M; driverRoute.AdjustmentAmount1TypeID = ""; driverRoute.AdjustmentAmount2 = 0.0M; driverRoute.AdjustmentAmount2TypeID = ""; driverRoute.TotalAmount = 0.0M; //driverRoute.Imported = ; //driverRoute.Exported = ; driverRoute.ArgixRtType = route.ArgixRtType; driverRoute.LastUpdated = DateTime.Today; driverRoute.UserID = Environment.UserName; #endregion //Apply rates and FSC to the current route RouteRates rates = this.mRates.GetRates(driverRoute.EquipmentTypeID, driverRoute.RouteName, driverRoute.Miles); if (!driverRoute.IsAdjust) { applyRates(driverRoute, rates); } applyFSC(driverRoute, rates); //Add route to rated routes this.mCompensation.DriverRouteTable.AddDriverRouteTableRow(driverRoute); //Apply fees to the current route based upon all routes for this driver applyFees(route.Operator); //Apply bonus to the current route based upon all routes for this driver applyBonus(route.Operator); //Update driver compensation for all routes for the current driver CalculateCompensation(route.Operator, false); } else { //Route exists MessageBox.Show("Route exists for " + route.Operator + " on " + route.Rt_Date.ToShortDateString()); } route.New = false; } else { //Wrong terminal System.Windows.Forms.MessageBox.Show("Route " + route.Rt_Name + " belongs to " + route.Depot + " terminal."); } } } SaveCompensation(); ImportRoutes(); } catch (ApplicationException ex) { throw ex; } catch (Exception ex) { throw new ApplicationException(ex.Message, ex); } }