Exemplo n.º 1
0
        public static OpResult SaveTuiHuang(OrderReturns obj, string receiveNum)
        {
            var op = new OpResult();

            try
            {
                obj.CompanyId = CommonService.CompanyId;
                if (obj.Id == 0)
                {
                    obj.State = 0;
                    var dist = OrderDistributionService.Find(o => o.DistributionId == obj.DistributionId);
                    if (dist != null)
                    {
                        dist.State       = 6;
                        dist.ReceivedNum = dist.DeliveryNum - obj.ReturnNum;
                        dist.ReceivedDT  = DateTime.Now;
                        if (obj.ReturnType == 0)//退货时
                        {
                            OrderDistributionService.Update(dist);
                            Update(obj.DistributionId, null, obj.Barcode);
                            obj.State = 1;
                        }
                    }
                    obj.CreateDT  = DateTime.Now;
                    obj.CreateUID = Sys.CurrentUser.UID;
                    op            = OrderReturnBLL.Add(obj);
                    //if(op.Successed)
                    //    InventoryRecordService.SaveLog(new List<InventoryRecord>(){
                    //        new InventoryRecord(){Barcode=obj.Barcode,StoreId=Sys.CurrentUser.StoreId,Source=12,Number=obj.ReturnNum.GetValueOrDefault()}
                    //    });
                }
                else
                {
                    var resour = OrderReturnBLL.FindById(obj.Id);
                    obj.ToCopyProperty(resour);
                    op = OrderReturnBLL.Update(resour);
                }
            }
            catch (Exception e)
            {
                op.Message = e.Message;
                new Sys.LogEngine().WriteError(e);
            }
            return(op);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 更新收货数量
        /// </summary>
        /// <param name="id"></param>
        /// <param name="num">null-设为已收货插入库存表</param>
        /// <returns></returns>
        public static OpResult Update(string id, decimal?num, string returnBarcode = "")
        {
            var ids = id.Split(',');
            var op  = new OpResult();

            try
            {
                var list = BaseService <OrderDistribution> .CurrentRepository.QueryEntity.Include(o => o.OrderDistributionGifts).Where(o => ids.Contains(o.DistributionId)).ToList();

                var orderIds      = list.Select(o => o.IndentOrderId).ToList();
                var orderDistrIds = list.Select(o => o.Id).ToList();
                var orderList     = OrderService.FindList(o => orderIds.Contains(o.IndentOrderId));
                var updated       = System.Web.HttpContext.Current.Request["Updated"];
                var gifts         = new List <OrderDistributionGift>();
                if (!updated.IsNullOrEmpty())
                {
                    gifts = updated.ToObject <List <OrderDistributionGift> >();
                }
                var records = new List <InventoryRecord>();
                list.Each(obj =>
                {
                    if (!num.HasValue)
                    {
                        obj.State = 5;
                    }
                    else
                    {
                        obj.ReceivedNum = num;
                        obj.ReceivedDT  = DateTime.Now;
                    }
                    var store = orderList.FirstOrDefault(o => o.IndentOrderId == obj.IndentOrderId);
                    foreach (var g in gifts)
                    {
                        var gift = obj.OrderDistributionGifts.FirstOrDefault(o => o.Barcode == g.Barcode);
                        if (gift != null)
                        {
                            gift.ReceivedNum = g.ReceivedNum;
                        }
                        else
                        {
                            obj.OrderDistributionGifts.Add(g);
                        }
                    }
                    foreach (var gift in obj.OrderDistributionGifts)
                    {
                        var pro = ProductService.Find(o => o.Barcode == gift.Barcode || ("," + o.Barcodes + ",").Contains("," + gift.Barcode + ","));
                        records.Add(new InventoryRecord()
                        {
                            Barcode = (pro != null?pro.Barcode: gift.Barcode), StoreId = Sys.CurrentUser.StoreId, Number = gift.ReceivedNum.GetValueOrDefault(), Source = 11, OperatId = obj.DistributionId
                        });
                    }
                });
                if (num.HasValue)
                {
                    op = BaseService <OrderDistribution> .Update(list);
                }
                else//影响库存
                {
                    var detailList = BaseService <IndentOrderList> .FindList(o => orderIds.Contains(o.IndentOrderId) && o.Nature == 0);

                    foreach (var dist in list)
                    {
                        var obj = detailList.FirstOrDefault(o => o.IndentOrderId == dist.IndentOrderId && (o.Barcode == dist.Barcode || o.AssistBarcode == dist.Barcode));
                        if (obj == null)
                        {
                            continue;
                        }
                        var store = orderList.FirstOrDefault(o => o.IndentOrderId == obj.IndentOrderId);
                        records.Add(new InventoryRecord()
                        {
                            Barcode = obj.Barcode, StoreId = store.StoreId, Number = dist.ReceivedNum.GetValueOrDefault(), OperatType = 1, Source = 11, OperatId = dist.DistributionId
                        });
                        obj.AcceptNum += dist.ReceivedNum.GetValueOrDefault();
                        if (obj.AcceptNum >= obj.IndentNum || obj.Barcode == returnBarcode)
                        {
                            obj.State = 5;
                        }
                    }
                    foreach (var order in orderList)
                    {
                        int count   = 0;
                        var details = detailList.Where(o => o.IndentOrderId == order.IndentOrderId);
                        foreach (var detail in details)
                        {
                            if (detail.State == 5)
                            {
                                count++;
                            }
                        }
                        if (details.Count() == count)//都为已收货时,更新订单主表状态
                        {
                            order.State      = 5;
                            order.ReceivedDT = DateTime.Now;
                        }
                    }
                    var returnIds = list.Where(o => o.OrderReturnId.HasValue).Select(o => o.OrderReturnId).ToList();
                    if (returnIds.Any())//已完成换
                    {
                        var rtns = OrderReturnBLL.FindList(o => returnIds.Contains(o.Id));
                        rtns.Each(o => o.State = 2);
                    }
                    BaseService <OrderDistribution> .Update(list, false);

                    BaseService <IndentOrderList> .Update(detailList, false);

                    op = BaseService <IndentOrder> .Update(orderList);

                    if (op.Successed)
                    {
                        InventoryRecordService.SaveLog(records);
                    }
                    //op = CommodityService.AddRange(commoditys);
                }
            }
            catch (Exception e)
            {
                op.Message = e.Message;
                new Sys.LogEngine().WriteError(e);
            }
            return(op);
        }