//[OutputCache(Duration = 3600, VaryByParam = "code,v")]
        public ActionResult GetPrice(int?code, string v)
        {
            Tax_Rate t = new Tax_Rate {
                id = 1, rate = 10, type = 2
            };
            //var product = ProductsList.FirstOrDefault(x => x.Id == code);

            var allPosItems = _posItemService.GetAllInclude("StockItem").ToList();

            var availableItemsId = allPosItems.Where(x => x.Remaining > 0 && x.DistributionPointId == DistributionPointId).Select(x => x.ItemId).ToList();

            var product = ProductsList.FirstOrDefault(x => x.Id == code && availableItemsId.Contains((int)x.Id));

            if (product == null)
            {
                product = new POSService.Entities.StockItem();
                product.TotalQuantity = 0;
            }
            else
            {
                var posItem = allPosItems.FirstOrDefault(x => x.ItemId == code.Value);
                product.TotalQuantity = posItem.Remaining;
            }



            return(Json(new
            {
                price = decimal.Zero,
                name = product.StockItemName,
                code = product.Id.ToString(),
                tax_rate = t,
                available = product.TotalQuantity
            }, JsonRequestBehavior.AllowGet));
        }
        public ActionResult GetProductCount(int?product_id)
        {
            var allPosItems = _posItemService.GetAllInclude("StockItem").ToList();

            var availableItemsId = allPosItems.Where(x => x.Remaining > 0 && x.DistributionPointId == DistributionPointId).Select(x => x.ItemId).ToList();

            var product = ProductsList.FirstOrDefault(x => x.Id == product_id && availableItemsId.Contains((int)x.Id));

            if (product == null)
            {
                product = new POSService.Entities.StockItem();
                product.TotalQuantity = 0;
            }
            else
            {
                var posItem = allPosItems.FirstOrDefault(x => x.ItemId == product_id.Value);
                product = new POSService.Entities.StockItem();
                product.TotalQuantity = posItem.Remaining;
            }

            return(Json(new
            {
                Remainder = product.TotalQuantity
            }, JsonRequestBehavior.AllowGet));
        }
 private void ProductInventoryUpdated(object sender, ProductInventoryUpdatedEventArgs e)
 {
     if (e != null)
     {
         var product = ProductsList.FirstOrDefault(x => x.ProductId == e.ProductId);
         product.Quantity = e.Quantity;
     }
 }
        public ActionResult GetItemByBarCode(string csrf_sma, string code)
        {
            Tax_Rate t = new Tax_Rate {
                id = 1, rate = 10, type = 2
            };
            var product = ProductsList.FirstOrDefault(x => x.Barcode == code);

            return(Json(new
            {
                item_price = product.UnitPrice,
                product_name = product.StockItemName,
                product_code = product.Id.ToString(),
                tax_rate = t
            }, JsonRequestBehavior.AllowGet));
        }
        public ActionResult CheckIn(string suspend)
        {
            if (!string.IsNullOrEmpty(suspend))
            {
                return(new JsonResult());
            }

            int count       = 0;
            int guestId     = 0;
            int guestRoomId = 0;

            int paymentMethodId = 1;

            int.TryParse(Request.Form["rpaidby"], out paymentMethodId);

            var rpaidby = Request.Form["rpaidby"].ToString();

            paymentMethodId = GetPaymentMethod(rpaidby.ToUpper());


            var cc_no_val     = Request.Form["cc_no_val"].ToString();
            var cc_holder_val = Request.Form["cc_holder_val"].ToString();
            var cheque_no_val = Request.Form["cheque_no_val"].ToString();

            var paymentMethodNote = cc_no_val + " " + cc_holder_val + " " + cheque_no_val;

            int.TryParse(Request.Form["count"], out count);
            int.TryParse(Request.Form["HotelGuestId"], out guestId);
            int.TryParse(Request.Form["GuestRoomId"], out guestRoomId);

            List <POSService.Entities.StockItem> lst = new List <POSService.Entities.StockItem>();

            if (paymentMethodId == (int)PaymentMethodEnum.POSTBILL && guestId == 0)
            {
                return(Content(@"<script language='javascript' type='text/javascript'>
                alert('You cannot post a bill for a customer who is not staying in the hotel! Please go back and select a guest!');
                $(this).location = 'POS/Index';
                </script>"));
            }

            var totalBill = Decimal.Zero;

            for (int i = 1; i < count; i++)
            {
                string p  = "product" + i.ToString();
                string q  = "quantity" + i.ToString();
                string pr = "price" + i.ToString();

                int     productId = 0;
                int     qty       = 0;
                decimal price     = decimal.Zero;

                int.TryParse(Request.Form[p], out productId);
                int.TryParse(Request.Form[q], out qty);
                decimal.TryParse(Request.Form[pr], out price);

                if (productId == 0)
                {
                    break;
                }

                totalBill += (price * qty);

                var itemDescription = ProductsList.FirstOrDefault(x => x.Id == productId).StockItemName;

                lst.Add(new POSService.Entities.StockItem {
                    Id = productId, Quantity = qty, UnitPrice = price, Description = itemDescription
                });
            }

            //Save Item To Database

            var conn = ConfigurationManager.ConnectionStrings[1].ConnectionString;

            var ticks = (int)DateTime.Now.Ticks;

            var transactionId = _personService.GetAllForLogin().FirstOrDefault(x => x.Username.ToUpper().Equals(User.Identity.Name.ToUpper())).PersonID;

            var cl = HttpContext.GetCourseListCookie("FrontOfficeTerminal");

            var terminal = "Terminal";

            if (!string.IsNullOrEmpty(cl.FirstOrDefault()))
            {
                terminal = cl.FirstOrDefault();
            }

            int terminalId = GetFrontOfficeTerminalId(terminal);

            var timeOfSale = DateTime.Now;

            //if (guestId > 0)
            StockItemService.UpdateSalesHouseKeeping(lst, transactionId, guestId, Person.PersonID, 1, guestRoomId, conn, paymentMethodId, paymentMethodNote, timeOfSale, DistributionPointId, terminalId);

            double dTotal = 0;

            double.TryParse(totalBill.ToString(), out dTotal);

            try
            {
                PrintReceipt(lst, dTotal, 0, 0);
            }
            catch
            {
            }

            return(RedirectToAction("Index"));
        }