Ejemplo n.º 1
0
        private static ProductGetOut _getProduct(int warehouse, tbl_Product product)
        {
            var quantity  = PJUtils.TotalProductQuantityInstock(1, product.ProductSKU);
            var quantity2 = StockManagerController.getQuantityStock2BySKU(product.ProductSKU);

            if (warehouse == 1 && quantity == 0)
            {
                return(null);
            }

            if (warehouse == 2 && (!quantity2.HasValue && quantity2.Value == 0))
            {
                return(null);
            }

            var result = new ProductGetOut()
            {
                ID                   = product.ID,
                ProductName          = product.ProductTitle,
                ProductVariable      = String.Empty,
                ProductVariableName  = String.Empty,
                ProductVariableValue = String.Empty,
                ProductStyle         = 1,
                ProductImage         = Thumbnail.getURL(product.ProductImage, Thumbnail.Size.Normal),
                ProductImageOrigin   = Thumbnail.getURL(product.ProductImage, Thumbnail.Size.Source),
                SKU                  = product.ProductSKU.Trim().ToUpper(),
                WarehouseQuantity    = String.Format("{0:N0}", quantity),
                WarehouseQuantity2   = String.Format("{0:N0}", quantity2),
                ParentID             = product.ID,
                ParentSKU            = product.ProductSKU
            };

            return(result);
        }
Ejemplo n.º 2
0
        private static ProductGetOut _getProduct(tbl_Product product)
        {
            var quantity = StockManagerController.getQuantityStock2BySKU(product.ProductSKU);

            if (!quantity.HasValue || quantity.Value == 0)
            {
                return(null);
            }

            var result = new ProductGetOut()
            {
                ID                   = product.ID,
                ProductName          = product.ProductTitle,
                ProductVariable      = String.Empty,
                ProductVariableName  = String.Empty,
                ProductVariableValue = String.Empty,
                ProductStyle         = 1,
                ProductImage         = Thumbnail.getURL(product.ProductImage, Thumbnail.Size.Normal),
                ProductImageOrigin   = Thumbnail.getURL(product.ProductImage, Thumbnail.Size.Source),
                SKU                  = product.ProductSKU.Trim().ToUpper(),
                SupplierID           = product.SupplierID.HasValue ? product.SupplierID.Value : 0,
                SupplierName         = String.IsNullOrEmpty(product.SupplierName) ? String.Empty : product.SupplierName,
                WarehouseQuantity    = string.Format("{0:N0}", quantity),
                ParentID             = product.ID,
                ParentSKU            = product.ProductSKU
            };

            return(result);
        }
Ejemplo n.º 3
0
        public static double TotalProductQuantityInstockBySKU(string SKU)
        {
            double currentQuantity = 0;
            var    ps = StockManagerController.GetBySKU(SKU);

            if (ps.Count > 0)
            {
                double quantity_pIn  = 0;
                double quantity_pOut = 0;

                var ps_in = ps.Where(p => p.Type == 1).ToList();
                if (ps_in.Count > 0)
                {
                    foreach (var p in ps_in)
                    {
                        quantity_pIn += Convert.ToDouble(p.Quantity);
                    }
                }
                var ps_out = ps.Where(p => p.Type == 2).ToList();
                if (ps_out.Count > 0)
                {
                    foreach (var p in ps_out)
                    {
                        quantity_pOut += Convert.ToDouble(p.Quantity);
                    }
                }
                if (quantity_pIn > quantity_pOut)
                {
                    currentQuantity = quantity_pIn - quantity_pOut;
                }
            }
            return(currentQuantity);
        }
Ejemplo n.º 4
0
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            try
            {
                RefundGoodDetailController.DeleteByRefundGoodsID(_refundGood.RefundGoodsID);
                RefundGoodController.DeleteByID(_refundGood.RefundGoodsID);
                int OrderSaleID = OrderController.DeleteOrderRefund(_refundGood.RefundGoodsID);
                if (OrderSaleID > 0)
                {
                    _refundGood.OrderSaleID = OrderSaleID;
                }

                foreach (var product in _refundGood.RefundDetails)
                {
                    if (!string.IsNullOrEmpty(product.ChildSKU))
                    {
                        var    ProductVariable = ProductVariableValueController.GetByProductVariableSKU(product.ChildSKU);
                        string VariableValue   = "";
                        if (ProductVariable.Count > 0)
                        {
                            foreach (var v in ProductVariable)
                            {
                                VariableValue += v.VariableName.Trim() + ": " + v.VariableValue.Trim() + "|";
                            }
                        }
                        product.VariableValue = VariableValue;
                    }

                    if (product.ChangeType != 3) // Change product error
                    {
                        StockManagerController.Insert(new tbl_StockManager()
                        {
                            AgentID           = 1,
                            ProductID         = product.ProductStyle == 1 ? product.ProductID : 0,
                            ProductVariableID = product.ProductVariableID,
                            Quantity          = product.QuantityRefund,
                            QuantityCurrent   = 0,
                            Type        = 1,
                            NoteID      = "Xuất kho do làm lại đơn hàng đổi trả",
                            OrderID     = product.OrderID,
                            Status      = 11,
                            SKU         = product.ProductStyle == 1 ? product.ParentSKU : product.ChildSKU,
                            CreatedDate = DateTime.Now,
                            CreatedBy   = _refundGood.CreateBy,
                            MoveProID   = 0,
                            ParentID    = product.ProductID,
                        });
                    }
                }

                HttpContext.Current.Items.Add("xem-don-hang-doi-tra", JsonConvert.SerializeObject(_refundGood));
                Server.Transfer("tao-don-hang-doi-tra.aspx");
            }
            catch (Exception)
            {
                throw;
            }
        }
Ejemplo n.º 5
0
        private static List <ProductGetOut> _getProductVariation(List <tbl_ProductVariable> variations, tbl_Product product = null)
        {
            var result = new List <ProductGetOut>();

            if (variations == null || variations.Count() == 0)
            {
                return(result);
            }

            if (product == null)
            {
                product = ProductController.GetBySKU(variations.FirstOrDefault().ParentSKU);
            }

            foreach (var variation in variations)
            {
                var attributes = ProductVariableValueController.GetByProductVariableSKU(variation.SKU);

                if (attributes.Count == 0)
                {
                    continue;
                }

                var variable      = String.Empty;
                var variablename  = String.Empty;
                var variablevalue = String.Empty;

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

                var quantity = StockManagerController.getQuantityStock2BySKU(variation.SKU);
                var item     = new ProductGetOut()
                {
                    ID                   = variation.ID,
                    ProductName          = product.ProductTitle,
                    ProductVariable      = variable,
                    ProductVariableName  = variablename,
                    ProductVariableValue = variablevalue,
                    ProductStyle         = 2,
                    ProductImage         = Thumbnail.getURL(variation.Image, Thumbnail.Size.Normal),
                    ProductImageOrigin   = Thumbnail.getURL(variation.Image, Thumbnail.Size.Source),
                    SKU                  = variation.SKU.Trim().ToUpper(),
                    SupplierID           = product.SupplierID.HasValue ? product.SupplierID.Value : 0,
                    SupplierName         = String.IsNullOrEmpty(product.SupplierName) ? String.Empty : product.SupplierName,
                    WarehouseQuantity    = string.Format("{0:N0}", quantity),
                    ParentID             = product.ID,
                    ParentSKU            = product.ProductSKU
                };
                result.Add(item);
            }

            return(result);
        }
Ejemplo n.º 6
0
        public void GetStockProduct(string username, string password)
        {
            if (Login(username, password))
            {
                var StockManager = StockManagerController.GetStockAll();

                if (StockManager.Count > 0)
                {
                    var dataToExportToCSV = StockManager.Select(x =>
                    {
                        var quantityCurrent = 0D;

                        if (x.Type == 1)
                        {
                            quantityCurrent = x.QuantityCurrent.Value + x.Quantity.Value;
                        }
                        else
                        {
                            quantityCurrent = x.QuantityCurrent.Value - x.Quantity.Value;
                        }

                        return(new StockManager()
                        {
                            SKU = x.SKU,
                            Quantity = quantityCurrent,
                        });
                    }).ToList();

                    string attachment = String.Format("attachment; filename={0}_stock-product.csv", DateTime.Now.ToString("yyyyMMddHHmmss"));
                    HttpContext.Current.Response.Clear();
                    HttpContext.Current.Response.ClearHeaders();
                    HttpContext.Current.Response.ClearContent();
                    HttpContext.Current.Response.AddHeader("content-disposition", attachment);
                    HttpContext.Current.Response.ContentType = "text/csv";
                    HttpContext.Current.Response.AddHeader("Pragma", "public");
                    HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;

                    var sb = new StringBuilder();
                    sb.AppendLine("sku, stock, stock_status, manage_stock");
                    foreach (var line in dataToExportToCSV)
                    {
                        var    Product   = ProductController.GetBySKU(line.SKU);
                        string parentSKU = "";
                        if (Product != null)
                        {
                            parentSKU = Product.ProductSKU;
                            sb.AppendLine(String.Format("{0}, {1}, {2}, {3}", line.SKU, line.Quantity, line.Quantity > 0 ? "instock" : "outofstock", "yes"));
                        }
                    }

                    HttpContext.Current.Response.Write(sb.ToString());
                }
            }
        }
Ejemplo n.º 7
0
        public static string StockStatusBySKU(int AgentID, string SKU)
        {
            double currentQuantity = 0;
            var    ps = StockManagerController.GetBySKU(AgentID, SKU).OrderByDescending(x => x.CreatedDate).FirstOrDefault();

            if (ps != null)
            {
                double quantity        = 0;
                double quantityCurrent = 0;

                if (ps.Quantity.HasValue)
                {
                    quantity = ps.Quantity.Value;
                }

                if (ps.QuantityCurrent.HasValue)
                {
                    quantityCurrent = ps.QuantityCurrent.Value;
                }

                switch (ps.Type)
                {
                case 1:
                    currentQuantity = quantityCurrent + quantity;
                    break;

                case 2:
                    currentQuantity = quantityCurrent - quantity;
                    break;

                default:
                    currentQuantity = 0;
                    break;
                }
                if (currentQuantity > 0)
                {
                    return("<span class=\"bg-green\">Còn hàng</span>");
                }
                else
                {
                    return("<span class=\"bg-red\">Hết hàng</span>");
                }
            }
            else
            {
                return("<span class=\"bg-yellow\">Nhập hàng</span>");
            }
        }
Ejemplo n.º 8
0
        public static double GetSotckProduct(int AgentID, string SKU)
        {
            double currentQuantity = 0;
            var    ps = StockManagerController.GetBySKU(AgentID, SKU).OrderByDescending(x => x.CreatedDate).FirstOrDefault();

            if (ps != null)
            {
                double quantity        = 0;
                double quantityCurrent = 0;

                if (ps.Quantity.HasValue)
                {
                    quantity = ps.Quantity.Value;
                }

                if (ps.QuantityCurrent.HasValue)
                {
                    quantityCurrent = ps.QuantityCurrent.Value;
                }

                switch (ps.Type)
                {
                case 1:
                    currentQuantity = quantityCurrent + quantity;
                    break;

                case 2:
                    currentQuantity = quantityCurrent - quantity;
                    break;

                default:
                    currentQuantity = 0;
                    break;
                }
            }
            else
            {
                currentQuantity = -1;
            }

            return(currentQuantity);
        }
Ejemplo n.º 9
0
        public static double ProductQuantityOutstock(int AgentID, string SKU)
        {
            double currentQuantity = 0;
            var    ps = StockManagerController.GetBySKU(AgentID, SKU);

            if (ps.Count > 0)
            {
                double quantity_pOut = 0;
                var    ps_out        = ps.Where(p => p.Type == 2).ToList();
                if (ps_out.Count > 0)
                {
                    foreach (var p in ps_out)
                    {
                        quantity_pOut += Convert.ToDouble(p.Quantity);
                    }
                }
                currentQuantity = quantity_pOut;
            }
            return(currentQuantity);
        }
Ejemplo n.º 10
0
        protected void btnImport_Click(object sender, EventArgs e)
        {
            DateTime currentDate = DateTime.Now;
            string   username    = Request.Cookies["usernameLoginSystem"].Value;
            var      acc         = AccountController.GetByUsername(username);

            if (acc != null)
            {
                int    AgentID = Convert.ToInt32(acc.AgentID);
                string note    = "Nhập kho 2 bằng chức năng nhập kho 2";
                var    data    = String.IsNullOrEmpty(hdfvalue.Value) ?
                                 new List <WarehousePostModel>() :
                                 JsonConvert.DeserializeObject <List <WarehousePostModel> >(hdfvalue.Value);

                foreach (var item in data)
                {
                    var stock2 = StockManagerController.warehousing2(new StockManager2()
                    {
                        AgentID           = AgentID,
                        ProductID         = item.productID,
                        ProductVariableID = item.productVariableID,
                        SKU             = item.sku,
                        ParentSKU       = item.parentSKU,
                        Type            = 1,
                        Quantity        = item.quantity,
                        QuantityCurrent = item.quantityCurrent,
                        Status          = 16,
                        Note            = note,
                        CreatedDate     = currentDate,
                        CreatedBy       = username,
                        ModifiedDate    = currentDate,
                        ModifiedBy      = username,
                    });

                    StockManagerController.warehousing1(stock2);
                }

                PJUtils.ShowMessageBoxSwAlert("Nhập kho 2 thành công!", "s", true, Page);
            }
        }
Ejemplo n.º 11
0
        protected void txtProductSKU_Changed(object sender, EventArgs e)
        {
            var productSKU = txtProductSKU.Text.Trim().ToUpper();

            if (!String.IsNullOrEmpty(productSKU))
            {
                if (productSKU != _productSKU)
                {
                    var product = ProductController.GetBySKU(txtProductSKU.Text.Trim().ToLower());

                    if (product != null)
                    {
                        txtProductSKU.Text = ViewState["SKU"].ToString();
                        PJUtils.ShowMessageBoxSwAlert(String.Format("Mã #SKU - {0} đã tồn tại", productSKU), "e", false, Page);
                        return;
                    }
                }

                var stocks = StockManagerController.warehousing1ByParentSKU(_productSKU);

                if (stocks.Count > 0)
                {
                    txtProductSKU.Text = ViewState["SKU"].ToString();
                    PJUtils.ShowMessageBoxSwAlert(String.Format("Sản phẩm #{0} đã tạo mã vạch nhập kho rồi nên không thể sửa", ViewState["SKU"]), "i", false, Page);
                    return;
                }

                var skuOld = ViewState["SKU"].ToString().Trim().ToUpper();
                var skuNew = productSKU;

                ViewState["SKU"] = productSKU;
                JavaScript.AfterPageLoad(Page).ExecuteCustomScript("updateVariationSKUA('{0}', '{1}');", new object[] { skuOld, skuNew });
            }
            else
            {
                txtProductSKU.Text = ViewState["SKU"].ToString();
                PJUtils.ShowMessageBoxSwAlert("Bạn đã quên nhập mã sản phẩm. Tôi đã lấy mã sản phẩm củ cho bạn", "i", false, Page);
            }
        }
        protected void btnOrder_Click(object sender, EventArgs e)
        {
            DateTime currentDate = DateTime.Now;
            string   username    = Request.Cookies["userLoginSystem"].Value;
            var      acc         = AccountController.GetByUsername(username);

            if (acc != null)
            {
                if (acc.RoleID == 0 || acc.RoleID == 2)
                {
                    int OrderID = ViewState["ID"].ToString().ToInt(0);
                    if (OrderID > 0)
                    {
                        var order = OrderController.GetByID(OrderID);

                        if (order != null)
                        {
                            int ExcuteStatusOld = Convert.ToInt32(order.ExcuteStatus);

                            string OrderNote = txtOrderNote.Text;

                            // Xử lý nhập kho khi chuyển hoàn
                            if (ExcuteStatusOld != 4)
                            {
                                var orderDetails = OrderDetailController.GetByOrderID(order.ID);

                                foreach (tbl_OrderDetail product in orderDetails)
                                {
                                    int parentID = 0;

                                    if (product.ProductID != 0)
                                    {
                                        parentID = product.ProductID.Value;
                                    }
                                    else
                                    {
                                        parentID = ProductVariableController.GetByID(product.ProductVariableID.Value).ProductID.Value;
                                    }

                                    StockManagerController.Insert(
                                        new tbl_StockManager
                                    {
                                        AgentID           = product.AgentID,
                                        ProductID         = product.ProductID,
                                        ProductVariableID = product.ProductVariableID,
                                        Quantity          = product.Quantity,
                                        QuantityCurrent   = 0,
                                        Type        = 1,
                                        NoteID      = "Nhập kho do chuyển hoàn đơn " + product.OrderID,
                                        OrderID     = product.OrderID,
                                        Status      = 13,
                                        SKU         = product.SKU,
                                        CreatedDate = currentDate,
                                        CreatedBy   = product.CreatedBy,
                                        MoveProID   = 0,
                                        ParentID    = parentID
                                    });
                                }
                            }

                            bool updateOrder = OrderController.UpdateExcuteStatus4(order.ID, username, OrderNote);

                            if (updateOrder == true)
                            {
                                Response.Redirect("/thong-tin-don-hang-chuyen-hoan?id=" + order.ID);
                            }
                            else
                            {
                                PJUtils.ShowMessageBoxSwAlertCallFunction("Đã xảy ra lỗi", "s", true, "payAllClicked()", Page);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 13
0
        public static string getAllCategoryImage(double productPrice = 0)
        {
            List <string> result = new List <string>();

            string rootPath          = HostingEnvironment.ApplicationPhysicalPath;
            string uploadsImagesPath = rootPath + "/uploads/images/";

            using (var dbe = new inventorymanagementEntities())
            {
                var products = dbe.tbl_Product.Where(p => p.CategoryID == 44).OrderByDescending(o => o.ID).ToList();
                if (productPrice > 0)
                {
                    products = products.Where(p => p.Regular_Price == productPrice).ToList();
                }
                else if (productPrice == -1)
                {
                    products = products.Where(p => p.Regular_Price != 30000 && p.Regular_Price != 35000 && p.Regular_Price != 49000 && p.Regular_Price != 135000).ToList();
                }

                if (products != null)
                {
                    List <string> images = new List <string>();

                    foreach (var item in products)
                    {
                        var    stock    = StockManagerController.getStock(item.ID, 0);
                        double quantity = 0;
                        if (stock.Count > 0)
                        {
                            quantity = stock
                                       .Select(s => s.Type == 2 ? (s.QuantityCurrent.Value - s.Quantity.Value) : (s.QuantityCurrent.Value + s.Quantity.Value))
                                       .Sum(s => s);
                        }

                        // Chỉ lấy ảnh sản phẩm còn hàng
                        if (quantity >= 3)
                        {
                            // lấy ảnh đại diện
                            string imgAdd = item.ProductImage;
                            if (File.Exists(uploadsImagesPath + imgAdd))
                            {
                                images.Add(imgAdd);
                            }

                            // lấy ảnh sản phẩm từ thư viện
                            var imageProduct = ProductImageController.GetByProductID(item.ID);
                            if (imageProduct != null)
                            {
                                foreach (var img in imageProduct)
                                {
                                    imgAdd = img.ProductImage;
                                    if (File.Exists(uploadsImagesPath + imgAdd))
                                    {
                                        images.Add(imgAdd);
                                    }
                                }
                            }

                            // lấy ảnh sản phẩm từ biến thể
                            var variable = ProductVariableController.GetByParentSKU(item.ProductSKU);
                            if (variable != null)
                            {
                                foreach (var v in variable)
                                {
                                    if (!String.IsNullOrEmpty(v.Image))
                                    {
                                        imgAdd = v.Image;
                                        if (File.Exists(uploadsImagesPath + imgAdd))
                                        {
                                            images.Add(imgAdd);
                                        }
                                    }
                                }
                            }
                        }
                    }

                    images = images.Distinct().ToList();

                    if (images.Count() > 0)
                    {
                        // lấy hình gốc
                        for (int i = 0; i < images.Count; i++)
                        {
                            result.Add(Thumbnail.getURL(images[i], Thumbnail.Size.Source));
                        }
                    }
                }
            }

            JavaScriptSerializer serializer = new JavaScriptSerializer();

            return(serializer.Serialize(result.ToList()));
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            DateTime currentDate = DateTime.Now;
            int      agentID     = 0;
            string   username    = Request.Cookies["userLoginSystem"].Value;

            if (!string.IsNullOrEmpty(username))
            {
                var a = AccountController.GetByUsername(username);

                if (a != null)
                {
                    // Change user
                    string RefundNote = "";
                    if (username != hdfUsernameCurrent.Value)
                    {
                        RefundNote = "Được tạo giúp bởi " + username;
                        username   = hdfUsernameCurrent.Value;
                    }

                    agentID = Convert.ToInt32(a.AgentID);

                    string CustomerPhone   = txtPhone.Text;
                    string CustomerName    = txtFullname.Text;
                    string Nick            = txtNick.Text.Trim();
                    string CustomerAddress = txtAddress.Text.Trim();
                    string Zalo            = txtZalo.Text.Trim();
                    string Facebook        = txtFacebook.Text.Trim();

                    if (!string.IsNullOrEmpty(CustomerPhone))
                    {
                        var checkCustomer = CustomerController.GetByPhone(CustomerPhone);

                        if (checkCustomer != null)
                        {
                            int custID = checkCustomer.ID;

                            string kq = CustomerController.Update(custID, CustomerName, checkCustomer.CustomerPhone, CustomerAddress, "", Convert.ToInt32(checkCustomer.CustomerLevelID), Convert.ToInt32(checkCustomer.Status), checkCustomer.CreatedBy, currentDate, username, false, Zalo, Facebook, checkCustomer.Note, checkCustomer.ProvinceID.ToString(), Nick, checkCustomer.Avatar, Convert.ToInt32(checkCustomer.ShippingType), Convert.ToInt32(checkCustomer.PaymentType), Convert.ToInt32(checkCustomer.TransportCompanyID), Convert.ToInt32(checkCustomer.TransportCompanySubID), checkCustomer.CustomerPhone2);

                            double totalPrice    = Convert.ToDouble(hdfTotalPrice.Value);
                            double totalQuantity = Convert.ToDouble(hdfTotalQuantity.Value);
                            double totalRefund   = Convert.ToDouble(hdfTotalRefund.Value);
                            var    agent         = AgentController.GetByID(agentID);
                            string agentName     = String.Empty;

                            if (agent != null)
                            {
                                agentName = agent.AgentName;
                            }

                            //insert ddlstatus, refundnote
                            int status = ddlRefundStatus.SelectedValue.ToInt();
                            RefundNote += ". " + txtRefundsNote.Text;
                            int rID = RefundGoodController.Insert(
                                new tbl_RefundGoods()
                            {
                                AgentID        = agentID,
                                TotalPrice     = totalPrice.ToString(),
                                Status         = status,
                                CustomerID     = custID,
                                TotalQuantity  = totalQuantity,
                                TotalRefundFee = totalRefund.ToString(),
                                CreatedDate    = currentDate,
                                CreatedBy      = username,
                                CustomerName   = checkCustomer.CustomerName,
                                CustomerPhone  = checkCustomer.CustomerPhone,
                                AgentName      = agentName,
                                RefundNote     = RefundNote
                            });

                            if (rID > 0)
                            {
                                RefundGoodModel refundModel = JsonConvert.DeserializeObject <RefundGoodModel>(hdfListProduct.Value);

                                int t    = 0;
                                int time = 0;
                                foreach (RefundDetailModel item in refundModel.RefundDetails)
                                {
                                    t++;
                                    time += 20;
                                    int rdID = RefundGoodDetailController.Insert(
                                        new tbl_RefundGoodsDetails()
                                    {
                                        RefundGoodsID           = rID,
                                        AgentID                 = agentID,
                                        OrderID                 = 0,
                                        ProductName             = item.ProductTitle,
                                        CustomerID              = custID,
                                        SKU                     = item.ProductStyle == 1 ? item.ParentSKU : item.ChildSKU,
                                        Quantity                = item.QuantityRefund,
                                        QuantityMax             = item.QuantityRefund,
                                        PriceNotFeeRefund       = (item.QuantityRefund * item.ReducedPrice).ToString(),
                                        ProductType             = item.ProductStyle,
                                        IsCount                 = true,
                                        RefundType              = item.ChangeType,
                                        RefundFeePerProduct     = item.ChangeType == 2 ? item.FeeRefund.ToString() : "0",
                                        TotalRefundFee          = item.ChangeType == 2 ? (item.FeeRefund * item.QuantityRefund).ToString() : "0",
                                        GiavonPerProduct        = item.Price.ToString(),
                                        DiscountPricePerProduct = (item.Price - item.ReducedPrice).ToString(),
                                        SoldPricePerProduct     = item.ReducedPrice.ToString(),
                                        TotalPriceRow           = item.TotalFeeRefund.ToString(),
                                        CreatedDate             = currentDate.AddMilliseconds(time),
                                        CreatedBy               = username
                                    });

                                    if (rdID > 0)
                                    {
                                        if (item.ChangeType < 3)
                                        {
                                            int    typeRe = 0;
                                            string note   = "";

                                            if (item.ChangeType == 1)
                                            {
                                                note   = "Đổi size đơn " + rdID;
                                                typeRe = 8;
                                            }
                                            else if (item.ChangeType == 2)
                                            {
                                                note   = "Đổi sản phẩm khác đơn " + rdID;
                                                typeRe = 9;
                                            }

                                            if (item.ChangeType == 1 || item.ChangeType == 2)
                                            {
                                                StockManagerController.Insert(
                                                    new tbl_StockManager
                                                {
                                                    AgentID           = agentID,
                                                    ProductID         = item.ProductStyle == 1 ? item.ProductID : 0,
                                                    ProductVariableID = item.ProductVariableID,
                                                    Quantity          = item.QuantityRefund,
                                                    QuantityCurrent   = 0,
                                                    Type        = 1,
                                                    NoteID      = note,
                                                    OrderID     = 0,
                                                    Status      = typeRe,
                                                    SKU         = item.ProductStyle == 1 ? item.ParentSKU : item.ChildSKU,
                                                    CreatedDate = currentDate.AddMilliseconds(time),
                                                    CreatedBy   = username,
                                                    MoveProID   = 0,
                                                    ParentID    = item.ProductID,
                                                });
                                            }
                                        }
                                    }
                                    PJUtils.ShowMessageBoxSwAlertCallFunction("Tạo đơn hàng đổi trả thành công", "s", true, "redirectTo(" + rID + ")", Page);
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 15
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);
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 16
0
        protected void btnOrder_Click(object sender, EventArgs e)
        {
            DateTime currentDate = DateTime.Now;
            string   username    = Request.Cookies["userLoginSystem"].Value;
            var      acc         = AccountController.GetByUsername(username);

            if (acc != null)
            {
                if (acc.RoleID == 0 || acc.RoleID == 2)
                {
                    int    AgentID     = Convert.ToInt32(acc.AgentID);
                    int    OrderType   = hdfOrderType.Value.ToInt();
                    string AdditionFee = "0";
                    string DisCount    = "0";
                    int    CustomerID  = 0;

                    string CustomerPhone   = txtPhone.Text.Trim().Replace(" ", "");
                    string CustomerName    = txtFullname.Text.Trim();
                    string Nick            = txtNick.Text.Trim();
                    string CustomerAddress = txtAddress.Text.Trim();
                    string Zalo            = txtZalo.Text.Trim();
                    string Facebook        = txtFacebook.Text.Trim();
                    int    PaymentStatus   = hdfPaymentStatus.Value.ToInt(1);
                    int    ExcuteStatus    = hdfExcuteStatus.Value.ToInt(1);
                    int    PaymentType     = hdfPaymentType.Value.ToInt(1);
                    int    ShippingType    = hdfShippingType.Value.ToInt(1);

                    var checkCustomer = CustomerController.GetByPhone(CustomerPhone);

                    if (checkCustomer != null)
                    {
                        CustomerID = checkCustomer.ID;
                        string kq = CustomerController.Update(CustomerID, CustomerName, checkCustomer.CustomerPhone, CustomerAddress, "", Convert.ToInt32(checkCustomer.CustomerLevelID), Convert.ToInt32(checkCustomer.Status), checkCustomer.CreatedBy, currentDate, username, false, Zalo, Facebook, checkCustomer.Note, checkCustomer.ProvinceID.ToString(), Nick, checkCustomer.Avatar, Convert.ToInt32(checkCustomer.ShippingType), Convert.ToInt32(checkCustomer.PaymentType), Convert.ToInt32(checkCustomer.TransportCompanyID), Convert.ToInt32(checkCustomer.TransportCompanySubID), checkCustomer.CustomerPhone2);
                    }
                    else
                    {
                        string kq = CustomerController.Insert(CustomerName, CustomerPhone, CustomerAddress, "", 0, 0, currentDate, username, false, Zalo, Facebook, "", "", Nick, "", ShippingType, PaymentType);
                        if (kq.ToInt(0) > 0)
                        {
                            CustomerID = kq.ToInt();
                        }
                    }

                    var Customer = CustomerController.GetByID(CustomerID);

                    int TransportCompanyID    = 0;
                    int TransportCompanySubID = 0;
                    if (Customer.ShippingType == ShippingType)
                    {
                        TransportCompanyID    = Convert.ToInt32(Customer.TransportCompanyID);
                        TransportCompanySubID = Convert.ToInt32(Customer.TransportCompanySubID);
                    }

                    string totalPrice            = hdfTotalPrice.Value.ToString();
                    string totalPriceNotDiscount = hdfTotalPriceNotDiscount.Value;


                    double DiscountPerProduct = Convert.ToDouble(pDiscount.Value);

                    double TotalDiscount = Convert.ToDouble(pDiscount.Value) * Convert.ToDouble(hdfTotalQuantity.Value);
                    string FeeShipping   = pFeeShip.Value.ToString();

                    string OtherFeeName  = txtOtherFeeName.Text;
                    double OtherFeeValue = Convert.ToDouble(pOtherFee.Value);

                    bool IsHidden = false;
                    int  WayIn    = 1;

                    string datedone = "";

                    if (ExcuteStatus == 2)
                    {
                        datedone = DateTime.Now.ToString();
                    }

                    var ret = OrderController.Insert(AgentID, OrderType, AdditionFee, DisCount, CustomerID, CustomerName, CustomerPhone, CustomerAddress,
                                                     "", totalPrice, totalPriceNotDiscount, PaymentStatus, ExcuteStatus, IsHidden, WayIn, currentDate, username, Convert.ToDouble(pDiscount.Value),
                                                     TotalDiscount, FeeShipping, PaymentType, ShippingType, datedone, 0, 0, TransportCompanyID, TransportCompanySubID, OtherFeeName, OtherFeeValue, 1);

                    int OrderID = ret.ID;

                    double totalQuantity = 0;
                    if (OrderID > 0)
                    {
                        string   list  = hdfListProduct.Value;
                        string[] items = list.Split(';');
                        if (items.Length - 1 > 0)
                        {
                            for (int i = 0; i < items.Length - 1; i++)
                            {
                                var      item      = items[i];
                                string[] itemValue = item.Split(',');

                                int    ProductID         = itemValue[0].ToInt();
                                int    ProductVariableID = itemValue[11].ToInt();
                                string SKU         = itemValue[1].ToString();
                                int    ProductType = itemValue[2].ToInt();

                                // Tìm parentID
                                int parentID = ProductID;
                                var variable = ProductVariableController.GetByID(ProductVariableID);
                                if (variable != null)
                                {
                                    parentID = Convert.ToInt32(variable.ProductID);
                                }

                                string ProductVariableName  = itemValue[3];
                                string ProductVariableValue = itemValue[4];
                                double Quantity             = Convert.ToDouble(itemValue[5]);
                                string ProductName          = itemValue[6];
                                string ProductImageOrigin   = itemValue[7];
                                string ProductVariable      = itemValue[8];
                                double Price = Convert.ToDouble(itemValue[9]);
                                string ProductVariableSave = itemValue[10];

                                OrderDetailController.Insert(AgentID, OrderID, SKU, ProductID, ProductVariableID, ProductVariableSave, Quantity, Price, 1, 0,
                                                             ProductType, currentDate, username, true);

                                StockManagerController.Insert(
                                    new tbl_StockManager
                                {
                                    AgentID           = AgentID,
                                    ProductID         = ProductID,
                                    ProductVariableID = ProductVariableID,
                                    Quantity          = Quantity,
                                    QuantityCurrent   = 0,
                                    Type        = 2,
                                    NoteID      = "Xuất kho khi tạo đơn",
                                    OrderID     = OrderID,
                                    Status      = 3,
                                    SKU         = SKU,
                                    CreatedDate = currentDate,
                                    CreatedBy   = username,
                                    MoveProID   = 0,
                                    ParentID    = parentID,
                                });
                                totalQuantity += Quantity;
                            }
                        }

                        string refund = Request.Cookies["refundt"].Value;
                        if (refund != "1")
                        {
                            string[] RefundID = refund.Split('|');
                            var      update   = RefundGoodController.UpdateStatus(RefundID[0].ToInt(), username, 2, OrderID);
                            var      updateor = OrderController.UpdateRefund(OrderID, RefundID[0].ToInt(), username);
                        }

                        Response.Cookies["refundt"].Expires = DateTime.Now.AddDays(-1d);
                        Response.Cookies.Add(Response.Cookies["refundt"]);

                        PJUtils.ShowMessageBoxSwAlertCallFunction("Tạo đơn hàng thành công", "s", true, "redirectTo(" + OrderID + ")", Page);
                    }
                }
            }
        }
Ejemplo n.º 17
0
        protected void btnImport_Click(object sender, EventArgs e)
        {
            DateTime currentDate = DateTime.Now;
            string   username    = Request.Cookies["userLoginSystem"].Value;
            var      acc         = AccountController.GetByUsername(username);

            if (acc != null)
            {
                if (acc.RoleID == 0 || acc.RoleID == 1)
                {
                    int      AgentID = Convert.ToInt32(acc.AgentID);
                    string   list    = hdfvalue.Value;
                    string   note    = hdfNote.Value;
                    string[] items   = list.Split(';');
                    if (items.Length - 1 > 0)
                    {
                        int SessionInOutID = SessionInOutController.Insert(currentDate, note, AgentID, 2, currentDate, username).ToInt(0);
                        if (SessionInOutID > 0)
                        {
                            for (int i = 0; i < items.Length - 1; i++)
                            {
                                //list += id + "," + sku + "," + producttype + "," + productnariablename + "," + productvariablevalue + "," + quantity + "|";
                                var      item                 = items[i];
                                string[] itemValue            = item.Split(',');
                                int      ID                   = itemValue[0].ToInt();
                                string   SKU                  = itemValue[1];
                                int      producttype          = itemValue[2].ToInt();
                                string   ProductVariableName  = itemValue[3];
                                string   ProductVariableValue = itemValue[4];
                                double   Quantity             = Convert.ToDouble(itemValue[5]);
                                string   ProductName          = itemValue[6];
                                string   ProductImageOrigin   = itemValue[7];
                                string   ProductVariable      = itemValue[8];

                                string noteeach        = itemValue[9];
                                double QuantityInStock = Convert.ToDouble(itemValue[10]);

                                if (!string.IsNullOrEmpty(noteeach))
                                {
                                    noteeach = "Cập nhật số lượng sản phẩm khi kiểm kho ngày: " + string.Format("0:dd/MM/yyyy", currentDate);
                                }


                                if (Quantity > QuantityInStock)
                                {
                                    double slIn = Quantity - QuantityInStock;
                                    if (producttype == 1)
                                    {
                                        StockManagerController.Insert(
                                            new tbl_StockManager {
                                            AgentID           = AgentID,
                                            ProductID         = ID,
                                            ProductVariableID = 0,
                                            Quantity          = slIn,
                                            QuantityCurrent   = 0,
                                            Type        = 1,
                                            NoteID      = note,
                                            OrderID     = 0,
                                            Status      = 1,
                                            SKU         = SKU,
                                            CreatedDate = currentDate,
                                            CreatedBy   = username,
                                            MoveProID   = 0,
                                            ParentID    = ID
                                        });
                                    }
                                    else
                                    {
                                        int    parentID  = 0;
                                        string parentSKU = "";
                                        var    productV  = ProductVariableController.GetByID(ID);
                                        if (productV != null)
                                        {
                                            parentSKU = productV.ParentSKU;
                                        }
                                        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          = slIn,
                                            QuantityCurrent   = 0,
                                            Type        = 1,
                                            NoteID      = note,
                                            OrderID     = 0,
                                            Status      = 1,
                                            SKU         = SKU,
                                            CreatedDate = currentDate,
                                            CreatedBy   = username,
                                            MoveProID   = 0,
                                            ParentID    = parentID
                                        });
                                    }
                                }
                                else if (Quantity < QuantityInStock)
                                {
                                    double slOut = QuantityInStock - Quantity;
                                    if (producttype == 1)
                                    {
                                        StockManagerController.Insert(
                                            new tbl_StockManager {
                                            AgentID           = AgentID,
                                            ProductID         = ID,
                                            ProductVariableID = 0,
                                            Quantity          = slOut,
                                            QuantityCurrent   = 0,
                                            Type        = 2,
                                            NoteID      = noteeach,
                                            OrderID     = 0,
                                            Status      = 2,
                                            SKU         = SKU,
                                            CreatedDate = currentDate,
                                            CreatedBy   = username,
                                            MoveProID   = 0,
                                            ParentID    = ID
                                        });
                                    }
                                    else
                                    {
                                        int    parentID  = 0;
                                        string parentSKU = "";
                                        var    productV  = ProductVariableController.GetByID(ID);
                                        if (productV != null)
                                        {
                                            parentSKU = productV.ParentSKU;
                                        }
                                        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          = slOut,
                                            QuantityCurrent   = 0,
                                            Type        = 2,
                                            NoteID      = noteeach,
                                            OrderID     = 0,
                                            Status      = 2,
                                            SKU         = SKU,
                                            CreatedDate = currentDate,
                                            CreatedBy   = username,
                                            MoveProID   = 0,
                                            ParentID    = parentID
                                        });
                                    }
                                }
                            }
                            PJUtils.ShowMessageBoxSwAlert("Kiểm kho thành công", "s", true, Page);
                        }
                    }
                }
            }
        }
Ejemplo n.º 18
0
        public void LoadData()
        {
            string username = Request.Cookies["usernameLoginSystem"].Value;
            var    acc      = AccountController.GetByUsername(username);

            if (acc != null)
            {
                DateTime DateConfig = new DateTime(2019, 12, 15);

                var config = ConfigController.GetByTop1();
                if (config.ViewAllOrders == 1)
                {
                    DateConfig = new DateTime(2018, 6, 22);
                }

                DateTime fromDate = DateTime.Today;
                DateTime toDate   = DateTime.Now;

                if (!String.IsNullOrEmpty(Request.QueryString["fromdate"]))
                {
                    fromDate = Convert.ToDateTime(Request.QueryString["fromdate"]);
                }

                if (!String.IsNullOrEmpty(Request.QueryString["todate"]))
                {
                    toDate = Convert.ToDateTime(Request.QueryString["todate"]).AddDays(1).AddMinutes(-1);
                }

                rFromDate.SelectedDate = fromDate;
                rFromDate.MinDate      = DateConfig;
                rFromDate.MaxDate      = DateTime.Now;

                rToDate.SelectedDate = toDate;
                rToDate.MinDate      = DateConfig;
                rToDate.MaxDate      = DateTime.Now;

                string TextSearch  = "";
                string CreatedDate = "today";
                int    CategoryID  = 0;
                string strColor    = String.Empty;
                string strSize     = String.Empty;
                int    Page        = 1;

                if (Request.QueryString["textsearch"] != null)
                {
                    TextSearch = Request.QueryString["textsearch"].Trim();
                }
                if (Request.QueryString["categoryid"] != null)
                {
                    CategoryID = Request.QueryString["categoryid"].ToInt();
                }
                if (Request.QueryString["createddate"] != null)
                {
                    CreatedDate = Request.QueryString["createddate"];
                }
                // Add filter valiable value
                if (Request.QueryString["color"] != null)
                {
                    strColor = Request.QueryString["color"].Trim();
                }
                if (Request.QueryString["size"] != null)
                {
                    strSize = Request.QueryString["size"].Trim();
                }
                if (Request.QueryString["Page"] != null)
                {
                    Page = Request.QueryString["Page"].ToInt();
                }

                txtSearchProduct.Text     = TextSearch;
                ddlCategory.SelectedValue = CategoryID.ToString();

                // Add filter valiable value
                ddlColor.SelectedValue = strColor;
                ddlSize.SelectedValue  = strSize;

                // Create order fileter
                var filter = new ProductFilterModel()
                {
                    search   = TextSearch,
                    category = CategoryID,
                    fromDate = fromDate,
                    toDate   = toDate,
                    color    = strColor,
                    size     = strSize
                };

                // Create pagination
                var page = new PaginationMetadataModel()
                {
                    currentPage = Page
                };
                int totalQuantityInput      = 0;
                List <GoodsReceiptReport> a = new List <GoodsReceiptReport>();
                a = StockManagerController.getGoodsReceiptReport(filter, ref page, ref totalQuantityInput);

                pagingall(filter, a, page);

                ltrNumberOfProduct.Text = String.Format("{0} sản phẩm - {1:#,###} cái", page.totalCount.ToString(), totalQuantityInput);
            }
        }
Ejemplo n.º 19
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));
        }
Ejemplo n.º 20
0
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            DateTime currentDate = DateTime.Now;
            string   username    = Request.Cookies["usernameLoginSystem"].Value;
            var      acc         = AccountController.GetByUsername(username);

            if (acc != null)
            {
                if (acc.RoleID == 0 || acc.RoleID == 1)
                {
                    int AgentID = Convert.ToInt32(acc.AgentID);
                    int ID      = hdfMPDID.Value.ToInt(0);
                    if (ID > 0)
                    {
                        var mpd = MoveProDetailController.GetByID(ID);
                        if (mpd != null)
                        {
                            if (mpd.IsCount == true)
                            {
                                if (mpd.ProductType == 1)
                                {
                                    StockManagerController.Insert(
                                        new tbl_StockManager {
                                        AgentID           = AgentID,
                                        ProductID         = ID,
                                        ProductVariableID = 0,
                                        Quantity          = Convert.ToDouble(mpd.QuantiySend),
                                        QuantityCurrent   = 0,
                                        Type        = 1,
                                        NoteID      = "Nhập lại sản phẩm khi xóa khỏi đợt chuyển hàng",
                                        OrderID     = 0,
                                        Status      = 6,
                                        SKU         = mpd.SKU,
                                        CreatedDate = currentDate,
                                        CreatedBy   = username,
                                        MoveProID   = Convert.ToInt32(mpd.MoveProID),
                                        ParentID    = ID
                                    });
                                }
                                else
                                {
                                    int    parentID  = 0;
                                    string parentSKU = "";
                                    var    productV  = ProductVariableController.GetByID(ID);
                                    if (productV != null)
                                    {
                                        parentSKU = productV.ParentSKU;
                                    }
                                    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          = Convert.ToDouble(mpd.QuantiySend),
                                        QuantityCurrent   = 0,
                                        Type        = 1,
                                        NoteID      = "Nhập lại sản phẩm khi xóa khỏi đợt chuyển hàng",
                                        OrderID     = 0,
                                        Status      = 6,
                                        SKU         = mpd.SKU,
                                        CreatedDate = currentDate,
                                        CreatedBy   = username,
                                        MoveProID   = Convert.ToInt32(mpd.MoveProID),
                                        ParentID    = parentID
                                    });
                                }
                            }
                            MoveProDetailController.Delete(ID);
                            PJUtils.ShowMessageBoxSwAlert("Xóa thành công", "s", true, Page);
                        }
                    }
                }
            }
        }
Ejemplo n.º 21
0
        public void pagingall(ProductFilterModel filter, List <GoodsReceiptReport> acs, PaginationMetadataModel page)
        {
            string username = Request.Cookies["usernameLoginSystem"].Value;
            var    acc      = AccountController.GetByUsername(username);

            StringBuilder html = new StringBuilder();

            html.AppendLine("<thead>");
            html.AppendLine("<tr>");
            html.AppendLine("    <th class='stt-column'>#</th>");
            html.AppendLine("    <th class='image-column'>Ảnh</th>");
            html.AppendLine("    <th class='name-column'>Sản phẩm</th>");
            html.AppendLine("    <th class='sku-column'>Mã</th>");
            html.AppendLine("    <th class='stock-column'>Nhập mới</th>");
            html.AppendLine("    <th class='stock-column'>Kho hiện tại</th>");
            html.AppendLine("    <th class='category-column'>Danh mục</th>");
            html.AppendLine("    <th class='date-column'>Ngày nhập</th>");
            html.AppendLine("    <th class='action-column'></th>");
            html.AppendLine("</tr>");
            html.AppendLine("</thead>");

            html.AppendLine("<tbody>");
            if (acs.Count > 0)
            {
                PageCount = page.totalPages;
                Int32 Page = page.currentPage;
                int   i    = 0;
                foreach (var item in acs)
                {
                    i++;
                    html.AppendLine("<tr class='parent-row'>");
                    html.AppendLine("   <td>" + i + "</td>");
                    html.AppendLine("   <td>");
                    html.AppendLine("      <a href='/xem-san-pham?sku=" + item.sku + "'>");
                    html.AppendLine("          <img src='" + Thumbnail.getURL(item.image, Thumbnail.Size.Small) + "'/>");
                    html.AppendLine("      </a>");
                    html.AppendLine("   <a href='javascript:;' onclick='copyProductInfo(" + item.productID + ")' class='btn download-btn h45-btn'><i class='fa fa-files-o'></i> Copy</a>");
                    html.AppendLine("   </td>");
                    html.AppendLine("   <td class='customer-name-link'>");
                    html.AppendLine("       <a href='/xem-san-pham?sku=" + item.sku + "'>" + item.title + "</a></td>");
                    html.AppendLine("   </td>");
                    html.AppendLine("   <td data-title='Mã' class='customer-name-link'>" + item.sku + "</td>");
                    html.AppendLine("   <td data-title='Nhập mới'>" + String.Format("{0:N0}", item.quantityInput) + "</td>");
                    html.AppendLine("   <td data-title='Kho hiện tại'><a target='_blank' href='/thong-ke-san-pham?SKU=" + item.sku + "'>" + String.Format("{0:N0}", item.quantityStock) + "</a></td>");
                    html.AppendLine("   <td data-title='Danh mục'>" + item.categoryName + "</td>");
                    html.AppendLine("   <td data-title='Ngày tạo'>" + String.Format("{0:dd/MM/yyyy HH:mm}", item.goodsReceiptDate) + "</td>");
                    html.AppendLine("   <td data-title='Thao tác' class='update-button'>");
                    if (item.isVariable)
                    {
                        html.AppendLine("      <a href='javascript:;' title='Xem thông tin sản phẩm con' class='btn primary-btn h45-btn btn-blue' onclick='showSubGoodsReceipt($(this), `" + item.sku + "`)'>");
                        html.AppendLine("           <i class='fa fa-chevron-down' aria-hidden='true'></i>");
                        html.AppendLine("      </a>");
                    }
                    html.AppendLine("       <a href='javascript:;' title='Download tất cả hình sản phẩm này' class='btn primary-btn h45-btn' onclick='getAllProductImage(`" + item.sku + "`);'><i class='fa fa-file-image-o' aria-hidden='true'></i></a>");
                    if (acc.RoleID == 0)
                    {
                        html.Append("       <a href='javascript:;' title='Đồng bộ sản phẩm' class='up-product-" + item.productID + " btn primary-btn h45-btn " + (item.showHomePage == 1 ? "" : "hide") + "' onclick='showProductSyncModal(`" + item.sku + "`, " + item.productID + ", " + item.categoryID + ");'><i class='fa fa-refresh' aria-hidden='true'></i></a>");
                    }
                    html.AppendLine("  </td>");
                    html.AppendLine("</tr>");

                    var productVariables = StockManagerController.getSubGoodsReceipt(filter, item);
                    foreach (var subItem in productVariables)
                    {
                        html.AppendLine("<tr class='" + item.sku + " child-row hide'>");
                        html.AppendLine("   <td></td>");
                        html.AppendLine("   <td></td>");
                        html.AppendLine("   <td>");
                        html.AppendLine("      <a href='/xem-san-pham?sku=" + subItem.sku + "'>");
                        html.AppendLine("          <img src='" + Thumbnail.getURL(subItem.image, Thumbnail.Size.Small) + "'/>");
                        html.AppendLine("      </a>");
                        html.AppendLine("   </td>");
                        html.AppendLine("   <td data-title='Mã' class='customer-name-link'>" + subItem.sku + "</td>");
                        html.AppendLine("   <td data-title='Nhập mới'>" + String.Format("{0:N0}", subItem.quantityInput) + "</td>");
                        html.AppendLine("   <td data-title='Kho hiện tại'><a target='_blank' href='/thong-ke-san-pham?SKU=" + subItem.sku + "'>" + String.Format("{0:N0}", subItem.quantityStock) + "</a></td>");
                        html.AppendLine("   <td data-title='Danh mục'></td>");
                        html.AppendLine("   <td data-title='Ngày nhập'>" + String.Format("{0:dd/MM/yyyy HH:mm}", subItem.goodsReceiptDate) + "</td>");
                        html.AppendLine("   <td data-title='Thao tác' class='update-button'></td>");
                        html.AppendLine("</tr>");
                    }
                }
            }
            else
            {
                html.Append("<tr><td colspan='11'>Không tìm thấy sản phẩm...</td></tr>");
            }
            html.Append("</tbody>");

            ltrList.Text = html.ToString();
        }
Ejemplo n.º 22
0
        public void pagingall(List <tbl_ProductVariable> acs, int userRole)
        {
            int           PageSize = 40;
            StringBuilder html     = new StringBuilder();

            if (acs.Count > 0)
            {
                int TotalItems = acs.Count;
                if (TotalItems % PageSize == 0)
                {
                    PageCount = TotalItems / PageSize;
                }
                else
                {
                    PageCount = TotalItems / PageSize + 1;
                }

                Int32 Page = GetIntFromQueryString("Page");

                if (Page == -1)
                {
                    Page = 1;
                }
                int FromRow = (Page - 1) * PageSize;
                int ToRow   = Page * PageSize - 1;
                if (ToRow >= TotalItems)
                {
                    ToRow = TotalItems - 1;
                }
                html.Append("<tr>");
                html.Append("    <th class='image-column'>Ảnh</th>");
                html.Append("    <th class='variable-column'>Thuộc tính</th>");
                html.Append("    <th class='sku-column'>Mã</th>");
                html.Append("    <th class='wholesale-price-column'>Giá sỉ</th>");
                if (userRole == 0)
                {
                    html.Append("    <th class='cost-price-column'>Giá vốn</th>");
                }
                html.Append("    <th class='retail-price-column'>Giá lẻ</th>");
                html.Append("    <th class='stock-column'>Kho</th>");
                html.Append("    <th class='stock-status-column'>Trạng thái</th>");
                html.Append("    <th class='date-column'>Ngày tạo</th>");
                html.Append("    <th class='hide-column'>Ẩn</th>");
                html.Append("    <th class='action-column'>Thao tác</th>");
                html.Append("</tr>");
                for (int i = FromRow; i < ToRow + 1; i++)
                {
                    var item   = acs[i];
                    var stock2 = StockManagerController.getQuantityStock2BySKU(item.SKU);
                    html.Append("<tr>");
                    html.Append("   <td><img src='" + Thumbnail.getURL(item.Image, Thumbnail.Size.Small) + "'></td>");

                    string date     = string.Format("{0:dd/MM/yyyy}", item.CreatedDate);
                    string ishidden = "";
                    if (item.IsHidden != null)
                    {
                        bool IsHidden = Convert.ToBoolean(item.IsHidden);
                        ishidden = PJUtils.IsHiddenStatus(IsHidden);
                    }
                    else
                    {
                        ishidden = PJUtils.IsHiddenStatus(false);
                    }

                    var value = ProductVariableValueController.GetByProductVariableID(item.ID);
                    if (value != null)
                    {
                        html.Append("   <td>");
                        string list = "";
                        foreach (var temp in value)
                        {
                            html.Append("" + temp.VariableName + ": " + temp.VariableValue + "</br>" + "");
                            list += temp.VariableName + "|";
                        }
                        html.Append("</td>");
                    }

                    html.Append("   <td>" + item.SKU + "</td>");

                    html.Append("   <td>" + string.Format("{0:N0}", item.Regular_Price) + "</td>");

                    if (userRole == 0)
                    {
                        html.Append("   <td>" + string.Format("{0:N0}", item.CostOfGood) + "</td>");
                    }

                    html.Append("   <td>" + string.Format("{0:N0}", item.RetailPrice) + "</td>");

                    if (stock2.HasValue)
                    {
                        html.Append(String.Format("   <td>{0:N0}<br>(Kho 2: {1:N0})</td>", PJUtils.TotalProductQuantityInstock(1, item.SKU), stock2.Value));
                    }
                    else
                    {
                        html.Append("   <td>" + PJUtils.TotalProductQuantityInstock(1, item.SKU) + "</td>");
                    }
                    html.Append("   <td>" + PJUtils.StockStatusBySKU(1, item.SKU) + "</td>");

                    html.Append("   <td>" + date + "</td>");
                    html.Append("   <td>" + ishidden + "</td>");
                    html.Append("   <td>");
                    html.Append("       <a href=\"/thong-tin-thuoc-tinh-san-pham?id=" + item.ID + "\" title=\"Xem chi tiết\" class=\"btn primary-btn h45-btn\"><i class=\"fa fa-info-circle\" aria-hidden=\"true\"></i></a>");
                    html.Append("       <a href=\"/gia-tri-thuoc-tinh-san-pham?productvariableid=" + item.ID + "\" title=\"Xem thuộc tính\" class=\"btn primary-btn h45-btn\"><i class=\"fa fa-file-text-o\" aria-hidden=\"true\"></i></a>");
                    html.Append("   </td>");
                    html.Append("</tr>");
                }
            }
            ltrList.Text = html.ToString();
        }
Ejemplo n.º 23
0
        protected void btnImport_Click(object sender, EventArgs e)
        {
            DateTime currentDate = DateTime.Now;
            string   username    = Request.Cookies["userLoginSystem"].Value;
            var      acc         = AccountController.GetByUsername(username);

            if (acc != null)
            {
                if (acc.RoleID == 0 || acc.RoleID == 1)
                {
                    int    AgentID = Convert.ToInt32(acc.AgentID);
                    string list    = hdfvalue.Value;
                    string note    = "Xuất kho bằng chức năng xuất kho";
                    if (hdfNote.Value != "")
                    {
                        note = hdfNote.Value;
                    }
                    string[] items = list.Split(';');
                    if (items.Length - 1 > 0)
                    {
                        int SessionInOutID = SessionInOutController.Insert(currentDate, note, AgentID, 2, currentDate, username).ToInt(0);
                        if (SessionInOutID > 0)
                        {
                            for (int i = 0; i < items.Length - 1; i++)
                            {
                                var      item                 = items[i];
                                string[] itemValue            = item.Split(',');
                                int      ID                   = itemValue[0].ToInt();
                                string   SKU                  = itemValue[1];
                                int      producttype          = itemValue[2].ToInt();
                                string   ProductVariableName  = itemValue[3];
                                string   ProductVariableValue = itemValue[4];
                                double   Quantity             = Convert.ToDouble(itemValue[5]);
                                string   ProductName          = itemValue[6];
                                string   ProductImageOrigin   = itemValue[7];
                                string   ProductVariable      = itemValue[8];
                                if (producttype == 1)
                                {
                                    StockManagerController.Insert(
                                        new tbl_StockManager {
                                        AgentID           = AgentID,
                                        ProductID         = ID,
                                        ProductVariableID = 0,
                                        Quantity          = Quantity,
                                        QuantityCurrent   = 0,
                                        Type        = 2,
                                        NoteID      = note,
                                        OrderID     = 0,
                                        Status      = 2,
                                        SKU         = SKU,
                                        CreatedDate = currentDate,
                                        CreatedBy   = username,
                                        MoveProID   = 0,
                                        ParentID    = ID,
                                    });
                                }
                                else
                                {
                                    int    parentID  = 0;
                                    string parentSKU = "";
                                    var    productV  = ProductVariableController.GetByID(ID);
                                    if (productV != null)
                                    {
                                        parentSKU = productV.ParentSKU;
                                    }
                                    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        = 2,
                                        NoteID      = note,
                                        OrderID     = 0,
                                        Status      = 2,
                                        SKU         = SKU,
                                        CreatedDate = currentDate,
                                        CreatedBy   = username,
                                        MoveProID   = 0,
                                        ParentID    = parentID,
                                    });
                                }
                            }
                            PJUtils.ShowMessageBoxSwAlert("Xuất kho thành công", "s", true, Page);
                        }
                    }
                }
            }
        }
Ejemplo n.º 24
0
        protected void btnImport_Click(object sender, EventArgs e)
        {
            if (hdfWarehouseTransfer.Value == "0")
            {
                PJUtils.ShowMessageBoxSwAlert("Vui lòng chọn kho muốn chuyển hàng tới", "i", false, Page);
                return;
            }

            DateTime currentDate = DateTime.Now;
            string   username    = Request.Cookies["usernameLoginSystem"].Value;
            var      acc         = AccountController.GetByUsername(username);

            if (acc != null)
            {
                int    AgentID = Convert.ToInt32(acc.AgentID);
                string note    = String.Empty;
                var    data    = String.IsNullOrEmpty(hdfvalue.Value) ?
                                 new List <WarehousePostModel>() :
                                 JsonConvert.DeserializeObject <List <WarehousePostModel> >(hdfvalue.Value);

                if (hdfWarehouseTransfer.Value == "1")
                {
                    foreach (var item in data)
                    {
                        StockManagerController.warehousing1(new tbl_StockManager()
                        {
                            AgentID           = AgentID,
                            ProductID         = item.productVariableID == 0 ? item.productID : 0,
                            ProductVariableID = item.productVariableID,
                            SKU             = item.sku,
                            Type            = 1,
                            Quantity        = item.quantity,
                            QuantityCurrent = item.stock2,
                            Status          = 18,
                            NoteID          = "Chuyển hàng sang kho 2 bằng chức năng chuyển kho",
                            CreatedDate     = currentDate,
                            CreatedBy       = username,
                            ModifiedDate    = currentDate,
                            ModifiedBy      = username,
                            OrderID         = 0,
                            MoveProID       = 0,
                            ParentID        = item.productID
                        });
                        StockManagerController.warehousing2(new StockManager2()
                        {
                            AgentID           = AgentID,
                            ProductID         = item.productID,
                            ProductVariableID = item.productVariableID,
                            SKU             = item.sku,
                            ParentSKU       = item.parentSKU,
                            Type            = 1,
                            Quantity        = item.quantity,
                            QuantityCurrent = item.stock2,
                            Status          = 20,
                            Note            = "Nhận hàng từ kho 1 bằng chức năng chuyển kho",
                            CreatedDate     = currentDate,
                            CreatedBy       = username,
                            ModifiedDate    = currentDate,
                            ModifiedBy      = username,
                        });
                    }
                }
                else
                {
                    foreach (var item in data)
                    {
                        StockManagerController.warehousing1(new tbl_StockManager()
                        {
                            AgentID           = AgentID,
                            ProductID         = item.productVariableID == 0 ? item.productID : 0,
                            ProductVariableID = item.productVariableID,
                            SKU             = item.sku,
                            Type            = 1,
                            Quantity        = item.quantity,
                            QuantityCurrent = (item.stock2 - item.quantity),
                            Status          = 20,
                            NoteID          = "Nhận hàng từ kho 2 bằng chức năng chuyển kho",
                            CreatedDate     = currentDate,
                            CreatedBy       = username,
                            ModifiedDate    = currentDate,
                            ModifiedBy      = username,
                            OrderID         = 0,
                            MoveProID       = 0,
                            ParentID        = item.productID
                        });
                        StockManagerController.warehousing2(new StockManager2()
                        {
                            AgentID           = AgentID,
                            ProductID         = item.productID,
                            ProductVariableID = item.productVariableID,
                            SKU             = item.sku,
                            ParentSKU       = item.parentSKU,
                            Type            = 2,
                            Quantity        = item.quantity,
                            QuantityCurrent = item.stock2,
                            Status          = 18,
                            Note            = "Chuyển hàng sang kho 1 bằng chức năng chuyển kho",
                            CreatedDate     = currentDate,
                            CreatedBy       = username,
                            ModifiedDate    = currentDate,
                            ModifiedBy      = username,
                        });
                    }
                }


                PJUtils.ShowMessageBoxSwAlert("Chuyển kho thành công!", "s", true, Page);
            }
        }
Ejemplo n.º 25
0
        protected void btnOrder_Click(object sender, EventArgs e)
        {
            DateTime currentDate = DateTime.Now;
            string   username    = Request.Cookies["userLoginSystem"].Value;
            var      acc         = AccountController.GetByUsername(username);

            if (acc != null)
            {
                if (acc.RoleID == 0 || acc.RoleID == 2)
                {
                    // Change user
                    string OrderNote = "";
                    if (username != hdfUsernameCurrent.Value)
                    {
                        OrderNote = "Được tính tiền giúp bởi " + username;
                        username  = hdfUsernameCurrent.Value;
                    }

                    int    AgentID     = Convert.ToInt32(acc.AgentID);
                    int    OrderType   = hdfOrderType.Value.ToInt();
                    string AdditionFee = "0";
                    string DisCount    = "0";
                    int    CustomerID  = 0;

                    string CustomerPhone   = txtPhone.Text.Trim().Replace(" ", "");
                    string CustomerName    = txtFullname.Text.Trim();
                    string Nick            = txtNick.Text.Trim();
                    string CustomerEmail   = "";
                    string CustomerAddress = txtAddress.Text.Trim();

                    var checkCustomer = CustomerController.GetByPhone(CustomerPhone);

                    if (checkCustomer != null)
                    {
                        CustomerID = checkCustomer.ID;
                        string kq = CustomerController.Update(CustomerID, CustomerName, checkCustomer.CustomerPhone, CustomerAddress, "", Convert.ToInt32(checkCustomer.CustomerLevelID), Convert.ToInt32(checkCustomer.Status), checkCustomer.CreatedBy, currentDate, username, false, checkCustomer.Zalo, checkCustomer.Facebook, checkCustomer.Note, checkCustomer.ProvinceID.ToString(), Nick, checkCustomer.Avatar, Convert.ToInt32(checkCustomer.ShippingType), Convert.ToInt32(checkCustomer.PaymentType), Convert.ToInt32(checkCustomer.TransportCompanyID), Convert.ToInt32(checkCustomer.TransportCompanySubID), checkCustomer.CustomerPhone2);
                    }
                    else
                    {
                        string kq = CustomerController.Insert(CustomerName, CustomerPhone, CustomerAddress, CustomerEmail, 0, 0, currentDate, username, false, "", "", "", "", Nick);
                        if (kq.ToInt(0) > 0)
                        {
                            CustomerID = kq.ToInt(0);
                        }
                    }

                    string totalPrice            = hdfTotalPrice.Value.ToString();
                    string totalPriceNotDiscount = hdfTotalPriceNotDiscount.Value;
                    int    PaymentStatus         = 3;
                    int    ExcuteStatus          = 2;
                    int    PaymentType           = 1;
                    int    ShippingType          = 1;
                    bool   IsHidden = false;
                    int    WayIn    = 1;

                    double DiscountPerProduct = Convert.ToDouble(pDiscount.Value);

                    double TotalDiscount = Convert.ToDouble(pDiscount.Value) * Convert.ToDouble(hdfTotalQuantity.Value);
                    string FeeShipping   = pFeeShip.Value.ToString();
                    double GuestPaid     = Convert.ToDouble(pGuestPaid.Value);
                    double GuestChange   = Convert.ToDouble(totalPrice) - GuestPaid;
                    string OtherFeeName  = txtOtherFeeName.Text;
                    double OtherFeeValue = Convert.ToDouble(pOtherFee.Value);

                    var ret = OrderController.InsertOnSystem(AgentID, OrderType, AdditionFee, DisCount, CustomerID, CustomerName, CustomerPhone, CustomerAddress,
                                                             CustomerEmail, totalPrice, totalPriceNotDiscount, PaymentStatus, ExcuteStatus, IsHidden, WayIn, currentDate, username, DiscountPerProduct,
                                                             TotalDiscount, FeeShipping, GuestPaid, GuestChange, PaymentType, ShippingType, OrderNote, DateTime.Now, OtherFeeName, OtherFeeValue, 1);
                    int OrderID = ret.ID;

                    if (OrderID > 0)
                    {
                        ProductPOS              POS          = JsonConvert.DeserializeObject <ProductPOS>(hdfListProduct.Value);
                        List <tbl_OrderDetail>  orderDetails = new List <tbl_OrderDetail>();
                        List <tbl_StockManager> stockManager = new List <tbl_StockManager>();

                        foreach (ProductGetOut item in POS.productPOS)
                        {
                            orderDetails.Add(
                                new tbl_OrderDetail()
                            {
                                AgentID                   = AgentID,
                                OrderID                   = OrderID,
                                SKU                       = item.SKU,
                                ProductID                 = item.ProductType == 1 ? item.ProductID : 0,
                                ProductVariableID         = item.ProductType == 1 ? 0 : item.ProductVariableID,
                                ProductVariableDescrition = item.ProductVariableSave,
                                Quantity                  = item.QuantityInstock,
                                Price                     = item.Giabanle,
                                Status                    = 1,
                                DiscountPrice             = 0,
                                ProductType               = item.ProductType,
                                CreatedDate               = currentDate,
                                CreatedBy                 = username,
                                IsCount                   = true
                            }
                                );

                            int parentID = item.ProductID;
                            var variable = ProductVariableController.GetByID(item.ProductVariableID);
                            if (variable != null)
                            {
                                parentID = Convert.ToInt32(variable.ProductID);
                            }

                            stockManager.Add(
                                new tbl_StockManager()
                            {
                                AgentID           = AgentID,
                                ProductID         = item.ProductType == 1 ? item.ProductID : 0,
                                ProductVariableID = item.ProductType == 1 ? 0 : item.ProductVariableID,
                                Quantity          = item.QuantityInstock,
                                QuantityCurrent   = 0,
                                Type        = 2,
                                NoteID      = "Xuất kho bán POS",
                                OrderID     = OrderID,
                                Status      = 3,
                                SKU         = item.SKU,
                                CreatedDate = currentDate,
                                CreatedBy   = username,
                                MoveProID   = 0,
                                ParentID    = parentID
                            }
                                );
                        }

                        OrderDetailController.Insert(orderDetails);
                        StockManagerController.Insert(stockManager);

                        string refund = Request.Cookies["refund"].Value;
                        if (refund != "1")
                        {
                            string[] RefundID = refund.Split('|');
                            var      update   = RefundGoodController.UpdateStatus(RefundID[0].ToInt(), username, 2, OrderID);
                            var      updateor = OrderController.UpdateRefund(OrderID, RefundID[0].ToInt(), username);
                        }

                        Response.Cookies["refund"].Expires = DateTime.Now.AddDays(-1d);
                        Response.Cookies.Add(Response.Cookies["refund"]);

                        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "script", "$(function () { printInvoice(" + OrderID + ") });", true);
                    }
                }
            }
        }
Ejemplo n.º 26
0
        protected void btnOrder_Click(object sender, EventArgs e)
        {
            try
            {
                DateTime currentDate = DateTime.Now;
                string   username    = Request.Cookies["usernameLoginSystem"].Value;
                var      acc         = AccountController.GetByUsername(username);
                if (acc != null)
                {
                    if (acc.RoleID == 0 || acc.RoleID == 2)
                    {
                        #region Lấy thông tin khởi tạo Order
                        // Change user
                        string UserHelp = "";
                        if (username != hdfUsernameCurrent.Value)
                        {
                            UserHelp = username;
                            username = hdfUsernameCurrent.Value;
                        }

                        int    AgentID     = Convert.ToInt32(acc.AgentID);
                        int    OrderType   = hdfOrderType.Value.ToInt();
                        string AdditionFee = "0";
                        string DisCount    = "0";
                        int    CustomerID  = 0;

                        string CustomerPhone   = Regex.Replace(txtPhone.Text.Trim(), @"[^\d]", "");
                        string CustomerName    = txtFullname.Text.Trim().ToLower().ToTitleCase();
                        string CustomerEmail   = "";
                        string CustomerAddress = txtAddress.Text.Trim().ToTitleCase();

                        int ProvinceID = hdfProvinceID.Value.ToInt(0);
                        int DistrictID = hdfDistrictID.Value.ToInt(0);
                        int WardID     = hdfWardID.Value.ToInt(0);

                        var checkCustomer = CustomerController.GetByPhone(CustomerPhone);

                        string kq = "";

                        #region Cập nhật thông tin khách hàng
                        if (checkCustomer != null)
                        {
                            CustomerID = checkCustomer.ID;
                            kq         = CustomerController.Update(CustomerID, CustomerName, checkCustomer.CustomerPhone, CustomerAddress, "", checkCustomer.CustomerLevelID.Value, checkCustomer.Status.Value, checkCustomer.CreatedBy, currentDate, username, false, checkCustomer.Zalo, checkCustomer.Facebook, checkCustomer.Note, checkCustomer.Nick, checkCustomer.Avatar, checkCustomer.ShippingType.Value, checkCustomer.PaymentType.Value, checkCustomer.TransportCompanyID.Value, checkCustomer.TransportCompanySubID.Value, checkCustomer.CustomerPhone2, ProvinceID, DistrictID, WardID);
                        }
                        else
                        {
                            kq = CustomerController.Insert(CustomerName, CustomerPhone, CustomerAddress, CustomerEmail, 0, 0, currentDate, username, false, "", "", "", "", "", 0, 0, 0, 0, "", ProvinceID, DistrictID, WardID);
                            if (kq.ToInt(0) > 0)
                            {
                                CustomerID = kq.ToInt(0);
                            }
                        }
                        #endregion

                        string totalPrice            = hdfTotalPrice.Value.ToString();
                        string totalPriceNotDiscount = hdfTotalPriceNotDiscount.Value;
                        int    PaymentStatus         = 3;
                        int    ExcuteStatus          = 2;
                        int    PaymentType           = 1;
                        int    ShippingType          = 1;

                        bool IsHidden = false;
                        int  WayIn    = 1;

                        double DiscountPerProduct = Convert.ToDouble(pDiscount.Value);

                        double TotalDiscount = Convert.ToDouble(pDiscount.Value) * Convert.ToDouble(hdfTotalQuantity.Value);
                        string FeeShipping   = pFeeShip.Value.ToString();
                        double GuestPaid     = Convert.ToDouble(pGuestPaid.Value);
                        double GuestChange   = Convert.ToDouble(totalPrice) - GuestPaid;
                        var    couponID      = hdfCouponID.Value.ToInt(0);
                        var    couponValue   = hdfCouponValue.Value.ToDecimal(0);

                        tbl_Order order = new tbl_Order()
                        {
                            AgentID               = AgentID,
                            OrderType             = OrderType,
                            AdditionFee           = AdditionFee,
                            DisCount              = DisCount,
                            CustomerID            = CustomerID,
                            CustomerName          = CustomerName,
                            CustomerPhone         = CustomerPhone,
                            CustomerAddress       = CustomerAddress,
                            CustomerEmail         = CustomerEmail,
                            TotalPrice            = totalPrice,
                            TotalPriceNotDiscount = totalPriceNotDiscount,
                            PaymentStatus         = PaymentStatus,
                            ExcuteStatus          = ExcuteStatus,
                            IsHidden              = IsHidden,
                            WayIn              = WayIn,
                            CreatedDate        = currentDate,
                            CreatedBy          = username,
                            DiscountPerProduct = DiscountPerProduct,
                            TotalDiscount      = TotalDiscount,
                            FeeShipping        = FeeShipping,
                            GuestPaid          = GuestPaid,
                            GuestChange        = GuestChange,
                            PaymentType        = PaymentType,
                            ShippingType       = ShippingType,
                            OrderNote          = String.Empty,
                            DateDone           = DateTime.Now,
                            OtherFeeName       = String.Empty,
                            OtherFeeValue      = 0,
                            PostalDeliveryType = 1,
                            UserHelp           = UserHelp,
                            CouponID           = couponID,
                            CouponValue        = couponValue
                        };

                        var ret = OrderController.InsertOnSystem(order);

                        int OrderID = ret.ID;
                        #endregion

                        #region Khởi tạo Other Fee
                        if (!String.IsNullOrEmpty(hdfOtherFees.Value))
                        {
                            JavaScriptSerializer serializer = new JavaScriptSerializer();
                            var fees = serializer.Deserialize <List <Fee> >(hdfOtherFees.Value);
                            if (fees != null)
                            {
                                foreach (var fee in fees)
                                {
                                    fee.OrderID      = ret.ID;
                                    fee.CreatedBy    = acc.ID;
                                    fee.CreatedDate  = DateTime.Now;
                                    fee.ModifiedBy   = acc.ID;
                                    fee.ModifiedDate = DateTime.Now;
                                }

                                FeeController.Update(ret.ID, fees);
                            }
                        }
                        #endregion

                        #region Cập nhật Coupon
                        if (order.CouponID.HasValue && order.CouponID.Value > 0)
                        {
                            CouponController.updateStatusCouponCustomer(CustomerID, order.CouponID.Value, false);
                        }
                        #endregion

                        if (OrderID > 0)
                        {
                            #region Khởi tạo chi tiết đơn hàng
                            ProductPOS              POS          = JsonConvert.DeserializeObject <ProductPOS>(hdfListProduct.Value);
                            List <tbl_OrderDetail>  orderDetails = new List <tbl_OrderDetail>();
                            List <tbl_StockManager> stockManager = new List <tbl_StockManager>();

                            // Reverser
                            POS.productPOS.Reverse();

                            foreach (ProductGetOut item in POS.productPOS)
                            {
                                orderDetails.Add(
                                    new tbl_OrderDetail()
                                {
                                    AgentID                   = AgentID,
                                    OrderID                   = OrderID,
                                    SKU                       = item.SKU,
                                    ProductID                 = item.ProductType == 1 ? item.ProductID : 0,
                                    ProductVariableID         = item.ProductType == 1 ? 0 : item.ProductVariableID,
                                    ProductVariableDescrition = item.ProductVariableSave,
                                    Quantity                  = item.QuantityInstock,
                                    Price                     = item.Giabanle,
                                    Status                    = 1,
                                    DiscountPrice             = 0,
                                    ProductType               = item.ProductType,
                                    CreatedDate               = currentDate,
                                    CreatedBy                 = username,
                                    IsCount                   = true
                                }
                                    );

                                int parentID = item.ProductID;
                                var variable = ProductVariableController.GetByID(item.ProductVariableID);
                                if (variable != null)
                                {
                                    parentID = Convert.ToInt32(variable.ProductID);
                                }

                                stockManager.Add(
                                    new tbl_StockManager()
                                {
                                    AgentID           = AgentID,
                                    ProductID         = item.ProductType == 1 ? item.ProductID : 0,
                                    ProductVariableID = item.ProductType == 1 ? 0 : item.ProductVariableID,
                                    Quantity          = item.QuantityInstock,
                                    QuantityCurrent   = 0,
                                    Type        = 2,
                                    NoteID      = "Xuất kho bán POS",
                                    OrderID     = OrderID,
                                    Status      = 3,
                                    SKU         = item.SKU,
                                    CreatedDate = currentDate,
                                    CreatedBy   = username,
                                    MoveProID   = 0,
                                    ParentID    = parentID
                                }
                                    );
                            }

                            OrderDetailController.Insert(orderDetails);
                            #endregion

                            // Cập nhật lại sô lượng và giá vố vào đơn hàng
                            OrderController.updateQuantityCOGS(OrderID);
                            // Cập nhật lại thông tin kho hàng
                            StockManagerController.Insert(stockManager);

                            #region Khởi tạo đơn hàng đổi trả
                            string refund = hdSession.Value;
                            if (refund != "1")
                            {
                                string[] RefundID = refund.Split('|');
                                var      update   = RefundGoodController.UpdateStatus(RefundID[0].ToInt(), username, 2, OrderID);
                                var      updateor = OrderController.UpdateRefund(OrderID, RefundID[0].ToInt(), username);
                            }
                            #endregion

                            // Hoàn thành khởi tạo đơn hàng nên gán lại giá trị trang lúc ban đầu
                            hdStatusPage.Value = "Create";
                            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "script", "$(function () { HoldOn.close(); printInvoice(" + OrderID + ") });", true);
                        }
                    }
                }
            }
            catch (Exception)
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "script", "$(function () { handleErrorSubmit(); });", true);
            }
        }
Ejemplo n.º 27
0
        protected void btnImport_Click(object sender, EventArgs e)
        {
            DateTime currentDate = DateTime.Now;
            string   username    = Request.Cookies["usernameLoginSystem"].Value;
            var      acc         = AccountController.GetByUsername(username);

            if (acc != null)
            {
                if (acc.RoleID == 0 || acc.RoleID == 1)
                {
                    int mpID = ViewState["ID"].ToString().ToInt(0);
                    var mp   = MoveProController.GetByID(mpID);
                    if (mp != null)
                    {
                        int    AgentID          = Convert.ToInt32(acc.AgentID);
                        int    AgentIDReceive   = hdfAgentID.Value.ToInt(0);
                        string agentSendname    = "";
                        string agentReceivename = "";
                        var    agentSend        = AgentController.GetByID(AgentID);
                        if (agentSend != null)
                        {
                            agentSendname = agentSend.AgentName;
                        }
                        var agentReceive = AgentController.GetByID(AgentIDReceive);
                        if (agentReceive != null)
                        {
                            agentReceivename = agentReceive.AgentName;
                        }
                        string list = hdfvalue.Value;
                        string note = hdfNote.Value;

                        int moveProStatus = hdfStatus.Value.ToInt(0);
                        MoveProController.UpdateStatus(mpID, moveProStatus, currentDate, username);
                        string[] items = list.Split(';');
                        if (items.Length - 1 > 0)
                        {
                            for (int i = 0; i < items.Length - 1; i++)
                            {
                                var      item                 = items[i];
                                string[] itemValue            = item.Split(',');
                                int      ID                   = itemValue[0].ToInt();
                                string   SKU                  = itemValue[1];
                                int      producttype          = itemValue[2].ToInt();
                                string   ProductVariableName  = itemValue[3];
                                string   ProductVariableValue = itemValue[4];
                                double   Quantity             = Convert.ToDouble(itemValue[5]);
                                string   ProductName          = itemValue[6];
                                string   ProductImageOrigin   = itemValue[7];
                                string   ProductVariable      = itemValue[8];
                                int      mpdid                = itemValue[9].ToInt(0);

                                if (mpdid > 0)
                                {
                                    var mpdetail = MoveProDetailController.GetByID(mpdid);
                                    if (mpdetail != null)
                                    {
                                        if (moveProStatus == 3)
                                        {
                                            if (producttype == 1)
                                            {
                                                StockManagerController.Insert(
                                                    new tbl_StockManager {
                                                    AgentID           = AgentID,
                                                    ProductID         = ID,
                                                    ProductVariableID = 0,
                                                    Quantity          = Quantity,
                                                    QuantityCurrent   = 0,
                                                    Type        = 1,
                                                    NoteID      = note,
                                                    OrderID     = 0,
                                                    Status      = 7,
                                                    SKU         = SKU,
                                                    CreatedDate = currentDate,
                                                    CreatedBy   = username,
                                                    MoveProID   = mpID,
                                                    ParentID    = ID
                                                });
                                            }
                                            else
                                            {
                                                int    parentID  = 0;
                                                string parentSKU = "";
                                                var    productV  = ProductVariableController.GetByID(ID);
                                                if (productV != null)
                                                {
                                                    parentSKU = productV.ParentSKU;
                                                }
                                                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     = 0,
                                                    Status      = 7,
                                                    SKU         = SKU,
                                                    CreatedDate = currentDate,
                                                    CreatedBy   = username,
                                                    MoveProID   = mpID,
                                                    ParentID    = parentID
                                                });
                                            }
                                            MoveProDetailController.UpdateQuantityReceive(mpdid, Quantity, currentDate, username);
                                        }
                                        else
                                        {
                                            MoveProDetailController.UpdateQuantityReceive(mpdid, Quantity, currentDate, username);
                                        }
                                    }
                                }
                            }
                        }
                        PJUtils.ShowMessageBoxSwAlert("Cập nhật nhận hàng thành công", "s", true, Page);
                    }
                }
            }
        }
Ejemplo n.º 28
0
        protected void btnImport_Click(object sender, EventArgs e)
        {
            DateTime currentDate = DateTime.Now;
            string   username    = Request.Cookies["usernameLoginSystem"].Value;
            var      acc         = AccountController.GetByUsername(username);

            if (acc != null)
            {
                int    AgentID = Convert.ToInt32(acc.AgentID);
                string list    = hdfvalue.Value;
                string note    = "Nhập kho bằng chức năng nhập kho";
                if (hdfNote.Value != "")
                {
                    note = hdfNote.Value;
                }
                string   jsonurl = "";
                string[] items   = list.Split(';');
                if (items.Length - 1 > 0)
                {
                    int SessionInOutID = SessionInOutController.Insert(currentDate, note, AgentID, 1, currentDate, username).ToInt(0);
                    if (SessionInOutID > 0)
                    {
                        for (int i = 0; i < items.Length - 1; i++)
                        {
                            var      item                 = items[i];
                            string[] itemValue            = item.Split(',');
                            int      ID                   = itemValue[0].ToInt();
                            string   SKU                  = itemValue[1];
                            int      producttype          = itemValue[2].ToInt();
                            string   ProductVariableName  = itemValue[3];
                            string   ProductVariableValue = itemValue[4];
                            double   Quantity             = Convert.ToDouble(itemValue[5]);
                            string   ProductName          = itemValue[6];
                            string   ProductImageOrigin   = itemValue[7];
                            string   ProductVariable      = itemValue[8];
                            var      productV             = ProductVariableController.GetByID(ID);
                            string   parentSKU            = "";
                            parentSKU = productV.ParentSKU;
                            if (producttype == 1)
                            {
                                ProductController.UpdateStockStatus(parentSKU, 1, false, currentDate, username);
                                StockManagerController.Insert(
                                    new tbl_StockManager {
                                    AgentID           = AgentID,
                                    ProductID         = ID,
                                    ProductVariableID = 0,
                                    Quantity          = Quantity,
                                    QuantityCurrent   = 0,
                                    Type        = 1,
                                    NoteID      = note,
                                    OrderID     = 0,
                                    Status      = 1,
                                    SKU         = SKU,
                                    CreatedDate = currentDate,
                                    CreatedBy   = username,
                                    MoveProID   = 0,
                                    ParentID    = ID
                                });
                            }
                            else
                            {
                                int parentID = 0;
                                if (productV != null)
                                {
                                    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     = 0,
                                    Status      = 1,
                                    SKU         = SKU,
                                    CreatedDate = currentDate,
                                    CreatedBy   = username,
                                    MoveProID   = 0,
                                    ParentID    = parentID
                                });
                            }
                            ProductVariableController.UpdateStockStatus(ID, 1, false, currentDate, username);

                            double total = PJUtils.TotalProductQuantityInstock(AgentID, itemValue[1]);

                            if (i == items.Length - 2)
                            {
                                jsonurl += "{\"id\":\"" + itemValue[0] + "\"," + "\"stock\":\"" + total + "\"}]";
                            }
                            else
                            {
                                jsonurl += "[{\"id\":\"" + itemValue[0] + "\"," + "\"stock\":\"" + total + "\"},";
                            }
                        }
                    }

                    var domain = WhiteDomainController.GetAll();
                    if (domain != null)
                    {
                        foreach (var item in domain)
                        {
                            var httpWebRequest = (HttpWebRequest)WebRequest.Create("" + item.Domain + "");
                            httpWebRequest.ContentType = "application/json";
                            httpWebRequest.Method      = "POST";

                            using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
                            {
                                string json = "{\"key\":\"asdasdasd\"," +
                                              "\"list_stock\":" + jsonurl + "}";

                                streamWriter.Write(json);
                                streamWriter.Flush();
                                streamWriter.Close();
                            }

                            var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                            using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
                            {
                                var result = streamReader.ReadToEnd();
                            }
                        }
                    }

                    string barcodeValue = "";
                    string productPrint = "";
                    string barcodeImage = "";

                    string[] value = hdfBarcode.Value.Split(';');
                    if (value.Count() > 1)
                    {
                        var temps = new List <String>();
                        productPrint += "<div class=\"qcode\">";
                        for (int i = 0; i < value.Length - 1; i++)
                        {
                            string[] list2    = value[i].Split(',');
                            int      quantity = list2[1].ToInt();

                            for (int j = 0; j < quantity; j++)
                            {
                                barcodeValue = list2[0];
                                var imageName = String.Format("{0}{1}.png", DateTime.UtcNow.ToString("yyyyMMddHHmmss"), Guid.NewGuid());
                                barcodeImage = "/uploads/barcodes/" + imageName;
                                System.Drawing.Image barCode = PJUtils.MakeBarcodeImage(barcodeValue, 2, true);

                                barCode.Save(HttpContext.Current.Server.MapPath("" + barcodeImage + ""), ImageFormat.Png);

                                productPrint += "<div class=\"item\">";
                                productPrint += "<div class=\"img\"><img src=\"data:image/png;base64, " + Convert.ToBase64String(File.ReadAllBytes(Server.MapPath("" + barcodeImage + ""))) + "\"></div>";
                                productPrint += "<div><h1>" + barcodeValue + "</h1></div>";
                                productPrint += "</div>";

                                temps.Add(imageName);
                            }
                        }
                        productPrint += "</div>";
                        string html = "";
                        html         += productPrint;
                        ltrprint.Text = html;

                        // Delete barcode image after print
                        string[] filePaths = Directory.GetFiles(Server.MapPath("/uploads/barcodes/"));
                        foreach (string filePath in filePaths)
                        {
                            foreach (var item in temps)
                            {
                                if (filePath.EndsWith(item))
                                {
                                    File.Delete(filePath);
                                }
                            }
                        }

                        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "script", "$(function () { printBarcode() });", true);
                    }
                    else
                    {
                        PJUtils.ShowMessageBoxSwAlert("Nhập kho thành công!", "s", true, Page);
                    }
                }
            }
        }
Ejemplo n.º 29
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));
        }
Ejemplo n.º 30
0
        public void InserOrderDetail(string AgentAPIID, string AgentAPICode, int OrderID, int ID, string SKU, int ProductType,
                                     string ProductVariableName, string ProductVariableValue, double Quantity, string ProductName, string ProductImageOrigin,
                                     double ProductPrice, string ProductVariableSave, int ExcuteStatus, int PaymentStatus, string CreatedBy, string username, string password)
        {
            var rs = new ResponseClass();

            if (Login(username, password))
            {
                DateTime currentDate = DateTime.Now;
                var      agent       = AgentController.GetByAPICodeID(AgentAPIID, AgentAPICode);
                if (agent != null)
                {
                    int AgentID           = agent.ID;
                    int ProductID         = 0;
                    int ProductVariableID = 0;
                    if (ProductType == 1)
                    {
                        ProductID         = ID;
                        ProductVariableID = 0;
                    }
                    else
                    {
                        ProductID         = 0;
                        ProductVariableID = ID;
                    }

                    if (ExcuteStatus == 2 && PaymentStatus == 3)
                    {
                        OrderDetailController.Insert(AgentID, OrderID, SKU, ProductID, ProductVariableID, ProductVariableSave, Quantity,
                                                     ProductPrice, 1, 0, ProductType, currentDate, CreatedBy, true);
                        if (ProductType == 1)
                        {
                            StockManagerController.Insert(
                                new tbl_StockManager
                            {
                                AgentID           = AgentID,
                                ProductID         = ProductID,
                                ProductVariableID = 0,
                                Quantity          = Quantity,
                                QuantityCurrent   = 0,
                                Type        = 2,
                                NoteID      = String.Empty,
                                OrderID     = OrderID,
                                Status      = 3,
                                SKU         = SKU,
                                CreatedDate = currentDate,
                                CreatedBy   = CreatedBy,
                                MoveProID   = 0,
                                ParentID    = ProductID
                            });
                        }
                        else
                        {
                            int    parentID  = 0;
                            string parentSKU = "";
                            var    productV  = ProductVariableController.GetByID(ProductVariableID);
                            if (productV != null)
                            {
                                parentSKU = productV.ParentSKU;
                            }
                            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 = ProductVariableID,
                                Quantity          = Quantity,
                                QuantityCurrent   = 0,
                                Type        = 2,
                                NoteID      = String.Empty,
                                OrderID     = OrderID,
                                Status      = 3,
                                SKU         = SKU,
                                CreatedDate = currentDate,
                                CreatedBy   = CreatedBy,
                                MoveProID   = 0,
                                ParentID    = parentID
                            });
                        }
                    }
                    else
                    {
                        OrderDetailController.Insert(AgentID, OrderID, SKU, ProductID, ProductVariableID, ProductVariableSave, Quantity,
                                                     ProductPrice, 1, 0, ProductType, currentDate, CreatedBy, false);
                    }
                    rs.Code    = APIUtils.GetResponseCode(APIUtils.ResponseCode.SUCCESS);
                    rs.Status  = APIUtils.ResponseMessage.Success.ToString();
                    rs.Message = "Tạo mới đơn hàng thành công";
                }
                else
                {
                    rs.Code    = APIUtils.GetResponseCode(APIUtils.ResponseCode.NotFound);
                    rs.Status  = APIUtils.ResponseMessage.Error.ToString();
                    rs.Message = "Không tồn tại thông tin đại lý";
                }
            }
            else
            {
                rs.Code   = APIUtils.GetResponseCode(APIUtils.ResponseCode.FAILED);
                rs.Status = APIUtils.ResponseMessage.Fail.ToString();
            }

            Context.Response.ContentType = "application/json";
            Context.Response.Write(JsonConvert.SerializeObject(rs, Formatting.Indented));
            Context.Response.Flush();
            Context.Response.End();
        }