Exemple #1
0
        public JsonResult RecallTransaction(Cart_Details model)
        {
            JsonResult jsonResult;

            app.bsms.Models.Sales.Cart cart = new app.bsms.Models.Sales.Cart();
            try
            {
                app.bsms.api.Service.Parameters.Clear();
                app.bsms.api.Service.Parameters.Add("siteCode", ((app.bsms.Models.Account.User)base.Session["Login_Details"]).siteCode);
                //app.bsms.api.Service.Parameters.Add("customerCode", model.staffcode);
                app.bsms.api.Service.Parameters.Add("transactionNumber", model.transactionNumber);
                //app.bsms.api.Service.Parameters.Add("userId", ((app.bsms.Models.Account.User)base.Session["Login_Details"]).userID);
                cart.cart = app.bsms.api.Service.Get <Temp_Cart>("postSales");
                if (cart.cart.transactionNumber == null)
                {
                    jsonResult = base.Json(string.Concat("{ \"status\": \"0\", \"message\":\"Are you sure to void this transaction?", "\" }"), JsonRequestBehavior.AllowGet);
                    //return null;
                }
                else
                {
                    jsonResult = base.Json("{ \"status\": \"1\", \"message\":\"" + cart.cart.transactionNumber + "\\" + cart.cart.invoiceNumber + "\" }", JsonRequestBehavior.AllowGet);
                    //jsonResult = base.Json("{ \"status\": \"1\", \"message\":\"\", \"data\":" + (object)JsonConvert.SerializeObject((object)app.bsms.api.Service.Get<app.bsms.Models.Sales.Post.Cart>("itemCart").transactionDetails + " }", JsonRequestBehavior.AllowGet);
                    //return this.Json((object)JsonConvert.SerializeObject((object)cart.cart.transactionDetails), JsonRequestBehavior.AllowGet);
                }
            }
            catch (Exception exception)
            {
                throw exception;
            }
            return(jsonResult);
        }
        public string AddToCart(int id, string email)
        {
            Cart_Details cartD = new Cart_Details();
            Customer     cus   = new Customer();
            Product      prod  = new Product();
            int          cd    = (from c in db.Carts
                                  join cu in db.Customers on c.Customer_ID equals cu.Customer_ID
                                  where cu.Customer_Email == email
                                  select c.Cart_Id).SingleOrDefault();
            int pri = (from p in db.Products
                       where p.Product_Id == id
                       select p.Product_Price).SingleOrDefault();

            string image1 = (from p in db.Products
                             where p.Product_Id == id
                             select p.Product_Image).SingleOrDefault();

            var qty = (from p in db.Products
                       where p.Product_Id == id
                       select p.Product_Ouantity).SingleOrDefault();

            //prod.Product_Ouantity = qty;


            cartD.Cart_Id          = cd;
            cartD.Product_Id       = id;
            cartD.Product_Price    = pri;
            cartD.Product_Quantity = 1;
            cartD.Product_Image    = image1;

            var oldqty = db.Products.Where(x => x.Product_Id == id).SingleOrDefault();

            if (oldqty.Product_Ouantity < cartD.Product_Quantity)
            {
                return("Not in Stock" + "" + oldqty.Product_Ouantity);
            }
            int minusqty;

            minusqty = Convert.ToInt32(qty) - cartD.Product_Quantity;
            oldqty.Product_Ouantity = minusqty;
            db.SaveChanges();



            try
            {
                db.Cart_Details.Add(cartD);
                var res = db.SaveChanges();
                if (res > 0)
                {
                    return(cartD.Cart_Id.ToString());
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return("not saved");
        }
        public async Task <IActionResult> Check_Out_Step_Four(string id)
        {
            ViewBag.TrackingId = id;
            ViewBag.Payments   = await _pay_repo.Get();

            var result = await _shop_repo.Shopping_Cart_Tracking_Get_By_Id(id);

            if (result == null)
            {
                return(RedirectToAction("Index", "ShopingCart"));
            }
            if (result.Shipping_Address_Id == 0)
            {
                return(RedirectToLocal(string.Format("/check-out-2/{0}", id)));
            }
            ViewBag.CartType = result.CartType;
            var obj = new Cart_Details(result);

            obj.TimeStamp  = Utility.GetUnixTime();
            obj.User.Email = Request.HttpContext.User.FindFirst(ClaimTypes.Email)?.Value;
            obj.Billing    = await _addr_repo.Get_By_Id(result.Billing_Address_Id);

            obj.Shipping = obj.Billing;

            obj.CallBackUrl = string.Format("{0}/payment/call-back", Constant.DomainNane);
            obj.SuccessUrl  = string.Format("auto:{0}/payment-success/{1}", Constant.DomainNane, id);
            obj.CanceledUrl = string.Format("auto:{0}/payment-cancelled/{1}", Constant.DomainNane, id);
            obj.DecliendUrl = string.Format("auto:{0}/payment-decliend/{1}", Constant.DomainNane, id);

            obj.Signature       = string.Format("{0}:{1}:{2}:{3}:{4}:{5}:Items:return", Constant.StoreID, obj.Cart.Total_Sum, Constant.Currency, Constant.TelrTestMode, obj.TimeStamp, obj.Cart.Id);
            obj.Signature       = Utility.Get_Hash(obj.Signature, Constant.TelrSecretKey).ToLower();
            obj.ReturnSignature = string.Format("{0}:{1}:{2}:{3}:{4}:{5}:{6}", obj.CallBackUrl, obj.CallBackUrl, obj.CallBackUrl, obj.SuccessUrl, obj.DecliendUrl, obj.CanceledUrl, obj.Signature);
            obj.ReturnSignature = Utility.Get_Hash(obj.ReturnSignature, Constant.TelrSecretKey).ToLower();

            return(View("PaymentRequestPage", obj));
        }
Exemple #4
0
        public ActionResult AddToCart(FormCollection collection)
        {
            ActionResult action;
            decimal      num;
            DateTime?    nullable;
            string       str;
            string       str1;
            string       str2;
            string       str3;

            try
            {
                if (base.ModelState.IsValid && collection["cart_details"] != null)
                {
                    List <Cart_Details> cartDetails = JsonConvert.DeserializeObject <List <Cart_Details> >(Convert.ToString(collection["cart_details"]));
                    if (cartDetails != null)
                    {
                        List <Cart_Details> list = (
                            from f in cartDetails
                            where f.lineType != "TD"
                            //Yoonus
                            group f by new { lineStatus = f.lineStatus, lineType = f.lineType, itemCode = f.itemCode, itemName = f.itemName, referenceTreatmentCode = f.referenceTreatmentCode, isFOC = f.isFOC, referenceTransactionNumber = f.referenceTransactionNumber, topupBalance = f.topupBalance, topupOutstanding = f.topupOutstanding } into f
                            //group f by new { lineStatus = f.lineStatus, lineType = f.lineType, itemCode = f.itemCode, itemName = f.itemName, referenceTreatmentCode = f.referenceTreatmentCode, isFOC = f.isFOC } into f
                            select new Cart_Details()
                        {
                            lineStatus = f.Key.lineStatus,
                            lineType = f.Key.lineType,
                            itemCode = f.Key.itemCode,
                            itemName = f.Key.itemName,
                            itemQty = f.Sum <Cart_Details>((Cart_Details s) => s.itemQty),
                            unitDiscount = f.Sum <Cart_Details>((Cart_Details s) => s.unitDiscount),
                            unitPrice = f.Sum <Cart_Details>((Cart_Details u) => u.unitPrice),
                            promoPrice = (f.Key.isFOC ? decimal.Zero : f.Sum <Cart_Details>((Cart_Details s) => s.itemQty * s.unitPrice) - f.Sum <Cart_Details>((Cart_Details s) => s.unitDiscount)),
                            itemAmount = (f.Key.isFOC ? decimal.Zero : f.Sum <Cart_Details>((Cart_Details s) => s.itemQty * s.unitPrice) - f.Sum <Cart_Details>((Cart_Details s) => s.unitDiscount)),
                            salesAmount = (f.Key.isFOC ? decimal.Zero : f.Sum <Cart_Details>((Cart_Details s) => s.itemQty * s.unitPrice) - f.Sum <Cart_Details>((Cart_Details s) => s.unitDiscount)),
                            referenceTreatmentCode = f.Key.referenceTreatmentCode,
                            //Yoonus
                            referenceTransactionNumber = f.Key.referenceTransactionNumber,
                            topupBalance = f.Key.topupBalance,
                            topupOutstanding = f.Key.topupOutstanding,
                            //Yoonus
                            isFOC = f.Key.isFOC,
                            courseDetails = new List <Course_Details>(),
                            discountDetails = new List <Discounts>(),
                            salesStaffDetails = new List <SalesStaff>(),
                            prepaidAccountDetails = new List <Prepaid>()
                        }).ToList <Cart_Details>();
                        List <Settings> item = ((app.bsms.Models.Account.User)base.Session["Login_Details"]).settings;
                        bool            flag = ((
                                                    from s in item
                                                    where s.settingName == "GST SETTING"
                                                    select s).FirstOrDefault <Settings>().settingValue == "INCLUSIVE" ? true : false);
                        decimal one = Convert.ToDecimal((
                                                            from s in item
                                                            where s.settingName == "GST PERCENTAGE"
                                                            select s).FirstOrDefault <Settings>().settingValue);
                        one = decimal.One + (one / new decimal(100));
                        string str4 = (
                            from s in item
                            where s.settingName == "GST APPLY BY"
                            select s).FirstOrDefault <Settings>().settingValue;
                        foreach (Cart_Details zero in list)
                        {
                            app.bsms.api.Service.Parameters.Clear();
                            app.bsms.api.Service.Parameters.Add("siteCode", ((app.bsms.Models.Account.User)base.Session["Login_Details"]).siteCode);
                            app.bsms.api.Service.Parameters.Add("itemCode", zero.itemCode);
                            //Item item1 = app.bsms.api.Service.Get<Item>("getItemDetails");
                            //Yoonus Changing to getItemDetail
                            Item         item1         = app.bsms.api.Service.Get <Item>("getItemDetail");
                            Cart_Details courseDetails = (
                                from f in cartDetails
                                where f.itemCode == zero.itemCode
                                select f).FirstOrDefault <Cart_Details>();
                            zero.salesStaffDetails = courseDetails.salesStaffDetails;
                            if (courseDetails.salesStaffDetails == null)
                            {
                                zero.strStaffs = null;
                            }
                            else
                            {
                                zero.strStaffs = JsonConvert.SerializeObject(courseDetails.salesStaffDetails);
                                Cart_Details cartDetail = zero;
                                if (courseDetails.strStaffs == "[]")
                                {
                                    str3 = null;
                                }
                                else
                                {
                                    str3 = courseDetails.strStaffs;
                                }
                                cartDetail.strStaffs = str3;
                            }
                            if (zero.lineType == "TD")
                            {
                                zero.discountDetails = null;
                                zero.strDiscounts    = null;
                            }
                            else
                            {
                                zero.discountDetails = courseDetails.discountDetails;
                                if (courseDetails.discountDetails == null)
                                {
                                    zero.strDiscounts = null;
                                }
                                else
                                {
                                    zero.strDiscounts = JsonConvert.SerializeObject(courseDetails.discountDetails);
                                    Cart_Details cartDetail1 = zero;
                                    if (courseDetails.strDiscounts == "[]")
                                    {
                                        str2 = null;
                                    }
                                    else
                                    {
                                        str2 = courseDetails.strDiscounts;
                                    }
                                    cartDetail1.strDiscounts = str2;
                                    zero.unitDiscount        = zero.discountDetails.Sum <Discounts>((Discounts d) => d.discountAmount);
                                    zero.discountPercent     = zero.discountDetails.Sum <Discounts>((Discounts p) => p.discountPercentage);
                                    zero.discountUser        = courseDetails.discountUser;
                                }
                            }
                            if (zero.lineType == "COURSE")
                            {
                                if (courseDetails.courseDetails == null)
                                {
                                    zero.promoPrice = (zero.unitPrice * zero.itemQty) - zero.unitDiscount;
                                }
                                else if (courseDetails.courseDetails.FirstOrDefault <Course_Details>().courseType != "N")
                                {
                                    zero.promoPrice = (zero.unitPrice * zero.itemQty) - zero.unitDiscount;
                                }
                                else
                                {
                                    zero.totalTreatments = courseDetails.totalTreatments;
                                    Cart_Details value     = zero;
                                    int?         nullable1 = zero.totalTreatments;
                                    value.promoPrice = (nullable1.Value * zero.unitPrice) - zero.unitDiscount;
                                }
                                zero.itemAmount    = zero.promoPrice;
                                zero.salesAmount   = zero.promoPrice;
                                zero.depositAmount = (zero.depositAmount.IsNullOrZero() ? new decimal?(zero.promoPrice) : zero.depositAmount);
                            }
                            else if (!(zero.lineType == "VOUCHER") || !(item1.brandName == "NON SALES VOUCHER"))
                            {
                                zero.promoPrice = (zero.isFOC ? decimal.Zero : (zero.unitPrice * zero.itemQty) - zero.unitDiscount);
                                zero.itemAmount = (zero.isFOC ? decimal.Zero : zero.promoPrice);
                                if (zero.lineType != "TD")
                                {
                                    zero.balanceAmount = decimal.Zero;
                                    zero.salesAmount   = (zero.isFOC ? decimal.Zero : zero.promoPrice);
                                    zero.depositAmount = (zero.depositAmount.IsNullOrZero() ? new decimal?(zero.promoPrice) : zero.depositAmount);
                                }
                                else
                                {
                                    zero.balanceAmount        = courseDetails.balanceAmount;
                                    zero.treatmentCode        = courseDetails.treatmentCode;
                                    zero.isFirstTreatmentDone = courseDetails.isFirstTreatmentDone;
                                    zero.salesAmount          = decimal.Zero;
                                    Cart_Details nullable2 = zero;
                                    num = new decimal();
                                    nullable2.depositAmount = new decimal?(num);
                                }
                            }
                            else
                            {
                                zero.promoPrice  = decimal.Zero;
                                zero.itemAmount  = decimal.Zero;
                                zero.salesAmount = decimal.Zero;
                                Cart_Details cartDetail2 = zero;
                                num = new decimal();
                                cartDetail2.depositAmount = new decimal?(num);
                            }
                            if (zero.lineType != "COURSE")
                            {
                                if (courseDetails.courseDetails == null)
                                {
                                    courseDetails.courseDetails = new List <Course_Details>();
                                }
                                if (zero.lineType != "PACKAGE")
                                {
                                    Course_Details courseDetail = new Course_Details()
                                    {
                                        treatmentNumber    = 1,
                                        itemCode           = zero.itemCode,
                                        itemDescription    = zero.itemName,
                                        treatmentUnitPrice = zero.itemAmount,
                                        courseType         = "N",
                                        treatmentStatus    = (courseDetails.isFirstTreatmentDone ? "Done" : "Open"),
                                        treatmentDate      = DateTime.Now
                                    };
                                    nullable = null;
                                    courseDetail.nextAppt = nullable;
                                    courseDetail.isFOC    = new bool?(zero.isFOC);
                                    courseDetails.courseDetails.Add(courseDetail);
                                }
                                else
                                {
                                    courseDetails.courseDetails = new List <Course_Details>();
                                    app.bsms.api.Service.Parameters.Clear();
                                    app.bsms.api.Service.Parameters.Add("siteCode", ((app.bsms.Models.Account.User)base.Session["Login_Details"]).siteCode);
                                    app.bsms.api.Service.Parameters.Add("itemCode", zero.itemCode);
                                    List <PackageDetails> packageDetails = new List <PackageDetails>();
                                    packageDetails.AddRange(app.bsms.api.Service.GetList <PackageDetails>("packageContent"));
                                    foreach (PackageDetails packageDetail in packageDetails)
                                    {
                                        for (int i = 0; i < packageDetail.quantity; i++)
                                        {
                                            Course_Details courseDetail1 = new Course_Details()
                                            {
                                                treatmentNumber    = packageDetail.lineNumber,
                                                itemCode           = packageDetail.contentItemCode,
                                                itemDescription    = packageDetail.contentItemName,
                                                treatmentUnitPrice = packageDetail.price,
                                                courseType         = "N",
                                                treatmentStatus    = (courseDetails.isFirstTreatmentDone ? "Done" : "Open"),
                                                treatmentDate      = DateTime.Now
                                            };
                                            nullable = null;
                                            courseDetail1.nextAppt = nullable;
                                            courseDetail1.isFOC    = new bool?(zero.isFOC);
                                            courseDetails.courseDetails.Add(courseDetail1);
                                        }
                                    }
                                }
                            }
                            zero.courseDetails = courseDetails.courseDetails;
                            if (zero.lineType == "PREPAID")
                            {
                                if (courseDetails.prepaidAccountDetails != null)
                                {
                                    zero.strPrepaid = JsonConvert.SerializeObject(courseDetails.prepaidAccountDetails);
                                    Cart_Details cartDetail3 = zero;
                                    if (zero.strStaffs == "[]")
                                    {
                                        str1 = null;
                                    }
                                    else
                                    {
                                        str1 = zero.strStaffs;
                                    }
                                    cartDetail3.strPrepaid = str1;
                                }
                                else if (!item1.openPrepaid)
                                {
                                    courseDetails.prepaidAccountDetails = new List <Prepaid>();
                                    app.bsms.api.Service.Parameters.Clear();
                                    app.bsms.api.Service.Parameters.Add("siteCode", ((app.bsms.Models.Account.User)base.Session["Login_Details"]).siteCode);
                                    app.bsms.api.Service.Parameters.Add("rangeCode", item1.rangeCode);
                                    ItemType itemType = app.bsms.api.Service.GetList <ItemType>("prepaid").FirstOrDefault <ItemType>((ItemType f) => f.stockCode == zero.itemCode);
                                    if (itemType != null)
                                    {
                                        foreach (Prepaid prepaid in itemType.prepaidCondition)
                                        {
                                            List <Prepaid> prepaids = courseDetails.prepaidAccountDetails;
                                            Prepaid        prepaid1 = new Prepaid()
                                            {
                                                prepaidLineNumber = 1,
                                                prepaidType       = zero.itemCode
                                            };
                                            decimal?nullable3 = prepaid.prepaidValue;
                                            prepaid1.prepaidBonus = nullable3.Value - zero.unitPrice;
                                            decimal num1 = zero.unitPrice;
                                            nullable3                  = prepaid.prepaidValue;
                                            prepaid1.prepaidTotal      = num1 + (nullable3.Value - zero.unitPrice);
                                            prepaid1.prepaidAmount     = new decimal?(zero.unitPrice);
                                            prepaid1.prepaidValue      = prepaid.prepaidValue;
                                            prepaid1.prepaidItemType   = prepaid.prepaidItemType;
                                            prepaid1.prepaidCondition1 = (prepaid.prepaidCondition1 == null ? "All" : prepaid.prepaidCondition1);
                                            prepaid1.prepaidCondition2 = (prepaid.prepaidCondition2 == null ? "All" : prepaid.prepaidCondition2);
                                            nullable = null;
                                            prepaid1.prepaidExpiryDate = nullable;
                                            prepaids.Add(prepaid1);
                                        }
                                    }
                                    zero.strPrepaid = JsonConvert.SerializeObject(courseDetails.prepaidAccountDetails);
                                    Cart_Details cartDetail4 = zero;
                                    if (zero.strStaffs == "[]")
                                    {
                                        str = null;
                                    }
                                    else
                                    {
                                        str = zero.strStaffs;
                                    }
                                    cartDetail4.strPrepaid = str;
                                }
                            }
                            zero.prepaidAccountDetails = courseDetails.prepaidAccountDetails;
                            zero.holdItemQty           = (courseDetails.holdItemQty.IsNullOrZero() ? new int?(0) : courseDetails.holdItemQty);
                            if (str4 != "ALL")
                            {
                                if (!item1.taxable)
                                {
                                    continue;
                                }
                                zero.gstAmountCollected = Utility.GetGST(flag, zero.itemAmount, one);
                            }
                            else
                            {
                                zero.gstAmountCollected = Utility.GetGST(flag, zero.itemAmount, one);
                            }
                        }
                        list.AddRange(
                            from f in cartDetails
                            where f.lineType == "TD"
                            select f);
                        app.bsms.api.Service.Parameters.Clear();
                        app.bsms.api.Service.Parameters.Add("siteCode", ((app.bsms.Models.Account.User)base.Session["Login_Details"]).siteCode);
                        app.bsms.api.Service.Parameters.Add("userId", ((app.bsms.Models.Account.User)base.Session["Login_Details"]).userID);
                        Temp_Cart tempCart = app.bsms.api.Service.Get <Temp_Cart>("itemCart");
                        if (tempCart.userID == null)
                        {
                            tempCart = new Temp_Cart()
                            {
                                userID     = ((app.bsms.Models.Account.User)base.Session["Login_Details"]).userID,
                                siteCode   = ((app.bsms.Models.Account.User)base.Session["Login_Details"]).siteCode,
                                staffCode  = ((app.bsms.Models.Account.User)base.Session["Login_Details"]).staffCode,
                                macAddress = base.Request.ServerVariables["REMOTE_ADDR"]
                            };
                        }
                        tempCart.transactionDetails = list;
                        tempCart.totalQuantity      = tempCart.transactionDetails.Sum <Cart_Details>((Cart_Details f) => f.itemQty);
                        tempCart.totalAmount        = tempCart.transactionDetails.Sum <Cart_Details>((Cart_Details f) => f.itemAmount);
                        tempCart.depositAmount      = tempCart.transactionDetails.Sum <Cart_Details>((Cart_Details f) => ((!f.depositAmount.HasValue ? new decimal?(new decimal()) : f.depositAmount)).Value);
                        tempCart.payDetails         = new List <app.bsms.Models.Sales.Post.Payment_Details>();
                        app.bsms.api.Service.Parameters.Clear();
                        JsonSerializerSettings jsonSerializerSetting = new JsonSerializerSettings()
                        {
                            ContractResolver = new NullToEmptyStringResolver()
                        };
                        app.bsms.api.Service.Post <Temp_Cart>("itemCart", JsonConvert.SerializeObject(tempCart, jsonSerializerSetting));
                    }
                    else
                    {
                        action = base.RedirectToAction("Empty", "Cart");
                        return(action);
                    }
                }
                if (Convert.ToString(collection["callBy"]) == "COURSE" || Convert.ToString(collection["callBy"]) == "PREPAID")
                {
                    action = base.Json("Success", JsonRequestBehavior.AllowGet);
                }
                else
                {
                    action = base.RedirectToAction("Index", "Cart");
                }
            }
            catch (Exception exception)
            {
                throw exception;
            }
            return(action);
        }
Exemple #5
0
        public JsonResult RedeemItem(Cart_Details model)
        {
            JsonResult jsonResult;

            app.bsms.Models.Sales.Cart cart = new app.bsms.Models.Sales.Cart();
            try
            {
                decimal num = new decimal();
                app.bsms.api.Service.Parameters.Clear();
                app.bsms.api.Service.Parameters.Add("siteCode", ((app.bsms.Models.Account.User)base.Session["Login_Details"]).siteCode);
                app.bsms.api.Service.Parameters.Add("customerCode", model.staffcode);
                app.bsms.api.Service.Parameters.Add("treatmentParentCode", model.referenceTreatmentCode);
                List <Accounts> list      = app.bsms.api.Service.GetList <Accounts>("serviceAccountSummaryInfo");
                Treatment       treatment = app.bsms.api.Service.GetList <Treatment>("serviceRedemptionReverseTreatmentList").FirstOrDefault <Treatment>();
                if (list != null)
                {
                    num = list.Sum <Accounts>((Accounts f) => f.balance);
                    list.Sum <Accounts>((Accounts f) => f.outstanding);
                }
                app.bsms.api.Service.Parameters.Clear();
                app.bsms.api.Service.Parameters.Add("siteCode", ((app.bsms.Models.Account.User)base.Session["Login_Details"]).siteCode);
                app.bsms.api.Service.Parameters.Add("userId", ((app.bsms.Models.Account.User)base.Session["Login_Details"]).userID);
                cart.cart = app.bsms.api.Service.Get <Temp_Cart>("itemCart");
                if (cart.cart.userID == null)
                {
                    cart.cart = new Temp_Cart()
                    {
                        userID             = ((app.bsms.Models.Account.User)base.Session["Login_Details"]).userID,
                        siteCode           = ((app.bsms.Models.Account.User)base.Session["Login_Details"]).siteCode,
                        staffCode          = ((app.bsms.Models.Account.User)base.Session["Login_Details"]).staffCode,
                        macAddress         = base.Request.ServerVariables["REMOTE_ADDR"],
                        customerCode       = model.staffcode,
                        transactionDetails = new List <Cart_Details>()
                    };
                }
                else if ((
                             from f in cart.cart.transactionDetails
                             where f.lineType == "TD"
                             select f).Count <Cart_Details>() <= 0 || !(cart.cart.customerCode != model.staffcode))
                {
                    cart.cart.customerCode = model.staffcode;
                    num = num - (
                        from f in cart.cart.transactionDetails
                        where f.lineType == "TD"
                        select f).Sum <Cart_Details>((Cart_Details f) => f.unitPrice);
                    if (cart.cart.transactionDetails.Where <Cart_Details>((Cart_Details f) => {
                        if (f.treatmentCode != model.treatmentCode)
                        {
                            return(false);
                        }
                        return(f.referenceTreatmentCode == model.referenceTreatmentCode);
                    }).Count <Cart_Details>() > 0)
                    {
                        jsonResult = base.Json("{ \"status\": \"0\", \"message\":\"Item already exists\" }", JsonRequestBehavior.AllowGet);
                        //jsonResult = base.Json(string.Concat("{ \"status\": \"0\", \"message\":\"Item already exists\" }"), JsonRequestBehavior.AllowGet);
                        return(jsonResult);
                    }
                }
                else
                {
                    //jsonResult = base.Json(string.Concat("{ \"status\": \"0\", \"message\":\"Item already exists\" }"), JsonRequestBehavior.AllowGet);
                    jsonResult = base.Json(string.Concat("{ \"status\": \"0\", \"message\":\"Re-deemed service(s) is not belongs to ", model.staffcode, "\" }"), JsonRequestBehavior.AllowGet);
                    //return jsonResult;
                }
                model.staffcode = null;
                if (cart.cart.customerCode != null && cart.cart.customerCode != string.Empty)
                {
                    Register customer = Utility.GetCustomer(cart.cart.customerCode, ((app.bsms.Models.Account.User)base.Session["Login_Details"]).siteCode);
                    cart.cart.customerName = customer.customerName;
                }
                num -= model.unitPrice;
                if (num >= decimal.Zero)
                {
                    model.balanceAmount = num;
                    if (treatment != null)
                    {
                        model.salesStaffDetails = treatment.salesStaffDetails;
                    }
                    model.treatmentCode          = model.treatmentCode;
                    model.referenceTreatmentCode = model.referenceTreatmentCode;
                    //Yoonustopup
                    model.referenceTransactionNumber = model.referenceTransactionNumber;
                    model.topupBalance     = model.topupBalance;
                    model.topupOutstanding = model.topupOutstanding;
                    //Yoonus
                    model.courseDetails = new List <Course_Details>();
                    Course_Details courseDetail = new Course_Details()
                    {
                        treatmentNumber    = 1,
                        itemCode           = model.itemCode,
                        itemDescription    = model.itemName,
                        treatmentUnitPrice = model.itemAmount,
                        courseType         = "N",
                        treatmentStatus    = "Done",                      //Yoonus Changing to Done from "Open"
                        treatmentDate      = DateTime.Now,
                        nextAppt           = null,
                        isFOC = new bool?(false)
                    };
                    model.courseDetails.Add(courseDetail);
                    model.holdItemQty   = (model.holdItemQty.IsNullOrZero() ? new int?(0) : model.holdItemQty);
                    model.depositAmount = (model.depositAmount.IsNullOrZero() ? new decimal?(0) : model.depositAmount);
                    cart.cart.transactionDetails.Add(model);
                    cart.cart.totalQuantity = cart.cart.transactionDetails.Sum <Cart_Details>((Cart_Details f) => f.itemQty);
                    cart.cart.totalAmount   = cart.cart.transactionDetails.Sum <Cart_Details>((Cart_Details f) => f.itemAmount);
                    cart.cart.depositAmount = cart.cart.transactionDetails.Sum <Cart_Details>((Cart_Details f) => ((!f.depositAmount.HasValue ? new decimal?(new decimal()) : f.depositAmount)).Value);
                    cart.cart.payDetails    = new List <app.bsms.Models.Sales.Post.Payment_Details>();
                    app.bsms.api.Service.Parameters.Clear();
                    JsonSerializerSettings jsonSerializerSetting = new JsonSerializerSettings()
                    {
                        ContractResolver = new NullToEmptyStringResolver()
                    };
                    app.bsms.api.Service.Post <Temp_Cart>("itemCart", JsonConvert.SerializeObject(cart.cart, jsonSerializerSetting));
                    jsonResult = base.Json("{ \"status\": \"1\", \"message\":\"\" }", JsonRequestBehavior.AllowGet);
                }
                else
                {
                    jsonResult = base.Json("{ \"status\": \"0\", \"message\":\"Insufficient Balance\" }", JsonRequestBehavior.AllowGet);
                }
            }
            catch (Exception exception)
            {
                throw exception;
            }
            return(jsonResult);
        }