Exemple #1
0
        public static string getProduct(string textsearch)
        {
            List <ProductGetOut> ps = new List <ProductGetOut>();
            string username         = HttpContext.Current.Request.Cookies["userLoginSystem"].Value;
            var    acc = AccountController.GetByUsername(username);

            if (acc != null)
            {
                int AgentID  = Convert.ToInt32(acc.AgentID);
                var products = ProductController.GetBySKU(textsearch.Trim().ToUpper());

                if (products != null)
                {
                    var productvariable = ProductVariableController.GetByParentSKU(products.ProductSKU);

                    if (productvariable.Count > 0)
                    {
                        foreach (var pv in productvariable)
                        {
                            string SKU = pv.SKU.Trim().ToUpper();

                            var check = StockManagerController.GetBySKU(AgentID, SKU);

                            if (check.Count > 0)
                            {
                                double total = PJUtils.TotalProductQuantityInstock(AgentID, SKU);

                                if (total > 0)
                                {
                                    var variables = ProductVariableValueController.GetByProductVariableSKU(pv.SKU);

                                    if (variables.Count > 0)
                                    {
                                        string variablename  = "";
                                        string variablevalue = "";
                                        string variable      = "";

                                        foreach (var v in variables)
                                        {
                                            variable      += v.VariableName.Trim() + ": " + v.VariableValue.Trim() + "|";
                                            variablename  += v.VariableName.Trim() + "|";
                                            variablevalue += v.VariableValue.Trim() + "|";
                                        }

                                        ProductGetOut p = new ProductGetOut();
                                        p.ID                   = pv.ID;
                                        p.ProductName          = products.ProductTitle;
                                        p.ProductVariable      = variable;
                                        p.ProductVariableName  = variablename;
                                        p.ProductVariableValue = variablevalue;
                                        p.ProductType          = 2;

                                        var product = ProductController.GetBySKU(pv.ParentSKU);

                                        if (!string.IsNullOrEmpty(pv.Image))
                                        {
                                            p.ProductImage       = "<img src=\"" + pv.Image + "\" />";
                                            p.ProductImageOrigin = pv.Image;
                                        }
                                        else if (!string.IsNullOrEmpty(product.ProductImage))
                                        {
                                            p.ProductImage       = "<img src=\"" + product.ProductImage + "\" />";
                                            p.ProductImageOrigin = product.ProductImage;
                                        }
                                        else
                                        {
                                            p.ProductImage       = "<img src=\"/App_Themes/Ann/image/placeholder.png\" />";
                                            p.ProductImageOrigin = "";
                                        }

                                        p.QuantityInstock       = total;
                                        p.QuantityInstockString = string.Format("{0:N0}", total);
                                        p.SKU = SKU;
                                        int supplierID = 0;
                                        if (pv.SupplierID != null)
                                        {
                                            supplierID = pv.SupplierID.ToString().ToInt(0);
                                        }
                                        p.SupplierID = supplierID;
                                        string supplierName = "";
                                        if (!string.IsNullOrEmpty(pv.SupplierName))
                                        {
                                            supplierName = pv.SupplierName;
                                        }
                                        p.SupplierName = supplierName;
                                        ps.Add(p);
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        string SKU   = products.ProductSKU.Trim().ToUpper();
                        var    check = StockManagerController.GetBySKU(AgentID, SKU);
                        if (check.Count > 0)
                        {
                            double total = PJUtils.TotalProductQuantityInstock(AgentID, SKU);
                            if (total > 0)
                            {
                                string variablename  = "";
                                string variablevalue = "";
                                string variable      = "";

                                ProductGetOut p = new ProductGetOut();
                                p.ID                   = products.ID;
                                p.ProductName          = products.ProductTitle;
                                p.ProductVariable      = variable;
                                p.ProductVariableName  = variablename;
                                p.ProductVariableValue = variablevalue;
                                p.ProductType          = 1;
                                var img = ProductImageController.GetFirstByProductID(products.ID);

                                if (!string.IsNullOrEmpty(products.ProductImage))
                                {
                                    p.ProductImage       = "<img src=\"" + products.ProductImage + "\" />";
                                    p.ProductImageOrigin = products.ProductImage;
                                }
                                else if (img != null)
                                {
                                    p.ProductImage       = "<img src=\"" + img.ProductImage + "\" />";
                                    p.ProductImageOrigin = img.ProductImage;
                                }
                                else
                                {
                                    p.ProductImage       = "<img src=\"/App_Themes/Ann/image/placeholder.png\" />";
                                    p.ProductImageOrigin = "";
                                }

                                p.SKU                   = SKU;
                                p.QuantityInstock       = total;
                                p.QuantityInstockString = string.Format("{0:N0}", total);
                                int supplierID = 0;
                                if (products.SupplierID != null)
                                {
                                    supplierID = products.SupplierID.ToString().ToInt(0);
                                }
                                p.SupplierID = supplierID;
                                string supplierName = "";
                                if (!string.IsNullOrEmpty(products.SupplierName))
                                {
                                    supplierName = products.SupplierName;
                                }
                                p.SupplierName = supplierName;
                                ps.Add(p);
                            }
                        }
                    }
                }
                else
                {
                    var productvariable = ProductVariableController.GetAllBySKU(textsearch.Trim().ToUpper());

                    if (productvariable != null)
                    {
                        foreach (var value in productvariable)
                        {
                            string SKU = value.SKU.Trim().ToUpper();

                            var check = StockManagerController.GetBySKU(AgentID, SKU);
                            if (check.Count > 0)
                            {
                                double total = PJUtils.TotalProductQuantityInstock(AgentID, SKU);
                                if (total > 0)
                                {
                                    var variables = ProductVariableValueController.GetByProductVariableSKU(value.SKU);

                                    if (variables.Count > 0)
                                    {
                                        string variablename  = "";
                                        string variablevalue = "";
                                        string variable      = "";

                                        foreach (var v in variables)
                                        {
                                            variable      += v.VariableName + ": " + v.VariableValue + "|";
                                            variablename  += v.VariableName + "|";
                                            variablevalue += v.VariableValue + "|";
                                        }

                                        ProductGetOut p = new ProductGetOut();
                                        p.ID = value.ID;

                                        var product = ProductController.GetBySKU(value.ParentSKU);

                                        if (product != null)
                                        {
                                            p.ProductName = product.ProductTitle;
                                        }
                                        p.ProductVariable      = variable;
                                        p.ProductVariableName  = variablename;
                                        p.ProductVariableValue = variablevalue;
                                        p.ProductType          = 2;

                                        if (!string.IsNullOrEmpty(value.Image))
                                        {
                                            p.ProductImage       = "<img src=\"" + value.Image + "\" />";
                                            p.ProductImageOrigin = value.Image;
                                        }
                                        else if (!string.IsNullOrEmpty(product.ProductImage))
                                        {
                                            p.ProductImage       = "<img src=\"" + product.ProductImage + "\" />";
                                            p.ProductImageOrigin = product.ProductImage;
                                        }
                                        else
                                        {
                                            p.ProductImage       = "<img src=\"/App_Themes/Ann/image/placeholder.png\" />";
                                            p.ProductImageOrigin = "";
                                        }

                                        p.SKU                   = value.SKU.Trim().ToUpper();
                                        p.QuantityInstock       = total;
                                        p.QuantityInstockString = string.Format("{0:N0}", total);
                                        int supplierID = 0;
                                        if (value.SupplierID != null)
                                        {
                                            supplierID = value.SupplierID.ToString().ToInt(0);
                                        }
                                        p.SupplierID = supplierID;
                                        string supplierName = "";
                                        if (!string.IsNullOrEmpty(value.SupplierName))
                                        {
                                            supplierName = value.SupplierName;
                                        }
                                        p.SupplierName = supplierName;
                                        ps.Add(p);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            JavaScriptSerializer serializer = new JavaScriptSerializer();

            return(serializer.Serialize(ps));
        }
        public void LoadData()
        {
            int ID = Request.QueryString["id"].ToInt(0);

            if (ID > 0)
            {
                var order = OrderController.GetByID(ID);
                if (order == null)
                {
                    PJUtils.ShowMessageBoxSwAlertError("Không tìm thấy đơn hàng " + ID, "e", true, "/danh-sach-don-hang-chuyen-hoan", Page);
                }
                else
                {
                    hdfOrderID.Value = order.ID.ToString();
                    string username = HttpContext.Current.Request.Cookies["userLoginSystem"].Value;
                    var    acc      = AccountController.GetByUsername(username);

                    // check order condition
                    if (acc.RoleID != 0)
                    {
                        if (order.ExcuteStatus == 4)
                        {
                            PJUtils.ShowMessageBoxSwAlertError("Đơn hàng này đã chuyển hoàn", "w", false, "", Page);
                        }
                        else
                        {
                            if (order.CreatedBy != acc.Username)
                            {
                                PJUtils.ShowMessageBoxSwAlertError("Đơn hàng này không phải của bạn", "e", true, "/danh-sach-don-hang-chuyen-hoan", Page);
                            }

                            if (order.ExcuteStatus == 1)
                            {
                                PJUtils.ShowMessageBoxSwAlertError("Đơn hàng này chưa hoàn tất nên không thể chuyển hoàn", "e", true, "/danh-sach-don-hang-chuyen-hoan", Page);
                            }

                            if (order.ExcuteStatus == 3)
                            {
                                PJUtils.ShowMessageBoxSwAlertError("Đơn hàng này đã hủy nên không thể chuyển hoàn", "e", true, "/danh-sach-don-hang-chuyen-hoan", Page);
                            }

                            if (order.ShippingType == 1)
                            {
                                PJUtils.ShowMessageBoxSwAlertError("Đơn hàng này lấy trực tiếp nên không thể chuyển hoàn", "e", true, "/danh-sach-don-hang-chuyen-hoan", Page);
                            }
                        }
                    }
                    else
                    {
                        if (order.ExcuteStatus == 4)
                        {
                            PJUtils.ShowMessageBoxSwAlertError("Đơn hàng này đã chuyển hoàn", "w", false, "", Page);
                        }
                        else
                        {
                            if (order.ExcuteStatus == 1)
                            {
                                PJUtils.ShowMessageBoxSwAlertError("Đơn hàng này chưa hoàn tất nên không thể chuyển hoàn", "e", true, "/danh-sach-don-hang-chuyen-hoan", Page);
                            }

                            if (order.ExcuteStatus == 3)
                            {
                                PJUtils.ShowMessageBoxSwAlertError("Đơn hàng này đã hủy nên không thể chuyển hoàn", "e", true, "/danh-sach-don-hang-chuyen-hoan", Page);
                            }

                            if (order.ShippingType == 1)
                            {
                                PJUtils.ShowMessageBoxSwAlertError("Đơn hàng này lấy trực tiếp nên không thể chuyển hoàn", "e", true, "/danh-sach-don-hang-chuyen-hoan", Page);
                            }
                        }
                    }

                    ViewState["ID"] = ID;

                    Response.Cookies["odid"].Value = ID.ToString();

                    int AgentID = Convert.ToInt32(order.AgentID);
                    txtPhone.Text    = order.CustomerPhone;
                    txtFullname.Text = order.CustomerName;
                    txtAddress.Text  = order.CustomerAddress;
                    var cus = CustomerController.GetByID(order.CustomerID.Value);
                    if (cus != null)
                    {
                        txtNick.Text = cus.Nick;

                        txtZalo.Text = cus.Zalo;

                        txtFacebook.Text = cus.Facebook;
                        if (!string.IsNullOrEmpty(cus.Facebook))
                        {
                            ltrFb.Text += "<a href =\"" + cus.Facebook + "\" class=\"btn primary-btn fw-btn not-fullwidth\" target=\"_blank\">Xem</a>";
                        }
                    }
                    int customerID = Convert.ToInt32(order.CustomerID);
                    ltrViewDetail.Text  = "<a href=\"javascript:;\" class=\"btn primary-btn fw-btn not-fullwidth\" onclick=\"viewCustomerDetail('" + customerID + "')\"><i class=\"fa fa-address-card-o\" aria-hidden=\"true\"></i> Xem chi tiết</a>";
                    ltrViewDetail.Text += "<a href=\"chi-tiet-khach-hang?id=" + customerID + "\" class=\"btn primary-btn fw-btn not-fullwidth edit-customer-btn\" target=\"_blank\"><i class=\"fa fa-pencil-square-o\" aria-hidden=\"true\"></i> Chỉnh sửa</a>";

                    var d = DiscountCustomerController.getbyCustID(customerID);
                    if (d.Count > 0)
                    {
                        var da = d[0].DiscountAmount;
                        hdfIsDiscount.Value     = "1";
                        hdfDiscountAmount.Value = da.ToString();
                        ltrDiscountInfo.Text    = "<strong>Khách hàng được chiết khấu: " + string.Format("{0:N0}", Convert.ToDouble(da)) + " vnđ/sản phẩm.</strong>";
                    }
                    else
                    {
                        hdfIsDiscount.Value     = "0";
                        hdfDiscountAmount.Value = "0";
                    }

                    int customerType = Convert.ToInt32(order.OrderType);
                    ltrCustomerType.Text  = "";
                    ltrCustomerType.Text += "<select disabled class=\"form-control customer-type\" onchange=\"getProductPrice($(this))\">";
                    if (customerType == 1)
                    {
                        ltrCustomerType.Text += "<option value=\"2\">Khách mua sỉ</option>";
                        ltrCustomerType.Text += "<option value=\"1\" selected>Khách mua lẻ</option>";
                    }
                    else
                    {
                        ltrCustomerType.Text += "<option value=\"2\" selected>Khách mua sỉ</option>";
                        ltrCustomerType.Text += "<option value=\"1\">Khách mua lẻ</option>";
                    }
                    ltrCustomerType.Text += "</select>";


                    double ProductQuantity       = 0;
                    double totalPrice            = Convert.ToDouble(order.TotalPrice);
                    double totalPriceNotDiscount = Convert.ToDouble(order.TotalPriceNotDiscount);

                    hdfcheckR.Value = "";

                    int totalrefund = 0;
                    if (order.RefundsGoodsID > 0)
                    {
                        var re = RefundGoodController.GetByID(order.RefundsGoodsID.Value);
                        if (re != null)
                        {
                            totalrefund     = Convert.ToInt32(re.TotalPrice);
                            hdfcheckR.Value = order.RefundsGoodsID.ToString() + "," + re.TotalPrice;
                        }

                        ltrtotalpricedetail.Text = string.Format("{0:N0}", totalPrice - totalrefund);

                        ltrTotalPriceRefund.Text = string.Format("{0:N0}", totalrefund);
                    }

                    hdfDiscountInOrder.Value = "";

                    if (order.DiscountPerProduct > 0)
                    {
                        hdfDiscountInOrder.Value = order.DiscountPerProduct.ToString();
                    }

                    int paymentStatus         = Convert.ToInt32(order.PaymentStatus);
                    int excuteStatus          = Convert.ToInt32(order.ExcuteStatus);
                    int shipping              = Convert.ToInt32(order.ShippingType);
                    int TransportCompanyID    = Convert.ToInt32(order.TransportCompanyID);
                    int TransportCompanySubID = Convert.ToInt32(order.TransportCompanySubID);
                    int PostalDeliveryType    = Convert.ToInt32(order.PostalDeliveryType);
                    int paymenttype           = Convert.ToInt32(order.PaymentType);
                    #region Lấy danh sách sản phẩm
                    var    orderdetails = OrderDetailController.GetByOrderID(ID);
                    string html         = "";
                    string Print        = "";
                    if (orderdetails.Count > 0)
                    {
                        int t         = 0;
                        int orderitem = 0;
                        foreach (var item in orderdetails)
                        {
                            ProductQuantity += Convert.ToDouble(item.Quantity);

                            int    ProductType       = Convert.ToInt32(item.ProductType);
                            int    ProductID         = Convert.ToInt32(item.ProductID);
                            int    ProductVariableID = Convert.ToInt32(item.ProductVariableID);
                            double ItemPrice         = Convert.ToDouble(item.Price);
                            string SKU                        = item.SKU;
                            double Giabansi                   = 0;
                            double Giabanle                   = 0;
                            string stringGiabansi             = "";
                            string stringGiabanle             = "";
                            double QuantityInstock            = 0;
                            string ProductImageOrigin         = "";
                            string ProductVariable            = "";
                            string ProductName                = "";
                            int    PID                        = 0;
                            string ProductVariableName        = "";
                            string ProductVariableValue       = "";
                            string ProductVariableSave        = "";
                            double QuantityMainInstock        = 0;
                            string ProductImage               = "";
                            string QuantityMainInstockString  = "";
                            string QuantityInstockString      = "";
                            string productVariableDescription = item.ProductVariableDescrition;

                            if (ProductType == 1)
                            {
                                PID = ProductID;
                                var product = ProductController.GetBySKU(SKU);
                                if (product != null)
                                {
                                    double mainstock = PJUtils.TotalProductQuantityInstock(1, SKU);

                                    if (customerType == 1)
                                    {
                                        Giabansi = Convert.ToDouble(product.Regular_Price);
                                        Giabanle = ItemPrice;
                                    }
                                    else
                                    {
                                        Giabansi = ItemPrice;
                                        Giabanle = Convert.ToDouble(product.Retail_Price);
                                    }
                                    stringGiabansi = string.Format("{0:N0}", Giabansi);
                                    stringGiabanle = string.Format("{0:N0}", Giabanle);
                                    string variablename  = "";
                                    string variablevalue = "";
                                    string variable      = "";



                                    QuantityInstock       = mainstock;
                                    QuantityInstockString = string.Format("{0:N0}", mainstock);

                                    var img = ProductImageController.GetFirstByProductID(product.ID);
                                    if (!string.IsNullOrEmpty(product.ProductImage))
                                    {
                                        ProductImage       = "<img src=\"" + product.ProductImage + "\" />";
                                        ProductImageOrigin = product.ProductImage;
                                    }
                                    else if (img != null)
                                    {
                                        ProductImage       = "<img src=\"" + img.ProductImage + "\" />";
                                        ProductImageOrigin = img.ProductImage;
                                    }
                                    else
                                    {
                                        ProductImage       = "<img src=\"/App_Themes/Ann/image/placeholder.png\" />";
                                        ProductImageOrigin = "";
                                    }
                                    ProductVariable = variable;
                                    ProductName     = product.ProductTitle;

                                    QuantityMainInstock       = mainstock;
                                    QuantityMainInstockString = string.Format("{0:N0}", mainstock);
                                    ProductVariableSave       = item.ProductVariableDescrition;

                                    ProductVariableName  = variablename;
                                    ProductVariableValue = variablevalue;
                                }
                            }
                            else
                            {
                                PID = ProductVariableID;
                                var productvariable = ProductVariableController.GetBySKU(SKU);
                                if (productvariable != null)
                                {
                                    SKU = productvariable.SKU.Trim().ToUpper();

                                    double mainstock = PJUtils.TotalProductQuantityInstock(1, SKU);

                                    if (customerType == 1)
                                    {
                                        Giabansi = Convert.ToDouble(productvariable.Regular_Price);
                                        Giabanle = ItemPrice;
                                    }
                                    else
                                    {
                                        Giabansi = ItemPrice;
                                        Giabanle = Convert.ToDouble(productvariable.RetailPrice);
                                    }
                                    stringGiabansi = string.Format("{0:N0}", Giabansi);
                                    stringGiabanle = string.Format("{0:N0}", Giabanle);


                                    string variablename  = "";
                                    string variablevalue = "";
                                    string variable      = "";

                                    string[] vs = productVariableDescription.Split('|');
                                    if (vs.Length - 1 > 0)
                                    {
                                        for (int i = 0; i < vs.Length - 1; i++)
                                        {
                                            string[] items = vs[i].Split(':');
                                            variable      += items[0] + ":" + items[1] + "<br/>";
                                            variablename  += items[0] + "|";
                                            variablevalue += items[1] + "|";
                                        }
                                    }

                                    QuantityInstock       = mainstock;
                                    QuantityInstockString = string.Format("{0:N0}", mainstock);

                                    var _product = ProductController.GetByID(Convert.ToInt32(productvariable.ProductID));

                                    if (!string.IsNullOrEmpty(productvariable.Image))
                                    {
                                        ProductImage       = "<img src=\"" + productvariable.Image + "\" />";
                                        ProductImageOrigin = productvariable.Image;
                                    }
                                    else if (_product != null && !string.IsNullOrEmpty(_product.ProductImage))
                                    {
                                        ProductImage       = "<img src=\"" + _product.ProductImage + "\" />";
                                        ProductImageOrigin = _product.ProductImage;
                                    }
                                    else
                                    {
                                        ProductImage       = "<img src=\"/App_Themes/Ann/image/placeholder.png\" />";
                                        ProductImageOrigin = "";
                                    }

                                    ProductVariable = variable;

                                    if (_product != null)
                                    {
                                        ProductName = _product.ProductTitle;
                                    }

                                    QuantityMainInstock       = mainstock;
                                    QuantityMainInstockString = string.Format("{0:N0}", mainstock);
                                    ProductVariableSave       = item.ProductVariableDescrition;

                                    ProductVariableName  = variablename;
                                    ProductVariableValue = variablevalue;
                                }
                            }
                            orderitem++;
                            html += "<tr class=\"product-result\" data-orderdetailid=\"" + item.ID + "\" data-giabansi=\"" + Giabansi + "\" data-giabanle=\"" + Giabanle + "\" " +
                                    "data-quantityinstock=\"" + QuantityInstock + "\" data-productimageorigin=\"" + ProductImageOrigin + "\" " +
                                    "data-productvariable=\"" + ProductVariable + "\" data-productname=\"" + ProductName + "\" " +
                                    "data-sku=\"" + SKU + "\" data-producttype=\"" + ProductType + "\" data-id=\"" + PID + "\" " +
                                    "data-productnariablename=\"" + ProductVariableName + "\" " +
                                    "data-productvariablevalue =\"" + ProductVariableValue + "\" " +
                                    "data-productvariablesave =\"" + ProductVariableSave + "\" " +
                                    "data-quantitymaininstock=\"" + QuantityMainInstock + "\">";
                            html += "   <td class=\"order-item\">" + orderitem + "";
                            html += "   <td class=\"image-item\">" + ProductImage + "";
                            html += "   <td class=\"name-item\">" + ProductName + "</td>";
                            html += "   <td class=\"sku-item\">" + SKU + "</td>";
                            html += "   <td class=\"variable-item\">" + ProductVariable + "</td>";
                            html += "   <td class=\"price-item gia-san-pham\" data-price=\"" + ItemPrice + "\">" + string.Format("{0:N0}", ItemPrice) + "</td>";
                            html += "   <td class=\"quantity-item soluong\">" + QuantityInstockString + "</td>";
                            html += "   <td class=\"quantity-item\"><input disabled data-quantity=\"" + item.Quantity + "\" value=\"" + item.Quantity + "\" type=\"text\" class=\"form-control in-quanlity\" value=\"1\" onblur=\"checkQuantiy($(this))\" onkeypress='return event.charCode >= 48 && event.charCode <= 57'/></td>";
                            int k = Convert.ToInt32(ItemPrice) * Convert.ToInt32(item.Quantity);
                            html += "<td class=\"total-item totalprice-view\">" + string.Format("{0:N0}", k) + "</td>";
                            html += "   <td class=\"trash-item\"><a href=\"javascript:;\" class=\"link-btn\"><i class=\"fa fa-trash\"></i></a>    </td>";

                            html += "</tr>";


                            Print += " <tr>";
                            t++;
                            Print += "<td>" + t + "</td>";
                            Print += "<td>" + SKU + " - " + ProductName + " - " + ProductVariableSave.Replace("|", ", ") + "</td> ";
                            Print += "<td>" + item.Quantity + "</td>";
                            Print += "<td>" + string.Format("{0:N0}", ItemPrice) + "</td>";

                            Print += "<td> " + string.Format("{0:N0}", k) + "</td>";

                            Print += "</tr>";
                        }
                        ltrProducts.Text = html;
                    }
                    #endregion
                    ddlPaymentStatus.SelectedValue      = paymentStatus.ToString();
                    ddlExcuteStatus.SelectedValue       = excuteStatus.ToString();
                    ddlPaymentType.SelectedValue        = paymenttype.ToString();
                    ddlShippingType.SelectedValue       = shipping.ToString();
                    ddlPostalDeliveryType.SelectedValue = PostalDeliveryType.ToString();

                    LoadTransportCompanySubID(TransportCompanyID);
                    ddlTransportCompanyID.SelectedValue    = TransportCompanyID.ToString();
                    ddlTransportCompanySubID.SelectedValue = TransportCompanySubID.ToString();

                    txtShippingCode.Text = order.ShippingCode;
                    txtOrderNote.Text    = order.OrderNote;

                    ltrProductQuantity.Text  = string.Format("{0:N0}", ProductQuantity) + " sản phẩm";
                    ltrTotalNotDiscount.Text = string.Format("{0:N0}", Convert.ToDouble(order.TotalPriceNotDiscount));
                    ltrTotalprice.Text       = string.Format("{0:N0}", Convert.ToDouble(order.TotalPrice));
                    pDiscount.Value          = order.DiscountPerProduct;
                    pFeeShip.Value           = Convert.ToDouble(order.FeeShipping);

                    ltrOtherFeeName.Text = order.OtherFeeName;
                    txtOtherFeeName.Text = order.OtherFeeName;
                    pOtherFee.Value      = Convert.ToDouble(order.OtherFeeValue);

                    ltrTotalAfterCK.Text = string.Format("{0:N0}", (Convert.ToDouble(order.TotalPriceNotDiscount) - Convert.ToDouble(order.TotalDiscount)));
                    ltrOrderID.Text      = ID.ToString();
                    ltrCreateBy.Text     = order.CreatedBy;
                    ltrCreateDate.Text   = order.CreatedDate.ToString();
                    ltrDateDone.Text     = "Chưa hoàn tất";
                    if (order.DateDone != null)
                    {
                        ltrDateDone.Text = order.DateDone.ToString();
                    }
                    ltrOrderNote.Text       = order.OrderNote;
                    ltrOrderQuantity.Text   = ProductQuantity.ToString();
                    ltrOrderTotalPrice.Text = string.Format("{0:N0}", Convert.ToDouble(order.TotalPrice));
                    ltrOrderStatus.Text     = PJUtils.OrderExcuteStatus(Convert.ToInt32(order.ExcuteStatus));

                    ltrOrderType.Text = PJUtils.OrderType(Convert.ToInt32(order.OrderType));
                }
            }
        }
Exemple #3
0
        public void LoadData()
        {
            int ID = Request.QueryString["id"].ToInt(0);

            if (ID > 0)
            {
                string username = Request.Cookies["usernameLoginSystem"].Value;
                var    acc      = AccountController.GetByUsername(username);
                if (acc != null)
                {
                    int agentIDReceive = Convert.ToInt32(acc.AgentID);
                    var mp             = MoveProController.GetByIDAndAgentIDReceive(ID, agentIDReceive);
                    if (mp != null)
                    {
                        ViewState["ID"] = ID;
                        int    agentIDSend      = Convert.ToInt32(mp.AgentIDSend);
                        string agentSendname    = "";
                        string agentReceivename = "";

                        var agentSend = AgentController.GetByID(agentIDSend);
                        if (agentSend != null)
                        {
                            agentSendname = agentSend.AgentName;
                        }
                        var agentReceive = AgentController.GetByID(agentIDReceive);
                        if (agentReceive != null)
                        {
                            agentReceivename = agentReceive.AgentName;
                        }
                        ltrAgentReceive.Text = agentReceivename;
                        ltrAgentSend.Text    = agentSendname;



                        int mpStatus = Convert.ToInt32(mp.Status);
                        ltrNote.Text = mp.Note;

                        if (mpStatus < 3)
                        {
                            ltrbutton1.Text = "<a href=\"javascript:;\" class=\"btn primary-btn fw-btn not-fullwidth\" onclick=\"inProduct()\">Cập nhật</a>";
                            ltrbutton2.Text = "<div class=\"float-right\"><a href=\"javascript:;\" class=\"btn primary-btn fw-btn not-fullwidth\" onclick=\"inProduct()\">Cập nhật</a></div>";
                        }
                        #region LoadDDL
                        //Lấy trạng thái
                        StringBuilder htmlStatus = new StringBuilder();
                        htmlStatus.Append("<select id=\"moveProStatus\" class=\"form-control\" style=\"width: 20%; display: inline-block\">");
                        if (mpStatus == 2)
                        {
                            htmlStatus.Append("<option value=\"2\" selected>Đã chuyển</option>");
                            htmlStatus.Append("<option value=\"3\">Đã hoàn tất</option>");
                        }
                        else if (mpStatus == 3)
                        {
                            htmlStatus.Append("<option value=\"2\">Đã chuyển</option>");
                            htmlStatus.Append("<option value=\"3\" selected>Đã hoàn tất</option>");
                        }
                        htmlStatus.Append("</select>");
                        ltrMoProStatus.Text = htmlStatus.ToString();

                        //Lấy nhà cung cấp
                        //var supplier = SupplierController.GetAllWithIsHidden(false);
                        //StringBuilder htmlSupplier = new StringBuilder();
                        //htmlSupplier.Append("<select id=\"supplierList\" class=\"form-control\" style=\"width: 20%; float: left; margin-right: 10px\">");
                        //htmlSupplier.Append("<option value=\"0\">Tất cả nhà cung cấp</option>");
                        //if (supplier.Count > 0)
                        //{
                        //    foreach (var s in supplier)
                        //    {
                        //        htmlSupplier.Append("<option value=\"" + s.ID + "\">" + s.SupplierName + "</option>");
                        //    }
                        //}
                        //htmlSupplier.Append("</select>");
                        //ltrSupplier.Text = htmlSupplier.ToString();
                        #endregion
                        #region Lấy danh sách sản phẩm
                        var    mpDetail = MoveProDetailController.GetByMoveProID(ID);
                        string html     = "";
                        if (mpDetail.Count > 0)
                        {
                            string listSKU = "";
                            foreach (var item in mpDetail)
                            {
                                listSKU += item.SKU + "|";
                                int ProductType       = Convert.ToInt32(item.ProductType);
                                int ProductID         = Convert.ToInt32(item.ProductID);
                                int ProductVariableID = Convert.ToInt32(item.ProductVariableID);

                                string SKU                        = item.SKU;
                                double QuantityInstock            = 0;
                                string ProductImageOrigin         = "";
                                string ProductVariable            = "";
                                string ProductName                = "";
                                int    PID                        = 0;
                                string ProductVariableName        = "";
                                string ProductVariableValue       = "";
                                string ProductVariableSave        = "";
                                double QuantityMainInstock        = 0;
                                string ProductImage               = "";
                                string QuantityMainInstockString  = "";
                                string QuantityInstockString      = "";
                                string productVariableDescription = item.ProductVariableDescription;
                                string SupplierName               = item.SupplierName;
                                if (ProductType == 1)
                                {
                                    PID = ProductID;
                                    var product = ProductController.GetBySKU(SKU);
                                    if (product != null)
                                    {
                                        double total = PJUtils.TotalProductQuantityInstock(agentIDSend, SKU);

                                        string variablename  = "";
                                        string variablevalue = "";
                                        string variable      = "";

                                        double mainstock = PJUtils.TotalProductQuantityInstock(1, SKU);

                                        QuantityInstock       = total;
                                        QuantityInstockString = string.Format("{0:N0}", total);

                                        var img = ProductImageController.GetFirstByProductID(product.ID);
                                        if (img != null)
                                        {
                                            ProductImage       = "<img src=\"" + Thumbnail.getURL(img.ProductImage, Thumbnail.Size.Small) + "\" alt=\"\" style=\"width: 50px\"  />";
                                            ProductImageOrigin = Thumbnail.getURL(img.ProductImage, Thumbnail.Size.Small);
                                        }
                                        else
                                        {
                                            ProductImage       = "";
                                            ProductImageOrigin = "";
                                        }


                                        ProductVariable = variable;
                                        ProductName     = product.ProductTitle;

                                        QuantityMainInstock       = mainstock;
                                        QuantityMainInstockString = string.Format("{0:N0}", mainstock);
                                        ProductVariableSave       = item.ProductVariableDescription;

                                        ProductVariableName  = variablename;
                                        ProductVariableValue = variablevalue;
                                    }
                                }
                                else
                                {
                                    PID = ProductVariableID;
                                    var productvariable = ProductVariableController.GetBySKU(SKU);
                                    if (productvariable != null)
                                    {
                                        SKU = productvariable.SKU.Trim().ToUpper();
                                        double total = PJUtils.TotalProductQuantityInstock(agentIDSend, SKU);


                                        string variablename  = "";
                                        string variablevalue = "";
                                        string variable      = "";

                                        string[] vs = productVariableDescription.Split('|');
                                        if (vs.Length - 1 > 0)
                                        {
                                            for (int i = 0; i < vs.Length - 1; i++)
                                            {
                                                string[] items = vs[i].Split(':');
                                                variable      += items[0] + ":" + items[1] + "<br/>";
                                                variablename  += items[0] + "|";
                                                variablevalue += items[1] + "|";
                                            }
                                        }

                                        double mainstock = PJUtils.TotalProductQuantityInstock(1, SKU);

                                        QuantityInstock       = total;
                                        QuantityInstockString = string.Format("{0:N0}", total);
                                        ProductImage          = "<img src=\"" + Thumbnail.getURL(productvariable.Image, Thumbnail.Size.Small) + "\" alt=\"\" style=\"width:50px;\" />";
                                        ProductImageOrigin    = Thumbnail.getURL(productvariable.Image, Thumbnail.Size.Small);

                                        ProductVariable = variable;
                                        var product1 = ProductController.GetByID(Convert.ToInt32(productvariable.ProductID));
                                        if (product1 != null)
                                        {
                                            ProductName = product1.ProductTitle;
                                        }

                                        QuantityMainInstock       = mainstock;
                                        QuantityMainInstockString = string.Format("{0:N0}", mainstock);
                                        ProductVariableSave       = item.ProductVariableDescription;

                                        ProductVariableName  = variablename;
                                        ProductVariableValue = variablevalue;
                                    }
                                }
                                html += "<tr class=\"product-result\" data-mpdid=\"" + item.ID + "\" data-quantityinstock=\"" + QuantityInstock
                                        + "\" data-productimageorigin=\"" + ProductImageOrigin
                                        + "\" data-productvariable=\"" + ProductVariableSave
                                        + "\" data-productname=\"" + ProductName
                                        + "\" data-sku=\"" + SKU + "\" data-producttype=\"" + ProductType
                                        + "\" data-id=\"" + item.ID + "\" data-productnariablename=\"" + ProductVariableName
                                        + "\" data-productvariablevalue =\"" + ProductVariableValue + "\">";
                                html += "   <td>" + ProductImage + "";
                                html += "   <td>" + ProductName + "</td>";
                                html += "   <td>" + SKU + "</td>";
                                html += "   <td>" + SupplierName + "</td>";
                                html += "   <td>" + ProductVariable + "</td>";
                                html += "   <td>" + item.QuantiySend + "</td>";
                                html += "   <td style=\"width:20%;\"><input type=\"text\" min=\"0\" class=\"form-control in-quanlity\" style=\"width: 40%;margin: 0 auto;\" value=\"" + item.QuantityReceive + "\"  onkeyup=\"checkQuantiy($(this))\" onkeypress='return event.charCode >= 48 && event.charCode <= 57'/></td>";
                                //html += "   <td><a href=\"javascript:;\" onclick=\"deleteRow($(this))\">Xóa</a></td>";
                                //html += "   <td></td>";
                                html += "</tr>";
                            }
                            ltrProducts.Text         = html;
                            hdfListProductSend.Value = listSKU;
                        }
                        #endregion
                    }
                }
            }
        }
Exemple #4
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            DateTime currentDate = DateTime.Now;
            int      AgentID     = 0;
            string   username    = Request.Cookies["usernameLoginSystem"].Value;

            if (!string.IsNullOrEmpty(username))
            {
                var a = AccountController.GetByUsername(username);
                if (a != null)
                {
                    AgentID = Convert.ToInt32(a.AgentID);
                    string phone = hdfPhone.Value;
                    if (!string.IsNullOrEmpty(phone))
                    {
                        var cust = CustomerController.GetByPhone(phone);
                        if (cust != null)
                        {
                            #region Tạo đơn hàng đổi tra
                            int    custID        = cust.ID;
                            string totalprice    = hdfTotalPrice.Value;
                            string totalquantity = hdfTotalQuantity.Value;
                            string totalrefund   = hdfTotalRefund.Value;
                            var    agent         = AgentController.GetByID(AgentID);
                            string agentName     = "";
                            if (agent != null)
                            {
                                agentName = agent.AgentName;
                            }
                            //insert ddlstatus, refundnote
                            int    status      = ddlRefundStatus.SelectedValue.ToInt();
                            string RefundsNote = txtRefundsNote.Text;
                            int    rID         = RefundGoodController.Insert(AgentID, totalprice, status, custID, Convert.ToInt32(totalquantity),
                                                                             totalrefund, agentName, cust.CustomerName, cust.CustomerPhone, currentDate, username, RefundsNote);
                            #endregion

                            if (rID > 0)
                            {
                                string   listString = hdfListProduct.Value;
                                string[] items      = listString.Split('|');
                                if (items.Length - 1 > 0)
                                {
                                    for (int i = 0; i < items.Length - 1; i++)
                                    {
                                        #region Tạo chi tiết đơn hàng đổi tra
                                        string[] element                 = items[i].Split(';');
                                        var      sku                     = element[0];
                                        var      orderID                 = element[1].ToInt(0);
                                        var      orderDetailID           = element[2];
                                        var      ProductName             = element[3];
                                        var      GiavonPerProduct        = Convert.ToDouble(element[5]);
                                        var      SoldPricePerProduct     = Convert.ToDouble(element[6]);
                                        var      DiscountPricePerProduct = Convert.ToDouble(element[7]);
                                        var      quantity                = Convert.ToDouble(element[10]);
                                        var      quantityMax             = Convert.ToDouble(element[8]);
                                        var      ProductType             = element[4].ToInt(1);
                                        var      RefundType              = element[9].ToInt(1);
                                        var      RefundFeePerProduct     = Convert.ToDouble(element[11]);
                                        var      TotalPriceRow           = element[12];
                                        var      PriceNotFeeRefund       = SoldPricePerProduct * quantity;
                                        var      rdTotalRefundFee        = RefundFeePerProduct * quantity;

                                        int rdID = RefundGoodDetailController.Insert(rID, AgentID, orderID, ProductName, custID, sku, quantity,
                                                                                     quantityMax, PriceNotFeeRefund.ToString(), ProductType, true, RefundType, RefundFeePerProduct.ToString(),
                                                                                     rdTotalRefundFee.ToString(), GiavonPerProduct.ToString(), DiscountPricePerProduct.ToString(), SoldPricePerProduct.ToString(),
                                                                                     TotalPriceRow, currentDate, username);
                                        #endregion

                                        #region Cập nhật stock
                                        if (rdID > 0)
                                        {
                                            if (RefundType < 3)
                                            {
                                                int    typeRe = 0;
                                                string note   = "";
                                                if (RefundType == 1)
                                                {
                                                    note   = "Đổi size";
                                                    typeRe = 8;
                                                }
                                                else if (RefundType == 2)
                                                {
                                                    note   = "Đổi sản phẩm";
                                                    typeRe = 9;
                                                }
                                                if (ProductType == 1)
                                                {
                                                    var product = ProductController.GetBySKU(sku);
                                                    if (product != null)
                                                    {
                                                        int    productID          = product.ID;
                                                        string ProductImageOrigin = "";
                                                        var    ProductImage       = ProductImageController.GetFirstByProductID(product.ID);
                                                        if (ProductImage != null)
                                                        {
                                                            ProductImageOrigin = ProductImage.ProductImage;
                                                        }
                                                        StockManagerController.Insert(
                                                            new tbl_StockManager {
                                                            AgentID           = AgentID,
                                                            ProductID         = productID,
                                                            ProductVariableID = 0,
                                                            Quantity          = quantity,
                                                            QuantityCurrent   = 0,
                                                            Type        = 1,
                                                            NoteID      = note,
                                                            OrderID     = orderID,
                                                            Status      = typeRe,
                                                            SKU         = sku,
                                                            CreatedDate = currentDate,
                                                            CreatedBy   = username,
                                                            MoveProID   = 0,
                                                            ParentID    = productID,
                                                        });
                                                    }
                                                }
                                                else
                                                {
                                                    string ProductVariableName  = "";
                                                    string ProductVariableValue = "";
                                                    string ProductVariable      = "";
                                                    int    parentID             = 0;
                                                    string parentSKU            = "";
                                                    string ProductImageOrigin   = "";
                                                    int    ID = 0;

                                                    var productvariable = ProductVariableController.GetBySKU(sku);
                                                    if (productvariable != null)
                                                    {
                                                        ID = productvariable.ID;
                                                        ProductImageOrigin = productvariable.Image;
                                                        parentSKU          = productvariable.ParentSKU;
                                                        var variables = ProductVariableValueController.GetByProductVariableID(productvariable.ID);
                                                        if (variables.Count > 0)
                                                        {
                                                            foreach (var v in variables)
                                                            {
                                                                ProductVariable      += v.VariableName.Trim() + ":" + v.VariableValue.Trim() + "|";
                                                                ProductVariableName  += v.VariableName + "|";
                                                                ProductVariableValue += v.VariableValue + "|";
                                                            }
                                                        }
                                                    }
                                                    if (!string.IsNullOrEmpty(parentSKU))
                                                    {
                                                        var product = ProductController.GetBySKU(parentSKU);
                                                        if (product != null)
                                                        {
                                                            parentID = product.ID;
                                                        }
                                                    }


                                                    StockManagerController.Insert(
                                                        new tbl_StockManager {
                                                        AgentID           = AgentID,
                                                        ProductID         = 0,
                                                        ProductVariableID = ID,
                                                        Quantity          = quantity,
                                                        QuantityCurrent   = 0,
                                                        Type        = 1,
                                                        NoteID      = note,
                                                        OrderID     = orderID,
                                                        Status      = typeRe,
                                                        SKU         = sku,
                                                        CreatedDate = currentDate,
                                                        CreatedBy   = username,
                                                        MoveProID   = 0,
                                                        ParentID    = parentID,
                                                    });
                                                }
                                            }
                                        }
                                        #endregion
                                    }

                                    RefundGoodController.updateQuantityCOGS(rID);

                                    PJUtils.ShowMessageBoxSwAlertCallFunction("Tạo đơn hàng đổi trả thành công", "s", true, "redirectTo(" + rID + ")", Page);
                                }
                            }
                        }
                    }
                }
            }
        }
Exemple #5
0
        public static string getProduct(string textsearch, int typeinout)
        {
            List <ProductGetOut> ps = new List <ProductGetOut>();
            string username         = HttpContext.Current.Request.Cookies["usernameLoginSystem"].Value;
            var    acc = AccountController.GetByUsername(username);

            if (acc != null)
            {
                int AgentID = Convert.ToInt32(acc.AgentID);
                if (typeinout == 1)
                {
                    var products = ProductController.GetByTextSearchIsHidden(textsearch.Trim(), false);
                    if (products.Count > 0)
                    {
                        foreach (var item in products)
                        {
                            var productvariable = ProductVariableController.GetProductID(item.ID);
                            if (productvariable.Count > 0)
                            {
                                foreach (var pv in productvariable)
                                {
                                    string SKU   = pv.SKU.Trim().ToUpper();
                                    var    check = StockManagerController.GetBySKU(AgentID, SKU);
                                    if (check.Count > 0)
                                    {
                                        double total = PJUtils.TotalProductQuantityInstock(AgentID, SKU);
                                        if (total > 0)
                                        {
                                            var variables = ProductVariableValueController.GetByProductVariableID(pv.ID);
                                            if (variables.Count > 0)
                                            {
                                                string variablename  = "";
                                                string variablevalue = "";
                                                string variable      = "";

                                                foreach (var v in variables)
                                                {
                                                    variable      += v.VariableName.Trim() + ":" + v.VariableValue.Trim() + "|";
                                                    variablename  += v.VariableName.Trim() + "|";
                                                    variablevalue += v.VariableValue.Trim() + "|";
                                                }

                                                ProductGetOut p = new ProductGetOut();
                                                p.ID                    = pv.ID;
                                                p.ProductName           = item.ProductTitle;
                                                p.ProductVariable       = variable;
                                                p.ProductVariableName   = variablename;
                                                p.ProductVariableValue  = variablevalue;
                                                p.ProductType           = 2;
                                                p.ProductImage          = "<img src=\"" + Thumbnail.getURL(pv.Image, Thumbnail.Size.Small) + "\" alt=\"\" style=\"width: 50px\" />";
                                                p.ProductImageOrigin    = Thumbnail.getURL(pv.Image, Thumbnail.Size.Small);
                                                p.QuantityInstock       = total;
                                                p.QuantityInstockString = string.Format("{0:N0}", total);
                                                p.SKU                   = SKU;
                                                int supplierID = 0;
                                                if (pv.SupplierID != null)
                                                {
                                                    supplierID = pv.SupplierID.ToString().ToInt(0);
                                                }
                                                p.SupplierID = supplierID;
                                                string supplierName = "";
                                                if (!string.IsNullOrEmpty(pv.SupplierName))
                                                {
                                                    supplierName = pv.SupplierName;
                                                }
                                                p.SupplierName = supplierName;
                                                ps.Add(p);
                                            }
                                        }
                                    }
                                }
                            }
                            else
                            {
                                string SKU   = item.ProductSKU.Trim().ToUpper();
                                var    check = StockManagerController.GetBySKU(AgentID, SKU);
                                if (check.Count > 0)
                                {
                                    double total = PJUtils.TotalProductQuantityInstock(AgentID, SKU);
                                    if (total > 0)
                                    {
                                        string variablename  = "";
                                        string variablevalue = "";
                                        string variable      = "";

                                        ProductGetOut p = new ProductGetOut();
                                        p.ID                   = item.ID;
                                        p.ProductName          = item.ProductTitle;
                                        p.ProductVariable      = variable;
                                        p.ProductVariableName  = variablename;
                                        p.ProductVariableValue = variablevalue;
                                        p.ProductType          = 1;
                                        var img = ProductImageController.GetFirstByProductID(item.ID);
                                        if (img != null)
                                        {
                                            p.ProductImage       = "<img src=\"" + Thumbnail.getURL(img.ProductImage, Thumbnail.Size.Small) + "\" alt=\"\" style=\"width: 50px\"  />";
                                            p.ProductImageOrigin = Thumbnail.getURL(img.ProductImage, Thumbnail.Size.Small);
                                        }
                                        else
                                        {
                                            p.ProductImage       = "";
                                            p.ProductImageOrigin = "";
                                        }
                                        p.QuantityInstock       = total;
                                        p.QuantityInstockString = string.Format("{0:N0}", total);
                                        p.SKU = SKU;
                                        int supplierID = 0;
                                        if (item.SupplierID != null)
                                        {
                                            supplierID = item.SupplierID.ToString().ToInt(0);
                                        }
                                        p.SupplierID = supplierID;
                                        string supplierName = "";
                                        if (!string.IsNullOrEmpty(item.SupplierName))
                                        {
                                            supplierName = item.SupplierName;
                                        }
                                        p.SupplierName = supplierName;
                                        ps.Add(p);
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    var products = ProductController.GetBySKU(textsearch);
                    if (products != null)
                    {
                        var productvariable = ProductVariableController.GetProductID(products.ID);
                        if (productvariable.Count > 0)
                        {
                            foreach (var pv in productvariable)
                            {
                                string SKU   = pv.SKU.Trim().ToUpper();
                                var    check = StockManagerController.GetBySKU(AgentID, SKU);
                                if (check.Count > 0)
                                {
                                    double total = PJUtils.TotalProductQuantityInstock(AgentID, SKU);

                                    if (total > 0)
                                    {
                                        var variables = ProductVariableValueController.GetByProductVariableID(pv.ID);
                                        if (variables.Count > 0)
                                        {
                                            string variablename  = "";
                                            string variablevalue = "";
                                            string variable      = "";

                                            foreach (var v in variables)
                                            {
                                                variable      += v.VariableName.Trim() + ":" + v.VariableValue.Trim() + "|";
                                                variablename  += v.VariableName.Trim() + "|";
                                                variablevalue += v.VariableValue.Trim() + "|";
                                            }

                                            ProductGetOut p = new ProductGetOut();
                                            p.ID                    = pv.ID;
                                            p.ProductName           = products.ProductTitle;
                                            p.ProductVariable       = variable;
                                            p.ProductVariableName   = variablename;
                                            p.ProductVariableValue  = variablevalue;
                                            p.ProductType           = 2;
                                            p.ProductImage          = "<img src=\"" + Thumbnail.getURL(pv.Image, Thumbnail.Size.Small) + "\" alt=\"\" style=\"width: 50px\"  />";
                                            p.ProductImageOrigin    = Thumbnail.getURL(pv.Image, Thumbnail.Size.Small);
                                            p.QuantityInstock       = total;
                                            p.QuantityInstockString = string.Format("{0:N0}", total);
                                            p.SKU                   = SKU;
                                            int supplierID = 0;
                                            if (pv.SupplierID != null)
                                            {
                                                supplierID = pv.SupplierID.ToString().ToInt(0);
                                            }
                                            p.SupplierID = supplierID;
                                            string supplierName = "";
                                            if (!string.IsNullOrEmpty(pv.SupplierName))
                                            {
                                                supplierName = pv.SupplierName;
                                            }
                                            p.SupplierName = supplierName;
                                            ps.Add(p);
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            string SKU   = products.ProductSKU.Trim().ToUpper();
                            var    check = StockManagerController.GetBySKU(AgentID, SKU);
                            if (check.Count > 0)
                            {
                                double total = PJUtils.TotalProductQuantityInstock(AgentID, SKU);
                                if (total > 0)
                                {
                                    string variablename  = "";
                                    string variablevalue = "";
                                    string variable      = "";

                                    ProductGetOut p = new ProductGetOut();
                                    p.ID                   = products.ID;
                                    p.ProductName          = products.ProductTitle;
                                    p.ProductVariable      = variable;
                                    p.ProductVariableName  = variablename;
                                    p.ProductVariableValue = variablevalue;
                                    p.ProductType          = 1;
                                    var img = ProductImageController.GetFirstByProductID(products.ID);
                                    if (img != null)
                                    {
                                        p.ProductImage       = "<img src=\"" + Thumbnail.getURL(img.ProductImage, Thumbnail.Size.Small) + "\" alt=\"\" style=\"width: 50px\"  />";
                                        p.ProductImageOrigin = Thumbnail.getURL(img.ProductImage, Thumbnail.Size.Small);
                                    }
                                    else
                                    {
                                        p.ProductImage       = "";
                                        p.ProductImageOrigin = "";
                                    }
                                    p.SKU                   = SKU;
                                    p.QuantityInstock       = total;
                                    p.QuantityInstockString = string.Format("{0:N0}", total);
                                    int supplierID = 0;
                                    if (products.SupplierID != null)
                                    {
                                        supplierID = products.SupplierID.ToString().ToInt(0);
                                    }
                                    p.SupplierID = supplierID;
                                    string supplierName = "";
                                    if (!string.IsNullOrEmpty(products.SupplierName))
                                    {
                                        supplierName = products.SupplierName;
                                    }
                                    p.SupplierName = supplierName;
                                    ps.Add(p);
                                }
                            }
                        }
                    }
                    else
                    {
                        var productvariable = ProductVariableController.GetBySKU(textsearch);
                        if (productvariable != null)
                        {
                            string SKU   = productvariable.SKU.Trim().ToUpper();
                            var    check = StockManagerController.GetBySKU(AgentID, SKU);
                            if (check.Count > 0)
                            {
                                double total = PJUtils.TotalProductQuantityInstock(AgentID, SKU);
                                if (total > 0)
                                {
                                    var variables = ProductVariableValueController.GetByProductVariableID(productvariable.ID);

                                    if (variables.Count > 0)
                                    {
                                        string variablename  = "";
                                        string variablevalue = "";
                                        string variable      = "";

                                        foreach (var v in variables)
                                        {
                                            variable      += v.VariableName + ":" + v.VariableValue + "|";
                                            variablename  += v.VariableName + "|";
                                            variablevalue += v.VariableValue + "|";
                                        }

                                        ProductGetOut p = new ProductGetOut();
                                        p.ID = productvariable.ID;
                                        var product = ProductController.GetByID(Convert.ToInt32(productvariable.ProductID));
                                        if (product != null)
                                        {
                                            p.ProductName = product.ProductTitle;
                                        }
                                        p.ProductVariable      = variable;
                                        p.ProductVariableName  = variablename;
                                        p.ProductVariableValue = variablevalue;
                                        p.ProductType          = 2;
                                        p.ProductImage         = "<img src=\"" + Thumbnail.getURL(productvariable.Image, Thumbnail.Size.Small) + "\" alt=\"\" style=\"width:50px;\" />";
                                        p.ProductImageOrigin   = Thumbnail.getURL(productvariable.Image, Thumbnail.Size.Small);
                                        p.SKU                   = productvariable.SKU.Trim().ToUpper();
                                        p.QuantityInstock       = total;
                                        p.QuantityInstockString = string.Format("{0:N0}", total);
                                        int supplierID = 0;
                                        if (productvariable.SupplierID != null)
                                        {
                                            supplierID = productvariable.SupplierID.ToString().ToInt(0);
                                        }
                                        p.SupplierID = supplierID;
                                        string supplierName = "";
                                        if (!string.IsNullOrEmpty(productvariable.SupplierName))
                                        {
                                            supplierName = productvariable.SupplierName;
                                        }
                                        p.SupplierName = supplierName;
                                        ps.Add(p);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            JavaScriptSerializer serializer = new JavaScriptSerializer();

            return(serializer.Serialize(ps));
        }