public ActionResult AddOrder(OrderAgencyModel data) { var order = new Shop_Orders { AgencyId = AgencyId }; var datenow = DateTime.Now.TotalSeconds(); var lst = _da.GetListImportProductBarcode(data.BarCodes, AgencyId); var lstDetail = lst.Select(item => new Shop_Order_Details { Barcode = item.BarCode, Quantity = 1, QuantityOld = 0, Price = item.Price, TotalPrice = item.PriceNew, Total = item.PriceNew, Discount = 0, DateCreated = datenow, Status = (int)FDI.CORE.OrderStatus.Complete, Value = item.Value, GID = Guid.NewGuid(), ImportProductGID = item.GID, ProductID = item.ProductValueID }).ToList(); if (!lstDetail.Any()) { return(Json(new JsonMessage(true, "Không tồn tại mã sản phẩm"), JsonRequestBehavior.AllowGet)); } var total = lstDetail.Sum(c => c.Total); var totalprice = lstDetail.Sum(c => c.TotalPrice); order.Shop_Order_Details = lstDetail; order.TotalSaleSP = 0; order.DateCreated = datenow; order.Status = (int)FDI.CORE.OrderStatus.Complete; order.IsDelete = false; order.StartDate = datenow; order.Total = total; order.TotalPrice = totalprice; order.CustomerID = data.CustomerId; order.Payments = order.TotalPrice; order.PriceReceipt = order.Payments; order.Type = (int)TypeOrder.Banle; order.ContactOrderID = data.OrderId; order.ReceiveDate = DateTime.Now.TotalSeconds(); _ordersDa.Add(order); _ordersDa.Save(); if (data.OrderId > 0) { var contact = _cusAppSaleDa.GetByID(data.OrderId.Value); contact.Status = (int)FDI.CORE.OrderStatus.Complete; } return(Json(new JsonMessage(false, ""), JsonRequestBehavior.AllowGet)); }
public ActionResult Actions() { var msg = new JsonMessage(); var order = new Shop_Orders(); switch (DoAction) { case ActionType.Add: var dateCreated = DateTime.Now.TotalSeconds(); var keyorder = Request["KeyOrder"]; var lstOrder = (List <ModelWholeSaleItem>)Session["WholeSale"] ?? new List <ModelWholeSaleItem>(); var temp = _freightWarehouseDa.GetByKey(Guid.Parse(keyorder)); if (temp.IsOrder == true) { msg = new JsonMessage { Erros = true, Message = "Đơn Yêu cầu này đã được tạo đơn hàng" }; return(Json(msg)); } else { if (lstOrder.Any()) { var model = lstOrder.FirstOrDefault(c => c.Key == Guid.Parse(keyorder)); if (model != null) { var lstM = model.WholeSaleItems; var lstDetail = new List <Shop_Order_Details>(); foreach (var saleItem in lstM) { var shopOrderDetails = new Shop_Order_Details { ProductID = saleItem.ProductID, Quantity = saleItem.Quantity, Status = (int)FDI.CORE.OrderStatus.Complete, QuantityOld = 0, IsPromotion = false, Price = saleItem.Price ?? 0, Barcode = saleItem.Barcode, //DateCreated = dateCreated, Percent = saleItem.PercentSale, Value = saleItem.Value, ImportProductGID = saleItem.Idimport, PriceSale = saleItem.PriceSale, Discount = saleItem.Discount, TotalPrice = saleItem.TotalPrice * saleItem.Quantity, Total = saleItem.TotalPrice - saleItem.Discount, }; lstDetail.Add(shopOrderDetails); if (saleItem.PromotionPs != null) { lstDetail.AddRange(from shopOrderDetailse in saleItem.PromotionPs from orderDetailse in shopOrderDetailse.PromotionSPItems select new Shop_Order_Details { ProductID = orderDetailse.ProductID, Quantity = orderDetailse.Quantity, Status = (int)FDI.CORE.OrderStatus.Complete, QuantityOld = 0, Price = orderDetailse.PriceSp ?? 0, Percent = orderDetailse.Percent, PriceSale = orderDetailse.Price, //DateCreated = dateCreated, IsPromotion = true, PromotionProductID = orderDetailse.ID, Discount = orderDetailse.Percent * orderDetailse.Quantity * orderDetailse.PriceSp / 100 + orderDetailse.Price, TotalPrice = orderDetailse.TotalPrice * orderDetailse.Quantity, Total = orderDetailse.TotalPrice * orderDetailse.Quantity - (orderDetailse.Percent * orderDetailse.Quantity * orderDetailse.PriceSp + orderDetailse.Price), ContentPromotion = orderDetailse.Name }); } } var lstO = model.PromotionOrder; if (lstO != null) { lstDetail.AddRange(from itemP in lstO from items in itemP.PromotionSPItems select new Shop_Order_Details { ProductID = items.ProductID, Quantity = items.Quantity, Status = (int)FDI.CORE.OrderStatus.Complete, QuantityOld = 0, Price = items.PriceSp ?? 0, //DateCreated = dateCreated, IsPromotion = true, PromotionProductID = items.ID, Percent = items.Percent, PriceSale = items.Price, Discount = items.PriceSp + (items.PriceSp * items.Percent / 100), TotalPrice = items.TotalPrice * items.Quantity, ContentPromotion = items.Title, Total = (items.TotalPrice - items.PriceSp - (items.PriceSp * items.Percent / 100)) * items.Quantity, }); } if (lstDetail.Any()) { UpdateModel(order); var dateOfSale = Request["DateOfSale_"]; order.StartDate = dateOfSale.StringToDate().TotalSeconds(); order.DateCreated = DateTime.Now.TotalSeconds(); order.TotalPrice = model.Total; order.Total = model.Total; order.Status = (int)FDI.CORE.OrderStatus.Complete; order.IsDelete = false; order.UserId = UserItem.UserId; order.UserCreate = UserItem.UserId; order.AgencyId = UserItem.AgencyID; order.SalePercent = model.SalePercent; order.SalePrice = model.SalePrice; order.Shop_Order_Details = lstDetail; order.Discount = model.Discount ?? 0; var payment = model.Total - (order.PrizeMoney ?? 0) - order.Discount - model.DiscountSale; order.Payments = payment; order.PriceReceipt = order.Payments; if (!string.IsNullOrEmpty(order.Company) && !string.IsNullOrEmpty(order.CodeCompany)) { order.Isinvoice = true; } order.Type = (int)TypeOrder.Banbuon; _ordersDa.Add(order); _ordersDa.Save(); // set trạng thái đơn yêu cầu đã đc đặt hàng temp.IsOrder = true; _freightWarehouseDa.Save(); // xóa key tại session lstOrder.Remove(model); Session["WholeSale"] = lstOrder; } else { msg.Erros = true; msg.Message = "Bạn chưa chọn sản phẩm nào."; } } else { msg.Erros = true; msg.Message = "Không thể tạo đơn hàng."; } } else { msg.Erros = true; msg.Message = "Bạn chưa chọn sản phẩm nào."; } } break; default: msg.Message = "Bạn không được phần quyển cho chức năng này."; msg.Erros = true; break; } return(Json(msg)); }
public ActionResult Actions() { var msg = new JsonMessage(); var order = new Shop_Orders(); switch (DoAction) { case ActionType.Add: var dateCreated = DateTime.Now.TotalSeconds(); var keyorder = Request["KeyOrder"]; var lstOrder = (List <ModelSaleItem>)Session["AddSale"] ?? new List <ModelSaleItem>(); var model = lstOrder.FirstOrDefault(c => c.Key == Guid.Parse(keyorder)); if (model != null) { var lstM = model.SaleItems; var lstDetail = new List <Shop_Order_Details>(); foreach (var saleItem in lstM) { var shopOrderDetails = new Shop_Order_Details { ProductID = saleItem.ProductID, Quantity = saleItem.Quantity, Status = (int)FDI.CORE.OrderStatus.Complete, QuantityOld = 0, IsPromotion = false, Value = saleItem.Value, Price = saleItem.Price, Barcode = saleItem.Barcode, ImportProductGID = saleItem.Idimport, //DateCreated = dateCreated, Percent = saleItem.PercentSale, PriceSale = saleItem.PriceSale, Discount = saleItem.Discount, TotalPrice = saleItem.TotalPrice * saleItem.Quantity, Total = saleItem.TotalPrice - saleItem.Discount, }; lstDetail.Add(shopOrderDetails); if (saleItem.PromotionPs.Any()) { lstDetail.AddRange(from shopOrderDetailse in saleItem.PromotionPs from orderDetailse in shopOrderDetailse.PromotionSPItems select new Shop_Order_Details { ProductID = orderDetailse.ProductID, Quantity = orderDetailse.Quantity, Status = (int)FDI.CORE.OrderStatus.Complete, QuantityOld = 0, Price = orderDetailse.PriceSp ?? 0, Percent = orderDetailse.Percent, PriceSale = orderDetailse.Price, //DateCreated = dateCreated, IsPromotion = true, PromotionProductID = orderDetailse.ID, Discount = orderDetailse.Percent * orderDetailse.Quantity * orderDetailse.PriceSp / 100 + orderDetailse.Price, TotalPrice = orderDetailse.TotalPrice * orderDetailse.Quantity, Total = orderDetailse.TotalPrice * orderDetailse.Quantity - (orderDetailse.Percent * orderDetailse.Quantity * orderDetailse.PriceSp + orderDetailse.Price), ContentPromotion = orderDetailse.Name }); } } var lstO = model.PromotionOrder; lstDetail.AddRange(from itemP in lstO from items in itemP.PromotionSPItems select new Shop_Order_Details { ProductID = items.ProductID, Quantity = items.Quantity, Status = (int)FDI.CORE.OrderStatus.Complete, QuantityOld = 0, Price = items.PriceSp ?? 0, //DateCreated = dateCreated, IsPromotion = true, PromotionProductID = items.ID, Percent = items.Percent, PriceSale = items.Price, Discount = items.PriceSp + (items.PriceSp * items.Percent / 100), TotalPrice = items.TotalPrice * items.Quantity, ContentPromotion = items.Title, Total = (items.TotalPrice - items.PriceSp - (items.PriceSp * items.Percent / 100)) * items.Quantity, }); if (lstDetail.Any()) { UpdateModel(order); var dateOfSale = Request["DateOfSale_"]; order.StartDate = dateOfSale.StringToDate().TotalSeconds(); order.DateCreated = DateTime.Now.TotalSeconds(); order.TotalPrice = model.TotalPrice; order.Total = model.Total; order.Status = (int)FDI.CORE.OrderStatus.Complete; order.IsDelete = false; order.UserId = UserItem.UserId; order.UserCreate = UserItem.UserId; order.AgencyId = UserItem.AgencyID; order.SalePercent = model.SalePercent; order.SalePrice = model.SalePrice; order.Shop_Order_Details = lstDetail; decimal?price = 0; if (!string.IsNullOrEmpty(order.SaleCode)) { var temp = _dnSalesDa.GetSaleCodebyCode(order.SaleCode); temp.IsUse = true; temp.DateUse = DateTime.Now.TotalSeconds(); price = (temp.DN_Sale.Price ?? 0) + ((temp.DN_Sale.Percent ?? 0) * order.TotalPrice / 100); _dnSalesDa.Save(); } order.Discount = model.Discount; var payment = model.Total - (order.PrizeMoney ?? 0) - order.Discount - price ?? 0; order.Payments = payment; order.PriceReceipt = order.Payments; if (!string.IsNullOrEmpty(order.Company) && !string.IsNullOrEmpty(order.CodeCompany)) { order.Isinvoice = true; } _ordersDa.Add(order); _ordersDa.Save(); } else { msg.Erros = true; msg.Message = "Bạn chưa chọn sản phẩm nào."; } } else { msg.Erros = true; msg.Message = "Bạn chưa chọn sản phẩm nào."; } break; default: msg.Message = "Bạn không được phần quyển cho chức năng này."; msg.Erros = true; break; } return(Json(msg)); }
public ActionResult Actions() { var msg = new JsonMessage(); var order = new Shop_Orders(); switch (DoAction) { case ActionType.Add: var dateCreated = DateTime.Now.TotalSeconds(); var keyorder = Request["KeyOrder"]; var lstOrder = (List <ModelWholeSaleOItem>)Session["WholeSaleO"] ?? new List <ModelWholeSaleOItem>(); var temp = _storageWareHouseDa.GetByKey(Guid.Parse(keyorder)); if (lstOrder.Any()) { var model = lstOrder.FirstOrDefault(c => c.Key == Guid.Parse(keyorder)); if (model != null) { var lstM = model.WholeSaleItems; var lstDetail = new List <Shop_Order_Details>(); foreach (var saleItem in lstM) { var lstDetail1 = saleItem.ListDnImportItems.Select(item => new Shop_Order_Details { ProductID = item.ProductID, ProductValueID = item.ProductValueID, Quantity = item.Quantity, Status = (int)FDI.CORE.OrderStatus.Complete, QuantityOld = 0, IsPromotion = false, CateValueID = saleItem.CateValueID, Price = item.Price ?? 0, Barcode = item.Barcode, //DateCreated = dateCreated, Percent = item.PercentSale, Value = item.Value, ImportProductGID = item.Idimport, PriceSale = item.PriceSale, Discount = item.Discount, TotalPrice = item.TotalPrice * item.Quantity, Total = item.Price * item.Quantity * item.Value, }).ToList(); lstDetail.AddRange(lstDetail1); } if (lstDetail.Any()) { UpdateModel(order); var dateOfSale = Request["DateOfSale_"]; order.StartDate = dateOfSale.StringToDate().TotalSeconds(); order.DateCreated = DateTime.Now.TotalSeconds(); order.TotalPrice = model.Total; order.Total = model.Total; order.Status = (int)FDI.CORE.OrderStatus.Complete; order.IsDelete = false; order.UserId = UserItem.UserId; order.UserCreate = UserItem.UserId; order.AgencyId = UserItem.AgencyID; order.SalePercent = model.SalePercent; order.SalePrice = model.SalePrice; order.Shop_Order_Details = lstDetail; order.Discount = model.Discount ?? 0; var payment = model.Total - (order.PrizeMoney ?? 0) - order.Discount - model.DiscountSale; order.Payments = payment; order.PriceReceipt = order.Payments; if (!string.IsNullOrEmpty(order.Company) && !string.IsNullOrEmpty(order.CodeCompany)) { order.Isinvoice = true; } order.Type = (int)TypeOrder.Banbuon; _ordersDa.Add(order); _ordersDa.Save(); // set trạng thái đơn yêu cầu đã đc đặt hàng _storageWareHouseDa.Save(); // xóa key tại session lstOrder.Remove(model); Session["WholeSaleO"] = lstOrder; } } } break; default: msg.Message = "Bạn không được phần quyển cho chức năng này."; msg.Erros = true; break; } return(Json(msg)); }
public ActionResult SendOrder() { var msg = new JsonMessage { Erros = false, Message = "Cảm ơn bạn đã đặt hàng, Chúng tôi sẽ liện hệ với bạn sớm nhất.!" }; try { var codeCookie = HttpContext.Request.Cookies["addtocart"]; if (codeCookie != null) { var temp = codeCookie.Value; var lst = new JavaScriptSerializer().Deserialize <List <ShopProductDetailCartItem> >(temp); var order = new Shop_Orders(); if (lst.Any()) { var listDetail = (from item in lst let product = _productDa.GetProductItem(item.ShopID ?? 0) select new Shop_Order_Details { ProductID = item.ShopID, Quantity = item.Quantity, DateCreated = DateTime.Now.TotalSeconds(), Status = 2, Price = product.PriceNew, }).ToList(); if (listDetail.Any()) { var total = listDetail.Sum(c => c.Price); order.AgencyId = 2010; order.CustomerName = Request["fullname"]; order.Mobile = Request["phone"]; order.Address = Request["address"]; order.Note = Request["ordernote"]; order.DateCreated = DateTime.Now.TotalSeconds(); order.Status = 2; order.Shop_Order_Details = listDetail; order.TotalPrice = total; order.Payments = total; order.IsDelete = false; _ordersDa.Add(order); _ordersDa.Save(); Response.Cookies["addtocart"].Expires = DateTime.Now.AddDays(-1); } else { msg = new JsonMessage { Erros = true, Message = "Giỏ hàng của bạn chưa có sản phẩm nào.!" }; } } else { msg = new JsonMessage { Erros = true, Message = "Giỏ hàng của bạn chưa có sản phẩm nào.!" }; } } else { msg = new JsonMessage { Erros = true, Message = "Giỏ hàng của bạn chưa có sản phẩm nào.!" }; } } catch (Exception) { msg = new JsonMessage { Erros = true, Message = "Có lỗi xảy ra.!" }; } return(Json(msg, JsonRequestBehavior.AllowGet)); }