Beispiel #1
0
        private void details_EditEnding(object sender, EditEndingEventArgs e)
        {
            RadDataForm form = (RadDataForm)sender;
            var         row  = View.Extension.UIHelper.GetAncestor <GridViewRow>(form);
            OrganizationGoodReturnRate rate = row.DataContext as OrganizationGoodReturnRate;

            if (rate.ID == default(int))
            {
                MessageBox.Show("请先保存机构品牌基本退货率");
                e.Cancel = true;
                return;
            }

            if (form.CanCommitEdit && e.EditAction == EditAction.Commit)
            {
                OrganizationGoodReturnRatePerQuarter entity = (OrganizationGoodReturnRatePerQuarter)form.CurrentItem;
                if (entity.ID == default(int))
                {
                    entity.RateID     = rate.ID;
                    entity.CreatorID  = VMGlobal.CurrentUser.ID;
                    entity.CreateTime = DateTime.Now;
                }
                var result = _dataContext.AddOrUpdate(entity);
                MessageBox.Show(result.Message);
                if (!result.IsSucceed)
                {
                    e.Cancel = true;
                }
            }
        }
        public OPResult Delete(OrganizationGoodReturnRatePerQuarter entity)
        {
            if (entity.ID == default(int))
            {
                return new OPResult {
                           IsSucceed = true, Message = "删除成功!"
                }
            }
            ;
            try
            {
                LinqOP.Delete <OrganizationGoodReturnRatePerQuarter>(entity);

                return(new OPResult {
                    IsSucceed = true, Message = "删除成功!"
                });
            }
            catch (Exception e)
            {
                return(new OPResult {
                    IsSucceed = false, Message = "删除失败,失败原因:\n" + e.Message
                });
            }
        }
    }
        public OPResult AddOrUpdate(OrganizationGoodReturnRatePerQuarter entity)
        {
            if (RateIsExist(entity))
            {
                return(new OPResult {
                    IsSucceed = false, Message = "该机构已经设置了该品牌年份季度的退货率."
                });
            }
            var id = entity.ID;

            try
            {
                if (id == default(int))
                {
                    entity.ID = LinqOP.Add <OrganizationGoodReturnRatePerQuarter, int>(entity, o => o.ID);
                }
                else
                {
                    LinqOP.Update <OrganizationGoodReturnRatePerQuarter>(entity);
                }
            }
            catch (Exception e)
            {
                entity.ID = id;
                return(new OPResult {
                    IsSucceed = false, Message = "保存失败,失败原因:\n" + e.Message
                });
            }

            return(new OPResult {
                IsSucceed = true, Message = "保存成功."
            });
        }
 public OrganizationGoodReturnRatePerQuarterBO(OrganizationGoodReturnRatePerQuarter rate)
 {
     this.ID             = rate.ID;
     this.RateID         = rate.RateID;
     this.Year           = rate.Year;
     this.Quarter        = rate.Quarter;
     this.GoodReturnRate = rate.GoodReturnRate;
     CreateTime          = rate.CreateTime;
     CreatorID           = rate.CreatorID;
 }
 private bool RateIsExist(OrganizationGoodReturnRatePerQuarter rate)
 {
     if (rate.ID == default(int))
     {
         return(LinqOP.Any <OrganizationGoodReturnRatePerQuarter>(oc => oc.RateID == rate.RateID && oc.Year == rate.Year && oc.Quarter == rate.Quarter));
     }
     else
     {
         return(LinqOP.Any <OrganizationGoodReturnRatePerQuarter>(oc => oc.ID != rate.ID && oc.RateID == rate.RateID && oc.Year == rate.Year && oc.Quarter == rate.Quarter));
     }
 }
Beispiel #6
0
        private void details_DeletingItem(object sender, System.ComponentModel.CancelEventArgs e)
        {
            RadDataForm form = (RadDataForm)sender;
            OrganizationGoodReturnRatePerQuarter entity = (OrganizationGoodReturnRatePerQuarter)form.CurrentItem;
            var result = _dataContext.Delete(entity);

            MessageBox.Show(result.Message);
            if (!result.IsSucceed)
            {
                e.Cancel = true;
            }
        }
Beispiel #7
0
        /// <summary>
        /// 检查退货率
        /// </summary>
        protected OPResult CheckGoodReturnRate(int organizationID)
        {
            var lp   = VMGlobal.DistributionQuery.LinqOP;
            var rate = lp.Search <OrganizationGoodReturnRate>(o => o.BrandID == this.Master.BrandID && o.OrganizationID == organizationID).FirstOrDefault();

            if (rate != null)
            {
                //获取年度季度退货率
                IEnumerable <string> yqs = this.GridDataItems.Where(o => o.Quantity != 0).Select(o => (o.Year + "-" + o.Quarter.ToString())).Distinct().ToList();
                var yqrateSource         = lp.Search <OrganizationGoodReturnRatePerQuarter>(o => o.RateID == rate.ID && yqs.Contains(o.Year.ToString() + "-" + o.Quarter.ToString())).ToList();
                IEnumerable <OrganizationGoodReturnRatePerQuarter> yqrates = yqs.Select(o =>
                {
                    OrganizationGoodReturnRatePerQuarter yqrate = yqrateSource.FirstOrDefault(yqr => o == yqr.Year.ToString() + "-" + yqr.Quarter.ToString());
                    if (yqrate == null)
                    {
                        var yq = o.Split('-');
                        yqrate = new OrganizationGoodReturnRatePerQuarter {
                            Year = Convert.ToInt32(yq[0]), Quarter = Convert.ToInt32(yq[1]), GoodReturnRate = rate.GoodReturnRate
                        };
                    }
                    return(yqrate);
                });

                IQueryable <Product>  products  = VMGlobal.DistributionQuery.QueryProvider.GetTable <Product>("SysProcess.dbo.Product");
                IQueryable <ProStyle> prostyles = VMGlobal.DistributionQuery.QueryProvider.GetTable <ProStyle>("SysProcess.dbo.ProStyle");
                IQueryable <ProBYQ>   byqs      = VMGlobal.DistributionQuery.QueryProvider.GetTable <ProBYQ>("SysProcess.dbo.ProBYQ");
                var deliveries  = lp.GetDataContext <BillDelivery>();
                var deDetails   = lp.GetDataContext <BillDeliveryDetails>();
                var goodreturns = lp.GetDataContext <BillGoodReturn>();
                var reDetails   = lp.GetDataContext <BillGoodReturnDetails>();
                //var billSnapshots = lp.GetDataContext<BillSnapshot>();
                //var ssDetails = lp.GetDataContext<BillSnapshotDetailsWithUniqueCode>();
                //var mappings = lp.GetDataContext<ViewProductUniqueCodeMapping>();
                foreach (var rateitem in yqrates)
                {
                    IQueryable <Product> tempProducts = from prostyle in prostyles
                                                        from byq in byqs
                                                        where byq.ID == prostyle.BYQID && byq.BrandID == this.Master.BrandID && byq.Year == rateitem.Year && byq.Quarter == rateitem.Quarter
                                                        from product in products
                                                        where product.StyleID == prostyle.ID
                                                        select product;
                    IQueryable <BillDeliveryDetails> tempDeDetails = from delivery in deliveries
                                                                     from dd in deDetails
                                                                     where delivery.ID == dd.BillID && delivery.ToOrganizationID == organizationID && delivery.DeliveryKind == 0 && delivery.Status != (int)BillDeliveryStatusEnum.已装箱未配送 //&& delivery.BrandID == this.Master.BrandID
                                                                     from product in tempProducts
                                                                     where product.ID == dd.ProductID
                                                                     select dd;
                    var deliveriedMoney = tempDeDetails.Sum(dd => dd.Quantity * dd.Price * dd.Discount);//已发货金额
                    if (deliveriedMoney <= 0)
                    {
                        return new OPResult {
                                   IsSucceed = false, Message = string.Format("无法退货,{0}年第{1}季货品没有发过货,无法退货", rateitem.Year, rateitem.Quarter)
                        }
                    }
                    ;

                    #region  唯一码原发货时折扣价格作为退货时的金额计算依据,但是逻辑太复杂了,因此改为退货金额直接使用当前折扣计算(一般来说同季商品的发货折扣应该是不会变的,退货折扣等于发货折扣)
                    //var returnedUniqueCodes = (from goodreturn in goodreturns
                    //                           from rd in reDetails
                    //                           where goodreturn.ID == rd.BillID && goodreturn.OrganizationID == VMGlobal.CurrentUser.OrganizationID && goodreturn.BrandID == this.Master.BrandID
                    //                           from product in tempProducts
                    //                           where product.ID == rd.ProductID
                    //                           from snapshot in billSnapshots
                    //                           where goodreturn.Code == snapshot.BillCode
                    //                           from sd in ssDetails
                    //                           where snapshot.ID == sd.SnapshotID
                    //                           from mapping in mappings
                    //                           where sd.UniqueCode == mapping.UniqueCode && mapping.ProductID == product.ID
                    //                           select sd.UniqueCode).ToList(); //获取已退货唯一码
                    //IEnumerable<string> tempReturnedUniqueCodes = returnedUniqueCodes.Select(rc=>rc.UniqueCode).Distinct().ToArray();
                    //var recentDeliveries = (from snapshot in billSnapshots
                    //                        from sd in ssDetails
                    //                        where snapshot.ID == sd.SnapshotID && snapshot.BillTypeName == "发货单" && tempReturnedUniqueCodes.Contains(sd.UniqueCode)
                    //                        from delivery in deliveries
                    //                        where snapshot.BillCode == delivery.Code && delivery.ToOrganizationID == VMGlobal.CurrentUser.OrganizationID && delivery.DeliveryKind == 0 && delivery.Status != (int)BillDeliveryStatusEnum.已装箱未配送 && delivery.BrandID == this.Master.BrandID
                    //                        select new { snapshot.BillCode, sd.UniqueCode,snapshot.CreateTime }).ToList();
                    //List<string> exceptDeliveries = new List<string>();
                    //foreach (var rc in tempReturnedUniqueCodes)
                    //{
                    //    //当最近的一次发货时间大于最近的一次退货时间
                    //    var recentDeliveryTime = recentDeliveries.Where(o => o.UniqueCode == rc).Max(o => o.CreateTime);
                    //    var recentReturnTime = returnedUniqueCodes.Where(o => o.UniqueCode == rc).Max(o => o.CreateTime);
                    //    if (recentDeliveryTime > recentReturnTime)
                    //        exceptDeliveries.Add(recentDeliveries.Find(o => o.UniqueCode == rc && o.CreateTime == recentDeliveryTime).BillCode);
                    //}
                    //退货自动计算退货金额的逻辑并不准确,只能做到大部分情况下(同一个唯一码退货之后不会重新发给同一个机构)不出错,否则逻辑就太复杂了
                    //以后将改成在扫单时候就判断唯一码在发货时的发货金额,然后保存时只要简单汇总即可。同时新建一个表专门存放发货总金额和退货总金额
                    //uniqueCodes = uniqueCodes.Concat(returnedUniqueCodes);
                    //tempDeDetails = from snapshot in billSnapshots
                    //                from sd in ssDetails
                    //                where snapshot.ID == sd.SnapshotID && snapshot.BillTypeName == "发货单" && uniqueCodes.Contains(sd.UniqueCode)
                    //                from delivery in deliveries
                    //                where snapshot.BillCode == delivery.Code && delivery.ToOrganizationID == VMGlobal.CurrentUser.OrganizationID && delivery.DeliveryKind == 0 && delivery.Status != (int)BillDeliveryStatusEnum.已装箱未配送 && delivery.BrandID == this.Master.BrandID
                    //                from dd in deDetails
                    //                where delivery.ID == dd.BillID
                    //                from product in tempProducts
                    //                where product.ID == dd.ProductID
                    //                from mapping in mappings
                    //                where sd.UniqueCode == mapping.UniqueCode && dd.ProductID == mapping.ProductID
                    //                select dd;
                    //var goodReturnMoney = tempDeDetails.Sum(dd => dd.Price * dd.Discount);//退货总金额=唯一码对应的原发货金额
                    //if (rateitem.GoodReturnRate < (goodReturnMoney * 100 / deliveriedMoney))
                    //    return new OPResult { IsSucceed = false, Message = string.Format("无法退货,{0}年第{1}季货品超出退货率", rateitem.Year, rateitem.Quarter) };
                    //returnMoney += goodReturnMoney;
                    #endregion

                    IQueryable <BillGoodReturnDetails> tempReDetails = from goodreturn in goodreturns
                                                                       from rd in reDetails
                                                                       where goodreturn.ID == rd.BillID && goodreturn.OrganizationID == organizationID && !goodreturn.IsDefective && goodreturn.Status != (int)BillGoodReturnStatusEnum.被退回 && goodreturn.Status != (int)BillGoodReturnStatusEnum.退回已入库
                                                                       from product in tempProducts
                                                                       where product.ID == rd.ProductID
                                                                       select rd;
                    var goodReturnMoney = tempReDetails.Sum(dd => dd.Quantity * dd.Price * dd.Discount);                                                                       //已退货金额
                    var nowReturnMoney  = this.GridDataItems.Where(o => o.Year == rateitem.Year && o.Quarter == rateitem.Quarter).Sum(o => o.Quantity * o.Price * o.Discount); //本单退货金额

                    if (rateitem.GoodReturnRate < ((goodReturnMoney + nowReturnMoney) * 100 / deliveriedMoney))
                    {
                        return new OPResult {
                                   IsSucceed = false, Message = string.Format("无法退货,{0}年第{1}季货品超出退货率", rateitem.Year, rateitem.Quarter)
                        }
                    }
                    ;
                }
            }
            return(new OPResult {
                IsSucceed = true
            });
        }
    }