private ErrorMessageDTO CalculateBonus(CalculateOperatorBonus bpObj)
        {
            ErrorMessageDTO errorDot = new ErrorMessageDTO();

            //foreach(Bonus
            return(errorDot);
        }
        public void ParseResponseAsync(string response)
        {
            if (string.IsNullOrEmpty(response))
            {
                Log.Info("The response was null/empty");
                return;
            }

            // open connection or ping response
            if (response == "40" || response == "3")
            {
                return;
            }


            response = SocketUtilities.CleanResponse(response);

            var errorMessage = new ErrorMessageDTO();
            var sytemError   = new SystemErrorDTO();


            switch (string.Empty)
            {
            case RouteProvider.CHARACTER_SELECTION_FAILED:
                errorMessage = SocketUtilities.ParseDataFromResponse <ErrorMessageDTO>(response);
                Log.Error($"Character selection failed: {errorMessage.Message}");

                StopConnection();
                break;


            case RouteProvider.SYSTEM_ERROR:
                sytemError = SocketUtilities.ParseDataFromResponse <SystemErrorDTO>(response);

                ParseSystemError(response);
                Log.Error($"Character selection failed: {errorMessage.Message}");

                StopConnection();
                break;

            case RouteProvider.MESSAGE_ERROR:
                errorMessage = SocketUtilities.ParseDataFromResponse <ErrorMessageDTO>(response);
                Log.Error($"Socket Error: {errorMessage.ErrorCode} - {errorMessage.Message}");
                StopConnection();
                break;

            case RouteProvider.EXCEPTION_ERROR:
                sytemError = SocketUtilities.ParseDataFromResponse <SystemErrorDTO>(response);
                Log.Error($"Server exception error: {errorMessage.Message}");

                AddToConnectionLog("THE SERVER IS MOST LIKELY DOWN!");
                StopConnection();
                break;

            default:

                break;
            }
        }
Esempio n. 3
0
        private Task HandleNotFoundException(HttpResponse response, EntityNotFoundException exception)
        {
            response.StatusCode  = (int)HttpStatusCode.NotFound;
            response.ContentType = "application/json";

            var message = new ErrorMessageDTO(exception.Message);

            return(response.WriteAsync(message.Serialize()));
        }
        public IActionResult InsertNewEmployee([FromBody] EmployeeBasicDTO modelDTO)
        {
            var employee = _mapper.Map <EmployeeModel>(modelDTO);

            if (String.IsNullOrWhiteSpace(modelDTO.FullName))
            {
                var error = new ErrorMessageDTO("FullName property cannot be null or empty", 201);
                return(BadRequest(error));
            }

            var returnEmployee = _employeeRepo.Insert(employee);

            return(Ok(_mapper.Map <EmployeeBasicDTO>(returnEmployee)));
        }
        public IActionResult GetEmployeeById(string id)
        {
            Guid employeeId;

            if (!Guid.TryParse(id, out employeeId))
            {
                var error = new ErrorMessageDTO("Cannot convert id", 101);
                return(BadRequest(error));
            }

            var employeeDTO = _employeeRepo.Get(employeeId);

            if (employeeDTO == null)
            {
                var error = new ErrorMessageDTO($"Cannot find user of id {id}", 101);
                return(BadRequest(error));
            }

            return(Ok(_mapper.Map <EmployeeBasicDTO>(employeeDTO)));
        }
Esempio n. 6
0
        private ErrorMessageDTO UpdateStatus(ApproveOperatorBonus bpObj)
        {
            ErrorMessageDTO errorDto = new ErrorMessageDTO();
            bool            result   = false;

            switch (bpObj.DocType)
            {
            case 0:      //采购业务员奖金单状态改变
                #region 更改采购业务员奖金单据状态
                BonusProductDocBE.BonusProductDoc bonusProduct = BonusProductDocBE.BonusProductDoc.Finder.FindByID(bpObj.DocID);
                if (bonusProduct != null && bonusProduct.SysVersion == bpObj.VIVersion)
                {
                    using (ISession session = Session.Open())
                    {
                        if (bonusProduct != null)
                        {
                            //提交
                            if (bpObj.DocStatus == 0)
                            {
                                bonusProduct.Status = EnumBE.FICommonStatusEnum.Approving;
                            }
                            //审核操作(
                            else if (bpObj.DocStatus == 1)
                            {
                                bonusProduct.Status = EnumBE.FICommonStatusEnum.Apporved;
                            }
                            //弃申操作
                            else if (bpObj.DocStatus == 2)
                            {
                                bonusProduct.Status = EnumBE.FICommonStatusEnum.Opened;
                            }
                        }
                        session.Commit();
                    }
                }
                else
                {
                    throw new Exception("当前数据已被修改或删除,请刷新后操作!!!");
                }
                result = true;
                break;

                #endregion
            case 1:    //包装业务员奖金单据状态改变
                #region
                BonusPackagingDocBE.BonusPackagingDoc bonusParkaging = BonusPackagingDocBE.BonusPackagingDoc.Finder.FindByID(bpObj.DocID);
                if (bonusParkaging != null && bonusParkaging.SysVersion == bpObj.VIVersion)
                {
                    using (ISession session = Session.Open())
                    {
                        if (bonusParkaging != null)
                        {
                            //提交
                            if (bpObj.DocStatus == 0)
                            {
                                bonusParkaging.Status = EnumBE.FICommonStatusEnum.Approving;
                            }
                            //审核操作(
                            else if (bpObj.DocStatus == 1)
                            {
                                bonusParkaging.Status = EnumBE.FICommonStatusEnum.Apporved;
                            }
                            //弃申操作
                            else if (bpObj.DocStatus == 2)
                            {
                                bonusParkaging.Status = EnumBE.FICommonStatusEnum.Opened;
                            }
                        }
                        session.Commit();
                    }
                }
                else
                {
                    throw new Exception("当前数据已被修改或删除,请刷新后操作!!!");
                }
                result = true;
                break;
                #endregion
            }
            errorDto.IsSuccess    = result;
            errorDto.ErrorMessage = "";
            return(errorDto);
        }
        public override object Do(object obj)
        {
            ApprovedPrePaymentBP bpObj = (ApprovedPrePaymentBP)obj;

            ErrorMessageDTO dto = new ErrorMessageDTO();

            if (bpObj == null)
            {
                dto.IsSuccess    = false;
                dto.ErrorMessage = "没有可返回的信息!";
                return(dto);
            }

            UFIDA.U9.Cust.GS.FI.PrePaymentBE.PrePayment mDoc = bpObj.EntityKey.GetEntity();

            if (mDoc == null)
            {
                dto.IsSuccess    = false;
                dto.ErrorMessage = "单据不存在或者已删除!";
                return(dto);
            }

            try
            {
                if (bpObj.Type == 0)
                {
                    //提交
                    using (Session s = Session.Open())
                    {
                        mDoc.StateMachineInstance.Opened_SubmitEventDriven(new UFIDA.U9.Cust.GS.FI.PrePaymentBE.SubmintEvent());
                        s.InList(mDoc);
                        s.Commit();
                    }
                }

                else if (bpObj.Type == 1)
                {
                    //审核
                    using (Session s = Session.Open())
                    {
                        mDoc.StateMachineInstance.Approving_ApproveEventDriven(new UFIDA.U9.GeneralEvents.ApprovalResultEvent());
                        s.InList(mDoc);
                        s.Commit();
                    }
                }
                else if (bpObj.Type == 2)
                {
                    //弃审
                    using (Session s = Session.Open())
                    {
                        mDoc.StateMachineInstance.Approved_UnApprovedEventDriven(new UFIDA.U9.Cust.GS.FI.PrePaymentBE.UnApprovedEvent());
                        s.InList(mDoc);
                        s.Commit();
                    }
                }
                else if (bpObj.Type == 3)
                {
                    //收回
                    using (Session s = Session.Open())
                    {
                        ApprovalService.Instance.CanRevocateAfterSubmit(mDoc, long.Parse(UFIDA.U9.Base.Context.LoginUserID.ToString()));
                        ApprovalService.Instance.RevocateAfterSubmit(mDoc, long.Parse(UFIDA.U9.Base.Context.LoginUserID.ToString()));
                        s.InList(mDoc);
                        s.Commit();
                    }
                }
                dto.IsSuccess = true;
            }
            catch (Exception ex)
            {
                dto.IsSuccess    = false;
                dto.ErrorMessage = ex.Message;
            }
            return(dto);
        }
        private ErrorMessageDTO CalculateAction(CalculateOperatorBonus bpObj)
        {
            ErrorMessageDTO errorDot = new ErrorMessageDTO();

            // 1、 bpObj.Type 为0计算采购业务员奖金,为1计算包装业务员奖金;
            //2、bpObj.OperatorsList为空或者bpObj.OperatorsList.Count为0计算指定会计期间内的所有业务员,反之计算指定业务员奖金
            //操作事件区分,0计算,1补算,2取消计算
            if (bpObj.CalculateType == 0)
            {
                #region 计算奖金功能
                //计算奖金
                #region 计算前校验
                //1、所选会计期间状态必须为“未计算”,
                foreach (BonusCalculateRecordBE.BonusCalculateRecordDTO dto in bpObj.BonusCalcuteList)
                {
                    //勾选的会计期间必须是当前月度前的会计期间并且期间状态是“未计算”的;
                    if (dto.PeriodStatus == EnumBE.PeriodStatusEnum.Calculate || dto.PeriodStatus == EnumBE.PeriodStatusEnum.RepairCalculate)
                    {
                        throw new Exception("会计期间" + dto.SOBAccountingPeriod.DisplayName + "已计算奖金");
                    }
                    if (dto.SOBAccountingPeriod != null && dto.SOBAccountingPeriod.DisplayName != "")
                    {
                        if (Convert.ToDateTime(dto.SOBAccountingPeriod.DisplayName) >= Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM")))
                        {
                            throw new Exception("会计期间" + dto.SOBAccountingPeriod.DisplayName + "必须是当前月度前的会计期间");
                        }
                    }
                }
                //2、勾选的会计期间前一个会计期间必须已完成计算,
                //找到最小的会计期间,判断它的前一个会计期间是否已计算
                var minPeriodNumber = bpObj.BonusCalcuteList.Min <BonusCalculateRecordDTO>(p => p.SOBAccountingPeriod.Number);
                if ((Convert.ToInt32(minPeriodNumber) - 10) > 0) //前一个会计期间不为XXXX-01(即本年度第一个会计期间)
                {
                    //勾选的最小会计期间前一个会计期间必须已完成计算,
                    BonusCalculateRecordBE.BonusCalculateRecord record = BonusCalculateRecordBE.BonusCalculateRecord.Finder.Find("SourceType=" + bpObj.Type + " and SOBAccountingPeriod.Year=" + bpObj.Year + " and SOBAccountingPeriod.Number=" + (Convert.ToInt32(minPeriodNumber) - 10) + "");
                    //BonusCalculateRecordBE.BonusCalculateRecord.EntityList recoudList = BonusCalculateRecordBE.BonusCalculateRecord.Finder.FindAll("1=1");
                    if (record == null || record.PeriodStatus == EnumBE.PeriodStatusEnum.NoCalculate)
                    {
                        throw new Exception("勾选的最小会计期间前一个会计期间必须已完成计算");
                    }
                }
                //3、如果勾选多个,则必须是连续性的会计期间,中间不允许出现未计算的或者没有勾选的;
                //先排序,再判断是否连续会计期间
                IEnumerable <BonusCalculateRecordDTO> recordDTO = from calDTO in bpObj.BonusCalcuteList orderby calDTO.SOBAccountingPeriod.Number descending select calDTO;
                int number = 0;//判断是否连续的标志
                foreach (BonusCalculateRecordDTO bonusDTO in recordDTO)
                {
                    if (number != 0)
                    {
                        if (number != bonusDTO.SOBAccountingPeriod.Number)
                        {
                            throw new Exception("请勾选连续的会计期间进行计算");
                        }
                    }
                    number = bonusDTO.SOBAccountingPeriod.Number;
                }
                #endregion 校验结束
                #region 校验通过,计算奖金
                //奖金计算时,不区分组织,即统计发生在勾选的会计期间范围内的已审核的付款通知单,
                //并且付款通知单来源采购订单的业务员类型为产品采购的(组织间的抛单业务除外),
                //根据业务员进行分组,计算业务员奖金,

                #region 获取预置参数
                decimal bonusCoefficient         = 0;                                                                 //奖金系数
                decimal degradationCoefficient   = 0;                                                                 //降价系数
                decimal packaingBonusCoefficient = 0;                                                                 //包装奖金系数
                int     deliveryExpectDay        = 0;                                                                 //交货基准交期
                GetSysteParma(bonusCoefficient, degradationCoefficient, packaingBonusCoefficient, deliveryExpectDay); //获取预置参数值
                #endregion

                #region 查询付款通知单
                //获得会计期间的最大、最小时间
                if (recordDTO == null || recordDTO.Count <BonusCalculateRecordDTO>() == 0)
                {
                    throw new Exception("请选择计算的会计期间");
                }
                //会计期间的最小时间
                string startTime = DateTime.Parse(recordDTO.First <BonusCalculateRecordDTO>().SOBAccountingPeriod.DisplayName).ToString("yyyy-MM-01 00:00:00");
                //string endTime = DateTime.Parse(recordDTO.Last<BonusCalculateRecordDTO>().SOBAccountingPeriod.DisplayName).ToString("yyyy-MM-
                //会计期间的最大时间
                int      year     = DateTime.Parse(recordDTO.Last <BonusCalculateRecordDTO>().SOBAccountingPeriod.DisplayName).Year;
                int      month    = DateTime.Parse(recordDTO.Last <BonusCalculateRecordDTO>().SOBAccountingPeriod.DisplayName).Month;
                int      days     = DateTime.DaysInMonth(year, month);
                DateTime datetime = new DateTime(year, month, 1);
                string   endTime  = datetime.AddDays(days - 1).ToString("yyyy-MM-dd 23:59:59");
                //获取付款通知单数据集
                DataTable tablePayment = GetPaymentData(bpObj, DateTime.Parse(startTime), DateTime.Parse(endTime));
                #endregion
                string docNo = "";
                #region 生成业务员奖金
                if (bpObj.Type == 0)//生成采购业务员奖金
                {
                    docNo = CreateProductOperatorBonus(bpObj, tablePayment, bonusCoefficient, degradationCoefficient, deliveryExpectDay);
                }
                else //生成包装业务员奖金
                {
                    docNo = CreatePackagingOperatorBonus(bpObj, tablePayment, packaingBonusCoefficient);
                }
                #endregion

                #region 生成奖金计算记录
                using (ISession session = Session.Open())
                {
                    BonusCalculateRecord bonusRecord = null;
                    foreach (BonusCalculateRecordDTO bonusDTO in bpObj.BonusCalcuteList)
                    {
                        bonusRecord = BonusCalculateRecord.Create();
                        if (bpObj.Type == 0)
                        {
                            bonusRecord.SourceType = EnumBE.BonusOperatorsTypeEnum.ProductOperators;
                        }
                        else
                        {
                            bonusRecord.SourceType = EnumBE.BonusOperatorsTypeEnum.PackagingOperators;
                        }
                        bonusRecord.SOBAccountingPeriodKey = bonusDTO.SOBAccountingPeriod.Key;
                        bonusRecord.Oprator       = UFIDA.U9.Base.Context.LoginUser;
                        bonusRecord.OprateTime    = DateTime.Now;
                        bonusRecord.PeriodStatus  = EnumBE.PeriodStatusEnum.Calculate;
                        bonusRecord.Org           = UFIDA.U9.Base.Context.LoginOrg;
                        bonusRecord.OperatorBonus = docNo;
                    }
                    session.Commit();
                }
                #endregion

                if (docNo != "")
                {
                    //生成成功,发送消息
                    List <long> recever = new System.Collections.Generic.List <long>();
                    recever.Add(Convert.ToInt64(UFIDA.U9.Base.Context.LoginUserID));
                    UFIDA.U9.Cust.GS.FI.FIBP.PubBP.SendMessageExtend.SendMessage("计算业务员奖金完成,生成单号" + docNo, "业务员奖金计算完成通知", recever, UFIDA.U9.BS.Notification.PriorityEnum.Medium);
                }
                #endregion
                #endregion 计算End
            }
            else if (bpObj.CalculateType == 1)
            {
                #region 补算
                #region 补算前校验
                //可以通过计算范围选择性的选择业务员进行奖金的补算,补算可以跨月进行,补算完后,记录补算的结果,并产生差异明细;
                foreach (BonusCalculateRecordBE.BonusCalculateRecordDTO dto in bpObj.BonusCalcuteList)
                {
                    //勾选的会计期间必须是当前月度前的会计期间并且期间状态是“未计算”的;
                    if (dto.PeriodStatus == EnumBE.PeriodStatusEnum.NoCalculate)
                    {
                        throw new Exception("会计期间" + dto.SOBAccountingPeriod.DisplayName + "未计算奖金,不能补算");
                    }
                }
                #endregion 补算前校验End
                #region 获取预置参数
                decimal bonusCoefficient         = 0;                                                                 //奖金系数
                decimal degradationCoefficient   = 0;                                                                 //降价系数
                decimal packaingBonusCoefficient = 0;                                                                 //包装奖金系数
                int     deliveryExpectDay        = 0;                                                                 //交货基准交期
                GetSysteParma(bonusCoefficient, degradationCoefficient, packaingBonusCoefficient, deliveryExpectDay); //获取预置参数值
                #endregion

                #region 补算
                //获取付款通知单数据集,因为可以跨月计算,所以根据每个会计期间查询
                DataTable tablePayment = GetPaymentData(bpObj, DateTime.Now, DateTime.Now);
                string    docNo        = "";
                #region 生成业务员奖金
                if (bpObj.Type == 0)//生成采购业务员奖金
                {
                    docNo = CreateProductOperatorBonus(bpObj, tablePayment, bonusCoefficient, degradationCoefficient, deliveryExpectDay);
                }
                else //生成包装业务员奖金
                {
                    docNo = CreatePackagingOperatorBonus(bpObj, tablePayment, packaingBonusCoefficient);
                }
                #endregion

                #region 生成奖金计算记录
                using (ISession session = Session.Open())
                {
                    BonusCalculateRecord bonusRecord = null;
                    foreach (BonusCalculateRecordDTO bonusDTO in bpObj.BonusCalcuteList)
                    {
                        bonusRecord = BonusCalculateRecord.Create();
                        if (bpObj.Type == 0)
                        {
                            bonusRecord.SourceType = EnumBE.BonusOperatorsTypeEnum.ProductOperators;
                        }
                        else
                        {
                            bonusRecord.SourceType = EnumBE.BonusOperatorsTypeEnum.PackagingOperators;
                        }
                        bonusRecord.SOBAccountingPeriodKey = bonusDTO.SOBAccountingPeriod.Key;
                        bonusRecord.Oprator             = UFIDA.U9.Base.Context.LoginUser;
                        bonusRecord.OprateTime          = DateTime.Now;
                        bonusRecord.PeriodStatus        = EnumBE.PeriodStatusEnum.RepairCalculate;//补算
                        bonusRecord.Org                 = UFIDA.U9.Base.Context.LoginOrg;
                        bonusRecord.RepairOperatorBonus = docNo;
                    }
                    session.Commit();
                }
                #endregion

                if (docNo != "")
                {
                    //生成成功,发送消息
                    List <long> recever = new System.Collections.Generic.List <long>();
                    recever.Add(Convert.ToInt64(UFIDA.U9.Base.Context.LoginUserID));
                    UFIDA.U9.Cust.GS.FI.FIBP.PubBP.SendMessageExtend.SendMessage("计算业务员奖金完成,生成单号" + docNo, "业务员奖金计算完成通知", recever, UFIDA.U9.BS.Notification.PriorityEnum.Medium);
                }
                #endregion 补算 End
                #endregion 补算
            }
            else if (bpObj.CalculateType == 2)
            {
                #region 取消计算
                //1、勾选的会计期间前后的会计期间状态必须是“未计算”的,否则提示不允许取消;
                //2、校验通过后,删除勾选的会计期间对应的业务员奖金计算结果
                #region 取消计算前校验
                foreach (BonusCalculateRecordBE.BonusCalculateRecordDTO dto in bpObj.BonusCalcuteList)
                {
                    //勾选的会计期间必须是当前月度前的会计期间并且期间状态是“未计算”的;
                    if (dto.PeriodStatus == EnumBE.PeriodStatusEnum.NoCalculate)
                    {
                        throw new Exception("会计期间" + dto.SOBAccountingPeriod.DisplayName + "未计算奖金,无需取消计算");
                    }
                }
                #endregion 取消计算前校验 end

                #region 取消计算
                using (ISession session = Session.Open())
                {
                    BonusProductDoc   bonusProduct   = null;
                    BonusPackagingDoc bonusPackaging = null;
                    foreach (BonusCalculateRecordBE.BonusCalculateRecordDTO dto in bpObj.BonusCalcuteList)
                    {
                        if (dto.ID > 0)
                        {
                            if (bpObj.Type == 0)//采购业务员奖金
                            {
                                bonusProduct = BonusProductDoc.Finder.Find("OperatorBonus='" + dto.OperatorBonus + "'");
                                if (bonusProduct != null)
                                {
                                    bonusProduct.Remove();
                                }
                            }
                            else if (bpObj.Type == 1)//包装业务员奖金
                            {
                                bonusPackaging = BonusPackagingDoc.Finder.Find("OperatorBonus='" + dto.OperatorBonus + "'");
                                if (bonusPackaging != null)
                                {
                                    bonusPackaging.Remove();
                                }
                            }
                        }
                    }
                    session.Commit();
                }
                #endregion

                #endregion
            }
            return(errorDot);
        }