Пример #1
0
            public List <Models.MViewModels.MItemProfatibilityReport> GetAll(DateTime fromDate, DateTime toDate)
            {
                #region Class Objects
                Classes.CSaleTransations ct = new CSaleTransations();
                Classes.CWareHouse       cw = new CWareHouse();
                Classes.CProducts        cp = new CProducts();

                #endregion

                #region Models
                Models.MSaleTransactions mt = new Models.MSaleTransactions();
                Models.MViewModels.MItemProfatibilityReport mii = new Models.MViewModels.MItemProfatibilityReport();
                #endregion

                #region Lists
                List <Models.MViewModels.MItemProfatibilityReport> ItemProfatiblity = new List <Models.MViewModels.MItemProfatibilityReport>();
                List <Models.MSaleTransactions> Transactions = new List <Models.MSaleTransactions>();
                List <string> Products = new List <string>();
                #endregion

                #region Logic
                float totalUnits = 0;
                Transactions = ct.GetAll();

                //filtering for only deductions
                Transactions = (from o in Transactions
                                where o.transactionType == Common.Constants.SaleTransactions.Deduction.ToString() &&
                                Convert.ToDateTime(o.date) >= fromDate && Convert.ToDateTime(o.date) <= toDate
                                select o).ToList();
                totalUnits = (from o in Transactions select Convert.ToSingle(o.units)).Sum();
                Products   = (from o in Transactions select o.ProductID).Distinct().ToList();
                for (int i = 0; i < Products.Count; i++)
                {
                    mii = new Models.MViewModels.MItemProfatibilityReport();
                    List <Models.MSaleTransactions> ProductWise = new List <Models.MSaleTransactions>();
                    ProductWise = (from o in Transactions where o.ProductID == Products[i] select o).ToList();
                    string ProductName = cp.GetProductNameWithTagsById(Convert.ToInt32(Products[i]));

                    float CostPrice = (from a in ProductWise
                                       where a.ProductID == Products[i]
                                       select Convert.ToSingle(a.CostPrice)).Sum();
                    float Revenue = (from a in ProductWise
                                     where a.ProductID == Products[i]
                                     select Convert.ToSingle(a.SalePrice)).Sum();
                    float units = (from a in ProductWise
                                   where a.ProductID == Products[i]
                                   select Convert.ToSingle(a.units)).Sum();
                    CostPrice = CostPrice * units;
                    Revenue   = Revenue * units;
                    float Difference = Revenue - CostPrice;
                    float totalCost  = Transactions.Select(o => Convert.ToSingle(o.units)).Sum();
                    float Percentage = (units / totalUnits) * 100;
                    mii.Inventory     = ProductName;
                    mii.WareHouse     = "Remaining";
                    mii.ActualCost    = CostPrice.ToString();
                    mii.ActualRevenue = Revenue.ToString();
                    mii.Diff          = Difference.ToString();
                    mii.UnitsSold     = units.ToString();
                    mii.Percent       = Percentage.ToString() + "%";
                    ItemProfatiblity.Add(mii);
                }
                #endregion
                return(ItemProfatiblity);
            }