public ActionResult MyOrders(SaleOrderModel objmodel)
        {
            LoginModel MdUser = Services.GetLoginWebUser(this.ControllerContext.HttpContext, _JwtTokenManager);
            if (MdUser.Id != 0)
            {
                objmodel.UserId = Convert.ToInt64(MdUser.Id);
            }
            else
            {
                //return JavaScript("window.alert('Please Log-In');");
                return RedirectToAction("Index", "WebLogin");
            }
            var _request = JsonConvert.SerializeObject(objmodel);
            ResponseModel ObjResponse = CommonFile.GetApiResponse(Constant.ApiGetOrders, _request);
            var Orders = JsonConvert.DeserializeObject<List<SaleOrderModel>>(ObjResponse.Response);

            foreach (var orders in Orders)
            {
                TimeSpan time = new TimeSpan(12, 30, 00);
                DateTime date = orders.OrderDate.Add(time);

                var b = date.ToString("dd-MM-yyyy hh:mm tt");

                orders.OrderDatestring = b;


            }
            ViewBag.MyOrders = Orders;
            return View(objmodel);
        }
Beispiel #2
0
        /// <summary>
        /// 处理销售单
        /// </summary>
        /// <param name="index">销售单的当前索引Id,用于生产SaleId</param>
        /// <param name="order">原始订单</param>
        /// <param name="sectionId">专柜Id</param>
        /// <param name="details">销售单清单</param>
        /// <returns>销售单</returns>
        protected virtual SaleOrderModel ProcessSaleOrder(int index, OrderModel order, int sectionId, IList <OPC_SaleDetail> details)
        {
            var saleOrderNo = GenerateSaleId(order.OrderNo, index);

            // 设置销售详情各项的SaleOrderNo
            //增加计算销售单总金额
            foreach (var detail in details)
            {
                detail.SaleOrderNo = saleOrderNo;
            }

            var result = new SaleOrderModel(details)
            {
                OrderNo     = order.OrderNo,
                SaleOrderNo = saleOrderNo,
                Status      = SystemDefine.SaleOrderDefaultStatus,
                SellDate    = order.CreateDate,
                SalesAmount = details.Sum(c => c.Price * c.SaleCount),
                SalesCount  = details.Sum(c => c.SaleCount),
                SectionId   = sectionId,
                CreatedDate = DateTime.Now,
                CreatedUser = SystemDefine.SysUserId
            };

            return(result);
        }
Beispiel #3
0
        private void Print(SaleOrderModel model)
        {
            IPosPrinter _printService = new DriverPrinterService();
            var         billTemplate  = ReplaceBill(model);

            _printService.Print(billTemplate);
        }
Beispiel #4
0
        public ResponseModel GetOrders(SaleOrderModel objModel)
        {
            var _result = _instance.GetOrders(objModel);

            return(new ResponseModel()
            {
                Response = JsonConvert.SerializeObject(_result), Success = true
            });
        }
Beispiel #5
0
        public ResponseModel SaveOrders(SaleOrderModel objModel)

        {
            var _result = _instance.SaveOrders(objModel);

            return(new ResponseModel()
            {
                Response = _result.Response, Success = _result.Success.Value
            });
        }
Beispiel #6
0
        public IHttpActionResult GetOrders(RequestModel requestModel)
        {
            var            data = requestModel.Data;
            SaleOrderModel objSaleOrderModel = JsonConvert.DeserializeObject <SaleOrderModel>(data);
            var            sendResponse      = new ResponseModel()
            {
                Response = JsonConvert.SerializeObject(userServices.GetOrders(objSaleOrderModel)), Success = true
            };
            var sendJson = Json(sendResponse);

            return(sendJson);
        }
Beispiel #7
0
        private string ReplaceBill(SaleOrderModel model)
        {
            // var store = _db.Stores.FirstOrDefault(n => n.Id == model.StoreId);
            //打印模板
            string posTemplate = FileHelper.ReadText(_BLLTemplate);

            if (string.IsNullOrEmpty(posTemplate))
            {
                throw new Exception("小票模板为空");
            }
            posTemplate = posTemplate.ToLower();
            var lineLocation = posTemplate.LastIndexOf("##itemtemplate##");
            //分离商品item模板
            string billTemplate = posTemplate.ToLower().Substring(0, lineLocation);
            var    itemStr      = posTemplate.Substring(lineLocation);
            var    len          = itemStr.IndexOf("{"); //去掉 ##itemtemplate## 以及换行符 从{{productname}}
            string itemTemplate = itemStr.Substring(len);

            //开始替换
            billTemplate = billTemplate.Replace("{{storename}}", "门店名");
            billTemplate = billTemplate.Replace("{{createdate}}", model.CreatedOn.ToString("yyyy-MM-dd HH:mm:ss"));
            billTemplate = billTemplate.Replace("{{ordercode}}", model.Code);
            billTemplate = billTemplate.Replace("{{createdby}}", model.CreatedBy.ToString());
            billTemplate = billTemplate.Replace("{{status}}", model.Status);
            //明细
            string productItems = "";

            foreach (var item in model.Items)
            {
                string tempItem = itemTemplate;
                tempItem = tempItem.Replace("{{productname}}", item.ProductName);
                tempItem = tempItem.Replace("{{productcode}}", item.ProductCode);
                tempItem = tempItem.Replace("{{price}}", item.RealPrice.ToString("F2"));
                tempItem = tempItem.Replace("{{quantity}}", item.Quantity.ToString());
                decimal amount = item.RealPrice * item.Quantity;
                tempItem      = tempItem.Replace("{{amount}}", amount.ToString("F2"));
                productItems += tempItem;;
            }
            billTemplate = billTemplate.Replace("{{items}}", productItems);
            //应收应付
            billTemplate = billTemplate.Replace("{{orderamount}}", model.OrderAmount.ToString("F2"));
            billTemplate = billTemplate.Replace("{{quantitytotal}}", model.GetQuantityTotal().ToString());
            billTemplate = billTemplate.Replace("{{discountamount}}", model.GetTotalDiscountAmount().ToString("F2"));
            billTemplate = billTemplate.Replace("{{payamount}}", model.PayAmount.ToString("F2"));
            billTemplate = billTemplate.Replace("{{chargeamount}}", model.GetChargeAmount().ToString("F2"));
            billTemplate = billTemplate.Replace("{{paymentway}}", model.PaymentWay);
            billTemplate = billTemplate.Replace("{{onlinepayamount}}", model.OnlinePayAmount.ToString("F2"));
            return(billTemplate);
        }
Beispiel #8
0
        public IHttpActionResult SaveOrders(RequestModel requestModel)

        {
            var data = requestModel.Data;

            SaleOrderModel objSaleOrder = JsonConvert.DeserializeObject <SaleOrderModel>(data);

            //var xmlNode = JsonConvert.DeserializeXmlNode(data.ToString(), "root").OuterXml;

            var sendResponse = new ResponseModel()
            {
                Response = JsonConvert.SerializeObject(userServices.SaveOrders(objSaleOrder)), Success = true
            };

            var sendJson = Json(sendResponse);

            return(sendJson);
        }
        public SaleOrderModel GetLastPlacedOrder()
        {
            LoginModel     MdUser   = Services.GetLoginWebUser(this.ControllerContext.HttpContext, _JwtTokenManager);
            SaleOrderModel objmodel = new SaleOrderModel();

            objmodel.UserId = MdUser.Id;
            var           _request    = JsonConvert.SerializeObject(objmodel);
            ResponseModel ObjResponse = CommonFile.GetApiResponse(Constant.ApiGetOrders, _request);
            var           Orders      = JsonConvert.DeserializeObject <List <SaleOrderModel> >(ObjResponse.Response);

            objmodel.OrderNo     = Orders.First().OrderNo;
            objmodel.SaleOrderId = Orders.First().Id;
            var           _secondrequest    = JsonConvert.SerializeObject(objmodel);
            ResponseModel ObjSecondResponse = CommonFile.GetApiResponse(Constant.ApiGetOrders, _secondrequest);

            ViewBag.OrderDetails = JsonConvert.DeserializeObject <List <SaleOrderModel> >(ObjSecondResponse.Response);
            return(objmodel);
        }
        public ActionResult OrderDetails(string Id)
        {
            long id = Convert.ToInt64(CommonFile.Decode(Id));
            SaleOrderModel objmodel = new SaleOrderModel();
            LoginModel MdUser = Services.GetLoginWebUser(this.ControllerContext.HttpContext, _JwtTokenManager);
            if (MdUser.EmailId != null)
            {
                if (MdUser.Id != 0)
                {
                    objmodel.UserId = Convert.ToInt64(MdUser.Id);
                }
                objmodel.SaleOrderId = id;
                objmodel.Id = id;
                var _request = JsonConvert.SerializeObject(objmodel);
                ResponseModel ObjResponse = CommonFile.GetApiResponse(Constant.ApiGetOrders, _request);
                var Orderdetails = JsonConvert.DeserializeObject<List<SaleOrderModel>>(ObjResponse.Response);

                decimal TotalAmount = 0;
                List<SaleOrderModel> Locallist = new List<SaleOrderModel>();
                foreach (var orders in Orderdetails)
                {
                    TotalAmount = +(orders.Amount * Convert.ToInt32(orders.Quantity)) + (TotalAmount);
                    orders.IProductsTotal = (orders.Amount * Convert.ToInt32(orders.Quantity));
                    Locallist.Add(orders);
                }
                if (TotalAmount >= 500)
                {
                    ViewBag.charges = 0;
                }
                else
                {
                    ViewBag.charges = 50;
                }
                ViewBag.TotalAmount = TotalAmount;
                ViewBag.Orderdetails = Locallist;


                return View(objmodel);
            }
            else
            {
                return RedirectToAction("Index", "WebLogin");
            }
        }
        public JsonResult PlaceOrder(long AddressId, string PaymentMode)
        {
            LoginModel            MdUser        = Services.GetLoginWebUser(this.ControllerContext.HttpContext, _JwtTokenManager);
            SaleOrderModel        objModel      = new SaleOrderModel();
            List <AddToCartModel> ListAddToCart = Services.GetMyCart(this.ControllerContext.HttpContext, _JwtTokenManager);

            objModel             = GetSaleOrderValues(ListAddToCart, PaymentMode);
            objModel.Operation   = "insert";
            objModel.PaymentMode = PaymentMode;
            objModel.UserId      = MdUser.Id;
            var           _request    = JsonConvert.SerializeObject(objModel);
            ResponseModel ObjResponse = CommonFile.GetApiResponse(Constant.ApiSaveOrders, _request);

            if (ObjResponse.Response.Equals("Order Saved"))
            {
                var _newrequest = JsonConvert.SerializeObject(objModel);
                var Orders      = CommonFile.GetApiResponse(Constant.ApiGetOrders, _newrequest);
                Services.RemoveCookie(this.ControllerContext.HttpContext, "addtocart");
            }
            String Response = "[{\"Response\":\"" + ObjResponse.Response + "\"}]";

            return(Json(Response));
        }
        private SaleOrderModel GetSaleOrderValues(List <AddToCartModel> ListCart, string PaymentMode)
        {
            decimal TotalAmount   = 0;
            decimal TotalDiscount = 0;

            for (int i = 0; i < ListCart.Count; i++)
            {
                TotalAmount   += ListCart[i].Amount;
                TotalDiscount += ListCart[i].Discount;
            }
            SaleOrderModel objModel = new SaleOrderModel();

            if (PaymentMode != "Pick Up Order")
            {
                if (TotalAmount <= 500)
                {
                    TotalAmount += 50;
                }
            }
            objModel.TotalAmount        = TotalAmount;
            objModel.TotalDiscount      = TotalDiscount;
            objModel.XmlSaleOrderDetail = ListToXml(ListCart);
            return(objModel);
        }
        /// <summary>
        /// 分页查找销售单列表
        /// </summary>
        /// <param name="filter"></param>
        /// <returns></returns>
        public PagedQueryResult <SaleOrderModel> FindList(PagedQueryFilter filter)
        {
            var result    = SaleOrderRepository.FindPaged <SaleOrder>(filter);
            var modelList = new List <SaleOrderModel>();
            var response  = new PagedQueryResult <SaleOrderModel>();

            foreach (var item in result.Data)
            {
                item.Customer = CustomerService.Get(item.CustomerId);
                item.SaleBy   = EmployeeService.Get(item.SaleById);

                var model = new SaleOrderModel
                {
                    Id               = item.Id,
                    Code             = item.Code,
                    Amount           = item.Amount,
                    CustomerName     = item.Customer == null ? string.Empty : item.Customer.Name,
                    OutboundOn       = item.OutboundOn,
                    Remark           = item.Remark,
                    SaleByName       = item.SaleBy == null ? string.Empty : item.SaleBy.Name,
                    SaleOn           = item.SaleOn,
                    SettlementAmount = item.SettlementAmount,
                    SettlementOn     = item.SettlementOn,
                    SettlementStatus = item.SettlementStatus,
                    Status           = item.Status,
                };
                modelList.Add(model);
            }
            response.Data       = modelList;
            response.PageIndex  = result.PageIndex;
            response.PageSize   = result.PageSize;
            response.TotalCount = result.TotalCount;
            response.TotalPage  = result.TotalPage;

            return(response);
        }
        public IActionResult SaleCoin(SaleOrderModel model)
        {
            using (var context = new MyAngularAppContext())
            {
                var saleData    = context.BuyOrder.Where(x => x.Rate <= model.Rate).ToList();
                var totalCoin   = model.Coin;
                var coinTosale  = 0;
                var isCompleted = false;
                foreach (var item in saleData)
                {
                    if (item.Coin <= (totalCoin - coinTosale))
                    {
                        Transaction objTransaction = new Transaction();
                        objTransaction.UserId              = 1;
                        objTransaction.TransactionType     = 2;
                        objTransaction.SaleUserId          = item.UserId;
                        objTransaction.TransactionDateTime = DateTime.Now;
                        objTransaction.Coin = item.Coin;
                        objTransaction.Rate = item.Rate;
                        context.Transaction.Add(objTransaction);
                        context.SaveChanges();
                        coinTosale += (int)objTransaction.Coin;

                        var buyCoin = context.BuyOrder.Find(item.OrderId);
                        if (buyCoin != null)
                        {
                            var remaining_coin = buyCoin.Coin - objTransaction.Coin;
                            if (remaining_coin <= 0)
                            {
                                context.BuyOrder.Remove(buyCoin);
                            }
                            else
                            {
                                buyCoin.Coin = remaining_coin;
                            }

                            context.SaveChanges();
                        }
                    }
                    else
                    {
                        Transaction objTransaction = new Transaction();
                        objTransaction.UserId              = 1;
                        objTransaction.TransactionType     = 1;
                        objTransaction.SaleUserId          = item.UserId;
                        objTransaction.TransactionDateTime = DateTime.Now;
                        objTransaction.Coin = (totalCoin - coinTosale);
                        objTransaction.Rate = model.Rate;
                        context.Transaction.Add(objTransaction);
                        context.SaveChanges();
                        coinTosale += (int)objTransaction.Coin;

                        var buyCoin = context.BuyOrder.Find(item.OrderId);
                        if (buyCoin != null)
                        {
                            var remaining_coin = buyCoin.Coin - objTransaction.Coin;
                            if (remaining_coin <= 0)
                            {
                                context.BuyOrder.Remove(buyCoin);
                            }
                            else
                            {
                                buyCoin.Coin = remaining_coin;
                            }

                            context.SaveChanges();
                        }
                    }

                    if (totalCoin == coinTosale)
                    {
                        isCompleted = true;
                        break;
                    }
                }

                if (!isCompleted)
                {
                    SaleOrder objSaleOrder = new SaleOrder();
                    objSaleOrder.Coin   = (totalCoin - coinTosale);
                    objSaleOrder.Rate   = model.Rate;
                    objSaleOrder.UserId = 1;
                    context.SaleOrder.Add(objSaleOrder);
                    context.SaveChanges();
                }
                return(this.Ok(ApiResponse.SetResponse(ApiResponseStatus.Ok, "Order Placed Successfully ", null)));
            }


            //using (var context = new MyAngularAppContext())
            //{
            //    SaleOrder objSaleOrder=new SaleOrder();
            //    objSaleOrder.Coin = model.Coin;
            //    objSaleOrder.Rate = model.Rate;
            //    objSaleOrder.UserId = 1;
            //    context.SaleOrder.Add(objSaleOrder);
            //    context.SaveChanges();
            //    return this.Ok(ApiResponse.SetResponse(ApiResponseStatus.Ok, "Order Placed Successfully ", null));
            //}
        }
Beispiel #15
0
        public SaveOrders_Result SaveOrders(SaleOrderModel objModel)

        {
            return(Context.SaveOrders(objModel.UserId, objModel.TotalDiscount, objModel.TotalAmount, objModel.PaymentMode, objModel.XmlSaleOrderDetail, objModel.Operation, objModel.SaleOrderId).FirstOrDefault());
        }
        public ActionResult GetCoupon(string CouponCode)
        {
            CouponModel ObjCouponModel = new CouponModel();
            LoginModel  MdUser         = Services.GetLoginWebUser(this.ControllerContext.HttpContext, _JwtTokenManager);

            if (MdUser.Id != 0)
            {
                ObjCouponModel.UserId = Convert.ToInt64(MdUser.Id);
            }
            ObjCouponModel.CouponCode = CouponCode;
            var           _request       = JsonConvert.SerializeObject(ObjCouponModel);
            ResponseModel ObjResponse    = CommonFile.GetApiResponse(Constant.ApiGetCoupon, _request);
            var           ObjResponse1   = JsonConvert.DeserializeObject <List <ResponseModel> >(ObjResponse.Response);
            var           couponresponse = ObjResponse1[0].Response.ToString();

            if (couponresponse.Equals("already used"))
            {
                ViewBag.CouponResponse = "Coupon already used";
                return(JavaScript("swal('coupon already used')"));
            }
            if (couponresponse.Equals("coupon expired"))
            {
                ViewBag.CouponResponse = "coupon expired";
                return(JavaScript("swal('Coupon Expired')"));
            }
            if (couponresponse.Equals("coupon does not exist"))
            {
                ViewBag.CouponResponse = "coupon does not exist";
                return(JavaScript("swal('Coupon does not exist')"));
            }
            else
            {
                if (iscouponapplied == false)
                {
                    string[] ArrResponse = couponresponse.Split(',');
                    if (ArrResponse[3] == "Discount")                   //if coupon type is "discount"
                    {
                        ViewBag.CouponResponse = ArrResponse[6];
                        AddToCart objAddToCart = new AddToCart();
                        var       totalamount  = objAddToCart.GetTotalAmountCheckOut(this.ControllerContext.HttpContext);
                        if (totalamount < Convert.ToInt64(ArrResponse[4]))
                        {
                            return(JavaScript("swal('Cart value is not sufficient')"));
                        }
                        ViewBag.TotalAmount = totalamount - Convert.ToInt64(ArrResponse[2]);
                        if (ViewBag.TotalAmount <= Constant.MinimumAmountForFreeDelivery)
                        {
                            ViewBag.TotalAmount            += Constant.ShippingCharges;    //Adding shipping/delivery charges
                            ViewBag.TotalAmount            -= (2 * (ViewBag.TotalAmount)); //making the total negative for handling it securely in client side
                            ViewBag.TotalAmountAfterCharges = ViewBag.TotalAmount;
                        }
                        totalamount = ViewBag.TotalAmount;
                        SaleOrderModel objmodel = new SaleOrderModel();
                        objmodel.TotalAmount           = totalamount;
                        ObjCouponModel.IsCouponApplied = true;
                        iscouponapplied          = true;
                        objmodel.IsCouponApplied = true;
                        return(Json(ViewBag.TotalAmount));
                    }
                    else if (ArrResponse[3] == "BOGO")        //Condition for Coupon Type=="BOGO" (Buy One Get One)
                    {
                        return(JavaScript("swal('Coupon does not exist')"));
                    }
                    return(JavaScript("swal('Error')"));
                }
                return(JavaScript("swal('Error')"));
            }
        }
Beispiel #17
0
        public IEnumerable <GetOrders_Result> GetOrders(SaleOrderModel objModel)

        {
            return(Context.GetOrders(objModel.UserId, objModel.SaleOrderId, objModel.ProductId).ToList());
        }