Example #1
0
        public JsonResult GetUserPriceInfo(string UserInfo, string belongYear, string belongMonth)
        {
            var userList = JsonHelper.ToList(UserInfo);

            if (String.IsNullOrEmpty(belongYear) | String.IsNullOrEmpty(belongMonth))
            {
                return(Json(userList));
            }
            foreach (var user in userList)
            {
                var result = CostFO.GetUserUnitPrice(user.GetValue("UserInfo"), Convert.ToInt32(belongYear), Convert.ToInt32(belongMonth));
                user.SetValue("UnitPrice", result);
            }
            return(Json(userList));
        }
Example #2
0
        public JsonResult CalcTotalValue(string belongYear, string belongMonth, string isActual)
        {
            var dt = this.SQLDB.ExecuteDataTable(String.Format("SELECT * FROM S_EP_LockAccount WHERE BelongYear={0} and BelongMonth={1} and State='Finish'", belongYear, belongMonth));

            if (dt.Rows.Count > 0)
            {
                throw new Formula.Exceptions.BusinessValidationException(String.Format("{0}年{1}月已经关账锁定,无法计算人工成本", belongYear, belongMonth));
            }

            string    workHourUserSql  = "select * from S_EP_WorkHourUser where BelongYear = {0} and BelongMonth = {1}";
            var       workHourUserDT   = this.SQLDB.ExecuteDataTable(string.Format(workHourUserSql, belongYear, belongMonth));
            DataTable costInfoToInsert = new DataTable();

            foreach (DataRow workHourUserDr in workHourUserDT.Rows)
            {
                string costInfoSql = "select * from S_EP_CostInfo where RelateID = '{0}'";
                var    costInfoDT  = this.SQLDB.ExecuteDataTable(string.Format(costInfoSql, workHourUserDr["ID"]));

                if (costInfoToInsert.Columns.Count == 0)
                {
                    foreach (DataColumn col in costInfoDT.Columns)
                    {
                        costInfoToInsert.Columns.Add(new DataColumn(col.ColumnName));
                    }
                }

                decimal unitPrice = CostFO.GetUserUnitPrice(workHourUserDr["UserInfo"].ToString(), Convert.ToInt32(belongYear), Convert.ToInt32(belongMonth), isActual.ToLower() == "true");
                decimal workHour  = 0;
                decimal.TryParse(workHourUserDr["WorkHour"].ToString(), out workHour);

                //add
                if (costInfoDT.Rows.Count == 0)
                {
                    var costUnitDic = this.GetDataDicByID("S_EP_CostUnit", workHourUserDr["CostUnitInfo"].ToString());
                    if (costUnitDic == null)
                    {
                        continue;
                    }
                    var cbsNodeDic = this.GetDataDicByID("S_EP_CBSNode", costUnitDic.GetValue("CBSNodeID"));
                    if (cbsNodeDic == null)
                    {
                        continue;
                    }

                    var subjectDt = this.SQLDB.ExecuteDataTable(String.Format(@"select * from S_EP_CBSNode with(nolock)
where FullID like '{0}%' order by FullID", cbsNodeDic.GetValue("FullID")));

                    var subjectNode = subjectDt.AsEnumerable().FirstOrDefault(c => c["SubjectType"] != null && c["SubjectType"] != DBNull.Value &&
                                                                              c["SubjectType"].ToString() == SubjectType.HRCost.ToString());

                    if (subjectNode == null)
                    {
                        throw new BusinessException("未找到SubjectType为【" + SubjectType.HRCost.ToString() + "】的节点");
                    }

                    DataRow newCostInfoDr = costInfoToInsert.NewRow();
                    newCostInfoDr["ID"]            = FormulaHelper.CreateGuid();
                    newCostInfoDr["Name"]          = subjectNode["Name"];
                    newCostInfoDr["Code"]          = subjectNode["Code"];
                    newCostInfoDr["CostType"]      = SubjectType.HRCost.ToString();
                    newCostInfoDr["CBSInfoID"]     = costUnitDic.GetValue("CBSInfoID");
                    newCostInfoDr["CostUnitID"]    = costUnitDic.GetValue("ID");
                    newCostInfoDr["CBSFullCode"]   = subjectNode["FullCode"];
                    newCostInfoDr["CBSNodeID"]     = subjectNode["ID"];
                    newCostInfoDr["CBSNodeFullID"] = subjectNode["FullID"];
                    newCostInfoDr["RelateID"]      = workHourUserDr["ID"];
                    newCostInfoDr["CostDate"]      = workHourUserDr["CreateDate"];
                    newCostInfoDr["BelongYear"]    = workHourUserDr["BelongYear"];
                    newCostInfoDr["BelongMonth"]   = workHourUserDr["BelongMonth"];

                    if (!String.IsNullOrEmpty(workHourUserDr["BelongMonth"].ToString()))
                    {
                        var nBelongMonth = Convert.ToInt32(workHourUserDr["BelongMonth"].ToString());
                        newCostInfoDr["BelongQuarter"] = (nBelongMonth - 1) / 3 + 1;
                    }
                    newCostInfoDr["UnitPrice"]   = unitPrice;
                    newCostInfoDr["Quantity"]    = workHourUserDr["WorkHour"];
                    newCostInfoDr["TotalPrice"]  = workHour * unitPrice;
                    newCostInfoDr["SubjectCode"] = subjectNode["SubjectCode"];
                    newCostInfoDr["ExpenseType"] = subjectNode["ExpenseType"];

                    newCostInfoDr["BelongDept"]     = subjectNode["ChargerDept"];
                    newCostInfoDr["BelongDeptName"] = subjectNode["ChargerDeptName"];
                    newCostInfoDr["BelongUser"]     = subjectNode["ChargerUser"];
                    newCostInfoDr["BelongUserName"] = subjectNode["ChargerUserName"];
                    newCostInfoDr["UserID"]         = workHourUserDr["UserInfo"];
                    newCostInfoDr["UserName"]       = workHourUserDr["UserInfoName"];
                    newCostInfoDr["UserDept"]       = workHourUserDr["UserDeptInfo"];
                    newCostInfoDr["UserDeptName"]   = workHourUserDr["UserDeptInfoName"];
                    newCostInfoDr["State"]          = IncomeState.Finish.ToString();
                    newCostInfoDr["Status"]         = IncomeState.Finish.ToString();

                    newCostInfoDr["CreateUser"]     = CurrentUserInfo.UserID;
                    newCostInfoDr["CreateUserName"] = CurrentUserInfo.UserName;
                    newCostInfoDr["CreateDate"]     = DateTime.Now;
                    newCostInfoDr["ModifyUser"]     = CurrentUserInfo.UserID;
                    newCostInfoDr["ModifyUserName"] = CurrentUserInfo.UserName;
                    newCostInfoDr["ModifyDate"]     = DateTime.Now;
                    costInfoToInsert.Rows.Add(newCostInfoDr);
                }
                //update
                else
                {
                    DataRow updateDr = costInfoDT.Rows[0];

                    var costUnitDic = this.GetDataDicByID("S_EP_CostUnit", workHourUserDr["CostUnitInfo"].ToString());
                    if (costUnitDic == null)
                    {
                        continue;
                    }
                    var cbsNodeDic = this.GetDataDicByID("S_EP_CBSNode", costUnitDic.GetValue("CBSNodeID"));
                    if (cbsNodeDic == null)
                    {
                        continue;
                    }
                    var subjectDt = this.SQLDB.ExecuteDataTable(String.Format(@"select * from S_EP_CBSNode with(nolock)
where FullID like '{0}%' order by FullID", cbsNodeDic.GetValue("FullID")));

                    var subjectNode = subjectDt.AsEnumerable().FirstOrDefault(c => c["SubjectType"] != null && c["SubjectType"] != DBNull.Value &&
                                                                              c["SubjectType"].ToString() == SubjectType.HRCost.ToString());

                    if (subjectNode == null)
                    {
                        throw new BusinessException("未找到SubjectType为【" + SubjectType.HRCost.ToString() + "】的节点");
                    }

                    updateDr["SubjectCode"]    = subjectNode["Code"];
                    updateDr["ModifyUser"]     = CurrentUserInfo.UserID;
                    updateDr["ModifyUserName"] = CurrentUserInfo.UserID;
                    updateDr["ModifyDate"]     = DateTime.Now;
                    updateDr["UserID"]         = workHourUserDr["UserInfo"];
                    updateDr["UserName"]       = workHourUserDr["UserInfoName"];
                    updateDr["UserDept"]       = workHourUserDr["UserDeptInfo"];
                    updateDr["UserDeptName"]   = workHourUserDr["UserDeptInfoName"];
                    updateDr["UnitPrice"]      = unitPrice;
                    //updateDr["Quantity"] = workHourUserDr["WorkHour"];
                    updateDr["TotalPrice"]  = workHour * unitPrice;
                    updateDr["ExpenseType"] = subjectNode["ExpenseType"];
                    var updateDic = FormulaHelper.DataRowToDic(updateDr);
                    updateDic.UpdateDB(this.SQLDB, "S_EP_CostInfo", updateDr["ID"].ToString());
                }
            }
            this.SQLDB.BulkInsertToDB(costInfoToInsert, "S_EP_CostInfo");
            return(Json(""));
        }