示例#1
0
 public static int MassUserOverBudgetPercent(BudgetType budgetType)
 {
     return(DefaultThrottlingAlertValues.SafeGetValueFromMap(DefaultThrottlingAlertValues.massUserOverBudgetPercentMap, budgetType, 50));
 }
示例#2
0
 // Token: 0x0600722B RID: 29227 RVA: 0x0017A1D8 File Offset: 0x001783D8
 internal static string BuildMicroDelayMultiplierKey(BudgetType budgetType)
 {
     return(string.Format("{0}.{1}", budgetType, "MaxMicroDelayMultiplier"));
 }
示例#3
0
 // Token: 0x0600722D RID: 29229 RVA: 0x0017A206 File Offset: 0x00178406
 internal static string BuildMaxDelayedThreadsKey(BudgetType budgetType)
 {
     return(string.Format("{0}.{1}", budgetType, "MaxDelayedThreadsPerProcessor"));
 }
示例#4
0
 public BudgetEntryBiMonthly(double amount, int month, string label, BudgetType budgetType)
     : base(amount, label, budgetType)
 {
     this.Odd = IsOdd(month);
 }
示例#5
0
 public static bool IsIncome(BudgetType type)
 {
     return(new BudgetCategory(type).MainCategory == "Income");
 }
示例#6
0
 public KgsaBudgetProduct(BudgetType product, BudgetValueType type)
 {
     this.product = product;
     this.mainType = type;
     fields = new List<KgsaBudgetField>() { };
 }
示例#7
0
 public BudgetEntryWeekly(double amount, string label, BudgetType budgetType) : this(amount, label, budgetType, 1, "Jan 1")
 {
 }
示例#8
0
文件: Budget.cs 项目: tborgund/kgsa
 public BudgetValueType ProductToType(BudgetType product)
 {
     if (product == BudgetType.Vinnprodukt)
         return BudgetValueType.Poeng;
     else if (product == BudgetType.Strom)
         return strom_type;
     else if (product == BudgetType.TA)
         return ta_type;
     else if (product == BudgetType.Rtgsa)
         return rtgsa_type;
     else if (product == BudgetType.Finans)
         return finans_type;
     else if (product == BudgetType.Acc)
         return acc_type;
     else
         return BudgetValueType.Antall;
 }
示例#9
0
文件: Budget.cs 项目: tborgund/kgsa
        public string GetProductColor(BudgetType type)
        {
            if (type == BudgetType.Vinnprodukt)
                return "#4cad88";
            if (type == BudgetType.Finans)
                return "#f5954e";
            if (type == BudgetType.TA)
                return "#6699ff";
            if (type == BudgetType.Strom)
                return "#FAF39E";
            if (type == BudgetType.Rtgsa)
                return "#80c34a";
            if (type == BudgetType.Acc)
                return "#f36565";
            if (type == BudgetType.Inntjening)
                return "#ff5b2e";
            if (type == BudgetType.Omsetning)
                return "#ff5b2e";

             return "#f5954e";
        }
示例#10
0
 public IList <Income> GetIncomeByBudgetType(BudgetType budgetType, IList <Income> incomeToFilterBy)
 {
     return(incomeToFilterBy.Where(i => i.BudgetType == budgetType).ToList());
 }
示例#11
0
文件: Budget.cs 项目: tborgund/kgsa
        private Bitmap DrawChartData(int argX, int argY, BudgetValueType type, BudgetType product, List<BudgetChartData> list)
        {
            Bitmap b = new Bitmap(argX, argY);
            using (Graphics g = Graphics.FromImage(b))
            {
                try
                {
                    float dpi = 1;

                    g.SmoothingMode = SmoothingMode.AntiAlias;
                    g.Clear(Color.White);
                    if (list.Count == 0)
                    {
                        g.DrawString("Mangler info!", new Font("Verdana", 30, FontStyle.Bold), new SolidBrush(Color.Red), 400, 0);
                        return b;
                    }

                    float offsetTop = 20;
                    float offsetLeft = 25;
                    float offsetBottom = 35;
                    float X = argX;
                    float Y = argY;

                    PointF p1, p2;
                    SolidBrush bBrush = new SolidBrush(Color.Gray);
                    Pen pen = new Pen(Color.Black, 3 * dpi);
                    Font fontNormal = new Font("Helvetica", 22 * dpi, FontStyle.Regular);
                    Color resultColor = System.Drawing.ColorTranslator.FromHtml(GetProductColor(product));
                    Color resultColorDark = Tint(System.Drawing.ColorTranslator.FromHtml(GetProductColor(product)), Color.Black, 0.5M);

                    Color targetColor = System.Drawing.ColorTranslator.FromHtml("#1163b0");
                    Color targetColorDark = System.Drawing.ColorTranslator.FromHtml("#004586");

                    int count = list.Count;
                    if (count < main.appConfig.budgetChartMinPosts)
                        count = main.appConfig.budgetChartMinPosts;

                    int maxI = 0, mI = 0;
                    for (int i = 0; i < list.Count; i++)
                    {
                        mI = Convert.ToInt32(list[i].actual);
                        if (mI > maxI)
                            maxI = mI;

                        mI = Convert.ToInt32(list[i].target);
                        if (mI > maxI)
                            maxI = mI;
                    }

                    float innject = 200 * dpi;
                    float maxW = X - (X / 8) - innject;
                    float Vstep = (Y - 100) / count;

                    int roundTo = 1000;

                    if (maxI > 1000000)
                        roundTo = 125000;
                    else if (maxI > 500000)
                        roundTo = 100000;
                    else if (maxI > 100000)
                        roundTo = 40000;
                    else if (maxI > 50000)
                        roundTo = 10000;
                    else if (maxI > 25000)
                        roundTo = 5000;
                    else if (maxI > 5000)
                        roundTo = 1000;
                    else if (maxI > 1000)
                        roundTo = 500;
                    else if (maxI > 250)
                        roundTo = 50;
                    else if (maxI > 150)
                        roundTo = 25;
                    else if (maxI > 100)
                        roundTo = 20;
                    else if (maxI > 50)
                        roundTo = 10;
                    else if (maxI > 25)
                        roundTo = 5;
                    else if (maxI > 10)
                        roundTo = 2;
                    else if (maxI > 1)
                        roundTo = 1;

                    for (int i = 0; i < 100; i++)
                    {
                        float someNumber = maxI - (roundTo * i);
                        int closest = (int)((someNumber + (0.5 * roundTo)) / roundTo) * roundTo;
                        float wI = maxW * ((float)closest / (float)maxI);
                        if (float.IsNaN(wI) || float.IsInfinity(wI))
                            wI = 1;
                        if (closest < 0)
                            break;

                        g.DrawLine(new Pen(Color.LightGray, 5 * dpi), new PointF(wI + offsetLeft + innject, 0 + offsetTop), new PointF(wI + offsetLeft + innject, Y - offsetBottom));
                        g.DrawString(ForkortTallBudget(closest) + " " + GetValueTypeSuffix(type), new Font("Verdana", 20 * dpi, FontStyle.Regular), new SolidBrush(Color.Black), wI + offsetLeft + innject, Y - offsetBottom);
                    }

                    System.Drawing.StringFormat drawFormat = new System.Drawing.StringFormat(StringFormatFlags.DirectionVertical);
                    g.DrawString(ProductToString(product), new Font("Verdana", 38 * dpi, FontStyle.Bold), new SolidBrush(Color.Gray), X - (100 * dpi), 30, drawFormat);

                    for (int i = 0; i < count; i++)
                    {
                        if (list.Count > i)
                        {
                            string selger = list[i].selgerkode;
                            decimal actual = list[i].actual;
                            decimal target = list[i].target;

                            float x = offsetLeft + innject;
                            float y = Vstep * i + offsetTop;
                            float y2 = Vstep * i + offsetTop + (Vstep / 5);

                            p1 = new PointF(x, y);
                            p2 = new PointF(x, y2);

                            float wI = maxW * ((float)actual / (float)maxI);
                            float wIT = maxW * ((float)target / (float)maxI);

                            if (float.IsNaN(wI) || float.IsInfinity(wI))
                                wI = 1;
                            if (float.IsNaN(wIT) || float.IsInfinity(wIT))
                                wIT = 1;

                            g.DrawString(main.salesCodes.GetNavn(selger), fontNormal, new SolidBrush(Color.Black), new PointF(x + 10 - innject, Vstep * i + offsetTop + (Vstep / 10)));

                            if (type != BudgetValueType.Hitrate && type != BudgetValueType.SoB && type != BudgetValueType.SoM)
                            {
                                g.FillRectangle(new SolidBrush(targetColor), new RectangleF(p2, new SizeF(wIT, Vstep / 1.5f)));
                                g.DrawRectangle(new Pen(targetColorDark, 3 * dpi), x, y2, wIT, Vstep / 1.5f);
                            }

                            g.FillRectangle(new SolidBrush(resultColor), new RectangleF(p1, new SizeF(wI, Vstep / 1.5f)));
                            g.DrawRectangle(new Pen(resultColorDark, 3 * dpi), x, y, wI, Vstep / 1.5f);
                            if (actual > 0)
                            {

                                GraphicsPath path = new GraphicsPath();

                                string strTall = "";
                                if (type != BudgetValueType.Hitrate && type != BudgetValueType.SoB && type != BudgetValueType.SoM)
                                    strTall = ForkortTallBudget(actual) + " " + GetValueTypeSuffix(type);
                                else
                                    strTall = Math.Round(actual, 2).ToString() + " %";

                                path.AddString(strTall, new FontFamily("Helvetica"), (int)FontStyle.Bold, 28f * dpi, new PointF(wI + innject + offsetLeft + (5 * dpi), Vstep * i + offsetTop + (Vstep / 10)), StringFormat.GenericDefault);

                                for (int c = 1; c < 8; ++c)
                                {
                                    Pen pen3 = new Pen(Color.FromArgb(32, 255, 255, 255), c);
                                    pen3.LineJoin = LineJoin.Round;
                                    g.DrawPath(pen3, path);
                                    pen3.Dispose();
                                }

                                SolidBrush brush = new SolidBrush(Color.FromArgb(0, 0, 0));
                                g.FillPath(brush, path);
                            }
                        }
                        else // Hvis ingen flere selgere, vis tomme felt
                        {
                            // Nothing to do..
                        }
                    }

                    if (type == BudgetValueType.Hitrate || type == BudgetValueType.SoB || type == BudgetValueType.SoM)
                    {
                        float wI = maxW * ((float)list[0].target / (float)maxI);
                        g.DrawLine(new Pen(Color.Red, 10 * dpi), new PointF(wI + offsetLeft + innject, 0 + offsetTop), new PointF(wI + offsetLeft + innject, Y - offsetBottom));
                    }

                }
                catch
                {
                }
            }
            return b;
        }
示例#12
0
 public IList <Income> GetIncomeByBudgetType(BudgetType budgetType)
 {
     return(incomeRepository.GetBy(i => i.BudgetType == budgetType));
 }
        /// <summary>
        /// Constructs a new instance of NMCTSBot with default strategies.
        /// </summary>
        /// <param name="allowPerfectInformation">[Optional] Whether or not this bot is allowed perfect information about the game state (i.e. no obfuscation and therefore no determinisation). Default value is false.</param>
        /// <param name="ensembleSize">[Optional] The size of the ensemble to use. Default value is 1.</param>
        /// <param name="playoutBotType">[Optional] The type of playout bot to be used during playouts. Default value is <see cref="PlayoutBotType.MAST"/>.</param>
        /// <param name="mastSelectionType">[Optional] The type of selection strategy used by the MAST playout. Default value is <see cref="MASTPlayoutBot.SelectionType.EGreedy"/>.</param>
        /// <param name="budgetType">[Optional] The type of budget that this bot will use. Default value is <see cref="BudgetType.Iterations"/>.</param>
        /// <param name="iterations">[Optional] The budget for the amount of iterations NMCTS can use. Default value is <see cref="Constants.DEFAULT_COMPUTATION_ITERATION_BUDGET"/>.</param>
        /// <param name="time">[Optional] The budget for the amount of milliseconds NMCTS can spend on searching. Default value is <see cref="Constants.DEFAULT_COMPUTATION_TIME_BUDGET"/>.</param>
        /// <param name="playoutTurnCutoff">[Optional] The amount of turns after which to stop a simulation. Default value is <see cref="Constants.DEFAULT_PLAYOUT_TURN_CUTOFF"/>.</param>
        /// <param name="globalPolicy">[Optional] The exploration-threshold for the e-greedy global policy. Default value is <see cref="Constants.DEFAULT_NMCTS_GLOBAL_POLICY"/>.</param>
        /// <param name="localPolicy">[Optional] The exploration-threshold for the e-greedy local policy. Default value is <see cref="Constants.DEFAULT_NMCTS_LOCAL_POLICY"/>.</param>
        /// <param name="useHeuristicEvaluation">[Optional] Whether or not to use the HeuristicBot's evaluation function. Default value is false.</param>
        /// <param name="debugInfoToConsole">[Optional] Whether or not to write debug information to the console. Default value is false.</param>
        public NMCTSBot(bool allowPerfectInformation  = false,
                        int ensembleSize              = 1,
                        PlayoutBotType playoutBotType = PlayoutBotType.MAST,
                        MASTPlayoutBot.SelectionType mastSelectionType = MASTPlayoutBot.SelectionType.EGreedy,
                        BudgetType budgetType       = BudgetType.Iterations,
                        int iterations              = Constants.DEFAULT_COMPUTATION_ITERATION_BUDGET,
                        long time                   = Constants.DEFAULT_COMPUTATION_TIME_BUDGET,
                        int playoutTurnCutoff       = Constants.DEFAULT_PLAYOUT_TURN_CUTOFF,
                        double globalPolicy         = Constants.DEFAULT_NMCTS_GLOBAL_POLICY,
                        double localPolicy          = Constants.DEFAULT_NMCTS_LOCAL_POLICY,
                        bool useHeuristicEvaluation = false,
                        bool debugInfoToConsole     = false)
        {
            PerfectInformation = allowPerfectInformation;
            EnsembleSize       = ensembleSize;
            PlayoutBotType     = playoutBotType;
            MASTSelectionType  = mastSelectionType;
            BudgetType         = budgetType;
            Iterations         = iterations;
            Time = time;
            PlayoutTurnCutoff = playoutTurnCutoff;
            GlobalPolicy      = globalPolicy;
            LocalPolicy       = localPolicy;
            _debug            = debugInfoToConsole;

            // Create the ensemble search
            Ensemble = new EnsembleStrategySabberStone(enableStateObfuscation: true, enablePerfectInformation: PerfectInformation);

            // Simulation will be handled by the Playout
            var sabberStoneStateEvaluation = new EvaluationStrategyHearthStone(useHeuristicEvaluation);

            Playout = new PlayoutStrategySabberStone();

            // Set the playout bots
            switch (PlayoutBotType)
            {
            case PlayoutBotType.Random:
                MyPlayoutBot       = new RandomBot(filterDuplicatePositionTasks: true);
                OpponentPlayoutBot = new RandomBot(filterDuplicatePositionTasks: true);
                break;

            case PlayoutBotType.Heuristic:
                MyPlayoutBot       = new HeuristicBot();
                OpponentPlayoutBot = new HeuristicBot();
                break;

            case PlayoutBotType.MAST:
                MyPlayoutBot       = new MASTPlayoutBot(MASTSelectionType, sabberStoneStateEvaluation);
                OpponentPlayoutBot = new MASTPlayoutBot(MASTSelectionType, sabberStoneStateEvaluation);
                break;

            default:
                throw new InvalidEnumArgumentException($"PlayoutBotType `{PlayoutBotType}' is not supported.");
            }

            // And the random sampling bot
            RandomSamplingBot = new RandomBot(filterDuplicatePositionTasks: true);

            // We'll be cutting off the simulations after X turns, using a GoalStrategy
            Goal = new GoalStrategyTurnCutoff(PlayoutTurnCutoff);

            // Application and Goal will be handled by the GameLogic
            GameLogic = new SabberStoneGameLogic(Goal, false);

            // Build NMCTS
            Builder = NMCTS <List <SabberStoneAction>, SabberStoneState, SabberStoneAction, object, SabberStoneAction> .Builder();

            Builder.ExplorationStrategy = new ChanceExploration <List <SabberStoneAction>, SabberStoneState, SabberStoneAction, object, SabberStoneAction>(LocalPolicy);
            Builder.PlayoutStrategy     = Playout;
            Builder.PolicyGlobal        = GlobalPolicy;
            Builder.SamplingStrategy    = new SabberStoneNMCSamplingStrategy(RandomSamplingBot);
            Builder.SolutionStrategy    = new SolutionStrategySabberStone(false, new AverageScore <SabberStoneState, SabberStoneAction>());
            Builder.EvaluationStrategy  = sabberStoneStateEvaluation;
            switch (BudgetType)
            {
            case BudgetType.Iterations:
                Builder.Iterations = EnsembleSize > 0 ? Iterations / EnsembleSize : Iterations;     // Note: Integer division by design.
                break;

            case BudgetType.Time:
                Builder.Time = EnsembleSize > 0 ? Time / EnsembleSize : Time;     // Note: Integer division by design.
                break;

            default:
                throw new InvalidEnumArgumentException($"BudgetType `{BudgetType}' is not supported.");
            }
        }
示例#14
0
        // Token: 0x0600746D RID: 29805 RVA: 0x0017FEC4 File Offset: 0x0017E0C4
        public static IStandardBudget AcquireUnthrottledBudget(string identifier, BudgetType budgetType)
        {
            UnthrottledBudgetKey budgetKey = new UnthrottledBudgetKey(identifier, budgetType);

            return(StandardBudget.Acquire(budgetKey));
        }
示例#15
0
 internal abstract bool AddRecord(decimal amount, Category category, BudgetType budgetType, int onDay, int selectedMonth, int selectedYear, out BudgetRecord newRecord);
示例#16
0
文件: Budget.cs 项目: tborgund/kgsa
        public string ProductToString(BudgetType type)
        {
            if (type == BudgetType.Vinnprodukt)
                return "Vinnprodukt";
            if (type == BudgetType.Acc)
                return "Tilbehør";
            if (type == BudgetType.Finans)
                return "Finansiering";
            if (type == BudgetType.Rtgsa)
                return "RTG/SA";
            if (type == BudgetType.Strom)
                return "Norges Energi";
            if (type == BudgetType.TA)
                return "Trygghetsavtale";
            if (type == BudgetType.Inntjening)
                return "Inntjening";
            if (type == BudgetType.Omsetning)
                return "Omsetning";
            if (type == BudgetType.Kvalitet)
                return "Kvalitet";
            if (type == BudgetType.Effektivitet)
                return "Effektivitet";

            return "Ukjent";
        }
 // Token: 0x060072B2 RID: 29362 RVA: 0x0017B906 File Offset: 0x00179B06
 public LookupBudgetKey(BudgetType budgetType, bool isServiceAccount) : base(budgetType, isServiceAccount)
 {
 }
示例#18
0
文件: Budget.cs 项目: tborgund/kgsa
 public void SaveChartImage(int argX, int argY, string argFilename, BudgetValueType type, BudgetType product, List<BudgetChartData> list)
 {
     Bitmap graphBitmap = DrawChartData(argX, argY, type, product, list);
     if (graphBitmap != null)
     {
         graphBitmap.Save(argFilename, ImageFormat.Png);
         graphBitmap.Dispose();
     }
 }
示例#19
0
        // Token: 0x0600746C RID: 29804 RVA: 0x0017FEA8 File Offset: 0x0017E0A8
        public static IStandardBudget AcquireFallback(string identifier, BudgetType budgetType)
        {
            StringBudgetKey budgetKey = new StringBudgetKey(identifier, false, budgetType);

            return(StandardBudget.Acquire(budgetKey));
        }
示例#20
0
 public static void CreateMonthly(BudgetType budgetType, string label, double amount)
 {
     _budget.AddEntry(new BudgetEntryMonthly(amount, label, budgetType));
 }
示例#21
0
 public BudgetEntryMonthly(double amount, string label, BudgetType budgetType)
     : base(amount, label, budgetType)
 {
 }
示例#22
0
 public static void CreateAnnual(BudgetType budgetType, string label, double amount, int month)
 {
     _budget.AddEntry(new BudgetEntryAnnual(amount, month, label, budgetType));
 }
示例#23
0
        public static string Serialize(BudgetType budgetType)
        {
            var category = GetBudgetCategory(budgetType);

            return(string.IsNullOrWhiteSpace(category.SubCategory) ? category.MainCategory : $"{category.MainCategory}:{category.SubCategory}");
        }
示例#24
0
 internal static void CreateWeekly(BudgetType budgetType, string label, double amount, int period = 1, string start = "Jan 4", int max = 52)
 {
     _budget.AddEntry(new BudgetEntryWeekly(amount, label, budgetType, period, start, max));
 }
示例#25
0
 public static BudgetCategory GetBudgetCategory(BudgetType budgetType)
 {
     return(_budgetCategory[budgetType]);
 }
示例#26
0
 internal static void CreateDaily(BudgetType budgetType, string label, double amount, string start = "Jan 1")
 {
     _budget.AddEntry(new BudgetEntryDaily(amount, label, budgetType, start));
 }
示例#27
0
 // Token: 0x0600722C RID: 29228 RVA: 0x0017A1EF File Offset: 0x001783EF
 internal static string BuildMaxDelayKey(BudgetType budgetType)
 {
     return(string.Format("{0}.{1}", budgetType, "MaxDelayInSeconds"));
 }
示例#28
0
 static void GetCommonParameters(ref string[] components, out double amount, out string label, out BudgetType budgetType)
 {
     budgetType = BudgetCategoryFactory.DeSerialize(components[0]);
     amount     = double.Parse(components[1]);
     label      = components[2];
     components = components.Skip(3).ToArray();
 }
示例#29
0
 public static int DelayTimeThreshold(BudgetType budgetType)
 {
     return(DefaultThrottlingAlertValues.SafeGetValueFromMap(DefaultThrottlingAlertValues.delayTimeThresholdMap, budgetType, 10000));
 }
示例#30
0
 public BudgetEntryBiMonthly(double amount, bool odd, string label, BudgetType budgetType)
     : base(amount, label, budgetType)
 {
     this.Odd = odd;
 }
 /// <summary>
 /// Constructs a new instance of a TournamentMatch with a specific GameConfig between two bots.
 /// Note: the order of the bots does not reflect the playing order in the match's games. (starting player is alternated)
 /// </summary>
 /// <param name="bot1Setup">The setup for the first bot.</param>
 /// <param name="bot2Setup">The setup for the second bot.</param>
 /// <param name="numberOfGames">The amount of games that should be played in this match.</param>
 /// <param name="budgetType">The type of budget that this match will be limited on.</param>
 /// <param name="budgetLimit">The amount of budget that is available to the players, relative to the <see cref="BudgetType"/>.</param>
 /// <param name="printToConsole">[Optional] Whether or not to print game information to the Console.</param>
 public TournamentMatch(BotSetupType bot1Setup, BotSetupType bot2Setup, int numberOfGames, BudgetType budgetType, long budgetLimit, bool printToConsole = false)
 {
     Bots = new List <ISabberStoneBot> {
         BotFactory.CreateSabberStoneBot(bot1Setup), BotFactory.CreateSabberStoneBot(bot2Setup)
     };
     NumberOfGames   = numberOfGames;
     BudgetType      = budgetType;
     BudgetLimit     = (long)(budgetLimit * 1.02); // I'll allow a 2% margin on the budget limitation.
     MatchStatistics = new MatchStatistics($"{bot1Setup.ToString()}[{Constants.SABBERSTONE_GAMECONFIG_PLAYER1_NAME}]", $"{bot2Setup.ToString()}[{Constants.SABBERSTONE_GAMECONFIG_PLAYER2_NAME}]", numberOfGames, BudgetType, BudgetLimit);
     _printToConsole = printToConsole;
 }
示例#32
0
 public BudgetEntryAnnual(double amount, int month, string label, BudgetType budgetType)
     : base(amount, label, budgetType)
 {
     Month = month;
 }
示例#33
0
 internal abstract bool UpdateRecord(BudgetRecord record, decimal amount, Category category, BudgetType budgetType, int onDay, int selectedMonth, int selectedYear);
示例#34
0
 public BudgetEntryWeekly(double amount, string label, BudgetType budgetType, int period, string start) : this(amount, label, budgetType, period, start, 52)
 {
 }
示例#35
0
        public List<string> GetTableHtmlProduct(BudgetCategory cat, BudgetType product)
        {
            try
            {
                var doc = new List<string>();
                if (StopRankingPending())
                    return doc;
                var hashId = random.Next(999, 99999);

                string urlID = "link";
                doc.Add("<br>");
                doc.Add("<a name='" + budget.ProductToString(product) + "'></a>");

                budgetInfo = budget.GetBudgetInfo(dtTil, cat);
                if (budgetInfo == null)
                {
                    doc.Add("<span class='Subtitle' style='color:red !important;'>Budsjett for " + BudgetCategoryClass.TypeToName(cat) + " mangler for valgt måned.</span><br>");
                    return doc;
                }
                if (budgetInfo.selgere.Count == 0)
                {
                    doc.Add("<span class='Subtitle' style='color:red !important;'>Ingen selgerkoder er satt opp for " + BudgetCategoryClass.TypeToName(cat) + " budsjettet.</span><br>");
                    return doc;
                }
                BudgetValueType type = budgetInfo.ProductToType(product);
                DataTable dtBudgetProduct = MakeTableBudgetProduct(cat, product, type);
                string productColor = budget.GetProductColor(product);

                DateTime date = dtTil;
                if (date > main.appConfig.dbTo)
                    date = main.appConfig.dbTo;

                doc.Add("<h2>Resultat for " + budget.ProductToString(product) + " - " + BudgetCategoryClass.TypeToName(cat) + " budsjett oppdatert " + date.ToString("dddd d. MMMM yyyy", FormMain.norway) + " og timeantall oppdatert " + budgetInfo.updated.ToString("dddd d. MMMM yyyy", FormMain.norway) + "</h2>");

                doc.Add("<div class='toolbox hidePdf'>");
                doc.Add("<a class='GuiButton hidePdf' onclick='toggleTable(" + hashId + ");' href='#'>Vis / Skjul</a><br>");
                doc.Add("<a class='GuiButton hidePdf' onclick='toggleAll();' href='#'>Alle</a><br>");
                doc.Add("</div>");

                doc.Add("<table class='" + outerclass + " toggleAll' id='" + hashId + "'><tr><td>");

                doc.Add("<table style='font: bold 12px/18px Arial, Sans-serif;' >");
                doc.Add("<tr><td style='background-color:#D9D9D9;text-align:center;padding: 0px 5px 0px 5px;' width=144 >" + BudgetCategoryClass.TypeToName(cat).ToUpper() + "</td>");
                doc.Add("<td style='background-color:" + productColor + ";text-align:center;padding: 0px 5px 0px 5px;border-left:1px solid black;' width=362 >Resultat</td>");
                doc.Add("<td style='background-color:#1163b0;text-align:center;padding: 0px 5px 0px 5px;border-left:1px solid black;' width=208 >Mål</td>");
                doc.Add("<td style='background-color:orange;text-align:center;padding: 0px 5px 0px 5px;border-left:1px solid black;' width=188 >Differanse</td>");
                doc.Add("</tr>");
                doc.Add("</table>");

                doc.Add("<table class='tablesorter'>");
                doc.Add("<thead><tr>");
                doc.Add("<th class=\"{sorter: 'text'}\" width=150 >" + budget.ProductToString(product) + "</td>");
                KgsaBudgetProduct proActual = (KgsaBudgetProduct)dtBudgetProduct.Rows[0]["Field1"];
                doc.Add("<th class=\"{sorter: '" + proActual.fields[0].sorter + "'}\" style='border-left:1px solid black;background-color:" + productColor + ";' width=130 >" + proActual.fields[0].header + "</td>");
                doc.Add("<th class=\"{sorter: '" + proActual.fields[1].sorter + "'}\" style='background-color:" + productColor + ";' width=130 >" + proActual.fields[1].header + "</td>");
                doc.Add("<th class=\"{sorter: '" + proActual.fields[2].sorter + "'}\" style='background-color:" + productColor + ";' width=100 >" + proActual.fields[2].header + "</td>");

                KgsaBudgetProduct proTarget = (KgsaBudgetProduct)dtBudgetProduct.Rows[0]["Field2"];
                doc.Add("<th class=\"{sorter: '" + proTarget.fields[0].sorter + "'}\" style='border-left:1px solid black;background-color:#1163b0;' width=120 >" + proTarget.fields[0].header + "</td>");
                doc.Add("<th class=\"{sorter: '" + proTarget.fields[1].sorter + "'}\" style='background-color:#1163b0;' width=90 >" + proTarget.fields[1].header + "</td>");

                KgsaBudgetProduct proDiff = (KgsaBudgetProduct)dtBudgetProduct.Rows[0]["Field3"];
                doc.Add("<th class=\"{sorter: '" + proDiff.fields[0].sorter + "'}\" style='border-left:1px solid black;background-color:orange;' width=100 >" + proDiff.fields[0].header + "</td>");
                doc.Add("<th class=\"{sorter: '" + proDiff.fields[1].sorter + "'}\" style='background-color:orange;' width=90 >" + proDiff.fields[1].header + "</td>");
                doc.Add("</tr></thead>");
                doc.Add("<tbody>");

                string sorterStyle = type == BudgetValueType.Antall || type == BudgetValueType.Inntjening || type == BudgetValueType.Omsetning ? "numbers-gen" : "percent";
                for (int i = 0; i < dtBudgetProduct.Rows.Count; i++)
                {
                    string strLine = dtBudgetOverall.Rows[i]["Selgerkode"].ToString() == "Totalt" ? " style='border-top:2px solid black;border-bottom:none;' " : "";

                    if (dtBudgetOverall.Rows[i]["Selgerkode"].ToString() == "Totalt")
                        doc.Add("</tbody><tfoot><tr><td class='text-cat' " + strLine + ">" + main.salesCodes.GetNavn(dtBudgetProduct.Rows[i]["Selgerkode"].ToString()) + "</td>");
                    else
                        doc.Add("<tr><td class='text-cat' " + strLine + "><a href='#" + urlID + "b" + dtBudgetProduct.Rows[i]["Selgerkode"].ToString() + "'>" + main.salesCodes.GetNavn(dtBudgetProduct.Rows[i]["Selgerkode"].ToString()) + "</a></td>");

                    proActual = (KgsaBudgetProduct)dtBudgetProduct.Rows[i]["Field1"];
                    doc.Add("<td class='" + proActual.fields[0].style + "'" + strLine + ">" + proActual.fields[0].text + "</td>");
                    doc.Add("<td class='" + proActual.fields[1].style + "'" + strLine + ">" + proActual.fields[1].text + "</td>");
                    doc.Add("<td class='" + proActual.fields[2].style + "'" + strLine + ">" + proActual.fields[2].text + "</td>");

                    proTarget = (KgsaBudgetProduct)dtBudgetProduct.Rows[i]["Field2"];
                    doc.Add("<td class='" + proTarget.fields[0].style + "'" + strLine + ">" + proTarget.fields[0].text + "</td>");
                    doc.Add("<td class='" + proTarget.fields[1].style + "'" + strLine + ">" + proTarget.fields[1].text + "</td>");

                    proDiff = (KgsaBudgetProduct)dtBudgetProduct.Rows[i]["Field3"];
                    doc.Add("<td class='" + proDiff.fields[0].style + "'" + strLine + ">" + proDiff.fields[0].text + "</td>");
                    doc.Add("<td class='" + proDiff.fields[1].style + "'" + strLine + ">" + proDiff.fields[1].text + "</td>");

                    doc.Add("</tr>");
                }
                doc.Add("</tfoot></table>");
                doc.Add("</td></tr></table>");

                decimal count = budgetInfo.selgere.Count;
                if (count < main.appConfig.budgetChartMinPosts)
                    count = main.appConfig.budgetChartMinPosts;
                decimal chartHeight = 100 + main.appConfig.budgetChartPostWidth * count;

                hashId = random.Next(999, 99999);
                doc.Add("<div class='toolbox hidePdf'>");
                doc.Add("<a class='GuiButton hidePdf' onclick='toggleTable(" + hashId + ");' href='#'>Vis / Skjul</a><br>");
                doc.Add("<a class='GuiButton hidePdf' onclick='toggleAll();' href='#'>Alle</a><br>");
                doc.Add("</div>");

                doc.Add("<div class='no-break'>");
                doc.Add("<h3>" + budget.ProductToString(product) + "</h3>");
                doc.Add("<table class='toggleAll' style='background-color:white;border:1px solid black;' id='" + hashId + "'><tr><td>");
                budget.SaveChartImage(main.appConfig.graphResX, (int)chartHeight, FormMain.settingsPath + @"\graphBudget" + product + BudgetCategoryClass.TypeToName(cat) + ".png", type, product, budgetInfo.chartdata);
                doc.Add("<img src='graphBudget" + product + BudgetCategoryClass.TypeToName(cat) + ".png' style='width:900px;height:auto;'><br>");
                doc.Add("</td></tr></table>");
                doc.Add("</div>");

                return doc;
            }
            catch (Exception ex)
            {
                Log.Unhandled(ex);
                return null;
            }
        }
示例#36
0
 public BudgetEntryWeekly(double amount, string label, BudgetType budgetType, int period) : this(amount, label, budgetType, period, "Jan 1")
 {
 }
示例#37
0
        private DataTable MakeTableBudgetProduct(BudgetCategory cat, BudgetType product, BudgetValueType type)
        {
            try
            {
                DataTable dtWork = ReadyTableProductNew();

                sqlce = main.database.CallMonthTable(dtTil, main.appConfig.Avdeling);
                if (sqlce.Rows.Count == 0)
                    return dtWork;

                string strSel = ""; DataRow[] rowsSel;
                for (int i = 0; i < budgetInfo.selgere.Count; i++)
                    strSel += " OR Selgerkode = '" + budgetInfo.selgere[i].selgerkode + "'";
                strSel = strSel.Substring(4, strSel.Length - 4);
                rowsSel = sqlce.Select(strSel + " AND (Dato >= '" + dtFra.ToString("yyy-MM-dd") + "' AND Dato <= '" + dtTil.ToString("yyy-MM-dd") + "')");
                DataTable dtSel = rowsSel.Any() ? rowsSel.CopyToDataTable() : sqlce.Clone();

                object r;
                decimal omset_total = 0, inntjen_total = 0, omsetExMva_total = 0;
                int d = 0;
                if (cat == BudgetCategory.MDA)
                    d = 1;
                else if (cat == BudgetCategory.AudioVideo)
                    d = 2;
                else if (cat == BudgetCategory.SDA)
                    d = 3;
                else if (cat == BudgetCategory.Tele)
                    d = 4;
                else if (cat == BudgetCategory.Data)
                    d = 5;
                decimal target_value = 0;
                if (product == BudgetType.Acc)
                    target_value = budgetInfo.acc;
                else if (product == BudgetType.Finans)
                    target_value = budgetInfo.finans;
                else if (product == BudgetType.Rtgsa)
                    target_value = budgetInfo.rtgsa;
                else if (product == BudgetType.Strom)
                    target_value = budgetInfo.strom;
                else if (product == BudgetType.TA)
                    target_value = budgetInfo.ta;
                else if (product == BudgetType.Vinnprodukt)
                    target_value = budgetInfo.vinn;

                inntjen_total = Compute(dtSel, "Sum(Btokr)");
                omset_total = Compute(dtSel, "Sum(Salgspris)");
                omsetExMva_total = Compute(dtSel, "Sum(SalgsprisExMva)");

                DataRow dtRowAvd = dtWork.NewRow();
                dtRowAvd["Kategori"] = product;
                dtRowAvd["Selgerkode"] = "Totalt";

                dtRowAvd["Actual_inntjen"] = inntjen_total;
                dtRowAvd["Actual_omset"] = omset_total;
                dtRowAvd["Actual_omsetExMva"] = omsetExMva_total;
                if (omsetExMva_total != 0)
                    dtRowAvd["Actual_margin"] = Math.Round(inntjen_total / omsetExMva_total, 2);
                else
                    dtRowAvd["Actual_margin"] = 0;

                if (sqlce.Rows.Count > 0)
                {
                    decimal inntjen_prod = 0, antall_prod = 0, omset_prod = 0, hovedprod_antall = 0, vinnprodukt_poeng = 0;
                    KgsaBudgetProduct Actual = new KgsaBudgetProduct(product, type);
                    KgsaBudgetField actual_1 = new KgsaBudgetField();
                    KgsaBudgetField actual_2 = new KgsaBudgetField();
                    KgsaBudgetField actual_3 = new KgsaBudgetField();

                    KgsaBudgetProduct Target = new KgsaBudgetProduct(product, type);
                    KgsaBudgetField target_1 = new KgsaBudgetField();
                    KgsaBudgetField target_2 = new KgsaBudgetField();

                    KgsaBudgetProduct Difference = new KgsaBudgetProduct(product, type);
                    KgsaBudgetField difference_1 = new KgsaBudgetField();
                    KgsaBudgetField difference_2 = new KgsaBudgetField();

                    if (product == BudgetType.Vinnprodukt)
                    {
                        decimal antall = 0;
                        List<VinnproduktItem> items = main.vinnprodukt.GetList();
                        foreach (VinnproduktItem item in items)
                        {
                            inntjen_prod += Compute(dtSel, "Sum(Btokr)", "[Varekode] = '" + item.varekode + "'");
                            omset_prod += Compute(dtSel, "Sum(Salgspris)", "[Varekode] = '" + item.varekode + "'");
                            antall = Compute(dtSel, "Sum(Antall)", "[Varekode] = '" + item.varekode + "'");
                            antall_prod += antall;
                            vinnprodukt_poeng += item.poeng * antall;
                        }
                    }
                    else if (product == BudgetType.Acc)
                    {
                        int[] accessoriesGrpList = main.appConfig.GetAccessorieGroups(0);
                        foreach (int ac in accessoriesGrpList)
                        {
                            inntjen_prod += Compute(dtSel, "Sum(Btokr)", "[Varegruppe] = " + ac);
                            omset_prod += Compute(dtSel, "Sum(Salgspris)", "[Varegruppe] = " + ac);
                            antall_prod += Compute(dtSel, "Sum(Antall)", "[Varegruppe] = " + ac);
                        }
                    }
                    else if (product == BudgetType.Finans)
                    {
                        var rowf = dtSel.Select("[Varegruppe] = 961");
                        for (int f = 0; f < rowf.Length; f++)
                        {
                            var rows2 = sqlce.Select("[Bilagsnr] = " + rowf[f]["Bilagsnr"]);
                            DataTable dtFinans = rows2.Any() ? rows2.CopyToDataTable() : sqlce.Clone();
                            dtFinans.DefaultView.Sort = "Salgspris DESC";
                            int gruppe = Convert.ToInt32(dtFinans.Rows[0]["Varegruppe"].ToString().Substring(0, 1));
                            if (gruppe == d || d == 0)
                            {
                                r = sqlce.Compute("Sum(Btokr)", "[Varegruppe] = 961 AND [Bilagsnr] = " + dtFinans.Rows[0]["Bilagsnr"].ToString());
                                if (!DBNull.Value.Equals(r))
                                    inntjen_prod += Convert.ToDecimal(r);

                                r = sqlce.Compute("Sum(Antall)", "[Varegruppe] = 961 AND [Bilagsnr] = " + dtFinans.Rows[0]["Bilagsnr"].ToString());
                                if (!DBNull.Value.Equals(r))
                                    antall_prod += Convert.ToInt32(r);
                            }
                        }
                    }
                    else if (product == BudgetType.Rtgsa)
                    {
                        r = dtSel.Compute("Sum(Antall)", "([Varegruppe]=531 OR [Varegruppe]=533 OR [Varegruppe]=534 OR [Varegruppe]=224 OR [Varegruppe]=431)");
                        if (!DBNull.Value.Equals(r))
                            hovedprod_antall = Convert.ToInt32(r);

                        foreach (var varekode in varekoderAlle)
                        {
                            r = dtSel.Compute("Sum(Btokr)", "[Varekode]='" + varekode.kode + "'");
                            if (!DBNull.Value.Equals(r))
                                inntjen_prod += Convert.ToDecimal(r);

                            r = dtSel.Compute("Sum(Salgspris)", "[Varekode]='" + varekode.kode + "'");
                            if (!DBNull.Value.Equals(r))
                                omset_prod += Convert.ToDecimal(r);

                            if (varekode.synlig)
                            {
                                r = dtSel.Compute("Sum(Antall)", "[Varekode]='" + varekode.kode + "'");
                                if (!DBNull.Value.Equals(r))
                                    antall_prod += Convert.ToInt32(r);
                            }
                        }
                    }
                    else if (product == BudgetType.Strom)
                    {
                        r = dtSel.Compute("Sum(Btokr)", "[Varekode] LIKE 'ELSTROM*' OR [Varekode] LIKE 'ELRABATT*'");
                        if (!DBNull.Value.Equals(r))
                            inntjen_prod = Convert.ToDecimal(r);

                        r = dtSel.Compute("Sum(Salgspris)", "[Varekode] LIKE 'ELSTROM*' OR [Varekode] LIKE 'ELRABATT*'");
                        if (!DBNull.Value.Equals(r))
                            omset_prod = Convert.ToDecimal(r);

                        r = dtSel.Compute("Sum(Antall)", "[Varekode] LIKE 'ELSTROM*'");
                        if (!DBNull.Value.Equals(r))
                            antall_prod = Convert.ToInt32(r);
                    }
                    else if (product == BudgetType.TA)
                    {
                        r = dtSel.Compute("Sum(Btokr)", "[Varegruppe] % 100 = 83 AND [Varekode] LIKE 'MOD*'");
                        if (!DBNull.Value.Equals(r))
                            inntjen_prod = Convert.ToDecimal(r);

                        r = dtSel.Compute("Sum(Salgspris)", "[Varegruppe] % 100 = 83 AND [Varekode] LIKE 'MOD*'");
                        if (!DBNull.Value.Equals(r))
                            omset_prod = Convert.ToDecimal(r);

                        r = dtSel.Compute("Sum(Antall)", "[Varegruppe] % 100 = 83 AND [Varekode] LIKE 'MOD*'");
                        if (!DBNull.Value.Equals(r))
                            antall_prod = Convert.ToInt32(r);
                    }

                    if (type == BudgetValueType.Poeng)
                    {
                        actual_1.value = vinnprodukt_poeng;
                        actual_1.type = BudgetValueType.Poeng;
                        actual_2.value = antall_prod;
                        actual_2.type = BudgetValueType.Antall;
                        actual_3.value = inntjen_prod;
                        actual_3.type = BudgetValueType.Inntjening;

                        target_1.value = target_value * budgetInfo.timeElapsedCoefficient;
                        target_1.type = BudgetValueType.Poeng;
                        target_2.value = (target_value * budgetInfo.timeElapsedCoefficient) / budgetInfo.daysElapsed;
                        target_2.type = BudgetValueType.AntallPerDag;

                        difference_1.value = actual_1.value - target_1.value;
                        difference_1.type = BudgetValueType.Poeng;
                        difference_2.value = ((antall_prod * budgetInfo.timeElapsedCoefficient) / budgetInfo.daysElapsed) - target_2.value;
                        difference_2.type = BudgetValueType.AntallPerDag;
                    }
                    else if (type == BudgetValueType.Hitrate)
                    {
                        if (hovedprod_antall != 0)
                            actual_1.value = antall_prod / hovedprod_antall;
                        else
                            actual_1.value = 0;
                        actual_1.type = BudgetValueType.Hitrate;
                        actual_2.value = antall_prod;
                        actual_2.type = BudgetValueType.Antall;
                        actual_3.value = inntjen_prod;
                        actual_3.type = BudgetValueType.Inntjening;

                        target_1.value = target_value;
                        target_1.type = BudgetValueType.Hitrate;
                        target_2.value = (hovedprod_antall * target_value) / budgetInfo.daysElapsed;
                        target_2.type = BudgetValueType.AntallPerDag;

                        difference_1.value = actual_1.value - target_1.value;
                        difference_1.type = BudgetValueType.Hitrate;
                        difference_2.value = ((hovedprod_antall * actual_1.value) / budgetInfo.daysElapsed) - target_2.value;
                        difference_2.type = BudgetValueType.AntallPerDag;
                    }
                    else if (type == BudgetValueType.Antall)
                    {
                        actual_1.value = antall_prod;
                        actual_1.type = BudgetValueType.Antall;
                        actual_2.value = inntjen_prod;
                        actual_2.type = BudgetValueType.Inntjening;
                        if (inntjen_total != 0)
                            actual_3.value = inntjen_prod / inntjen_total;
                        else
                            actual_3.value = 0;
                        actual_3.type = BudgetValueType.SoM;

                        target_1.value = target_value * budgetInfo.timeElapsedCoefficient;
                        target_1.type = BudgetValueType.Antall;
                        target_2.value = (target_value * budgetInfo.timeElapsedCoefficient) / budgetInfo.daysElapsed;
                        target_2.type = BudgetValueType.AntallPerDag;

                        difference_1.value = actual_1.value - target_1.value;
                        difference_1.type = BudgetValueType.Antall;
                        difference_2.value = ((antall_prod * budgetInfo.timeElapsedCoefficient) / budgetInfo.daysElapsed) - target_2.value;
                        difference_2.type = BudgetValueType.AntallPerDag;
                    }
                    if (type == BudgetValueType.Inntjening)
                    {
                        actual_1.value = antall_prod;
                        actual_1.type = BudgetValueType.Antall;
                        actual_2.value = inntjen_prod;
                        actual_2.type = BudgetValueType.Inntjening;
                        if (inntjen_total != 0)
                            actual_3.value = inntjen_prod / inntjen_total;
                        else
                            actual_3.value = 0;
                        actual_3.type = BudgetValueType.SoM;

                        target_1.value = target_value * budgetInfo.timeElapsedCoefficient;
                        target_1.type = BudgetValueType.Inntjening;
                        target_2.value = (target_value * budgetInfo.timeElapsedCoefficient) / budgetInfo.daysElapsed;
                        target_2.type = BudgetValueType.InntjeningPerDag;

                        difference_1.value = actual_2.value - target_1.value;
                        difference_1.type = BudgetValueType.Inntjening;
                        difference_2.value = (inntjen_prod / budgetInfo.daysElapsed) - target_2.value;
                        difference_2.type = BudgetValueType.InntjeningPerDag;
                    }
                    if (type == BudgetValueType.Omsetning)
                    {
                        actual_1.value = antall_prod;
                        actual_1.type = BudgetValueType.Antall;
                        actual_2.value = omset_prod;
                        actual_2.type = BudgetValueType.Omsetning;
                        if (omset_prod != 0)
                            actual_3.value = omset_total / omset_prod;
                        else
                            actual_3.value = 0;
                        actual_3.type = BudgetValueType.SoB;

                        target_1.value = target_value * budgetInfo.timeElapsedCoefficient;
                        target_1.type = BudgetValueType.Omsetning;
                        target_2.value = (target_value * budgetInfo.timeElapsedCoefficient) / budgetInfo.daysElapsed;
                        target_2.type = BudgetValueType.OmsetningPerDag;

                        difference_1.value = actual_2.value - target_1.value;
                        difference_1.type = BudgetValueType.Omsetning;
                        difference_2.value = (omset_prod / budgetInfo.daysElapsed) - target_2.value;
                        difference_2.type = BudgetValueType.OmsetningPerDag;
                    }
                    if (type == BudgetValueType.SoB)
                    {
                        actual_1.value = antall_prod;
                        actual_1.type = BudgetValueType.Antall;
                        actual_2.value = omset_prod;
                        actual_2.type = BudgetValueType.Omsetning;
                        if (omset_total != 0)
                            actual_3.value = omset_prod / omset_total;
                        else
                            actual_3.value = 0;
                        actual_3.type = BudgetValueType.SoB;

                        target_1.value = target_value;
                        target_1.type = BudgetValueType.SoB;
                        target_2.value = omset_total * target_value;
                        target_2.type = BudgetValueType.Omsetning;

                        difference_1.value = actual_3.value - target_1.value;
                        difference_1.type = BudgetValueType.SoB;
                        difference_2.value = actual_2.value - target_2.value;
                        difference_2.type = BudgetValueType.Omsetning;
                    }
                    if (type == BudgetValueType.SoM)
                    {
                        actual_1.value = antall_prod;
                        actual_1.type = BudgetValueType.Antall;
                        actual_2.value = inntjen_prod;
                        actual_2.type = BudgetValueType.Inntjening;
                        if (inntjen_total != 0)
                            actual_3.value = inntjen_prod / inntjen_total;
                        else
                            actual_3.value = 0;
                        actual_3.type = BudgetValueType.SoM;

                        target_1.value = target_value;
                        target_1.type = BudgetValueType.SoM;
                        target_2.value = target_1.value * inntjen_total;
                        target_2.type = BudgetValueType.Inntjening;

                        difference_1.value = actual_3.value - target_1.value;
                        difference_1.type = BudgetValueType.SoM;
                        difference_2.value = actual_2.value - target_2.value;
                        difference_2.type = BudgetValueType.Inntjening;
                    }

                    Actual.fields.Add(actual_1); // kolonne 1 av 3
                    Actual.fields.Add(actual_2); // kolonne 2 av 3
                    Actual.fields.Add(actual_3); // kolonne 3 av 3

                    Target.fields.Add(target_1); // kolonne 1 av 3
                    Target.fields.Add(target_2); // kolonne 2 av 3

                    Difference.fields.Add(difference_1); // kolonne 1 av 3
                    Difference.fields.Add(difference_2); // kolonne 2 av 3

                    dtRowAvd["Field1"] = PrepFields(Actual, false, true);
                    dtRowAvd["Field2"] = PrepFields(Target);
                    dtRowAvd["Field3"] = PrepFields(Difference, true);

                    dtRowAvd["Sort_value"] = -9999999;
                }

                budgetInfo.chartdata = new List<BudgetChartData>() { };

                for (int i = 0; i < budgetInfo.selgere.Count; i++)
                {
                    decimal omset_sel = 0, inntjen_sel = 0, omsetExMva_sel = 0;

                    inntjen_sel = Compute(sqlce, "Sum(Btokr)", "Selgerkode = '" + budgetInfo.selgere[i].selgerkode + "'");
                    omset_sel = Compute(sqlce, "Sum(Salgspris)", "Selgerkode = '" + budgetInfo.selgere[i].selgerkode + "'");
                    omsetExMva_sel = Compute(sqlce, "Sum(SalgsprisExMva)", "Selgerkode = '" + budgetInfo.selgere[i].selgerkode + "'");

                    DataRow dtRowSel = dtWork.NewRow();
                    dtRowSel["Kategori"] = product;
                    dtRowSel["Selgerkode"] = budgetInfo.selgere[i].selgerkode;

                    dtRowSel["Actual_inntjen"] = inntjen_sel;
                    dtRowSel["Actual_omset"] = omset_sel;
                    dtRowSel["Actual_omsetExMva"] = omsetExMva_sel;
                    if (omsetExMva_sel != 0)
                        dtRowSel["Actual_margin"] = Math.Round(inntjen_sel / omsetExMva_sel, 2);
                    else
                        dtRowSel["Actual_margin"] = 0;

                    if (sqlce.Rows.Count > 0)
                    {
                        decimal inntjen_prod = 0, antall_prod = 0, omset_prod = 0, hovedprod_antall = 0, vinnprodukt_poeng = 0;
                        KgsaBudgetProduct Actual = new KgsaBudgetProduct(product, type);
                        KgsaBudgetField actual_1 = new KgsaBudgetField();
                        KgsaBudgetField actual_2 = new KgsaBudgetField();
                        KgsaBudgetField actual_3 = new KgsaBudgetField();
                        KgsaBudgetProduct Target = new KgsaBudgetProduct(product, type);
                        KgsaBudgetField target_1 = new KgsaBudgetField();
                        KgsaBudgetField target_2 = new KgsaBudgetField();
                        KgsaBudgetProduct Difference = new KgsaBudgetProduct(product, type);
                        KgsaBudgetField diff_1 = new KgsaBudgetField();
                        KgsaBudgetField diff_2 = new KgsaBudgetField();

                        if (product == BudgetType.Vinnprodukt)
                        {
                            decimal antall = 0;
                            List<VinnproduktItem> items = main.vinnprodukt.GetList();
                            foreach (VinnproduktItem item in items)
                            {
                                inntjen_prod += Compute(sqlce, "Sum(Btokr)", "[Varekode] = '" + item.varekode + "' AND Selgerkode = '" + budgetInfo.selgere[i].selgerkode + "'");
                                omset_prod += Compute(sqlce, "Sum(Salgspris)", "[Varekode] = '" + item.varekode + "' AND Selgerkode = '" + budgetInfo.selgere[i].selgerkode + "'");
                                antall = Compute(sqlce, "Sum(Antall)", "[Varekode] = '" + item.varekode + "' AND Selgerkode = '" + budgetInfo.selgere[i].selgerkode + "'");
                                antall_prod += antall;
                                vinnprodukt_poeng += item.poeng * antall;
                            }
                        }
                        else if (product == BudgetType.Acc)
                        {
                            int[] accessoriesGrpList = main.appConfig.GetAccessorieGroups(0);
                            foreach (int ac in accessoriesGrpList)
                            {
                                r = sqlce.Compute("Sum(Antall)", "[Varegruppe] = " + ac + " AND Selgerkode = '" + budgetInfo.selgere[i].selgerkode + "'");
                                if (!DBNull.Value.Equals(r))
                                    antall_prod += Convert.ToInt32(r);

                                r = sqlce.Compute("Sum(Btokr)", "[Varegruppe] = " + ac + " AND Selgerkode = '" + budgetInfo.selgere[i].selgerkode + "'");
                                if (!DBNull.Value.Equals(r))
                                    inntjen_prod += Convert.ToDecimal(r);

                                r = sqlce.Compute("Sum(Salgspris)", "[Varegruppe] = " + ac + " AND Selgerkode = '" + budgetInfo.selgere[i].selgerkode + "'");
                                if (!DBNull.Value.Equals(r))
                                    omset_prod += Convert.ToDecimal(r);
                            }
                        }
                        else if (product == BudgetType.Finans)
                        {
                            var rowf = sqlce.Select("[Varegruppe] = 961 AND [Selgerkode] = '" + budgetInfo.selgere[i].selgerkode + "'");
                            for (int f = 0; f < rowf.Length; f++)
                            {
                                var rows2 = sqlce.Select("[Bilagsnr] = " + rowf[f]["Bilagsnr"]);
                                DataTable dtFinans = rows2.Any() ? rows2.CopyToDataTable() : sqlce.Clone();
                                dtFinans.DefaultView.Sort = "Salgspris DESC";
                                int gruppe = Convert.ToInt32(dtFinans.Rows[0]["Varegruppe"].ToString().Substring(0, 1));
                                if (gruppe == d || d == 0)
                                {
                                    r = sqlce.Compute("Sum(Btokr)", "[Varegruppe] = 961 AND [Selgerkode] = '" + budgetInfo.selgere[i].selgerkode + "' AND [Bilagsnr] = " + dtFinans.Rows[0]["Bilagsnr"].ToString());
                                    if (!DBNull.Value.Equals(r))
                                        inntjen_prod += Convert.ToDecimal(r);

                                    r = sqlce.Compute("Sum(Antall)", "[Varegruppe] = 961 AND [Selgerkode] = '" + budgetInfo.selgere[i].selgerkode + "' AND [Bilagsnr] = " + dtFinans.Rows[0]["Bilagsnr"].ToString());
                                    if (!DBNull.Value.Equals(r))
                                        antall_prod += Convert.ToInt32(r);
                                }
                            }
                        }
                        else if (product == BudgetType.Rtgsa)
                        {
                            r = sqlce.Compute("Sum(Antall)", "([Varegruppe]=531 OR [Varegruppe]=533 OR [Varegruppe]=534 OR [Varegruppe]=224 OR [Varegruppe]=431) AND Selgerkode = '" + budgetInfo.selgere[i].selgerkode + "'");
                            if (!DBNull.Value.Equals(r))
                                hovedprod_antall = Convert.ToInt32(r);

                            foreach (var varekode in varekoderAlle)
                            {
                                r = sqlce.Compute("Sum(Salgspris)", "[Varekode]='" + varekode.kode + "' AND Selgerkode = '" + budgetInfo.selgere[i].selgerkode + "'");
                                if (!DBNull.Value.Equals(r))
                                    omset_prod += Convert.ToDecimal(r);

                                r = sqlce.Compute("Sum(Btokr)", "[Varekode]='" + varekode.kode + "' AND Selgerkode = '" + budgetInfo.selgere[i].selgerkode + "'");
                                if (!DBNull.Value.Equals(r))
                                    inntjen_prod += Convert.ToDecimal(r);

                                if (varekode.synlig)
                                {
                                    r = sqlce.Compute("Sum(Antall)", "[Varekode]='" + varekode.kode + "' AND Selgerkode = '" + budgetInfo.selgere[i].selgerkode + "'");
                                    if (!DBNull.Value.Equals(r))
                                        antall_prod += Convert.ToInt32(r);
                                }
                            }
                        }
                        else if (product == BudgetType.Strom)
                        {
                            r = sqlce.Compute("Sum(Btokr)", "([Varekode] LIKE 'ELSTROM*' OR [Varekode] LIKE 'ELRABATT*') AND Selgerkode = '" + budgetInfo.selgere[i].selgerkode + "'");
                            if (!DBNull.Value.Equals(r))
                                inntjen_prod = Convert.ToDecimal(r);

                            r = sqlce.Compute("Sum(Salgspris)", "([Varekode] LIKE 'ELSTROM*' OR [Varekode] LIKE 'ELRABATT*') AND Selgerkode = '" + budgetInfo.selgere[i].selgerkode + "'");
                            if (!DBNull.Value.Equals(r))
                                omset_prod = Convert.ToDecimal(r);

                            r = sqlce.Compute("Sum(Antall)", "[Varekode] LIKE 'ELSTROM*' AND Selgerkode = '" + budgetInfo.selgere[i].selgerkode + "'");
                            if (!DBNull.Value.Equals(r))
                                antall_prod = Convert.ToInt32(r);
                        }
                        else if (product == BudgetType.TA)
                        {
                            r = sqlce.Compute("Sum(Btokr)", "[Varegruppe] % 100 = 83 AND [Varekode] LIKE 'MOD*' AND Selgerkode = '" + budgetInfo.selgere[i].selgerkode + "'");
                            if (!DBNull.Value.Equals(r))
                                inntjen_prod = Convert.ToDecimal(r);

                            r = sqlce.Compute("Sum(Salgspris)", "[Varegruppe] % 100 = 83 AND [Varekode] LIKE 'MOD*' AND Selgerkode = '" + budgetInfo.selgere[i].selgerkode + "'");
                            if (!DBNull.Value.Equals(r))
                                omset_prod = Convert.ToDecimal(r);

                            r = sqlce.Compute("Sum(Antall)", "[Varegruppe] % 100 = 83 AND [Varekode] LIKE 'MOD*' AND Selgerkode = '" + budgetInfo.selgere[i].selgerkode + "'");
                            if (!DBNull.Value.Equals(r))
                                antall_prod = Convert.ToInt32(r);
                        }

                        if (type == BudgetValueType.Poeng)
                        {
                            actual_1.value = vinnprodukt_poeng;
                            actual_1.type = BudgetValueType.Poeng;
                            actual_2.value = antall_prod;
                            actual_2.type = BudgetValueType.Antall;
                            actual_3.value = inntjen_prod;
                            actual_3.type = BudgetValueType.Inntjening;

                            target_1.value = target_value * budgetInfo.timeElapsedCoefficient * budgetInfo.selgere[i].weight;
                            target_1.type = BudgetValueType.Poeng;
                            target_2.value = ((target_value * budgetInfo.timeElapsedCoefficient) / budgetInfo.daysElapsed) * budgetInfo.selgere[i].weight;
                            target_2.type = BudgetValueType.AntallPerDag;

                            diff_1.value = actual_1.value - target_1.value;
                            diff_1.type = BudgetValueType.Poeng;
                            diff_2.value = ((antall_prod * budgetInfo.timeElapsedCoefficient) / budgetInfo.daysElapsed) - target_2.value;
                            diff_2.type = BudgetValueType.AntallPerDag;
                        }
                        else  if (type == BudgetValueType.Hitrate)
                        {
                            if (hovedprod_antall != 0)
                                actual_1.value = antall_prod / hovedprod_antall;
                            else
                                actual_1.value = 0;
                            actual_1.type = BudgetValueType.Hitrate;
                            actual_2.value = antall_prod;
                            actual_2.type = BudgetValueType.Antall;
                            actual_3.value = inntjen_prod;
                            actual_3.type = BudgetValueType.Inntjening;

                            target_1.value = target_value;
                            target_1.type = BudgetValueType.Hitrate;
                            target_2.value = (hovedprod_antall * target_value) / budgetInfo.daysElapsed;
                            target_2.type = BudgetValueType.AntallPerDag;

                            diff_1.value = actual_1.value - target_1.value;
                            diff_1.type = BudgetValueType.Hitrate;
                            diff_2.value = ((hovedprod_antall * actual_1.value) / budgetInfo.daysElapsed) - target_2.value;
                            diff_2.type = BudgetValueType.AntallPerDag;
                        }
                        else if (type == BudgetValueType.Antall)
                        {
                            actual_1.value = antall_prod;
                            actual_1.type = BudgetValueType.Antall;
                            actual_2.value = inntjen_prod;
                            actual_2.type = BudgetValueType.Inntjening;
                            if (inntjen_sel != 0)
                                actual_3.value = inntjen_prod / inntjen_sel;
                            else
                                actual_3.value = 0;
                            actual_3.type = BudgetValueType.SoM;

                            target_1.value = target_value * budgetInfo.timeElapsedCoefficient * budgetInfo.selgere[i].weight;
                            target_1.type = BudgetValueType.Antall;
                            target_2.value = ((target_value * budgetInfo.timeElapsedCoefficient) / budgetInfo.daysElapsed) * budgetInfo.selgere[i].weight;
                            target_2.type = BudgetValueType.AntallPerDag;

                            diff_1.value = actual_1.value - target_1.value;
                            diff_1.type = BudgetValueType.Antall;
                            diff_2.value = antall_prod / budgetInfo.daysElapsed - target_2.value;
                            diff_2.type = BudgetValueType.AntallPerDag;
                        }
                        else if (type == BudgetValueType.Inntjening)
                        {
                            actual_1.value = antall_prod;
                            actual_1.type = BudgetValueType.Antall;
                            actual_2.value = inntjen_prod;
                            actual_2.type = BudgetValueType.Inntjening;
                            if (inntjen_sel != 0)
                                actual_3.value = inntjen_prod / inntjen_sel;
                            else
                                actual_3.value = 0;
                            actual_3.type = BudgetValueType.SoM;

                            target_1.value = target_value * budgetInfo.timeElapsedCoefficient * budgetInfo.selgere[i].weight;
                            target_1.type = BudgetValueType.Inntjening;
                            target_2.value = ((target_value * budgetInfo.timeElapsedCoefficient) / budgetInfo.daysElapsed) * budgetInfo.selgere[i].weight;
                            target_2.type = BudgetValueType.InntjeningPerDag;

                            diff_1.value = actual_2.value - target_1.value;
                            diff_1.type = BudgetValueType.Inntjening;
                            diff_2.value = inntjen_prod / budgetInfo.daysElapsed - target_2.value;
                            diff_2.type = BudgetValueType.InntjeningPerDag;
                        }
                        else if (type == BudgetValueType.Omsetning)
                        {
                            actual_1.value = antall_prod;
                            actual_1.type = BudgetValueType.Antall;
                            actual_2.value = omset_prod;
                            actual_2.type = BudgetValueType.Omsetning;
                            if (omset_sel != 0)
                                actual_3.value = omset_prod / omset_sel;
                            else
                                actual_3.value = 0;
                            actual_3.type = BudgetValueType.SoB;

                            target_1.value = target_value * budgetInfo.timeElapsedCoefficient * budgetInfo.selgere[i].weight;
                            target_1.type = BudgetValueType.Omsetning;
                            target_2.value = ((target_value * budgetInfo.timeElapsedCoefficient) / budgetInfo.daysElapsed) * budgetInfo.selgere[i].weight;
                            target_2.type = BudgetValueType.OmsetningPerDag;

                            diff_1.value = actual_2.value - target_1.value;
                            diff_1.type = BudgetValueType.Omsetning;
                            diff_2.value = omset_prod / budgetInfo.daysElapsed - target_2.value;
                            diff_2.type = BudgetValueType.OmsetningPerDag;
                        }
                        else if (type == BudgetValueType.SoB)
                        {
                            actual_1.value = antall_prod;
                            actual_1.type = BudgetValueType.Antall;
                            actual_2.value = omset_prod;
                            actual_2.type = BudgetValueType.Omsetning;
                            if (omset_sel != 0)
                                actual_3.value = omset_prod / omset_sel;
                            else
                                actual_3.value = 0;
                            actual_3.type = BudgetValueType.SoB;

                            target_1.value = target_value;
                            target_1.type = BudgetValueType.SoB;
                            target_2.value = omset_sel * target_value;
                            target_2.type = BudgetValueType.Omsetning;

                            diff_1.value = actual_3.value - target_1.value;
                            diff_1.type = BudgetValueType.SoB;
                            diff_2.value = actual_2.value - target_2.value;
                            diff_2.type = BudgetValueType.Omsetning;
                        }
                        else if (type == BudgetValueType.SoM)
                        {
                            actual_1.value = antall_prod;
                            actual_1.type = BudgetValueType.Antall;
                            actual_2.value = inntjen_prod;
                            actual_2.type = BudgetValueType.Inntjening;
                            if (inntjen_sel != 0)
                                actual_3.value = inntjen_prod / inntjen_sel;
                            else
                                actual_3.value = 0;
                            actual_3.type = BudgetValueType.SoM;

                            target_1.value = target_value;
                            target_1.type = BudgetValueType.SoM;
                            target_2.value = inntjen_sel * target_value;
                            target_2.type = BudgetValueType.Inntjening;

                            diff_1.value = actual_3.value - target_1.value;
                            diff_1.type = BudgetValueType.SoM;
                            diff_2.value = actual_2.value - target_2.value;
                            diff_2.type = BudgetValueType.Inntjening;
                        }
                        Actual.fields.Add(actual_1); // kolonne 1 av 3
                        Actual.fields.Add(actual_2); // kolonne 2 av 3
                        Actual.fields.Add(actual_3); // kolonne 3 av 3

                        Target.fields.Add(target_1); // kolonne 1 av 2
                        Target.fields.Add(target_2); // kolonne 2 av 2

                        Difference.fields.Add(diff_1); // kolonne 1 av 2
                        Difference.fields.Add(diff_2); // kolonne 2 av 2

                        dtRowSel["Field1"] = PrepFields(Actual, false, true);
                        dtRowSel["Field2"] = PrepFields(Target);
                        dtRowSel["Field3"] = PrepFields(Difference, true);

                        if (type == BudgetValueType.Antall || type == BudgetValueType.Poeng)
                        {
                            dtRowSel["Sort_value"] = actual_1.value;
                            budgetInfo.chartdata.Add(new BudgetChartData(budgetInfo.selgere[i].selgerkode, target_1.value, actual_1.value));
                        }
                        else if (type == BudgetValueType.Inntjening || type == BudgetValueType.Omsetning)
                        {
                            dtRowSel["Sort_value"] = actual_2.value;
                            budgetInfo.chartdata.Add(new BudgetChartData(budgetInfo.selgere[i].selgerkode, target_1.value, actual_2.value));
                        }
                        else if (type == BudgetValueType.SoM || type == BudgetValueType.SoB)
                        {
                            dtRowSel["Sort_value"] = actual_3.value;
                            budgetInfo.chartdata.Add(new BudgetChartData(budgetInfo.selgere[i].selgerkode, target_1.value, actual_3.value));
                        }
                        else if (type == BudgetValueType.Hitrate)
                        {
                            dtRowSel["Sort_value"] = actual_1.value;
                            budgetInfo.chartdata.Add(new BudgetChartData(budgetInfo.selgere[i].selgerkode, target_1.value, actual_1.value));
                        }
                    }
                    dtWork.Rows.Add(dtRowSel);
                }

                dtWork.Rows.Add(dtRowAvd);
                DataView dv = dtWork.DefaultView;
                dv.Sort = "Sort_value desc";

                budgetInfo.chartdata = budgetInfo.chartdata.OrderByDescending(x => x.actual).ToList();

                return dv.ToTable();
            }
            catch (Exception ex)
            {
                Log.Unhandled(ex);
                return null;
            }
        }
示例#38
0
 // Token: 0x0600746B RID: 29803 RVA: 0x0017FE9D File Offset: 0x0017E09D
 public static IStandardBudget Acquire(SecurityIdentifier budgetSid, BudgetType budgetType, ADSessionSettings settings)
 {
     return(StandardBudget.Acquire(budgetSid, budgetType, false, settings));
 }