Пример #1
0
        public void Generate(ChartResultParameter par)
        {
            DateTime begin = DateTime.Now;
            HtmlTemplate index = new HtmlTemplate("index");
            string articlesString = "", cancellationsString = "", depositsString = "";
            string usersString = "";
            double sum = 0.0;

            result.Sales.Sort(par.SortOrder);
            result.Cancellations.Sort(par.SortOrder);

            index.Insert("datetime", DateTime.Now.ToString());
            index.Insert("version", Administration.Properties.Resources.Version);

            #region information
            index.Insert("profile", chart.Profile.Name);
            foreach (User u in chart.Users) usersString += u.Username + "<br />\r\n";
            usersString.Remove(usersString.Length - 8);
            index.Insert("user", usersString);
            index.Insert("cancellationsInvolved", par.InvolveCancellation ? "ja" : "nein");
            index.Insert("deletedArticlesShown", par.ShowDeletedArticles ? "ja" : "nein");
            index.Insert("sortedBy", par.SortOrder.ToString());
            #endregion

            #region articles
            HtmlTemplate articles = new HtmlTemplate("articlecollection");
            articles.Insert("header", "Artikel");
            foreach (ArticleCount ac in result.Sales.Container)
            {
                if (!par.ShowDeletedArticles && ac.Article.IsDeleted) continue;
                if (!par.ShowUnsoldArticles && ac.Count < 1) continue;

                HtmlTemplate tpl = new HtmlTemplate("article");
                tpl.Insert("name", ac.Article.Name);
                tpl.Insert("price", string.Format("{0:0.00 €}", ac.Article.Price));
                tpl.Insert("count", par.InvolveCancellation ?
                                    (ac.Count - result.Cancellations[ac.Article].Count).ToString() :
                                    ac.Count.ToString());
                tpl.Insert("sum", par.InvolveCancellation ?
                    string.Format("{0:0.00 €}", ac.Article.Price * (ac.Count - result.Cancellations[ac.Article].Count)) :
                    string.Format("{0:0.00 €}", ac.Article.Price * ac.Count));
                articlesString += tpl.Get();
            }

            articles.Insert("articles", articlesString);
            articles.Insert("articlescount", par.InvolveCancellation ?
                (result.Sales.Count - result.Cancellations.Count).ToString() :
                result.Sales.Count.ToString());
            sum = par.InvolveCancellation ? (result.Sales.Amount - result.Cancellations.Amount) : result.Sales.Amount;
            articles.Insert("articlessum", string.Format("{0:0.00 €}", sum));

            index.Insert("sales", articles.Get());
            #endregion

            #region deposits
            double depositSum = 0.0;
            int depositCount = 0;
            List<ArticleCount> deps = (from d in result.Sales.Container where d.Article.Deposit.DepositID != -1 select d as ArticleCount).ToList();
            List<ArticleCount> depcancs = (from d in result.Cancellations.Container where d.Article.Deposit.DepositID != -1 select d as ArticleCount).ToList();

            Cart depresult = new Cart();
            foreach (ArticleCount d in deps)
                depresult.Add(d);
            if (par.InvolveCancellation) // remove cancelled deposites
                foreach (ArticleCount d in depcancs)
                    depresult.Remove(d);

            // add returned deposites which are not children of depresult (never bought it, but returned it)
            List<DepositReturn> unbought = (from d in result.DepositReturns
                            where
                                (from a in depresult.Container select a.Article.Deposit).ToList<Deposit>().Contains(d.Deposit) == false
                            select d).ToList();
            foreach (DepositReturn d in unbought)
            {
                int count = d.Count;

                HtmlTemplate tpl = new HtmlTemplate("article");
                tpl.Insert("name", d.Deposit.Name);
                tpl.Insert("price", string.Format("{0:0.00 €}", d.Deposit.Amount));
                tpl.Insert("count", count.ToString());
                tpl.Insert("sum", string.Format("{0:0.00 €}", count * d.Deposit.Amount));

                depositSum -= count * d.Deposit.Amount;
                depositCount -= count;
                depositsString += tpl.Get();
            }

            // enumerate deposit objects
            foreach (ArticleCount d in depresult.Container)
            {
                int count = d.Count;

                // subtract returned deposites
                foreach (DepositReturn dr in (from ret in result.DepositReturns where ret.Deposit.DepositID == d.Article.Deposit.DepositID select ret).ToList())
                {
                    count -= dr.Count;
                }

                HtmlTemplate tpl = new HtmlTemplate("article");
                tpl.Insert("name", d.Article.Deposit.Name);
                tpl.Insert("price", string.Format("{0:0.00 €}", d.Article.Deposit.Amount));
                tpl.Insert("count", count.ToString());
                tpl.Insert("sum", string.Format("{0:0.00 €}", count * d.Article.Deposit.Amount));


                depositSum += count * d.Article.Deposit.Amount;
                depositCount += count;
                depositsString += tpl.Get();
            }

            if (par.ShowDeposits)
            {
                HtmlTemplate deposits = new HtmlTemplate("articlecollection");
                deposits.Insert("header", "Pfänder");
                deposits.Insert("articles", depositsString);
                deposits.Insert("articlescount", depositCount.ToString());
                deposits.Insert("articlessum", string.Format("{0:0.00 €}", depositSum));

                index.Insert("deposits", deposits.Get());
            }
            else
                index.Insert("deposits", "");
            #endregion

            #region cancellations
            if (par.ShowCancellation)
            {
                HtmlTemplate cancellations = new HtmlTemplate("articlecollection");
                cancellations.Insert("header", "Stornos");
                foreach (ArticleCount ac in result.Cancellations.Container)
                {
                    HtmlTemplate tpl = new HtmlTemplate("article");
                    tpl.Insert("name", ac.Article.Name);
                    tpl.Insert("price", string.Format("{0:0.00 €}", ac.Article.Price));
                    tpl.Insert("count", ac.Count.ToString());
                    tpl.Insert("sum", string.Format("{0:0.00 €}", ac.Article.Price * ac.Count));
                    cancellationsString += tpl.Get();
                }

                cancellations.Insert("articles", cancellationsString);
                cancellations.Insert("articlescount", result.Cancellations.Count.ToString());
                cancellations.Insert("articlessum", string.Format("{0:0.00 €}", result.Cancellations.Amount));

                index.Insert("cancellations", cancellations.Get());
            }
            else
                index.Insert("cancellations", "");
            #endregion

            #region staff
            if (par.ShowCalculation)
            {
                HtmlTemplate calculation = new HtmlTemplate("staffcalculation");
                calculation.Insert("header", "Abrechnung");
                calculation.Insert("sum", string.Format("{0:0.00 €}", sum));
                calculation.Insert("commissionpercentage", string.Format("{0:0.0 %}", par.Provision / 100));
                calculation.Insert("commissionamount", string.Format("{0:0.00 €}", sum * par.Provision / 100));
                calculation.Insert("benefit", string.Format("{0:0.00 €}", par.FreeAmount));
                calculation.Insert("depositsum", string.Format("{0:0.00 €}", depositSum));
                calculation.Insert("summary", string.Format("{0:0.00 €}", sum + depositSum - (sum * par.Provision / 100) - par.FreeAmount));

                index.Insert("staff", calculation.Get());
            }
            else
                index.Insert("staff", "");
            #endregion

            index.Insert("creationduration", (result.CreationBegin - result.CreationEnd).ToString());
            index.Insert("writingduration", (begin - DateTime.Now).ToString());


            this.output = index.Get();
        }