コード例 #1
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;
            }
        }
コード例 #2
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            // Làm lại đơn hàng đổi trả
            if (!String.IsNullOrEmpty(hdRefundGoodsID.Value))
            {
                RefundGoodDetailController.DeleteByRefundGoodsID(hdRefundGoodsID.Value.ToInt());
                RefundGoodController.DeleteByID(hdRefundGoodsID.Value.ToInt());
                OrderController.DeleteOrderRefund(hdRefundGoodsID.Value.ToInt());
            }
            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)
                {
                    #region Lấy thông tin tao đơn đổi tra
                    // Change user
                    string UserHelp           = "";
                    string redirectToUsername = "";
                    if (username != hdfUsernameCurrent.Value)
                    {
                        UserHelp           = username;
                        username           = hdfUsernameCurrent.Value;
                        redirectToUsername = 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            = "";
                    string Facebook        = txtFacebook.Text.Trim();
                    string RefundNote      = txtRefundsNote.Text;

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

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

                        if (checkCustomer != null)
                        {
                            #region Cập nhật thông tin khách hàng
                            int custID = checkCustomer.ID;

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

                            #region Tạo đơn hàng đổi trả
                            double totalPrice  = Convert.ToDouble(hdfTotalPrice.Value);
                            double totalRefund = Convert.ToDouble(hdfTotalRefund.Value);
                            int    OrderSaleID = hdfOrderSaleID.Value.ToInt(0);

                            var    agent     = AgentController.GetByID(agentID);
                            string agentName = String.Empty;

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

                            //insert ddlstatus, refundnote
                            int status = ddlRefundStatus.SelectedValue.ToInt();

                            if (OrderSaleID != 0)
                            {
                                status = 2;
                            }

                            int rID = RefundGoodController.Insert(
                                new tbl_RefundGoods()
                            {
                                AgentID        = agentID,
                                TotalPrice     = totalPrice.ToString(),
                                Status         = status,
                                CustomerID     = custID,
                                TotalRefundFee = totalRefund.ToString(),
                                CreatedDate    = currentDate,
                                CreatedBy      = username,
                                CustomerName   = checkCustomer.CustomerName,
                                CustomerPhone  = checkCustomer.CustomerPhone,
                                AgentName      = agentName,
                                RefundNote     = RefundNote,
                                OrderSaleID    = OrderSaleID,
                                UserHelp       = UserHelp
                            });
                            #endregion

                            if (rID > 0)
                            {
                                #region Cập nhật đơn đổi hàng vào order
                                if (OrderSaleID != 0)
                                {
                                    OrderController.UpdateRefund(OrderSaleID, rID, username);
                                }
                                #endregion

                                #region Thực hiện tạo chi tiết đơn đổi hàng
                                RefundGoodModel refundModel   = JsonConvert.DeserializeObject <RefundGoodModel>(hdfListProduct.Value);
                                var             refundDetails = new List <tbl_RefundGoodsDetails>();
                                var             stocks        = new List <tbl_StockManager>();
                                int             t             = 0;
                                int             time          = 0;

                                foreach (RefundDetailModel item in refundModel.RefundDetails)
                                {
                                    #region Tạo từng dòng chi tiết đổi hàng
                                    t++;
                                    time += 20;
                                    refundDetails.Add(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
                                    });
                                    #endregion

                                    #region Cập nhật thông tin đổi hàng vào Stock
                                    if (item.ChangeType < 3)
                                    {
                                        int    typeRe = 0;
                                        string note   = "";

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

                                        if (item.ChangeType == 1 || item.ChangeType == 2)
                                        {
                                            stocks.Add(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,
                                            });
                                        }
                                    }
                                    #endregion
                                }

                                refundDetails = RefundGoodDetailController.Insert(refundDetails);
                                RefundGoodController.updateQuantityCOGS(rID);
                                StockManagerController.Insert(stocks);
                                #endregion

                                PJUtils.ShowMessageBoxSwAlertCallFunction("Tạo đơn hàng đổi trả thành công", "s", true, "redirectTo(" + rID + ",'" + redirectToUsername + "')", Page);
                            }
                        }
                    }
                }
            }
        }