Esempio n. 1
0
        public ActionResult GetReceiveCostJson(string queryJson)
        {
            var          queryParam   = queryJson.ToJObject();
            GoodstypeBLL goodstypebll = new GoodstypeBLL();
            //获取商品类别List
            List <GoodstypeEntity> goodList = goodstypebll.GetListJson("0").ToList();
            DataTable     dt  = new DataTable();
            List <object> obj = new List <object>();

            if (goodList != null && goodList.Count > 0)
            {
                #region 1、创建列名

                //1、固定列名
                dt.Columns.Add("部门");//部门
                //2、动态创建列名
                foreach (var item in goodList)
                {
                    dt.Columns.Add(item.ftypename);
                }
                //3、固定列名
                dt.Columns.Add("小计");//小计

                #endregion 1、创建列名

                #region 2、添加行数据

                //获取部门
                HrDepartmentCache         hrDepartmentCache = new HrDepartmentCache();
                List <HrDepartmentEntity> departList        = hrDepartmentCache.GetList().ToList();

                //获取费用列表
                List <ReceiveCostModel> list     = outbillitembll.GetReceiveCostList().ToList();
                List <ReceiveCostModel> costList = null;
                DataRow dr = dt.NewRow();
                //查询条件 领用时间
                DateTime?startDate = null;
                DateTime?endDate   = null;
                if (!queryParam["StartDate"].IsEmpty())
                {
                    startDate = Convert.ToDateTime(queryParam["StartDate"]);
                }
                if (!queryParam["EndDate"].IsEmpty())
                {
                    endDate = Convert.ToDateTime(queryParam["EndDate"]);
                }
                if (departList != null && departList.Count > 0 && list != null && list.Count > 0)
                {
                    foreach (var dep in departList)
                    {
                        dr       = dt.NewRow();
                        dr["部门"] = dep.deptname;
                        decimal amount = 0;
                        decimal money  = 0;
                        foreach (var li in goodList)
                        {
                            costList = list.FindAll(o => o.fgoodsid == li.frootid && o.fdeptid == dep.deptid).ToList();
                            if (startDate != null)
                            {
                                costList = costList.FindAll(o => o.foutdate >= startDate).ToList();
                            }
                            if (endDate != null)
                            {
                                costList = costList.FindAll(o => o.foutdate <= endDate).ToList();
                            }
                            money            = costList.Sum(o => o.fmoney);
                            dr[li.ftypename] = money.ToString("F");
                            amount          += money;
                        }
                        dr["小计"] = amount.ToString("F");
                        dt.Rows.Add(dr);
                    }
                }

                #endregion 2、添加行数据
            }
            return(ToJsonResult(dt));
        }