Ejemplo n.º 1
0
        public override void SetRetailData()
        {
            Action <DistributionProductShow> action = p =>
            {
                this.Master.Quantity  += p.Quantity;
                this.Master.CostMoney += (p.Quantity * p.Price * p.Discount / 100.0M);
            };

            this.TraverseGridDataItems(action);

            if (this.Master.Remark == _retailTacticRemark)
            {
                this.Master.Remark = _retailTacticRemark = "";
            }

            if (_discountTacticProductMapping.Count > 0)
            {
                _discountTacticProductMapping.RemoveAll(o => !(GridDataItems.Where(d => d.Quantity != 0).Select(d => d.ProductID).Contains(o.ProductID)));
                var dtactics = _discountTacticProductMapping.Select(o => o.TacticName).Distinct();
                _retailTacticRemark = string.Join(",", dtactics) + ",";
            }

            //零售满减策略
            //if (retail.CostMoney > 0)
            //{
            var details   = GridDataItems.Where(o => o.Quantity != 0);
            var cctactics = GetCostCutTacticForProduct(details.Select(o => o.ProductID));

            if (cctactics != null)
            {
                decimal costMoney = this.Master.CostMoney;
                foreach (var cctactic in cctactics)
                {
                    var temp      = details.Where(o => cctactic.ProductIDs.Contains(o.ProductID));
                    var costprice = temp.Sum(o => o.Quantity * o.Price * o.Discount / 100.0M);
                    if (costprice >= cctactic.CostMoney)
                    {
                        int times    = (int)costprice / cctactic.CostMoney;//倍数
                        var cutMoney = Math.Min(this.Master.CostMoney, cctactic.CutMoney * times);
                        costMoney           -= cutMoney;
                        _retailTacticRemark += cctactic.TacticName + ",";
                        foreach (var d in temp)
                        {
                            d.CutMoney = (d.Price * d.Quantity * d.Discount * cutMoney / (100 * costprice));
                        }
                        if (costMoney == 0)
                        {
                            break;
                        }
                    }
                }
            }
            // }
            if (string.IsNullOrWhiteSpace(this.Master.Remark) && !string.IsNullOrEmpty(_retailTacticRemark))
            {
                this.Master.Remark = _retailTacticRemark.TrimEnd(',');
            }

            base.SetRetailData();
        }
Ejemplo n.º 2
0
 private IEnumerable <VIPUpTactic> GetVIPUpTacticsWhenCash()
 {
     if (_vipInfo == null)
     {
         return(null);
     }
     else
     {
         List <VIPUpTactic> reTactics = new List <VIPUpTactic>();
         var lp       = VMGlobal.DistributionQuery.LinqOP;
         var brandIDs = GridDataItems.Select(o => o.BrandID).Distinct();
         var kindIDs  = _vipInfo.VIPKinds.Where(o => brandIDs.Contains(o.BrandID)).Select(o => o.ID);
         var tactics  = lp.Search <VIPUpTactic>(o => kindIDs.Contains(o.FormerKindID) && o.IsEnabled).ToList();
         foreach (var tactic in tactics)
         {
             if (tactic.OnceConsume != 0)
             {
                 var pids      = GridDataItems.Where(o => o.BrandID == tactic.BrandID).Select(o => o.ProductID);
                 var costMoney = Details.Where(o => pids.Contains(o.ProductID)).Sum(o => o.Quantity * o.Price * o.Discount / 100.0M - o.CutMoney);
                 if (costMoney >= tactic.OnceConsume)
                 {
                     reTactics.Add(tactic);
                     continue;
                 }
             }
             if (tactic.DateSpan != 0 && tactic.SpanConsume != 0)
             {
                 var beginDate = DateTime.Now.AddDays(tactic.DateSpan * (-1)).Date;
                 var retails   = lp.Search <BillRetail>(o => o.CreateTime >= beginDate && o.VIPID == _vipInfo.ID);
                 var details   = lp.GetDataContext <BillRetailDetails>();
                 var products  = lp.Search <ViewProduct>(o => o.BrandID == tactic.BrandID);
                 var data      = from detail in details
                                 from retail in retails
                                 where retail.ID == detail.BillID
                                 from product in products
                                 where detail.ProductID == product.ProductID
                                 select detail;
                 var totalCost = data.Sum(o => o.Quantity * o.Price * o.Discount / 100.0M - o.CutMoney);
                 if (totalCost >= tactic.SpanConsume)
                 {
                     reTactics.Add(tactic);
                     continue;
                 }
             }
         }
         return(reTactics.OrderBy(o => o.FormerKindID));
     }
 }
Ejemplo n.º 3
0
 public override void AddRangeToItems(IEnumerable <DistributionProductShow> datas)
 {
     foreach (var data in datas)
     {
         if (data.Quantity > 0)
         {
             var item = GridDataItems.FirstOrDefault(o => o.ProductID == data.ProductID);
             if (item != null)
             {
                 item.Quantity += data.Quantity;
             }
             else
             {
                 GridDataItems.Add(data);
             }
         }
     }
 }
 public override void AddRangeToItems(IEnumerable <ProductForStoringWhenReceiving> datas)
 {
     foreach (var data in datas)
     {
         if (data.Quantity != 0)
         {
             var item = GridDataItems.FirstOrDefault(o => o.ProductID == data.ProductID);
             if (item != null)
             {
                 item.ReceiveQuantity += data.Quantity;
             }
             else
             {
                 data.ReceiveQuantity = data.Quantity;
                 data.Quantity        = 0;
                 GridDataItems.Add(data);
             }
         }
     }
 }
        public BillStoringWhenReceivingVMBase(BillWithBrand bill)
            : base()
        {
            GridDataItems.Clear();
#if UniqueCode
            var ssdetails = BillStoringCannibalizeVM.GetSnapshotDetails(bill.Code);
#endif
            var data = this.GetBillReceiveDetails(bill.ID);
            foreach (var o in data)
            {
#if UniqueCode
                var temp = ssdetails.Where(u => u.ProductID == o.ProductID);
                foreach (var t in temp)
                {
                    o.UniqueCodes.Add(t.UniqueCode);
                }
#endif
                GridDataItems.Add(o);
            }
        }
Ejemplo n.º 6
0
        public OPResult ValidateWhenCash()
        {
            if (Master.StorageID == default(int))
            {
                return(new OPResult {
                    IsSucceed = false, Message = "请选择出货仓库"
                });
            }
            int quantity = GridDataItems.Count(o => o.Quantity != 0);

            if (quantity == 0)
            {
                return(new OPResult {
                    IsSucceed = false, Message = "没有需要保存的数据"
                });
            }
            return(new OPResult {
                IsSucceed = true
            });
        }
        public override void ProductCodeInput(string pcode, Action <IEnumerable <ProductForStoringWhenReceiving> > actionWhenMore)
        {
            if (GridDataItems.Count > 0)
            {
                if (TryReceiveProductOneByOne(pcode))
                {
                    return;
                }
            }
            var datas = this.GetProductForShow(pcode);

            if (datas != null && datas.Count > 0)
            {
                if (datas.Count == 1)
                {
                    var item = GridDataItems.FirstOrDefault(o => o.ProductID == datas[0].ProductID);
                    if (item != null)
                    {
                        item.ReceiveQuantity += 1;
                    }
                    else
                    {
                        datas[0].ReceiveQuantity = 1;
                        GridDataItems.Add(datas[0]);
                    }
                }
                else
                {
                    if (actionWhenMore != null)
                    {
                        actionWhenMore(datas);
                    }
                }
            }
            else
            {
                throw new Exception("没有相关成品信息.");
            }
        }
Ejemplo n.º 8
0
        protected virtual BillRetailBO GenerateRetailBO()
        {
            var bo = new BillRetailBO {
                Bill = this.Master, Details = this.Details
            };
            var brandIDs = GridDataItems.Select(o => o.BrandID).Distinct().ToList();

            bo.BillStoreOuts = new List <BillBO <BillStoreOut, BillStoreOutDetails> >();
            bo.BillStorings  = new List <BillBO <BillStoring, BillStoringDetails> >();
            foreach (var bid in brandIDs)
            {
                var storeout = this.GenerateStoreOut(bid);
                if (storeout.Details.Count > 0)
                {
                    bo.BillStoreOuts.Add(storeout);
                }
                var storing = this.GenerateStoring(bid);
                if (storing.Details.Count > 0)
                {
                    bo.BillStorings.Add(storing);
                }
            }
            return(bo);
        }
Ejemplo n.º 9
0
        public override OPResult Save()
        {
            var lp = VMGlobal.DistributionQuery.LinqOP;

            var brandIDs = GridDataItems.Select(o => o.BrandID).Distinct().ToList();
            List <BillStoreOutVM> storeouts = new List <BillStoreOutVM>();
            List <BillStoringVM>  storings  = new List <BillStoringVM>();

            foreach (var bid in brandIDs)
            {
                var storeout = this.GenerateStoreOut(bid);
                if (storeout.Details.Count > 0)
                {
                    storeouts.Add(storeout);
                }
                var storing = this.GenerateStoring(bid);
                if (storing.Details.Count > 0)
                {
                    storings.Add(storing);
                }
            }
            Action storeAction = () =>
            {
                foreach (var storeout in storeouts)
                {
                    storeout.Master.RefrenceBillCode = Master.Code;
                    storeout.SaveWithNoTran();
                }
                foreach (var storing in storings)
                {
                    storing.Master.RefrenceBillCode = Master.Code;
                    storing.SaveWithNoTran();
                }
            };

            using (TransactionScope scope = new TransactionScope())
            {
                try
                {
                    base.SaveWithNoTran();
                    storeAction();
                    if (this._vipInfo != null)
                    {
                        //添加VIP积分记录
                        VIPPointTrack pointTrack = new VIPPointTrack
                        {
                            CreateTime = DateTime.Now,
                            Point      = _vipInfo.PointTimes * ((int)Master.CostMoney),
                            VIPID      = _vipInfo.ID,
                            Remark     = "零售单产生,小票号" + Master.Code
                        };
                        lp.Add <VIPPointTrack>(pointTrack);
                        if (_vipUpgradeInfo != null)
                        {
                            var tactics = _vipUpgradeInfo.UpTactics.Where(o => o.IsChecked);
                            if (tactics != null && tactics.Count() > 0)
                            {
                                IEnumerable <int> kindIDs = tactics.Select(o => o.FormerKindID).ToList();
                                IEnumerable <VIPCardKindMapping> mappings = lp.Search <VIPCardKindMapping>(o => o.CardID == _vipInfo.ID && kindIDs.Contains(o.KindID)).ToList();
                                foreach (var mapping in mappings)
                                {
                                    var t = tactics.First(o => o.FormerKindID == mapping.KindID);
                                    mapping.KindID = t.AfterKindID;
                                    if (t.CutPoint != 0)
                                    {
                                        pointTrack = new VIPPointTrack
                                        {
                                            CreateTime = DateTime.Now,
                                            Point      = (-1 * t.CutPoint),
                                            VIPID      = _vipInfo.ID,
                                            Remark     = "VIP升级产生," + t.Description
                                        };
                                        lp.Add <VIPPointTrack>(pointTrack);
                                    }
                                }
                                lp.Update <VIPCardKindMapping>(mappings);
                            }
                        }
                        if (_vipInfo.IsBirthday && this._vipInfo.CostMoney != 0 && this._vipInfo.Quantity != 0)
                        {
                            lp.Delete <VIPBirthdayConsumption>(o => o.VIPID == _vipInfo.ID && o.ConsumeDay == DateTime.Now.Date);
                            lp.Add <VIPBirthdayConsumption>(new VIPBirthdayConsumption
                            {
                                VIPID      = _vipInfo.ID,
                                Quantity   = _vipInfo.Quantity,
                                CostMoney  = _vipInfo.CostMoney,
                                ConsumeDay = DateTime.Now.Date
                            });
                        }
                    }
                    scope.Complete();
                }
                catch (Exception e)
                {
                    return(new OPResult {
                        IsSucceed = false, Message = e.Message
                    });
                }
            }
            var users = IMHelper.OnlineUsers.Where(o => o.OrganizationID == OrganizationListVM.CurrentOrganization.ParentID).ToArray();

            IMHelper.AsyncSendMessageTo(users, new IMessage
            {
                Message = string.Format("{2}销售{0}件,单号{1},金额{3:C}.", Details.Sum(o => o.Quantity), Master.Code, OrganizationListVM.CurrentOrganization.Name, Master.CostMoney)
            }, IMReceiveAccessEnum.零售单);
            return(new OPResult {
                IsSucceed = true
            });
        }
Ejemplo n.º 10
0
        public void SetRetailData()
        {
            BillRetail retail = this.Master;

            //数量和金额置0
            retail.Quantity  = 0;
            retail.CostMoney = 0.0M;
            if (retail.Remark == _retailTacticRemark)
            {
                retail.Remark = _retailTacticRemark = "";
            }

            decimal totalPriceForCoupon = 0.0M;//抵价券应用的品牌原总金额(未打折时金额累加)
            Action <DistributionProductForBrush> action = p =>
            {
                retail.Quantity  += p.Quantity;
                retail.CostMoney += (p.Quantity * p.Price * p.Discount / 100.0M);
                if (_couponBrandIDs != null && _couponBrandIDs.Contains(p.BrandID))
                {
                    totalPriceForCoupon += (p.Quantity * p.Price);
                }
            };

            this.TraverseGridDataItems(action);
            retail.CostMoney     = Math.Ceiling(retail.CostMoney);//向上取整
            retail.ReceiveTicket = _beforeDiscountCoupon + _afterDiscountCoupon;

            if (retail.CostMoney > 0)             //抵用券只适用于正金额
            {
                decimal beforeTicketMoney = 0.0M; //折前券抵用金额,以原金额占比计算
                if (_beforeDiscountCoupon != 0 && totalPriceForCoupon != 0)
                {
                    action = p =>
                    {
                        if (_couponBrandIDs != null && _couponBrandIDs.Contains(p.BrandID))
                        {
                            beforeTicketMoney += (p.Quantity * p.Price * p.Discount / 100.0M) * _beforeDiscountCoupon / totalPriceForCoupon;
                        }
                    };
                    this.TraverseGridDataItems(action);
                }
                retail.TicketMoney = Math.Floor(beforeTicketMoney + Math.Min(retail.CostMoney - beforeTicketMoney, _afterDiscountCoupon));//向下取整
                retail.TicketMoney = Math.Min(retail.TicketMoney, retail.CostMoney);
                if (_beforeDiscountCoupon != 0 && _afterDiscountCoupon != 0)
                {
                    retail.TicketKind = 3;
                }
                else if (_beforeDiscountCoupon != 0)
                {
                    retail.TicketKind = 1;
                }
                else if (_afterDiscountCoupon != 0)
                {
                    retail.TicketKind = 2;
                }
            }
            if (this._vipInfo != null)
            {
                retail.VIPID = this._vipInfo.ID;
            }
            retail.OrganizationID = VMGlobal.CurrentUser.OrganizationID;

            if (_discountTacticProductMapping.Count > 0)
            {
                _discountTacticProductMapping.RemoveAll(o => !(GridDataItems.Where(d => d.Quantity != 0).Select(d => d.ProductID).Contains(o.ProductID)));
                var dtactics = _discountTacticProductMapping.Select(o => o.TacticName).Distinct();
                _retailTacticRemark = string.Join(",", dtactics) + ",";
            }

            //零售满减策略
            //if (retail.CostMoney > 0)
            //{
            var details   = GridDataItems.Where(o => o.Quantity != 0);
            var cctactics = GetCostCutTacticForProduct(details.Select(o => o.ProductID));

            if (cctactics != null)
            {
                decimal costMoney = retail.CostMoney;
                foreach (var cctactic in cctactics)
                {
                    var temp      = details.Where(o => cctactic.ProductIDs.Contains(o.ProductID));
                    var costprice = temp.Sum(o => o.Quantity * o.Price * o.Discount / 100.0M);
                    if (costprice >= cctactic.CostMoney)
                    {
                        int times    = (int)costprice / cctactic.CostMoney;//倍数
                        var cutMoney = Math.Min(retail.CostMoney, cctactic.CutMoney * times);
                        costMoney           -= cutMoney;
                        _retailTacticRemark += cctactic.TacticName + ",";
                        foreach (var d in temp)
                        {
                            d.CutMoney = (d.Price * d.Quantity * d.Discount * cutMoney / (100 * costprice));
                        }
                        if (costMoney == 0)
                        {
                            break;
                        }
                    }
                }
            }
            // }
            if (string.IsNullOrWhiteSpace(retail.Remark) && !string.IsNullOrEmpty(_retailTacticRemark))
            {
                retail.Remark = _retailTacticRemark.TrimEnd(',');
            }

            Details = new List <BillRetailDetails>();
            this.TraverseGridDataItems(p =>
            {
                Details.Add(new BillRetailDetailsForPrint
                {
                    ProductID   = p.ProductID,
                    Quantity    = p.Quantity,
                    Discount    = p.Discount,
                    Price       = p.Price,
                    ProductCode = p.ProductCode,
                    CutMoney    = p.CutMoney
                });
                retail.CostMoney -= p.CutMoney;
            });
            retail.ReceiveMoney = retail.CostMoney - retail.TicketMoney;
        }