Esempio n. 1
0
        public ActionResult _GetServicePartital(bool Gender)
        {
            var lst = (
                from p in _context.Master_ChicCut_ServiceModel
                join sc in _context.Master_ChicCut_ServiceCategoryModel on p.ServiceCategoryId equals sc.ServiceCategoryId
                where // p.Gender == Gender &&
                p.Actived == true &&
                p.Price > 0
                group p by p.ServiceCategoryId into P_Groupby // nhóm bảng nào  + theo cột nào + ra bảng mới
                orderby(P_Groupby.Key)
                select new Master_ChicCut_ServiceViewModel()
            {
                ServiceCategoryId = P_Groupby.Key,
                MinPrice = P_Groupby.Min(p => p.Price.Value),
                MaxPrice = P_Groupby.Max(p => p.Price.Value),
                ServiceName = _context.Master_ChicCut_ServiceCategoryModel.Where(p => p.ServiceCategoryId == P_Groupby.Key).Select(p => p.ServiceName).FirstOrDefault()
            }
                ).ToList();

            return(PartialView(lst));
        }
Esempio n. 2
0
        //CreateListInner
        public ActionResult _DailyChicCutOrderDetailInnerInfo(List <Daily_ChicCut_Pre_OrderDetailViewModel> details = null, int?ServiceCategoryId = null, int?PreOrderId = null)
        {
            if (details == null)
            {
                details = new List <Daily_ChicCut_Pre_OrderDetailViewModel>();
            }

            /*Kiểm tra xem Danh sách đã có dịch vụ đó chưa :
             + Có rồi: Tăng Qty + Cogs + UnitPrice
             + Chưa có: Thêm mới.
             */
            if (ServiceCategoryId.HasValue)
            {
                var itemExist = details.Where(p => p.ServiceCategoryId == ServiceCategoryId).FirstOrDefault();
                if (itemExist != null)     //Đã có dịch vụ đó
                {
                    var index = details.FindIndex(c => c.ServiceCategoryId == ServiceCategoryId);
                    details[index] = new Daily_ChicCut_Pre_OrderDetailViewModel()
                    {
                        ServiceCategoryId = itemExist.ServiceCategoryId,
                        // COGS = itemExist.COGS,
                        MinPrice = itemExist.MinPrice,
                        MaxPrice = itemExist.MaxPrice,
                        Qty      = itemExist.Qty + 1,
                        // UnitCOGS = itemExist.COGS * (itemExist.Qty + 1),
                        MinUnitPrice = itemExist.MinPrice * (itemExist.Qty + 1),
                        MaxUnitPrice = itemExist.MaxUnitPrice * (itemExist.Qty + 1),
                        ServiceName  = itemExist.ServiceName
                    };
                }
                else //Chưa có dịch vụ đó
                {
                    #region Chưa có dịch vụ đó

                    /* Tính giá vốn
                     * List<int> ProductIdLst = (from QMaster in _context.Master_ChicCut_QuantificationMasterModel
                     *                        join QDetail in _context.Master_ChicCut_QuantificationDetailModel on QMaster.QuantificationMasterId equals QDetail.QuantificationMasterId
                     *                        where QMaster.ServiceId == ServiceId
                     *                        select QDetail.ProductId.Value).ToList();
                     * var LstProductModel = _context.ProductModel.Where(p => ProductIdLst.Contains(p.ProductId)).ToList();
                     * decimal COGSCal = (LstProductModel != null && LstProductModel.Count > 0) ? LstProductModel.Sum(p => p.COGS.HasValue ? p.COGS : 0).Value : 0;
                     */

                    //    from p in _context.Master_ChicCut_ServiceModel
                    //join sc in _context.Master_ChicCut_ServiceCategoryModel on p.ServiceCategoryId equals sc.ServiceCategoryId
                    //where p.Gender == Gender && p.Actived == true && p.Price > 0
                    //group p by p.ServiceCategoryId into P_Groupby // nhóm bảng nào  + theo cột nào + ra bảng mới
                    //orderby (P_Groupby.Key)
                    //select new Master_ChicCut_ServiceViewModel()
                    //{
                    //    ServiceCategoryId = P_Groupby.Key,
                    //    MinPrice = P_Groupby.Min(p => p.Price.Value),
                    //    MaxPrice = P_Groupby.Max(p => p.Price.Value),
                    //    ServiceName = _context.Master_ChicCut_ServiceCategoryModel.Where(p => p.ServiceCategoryId == P_Groupby.Key).Select(p => p.ServiceName).FirstOrDefault()
                    //}

                    var item = (
                        from p in _context.Master_ChicCut_ServiceModel
                        join sc in _context.Master_ChicCut_ServiceCategoryModel on p.ServiceCategoryId equals sc.ServiceCategoryId
                        where p.Actived == true && p.Price > 0 && p.ServiceCategoryId == ServiceCategoryId
                        group p by p.ServiceCategoryId into P_Groupby // nhóm bảng nào  + theo cột nào + ra bảng mới
                        select new Daily_ChicCut_Pre_OrderDetailViewModel()
                    {
                        ServiceCategoryId = P_Groupby.Key,
                        //COGS = 0,
                        MinPrice = P_Groupby.Min(p => p.Price.Value),
                        MaxPrice = P_Groupby.Max(p => p.Price.Value),
                        Qty = 1,
                        ServiceName = _context.Master_ChicCut_ServiceCategoryModel.Where(p => p.ServiceCategoryId == P_Groupby.Key).Select(p => p.ServiceName).FirstOrDefault(),
                        MinUnitPrice = P_Groupby.Min(p => p.Price.Value),
                        MaxUnitPrice = P_Groupby.Max(p => p.Price.Value)
                    }).FirstOrDefault();
                    details.Add(item);
                    #endregion
                }
                if (PreOrderId.HasValue && PreOrderId.Value > 0)//Sửa đơn hàng: + Chưa có dịch vụ đó: Thêm mới
                {
                    //              + Có rồi: Update Qty, TT, Vốn, Sum..
                    #region //Sửa đơn hàng:
                    using (TransactionScope ts = new TransactionScope())
                    {
                        var itemOrderDetailModel = _context.Daily_ChicCut_Pre_OrderDetailModel.Where(p => p.ServiceCategoryId == ServiceCategoryId && p.PreOrderId == PreOrderId).FirstOrDefault();
                        if (itemOrderDetailModel != null) // Update
                        {
                            //itemOrderDetailModel.COGS = itemOrderDetailModel.COGS;
                            //itemOrderDetailModel.UnitCOGS = itemOrderDetailModel.COGS * (itemOrderDetailModel.Qty + 1);
                            itemOrderDetailModel.MinUnitPrice = itemExist.MinPrice * (itemExist.Qty + 1);
                            itemOrderDetailModel.MaxUnitPrice = itemExist.MaxUnitPrice * (itemExist.Qty + 1);
                            itemOrderDetailModel.Qty++;
                            _context.Entry(itemOrderDetailModel).State = System.Data.Entity.EntityState.Modified;
                            _context.SaveChanges();
                        }
                        else // Chưa có
                        {
                            #region Thêm mới
                            /* Tính giá vốn  */
                            //List<int> ProductIdLst = (from QMaster in _context.Master_ChicCut_QuantificationMasterModel
                            //                          join QDetail in _context.Master_ChicCut_QuantificationDetailModel on QMaster.QuantificationMasterId equals QDetail.QuantificationMasterId
                            //                          where QMaster.ServiceId == ServiceId
                            //                          select QDetail.ProductId.Value).ToList();
                            //var LstProductModel = _context.ProductModel.Where(p => ProductIdLst.Contains(p.ProductId)).ToList();
                            //decimal COGSCal = (LstProductModel != null && LstProductModel.Count > 0) ? LstProductModel.Sum(p => p.COGS.HasValue ? p.COGS : 0).Value : 0;
                            var ServiceLstModel = _context.Master_ChicCut_ServiceModel.Where(p => p.ServiceCategoryId == ServiceCategoryId).ToList();

                            var itemAdd = new Daily_ChicCut_Pre_OrderDetailModel()
                            {
                                PreOrderId        = PreOrderId,
                                ServiceCategoryId = ServiceLstModel.Select(p => p.ServiceCategoryId).FirstOrDefault(),
                                // COGS = itemExist.COGS,
                                MinPrice = ServiceLstModel.Where(p => p.Price > 0).Min(p => p.Price),
                                MaxPrice = ServiceLstModel.Where(p => p.Price > 0).Max(p => p.Price),
                                Qty      = 1,
                                // UnitCOGS = itemExist.COGS * (itemExist.Qty + 1),
                                MinUnitPrice = ServiceLstModel.Where(p => p.Price > 0).Min(p => p.Price),
                                MaxUnitPrice = ServiceLstModel.Where(p => p.Price > 0).Max(p => p.Price),
                            };

                            _context.Entry(itemAdd).State = System.Data.Entity.EntityState.Added;
                            _context.SaveChanges();
                            #endregion
                        }
                        var model = _context.Daily_ChicCut_Pre_OrderModel.Where(p => p.PreOrderId == PreOrderId).FirstOrDefault();
                        if (model != null)// Cập nhật Master
                        {
                            var lstDetail = model.Daily_ChicCut_Pre_OrderDetailModel.ToList();
                            //model.SumCOGSOfOrderDetail = lstDetail.Sum(p => p.UnitCOGS.HasValue ? p.UnitCOGS.Value : 0);
                            model.MinSumPriceOfOrderDetail = lstDetail.Sum(p => p.MinUnitPrice.HasValue ? p.MinUnitPrice.Value : 0);
                            model.MaxSumPriceOfOrderDetail = lstDetail.Sum(p => p.MaxUnitPrice.HasValue ? p.MaxUnitPrice.Value : 0);
                            model.MinTotalBillDiscount     = model.BillDiscount.HasValue ? ((model.BillDiscountTypeId == 1 ? model.BillDiscount : (model.BillDiscount / 100) * lstDetail.Sum(p => p.MinUnitPrice.HasValue ? p.MinUnitPrice.Value : 0))) : 0;
                            model.MaxTotalBillDiscount     = model.BillDiscount.HasValue ? ((model.BillDiscountTypeId == 1 ? model.BillDiscount : (model.BillDiscount / 100) * lstDetail.Sum(p => p.MaxUnitPrice.HasValue ? p.MaxUnitPrice.Value : 0))) : 0;
                            model.MinTotal = model.MinSumPriceOfOrderDetail - model.MinTotalBillDiscount;
                            model.MaxTotal = model.MaxSumPriceOfOrderDetail - model.MaxTotalBillDiscount;
                            _context.Entry(model).State = System.Data.Entity.EntityState.Modified;
                            _context.SaveChanges();
                            ts.Complete();
                        }
                    }
                    #endregion
                }
            }


            return(PartialView(details));
        }