Example #1
0
        public void Add(ChargeBackModel chargeBack)
        {
            if (chargeBack.Details.Count(c => c.Count <= 0) > 0)
            {
                throw new Exception("退货商品数量无效");
            }

            try
            {
                var dbcontext = ServiceProvider.GetDbcontext <IPurocumentDbcontext>();
                var order     = dbcontext.PurchasingOrder.Include(i => i.Details).SingleOrDefault(s => s.ID.Equals(chargeBack.PurchasingOrderID));
                if (order == null || order.ID < 1)
                {
                    throw new Exception("订单不存在");
                }

                //创建主表
                var entity = new Entity.ChargeBack()
                {
                    Code = StrCBPrefix + DateTime.Now.ToString(StrCBSuffixFormat),
                    PurchasingOrderID       = order.ID,
                    PurchasingOrderStatusID = (int)EnumPurchasingOrderState.DepartmentChargeBack,
                    CreateTime   = chargeBack.CreateTime,
                    UpdateTime   = chargeBack.CreateTime,
                    CreateUsrID  = chargeBack.CreateUsrID,
                    UpdateUserID = chargeBack.CreateUsrID,
                    ItemCount    = chargeBack.Details.Count(),
                    Total        = Convert.ToDecimal(0)
                };

                var details = from a in chargeBack.Details
                              join b in order.Details on a.PurchasingOrderDetailID equals b.ID
                              select new Entity.ChargeBackDetail()
                {
                    PurchasingOrderDetailID = a.PurchasingOrderDetailID,
                    Count      = a.Count,
                    Price      = b.Price,
                    Subtotal   = a.Count * b.Price,
                    ChargeBack = entity
                };
                entity.Total   = details.Sum(d => d.Subtotal);
                entity.Details = details.ToList();

                dbcontext.Add(entity);
                //dbcontext.AddRange(details);

                //更新订单状态
                order.PurchasingOrderStatusID = (int)EnumPurchasingOrderState.DepartmentChargeBack;
                order.UpdateUserID            = chargeBack.CreateUsrID;
                order.UpdateTime = chargeBack.CreateTime;
                dbcontext.Update(order);

                dbcontext.SaveChanges();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.InnerException.Message);
            }
        }
Example #2
0
        //GET:get the view of chargeback report
        public async Task <IActionResult> chargebacklist(string searchType, string searchString, int?year)
        {
            if (HttpContext.User.IsInRole("supervisor") || HttpContext.User.IsInRole("manager"))
            {
                List <String> stype = new List <string> {
                    "ItemName", "Department"
                };

                DateTime st         = new DateTime(DateTime.Now.Year, 1, 1);
                var      chargeBack = from a in _context.DeptRequest.Include(p => p.Dept).Include(p => p.Item).Where(p => p.IsCompleted == true && p.TotalQty > p.ReceivedQty) select a;
                if (year == null)
                {
                    chargeBack = chargeBack.Where(p => (DateTime.Compare((DateTime)p.GeneratedTime, st) > 0));
                }
                else
                {
                    st = new DateTime((int)year, 1, 1);
                    DateTime et = new DateTime((int)year, 12, 31);
                    chargeBack = chargeBack.Where(p => (DateTime.Compare((DateTime)p.GeneratedTime, st) > 0) && (DateTime.Compare((DateTime)p.GeneratedTime, et) < 0));
                }
                if (!String.IsNullOrEmpty(searchString))
                {
                    if (!String.IsNullOrEmpty(searchType))
                    {
                        if (searchType == "ItemName")
                        {
                            chargeBack = chargeBack.Where(s => s.Item.ItemName.Contains(searchString));
                        }
                        else if (searchType == "Department")
                        {
                            chargeBack = chargeBack.Where(s => s.Dept.Name.Contains(searchString));
                        }
                    }
                }
                List <DeptRequest> chargebacklist = await chargeBack.ToListAsync();

                List <double> cbamount = new List <double>();
                double        total    = 0;
                foreach (DeptRequest dr in chargebacklist)
                {
                    double amount = (double)dr.Item.Unitprice * (double)(dr.TotalQty - dr.ReceivedQty);
                    cbamount.Add(amount);
                    total += amount;
                }
                var cbl = new ChargeBackModel
                {
                    deptRequests = chargebacklist,
                    deptList     = new SelectList(stype),
                    amountList   = cbamount,
                    tot          = total,
                    startTime    = st.ToString("Y")
                };
                return(View(cbl));
            }
            else
            {
                return(NotFound());
            }
        }
Example #3
0
        public void Add(ChargeBackModel chargeBack)
        {
            if (chargeBack.Details.Count(c => c.Count <= 0) > 0)
            {
                throw new Exception("退货商品数量无效");
            }

            try
            {
                var dbcontext = ServiceProvider.GetDbcontext <IPurocumentDbcontext>();
                var order     = dbcontext.PurchasingOrder.Include(i => i.Details).SingleOrDefault(s => s.ID.Equals(chargeBack.PurchasingOrderID));
                if (order == null || order.ID < 1)
                {
                    throw new Exception("订单不存在");
                }

                DateTime dtNow = DateTime.Now;



                //创建主表
                var entity = new Entity.ChargeBack()
                {
                    Code = StrCBPrefix + DateTime.Now.ToString(StrCBSuffixFormat),
                    PurchasingOrderID       = order.ID,
                    PurchasingOrderStatusID = (int)EnumPurchasingOrderState.DepartmentChargeBack,
                    CreateTime   = chargeBack.CreateTime,
                    UpdateTime   = chargeBack.CreateTime,
                    CreateUsrID  = chargeBack.CreateUsrID,
                    UpdateUserID = chargeBack.CreateUsrID,
                    ItemCount    = chargeBack.Details.Count(),
                    Total        = Convert.ToDecimal(0)
                };

                int    intDepartmentID = order.DepartmentID;
                string strOrderCode    = entity.Code;
                string strCode         = string.Empty;
                string strDateTime     = dtNow.ToString(StrDateTimeFormat);
                //string result = isPass ? "通过" : $"未通过:{Desc}";
                string title   = string.Empty;
                string content = string.Empty;
                string toUsrID = string.Empty;


                var details = from a in chargeBack.Details
                              join b in order.Details on a.PurchasingOrderDetailID equals b.ID
                              select new Entity.ChargeBackDetail()
                {
                    PurchasingOrderDetailID = a.PurchasingOrderDetailID,
                    Count      = a.Count,
                    Price      = b.Price,
                    Subtotal   = a.Count * b.Price,
                    ChargeBack = entity
                };
                entity.Total   = details.Sum(d => d.Subtotal);
                entity.Details = details.ToList();

                dbcontext.Add(entity);
                //dbcontext.AddRange(details);

                //更新订单状态
                order.PurchasingOrderStatusID = (int)EnumPurchasingOrderState.DepartmentChargeBack;
                order.UpdateUserID            = chargeBack.CreateUsrID;
                order.UpdateTime = chargeBack.CreateTime;
                dbcontext.Update(order);

                dbcontext.SaveChanges();

                Department department = dbcontext.Department.SingleOrDefault(s => s.ID == intDepartmentID);

                var toUsrs = dbcontext.Usr.Where(w =>
                                                 w.RoleID == (int)EnumRole.测试 ||
                                                 w.RoleID == (int)EnumRole.采购员
                                                 ).ToList();

                var toUsrIDs        = toUsrs.Select(s => s.WechatID);
                var toUserWechatIDs = toUsrs.Select(s => s.WechatID);
                toUsrID = string.Join("|", toUsrs.Select(s => s.WechatID).ToArray());

                title   = "待审核退货计划";
                content = $"订单编号:{strOrderCode}  退货编号:{strCode}  部门:{department?.Name}";

                MessageService.Post(
                    toUsrID,
                    title,
                    strDateTime,
                    content
                    );
            }
            catch (Exception ex)
            {
                throw new Exception(ex.InnerException.Message);
            }
        }