Beispiel #1
0
        /// <summary>
        /// Derive Standard Conversions
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="C_UOM_ID"></param>
        /// <param name="C_UOM_To_ID"></param>
        /// <returns>Conversion or null</returns>
        public static Decimal?DeriveRate(Ctx ctx, int C_UOM_ID, int C_UOM_To_ID)
        {
            if (C_UOM_ID == C_UOM_To_ID)
            {
                return(Env.ONE);
            }
            //	get Info
            MUOM from = MUOM.Get(ctx, C_UOM_ID);
            MUOM to   = MUOM.Get(ctx, C_UOM_To_ID);

            if (from == null || to == null)
            {
                return(null);
            }

            //	Time - Minute
            if (from.IsMinute())
            {
                if (to.IsHour())
                {
                    return(new Decimal(1.0 / 60.0));
                }
                if (to.IsDay())
                {
                    return(new Decimal(1.0 / 1440.0));           //	24 * 60
                }
                if (to.IsWorkDay())
                {
                    return(new Decimal(1.0 / 480.0));            //	8 * 60
                }
                if (to.IsWeek())
                {
                    return(new Decimal(1.0 / 10080.0));          //	7 * 24 * 60
                }
                if (to.IsMonth())
                {
                    return(new Decimal(1.0 / 43200.0));          //	30 * 24 * 60
                }
                if (to.IsWorkMonth())
                {
                    return(new Decimal(1.0 / 9600.0));           //	4 * 5 * 8 * 60
                }
                if (to.IsYear())
                {
                    return(new Decimal(1.0 / 525600.0)); //	365 * 24 * 60
                }
            }
            //	Time - Hour
            if (from.IsHour())
            {
                if (to.IsMinute())
                {
                    return(new Decimal(60.0));
                }
                if (to.IsDay())
                {
                    return(new Decimal(1.0 / 24.0));
                }
                if (to.IsWorkDay())
                {
                    return(new Decimal(1.0 / 8.0));
                }
                if (to.IsWeek())
                {
                    return(new Decimal(1.0 / 168.0));            //	7 * 24
                }
                if (to.IsMonth())
                {
                    return(new Decimal(1.0 / 720.0));            //	30 * 24
                }
                if (to.IsWorkMonth())
                {
                    return(new Decimal(1.0 / 160.0));            //	4 * 5 * 8
                }
                if (to.IsYear())
                {
                    return(new Decimal(1.0 / 8760.0));           //	365 * 24
                }
            }
            //	Time - Day
            if (from.IsDay())
            {
                if (to.IsMinute())
                {
                    return(new Decimal(1440.0));                 //	24 * 60
                }
                if (to.IsHour())
                {
                    return(new Decimal(24.0));
                }
                if (to.IsWorkDay())
                {
                    return(new Decimal(3.0));                            //	24 / 8
                }
                if (to.IsWeek())
                {
                    return(new Decimal(1.0 / 7.0));                      //	7
                }
                if (to.IsMonth())
                {
                    return(new Decimal(1.0 / 30.0));             //	30
                }
                if (to.IsWorkMonth())
                {
                    return(new Decimal(1.0 / 20.0));             //	4 * 5
                }
                if (to.IsYear())
                {
                    return(new Decimal(1.0 / 365.0));            //	365
                }
            }
            //	Time - WorkDay
            if (from.IsWorkDay())
            {
                if (to.IsMinute())
                {
                    return(new Decimal(480.0));                  //	8 * 60
                }
                if (to.IsHour())
                {
                    return(new Decimal(8.0));                            //	8
                }
                if (to.IsDay())
                {
                    return(new Decimal(1.0 / 3.0));                      //	24 / 8
                }
                if (to.IsWeek())
                {
                    return(new Decimal(1.0 / 5));                        //	5
                }
                if (to.IsMonth())
                {
                    return(new Decimal(1.0 / 20.0));             //	4 * 5
                }
                if (to.IsWorkMonth())
                {
                    return(new Decimal(1.0 / 20.0));             //	4 * 5
                }
                if (to.IsYear())
                {
                    return(new Decimal(1.0 / 240.0));            //	4 * 5 * 12
                }
            }
            //	Time - Week
            if (from.IsWeek())
            {
                if (to.IsMinute())
                {
                    return(new Decimal(10080.0));                        //	7 * 24 * 60
                }
                if (to.IsHour())
                {
                    return(new Decimal(168.0));                  //	7 * 24
                }
                if (to.IsDay())
                {
                    return(new Decimal(7.0));
                }
                if (to.IsWorkDay())
                {
                    return(new Decimal(5.0));
                }
                if (to.IsMonth())
                {
                    return(new Decimal(1.0 / 4.0));                      //	4
                }
                if (to.IsWorkMonth())
                {
                    return(new Decimal(1.0 / 4.0));                      //	4
                }
                if (to.IsYear())
                {
                    return(new Decimal(1.0 / 50.0));             //	50
                }
            }
            //	Time - Month
            if (from.IsMonth())
            {
                if (to.IsMinute())
                {
                    return(new Decimal(43200.0));                        //	30 * 24 * 60
                }
                if (to.IsHour())
                {
                    return(new Decimal(720.0));                  //	30 * 24
                }
                if (to.IsDay())
                {
                    return(new Decimal(30.0));                   //	30
                }
                if (to.IsWorkDay())
                {
                    return(new Decimal(20.0));                   //	4 * 5
                }
                if (to.IsWeek())
                {
                    return(new Decimal(4.0));                            //	4
                }
                if (to.IsWorkMonth())
                {
                    return(new Decimal(1.5));                            //	30 / 20
                }
                if (to.IsYear())
                {
                    return(new Decimal(1.0 / 12.0));             //	12
                }
            }
            //	Time - WorkMonth
            if (from.IsWorkMonth())
            {
                if (to.IsMinute())
                {
                    return(new Decimal(9600.0));                 //	4 * 5 * 8 * 60
                }
                if (to.IsHour())
                {
                    return(new Decimal(160.0));                  //	4 * 5 * 8
                }
                if (to.IsDay())
                {
                    return(new Decimal(20.0));                   //	4 * 5
                }
                if (to.IsWorkDay())
                {
                    return(new Decimal(20.0));                   //	4 * 5
                }
                if (to.IsWeek())
                {
                    return(new Decimal(4.0));                            //	4
                }
                if (to.IsMonth())
                {
                    return(new Decimal(20.0 / 30.0));            //	20 / 30
                }
                if (to.IsYear())
                {
                    return(new Decimal(1.0 / 12.0));             //	12
                }
            }
            //	Time - Year
            if (from.IsYear())
            {
                if (to.IsMinute())
                {
                    return(new Decimal(518400.0));               //	12 * 30 * 24 * 60
                }
                if (to.IsHour())
                {
                    return(new Decimal(8640.0));                 //	12 * 30 * 24
                }
                if (to.IsDay())
                {
                    return(new Decimal(365.0));                  //	365
                }
                if (to.IsWorkDay())
                {
                    return(new Decimal(240.0));                  //	12 * 4 * 5
                }
                if (to.IsWeek())
                {
                    return(new Decimal(50.0));                   //	52
                }
                if (to.IsMonth())
                {
                    return(new Decimal(12.0));                   //	12
                }
                if (to.IsWorkMonth())
                {
                    return(new Decimal(12.0));                   //	12
                }
            }
            //
            return(null);
        }