Exemple #1
0
        public FormBudgetTimer(BudgetInfo info, int id)
        {
            this.budgetInfo = info;
            this.budgetId = id;
            InitializeComponent();
            AddColumns();

            RefreshDataGrid();
        }
Exemple #2
0
        public FormBudgetDetails(AppSettings app, BudgetObj bud, int id)
        {
            this.appConfig = app;
            this.budget = bud;
            this.budgetId = id;
            InitializeComponent();

            budget.UpdateBudgetSelgerkoder(budgetId);
            budgetInfo = budget.GetBudgetInfo(budgetId);

            SetUI();

            RefreshDataGridView();
        }
Exemple #3
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;
            }
        }
Exemple #4
0
        public RankingBudget(FormMain form, DateTime dtFraArg, DateTime dtTilArg, BudgetCategory cat)
        {
            try
            {
                this.main = form;
                dtFra = dtFraArg;
                dtTil = dtTilArg;
                velgerPeriode = FormMain.datoPeriodeVelger;

                this.varekoderAlle = main.appConfig.varekoder.ToList();
                this.varekoderAlleAlias = varekoderAlle.Where(item => item.synlig == true).Select(x => x.alias).Distinct();

                budget = new BudgetObj(main);

                budgetInfo = budget.GetBudgetInfo(dtTil, cat);
                if (budgetInfo != null)
                    if (budgetInfo.selgere != null)
                        if (budgetInfo.selgere.Count == 0)
                            budgetInfo = null;
            }
            catch (Exception ex)
            {
                Log.Unhandled(ex);
                budgetInfo = null;
            }
        }
Exemple #5
0
        private Bitmap DrawBarChartData(BudgetInfo budgetinfo, int argX = 820, int argY = 350)
        {
            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 (budgetinfo.barchart == null)
                    {
                        g.DrawString("Mangler info!", new Font("Verdana", 30, FontStyle.Bold), new SolidBrush(Color.Red), 400, 0);
                        return b;
                    }

                    float X = argX;
                    float Y = argY;

                    SolidBrush bBrush = new SolidBrush(Color.Gray);
                    Pen pen = new Pen(Color.Black, 3 * dpi);
                    Font fontNormal = new Font("Helvetica", 22 * dpi, FontStyle.Regular);
                    Font fontMedium = new Font("Helvetica", 20 * dpi, FontStyle.Regular);
                    Font fontSmall = new Font("Helvetica", 16 * dpi, FontStyle.Regular);
                    Color resultColor = System.Drawing.ColorTranslator.FromHtml("#ff5b2e");
                    Color resultColorDark = Tint(System.Drawing.ColorTranslator.FromHtml("#ff5b2e"), Color.Black, 0.5M);
                    Color targetColor = System.Drawing.ColorTranslator.FromHtml("#1163b0");
                    Color targetColorDark = System.Drawing.ColorTranslator.FromHtml("#004586");

                    float offsetTop = 20;
                    float barTop = 100;
                    float barBottom = 300;
                    float barHeight = 200;
                    float barWidth = 75;

                    Color resColorIntjen = Color.Green, resColorOmset = Color.Green;
                    if (budgetinfo.barchart.result_omset < 100)
                        resColorOmset = Color.Red;
                    if (budgetinfo.barchart.result_inntjen < 100)
                        resColorIntjen = Color.Red;

                    float omset = (float)budgetinfo.barchart.result_omset / 100;
                    float inntjen = (float)budgetinfo.barchart.result_inntjen / 100;

                    float omsetBarHeight = omset * 200;
                    float omsetBarTop = barTop - (omsetBarHeight - 200);

                    float inntjenBarHeight = inntjen * 200;
                    float inntjenBarTop = barTop - (inntjenBarHeight - 200);

                    g.DrawLine(new Pen(Color.Gray, 5 * dpi), new Point(75 - 50, (int)barBottom), new PointF(300 - 50, (int)barBottom));

                    g.FillRectangle(new SolidBrush(resultColor), new RectangleF(new PointF(100 - 50, omsetBarTop), new SizeF(barWidth, omsetBarHeight)));
                    g.DrawRectangle(new Pen(resultColorDark, 3 * dpi), 100 - 50, omsetBarTop, barWidth, omsetBarHeight);

                    g.FillRectangle(new SolidBrush(targetColor), new RectangleF(new PointF(200 - 50, barTop), new SizeF(barWidth, barHeight)));
                    g.DrawRectangle(new Pen(targetColorDark, 3 * dpi), 200 - 50, barTop, barWidth, barHeight);

                    g.DrawString("Omsetning:", fontNormal, new SolidBrush(Color.Black), new PointF(70 - 50, offsetTop));
                    g.DrawString(budgetinfo.barchart.result_omset + " %", fontNormal, new SolidBrush(resColorOmset), new PointF(230 - 50, offsetTop));

                    g.DrawLine(new Pen(Color.Gray, 5 * dpi), new Point(430 - 100, (int)barBottom), new PointF(655 - 100, (int)barBottom));

                    g.FillRectangle(new SolidBrush(resultColor), new RectangleF(new PointF(455 - 100, inntjenBarTop), new SizeF(barWidth, inntjenBarHeight)));
                    g.DrawRectangle(new Pen(resultColorDark, 3 * dpi), 455 - 100, inntjenBarTop, barWidth, inntjenBarHeight);

                    g.FillRectangle(new SolidBrush(targetColor), new RectangleF(new PointF(555 - 100, barTop), new SizeF(barWidth, barHeight)));
                    g.DrawRectangle(new Pen(targetColorDark, 3 * dpi), 555 - 100, barTop, barWidth, barHeight);

                    g.DrawString("Dag: " + budgetinfo.daysElapsed + " / " + budgetinfo.dager, fontMedium, new SolidBrush(Color.Black), new PointF(610, offsetTop + 50));
                    g.DrawString("Andel: " + Math.Round(budgetinfo.timeElapsedCoefficient * 100, 0) + " %", fontMedium, new SolidBrush(Color.Black), new PointF(610, offsetTop + 90));

                    g.DrawString("Inntjening:", fontNormal, new SolidBrush(Color.Black), new PointF(430 - 100, offsetTop));
                    g.DrawString(budgetinfo.barchart.result_inntjen + " %", fontNormal, new SolidBrush(resColorIntjen), new PointF(575 - 100, offsetTop));

                    g.DrawString("Resultat", fontSmall, new SolidBrush(Color.Black), new PointF(45, 300));
                    g.DrawString("Mål", fontSmall, new SolidBrush(Color.Black), new PointF(170, 300));

                    g.DrawString("Resultat", fontSmall, new SolidBrush(Color.Black), new PointF(350, 300));
                    g.DrawString("Mål", fontSmall, new SolidBrush(Color.Black), new PointF(475, 300));

                }
                catch
                {
                }
            }
            return b;
        }
Exemple #6
0
        public void SumWorkHoursAndDays(BudgetInfo budget_info)
        {
            try
            {
                var con = new SqlCeConnection(FormMain.SqlConStr);
                con.Open();
                var command = new SqlCeCommand("SELECT * FROM tblBudgetSelger WHERE BudgetId = " + budget_info.budget_id, con);
                var da = new SqlCeDataAdapter(command);
                var ds = new DataSet();
                da.Fill(ds, "tblBudgetTimer");
                var ca = new SqlCeCommandBuilder(da);

                DataTable dtTimer = main.database.GetSqlDataTable("SELECT * FROM tblBudgetTimer WHERE BudgetId = " + budget_info.budget_id);

                if (dtTimer.Rows.Count == 0)
                    return;

                for (int i = 0; i < dtTimer.Rows.Count; i++)
                {
                    for (int b = 0; b < ds.Tables["tblBudgetTimer"].Rows.Count; b++)
                    {
                        if (ds.Tables["tblBudgetTimer"].Rows[b]["Selgerkode"].ToString() == dtTimer.Rows[i]["Selgerkode"].ToString())
                        {
                            decimal timer = 0, dager = 0;

                            for (int c = 3; c < dtTimer.Columns.Count; c++)
                            {
                                if (!DBNull.Value.Equals(dtTimer.Rows[i][c]))
                                {
                                    decimal t = Convert.ToDecimal(dtTimer.Rows[i][c]);
                                    timer += t;
                                    dager++;
                                }
                            }

                            ds.Tables["tblBudgetTimer"].Rows[b]["Timer"] = timer;
                            ds.Tables["tblBudgetTimer"].Rows[b]["Dager"] = dager;

                        }
                    }
                }

                da.Update(ds, "tblBudgetTimer");

                // Oppdater timeantall oppdaterings tid
                con = new SqlCeConnection(FormMain.SqlConStr);
                con.Open();
                command = new SqlCeCommand("SELECT * FROM tblBudget WHERE Id = " + budget_info.budget_id, con);
                da = new SqlCeDataAdapter(command);
                ds = new DataSet();
                da.Fill(ds, "tblBudget");
                ca = new SqlCeCommandBuilder(da);
                if (ds.Tables["tblBudget"].Rows.Count > 0)
                    ds.Tables["tblBudget"].Rows[0]["Updated"] = DateTime.Now;
                else
                    Log.n("Fikk ikke satt tidspunkt for timeantall oppdatering.", Color.Red);
                da.Update(ds, "tblBudget");

                con.Close();
                con.Dispose();
            }
            catch(Exception ex)
            {
                Log.Unhandled(ex);
            }
        }
Exemple #7
0
 public void SaveBarChartImage(string argFilename, BudgetInfo budgetinfo)
 {
     Bitmap graphBitmap = DrawBarChartData(budgetinfo);
     if (graphBitmap != null)
     {
         graphBitmap.Save(argFilename, ImageFormat.Png);
         graphBitmap.Dispose();
     }
 }
Exemple #8
0
        private BudgetInfo GetBudgetInternal(DateTime date, int budgetId = 0, BudgetCategory cat = BudgetCategory.None)
        {
            try
            {
                string sql = "";

                if (budgetId == 0)
                    sql = "SELECT * FROM tblBudget WHERE Avdeling = " + main.appConfig.Avdeling + " AND Kategori = '" + BudgetCategoryClass.TypeToName(cat) + "' AND datepart(Month, Date) = " + date.Month + " AND datepart(Year, Date) = " + date.Year;
                else
                    sql = "SELECT * FROM tblBudget WHERE Id = " + budgetId;

                DataTable dt = main.database.GetSqlDataTable(sql);

                if (dt.Rows.Count > 0)
                {
                    var _budgetObj = new BudgetInfo();

                    // Legg till generell info
                    budgetId = Convert.ToInt32(dt.Rows[0]["Id"].ToString());
                    _budgetObj.budget_id = budgetId;
                    _budgetObj.date = Convert.ToDateTime(dt.Rows[0]["Date"].ToString());
                    _budgetObj.dager = Convert.ToInt32(dt.Rows[0]["Dager"].ToString());
                    _budgetObj.avdeling = Convert.ToInt32(dt.Rows[0]["Avdeling"].ToString());
                    _budgetObj.kategori = BudgetCategoryClass.NameToType(dt.Rows[0]["Kategori"].ToString());
                    _budgetObj.omsetning = Convert.ToDecimal(dt.Rows[0]["Omsetning"].ToString());
                    _budgetObj.inntjening = Convert.ToDecimal(dt.Rows[0]["Inntjening"].ToString());
                    _budgetObj.margin = Convert.ToDecimal(dt.Rows[0]["Margin"].ToString());

                    _budgetObj.ta = Convert.ToDecimal(dt.Rows[0]["TA"].ToString());
                    _budgetObj.ta_type = ConvertToBudgetType(dt.Rows[0]["TA_Type"].ToString());
                    _budgetObj.strom = Convert.ToDecimal(dt.Rows[0]["Strom"].ToString());
                    _budgetObj.strom_type = ConvertToBudgetType(dt.Rows[0]["Strom_Type"].ToString());
                    _budgetObj.finans = Convert.ToDecimal(dt.Rows[0]["Finans"].ToString());
                    _budgetObj.finans_type = ConvertToBudgetType(dt.Rows[0]["Finans_Type"].ToString());
                    _budgetObj.rtgsa = Convert.ToDecimal(dt.Rows[0]["Rtgsa"].ToString());
                    _budgetObj.rtgsa_type = ConvertToBudgetType(dt.Rows[0]["Rtgsa_Type"].ToString());
                    _budgetObj.acc = Convert.ToDecimal(dt.Rows[0]["Acc"].ToString());
                    _budgetObj.acc_type = ConvertToBudgetType(dt.Rows[0]["Acc_Type"].ToString());
                    _budgetObj.vinn = Convert.ToDecimal(dt.Rows[0]["Vinn"].ToString());
                    _budgetObj.vinn_type = ConvertToBudgetType(dt.Rows[0]["Vinn_Type"].ToString());

                    _budgetObj.updated = Convert.ToDateTime(dt.Rows[0]["Updated"].ToString());

                    // Legg til selgere under dette budsjettet
                    DataTable dtSel = main.database.GetSqlDataTable("SELECT Selgerkode, Timer, Dager, Multiplikator FROM tblBudgetSelger WHERE BudgetId = " + budgetId);
                    if (dtSel.Rows.Count > 0)
                    {
                        List<BudgetSelger> list = new List<BudgetSelger>() { };
                        int timer = 0, dager = 0;
                        for(int i = 0; i < dtSel.Rows.Count; i++)
                        {
                            BudgetSelger bselger = new BudgetSelger();
                            bselger.selgerkode = dtSel.Rows[i]["Selgerkode"].ToString();

                            bselger.timer = Convert.ToInt32(dtSel.Rows[i]["Timer"]);
                            timer += bselger.timer;
                            bselger.dager = Convert.ToInt32(dtSel.Rows[i]["Dager"]);
                            dager += bselger.dager;
                            bselger.multiplikator = Convert.ToDecimal(dtSel.Rows[i]["Multiplikator"]);
                            list.Add(bselger);
                        }
                        _budgetObj.totalt_timer = timer;
                        _budgetObj.totalt_dager = dager;

                        for (int i = 0; i < list.Count; i++ )
                        {
                            decimal weight = 0;
                            if (timer > 0)
                                weight = (list[i].timer * list[i].multiplikator) / timer;

                            list[i].weight = weight;
                        }
                        _budgetObj.selgere = list;
                    }

                    // Regne ut coefficient tall for beregning av budsjett MTD
                    decimal daysElapsed = GetNumberOfOpenDaysInMonth(FormMain.GetFirstDayOfMonth(date), date);
                    decimal daysInMonth = _budgetObj.dager;
                    _budgetObj.timeElapsedCoefficient = daysElapsed / daysInMonth;
                    _budgetObj.daysElapsed = (int)daysElapsed;

                    return _budgetObj;
                }

            }
            catch (Exception ex)
            {
                Log.Unhandled(ex);
            }
            return null;
        }