Exemple #1
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="backSaleId"></param>
        /// <param name="order_id"></param>
        /// <param name="status"></param>
        public void HandleWastageBackSale_TotalWaste(int backSaleId,List<BOrder> borders,int status)
        {
            if (this.CurrentUserPermission.HANDLE_BACK_SALE == 0)
            {
                throw new KMJXCException("没有处理退货单的权限");
            }

            string[] order_id = null;

            if (backSaleId <= 0 || borders==null || borders.Count==0)
            {
                throw new KMJXCException("没有退货单信息");
            }

            order_id=(from o in borders select o.Order_ID).ToArray<string>();

            using (KuanMaiEntities db = new KuanMaiEntities())
            {
                Back_Sale backSake=(from bs in db.Back_Sale where bs.Back_Sale_ID==backSaleId select bs).FirstOrDefault<Back_Sale>();
                if (backSake == null)
                {
                    throw new KMJXCException("编号为:"+backSaleId+" 的退货单信息不存在");
                }

                List<Back_Sale_Detail> details=(from bsd in db.Back_Sale_Detail where bsd.Back_Sale_ID==backSaleId && order_id.Contains(bsd.Order_ID) select bsd).ToList<Back_Sale_Detail>();

                int[] child_shop=(from child in this.DBChildShops select child.Shop_ID).ToArray<int>();

                List<Stock_Waste> wastage=(from waste in db.Stock_Waste
                                           where waste.Shop_ID==this.Shop.Shop_ID || waste.Shop_ID==this.Main_Shop.Shop_ID || child_shop.Contains(waste.Shop_ID)
                                           select waste).ToList<Stock_Waste>();

                Leave_Stock leave_Stock = (from ls in db.Leave_Stock where ls.Sale_ID == backSake.Sale_ID select ls).FirstOrDefault<Leave_Stock>();

                //no leave no need to set to wastage
                if (leave_Stock == null)
                {
                    return;
                }

                List<Leave_Stock_Detail> leaveDetails = (from ld in db.Leave_Stock_Detail where ld.Leave_Stock_ID == leave_Stock.Leave_Stock_ID select ld).ToList<Leave_Stock_Detail>();

                foreach (Back_Sale_Detail detail in details)
                {
                    Leave_Stock_Detail leaveDetail=(from ld in leaveDetails where ld.Order_ID==detail.Order_ID && ld.Product_ID==detail.Product_ID select ld).FirstOrDefault<Leave_Stock_Detail>();
                    if (leaveDetail == null)
                    {
                        continue;
                    }

                    int q=(from o in borders where o.Order_ID == detail.Order_ID select o.Quantity).FirstOrDefault<int>();
                    Stock_Waste w = (from waste in wastage where waste.Product_ID == detail.Product_ID select waste).FirstOrDefault<Stock_Waste>();
                    if (w == null)
                    {
                        w = new Stock_Waste();
                        w.Parent_ProductID = detail.Parent_Product_ID;
                        w.Price = detail.Price;
                        w.Product_ID = w.Product_ID;
                        if (w.Parent_ProductID == 0)
                        {
                            w.Parent_ProductID = w.Product_ID;
                        }
                        w.Quantity = q;
                        w.Shop_ID = this.Shop.Shop_ID;
                        db.Stock_Waste.Add(w);
                    }
                    else
                    {
                        w.Quantity += q;
                    }

                    detail.Status = status;
                    leaveDetail.Status = status;
                    Sale_Detail saleDetail=(from sd in db.Sale_Detail where sd.Mall_Order_ID==detail.Order_ID select sd).FirstOrDefault<Sale_Detail>();
                    if (saleDetail != null)
                    {
                        saleDetail.Status1 = (int)SaleDetailStatus.REFOUND_HANDLED;
                        saleDetail.SyncResultMessage = "退货已经处理";
                    }
                }

                db.SaveChanges();
            }
        }
Exemple #2
0
        /// <summary>
        /// Update product wastage quantity
        /// </summary>
        /// <param name="products">List of BProduct object, ID and Quantity fields must have valid values.</param>
        public void UpdateProductsWastage(List<BProduct> products)
        {
            if (products == null || products.Count == 0)
            {
                return;
            }

            if (this.CurrentUserPermission.UPDATE_WASTAGE == 0)
            {
                throw new KMJXCException("没有权限更新产品损耗数量");
            }

            using (KuanMaiEntities db = new KuanMaiEntities())
            {
                int[] product_ids=(from p in products select p.ID).ToArray<int>();

                List<Product> dbProducts=(from p in db.Product where product_ids.Contains(p.Product_ID) select p).ToList<Product>();
                List<Stock_Waste> wss = (from s in db.Stock_Waste where product_ids.Contains(s.Product_ID) select s).ToList<Stock_Waste>();
                foreach (Product product in dbProducts)
                {
                    BProduct bProduct=(from bp in products where bp.ID==product.Product_ID select bp).FirstOrDefault<BProduct>();
                    Stock_Waste sw=(from s in wss where s.Product_ID == product.Product_ID select s).FirstOrDefault<Stock_Waste>();
                    if (sw != null)
                    {
                        sw.Quantity = bProduct.Quantity;
                    }
                    else
                    {
                        sw = new Stock_Waste();
                        sw.Product_ID = product.Product_ID;
                        sw.Parent_ProductID = product.Parent_ID;
                        if (sw.Parent_ProductID == 0)
                        {
                            sw.Parent_ProductID = product.Product_ID;
                        }
                        sw.Shop_ID = product.Shop_ID;
                        sw.Quantity = bProduct.Quantity;
                        db.Stock_Waste.Add(sw);
                    }
                }

                db.SaveChanges();
            }
        }