public async Task Update(PurchaseInputDto input)
        {
            var data = await db.Purchases.SingleOrDefaultAsync(m => m.Id == input.PurchaseId && !m.IsDelete && m.ApprovalType == EApprovalType.UnderReview);

            var amount = decimal.Zero;

            if (input.Price != null && input.QuasiPurchaseNumber != null && input.Price != 0 && input.QuasiPurchaseNumber != 0)
            {
                amount = (decimal)input.Price * (decimal)input.QuasiPurchaseNumber;
            }

            if (data != null)
            {
                data.Amount              = amount;
                data.ApplicantRemarks    = input.ApplicantRemarks;
                data.ApplyNumber         = input.ApplyNumber;
                data.ApplyTime           = input.ApplyTime;
                data.ArrivalTime         = input.ArrivalTime;
                data.SupplierId          = input.SupplierId;
                data.Enclosure           = input.Enclosure;
                data.Price               = input.Price;
                data.PurchaseContract    = input.PurchaseContract;
                data.PurchaseTime        = input.PurchaseTime;
                data.Purpose             = input.Purpose;
                data.QuasiPurchaseNumber = input.ApplyNumber;
                data.RawMaterialId       = input.RawMaterialId;
                data.WaybillNumber       = input.WaybillNumber;
                data.ProjectId           = (long)input.ProjectId;
                data.ApprovalDesc        = input.ApprovalDesc;
                data.ExpectArrivalTime   = input.ExpectArrivalTime;
                //data.DepartmentLeaderId = input.DepartmentLeaderId;
                //data.GeneralManagerId = input.GeneralManagerId;
                //data.PurchasingSpecialistId = input.PurchasingSpecialistId;
            }

            if (await db.SaveChangesAsync() <= 0)
            {
                throw new HttpResponseException(new HttpResponseMessage()
                {
                    Content = new StringContent(JsonConvert.SerializeObject(new ResponseApi()
                    {
                        Code = EExceptionType.Implement, Message = "更新失败"
                    }))
                });
            }
        }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task <ComparePriceToCrmApiResultDto <List <CrmPurchaseOutPutDto> > > GetPurchaseBelongsFromCrm(PurchaseInputDto input)
        {
            string poststr = Newtonsoft.Json.JsonConvert.SerializeObject(input);
            ComparePriceToCrmApiResultDto <List <CrmPurchaseOutPutDto> > output = await new ComparePriceToCrmApi(_apiRequest).GetPurchaseBelongsFromCrm(input);

            return(output);
        }
Exemplo n.º 3
0
 public OnlineOrdersResultDto <List <Ppc_PlatformConfigOutPutDto> > GetPlatform(PurchaseInputDto input)
 {
     input.CRMUserId = "17b2269a-0bc6-4a20-95ed-25b3386250b1";
     _service.GetPurchaseBelongsFromCrm1(input);
     return(new OnlineOrdersResultDto <List <Ppc_PlatformConfigOutPutDto> >());
 }
        public async Task UpdatePurchaseApprovalType(PurchaseInputDto input)
        {
            var userId = ((UserIdentity)User.Identity).UserId;
            var token  = ((UserIdentity)User.Identity).Token;

            var userTypeKeys = await db.UserDetailsTypes.Where(m => m.UserId == userId).Select(m => m.UserType.Key).ToListAsync();

            var user = await db.UserDetails.Include(m => m.User).SingleOrDefaultAsync(m => m.Id == userId && !m.IsDelete);

            if (user == null)
            {
                throw new HttpResponseException(new HttpResponseMessage()
                {
                    Content = new StringContent(JsonConvert.SerializeObject(new ResponseApi()
                    {
                        Code = EExceptionType.Implement, Message = "无权操作权限"
                    }))
                });
            }

            var data = await db.Purchases
                       .Include(m => m.Applicant)
                       .Include(m => m.Applicant.User)
                       .SingleOrDefaultAsync(m => m.Id == input.PurchaseId && !m.IsDelete);

            if (data == null)
            {
                throw new HttpResponseException(new HttpResponseMessage()
                {
                    Content = new StringContent(JsonConvert.SerializeObject(new ResponseApi()
                    {
                        Code = EExceptionType.Implement, Message = "该订单不存在"
                    }))
                });
            }

            if (data.ApprovalType == EApprovalType.Rejected)
            {
                throw new HttpResponseException(new HttpResponseMessage()
                {
                    Content = new StringContent(JsonConvert.SerializeObject(new ResponseApi()
                    {
                        Code = EExceptionType.Implement, Message = "该订单已被驳回"
                    }))
                });
            }

            var approval = await db.Approvals.Where(m => m.Key == data.ApprovalKey).ToListAsync();

            if (approval == null && approval.Count <= 0)
            {
                throw new HttpResponseException(new HttpResponseMessage()
                {
                    Content = new StringContent(JsonConvert.SerializeObject(new ResponseApi()
                    {
                        Code = EExceptionType.Implement, Message = data.ApprovalKey + "该审批流不存在,请重新提交申请"
                    }))
                });
            }

            var index = data.ApprovalIndex + 1;

            var maxIndex = approval.Max(m => m.Deis);

            var userApproval = approval.SingleOrDefault(m => m.Deis == index);

            if (userApproval != null && input.ApprovalType == null)
            {
                if (!userTypeKeys.Contains(userApproval.UserTypeKey))
                {
                    //}
                    //if (userApproval.UserTypeKey != token.UserTypeKey)
                    //{
                    throw new HttpResponseException(new HttpResponseMessage()
                    {
                        Content = new StringContent(JsonConvert.SerializeObject(new ResponseApi()
                        {
                            Code = EExceptionType.Implement, Message = data.ApprovalKey + "无权操作"
                        }))
                    });
                }
                else
                {
                    data.ApprovalIndex += 1;

                    data.ApprovalType = EApprovalType.InExecution;

                    //var purchaseApproval = await db.PurchaseApprovals.SingleOrDefaultAsync(m => m.UserTypeKey == token.UserTypeKey && m.ApprovalIndex == index && m.PurchaseId == data.Id);
                    var purchaseApproval = await db.PurchaseApprovals.SingleOrDefaultAsync(m => userTypeKeys.Contains(m.UserTypeKey) && m.ApprovalIndex == index && m.PurchaseId == data.Id);

                    if (purchaseApproval == null)
                    {
                        throw new HttpResponseException(new HttpResponseMessage()
                        {
                            Content = new StringContent(JsonConvert.SerializeObject(new ResponseApi()
                            {
                                Code = EExceptionType.Implement, Message = data.ApprovalKey + "审批流程异常"
                            }))
                        });
                    }

                    purchaseApproval.IsApproval = true;
                    purchaseApproval.UserId     = token.UserId;

                    var userTypeKey = approval.SingleOrDefault(m => m.Deis == index + 1);

                    if (userTypeKey != null)
                    {
                        db.PurchaseApprovals.Add(new PurchaseApproval
                        {
                            Id            = IdentityManager.NewId(),
                            PurchaseId    = data.Id,
                            IsApproval    = false,
                            UserTypeKey   = userTypeKey.UserTypeKey,
                            ApprovalIndex = index + 1
                        });
                    }

                    if (maxIndex == data.ApprovalIndex)
                    {
                        data.ApprovalType = EApprovalType.Reviewed;
                    }
                }
            }
            else if (maxIndex == data.ApprovalIndex && input.ApprovalType == null)
            {
                data.ApprovalType = EApprovalType.Reviewed;
            }
            else
            {
                if (input.ApprovalType == EApprovalType.Rejected || input.ApprovalType == EApprovalType.Paid)
                {
                    data.ApprovalType = input.ApprovalType;
                }

                if (data.ApprovalType == EApprovalType.Paid)
                {
                    db.AssetExpenditures.Add(new AssetExpenditure
                    {
                        Id         = IdentityManager.NewId(),
                        Desc       = input.AssetExpenditureDesc,
                        PurchaseId = data.Id,
                        UserId     = userId,
                        Amount     = (decimal)data.Amount
                    });
                }
            }

            if (await db.SaveChangesAsync() <= 0)
            {
                throw new HttpResponseException(new HttpResponseMessage()
                {
                    Content = new StringContent(JsonConvert.SerializeObject(new ResponseApi()
                    {
                        Code = EExceptionType.Implement, Message = "更新失败"
                    }))
                });
            }
        }
        public async Task Add(PurchaseInputDto input)
        {
            var userId = ((UserIdentity)User.Identity).UserId;

            try
            {
                var amount = decimal.Zero;

                if (input.Price != null && input.QuasiPurchaseNumber != null && input.Price != 0 && input.QuasiPurchaseNumber != 0)
                {
                    amount = (decimal)input.Price * (decimal)input.QuasiPurchaseNumber;
                }

                if (input.RawId != null)
                {
                    var result = await Task.Run(() => db.RawRooms.AsNoTracking().Where(p => p.RawId == input.RawId));

                    // int is_or;
                    foreach (var item in result)
                    {
                        if (item.RawNumber >= input.ApplyNumber)
                        {
                            //可以直接领取
                            this.Is_Or = 1;
                            break;
                        }
                        else
                        {
                            //不可以直接领取
                            this.Is_Or = 2;
                            break;
                        }
                    }

                    var data = new Purchase()
                    {
                        Id               = IdentityManager.NewId(),
                        Amount           = amount,
                        ApplicantId      = userId,
                        ApplicantRemarks = input.ApplicantRemarks,
                        ApplyNumber      = input.ApplyNumber,
                        ApplyTime        = input.ApplyTime,
                        ApprovalType     = EApprovalType.UnderReview,
                        ArrivalTime      = input.ArrivalTime,
                        SupplierId       = input.SupplierId,
                        Enclosure        = input.Enclosure,
                        Price            = input.Price,

                        PurchaseContract    = input.PurchaseContract,
                        PurchaseTime        = input.PurchaseTime,
                        Purpose             = input.Purpose,
                        QuasiPurchaseNumber = input.ApplyNumber,
                        RawId             = input.RawId,
                        WaybillNumber     = input.WaybillNumber,
                        ProjectId         = (long)input.ProjectId,
                        ApprovalDesc      = input.ApprovalDesc,
                        ExpectArrivalTime = input.ExpectArrivalTime,
                        IsDelete          = false,
                        User_Id           = input.User_id,
                        is_or             = this.Is_Or,
                        // ApprovalKey = related.ApprovalKey,
                        ApprovalIndex = 0
                    };

                    db.Purchases.Add(data);
                }
                //if (input.User_id == null)
                //{
                //    throw new HttpResponseException(new HttpResponseMessage()
                //    {
                //        Content = new StringContent(JsonConvert.SerializeObject(new ResponseApi() { Code = EExceptionType.Implement, Message = "请填写必要字段" }))
                //    });
                //}
                if (await db.SaveChangesAsync() > 0)
                {
                    throw new HttpResponseException(new HttpResponseMessage()
                    {
                        Content = new StringContent(JsonConvert.SerializeObject(new ResponseApi()
                        {
                            Code = EExceptionType.Implement, Message = "添加成功"
                        }))
                    });
                }
                ;
            }
            catch (Exception)
            {
                throw;
            }


            //var related = await db.RelatedApprovals.SingleOrDefaultAsync(m => m.RelatedKey == "Purchase");

            //if (related == null)
            //{
            //    throw new HttpResponseException(new HttpResponseMessage()
            //    {
            //        Content = new StringContent(JsonConvert.SerializeObject(new ResponseApi() { Code = EExceptionType.Implement, Message = "采购申请未绑定审批流,添加失败" }))
            //    });
            //}

            //var approval = await db.Approvals.Where(m => m.Key == related.ApprovalKey).ToListAsync();

            //if (approval == null && approval.Count <= 0)
            //{
            //    throw new HttpResponseException(new HttpResponseMessage()
            //    {
            //        Content = new StringContent(JsonConvert.SerializeObject(new ResponseApi() { Code = EExceptionType.Implement, Message = related.ApprovalKey + "该审批流不存在,添加失败" }))
            //    });
            //}



            //var userTypeKey = await db.Approvals.SingleOrDefaultAsync(m => m.Deis == 1 && m.Key == data.ApprovalKey);

            //if (userTypeKey != null)
            //{
            //    db.PurchaseApprovals.Add(new PurchaseApproval
            //    {
            //        Id = IdentityManager.NewId(),
            //        PurchaseId = data.Id,
            //        IsApproval = false,
            //        UserTypeKey = userTypeKey.UserTypeKey,
            //        ApprovalIndex = 1
            //    });
            //}
            //else
            //{
            //    throw new HttpResponseException(new HttpResponseMessage()
            //    {
            //        Content = new StringContent(JsonConvert.SerializeObject(new ResponseApi() { Code = EExceptionType.Implement, Message = data.ApprovalKey + "审批流异常" }))
            //    });
            //}

            //if (await db.SaveChangesAsync() <= 0)
            //{
            //    throw new HttpResponseException(new HttpResponseMessage()
            //    {
            //        Content = new StringContent(JsonConvert.SerializeObject(new ResponseApi() { Code = EExceptionType.Implement, Message = "添加失败" }))
            //    });
            //}
        }