コード例 #1
0
        public JsonResult SettlementRevert(string id)
        {
            var sql = string.Format(@"select top 1 * from S_EP_SubContractSettlement order by CreateDate desc ", "");
            var dt  = SQLDB.ExecuteDataTable(sql);

            if (dt.Rows.Count == 0)
            {
                throw new Formula.Exceptions.BusinessValidationException("无结算单,请确认!");
            }
            var dicLast = FormulaHelper.DataRowToDic(dt.Rows[0]);

            CostFO.ValidatePeriodIsClosed(Convert.ToDateTime(dicLast.GetValue("SettlementDate")));

            if (dicLast.GetValue("FlowPhase") == "Start")
            {
                sql = string.Format(@"delete from S_EP_SubContractSettlement where ID='{0}' ", id);
                SQLDB.ExecuteNonQuery(sql);
                return(Json(""));
            }
            if (dicLast.GetValue("FlowPhase") == "Processing")
            {
                throw new Formula.Exceptions.BusinessValidationException("此结算单在【流程中】,无法撤销!");
            }



            sql = string.Format(@"select * from S_EP_SubContractSettlement_Detail where S_EP_SubContractSettlementID='{0}' ", id);
            dt  = SQLDB.ExecuteDataTable(sql);
            var settlementDetail = FormulaHelper.DataTableToListDic(dt);

            var cbsInfoIDs = new List <string>();
            var revertID   = FormulaHelper.CreateGuid();

            dicLast.SetValue("RevertReason", string.Empty);
            var sqlUpdate = dicLast.CreateInsertSql(SQLDB, "S_EP_SubContractSettlementRevert", revertID);

            sqlUpdate += string.Format(@"delete from S_EP_SubContractSettlement where ID='{0}' ", id);
            foreach (var item in settlementDetail)
            {
                cbsInfoIDs.Add(item.GetValue("CBSInfoID"));
                item.SetValue("S_EP_SubContractSettlementRevertID", revertID);
                sqlUpdate += item.CreateInsertSql(SQLDB, "S_EP_SubContractSettlementRevert_Detail", FormulaHelper.CreateGuid());
                sqlUpdate += string.Format(@"delete from S_EP_CostInfo where RelateID='{0}' ", item.GetValue("ID"));
            }
            SQLDB.ExecuteNonQuery(sqlUpdate);

            foreach (var cbsInfoID in cbsInfoIDs.Distinct())
            {
                var cbsInfoDic = this.GetDataDicByID("S_EP_CBSInfo", cbsInfoID);
                if (cbsInfoDic == null)
                {
                    throw new Formula.Exceptions.BusinessValidationException("没有找到成本单元对应的核算项目,无法撤销!");
                }
                var cbsInfo = new S_EP_CBSInfo(cbsInfoDic);
                cbsInfo.SummaryCostValue();
            }


            return(Json(""));
        }
コード例 #2
0
        public void Push()
        {
            //判断是否是最后确认节点
            var dt = this.DB.ExecuteDataTable(string.Format("select top 1 ID,CBSInfoID,ConfirmDate from S_EP_InvoiceConfirm where InvoiceID='{0}' order by ID desc ", this.ModelDic.GetValue("InvoiceID")));

            if (dt.Rows.Count == 0)
            {
                throw new Formula.Exceptions.BusinessValidationException("无确认信息,无需撤销!");
            }
            var dicConfirm = FormulaHelper.DataRowToDic(dt.Rows[0]);

            if (this.ModelDic.GetValue("InvoiceConfirmID") != dicConfirm.GetValue("ID"))
            {
                throw new Formula.Exceptions.BusinessValidationException("只能逐步撤销节点");
            }
            CostFO.ValidatePeriodIsClosed(Convert.ToDateTime(dicConfirm.GetValue("ConfirmDate")));

            var cbsInfoDic = this.GetDataDicByID("S_EP_CBSInfo", dicConfirm.GetValue("CBSInfoID"));

            if (cbsInfoDic == null)
            {
                throw new Formula.Exceptions.BusinessValidationException("没有找到成本单元对应的核算项目,无法撤销!");
            }

            string sql = string.Format(@"delete from S_EP_InvoiceConfirm where ID='{0}' ", this.ModelDic.GetValue("InvoiceConfirmID"));

            sql += string.Format(@"delete from S_EP_CostInfo where RelateID='{0}' ", this.ModelDic.GetValue("InvoiceConfirmID"));
            this.DB.ExecuteNonQuery(sql);

            var cbsInfo = new S_EP_CBSInfo(cbsInfoDic);

            cbsInfo.SummaryCostValue();
        }
コード例 #3
0
        public JsonResult DeleteCostInfo(string listJson)
        {
            var    dicList = JsonHelper.ToList(listJson);
            string delSql  = "";

            foreach (var dic in dicList)
            {
                var dateTime = Convert.ToDateTime(string.Format("{0}-{1}-01", dic.GetValue("BelongYear"), dic.GetValue("BelongMonth")));
                CostFO.ValidatePeriodIsClosed(dateTime);

                delSql += string.Format(" delete S_EP_CostInfo where ID = '{0}' ", dic.GetValue("ID"));
            }

            this.SQLDB.ExecuteNonQuery(delSql);

            var distinctCBSInfoList = dicList.Select(a => a.GetValue("CBSInfoID")).Distinct();
            var sqlCBSInfo          = "select * from S_EP_CBSInfo where ID ='{0}' ";

            foreach (var cbsInfoID in distinctCBSInfoList)
            {
                var cbsDt = SQLDB.ExecuteDataTable(string.Format(sqlCBSInfo, cbsInfoID));
                if (cbsDt.Rows.Count > 0)
                {
                    var cbsInfo = new S_EP_CBSInfo(FormulaHelper.DataRowToDic(cbsDt.Rows[0]));
                    cbsInfo.SummaryCostValue();
                }
            }

            return(Json("true"));
        }
コード例 #4
0
        protected override void BeforeSave(Dictionary <string, string> dic, Base.Logic.Domain.S_UI_Form formInfo, bool isNew)
        {
            DateTime incomeSubmitEndDate = DateTime.Now;

            DateTime.TryParse(dic.GetValue("IncomeSubmitEndDate"), out incomeSubmitEndDate);
            CostFO.ValidatePeriodIsClosed(incomeSubmitEndDate);
        }
コード例 #5
0
        protected override void BeforeSave(Dictionary <string, string> dic, Base.Logic.Domain.S_UI_Form formInfo, bool isNew)
        {
            string   datetTimeStr = dic.GetValue("FactEndDate");
            DateTime dateTime     = Convert.ToDateTime(datetTimeStr);

            CostFO.ValidatePeriodIsClosed(dateTime);
        }
コード例 #6
0
        public JsonResult ValidateRevert(string Data)
        {
            var item        = JsonHelper.ToObject(Data);
            var belongYear  = item.GetValue("BelongYear");
            var belongMonth = item.GetValue("BelongMonth");

            if (String.IsNullOrEmpty(belongYear))
            {
                throw new Formula.Exceptions.BusinessValidationException("没有指定年份的工时填报单,无法撤销");
            }
            if (String.IsNullOrEmpty(belongMonth))
            {
                throw new Formula.Exceptions.BusinessValidationException("没有指定月份的工时填报单,无法撤销");
            }
            CostFO.ValidatePeriodIsClosed(new DateTime(Convert.ToInt32(belongYear), Convert.ToInt32(belongMonth), 1), "无法撤销工时填报信息");

            //已经计算过单价情况下(存在CostInfo)不能撤销
            string costInfoExistSql = @"select count(*) from S_EP_WorkHourUser 
                                      inner join S_EP_CostInfo on S_EP_CostInfo.RelateID = S_EP_WorkHourUser.ID
                                      inner join S_EP_WorkHourDepartSubmit_WorkHourDetail on S_EP_WorkHourDepartSubmit_WorkHourDetail.ID = S_EP_WorkHourUser.RelateID
                                      where S_EP_WorkHourDepartSubmit_WorkHourDetail.S_EP_WorkHourDepartSubmitID = '{0}'";
            var    countObj         = this.SQLDB.ExecuteScalar(string.Format(costInfoExistSql, item.GetValue("ID")));

            if (countObj != null && (int)countObj > 0)
            {
                throw new Formula.Exceptions.BusinessValidationException("工时已经计入人工成本无法撤销");
            }

            return(Json(""));
        }
コード例 #7
0
        private void ValidateNodeRevert(string id, string nodeID)
        {
            #region 判断节点是否是最后确认节点,是否已确认,是否已撤销
            var sql = string.Format(@"select FinalConfirm.*,RevertInfo.FlowPhase as RevertFlowPhase, RevertInfo.ID as ConfirmRevertID
from (select top 1 ID,CBSInfoID,ConfirmDate,FlowPhase as ConfirmFlowPhase from S_EP_SupplierContractConfirm where SubContractDetailID='{0}' order by ID desc) FinalConfirm
left join S_EP_SupplierContractConfirmRevert RevertInfo on FinalConfirm.ID=RevertInfo.SubContractConfirmID ", id);
            var dt  = this.SQLDB.ExecuteDataTable(sql);
            if (dt.Rows.Count == 0)
            {
                throw new Formula.Exceptions.BusinessValidationException("无确认信息,无需撤销!");
            }
            var dicConfirm = FormulaHelper.DataRowToDic(dt.Rows[0]);
            if (dicConfirm.GetValue("ConfirmFlowPhase") != "End")
            {
                throw new Formula.Exceptions.BusinessValidationException("此节点在审批中,不允许撤销!");
            }
            if (nodeID != dicConfirm.GetValue("ID"))
            {
                throw new Formula.Exceptions.BusinessValidationException("只能逐步撤销节点");
            }
            if (!string.IsNullOrWhiteSpace(dicConfirm.GetValue("ConfirmRevertID")))
            {
                throw new Formula.Exceptions.BusinessValidationException("此节点已撤销,不能重复撤销,请确认!");
            }

            #endregion

            CostFO.ValidatePeriodIsClosed(Convert.ToDateTime(dicConfirm.GetValue("ConfirmDate")));

            var cbsInfoDic = this.GetDataDicByID("S_EP_CBSInfo", dicConfirm.GetValue("CBSInfoID"));
            if (cbsInfoDic == null)
            {
                throw new Formula.Exceptions.BusinessValidationException("没有找到对应的核算项目,无法撤销!");
            }
        }
コード例 #8
0
 protected override void BeforeSave(Dictionary <string, string> dic, Base.Logic.Domain.S_UI_Form formInfo, bool isNew)
 {
     if (!isNew)
     {
         Expenses.Logic.BusinessFacade.DataInterfaceFo.ValidateDataSyn("S_EP_ReimbursementApply", dic.GetValue("ID"));
     }
     CostFO.ValidatePeriodIsClosed(DateTime.Now);
 }
コード例 #9
0
        protected override void BeforeSave(Dictionary <string, string> dic, S_UI_Form formInfo, bool isNew)
        {
            if (String.IsNullOrEmpty(dic.GetValue("ConfirmDate")))
            {
                throw new Formula.Exceptions.BusinessValidationException("必须填写完成日期");
            }
            var dateTime = String.IsNullOrEmpty(dic.GetValue("ConfirmDate")) ? DateTime.Now : Convert.ToDateTime(dic.GetValue("ConfirmDate"));

            CostFO.ValidatePeriodIsClosed(dateTime);
            ValidateStart(dic.GetValue("InvoiceID"));
        }
コード例 #10
0
        public JsonResult CheckPeriodIsClosed()
        {
            var      dateStr = GetQueryString("date");
            DateTime date    = DateTime.Now;

            if (DateTime.TryParse(dateStr, out date))
            {
                CostFO.ValidatePeriodIsClosed(date);
            }
            return(Json(""));
        }
コード例 #11
0
        protected override void BeforeSave(Dictionary <string, string> dic, Base.Logic.Domain.S_UI_Form formInfo, bool isNew)
        {
            CheckSubContractConfirmMethod();
            if (String.IsNullOrEmpty(dic.GetValue("ConfirmDate")))
            {
                throw new Formula.Exceptions.BusinessValidationException("委外进度确认必须填写完工日期");
            }
            var dateTime = String.IsNullOrEmpty(dic.GetValue("ConfirmDate")) ? DateTime.Now : Convert.ToDateTime(dic.GetValue("ConfirmDate"));

            CostFO.ValidatePeriodIsClosed(dateTime);
        }
コード例 #12
0
        public JsonResult ValidateDelete(string ids)
        {
            var costInfoDT      = this.SQLDB.ExecuteDataTable(string.Format("select * from S_EP_CostInfo where id in ('{0}')", ids.Replace(",", "','")));
            var costInfoDicList = FormulaHelper.DataTableToListDic(costInfoDT);

            foreach (var dic in costInfoDicList)
            {
                CostFO.ValidatePeriodIsClosed(new DateTime((int)dic["BelongYear"], (int)dic["BelongMonth"], 1), "不能删除");
            }

            return(Json(""));
        }
コード例 #13
0
        protected override void BeforeSave(Dictionary <string, string> dic, Base.Logic.Domain.S_UI_Form formInfo, bool isNew)
        {
            if (string.IsNullOrEmpty(dic.GetValue("PaymentDate")))
            {
                throw new Formula.Exceptions.BusinessValidationException("请填写付款日期");
            }
            CostFO.ValidatePeriodIsClosed(Convert.ToDateTime(dic.GetValue("PaymentDate")));
            Expenses.Logic.BusinessFacade.DataInterfaceFo.ValidateDataSyn("S_SP_Payment", dic.GetValue("ID"));
            var entity = this.GetEntityByID(dic["ID"]) ?? new S_SP_Payment();

            this.UpdateEntity(entity, dic);
            entity.Validate();
            paymentid = dic["ID"];
        }
コード例 #14
0
        public JsonResult LoadUserWorkHourFromHR(string belongYear, string belongMonth)
        {
            CostFO.ValidatePeriodIsClosed(new DateTime(Convert.ToInt32(belongYear), Convert.ToInt32(belongMonth), 1), "无法再在该月份汇总工时");

            string excuteSql = "";

            excuteSql += LoadProductionUserWorkHourFromHR(belongYear, belongMonth);
            excuteSql += LoadManageUserWorkHourFromHR(belongYear, belongMonth);
            if (!string.IsNullOrEmpty(excuteSql))
            {
                this.SQLDB.ExecuteNonQuery(excuteSql);
            }

            return(Json(""));
        }
コード例 #15
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));
        }
コード例 #16
0
        protected override void BeforeSave(Dictionary <string, string> dic, S_UI_Form formInfo, bool isNew)
        {
            var applyValue = 0m;

            if (!decimal.TryParse(dic.GetValue("ApplyValue"), out applyValue))
            {
                throw new Formula.Exceptions.BusinessValidationException("金额格式不正确!");
            }
            if (applyValue <= 0)
            {
                throw new Formula.Exceptions.BusinessValidationException("金额必须大于0!");
            }

            var applyDate = DateTime.Now.Date;

            if (!DateTime.TryParse(dic.GetValue("ApplyDate"), out applyDate))
            {
                throw new Formula.Exceptions.BusinessValidationException("请选择申请日期!");
            }
            CostFO.ValidatePeriodIsClosed(applyDate);

            dic.SetValue("BelongYear", applyDate.Year.ToString());
            dic.SetValue("BelongQuarter", ((applyDate.Month + 2) / 3).ToString());
            dic.SetValue("BelongMonth", applyDate.Month.ToString());

            if (isNew)
            {
                dic.SetValue("Source", "Input");
            }
            else
            {
                if (dic.GetValue("Source") == "Reimbursement")
                {
                    throw new Formula.Exceptions.BusinessValidationException("报销单费用不能修改!");
                }

                //是否已分摊
                if (ValidateCostApportion(dic.GetValue("ID")) != null)
                {
                    var apportionValue = Convert.ToDecimal(dic.GetValue("ApportionValue"));
                    if (applyValue < apportionValue)
                    {
                        throw new Formula.Exceptions.BusinessValidationException(string.Format("金额【{0}】必须大于已分摊金额【{1}】!",
                                                                                               applyValue, apportionValue));
                    }
                }
            }
        }
コード例 #17
0
        protected override void BeforeSave(Dictionary <string, string> dic, Base.Logic.Domain.S_UI_Form formInfo, bool isNew)
        {
            CostFO.ValidatePeriodIsClosed(new DateTime(Convert.ToInt32(dic["BelongYear"]), Convert.ToInt32(dic["BelongMonth"]), 1), "不能增加人工成本数据");

            var costUnitID = dic.GetValue("CostUnitID");

            var costUnitDic = this.GetDataDicByID("S_EP_CostUnit", costUnitID);

            if (costUnitDic == null)
            {
                throw new BusinessException("成本单元为空");
            }
            var cbsNodeDic = this.GetDataDicByID("S_EP_CBSNode", costUnitDic.GetValue("CBSNodeID"));

            if (cbsNodeDic == null)
            {
                throw new BusinessException("未找到成本单元的cbsNode节点");
            }

            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() + "】的节点");
            }

            dic["Name"]           = subjectNode["Name"].ToString();
            dic["Code"]           = subjectNode["Code"].ToString();
            dic["CBSNodeFullID"]  = subjectNode["FullID"].ToString();
            dic["CBSFullCode"]    = subjectNode["FullCode"].ToString();
            dic["CBSNodeID"]      = subjectNode["ID"].ToString();
            dic["SubjectCode"]    = subjectNode["SubjectCode"].ToString();
            dic["BelongDept"]     = subjectNode["ChargerDept"].ToString();
            dic["BelongDeptName"] = subjectNode["ChargerDeptName"].ToString();
            dic["BelongUser"]     = subjectNode["ChargerUser"].ToString();
            dic["BelongUserName"] = subjectNode["ChargerUserName"].ToString();
            dic["CostType"]       = SubjectType.HRCost.ToString();
            if (!String.IsNullOrEmpty(dic["BelongMonth"].ToString()))
            {
                var nBelongMonth = Convert.ToInt32(dic["BelongMonth"].ToString());
                dic["BelongQuarter"] = ((nBelongMonth - 1) / 3 + 1).ToString();
            }
        }
コード例 #18
0
        private void ValidateConfirmNode(string id, string nodeID)
        {
            //判断是否是最后确认节点
            var dt = this.SQLDB.ExecuteDataTable(string.Format("select top 1 ID,ConfirmDate from S_EP_IncomeInvoiceConfirm where InvoiceID='{0}' order by ID desc ", id));

            if (dt.Rows.Count == 0)
            {
                throw new Formula.Exceptions.BusinessValidationException("无确认信息,无需撤销!");
            }
            var dicConfirm = FormulaHelper.DataRowToDic(dt.Rows[0]);

            if (nodeID != dicConfirm.GetValue("ID"))
            {
                throw new Formula.Exceptions.BusinessValidationException("只能逐步撤销节点");
            }
            CostFO.ValidatePeriodIsClosed(Convert.ToDateTime(dicConfirm.GetValue("ConfirmDate")));
        }
コード例 #19
0
 protected override void BeforeSave(Dictionary <string, string> dic, Base.Logic.Domain.S_UI_Form formInfo, bool isNew)
 {
     if (isNew)
     {
         CostFO.ValidatePeriodIsClosed(new DateTime(Convert.ToInt32(dic["BelongYear"]), Convert.ToInt32(dic["BelongMonth"]), 1), "无法再在该月份上报工时");
         //不能重复上报
         //if (String.IsNullOrEmpty(dic.GetValue("DepartInfo")))
         //{
         //    throw new Formula.Exceptions.BusinessValidationException("必须指定部门");
         //}
         //string submitSql = @"select count(1) from S_EP_WorkHourDepartSubmit where BelongYear = {0} and BelongMonth = {1} and DepartInfo = '{2}' and State != 'Removed'";
         //var resObj = this.SQLDB.ExecuteScalar(string.Format(submitSql, dic.GetValue("BelongYear"), dic.GetValue("BelongMonth"), dic.GetValue("DepartInfo")));
         //if (resObj != null && (int)resObj > 0)
         //{
         //    throw new Formula.Exceptions.BusinessValidationException(string.Format("该部门在{0}年{1}月已经上报过,不能重复上报"));
         //}
     }
 }
コード例 #20
0
        public JsonResult ValidateData(string belongYear, string belongMonth)
        {
            var i = 0;

            if (string.IsNullOrWhiteSpace(belongYear) || string.IsNullOrWhiteSpace(belongMonth))
            {
                throw new Formula.Exceptions.BusinessValidationException("请选择年月!");
            }
            if (!int.TryParse(belongYear, out i) || !int.TryParse(belongMonth, out i))
            {
                throw new Formula.Exceptions.BusinessValidationException("年月格式不正确!");
            }

            var dateTime = Convert.ToDateTime(string.Format("{0}-{1}-01", belongYear, belongMonth));

            CostFO.ValidatePeriodIsClosed(dateTime);

            return(Json(""));
        }
コード例 #21
0
        public void Push()
        {
            //判断是否是最后确认节点
            var dt = this.DB.ExecuteDataTable(string.Format("select top 1 ID,ConfirmDate from S_EP_IncomeInvoiceConfirm where InvoiceID='{0}' order by ID desc ", this.ModelDic.GetValue("InvoiceID")));

            if (dt.Rows.Count == 0)
            {
                throw new Formula.Exceptions.BusinessValidationException("无确认信息,无需撤销!");
            }
            var dicConfirm = FormulaHelper.DataRowToDic(dt.Rows[0]);

            if (this.ModelDic.GetValue("InvoiceConfirmID") != dicConfirm.GetValue("ID"))
            {
                throw new Formula.Exceptions.BusinessValidationException("只能逐步撤销节点");
            }
            CostFO.ValidatePeriodIsClosed(Convert.ToDateTime(dicConfirm.GetValue("ConfirmDate")));

            string sql = string.Format(@"delete from S_EP_IncomeInvoiceConfirm where ID='{0}' ", this.ModelDic.GetValue("InvoiceConfirmID"));

            this.DB.ExecuteNonQuery(sql);
        }
コード例 #22
0
        protected override void BeforeSave(Dictionary <string, string> dic, Base.Logic.Domain.S_UI_Form formInfo, bool isNew)
        {
            CostFO.ValidatePeriodIsClosed(DateTime.Now);

            #region  累计和当期相互根据逻辑计算赋予默认值(前提是有一个数据为空)
            var lastScale    = String.IsNullOrEmpty(dic.GetValue("LastScale")) ? 0m : Convert.ToDecimal(dic.GetValue("LastScale"));
            var totalScale   = 0m;
            var currentScale = 0m;
            if (String.IsNullOrEmpty(dic.GetValue("TotalScale")) && !String.IsNullOrEmpty(dic.GetValue("CurrentScale")))
            {
                currentScale = Convert.ToDecimal(dic.GetValue("CurrentScale"));
                totalScale   = currentScale + lastScale;
                dic.SetValue("TotalScale", totalScale.ToString());
            }
            else if (!String.IsNullOrEmpty(dic.GetValue("TotalScale")) && String.IsNullOrEmpty(dic.GetValue("CurrentScale")))
            {
                totalScale   = Convert.ToDecimal(dic.GetValue("TotalScale"));
                currentScale = Convert.ToDecimal(dic.GetValue("TotalScale")) + lastScale;
                dic.SetValue("CurrentScale", currentScale.ToString());
            }
            #endregion
        }
コード例 #23
0
        public JsonResult AdjustTotalValue(string ids, string totalValue)
        {
            var     costInfoDT      = this.SQLDB.ExecuteDataTable(string.Format("select * from S_EP_CostInfo where id in ('{0}')", ids.Replace(",", "','")));
            var     costInfoDicList = FormulaHelper.DataTableToListDic(costInfoDT);
            decimal dTotalValue     = 0;

            decimal.TryParse(totalValue, out dTotalValue);
            foreach (var dic in costInfoDicList)
            {
                CostFO.ValidatePeriodIsClosed(new DateTime((int)dic["BelongYear"], (int)dic["BelongMonth"], 1), "不能调整成本");
                dic.SetValue("TotalPrice", totalValue);
                decimal dWorkHour = 0;
                decimal.TryParse(dic.GetValue("Quantity"), out dWorkHour);
                if (dWorkHour != 0)
                {
                    decimal unitPrice = dTotalValue / dWorkHour;
                    dic.SetValue("UnitPrice", unitPrice.ToString("0.00"));
                }
                dic.UpdateDB(this.SQLDB, "S_EP_CostInfo", dic.GetValue("ID"));
            }

            return(Json(""));
        }
コード例 #24
0
        public void Push()
        {
            #region 判断节点是否是最后确认节点
            var sql = string.Format(@"select top 1 ID,CBSInfoID,ConfirmDate,FlowPhase as ConfirmFlowPhase from S_EP_SupplierContractConfirm 
where SubContractDetailID='{0}' order by ID desc ", this.ModelDic.GetValue("SubContractDetailID"));
            var dt  = this.DB.ExecuteDataTable(sql);
            if (dt.Rows.Count == 0)
            {
                throw new Formula.Exceptions.BusinessValidationException("要撤销的节点不存在!");
            }
            var dicConfirm = FormulaHelper.DataRowToDic(dt.Rows[0]);
            if (this.ModelDic.GetValue("SubContractConfirmID") != dicConfirm.GetValue("ID"))
            {
                throw new Formula.Exceptions.BusinessValidationException("只能逐步撤销节点");
            }

            #endregion

            CostFO.ValidatePeriodIsClosed(Convert.ToDateTime(dicConfirm.GetValue("ConfirmDate")));

            var cbsInfoDic = this.GetDataDicByID("S_EP_CBSInfo", dicConfirm.GetValue("CBSInfoID"));
            if (cbsInfoDic == null)
            {
                throw new Formula.Exceptions.BusinessValidationException("没有找到成本单元对应的核算项目,无法撤销!");
            }

            sql  = string.Format(@"delete from S_EP_SupplierContractConfirm where ID='{0}' ", this.ModelDic.GetValue("SubContractConfirmID"));
            sql += string.Format(@"delete from S_EP_CostInfo where RelateID='{0}' ", this.ModelDic.GetValue("SubContractConfirmID"));
            sql += string.Format(@"update S_SP_SupplierContract_ContractSplit 
set MinContractValue=(select ISNULL(sum(CurrentValue),0) from S_EP_SupplierContractConfirm where SubContractDetailID='{0}') 
where ID='{0}'  ", this.ModelDic.GetValue("SubContractDetailID"));
            this.DB.ExecuteNonQuery(sql);

            var cbsInfo = new S_EP_CBSInfo(cbsInfoDic);
            cbsInfo.SummaryCostValue();
        }
コード例 #25
0
        public JsonResult LoadUserWorkHourFromHR(string belongYear, string belongMonth)
        {
            CostFO.ValidatePeriodIsClosed(new DateTime(Convert.ToInt32(belongYear), Convert.ToInt32(belongMonth), 1), "无法再在该月份上报工时");

            var    hrSqlDB      = SQLHelper.CreateSqlHelper(ConnEnum.HR);
            string sql          = @"select UserDeptID,UserDeptName,
                         UserID as UserInfo, 
                         UserName as UserInfoName,
                         ProjectID as CostUnitInfo,
                         ProjectName as CostUnitInfoName,
                         sum(isnull(WorkHourValue,0)) as WorkHour
                         from S_W_UserWorkHour
                         where BelongYear = {0} and BelongMonth = {1} group by UserID,UserName,ProjectID,ProjectName,UserDeptID,UserDeptName";
            var    dt           = hrSqlDB.ExecuteDataTable(string.Format(sql, belongYear, belongMonth));
            var    list         = FormulaHelper.DataTableToListDic(dt);
            var    costCodeList = list.GroupBy(a => new { CostUnitInfo = a.GetValue("CostUnitInfo"), CostUnitInfoName = a.GetValue("CostUnitInfoName") }).Select(a => a.Key);

            foreach (var item in costCodeList)
            {
                var costUnitDT = this.SQLDB.ExecuteDataTable(@"select S_EP_CostUnit.*,ChargerUser,ChargerUserName,ChargerDept,ChargerDeptName from S_EP_CostUnit
                                                             inner join S_EP_CBSNode on S_EP_CBSNode.ID = S_EP_CostUnit.CBSNodeID 
                                                             where S_EP_CostUnit.ID = '" + item.CostUnitInfo + "'");
                if (costUnitDT.Rows.Count == 0)
                {
                    continue;
                }
                DataRow dr = costUnitDT.Rows[0];

                var workHourSubmitDic = new Dictionary <string, object>();
                workHourSubmitDic.SetValue("ID", FormulaHelper.CreateGuid());
                workHourSubmitDic.SetValue("CreateUserID", CurrentUserInfo.UserID);
                workHourSubmitDic.SetValue("CreateUser", CurrentUserInfo.UserName);
                workHourSubmitDic.SetValue("ModifyUserID", CurrentUserInfo.UserID);
                workHourSubmitDic.SetValue("ModifyUser", CurrentUserInfo.UserName);
                workHourSubmitDic.SetValue("CreateDate", DateTime.Now);
                workHourSubmitDic.SetValue("CreateDate", DateTime.Now);
                workHourSubmitDic.SetValue("ModifyDate", DateTime.Now);

                workHourSubmitDic.SetValue("FlowPhase", "End");
                workHourSubmitDic.SetValue("CostUnitID", dr["ID"]);
                workHourSubmitDic.SetValue("CostUnitInfo", dr["ID"]);
                workHourSubmitDic.SetValue("CostUnitInfoName", dr["Name"]);
                workHourSubmitDic.SetValue("Code", dr["Code"]);
                workHourSubmitDic.SetValue("ChargerUser", dr["ChargerUser"]);
                workHourSubmitDic.SetValue("ChargerUserName", dr["ChargerUserName"]);
                workHourSubmitDic.SetValue("ChargerDept", dr["ChargerDept"]);
                workHourSubmitDic.SetValue("ChargerDeptName", dr["ChargerDeptName"]);
                workHourSubmitDic.SetValue("BelongYear", belongYear);
                workHourSubmitDic.SetValue("BelongMonth", belongMonth);
                workHourSubmitDic.SetValue("State", "Finish");

                var detailList = list.Where(a => a.GetValue("CostUnitInfo") == item.CostUnitInfo);

                var index         = 0;
                var detailDicList = new List <Dictionary <string, object> >();
                foreach (var detail in detailList)
                {
                    var workHourSubmitDetailDic = new Dictionary <string, object>();
                    detailDicList.Add(workHourSubmitDetailDic);

                    workHourSubmitDetailDic.SetValue("ID", FormulaHelper.CreateGuid());
                    workHourSubmitDetailDic.SetValue("S_EP_WorkHourSubmitID", workHourSubmitDic.GetValue("ID"));
                    workHourSubmitDetailDic.SetValue("SortIndex", index);
                    workHourSubmitDetailDic.SetValue("UserInfo", detail["UserInfo"]);
                    workHourSubmitDetailDic.SetValue("UserInfoName", detail["UserInfoName"]);
                    workHourSubmitDetailDic.SetValue("WorkHour", detail["WorkHour"]);
                    workHourSubmitDetailDic.SetValue("UserDeptInfo", detail["UserDeptID"]);
                    workHourSubmitDetailDic.SetValue("UserDeptInfoName", detail["UserDeptName"]);
                    index++;
                }
                workHourSubmitDic.SetValue("WorkHourDetail", JsonHelper.ToJson(detailDicList));
                workHourSubmitDic.InsertDB(this.SQLDB, "S_EP_WorkHourSubmit", workHourSubmitDic.GetValue("ID"));
                foreach (var detailDic in detailDicList)
                {
                    detailDic.InsertDB(this.SQLDB, "S_EP_WorkHourSubmit_WorkHourDetail");
                }

                S_EP_WorkHourSubmit submit = new S_EP_WorkHourSubmit(workHourSubmitDic);
                submit.Push();
            }

            return(Json(""));
        }
コード例 #26
0
        protected override void BeforeDelete(string[] Ids)
        {
            var sql     = string.Format(@"select PaymentCostInfo.ID,
PaymentCostInfo.CostUnitID as CostUnit,
ISNULL(PaymentCostInfo.CostValue,0) as CostValue,
Payment.ID as PaymentID,
Payment.PaymentDate,
Payment.PaymentUser,
Payment.PaymentUserName,
isnull(SupplierContract.TaxRate,0) as TaxRate
from (select * from S_SP_Payment where ID in ('{0}') ) as Payment
inner join S_SP_Payment_CostInfo PaymentCostInfo on Payment.ID=PaymentCostInfo.S_SP_PaymentID
left join S_SP_SupplierContract SupplierContract on Payment.Contract = SupplierContract.ID ", string.Join("','", Ids));
            var dicList = FormulaHelper.DataTableToListDic(MarketSQLDB.ExecuteDataTable(sql));

            foreach (var dic in dicList)
            {
                Expenses.Logic.BusinessFacade.DataInterfaceFo.ValidateDataSyn("S_SP_Payment", dic.GetValue("PaymentID"));
                if (string.IsNullOrEmpty(dic.GetValue("PaymentDate")))
                {
                    throw new Formula.Exceptions.BusinessValidationException("付款日期为空,请确认!");
                }
                CostFO.ValidatePeriodIsClosed(Convert.ToDateTime(dic.GetValue("PaymentDate")));

                var dt = MarketSQLDB.ExecuteDataTable(string.Format(@"select * from S_EP_CostUnit where ID='{0}' ", dic.GetValue("CostUnit")));
                if (dt.Rows.Count == 0)
                {
                    throw new Formula.Exceptions.BusinessValidationException("没有找到指定的成本单元,无法确认成本");
                }
                var unitDic = FormulaHelper.DataRowToDic(dt.Rows[0]);

                dt = MarketSQLDB.ExecuteDataTable(string.Format(@"select * from S_EP_CBSNode where ID='{0}' ", unitDic.GetValue("CBSNodeID")));
                if (dt.Rows.Count == 0)
                {
                    throw new Formula.Exceptions.BusinessValidationException("没有找到成本单元对应的CBS节点,无法确认成本");
                }
                var unitCBSNode = FormulaHelper.DataRowToDic(dt.Rows[0]);

                dt = MarketSQLDB.ExecuteDataTable(string.Format(@"select * from S_EP_CBSInfo where ID='{0}' ", unitDic.GetValue("CBSInfoID")));
                if (dt.Rows.Count == 0)
                {
                    throw new Formula.Exceptions.BusinessValidationException("没有找到成本单元对应的核算项目,无法确认成本");
                }
                var cbsInfoDic = FormulaHelper.DataRowToDic(dt.Rows[0]);

                var costDetailDic = new Dictionary <string, object>();

                sql = string.Format(@"delete from S_EP_CostInfo where RelateID='{0}' ", dic.GetValue("ID"));
                MarketSQLDB.ExecuteNonQuery(sql);
                var cbsInfo = new Expenses.Logic.Domain.S_EP_CBSInfo(cbsInfoDic);
                cbsInfo.SummaryCostValue();
            }

            var cons = this.BusinessEntities.Set <S_SP_Payment>().Where(t => Ids.Contains(t.ID))
                       .Select(t => t.S_SP_SupplierContract).ToList();
            //承兑汇票
            var payMents = this.BusinessEntities.Set <S_SP_Payment>().Where(t => Ids.Contains(t.ID)).ToList();
            //修改承兑汇票支付状态
            var acceptanceBillIDs = new List <string>();

            foreach (var payMent in payMents)
            {
                var billIDs = payMent.S_SP_Payment_AcceptanceBill.Select(a => a.AcceptanceBillID).ToList();
                var tmpList = this.BusinessEntities.Set <S_C_AcceptanceBill>().Where(a => billIDs.Contains(a.ID)).ToList();
                foreach (var tmp in tmpList)
                {
                    tmp.State = "UnPaid";
                }
            }

            this.BusinessEntities.Set <S_FC_CostInfo>().Delete(d => Ids.Contains(d.RelateID));
            foreach (var con in cons)
            {
                con.SumPaymentValue = con.S_SP_Payment.Where(a => !Ids.Contains(a.ID)).Sum(a => a.PaymentValue);
            }
            this.BusinessEntities.SaveChanges();

            var OADB = SQLHelper.CreateSqlHelper(ConnEnum.OfficeAuto);

            OADB.ExecuteNonQuery("Delete from S_FC_CostInfo where RelateID in ('" + string.Join("','", Ids) + "')");
        }
コード例 #27
0
        private void ToCostInfo(Dictionary <string, string> entity)
        {
            if (string.IsNullOrEmpty(entity.GetValue("PaymentDate")))
            {
                throw new Formula.Exceptions.BusinessValidationException("请填写付款日期");
            }
            CostFO.ValidatePeriodIsClosed(Convert.ToDateTime(entity.GetValue("PaymentDate")));

            var sql     = string.Format(@"select PaymentCostInfo.ID,
PaymentCostInfo.CostUnitID as CostUnit,
ISNULL(PaymentCostInfo.CostValue,0) as CostValue,
Payment.PaymentDate,
Payment.PaymentUser,
Payment.PaymentUserName,
isnull(SupplierContract.TaxRate,0) as TaxRate
from (select * from S_SP_Payment where ID='{0}') as Payment
inner join S_SP_Payment_CostInfo PaymentCostInfo on Payment.ID=PaymentCostInfo.S_SP_PaymentID
left join S_SP_SupplierContract SupplierContract on Payment.Contract = SupplierContract.ID ", entity.GetValue("ID"));
            var dicList = FormulaHelper.DataTableToListDic(MarketSQLDB.ExecuteDataTable(sql));

            foreach (var dic in dicList)
            {
                var dt = MarketSQLDB.ExecuteDataTable(string.Format(@"select * from S_EP_CostUnit where ID='{0}' ", dic.GetValue("CostUnit")));
                if (dt.Rows.Count == 0)
                {
                    throw new Formula.Exceptions.BusinessValidationException("没有找到指定的成本单元,无法确认成本");
                }
                var unitDic = FormulaHelper.DataRowToDic(dt.Rows[0]);

                dt = MarketSQLDB.ExecuteDataTable(string.Format(@"select * from S_EP_CBSNode where ID='{0}' ", unitDic.GetValue("CBSNodeID")));
                if (dt.Rows.Count == 0)
                {
                    throw new Formula.Exceptions.BusinessValidationException("没有找到成本单元对应的CBS节点,无法确认成本");
                }
                var unitCBSNode = FormulaHelper.DataRowToDic(dt.Rows[0]);

                dt = MarketSQLDB.ExecuteDataTable(string.Format(@"select * from S_EP_CBSInfo where ID='{0}' ", unitDic.GetValue("CBSInfoID")));
                if (dt.Rows.Count == 0)
                {
                    throw new Formula.Exceptions.BusinessValidationException("没有找到成本单元对应的核算项目,无法确认成本");
                }
                var cbsInfoDic = FormulaHelper.DataRowToDic(dt.Rows[0]);

                var costValue      = string.IsNullOrEmpty(dic.GetValue("CostValue")) ? 0m : Convert.ToDecimal(dic.GetValue("CostValue"));
                var taxRate        = string.IsNullOrEmpty(dic.GetValue("TaxRate")) ? 0m : Convert.ToDecimal(dic.GetValue("TaxRate"));
                var taxValue       = costValue / (1 + taxRate) * taxRate;
                var clearCostValue = costValue - taxValue;

                var costDetailDic = new Dictionary <string, object>();
                var subjectDt     = this.MarketSQLDB.ExecuteDataTable(String.Format(@"select * from S_EP_CBSNode with(nolock)
where FullID like '{0}%' order by FullID", unitCBSNode.GetValue("FullID")));
                var subjectNode   = subjectDt.AsEnumerable().FirstOrDefault(c => c["SubjectType"] != null && c["SubjectType"] != DBNull.Value &&
                                                                            c["SubjectType"].ToString() == SubjectType.SubContractCost.ToString());

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

                var costState = "Finish";
                costDetailDic.SetValue("Name", subjectNode["Name"]);
                costDetailDic.SetValue("CBSFullCode", subjectNode["FullCode"]);
                costDetailDic.SetValue("CBSNodeID", subjectNode["ID"]);
                costDetailDic.SetValue("CBSNodeFullID", subjectNode["FullID"]);
                if (String.IsNullOrEmpty(costDetailDic.GetValue("Name")))
                {
                    costDetailDic.SetValue("Name", "采购分包费");
                }
                costDetailDic.SetValue("Code", subjectNode["Code"]);
                if (String.IsNullOrEmpty(costDetailDic.GetValue("Code")))
                {
                    costDetailDic.SetValue("Code", unitCBSNode.GetValue("Code"));
                }
                costDetailDic.SetValue("CostType", SubjectType.SubContractCost.ToString());
                costDetailDic.SetValue("CBSInfoID", unitDic.GetValue("CBSInfoID"));
                costDetailDic.SetValue("CostUnitID", unitDic.GetValue("ID"));
                costDetailDic.SetValue("SubjectCode", subjectNode["SubjectCode"]);
                costDetailDic.SetValue("RelateID", dic.GetValue("ID"));
                var costDate = String.IsNullOrEmpty(dic.GetValue("PaymentDate")) ? DateTime.Now : Convert.ToDateTime(dic.GetValue("PaymentDate"));
                costDetailDic.SetValue("CostDate", costDate);
                costDetailDic.SetValue("BelongYear", costDate.Year);
                costDetailDic.SetValue("BelongMonth", costDate.Month);
                costDetailDic.SetValue("BelongQuarter", (costDate.Month - 1) / 3 + 1);
                costDetailDic.SetValue("TotalPrice", costValue);
                costDetailDic.SetValue("TaxRate", taxRate);
                costDetailDic.SetValue("TaxValue", taxValue);
                costDetailDic.SetValue("ClearValue", clearCostValue);
                costDetailDic.SetValue("BelongDept", unitCBSNode.GetValue("ChargerDept"));
                costDetailDic.SetValue("BelongDeptName", unitCBSNode.GetValue("ChargerDeptName"));
                costDetailDic.SetValue("BelongUser", unitCBSNode.GetValue("ChargerUser"));
                costDetailDic.SetValue("BelongUserName", unitCBSNode.GetValue("ChargerUserName"));
                costDetailDic.SetValue("State", costState);
                costDetailDic.SetValue("Status", costState);
                costDetailDic.SetValue("CreateUser", dic.GetValue("PaymentUser"));
                costDetailDic.SetValue("CreateUserName", dic.GetValue("PaymentUserName"));
                costDetailDic.SetValue("CreateDate", DateTime.Now);
                sql = string.Format(@"delete from S_EP_CostInfo where RelateID='{0}' ", dic.GetValue("ID"));
                MarketSQLDB.ExecuteNonQuery(sql);
                costDetailDic.InsertDB(this.MarketSQLDB, "S_EP_CostInfo");
                var cbsInfo = new S_EP_CBSInfo(cbsInfoDic);
                cbsInfo.SummaryCostValue();
            }
        }
コード例 #28
0
 protected override void BeforeSave(Dictionary <string, string> dic, S_UI_Form formInfo, bool isNew)
 {
     CostFO.ValidatePeriodIsClosed(Convert.ToDateTime(dic.GetValue("SettlementDate")));
 }
コード例 #29
0
        //批量确认开票
        public JsonResult BatchConfirm()
        {
            if (SysParams.Params.GetValue("IncomeInvoiceConfirm").ToLower() != "true")//开票确认
            {
                throw new Formula.Exceptions.BusinessValidationException("系统参数设置中【开票收入确认】为否!");
            }

            var confirmDate = DateTime.Now.Date;

            if (!DateTime.TryParse(Request["ConfirmDate"], out confirmDate))
            {
                throw new Formula.Exceptions.BusinessValidationException("请选择确认日期!");
            }
            CostFO.ValidatePeriodIsClosed(confirmDate);

            var    list    = JsonHelper.ToList(Request["ListData"]);
            string mainSql = "";

            foreach (var item in list)
            {
                #region 验证数据,变量赋值
                //上期开票确认信息
                var sql = string.Format(@"select * ,
1 as TotalProgress,--本期确认进度_默认100
InvoiceValue as TotalValue,--本期末累计确认金额_默认为合同额(全确认)
CurrentValue/(1+TaxRate)*TaxRate as TaxValue,--税金
CurrentValue/(1+TaxRate) as ClearValue,--去税金额
InvoiceValue
from (

select Invoice.ID,
ISNULL(Invoice.Amount,0) as InvoiceValue,
Invoice.PayerUnit,
Invoice.TaxRate,
Invoice.IncomeUnit,
Invoice.InvoiceType,
Invoice.ContractInfoID,
Invoice.ContractName,
Invoice.ContractCode,
ISNULL(ConfirmInfo.TotalProgress,0) as LastProgress,--上期末累计确认比例
ISNULL(ConfirmInfo.TotalValue,0) as LastValue,--上期末累计确认金额
case when ISNULL(Invoice.Amount,0)-ISNULL(ConfirmInfo.TotalValue,0)<=0 then 0 else 
ISNULL(Invoice.Amount,0)-ISNULL(ConfirmInfo.TotalValue,0) end as CurrentValue--本期确认金额
from (select * from S_C_Invoice  where ID='{0}') as Invoice
outer apply(select top 1 * from S_EP_IncomeInvoiceConfirm a where Invoice.ID=a.InvoiceID order by a.ID desc) ConfirmInfo
) as a
", item.GetValue("ID"));
                var dt  = SQLDB.ExecuteDataTable(sql);
                if (dt.Rows.Count == 0)
                {
                    throw new Formula.Exceptions.BusinessValidationException(string.Format("项目【{0}】没有找到指定的开票信息,无法进行确认", item.GetValue("Name")));
                }
                var dic = FormulaHelper.DataRowToDic(dt.Rows[0]);

                var dicConfirm = new Dictionary <string, object>();
                dicConfirm.SetValue("ID", FormulaHelper.CreateGuid());
                dicConfirm.SetValue("InvoiceID", dic.GetValue("ID"));
                dicConfirm.SetValue("Contract", dic.GetValue("ContractInfoID"));
                dicConfirm.SetValue("ContractName", dic.GetValue("ContractName"));
                dicConfirm.SetValue("ContractCode", dic.GetValue("ContractCode"));
                dicConfirm.SetValue("PayerUnit", dic.GetValue("PayerUnit"));
                dicConfirm.SetValue("InvoiceValue", dic.GetValue("InvoiceValue"));
                dicConfirm.SetValue("InvoiceType", dic.GetValue("InvoiceType"));
                dicConfirm.SetValue("LastProgress", dic.GetValue("LastProgress"));
                dicConfirm.SetValue("LastValue", dic.GetValue("LastValue"));
                dicConfirm.SetValue("TotalProgress", dic.GetValue("TotalProgress"));
                dicConfirm.SetValue("TotalValue", dic.GetValue("TotalValue"));
                dicConfirm.SetValue("CurrentValue", dic.GetValue("CurrentValue"));
                dicConfirm.SetValue("TaxRate", dic.GetValue("TaxRate"));
                dicConfirm.SetValue("TaxValue", dic.GetValue("TaxValue"));
                dicConfirm.SetValue("ClearValue", dic.GetValue("ClearValue"));
                dicConfirm.SetValue("ApplyUser", CurrentUserInfo.UserID);
                dicConfirm.SetValue("ApplyUserName", CurrentUserInfo.UserName);
                dicConfirm.SetValue("ApplyDate", DateTime.Now.ToString("yyyy-MM-dd"));
                dicConfirm.SetValue("ConfirmDate", DateTime.Now.ToString("yyyy-MM-dd"));
                dicConfirm.SetValue("IncomeUnitID", dic.GetValue("IncomeUnit"));
                dicConfirm.SetValue("FlowPhase", "End");
                #endregion
                mainSql += dicConfirm.CreateInsertSql(this.SQLDB, "S_EP_IncomeInvoiceConfirm", dicConfirm.GetValue("ID"));
            }
            this.SQLDB.ExecuteNonQuery(mainSql);
            return(Json(""));
        }
コード例 #30
0
        protected override void BeforeSave(Dictionary <string, string> dic, S_UI_Form formInfo, bool isNew)
        {
            CheckSubContractConfirmMethod();
            if (String.IsNullOrEmpty(dic.GetValue("ConfirmDate")))
            {
                throw new Formula.Exceptions.BusinessValidationException("请选择确认日期!");
            }
            var dateTime = String.IsNullOrEmpty(dic.GetValue("ConfirmDate")) ? DateTime.Now : Convert.ToDateTime(dic.GetValue("ConfirmDate"));

            CostFO.ValidatePeriodIsClosed(dateTime);

            var totalProgress = 0m;

            decimal.TryParse(dic.GetValue("TotalProgress"), out totalProgress);
            if (totalProgress <= 0 || totalProgress > 1)
            {
                throw new Formula.Exceptions.BusinessValidationException("本期末累计进度必须大于0!");
            }

            if (isNew)
            {
                var sql           = string.Format(@"select ContractSplit.ID as SplitID,
ISNULL(ContractSplit.SplitValue,0) as SplitValue,
ContractSplit.ChargerUserName,
ContractSplit.ChargerDeptName,
SupplierContract.Supplier,
SupplierContract.SupplierName,
SupplierContract.ProjectInfo,
SupplierContract.ProjectInfoName,
SupplierContract.Name as SubContracName,
SupplierContract.SerialNumber as SubContracCode,
SupplierContract.TaxName,
isnull(SupplierContract.TaxRate,0) as TaxRate,
ISNULL(ConfirmInfo.TotalProgress,0) as LastProgress,--上期末累计确认比例
ISNULL(ConfirmInfo.TotalValue,0) as LastValue,--上期末累计确认金额
RevertInfo.FlowPhase as RevertFlowPhase,
RevertInfo.ID as ConfirmRevertID
from (select * from S_SP_SupplierContract_ContractSplit where ID='{0}') as ContractSplit
left join S_SP_SupplierContract SupplierContract on S_SP_SupplierContractID = SupplierContract.ID
outer apply(select top 1 * from S_EP_SupplierContractConfirm a where ContractSplit.ID=a.SubContractDetailID order by a.ID desc) ConfirmInfo
left join S_EP_SupplierContractConfirmRevert RevertInfo on ConfirmInfo.ID=RevertInfo.SubContractConfirmID ", dic.GetValue("SubContractDetailID"));
                var dtLastConfirm = SQLDB.ExecuteDataTable(sql);
                if (dtLastConfirm.Rows.Count > 0)
                {
                    var dicLastConfirm = FormulaHelper.DataRowToDic(dtLastConfirm.Rows[0]);
                    var lastProgress   = string.IsNullOrEmpty(dicLastConfirm.GetValue("LastProgress")) ? 0m : Convert.ToDecimal(dicLastConfirm.GetValue("LastProgress"));
                    if (lastProgress >= 1)
                    {
                        throw new Formula.Exceptions.BusinessValidationException("已经确认至100%,不能再进行确认!");
                    }
                    if (totalProgress <= lastProgress)
                    {
                        throw new Formula.Exceptions.BusinessValidationException(string.Format("本期末累计确认比例【{0}%】必须大于上期末累计确认比例【{1}%】", Math.Round(totalProgress * 100, 2), Math.Round(lastProgress * 100, 2)));
                    }
                    if (!string.IsNullOrWhiteSpace(dicLastConfirm.GetValue("ConfirmRevertID")))
                    {
                        throw new Formula.Exceptions.BusinessValidationException("确认节点正在撤销中,不能进行确认!");
                    }
                    var splitValue = string.IsNullOrEmpty(dicLastConfirm.GetValue("SplitValue")) ? 0m : Convert.ToDecimal(dicLastConfirm.GetValue("SplitValue"));
                    if (splitValue == 0)
                    {
                        throw new Formula.Exceptions.BusinessValidationException("合同金额为0,不能确认!");
                    }

                    #region 计算【本期末累计确认金额】【本期确认金额】【税金】【去税金额】
                    var lastValue    = string.IsNullOrEmpty(dicLastConfirm.GetValue("LastValue")) ? 0m : Convert.ToDecimal(dicLastConfirm.GetValue("LastValue"));
                    var totalValue   = splitValue * totalProgress; //本期末累计确认金额
                    var currentValue = totalValue - lastValue;     //本期确认金额
                    if (currentValue <= 0)
                    {
                        throw new Formula.Exceptions.BusinessValidationException(string.Format("本期确认金额【{0}】必须大于【0】,请确认!", Math.Round(currentValue, 2)));
                    }
                    var taxRate    = string.IsNullOrEmpty(dicLastConfirm.GetValue("TaxRate")) ? 0m : Convert.ToDecimal(dicLastConfirm.GetValue("TaxRate")); //税率
                    var taxValue   = currentValue * taxRate / (1 + taxRate);                                                                                //税金
                    var clearValue = currentValue / (1 + taxRate);                                                                                          //去税金额

                    dicLastConfirm.SetValue("LastProgress", lastProgress);
                    dicLastConfirm.SetValue("LastValue", lastValue);
                    dicLastConfirm.SetValue("TotalProgress", totalProgress);
                    dicLastConfirm.SetValue("TotalValue", Math.Round(totalValue, 2));
                    dicLastConfirm.SetValue("CurrentValue", Math.Round(currentValue, 2));
                    dicLastConfirm.SetValue("TaxRate", taxRate);
                    dicLastConfirm.SetValue("TaxValue", Math.Round(taxValue, 2));
                    dicLastConfirm.SetValue("ClearValue", Math.Round(clearValue, 2));

                    #endregion
                }
                else
                {
                    throw new Formula.Exceptions.BusinessValidationException("没有找到指定的委外合同,无法进行确认");
                }
            }
            else
            {
                var lastProgress = Convert.ToDecimal(dic.GetValue("LastProgress"));
                if (totalProgress <= lastProgress)
                {
                    throw new Formula.Exceptions.BusinessValidationException(string.Format("本期末累计确认比例【{0}%】必须大于上期末累计确认比例【{1}%】", totalProgress * 100, lastProgress * 100));
                }

                #region 计算【本期末累计确认金额】【本期确认金额】【税金】【去税金额】
                var splitValue   = Convert.ToDecimal(dic.GetValue("SplitValue"));
                var lastValue    = Convert.ToDecimal(dic.GetValue("LastValue"));
                var totalValue   = splitValue * totalProgress; //本期末累计确认金额
                var currentValue = totalValue - lastValue;     //本期确认金额
                if (currentValue <= 0)
                {
                    throw new Formula.Exceptions.BusinessValidationException(string.Format("本期确认金额【{0}】必须大于【0】,请确认!", Math.Round(currentValue, 2)));
                }
                var taxRate    = string.IsNullOrEmpty(dic.GetValue("TaxRate")) ? 0m : Convert.ToDecimal(dic.GetValue("TaxRate")); //税率
                var taxValue   = currentValue * taxRate / (1 + taxRate);                                                          //税金
                var clearValue = currentValue / (1 + taxRate);                                                                    //去税金额

                dic.SetValue("TotalProgress", totalProgress.ToString());
                dic.SetValue("TotalValue", Math.Round(totalValue, 2).ToString());
                dic.SetValue("CurrentValue", Math.Round(currentValue, 2).ToString());
                dic.SetValue("TaxValue", Math.Round(taxValue, 2).ToString());
                dic.SetValue("ClearValue", Math.Round(clearValue, 2).ToString());
                #endregion
            }
        }