Example #1
0
        public static string checkphone(string phonefullname)
        {
            RefundCust rf       = new RefundCust();
            int        AgentID  = 0;
            string     username = HttpContext.Current.Request.Cookies["usernameLoginSystem"].Value;

            if (!string.IsNullOrEmpty(username))
            {
                var a = AccountController.GetByUsername(username);
                if (a != null)
                {
                    AgentID = Convert.ToInt32(a.AgentID);
                }
            }
            var customer = CustomerController.GetByPhone(phonefullname);

            if (customer != null)
            {
                rf.CustName    = customer.CustomerName;
                rf.CustPhone   = customer.CustomerPhone;
                rf.CustZalo    = customer.Zalo;
                rf.CustFB      = customer.Facebook;
                rf.CustAddress = customer.CustomerAddress;


                int    custID    = customer.ID;
                double FeeRefund = 0;
                double NumOfDateToChangeProduct = 0;
                double NumOfProductCanChange    = 0;
                var    config = ConfigController.GetByTop1();
                if (config != null)
                {
                    FeeRefund = Convert.ToDouble(config.FeeChangeProduct);
                    NumOfDateToChangeProduct = Convert.ToDouble(config.NumOfDateToChangeProduct);
                    NumOfProductCanChange    = Convert.ToDouble(config.NumOfProductCanChange);
                }
                var d = DiscountCustomerController.getbyCustID(custID);
                if (d.Count > 0)
                {
                    FeeRefund = d[0].FeeRefund;
                    NumOfDateToChangeProduct = d[0].NumOfDateToChangeProduct;
                    NumOfProductCanChange    = d[0].NumOfProductCanChange;
                }

                DateTime toDate   = DateTime.Now.Date;
                var      fromDate = toDate.AddDays(-NumOfDateToChangeProduct);

                double totalProductRefund = 0;
                var    refundList         = RefundGoodController.GetByAgentIDCustomerIDFromDateToDate(AgentID, custID, fromDate, toDate.AddDays(1));
                if (refundList.Count > 0)
                {
                    foreach (var item in refundList)
                    {
                        var rfD = RefundGoodDetailController.GetByRefundGoodsID(item.ID);
                        if (rfD.Count > 0)
                        {
                            foreach (var fd in rfD)
                            {
                                totalProductRefund += Convert.ToDouble(fd.Quantity);
                            }
                        }
                    }
                }
                double leftCanchange = NumOfProductCanChange - totalProductRefund;
                if (leftCanchange > 0)
                {
                    rf.CustleftCanchange = leftCanchange.ToString();

                    JavaScriptSerializer serializer = new JavaScriptSerializer();
                    return(serializer.Serialize(rf));
                }
                else
                {
                    rf.CustleftCanchange = "full";
                    JavaScriptSerializer serializer = new JavaScriptSerializer();
                    return(serializer.Serialize(rf));
                }
            }
            else
            {
                rf.CustleftCanchange = "nocustomer";
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                return(serializer.Serialize(rf));
            }
        }