Пример #1
0
        private S_I_ProjectInfo AddProject(T_CP_TaskNotice entity, S_I_Engineering engineering, T_CP_TaskNotice_PhaseDetail singlePhase = null)
        {
            var marketEntities = FormulaHelper.GetEntities <Market.Logic.Domain.MarketEntities>();

            S_I_ProjectInfo projectInfo = entity.Push();

            projectInfo.ModifyDate   = projectInfo.CreateDate;
            projectInfo.ModifyUser   = projectInfo.CreateUser;
            projectInfo.ModifyUserID = projectInfo.CreateUserID;

            //重新修改phaseValue、phaseName、Name、Code等信息
            if (singlePhase != null)
            {
                projectInfo.PhaseValue        = singlePhase.Phase;
                projectInfo.WBSRoot.PhaseCode = singlePhase.Phase;
                var phaseList = BaseConfigFO.GetWBSAttrList(WBSNodeType.Phase);
                var phaseItem = phaseList.FirstOrDefault(d => projectInfo.PhaseValue == d.Code);
                projectInfo.PhaseName      = phaseItem.Name;
                projectInfo.Name           = singlePhase.Name;
                projectInfo.Code           = singlePhase.Code;
                projectInfo.ChargeDeptID   = singlePhase.ChargeDept ?? entity.ChargeDept;
                projectInfo.ChargeDeptName = singlePhase.ChargeDeptName ?? entity.ChargeDeptName;
                projectInfo.ChargeUserID   = singlePhase.ChargeUser ?? entity.ChargeUser;
                projectInfo.ChargeUserName = singlePhase.ChargeUserName ?? entity.ChargeUserName;
                projectInfo.OtherDeptID    = singlePhase.OtherDept ?? entity.OtherDept;
                projectInfo.OtherDeptName  = singlePhase.OtherDeptName ?? entity.OtherDeptName;
                projectInfo.PlanStartDate  = singlePhase.PlanStartDate ?? entity.PlanStartDate;
                projectInfo.PlanFinishDate = singlePhase.PlanFinishDate ?? entity.PlanFinishDate;
            }

            projectInfo.ModifyDate   = projectInfo.CreateDate;
            projectInfo.ModifyUser   = projectInfo.CreateUser;
            projectInfo.ModifyUserID = projectInfo.CreateUserID;
            #region  步创建经营库的项目信息
            S_I_Project project    = null;
            var         marketClue = marketEntities.S_P_MarketClue.Find(entity.RelateID);
            project = marketEntities.S_I_Project.FirstOrDefault(d => d.TasKNoticeID == entity.ID);
            if (project != null)
            {
                throw new Formula.Exceptions.BusinessException("任务单已经下达过项目,无法重复下达");
            }
            project                    = new S_I_Project();
            project.ID                 = projectInfo.ID;
            project.TasKNoticeID       = entity.ID;
            project.TasKNoticeTmplCode = entity.TmplCode;
            project.Name               = projectInfo.Name;
            project.Code               = projectInfo.Code;
            project.Phase              = projectInfo.PhaseValue;
            project.ProjectClass       = projectInfo.ProjectClass;
            project.Customer           = projectInfo.CustomerID;
            project.CustomerName       = projectInfo.CustomerName;
            project.CreateDate         = DateTime.Now;
            project.EngineeringInfo    = entity.EngineeringID;
            project.ChargerDept        = projectInfo.ChargeDeptID;
            project.ChargerDeptName    = projectInfo.ChargeDeptName;
            project.ChargerUser        = projectInfo.ChargeUserID;
            project.ChargerUserName    = projectInfo.ChargeUserName;
            project.Country            = projectInfo.Country;
            project.Province           = projectInfo.Province;
            project.Area               = projectInfo.Area;
            project.City               = projectInfo.City;
            project.State              = projectInfo.State;
            project.ProjectScale       = entity.ProjectLevel;
            if (marketClue != null)
            {
                project.MakertClueID = marketClue.ID;
                marketClue.State     = Market.Logic.ClueState.Succeed.ToString();
            }
            marketEntities.S_I_Project.Add(project);
            entity.MarketProjectID = project.ID;
            #endregion

            #region  步绑定合同

            if (!String.IsNullOrEmpty(entity.ContractInfo))
            {
                var contract = marketEntities.Set <S_C_ManageContract>().Include("S_C_ManageContract_ProjectRelation")
                               .Include("S_C_ManageContract_ReceiptObj").FirstOrDefault(d => d.ID == entity.ContractInfo);
                if (contract != null)
                {
                    var relation = contract.S_C_ManageContract_ProjectRelation.FirstOrDefault(a => a.ProjectID == project.ID);
                    if (relation == null)
                    {
                        relation                      = new S_C_ManageContract_ProjectRelation();
                        relation.ID                   = FormulaHelper.CreateGuid();
                        relation.ProjectID            = project.ID;
                        relation.S_C_ManageContractID = contract.ID;
                        relation.ProjectCode          = project.Code;
                        relation.ProjectName          = project.Name;
                        if (contract.S_C_ManageContract_ProjectRelation.Count == 0)
                        {
                            if (entity.ContractValue.HasValue && contract.ContractRMBAmount > 0)
                            {
                                if (contract.ContractRMBAmount > 0)
                                {
                                    relation.Scale = entity.ContractValue.Value / contract.ContractRMBAmount * 100;
                                }
                                else
                                {
                                    relation.Scale = 0;
                                }
                                relation.ProjectValue = entity.ContractValue;
                                relation.TaxRate      = contract.TaxRate;
                                relation.TaxValue     = relation.ProjectValue / (1 + contract.TaxRate) * contract.TaxRate;
                                relation.ClearValue   = relation.ProjectValue - relation.TaxValue;
                            }
                            else
                            {
                                relation.Scale        = 100;
                                relation.ProjectValue = contract.ContractRMBAmount;
                                var taxRate    = contract.TaxRate.HasValue ? contract.TaxRate.Value : 0;
                                var taxValue   = contract.ContractRMBAmount / (1 + taxRate) * taxRate;
                                var clearVlaue = contract.ContractRMBAmount - taxValue;
                                relation.TaxRate    = taxRate;
                                relation.TaxValue   = taxValue;
                                relation.ClearValue = contract.ContractRMBAmount - taxValue;
                            }
                            foreach (var item in contract.S_C_ManageContract_ReceiptObj.ToList())
                            {
                                item.ProjectInfo     = project.ID;
                                item.ProjectInfoName = project.Name;
                                relation.TaxRate     = contract.TaxRate;
                            }
                        }
                        else
                        {
                            if (entity.ContractValue.HasValue && contract.ContractRMBAmount > 0)
                            {
                                if (contract.ContractRMBAmount > 0)
                                {
                                    relation.Scale = entity.ContractValue.Value / contract.ContractRMBAmount * 100;
                                }
                                else
                                {
                                    relation.Scale = 0;
                                }
                                relation.ProjectValue = entity.ContractValue;
                                relation.TaxRate      = contract.TaxRate;
                                relation.TaxValue     = relation.ProjectValue / (1 + contract.TaxRate) * contract.TaxRate;
                                relation.ClearValue   = relation.ProjectValue - relation.TaxValue;
                            }
                            else
                            {
                                relation.Scale        = 0;
                                relation.ProjectValue = 0;
                                relation.TaxRate      = contract.TaxRate;
                            }
                        }
                        contract.S_C_ManageContract_ProjectRelation.Add(relation);
                        if (String.IsNullOrEmpty(contract.EngineeringInfo) && engineering != null)
                        {
                            contract.EngineeringInfo     = engineering.ID;
                            contract.EngineeringInfoName = engineering.Name;
                        }
                    }
                }
            }
            else
            {
                var contractList = marketEntities.Set <S_C_ManageContract>().Include("S_C_ManageContract_ProjectRelation")
                                   .Include("S_C_ManageContract_ReceiptObj").Where(d => d.EngineeringInfo == entity.EngineeringID).ToList();
                foreach (var contract in contractList)
                {
                    var relation = contract.S_C_ManageContract_ProjectRelation.FirstOrDefault(a => a.ProjectID == project.ID);
                    if (relation == null)
                    {
                        relation                      = new S_C_ManageContract_ProjectRelation();
                        relation.ID                   = FormulaHelper.CreateGuid();
                        relation.ProjectID            = project.ID;
                        relation.S_C_ManageContractID = contract.ID;
                        relation.ProjectCode          = project.Code;
                        relation.ProjectName          = project.Name;
                        if (contract.S_C_ManageContract_ProjectRelation.Count == 0)
                        {
                            relation.Scale        = 100;
                            relation.ProjectValue = contract.ContractRMBAmount;
                            foreach (var item in contract.S_C_ManageContract_ReceiptObj.ToList())
                            {
                                item.ProjectInfo     = project.ID;
                                item.ProjectInfoName = project.Name;
                            }
                        }
                        else
                        {
                            relation.Scale        = 0;
                            relation.ProjectValue = 0;
                        }
                        contract.S_C_ManageContract_ProjectRelation.Add(relation);
                    }
                }
            }


            #endregion

            projectInfo.MarketProjectInfoID = project.ID;

            #region 默认创建EPS结构
            var group = this.BusinessEntities.Set <S_I_ProjectGroup>().FirstOrDefault(d => d.RelateID == entity.EngineeringID && d.Type == "Engineering");
            if (group == null)
            {
                group                      = new S_I_ProjectGroup();
                group.ID                   = Formula.FormulaHelper.CreateGuid();
                group.Name                 = engineering.Name;
                group.Code                 = engineering.Code;
                group.City                 = engineering.City;
                group.Country              = engineering.Country;
                group.Province             = engineering.Province;
                group.Area                 = engineering.Area;
                group.ProjectClass         = engineering.Class;
                group.Investment           = engineering.Investment;
                group.Proportion           = engineering.Proportion;
                group.PhaseContent         = engineering.PhaseContent;
                group.Address              = engineering.Address;
                group.DeptID               = engineering.MainDept;
                group.DeptName             = engineering.MainDeptName;
                group.RelateID             = engineering.ID;
                group.EngineeringSpaceCode = ProjectMode.Standard.ToString();
                group.CreateDate           = DateTime.Now;
                var fo = Formula.FormulaHelper.CreateFO <EPSFO>();
                fo.BuildEngineering(group);
            }
            group.BindingProject(projectInfo);
            entity.GroupID     = group.ID;
            group.PhaseContent = engineering.PhaseContent;
            group.PhaseValue   = engineering.PhaseValue;
            #endregion

            projectInfo.InitDeisgnInputTemplate(true);

            //把设总放进RBS中
            if (projectInfo != null && !string.IsNullOrEmpty(entity.DesignManager))
            {
                projectInfo.WBSRoot.SetUsers(ProjectRole.DesignManager.ToString(), entity.DesignManager.Split(','), true, true, true, true);
            }

            var customer = marketEntities.Set <S_F_Customer>().FirstOrDefault(a => a.ID == entity.Customer);
            if (customer != null)
            {
                if (string.IsNullOrEmpty(entity.Country))
                {
                    project.Country     = customer.Country;
                    projectInfo.Country = customer.Country;
                }
                if (string.IsNullOrEmpty(entity.Province))
                {
                    project.Province     = customer.Province;
                    projectInfo.Province = customer.Province;
                }
                if (string.IsNullOrEmpty(entity.City))
                {
                    project.City     = customer.City;
                    projectInfo.City = customer.City;
                }
                if (string.IsNullOrEmpty(entity.Area))
                {
                    project.Area     = customer.Area;
                    projectInfo.Area = customer.Area;
                }
            }

            return(projectInfo);
        }
Пример #2
0
        protected override void OnFlowEnd(T_CP_TaskNotice entity, Workflow.Logic.Domain.S_WF_InsTaskExec taskExec, Workflow.Logic.Domain.S_WF_InsDefRouting routing)
        {
            if (entity == null)
            {
                throw new Formula.Exceptions.BusinessException("没有找到指定的任务单,立项失败");
            }
            var marketEntities = FormulaHelper.GetEntities <Market.Logic.Domain.MarketEntities>();

            var projectList = new List <S_I_ProjectInfo>();

            if (!String.IsNullOrEmpty(entity.ProjectInfoID) &&
                this.BusinessEntities.Set <S_I_ProjectInfo>().Any(a => a.ID == entity.ProjectInfoID))
            {
                #region 任务单升版
                S_I_ProjectInfo projectInfo = null;
                S_I_Project     project     = null;
                projectInfo             = entity.UpGrade();
                project                 = marketEntities.S_I_Project.FirstOrDefault(d => d.ID == projectInfo.MarketProjectInfoID);
                project.Name            = entity.ProjectInfo;
                project.Code            = entity.SerialNumber;
                project.Phase           = entity.Phase;
                project.ProjectClass    = entity.ProjectClass;
                project.Customer        = entity.Customer;
                project.CustomerName    = entity.CustomerName;
                project.CreateDate      = DateTime.Now;
                project.EngineeringInfo = entity.EngineeringID;
                project.ChargerDept     = string.IsNullOrEmpty(entity.ChargeDept) ? entity.DesignDept : entity.ChargeDept;
                project.ChargerDeptName = string.IsNullOrEmpty(entity.ChargeDeptName) ? entity.DesignDeptName : entity.ChargeDeptName;
                project.ChargerUser     = entity.ChargeUser;
                project.ChargerUserName = entity.ChargeUserName;
                project.Country         = entity.Country;
                project.Province        = entity.Province;
                project.Area            = entity.Area;

                if (string.IsNullOrEmpty(project.Area))
                {
                    //获取省份对应的地区(SubCategory)
                    var enumItem = EnumBaseHelper.GetEnumDef("System.Province").EnumItem.FirstOrDefault(a => a.Code == entity.Province);
                    if (enumItem != null)
                    {
                        project.Area = enumItem.SubCategory;
                    }
                }
                project.City             = entity.City;
                project.ProjectScale     = entity.ProjectLevel;
                projectInfo.ModifyDate   = DateTime.Now;
                projectInfo.ModifyUser   = entity.CreateUser;
                projectInfo.ModifyUserID = entity.CreateUserID;

                //修改经营库项目名称冗余字段
                if (!string.IsNullOrEmpty(projectInfo.MarketProjectInfoID))
                {
                    if (entity.ContractValue.HasValue && String.IsNullOrEmpty(entity.ContractInfo))
                    {
                        marketEntities.S_C_ManageContract_ProjectRelation.Where(a => a.ProjectID == projectInfo.MarketProjectInfoID &&
                                                                                a.S_C_ManageContractID == entity.ContractInfo).Update(a => a.ProjectValue = entity.ContractValue);
                    }
                    marketEntities.S_C_ManageContract_ProjectRelation.Where(a => a.ProjectID == projectInfo.MarketProjectInfoID).Update(a => a.ProjectName  = entity.ProjectInfo);
                    marketEntities.S_C_ManageContract_ReceiptObj.Where(a => a.ProjectInfo == projectInfo.MarketProjectInfoID).Update(a => a.ProjectInfoName = entity.ProjectInfo);
                    marketEntities.S_C_PlanReceipt.Where(a => a.ProjectID == projectInfo.MarketProjectInfoID).Update(a => a.ProjectName             = entity.ProjectInfo);
                    marketEntities.S_FC_CostInfo.Where(a => a.ProjectID == projectInfo.MarketProjectInfoID).Update(a => a.ProjectName               = entity.ProjectInfo);
                    marketEntities.S_SP_SupplierContract.Where(a => a.ProjectInfo == projectInfo.MarketProjectInfoID).Update(a => a.ProjectInfoName = entity.ProjectInfo);
                }
                projectList.Add(projectInfo);
                #endregion
            }
            else
            {
                #region 新建任务单立项

                #region 如果工程信息为空,则默认创建工程
                var  engineering = marketEntities.S_I_Engineering.Find(entity.EngineeringID);
                bool newEngineer = false;
                if (engineering == null)
                {
                    engineering    = new S_I_Engineering();
                    engineering.ID = FormulaHelper.CreateGuid();
                    marketEntities.S_I_Engineering.Add(engineering);
                    newEngineer = true;
                }
                engineering.Name = String.IsNullOrEmpty(entity.EngineeringName) ? entity.ProjectInfo : entity.EngineeringName;
                if (!String.IsNullOrEmpty(entity.Customer))
                {
                    engineering.CustomerInfo     = entity.Customer;
                    engineering.CustomerInfoName = entity.CustomerName;
                }
                engineering.Code = String.IsNullOrEmpty(entity.EngineeringCode) ? entity.SerialNumber : entity.EngineeringCode;
                if (!string.IsNullOrEmpty(entity.MainDeptInfo))
                {
                    engineering.MainDept     = entity.MainDeptInfo;
                    engineering.MainDeptName = entity.MainDeptInfoName;
                }
                else if (string.IsNullOrEmpty(engineering.MainDept))
                {
                    engineering.MainDept     = entity.ChargeDept;
                    engineering.MainDeptName = entity.ChargeDeptName;
                }
                engineering.OtherDept       = String.IsNullOrEmpty(entity.EngineeringOtherDept) ? entity.OtherDept : entity.EngineeringOtherDept;
                engineering.OtherDeptName   = String.IsNullOrEmpty(entity.EngineeringOtherDeptName) ? entity.OtherDeptName : entity.EngineeringOtherDeptName;
                engineering.ChargerUser     = String.IsNullOrEmpty(entity.EngineeringChargeUser) ? entity.ChargeUser : entity.EngineeringChargeUser;
                engineering.ChargerUserName = String.IsNullOrEmpty(entity.EngineeringChargeUserName) ? entity.ChargeUserName : entity.EngineeringChargeUserName;
                engineering.Country         = entity.Country;
                engineering.Province        = entity.Province;
                engineering.City            = entity.City;
                engineering.Area            = entity.Area;
                engineering.Proportion      = entity.BuildArea;
                engineering.Address         = entity.BuildAddress;
                engineering.LandingArea     = entity.LandArea;
                engineering.CreateDate      = DateTime.Now;
                if (!String.IsNullOrEmpty(entity.Investment))
                {
                    engineering.Investment = Convert.ToDecimal(entity.Investment);
                }
                if (newEngineer)
                {
                    entity.EngineeringID             = engineering.ID;
                    entity.EngineeringName           = engineering.Name;
                    entity.EngineeringCode           = engineering.Code;
                    entity.EngineeringChargeUser     = engineering.ChargerUser;
                    entity.EngineeringChargeUserName = engineering.ChargerUserName;
                    entity.MainDeptInfo             = engineering.MainDept;
                    entity.MainDeptInfoName         = engineering.MainDeptName;
                    entity.EngineeringOtherDept     = engineering.OtherDept;
                    entity.EngineeringOtherDeptName = engineering.OtherDeptName;
                }

                var phaseName       = "";
                var phaseList       = BaseConfigFO.GetWBSAttrList(WBSNodeType.Phase);
                var entityPhaseList = phaseList.Where(d => entity.Phase.Contains(d.Code)).ToList();
                foreach (var item in entityPhaseList)
                {
                    phaseName += item.Name + ",";
                }
                engineering.PhaseContent = phaseName.TrimEnd(',');
                engineering.PhaseValue   = entity.Phase;
                #endregion

                if (!string.IsNullOrEmpty(entity.MultiProjMode) && entity.MultiProjMode.ToLower() == "1")
                {
                    var list = entity.Phase.Split(',');
                    if (list.Length == 0)
                    {
                        throw new Formula.Exceptions.BusinessException("没有指定阶段");
                    }

                    string projIds = "";
                    foreach (var item in entity.T_CP_TaskNotice_PhaseDetail)
                    {
                        var prj = AddProject(entity, engineering, item);
                        projIds           += prj.ID + ",";
                        item.ProjectInfoID = prj.ID;
                        projectList.Add(prj);
                    }
                    entity.ProjectInfoID = projIds.TrimEnd(',');
                }
                else
                {
                    var prj = AddProject(entity, engineering);
                    projectList.Add(prj);
                }

                #endregion
            }

            this.BusinessEntities.SaveChanges();
            marketEntities.SaveChanges();


            #region 自动同步核算项目
            Expenses.Logic.CBSInfoFO.SynCBSInfo(FormulaHelper.ModelToDic <T_CP_TaskNotice>(entity), Expenses.Logic.SetCBSOpportunity.TaskNoticeComplete);
            #endregion
        }